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

@ -71,14 +71,14 @@ class PayNotifyLogic extends BaseLogic
if ($user['now_money'] < $order['pay_price']) { if ($user['now_money'] < $order['pay_price']) {
throw new \Exception('余额不足'); throw new \Exception('余额不足');
} }
// $order->money = $order['pay_price']; // $order->money = $order['pay_price'];
$order->paid = 1; $order->paid = 1;
$order->pay_time = time(); $order->pay_time = time();
if (!$order->save()) { if (!$order->save()) {
throw new \Exception('订单保存出错'); throw new \Exception('订单保存出错');
} }
if($order['is_storage']==1){ if ($order['is_storage'] == 1) {
$order->status=2; $order->status = 2;
UserProductStorageLogic::add($order); UserProductStorageLogic::add($order);
} }
// 减去余额 // 减去余额
@ -95,9 +95,9 @@ class PayNotifyLogic extends BaseLogic
$capitalFlowDao = new CapitalFlowLogic($user); $capitalFlowDao = new CapitalFlowLogic($user);
$capitalFlowDao->userExpense('user_order_balance_pay', 'order', $order['id'], $order['pay_price'], '', 0, $order['store_id']); $capitalFlowDao->userExpense('user_order_balance_pay', 'order', $order['id'], $order['pay_price'], '', 0, $order['store_id']);
self::dealProductLog($order); self::dealProductLog($order);
// if ($order['shipping_type'] == 3) { // if ($order['shipping_type'] == 3) {
// self::descStock($order['id']); // self::descStock($order['id']);
// } // }
self::afterPay($order); self::afterPay($order);
if ($extra && $extra['store_id']) { if ($extra && $extra['store_id']) {
$params = [ $params = [
@ -184,8 +184,8 @@ class PayNotifyLogic extends BaseLogic
if (!$order->save()) { if (!$order->save()) {
throw new \Exception('订单保存出错'); throw new \Exception('订单保存出错');
} }
if($order['is_storage']==1){ if ($order['is_storage'] == 1) {
$order->status=2; $order->status = 2;
UserProductStorageLogic::add($order); UserProductStorageLogic::add($order);
} }
// 减去采购款 // 减去采购款
@ -208,15 +208,15 @@ class PayNotifyLogic extends BaseLogic
OrderLogic::writeOff($params); OrderLogic::writeOff($params);
} }
self::dealProductLog($order); self::dealProductLog($order);
// $count = UserSign::where([ // $count = UserSign::where([
// 'uid'=>$order['uid'], // 'uid'=>$order['uid'],
// 'type'=>1, // 'type'=>1,
// 'status'=>0 // 'status'=>0
// ])->count(); // ])->count();
// //
// if($count){ // if($count){
// self::addFlowLog($order); // self::addFlowLog($order);
// } // }
// if($order['shipping_type'] == 3){ // if($order['shipping_type'] == 3){
// self::descStock($order['id']); // self::descStock($order['id']);
// } // }
@ -225,85 +225,83 @@ class PayNotifyLogic extends BaseLogic
// Redis::send('push-platform-print', ['id' => $order['id']], 60); // Redis::send('push-platform-print', ['id' => $order['id']], 60);
// PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']); // PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
} }
//采购款支付后如果有对应的冻结的话就去反对应的log //采购款支付后如果有对应的冻结的话就去反对应的log
public static function addFlowLog($order) public static function addFlowLog($order)
{ {
//查询当前用户有无对应的充值的冻结金额 //查询当前用户有无对应的充值的冻结金额
if($order['uid'] >0){ if ($order['uid'] > 0) {
$query = UserSign::where([ $query = UserSign::where([
'uid'=>$order['uid'], 'uid' => $order['uid'],
'type'=>1, 'type' => 1,
'status'=>0 'status' => 0
]); ]);
// $query1 = clone $query; // $query1 = clone $query;
// $ids = $query->column('id'); // $ids = $query->column('id');
$check = $query->sum('number'); $check = $query->sum('number');
// $count = $query1->count(); // $count = $query1->count();
if($check && $check >0){ if ($check && $check > 0) {
$backPurchase = bcmul($order['pay_price'],0.1,2); $backPurchase = bcmul($order['pay_price'], 0.1, 2);
// if($count == 1){ // if($count == 1){
//存在拆单子否 //存在拆单子否
//少了就冻结减去这个对应的金额 //少了就冻结减去这个对应的金额
$one = UserSign::where([ $one = UserSign::where([
'uid'=>$order['uid'], 'uid' => $order['uid'],
'type'=>1, 'type' => 1,
'status'=>0 'status' => 0
])->find(); ])->find();
$data = [ $data = [
'sid'=>$one['id'], 'sid' => $one['id'],
'uid' => $order['uid'], 'uid' => $order['uid'],
'order_id' => $order['order_id'], 'order_id' => $order['order_id'],
'title' => '充值获得冻结兑换券', 'title' => '充值获得冻结兑换券',
'financial_pm' => 1, 'financial_pm' => 1,
'type' => 1, 'type' => 1,
'status' => 1, 'status' => 1,
]; ];
if($one['number'] >= $backPurchase){ if ($one['number'] >= $backPurchase) {
// $wait = bcsub($one['number'],$backPurchase,2)??0; // $wait = bcsub($one['number'],$backPurchase,2)??0;
$data['number'] =$backPurchase; $data['number'] = $backPurchase;
Db::name('user_sign_log')->insert($data); Db::name('user_sign_log')->insert($data);
//总的减去采购款百分之十剩余的 //总的减去采购款百分之十剩余的
// if(empty($wait)){ // if(empty($wait)){
// UserSign::where('id',$one['id'])->update( // UserSign::where('id',$one['id'])->update(
// [ // [
// 'number'=>0, // 'number'=>0,
// 'status'=>1 // 'status'=>1
// ] // ]
// ); // );
// }else{ // }else{
// //add // //add
// UserSign::where('id',$one['id'])->update( // UserSign::where('id',$one['id'])->update(
// [ // [
// 'number'=>$wait // '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();
}
//并且加到对应的用户的采购款中
// 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的时候 //大于0的时候
//先处理金额大的再处理剩余的 //先处理金额大的再处理剩余的
//把所有的金额改为正的再加一条后再加 //把所有的金额改为正的再加一条后再加
@ -358,9 +356,8 @@ class PayNotifyLogic extends BaseLogic
}*/ }*/
// } // }
return true; return true;
} }
return true; return true;
@ -382,8 +379,8 @@ class PayNotifyLogic extends BaseLogic
$order->status = 1; $order->status = 1;
$order->paid = 1; $order->paid = 1;
$order->pay_time = time(); $order->pay_time = time();
if($order['is_storage']==1){ if ($order['is_storage'] == 1) {
$order->status=2; $order->status = 2;
UserProductStorageLogic::add($order); UserProductStorageLogic::add($order);
} }
if ($order->pay_type != 10) { if ($order->pay_type != 10) {
@ -442,7 +439,7 @@ class PayNotifyLogic extends BaseLogic
$user = User::where('id', $order['uid'])->findOrEmpty(); $user = User::where('id', $order['uid'])->findOrEmpty();
$capitalFlowDao = new CapitalFlowLogic($user); $capitalFlowDao = new CapitalFlowLogic($user);
$deal_money = bcdiv($extra['amount']['refund'], 100, 2); $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 (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) {
if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额 if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额
$user->now_money = bcadd($user->now_money, $deal_money, 2); $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); $capitalFlowDao->userIncome('system_purchase_back', 'system_back', $order['id'], $deal_money);
} }
if($check_user_sing){ if ($check_user_sing) {
self::descUserSing($order); self::descUserSing($order);
} }
return true; return true;
} }
//积分 //积分
if($check_user_sing){ if ($check_user_sing) {
self::descUserSing($order); self::descUserSing($order);
} }
//微信日志 user_order_refund //微信日志 user_order_refund
@ -478,12 +475,12 @@ class PayNotifyLogic extends BaseLogic
// self::afterPay($order,$extra['transaction_id']); // self::afterPay($order,$extra['transaction_id']);
} }
//退积分-->订单 //退积分-->订单
public static function descUserSing($order) public static function descUserSing($order)
{ {
$user_sing = new UserSign(); $user_sing = new UserSign();
if ($order['uid'] > 0 ) { if ($order['uid'] > 0) {
$user_number = bcmul($order['refund_price'], '0.10', 2); $user_number = bcmul($order['refund_price'], '0.10', 2);
$sing = [ $sing = [
'uid' => $order['uid'], 'uid' => $order['uid'],
@ -496,21 +493,19 @@ class PayNotifyLogic extends BaseLogic
$user_sing->save($sing); $user_sing->save($sing);
//删除之前获得的兑换券 //删除之前获得的兑换券
UserSign::where([ UserSign::where([
'order_id'=>$order['order_id'], 'order_id' => $order['order_id'],
'financial_pm'=>1, 'financial_pm' => 1,
])->update(['delete_time'=>time()]); ])->update(['delete_time' => time()]);
$now_int = User::where('id',$order['uid'])->withTrashed()->find(); $now_int = User::where('id', $order['uid'])->withTrashed()->find();
if($now_int){ if ($now_int) {
if($now_int['integral'] > $user_number){ if ($now_int['integral'] > $user_number) {
User::where('id',$order['uid'])->withTrashed()->dec('integral',$user_number)->update(); User::where('id', $order['uid'])->withTrashed()->dec('integral', $user_number)->update();
}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;
} }
@ -613,7 +608,7 @@ class PayNotifyLogic extends BaseLogic
public static function dealRechargeFrozen($order) 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(); $user_sing = new UserSign();
$sing = [ $sing = [
'uid' => $order['uid'], 'uid' => $order['uid'],
@ -626,8 +621,8 @@ class PayNotifyLogic extends BaseLogic
'number' => $total_vip, 'number' => $total_vip,
'back_num' => $total_vip, 'back_num' => $total_vip,
]; ];
$user_sing->save($sing); $user_sing->save($sing);
User::where('id',$order->uid)->inc('integral',$total_vip)->update(); User::where('id', $order->uid)->inc('integral', $total_vip)->update();
return true; return true;
} }
@ -655,31 +650,30 @@ class PayNotifyLogic extends BaseLogic
$user = User::where('id', $uid)->findOrEmpty(); $user = User::where('id', $uid)->findOrEmpty();
//用户的财务add //用户的财务add
$capitalFlowDao = new CapitalFlowLogic($user); $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()) { if ($user->isEmpty()) {
return true; return true;
} }
bcscale(2); bcscale(2);
// $user->now_money = bcadd($user->now_money, $price, 2);//v.1 // $user->now_money = bcadd($user->now_money, $price, 2);//v.1
$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'];
$user->purchase_funds = bcadd($user->purchase_funds, $price, 2); $user->purchase_funds = bcadd($user->purchase_funds, $price, 2);
$user->total_recharge_amount = bcadd($user->total_recharge_amount, $price, 2); $user->total_recharge_amount = bcadd($user->total_recharge_amount, $price, 2);
$user->save(); $user->save();
if($order['other_uid']>0){ if ($order['other_uid'] > 0) {
$uid=$order['other_uid']; $uid = $order['other_uid'];
} }
PushService::push('wechat_mmp_' . $uid, $uid, ['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]]); PushService::push('store_merchant_' . $order['store_id'], $order['store_id'], ['type' => 'INDUSTRYMEMBERS', 'msg' => '订单支付成功', 'data' => ['id' => $order['id'], 'paid' => 1]]);
if (!empty($extra['payer']['openid'])) { if (!empty($extra['payer']['openid'])) {
Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid'], 'logistics_type' => 3], 4); 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('订单保存出错'); throw new \Exception('订单保存出错');
} }
self::afterPay($order); self::afterPay($order);
if($order['is_storage']==1){ if ($order['is_storage'] == 1) {
UserProductStorageLogic::add($order); UserProductStorageLogic::add($order);
} }
$cashFlowLogic = new CashFlowLogic(); $cashFlowLogic = new CashFlowLogic();
@ -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;
@ -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->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->out($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
$financeLogic->save(); $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); $user_number = bcmul($order['pay_price'], '0.10', 2);
$sing = [ $sing = [
'uid' => $order['uid'], 'uid' => $order['uid'],
@ -792,28 +789,19 @@ 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']);
} }
if($order['total_price'] >= 500 ){ if ($order['total_price'] >= 500) {
$user_number = bcmul($order['pay_price'], '0.10', 2); $user_number = bcmul($order['pay_price'], '0.10', 2);
$sing = [ $sing = [
'uid' => $order['uid'], 'uid' => $order['uid'],
@ -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();
} }
//查询用户对应的村长和队长
$address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find();
$financeLogic->order = $order; if ($address) {
$financeLogic->user = ['uid' => $order['uid']]; $arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');
// if ($order->pay_type != 9 || $order->pay_type != 10) { if ($arr1) {
$financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 $village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0;
$count_frees = 0; }
$arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid');
//平台手续费 if ($arr2) {
$fees = bcdiv(bcmul($order['pay_price'], '0.02', 2), 1, 2); $brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0;
$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); if ($order['spread_uid'] > 0 || $user_ship>0) {
//缴纳齐全了就加商户没有就加到平台 if($order['spread_uid'] > 0 && $user_ship == 0){
$money_limt = SystemStore::where('id', $order['store_id'])->field('paid_deposit,security_deposit')->find(); $user_ship = User::where('id', $order['spread_uid'])->value('user_ship');
$deposit = bcsub($money_limt['security_deposit'], $money_limt['paid_deposit'], 2); //保证金剩余额度 }
$store_profit = bcdiv(bcmul($order['pay_price'], '0.05', 2), 1, 2); switch ($user_ship) {
$count_frees = bcadd($count_frees, $store_profit, 2); case 1: // 行业会员
if ($deposit > 0) { case 4: // 商户
if ($deposit > $store_profit) { CommissionLogic::setCook($order, $village_uid, $brigade_uid, $transaction_id);
if ($store_profit > 0) { break;
// SystemStore::where('id', $order['store_id'])->inc('paid_deposit', $store_profit)->update(); case 2: // 村长
$financeLogic->out($transaction_id, $store_profit, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); CommissionLogic::setVillage($order, $village_uid, $brigade_uid, $transaction_id);
$financeLogic->in($transaction_id, 0, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']); //平台手续费 break;
} case 3: // 队长
} else { CommissionLogic::setBrigade($order, $village_uid, $brigade_uid, $transaction_id);
$money = bcsub($store_profit, $deposit, 2); break;
if ($deposit > 0) { default:
// SystemStore::where('id', $order['store_id'])->inc('paid_deposit', $deposit)->update(); CommissionLogic::setStore($order, $transaction_id);
$financeLogic->out($transaction_id, $deposit, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); break;
}
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 { } else {
if ($store_profit > 0) { CommissionLogic::setStore($order, $transaction_id);
// 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();
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();
// }
} }
/** /**