GroupController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Api\GroupService;
  5. use App\Services\Api\ImChatService;
  6. use App\Services\Api\MemberSettingService;
  7. use App\Services\Api\MessageService;
  8. /**
  9. * 群聊管理
  10. * @package App\Http\Controllers\Api
  11. */
  12. class GroupController extends webApp
  13. {
  14. /**
  15. * 我的群聊
  16. * @return array
  17. */
  18. public function index()
  19. {
  20. $params = request()->post();
  21. $pageSize = request()->post('pageSize', 12);
  22. $datas = GroupService::make()->getDataList($this->userId,$params,$pageSize);
  23. return showJson(1010, true, $datas);
  24. }
  25. /**
  26. * 聊天主页
  27. * @return array
  28. */
  29. public function create()
  30. {
  31. $params = request()->all();
  32. if(!$result = GroupService::make()->create($this->userId, $params)){
  33. return showJson(GroupService::make()->getError(), false);
  34. }else{
  35. return showJson(GroupService::make()->getError(), true, $result);
  36. }
  37. }
  38. /**
  39. * 群聊信息
  40. * @return array
  41. */
  42. public function info()
  43. {
  44. $id = request()->post('id',0);
  45. $info = GroupService::make()->getInfo($this->userId, $id);
  46. return showJson(1010, true, $info);
  47. }
  48. /**
  49. * 消息列表
  50. * @return array|mixed
  51. */
  52. public function history()
  53. {
  54. $params = request()->post();
  55. $pageSize = request()->post('pageSize', 20);
  56. $datas = MessageService::make()->getDataList($this->userId, $params, $pageSize);
  57. return showJson(1010, true, $datas);
  58. }
  59. /**
  60. * 修改消息设置参数
  61. * @return array
  62. */
  63. public function setting()
  64. {
  65. $params = request()->post();
  66. if(!$result = GroupService::make()->saveData($this->userId, $params)){
  67. return showJson(1020, false);
  68. }else{
  69. return showJson(1019, true);
  70. }
  71. }
  72. /**
  73. * 退出群聊
  74. * @return array
  75. */
  76. public function exitGroup()
  77. {
  78. $groupId = request()->post('group_id',0);
  79. if(!$result = GroupService::make()->exitGroup($this->userId, $groupId)){
  80. return showJson(1020, false);
  81. }else{
  82. return showJson(1019, true);
  83. }
  84. }
  85. /**
  86. * 踢出群成员
  87. * @return array
  88. */
  89. public function decUser()
  90. {
  91. $params = request()->post();
  92. if(!$result = GroupService::make()->decUser($this->userId, $params)){
  93. return showJson(GroupService::make()->getError(), false);
  94. }else{
  95. return showJson(GroupService::make()->getError(), true);
  96. }
  97. }
  98. /**
  99. * 添加群管理员
  100. * @return array
  101. */
  102. public function addManage()
  103. {
  104. $params = request()->post();
  105. if(!$result = GroupService::make()->addManage($this->userId, $params)){
  106. return showJson(GroupService::make()->getError(), false);
  107. }else{
  108. return showJson(GroupService::make()->getError(), true);
  109. }
  110. }
  111. /**
  112. * 删除群管理员
  113. * @return array
  114. */
  115. public function decManage()
  116. {
  117. $params = request()->post();
  118. if(!$result = GroupService::make()->decManage($this->userId, $params)){
  119. return showJson(GroupService::make()->getError(), false);
  120. }else{
  121. return showJson(GroupService::make()->getError(), true);
  122. }
  123. }
  124. /**
  125. * 邀请群成员
  126. * @return array
  127. */
  128. public function addUser()
  129. {
  130. $params = request()->post();
  131. if(!$result = GroupService::make()->addUser($this->userId, $params)){
  132. return showJson(GroupService::make()->getError(), false);
  133. }else{
  134. return showJson(GroupService::make()->getError(), true);
  135. }
  136. }
  137. /**
  138. * 邀请进群
  139. * @return array
  140. */
  141. public function invite()
  142. {
  143. $groupId = request()->post('group_id',0);
  144. if(!$result = GroupService::make()->invite($this->userId, $groupId)){
  145. return showJson(GroupService::make()->getError(), false);
  146. }else{
  147. return showJson(GroupService::make()->getError(), true);
  148. }
  149. }
  150. /**
  151. * 聊天清除消息历史
  152. * @return array
  153. */
  154. public function clear()
  155. {
  156. $groupId = request()->post('group_id',0);
  157. if(!$result = GroupService::make()->clear($this->userId, $groupId)){
  158. return showJson(1003, false);
  159. }else{
  160. return showJson(1002, true);
  161. }
  162. }
  163. public function delete()
  164. {
  165. $groupId = request()->post('group_id',0);
  166. if(!$result = GroupService::make()->deleteGroup($this->userId, $groupId)){
  167. return showJson(1003, false);
  168. }else{
  169. return showJson(1002, true);
  170. }
  171. }
  172. }