| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace App\Module\Ulogic;
- use App\Module\App\SessionApp;
- use App\Module\Ulogic\Enum\PUNISH_TYPE;
- use App\Module\Ulogic\logic\PunishGroup;
- use App\Module\Ulogic\logic\PunishLevel;
- use App\Module\Ulogic\Model\UserPunish;
- use App\Module\User\Action;
- use Dcat\Admin\Http\Middleware\Session;
- use UCore\Helper\Logger;
- use Illuminate\Support\Facades\DB;
- /**
- * 违规记录
- *
- */
- class Punish
- {
- /**
- * 增加一个违规记录
- * @param $admin_id
- * @param $user_id
- * @param PUNISH_TYPE $type
- * @param $desc
- * @param $level
- * @return UserPunish
- */
- static public function push($admin_id, $user_id, PUNISH_TYPE $type, $desc)
- {
- $level = PunishLevel::levelMatch($type);
- $model = new UserPunish();
- $model->user_id = $user_id;
- $model->admin_id = $admin_id;
- $model->type = $type;
- $model->desc = $desc;
- $model->level = $level;
- // $model->status = 1;
- $model->save();
- \App\Jobs\UserPunish::dispatch($user_id,$type)->delay(2);
- return $model;
- }
- /**
- * 用户违规处理
- * @param $user_id
- * @return void
- */
- static public function call_user($user_id, PUNISH_TYPE $type,$admin_id,$desc)
- {
- list($group, $win) = PunishGroup::groupMatch($type);
- $level = PunishLevel::levelMatch($type);
- $groupCount = UserPunish::query()->where('user_id', $user_id)
- ->whereIn('type', $win)
- ->count();
- $levelCount = UserPunish::query()->where('user_id', $user_id)
- ->where('level', '=', $level)
- ->count();
- switch ($group) {
- case \App\Module\Ulogic\Enum\PUNISH_GROUP::Group1->value():
- self::call_user1($user_id, $groupCount,$levelCount,$admin_id,$desc);
- break;
- case \App\Module\Ulogic\Enum\PUNISH_GROUP::Group2->value():
- //直接封号
- self::call_user2($user_id, $groupCount,$levelCount,$admin_id,$desc);
- break;
- }
- }
- /**
- * 分组1的处理
- * @param $user_id
- * @param $groupCount
- * @param $levelCount
- * @return void
- */
- static protected function call_user1($user_id, $groupCount ,$levelCount,$admin_id,$desc)
- {
- Logger::info('Punish-call_user1',[$groupCount,$user_id,$levelCount,$admin_id,$desc]);
- if($groupCount >= 3 ){
- // 三次普通违规,封号
- Action::ban($admin_id,$user_id,$desc,'0','Punish');
- }
- }
- /**
- * 分组2 的处理
- * @param $user_id
- * @param $groupCount
- * @param $levelCount
- * @param $admin_id
- * @param $desc
- * @return void
- */
- static protected function call_user2($user_id, $groupCount, $levelCount, $admin_id, $desc)
- {
- // dd($user_id, $groupCount,$levelCount);
- if ($groupCount >= 1) {
- // 1次违规,封号
- Action::ban($admin_id, $user_id, $desc, '0', 'Punish',3153600000);
- SessionApp::removeUKeys($user_id);
- }
- }
- }
|