重构:股东分红金额计算方式,由仅参与当前等级分红修改为参与所有等级的分红,只要持有权重值
This commit is contained in:
parent
0e18cd6022
commit
a2370485f0
|
|
@ -28,6 +28,7 @@ use Yunshop\ShareholderDividend\models\TeamAgentModel;
|
|||
use Yunshop\TeamDividend\models\TeamDividendLevelModel;
|
||||
use app\common\models\Order;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Yunshop\WeightValue\models\WeightValue;
|
||||
|
||||
/**
|
||||
* Author:
|
||||
|
|
@ -304,27 +305,39 @@ class TimedTaskService
|
|||
|
||||
foreach ($teamLevels as $teamLevel) {
|
||||
if ($this->set['level_rate']['level_' . $teamLevel['id']]) {
|
||||
$teamAgents = TeamAgentModel::getTeamAgentByLevelId($teamLevel['id']); // 等级下团队代理
|
||||
// $teamAgents = TeamAgentModel::getTeamAgentByLevelId($teamLevel['id']); // 等级下团队代理
|
||||
// 每次分红 遍历全部的经销商
|
||||
$teamAgents = TeamAgentModel::uniacid()
|
||||
->select([
|
||||
'yz_team_dividend_agency.id',
|
||||
'yz_team_dividend_agency.uid',
|
||||
'yz_team_dividend_agency.parent_id',
|
||||
'yz_team_dividend_agency.level',
|
||||
'yz_team_dividend_agency.subordinate_num',
|
||||
'yz_team_dividend_agency.relation',
|
||||
'yz_weight_value.quantity'
|
||||
])
|
||||
->join('yz_weight_value', 'yz_weight_value.member_id', '=', 'yz_team_dividend_agency.uid')
|
||||
->where('yz_team_dividend_agency.is_black',0)
|
||||
->where('yz_weight_value.quantity','>',0)
|
||||
->where('yz_weight_value.team_dividend_agency_level_id',$teamLevel->id)
|
||||
->whereHas('hasOneMember');
|
||||
$teamAgentCount = $teamAgents->count(); // 同等级代理人数
|
||||
$teamAgentsList = $teamAgents->with([
|
||||
'hasOneMember' => function($query){
|
||||
$query->select(['uid','weight_value']);
|
||||
}
|
||||
])->get();
|
||||
$teamAgentsList = $teamAgents->get();
|
||||
$rate = $this->set['level_rate']['level_' . $teamLevel['id']]; // 等级分红比例
|
||||
$lvCountOrderAmount = sprintf("%.2f", $orderAmount / 100 * $rate);// 当前等级共分红金额
|
||||
$totalWeightValue = sprintf("%.2f", array_sum(array_column(array_column($teamAgentsList->toArray(),'has_one_member'),'weight_value')));
|
||||
// 获取当前等级的全部权重值
|
||||
foreach ($teamAgentsList as $item) {
|
||||
/********* 权重值相关操作 START ***************************************************/
|
||||
// 获取当前经销商的权重值
|
||||
$currentWeightValue = (float)$item->hasOneMember->weight_value;
|
||||
$currentWeightValue = (float)$item->quantity;
|
||||
if($currentWeightValue <= 0){
|
||||
\Log::debug("---- 固定分红 - 当前经销商没有权重值 -----:",['uid'=>$item->uid,'weight_value'=>$currentWeightValue]);
|
||||
continue;
|
||||
}
|
||||
// 存在权重值 查看当前用户比例
|
||||
$weightValueRate = $currentWeightValue / $totalWeightValue;// 权重值占比率
|
||||
$amount = sprintf("%.2f", $lvCountOrderAmount * $weightValueRate);// 当前经销商实际可得金额
|
||||
[$totalQuantity,$weightValueRate] = WeightValue::getTotalAndRatio($teamLevel->id,$currentWeightValue);
|
||||
$amount = sprintf("%.2f", $lvCountOrderAmount * $weightValueRate / 100);// 当前经销商实际可得金额
|
||||
if($amount <= 0){
|
||||
\Log::debug("---- 固定分红 - 当前经销商没有分红佣金 -----:",['uid'=>$item->uid,'weightValueRate'=>$weightValueRate,'weight_value'=>$currentWeightValue,'amount'=>$amount]);
|
||||
continue;
|
||||
|
|
@ -371,18 +384,22 @@ class TimedTaskService
|
|||
}
|
||||
// 股东分红数据
|
||||
$shareData = [
|
||||
'uniacid' => \YunShop::app()->uniacid,
|
||||
'member_id' => $item['uid'],
|
||||
'order_amount' => $orderAmount,
|
||||
'rate' => $rate,
|
||||
'team_level' => $teamLevel['id'],
|
||||
'team_level_name' => $teamLevel['level_name'],
|
||||
'level_num' => $teamAgentCount,
|
||||
'amount' => $check_amount,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time(),
|
||||
'uniacid' => \YunShop::app()->uniacid,
|
||||
'member_id' => $item['uid'],
|
||||
'order_amount' => $orderAmount,
|
||||
'rate' => $rate,
|
||||
'team_level' => $teamLevel['id'],
|
||||
'team_level_name' => $teamLevel['level_name'],
|
||||
'level_num' => $teamAgentCount,
|
||||
'amount' => $check_amount,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time(),
|
||||
'weight_value_total' => $totalQuantity,// 分红时当前等级权重值总数
|
||||
'weight_value_hold' => $currentWeightValue,// 分红时当前用户持有当前等级的权重值
|
||||
'weight_value_rate' => $weightValueRate,// 分红时当前用户持有当前等级的权重值比例
|
||||
];
|
||||
|
||||
|
||||
$shareholderDividendModel = new ShareholderDividendModel();
|
||||
|
||||
$shareholderDividendModel->fill($shareData);
|
||||
|
|
|
|||
|
|
@ -79,7 +79,48 @@
|
|||
<th style='width:10%;'>时间</th>
|
||||
<th style='width:10%;'>会员</th>
|
||||
<th style='width:8%;'>商城销售总额</th>
|
||||
<th style='width:8%;'>分红比例</th>
|
||||
<th style='width:8%;'>等级分红比例</th>
|
||||
<th style='width:8%;'>团队等级</th>
|
||||
<th style='width:10%;'>权重信息</th>
|
||||
<th style='width:10%;'>返现金额</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($list['data'] as $row)
|
||||
<tr>
|
||||
<td>{{$row['id']}}</td>
|
||||
<td>{{$row['created_at']}}</td>
|
||||
<td>
|
||||
<a target="_blank"
|
||||
href="{{yzWebUrl('member.member.detail',['id'=>$row['has_one_member']['uid']])}}">
|
||||
<img src="{{tomedia($row['has_one_member']['avatar'])}}"
|
||||
style="width: 30px; height: 30px;border:1px solid #ccc;padding:1px;">
|
||||
</br>
|
||||
{{$row['has_one_member']['nickname']}}
|
||||
</a>
|
||||
</td>
|
||||
<td>{{$row['order_amount']}}</td>
|
||||
<td>{{$row['rate']}}%</td>
|
||||
<td>{{$row['team_level_name']}}</td>
|
||||
<td>
|
||||
总权重值:{{ $row['weight_value_total'] }}<br />
|
||||
持有权重值:{{ $row['weight_value_hold'] }}<br />
|
||||
占比:{{ $row['weight_value_rate'] . '%' }}<br />
|
||||
</td>
|
||||
<td>{{$row['amount']}}元</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
{{--旧版本内容 2023-10-18 弃用--}}
|
||||
{{-- <table class="table table-hover" style="overflow:visible;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style='width:5%;'>ID</th>
|
||||
<th style='width:10%;'>时间</th>
|
||||
<th style='width:10%;'>会员</th>
|
||||
<th style='width:8%;'>商城销售总额</th>
|
||||
<th style='width:8%;'>等级分红比例</th>
|
||||
<th style='width:8%;'>团队等级</th>
|
||||
<th style='width:10%;'>同等级团队人数</th>
|
||||
<th style='width:10%;'>返现金额</th>
|
||||
|
|
@ -108,7 +149,7 @@
|
|||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</table>--}}
|
||||
|
||||
{!! $pager !!}
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue