修复:佣金小于0时 依然进行的佣金结算流程

修复:经销商佣金 当前下级等级超过上级时 上级平级奖计算错误
This commit is contained in:
wuhui_zzw 2024-04-25 09:54:47 +08:00
parent 65c7244380
commit 71d9d2eb6c
2 changed files with 27 additions and 28 deletions

View File

@ -176,13 +176,13 @@ class TeamDividendController extends BaseController
public function test(){ public function test(){
// date_default_timezone_set("PRC"); date_default_timezone_set("PRC");
// //订单model //订单model
// $model = Order::find(80); $model = Order::find(84);
// (new OrderCreatedListener())->handle($model); (new OrderCreatedListener())->handle($model);
//
//
// debug("结束"); debug("结束");
// (new \Yunshop\TeamDividend\services\TimedTaskService)->handle(); // (new \Yunshop\TeamDividend\services\TimedTaskService)->handle();

View File

@ -117,7 +117,7 @@ class TeamReturnService
private function running() private function running()
{ {
foreach ($this->agents as $agent) { foreach ($this->agents as $agent) {
\Log::debug(' ***************'.$agent['uid']." 开始处理 ***************"); // \Log::debug(' ***************'.$agent['uid']." 开始处理 ***************");
$this->amount_service = new GetAmountService($agent, $this->order, $this->order_goods, $this->set, $this->team_goods, $this->finish_ratio, $this->finish_price); $this->amount_service = new GetAmountService($agent, $this->order, $this->order_goods, $this->set, $this->team_goods, $this->finish_ratio, $this->finish_price);
//商品分红限制 不计入平级奖层级 不算感恩奖 //商品分红限制 不计入平级奖层级 不算感恩奖
@ -214,7 +214,7 @@ class TeamReturnService
// 经销商奖励 // 经销商奖励
private function dividendAward($agent) private function dividendAward($agent)
{ {
\Log::debug(' 经销商奖励 - 开始处理'); // \Log::debug(' 经销商奖励 - 开始处理');
//平级跳出 //平级跳出
if ($this->dividend_level_ids[$agent['level']]) { if ($this->dividend_level_ids[$agent['level']]) {
@ -222,8 +222,8 @@ class TeamReturnService
return; return;
} }
// 平级奖处理初始化 // 平级奖处理初始化
// $this->hierarchyHandle($agent); $this->hierarchyHandle($agent);
$this->dividend_level_ids[$agent['level']]['hierarchy'] = 0; // $this->dividend_level_ids[$agent['level']]['hierarchy'] = 0;
$this->hierarchy_uid = $agent['uid']; $this->hierarchy_uid = $agent['uid'];
// 分红比例 // 分红比例
@ -255,19 +255,21 @@ class TeamReturnService
if($currentStagesType == 1) $dividend_amount = (float)sprintf("%.2f",$monthInfo * $this->order_goods->total);// 固定金额 if($currentStagesType == 1) $dividend_amount = (float)sprintf("%.2f",$monthInfo * $this->order_goods->total);// 固定金额
else $dividend_amount = $this->amount_service->getDividendAmount($monthInfo);// 百分比 else $dividend_amount = $this->amount_service->getDividendAmount($monthInfo);// 百分比
if($dividend_amount <= 0) continue;
// 月月返 级差处理 // 月月返 级差处理
if($monthIndex > 0) { if($monthIndex > 0) {
$this->monthLvDiffMaxMoney = $dividend_amount; $this->monthLvDiffMaxMoney = $dividend_amount;
$dividend_amount = sprintf("%.2f", $dividend_amount - $lvDiffReduceMoney); $dividend_amount = sprintf("%.2f", $dividend_amount - $lvDiffReduceMoney);
} }
// 佣金小于等于0 跳出
if($dividend_amount <= 0) continue;
// todo 调试中... // todo 调试中...
if($monthIndex == 0 || $monthIndex == 1) { // if($monthIndex == 0 || $monthIndex == 1) {
\Log::debug("经销商奖励 {$agent['uid']} 金额:{$dividend_amount}"); // \Log::debug("经销商奖励金额 {$agent['uid']} 金额:{$dividend_amount} 类型:".($monthIndex == 0 ? '立即返' : '月月返'));
} // }
// 计算基数 // 计算基数
@ -364,7 +366,7 @@ class TeamReturnService
// 平级奖奖励层级 // 平级奖奖励层级
$award_hierarchy = $this->amount_service->getAwardHierarchy(); $award_hierarchy = $this->amount_service->getAwardHierarchy();
// 平级奖信息存在 并且 (平级奖奖励层级 小于等于 当前层级 或者 平级奖用户和代理用户为同一个人 不参加平级奖 // 平级奖信息存在 并且 (平级奖奖励层级 小于等于 当前层级 或者 平级奖用户和代理用户为同一个人 不参加平级奖
\Log::debug("平级奖励层级:{$award_hierarchy};当前层级:{$dividend_level['hierarchy']}"); // \Log::debug("平级奖励层级:{$award_hierarchy};当前层级:{$dividend_level['hierarchy']}");
if ($dividend_level && ($award_hierarchy <= $dividend_level['hierarchy'] || $this->hierarchy_uid == $agent['uid'])) { if ($dividend_level && ($award_hierarchy <= $dividend_level['hierarchy'] || $this->hierarchy_uid == $agent['uid'])) {
\Log::debug("平级奖奖励层级小于等于当前层级或者平级奖用户和代理用户为同一个人-不参加平级奖"); \Log::debug("平级奖奖励层级小于等于当前层级或者平级奖用户和代理用户为同一个人-不参加平级奖");
return; return;
@ -387,7 +389,7 @@ class TeamReturnService
// } // }
// 佣金处理 // 佣金处理
\Log::debug("上一个经销商用户ID {$this->upAgent['uid']}"); // \Log::debug("上一个经销商用户ID {$this->upAgent['uid']}");
$amountList = TeamDividendModel::where('order_sn',$this->order->order_sn) $amountList = TeamDividendModel::where('order_sn',$this->order->order_sn)
->select(['amount','status','expect_thaw_time','reality_thaw_time','month']) ->select(['amount','status','expect_thaw_time','reality_thaw_time','month'])
->whereIn('type',[7,8]) ->whereIn('type',[7,8])
@ -395,7 +397,7 @@ class TeamReturnService
->get() ->get()
->toArray(); ->toArray();
\Log::debug("列表内容: ",$amountList); // \Log::debug("列表内容: ",$amountList);
foreach($amountList as $amountIndex => $amountInfo){ foreach($amountList as $amountIndex => $amountInfo){
// 计算基数 // 计算基数
@ -412,9 +414,9 @@ class TeamReturnService
'month' => $amountInfo['month'] 'month' => $amountInfo['month']
]; ];
if($amountIndex == 0 || $amountIndex == 1) { // if($amountIndex == 0 || $amountIndex == 1) {
\Log::debug("经销平级奖奖励 {$agent['uid']} 金额:{$dividendData['dividend_amount']}"); // \Log::debug("经销平级奖奖励 {$agent['uid']} 金额:{$dividendData['dividend_amount']}");
} // }
// 分红 // 分红
$dividend_model = $this->addDividend($agent, $dividendData); $dividend_model = $this->addDividend($agent, $dividendData);
@ -501,14 +503,14 @@ class TeamReturnService
} }
// 平级奖层数增加 // 平级奖层数增加
// $this->hierarchyHandle($agent); $this->hierarchyHandle($agent);
$this->dividend_level_ids[$agent['level']]['hierarchy'] += 1; // $this->dividend_level_ids[$agent['level']]['hierarchy'] += 1;
} }
private function hierarchyHandle($agent){ private function hierarchyHandle($agent){
// 平级奖层数增加 修改:等级权重大于等于当前经销商用户 都拿平级奖处理 2024-3-15 // 平级奖层数增加 修改:等级权重大于等于当前经销商用户 都拿平级奖处理 2024-3-15
foreach($this->team_levels as $levelInfo){ foreach($this->team_levels as $levelInfo){
if($agent['has_one_level']['level_weight'] <= $levelInfo['level_weight']){ if($agent['has_one_level']['level_weight'] >= $levelInfo['level_weight']){
$levelInfoHierarchy = $this->dividend_level_ids[$levelInfo['id']]; $levelInfoHierarchy = $this->dividend_level_ids[$levelInfo['id']];
if(is_array($levelInfoHierarchy)){ if(is_array($levelInfoHierarchy)){
$this->dividend_level_ids[$levelInfo['id']]['hierarchy'] += 1; $this->dividend_level_ids[$levelInfo['id']]['hierarchy'] += 1;
@ -517,9 +519,6 @@ class TeamReturnService
} }
} }
} }
} }
@ -652,7 +651,7 @@ class TeamReturnService
} }
// 插入 // 插入
// if($dividendData['order_sn'] != 'SN2404231906E1F45C') { // if($dividendData['order_sn'] != 'SN2404250911AEB3F5') {
// if($agent['uid'] != 216) { // if($agent['uid'] != 216) {
if ($model = TeamDividendModel::create($dividendData)) { if ($model = TeamDividendModel::create($dividendData)) {
// 统计 // 统计