feat: 实现订单创建功能,包括更新商品库存和销量
This commit is contained in:
parent
d9bb85651e
commit
58cf679569
@ -330,19 +330,30 @@ class OrderLogic extends BaseLogic
|
|||||||
try {
|
try {
|
||||||
$order = StoreOrder::create($_order);
|
$order = StoreOrder::create($_order);
|
||||||
$goods_list = $orderInfo['cart_list'];
|
$goods_list = $orderInfo['cart_list'];
|
||||||
|
|
||||||
|
$updateData = [];
|
||||||
|
$updateDataTwo = [];
|
||||||
foreach ($goods_list as $k => $v) {
|
foreach ($goods_list as $k => $v) {
|
||||||
$goods_list[$k]['oid'] = $order->id;
|
$goods_list[$k]['oid'] = $order->id;
|
||||||
$goods_list[$k]['uid'] = $uid;
|
$goods_list[$k]['uid'] = $uid;
|
||||||
$goods_list[$k]['cart_id'] = implode(',', $cartId);
|
$goods_list[$k]['cart_id'] = implode(',', $cartId);
|
||||||
$goods_list[$k]['delivery_id'] = $params['store_id']; //商家id
|
$goods_list[$k]['delivery_id'] = $params['store_id']; //商家id
|
||||||
// $StoreBranchProduct = StoreBranchProduct::where('id', $v['branch_product_id'])->withTrashed()->find();
|
|
||||||
// if ($StoreBranchProduct['stock'] - $v['cart_num'] <= 0) {
|
$updateData[] = [
|
||||||
// Db::name('store_product_cate')->where(['cate_id' => $StoreBranchProduct['cate_id'], 'store_id' => $params['store_id']])->update(['count' => 0]);
|
'id' => $v['branch_product_id'],
|
||||||
// }
|
'sales' => ['inc', $v['cart_num']],
|
||||||
|
'stock' => ['dec', $v['cart_num']],
|
||||||
|
];
|
||||||
|
$updateDataTwo[] = [
|
||||||
|
'id' => $v['product_id'],
|
||||||
|
'sales' => ['inc', $v['cart_num']]
|
||||||
|
];
|
||||||
}
|
}
|
||||||
(new StoreOrderCartInfo())->saveAll($goods_list);
|
(new StoreOrderCartInfo())->saveAll($goods_list);
|
||||||
$where = ['is_pay' => 0];
|
$where = ['is_pay' => 0];
|
||||||
Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1]);
|
Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1]);
|
||||||
|
(new StoreBranchProduct())->saveAll($updateData);
|
||||||
|
(new StoreProduct())->saveAll($updateDataTwo);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return $order;
|
return $order;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user