|
|
@@ -114,19 +114,33 @@ class CommonLogic
|
|
|
|
|
|
|
|
|
//发放层级收益
|
|
|
- public static function setTeamLevelIncome(int $user_id, float $num, int $team_level_id, string $asset, string $action)
|
|
|
+ public static function setTeamLevelIncome(int $user_id, float $num,string $asset, string $action)
|
|
|
{
|
|
|
- $config = config('team_level_where');
|
|
|
- $team_level_id = $team_level_id - 1;
|
|
|
- $paths = UserPathModel::where('user_id', $user_id)->where('distance', '<=', $config[$team_level_id]['level'])->order('distance', 'asc')->column('parent_id');
|
|
|
$income = bcmul($num, config('team_level_inc'), 2); //收益
|
|
|
- if(count($paths) > 0 && $income > 0){
|
|
|
- //余额记录
|
|
|
- foreach($paths as $pathId){
|
|
|
- if(!empty(Loader::model('UserModel')::getTeamLevelId($pathId))) {
|
|
|
- Loader::model('LedgerWalletModel')->changeWalletAccount($pathId, $asset, $income, $action, $user_id);
|
|
|
- }
|
|
|
+ $parents_info = UserPathModel::where('p.user_id', $user_id)
|
|
|
+ ->alias('p')
|
|
|
+ ->join('user u', 'u.id = p.parent_id', 'left')
|
|
|
+ ->field('u.id, u.address_level, u.team_level_id,u.parent_id, p.distance')
|
|
|
+ ->where('u.team_level_id', '>', 0)
|
|
|
+ ->order('p.distance asc')
|
|
|
+ ->select();
|
|
|
+ if(empty($parents_info) || empty($income)) return true;
|
|
|
+
|
|
|
+ //分享 1 个拿 3 层,分享 2 个拿 7 层
|
|
|
+ foreach ($parents_info as $parent){
|
|
|
+ $send_user_id = 0; //需要发放的会员ID列表
|
|
|
+ if($parent['team_level_id'] >= 1 && $parent['distance'] <= 3){
|
|
|
+ $send_user_id = $parent['id'];
|
|
|
+ }else if($parent['team_level_id'] >= 2 && $parent['distance'] <= 7){
|
|
|
+ $send_user_id = $parent['id'];
|
|
|
+ }else if($parent['team_level_id'] >= 3 && $parent['distance'] <= 13){
|
|
|
+ $send_user_id = $parent['id'];
|
|
|
+ }else if($parent['team_level_id'] >= 4 && $parent['distance'] <= 21){
|
|
|
+ $send_user_id = $parent['id'];
|
|
|
+ }else if($parent['team_level_id'] >= 5 && $parent['distance'] <= 31){
|
|
|
+ $send_user_id = $parent['id'];
|
|
|
}
|
|
|
+ if($send_user_id > 0) Loader::model('LedgerWalletModel')->changeWalletAccount($send_user_id, $asset, $income, $action, $user_id);
|
|
|
}
|
|
|
return true;
|
|
|
}
|