MessageController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 showJson(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 showJson(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 showJson(1010, true, $datas);
  44. }
  45. /**
  46. * 聊天分组数据
  47. * @return array
  48. */
  49. public function chatGroupList()
  50. {
  51. $params = request()->post();
  52. // $pageSize = request()->post('pageSize', 30);
  53. $datas = MessageService::make()->getDataListFromatKey($this->userId, $params, 0);
  54. return showJson(1010, true, $datas);
  55. }
  56. /**
  57. * 分享
  58. * @return array
  59. */
  60. public function share()
  61. {
  62. $params = request()->post();
  63. if(!$result = MessageService::make()->share($this->userId, $params)){
  64. return showJson(MessageService::make()->getError(), false);
  65. }else{
  66. return showJson(MessageService::make()->getError(), true, $result);
  67. }
  68. }
  69. /**
  70. * 消息参数
  71. * @return array
  72. */
  73. public function getSetting()
  74. {
  75. $datas = MemberSettingService::make()->getSetting($this->userId);
  76. if(empty($datas)){
  77. $datas = [
  78. 'receive_app'=> 1,
  79. 'receive_custom'=> 1,
  80. 'receive_order'=> 1,
  81. 'receive_account'=> 1,
  82. ];
  83. }
  84. return showJson(1010, true, $datas);
  85. }
  86. /**
  87. * 修改消息设置参数
  88. * @return array
  89. */
  90. public function setSetting()
  91. {
  92. $params = request()->post();
  93. if(!$result = MemberSettingService::make()->setMsgData($this->userId, $params)){
  94. return showJson(1020, false);
  95. }else{
  96. return showJson(1019, true);
  97. }
  98. }
  99. /**
  100. * 设置已读
  101. * @return array
  102. */
  103. public function setRead()
  104. {
  105. $chatKey = request()->post('chat_key','');
  106. $type = request()->post('type',0);
  107. $groupId = request()->post('group_id',0);
  108. if(!$result = MessageService::make()->setRead($this->userId, $type, $chatKey,$groupId)){
  109. return showJson(1020, false);
  110. }else{
  111. return showJson(1019, true);
  112. }
  113. }
  114. /**
  115. * 隐藏
  116. * @return array
  117. */
  118. public function setHide()
  119. {
  120. $chatKey = request()->post('chat_key','');
  121. $type = request()->post('type',1);
  122. $msgType = request()->post('msg_type',1);
  123. if($type == 1){
  124. if(!$result = MessageService::make()->setHide($this->userId, $msgType)){
  125. return showJson(1020, false);
  126. }else{
  127. return showJson(1019, true);
  128. }
  129. }else if($type == 2){
  130. if(!$result = ImChatService::make()->setHide($this->userId, $chatKey)){
  131. return showJson(1020, false);
  132. }else{
  133. return showJson(1019, true);
  134. }
  135. }
  136. return showJson(1020, false);
  137. }
  138. /**
  139. * 聊天清除消息历史
  140. * @return array
  141. */
  142. public function clear()
  143. {
  144. $chatKey = request()->post('chat_key','');
  145. $type = request()->post('msg_type', 0);
  146. $groupId = request()->post('group_id', 0);
  147. if(!$result = MessageService::make()->clear($this->userId, $chatKey, $type, $groupId)){
  148. return showJson(1003, false);
  149. }else{
  150. return showJson(1002, true);
  151. }
  152. }
  153. /**
  154. * 聊天清除消息历史
  155. * @return array
  156. */
  157. public function clearAll()
  158. {
  159. $type = request()->post('type', 0);
  160. if(!$result = MessageService::make()->clearAll($this->userId, $type)){
  161. return showJson(1003, false);
  162. }else{
  163. return showJson(1002, true);
  164. }
  165. }
  166. /**
  167. * 未读消息
  168. * @return array
  169. */
  170. public function unread()
  171. {
  172. $result = MessageService::make()->getUnreadCount($this->userId);
  173. return showJson(1010, true, $result);
  174. }
  175. }