dever 3 년 전
부모
커밋
96573ac3f7
8개의 변경된 파일1041개의 추가작업 그리고 935개의 파일을 삭제
  1. 46 63
      app/mshop/src/Data.php
  2. 21 0
      app/shop/database/sell_order.php
  3. 20 0
      app/shop/database/sell_order_goods.php
  4. 293 0
      app/shop/lib/Buyorder.php
  5. 0 84
      app/shop/lib/Order.php
  6. 1 1
      app/shop/lib/Sell.php
  7. 417 419
      app/shop/src/Buy.php
  8. 243 368
      app/shop/src/My.php

+ 46 - 63
app/mshop/src/Data.php

@@ -6,78 +6,61 @@ use Dever;
 
 class Data extends Core
 {
-    public function home()
-    {
-        $day = Dever::input('day');
-
-        if (!$day) {
-            $day = date('Y-m-d');
-        }
+	public function home()
+	{
+		$day = Dever::input('day');
 
-        $where['start'] = Dever::maketime($day . ' 00:00:00');
-        $where['end'] = Dever::maketime($day . ' 23:59:59');
-        $where['shop_id'] = $this->shop_id;
+		if (!$day) {
+			$day = date('Y-m-d');
+		}
 
-        $this->data['num_order'] = round(Dever::db('shop/sell_order')->getOrderNum($where), 2);
-        $cash = Dever::db('shop/sell_order')->getCashNum($where);
-        if ($cash) {
-        	$this->data['num_cash'] = $cash['total'];
-        }
-        if (!$this->data['num_cash']) {
-        	$this->data['num_cash'] = 0;
-        }
-        $goods = Dever::db('shop/sell_order')->getGoodsNum($where);
-        if ($goods) {
-        	$this->data['num_goods'] = $goods['total'];
-        }
-        if (!$this->data['num_goods']) {
-        	$this->data['num_goods'] = 0;
-        }
+		$where['start'] = Dever::maketime($day . ' 00:00:00');
+		$where['end'] = Dever::maketime($day . ' 23:59:59');
+		$where['shop_id'] = $this->shop_id;
 
-        $this->data['num_cash'] = round($this->data['num_cash'], 2);
-        $this->data['num_goods'] = round($this->data['num_goods'], 2);
+		$this->data['num_order'] = round(Dever::db('shop/sell_order')->getOrderNum($where), 2);
+		$cash = Dever::db('shop/sell_order')->getCashNum($where);
+		if ($cash) {
+			$this->data['num_cash'] = $cash['total'];
+		}
+		if (!$this->data['num_cash']) {
+			$this->data['num_cash'] = 0;
+		}
+		$goods = Dever::db('shop/sell_order')->getGoodsNum($where);
+		if ($goods) {
+			$this->data['num_goods'] = $goods['total'];
+		}
+		if (!$this->data['num_goods']) {
+			$this->data['num_goods'] = 0;
+		}
 
-        return $this->data;
-    }
+		$this->data['num_cash'] = round($this->data['num_cash'], 2);
+		$this->data['num_goods'] = round($this->data['num_goods'], 2);
 
-    # 销售订单管理
-    public function sell_order()
-    {
-        $where['shop_id'] = $this->shop_id;
-        $mobile = Dever::input('mobile');
-        if ($mobile) {
-        	$where['mobile'] = $mobile;
-        }
-        $status = Dever::input('status');
-        if ($status) {
-        	$where['status'] = $status;
-        }
+		return $this->data;
+	}
 
-        $method = Dever::input('method');
-        if ($method) {
-        	$where['method'] = $method;
-        }
+	# 销售订单管理
+	public function sell_order()
+	{
+		return Dever::load('shop/lib/buyorder')->set(2, 1)->getList($this->shop_id);
+	}
 
-        $pay_method = Dever::input('pay_method');
-        if ($pay_method) {
-        	$where['pay_method'] = $pay_method;
-        }
+    # 查看订单详情
+    public function order_view()
+    {
+        $order_id = Dever::input('order_id');
 
-        $day = Dever::input('day');
-        if ($day) {
-        	$where['start'] = Dever::maketime($day . ' 00:00:00');
-        	$where['end'] = Dever::maketime($day . ' 23:59:59');
-        }
-        
-        $this->data = Dever::db('shop/sell_order')->getAll($where);
+        return Dever::load('shop/lib/buyorder')->set(2, 2)->getView($this->shop_id, $order_id);
+    }
 
-        if ($this->data) {
-            $this->config = Dever::db('shop/sell_order')->config;
-            foreach ($this->data as $k => $v) {
-                $this->data[$k] = $this->order_info($v);
-            }
-        }
+    # 门店全部退款
+    public function order_tui()
+    {
+        $order_id = Dever::input('order_id');
+        $status = Dever::input('status');
+        $desc = Dever::input('desc');
 
-        return $this->data;
+        return Dever::load('shop/lib/buyorder')->set(2, 2)->tui($this->shop_id, $order_id, $status, $desc);
     }
 }

+ 21 - 0
app/shop/database/sell_order.php

@@ -216,6 +216,26 @@ return array
             'list'      => true,
         ),
 
