|
|
@@ -16,8 +16,8 @@ use app\common\model\LedgerFrozenChangeModel;
|
|
|
class CommonLogic
|
|
|
{
|
|
|
|
|
|
- // 升级降级
|
|
|
- public static function setIsLevelSave(int $user_id, int $team_level_id, int $address_level, int $num): bool
|
|
|
+ // 升级
|
|
|
+ public static function setIsUpLevel(int $user_id, int $team_level_id, int $address_level, int $parent_id): bool
|
|
|
{
|
|
|
$config = config('team_level_where');
|
|
|
if($team_level_id == count($config)) return false;
|
|
|
@@ -26,35 +26,81 @@ class CommonLogic
|
|
|
if($address_level >= $config[$team_level_id]['direct']) {
|
|
|
$result = true;
|
|
|
$team_level_id += 1;
|
|
|
+ self::setIsUpLevelParent($parent_id, $config);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //组合套数
|
|
|
+ $groupCount = UserPledge::getPledgeCount($user_id) + 1;
|
|
|
+ //直推
|
|
|
+ $teamCount = UserModel::where('parent_id', $user_id)->where('team_level_id', $team_level_id)->count();
|
|
|
+ if($teamCount >= $config[$team_level_id]['direct'] && $groupCount >= $config[$team_level_id]['num']){
|
|
|
+ $result = true;
|
|
|
+ $team_level_id += 1; //+1
|
|
|
+ self::setIsUpLevelParent($parent_id, $config);
|
|
|
}
|
|
|
}
|
|
|
+ return $result? UserModel::where('id', $user_id)->update(['team_level_id'=> $team_level_id]): false;
|
|
|
+ }
|
|
|
|
|
|
+ //上级升级
|
|
|
+ public static function setIsUpLevelParent(int $parent_id, array $config){
|
|
|
+ $parent = UserModel::where('id', $parent_id)->find();
|
|
|
+ if($parent->team_level_id > 0){
|
|
|
+ //推广人数
|
|
|
+ $teamCount = UserModel::where('parent_id', $parent_id)->where('team_level_id', $parent->team_level_id)->count() +1;
|
|
|
+ //组合套数
|
|
|
+ $groupCount = UserPledge::getPledgeCount($parent_id);
|
|
|
+ if($teamCount >= $config[$parent->team_level_id]['direct'] && $groupCount >= $config[$parent->team_level_id]['num']){
|
|
|
+ $parent->team_level_id +=1;
|
|
|
+ $parent->save();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //降级
|
|
|
+ public static function setIsOuLevelSave($user_id, $team_level_id, $address_level, $parent_id)
|
|
|
+ {
|
|
|
+ $config = config('team_level_where');
|
|
|
+ $result = false;
|
|
|
//组合套数
|
|
|
- $groupCount = UserPledge::getPledgeCount($user_id) + $num;
|
|
|
+ $groupCount = UserPledge::getPledgeCount($user_id) -1 ;
|
|
|
if($team_level_id == 1 && ($groupCount == 0 || $address_level < $config[0]['direct'])){
|
|
|
$result = true;
|
|
|
$team_level_id = 0;
|
|
|
+ self::setIsUpLevelParent($parent_id, $config);
|
|
|
}
|
|
|
- //大于1
|
|
|
+
|
|
|
if($team_level_id > 1){
|
|
|
//直推
|
|
|
$teamCount = UserModel::where('parent_id', $user_id)->where('team_level_id', $team_level_id)->count();
|
|
|
- if($teamCount >= $config[$team_level_id]['direct'] && $groupCount >= $config[$team_level_id]['num']){
|
|
|
+ if($teamCount < $config[$team_level_id]['direct'] && $groupCount < $config[$team_level_id]['num']){
|
|
|
$result = true;
|
|
|
- $team_level_id += 1; //+1
|
|
|
- }else{
|
|
|
- $result = true;
|
|
|
- $team_level_id -=1; //-1
|
|
|
+ $team_level_id -= 1;
|
|
|
+ self::setIsUpLevelParent($parent_id, $config);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
return $result? UserModel::where('id', $user_id)->update(['team_level_id'=> $team_level_id]): false;
|
|
|
}
|
|
|
|
|
|
+ //上级降低级
|
|
|
+ public static function setIsOuLevelParent(int $parent_id, array $config){
|
|
|
+ $parent = UserModel::where('id', $parent_id)->find();
|
|
|
+ if($parent->team_level_id > 0){
|
|
|
+ //推广人数
|
|
|
+ $teamCount = UserModel::where('parent_id', $parent_id)->where('team_level_id', $parent->team_level_id)->count() +1;
|
|
|
+ //组合套数
|
|
|
+ $groupCount = UserPledge::getPledgeCount($parent_id);
|
|
|
+ if($teamCount < $config[$parent->team_level_id]['direct'] && $groupCount >= $config[$parent->team_level_id]['num']){
|
|
|
+ $parent->team_level_id -=1;
|
|
|
+ $parent->save();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
-
|
|
|
//发放层级收益
|
|
|
public static function setTeamLevelIncome(int $user_id, float $num, int $team_level_id, string $asset, string $action)
|
|
|
{
|
|
|
@@ -73,10 +119,8 @@ class CommonLogic
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
//判断发放茶宝数量
|
|
|
- public static function getFrozenIsChabao($token, $frozen)
|
|
|
- {
|
|
|
+ public static function getFrozenIsChabao($token, $frozen){
|
|
|
//标记茶宝
|
|
|
if(bccomp(bcmul($frozen, config('team_level_inc'), 6) , 0.0001, 6) == -1)
|
|
|
{
|
|
|
@@ -87,4 +131,6 @@ class CommonLogic
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
}
|