Kirin 3 주 전
부모
커밋
0eafd5450e
2개의 변경된 파일0개의 추가작업 그리고 459개의 파일을 삭제
  1. 0 177
      app/controller/chat/Chat.php
  2. 0 282
      app/controller/chat/ChatGroup.php

+ 0 - 177
app/controller/chat/Chat.php

@@ -1,177 +0,0 @@
-<?php
-/**
- * @Created by PhpStorm
- * @author: Kirin
- * @day: 2024/11/12
- * @time: 16:31
- */
-
-namespace app\controller\api\chat;
-
-
-use app\common\ApiBaseController;
-use app\Request;
-use app\services\chat\ChatGroupMemberServices;
-use app\services\chat\ChatGroupServices;
-use app\services\chat\ChatLogServices;
-use app\services\decoration\DecorationDesignerServices;
-use app\services\decoration\DecorationSalespersonServices;
-use app\services\decoration\DecorationWorkerServices;
-use app\services\system\store\SystemStoreServices;
-use app\services\user\UserServices;
-use think\db\exception\DataNotFoundException;
-use think\db\exception\DbException;
-use think\db\exception\ModelNotFoundException;
-
-class Chat extends ApiBaseController
-{
-    private $groupMemberService;
-    private $groupService;
-
-    public function __construct(Request $request, ChatLogServices $service, ChatGroupMemberServices $groupMemberService, ChatGroupServices $groupService)
-    {
-        parent::__construct($request);
-        $this->service = $service;
-        $this->groupMemberService = $groupMemberService;
-        $this->groupService = $groupService;
-    }
-
-
-    /**
-     * 聊天列表
-     * @param Request $request
-     * @return mixed
-     * @throws DataNotFoundException
-     * @throws DbException
-     * @throws ModelNotFoundException
-     */
-    public function index(Request $request)
-    {
-        $user_chat = $this->service->search()
-            ->where('uid|to_uid', $request->uid())
-//            ->where('add_time', '>=', time() - 7 * 86400)
-            ->where('group_id', 0)
-            ->field('if(uid=' . $request->uid() . ',to_uid,uid) as user_id,sum(if(status=0 && to_uid=' . $request->uid() . ',1,0)) as unread_count,max(add_time) as last_time,to_uid_type,uid_type')
-            ->group('user_id,to_uid_type,uid_type')
-            ->select();
-        foreach ($user_chat as &$v) {
-            $v['is_group'] = 0;
-            $v['f_info'] = $this->service->getInfo($v['to_uid_type'], $v['user_id']);
-            $user_uid = $request->uid();
-            $to_uid = $v['user_id'];
-            $v['last_msn'] = $this->service->search()->where(function ($query) use ($user_uid, $to_uid) {
-                $query->where(function ($q) use ($user_uid, $to_uid) {
-                    $q->where('uid', $user_uid)->where('to_uid', $to_uid);
-                })->whereOr(function ($q) use ($user_uid, $to_uid) {
-                    $q->where('uid', $to_uid)->where('to_uid', $user_uid);
-                });
-            })->order('add_time desc,id desc')->find();
-        }
-
-        $groups = $this->groupMemberService->search()->where('uid', $request->uid())->column('chat_group_id');
-        $groups = $this->groupService->search()->where('id', 'in', $groups)->column('id');
-        $group_chat = $this->service->search()->where('group_id', 'in', $groups)
-//            ->where('add_time', '>=', time() - 7 * 86400)
-            ->where('group_id', '>', 0)
-            ->field('group_id,sum(if(find_in_set(' . $request->uid() . ',group_see),0,1)) as unread_count,max(add_time) as last_time')
-            ->group('group_id')->select();
-        foreach ($group_chat as &$v) {
-            $v['is_group'] = 1;
-            $v['last_msn'] = $this->service->search()->where('group_id', $v['group_id'])
-                ->order('add_time desc,id desc')->find();
-            $v['at'] = $this->service->search()->where('group_id', $v['group_id'])
-                ->where('at', $request->uid())
-                ->where('find_in_set(' . $request->uid() . ',group_see)', '<=', 0)
-                ->where('find_in_set(' . $request->uid() . ',at)')
-                ->count();
-            $v['group_info'] = $this->groupService->get($v['group_id']);
-            $v['identity'] = $this->groupMemberService->search()->where('uid', $request->uid())->where('chat_group_id', $v['group_id'])->value('identity');
-        }
-        $log_list = array_merge($user_chat->toArray(), $group_chat->toArray());
-        usort($log_list, function ($a, $b) {
-            return -($a['last_time'] <=> $b['last_time']);
-        });
-        return $this->success('ok', $log_list);
-    }
-
-    /**
-     * 聊天记录
-     * @param $uid
-     * @param $type
-     * @param Request $request
-     * @return mixed
-     * @throws DataNotFoundException
-     * @throws DbException
-     * @throws ModelNotFoundException
-     */
-    public function chatLog(Request $request)
-    {
-        $page = $request->get('page', 1);
-        $limit = $request->get('limit', 30);
-        $user_uid = $request->uid();
-        list($uid, $user_type, $type) = $this->request->getMore([
-            ['uid', 0],
-            ['user_type', 0],
-            ['type', 0]
-        ], true);
-        $to_uid = $uid;
-        $log_list = $this->service->search()->where(function ($query) use ($user_uid, $to_uid, $type, $user_type) {
-            $query->where(function ($q) use ($user_uid, $to_uid, $type, $user_type) {
-                $q->where('uid', $user_uid)->where('to_uid', $to_uid)->where('to_uid_type', $type)->where('uid_type', $user_type);
-            })->whereOr(function ($q) use ($user_uid, $to_uid, $type, $user_type) {
-                $q->where('uid', $to_uid)->where('to_uid', $user_uid)->where('uid_type', $type)->where('to_uid_type', $user_type);
-            });
-        })->page($page, $limit)->order('add_time desc,id desc')->select();
-        $f_info = $this->service->getInfo($type, $to_uid);
-        $u_info = $this->service->getInfo($user_type, $user_uid);
-        return $this->success('ok', compact('log_list', 'f_info', 'u_info'));
-    }
-
-
-    public function setRead(Request $request)
-    {
-        list($uid, $user_type, $type) = $this->request->postMore([
-            ['uid', 0],
-            ['user_type', 0],
-            ['type', 0]
-        ], true);
-        $this->service->search()->where('uid', $uid)->where('to_uid', $request->uid())->where('uid_type', $user_type)->where('to_uid_type', $type)->update(['status' => 1]);
-        return $this->success('ok');
-    }
-
-
-    public function groupChatLog($group_id, Request $request)
-    {
-        if (!$user = $this->groupMemberService->search()->where('uid', $request->uid())->where('chat_group_id', $group_id)->find()) {
-            return $this->error('你没有权限');
-        }
-        $group = $this->groupService->search()->where('id', $group_id)->find();
-        if (!$group) return $this->error('群不存在');
-        $page = $request->get('page', 1);
-        $limit = $request->get('limit', 30);
-        $log_list = $this->service->search()->where('group_id', $group_id)
-            ->page($page, $limit)
-            ->where('add_time', '>=', $user['add_time'])
-            ->order('add_time desc,id desc')
-            ->select();
-        foreach ($log_list as &$v) {
-            $member = $this->groupMemberService->search()->where('chat_group_id', $group_id)->where('uid', $v['uid'])->find();
-            $v['f_info'] = $this->service->getInfo($member['identity'], $member['uid']);
-            $v['member_info'] = $member;
-        }
-        return $this->success('ok', compact('log_list'));
-    }
-
-    public function setGroupRead($group_id, Request $request)
-    {
-        if (!$user = $this->groupMemberService->search()->where('uid', $request->uid())->where('chat_group_id', $group_id)->find()) {
-            return $this->error('你没有权限');
-        }
-        $group = $this->groupService->search()->where('id', $group_id)->find();
-        if (!$group) return $this->error('群不存在');
-        $this->service->search()->where('group_id', $group_id)
-            ->where('!find_in_set(' . $request->uid() . ',group_see)')
-            ->update(['group_see' => ['exp', 'CONCAT(group_see,",' . $request->uid() . '")']]);
-        return $this->success();
-    }
-}

