修复:佣金提现计算错误,导致提现后可能会增加剩余可提现佣金数量的佣金

修复:提现页面的佣金显示错误
This commit is contained in:
wuhui_zzw 2024-01-04 18:08:09 +08:00
parent 3d83f49ea7
commit c82b023545
6 changed files with 66 additions and 12 deletions

View File

@ -123,17 +123,23 @@ class UserBillDao extends BaseDao
foreach($lst as $bill){ foreach($lst as $bill){
$refundPrice = bcadd($refundPrice,$bill['number'],2); $refundPrice = bcadd($refundPrice,$bill['number'],2);
} }
// 招商佣金&推广员佣金
return $refundPrice;
/* // 招商佣金&推广员佣金
$commissionList = UserBill::getDB()->where('category', 'brokerage') $commissionList = UserBill::getDB()->where('category', 'brokerage')
->whereIn('type', ['commission_merchants','commission_promoter']) ->whereIn('type', ['commission_merchants','commission_promoter'])
->where('uid', $uid) ->where('uid', $uid)
->where('pm', 1)
->where('status', 0) ->where('status', 0)
->field('link_id,number') ->field('link_id,number')
->select() ->select()
->toArray(); ->toArray();
$commissionRefundPrice = 0; $commissionRefundPrice = 0;
if (count($lst)) { if (count($commissionList)) {
$commissionRefundPrice = -1 * UserBill::getDB()->whereIn('link_id', array_column($lst, 'link_id'))->where('uid', $uid) $commissionRefundPrice = -1 * UserBill::getDB()
->whereIn('link_id', array_column($commissionList, 'link_id'))
->where('uid', $uid)
->where('pm', 0)
->where('category', 'brokerage') ->where('category', 'brokerage')
->whereIn('type', ['commission_merchants', 'commission_promoter']) ->whereIn('type', ['commission_merchants', 'commission_promoter'])
->sum('number'); ->sum('number');
@ -146,13 +152,16 @@ class UserBillDao extends BaseDao
->where('category', 'brokerage') ->where('category', 'brokerage')
->whereIn('type', ['commission_partner']) ->whereIn('type', ['commission_partner'])
->where('uid', $uid) ->where('uid', $uid)
->where('pm', 1)
->where('status', 0) ->where('status', 0)
->field('link_id,number') ->field('link_id,number')
->select() ->select()
->toArray(); ->toArray();
$commissionPartnerRefundPrice = 0; $commissionPartnerRefundPrice = 0;
if (count($lst)) { if (count($commissionPartnerList)) {
$commissionPartnerRefundPrice = -1 * UserBill::getDB()->whereIn('link_id', array_column($lst, 'link_id')) $commissionPartnerRefundPrice = -1 * UserBill::getDB()
->whereIn('link_id', array_column($commissionPartnerList, 'link_id'))
->where('pm', 0)
->where('uid', $uid) ->where('uid', $uid)
->where('category', 'brokerage') ->where('category', 'brokerage')
->whereIn('type', ['commission_partner']) ->whereIn('type', ['commission_partner'])
@ -160,10 +169,10 @@ class UserBillDao extends BaseDao
} }
foreach ($commissionPartnerList as $billThree) { foreach ($commissionPartnerList as $billThree) {
$commissionPartnerRefundPrice = bcadd($commissionPartnerRefundPrice, $billThree['number'], 2); $commissionPartnerRefundPrice = bcadd($commissionPartnerRefundPrice, $billThree['number'], 2);
} }*/
return (float)sprintf("%.2f",(float)$refundPrice + (float)$commissionRefundPrice + (float)$commissionPartnerList); // return (float)sprintf("%.2f",(float)$refundPrice + (float)$commissionRefundPrice + (float)$commissionPartnerList);
} }
public function lockIntegral($uid = null, $order_id = null) public function lockIntegral($uid = null, $order_id = null)

View File

@ -230,9 +230,16 @@ class User extends BaseModel
return app()->make(UserBillRepository::class)->totalBrokerage($this->uid) ?: 0; return app()->make(UserBillRepository::class)->totalBrokerage($this->uid) ?: 0;
} }
public function getTotalBrokeragePriceAttr() public function getBrokeragePriceAttr($value){
{ // 添加:合伙人佣金、招商佣金、推广佣金
return bcadd($this->lock_brokerage, $this->brokerage_price, 2); $PlatformCommissionMoney = app()->make(UserBillRepository::class)->getPlatformCommissionMoney($this->uid);
// debug([$value,$PlatformCommissionMoney]);
return (float)sprintf("%.2f",$value + $PlatformCommissionMoney);
}
public function getTotalBrokeragePriceAttr(){
return (float)bcadd($this->lock_brokerage, $this->brokerage_price, 2);
} }
public function getTotalIntegralAttr() public function getTotalIntegralAttr()

View File

