Punish.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace App\Module\Ulogic;
  3. use App\Module\App\SessionApp;
  4. use App\Module\Ulogic\Enum\PUNISH_TYPE;
  5. use App\Module\Ulogic\logic\PunishGroup;
  6. use App\Module\Ulogic\logic\PunishLevel;
  7. use App\Module\Ulogic\Model\UserPunish;
  8. use App\Module\User\Services\ActionService;
  9. use UCore\Helper\Logger;
  10. /**
  11. * 违规记录
  12. *
  13. */
  14. class Punish
  15. {
  16. /**
  17. * 增加一个违规记录
  18. * @param $admin_id
  19. * @param $user_id
  20. * @param PUNISH_TYPE $type
  21. * @param $desc
  22. * @param $level
  23. * @return UserPunish
  24. */
  25. static public function push($admin_id, $user_id, PUNISH_TYPE $type, $desc)
  26. {
  27. $level = PunishLevel::levelMatch($type);
  28. $model = new UserPunish();
  29. $model->user_id = $user_id;
  30. $model->admin_id = $admin_id;
  31. $model->type = $type;
  32. $model->desc = $desc;
  33. $model->level = $level;
  34. // $model->status = 1;
  35. $model->save();
  36. \App\Jobs\UserPunish::dispatch($user_id,$type)->delay(2);
  37. return $model;
  38. }
  39. /**
  40. * 用户违规处理
  41. * @param $user_id
  42. * @return void
  43. */
  44. static public function call_user($user_id, PUNISH_TYPE $type,$admin_id,$desc)
  45. {
  46. list($group, $win) = PunishGroup::groupMatch($type);
  47. $level = PunishLevel::levelMatch($type);
  48. $groupCount = UserPunish::query()->where('user_id', $user_id)
  49. ->whereIn('type', $win)
  50. ->count();
  51. $levelCount = UserPunish::query()->where('user_id', $user_id)
  52. ->where('level', '=', $level)
  53. ->count();
  54. switch ($group) {
  55. case \App\Module\Ulogic\Enum\PUNISH_GROUP::Group1->value():
  56. self::call_user1($user_id, $groupCount,$levelCount,$admin_id,$desc);
  57. break;
  58. case \App\Module\Ulogic\Enum\PUNISH_GROUP::Group2->value():
  59. //直接封号
  60. self::call_user2($user_id, $groupCount,$levelCount,$admin_id,$desc);
  61. break;
  62. }
  63. }
  64. /**
  65. * 分组1的处理
  66. * @param $user_id
  67. * @param $groupCount
  68. * @param $levelCount
  69. * @return void
  70. */
  71. static protected function call_user1($user_id, $groupCount ,$levelCount,$admin_id,$desc)
  72. {
  73. Logger::info('Punish-call_user1',[$groupCount,$user_id,$levelCount,$admin_id,$desc]);
  74. if($groupCount >= 3 ){
  75. // 三次普通违规,封号
  76. ActionService::ban($admin_id, $user_id, $desc, '0', 'Punish');
  77. }
  78. }
  79. /**
  80. * 分组2 的处理
  81. * @param $user_id
  82. * @param $groupCount
  83. * @param $levelCount
  84. * @param $admin_id
  85. * @param $desc
  86. * @return void
  87. */
  88. static protected function call_user2($user_id, $groupCount, $levelCount, $admin_id, $desc)
  89. {
  90. // dd($user_id, $groupCount,$levelCount);
  91. if ($groupCount >= 1) {
  92. // 1次违规,封号
  93. ActionService::ban($admin_id, $user_id, $desc, '0', 'Punish', 3153600000);
  94. SessionApp::removeUKeys($user_id);
  95. }
  96. }
  97. }