feat(pay-notify-logic): 修改支付通知逻辑,优化代码结构,提高可读性和可维护性。

This commit is contained in:
mkm 2024-06-28 16:58:57 +08:00
parent 9f3a36201d
commit c0f64c83fc
2 changed files with 205 additions and 322 deletions

View File

@ -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; $user_1=self::user($order, 0.05, $transaction_id,$village_uid,14);//村长
$brigade_uid=0; $user_2=self::user($order, 0.03, $transaction_id,0,12);//会员、厨师
if ($order['uid'] > 0) { $user_3=self::user($order, 0.01, $transaction_id,$brigade_uid,15);//队长
$address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find();
if ($address) { $platform=self::platform($order, 0.02, $transaction_id);//平台
$arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid'); $store=self::store($order, 0.05, $transaction_id,0);//门店
if ($arr1) { $user_4=self::user($order, 0.02, $transaction_id,0,16);//其他
$uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id');
if ($uid) { $moeny=bcadd(bcadd(bcadd(bcadd($user_1,$user_2,2),$user_3,2),$platform,2),bcadd($store,$user_4,2),2);
$village_uid = $uid; self::suppliter($order, $moeny, $transaction_id);
}
}
$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);//其他
} }
/** /**
* 走队长分润 * 走队长分润
*/ */
public static function setBrigade($order, $transaction_id) public static function setBrigade($order,$village_uid=0,$brigade_uid=0, $transaction_id=0)
{ {
$village_uid=0; $user_1=self::user($order, 0.05, $transaction_id,$brigade_uid,14);//队长
$brigade_uid=0; $user_2=self::user($order, 0.03, $transaction_id,0,12);////会员、厨师
if ($order['uid'] > 0) { $user_3=self::user($order, 0.01, $transaction_id,$village_uid,15);//村长
$address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find();
if ($address) { $platform=self::platform($order, 0.02, $transaction_id);//平台
$arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid'); $store=self::store($order, 0.05, $transaction_id,0);//门店
if ($arr1) { $user_4=self::user($order, 0.02, $transaction_id,0,16);//其他
$uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id');
if ($uid) { $moeny=bcadd(bcadd(bcadd(bcadd($user_1,$user_2,2),$user_3,2),$platform,2),bcadd($store,$user_4,2),2);
$village_uid = $uid; self::suppliter($order, $moeny, $transaction_id);
}
}
$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);//其他
} }
/** /**
* 走厨师分润 * 走厨师分润
*/ */
public static function setCook($order, $transaction_id) public static function setCook($order,$village_uid=0,$brigade_uid=0, $transaction_id=0)
{ {
$village_uid=0; $user_1=self::user($order, 0.07, $transaction_id,0,12);//会员、厨师
$brigade_uid=0; $user_2=self::user($order, 0.01, $transaction_id,$village_uid,14);//村长
if ($order['uid'] > 0) { $user_3=self::user($order, 0.01, $transaction_id,$brigade_uid,15);//队长
$address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find();
if ($address) { $platform=self::platform($order, 0.02, $transaction_id);//平台
$arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid'); $store=self::store($order, 0.05, $transaction_id,0);//门店
if ($arr1) { $user_4=self::user($order, 0.02, $transaction_id,0,16);//其他
$uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id');
if ($uid) { $moeny=bcadd(bcadd(bcadd(bcadd($user_1,$user_2,2),$user_3,2),$platform,2),bcadd($store,$user_4,2),2);
$village_uid = $uid; self::suppliter($order, $moeny, $transaction_id);
}
}
$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);//其他
} }
/** /**
* 走线下分润 * 走线下分润
*/ */
public static function setStore($order, $transaction_id) public static function setStore($order, $transaction_id=0)
{ {
self::platform($order, 0.05, $transaction_id);//平台 $platform= self::platform($order, 0.05, $transaction_id);//平台
self::store($order, 0.02, $transaction_id,0);//门店 $store= self::store($order, 0.02, $transaction_id,0);//门店
self::user($order, 0.01, $transaction_id,0,16);//其他 $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 = new StoreFinanceFlowLogic();
$financeLogic->order=$order; $financeLogic->order=$order;
$financeLogic->user['uid']=$order['uid'];
$fees = bcdiv(bcmul($order['pay_price'], $platformRate, 2), 1, 2); $fees = bcdiv(bcmul($order['pay_price'], $platformRate, 2), 1, 2);
if ($fees > 0) { if ($fees > 0) {
$financeLogic->in($transaction_id, $fees, OrderEnum::ORDER_HANDLING_FEES, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费 $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']); //商户平台手续费支出 $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(); $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); //保证金剩余额度 $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 > 0) {
if ($deposit > $store_profit) { if ($deposit > $store_profit) {
if ($store_profit > 0) { 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']); //平台手续费 $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->order=$order;
$financeLogic->in($transaction_id, $fees, $enum, $order['store_id'], 0, 0, $order['pay_type']); $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']); $financeLogic->out($transaction_id, $fees, $enum, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
}
return $fees;
}
} }
} }

View File

@ -286,8 +286,7 @@ class PayNotifyLogic extends BaseLogic
//并且加到对应的用户的采购款中 //并且加到对应的用户的采购款中
// User::where('id',$order['uid'])->inc('purchase_funds',$wait)->update(); // User::where('id',$order['uid'])->inc('purchase_funds',$wait)->update();
} } else {
else{
//对比采购款支付的多少 多了就拿冻结金额即可 //对比采购款支付的多少 多了就拿冻结金额即可
$data['number'] = $one['number']; $data['number'] = $one['number'];
//都存到对应的log日志 //都存到对应的log日志
@ -301,7 +300,6 @@ class PayNotifyLogic extends BaseLogic
//并且加到对应的用户的采购款中 //并且加到对应的用户的采购款中
// User::where('id',$order['uid'])->inc('purchase_funds',$wait)->update(); // User::where('id',$order['uid'])->inc('purchase_funds',$wait)->update();
} }
} }
/* else{ /* else{
//大于0的时候 //大于0的时候
@ -360,7 +358,6 @@ class PayNotifyLogic extends BaseLogic
// } // }
return true; return true;
} }
return true; return true;
@ -506,11 +503,9 @@ class PayNotifyLogic extends BaseLogic
} else { } else {
User::where('id', $order['uid'])->withTrashed()->dec('integral', $now_int['integral'])->update(); User::where('id', $order['uid'])->withTrashed()->dec('integral', $now_int['integral'])->update();
} }
} }
} }
return true; return true;
} }
@ -665,7 +660,6 @@ class PayNotifyLogic extends BaseLogic
$check = UserSign::where(['uid' => $order->uid, 'type' => 1])->count(); $check = UserSign::where(['uid' => $order->uid, 'type' => 1])->count();
if (empty($check) && $user['user_ship'] == 0) { if (empty($check) && $user['user_ship'] == 0) {
self::dealRechargeFrozen($order); self::dealRechargeFrozen($order);
} }
//更新等级 //更新等级
$user->user_ship = $order['user_ship']; $user->user_ship = $order['user_ship'];
@ -770,6 +764,9 @@ class PayNotifyLogic extends BaseLogic
$financeLogic = new StoreFinanceFlowLogic(); $financeLogic = new StoreFinanceFlowLogic();
$user_sing = new UserSign(); $user_sing = new UserSign();
$off_activity = Config::where('name', 'off_activity')->value('value'); $off_activity = Config::where('name', 'off_activity')->value('value');
$village_uid = 0;
$brigade_uid = 0;
$user_ship = 0;
if ($off_activity == 1) { if ($off_activity == 1) {
//-----活动价结算更改 //-----活动价结算更改
$financeLogic->order = $order; $financeLogic->order = $order;
@ -792,24 +789,15 @@ class PayNotifyLogic extends BaseLogic
} }
return false; return false;
} }
$vipFen = 0;
if ($order['uid'] > 0) { if ($order['uid'] > 0) {
// 结算金额 要支付的钱减去冻结得钱去走后面得逻辑 发得兑换券也要去减去 // 结算金额 要支付的钱减去冻结得钱去走后面得逻辑 发得兑换券也要去减去
//用户下单该用户等级为1得时候才处理冻结金额 //用户下单该用户等级为1得时候才处理冻结金额
$user = User::where('id', $order['uid'])->find(); $user = User::where('id', $order['uid'])->find();
$user_ship = $user['user_ship'];
//纯在分销关系的时候要去判断分销出来的用户的采购款的额度 (只有会员按照这个逻辑拆分,其余的还是按照正常的支付金额) //纯在分销关系的时候要去判断分销出来的用户的采购款的额度 (只有会员按照这个逻辑拆分,其余的还是按照正常的支付金额)
if ($order['spread_uid'] > 0) { if ($user['user_ship'] == 1 && $order['pay_type'] != PayEnum::CASH_PAY) {
$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) {
$vipFrozenAmount = self::dealFrozenPrice($order['id']); $vipFrozenAmount = self::dealFrozenPrice($order['id']);
//为1的时候要去减活动价 //为1的时候要去减活动价
// $final_price = bcsub($order['pay_price'],$order['deduction_price'],2);
// d($final_price,$vipFrozenAmount);
$order['pay_price'] = bcsub($order['pay_price'], $vipFrozenAmount, 2); $order['pay_price'] = bcsub($order['pay_price'], $vipFrozenAmount, 2);
self::dealVipAmount($order, $order['pay_type']); self::dealVipAmount($order, $order['pay_type']);
} }
@ -826,119 +814,41 @@ class PayNotifyLogic extends BaseLogic
]; ];
$user_sing->save($sing); $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']); //商户平台手续费支出
}
// $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']); //平台手续费
}
}
} 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']); //平台手续费
}
}
// 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(); $address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find();
if ($address) { if ($address) {
$arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid'); $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');
if ($arr1) { if ($arr1) {
$uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id'); $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0;
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'); $arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid');
if ($arr2) { if ($arr2) {
$uid = User::where('id', 'in', $arr1)->where('user_ship', 3)->value('id'); $brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0;
if ($uid) {
// User::where('id', $uid)->inc('integral', $fees)->update();
$brigade_uid = $uid;
} }
} }
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;
} }
if ($fees > 0) { } else {
if ($village_uid > 0) { CommissionLogic::setStore($order, $transaction_id);
// 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();
// }
} }
/** /**