feat: 修改订单逻辑和支付通知逻辑以优化库存和财务流水的处理

This commit is contained in:
mkm 2024-08-22 17:43:51 +08:00
parent 51f5725afa
commit 375d915045
2 changed files with 23 additions and 20 deletions

View File

@ -340,32 +340,17 @@ class OrderLogic extends BaseLogic
$order = StoreOrder::create($_order);
$goods_list = $orderInfo['cart_list'];
$updateData = [];
$updateDataTwo = [];
foreach ($goods_list as $k => $v) {
$goods_list[$k]['oid'] = $order->id;
$goods_list[$k]['uid'] = $uid;
$goods_list[$k]['cart_id'] = implode(',', $cartId);
$goods_list[$k]['delivery_id'] = $params['store_id']; //商家id
$id = StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $params['store_id'])->value('id');
if ($id) {
$updateData[] = [
'id' => $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);
$where = ['is_pay' => 0];
Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1]);
(new StoreBranchProduct())->saveAll($updateData);
(new StoreProduct())->saveAll($updateDataTwo);
Db::commit();
return $order;
} catch (\Exception $e) {

View File

@ -19,6 +19,7 @@ use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow;
use app\common\model\store_finance_flow\StoreFinanceFlow;
use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_log\StoreProductLog;
use app\common\model\system_store\SystemStore;
use app\common\model\user\User;
@ -358,7 +359,6 @@ class PayNotifyLogic extends BaseLogic
$capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $order['pay_price'], '', 1);
self::addStock($order['id']); //微信
return true;
// self::afterPay($order,$extra['transaction_id']);
}
/**
@ -572,7 +572,25 @@ class PayNotifyLogic extends BaseLogic
*/
public static function afterPay($order, $transaction_id = 0)
{
$updateData = [];
$updateDataTwo = [];
StoreOrderCartInfo::where('oid', $order['id'])->update(['is_pay' => 1]);
$arr = StoreOrderCartInfo::where('oid', $order['id'])->field('id,oid,product_id,store_id,cart_num')->select();
foreach ($arr as $k => $v) {
$updateData[] = [
'store_id' => $v['store_id'],
'product_id' => $v['product_id'],
'sales' => ['inc', $v['cart_num']],
'stock' => ['dec', $v['cart_num']],
];
$updateDataTwo[] = [
'id' => $v['product_id'],
'sales' => ['inc', $v['cart_num']]
];
}
(new StoreBranchProduct())->saveAll($updateData);
(new StoreProduct())->saveAll($updateDataTwo);
$financeLogic = new StoreFinanceFlowLogic();
$off_activity = Config::where('name', 'off_activity')->value('value');
$village_uid = 0;