From b1d6d23f736f6cefa3b3906c50a8a22424214c8b Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 14 Jun 2024 11:50:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BC=9A=E5=91=98?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E8=8E=B7=E5=BE=97=E7=AD=89=E6=9E=9A=E4=B8=BE?= =?UTF-8?q?=E5=80=BC=E5=92=8C=E5=A4=84=E7=90=86VIP=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E7=AD=89=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/enum/OrderEnum.php | 12 +++- app/common/logic/PayNotifyLogic.php | 80 ++++++++++++++-------- app/common/logic/StoreFinanceFlowLogic.php | 14 ++-- 3 files changed, 67 insertions(+), 39 deletions(-) diff --git a/app/common/enum/OrderEnum.php b/app/common/enum/OrderEnum.php index 4c0560214..215162939 100644 --- a/app/common/enum/OrderEnum.php +++ b/app/common/enum/OrderEnum.php @@ -16,9 +16,14 @@ class OrderEnum * @MERCHANT_ORDER_PAY 商户订单支付 * @PLATFORM_ORDER_OBTAINS 平台订单获得 * @SUPPLIER_ORDER_OBTAINS 供应链订单获得 + * @VIP_ORDER_OBTAINS 会员订单获得 + * @VILLAGE_ORDER_OBTAINS 村长获得 + * @BRIGADE_ORDER_OBTAINS 队长获得 + * @OTHER_ORDER_OBTAINS 其他获得 * @PLATFORM_ORDER_PAY 平台订单支付 * @SYSTEM_SET 系统设置 * @OWN_GET 平台收入 + * @ORDER_MARGIN 商户保证金 */ const USER_ORDER_PAY = 1; const MERCHANT_ORDER_OBTAINS = 2; @@ -30,11 +35,12 @@ class OrderEnum const SYSTEM_SET = 8; const CASHIER_ORDER_PAY = 9;//微信条码 const CASHIER_CASH_ORDER_PAY = 10; - const ORDER_MARGIN = 11; - const ORDER_COMMITION = 12; - + const VIP_ORDER_OBTAINS = 12; const CASHIER_ORDER_ALI_PAY = 13;//支付宝条码 + const VILLAGE_ORDER_OBTAINS = 14; + const BRIGADE_ORDER_OBTAINS = 15; + const OTHER_ORDER_OBTAINS = 16; const CASHIER_FACE_PAY = 17;//现金收银 diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index d0b1e159e..f7cfcf2c2 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -12,6 +12,7 @@ use app\common\model\store_finance_flow\StoreFinanceFlow; use app\common\model\store_order\StoreOrder; use app\common\model\system_store\SystemStore; use app\common\model\user\User; +use app\common\model\user\UserAddress; use app\common\model\user\UserRecharge; use app\common\model\user\UserShip; use app\common\service\PushService; @@ -29,8 +30,8 @@ class PayNotifyLogic extends BaseLogic public static function handle($action, $orderSn, $extra = []) { - // Db::startTrans(); - // try { + Db::startTrans(); + try { if ($action != 'cash_pay' && $action != 'balancePay') { $payNotifyLogLogic = new PayNotifyLogLogic(); if ($action == 'refund') { @@ -40,13 +41,13 @@ class PayNotifyLogic extends BaseLogic } } self::$action($orderSn, $extra); - // Db::commit(); + Db::commit(); return true; - // } catch (\Exception $e) { - // Db::rollback(); - // Log::error('支付回调处理失败' . $e->getMessage() . ',lien:' . $e->getLine() . ',file:' . $e->getFile()); - // throw new \Exception($e->getMessage()); - // } + } catch (\Exception $e) { + Db::rollback(); + Log::error('支付回调处理失败' . $e->getMessage() . ',lien:' . $e->getLine() . ',file:' . $e->getFile()); + throw new \Exception($e->getMessage()); + } } /** @@ -80,7 +81,6 @@ class PayNotifyLogic extends BaseLogic self::afterPay($order); Redis::send('push-platform-print', ['id' => $order['id']], 60); PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); - } /** @@ -106,7 +106,7 @@ class PayNotifyLogic extends BaseLogic $extra['transaction_id'] = time(); } $user = User::where('id', $order['uid'])->find(); - if ($order->pay_type == OrderEnum::CASHIER_ORDER_PAY || $order->pay_type == OrderEnum::CASHIER_ORDER_ALI_PAY) {//收银台支付 + if ($order->pay_type == OrderEnum::CASHIER_ORDER_PAY || $order->pay_type == OrderEnum::CASHIER_ORDER_ALI_PAY) { //收银台支付 $order->status = 2; } else { $capitalFlowDao = new CapitalFlowLogic($user); @@ -117,7 +117,7 @@ class PayNotifyLogic extends BaseLogic //活动期间消费 $check = DictType::where('type', 'activities')->find(); - if (isset($check) && $check['status'] == 1 && in_array($order->pay_type,[9,17])==false && $user['user_ship'] == 0) { + if (isset($check) && $check['status'] == 1 && in_array($order->pay_type, [9, 17]) == false && $user['user_ship'] == 0) { self::dealChange($order['uid']); } @@ -172,7 +172,7 @@ class PayNotifyLogic extends BaseLogic //用户的财务add $capitalFlowDao = new CapitalFlowLogic($user); $capitalFlowDao->userIncome('user_balance_recharge', 'user_recharge', $order['id'], $price); - + if ($user->isEmpty()) { return true; } @@ -183,8 +183,8 @@ class PayNotifyLogic extends BaseLogic //更新等级 self::dealLevel($uid, $user->total_recharge_amount); - if (!empty($extra['payer']['openid']) ) { - Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid'],'logistics_type'=>3], 5); + if (!empty($extra['payer']['openid'])) { + Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid'], 'logistics_type' => 3], 5); } return true; } @@ -258,31 +258,51 @@ class PayNotifyLogic extends BaseLogic $financeLogic = new StoreFinanceFlowLogic(); $financeLogic->order = $order; $financeLogic->user = ['uid' => $order['uid']]; - if ($order->pay_type != 9 || $order->pay_type != 10) { - $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY); //用户单入账 + // if ($order->pay_type != 9 || $order->pay_type != 10) { + $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY); //用户订单支付 //商户应该获得的钱 每个商品的price-ot_price 利润 - if (isset($order->profit) && $order->profit > 0) { - //手续费 + // if (isset($order->profit) && $order->profit > 0) { + //平台手续费 $fees = bcdiv(bcmul($order['pay_price'], '0.02', 2), 1, 2); - $financeLogic->in($transaction_id, $fees, OrderEnum::ORDER_COMMITION, $order['store_id']); //手续费入账 - $financeLogic->out($transaction_id, $order['profit'], OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0); //商户获得的 + $financeLogic->in($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'],0,$order['pay_type']); //平台手续费 + + $financeLogic->out($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], $order['staff_id'],0,$order['pay_type']); //商户平台手续费支出 //冻结金额的 - $frozen = bcsub($order->profit, $fees, 2); + // $frozen = bcsub($order->profit, $fees, 2); //缴纳齐全了就加商户没有就加到平台 $money_limt = SystemStore::where('id', $order['store_id'])->field('paid_deposit,security_deposit')->find(); - $deposit = bcsub($money_limt['security_deposit'], $money_limt['paid_deposit'], 2); //剩余额度 - if ($deposit > 0 && $frozen > 0) { - $amount = min($deposit, $frozen); - $financeLogic->in($transaction_id, $amount, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id']); + $deposit = bcsub($money_limt['security_deposit'], $money_limt['paid_deposit'], 2); //保证金剩余额度 + $store_profit= bcdiv(bcmul($order['pay_price'], '0.05', 2), 1, 2); + if ($deposit > 0 ) { + if($deposit>$store_profit){ + $financeLogic->out($transaction_id, $store_profit, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id'],0,$order['pay_type']); + }else{ + $money=bcsub($store_profit,$deposit,2); + $financeLogic->out($transaction_id, $deposit, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id'],0,$order['pay_type']); + $financeLogic->in($transaction_id, $money, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'],0,$order['pay_type']); //平台手续费 + } + }else{ + $financeLogic->in($transaction_id, $store_profit, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'],0,$order['pay_type']); //平台手续费 } - //入商户帐 - if($deposit <= 0 && $frozen > 0){ - SystemStore::where('id',$order['store_id'])->inc('store_money',$frozen); + if($order['is_vip']==1 ){ + if($order['spread_uid']>0){ + $financeLogic->other_arr['vip_uid'] = $order['spread_uid']; + $fees = bcdiv(bcmul($order['pay_price'], '0.08', 2), 1, 2); + $financeLogic->in($transaction_id, $fees, OrderEnum::VIP_ORDER_OBTAINS, $order['store_id'],0,$order['pay_type']); //vip订单获得 + $financeLogic->out($transaction_id, $fees, OrderEnum::VIP_ORDER_OBTAINS, $order['store_id'], $order['staff_id'],0,$order['pay_type']); + } + $fees = bcdiv(bcmul($order['pay_price'], '0.01', 2), 1, 2); + $financeLogic->in($transaction_id, $fees, OrderEnum::VILLAGE_ORDER_OBTAINS, $order['store_id'],0,$order['pay_type']); //vip订单获得 + $financeLogic->out($transaction_id, $fees, OrderEnum::VILLAGE_ORDER_OBTAINS, $order['store_id'], $order['staff_id'],0,$order['pay_type']); + $financeLogic->in($transaction_id, $fees, OrderEnum::BRIGADE_ORDER_OBTAINS, $order['store_id'],0,$order['pay_type']); //vip订单获得 + $financeLogic->out($transaction_id, $fees, OrderEnum::BRIGADE_ORDER_OBTAINS, $order['store_id'], $order['staff_id'],0,$order['pay_type']); + $financeLogic->in($transaction_id, $fees, OrderEnum::OTHER_ORDER_OBTAINS, $order['store_id'],0,$order['pay_type']); //vip订单获得 + $financeLogic->out($transaction_id, $fees, OrderEnum::OTHER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'],0,$order['pay_type']); } - } + // } $financeLogic->save(); - } + // } } //等级处理 diff --git a/app/common/logic/StoreFinanceFlowLogic.php b/app/common/logic/StoreFinanceFlowLogic.php index c1489abb8..dfcf265aa 100644 --- a/app/common/logic/StoreFinanceFlowLogic.php +++ b/app/common/logic/StoreFinanceFlowLogic.php @@ -11,6 +11,7 @@ class StoreFinanceFlowLogic extends BaseLogic public $order; public $user; + public $other_arr; public $index = 0; public $financeSn; public $list = []; @@ -24,9 +25,9 @@ class StoreFinanceFlowLogic extends BaseLogic * @param $staffId * @param $status */ - public function out($transaction_id,$number, $financialType, $storeId = 0, $staffId = 0, $status = 1) + public function out($transaction_id,$number, $financialType, $storeId = 0, $staffId = 0, $status = 1,$pay_type=7) { - $this->setData($number, $financialType, 0, $storeId, $staffId, $status,$transaction_id); + $this->setData($number, $financialType, 0, $storeId, $staffId, $status,$transaction_id,$pay_type); } /** @@ -38,12 +39,12 @@ class StoreFinanceFlowLogic extends BaseLogic * @param $staffId * @param $status */ - public function in($transaction_id,$number, $financialType, $storeId = 0, $staffId = 0, $status = 1) + public function in($transaction_id,$number, $financialType, $storeId = 0, $staffId = 0, $status = 1,$pay_type=7) { - $this->setData($number, $financialType, 1, $storeId, $staffId, $status,$transaction_id); + $this->setData($number, $financialType, 1, $storeId, $staffId, $status,$transaction_id,$pay_type); } - public function setData($number, $financialType, $pm, $storeId, $staffId, $status,$transaction_id) + public function setData($number, $financialType, $pm, $storeId, $staffId, $status,$transaction_id,$pay_type=7) { if (empty($this->financeSn)) { $this->financeSn = $this->getSn(); @@ -53,10 +54,11 @@ class StoreFinanceFlowLogic extends BaseLogic 'transaction_id' => $transaction_id, 'order_sn' => $this->order['order_id'], 'user_id' => $this->user['uid'], + 'other_uid' => $this->other_arr['vip_uid']??0, 'financial_type' => $financialType, 'financial_pm' => $pm, 'number' => $number, - 'pay_type' => PayEnum::WECHAT_PAY_MINI, + 'pay_type' => $pay_type, 'status' => $status, 'store_id' => $storeId !== '' ? $storeId : $this->order['store_id'], 'staff_id' => $staffId !== '' ? $staffId : $this->order['staff_id'],