ComplaintHandle.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. namespace App\Services\Complain;
  3. use App\Exceptions\AlertException;
  4. use App\Models\ComplaintModel;
  5. use App\Models\User\UserModel;
  6. abstract class ComplaintHandle
  7. {
  8. public $complaint;
  9. public $be_user;
  10. public $fields = [];
  11. public $field;
  12. public $value = null;
  13. public $state;
  14. public $reply_state;
  15. public $reply_content;
  16. /**
  17. * 拉黑的类型
  18. * @var int $defriend_state
  19. */
  20. public $defriend_state;
  21. protected $check = [
  22. "photo_src" => "check_photo",
  23. "photo_1" => "photo_1_check",
  24. "photo_2" => "photo_2_check",
  25. "photo_3" => "photo_3_check",
  26. "photo_4" => "photo_4_check",
  27. "voice" => "voice_check",
  28. ];
  29. protected $user;
  30. protected $data;
  31. /**
  32. * 拉黑时间
  33. * @defriend_at int
  34. */
  35. protected $defriend_at;
  36. public function __construct(ComplaintModel $complaint)
  37. {
  38. $this->complaint = $complaint;
  39. }
  40. public static function make($id)
  41. {
  42. $complaint = ComplaintModel::findOrFail($id);
  43. switch ($complaint->type) {
  44. case "partner":
  45. return new PartnerComplaintHandle($complaint);
  46. break;
  47. case "contact":
  48. return new ContactComplaintHandle($complaint);
  49. break;
  50. case "pair":
  51. return new PairComplaintHandle($complaint);
  52. break;
  53. case "game":
  54. return new GameComplaintHandle($complaint);
  55. break;
  56. case "goodnight":
  57. return new GoodnightComplaintHandle($complaint);
  58. break;
  59. default:
  60. throw new \Exception("举报类型异常", 500);
  61. }
  62. }
  63. /**
  64. * 获取举报人
  65. */
  66. public function getUser()
  67. {
  68. $this->user = UserModel::findOrFail($this->complaint->uid);
  69. return $this->user;
  70. }
  71. /**
  72. * 获取被举报人
  73. */
  74. public function getBeUser()
  75. {
  76. $this->be_user = UserModel::findOrFail($this->complaint->be_uid);
  77. return $this->be_user;
  78. }
  79. public function setField($field)
  80. {
  81. array_push($this->fields, $field);
  82. }
  83. /**
  84. * 删除或修改字段
  85. * @return mixed
  86. */
  87. abstract public function erasing();
  88. /**
  89. * 举报
  90. * @return mixed
  91. */
  92. abstract public function reply();
  93. /**
  94. * 处理举报
  95. * @throws AlertException
  96. */
  97. public function updateState()
  98. {
  99. if ($this->complaint->reply_at > 0) {
  100. throw new AlertException("举报已经处理", 411);
  101. }
  102. $this->complaint->state = $this->state;
  103. $this->complaint->reply_content = $this->reply_content;
  104. $this->complaint->reply_at = time();
  105. $this->complaint->save();
  106. }
  107. /**
  108. * 设置拉黑时间
  109. * @param int $state
  110. */
  111. public function setDefriend(int $state)
  112. {
  113. switch ($state) {
  114. case "1":
  115. $this->defriend_at = time() + 7 * 24 * 3600;
  116. break;
  117. case "2":
  118. $this->defriend_at = time() + 30 * 24 * 3600;
  119. break;
  120. case "3":
  121. $this->defriend_at = 1893427200;
  122. break;
  123. }
  124. $this->defriend_state = $state;
  125. }
  126. public function getDefriendAt()
  127. {
  128. return $this->defriend_at;
  129. }
  130. /**
  131. * 拉黑
  132. * @return mixed
  133. */
  134. abstract public function defriend();
  135. }