Punish.php 3.0 KB

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