调整扣库存相关逻辑
This commit is contained in:
parent
47ce687f90
commit
ca711b1885
@ -224,24 +224,17 @@ class OrderLogic extends BaseLogic
|
||||
try {
|
||||
$order = StoreOrder::create($_order);
|
||||
$goods_list = $orderInfo['cart_list'];
|
||||
$updateData = [];
|
||||
foreach ($goods_list as $k => $v) {
|
||||
$goods_list[$k]['oid'] = $order->id;
|
||||
$goods_list[$k]['uid'] = $user['id'];
|
||||
$goods_list[$k]['cart_id'] = implode(',', $cartId);
|
||||
$goods_list[$k]['delivery_id'] = $params['store_id']; //商家id
|
||||
$StoreBranchProduct = StoreBranchProduct::where('id',$v['branch_product_id'])->withTrashed()->find();
|
||||
$updateData[] = [
|
||||
'id' => $v['branch_product_id'],
|
||||
'stock' => $StoreBranchProduct['stock']-$v['cart_num'],
|
||||
'sales' => ['inc', $v['cart_num']]
|
||||
];
|
||||
if($StoreBranchProduct['stock']-$v['cart_num']<=0){
|
||||
Db::name('store_product_cate')->where(['cate_id'=>$StoreBranchProduct['cate_id'],'store_id'=>$params['store_id']])->update(['count'=>0]);
|
||||
}
|
||||
}
|
||||
(new StoreOrderCartInfo())->saveAll($goods_list);
|
||||
(new StoreBranchProduct())->saveAll($updateData);
|
||||
$where = ['is_pay' => 0];
|
||||
Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1]);
|
||||
Db::commit();
|
||||
|
@ -9,6 +9,7 @@ use app\common\enum\user\UserShipEnum;
|
||||
use app\common\model\dict\DictType;
|
||||
use app\common\model\finance\PayNotifyLog;
|
||||
use app\common\model\pay\PayNotify;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_finance_flow\StoreFinanceFlow;
|
||||
use app\common\model\store_order\StoreOrder;
|
||||
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||
@ -89,6 +90,7 @@ class PayNotifyLogic extends BaseLogic
|
||||
$capitalFlowDao = new CapitalFlowLogic($user);
|
||||
$capitalFlowDao->userExpense('user_order_balance_pay', 'order', $order['id'], $order['pay_price'],'',0,$order['store_id']);
|
||||
self::dealProductLog($order);
|
||||
self::descStock($order['id']);
|
||||
// self::afterPay($order);
|
||||
// Redis::send('push-platform-print', ['id' => $order['id']], 60);
|
||||
// PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
|
||||
@ -136,6 +138,7 @@ class PayNotifyLogic extends BaseLogic
|
||||
OrderLogic::writeOff($params);
|
||||
}
|
||||
self::dealProductLog($order);
|
||||
self::descStock($order['id']);
|
||||
|
||||
// self::afterPay($order);
|
||||
// Redis::send('push-platform-print', ['id' => $order['id']], 60);
|
||||
@ -175,6 +178,7 @@ class PayNotifyLogic extends BaseLogic
|
||||
}
|
||||
|
||||
self::dealProductLog($order);
|
||||
self::descStock($order['id']);
|
||||
|
||||
// if ($order->pay_type == 9) {
|
||||
// $extra['create_time'] = $order['create_time'];
|
||||
@ -273,6 +277,7 @@ class PayNotifyLogic extends BaseLogic
|
||||
$cashFlowLogic = new CashFlowLogic();
|
||||
$cashFlowLogic->insert($order['store_id'], $order['pay_price']);
|
||||
self::dealProductLog($order);
|
||||
self::descStock($order['id']);
|
||||
// Redis::send('push-platform-print', ['id' => $order['id']]);
|
||||
}
|
||||
|
||||
@ -304,6 +309,7 @@ class PayNotifyLogic extends BaseLogic
|
||||
self::afterPay($order);
|
||||
}
|
||||
self::dealProductLog($order);
|
||||
self::descStock($order['id']);
|
||||
|
||||
// if ($order->pay_type == 9) {
|
||||
// $extra['create_time'] = $order['create_time'];
|
||||
@ -621,4 +627,38 @@ class PayNotifyLogic extends BaseLogic
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 扣库存
|
||||
* @param $oid
|
||||
* @return void
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function descStock($oid)
|
||||
{
|
||||
$updateData = [];
|
||||
$goods_list = StoreOrderCartInfo::where('oid',$oid)->select()->toArray();
|
||||
foreach ($goods_list as $v) {
|
||||
$StoreBranchProduct =StoreBranchProduct::where(
|
||||
[
|
||||
'store_id'=>$v['store_id'],
|
||||
'product_id'=>$v['product_id'],
|
||||
]
|
||||
)->withTrashed()->find();
|
||||
$updateData[] = [
|
||||
'id' => $StoreBranchProduct['id'],
|
||||
'stock' => $StoreBranchProduct['stock']-$v['cart_num'],
|
||||
'sales' => ['inc', $v['cart_num']]
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
(new StoreBranchProduct())->saveAll($updateData);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user