作者 李忠强

更新

@@ -71,6 +71,10 @@ class Activity extends Api @@ -71,6 +71,10 @@ class Activity extends Api
71 $goods_spec = Db::name('litestore_goods_spec') 71 $goods_spec = Db::name('litestore_goods_spec')
72 ->where('goods_id',$item['goods_id']) 72 ->where('goods_id',$item['goods_id'])
73 ->find(); 73 ->find();
  74 + $item['cart_number'] = Db::name('cart')
  75 + ->where('user_id',$this->auth->id)
  76 + ->where('goods_id',$item['goods_id'])
  77 + ->sum('number');
74 $item['price'] = $goods_spec['goods_price']; 78 $item['price'] = $goods_spec['goods_price'];
75 $item['line_price'] = $goods_spec['line_price']; 79 $item['line_price'] = $goods_spec['line_price'];
76 }); 80 });
@@ -41,10 +41,15 @@ class Cart extends Api @@ -41,10 +41,15 @@ class Cart extends Api
41 'user_id' => $this->auth->id, 41 'user_id' => $this->auth->id,
42 'sku_id' => $sku_id, 42 'sku_id' => $sku_id,
43 'goods_id' => $goods_id, 43 'goods_id' => $goods_id,
44 - 'number' => $number,  
45 ]; 44 ];
46 $model = new \app\api\model\Cart(); 45 $model = new \app\api\model\Cart();
47 - $model->save($data); 46 + $cart = $model->where($data)->find();
  47 + if ($cart){
  48 + $cart->setInc('number',$number);
  49 + }else{
  50 + $data['number'] = $number;
  51 + $model->isUpdate(false)->save($data);
  52 + }
48 $this->success('SUCCESS'); 53 $this->success('SUCCESS');
49 } 54 }
50 55
@@ -17,7 +17,7 @@ use think\Db; @@ -17,7 +17,7 @@ use think\Db;
17 */ 17 */
18 class Classification extends Api 18 class Classification extends Api
19 { 19 {
20 - protected $noNeedLogin = ['*']; 20 + protected $noNeedLogin = ['sort'];
21 protected $noNeedRight = ['*']; 21 protected $noNeedRight = ['*'];
22 22
23 /** 23 /**
@@ -99,6 +99,10 @@ class Classification extends Api @@ -99,6 +99,10 @@ class Classification extends Api
99 $goods_spec = Db::name('litestore_goods_spec') 99 $goods_spec = Db::name('litestore_goods_spec')
100 ->where('goods_id',$item['goods_id']) 100 ->where('goods_id',$item['goods_id'])
101 ->find(); 101 ->find();
  102 + $item['cart_number'] = Db::name('cart')
  103 + ->where('user_id',$this->auth->id)
  104 + ->where('goods_id',$item['goods_id'])
  105 + ->sum('number');
102 $item['price'] = $goods_spec['goods_price']; 106 $item['price'] = $goods_spec['goods_price'];
103 $item['line_price'] = $goods_spec['line_price']; 107 $item['line_price'] = $goods_spec['line_price'];
104 }); 108 });
@@ -110,6 +114,10 @@ class Classification extends Api @@ -110,6 +114,10 @@ class Classification extends Api
110 $goods_spec = Db::name('litestore_goods_spec') 114 $goods_spec = Db::name('litestore_goods_spec')
111 ->where('goods_id',$item['goods_id']) 115 ->where('goods_id',$item['goods_id'])
112 ->find(); 116 ->find();
  117 + $item['cart_number'] = Db::name('cart')
  118 + ->where('user_id',$this->auth->id)
  119 + ->where('goods_id',$item['goods_id'])
  120 + ->sum('number');
113 $item['price'] = $goods_spec['goods_price']; 121 $item['price'] = $goods_spec['goods_price'];
114 $item['line_price'] = $goods_spec['line_price']; 122 $item['line_price'] = $goods_spec['line_price'];
115 }); 123 });