优化财务流水写入

This commit is contained in:
luofei 2024-01-30 14:10:53 +08:00
parent 38157d4bbb
commit 3626181717

View File

@ -86,23 +86,20 @@ class CommissionDao
if (empty($consumption)) {
return [];
}
$financialRecordRepository = app()->make(FinancialRecordRepository::class);
$financeSn = $financialRecordRepository->getSn();
$users = $this->getUsers($data['user']);
$order = StoreOrder::where('order_id', $data['order_id'])->find();
if (empty($order)) {
return [];
}
$finance = [];
$result = [];
$financeDao = new FinancialDao();
foreach ($users as $k => $user) {
foreach ($users as $user) {
$commission = bcdiv($user['user_profit'], 100, 2);
if ($commission > 0) {
$financeDao->user = $user;
$financeDao->order = $order;
$financialType = $user['type'] == 3 ? 'order_commission' : 'first_order_commission'; // TODO 配送员的佣金类型需要调整
$finance[] = $financeDao->platformOut($commission, $financialType, $financeSn, $k + 1);
$financeDao->platformOut($commission, $financialType);
$result[] = $user;
}
$redPack = bcmul($order['pay_price'], $consumption['config']['red_pack_rate'], 2);
@ -114,9 +111,7 @@ class CommissionDao
}
}
}
if (count($finance) > 0) {
$financialRecordRepository->insertAll($finance);
}
$financeDao->save();
return $result;
}
@ -168,15 +163,12 @@ class CommissionDao
return;
}
$commission = bcmul($refundOrder->order['pay_price'], 0.01, 2);
$financialRecordRepository = app()->make(FinancialRecordRepository::class);
$financeSn = $financialRecordRepository->getSn();
$financeDao = new FinancialDao();
$finance = [];
if ($commission > 0 && $refundOrder->order['order_type'] == 1) {
// 订单为自提且佣金大于0下单的店铺退佣金
$financeDao->user = $refundOrder->order->user;
$financeDao->order = $refundOrder->order;
$finance[] = $financeDao->platformIn($commission, 'first_order_commission_refund', $financeSn, 0);
$financeDao->platformIn($commission, 'first_order_commission_refund');
app()->make(MerchantRepository::class)->subLockMoney($refundOrder->order['mer_id'], 'order', $refundOrder->order['order_id'], $commission);
}
@ -186,14 +178,12 @@ class CommissionDao
->field('user_id uid,user_info nickname')->select()->toArray();
$redPack = bcmul($refundOrder->order['pay_price'], 0.07, 2);
(new StoreConsumptionUserDao())->refundByCommission($refundOrder->order['uid'], $refundOrder->order->order_id, $redPack);
foreach ($financeRecord as $k => $item) {
foreach ($financeRecord as $item) {
$financeDao->user = $item;
$financeDao->order = $refundOrder->order;
$finance[] = $financeDao->platformIn($item['number'], $item['financial_type'] . '_refund', $financeSn, $k + 1);
}
if (count($finance) > 0) {
$financialRecordRepository->insertAll($finance);
$financeDao->platformIn($item['number'], $item['financial_type'] . '_refund');
}
$financeDao->save();
$promotionCode = User::where('uid', $refundOrder['uid'])->value('promotion_code');
if ($promotionCode) {