From 1c6517ee20ae2c6b85aa2942ff19d382cc884c8a Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Thu, 7 Mar 2024 14:54:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BD=AC=E8=B4=A6=E8=AE=A2?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/order/StoreOrderRepository.php | 2 +- .../store/order/StoreOtherOrderRepository.php | 104 ++++++------------ 2 files changed, 36 insertions(+), 70 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 591bcfb1..8e5644ef 100755 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -346,7 +346,7 @@ class StoreOrderRepository extends BaseRepository $financeDao->order = $order; $financeDao->user = $groupOrder->user; $financialType = $presell ? 'order_presell' : 'order'; - // 公共收入流水账单数据 + // 平台收入流水账单数据 $financeDao->platformIn($order->total_price, $financialType); if ($order->consumption_money > 0) { // 平台支出优惠金额 diff --git a/app/common/repositories/store/order/StoreOtherOrderRepository.php b/app/common/repositories/store/order/StoreOtherOrderRepository.php index cc19b248..42a664ee 100755 --- a/app/common/repositories/store/order/StoreOtherOrderRepository.php +++ b/app/common/repositories/store/order/StoreOtherOrderRepository.php @@ -12,6 +12,7 @@ namespace app\common\repositories\store\order; use app\common\dao\store\order\StoreOrderOtherDao; +use app\common\dao\system\financial\FinancialDao; use app\common\model\store\order\StoreGroupOrderOther; use app\common\model\store\order\StoreOrderInterestOther; use app\common\model\store\order\StoreOrderOther; @@ -171,6 +172,7 @@ class StoreOtherOrderRepository extends BaseRepository //订单记录 $storeOrderStatusRepository = app()->make(StoreOrderStatusOtherRepository::class); $svipDiscount = 0; + $financeDao = new FinancialDao(); foreach ($groupOrder->orderList as $_k => $order) { if($groupOrder->order_extend){ if($order->order_extend){ @@ -205,21 +207,18 @@ class StoreOtherOrderRepository extends BaseRepository 'user_type' => $storeOrderStatusRepository::U_TYPE_USER, ]; - // 商户流水账单数据 - $finance[] = [ - 'order_id' => $order->order_id, - 'order_sn' => $order->order_sn, - 'user_info' => $groupOrder->user->nickname, - 'user_id' => $uid, - 'financial_type' => $presell ? 'order_presell' : 'order', - 'financial_pm' => 1, - 'type' => $presell ? 2 : 1, - 'number' => $order->pay_price, - 'mer_id' => $order->mer_id, - 'financial_record_sn' => $financeSn . ($i++) - ]; + $financeDao->order = $order; + $financeDao->user = $groupOrder->user; + $financialType = $presell ? 'order_presell' : 'order'; + // 平台收入流水账单数据 + $financeDao->platformIn($order->total_price, $financialType); + if ($order->consumption_money > 0) { + // 平台支出优惠金额 + $financeDao->platformOut($order->consumption_money, 'platform_consumption'); + } $_payPrice = bcsub($order->pay_price, bcadd($order['extension_one'], $order['extension_two'], 3), 2); + $orderValidAmount = bcsub($order->total_price, bcadd($order['extension_one'], $order['extension_two'], 3), 2); if ($presell) { if (isset($order->orderProduct[0]['cart_info']['presell_extension_one']) && $order->orderProduct[0]['cart_info']['presell_extension_one'] > 0) { $_payPrice = bcadd($_payPrice, $order->orderProduct[0]['cart_info']['presell_extension_one'], 2); @@ -229,72 +228,39 @@ class StoreOtherOrderRepository extends BaseRepository } } - $_order_rate = 0; + // 平台支出推广费 + $promoter = $order->merchant->promoter(); + $promoterCommission = bcmul($orderValidAmount, 0.003, 2); + if (!empty($promoter) && $promoterCommission > 0) { + $financeDao->platformOut($promoterCommission, 'commission_to_promoter'); + } - //平台手续费 - if ($order['commission_rate'] > 0) { - - $commission_rate = ($order['commission_rate'] / 100); - - $_order_rate = bcmul($_payPrice, $commission_rate, 2); - - $_payPrice = bcsub($_payPrice, $_order_rate, 2); - // 结算各镇 小组佣金 - event('order.paySuccessOrderOther', compact('order', '_order_rate')); + // 平台收入手续费 + $commission_rate = bcdiv((string)$order['commission_rate'],'100',6); + $platformCommission = bcmul($orderValidAmount, (string)$commission_rate, 2); + if ($commission_rate > 0 && $platformCommission > 0) { + $orderValidAmount = bcsub($orderValidAmount, $platformCommission, 2); + if ($promoterCommission > 0 && !empty($promoter)) { + $platformCommission = bcsub($platformCommission, $promoterCommission, 2); + } + $financeDao->platformIn($platformCommission, 'commission_to_platform', $order['mer_id']); } if (!$presell) { - - if ($order['commission_rate'] > 0) { - $finance[] = [ - 'order_id' => $order->order_id, - 'order_sn' => $order->order_sn, - 'user_info' => $groupOrder->user->nickname, - 'user_id' => $uid, - 'financial_type' => 'order_charge', - 'financial_pm' => 0, - 'type' => 1, - 'number' => $_order_rate, - 'mer_id' => $order->mer_id, - 'financial_record_sn' => $financeSn . ($i++) - ]; - } //押金计算 - if ($_payPrice > 0) { + if ($orderValidAmount > 0) { /** @var MerchantRepository $merchantRepo */ $merchantRepo = app()->make(MerchantRepository::class); - $merchantRepo->merId = $order->mer_id; + $merchantRepo->merId = $order['mer_id']; $merchantRepo->forceMargin = false; - [$_payPrice, $finance, $increase] = $merchantRepo->autoMargin($_payPrice, $order, $finance, $financeSn, $i++); + [$orderValidAmount, $financeDao] = $merchantRepo->deductDeposit($orderValidAmount, $order, $financeDao); + } + // 商户收入金额 + $financeDao->platformOut($orderValidAmount, 'merchant_order', $order['mer_id']); + if (!$is_combine) { + app()->make(MerchantRepository::class)->addLockMoney($order->mer_id, 'order', $order->order_id, $orderValidAmount); } - $finance[] = [ - 'order_id' => $order->order_id, - 'order_sn' => $order->order_sn, - 'user_info' => $groupOrder->user->nickname, - 'user_id' => $uid, - 'financial_type' => 'order_true', - 'financial_pm' => 0, - 'type' => 2, - 'number' => $_payPrice, - 'mer_id' => $order->mer_id, - 'financial_record_sn' => $financeSn . ($i++) - ]; - if ($order->platform_coupon_price > 0) { - $finance[] = [ - 'order_id' => $order->order_id, - 'order_sn' => $order->order_sn, - 'user_info' => $groupOrder->user->nickname, - 'user_id' => $uid, - 'financial_type' => $isVipCoupon ? 'order_svip_coupon' : 'order_platform_coupon', - 'financial_pm' => 0, - 'type' => 1, - 'number' => $order->platform_coupon_price, - 'mer_id' => $order->mer_id, - 'financial_record_sn' => $financeSn . ($i++) - ]; - // $_payPrice = bcadd($_payPrice, $order->platform_coupon_price, 2); - } // if (!$is_combine) { // app()->make(MerchantRepository::class)->addLockMoney($order->mer_id, 'order', $order->order_id, $_payPrice); // }