From 0db7c644ef50b8094136b467a9f33670d39c3b65 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Fri, 24 May 2024 10:25:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E6=88=90=E5=8A=9F=E5=90=8E=20=E9=97=A8?= =?UTF-8?q?=E5=BA=97=E7=BB=93=E7=AE=97=E9=87=91=E9=A2=9D=E9=94=99=E8=AF=AF?= =?UTF-8?q?=EF=BC=8C=E6=9C=AA=E6=88=90=E5=8A=9F=E5=A2=9E=E5=8A=A0=E5=92=8C?= =?UTF-8?q?=E5=87=8F=E5=B0=91=E7=9C=81=E5=85=AC=E5=8F=B8=E9=97=A8=E5=BA=97?= =?UTF-8?q?=E4=BD=A3=E9=87=91=E5=8F=8A=E4=BE=9B=E5=BA=94=E5=95=86=E9=97=A8?= =?UTF-8?q?=E5=BA=97=E4=BD=A3=E9=87=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/order/StoreOrderRepository.php | 145 ++++++++++++------ .../admin/system/merchant/FinancialRecord.php | 8 +- 2 files changed, 101 insertions(+), 52 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index c3ee9c9..84a923e 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -311,48 +311,6 @@ class StoreOrderRepository extends BaseRepository 'user_type' => $storeOrderStatusRepository::U_TYPE_USER, ]; - // 循环商品处理 - foreach ($order->orderProduct as $product) { - $product->append(['product']); - //TODO 成为推广员 - if ($flag && $product['cart_info']['product']['is_gift_bag']) { - app()->make(UserRepository::class)->promoter($order->uid); - $flag = false; - } - - // 判断:是否存在 province_here_id(当前所在地址绑定商户id) - if((int)$product['province_here_id'] > 0 && (float)$product['product']['agent_two_money'] > 0){ - $finance[] = [ - 'order_id' => $order->order_id, - 'order_sn' => $order->order_sn, - 'user_info' => $groupOrder->user->nickname, - 'user_id' => $uid, - 'financial_type' => 'province_mer',// 省公司门店提成 - 'financial_pm' => 1, - 'type' => 1, - 'number' => (float)sprintf("%.2f",(float)$product['product']['agent_two_money'] * (int)$product['product_num']), - 'mer_id' => (int)$product['province_here_id'], - 'financial_record_sn' => $financeSn. ($i++), - 'status' => 0, - ]; - } - // 判断:是否存在 供应商提成 - if((float)$product['product']['supplier_money'] > 0 && (int)$product['product']['supplier_mer_id'] > 0){ - $finance[] = [ - 'order_id' => $order->order_id, - 'order_sn' => $order->order_sn, - 'user_info' => $groupOrder->user->nickname, - 'user_id' => $uid, - 'financial_type' => 'supplier_mer',// 供应商提成 - 'financial_pm' => 1, - 'type' => 1, - 'number' => (float)sprintf("%.2f",(float)$product['product']['supplier_money'] * (int)$product['product_num']), - 'mer_id' => (int)(int)$product['product']['supplier_mer_id'], - 'financial_record_sn' => $financeSn. ($i++), - 'status' => 0, - ]; - } - } $finance[] = [ 'order_id' => $order->order_id, @@ -367,17 +325,104 @@ class StoreOrderRepository extends BaseRepository 'financial_record_sn' => $financeSn . ($i++), 'status' => 1, ]; - - $_payPrice = bcsub($order->pay_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); + // 循环商品处理 + foreach ($order->orderProduct as $product) { + $product->append(['product']); + //TODO 成为推广员 + if ($flag && $product['cart_info']['product']['is_gift_bag']) { + app()->make(UserRepository::class)->promoter($order->uid); + $flag = false; } - if (isset($order->orderProduct[0]['cart_info']['presell_extension_two']) && $order->orderProduct[0]['cart_info']['presell_extension_two'] > 0) { - $_payPrice = bcadd($_payPrice, $order->orderProduct[0]['cart_info']['presell_extension_two'], 2); + + $_payPrice = bcsub($order->pay_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); + } + if (isset($order->orderProduct[0]['cart_info']['presell_extension_two']) && $order->orderProduct[0]['cart_info']['presell_extension_two'] > 0) { + $_payPrice = bcadd($_payPrice, $order->orderProduct[0]['cart_info']['presell_extension_two'], 2); + } + } + + // 判断:是否存在 province_here_id(当前所在地址绑定商户id) + if((int)$product['province_here_id'] > 0 && (float)$product['product']['agent_two_money'] > 0){ + $agentTwoMoney = (float)sprintf("%.2f",(float)$product['product']['agent_two_money'] * (int)$product['product_num']); + // 减少当前门店结算金额 + $finance[] = [ + 'order_id' => $order->order_id, + 'order_sn' => $order->order_sn, + 'user_info' => $groupOrder->user->nickname, + 'user_id' => $uid, + 'financial_type' => 'province_mer_dec',// 省公司门店提成 - 减少省公司门店结算金额 + 'financial_pm' => 0, + 'type' => 1, + 'number' => $agentTwoMoney, + 'mer_id' => $order->mer_id, + 'financial_record_sn' => $financeSn. ($i++), + 'status' => 0, + ]; + $_payPrice = bcsub($_payPrice, $agentTwoMoney, 2); + // 增加 当前所在地址绑定商户增加门店佣金 + $finance[] = [ + 'order_id' => $order->order_id, + 'order_sn' => $order->order_sn, + 'user_info' => $groupOrder->user->nickname, + 'user_id' => $uid, + 'financial_type' => 'province_mer',// 省公司门店提成 - 增加省公司门店结算金额 + 'financial_pm' => 1, + 'type' => 1, + 'number' => $agentTwoMoney, + 'mer_id' => (int)$product['province_here_id'], + 'financial_record_sn' => $financeSn. ($i++), + 'status' => 0, + ]; + Db::name('merchant') + ->where('mer_id', (int)$product['province_here_id']) + ->inc('mer_money', $agentTwoMoney) + ->update(); + } + // 判断:是否存在 供应商提成 + if((float)$product['product']['supplier_money'] > 0 && (int)$product['product']['supplier_mer_id'] > 0){ + $supplierMoney = (float)sprintf("%.2f",(float)$product['product']['supplier_money'] * (int)$product['product_num']); + // 减少当前门店结算金额 + $finance[] = [ + 'order_id' => $order->order_id, + 'order_sn' => $order->order_sn, + 'user_info' => $groupOrder->user->nickname, + 'user_id' => $uid, + 'financial_type' => 'supplier_mer_dec',// 供应商提成 - 减少省公司门店结算金额 + 'financial_pm' => 0, + 'type' => 1, + 'number' => $supplierMoney, + 'mer_id' => $order->mer_id, + 'financial_record_sn' => $financeSn. ($i++), + 'status' => 0, + ]; + $_payPrice = bcsub($_payPrice, $supplierMoney, 2); + // 增加供应商 门店佣金 + $finance[] = [ + 'order_id' => $order->order_id, + 'order_sn' => $order->order_sn, + 'user_info' => $groupOrder->user->nickname, + 'user_id' => $uid, + 'financial_type' => 'supplier_mer',// 供应商提成 - 增加供应商结算金额 + 'financial_pm' => 1, + 'type' => 1, + 'number' => $supplierMoney, + 'mer_id' => (int)$product['product']['supplier_mer_id'], + 'financial_record_sn' => $financeSn. ($i++), + 'status' => 0, + ]; + Db::name('merchant') + ->where('mer_id', (int)$product['product']['supplier_mer_id']) + ->inc('mer_money', $supplierMoney) + ->update(); } } + + + $_order_rate = 0; if ($order['commission_rate'] > 0) { @@ -510,7 +555,7 @@ class StoreOrderRepository extends BaseRepository $storeOrderProfitsharingRepository->insertAll($profitsharing); } - $financialRecordRepository->insertAll($finance); + $financialRecordRepository->insertAll(array_reverse($finance)); $storeOrderStatusRepository->batchCreateLog($orderStatus); if (count($groupOrder['give_coupon_ids']) > 0) $groupOrder['give_coupon_ids'] = app()->make(StoreCouponRepository::class)->getGiveCoupon($groupOrder['give_coupon_ids'])->column('coupon_id'); $groupOrder->save(); diff --git a/app/controller/admin/system/merchant/FinancialRecord.php b/app/controller/admin/system/merchant/FinancialRecord.php index d6dffcc..1557964 100644 --- a/app/controller/admin/system/merchant/FinancialRecord.php +++ b/app/controller/admin/system/merchant/FinancialRecord.php @@ -40,7 +40,9 @@ class FinancialRecord extends BaseController 'order_platform_coupon', 'order_svip_coupon', 'province_mer', - 'supplier_mer' + 'province_mer_dec', + 'supplier_mer', + 'supplier_mer_dec' ]; } else{ @@ -55,7 +57,9 @@ class FinancialRecord extends BaseController 'order_platform_coupon', 'order_svip_coupon', 'province_mer', - 'supplier_mer' + 'province_mer_dec', + 'supplier_mer', + 'supplier_mer_dec' ]; } return app('json')->success($this->repository->getList($where, $page, $limit));