MailController.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace frontend\modules\api\controllers;
  3. use common\components\AjaxException;
  4. use common\services\MailService;
  5. use frontend\modules\api\components\BaseAdminController;
  6. class MailController extends BaseAdminController
  7. {
  8. public function actionList(int $current = 1, int $page = 10)
  9. {
  10. $query = MailService::getMailAllQuery()
  11. ->limit($page)
  12. ->offset(($current - 1) * $page);
  13. //排序
  14. $this->initSequence($query);
  15. $query = $this->addConditionToQuery("receiver", $query, true);
  16. $query = $this->addConditionToQuery("receiver_name", $query, true);
  17. $query = $this->addStartEndConditionToQuery("start_time", $query);
  18. $query = $this->addConditionToQuery("case_type", $query);
  19. $query = $this->addConditionToQuery("status", $query);
  20. $data['data'] = $query->all();
  21. $data['total'] = $query->count();
  22. return $this->asJson($data);
  23. }
  24. public function actionMyList(int $current = 1, int $page = 10)
  25. {
  26. $query = MailService::getMailQuery()
  27. ->limit($page)
  28. ->offset(($current - 1) * $page);
  29. //排序
  30. $this->initSequence($query);
  31. $query = $query->andWhere(["receiver" => $this->userInfo->username]);
  32. $query = $this->addStartEndConditionToQuery("start_time", $query);
  33. $query = $this->addConditionToQuery("case_type", $query);
  34. $query = $this->addConditionToQuery("status", $query);
  35. $data['data'] = $query->all();
  36. $data['total'] = $query->count();
  37. return $this->asJson($data);
  38. }
  39. /**
  40. * @throws AjaxException
  41. */
  42. public function actionReadMessage($id)
  43. {
  44. MailService::readMessage($id, $this->userInfo);
  45. return $this->asJson();
  46. }
  47. /**
  48. * @throws AjaxException
  49. */
  50. public function actionDelete($id)
  51. {
  52. MailService::delete($id, $this->userInfo);
  53. return $this->asJson();
  54. }
  55. public function actionGetUnreadMessagesNumber()
  56. {
  57. $data = MailService::getUnreadMessagesNumber($this->userInfo);
  58. return $this->asJson($data);
  59. }
  60. }