+        'tk_cash'      => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '退款金额',
+            'default'   => '',
+            'desc'      => '退款金额',
+            'match'     => 'option',
+            'update'    => 'text',
+        ),
+
+        'tk_desc'      => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '退款描述',
+            'default'   => '',
+            'desc'      => '退款描述',
+            'match'     => 'option',
+            'update'    => 'textarea',
+        ),
+
         'info'      => array
         (
             'type'      => 'varchar-300',
@@ -356,6 +376,7 @@ return array
             'option' => array
             (
                 'uid' => 'yes',
+                'name' => array('yes', 'like'),
                 'shop_id' => 'yes',
                 'mobile' => 'yes',
                 'method' => 'yes',

+ 20 - 0
app/shop/database/sell_order_goods.php

@@ -122,6 +122,26 @@ return array
             'list'        => true,
         ),
 
+        'tk_cash'      => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '退款金额',
+            'default'   => '',
+            'desc'      => '退款金额',
+            'match'     => 'option',
+            'update'    => 'text',
+        ),
+
+        'tk_desc'      => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '退款描述',
+            'default'   => '',
+            'desc'      => '退款描述',
+            'match'     => 'option',
+            'update'    => 'textarea',
+        ),
+
         'status'        => array
         (
             'type'      => 'int-11',

+ 293 - 0
app/shop/lib/Buyorder.php

@@ -0,0 +1,293 @@
+<?php
+
+namespace Shop\Lib;
+
+use Dever;
+
+class Buyorder
+{
+	# 1是用户自己看,2是门店看
+	public $type = 1;
+	# 1是列表,2是详情
+	public $view = 1;
+	# 获取配置
+	public $config = array();
+	# table
+	public $table = 'shop/sell_order';
+
+	public function __construct()
+	{
+		$this->config = Dever::db($this->table)->config;
+	}
+
+	# 设置订单的类型
+	public function set($type, $view)
+	{
+		$this->type = $type;
+		$this->view = $view;
+
+		return $this;
+	}
+
+	# 获取公共的where
+	public function where($id)
+	{
+		$where = array();
+		if ($this->type == 1) {
+			$where['uid'] = $id;
+		} elseif ($this->type == 2) {
+			$where['shop_id'] = $id;
+		}
+		if (!$where) {
+			Dever::alert('参数错误');
+		}
+
+		return $where;
+	}
+
+	# 获取订单列表
+	public function getList($id)
+	{
+		$result = array();
+		$where = $this->where($id);
+		$mobile = Dever::input('mobile');
+		if ($mobile) {
+			$where['mobile'] = $mobile;
+		}
+		$status = Dever::input('status');
+		if ($status) {
+			$where['status'] = $status;
+		}
+
+		$method = Dever::input('method');
+		if ($method) {
+			$where['method'] = $method;
+		}
+
+		$pay_method = Dever::input('pay_method');
+		if ($pay_method) {
+			$where['pay_method'] = $pay_method;
+		}
+
+		$result['search_value'] = $where;
+		$result['search_value']['day'] = $day = Dever::input('day');
+		if ($day) {
+			$where['start'] = Dever::maketime($day . ' 00:00:00');
+			$where['end'] = Dever::maketime($day . ' 23:59:59');
+		}
+
+		$result['order'] = Dever::db($this->table)->getAll($where);
+
+		if ($result['order']) {
+			foreach ($result['order'] as $k => $v) {
+				$result['order'][$k] = $this->getInfo($v);
+			}
+		}
+
+		$result['search'] = array();
+		$result['search']['status'] = array
+		(
+			array('value' => 1, 'name' => '待支付'),
+			array('value' => 2, 'name' => '待处理'),
+			array('value' => 3, 'name' => '待自提'),
+			array('value' => 3, 'name' => '配送中'),
+			array('value' => '6,7,8', 'name' => '退款'),
+			array('value' => 4, 'name' => '已完成'),
+			array('value' => 5, 'name' => '已取消'),
+		);
+		$result['search']['method'] = array
+		(
+			array('value' => 1, 'name' => '自提'),
+			array('value' => 2, 'name' => '配送')
+		);
+		$result['search']['pay_method'] = array
+		(
+			array('value' => 1, 'name' => '平台结算'),
+			array('value' => 2, 'name' => '门店代下单')
+		);
+
+		return $result;
+	}
+
+	# 查看详情
+	public function getView($id, $order_id, $show = true)
+	{
+		$where = $this->where($id);
+		$where['id'] = $order_id;
+
+		$result = Dever::db($this->table)->find($where);
+
+		if (!$result) {
+			Dever::alert('订单不存在');
+		}
+
+		if ($show) {
+			$result = $this->getInfo($result);
+		}
+
+		return $result;
+	}
+
+	# 获取订单详细信息
+	public function getInfo($info)
+	{
+		if ($info['status'] == 1) {
+			# 15分钟内支付,900秒
+			$m = 9000;
+			# 支付倒计时
+			$info['time'] = time() - $info['cdate'];
+			if ($info['time'] >= $m) {
+				# 已过期,自动取消
+				$info['time'] = -1;
+				Dever::db($this->table)->update(array('where_id' => $info['id'], 'status' => 11));
+				$info['status'] = 11;
+			} else {
+				$info['time'] = $m - $info['time'];
+			}
+		}
+
+		$info['status_name'] = $this->config['status'][$info['status']];
+		$info['method_name'] = $this->config['method'][$info['method']];
+		$info['pay_method_name'] = $this->config['pay_method'][$info['pay_method']];
+
+		if ($this->type == 1) {
+			if ($info['status'] == 2) {
+				$info['status_name'] = '支付成功';
+			}
+			if ($info['status'] == 3) {
+				if ($info['method'] == 1) {
+					$info['status_name'] = '已配货';
+				} else {
+					$info['status_name'] = '配送中';
+				}
+			}
+		} elseif ($this->type == 2) {
+			if ($info['status'] == 2) {
+				$info['status_name'] = '待处理';
+			}
+			if ($info['status'] == 3) {
+				if ($info['method'] == 1) {
+					$info['status_name'] = '待自提';
+				} else {
+					$info['status_name'] = '配送中';
+				}
+			}
+		}
+
+		if ($info['method'] == 2) {
+			$info['ps_info'] = Dever::db('shop/sell_order_ps')->find(array('order_id' => $info['id']));
+			if ($info['ps_info']) {
+				$info['ps_info']['service_name'] = '商家自送';
+				if ($info['ps_info']['service_id'] > 0) {
+					//暂时还没有
+				}
+			}
+		}
+
+		$info['goods'] = Dever::db('shop/sell_order_goods')->select(array('order_id' => $info['id']));
+		$info['user'] = Dever::load('passport/api')->info($info['uid']);
+		$info['shop'] = Dever::db('shop/info')->getOne($info['shop_id']);
+		$info['cdate'] = date('Y-m-d H:i', $info['cdate']);
+
+		if ($this->view == 2) {
+			foreach ($info['goods'] as $k => $v) {
+				$info['goods'][$k]['info'] = Dever::load('goods/lib/info')->getPayInfo($v['goods_id'], $v['sku_id']);
+			}
+			if ($info['address_id']) {
+				$info['address'] = Dever::db('passport/address')->find($info['address_id']);
+			}
+
+			if ($info['invoice_id']) {
+				$info['invoice'] = Dever::db('passport/invoice')->find($info['invoice_id']);
+			}
+
+			if ($info['user_coupon_id']) {
+				$coupon = Dever::db('shop/user_coupon')->find($info['user_coupon_id']);
+				if ($coupon) {
+					$info['coupon'] = Dever::db('goods/coupon')->find($coupon['coupon_id']);
+				}
+			}
+		} else {
+			foreach ($info['goods'] as $k => $v) {
+				$goods = Dever::db('goods/info')->one($v['goods_id']);
+				$info['goods'][$k]['name'] = $goods['name'];
+				$info['goods'][$k]['cover'] = $goods['cover'];
+			}
+		}
+
+		return $info;
+	}
+
+	# 取消订单
+	public function cancel($id, $order_id)
+	{
+		$data = $this->getView($id, $order_id);
+		if ($data['status'] == 1) {
+			$state = Dever::db('shop/sell_order')->update(array('where_id' => $id, 'status' => 5));
+			if ($state) {
+
+			}
+
+			return 'ok';
+		} else {
+			Dever::alert('当前订单状态不允许取消');
+		}
+	}
+
+	# 全部退款
+	public function tui($id, $order_id, $status = 6, $desc = '')
+	{
+        if ($status != 6 && $status != 7 && $status != 8) {
+            Dever::alert('当前订单状态不允许退货退款');
+        }
+
+        $data = $this->getView($id, $order_id);
+        if ($data['status'] == 2) {
+            $state = Dever::db('shop/sell_order')->update(array('where_id' => $id, 'status' => $status, 'tk_desc' => $desc, 'tk_cash' => $data['price']));
+            if ($state) {
+                $shop = Dever::db('shop/info')->one($data['shop_id']);
+                $msg_param['type'] = 1;//消息类型1是订单消息
+                $msg_param['id'] = $data['id'];
+                $msg_param['name'] = $shop['name'];
+                $msg_param = Dever::json_encode($msg_param);
+                $msg = '您有一笔订单已退款,退款将在3个工作日内返回原支付账户';
+                Dever::load('message/lib/data')->push(-1, $data['uid'], '退款成功通知', $msg, 1, 1, false, $msg_param);
+            }
+
+            # 退款到原支付账户 待处理
+
+            return 'ok';
+        } else {
+            Dever::alert('当前订单状态不允许退货退款');
+        }
+	}
+
+	# 部分退款
+	public function tui_one($id, $order_id, $goods_id, $status = 6, $desc = '')
+	{
+        if ($status != 6 && $status != 7 && $status != 8) {
+            Dever::alert('当前订单状态不允许退货退款');
+        }
+
+        $data = $this->getView($id, $order_id);
+        if ($data['status'] == 2) {
+            $state = Dever::db('shop/sell_order')->update(array('where_id' => $id, 'status' => $status, 'tk_desc' => $desc, 'tk_cash' => $data['price']));
+            if ($state) {
+                $shop = Dever::db('shop/info')->one($data['shop_id']);
+                $msg_param['type'] = 1;//消息类型1是订单消息
+                $msg_param['id'] = $data['id'];
+                $msg_param['name'] = $shop['name'];
+                $msg_param = Dever::json_encode($msg_param);
+                $msg = '您有一笔订单已退款,退款将在3个工作日内返回原支付账户';
+                Dever::load('message/lib/data')->push(-1, $data['uid'], '退款成功通知', $msg, 1, 1, false, $msg_param);
+            }
+
+            # 退款到原支付账户 待处理
+
+            return 'ok';
+        } else {
+            Dever::alert('当前订单状态不允许退货退款');
+        }
+	}
+
+}

+ 0 - 84
app/shop/lib/Order.php

@@ -1,84 +0,0 @@
-<?php
-
-namespace Shop\Lib;
-
-use Dever;
-
-class Order
-{
-    # 获取订单详细信息
-    public function order_info($info, $type = 1)
-    {
-        if ($info['status'] == 1) {
-            # 15分钟内支付,900秒
-            $m = 9000;
-            # 支付倒计时
-            $info['time'] = time() - $info['cdate'];
-            if ($info['time'] >= $m) {
-                # 已过期,自动取消
-                $info['time'] = -1;
-                Dever::db('shop/sell_order')->update(array('where_id' => $info['id'], 'status' => 11));
-                $info['status'] = 11;
-            } else {
-                $info['time'] = $m - $info['time'];
-            }
-        }
-
-        $info['status_name'] = $this->config['status'][$info['status']];
-        $info['method_name'] = $this->config['method'][$info['method']];
-        $info['pay_method_name'] = $this->config['pay_method'][$info['pay_method']];
-
-        if ($info['status'] == 2) {
-            $info['status_name'] = '待处理';
-        }
-        if ($info['status'] == 3) {
-            if ($info['method'] == 1) {
-                $info['status_name'] = '待自提';
-            } else {
-                $info['status_name'] = '配送中';
-            }
-        }
-
-        if ($info['method'] == 2) {
-            $info['ps_info'] = Dever::db('shop/sell_order_ps')->find(array('order_id' => $info['id']));
-            if ($info['ps_info']) {
-                $info['ps_info']['service_name'] = '商家自送';
-                if ($info['ps_info']['service_id'] > 0) {
-                    //暂时还没有
-                }
-            }
-        }
-
-        $info['goods'] = Dever::db('shop/sell_order_goods')->select(array('order_id' => $info['id']));
-        $info['shop'] = Dever::db('shop/info')->getOne($info['shop_id']);
-        $info['cdate'] = date('Y-m-d H:i', $info['cdate']);
-
-        if ($type == 2) {
-            foreach ($info['goods'] as $k => $v) {
-                $info['goods'][$k]['info'] = Dever::load('goods/lib/info')->getPayInfo($v['goods_id'], $v['sku_id']);
-            }
-            if ($info['address_id']) {
-                $info['address'] = Dever::db('passport/address')->find($info['address_id']);
-            }
-
-            if ($info['invoice_id']) {
-                $info['invoice'] = Dever::db('passport/invoice')->find($info['invoice_id']);
-            }
-
-            if ($info['user_coupon_id']) {
-                $coupon = Dever::db('shop/user_coupon')->find($info['user_coupon_id']);
-                if ($coupon) {
-                    $info['coupon'] = Dever::db('goods/coupon')->find($coupon['coupon_id']);
-                }
-            }
-        } else {
-            foreach ($info['goods'] as $k => $v) {
-                $goods = Dever::db('goods/info')->one($v['goods_id']);
-                $info['goods'][$k]['name'] = $goods['name'];
-                $info['goods'][$k]['cover'] = $goods['cover'];
-            }
-        }
-
-        return $info;
-    }
-}

+ 1 - 1
app/shop/lib/Sell.php

@@ -22,7 +22,7 @@ class Sell
         $order_data['mobile'] = $user['mobile'];
         $order_data['address_id'] = $address_id;
         $order_data['invoice_id'] = $invoice_id;
-        $order_data['name'] = $name;
+        $order_data['name'] = is_array($name) ? implode(',', $name) : $name;
         $order_data['num'] = $num;
         $order_data['info'] = $info;
         $order_data['price'] = $price;

+ 417 - 419
app/shop/src/Buy.php

@@ -7,423 +7,421 @@ use Main\Lib\Core;
 
 class Buy extends Core
 {
-    public function __construct()
-    {
-        parent::__construct();
-        $this->checkLogin();
-        $this->shop_id = Dever::input('shop_id');
-
-        if (!$this->shop_id) {
-            Dever::alert('请选择门店');
-        }
-
-        $this->shop = Dever::db('shop/info')->getOne($this->shop_id);
-
-        if (!$this->shop) {
-            Dever::alert('门店不存在');
-        }
-    }
-
-    # 分享
-    public function share()
-    {
-        $act_id = Dever::input('act_id', 1);
-        $path = Dever::input('path');
-        $this->data = Dever::load('shop/lib/share')->up($this->uid, $this->shop_id, $act_id, $path);
-
-        return $this->data;
-    }
-
-    # 获取店铺的优惠券
-    public function getCoupon()
-    {
-        $this->data['coupon'] = Dever::load('shop/lib/coupon')->getAll($this->shop_id);
-
-        $this->data['shop'] = $this->shop;
-
-        $act_id = Dever::input('act_id', 1);
-
-        $this->data['act'] = Dever::db('act/info')->find($act_id);
-
-        return $this->data;
-    }
-
-    # 领取优惠券 也得判断一下用户是否有权限领取
-    public function takeCoupon()
-    {
-        # 验证这个券是否可以领取
-        $shop_coupon_id = Dever::input('shop_coupon_id');
-        $coupon = explode(',', $shop_coupon_id);
-
-        $this->data['take'] = array();
-        foreach ($coupon as $k => $v) {
-            $this->data['take']['shop_coupon_id'] = $v;
-            $this->data['take']['status'] = Dever::load('shop/lib/coupon')->getOne($this->uid, $this->shop, $v);
-        }
-
-        return $this->data;
-    }
-
-    # 获取商品详细信息
-    public function getGoodsInfo()
-    {
-        $id = Dever::input('goods_id');
-        if (!$id) {
-            Dever::alert('错误的商品');
-        }
-
-        $this->data['goods'] = Dever::load('shop/lib/info')->getGoodsInfo($this->shop_id, $id);
-
-        //$this->data['shop'] = $this->shop;
-
-        return $this->data;
-    }
-
-    # 获取购物车的数据
-    public function getCart()
-    {
-        $where['uid'] = $this->uid;
-        $where['shop_id'] = $this->shop_id;
-
-        $this->data['cart'] = Dever::db('shop/cart')->select($where);
-
-        if ($this->data['cart']) {
-            foreach ($this->data['cart'] as $k => $v) {
-                $this->data['cart'][$k]['goods'] = Dever::load('goods/lib/info')->getPayInfo($v['goods_id'], $v['sku_id']);
-
-                if (isset($this->data['cart'][$k]['goods']['sku_id'])) {
-                    $this->data['cart'][$k]['price_id'] = $this->data['cart'][$k]['goods']['sku_id'];
-                }
-            }
-        }
-
-        return $this->data['cart'];
-    }
-
-    # 加入到购物车
-    public function addCart()
-    {
-        $where['uid'] = $this->uid;
-        $where['shop_id'] = $this->shop_id;
-        $where['goods_id'] = Dever::input('goods_id');
-        $where['sku_id'] = Dever::input('price_id');
-        if (!$where['goods_id']) {
-            Dever::alert('错误的商品');
-        }
-
-        $info = Dever::db('shop/cart')->find($where);
-
-        $where['num'] = Dever::input('num');
-        if (!$info) {
-            # 验证库存
-            Dever::load('shop/lib/info')->checkTotal($where['num'], $where['goods_id'], $this->shop_id, $where['sku_id'], 2);
-            $state = Dever::db('shop/cart')->insert($where);
-        } else {
-            $where['num'] += $info['num'];
-            # 验证库存
-            Dever::load('shop/lib/info')->checkTotal($where['num'], $where['goods_id'], $this->shop_id, $where['sku_id'], 2);
-            $where['where_id'] = $info['id'];
-            $state = Dever::db('shop/cart')->update($where);
-        }
-
-        return $this->getCart();
-    }
-
-    # 清空购物车
-    public function dropCart()
-    {
-        $where['uid'] = $this->uid;
-        $where['shop_id'] = $this->shop_id;
-
-        $state = Dever::db('shop/cart')->delete($where);
-
-        return $this->alert($state);
-    }
-
-    # 更新购物车数量
-    public function upCart()
-    {
-        $where['uid'] = $this->uid;
-        $where['shop_id'] = $this->shop_id;
-        $where['id'] = Dever::input('cart_id');
-
-        $status = Dever::input('status', 1);
-        $type = Dever::input('type', 1);
-        $num = Dever::input('num');
-
-        $info = Dever::db('shop/cart')->find($where);
-
-        $state = false;
-
-        if ($info) {
-            if ($type == 1) {
-                $num = $info['num'] + $num;
-            } else {
-                $num = $info['num'] - $num;
-            }
-            $where = array();
-            $where['where_id'] = $info['id'];
-            if ($num <= 0) {
-                $state = Dever::db('shop/cart')->delete($info['id']);
-            } else {
-                $where['status'] = $status;
-                $where['num'] = $num;
-                
-                # 验证库存
-                $total = Dever::load('shop/lib/info')->checkTotal($num, $info['goods_id'], $this->shop_id, $info['sku_id']);
-
-                if ($where['num'] > $total) {
-                    # 库存不足
-                    $where['num'] = $total;
-                    $state = Dever::db('shop/cart')->update($where); 
-                    return array('cart' => 2, 'data' => $total);
-                }
-                $state = Dever::db('shop/cart')->update($where); 
-            }
-        }
-
-        return array('cart' => 1, 'data' => $this->getCart());
-    }
-
-    # 确认订单页面
-    public function confirm()
-    {
-        $this->data['user'] = $this->user;
-        $this->goods();
-        $this->coupon($this->data['price'], $this->data['method']);
-
-        return $this->data;
-    }
-
-    # 优惠券
-    public function coupon($price, $method, $type = 1)
-    {
-        $user_coupon_id = Dever::input('user_coupon_id');
-
-        $this->data['user_coupon_id'] = 0;
-        $this->data['coupon_id'] = 0;
-        $this->data['coupon_cash'] = 0;
-
-        if ($type == 1) {
-            if ($price <= 0) {
-                Dever::alert('付款价格错误');
-            }
-            # 查找符合要求的优惠券
-            $coupon = Dever::db('shop/user_coupon')->getAll(array('uid' => $this->uid, 'city' => $this->shop['city'], 'status' => 1, 'edate' => time()));
-
-            if ($coupon) {
-                foreach ($coupon as $k => $v) {
-                    if ($v['shop_id'] != $this->shop_id) {
-                        # 查找该券是否符合当前店铺
-                        if ($this->shop['coupon_city'] == 2) {
-                            continue;
-                        }
-                    }
-                    $coupon_info = Dever::db('goods/coupon')->find($v['coupon_id']);
-                    if ($coupon_info && ($coupon_info['method'] == $method || $coupon_info['method'] == 3)) {
-                        $kou = false;
-                        if ($coupon_info['type'] == 1) {
-                            # 满减券
-                            if ($price >= $coupon_info['total_cash']) {
-                                $kou = true;
-                            }
-                        } else {
-                            $kou = true;
-                        }
-
-                        if ($kou) {
-                            $coupon_info['user_coupon_id'] = $v['id'];
-                            $coupon_info['uid'] = $v['uid'];
-                            $coupon_info['shop_id'] = $v['shop_id'];
-                            $coupon_info['edate'] = date('Y-m-d', $v['edate']);
-                            $this->data['coupon'][] = $coupon_info;
-
-                            if (!$user_coupon_id && $this->data['coupon_cash'] <= $coupon_info['cash']) {
-                                $this->data['user_coupon_id'] = $v['id'];
-                                $this->data['coupon_id'] = $coupon_info['id'];
-                                $this->data['coupon_cash'] = $coupon_info['cash'];
-                            }
-                        }
-                    }
-                }
-            }
-        }
-
-        if ($user_coupon_id) {
-            if ($price <= 0) {
-                Dever::alert('付款价格错误');
-            }
-            $coupon = Dever::db('shop/user_coupon')->find(array('uid' => $this->uid, 'id' => $user_coupon_id, 'status' => 1));
-            if (!$coupon) {
-                Dever::alert('优惠券不可用');
-            }
-            if (time() > $coupon['edate']) {
-                Dever::db('shop/user_coupon')->update(array('where_id' => $user_coupon_id, 'status' => 3));
-                Dever::alert('优惠券已过期');
-            }
-
-            if ($coupon['shop_id'] != $this->shop_id) {
-                if ($this->shop['coupon_city'] == 2) {
-                    Dever::alert('优惠券不可用');
-                } else {
-                    $coupon_info = Dever::db('shop/coupon')->find(array('shop_id' => $coupon['shop_id'], 'coupon_id' => $coupon['coupon_id'], 'city' => $coupon['city']));
-                    if (!$coupon_info) {
-                        Dever::alert('优惠券不可用');
-                    }
-                }
-            }
-
-            $goods_coupon = Dever::db('goods/coupon')->find($coupon['coupon_id']);
-            if ($goods_coupon['type'] == 2 && $this->data['price'] < $goods_coupon['total_cash']) {
-                Dever::alert('优惠券不可用');
-            }
-            if ($goods_coupon['method'] != $method && $goods_coupon['method'] != 3) {
-                Dever::alert('优惠券不可用');
-            }
-
-            $this->data['user_coupon_id'] = $user_coupon_id;
-            $this->data['coupon_id'] = $goods_coupon['id'];
-            $this->data['coupon_cash'] = $goods_coupon['cash'];
-        }
-
-        if (isset($this->data['coupon_cash']) && $this->data['coupon_cash'] > 0) {
-            $this->data['price'] -= $this->data['coupon_cash'];
-            if ($this->data['price'] < 0) {
-                $this->data['price'] = 0;
-            }
-        }
-    }
-
-    # 得到商品和总价
-    private function goods()
-    {
-        # 1自提,2配送
-        $this->data['method'] = Dever::input('method', 1);
-        $this->data['pay_method'] = Dever::input('pay_method');
-        $card = Dever::input('card');
-        $pwd = Dever::input('pwd');
-
-        if ($this->data['pay_method'] == 3 && $card && $pwd) {
-            $this->data['card'] = Dever::db('goods/card_code')->find(array('card' => $card, 'pwd' => $pwd, 'status' => 1));
-            if (!$this->data['card']) {
-                Dever::alert('卡号/密码错误');
-            }
-            if (time() > $this->data['card']['edate']) {
-                Dever::alert('礼品卡已失效');
-            }
-            $card_info = Dever::db('goods/card')->find($this->data['card']['card_id']);
-            if (!$card_info) {
-                Dever::alert('卡号/密码错误');
-            }
-            $goods = Dever::array_decode($card_info['goods']);
-
-            $goods_id = array();
-            $num = array();
-            $sku_id = array();
-            foreach ($goods as $k => $v) {
-                $goods_id[] = $v['goods_id'];
-                $num[] = $v['num'];
-                $sku_id[] = -1;
-            }
-        } else {
-            $goods_id = Dever::input('goods_id');
-            if (!$goods_id) {
-                Dever::alert('请传入商品');
-            }
-            $goods_id = explode(',', $goods_id);
-
-            $sku_id = Dever::input('price_id');
-            if ($sku_id) {
-                $sku_id = explode(',', $sku_id);
-            }
-            
-            $num = Dever::input('num');
-            $num = Dever::input('num');
-            if (!$num) {
-                Dever::alert('请传入商品数量');
-            }
-            $num = explode(',', $num);
-        }
-
-        $this->data['price'] = 0;
-        $this->data['num'] = 0;
-        $this->data['name'] = '';
-        $count = count($goods_id);
-        # 计算总价格
-        foreach ($goods_id as $k => $v) {
-            $s = isset($sku_id[$k]) ? $sku_id[$k] : -1;
-            $n = isset($num[$k]) ? $num[$k] : 1;
-            $this->data['list'][$k] = Dever::load('goods/lib/info')->getPayInfo($v, $s, $n);
-            $this->data['list'][$k]['num'] = $n;
-
-            # 2是库存不足
-            $this->data['list'][$k]['ku_state'] = 1;
-
-            # 验证是否有货
-            $total = Dever::load('shop/lib/info')->checkTotal($n, $v, $this->shop_id, $s);
-
-            if ($total <= 0) {
-                $this->data['list'][$k]['ku_state'] = 2;
-                $this->data['list'][$k]['buy_num'] = 0;
-            }
-
-            if ($this->data['list'][$k]['ku_state'] == 1) {
-                $this->data['list'][$k]['buy_num'] = $n;
-                $this->data['num'] += $n;
-                $this->data['price'] += $this->data['list'][$k]['price'] * $n;
-                if (!$this->data['name']) {
-                    if ($count > 1) {
-                        $this->data['name'] = $this->data['list'][$k]['name'] . '等' . $count . '种商品';
-                    } else {
-                        $this->data['name'] = $this->data['list'][$k]['name'];
-                    }
-                }
-            }
-        }
-    }
-
-    # 开始下单
-    public function pay()
-    {
-        $refer = Dever::input('refer');
-        $cart = Dever::input('cart', 1);
-        $parent_uid = Dever::input('parent_uid');
-        $address_id = Dever::input('address_id');
-        $invoice_id = Dever::input('invoice_id');
-        
-        $info = Dever::input('info');
-
-        $this->goods();
-        $this->coupon($this->data['price'], $this->data['method'], 2);
-
-        if ($this->data['pay_method'] > 1) {
-            $cart = 2;
-        }
-
-        if (!$this->data['coupon_id'] && $this->data['price'] <= 0) {
-            Dever::alert('已售空');
-        }
-
-        if ($this->data['method'] == 2 && !$address_id) {
-            Dever::alert('收货地址不能为空');
-        }
-
-        if (!isset($this->data['card'])) {
-            $this->data['card'] = false;
-        }
-
-        $pay = Dever::load('shop/lib/sell')->action($this->data['method'], $this->data['pay_method'], $this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['price'], $address_id, $invoice_id, $info, $this->data['card'], $this->data['user_coupon_id'], $cart, $refer);
-        return $pay;
-    }
-
-    # 再次付款
-    public function r_pay()
-    {
-        $refer = Dever::input('refer');
-        $order_id = Dever::input('order_id');
-
-        $pay = Dever::load('shop/lib/sell')->raction($order_id, $refer);
-
-        return $pay;
-    }
+	public function __construct()
+	{
+		parent::__construct();
+		$this->checkLogin();
+		$this->shop_id = Dever::input('shop_id');
+
+		if (!$this->shop_id) {
+			Dever::alert('请选择门店');
+		}
+
+		$this->shop = Dever::db('shop/info')->getOne($this->shop_id);
+
+		if (!$this->shop) {
+			Dever::alert('门店不存在');
+		}
+	}
+
+	# 分享
+	public function share()
+	{
+		$act_id = Dever::input('act_id', 1);
+		$path = Dever::input('path');
+		$this->data = Dever::load('shop/lib/share')->up($this->uid, $this->shop_id, $act_id, $path);
+
+		return $this->data;
+	}
+
+	# 获取店铺的优惠券
+	public function getCoupon()
+	{
+		$this->data['coupon'] = Dever::load('shop/lib/coupon')->getAll($this->shop_id);
+
+		$this->data['shop'] = $this->shop;
+
+		$act_id = Dever::input('act_id', 1);
+
+		$this->data['act'] = Dever::db('act/info')->find($act_id);
+
+		return $this->data;
+	}
+
+	# 领取优惠券 也得判断一下用户是否有权限领取
+	public function takeCoupon()
+	{
+		# 验证这个券是否可以领取
+		$shop_coupon_id = Dever::input('shop_coupon_id');
+		$coupon = explode(',', $shop_coupon_id);
+
+		$this->data['take'] = array();
+		foreach ($coupon as $k => $v) {
+			$this->data['take']['shop_coupon_id'] = $v;
+			$this->data['take']['status'] = Dever::load('shop/lib/coupon')->getOne($this->uid, $this->shop, $v);
+		}
+
+		return $this->data;
+	}
+
+	# 获取商品详细信息
+	public function getGoodsInfo()
+	{
+		$id = Dever::input('goods_id');
+		if (!$id) {
+			Dever::alert('错误的商品');
+		}
+
+		$this->data['goods'] = Dever::load('shop/lib/info')->getGoodsInfo($this->shop_id, $id);
+
+		//$this->data['shop'] = $this->shop;
+
+		return $this->data;
+	}
+
+	# 获取购物车的数据
+	public function getCart()
+	{
+		$where['uid'] = $this->uid;
+		$where['shop_id'] = $this->shop_id;
+
+		$this->data['cart'] = Dever::db('shop/cart')->select($where);
+
+		if ($this->data['cart']) {
+			foreach ($this->data['cart'] as $k => $v) {
+				$this->data['cart'][$k]['goods'] = Dever::load('goods/lib/info')->getPayInfo($v['goods_id'], $v['sku_id']);
+
+				if (isset($this->data['cart'][$k]['goods']['sku_id'])) {
+					$this->data['cart'][$k]['price_id'] = $this->data['cart'][$k]['goods']['sku_id'];
+				}
+			}
+		}
+
+		return $this->data['cart'];
+	}
+
+	# 加入到购物车
+	public function addCart()
+	{
+		$where['uid'] = $this->uid;
+		$where['shop_id'] = $this->shop_id;
+		$where['goods_id'] = Dever::input('goods_id');
+		$where['sku_id'] = Dever::input('price_id');
+		if (!$where['goods_id']) {
+			Dever::alert('错误的商品');
+		}
+
+		$info = Dever::db('shop/cart')->find($where);
+
+		$where['num'] = Dever::input('num');
+		if (!$info) {
+			# 验证库存
+			Dever::load('shop/lib/info')->checkTotal($where['num'], $where['goods_id'], $this->shop_id, $where['sku_id'], 2);
+			$state = Dever::db('shop/cart')->insert($where);
+		} else {
+			$where['num'] += $info['num'];
+			# 验证库存
+			Dever::load('shop/lib/info')->checkTotal($where['num'], $where['goods_id'], $this->shop_id, $where['sku_id'], 2);
+			$where['where_id'] = $info['id'];
+			$state = Dever::db('shop/cart')->update($where);
+		}
+
+		return $this->getCart();
+	}
+
+	# 清空购物车
+	public function dropCart()
+	{
+		$where['uid'] = $this->uid;
+		$where['shop_id'] = $this->shop_id;
+
+		$state = Dever::db('shop/cart')->delete($where);
+
+		return $this->alert($state);
+	}
+
+	# 更新购物车数量
+	public function upCart()
+	{
+		$where['uid'] = $this->uid;
+		$where['shop_id'] = $this->shop_id;
+		$where['id'] = Dever::input('cart_id');
+
+		$status = Dever::input('status', 1);
+		$type = Dever::input('type', 1);
+		$num = Dever::input('num');
+
+		$info = Dever::db('shop/cart')->find($where);
+
+		$state = false;
+
+		if ($info) {
+			if ($type == 1) {
+				$num = $info['num'] + $num;
+			} else {
+				$num = $info['num'] - $num;
+			}
+			$where = array();
+			$where['where_id'] = $info['id'];
+			if ($num <= 0) {
+				$state = Dever::db('shop/cart')->delete($info['id']);
+			} else {
+				$where['status'] = $status;
+				$where['num'] = $num;
+				
+				# 验证库存
+				$total = Dever::load('shop/lib/info')->checkTotal($num, $info['goods_id'], $this->shop_id, $info['sku_id']);
+
+				if ($where['num'] > $total) {
+					# 库存不足
+					$where['num'] = $total;
+					$state = Dever::db('shop/cart')->update($where); 
+					return array('cart' => 2, 'data' => $total);
+				}
+				$state = Dever::db('shop/cart')->update($where); 
+			}
+		}
+
+		return array('cart' => 1, 'data' => $this->getCart());
+	}
+
+	# 确认订单页面
+	public function confirm()
+	{
+		$this->data['user'] = $this->user;
+		$this->goods();
+		$this->coupon($this->data['price'], $this->data['method']);
+
+		return $this->data;
+	}
+
+	# 优惠券
+	public function coupon($price, $method, $type = 1)
+	{
+		$user_coupon_id = Dever::input('user_coupon_id');
+
+		$this->data['user_coupon_id'] = 0;
+		$this->data['coupon_id'] = 0;
+		$this->data['coupon_cash'] = 0;
+
+		if ($type == 1) {
+			if ($price <= 0) {
+				Dever::alert('付款价格错误');
+			}
+			# 查找符合要求的优惠券
+			$coupon = Dever::db('shop/user_coupon')->getAll(array('uid' => $this->uid, 'city' => $this->shop['city'], 'status' => 1, 'edate' => time()));
+
+			if ($coupon) {
+				foreach ($coupon as $k => $v) {
+					if ($v['shop_id'] != $this->shop_id) {
+						# 查找该券是否符合当前店铺
+						if ($this->shop['coupon_city'] == 2) {
+							continue;
+						}
+					}
+					$coupon_info = Dever::db('goods/coupon')->find($v['coupon_id']);
+					if ($coupon_info && ($coupon_info['method'] == $method || $coupon_info['method'] == 3)) {
+						$kou = false;
+						if ($coupon_info['type'] == 1) {
+							# 满减券
+							if ($price >= $coupon_info['total_cash']) {
+								$kou = true;
+							}
+						} else {
+							$kou = true;
+						}
+
+						if ($kou) {
+							$coupon_info['user_coupon_id'] = $v['id'];
+							$coupon_info['uid'] = $v['uid'];
+							$coupon_info['shop_id'] = $v['shop_id'];
+							$coupon_info['edate'] = date('Y-m-d', $v['edate']);
+							$this->data['coupon'][] = $coupon_info;
+
+							if (!$user_coupon_id && $this->data['coupon_cash'] <= $coupon_info['cash']) {
+								$this->data['user_coupon_id'] = $v['id'];
+								$this->data['coupon_id'] = $coupon_info['id'];
+								$this->data['coupon_cash'] = $coupon_info['cash'];
+							}
+						}
+					}
+				}
+			}
+		}
+
+		if ($user_coupon_id) {
+			if ($price <= 0) {
+				Dever::alert('付款价格错误');
+			}
+			$coupon = Dever::db('shop/user_coupon')->find(array('uid' => $this->uid, 'id' => $user_coupon_id, 'status' => 1));
+			if (!$coupon) {
+				Dever::alert('优惠券不可用');
+			}
+			if (time() > $coupon['edate']) {
+				Dever::db('shop/user_coupon')->update(array('where_id' => $user_coupon_id, 'status' => 3));
+				Dever::alert('优惠券已过期');
+			}
+
+			if ($coupon['shop_id'] != $this->shop_id) {
+				if ($this->shop['coupon_city'] == 2) {
+					Dever::alert('优惠券不可用');
+				} else {
+					$coupon_info = Dever::db('shop/coupon')->find(array('shop_id' => $coupon['shop_id'], 'coupon_id' => $coupon['coupon_id'], 'city' => $coupon['city']));
+					if (!$coupon_info) {
+						Dever::alert('优惠券不可用');
+					}
+				}
+			}
+
+			$goods_coupon = Dever::db('goods/coupon')->find($coupon['coupon_id']);
+			if ($goods_coupon['type'] == 2 && $this->data['price'] < $goods_coupon['total_cash']) {
+				Dever::alert('优惠券不可用');
+			}
+			if ($goods_coupon['method'] != $method && $goods_coupon['method'] != 3) {
+				Dever::alert('优惠券不可用');
+			}
+
+			$this->data['user_coupon_id'] = $user_coupon_id;
+			$this->data['coupon_id'] = $goods_coupon['id'];
+			$this->data['coupon_cash'] = $goods_coupon['cash'];
+		}
+
+		if (isset($this->data['coupon_cash']) && $this->data['coupon_cash'] > 0) {
+			$this->data['price'] -= $this->data['coupon_cash'];
+			if ($this->data['price'] < 0) {
+				$this->data['price'] = 0;
+			}
+		}
+	}
+
+	# 得到商品和总价
+	private function goods()
+	{
+		# 1自提,2配送
+		$this->data['method'] = Dever::input('method', 1);
+		$this->data['pay_method'] = Dever::input('pay_method');
+		$card = Dever::input('card');
+		$pwd = Dever::input('pwd');
+
+		if ($this->data['pay_method'] == 3 && $card && $pwd) {
+			$this->data['card'] = Dever::db('goods/card_code')->find(array('card' => $card, 'pwd' => $pwd, 'status' => 1));
+			if (!$this->data['card']) {
+				Dever::alert('卡号/密码错误');
+			}
+			if (time() > $this->data['card']['edate']) {
+				Dever::alert('礼品卡已失效');
+			}
+			$card_info = Dever::db('goods/card')->find($this->data['card']['card_id']);
+			if (!$card_info) {
+				Dever::alert('卡号/密码错误');
+			}
+			$goods = Dever::array_decode($card_info['goods']);
+
+			$goods_id = array();
+			$num = array();
+			$sku_id = array();
+			foreach ($goods as $k => $v) {
+				$goods_id[] = $v['goods_id'];
+				$num[] = $v['num'];
+				$sku_id[] = -1;
+			}
+		} else {
+			$goods_id = Dever::input('goods_id');
+			if (!$goods_id) {
+				Dever::alert('请传入商品');
+			}
+			$goods_id = explode(',', $goods_id);
+
+			$sku_id = Dever::input('price_id');
+			if ($sku_id) {
+				$sku_id = explode(',', $sku_id);
+			}
+			
+			$num = Dever::input('num');
+			$num = Dever::input('num');
+			if (!$num) {
+				Dever::alert('请传入商品数量');
+			}
+			$num = explode(',', $num);
+		}
+
+		$this->data['price'] = 0;
+		$this->data['num'] = 0;
+		$this->data['name'] = array();
+		$count = count($goods_id);
+		# 计算总价格
+		foreach ($goods_id as $k => $v) {
+			$s = isset($sku_id[$k]) ? $sku_id[$k] : -1;
+			$n = isset($num[$k]) ? $num[$k] : 1;
+			$this->data['list'][$k] = Dever::load('goods/lib/info')->getPayInfo($v, $s, $n);
+			$this->data['list'][$k]['num'] = $n;
+
+			# 2是库存不足
+			$this->data['list'][$k]['ku_state'] = 1;
+
+			# 验证是否有货
+			$total = Dever::load('shop/lib/info')->checkTotal($n, $v, $this->shop_id, $s);
+
+			if ($total <= 0) {
+				$this->data['list'][$k]['ku_state'] = 2;
+				$this->data['list'][$k]['buy_num'] = 0;
+			}
+
+			if ($this->data['list'][$k]['ku_state'] == 1) {
+				$this->data['list'][$k]['buy_num'] = $n;
+				$this->data['num'] += $n;
+				$this->data['price'] += $this->data['list'][$k]['price'] * $n;
+				if ($count > 1) {
+					$this->data['name'][] = $this->data['list'][$k]['name'];
+				} else {
+					$this->data['name'][] = $this->data['list'][$k]['name'];
+				}
+			}
+		}
+	}
+
+	# 开始下单
+	public function pay()
+	{
+		$refer = Dever::input('refer');
+		$cart = Dever::input('cart', 1);
+		$parent_uid = Dever::input('parent_uid');
+		$address_id = Dever::input('address_id');
+		$invoice_id = Dever::input('invoice_id');
+		
+		$info = Dever::input('info');
+
+		$this->goods();
+		$this->coupon($this->data['price'], $this->data['method'], 2);
+
+		if ($this->data['pay_method'] > 1) {
+			$cart = 2;
+		}
+
+		if (!$this->data['coupon_id'] && $this->data['price'] <= 0) {
+			Dever::alert('已售空');
+		}
+
+		if ($this->data['method'] == 2 && !$address_id) {
+			Dever::alert('收货地址不能为空');
+		}
+
+		if (!isset($this->data['card'])) {
+			$this->data['card'] = false;
+		}
+
+		$pay = Dever::load('shop/lib/sell')->action($this->data['method'], $this->data['pay_method'], $this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['price'], $address_id, $invoice_id, $info, $this->data['card'], $this->data['user_coupon_id'], $cart, $refer);
+		return $pay;
+	}
+
+	# 再次付款
+	public function r_pay()
+	{
+		$refer = Dever::input('refer');
+		$order_id = Dever::input('order_id');
+
+		$pay = Dever::load('shop/lib/sell')->raction($order_id, $refer);
+
+		return $pay;
+	}
 }

+ 243 - 368
app/shop/src/My.php

@@ -7,372 +7,247 @@ use Main\Lib\Core;
 
 class My extends Core
 {
-    public function __construct()
-    {
-        parent::__construct();
-        $this->checkLogin();
-    }
-
-    public function getInfo()
-    {
-        $this->data['user'] = $this->user;
-
-        # 获取拥有的优惠券数量
-        $this->data['coupon_num'] = Dever::db('shop/user_coupon')->total(array('uid' => $this->uid));
-
-        $this->data['card_num'] = Dever::db('goods/card_code')->total(array('uid' => $this->uid));
-
-        $this->data['score'] = Dever::load('score/lib/core')->getUserScore($this->uid);
-
-        $this->data['msg'] = Dever::load('message/lib/data')->num($this->uid);
-
-        return $this->data;
-    }
-
-    # 我的优惠券列表
-    public function coupon()
-    {
-        $this->data = Dever::db('shop/user_coupon')->getAllPage(array('uid' => $this->uid));
-
-        if ($this->data) {
-            $time = time();
-            foreach ($this->data as $k => $v) {
-                if ($time > $v['edate']) {
-                    $this->data[$k]['status'] = 3;
-                }
-                $this->data[$k]['edate'] = date('Y-m-d', $v['edate']);
-                $this->data[$k]['info'] = Dever::db('goods/coupon')->find($v['coupon_id']);
-                $this->data[$k]['shop'] = array();
-                $coupon = Dever::db('shop/coupon')->select(array('coupon_id' => $v['coupon_id'], 'city' => $v['city']));
-
-                foreach ($coupon as $k1 => $v1) {
-                    $shop = Dever::db('shop/info')->getOne(array('id' => $v1['shop_id'], 'city' => $v['city'], 'coupon_city' => 1));
-                    if ($shop) {
-                        $this->data[$k]['shop'][] = $shop;
-
-                        if ($k1 > 0) {
-                            $city = Dever::db('area/city')->find($v['city']);
-                            $this->data[$k]['shop_name'] = $city['name'] . '多店通用';
-                        } else {
-                            $this->data[$k]['shop_name'] = $shop['name'];
-                        }
-                    }
-                }
-
-                if (!$this->data[$k]['shop']) {
-                    $shop = Dever::db('shop/info')->getOne($v['shop_id']);
-                    $this->data[$k]['shop'][] = $shop;
-                    $this->data[$k]['shop_name'] = $shop['name'];
-                }
-            }
-        }
-
-        return $this->data;
-    }
-
-    # 我的礼品卡列表
-    public function card()
-    {
-        $this->data = Dever::db('goods/card_code')->page(array('uid' => $this->uid));
-
-        if ($this->data) {
-            $status = Dever::db('goods/card_code')->config['status'];
-            $time = time();
-            foreach ($this->data as $k => $v) {
-
-                if ($v['status'] == 1 && $time > $v['edate']) {
-                    $v['status'] = 4;
-                    Dever::db('goods/card_code')->update(array('where_id' => $v['id'], 'status' => 4));
-                }
-                $this->data[$k]['status_name'] = $status[$v['status']];
-                $this->data[$k]['edate'] = date('Y-m-d', $v['edate']);
-                $this->data[$k]['goods'] = array();
-                $info = Dever::db('goods/card')->find($v['card_id']);
-                $goods = Dever::array_decode($info['goods']);
-                foreach ($goods as $k1 => $v1) {
-                    $this->data[$k]['goods'][$k1] = Dever::db('goods/info')->find($v1['goods_id']);
-                    $this->data[$k]['goods'][$k1]['num'] = $v1['num'];
-                }
-
-                if (($v['status'] == 2 || $v['status'] == 3) && $v['order_id'] > 0) {
-                    # 查找订单
-                    $order = Dever::db('shop/sell_order')->find($v['order_id']);
-                    $this->data[$k]['order_num'] = $order['order_num'];
-                } else {
-                    $this->data[$k]['order_num'] = '';
-                }
-            }
-        }
-
-        return $this->data;
-    }
-
-    # 兑换礼品卡
-    public function dh_card()
-    {
-        $where['card'] = Dever::input('card');
-        $where['pwd'] = Dever::input('pwd');
-        $info = Dever::db('goods/card_code')->find($where);
-
-        if ($info && $info['status'] == 1) {
-            # 可以兑换
-        } else {
-            return "该礼品卡过有效期\r\n无法兑换";
-        }
-    }
-
-    # 我的订单列表
-    public function order()
-    {
-        $this->data = Dever::db('shop/sell_order')->getAll(array('uid' => $this->uid));
-
-        if ($this->data) {
-            $this->config = Dever::db('shop/sell_order')->config;
-            foreach ($this->data as $k => $v) {
-                $this->data[$k] = Dever::load('shop/lib/order')->order_info($v);
-            }
-        }
-
-        return $this->data;
-    }
-
-    # 查看订单详情
-    public function order_view()
-    {
-        $id = Dever::input('order_id');
-
-        $this->data = Dever::db('shop/sell_order')->find(array('uid' => $this->uid, 'id' => $id));
-        if (!$this->data) {
-            Dever::alert('订单不存在');
-        }
-
-        $this->config = Dever::db('shop/sell_order')->config;
-        $this->data = Dever::load('shop/lib/order')->order_info($this->data, 2);
-
-        return $this->data;
-    }
-
-    # 获取订单详细信息
-    public function order_info($info, $type = 1)
-    {
-        if ($info['status'] == 1) {
-            # 15分钟内支付,900秒
-            $m = 9000;
-            # 支付倒计时
-            $info['time'] = time() - $info['cdate'];
-            if ($info['time'] >= $m) {
-                # 已过期,自动取消
-                $info['time'] = -1;
-                Dever::db('shop/sell_order')->update(array('where_id' => $info['id'], 'status' => 11));
-                $info['status'] = 11;
-            } else {
-                $info['time'] = $m - $info['time'];
-            }
-        }
-
-        $info['status_name'] = $this->config['status'][$info['status']];
-        $info['method_name'] = $this->config['method'][$info['method']];
-        $info['pay_method_name'] = $this->config['pay_method'][$info['pay_method']];
-
-        if ($info['status'] == 2) {
-            $info['status_name'] = '支付成功';
-        }
-        if ($info['status'] == 3) {
-            if ($info['method'] == 1) {
-                $info['status_name'] = '已配货';
-            } else {
-                $info['status_name'] = '配送中';
-            }
-        }
-
-        if ($info['method'] == 2) {
-            $info['ps_info'] = Dever::db('shop/sell_order_ps')->find(array('order_id' => $info['id']));
-            if ($info['ps_info']) {
-                $info['ps_info']['service_name'] = '商家自送';
-                if ($info['ps_info']['service_id'] > 0) {
-                    //暂时还没有
-                }
-            }
-        }
-
-        $info['goods'] = Dever::db('shop/sell_order_goods')->select(array('order_id' => $info['id']));
-        $info['shop'] = Dever::db('shop/info')->getOne($info['shop_id']);
-        $info['cdate'] = date('Y-m-d H:i', $info['cdate']);
-
-        if ($type == 2) {
-            foreach ($info['goods'] as $k => $v) {
-                $info['goods'][$k]['info'] = Dever::load('goods/lib/info')->getPayInfo($v['goods_id'], $v['sku_id']);
-            }
-            if ($info['address_id']) {
-                $info['address'] = Dever::db('passport/address')->find($info['address_id']);
-            }
-
-            if ($info['invoice_id']) {
-                $info['invoice'] = Dever::db('passport/invoice')->find($info['invoice_id']);
-            }
-
-            if ($info['user_coupon_id']) {
-                $coupon = Dever::db('shop/user_coupon')->find($info['user_coupon_id']);
-                if ($coupon) {
-                    $info['coupon'] = Dever::db('goods/coupon')->find($coupon['coupon_id']);
-                }
-            }
-        } else {
-            foreach ($info['goods'] as $k => $v) {
-                $goods = Dever::db('goods/info')->one($v['goods_id']);
-                $info['goods'][$k]['name'] = $goods['name'];
-                $info['goods'][$k]['cover'] = $goods['cover'];
-            }
-        }
-
-        return $info;
-    }
-
-    # 取消订单
-    public function order_cancel()
-    {
-        $id = Dever::input('order_id');
-
-        $this->data = Dever::db('shop/sell_order')->find(array('uid' => $this->uid, 'id' => $id));
-        if (!$this->data) {
-            Dever::alert('订单不存在');
-        }
-        if ($this->data['status'] == 1) {
-            $state = Dever::db('shop/sell_order')->update(array('where_id' => $id, 'status' => 5));
-            if ($state) {
-
-            }
-
-            return 'ok';
-        } else {
-            Dever::alert('当前订单状态不允许取消');
-        }
-    }
-
-    # 退款退货
-    public function order_tui()
-    {
-        $id = Dever::input('order_id');
-
-        $this->data = Dever::db('shop/sell_order')->find(array('uid' => $this->uid, 'id' => $id));
-        if (!$this->data) {
-            Dever::alert('订单不存在');
-        }
-        if ($this->data['status'] == 2) {
-            $state = Dever::db('shop/sell_order')->update(array('where_id' => $id, 'status' => 6));
-            if ($state) {
-                $shop = Dever::db('shop/info')->one($this->data['shop_id']);
-                $msg_param['type'] = 1;//消息类型1是订单消息
-                $msg_param['id'] = $this->data['id'];
-                $msg_param['name'] = $shop['name'];
-                $msg_param = Dever::json_encode($msg_param);
-                $msg = '您有一笔订单已退款,退款将在3个工作日内返回原支付账户';
-                Dever::load('message/lib/data')->push(-1, $this->data['uid'], '退款成功通知', $msg, 1, 1, false, $msg_param);
-            }
-
-            # 退款到原支付账户
-            return 'ok';
-        } else {
-            Dever::alert('当前订单状态不允许退货退款');
-        }
-    }
-
-    # 我的消息列表
-    public function msg()
-    {
-        $data = Dever::load('message/lib/data')->read($this->uid, false, true);
-
-        if ($data) {
-            foreach ($data as $k => $v) {
-                $data[$k]['cdate_string'] = Dever::ddate($v['cdate']);
-                if ($v['param']) {
-                    $data[$k]['param'] = Dever::json_decode($v['param']);
-                }
-            }
-        }
-        return $data;
-    }
-
-    # 删除消息
-    public function msg_delete()
-    {
-        $id = Dever::input('id');
-
-        Dever::db('message/inbox')->delete(array('id' => $id, 'uid' => $this->uid));
-
-        return $this->msg();
-    }
-
-    # 查看我的消息 废弃
-    public function view_msg()
-    {
-        $id = Dever::input('id');
-        $data = Dever::load('message/lib/data')->view($this->uid, $id);
-
-        if ($data) {
-            $data['cdate_string'] = Dever::ddate($data['cdate']);
-            $type = Dever::db('message/type')->one($data['type']);
-            $data['type_name'] = $type['name'];
-        }
-
-        return $data;
-    }
-
-    # 我的地址列表
-    public function address()
-    {
-        return Dever::load('passport/address')->getAddress($this->uid);
-    }
-
-    # 获取单个地址信息
-    public function getAddress()
-    {
-        $id = Dever::input('id');
-        return Dever::load('passport/address')->getOne($this->uid, $id);
-    }
-
-    # 删除单个地址信息
-    public function delAddress()
-    {
-        $id = Dever::input('id');
-        return Dever::load('passport/address')->del($this->uid, $id, 2);
-    }
-
-    # 我的发票列表
-    public function invoice()
-    {
-        return Dever::load('passport/invoice')->get($this->uid);
-    }
-
-    # 获取单个发票信息
-    public function getInvoice()
-    {
-        $id = Dever::input('id');
-        return Dever::load('passport/invoice')->getOne($this->uid, $id);
-    }
-
-    # 删除单个发票信息
-    public function delInvoice()
-    {
-        $id = Dever::input('id');
-        return Dever::load('passport/invoice')->del($this->uid, $id, 2);
-    }
-
-    # 提交反馈
-    public function feedback()
-    {
-        $data['uid'] = $this->uid;
-        $data['shop_id'] = Dever::input('shop_id');
-        $data['mobile'] = Dever::input('mobile');
-        $data['truename'] = Dever::input('truename');
-        $data['content'] = Dever::input('content');
-
-        return Dever::db('shop/feedback')->insert($data);
-    }
-
-    # 领取优惠券
-    public function take_coupon()
-    {
-        
-    }
+	public function __construct()
+	{
+		parent::__construct();
+		$this->checkLogin();
+	}
+
+	public function getInfo()
+	{
+		$this->data['user'] = $this->user;
+
+		# 获取拥有的优惠券数量
+		$this->data['coupon_num'] = Dever::db('shop/user_coupon')->total(array('uid' => $this->uid));
+
+		$this->data['card_num'] = Dever::db('goods/card_code')->total(array('uid' => $this->uid));
+
+		$this->data['score'] = Dever::load('score/lib/core')->getUserScore($this->uid);
+
+		$this->data['msg'] = Dever::load('message/lib/data')->num($this->uid);
+
+		return $this->data;
+	}
+
+	# 我的优惠券列表
+	public function coupon()
+	{
+		$this->data = Dever::db('shop/user_coupon')->getAllPage(array('uid' => $this->uid));
+
+		if ($this->data) {
+			$time = time();
+			foreach ($this->data as $k => $v) {
+				if ($time > $v['edate']) {
+					$this->data[$k]['status'] = 3;
+				}
+				$this->data[$k]['edate'] = date('Y-m-d', $v['edate']);
+				$this->data[$k]['info'] = Dever::db('goods/coupon')->find($v['coupon_id']);
+				$this->data[$k]['shop'] = array();
+				$coupon = Dever::db('shop/coupon')->select(array('coupon_id' => $v['coupon_id'], 'city' => $v['city']));
+
+				foreach ($coupon as $k1 => $v1) {
+					$shop = Dever::db('shop/info')->getOne(array('id' => $v1['shop_id'], 'city' => $v['city'], 'coupon_city' => 1));
+					if ($shop) {
+						$this->data[$k]['shop'][] = $shop;
+
+						if ($k1 > 0) {
+							$city = Dever::db('area/city')->find($v['city']);
+							$this->data[$k]['shop_name'] = $city['name'] . '多店通用';
+						} else {
+							$this->data[$k]['shop_name'] = $shop['name'];
+						}
+					}
+				}
+
+				if (!$this->data[$k]['shop']) {
+					$shop = Dever::db('shop/info')->getOne($v['shop_id']);
+					$this->data[$k]['shop'][] = $shop;
+					$this->data[$k]['shop_name'] = $shop['name'];
+				}
+			}
+		}
+
+		return $this->data;
+	}
+
+	# 我的礼品卡列表
+	public function card()
+	{
+		$this->data = Dever::db('goods/card_code')->page(array('uid' => $this->uid));
+
+		if ($this->data) {
+			$status = Dever::db('goods/card_code')->config['status'];
+			$time = time();
+			foreach ($this->data as $k => $v) {
+
+				if ($v['status'] == 1 && $time > $v['edate']) {
+					$v['status'] = 4;
+					Dever::db('goods/card_code')->update(array('where_id' => $v['id'], 'status' => 4));
+				}
+				$this->data[$k]['status_name'] = $status[$v['status']];
+				$this->data[$k]['edate'] = date('Y-m-d', $v['edate']);
+				$this->data[$k]['goods'] = array();
+				$info = Dever::db('goods/card')->find($v['card_id']);
+				$goods = Dever::array_decode($info['goods']);
+				foreach ($goods as $k1 => $v1) {
+					$this->data[$k]['goods'][$k1] = Dever::db('goods/info')->find($v1['goods_id']);
+					$this->data[$k]['goods'][$k1]['num'] = $v1['num'];
+				}
+
+				if (($v['status'] == 2 || $v['status'] == 3) && $v['order_id'] > 0) {
+					# 查找订单
+					$order = Dever::db('shop/sell_order')->find($v['order_id']);
+					$this->data[$k]['order_num'] = $order['order_num'];
+				} else {
+					$this->data[$k]['order_num'] = '';
+				}
+			}
+		}
+
+		return $this->data;
+	}
+
+	# 兑换礼品卡
+	public function dh_card()
+	{
+		$where['card'] = Dever::input('card');
+		$where['pwd'] = Dever::input('pwd');
+		$info = Dever::db('goods/card_code')->find($where);
+
+		if ($info && $info['status'] == 1) {
+			# 可以兑换
+		} else {
+			return "该礼品卡过有效期\r\n无法兑换";
+		}
+	}
+
+	# 我的订单列表
+	public function order()
+	{
+		return Dever::load('shop/lib/buyorder')->set(1, 1)->getList($this->uid);
+	}
+
+	# 查看订单详情
+	public function order_view()
+	{
+		$id = Dever::input('order_id');
+
+		return Dever::load('shop/lib/buyorder')->set(1, 2)->getView($this->uid, $id);
+	}
+
+	# 取消订单
+	public function order_cancel()
+	{
+		$order_id = Dever::input('order_id');
+
+        return Dever::load('shop/lib/buyorder')->set(1, 2)->cancel($this->uid, $order_id);
+	}
+
+	# 用户退款
+	public function order_tui()
+	{
+		$order_id = Dever::input('order_id');
+        $status = Dever::input('status');
+
+        return Dever::load('shop/lib/buyorder')->set(1, 2)->tui($this->uid, $order_id, $status);
+	}
+
+	# 我的消息列表
+	public function msg()
+	{
+		$data = Dever::load('message/lib/data')->read($this->uid, false, true);
+
+		if ($data) {
+			foreach ($data as $k => $v) {
+				$data[$k]['cdate_string'] = Dever::ddate($v['cdate']);
+				if ($v['param']) {
+					$data[$k]['param'] = Dever::json_decode($v['param']);
+				}
+			}
+		}
+		return $data;
+	}
+
+	# 删除消息
+	public function msg_delete()
+	{
+		$id = Dever::input('id');
+
+		Dever::db('message/inbox')->delete(array('id' => $id, 'uid' => $this->uid));
+
+		return $this->msg();
+	}
+
+	# 查看我的消息 废弃
+	public function view_msg()
+	{
+		$id = Dever::input('id');
+		$data = Dever::load('message/lib/data')->view($this->uid, $id);
+
+		if ($data) {
+			$data['cdate_string'] = Dever::ddate($data['cdate']);
+			$type = Dever::db('message/type')->one($data['type']);
+			$data['type_name'] = $type['name'];
+		}
+
+		return $data;
+	}
+
+	# 我的地址列表
+	public function address()
+	{
+		return Dever::load('passport/address')->getAddress($this->uid);
+	}
+
+	# 获取单个地址信息
+	public function getAddress()
+	{
+		$id = Dever::input('id');
+		return Dever::load('passport/address')->getOne($this->uid, $id);
+	}
+
+	# 删除单个地址信息
+	public function delAddress()
+	{
+		$id = Dever::input('id');
+		return Dever::load('passport/address')->del($this->uid, $id, 2);
+	}
+
+	# 我的发票列表
+	public function invoice()
+	{
+		return Dever::load('passport/invoice')->get($this->uid);
+	}
+
+	# 获取单个发票信息
+	public function getInvoice()
+	{
+		$id = Dever::input('id');
+		return Dever::load('passport/invoice')->getOne($this->uid, $id);
+	}
+
+	# 删除单个发票信息
+	public function delInvoice()
+	{
+		$id = Dever::input('id');
+		return Dever::load('passport/invoice')->del($this->uid, $id, 2);
+	}
+
+	# 提交反馈
+	public function feedback()
+	{
+		$data['uid'] = $this->uid;
+		$data['shop_id'] = Dever::input('shop_id');
+		$data['mobile'] = Dever::input('mobile');
+		$data['truename'] = Dever::input('truename');
+		$data['content'] = Dever::input('content');
+
+		return Dever::db('shop/feedback')->insert($data);
+	}
+
+	# 领取优惠券
+	public function take_coupon()
+	{
+		
+	}
 }