| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <?php
- namespace App\Http\Controllers\Api\v1;
- use App\Http\Controllers\Api\webApp;
- use App\Services\Api\ImChatService;
- use App\Services\Api\MemberSettingService;
- use App\Services\Api\MessageService;
- /**
- * 消息管理
- * Class MessageController
- * @package App\Http\Controllers\Api
- */
- class MessageController extends webApp
- {
- /**
- * 聊天主页
- * @return array
- */
- public function index()
- {
- $datas = MessageService::make()->getGroupList($this->userId);
- return showJson(1010, true, $datas);
- }
- /**
- * 消息列表
- * @return array|mixed
- */
- public function history()
- {
- $params = request()->post();
- $pageSize = request()->post('pageSize', 20);
- $datas = MessageService::make()->getDataList($this->userId, $params, $pageSize);
- return showJson(1010, true, $datas);
- }
- /**
- * 直播消息列表
- * @return array|mixed
- */
- public function live()
- {
- $params = request()->post();
- $pageSize = request()->post('pageSize', 20);
- $datas = MessageService::make()->getLiveDataList($this->userId, $params, $pageSize);
- return showJson(1010, true, $datas);
- }
- /**
- * 聊天分组数据
- * @return array
- */
- public function chatGroupList()
- {
- $params = request()->post();
- // $pageSize = request()->post('pageSize', 30);
- $datas = MessageService::make()->getDataListFromatKey($this->userId, $params, 0);
- return showJson(1010, true, $datas);
- }
- /**
- * 分享
- * @return array
- */
- public function share()
- {
- $params = request()->post();
- if(!$result = MessageService::make()->share($this->userId, $params)){
- return showJson(MessageService::make()->getError(), false);
- }else{
- return showJson(MessageService::make()->getError(), true, $result);
- }
- }
- /**
- * 消息参数
- * @return array
- */
- public function getSetting()
- {
- $datas = MemberSettingService::make()->getSetting($this->userId);
- if(empty($datas)){
- $datas = [
- 'receive_app'=> 1,
- 'receive_custom'=> 1,
- 'receive_order'=> 1,
- 'receive_account'=> 1,
- ];
- }
- return showJson(1010, true, $datas);
- }
- /**
- * 修改消息设置参数
- * @return array
- */
- public function setSetting()
- {
- $params = request()->post();
- if(!$result = MemberSettingService::make()->setMsgData($this->userId, $params)){
- return showJson(1020, false);
- }else{
- return showJson(1019, true);
- }
- }
- /**
- * 设置已读
- * @return array
- */
- public function setRead()
- {
- $chatKey = request()->post('chat_key','');
- $type = request()->post('type',0);
- $groupId = request()->post('group_id',0);
- if(!$result = MessageService::make()->setRead($this->userId, $type, $chatKey,$groupId)){
- return showJson(1020, false);
- }else{
- return showJson(1019, true);
- }
- }
- /**
- * 隐藏
- * @return array
- */
- public function setHide()
- {
- $chatKey = request()->post('chat_key','');
- $type = request()->post('type',1);
- $msgType = request()->post('msg_type',1);
- if($type == 1){
- if(!$result = MessageService::make()->setHide($this->userId, $msgType)){
- return showJson(1020, false);
- }else{
- return showJson(1019, true);
- }
- }else if($type == 2){
- if(!$result = ImChatService::make()->setHide($this->userId, $chatKey)){
- return showJson(1020, false);
- }else{
- return showJson(1019, true);
- }
- }
- return showJson(1020, false);
- }
- /**
- * 聊天清除消息历史
- * @return array
- */
- public function clear()
- {
- $chatKey = request()->post('chat_key','');
- $type = request()->post('msg_type', 0);
- $groupId = request()->post('group_id', 0);
- if(!$result = MessageService::make()->clear($this->userId, $chatKey, $type, $groupId)){
- return showJson(1003, false);
- }else{
- return showJson(1002, true);
- }
- }
- /**
- * 聊天清除消息历史
- * @return array
- */
- public function clearAll()
- {
- $type = request()->post('type', 0);
- if(!$result = MessageService::make()->clearAll($this->userId, $type)){
- return showJson(1003, false);
- }else{
- return showJson(1002, true);
- }
- }
- /**
- * 未读消息
- * @return array
- */
- public function unread()
- {
- $result = MessageService::make()->getUnreadCount($this->userId);
- return showJson(1010, true, $result);
- }
- }
|