群操作完结
This commit is contained in:
@@ -6,6 +6,7 @@ use app\chat\model\ChatGroupMember;
|
|||||||
use app\chat\model\ChatGroupMute;
|
use app\chat\model\ChatGroupMute;
|
||||||
use app\chat\model\ChatDoNotDisturb;
|
use app\chat\model\ChatDoNotDisturb;
|
||||||
use app\common\controller\ApiController;
|
use app\common\controller\ApiController;
|
||||||
|
use app\exception\MyBusinessException;
|
||||||
use app\utils\Session;
|
use app\utils\Session;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
use support\Response;
|
use support\Response;
|
||||||
@@ -124,17 +125,56 @@ class GroupController extends ApiController
|
|||||||
$insert_arr['group_id'] = $decryptedText_arr['group_id'];
|
$insert_arr['group_id'] = $decryptedText_arr['group_id'];
|
||||||
$group_id = $decryptedText_arr['group_id'];
|
$group_id = $decryptedText_arr['group_id'];
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
// 加入群
|
Db::startTrans();
|
||||||
if($is_insert) {
|
// 插入用户信息
|
||||||
$res = Db::name('chat_group_member')->insert($insert_arr);
|
if($this->user_type == 1) {
|
||||||
}else {
|
// 用户
|
||||||
$res = Db::name('chat_group_member')->where(['user_id' => $this->uid, 'group_id' => $group_id])->update($insert_arr);
|
$user = Db::name('tb_user_info')->where(['id' => $this->uid])->find();
|
||||||
}
|
if($user) {
|
||||||
if($res) {
|
$user_arr = [
|
||||||
return $this->success();
|
'user_id' => $this->uid,
|
||||||
}else {
|
'nick_name' => $user['nick_name'],
|
||||||
return $this->error();
|
'avatar' => $user['head_img'],
|
||||||
|
'type' => 1,
|
||||||
|
'created_time' => d(),
|
||||||
|
];
|
||||||
|
}else {
|
||||||
|
throw new MyBusinessException('用户信息不存在');
|
||||||
|
}
|
||||||
|
}elseif ($this->user_type == 2) {
|
||||||
|
// 商家
|
||||||
|
$user = Db::name('sys_user')->where(['id' => $this->uid])->find();
|
||||||
|
if($user) {
|
||||||
|
$user_arr = [
|
||||||
|
'user_id' => $this->uid,
|
||||||
|
'nick_name' => $user['nick_name'],
|
||||||
|
'avatar' => $user['avatar'],
|
||||||
|
'type' => 2,
|
||||||
|
'created_time' => d(),
|
||||||
|
];
|
||||||
|
}else {
|
||||||
|
throw new MyBusinessException('用户信息不存在');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!Db::name('chat_user')->where(['user_id' => $this->uid])->find()) {
|
||||||
|
Db::name('chat_user')->insert($user_arr);
|
||||||
|
}
|
||||||
|
// 加入群
|
||||||
|
if($is_insert) {
|
||||||
|
$res = Db::name('chat_group_member')->insert($insert_arr);
|
||||||
|
}else {
|
||||||
|
$res = Db::name('chat_group_member')->where(['user_id' => $this->uid, 'group_id' => $group_id])->update($insert_arr);
|
||||||
|
}
|
||||||
|
Db::commit();
|
||||||
|
if($res) {
|
||||||
|
return $this->success();
|
||||||
|
}else {
|
||||||
|
return $this->error();
|
||||||
|
}
|
||||||
|
}catch (\Throwable $exception) {
|
||||||
|
Db::rollback();
|
||||||
|
return $this->error($exception->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user