+ 0 - 282
app/controller/chat/ChatGroup.php

@@ -1,282 +0,0 @@
-<?php
-/**
- * @Created by PhpStorm
- * @author: Kirin
- * @day: 2024/11/12
- * @time: 16:35
- */
-
-namespace app\controller\api\chat;
-
-
-use app\common\ApiBaseController;
-use app\Request;
-use app\services\chat\ChatGroupMemberServices;
-use app\services\chat\ChatGroupServices;
-use app\services\chat\ChatLogServices;
-use app\services\user\UserServices;
-use app\webscoket\SocketPush;
-use think\db\exception\DataNotFoundException;
-use think\db\exception\DbException;
-use think\db\exception\ModelNotFoundException;
-use think\Exception;
-
-/**
- * Class ChatGroup
- * @package app\controller\api\chat
- */
-class ChatGroup extends ApiBaseController
-{
-    /** @var ChatGroupServices $groupService */
-    private $groupService;
-    /** @var ChatGroupMemberServices $groupMemberService */
-    private $groupMemberService;
-
-    /**
-     * @param Request $request
-     * @param ChatLogServices $service
-     * @param ChatGroupMemberServices $groupMemberService
-     * @param ChatGroupServices $groupService
-     */
-    public function __construct(Request $request, ChatLogServices $service, ChatGroupMemberServices $groupMemberService, ChatGroupServices $groupService)
-    {
-        parent::__construct($request);
-        $this->service = $service;
-        $this->groupMemberService = $groupMemberService;
-        $this->groupService = $groupService;
-    }
-
-    /**
-     * 我的群列表
-     * @para
-     * @return mixed
-     * @throws DataNotFoundException
-     * @throws DbException
-     * @throws ModelNotFoundException
-     */
-    public function group()
-    {
-        $groups = $this->groupMemberService->getColumn(['uid' => $this->request->uid()], 'id');
-        $list = $this->groupService->search()->where('id', 'in', $groups)
-            ->order('last_message_time', 'desc')
-            ->select();
-        return $this->success('ok', compact('list'));
-    }
-
-
-    /**
-     * 群详情
-     * @param $id
-     * @para
-     * @return mixed
-     * @throws DataNotFoundException
-     * @throws DbException
-     * @throws ModelNotFoundException
-     */
-    public function groupInfo($id)
-    {
-        $group = $this->groupService->get($id);
-        if (!$group) return $this->error('群不存在');
-        return $this->success('ok', compact('group'));
-    }
-
-    /**
-     * 群成员列表
-     * @param $id
-     * @para
-     * @return mixed
-     * @throws DataNotFoundException
-     * @throws DbException
-     * @throws ModelNotFoundException
-     */
-    public function groupMembers($id)
-    {
-        $group = $this->groupService->get($id);
-        if (!$group) return $this->error('群不存在');
-        $list = $this->groupMemberService->search()->where('chat_group_id', $id)->select();
-        foreach ($list as &$v) {
-            $v['ext_info'] = $this->service->getInfo($v['identity'], $v['uid']);
-        }
-        return $this->success('ok', compact('list'));
-    }
-
-    /**
-     * 添加群成员
-     * @param $id
-     * @return mixed
-     * @throws DataNotFoundException
-     * @throws DbException
-     * @throws ModelNotFoundException
-     * @para
-     */
-    public function groupAddMember($id)
-    {
-        $group = $this->groupService->get($id);
-        if (!$group) return $this->error('群不存在');
-        if (!$this->groupMemberService->search()->where('uid', $this->request->uid())->where('chat_group_id', $id)->where('is_hoster', 1)->find()) {
-            return $this->error('你没有权限');
-        }
-        $uid = $this->request->post('uid', 0);
-        $identity = $this->request->post('identity', 0);
-        if ($this->groupMemberService->search()->where('uid', $uid)->where('chat_group_id', $id)->find()) {
-            return $this->error('用户已在群聊中');
-        }
-        /** @var UserServices $userService */
-        $userService = app()->make(UserServices::class);
-        $user = $userService->getUserInfo($uid);
-        if (!$user) return $this->error('用户不存在');
-        $ext_info = $this->service->getInfo($identity, $uid);
-        if (!$ext_info) return $this->error('用户不存在');
-        try {
-            $this->groupMemberService->create([
-                'uid' => $uid,
-                'chat_group_id' => $id,
-                'identity' => $identity,
-            ]);
-            $this->service->create([
-                'uid' => $uid,
-                'to_uid' => 0,
-                'add_time' => time(),
-                'status' => 1,
-                'msn_type' => 'notice',
-                'group_id' => $id,
-                'msn' => $ext_info['info']['name'] . ' 加入群聊',
-                'group_see' => $uid,
-            ]);
-            $this->groupService->update($id, ['last_message_time' => time()]);
-            return $this->success('ok', ['date' => ['name' => $ext_info['info']['name'], 'type' => $ext_info['type'], 'uid' => $uid, 'add_time' => time(), 'group_id' => $id], 'type' => 'group:new_member']);
-        } catch (Exception $e) {
-            return $this->error($e->getMessage());
-        }
-    }
-
-
-    /**
-     * 移除群成员
-     * @param $id
-     * @return mixed
-     * @throws DataNotFoundException
-     * @throws DbException
-     * @throws ModelNotFoundException
-     * @para
-     */
-    public function groupRemoveMember($id)
-    {
-        $group = $this->groupService->get($id);
-        if (!$group) return $this->error('群不存在');
-        if (!$this->groupMemberService->search()->where('uid', $this->request->uid())->where('chat_group_id', $id)->where('is_hoster', 1)->find()) {
-            return $this->error('你没有权限');
-        }
-        $uid = $this->request->post('uid', 0);
-        if (!$user = $this->groupMemberService->search()->where('uid', $uid)->where('chat_group_id', $id)->find()) {
-            return $this->error('用户不在群聊中');
-        }
-        if ($user['is_hoster']) return $this->error('群主不能移除');
-
-        try {
-            $this->groupMemberService->delete($user['id']);
-            return $this->success('ok');
-        } catch (Exception $e) {
-            return $this->error($e->getMessage());
-        }
-    }
-
-
-    /**
-     * 修改群昵称
-     * @param $id
-     * @return mixed
-     * @throws DataNotFoundException
-     * @throws DbException
-     * @throws ModelNotFoundException
-     */
-    public function setMark($id)
-    {
-        $group = $this->groupService->get($id);
-        if (!$group) return $this->error('群不存在');
-        $mark = $this->request->post('mark');
-        $info = $this->groupMemberService->search()->where('uid', $this->request->uid())->where('chat_group_id', $id)->find();
-        if (!$info) return $this->error('你没有权限');
-        $info->nickname = $mark;
-        $res = $info->save();
-        if ($res)
-            return $this->success('修改成功');
-        else
-            return $this->error('修改失败');
-    }
-
-
-    /**
-     * 修改群信息
-     * @param $id
-     * @return mixed
-     * @throws DataNotFoundException
-     * @throws DbException
-     * @throws ModelNotFoundException
-     * @para
-     */
-    public function editGroup($id)
-    {
-        $info = $this->request->post('info', '');
-        $name = $this->request->post('name', '');
-        $avatar = $this->request->post('avatar', '');
-        $group = $this->groupService->get($id);
-        if (!$group) return $this->error('群不存在');
-        if (!$this->groupMemberService->search()->where('uid', $this->request->uid())->where('chat_group_id', $id)->where('is_hoster', 1)->find()) {
-            return $this->error('你没有权限');
-        }
-        $res = $this->groupService->update($id, ['name' => $name, 'info' => $info, 'avatar' => $avatar]);
-        if ($res)
-            return $this->success('修改成功');
-        else
-            return $this->error('修改失败');
-    }
-
-    /**
-     * 新增群公告
-     * @param $id
-     * @return mixed
-     * @throws DataNotFoundException
-     * @throws DbException
-     * @throws ModelNotFoundException
-     * @para
-     */
-    public function setNotice($id)
-    {
-        $notice = $this->request->post('notice', '');
-        $group = $this->groupService->get($id);
-        if (!$group) return $this->error('群不存在');
-        if (!$this->groupMemberService->search()->where('uid', $this->request->uid())->where('chat_group_id', $id)->where('is_hoster', 1)->find()) {
-            return $this->error('你没有权限');
-        }
-        $res = $this->groupService->update($id, ['notice' => $notice]);
-        $this->service->create([
-            'uid' => $this->request->uid(),
-            'to_uid' => 0,
-            'add_time' => time(),
-            'status' => 1,
-            'msn_type' => 'announcement',
-            'group_id' => $id,
-            'msn' => '群公告' . ':' . $notice,
-            'group_see' => $this->request->uid(),
-        ]);
-
-        /** @var ChatGroupMemberServices $chatMemberService */
-        $chatMemberService = app()->make(ChatGroupMemberServices::class);
-
-        $members = $chatMemberService->getColumn(['chat_group_id' => $id], 'uid');
-        foreach ($members as $member) {
-            SocketPush::user()->toGroup($member, $id)->type('announcement')
-                ->data('群公告' . ':' . $notice)
-                ->push();
-        }
-
-        $res = $this->groupService->update($id, ['last_message_time' => time()]);
-        if ($res)
-            return $this->success('修改成功', ['type' => 'group:notice', 'data' => ['notice' => $notice]]);
-        else
-            return $this->error('修改失败');
-    }
-
-
-}