dever 3 years ago
parent
commit
7ba5683cdf

+ 5 - 1
app/goods/database/card_code.php

@@ -171,7 +171,11 @@ return array
     'index' => array
     (
         # 索引名 => 索引id
-        'index' => 'card,pwd',
+        1 => array
+        (
+            'card' => 'card,pwd'
+        ),
+        'version' => 1,
     ),
 
     'request' => array

+ 6 - 1
app/goods/lib/Info.php

@@ -253,7 +253,12 @@ class Info
                 if ($sku) {
                     $info['sku_id'] = $sku['id'];
                     $info['price'] = $sku['price'];
-                    $info['num'] = $sku['num'];
+                    //$info['num'] = $sku['num'];
+                    $info['attr'] = Dever::json_decode($sku['attr']);
+
+                    if ($info['attr']) {
+                        $info['attr'] = Dever::load('attr/api')->getInfoByJson($info['attr']);
+                    }
                 }
             }
 

+ 15 - 1
app/shop/database/coupon.php

@@ -87,6 +87,8 @@ return array
             'desc'      => '发放数量',
             'match'     => 'is_string',
             'update'    => 'text',
+            'list_name' => '当前库存',
+            'list'        => '{num}-{act_num}',
         ),
 
         'act_num'      => array
@@ -128,6 +130,18 @@ return array
 
     'request' => array
     (
-        
+        # 更新售出量
+        'updateNum' => array
+        (
+            'type' => 'update',
+            'where' => array
+            (
+                'id' => 'yes',
+            ),
+            'set' => array
+            (
+                'act_num' => array('yes', '+='),
+            ),
+        ),
     ),
 );

+ 2 - 1
app/shop/database/user_coupon.php

@@ -2,7 +2,8 @@
 $status = array
 (
     1 => '可用',
-    2 => '已过期',
+    2 => '已使用',
+    3 => '已过期',
 );
 return array
 (

+ 34 - 2
app/shop/lib/Sell.php

@@ -9,7 +9,7 @@ use Dever;
 class Sell
 {
     # 发起支付
-	public function action($method, $pay_method, $user, $shop, $name, $num, $goods, $price, $address_id, $invoice_id, $info, $card, $coupon_id, $parent_uid = false, $refer = '')
+	public function action($method, $pay_method, $user, $shop, $name, $num, $goods, $price, $address_id, $invoice_id, $info, $card, $coupon_id, $user_coupon_id, $parent_uid = false, $cart = false, $refer = '')
     {
         if (!$user) {
             Dever::alert('错误的用户信息');
@@ -47,6 +47,9 @@ class Sell
         if ($coupon_id) {
         	$order_data['coupon_id'] = $coupon_id;
         }
+        if ($user_coupon_id) {
+            $order_data['user_coupon_id'] = $user_coupon_id;
+        }
 
         $order_data['order_num'] = $this->getOrderId();
         $order_data['pay_id'] = $order_data['order_num'] . '_p1';
@@ -78,6 +81,13 @@ class Sell
         	$param['pay_cash'] = $price;
         	$param['pay_msg'] = '';
         	$this->success($param);
+
+            if ($cart) {
+                # 来自购物车,要清空一下
+                $this->dropCart($uid, $goods, $shop['id']);
+                # 使用优惠券
+                $this->useCoupon($coupon_id, $user_coupon_id);
+            }
         	return 'ok';
         }
 
@@ -100,10 +110,32 @@ class Sell
         }
 
         $result = Dever::load('pay/api.pay', $param);
-
+        if ($cart) {
+            # 来自购物车,要清空一下
+            $this->dropCart($uid, $goods, $shop['id']);
+            # 使用优惠券
+            $this->useCoupon($coupon_id, $user_coupon_id);
+        }
         return $result;
     }
 
+    public function dropCart($uid, $goods, $shop_id)
+    {
+        $where['uid'] = $uid;
+        $where['shop_id'] = $shop_id;
+        foreach ($goods as $k => $v) {
+            $where['goods_id'] = $v['id'];
+            Dever::db('shop/cart')->delete($where);
+        }
+    }
+
+    public function useCoupon($coupon_id, $user_coupon_id)
+    {
+        if ($user_coupon_id) {
+            Dever::db('shop/user_coupon')->update(array('where_id' => $user_coupon_id, 'status' => 2));
+        }
+    }
+
     # 再次发起支付
     public function raction($id, $refer = '')
     {

+ 4 - 1
app/shop/src/Buy.php

@@ -179,6 +179,7 @@ class Buy extends Core
                             $this->data['coupon'][] = $coupon_info;
 
                             if (!$coupon_id && $this->data['coupon_cash'] <= $coupon_info['cash']) {
+                                $this->data['user_coupon_id'] = $coupon['id'];
                                 $this->data['coupon_id'] = $v['id'];
                                 $this->data['coupon_cash'] = $coupon_info['cash'];
                             }
@@ -217,6 +218,7 @@ class Buy extends Core
                 Dever::alert('优惠券不可用');
             }
 
+            $this->data['user_coupon_id'] = $coupon['id'];
             $this->data['coupon_id'] = $coupon_id;
             $this->data['coupon_cash'] = $goods_coupon['cash'];
         }
@@ -307,6 +309,7 @@ class Buy extends Core
     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');
@@ -324,7 +327,7 @@ class Buy extends Core
             Dever::alert('收货地址不能为空');
         }
 
-        $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['coupon_id'], $parent_uid, $refer);
+        $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['coupon_id'], $this->data['user_coupon_id'], $parent_uid, $cart, $refer);
 
         return $pay;
     }

+ 6 - 0
app/shop/src/My.php

@@ -221,4 +221,10 @@ class My extends Core
 
         return Dever::load('shop/feedback')->insert($data);
     }
+
+    # 领取优惠券
+    public function take_coupon()
+    {
+        
+    }
 }