From c0f64c83fcd6ccca14e83a0bb2741a673928ffc8 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 28 Jun 2024 16:58:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(pay-notify-logic):=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E9=80=9A=E7=9F=A5=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84=EF=BC=8C?= =?UTF-8?q?=E6=8F=90=E9=AB=98=E5=8F=AF=E8=AF=BB=E6=80=A7=E5=92=8C=E5=8F=AF?= =?UTF-8?q?=E7=BB=B4=E6=8A=A4=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/CommissionLogic.php | 143 ++++------ app/common/logic/PayNotifyLogic.php | 384 ++++++++++----------------- 2 files changed, 205 insertions(+), 322 deletions(-) diff --git a/app/common/logic/CommissionLogic.php b/app/common/logic/CommissionLogic.php index 072731033..b239ef66f 100644 --- a/app/common/logic/CommissionLogic.php +++ b/app/common/logic/CommissionLogic.php @@ -12,105 +12,62 @@ class CommissionLogic extends BaseLogic /** * 走村长分润 */ - public static function setVillage($order, $transaction_id) + public static function setVillage($order,$village_uid=0,$brigade_uid=0, $transaction_id=0) { - $village_uid=0; - $brigade_uid=0; - if ($order['uid'] > 0) { - $address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find(); - if ($address) { - $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid'); - if ($arr1) { - $uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id'); - if ($uid) { - $village_uid = $uid; - } - } - $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid'); - if ($arr2) { - $uid = User::where('id', 'in', $arr1)->where('user_ship', 3)->value('id'); - if ($uid) { - $brigade_uid = $uid; - } - } - } - } - self::user($order, 0.05, $transaction_id,$village_uid,14);//村长 - self::user($order, 0.03, $transaction_id,0,12);//会员、厨师 - self::user($order, 0.01, $transaction_id,$brigade_uid,15);//队长 - self::user($order, 0.01, $transaction_id,0,16);//其他 + $user_1=self::user($order, 0.05, $transaction_id,$village_uid,14);//村长 + $user_2=self::user($order, 0.03, $transaction_id,0,12);//会员、厨师 + $user_3=self::user($order, 0.01, $transaction_id,$brigade_uid,15);//队长 + + $platform=self::platform($order, 0.02, $transaction_id);//平台 + $store=self::store($order, 0.05, $transaction_id,0);//门店 + $user_4=self::user($order, 0.02, $transaction_id,0,16);//其他 + + $moeny=bcadd(bcadd(bcadd(bcadd($user_1,$user_2,2),$user_3,2),$platform,2),bcadd($store,$user_4,2),2); + self::suppliter($order, $moeny, $transaction_id); } /** * 走队长分润 */ - public static function setBrigade($order, $transaction_id) + public static function setBrigade($order,$village_uid=0,$brigade_uid=0, $transaction_id=0) { - $village_uid=0; - $brigade_uid=0; - if ($order['uid'] > 0) { - $address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find(); - if ($address) { - $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid'); - if ($arr1) { - $uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id'); - if ($uid) { - $village_uid = $uid; - } - } - $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid'); - if ($arr2) { - $uid = User::where('id', 'in', $arr1)->where('user_ship', 3)->value('id'); - if ($uid) { - $brigade_uid = $uid; - } - } - } - } - self::user($order, 0.05, $transaction_id,$brigade_uid,14);//队长 - self::user($order, 0.03, $transaction_id,0,12);////会员、厨师 - self::user($order, 0.01, $transaction_id,$village_uid,15);//村长 - self::user($order, 0.01, $transaction_id,0,16);//其他 + $user_1=self::user($order, 0.05, $transaction_id,$brigade_uid,14);//队长 + $user_2=self::user($order, 0.03, $transaction_id,0,12);////会员、厨师 + $user_3=self::user($order, 0.01, $transaction_id,$village_uid,15);//村长 + + $platform=self::platform($order, 0.02, $transaction_id);//平台 + $store=self::store($order, 0.05, $transaction_id,0);//门店 + $user_4=self::user($order, 0.02, $transaction_id,0,16);//其他 + + $moeny=bcadd(bcadd(bcadd(bcadd($user_1,$user_2,2),$user_3,2),$platform,2),bcadd($store,$user_4,2),2); + self::suppliter($order, $moeny, $transaction_id); } /** * 走厨师分润 */ - public static function setCook($order, $transaction_id) + public static function setCook($order,$village_uid=0,$brigade_uid=0, $transaction_id=0) { - $village_uid=0; - $brigade_uid=0; - if ($order['uid'] > 0) { - $address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find(); - if ($address) { - $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid'); - if ($arr1) { - $uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id'); - if ($uid) { - $village_uid = $uid; - } - } - $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid'); - if ($arr2) { - $uid = User::where('id', 'in', $arr1)->where('user_ship', 3)->value('id'); - if ($uid) { - $brigade_uid = $uid; - } - } - } - } - self::user($order, 0.07, $transaction_id,0,12);//会员、厨师 - self::user($order, 0.01, $transaction_id,$village_uid,14);//村长 - self::user($order, 0.01, $transaction_id,$brigade_uid,15);//队长 - self::user($order, 0.01, $transaction_id,0,16);//其他 + $user_1=self::user($order, 0.07, $transaction_id,0,12);//会员、厨师 + $user_2=self::user($order, 0.01, $transaction_id,$village_uid,14);//村长 + $user_3=self::user($order, 0.01, $transaction_id,$brigade_uid,15);//队长 + + $platform=self::platform($order, 0.02, $transaction_id);//平台 + $store=self::store($order, 0.05, $transaction_id,0);//门店 + $user_4=self::user($order, 0.02, $transaction_id,0,16);//其他 + + $moeny=bcadd(bcadd(bcadd(bcadd($user_1,$user_2,2),$user_3,2),$platform,2),bcadd($store,$user_4,2),2); + self::suppliter($order, $moeny, $transaction_id); } /** * 走线下分润 */ - public static function setStore($order, $transaction_id) + public static function setStore($order, $transaction_id=0) { - self::platform($order, 0.05, $transaction_id);//平台 - self::store($order, 0.02, $transaction_id,0);//门店 - self::user($order, 0.01, $transaction_id,0,16);//其他 + $platform= self::platform($order, 0.05, $transaction_id);//平台 + $store= self::store($order, 0.02, $transaction_id,0);//门店 + $user= self::user($order, 0.01, $transaction_id,0,16);//其他 + $moeny=bcadd(bcadd($platform,$store,2),$user,2); + self::suppliter($order, $moeny, $transaction_id); } @@ -122,11 +79,27 @@ class CommissionLogic extends BaseLogic { $financeLogic = new StoreFinanceFlowLogic(); $financeLogic->order=$order; + $financeLogic->user['uid']=$order['uid']; $fees = bcdiv(bcmul($order['pay_price'], $platformRate, 2), 1, 2); if ($fees > 0) { $financeLogic->in($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费 $financeLogic->out($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //商户平台手续费支出 } + return $fees; + } + /** + * 供应链订单获得 + */ + public static function suppliter($order, $platformRate, $transaction_id) + { + $financeLogic = new StoreFinanceFlowLogic(); + $financeLogic->order=$order; + $financeLogic->user['uid']=$order['uid']; + $fees = bcsub($order['pay_price'], $platformRate,2); + if ($fees > 0) { + $financeLogic->in($transaction_id, $fees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); + $financeLogic->out($transaction_id, $fees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); + } } /** * 门店分润 @@ -142,7 +115,7 @@ class CommissionLogic extends BaseLogic //缴纳齐全了就加商户没有就加到平台 $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); //保证金剩余额度 - $store_profit = bcdiv(bcmul($order['pay_price'], $platformRate, 2), 1, 2); + $store_profit = bcmul($order['pay_price'], $platformRate, 2); if ($deposit > 0) { if ($deposit > $store_profit) { if ($store_profit > 0) { @@ -167,6 +140,7 @@ class CommissionLogic extends BaseLogic $financeLogic->in($transaction_id, $store_profit, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费 } } + return $store_profit; } /** @@ -188,8 +162,7 @@ class CommissionLogic extends BaseLogic $financeLogic->order=$order; $financeLogic->in($transaction_id, $fees, $enum, $order['store_id'], 0, 0, $order['pay_type']); $financeLogic->out($transaction_id, $fees, $enum, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); - - } + return $fees; } } diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 8cc60abb3..66857b2de 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -71,14 +71,14 @@ class PayNotifyLogic extends BaseLogic if ($user['now_money'] < $order['pay_price']) { throw new \Exception('余额不足'); } -// $order->money = $order['pay_price']; + // $order->money = $order['pay_price']; $order->paid = 1; $order->pay_time = time(); if (!$order->save()) { throw new \Exception('订单保存出错'); } - if($order['is_storage']==1){ - $order->status=2; + if ($order['is_storage'] == 1) { + $order->status = 2; UserProductStorageLogic::add($order); } // 减去余额 @@ -95,9 +95,9 @@ class PayNotifyLogic extends BaseLogic $capitalFlowDao = new CapitalFlowLogic($user); $capitalFlowDao->userExpense('user_order_balance_pay', 'order', $order['id'], $order['pay_price'], '', 0, $order['store_id']); self::dealProductLog($order); -// if ($order['shipping_type'] == 3) { -// self::descStock($order['id']); -// } + // if ($order['shipping_type'] == 3) { + // self::descStock($order['id']); + // } self::afterPay($order); if ($extra && $extra['store_id']) { $params = [ @@ -184,8 +184,8 @@ class PayNotifyLogic extends BaseLogic if (!$order->save()) { throw new \Exception('订单保存出错'); } - if($order['is_storage']==1){ - $order->status=2; + if ($order['is_storage'] == 1) { + $order->status = 2; UserProductStorageLogic::add($order); } // 减去采购款 @@ -208,15 +208,15 @@ class PayNotifyLogic extends BaseLogic OrderLogic::writeOff($params); } self::dealProductLog($order); -// $count = UserSign::where([ -// 'uid'=>$order['uid'], -// 'type'=>1, -// 'status'=>0 -// ])->count(); -// -// if($count){ -// self::addFlowLog($order); -// } + // $count = UserSign::where([ + // 'uid'=>$order['uid'], + // 'type'=>1, + // 'status'=>0 + // ])->count(); + // + // if($count){ + // self::addFlowLog($order); + // } // if($order['shipping_type'] == 3){ // self::descStock($order['id']); // } @@ -225,85 +225,83 @@ class PayNotifyLogic extends BaseLogic // Redis::send('push-platform-print', ['id' => $order['id']], 60); // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); } - + //采购款支付后如果有对应的冻结的话就去反对应的log public static function addFlowLog($order) { //查询当前用户有无对应的充值的冻结金额 - if($order['uid'] >0){ + if ($order['uid'] > 0) { $query = UserSign::where([ - 'uid'=>$order['uid'], - 'type'=>1, - 'status'=>0 + 'uid' => $order['uid'], + 'type' => 1, + 'status' => 0 ]); -// $query1 = clone $query; -// $ids = $query->column('id'); + // $query1 = clone $query; + // $ids = $query->column('id'); $check = $query->sum('number'); -// $count = $query1->count(); - if($check && $check >0){ - $backPurchase = bcmul($order['pay_price'],0.1,2); + // $count = $query1->count(); + if ($check && $check > 0) { + $backPurchase = bcmul($order['pay_price'], 0.1, 2); -// if($count == 1){ - //存在拆单子否 - //少了就冻结减去这个对应的金额 - $one = UserSign::where([ - 'uid'=>$order['uid'], - 'type'=>1, - 'status'=>0 - ])->find(); - $data = [ - 'sid'=>$one['id'], - 'uid' => $order['uid'], - 'order_id' => $order['order_id'], - 'title' => '充值获得冻结兑换券', - 'financial_pm' => 1, - 'type' => 1, - 'status' => 1, - ]; + // if($count == 1){ + //存在拆单子否 + //少了就冻结减去这个对应的金额 + $one = UserSign::where([ + 'uid' => $order['uid'], + 'type' => 1, + 'status' => 0 + ])->find(); + $data = [ + 'sid' => $one['id'], + 'uid' => $order['uid'], + 'order_id' => $order['order_id'], + 'title' => '充值获得冻结兑换券', + 'financial_pm' => 1, + 'type' => 1, + 'status' => 1, + ]; - if($one['number'] >= $backPurchase){ -// $wait = bcsub($one['number'],$backPurchase,2)??0; - $data['number'] =$backPurchase; + if ($one['number'] >= $backPurchase) { + // $wait = bcsub($one['number'],$backPurchase,2)??0; + $data['number'] = $backPurchase; - Db::name('user_sign_log')->insert($data); + Db::name('user_sign_log')->insert($data); - //总的减去采购款百分之十剩余的 -// if(empty($wait)){ -// UserSign::where('id',$one['id'])->update( -// [ -// 'number'=>0, -// 'status'=>1 -// ] -// ); -// }else{ -// //add -// UserSign::where('id',$one['id'])->update( -// [ -// 'number'=>$wait -// ] -// ); -// } - - //并且加到对应的用户的采购款中 -// User::where('id',$order['uid'])->inc('purchase_funds',$wait)->update(); - } - else{ - //对比采购款支付的多少 多了就拿冻结金额即可 - $data['number'] =$one['number']; - //都存到对应的log日志 - Db::name('user_sign_log')->insert($data); -// UserSign::where('id',$one['id'])->update( -// [ -// 'number'=>0, -// 'status'=>1 -// ] -// ); - //并且加到对应的用户的采购款中 -// User::where('id',$order['uid'])->inc('purchase_funds',$wait)->update(); - } + //总的减去采购款百分之十剩余的 + // if(empty($wait)){ + // UserSign::where('id',$one['id'])->update( + // [ + // 'number'=>0, + // 'status'=>1 + // ] + // ); + // }else{ + // //add + // UserSign::where('id',$one['id'])->update( + // [ + // 'number'=>$wait + // ] + // ); + // } + //并且加到对应的用户的采购款中 + // User::where('id',$order['uid'])->inc('purchase_funds',$wait)->update(); + } else { + //对比采购款支付的多少 多了就拿冻结金额即可 + $data['number'] = $one['number']; + //都存到对应的log日志 + Db::name('user_sign_log')->insert($data); + // UserSign::where('id',$one['id'])->update( + // [ + // 'number'=>0, + // 'status'=>1 + // ] + // ); + //并且加到对应的用户的采购款中 + // User::where('id',$order['uid'])->inc('purchase_funds',$wait)->update(); } - /* else{ + } + /* else{ //大于0的时候 //先处理金额大的再处理剩余的 //把所有的金额改为正的再加一条后再加 @@ -358,9 +356,8 @@ class PayNotifyLogic extends BaseLogic }*/ -// } + // } return true; - } return true; @@ -382,8 +379,8 @@ class PayNotifyLogic extends BaseLogic $order->status = 1; $order->paid = 1; $order->pay_time = time(); - if($order['is_storage']==1){ - $order->status=2; + if ($order['is_storage'] == 1) { + $order->status = 2; UserProductStorageLogic::add($order); } if ($order->pay_type != 10) { @@ -442,7 +439,7 @@ class PayNotifyLogic extends BaseLogic $user = User::where('id', $order['uid'])->findOrEmpty(); $capitalFlowDao = new CapitalFlowLogic($user); $deal_money = bcdiv($extra['amount']['refund'], 100, 2); - $check_user_sing = UserSign::where('order_id',$order['order_id'])->count(); + $check_user_sing = UserSign::where('order_id', $order['order_id'])->count(); if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额 $user->now_money = bcadd($user->now_money, $deal_money, 2); @@ -460,13 +457,13 @@ class PayNotifyLogic extends BaseLogic //退款 $capitalFlowDao->userIncome('system_purchase_back', 'system_back', $order['id'], $deal_money); } - if($check_user_sing){ + if ($check_user_sing) { self::descUserSing($order); } return true; } //积分 - if($check_user_sing){ + if ($check_user_sing) { self::descUserSing($order); } //微信日志 user_order_refund @@ -478,12 +475,12 @@ class PayNotifyLogic extends BaseLogic // self::afterPay($order,$extra['transaction_id']); } - + //退积分-->订单 public static function descUserSing($order) { $user_sing = new UserSign(); - if ($order['uid'] > 0 ) { + if ($order['uid'] > 0) { $user_number = bcmul($order['refund_price'], '0.10', 2); $sing = [ 'uid' => $order['uid'], @@ -496,21 +493,19 @@ class PayNotifyLogic extends BaseLogic $user_sing->save($sing); //删除之前获得的兑换券 UserSign::where([ - 'order_id'=>$order['order_id'], - 'financial_pm'=>1, - ])->update(['delete_time'=>time()]); - $now_int = User::where('id',$order['uid'])->withTrashed()->find(); - if($now_int){ - if($now_int['integral'] > $user_number){ - User::where('id',$order['uid'])->withTrashed()->dec('integral',$user_number)->update(); - }else{ - User::where('id',$order['uid'])->withTrashed()->dec('integral',$now_int['integral'])->update(); + 'order_id' => $order['order_id'], + 'financial_pm' => 1, + ])->update(['delete_time' => time()]); + $now_int = User::where('id', $order['uid'])->withTrashed()->find(); + if ($now_int) { + if ($now_int['integral'] > $user_number) { + User::where('id', $order['uid'])->withTrashed()->dec('integral', $user_number)->update(); + } else { + User::where('id', $order['uid'])->withTrashed()->dec('integral', $now_int['integral'])->update(); } - } } return true; - } @@ -613,7 +608,7 @@ class PayNotifyLogic extends BaseLogic public static function dealRechargeFrozen($order) { - $total_vip = bcmul($order['price'],0.1,2); + $total_vip = bcmul($order['price'], 0.1, 2); $user_sing = new UserSign(); $sing = [ 'uid' => $order['uid'], @@ -626,8 +621,8 @@ class PayNotifyLogic extends BaseLogic 'number' => $total_vip, 'back_num' => $total_vip, ]; - $user_sing->save($sing); - User::where('id',$order->uid)->inc('integral',$total_vip)->update(); + $user_sing->save($sing); + User::where('id', $order->uid)->inc('integral', $total_vip)->update(); return true; } @@ -655,31 +650,30 @@ class PayNotifyLogic extends BaseLogic $user = User::where('id', $uid)->findOrEmpty(); //用户的财务add $capitalFlowDao = new CapitalFlowLogic($user); - $capitalFlowDao->userIncome('user_balance_recharge', 'user_recharge', $order['id'], $price,[],1); + $capitalFlowDao->userIncome('user_balance_recharge', 'user_recharge', $order['id'], $price, [], 1); if ($user->isEmpty()) { return true; } bcscale(2); // $user->now_money = bcadd($user->now_money, $price, 2);//v.1 - $check = UserSign::where(['uid'=>$order->uid,'type'=>1])->count(); - if(empty($check) && $user['user_ship'] == 0){ + $check = UserSign::where(['uid' => $order->uid, 'type' => 1])->count(); + if (empty($check) && $user['user_ship'] == 0) { self::dealRechargeFrozen($order); - } //更新等级 $user->user_ship = $order['user_ship']; - + $user->purchase_funds = bcadd($user->purchase_funds, $price, 2); $user->total_recharge_amount = bcadd($user->total_recharge_amount, $price, 2); $user->save(); - if($order['other_uid']>0){ - $uid=$order['other_uid']; + if ($order['other_uid'] > 0) { + $uid = $order['other_uid']; } - PushService::push('wechat_mmp_' . $uid, $uid, ['type'=>'INDUSTRYMEMBERS','msg'=>'订单支付成功','data'=>['id'=>$order['id'],'paid'=>1]]); - PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type'=>'INDUSTRYMEMBERS','msg'=>'订单支付成功','data'=>['id'=>$order['id'],'paid'=>1]]); + PushService::push('wechat_mmp_' . $uid, $uid, ['type' => 'INDUSTRYMEMBERS', 'msg' => '订单支付成功', 'data' => ['id' => $order['id'], 'paid' => 1]]); + PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'INDUSTRYMEMBERS', 'msg' => '订单支付成功', 'data' => ['id' => $order['id'], 'paid' => 1]]); if (!empty($extra['payer']['openid'])) { Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid'], 'logistics_type' => 3], 4); } @@ -703,7 +697,7 @@ class PayNotifyLogic extends BaseLogic throw new \Exception('订单保存出错'); } self::afterPay($order); - if($order['is_storage']==1){ + if ($order['is_storage'] == 1) { UserProductStorageLogic::add($order); } $cashFlowLogic = new CashFlowLogic(); @@ -770,6 +764,9 @@ class PayNotifyLogic extends BaseLogic $financeLogic = new StoreFinanceFlowLogic(); $user_sing = new UserSign(); $off_activity = Config::where('name', 'off_activity')->value('value'); + $village_uid = 0; + $brigade_uid = 0; + $user_ship = 0; if ($off_activity == 1) { //-----活动价结算更改 $financeLogic->order = $order; @@ -778,7 +775,7 @@ class PayNotifyLogic extends BaseLogic $financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); $financeLogic->out($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); $financeLogic->save(); - if ($order['uid'] > 0 && $order['total_price'] >= 500 ) { + if ($order['uid'] > 0 && $order['total_price'] >= 500) { $user_number = bcmul($order['pay_price'], '0.10', 2); $sing = [ 'uid' => $order['uid'], @@ -792,28 +789,19 @@ class PayNotifyLogic extends BaseLogic } return false; } - $vipFen = 0; if ($order['uid'] > 0) { // 结算金额 要支付的钱减去冻结得钱去走后面得逻辑 发得兑换券也要去减去 //用户下单该用户等级为1得时候才处理冻结金额 $user = User::where('id', $order['uid'])->find(); + $user_ship = $user['user_ship']; //纯在分销关系的时候要去判断分销出来的用户的采购款的额度 (只有会员按照这个逻辑拆分,其余的还是按照正常的支付金额) - if ($order['spread_uid'] > 0) { - $oldUser = User::where('id', $order['spread_uid'])->field('purchase_funds,user_ship')->find(); - if ($oldUser && $oldUser['user_ship'] == 1) { - if ($oldUser['purchase_funds'] < $order['pay_price']) { - $vipFen = $oldUser['purchase_funds']; - } - } - } elseif ($user['user_ship'] == 1 && $order['pay_type'] != PayEnum::CASH_PAY) { + if ($user['user_ship'] == 1 && $order['pay_type'] != PayEnum::CASH_PAY) { $vipFrozenAmount = self::dealFrozenPrice($order['id']); //为1的时候要去减活动价 - // $final_price = bcsub($order['pay_price'],$order['deduction_price'],2); - // d($final_price,$vipFrozenAmount); $order['pay_price'] = bcsub($order['pay_price'], $vipFrozenAmount, 2); self::dealVipAmount($order, $order['pay_type']); } - if($order['total_price'] >= 500 ){ + if ($order['total_price'] >= 500) { $user_number = bcmul($order['pay_price'], '0.10', 2); $sing = [ 'uid' => $order['uid'], @@ -826,119 +814,41 @@ class PayNotifyLogic extends BaseLogic ]; $user_sing->save($sing); } - - // User::where('id', $order['uid'])->inc('integral', $user_number)->update(); } - - - $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, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 - $count_frees = 0; - - //平台手续费 - $fees = bcdiv(bcmul($order['pay_price'], '0.02', 2), 1, 2); - $count_frees = bcadd($count_frees, $fees, 2); - if ($fees > 0) { - $financeLogic->in($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费 - $financeLogic->out($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //商户平台手续费支出 + //查询用户对应的村长和队长 + $address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find(); + if ($address) { + $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid'); + if ($arr1) { + $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0; + } + $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid'); + if ($arr2) { + $brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0; + } } - // $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); //保证金剩余额度 - $store_profit = bcdiv(bcmul($order['pay_price'], '0.05', 2), 1, 2); - $count_frees = bcadd($count_frees, $store_profit, 2); - if ($deposit > 0) { - if ($deposit > $store_profit) { - if ($store_profit > 0) { - // SystemStore::where('id', $order['store_id'])->inc('paid_deposit', $store_profit)->update(); - $financeLogic->out($transaction_id, $store_profit, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); - $financeLogic->in($transaction_id, 0, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费 - } - } else { - $money = bcsub($store_profit, $deposit, 2); - if ($deposit > 0) { - // SystemStore::where('id', $order['store_id'])->inc('paid_deposit', $deposit)->update(); - $financeLogic->out($transaction_id, $deposit, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); - } - if ($money) { - // SystemStore::where('id', $order['store_id'])->inc('store_money', $money)->update(); - $financeLogic->in($transaction_id, $money, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费 - } + if ($order['spread_uid'] > 0 || $user_ship>0) { + if($order['spread_uid'] > 0 && $user_ship == 0){ + $user_ship = User::where('id', $order['spread_uid'])->value('user_ship'); + } + switch ($user_ship) { + case 1: // 行业会员 + case 4: // 商户 + CommissionLogic::setCook($order, $village_uid, $brigade_uid, $transaction_id); + break; + case 2: // 村长 + CommissionLogic::setVillage($order, $village_uid, $brigade_uid, $transaction_id); + break; + case 3: // 队长 + CommissionLogic::setBrigade($order, $village_uid, $brigade_uid, $transaction_id); + break; + default: + CommissionLogic::setStore($order, $transaction_id); + break; } } else { - if ($store_profit > 0) { - // SystemStore::where('id', $order['store_id'])->inc('store_money', $store_profit)->update(); - $financeLogic->in($transaction_id, $store_profit, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费 - } + CommissionLogic::setStore($order, $transaction_id); } - // if ($order['is_vip'] >= 1) { - if ($order['spread_uid'] > 0) { - if ($vipFen) { - $fees = bcdiv(bcmul($vipFen, '0.08', 2), 1, 2); - } else { - $fees = bcdiv(bcmul($order['pay_price'], '0.08', 2), 1, 2); - } - $count_frees = bcadd($count_frees, $fees, 2); - } - $fees = bcdiv(bcmul($order['pay_price'], '0.01', 2), 1, 2); - $count_frees = bcadd($count_frees, bcmul($fees, 3, 2), 2); - $village_uid = 0; - $brigade_uid = 0; - //查询用户对应的村长和队长 - if ($order['uid'] > 0) { - $address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find(); - if ($address) { - $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid'); - if ($arr1) { - $uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id'); - if ($uid) { - // User::where('id', $uid)->inc('integral', $fees)->update(); - $village_uid = $uid; - } - } - $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid'); - if ($arr2) { - $uid = User::where('id', 'in', $arr1)->where('user_ship', 3)->value('id'); - if ($uid) { - // User::where('id', $uid)->inc('integral', $fees)->update(); - $brigade_uid = $uid; - } - } - } - } - if ($fees > 0) { - if ($village_uid > 0) { - // SystemStore::where('id', $village_uid)->inc('store_money', $fees)->update(); - $financeLogic->other_arr['vip_uid'] = $village_uid; - } - $financeLogic->in($transaction_id, $fees, OrderEnum::VILLAGE_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); - $financeLogic->out($transaction_id, $fees, OrderEnum::VILLAGE_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); - //队长获得 - if ($brigade_uid > 0) { - // SystemStore::where('id', $brigade_uid)->inc('store_money', $fees)->update(); - $financeLogic->other_arr['vip_uid'] = $brigade_uid; - } - $financeLogic->in($transaction_id, $fees, OrderEnum::BRIGADE_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); - $financeLogic->out($transaction_id, $fees, OrderEnum::BRIGADE_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); - // $user_sing->saveAll($sing); - //其他获得 - $financeLogic->other_arr['vip_uid'] = 0; - $financeLogic->in($transaction_id, $fees, OrderEnum::OTHER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); - $financeLogic->out($transaction_id, $fees, OrderEnum::OTHER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); - } - // } - $fees = bcsub($order['pay_price'], $count_frees, 2); - //供应链订单获得 - if ($fees > 0) { - $financeLogic->in($transaction_id, $fees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); - $financeLogic->out($transaction_id, $fees, OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); - } - // } - $financeLogic->save(); - // } } /**