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

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

... ... @@ -322,6 +322,19 @@ class Cart extends Api
$order->pay_time = time(); // 更新支付时间为当前时间
$order->pay_status = '1';
$order->save();
// 非定制商品减库存
$deductStockData = [];
foreach($order['goods'] as $v){
$goods = \app\common\model\Goods::get($v['goods_id'],['spec_rel.spec']);
if($goods['ismake'] == '0'){
$goods_sku = $goods->getGoodsSku($v['spec_sku_id']);
$deductStockData[] = [
'id' => $goods_sku['id'],
'stock_num' => ['dec', $v['goods_num']]
];
}
}
!empty($deductStockData) && (new \app\common\model\GoodsSpec)->isUpdate()->saveAll($deductStockData);
return true;
}
}
\ No newline at end of file
... ...