| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace app\api\logic;
- use Exception;
- use think\Env;
- use fast\Asset;
- use think\Loader;
- use app\common\model\UserModel;
- use app\common\model\UserPledge;
- use app\common\model\UserPathModel;
- use app\common\model\LedgerWalletModel;
- use app\common\model\LedgerTokenChangeModel;
- use app\common\model\LedgerFrozenChangeModel;
- //公共
- class CommonLogic
- {
- // 升级降级
- public static function setIsLevelSave(int $user_id, int $team_level_id, int $address_level, int $num): bool
- {
- $config = config('team_level_where');
- if($team_level_id == count($config)) return false;
- $result = false;
- if($team_level_id == 0){
- if($address_level >= $config[$team_level_id]['direct']) {
- $result = true;
- $team_level_id += 1;
- }
- }else{
- //直推
- $teamCount = UserModel::where('parent_id', $user_id)->where('team_level_id', $team_level_id)->count();
- //组合套数
- $groupCount = UserPledge::getPledgeCount($user_id) + $num;
- if($team_level_id == 1 && ($groupCount == 0 || $address_level < $config[0]['direct'])){
- $result = true;
- $team_level_id = 0;
- }
- //大于1
- if($team_level_id > 1){
- 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
- }
- }
-
- }
- return $result? UserModel::where('id', $user_id)->update(['team_level_id'=> $team_level_id]): false;
- }
-
- //发放层级收益
- public static function setTeamLevelIncome(int $user_id, float $num, int $team_level_id, 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');
- if(count($paths) > 0){
- //收益
- $income = bcmul($num, config('team_level_inc'), 2);
- //余额记录
- foreach($paths as $pathId){
- Loader::model('LedgerWalletModel')->changeWalletAccount($pathId, $asset, $income, $action, $user_id);
- }
- }
- return true;
- }
- //判断发放茶宝数量
- public static function getFrozenIsChabao($token, $frozen)
- {
- //标记茶宝
- if(bccomp(bcmul($frozen, config('team_level_inc'), 6) , 0.0001, 6) == -1)
- {
- return [$token, Asset::TOKEN, LedgerTokenChangeModel::TeamLevel];
- }else{
- //标记茶宝
- return [$frozen, Asset::FROZEN, LedgerFrozenChangeModel::TeamLevel];
- }
- }
- }
|