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

订单支付后,非定制商品减库存

@@ -322,6 +322,19 @@ class Cart extends Api @@ -322,6 +322,19 @@ class Cart extends Api
322 $order->pay_time = time(); // 更新支付时间为当前时间 322 $order->pay_time = time(); // 更新支付时间为当前时间
323 $order->pay_status = '1'; 323 $order->pay_status = '1';
324 $order->save(); 324 $order->save();
  325 + // 非定制商品减库存
  326 + $deductStockData = [];
  327 + foreach($order['goods'] as $v){
  328 + $goods = \app\common\model\Goods::get($v['goods_id'],['spec_rel.spec']);
  329 + if($goods['ismake'] == '0'){
  330 + $goods_sku = $goods->getGoodsSku($v['spec_sku_id']);
  331 + $deductStockData[] = [
  332 + 'id' => $goods_sku['id'],
  333 + 'stock_num' => ['dec', $v['goods_num']]
  334 + ];
  335 + }
  336 + }
  337 + !empty($deductStockData) && (new \app\common\model\GoodsSpec)->isUpdate()->saveAll($deductStockData);
325 return true; 338 return true;
326 } 339 }
327 } 340 }