MessageService.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace app\api\servies\message;
  3. use app\api\response\ZskkErrorResponse;
  4. use app\api\servies\ZskkDefaultService;
  5. use app\api\validate\message\MessageValidate;
  6. use app\api\dao\message\MessageDao;
  7. use app\api\servies\common\CommonService;
  8. use think\facade\Log;
  9. use think\Exception;
  10. /**
  11. * 后台控制器基类
  12. * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
  13. */
  14. class MessageService extends ZskkDefaultService {
  15. protected $logName = "MessageService";
  16. private $message = null;
  17. public function __construct(MessageDao $messageDao) {
  18. parent::__construct();
  19. $this->message = $messageDao;
  20. }
  21. public function getMessageList($params,$token)
  22. {
  23. $user = $this->message->getUser($token);
  24. $info = $this->message->getMessageList($params,$user['id']);
  25. return $info;
  26. }
  27. public function handleAllRead($token)
  28. {
  29. try{
  30. $user = $this->message->getUser($token);
  31. $res = $this->message->readMessage($user['id'],$user);
  32. if(!$res){
  33. $this->throwError('修改失败',0016);
  34. }
  35. return $res;
  36. }catch (Exception $exception){
  37. $this->throwError($exception->getMessage(),0001);
  38. }
  39. }
  40. public function unRead($token)
  41. {
  42. try{
  43. $user = $this->message->getUser($token);
  44. $res = $this->message->unReadMessage($user['id'],$user['institution_id']);
  45. // $message = $this->message->getUnReadList($user['institution_id']);
  46. // if($message > 0){
  47. // $notice = 1;
  48. // }
  49. $list = $this->message->getAppUnread($user['id'],$user['institution_id']);
  50. $data = [
  51. 'all_unread'=>$res,
  52. 'list'=>$list
  53. ];
  54. return $data;
  55. }catch (Exception $exception){
  56. $this->throwError($exception->getMessage(),0001);
  57. }
  58. }
  59. public function handleDelRead($token)
  60. {
  61. try{
  62. $user = $this->message->getUser($token);
  63. $res = $this->message->delReadMessage($user['id']);
  64. if(!$res){
  65. $this->throwError('修改失败',0016);
  66. }
  67. return $res;
  68. }catch (Exception $exception){
  69. $this->throwError($exception->getMessage(),0001);
  70. }
  71. }
  72. public function handleDelAll($token)
  73. {
  74. try{
  75. $user = $this->message->getUser($token);
  76. $res = $this->message->delAllMessage($user['id'],$user);
  77. if(!$res){
  78. $this->throwError('修改失败',0016);
  79. }
  80. return $res;
  81. }catch (Exception $exception){
  82. $this->throwError($exception->getMessage(),0001);
  83. }
  84. }
  85. public function read($id,$token)
  86. {
  87. try{
  88. $user = $this->message->getUser($token);
  89. $res = $this->message->read($id,$user);
  90. if(!$res){
  91. $this->throwError('修改失败',0016);
  92. }
  93. return $res;
  94. }catch (Exception $exception){
  95. $this->throwError($exception->getMessage(),0001);
  96. }
  97. }
  98. public function getInfo($id,$token)
  99. {
  100. try{
  101. $user = $this->message->getUser($token);
  102. $res = $this->message->getInfo($id,$user);
  103. if(!$res){
  104. $this->throwError('获取失败',0017);
  105. }
  106. return $res;
  107. }catch (Exception $exception){
  108. $this->throwError($exception->getMessage(),0001);
  109. }
  110. }
  111. public function deleteone($id,$token)
  112. {
  113. try{
  114. $user = $this->message->getUser($token);
  115. $res = $this->message->deleteone($id,$user);
  116. if(!$res){
  117. $this->throwError('删除失败',0020);
  118. }
  119. return $res;
  120. }catch (Exception $exception){
  121. $this->throwError($exception->getMessage(),0001);
  122. }
  123. }
  124. public function getSpecialMessage($token)
  125. {
  126. $user = $this->message->getUser($token);
  127. $message = $this->message->getSpecialMessage($user['institution_id']);
  128. if(empty($message))
  129. {
  130. return ['code'=>0,'message'=>''];
  131. }else{
  132. return ['code'=>1,'message'=>$message];
  133. }
  134. }
  135. }