重构群组相关代码
parent
f60ab0f0c1
commit
619d0234c1
|
@ -68,15 +68,15 @@ class GroupController extends CController
|
|||
$params = $this->request->inputs(['group_name', 'uids']);
|
||||
$this->validate($params, [
|
||||
'group_name' => 'required',
|
||||
'uids' => 'required|ids'
|
||||
'uids' => 'required|ids'
|
||||
]);
|
||||
|
||||
$friend_ids = parse_ids($params['uids']);
|
||||
|
||||
$user_id = $this->uid();
|
||||
[$isTrue, $data] = $this->groupService->create($user_id, [
|
||||
'name' => $params['group_name'],
|
||||
'avatar' => $params['avatar'] ?? '',
|
||||
'name' => $params['group_name'],
|
||||
'avatar' => $params['avatar'] ?? '',
|
||||
'profile' => $params['group_profile'] ?? ''
|
||||
], $friend_ids);
|
||||
|
||||
|
@ -90,13 +90,13 @@ class GroupController extends CController
|
|||
$this->socketRoomService->addRoomMember($uid, $data['group_id']);
|
||||
}
|
||||
|
||||
// ...消息推送队列
|
||||
// ... 消息推送队列
|
||||
$this->producer->produce(
|
||||
new ChatMessageProducer(SocketConstants::EVENT_TALK, [
|
||||
'sender' => $user_id, //发送者ID
|
||||
'receive' => intval($data['group_id']), //接收者ID
|
||||
'source' => 2, //接收者类型 1:好友;2:群组
|
||||
'record_id' => intval($data['record_id'])
|
||||
'sender' => $user_id, // 发送者ID
|
||||
'receive' => (int)$data['group_id'], // 接收者ID
|
||||
'source' => 2, // 接收者类型[1:好友;2:群组;]
|
||||
'record_id' => (int)$data['record_id']
|
||||
])
|
||||
);
|
||||
|
||||
|
@ -124,7 +124,7 @@ class GroupController extends CController
|
|||
|
||||
$this->socketRoomService->delRoom($params['group_id']);
|
||||
|
||||
// ... 推送群消息(后期添加)
|
||||
// ... 推送群消息(预留)
|
||||
|
||||
return $this->response->success([], '群组解散成功...');
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ class GroupController extends CController
|
|||
$params = $this->request->inputs(['group_id', 'uids']);
|
||||
$this->validate($params, [
|
||||
'group_id' => 'required|integer',
|
||||
'uids' => 'required|ids'
|
||||
'uids' => 'required|ids'
|
||||
]);
|
||||
|
||||
$uids = parse_ids($params['uids']);
|
||||
|
@ -158,9 +158,9 @@ class GroupController extends CController
|
|||
// ...消息推送队列
|
||||
$this->producer->produce(
|
||||
new ChatMessageProducer(SocketConstants::EVENT_TALK, [
|
||||
'sender' => $user_id, //发送者ID
|
||||
'receive' => intval($params['group_id']), //接收者ID
|
||||
'source' => 2, //接收者类型 1:好友;2:群组
|
||||
'sender' => $user_id, // 发送者ID
|
||||
'receive' => (int)$params['group_id'], // 接收者ID
|
||||
'source' => 2, // 接收者类型[1:好友;2:群组;]
|
||||
'record_id' => $record_id
|
||||
])
|
||||
);
|
||||
|
@ -192,9 +192,9 @@ class GroupController extends CController
|
|||
// ...消息推送队列
|
||||
$this->producer->produce(
|
||||
new ChatMessageProducer(SocketConstants::EVENT_TALK, [
|
||||
'sender' => $user_id, //发送者ID
|
||||
'receive' => intval($params['group_id']), //接收者ID
|
||||
'source' => 2, //接收者类型 1:好友;2:群组
|
||||
'sender' => $user_id, // 发送者ID
|
||||
'receive' => (int)$params['group_id'], // 接收者ID
|
||||
'source' => 2, // 接收者类型[1:好友;2:群组;]
|
||||
'record_id' => $record_id
|
||||
])
|
||||
);
|
||||
|
@ -209,22 +209,21 @@ class GroupController extends CController
|
|||
*/
|
||||
public function editDetail()
|
||||
{
|
||||
$params = $this->request->inputs(['group_id', 'group_name', 'group_profile', 'avatar']);
|
||||
$params = $this->request->inputs(['group_id', 'group_name', 'profile', 'avatar']);
|
||||
$this->validate($params, [
|
||||
'group_id' => 'required|integer',
|
||||
'group_id' => 'required|integer',
|
||||
'group_name' => 'required|max:30',
|
||||
'group_profile' => 'required|max:100',
|
||||
'avatar' => 'present|url'
|
||||
'profile' => 'present|max:100',
|
||||
'avatar' => 'present|url'
|
||||
]);
|
||||
|
||||
$result = Group::where('id', $params['group_id'])->where('user_id', $this->uid())->update([
|
||||
$result = Group::where('id', $params['group_id'])->where('creator_id', $this->uid())->update([
|
||||
'group_name' => $params['group_name'],
|
||||
'group_profile' => $params['group_profile'],
|
||||
'avatar' => $params['avatar']
|
||||
'profile' => $params['profile'],
|
||||
'avatar' => $params['avatar']
|
||||
]);
|
||||
|
||||
// 推送消息通知
|
||||
// ...
|
||||
// ... 推送消息通知(预留)
|
||||
|
||||
return $result
|
||||
? $this->response->success([], '群组信息修改成功...')
|
||||
|
@ -240,10 +239,12 @@ class GroupController extends CController
|
|||
{
|
||||
$params = $this->request->inputs(['group_id', 'members_ids']);
|
||||
$this->validate($params, [
|
||||
'group_id' => 'required|integer',
|
||||
'members_ids' => 'required|array'
|
||||
'group_id' => 'required|integer',
|
||||
'members_ids' => 'required|ids'
|
||||
]);
|
||||
|
||||
$params['members_ids'] = parse_ids($params['members_ids']);
|
||||
|
||||
$user_id = $this->uid();
|
||||
if (in_array($user_id, $params['members_ids'])) {
|
||||
return $this->response->fail('群聊用户移除失败...');
|
||||
|
@ -259,12 +260,12 @@ class GroupController extends CController
|
|||
$this->socketRoomService->delRoomMember($params['group_id'], $uid);
|
||||
}
|
||||
|
||||
// ...消息推送队列
|
||||
// ... 消息推送队列
|
||||
$this->producer->produce(
|
||||
new ChatMessageProducer(SocketConstants::EVENT_TALK, [
|
||||
'sender' => $user_id, //发送者ID
|
||||
'receive' => intval($params['group_id']), //接收者ID
|
||||
'source' => 2, //接收者类型 1:好友;2:群组
|
||||
'sender' => $user_id, // 发送者ID
|
||||
'receive' => (int)$params['group_id'], // 接收者ID
|
||||
'source' => 2, // 接收者类型[1:好友;2:群组;]
|
||||
'record_id' => $record_id
|
||||
])
|
||||
);
|
||||
|
@ -280,19 +281,21 @@ class GroupController extends CController
|
|||
public function detail()
|
||||
{
|
||||
$group_id = $this->request->input('group_id', 0);
|
||||
$user_id = $this->uid();
|
||||
|
||||
$user_id = $this->uid();
|
||||
$groupInfo = Group::leftJoin('users', 'users.id', '=', 'group.user_id')
|
||||
->where('group.id', $group_id)->where('group.status', 0)->first([
|
||||
'group.id', 'group.user_id',
|
||||
$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.group_profile', 'group.avatar',
|
||||
'group.profile',
|
||||
'group.avatar',
|
||||
'group.created_at',
|
||||
'users.nickname'
|
||||
]);
|
||||
|
||||
if (!$groupInfo) {
|
||||
return $this->response->success([]);
|
||||
return $this->response->success();
|
||||
}
|
||||
|
||||
$notice = GroupNotice::where('group_id', $group_id)
|
||||
|
@ -301,16 +304,16 @@ class GroupController extends CController
|
|||
->first(['title', 'content']);
|
||||
|
||||
return $this->response->success([
|
||||
'group_id' => $groupInfo->id,
|
||||
'group_name' => $groupInfo->group_name,
|
||||
'group_profile' => $groupInfo->group_profile,
|
||||
'avatar' => $groupInfo->avatar,
|
||||
'created_at' => $groupInfo->created_at,
|
||||
'is_manager' => $groupInfo->user_id == $user_id,
|
||||
'group_id' => $groupInfo->id,
|
||||
'group_name' => $groupInfo->group_name,
|
||||
'group_profile' => $groupInfo->profile,
|
||||
'avatar' => $groupInfo->avatar,
|
||||
'created_at' => $groupInfo->created_at,
|
||||
'is_manager' => $groupInfo->creator_id == $user_id,
|
||||
'manager_nickname' => $groupInfo->nickname,
|
||||
'visit_card' => GroupMember::visitCard($user_id, $group_id),
|
||||
'not_disturb' => UsersChatList::where('uid', $user_id)->where('group_id', $group_id)->where('type', 2)->value('not_disturb') ?? 0,
|
||||
'notice' => $notice ? $notice->toArray() : []
|
||||
'visit_card' => GroupMember::visitCard($user_id, $group_id),
|
||||
'not_disturb' => UsersChatList::where('uid', $user_id)->where('group_id', $group_id)->where('type', 2)->value('not_disturb') ?? 0,
|
||||
'notice' => $notice ? $notice->toArray() : []
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -319,18 +322,17 @@ class GroupController extends CController
|
|||
*
|
||||
* @RequestMapping(path="set-group-card", methods="post")
|
||||
*/
|
||||
public function setGroupCard()
|
||||
public function editGroupCard()
|
||||
{
|
||||
$params = $this->request->inputs(['group_id', 'visit_card']);
|
||||
$this->validate($params, [
|
||||
'group_id' => 'required|integer',
|
||||
'group_id' => 'required|integer',
|
||||
'visit_card' => 'required|max:20'
|
||||
]);
|
||||
|
||||
$isTrue = GroupMember::where('group_id', $params['group_id'])
|
||||
->where('user_id', $this->uid())
|
||||
->where('status', 0)
|
||||
->update(['visit_card' => $params['visit_card']]);
|
||||
->update(['user_card' => $params['visit_card']]);
|
||||
|
||||
return $isTrue
|
||||
? $this->response->success([], '群名片修改成功...')
|
||||
|
@ -387,15 +389,20 @@ class GroupController extends CController
|
|||
}
|
||||
|
||||
$members = GroupMember::select([
|
||||
'group_member.id', 'group_member.group_owner as is_manager', 'group_member.visit_card',
|
||||
'group_member.user_id', 'users.avatar', 'users.nickname', 'users.gender',
|
||||
'group_member.id',
|
||||
'group_member.leader',
|
||||
'group_member.user_card',
|
||||
'group_member.user_id',
|
||||
'users.avatar',
|
||||
'users.nickname',
|
||||
'users.gender',
|
||||
'users.motto',
|
||||
])
|
||||
->leftJoin('users', 'users.id', '=', 'group_member.user_id')
|
||||
->where([
|
||||
['group_member.group_id', '=', $group_id],
|
||||
['group_member.status', '=', 0],
|
||||
])->orderBy('is_manager', 'desc')->get()->toArray();
|
||||
['group_member.is_quit', '=', 0],
|
||||
])->orderBy('leader', 'desc')->get()->toArray();
|
||||
|
||||
return $this->response->success($members);
|
||||
}
|
||||
|
@ -405,7 +412,7 @@ class GroupController extends CController
|
|||
*
|
||||
* @RequestMapping(path="notices", methods="get")
|
||||
*/
|
||||
public function getGroupNotices()
|
||||
public function getGroupNotice()
|
||||
{
|
||||
$user_id = $this->uid();
|
||||
$group_id = $this->request->input('group_id', 0);
|
||||
|
@ -415,20 +422,25 @@ class GroupController extends CController
|
|||
return $this->response->fail('非管理员禁止操作...');
|
||||
}
|
||||
|
||||
$rows = GroupNotice::leftJoin('users', 'users.id', '=', 'group_notice.user_id')
|
||||
$rows = GroupNotice::leftJoin('users', 'users.id', '=', 'group_notice.creator_id')
|
||||
->where([
|
||||
['group_notice.group_id', '=', $group_id],
|
||||
['group_notice.is_delete', '=', 0]
|
||||
])
|
||||
->orderBy('group_notice.id', 'desc')
|
||||
->orderBy('group_notice.is_top', 'desc')
|
||||
->orderBy('group_notice.updated_at', 'desc')
|
||||
->get([
|
||||
'group_notice.id',
|
||||
'group_notice.user_id',
|
||||
'group_notice.creator_id',
|
||||
'group_notice.title',
|
||||
'group_notice.content',
|
||||
'group_notice.is_top',
|
||||
'group_notice.is_confirm',
|
||||
'group_notice.confirm_users',
|
||||
'group_notice.created_at',
|
||||
'group_notice.updated_at',
|
||||
'users.avatar', 'users.nickname',
|
||||
'users.avatar',
|
||||
'users.nickname',
|
||||
])->toArray();
|
||||
|
||||
return $this->response->success($rows);
|
||||
|
@ -441,12 +453,14 @@ class GroupController extends CController
|
|||
*/
|
||||
public function editNotice()
|
||||
{
|
||||
$params = $this->request->inputs(['group_id', 'notice_id', 'title', 'content']);
|
||||
$params = $this->request->inputs(['group_id', 'notice_id', 'title', 'content', 'is_top', 'is_confirm']);
|
||||
$this->validate($params, [
|
||||
'group_id' => 'required|integer',
|
||||
'notice_id' => 'required|integer',
|
||||
'title' => 'required|max:50',
|
||||
'content' => 'required'
|
||||
'notice_id' => 'required|integer',
|
||||
'group_id' => 'required|integer',
|
||||
'title' => 'required|max:50',
|
||||
'is_top' => 'integer|in:0,1',
|
||||
'is_confirm' => 'integer|in:0,1',
|
||||
'content' => 'required'
|
||||
]);
|
||||
|
||||
$user_id = $this->uid();
|
||||
|
@ -457,12 +471,14 @@ class GroupController extends CController
|
|||
}
|
||||
|
||||
// 判断是否是新增数据
|
||||
if (empty($data['notice_id'])) {
|
||||
if (empty($params['notice_id'])) {
|
||||
$result = GroupNotice::create([
|
||||
'group_id' => $params['group_id'],
|
||||
'title' => $params['title'],
|
||||
'content' => $params['content'],
|
||||
'user_id' => $user_id,
|
||||
'group_id' => $params['group_id'],
|
||||
'creator_id' => $user_id,
|
||||
'title' => $params['title'],
|
||||
'content' => $params['content'],
|
||||
'is_top' => $params['is_top'],
|
||||
'is_confirm' => $params['is_confirm'],
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
@ -471,13 +487,15 @@ class GroupController extends CController
|
|||
return $this->response->fail('添加群公告信息失败...');
|
||||
}
|
||||
|
||||
// ... 推送群消息
|
||||
// ... 推送群消息(预留)
|
||||
|
||||
return $this->response->success([], '添加群公告信息成功...');
|
||||
}
|
||||
|
||||
$result = GroupNotice::where('id', $data['notice_id'])->update([
|
||||
'title' => $data['title'],
|
||||
'content' => $data['content'],
|
||||
$result = GroupNotice::where('id', $params['notice_id'])->update([
|
||||
'title' => $params['title'],
|
||||
'content' => $params['content'],
|
||||
'is_top' => $params['is_top'],
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
|
@ -495,7 +513,7 @@ class GroupController extends CController
|
|||
{
|
||||
$params = $this->request->inputs(['group_id', 'notice_id']);
|
||||
$this->validate($params, [
|
||||
'group_id' => 'required|integer',
|
||||
'group_id' => 'required|integer',
|
||||
'notice_id' => 'required|integer'
|
||||
]);
|
||||
|
||||
|
@ -509,7 +527,7 @@ class GroupController extends CController
|
|||
$result = GroupNotice::where('id', $params['notice_id'])
|
||||
->where('group_id', $params['group_id'])
|
||||
->update([
|
||||
'is_delete' => 1,
|
||||
'is_delete' => 1,
|
||||
'deleted_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
|
|
|
@ -27,6 +27,10 @@ class ValidatorFactoryResolvedListener implements ListenerInterface
|
|||
|
||||
// 注册了 ids 验证器(验证英文逗号拼接的整形数字字符串 例如:[1,2,3,4,5])
|
||||
$validatorFactory->extend('ids', function ($attribute, $value, $parameters, $validator) {
|
||||
if (!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$arr = explode(',', $value);
|
||||
foreach ($arr as $id) {
|
||||
if (!check_int($id)) return false;
|
||||
|
|
|
@ -59,9 +59,9 @@ class Group extends BaseModel
|
|||
*/
|
||||
protected $casts = [
|
||||
'creator_id' => 'integer',
|
||||
'max_num' => 'integer',
|
||||
'is_overt' => 'integer',
|
||||
'is_mute' => 'integer',
|
||||
'max_num' => 'integer',
|
||||
'is_overt' => 'integer',
|
||||
'is_mute' => 'integer',
|
||||
'is_dismiss' => 'integer',
|
||||
'created_at' => 'datetime'
|
||||
];
|
||||
|
@ -84,7 +84,7 @@ class Group extends BaseModel
|
|||
*/
|
||||
public static function isManager(int $user_id, int $group_id, $leader = 2)
|
||||
{
|
||||
return self::where('id', $group_id)->where('creator_id', $user_id)->where('leader', $leader)->exists();
|
||||
return self::where('id', $group_id)->where('creator_id', $user_id)->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,11 +51,11 @@ class GroupMember extends BaseModel
|
|||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'group_id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'leader' => 'integer',
|
||||
'is_mute' => 'integer',
|
||||
'is_quit' => 'integer',
|
||||
'group_id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'leader' => 'integer',
|
||||
'is_mute' => 'integer',
|
||||
'is_quit' => 'integer',
|
||||
'created_at' => 'datetime',
|
||||
'deleted_at' => 'datetime',
|
||||
];
|
||||
|
@ -80,7 +80,7 @@ class GroupMember extends BaseModel
|
|||
*/
|
||||
public static function visitCard(int $user_id, int $group_id)
|
||||
{
|
||||
return self::where('group_id', $group_id)->where('user_id', $user_id)->value('visit_card') ?? "";
|
||||
return self::where('group_id', $group_id)->where('user_id', $user_id)->value('user_card') ?? "";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -57,10 +57,10 @@ class GroupNotice extends BaseModel
|
|||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'group_id' => 'integer',
|
||||
'group_id' => 'integer',
|
||||
'creator_id' => 'integer',
|
||||
'is_top' => 'integer',
|
||||
'is_delete' => 'integer',
|
||||
'is_top' => 'integer',
|
||||
'is_delete' => 'integer',
|
||||
'is_confirm' => 'integer',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
|
@ -13,6 +14,7 @@ use Exception;
|
|||
|
||||
/**
|
||||
* Class GroupService
|
||||
*
|
||||
* @package App\Service
|
||||
*/
|
||||
class GroupService extends BaseService
|
||||
|
@ -25,9 +27,7 @@ class GroupService extends BaseService
|
|||
*/
|
||||
public function getGroups(int $user_id): array
|
||||
{
|
||||
$items = GroupMember::join('group', 'group.id', '=', 'group_member.group_id', 'inner', [
|
||||
['group.is_dismiss', '=', 0]
|
||||
])
|
||||
$items = GroupMember::join('group', 'group.id', '=', 'group_member.group_id')
|
||||
->where([
|
||||
['group_member.user_id', '=', $user_id],
|
||||
['group_member.is_quit', '=', 0]
|
||||
|
@ -37,17 +37,17 @@ class GroupService extends BaseService
|
|||
'group.id',
|
||||
'group.group_name',
|
||||
'group.avatar',
|
||||
'group.group_profile',
|
||||
'group.leader',
|
||||
'group.profile',
|
||||
'group_member.leader',
|
||||
])->toArray();
|
||||
|
||||
$arr = UsersChatList::where([
|
||||
['uid', '=', $user_id],
|
||||
['type', '=', 2],
|
||||
])->get(['group_id', 'not_disturb'])->keyBy('group_id')->toArray();
|
||||
|
||||
foreach ($items as $key => $item) {
|
||||
// 是否消息免打扰
|
||||
$items[$key]['not_disturb'] = UsersChatList::where([
|
||||
['uid', '=', $user_id],
|
||||
['type', '=', 2],
|
||||
['group_id', '=', $item['id']]
|
||||
])->value('not_disturb');
|
||||
$items[$key]['not_disturb'] = $arr[$item['id']] ? $arr[$item['id']]['not_disturb'] : 0;
|
||||
}
|
||||
|
||||
return $items;
|
||||
|
@ -72,32 +72,32 @@ class GroupService extends BaseService
|
|||
$insRes = Group::create([
|
||||
'creator_id' => $user_id,
|
||||
'group_name' => $group_info['name'],
|
||||
'avatar' => $group_info['avatar'],
|
||||
'profile' => $group_info['profile'],
|
||||
'max_num' => Group::MAX_MEMBER_NUM,
|
||||
'is_overt' => 0,
|
||||
'is_mute' => 0,
|
||||
'avatar' => $group_info['avatar'],
|
||||
'profile' => $group_info['profile'],
|
||||
'max_num' => Group::MAX_MEMBER_NUM,
|
||||
'is_overt' => 0,
|
||||
'is_mute' => 0,
|
||||
'is_dismiss' => 0,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
foreach ($friend_ids as $k => $uid) {
|
||||
$groupMember[] = [
|
||||
'group_id' => $insRes->id,
|
||||
'user_id' => $uid,
|
||||
'leader' => $user_id == $uid ? 2 : 0,
|
||||
'is_mute' => 0,
|
||||
'is_quit' => 0,
|
||||
'user_card' => 0,
|
||||
'group_id' => $insRes->id,
|
||||
'user_id' => $uid,
|
||||
'leader' => $user_id == $uid ? 2 : 0,
|
||||
'is_mute' => 0,
|
||||
'is_quit' => 0,
|
||||
'user_card' => '',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
|
||||
$chatList[] = [
|
||||
'type' => 2,
|
||||
'uid' => $uid,
|
||||
'friend_id' => 0,
|
||||
'group_id' => $insRes->id,
|
||||
'status' => 1,
|
||||
'type' => 2,
|
||||
'uid' => $uid,
|
||||
'friend_id' => 0,
|
||||
'group_id' => $insRes->id,
|
||||
'status' => 1,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
];
|
||||
|
@ -112,18 +112,18 @@ class GroupService extends BaseService
|
|||
}
|
||||
|
||||
$result = ChatRecord::create([
|
||||
'msg_type' => 3,
|
||||
'source' => 2,
|
||||
'user_id' => 0,
|
||||
'msg_type' => 3,
|
||||
'source' => 2,
|
||||
'user_id' => 0,
|
||||
'receive_id' => $insRes->id,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
ChatRecordsInvite::create([
|
||||
'record_id' => $result->id,
|
||||
'type' => 1,
|
||||
'record_id' => $result->id,
|
||||
'type' => 1,
|
||||
'operate_user_id' => $user_id,
|
||||
'user_ids' => implode(',', $friend_ids)
|
||||
'user_ids' => implode(',', $friend_ids)
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
|
@ -139,7 +139,7 @@ class GroupService extends BaseService
|
|||
}
|
||||
|
||||
/**
|
||||
* 解散群组
|
||||
* 解散群组(群主权限)
|
||||
*
|
||||
* @param int $group_id 群ID
|
||||
* @param int $user_id 用户ID
|
||||
|
@ -152,10 +152,19 @@ class GroupService extends BaseService
|
|||
return false;
|
||||
}
|
||||
|
||||
return Group::where('id', $group_id)->where('creator_id', $user_id)->update([
|
||||
'is_dismiss' => 1,
|
||||
'dismissed_at' => date('Y-m-d H:i:s'),
|
||||
]) ? true : false;
|
||||
DB::transaction(function () use ($group_id, $user_id) {
|
||||
Group::where('id', $group_id)->where('creator_id', $user_id)->update([
|
||||
'is_dismiss' => 1,
|
||||
'dismissed_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
GroupMember::where('group_id', $group_id)->update([
|
||||
'is_quit' => 1,
|
||||
'deleted_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
}, 2);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -168,9 +177,7 @@ class GroupService extends BaseService
|
|||
*/
|
||||
public function invite(int $user_id, int $group_id, $friend_ids = [])
|
||||
{
|
||||
if (empty($friend_ids)) {
|
||||
return [false, 0];
|
||||
}
|
||||
if (!$friend_ids) return [false, 0];
|
||||
|
||||
$info = GroupMember::where('group_id', $group_id)->where('user_id', $user_id)->first(['id', 'is_quit']);
|
||||
|
||||
|
@ -185,14 +192,14 @@ class GroupService extends BaseService
|
|||
$chatArr = UsersChatList::where('group_id', $group_id)->whereIn('uid', $friend_ids)->get(['id', 'uid', 'status'])->keyBy('uid')->toArray();
|
||||
|
||||
foreach ($friend_ids as $uid) {
|
||||
if (!isset($members[$uid])) {//存在聊天群成员记录
|
||||
if (!isset($members[$uid])) {
|
||||
$insertArr[] = [
|
||||
'group_id' => $group_id,
|
||||
'user_id' => $uid,
|
||||
'leader' => 0,
|
||||
'is_mute' => 0,
|
||||
'is_quit' => 0,
|
||||
'user_card' => '',
|
||||
'group_id' => $group_id,
|
||||
'user_id' => $uid,
|
||||
'leader' => 0,
|
||||
'is_mute' => 0,
|
||||
'is_quit' => 0,
|
||||
'user_card' => '',
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
];
|
||||
} else if ($members[$uid]['status'] == 1) {
|
||||
|
@ -201,11 +208,11 @@ class GroupService extends BaseService
|
|||
|
||||
if (!isset($chatArr[$uid])) {
|
||||
$insertArr1[] = [
|
||||
'type' => 2,
|
||||
'uid' => $uid,
|
||||
'friend_id' => 0,
|
||||
'group_id' => $group_id,
|
||||
'status' => 1,
|
||||
'type' => 2,
|
||||
'uid' => $uid,
|
||||
'friend_id' => 0,
|
||||
'group_id' => $group_id,
|
||||
'status' => 1,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
];
|
||||
|
@ -217,10 +224,10 @@ class GroupService extends BaseService
|
|||
try {
|
||||
if ($updateArr) {
|
||||
GroupMember::whereIn('id', $updateArr)->update([
|
||||
'leader' => 0,
|
||||
'is_mute' => 0,
|
||||
'is_quit' => 0,
|
||||
'user_card' => '',
|
||||
'leader' => 0,
|
||||
'is_mute' => 0,
|
||||
'is_quit' => 0,
|
||||
'user_card' => '',
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
@ -231,7 +238,7 @@ class GroupService extends BaseService
|
|||
|
||||
if ($updateArr1) {
|
||||
UsersChatList::whereIn('id', $updateArr1)->update([
|
||||
'status' => 1,
|
||||
'status' => 1,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
@ -241,22 +248,22 @@ class GroupService extends BaseService
|
|||
}
|
||||
|
||||
$result = ChatRecord::create([
|
||||
'msg_type' => 3,
|
||||
'source' => 2,
|
||||
'user_id' => 0,
|
||||
'msg_type' => 3,
|
||||
'source' => 2,
|
||||
'user_id' => 0,
|
||||
'receive_id' => $group_id,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
ChatRecordsInvite::create([
|
||||
'record_id' => $result->id,
|
||||
'type' => 1,
|
||||
'record_id' => $result->id,
|
||||
'type' => 1,
|
||||
'operate_user_id' => $user_id,
|
||||
'user_ids' => implode(',', $friend_ids)
|
||||
'user_ids' => implode(',', $friend_ids)
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
Db::rollBack();
|
||||
return [false, 0];
|
||||
}
|
||||
|
@ -266,7 +273,7 @@ class GroupService extends BaseService
|
|||
}
|
||||
|
||||
/**
|
||||
* 退出群组
|
||||
* 退出群组(仅普通管理员及群成员)
|
||||
*
|
||||
* @param int $user_id 用户ID
|
||||
* @param int $group_id 群组ID
|
||||
|
@ -280,30 +287,35 @@ class GroupService extends BaseService
|
|||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
GroupMember::where('group_id', $group_id)->where('user_id', $user_id)->update([
|
||||
'is_quit' => 1,
|
||||
$count = GroupMember::where('group_id', $group_id)->where('user_id', $user_id)->where('is_quit', 0)->update([
|
||||
'is_quit' => 1,
|
||||
'deleted_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
UsersChatList::where('uid', $user_id)->where('type', 2)->where('group_id', $group_id)->update(['status' => 0]);
|
||||
if ($count == 0) {
|
||||
throw new Exception('更新记录失败...');
|
||||
}
|
||||
|
||||
$result = ChatRecord::create([
|
||||
'msg_type' => 3,
|
||||
'source' => 2,
|
||||
'user_id' => 0,
|
||||
'msg_type' => 3,
|
||||
'source' => 2,
|
||||
'user_id' => 0,
|
||||
'receive_id' => $group_id,
|
||||
'content' => $user_id,
|
||||
'content' => $user_id,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
$record_id = $result->id;
|
||||
|
||||
ChatRecordsInvite::create([
|
||||
'record_id' => $result->id,
|
||||
'type' => 2,
|
||||
'record_id' => $result->id,
|
||||
'type' => 2,
|
||||
'operate_user_id' => $user_id,
|
||||
'user_ids' => $user_id
|
||||
'user_ids' => $user_id
|
||||
]);
|
||||
|
||||
UsersChatList::where('uid', $user_id)->where('type', 2)->where('group_id', $group_id)->update(['status' => 0]);
|
||||
|
||||
Db::commit();
|
||||
} catch (Exception $e) {
|
||||
Db::rollBack();
|
||||
|
@ -323,33 +335,40 @@ class GroupService extends BaseService
|
|||
*/
|
||||
public function removeMember(int $group_id, int $user_id, array $member_ids)
|
||||
{
|
||||
if (!Group::isManager($user_id, $group_id, [1, 2])) {
|
||||
if (!Group::isManager($user_id, $group_id)) {
|
||||
return [false, 0];
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
GroupMember::where('group_id', $group_id)->whereIn('user_id', $member_ids)->whereIn('leader', [0, 1])->update([
|
||||
'is_quit' => 1,
|
||||
$count = GroupMember::where('group_id', $group_id)->whereIn('user_id', $member_ids)->where('is_quit', 0)->update([
|
||||
'is_quit' => 1,
|
||||
'deleted_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
if ($count == 0) {
|
||||
throw new Exception('更新记录失败...');
|
||||
}
|
||||
|
||||
$result = ChatRecord::create([
|
||||
'msg_type' => 3,
|
||||
'source' => 2,
|
||||
'user_id' => 0,
|
||||
'msg_type' => 3,
|
||||
'source' => 2,
|
||||
'user_id' => 0,
|
||||
'receive_id' => $group_id,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
ChatRecordsInvite::create([
|
||||
'record_id' => $result->id,
|
||||
'type' => 3,
|
||||
'record_id' => $result->id,
|
||||
'type' => 3,
|
||||
'operate_user_id' => $user_id,
|
||||
'user_ids' => implode(',', $member_ids)
|
||||
'user_ids' => implode(',', $member_ids)
|
||||
]);
|
||||
|
||||
UsersChatList::whereIn('uid', $member_ids)->where('group_id', $group_id)->update(['status' => 0, 'updated_at' => date('Y-m-d H:i:s')]);
|
||||
UsersChatList::whereIn('uid', $member_ids)->where('group_id', $group_id)->update([
|
||||
'status' => 0,
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
} catch (Exception $e) {
|
||||
|
|
|
@ -48,7 +48,7 @@ return [
|
|||
],
|
||||
'settings' => [
|
||||
'enable_coroutine' => true,
|
||||
'worker_num' => swoole_cpu_num() * 4,
|
||||
'worker_num' => 1,
|
||||
'pid_file' => BASE_PATH . '/runtime/hyperf.pid',
|
||||
'open_tcp_nodelay' => true,
|
||||
'max_coroutine' => 100000,
|
||||
|
|
Loading…
Reference in New Issue