@ -269,7 +269,11 @@ class PointsOrderCreateRepository
if (!$orderInfo['address']['province_id']) throw new ValidateException('请完善收货地址信息'); if (!$orderInfo['address']['province_id']) throw new ValidateException('请完善收货地址信息');
if (!$orderInfo['order_delivery_status']) throw new ValidateException('部分商品配送方式不一致,请单独下单'); if (!$orderInfo['order_delivery_status']) throw new ValidateException('部分商品配送方式不一致,请单独下单');
if ($orderInfo['order_total_price'] > 1000000) throw new ValidateException('支付金额超出最大限制'); if ($orderInfo['order_total_price'] > 1000000) throw new ValidateException('支付金额超出最大限制');
if ($orderInfo['order_total_integral'] > $user->integral) throw new ValidateException('积分不足'); // if ($orderInfo['order_total_integral'] > $user->integral) throw new ValidateException('积分不足');
$hold_legumes_integral = app()->make(LegumesLogRepository::class)->getHoldLegumesIntegral((int)$user->uid);
if ($orderInfo['order_total_integral'] > $hold_legumes_integral) throw new ValidateException('积分不足');
$merchantCartList = $orderInfo['order']; $merchantCartList = $orderInfo['order'];
$address =$orderInfo['address']; $address =$orderInfo['address'];
$user_address = isset($address) ? ($address['province'] . $address['city'] . $address['district'] . $address['street'] . $address['detail']) : ''; $user_address = isset($address) ? ($address['province'] . $address['city'] . $address['district'] . $address['street'] . $address['detail']) : '';

View File

@ -59,6 +59,8 @@ class PartnerSettlementCycleRepository extends BaseRepository{
if($this->set['commission_partner_cycle'] == 1) [$this->startTime,$this->endTime] = getTimeStamp('last_week');// 周 if($this->set['commission_partner_cycle'] == 1) [$this->startTime,$this->endTime] = getTimeStamp('last_week');// 周
else if($this->set['commission_partner_cycle'] == 2) [$this->startTime,$this->endTime] = getTimeStamp('last_month');// 月 else if($this->set['commission_partner_cycle'] == 2) [$this->startTime,$this->endTime] = getTimeStamp('last_month');// 月
else [$this->startTime,$this->endTime] = getTimeStamp('yesterday');// 天 else [$this->startTime,$this->endTime] = getTimeStamp('yesterday');// 天
// [$this->startTime,$this->endTime] = getTimeStamp('today');// 测试使用
// 判断:是否允许执行 // 判断:是否允许执行
$this->settlementIsRun(); $this->settlementIsRun();
// 佣金分红计算并且记录 // 佣金分红计算并且记录

View File

@ -8,6 +8,7 @@ namespace app\common\repositories\user;
use app\common\dao\BaseDao; use app\common\dao\BaseDao;
use app\common\dao\user\UserBillDao; use app\common\dao\user\UserBillDao;
use app\common\model\user\UserBill;
use app\common\repositories\BaseRepository; use app\common\repositories\BaseRepository;
use app\common\repositories\store\product\ProductRepository; use app\common\repositories\store\product\ProductRepository;
use crmeb\jobs\SendSmsJob; use crmeb\jobs\SendSmsJob;
@ -264,6 +265,33 @@ class UserBillRepository extends BaseRepository
], ],
]; ];
} }
/**
* Common: 获取用户实际获得的可用合伙人佣金、推广佣金、招商佣金(已解冻)
* Author: wu-hui
* Time: 2024/01/04 18:00
* @param $uid
* @return float
*/
public function getPlatformCommissionMoney($uid){
// 获得佣金
$increaseMoney = (float)UserBill::getDB()->where('category', 'brokerage')
->whereIn('type', ['commission_merchants','commission_promoter', 'commission_partner'])
->where('uid', $uid)
->where('pm', 1)
->where('status', 1)
->field('link_id,number')
->sum('number');
// 退款减少佣金
$reduceMoney = (float)UserBill::getDB()->where('category', 'brokerage')
->whereIn('type', ['commission_merchants','commission_promoter', 'commission_partner'])
->where('uid', $uid)
->where('pm', 0)
->where('status', 1)
->field('link_id,number')
->sum('number');
// 实际获得佣金
return (float)sprintf("%.2f", $increaseMoney - $reduceMoney);
}
} }

View File

@ -108,7 +108,11 @@ class UserExtractRepository extends BaseRepository
if(!$openid) throw new ValidateException('openID获取失败,请确认是微信用户'); if(!$openid) throw new ValidateException('openID获取失败,请确认是微信用户');
} }
} }
$brokerage_price = bcsub($user['brokerage_price'],$data['extract_price'],2); // 由于 佣金包含平台抽成相关佣金 需要减去相关佣金,然后计算。否则会出现问题
$PlatformCommissionMoney = app()->make(UserBillRepository::class)->getPlatformCommissionMoney($user['uid']);
$brokeragePrice = bcsub($user['brokerage_price'],$PlatformCommissionMoney,2);
$brokerage_price = bcsub($brokeragePrice,$data['extract_price'],2);
// debug($brokerage_price);
$user->brokerage_price = $brokerage_price; $user->brokerage_price = $brokerage_price;
$user->save(); $user->save();