作者 jinglong
1 个管道 的构建 通过 耗费 0 秒

修改购物车列表库存

@@ -120,13 +120,16 @@ class Cars extends Api @@ -120,13 +120,16 @@ class Cars extends Api
120 ->alias('c') 120 ->alias('c')
121 ->join('goods g','c.g_id = g.id','LEFT') 121 ->join('goods g','c.g_id = g.id','LEFT')
122 ->where(['c.uid'=>$this->uid]) 122 ->where(['c.uid'=>$this->uid])
123 - ->field('c.id,c.g_id goods_id,c.price,c.goods_number,c.style,g.name,g.image,g.stock,g.introduce') 123 + ->field('c.id,c.g_id goods_id,c.price,c.goods_number,c.style,g.name,g.image,g.style g_style,g.stock,g.introduce')
124 ->useSoftDelete('g.deletetime') 124 ->useSoftDelete('g.deletetime')
125 ->select(); 125 ->select();
126 $total_price = 0; 126 $total_price = 0;
127 foreach ($res as &$value){ 127 foreach ($res as &$value){
128 $value['image'] = $this->auth->absolutionUrlOne($value['image']); 128 $value['image'] = $this->auth->absolutionUrlOne($value['image']);
129 $total_price += $value['price'] * $value['goods_number']; 129 $total_price += $value['price'] * $value['goods_number'];
  130 + //查看规格所属索引
  131 + $s_index = array_search($value['style'],Common::salePrice($value['g_style']));
  132 + $value['stock'] = Common::salePrice($value['stock'][$s_index]);
130 if(($value['stock'] <=> $value['goods_number']) == -1){ 133 if(($value['stock'] <=> $value['goods_number']) == -1){
131 //购物车数量大于库存 134 //购物车数量大于库存
132 $value['goods_number'] = $value['stock']; 135 $value['goods_number'] = $value['stock'];