作者 何书鹏
1 个管道 的构建 通过 耗费 1 秒

测试购物车

@@ -191,12 +191,14 @@ class Cart extends Api @@ -191,12 +191,14 @@ class Cart extends Api
191 }) 191 })
192 */ 192 */
193 public function editGoodsNum($cart_id,$goods_num){ 193 public function editGoodsNum($cart_id,$goods_num){
194 - halt($cart_id);  
195 $cart = $this->model->get($cart_id); 194 $cart = $this->model->get($cart_id);
196 empty($cart) && $this->error(__('购物车信息不存在')); 195 empty($cart) && $this->error(__('购物车信息不存在'));
197 $goods_num < 1 && $this->error(__('商品数量不能小于1')); 196 $goods_num < 1 && $this->error(__('商品数量不能小于1'));
198 - halt($cart['spec']->toArray());  
199 - if($cart['goods']['ismake'] == '0' && $cart['spec']['stock_num'] < $goods_num){ 197 + // 检查库存
  198 + $goods = Goods::get($cart['goods_id'],['spec_rel.spec']);
  199 + $goods_sku = $goods->getGoodsSku($cart['spec_sku_id']);
  200 + halt($goods_sku);
  201 + if($goods['ismake'] == '0' && $goods_sku['stock_num'] < $goods_num){
200 $this->error(__('商品库存不足'.$goods_num.'件')); 202 $this->error(__('商品库存不足'.$goods_num.'件'));
201 } 203 }
202 $cart->goods_num = $goods_num; 204 $cart->goods_num = $goods_num;
@@ -40,15 +40,6 @@ class Cart extends Model @@ -40,15 +40,6 @@ class Cart extends Model
40 } 40 }
41 41
42 /** 42 /**
43 - * 关联商品规格表  
44 - * @return \think\model\relation\BelongsTo  
45 - */  
46 - public function spec()  
47 - {  
48 - return $this->belongsTo('GoodsSpec', 'spec_sku_id', 'spec_sku_id');  
49 - }  
50 -  
51 - /**  
52 * 定制项详情 43 * 定制项详情
53 */ 44 */
54 public function getGoodsStyleTextAttr($value,$data){ 45 public function getGoodsStyleTextAttr($value,$data){
@@ -371,14 +371,15 @@ class Order extends Model @@ -371,14 +371,15 @@ class Order extends Model
371 */ 371 */
372 public function checkGoodsStatusFromOrder($goodsList) 372 public function checkGoodsStatusFromOrder($goodsList)
373 { 373 {
374 - foreach ($goodsList as $goods) { 374 + foreach ($goodsList as $order_goods) {
  375 + $goods = Goods::get($order_goods['goods_id'],['spec_rel.spec']);
375 // 判断商品是否下架 376 // 判断商品是否下架
376 - if ($goods['goods']['issale'] != '1') { 377 + if ($goods['issale'] != '1') {
377 $this->setError('很抱歉,商品 [' . $goods['goods_name'] . '] 已下架'); 378 $this->setError('很抱歉,商品 [' . $goods['goods_name'] . '] 已下架');
378 return false; 379 return false;
379 } 380 }
380 // 付款减库存 381 // 付款减库存
381 - if ($goods['goods']['ismake'] == '0' && $goods['spec']['stock_num'] < 1) { 382 + if ($goods['ismake'] == '0' && $goods->getGoodsSku($order_goods['spec_sku_id'])['stock_num'] < 1) {
382 $this->setError('很抱歉,商品 [' . $goods['goods_name'] . '] 库存不足'); 383 $this->setError('很抱歉,商品 [' . $goods['goods_name'] . '] 库存不足');
383 return false; 384 return false;
384 } 385 }