feat:兼容开发
parent
5b45941c58
commit
3cea1388fb
|
@ -3,9 +3,13 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Controller\Api\V1\Group;
|
namespace App\Controller\Api\V1\Group;
|
||||||
|
|
||||||
|
use App\Constants\TalkModeConstant;
|
||||||
use App\Controller\Api\V1\CController;
|
use App\Controller\Api\V1\CController;
|
||||||
|
use App\Model\Group\Group;
|
||||||
|
use App\Model\Group\GroupNotice;
|
||||||
use App\Service\Group\GroupMemberService;
|
use App\Service\Group\GroupMemberService;
|
||||||
use App\Service\Group\GroupService;
|
use App\Service\Group\GroupService;
|
||||||
|
use App\Service\TalkListService;
|
||||||
use Hyperf\Di\Annotation\Inject;
|
use Hyperf\Di\Annotation\Inject;
|
||||||
use Hyperf\HttpServer\Annotation\Controller;
|
use Hyperf\HttpServer\Annotation\Controller;
|
||||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||||
|
@ -46,33 +50,145 @@ class GroupController extends CController
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public function Detail()
|
/**
|
||||||
// {
|
* 创建群组
|
||||||
//
|
* @RequestMapping(path="create", methods="post")
|
||||||
// }
|
*/
|
||||||
//
|
public function create(): ResponseInterface
|
||||||
// public function Create()
|
{
|
||||||
// {
|
$params = $this->request->inputs(['name', 'ids']);
|
||||||
//
|
|
||||||
// }
|
$this->validate($params, [
|
||||||
//
|
'name' => 'required',
|
||||||
// public function Dismiss()
|
'ids' => 'required|ids'
|
||||||
// {
|
]);
|
||||||
//
|
|
||||||
// }
|
[$isTrue, $group] = $this->groupService->create($this->uid(), [
|
||||||
//
|
'name' => $params['name'],
|
||||||
// public function Invite()
|
'avatar' => $params['avatar'] ?? '',
|
||||||
// {
|
'profile' => $params['profile'] ?? ''
|
||||||
//
|
], parse_ids($params['ids']));
|
||||||
// }
|
|
||||||
//
|
if (!$isTrue) return $this->response->fail('创建群聊失败,请稍后再试!');
|
||||||
// public function SignOut()
|
|
||||||
// {
|
return $this->response->success(['group_id' => $group->id]);
|
||||||
//
|
}
|
||||||
// }
|
|
||||||
//
|
/**
|
||||||
// public function Setting()
|
* 解散群组接口
|
||||||
// {
|
* @RequestMapping(path="dismiss", methods="post")
|
||||||
//
|
*/
|
||||||
// }
|
public function dismiss(): ResponseInterface
|
||||||
|
{
|
||||||
|
$params = $this->request->inputs(['group_id']);
|
||||||
|
|
||||||
|
$this->validate($params, [
|
||||||
|
'group_id' => 'required|integer'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$isTrue = $this->groupService->dismiss($params['group_id'], $this->uid());
|
||||||
|
if (!$isTrue) {
|
||||||
|
return $this->response->fail('群组解散失败!');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->response->success([], '群组解散成功...');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邀请好友加入群组接口
|
||||||
|
* @RequestMapping(path="invite", methods="post")
|
||||||
|
*/
|
||||||
|
public function invite(): ResponseInterface
|
||||||
|
{
|
||||||
|
$params = $this->request->inputs(['group_id', 'ids']);
|
||||||
|
|
||||||
|
$this->validate($params, [
|
||||||
|
'group_id' => 'required|integer',
|
||||||
|
'ids' => 'required|ids'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$isTrue = $this->groupService->invite($this->uid(), intval($params['group_id']), parse_ids($params['ids']));
|
||||||
|
if (!$isTrue) {
|
||||||
|
return $this->response->fail('邀请好友加入群聊失败!');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->response->success([], '好友已成功加入群聊...');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出群组接口
|
||||||
|
* @RequestMapping(path="secede", methods="post")
|
||||||
|
*/
|
||||||
|
public function secede(): ResponseInterface
|
||||||
|
{
|
||||||
|
$params = $this->request->inputs(['group_id']);
|
||||||
|
|
||||||
|
$this->validate($params, [
|
||||||
|
'group_id' => 'required|integer'
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!$this->groupService->quit($this->uid(), intval($params['group_id']))) {
|
||||||
|
return $this->response->fail('退出群组失败!');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->response->success([], '已成功退出群组...');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取群信息接口
|
||||||
|
* @RequestMapping(path="detail", methods="get")
|
||||||
|
*/
|
||||||
|
public function detail(TalkListService $service): ResponseInterface
|
||||||
|
{
|
||||||
|
$group_id = (int)$this->request->input('group_id', 0);
|
||||||
|
$user_id = $this->uid();
|
||||||
|
|
||||||
|
$groupInfo = Group::leftJoin('users', 'users.id', '=', 'group.creator_id')
|
||||||
|
->where('group.id', $group_id)->where('group.is_dismiss', 0)->first([
|
||||||
|
'group.id',
|
||||||
|
'group.creator_id',
|
||||||
|
'group.group_name',
|
||||||
|
'group.profile',
|
||||||
|
'group.avatar',
|
||||||
|
'group.created_at',
|
||||||
|
'users.nickname'
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!$groupInfo) return $this->response->success();
|
||||||
|
|
||||||
|
$notice = GroupNotice::where('group_id', $group_id)->where('is_delete', 0)->orderBy('id', 'desc')->first(['title', 'content']);
|
||||||
|
|
||||||
|
return $this->response->success([
|
||||||
|
'group_id' => $groupInfo->id,
|
||||||
|
'group_name' => $groupInfo->group_name,
|
||||||
|
'profile' => $groupInfo->profile,
|
||||||
|
'avatar' => $groupInfo->avatar,
|
||||||
|
'created_at' => $groupInfo->created_at,
|
||||||
|
'is_manager' => $groupInfo->creator_id == $user_id,
|
||||||
|
'manager_nickname' => $groupInfo->nickname,
|
||||||
|
'visit_card' => $this->groupMemberService->getVisitCard($group_id, $user_id),
|
||||||
|
'is_disturb' => (int)$service->isDisturb($user_id, $group_id, TalkModeConstant::GROUP_CHAT),
|
||||||
|
'notice' => $notice ? $notice->toArray() : []
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑群组信息
|
||||||
|
* @RequestMapping(path="setting", methods="post")
|
||||||
|
*/
|
||||||
|
public function Setting(): ResponseInterface
|
||||||
|
{
|
||||||
|
$params = $this->request->inputs(['group_id', 'group_name', 'profile', 'avatar']);
|
||||||
|
|
||||||
|
$this->validate($params, [
|
||||||
|
'group_id' => 'required|integer',
|
||||||
|
'group_name' => 'required|max:30',
|
||||||
|
'profile' => 'present|max:100',
|
||||||
|
'avatar' => 'present|url'
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->groupService->update($params['group_id'], $this->uid(), $params)
|
||||||
|
? $this->response->success([], '群组信息修改成功...')
|
||||||
|
: $this->response->fail('群组信息修改失败!');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,178 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controller\Api\V1;
|
|
||||||
|
|
||||||
use App\Constants\TalkModeConstant;
|
|
||||||
|
|
||||||
use App\Service\Group\GroupMemberService;
|
|
||||||
use App\Service\TalkListService;
|
|
||||||
use Hyperf\Di\Annotation\Inject;
|
|
||||||
use Hyperf\HttpServer\Annotation\Controller;
|
|
||||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
|
||||||
use Hyperf\HttpServer\Annotation\Middleware;
|
|
||||||
use App\Middleware\JWTAuthMiddleware;
|
|
||||||
use App\Model\Group\Group;
|
|
||||||
use App\Model\Group\GroupNotice;
|
|
||||||
use App\Service\Group\GroupService;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class GroupController
|
|
||||||
* @Controller(prefix="/api/v1/group")
|
|
||||||
* @Middleware(JWTAuthMiddleware::class)
|
|
||||||
*
|
|
||||||
* @package App\Controller\Api\V1
|
|
||||||
*/
|
|
||||||
class GroupController extends CController
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @Inject
|
|
||||||
* @var GroupService
|
|
||||||
*/
|
|
||||||
private $groupService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inject
|
|
||||||
* @var GroupMemberService
|
|
||||||
*/
|
|
||||||
private $groupMemberService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建群组
|
|
||||||
* @RequestMapping(path="create", methods="post")
|
|
||||||
*/
|
|
||||||
public function create(): ResponseInterface
|
|
||||||
{
|
|
||||||
$params = $this->request->inputs(['group_name', 'uids']);
|
|
||||||
$this->validate($params, [
|
|
||||||
'group_name' => 'required',
|
|
||||||
'uids' => 'required|ids'
|
|
||||||
]);
|
|
||||||
|
|
||||||
[$isTrue, $group] = $this->groupService->create($this->uid(), [
|
|
||||||
'name' => $params['group_name'],
|
|
||||||
'avatar' => $params['avatar'] ?? '',
|
|
||||||
'profile' => $params['group_profile'] ?? ''
|
|
||||||
], parse_ids($params['uids']));
|
|
||||||
|
|
||||||
if (!$isTrue) return $this->response->fail('创建群聊失败,请稍后再试!');
|
|
||||||
|
|
||||||
return $this->response->success([
|
|
||||||
'group_id' => $group->id
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解散群组接口
|
|
||||||
* @RequestMapping(path="dismiss", methods="post")
|
|
||||||
*/
|
|
||||||
public function dismiss(): ResponseInterface
|
|
||||||
{
|
|
||||||
$params = $this->request->inputs(['group_id']);
|
|
||||||
$this->validate($params, [
|
|
||||||
'group_id' => 'required|integer'
|
|
||||||
]);
|
|
||||||
|
|
||||||
$isTrue = $this->groupService->dismiss($params['group_id'], $this->uid());
|
|
||||||
if (!$isTrue) {
|
|
||||||
return $this->response->fail('群组解散失败!');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->response->success([], '群组解散成功...');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 邀请好友加入群组接口
|
|
||||||
* @RequestMapping(path="invite", methods="post")
|
|
||||||
*/
|
|
||||||
public function invite(): ResponseInterface
|
|
||||||
{
|
|
||||||
$params = $this->request->inputs(['group_id', 'uids']);
|
|
||||||
$this->validate($params, [
|
|
||||||
'group_id' => 'required|integer',
|
|
||||||
'uids' => 'required|ids'
|
|
||||||
]);
|
|
||||||
|
|
||||||
$isTrue = $this->groupService->invite($this->uid(), $params['group_id'], parse_ids($params['uids']));
|
|
||||||
if (!$isTrue) {
|
|
||||||
return $this->response->fail('邀请好友加入群聊失败!');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->response->success([], '好友已成功加入群聊...');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 退出群组接口
|
|
||||||
* @RequestMapping(path="secede", methods="post")
|
|
||||||
*/
|
|
||||||
public function secede(): ResponseInterface
|
|
||||||
{
|
|
||||||
$params = $this->request->inputs(['group_id']);
|
|
||||||
$this->validate($params, [
|
|
||||||
'group_id' => 'required|integer'
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!$this->groupService->quit($this->uid(), $params['group_id'])) {
|
|
||||||
return $this->response->fail('退出群组失败!');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->response->success([], '已成功退出群组...');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 编辑群组信息
|
|
||||||
* @RequestMapping(path="edit", methods="post")
|
|
||||||
*/
|
|
||||||
public function editDetail(): ResponseInterface
|
|
||||||
{
|
|
||||||
$params = $this->request->inputs(['group_id', 'group_name', 'profile', 'avatar']);
|
|
||||||
$this->validate($params, [
|
|
||||||
'group_id' => 'required|integer',
|
|
||||||
'group_name' => 'required|max:30',
|
|
||||||
'profile' => 'present|max:100',
|
|
||||||
'avatar' => 'present|url'
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $this->groupService->update($params['group_id'], $this->uid(), $params)
|
|
||||||
? $this->response->success([], '群组信息修改成功...')
|
|
||||||
: $this->response->fail('群组信息修改失败!');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取群信息接口
|
|
||||||
* @RequestMapping(path="detail", methods="get")
|
|
||||||
*/
|
|
||||||
public function detail(TalkListService $service): ResponseInterface
|
|
||||||
{
|
|
||||||
$group_id = $this->request->input('group_id', 0);
|
|
||||||
$user_id = $this->uid();
|
|
||||||
|
|
||||||
$groupInfo = Group::leftJoin('users', 'users.id', '=', 'group.creator_id')
|
|
||||||
->where('group.id', $group_id)->where('group.is_dismiss', 0)->first([
|
|
||||||
'group.id',
|
|
||||||
'group.creator_id',
|
|
||||||
'group.group_name',
|
|
||||||
'group.profile',
|
|
||||||
'group.avatar',
|
|
||||||
'group.created_at',
|
|
||||||
'users.nickname'
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!$groupInfo) return $this->response->success();
|
|
||||||
|
|
||||||
$notice = GroupNotice::where('group_id', $group_id)->where('is_delete', 0)->orderBy('id', 'desc')->first(['title', 'content']);
|
|
||||||
|
|
||||||
return $this->response->success([
|
|
||||||
'group_id' => $groupInfo->id,
|
|
||||||
'group_name' => $groupInfo->group_name,
|
|
||||||
'profile' => $groupInfo->profile,
|
|
||||||
'avatar' => $groupInfo->avatar,
|
|
||||||
'created_at' => $groupInfo->created_at,
|
|
||||||
'is_manager' => $groupInfo->creator_id == $user_id,
|
|
||||||
'manager_nickname' => $groupInfo->nickname,
|
|
||||||
'visit_card' => $this->groupMemberService->getVisitCard($group_id, $user_id),
|
|
||||||
'is_disturb' => (int)$service->isDisturb($user_id, $group_id, TalkModeConstant::GROUP_CHAT),
|
|
||||||
'notice' => $notice ? $notice->toArray() : []
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -7,7 +7,7 @@ use App\Cache\Repository\LockRedis;
|
||||||
use App\Cache\UnreadTalkCache;
|
use App\Cache\UnreadTalkCache;
|
||||||
use App\Constants\TalkMessageType;
|
use App\Constants\TalkMessageType;
|
||||||
use App\Constants\TalkModeConstant;
|
use App\Constants\TalkModeConstant;
|
||||||
use App\Model\Talk\TalkList;
|
use App\Model\Talk\TalkSession;
|
||||||
use App\Service\Group\GroupMemberService;
|
use App\Service\Group\GroupMemberService;
|
||||||
use App\Service\UserFriendService;
|
use App\Service\UserFriendService;
|
||||||
use App\Support\UserRelation;
|
use App\Support\UserRelation;
|
||||||
|
@ -95,7 +95,7 @@ class TalkController extends CController
|
||||||
return $this->response->fail('创建失败!');
|
return $this->response->fail('创建失败!');
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = TalkList::item([
|
$data = TalkSession::item([
|
||||||
'id' => $result['id'],
|
'id' => $result['id'],
|
||||||
'talk_type' => $result['talk_type'],
|
'talk_type' => $result['talk_type'],
|
||||||
'receiver_id' => $result['receiver_id'],
|
'receiver_id' => $result['receiver_id'],
|
||||||
|
|
|
@ -40,6 +40,7 @@ class Group extends BaseModel
|
||||||
'is_mute',
|
'is_mute',
|
||||||
'is_dismiss',
|
'is_dismiss',
|
||||||
'created_at',
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
'dismissed_at',
|
'dismissed_at',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -49,6 +50,7 @@ class Group extends BaseModel
|
||||||
'is_overt' => 'integer',
|
'is_overt' => 'integer',
|
||||||
'is_mute' => 'integer',
|
'is_mute' => 'integer',
|
||||||
'is_dismiss' => 'integer',
|
'is_dismiss' => 'integer',
|
||||||
'created_at' => 'datetime'
|
'created_at' => 'datetime',
|
||||||
|
'updated_at' => 'datetime',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ class GroupMember extends BaseModel
|
||||||
'is_quit',
|
'is_quit',
|
||||||
'user_card',
|
'user_card',
|
||||||
'created_at',
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
'deleted_at',
|
'deleted_at',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ class GroupMember extends BaseModel
|
||||||
'is_mute' => 'integer',
|
'is_mute' => 'integer',
|
||||||
'is_quit' => 'integer',
|
'is_quit' => 'integer',
|
||||||
'created_at' => 'datetime',
|
'created_at' => 'datetime',
|
||||||
|
'updated_at' => 'datetime',
|
||||||
'deleted_at' => 'datetime',
|
'deleted_at' => 'datetime',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ use App\Model\BaseModel;
|
||||||
* @property \Carbon\Carbon $updated_at 更新时间
|
* @property \Carbon\Carbon $updated_at 更新时间
|
||||||
* @package App\Model
|
* @package App\Model
|
||||||
*/
|
*/
|
||||||
class TalkList extends BaseModel
|
class TalkSession extends BaseModel
|
||||||
{
|
{
|
||||||
protected $table = 'talk_session';
|
protected $table = 'talk_session';
|
||||||
|
|
|
@ -13,7 +13,7 @@ use App\Model\Talk\TalkRecords;
|
||||||
use App\Model\Talk\TalkRecordsInvite;
|
use App\Model\Talk\TalkRecordsInvite;
|
||||||
use App\Model\Group\Group;
|
use App\Model\Group\Group;
|
||||||
use App\Model\Group\GroupMember;
|
use App\Model\Group\GroupMember;
|
||||||
use App\Model\Talk\TalkList;
|
use App\Model\Talk\TalkSession;
|
||||||
use Hyperf\DbConnection\Db;
|
use Hyperf\DbConnection\Db;
|
||||||
use Exception;
|
use Exception;
|
||||||
use App\Service\BaseService;
|
use App\Service\BaseService;
|
||||||
|
@ -62,7 +62,8 @@ class GroupService extends BaseService
|
||||||
'is_overt' => 0,
|
'is_overt' => 0,
|
||||||
'is_mute' => 0,
|
'is_mute' => 0,
|
||||||
'is_dismiss' => 0,
|
'is_dismiss' => 0,
|
||||||
'created_at' => date('Y-m-d H:i:s')
|
'created_at' => date('Y-m-d H:i:s'),
|
||||||
|
'updated_at' => date('Y-m-d H:i:s'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
foreach ($friend_ids as $friend_id) {
|
foreach ($friend_ids as $friend_id) {
|
||||||
|
@ -71,6 +72,7 @@ class GroupService extends BaseService
|
||||||
'user_id' => $friend_id,
|
'user_id' => $friend_id,
|
||||||
'leader' => $user_id == $friend_id ? 2 : 0,
|
'leader' => $user_id == $friend_id ? 2 : 0,
|
||||||
'created_at' => date('Y-m-d H:i:s'),
|
'created_at' => date('Y-m-d H:i:s'),
|
||||||
|
'updated_at' => date('Y-m-d H:i:s'),
|
||||||
];
|
];
|
||||||
|
|
||||||
$chatList[] = [
|
$chatList[] = [
|
||||||
|
@ -86,7 +88,7 @@ class GroupService extends BaseService
|
||||||
throw new Exception('创建群成员信息失败');
|
throw new Exception('创建群成员信息失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TalkList::insert($chatList)) {
|
if (!TalkSession::insert($chatList)) {
|
||||||
throw new Exception('创建群成员的聊天列表失败');
|
throw new Exception('创建群成员的聊天列表失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +111,7 @@ class GroupService extends BaseService
|
||||||
Db::commit();
|
Db::commit();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Db::rollBack();
|
Db::rollBack();
|
||||||
|
logger()->error($e->getMessage());
|
||||||
return [false, null];
|
return [false, null];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +209,8 @@ class GroupService extends BaseService
|
||||||
$updateArr = $insertArr = $updateArr1 = $insertArr1 = [];
|
$updateArr = $insertArr = $updateArr1 = $insertArr1 = [];
|
||||||
|
|
||||||
$members = GroupMember::where('group_id', $group_id)->whereIn('user_id', $friend_ids)->get(['id', 'user_id', 'is_quit'])->keyBy('user_id')->toArray();
|
$members = GroupMember::where('group_id', $group_id)->whereIn('user_id', $friend_ids)->get(['id', 'user_id', 'is_quit'])->keyBy('user_id')->toArray();
|
||||||
$chatArr = TalkList::where('talk_type', TalkModeConstant::GROUP_CHAT)
|
|
||||||
|
$chatArr = TalkSession::where('talk_type', TalkModeConstant::GROUP_CHAT)
|
||||||
->where('receiver_id', $group_id)
|
->where('receiver_id', $group_id)
|
||||||
->whereIn('user_id', $friend_ids)
|
->whereIn('user_id', $friend_ids)
|
||||||
->get(['id', 'user_id', 'is_delete'])
|
->get(['id', 'user_id', 'is_delete'])
|
||||||
|
@ -217,7 +221,8 @@ class GroupService extends BaseService
|
||||||
$insertArr[] = [
|
$insertArr[] = [
|
||||||
'group_id' => $group_id,
|
'group_id' => $group_id,
|
||||||
'user_id' => $uid,
|
'user_id' => $uid,
|
||||||
'created_at' => date('Y-m-d H:i:s')
|
'created_at' => date('Y-m-d H:i:s'),
|
||||||
|
'updated_at' => date('Y-m-d H:i:s')
|
||||||
];
|
];
|
||||||
} else if ($members[$uid]['is_quit'] == 1) {
|
} else if ($members[$uid]['is_quit'] == 1) {
|
||||||
$updateArr[] = $members[$uid]['id'];
|
$updateArr[] = $members[$uid]['id'];
|
||||||
|
@ -243,25 +248,20 @@ class GroupService extends BaseService
|
||||||
'leader' => 0,
|
'leader' => 0,
|
||||||
'is_mute' => 0,
|
'is_mute' => 0,
|
||||||
'is_quit' => 0,
|
'is_quit' => 0,
|
||||||
'user_card' => '',
|
'created_at' => date('Y-m-d H:i:s'),
|
||||||
'created_at' => date('Y-m-d H:i:s')
|
'updated_at' => date('Y-m-d H:i:s')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($insertArr) {
|
|
||||||
GroupMember::insert($insertArr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($updateArr1) {
|
if ($updateArr1) {
|
||||||
TalkList::whereIn('id', $updateArr1)->update([
|
TalkSession::whereIn('id', $updateArr1)->update([
|
||||||
'is_delete' => 0,
|
'is_delete' => 0,
|
||||||
'created_at' => date('Y-m-d H:i:s')
|
'created_at' => date('Y-m-d H:i:s')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($insertArr1) {
|
$insertArr && GroupMember::insert($insertArr);
|
||||||
TalkList::insert($insertArr1);
|
$insertArr1 && TalkSession::insert($insertArr1);
|
||||||
}
|
|
||||||
|
|
||||||
$result = TalkRecords::create([
|
$result = TalkRecords::create([
|
||||||
'talk_type' => TalkModeConstant::GROUP_CHAT,
|
'talk_type' => TalkModeConstant::GROUP_CHAT,
|
||||||
|
@ -282,6 +282,7 @@ class GroupService extends BaseService
|
||||||
Db::commit();
|
Db::commit();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Db::rollBack();
|
Db::rollBack();
|
||||||
|
var_dump($e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,7 +346,7 @@ class GroupService extends BaseService
|
||||||
'user_ids' => $user_id
|
'user_ids' => $user_id
|
||||||
]);
|
]);
|
||||||
|
|
||||||
TalkList::where([
|
TalkSession::where([
|
||||||
['talk_type', '=', TalkModeConstant::GROUP_CHAT],
|
['talk_type', '=', TalkModeConstant::GROUP_CHAT],
|
||||||
['user_id', '=', $user_id],
|
['user_id', '=', $user_id],
|
||||||
['receiver_id', '=', $group_id],
|
['receiver_id', '=', $group_id],
|
||||||
|
@ -409,7 +410,7 @@ class GroupService extends BaseService
|
||||||
'user_ids' => implode(',', $member_ids)
|
'user_ids' => implode(',', $member_ids)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
TalkList::whereIn('user_id', $member_ids)->where('receiver_id', $group_id)->where('talk_type', TalkModeConstant::GROUP_CHAT)->update([
|
TalkSession::whereIn('user_id', $member_ids)->where('receiver_id', $group_id)->where('talk_type', TalkModeConstant::GROUP_CHAT)->update([
|
||||||
'is_delete' => 1,
|
'is_delete' => 1,
|
||||||
'updated_at' => date('Y-m-d H:i:s')
|
'updated_at' => date('Y-m-d H:i:s')
|
||||||
]);
|
]);
|
||||||
|
@ -472,7 +473,7 @@ class GroupService extends BaseService
|
||||||
|
|
||||||
$list = [];
|
$list = [];
|
||||||
if ($items) {
|
if ($items) {
|
||||||
$list = TalkList::query()->where('user_id', $user_id)
|
$list = TalkSession::query()->where('user_id', $user_id)
|
||||||
->where('talk_type', TalkModeConstant::GROUP_CHAT)
|
->where('talk_type', TalkModeConstant::GROUP_CHAT)
|
||||||
->whereIn('receiver_id', array_column($items, 'id'))
|
->whereIn('receiver_id', array_column($items, 'id'))
|
||||||
->get(['receiver_id', 'is_disturb'])->keyBy('receiver_id')->toArray();
|
->get(['receiver_id', 'is_disturb'])->keyBy('receiver_id')->toArray();
|
||||||
|
|
|
@ -7,7 +7,7 @@ use App\Cache\LastMessage;
|
||||||
use App\Cache\ServerRunID;
|
use App\Cache\ServerRunID;
|
||||||
use App\Cache\UnreadTalkCache;
|
use App\Cache\UnreadTalkCache;
|
||||||
use App\Constants\TalkModeConstant;
|
use App\Constants\TalkModeConstant;
|
||||||
use App\Model\Talk\TalkList;
|
use App\Model\Talk\TalkSession;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
|
||||||
class TalkListService
|
class TalkListService
|
||||||
|
@ -23,7 +23,7 @@ class TalkListService
|
||||||
*/
|
*/
|
||||||
public function create(int $user_id, int $receiver_id, int $talk_type, bool $is_robot = false): array
|
public function create(int $user_id, int $receiver_id, int $talk_type, bool $is_robot = false): array
|
||||||
{
|
{
|
||||||
$result = TalkList::updateOrCreate([
|
$result = TalkSession::updateOrCreate([
|
||||||
'talk_type' => $talk_type,
|
'talk_type' => $talk_type,
|
||||||
'user_id' => $user_id,
|
'user_id' => $user_id,
|
||||||
'receiver_id' => $receiver_id,
|
'receiver_id' => $receiver_id,
|
||||||
|
@ -53,7 +53,7 @@ class TalkListService
|
||||||
*/
|
*/
|
||||||
public function top(int $user_id, int $list_id, $is_top = true): bool
|
public function top(int $user_id, int $list_id, $is_top = true): bool
|
||||||
{
|
{
|
||||||
return (bool)TalkList::query()->where([
|
return (bool)TalkSession::query()->where([
|
||||||
['id', '=', $list_id],
|
['id', '=', $list_id],
|
||||||
['user_id', '=', $user_id],
|
['user_id', '=', $user_id],
|
||||||
])->update([
|
])->update([
|
||||||
|
@ -71,7 +71,7 @@ class TalkListService
|
||||||
*/
|
*/
|
||||||
public function delete(int $user_id, int $list_id): bool
|
public function delete(int $user_id, int $list_id): bool
|
||||||
{
|
{
|
||||||
return (bool)TalkList::query()->where([
|
return (bool)TalkSession::query()->where([
|
||||||
['id', '=', $list_id],
|
['id', '=', $list_id],
|
||||||
['user_id', '=', $user_id],
|
['user_id', '=', $user_id],
|
||||||
])->update([
|
])->update([
|
||||||
|
@ -90,7 +90,7 @@ class TalkListService
|
||||||
*/
|
*/
|
||||||
public function deleteByType(int $user_id, int $receiver_id, int $talk_type): bool
|
public function deleteByType(int $user_id, int $receiver_id, int $talk_type): bool
|
||||||
{
|
{
|
||||||
return (bool)TalkList::query()->where([
|
return (bool)TalkSession::query()->where([
|
||||||
['user_id', '=', $user_id],
|
['user_id', '=', $user_id],
|
||||||
['talk_type', '=', $talk_type],
|
['talk_type', '=', $talk_type],
|
||||||
['receiver_id', '=', $receiver_id],
|
['receiver_id', '=', $receiver_id],
|
||||||
|
@ -114,7 +114,7 @@ class TalkListService
|
||||||
'group.group_name', 'group.avatar as group_avatar'
|
'group.group_name', 'group.avatar as group_avatar'
|
||||||
];
|
];
|
||||||
|
|
||||||
$rows = TalkList::from('talk_session as list')
|
$rows = TalkSession::from('talk_session as list')
|
||||||
->leftJoin('users', function ($join) {
|
->leftJoin('users', function ($join) {
|
||||||
$join->on('users.id', '=', 'list.receiver_id')->where('list.talk_type', '=', TalkModeConstant::PRIVATE_CHAT);
|
$join->on('users.id', '=', 'list.receiver_id')->where('list.talk_type', '=', TalkModeConstant::PRIVATE_CHAT);
|
||||||
})
|
})
|
||||||
|
@ -131,7 +131,7 @@ class TalkListService
|
||||||
|
|
||||||
$runIdAll = ServerRunID::getInstance()->getServerRunIdAll();
|
$runIdAll = ServerRunID::getInstance()->getServerRunIdAll();
|
||||||
return array_map(function ($item) use ($user_id, $runIdAll) {
|
return array_map(function ($item) use ($user_id, $runIdAll) {
|
||||||
$data = TalkList::item([
|
$data = TalkSession::item([
|
||||||
'id' => $item['id'],
|
'id' => $item['id'],
|
||||||
'talk_type' => $item['talk_type'],
|
'talk_type' => $item['talk_type'],
|
||||||
'receiver_id' => $item['receiver_id'],
|
'receiver_id' => $item['receiver_id'],
|
||||||
|
@ -173,7 +173,7 @@ class TalkListService
|
||||||
*/
|
*/
|
||||||
public function disturb(int $user_id, int $receiver_id, int $talk_type, int $is_disturb): bool
|
public function disturb(int $user_id, int $receiver_id, int $talk_type, int $is_disturb): bool
|
||||||
{
|
{
|
||||||
$result = TalkList::query()->where([
|
$result = TalkSession::query()->where([
|
||||||
['user_id', '=', $user_id],
|
['user_id', '=', $user_id],
|
||||||
['talk_type', '=', $talk_type],
|
['talk_type', '=', $talk_type],
|
||||||
['receiver_id', '=', $receiver_id],
|
['receiver_id', '=', $receiver_id],
|
||||||
|
@ -183,7 +183,7 @@ class TalkListService
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (bool)TalkList::query()->where('id', $result->id)->update([
|
return (bool)TalkSession::query()->where('id', $result->id)->update([
|
||||||
'is_disturb' => $is_disturb,
|
'is_disturb' => $is_disturb,
|
||||||
'updated_at' => date('Y-m-d H:i:s')
|
'updated_at' => date('Y-m-d H:i:s')
|
||||||
]);
|
]);
|
||||||
|
@ -199,7 +199,7 @@ class TalkListService
|
||||||
*/
|
*/
|
||||||
public function isDisturb(int $user_id, int $receiver_id, int $talk_type): bool
|
public function isDisturb(int $user_id, int $receiver_id, int $talk_type): bool
|
||||||
{
|
{
|
||||||
return (bool)TalkList::query()->where([
|
return (bool)TalkSession::query()->where([
|
||||||
['user_id', '=', $user_id],
|
['user_id', '=', $user_id],
|
||||||
['talk_type', '=', $talk_type],
|
['talk_type', '=', $talk_type],
|
||||||
['receiver_id', '=', $receiver_id],
|
['receiver_id', '=', $receiver_id],
|
||||||
|
|
Loading…
Reference in New Issue