123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- namespace App\Services\Complain;
- use App\Exceptions\AlertException;
- use App\Models\ComplaintModel;
- use App\Models\User\UserModel;
- abstract class ComplaintHandle
- {
- public $complaint;
- public $be_user;
- public $fields = [];
- public $field;
- public $value = null;
- public $state;
- public $reply_state;
- public $reply_content;
- /**
- * 拉黑的类型
- * @var int $defriend_state
- */
- public $defriend_state;
- protected $check = [
- "photo_src" => "check_photo",
- "photo_1" => "photo_1_check",
- "photo_2" => "photo_2_check",
- "photo_3" => "photo_3_check",
- "photo_4" => "photo_4_check",
- "voice" => "voice_check",
- ];
- protected $user;
- protected $data;
- /**
- * 拉黑时间
- * @defriend_at int
- */
- protected $defriend_at;
- public function __construct(ComplaintModel $complaint)
- {
- $this->complaint = $complaint;
- }
- public static function make($id)
- {
- $complaint = ComplaintModel::findOrFail($id);
- switch ($complaint->type) {
- case "partner":
- return new PartnerComplaintHandle($complaint);
- break;
- case "contact":
- return new ContactComplaintHandle($complaint);
- break;
- case "pair":
- return new PairComplaintHandle($complaint);
- break;
- case "game":
- return new GameComplaintHandle($complaint);
- break;
- case "goodnight":
- return new GoodnightComplaintHandle($complaint);
- break;
- default:
- throw new \Exception("举报类型异常", 500);
- }
- }
- /**
- * 获取举报人
- */
- public function getUser()
- {
- $this->user = UserModel::findOrFail($this->complaint->uid);
- return $this->user;
- }
- /**
- * 获取被举报人
- */
- public function getBeUser()
- {
- $this->be_user = UserModel::findOrFail($this->complaint->be_uid);
- return $this->be_user;
- }
- public function setField($field)
- {
- array_push($this->fields, $field);
- }
- /**
- * 删除或修改字段
- * @return mixed
- */
- abstract public function erasing();
- /**
- * 举报
- * @return mixed
- */
- abstract public function reply();
- /**
- * 处理举报
- * @throws AlertException
- */
- public function updateState()
- {
- if ($this->complaint->reply_at > 0) {
- throw new AlertException("举报已经处理", 411);
- }
- $this->complaint->state = $this->state;
- $this->complaint->reply_content = $this->reply_content;
- $this->complaint->reply_at = time();
- $this->complaint->save();
- }
- /**
- * 设置拉黑时间
- * @param int $state
- */
- public function setDefriend(int $state)
- {
- switch ($state) {
- case "1":
- $this->defriend_at = time() + 7 * 24 * 3600;
- break;
- case "2":
- $this->defriend_at = time() + 30 * 24 * 3600;
- break;
- case "3":
- $this->defriend_at = 1893427200;
- break;
- }
- $this->defriend_state = $state;
- }
- public function getDefriendAt()
- {
- return $this->defriend_at;
- }
- /**
- * 拉黑
- * @return mixed
- */
- abstract public function defriend();
- }
|