...
|
...
|
@@ -5,6 +5,7 @@ namespace app\api\controller; |
|
|
use app\common\controller\Api;
|
|
|
use app\common\model\Goods;
|
|
|
use app\common\model\GoodsStyle;
|
|
|
use app\common\model\GoodsSpec;
|
|
|
use app\common\controller\Wechat;
|
|
|
use think\Db;
|
|
|
|
...
|
...
|
@@ -371,17 +372,29 @@ class Cart extends Api |
|
|
$order->pay_time = time(); // 更新支付时间为当前时间
|
|
|
$order->pay_status = '1';
|
|
|
$order->save();
|
|
|
// 非定制商品减库存
|
|
|
$deductStockData = [];
|
|
|
// 整理批量更新商品销量
|
|
|
$goodsSave = [];
|
|
|
// 批量更新商品规格:sku销量、库存
|
|
|
$goodsSpecSave = [];
|
|
|
foreach($order['goods'] as $v){
|
|
|
$goodsSave[] = [
|
|
|
'id' => $v['goods_id'],
|
|
|
'sale_num' => ['inc', $v['goods_num']]
|
|
|
];
|
|
|
$specData = [
|
|
|
'id' => $v['spec']['id'],
|
|
|
'sale_num' => ['inc', $v['goods_num']]
|
|
|
];
|
|
|
// 非定制商品减库存
|
|
|
if($v['goods']['ismake'] == '0'){
|
|
|
$deductStockData[] = [
|
|
|
'id' => $v['spec']['id'],
|
|
|
'stock_num' => ['dec', $v['goods_num']]
|
|
|
];
|
|
|
$specData['stock_num'] = ['dec', $v['goods_num']];
|
|
|
}
|
|
|
$goodsSpecSave[] = $specData;
|
|
|
}
|
|
|
!empty($deductStockData) && (new \app\common\model\GoodsSpec)->isUpdate()->saveAll($deductStockData);
|
|
|
// 更新商品总销量
|
|
|
(new Goods)->allowField(true)->isUpdate()->saveAll($goodsSave);
|
|
|
// 更新商品规格库存
|
|
|
(new GoodsSpec)->allowField(true)->isUpdate()->saveAll($goodsSpecSave);
|
|
|
return true;
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|