MessageController.php 4.3 KB

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