MessageController.php 4.0 KB

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