MessageController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Api\ImChatService;
  5. use App\Services\Api\MemberSettingService;
  6. use App\Services\Api\MessageService;
  7. use App\Services\ZegoService;
  8. /**
  9. * 消息管理
  10. * Class MessageController
  11. * @package App\Http\Controllers\Api
  12. */
  13. class MessageController extends webApp
  14. {
  15. /**
  16. * 聊天主页
  17. * @return array
  18. */
  19. public function index()
  20. {
  21. $datas = MessageService::make()->getGroupList($this->userId);
  22. return message(1010, true, $datas);
  23. }
  24. /**
  25. * 消息列表
  26. * @return array|mixed
  27. */
  28. public function history()
  29. {
  30. $params = request()->post();
  31. $pageSize = request()->post('pageSize', 20);
  32. $datas = MessageService::make()->getDataList($this->userId, $params, $pageSize);
  33. return message(1010, true, $datas);
  34. }
  35. /**
  36. * 聊天分组数据
  37. * @return array
  38. */
  39. public function chatGroupList()
  40. {
  41. $params = request()->post();
  42. $pageSize = request()->post('pageSize', 20);
  43. $datas = MessageService::make()->getDataListFromatKey($this->userId, $params, $pageSize);
  44. return message(1010, true, $datas);
  45. }
  46. /**
  47. * 消息参数
  48. * @return array
  49. */
  50. public function getSetting()
  51. {
  52. $datas = MemberSettingService::make()->getSetting($this->userId);
  53. if(empty($datas)){
  54. $datas = [
  55. 'receive_app'=> 1,
  56. 'receive_custom'=> 1,
  57. 'receive_order'=> 1,
  58. 'receive_account'=> 1,
  59. ];
  60. }
  61. return message(1010, true, $datas);
  62. }
  63. /**
  64. * 修改消息设置参数
  65. * @return array
  66. */
  67. public function setSetting()
  68. {
  69. $params = request()->post();
  70. if(!$result = MemberSettingService::make()->setMsgData($this->userId, $params)){
  71. return message(1020, false);
  72. }else{
  73. return message(1019, true);
  74. }
  75. }
  76. /**
  77. * 设置已读
  78. * @return array
  79. */
  80. public function setRead()
  81. {
  82. $chatKey = request()->post('chat_key','');
  83. $type = request()->post('type',0);
  84. if(!$result = MessageService::make()->setRead($this->userId, $type, $chatKey)){
  85. return message(1020, false);
  86. }else{
  87. return message(1019, true);
  88. }
  89. }
  90. /**
  91. * 隐藏
  92. * @return array
  93. */
  94. public function setHide()
  95. {
  96. $chatKey = request()->post('chat_key','');
  97. $type = request()->post('type',1);
  98. $msgType = request()->post('msg_type',1);
  99. if($type == 1){
  100. if(!$result = MessageService::make()->setHide($this->userId, $msgType)){
  101. return message(1020, false);
  102. }else{
  103. return message(1019, true);
  104. }
  105. }else if($type == 2){
  106. if(!$result = ImChatService::make()->setHide($this->userId, $chatKey)){
  107. return message(1020, false);
  108. }else{
  109. return message(1019, true);
  110. }
  111. }
  112. return message(1020, false);
  113. }
  114. /**
  115. * 聊天清除消息历史
  116. * @return array
  117. */
  118. public function clear()
  119. {
  120. $chatKey = request()->post('chat_key','');
  121. $type = request()->post('msg_type', 0);
  122. if(!$result = MessageService::make()->clear($this->userId, $chatKey, $type)){
  123. return message(1003, false);
  124. }else{
  125. return message(1002, true);
  126. }
  127. }
  128. /**
  129. * 聊天清除消息历史
  130. * @return array
  131. */
  132. public function clearAll()
  133. {
  134. $type = request()->post('type', 1);
  135. if(!$result = ImChatService::make()->clearAll($this->userId, $type)){
  136. return message(1003, false);
  137. }else{
  138. return message(1002, true);
  139. }
  140. }
  141. /**
  142. * 未读消息
  143. * @return array
  144. */
  145. public function unread()
  146. {
  147. $result = MessageService::make()->getUnreadCount($this->userId);
  148. return message(1010, true, $result);
  149. }
  150. }