From cde71f49a72b579b671ca327721b707e5d6bc1e7 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Tue, 27 Feb 2024 18:05:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=AE=A2=E5=8D=95=E4=BD=A3?= =?UTF-8?q?=E9=87=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/system/financial/FinancialDao.php | 22 +++++++ app/common/model/system/merchant/Merchant.php | 6 ++ .../store/order/StoreOrderRepository.php | 64 ++++++++++--------- app/listener/paySuccess.php | 8 +-- 4 files changed, 67 insertions(+), 33 deletions(-) diff --git a/app/common/dao/system/financial/FinancialDao.php b/app/common/dao/system/financial/FinancialDao.php index 17a9ebde..14d889be 100755 --- a/app/common/dao/system/financial/FinancialDao.php +++ b/app/common/dao/system/financial/FinancialDao.php @@ -131,6 +131,28 @@ class FinancialDao extends BaseDao $this->setData($number, $financialType, 1, 1, $merId); } + /** + * 商户入账财务流水 + * @param $number + * @param $financialType + * @param $merId + */ + public function merchantOut($number, $financialType, $merId = '') + { + $this->setData($number, $financialType, 0, 0, $merId); + } + + /** + * 商户入账财务流水 + * @param $number + * @param $financialType + * @param $merId + */ + public function merchantIn($number, $financialType, $merId = '') + { + $this->setData($number, $financialType, 1, 0, $merId); + } + public function setData($number, $financialType, $pm, $type = 2, $merId = '') { if (empty($this->financeSn)) { diff --git a/app/common/model/system/merchant/Merchant.php b/app/common/model/system/merchant/Merchant.php index 8e3b1f47..d11a256c 100755 --- a/app/common/model/system/merchant/Merchant.php +++ b/app/common/model/system/merchant/Merchant.php @@ -24,6 +24,7 @@ use app\common\model\system\config\SystemConfigValue; use app\common\model\system\financial\Financial; use app\common\model\system\GeoStreet; use app\common\model\system\serve\ServeOrder; +use app\common\model\user\User; use app\common\repositories\store\StoreActivityRepository; use think\facade\Db; @@ -316,4 +317,9 @@ class Merchant extends BaseModel return $this->hasOne(GeoStreet::class, 'street_code', 'street_id'); } + public function promoter() + { + return User::where('uid', $this->uid)->value('spread_uid'); + } + } diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 50e76908..255cdb3b 100755 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -22,6 +22,7 @@ use app\common\model\store\order\StoreOrder; use app\common\model\store\order\StoreOrderInterest; use app\common\model\store\order\StoreRefundOrder; use app\common\model\store\product\PurchaseRecord; +use app\common\model\system\merchant\FinancialRecord; use app\common\model\user\User; use app\common\model\system\merchant\Merchant; use app\common\repositories\BaseRepository; @@ -288,7 +289,6 @@ class StoreOrderRepository extends BaseRepository 'user_type' => $storeOrderStatusRepository::U_TYPE_USER, ]; - //TODO 成为推广员 foreach ($order->orderProduct as $product) { if ($flag && $product['cart_info']['product']['is_gift_bag']) { app()->make(UserRepository::class)->promoter($order->uid); @@ -304,36 +304,30 @@ class StoreOrderRepository extends BaseRepository $financeDao->order = $order; $financeDao->user = $groupOrder->user; $financialType = $presell ? 'order_presell' : 'order'; - // 平台订单收入流水账单数据 - $financeDao->platformIn($order->total_price, $financialType); + // 公共收入流水账单数据 + $financeDao->publicIn($order->total_price, $financialType); if ($order->consumption_money > 0) { + // 平台支出优惠金额 $financeDao->platformOut($order->consumption_money, 'platform_consumption'); } - if ($order->source == 103) { - $_payPrice = $order->procure_price; - //市级供应链 - $product_mer_id = Db::name('store_order_product')->where('order_id', $order->order_id)->value('product_mer_id'); - // 平台支付市供应链流水账单数据 - $financeDao->platformOut($_payPrice, 'supply_chain', $product_mer_id); - if ($product_mer_id) { - //市级供应链押金计算 - if ($_payPrice > 0) { - /** @var MerchantRepository $merchantRepo */ - $merchantRepo = app()->make(MerchantRepository::class); - $merchantRepo->merId = $product_mer_id; - $merchantRepo->forceMargin = false; - [$_payCityPrice, $financeDao] = $merchantRepo->deductDeposit($_payPrice, $order, $financeDao); - } - if (isset($_payCityPrice)) { - if (!$is_combine) { - app()->make(MerchantRepository::class)->addLockMoney($product_mer_id, 'order', $order->order_id, $_payCityPrice); - } - } + $_payPrice = bcsub($order->pay_price, bcadd($order['extension_one'], $order['extension_two'], 3), 2); + + if ($order['commission_rate'] > 0) { + $commission_rate = bcdiv((string)$order['commission_rate'],'100',6); + $platformCommission = bcmul($_payPrice, (string)$commission_rate, 2); + // 平台收入手续费 + $financeDao->platformIn($platformCommission, 'platform_commission'); + $promoter = $order->merchant->promoter(); + if (!empty($promoter)) { + $promoterCommission = bcmul($_payPrice, 0.003, 2); + // 平台支出推广费 + $financeDao->platformOut($promoterCommission, 'promoter_commission'); } - } else { - $_payPrice = $order->pay_price; + $_payPrice = bcsub($_payPrice, $platformCommission, 2); } + // 商户收入金额 + $financeDao->merchantIn($_payPrice, 'merchant_order', $order['mer_id']); if ($is_combine) { $profitsharing[] = [ @@ -357,10 +351,6 @@ class StoreOrderRepository extends BaseRepository ], $order->mer_id); //自动打印订单 $this->autoPrinter($order->order_id, $order->mer_id); - if ($order['pay_price'] > 0 && $order['source'] == 103) { - // "惠农供销,谱写数字新篇章"活动首单分润,商户和村、小组合伙人 - $financeDao = (new CommissionDao())->firstOrderCommission($order, $financeDao); - } //判断是否是平台购物卡 $merchantCate = $order->orderProduct[0]->product->merCateId; @@ -744,6 +734,22 @@ class StoreOrderRepository extends BaseRepository // 'number' => $order->extension_two, // ], $order->mer_id); } + + $promoterCommission = FinancialRecord::where('order_id', $order['id']) + ->where('financial_type', 'promoter_commission') + ->column('user_id,number'); + if (!empty($promoterCommission)) { + $userBillRepository->incBill($promoterCommission['user_id'], 'brokerage', 'order_one', [ + 'link_id' => $order['order_id'], + 'status' => 0, + 'title' => '获得推广佣金', + 'number' => $promoterCommission['number'], + 'mark' => $order->merchant['mer_name'] . '成功销售' . floatval($order['pay_price']) . '元,奖励推广佣金' . floatval($promoterCommission['number']), + 'balance' => 0 + ]); + $userRepository = app()->make(UserRepository::class); + $userRepository->incBrokerage($promoterCommission['user_id'], $promoterCommission['number']); + } } /** diff --git a/app/listener/paySuccess.php b/app/listener/paySuccess.php index 810c1023..18d21c6c 100755 --- a/app/listener/paySuccess.php +++ b/app/listener/paySuccess.php @@ -35,10 +35,10 @@ class paySuccess { try { $orderList = $event['groupOrder']['orderList']; - if ($event['groupOrder']['source'] == 103) { - $storeConsumptionUserDao = new StoreConsumptionUserDao(); - $storeConsumptionUserDao->check($event['groupOrder']['uid'], $event['groupOrder']['group_order_id']); - } +// if ($event['groupOrder']['source'] == 103) { +// $storeConsumptionUserDao = new StoreConsumptionUserDao(); +// $storeConsumptionUserDao->check($event['groupOrder']['uid'], $event['groupOrder']['group_order_id']); +// } foreach ($orderList as $k => $order) { // $StoreProcessing->AutomaticallyCreateOrders($order);