admin_id = $admin_id; $model->desc = $desc; $model->user_id = $user_id; $model->re_id = $re_id; $model->re_type = $re_type; $model->type =$type; if($exp){ $model->exp_time = time()+$exp; $model->status = ACTION_STATUS::ING; }else{ $model->exp_time = 0; $model->status = ACTION_STATUS::OK; } if(! $model->save()){ throw new \LogicException("user - Action save type error. "); } $list = [ ACTION_TYPE::RESTRICT->value() => STATUS2::Restrict->value(), ACTION_TYPE::NORMAL->value() => STATUS2::Normal->value(), ACTION_TYPE::DELETE->value() => STATUS2::Deleteing->value(), ACTION_TYPE::BAN->value() => STATUS2::Ban->value(), ]; $status = $list[$type->value()]??null; if(is_null($status)){ throw new \LogicException("user - Action call_type type error. "); } // 处理账号 $info = UserService::info($user_id, true); $info->status2 = $status; if( ! $info->save()){ throw new \LogicException("user - Action save error. "); } if($type === ACTION_TYPE::NORMAL){ // 正常化处理,需要解除进行中的惩罚 // 没有过期时间的 UserAction::query() ->where('user_id',$user_id) ->where('status',ACTION_STATUS::OK) ->whereNotIn('type',[ACTION_TYPE::NORMAL]) ->update([ 'status'=>ACTION_STATUS::END->value ]); // 生效中 UserAction::query() ->where('user_id',$user_id) ->where('status',ACTION_STATUS::ING) ->whereNotIn('type',[ACTION_TYPE::NORMAL]) ->update([ 'status'=>ACTION_STATUS::END->value ]); } Logger::info('type',[$type->value()]); if($type === ACTION_TYPE::BAN){ // 禁止 Logger::info('ban'); SessionApp::removeUKeys($user_id); } if($type === ACTION_TYPE::RESTRICT){ // 限制登陆 Logger::info('Restrict'); SessionApp::removeUKeys($user_id); } return $model; } /** * 过期时间处理 * * @return void */ static public function outtime() { $time = time(); /** * @var UserAction[] $list */ $list = UserAction::query() ->where('status', ACTION_STATUS::ING) ->where('exp_time','>',0) ->where('exp_time','<',$time) ->limit(10) ->get(); // dump($list); foreach ($list as $item){ try { DB::beginTransaction(); $item->status = ACTION_STATUS::OUT_TIME; $item->save(); self::callItem($item); DB::commit(); }catch (\Exception $exception){ DB::rollBack(); Logger::exception("user-Action-outtime",$exception); } } } /** * 处理过去 * @param UserAction $action * @return void */ static private function callItem(UserAction $action) { $type = $action->type->value(); // 判断是否存在其他生效的禁令 $lsit = UserAction::query() ->where('status', '=', ACTION_STATUS::ING) ->where('user_id','=',$action->user_id) ->where('type','=', $action->type) ->where(function ( \Illuminate\Database\Eloquent\Builder $builder) { $builder->orWhere('exp_time', '=', 0) ->orWhere('exp_time', '>', time()); })->get(); // ->get(); // dd($lsit->toSql()); if($lsit->count()){ // 有其他禁令生效 Logger::info("callItem $action->id $type have other. "); return; } $info = UserService::infoinfo($action->user_id, true); if($action->type === ACTION_TYPE::BAN){ if($info->status2 === STATUS2::Ban){ // 接触 封禁 self::call_type(\App\Module\Sys\Admin::AUTO_BOT,$action->user_id,"到期自动解除-封禁",$action->id,'ActionAuto',ACTION_TYPE::NORMAL,0); Logger::info("callItem $action->id $type ban ->Normal "); }else{ Logger::info("callItem $action->id $type now no ban "); } } if($action->type === ACTION_TYPE::RESTRICT){ if($info->status2 === STATUS2::Restrict){ // 接触禁止登录 self::call_type(\App\Module\Sys\Admin::AUTO_BOT,$action->user_id,"到期自动解除-限制登录",$action->id,'ActionAuto',ACTION_TYPE::NORMAL); Logger::info("callItem $action->id $type Restrict ->Normal "); }else{ Logger::info("callItem $action->id $type now no Restrict "); } } } }