feat(user): 添加用户申请联系功能并优化俱乐部相关操作
- 新增用户申请联系信息功能,包括申请、审核和处理流程 - 优化俱乐部申请、邀请和处理申请的逻辑 - 修复活动不存在时的错误提示 - 优化活动查询条件,支持一次性活动的特殊处理
This commit is contained in:
@@ -38,12 +38,12 @@ class Club extends Base
|
||||
$params = $this->request->param();
|
||||
Db::startTrans();
|
||||
try {
|
||||
$params['president'] = $this->user->id;
|
||||
$params['president'] = $this->auth->id;
|
||||
$result = $this->model->allowField(true)->save($params);
|
||||
$menber = new Menber;
|
||||
$menber->allowField(true)->save([
|
||||
'club_id' => $this->model->id,
|
||||
'user_id' => $this->user->id,
|
||||
'user_id' => $this->auth->id,
|
||||
'role' => 3
|
||||
]);
|
||||
Db::commit();
|
||||
@@ -100,46 +100,58 @@ class Club extends Base
|
||||
public function apply()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$club = $this->model->get($params['club_id']);
|
||||
if (empty($club)) {
|
||||
return $this->error('俱乐部不存在');
|
||||
}
|
||||
if ($club['join_type'] > 1) {
|
||||
$this->error('该俱乐部不允许申请');
|
||||
}
|
||||
if (!empty(Menber::get(['club_id' => $params['club_id'], 'user_id' => $this->user->id]))) {
|
||||
$this->error('您已经是俱乐部成员,无需重复申请');
|
||||
}
|
||||
if ($club['join_type'] == 0) {
|
||||
(new Menber)->allowField(true)->save([
|
||||
'club_id' => $params['club_id'],
|
||||
'user_id' => $this->user->id,
|
||||
'role' => 1
|
||||
Db::startTrans();
|
||||
try {
|
||||
$club = $this->model->get($params['club_id']);
|
||||
if (empty($club)) {
|
||||
return $this->error('俱乐部不存在');
|
||||
}
|
||||
if ($club['join_type'] > 1) {
|
||||
$this->error('该俱乐部不允许申请');
|
||||
}
|
||||
if (!empty(Menber::get(['club_id' => $club->id, 'user_id' => $this->auth->id]))) {
|
||||
$this->error('您已经是俱乐部成员,无需重复申请');
|
||||
}
|
||||
if ($club['join_type'] == 0) {
|
||||
(new Menber)->allowField(true)->save([
|
||||
'club_id' => $club->id,
|
||||
'user_id' => $this->auth->id,
|
||||
'role' => 1
|
||||
]);
|
||||
$this->success('加入成功');
|
||||
}
|
||||
$apply = new Apply;
|
||||
if ($apply::get(['type' => 1, 'user_id' => $this->auth->id, 'target_id' => $club->id, 'status' => 1])) {
|
||||
return $this->error('申请审核中');
|
||||
}
|
||||
$apply->allowField(true)->save([ // 记录申请
|
||||
'type' => 1,
|
||||
'user_id' => $this->auth->id,
|
||||
'target_id' => $club->id,
|
||||
'content' => json_encode(['reason' => $params['reason'] ?? '']),
|
||||
'reason' => $params['reason'],
|
||||
'status' => 1
|
||||
]);
|
||||
$this->success('加入成功');
|
||||
(new Message())->allowField(true)->save([ // 消息通知
|
||||
'type' => 3,
|
||||
'name' => $club->name,
|
||||
'avatar' => $club->logo,
|
||||
'from_id' => $this->auth->id,
|
||||
'target_id' => $club->id,
|
||||
'content' => json_encode([
|
||||
'topic' => '俱乐部加入申请',
|
||||
'俱乐部名称' => $club->name,
|
||||
'申请人' => $this->user->nickname,
|
||||
'申请时间' => date('Y-m-d H:i:s'),
|
||||
'reason' => $params['reason'] ?? '',
|
||||
'apply_id' => $apply->id
|
||||
])
|
||||
]);
|
||||
Db::commit();
|
||||
} catch (ValidateException | PDOException | Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
(new Apply)->allowField(true)->save([ // 记录申请
|
||||
'type' => 1,
|
||||
'user_id' => $this->user->id,
|
||||
'target_id' => $params['club_id'],
|
||||
'content' => json_encode(['reason' => $params['reason'] ?? '']),
|
||||
'reason' => $params['reason'],
|
||||
'status' => 1
|
||||
]);
|
||||
(new Message())->allowField(true)->save([ // 消息通知
|
||||
'type' => 3,
|
||||
'name' => $club->name,
|
||||
'avatar' => $club->logo,
|
||||
'from_id' => $this->user->id,
|
||||
'target_id' => $params['club_id'],
|
||||
'content' => json_encode([
|
||||
'topic' => '俱乐部加入申请',
|
||||
'俱乐部名称' => $club->name,
|
||||
'申请人' => $this->user->nickname,
|
||||
'申请时间' => date('Y-m-d H:i:s'),
|
||||
'reason' => $params['reason'] ?? ''
|
||||
])
|
||||
]);
|
||||
$this->success('已申请,请等候审核');
|
||||
}
|
||||
//join_type 0:'开放加入,无需审核',1:'开放申请,审核加入',2:'会员邀请,无需审核',3:'会员邀请,审核加入',4:'仅管理员邀请,无需审核'
|
||||
@@ -148,50 +160,62 @@ class Club extends Base
|
||||
public function invite()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$club = $this->model->get($params['club_id']);
|
||||
if (empty($club)) {
|
||||
return $this->error('俱乐部不存在');
|
||||
}
|
||||
$menber = Menber::where('club_id', $params['club_id'])
|
||||
->where('user_id', $this->user->id)
|
||||
->where('role', '>', 0)->find();
|
||||
if (empty($menber)) {
|
||||
$this->error('您无权邀请加入俱乐部');
|
||||
}
|
||||
$user = User::get($params['user_id']);
|
||||
if (empty($user)) {
|
||||
return $this->error('用户不存在');
|
||||
}
|
||||
if ($menber['role'] > 1 || $club['join_type'] == 0 || $club['join_type'] == 2) { // 管理员或者开放加入
|
||||
(new Menber)->allowField(true)->save([
|
||||
'club_id' => $club->id,
|
||||
Db::startTrans();
|
||||
try {
|
||||
$club = $this->model->get($params['club_id']);
|
||||
if (empty($club)) {
|
||||
return $this->error('俱乐部不存在');
|
||||
}
|
||||
$menber = Menber::where('club_id', $params['club_id'])
|
||||
->where('user_id', $this->auth->id)
|
||||
->where('role', '>', 0)->find();
|
||||
if (empty($menber)) {
|
||||
$this->error('您无权邀请加入俱乐部');
|
||||
}
|
||||
$user = User::get($params['user_id']);
|
||||
if (empty($user)) {
|
||||
return $this->error('用户不存在');
|
||||
}
|
||||
$apply = new Apply;
|
||||
if ($apply::get(['type' => 1, 'user_id' => $this->auth->id, 'target_id' => $user->id, 'status' => 1])) {
|
||||
return $this->error('申请审核中');
|
||||
}
|
||||
if ($menber['role'] > 1 || $club['join_type'] == 0 || $club['join_type'] == 2) { // 管理员或者开放加入
|
||||
(new Menber)->allowField(true)->save([
|
||||
'club_id' => $club->id,
|
||||
'user_id' => $user->id,
|
||||
'role' => 1
|
||||
]);
|
||||
$this->success('邀请加入成功');
|
||||
}
|
||||
$apply->allowField(true)->save([ // 记录申请
|
||||
'type' => 1,
|
||||
'user_id' => $user->id,
|
||||
'role' => 1
|
||||
'target_id' => $club->id,
|
||||
'content' => json_encode(['reason' => $params['reason'] ?? '']),
|
||||
'reason' => $params['reason'],
|
||||
'status' => 1
|
||||
]);
|
||||
$this->success('邀请加入成功');
|
||||
(new Message())->allowField(true)->save([ // 消息通知
|
||||
'type' => 3,
|
||||
'name' => $club->name,
|
||||
'avatar' => $club->logo,
|
||||
'from_id' => $this->auth->id,
|
||||
'target_id' => $params['club_id'],
|
||||
'content' => json_encode([
|
||||
'topic' => '俱乐部加入申请',
|
||||
'俱乐部名称' => $club->name,
|
||||
'申请人' => $user->nickname,
|
||||
'申请时间' => date('Y-m-d H:i:s'),
|
||||
'reason' => $params['reason'] ?? '',
|
||||
'apply_id' => $apply->id,
|
||||
])
|
||||
]);
|
||||
Db::commit();
|
||||
} catch (ValidateException | PDOException | Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
(new Apply)->allowField(true)->save([ // 记录申请
|
||||
'type' => 1,
|
||||
'user_id' => $user->id,
|
||||
'target_id' => $club->id,
|
||||
'content' => json_encode(['reason' => $params['reason'] ?? '']),
|
||||
'reason' => $params['reason'],
|
||||
'status' => 1
|
||||
]);
|
||||
(new Message())->allowField(true)->save([ // 消息通知
|
||||
'type' => 3,
|
||||
'name' => $club->name,
|
||||
'avatar' => $club->logo,
|
||||
'from_id' => $this->user->id,
|
||||
'target_id' => $params['club_id'],
|
||||
'content' => json_encode([
|
||||
'topic' => '俱乐部加入申请',
|
||||
'俱乐部名称' => $club->name,
|
||||
'申请人' => $this->user->nickname,
|
||||
'申请时间' => date('Y-m-d H:i:s'),
|
||||
'reason' => $params['reason'] ?? ''
|
||||
])
|
||||
]);
|
||||
$this->success('已邀请,请等候审核');
|
||||
}
|
||||
|
||||
@@ -204,7 +228,7 @@ class Club extends Base
|
||||
return $this->error('俱乐部不存在');
|
||||
}
|
||||
$menber = Menber::where('club_id', $params['club_id'])
|
||||
->where('user_id', $this->user->id)
|
||||
->where('user_id', $this->auth->id)
|
||||
->where('role', '>', 1)->find();
|
||||
if (empty($menber)) {
|
||||
$this->error('您无权处理申请');
|
||||
@@ -221,31 +245,37 @@ class Club extends Base
|
||||
public function handle()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$apply = Apply::get($params['apply_id']);
|
||||
$menber = Menber::where('club_id', $apply['target_id'])
|
||||
->where('user_id', $this->user->id)
|
||||
->where('role', '>', 1)->find();
|
||||
if (empty($menber)) {
|
||||
$this->error('您无权处理申请');
|
||||
}
|
||||
if (empty($apply)) {
|
||||
return $this->error('申请记录不存在');
|
||||
}
|
||||
if ($apply['status'] != 1) {
|
||||
return $this->error('该申请已处理');
|
||||
}
|
||||
if ($params['status'] == 2) {
|
||||
(new Menber)->allowField(true)->save([
|
||||
'club_id' => $apply['target_id'],
|
||||
'user_id' => $apply['user_id'],
|
||||
'role' => 1
|
||||
Db::startTrans();
|
||||
try {
|
||||
$apply = Apply::get(['id' => $params['apply_id'], 'status' => 1]);
|
||||
if (empty($apply)) {
|
||||
return $this->error('申请记录不存在');
|
||||
}
|
||||
$menber = Menber::where('club_id', $apply['target_id'])
|
||||
->where('user_id', $this->auth->id)
|
||||
->where('role', '>', 1)->find();
|
||||
if (empty($menber)) {
|
||||
$this->error('您无权处理申请');
|
||||
}
|
||||
if ($apply['status'] != 1) {
|
||||
return $this->error('该申请已处理');
|
||||
}
|
||||
if ($params['status'] == 2) {
|
||||
(new Menber)->allowField(true)->save([
|
||||
'club_id' => $apply['target_id'],
|
||||
'user_id' => $apply['user_id'],
|
||||
'role' => 1
|
||||
]);
|
||||
}
|
||||
$apply->save([
|
||||
'status' => $params['status'],
|
||||
'reply' => $params['reply'] ?? ''
|
||||
]);
|
||||
Db::commit();
|
||||
} catch (ValidateException | PDOException | Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$apply->save([
|
||||
'status' => $params['status'],
|
||||
'reply' => $params['reply'] ?? ''
|
||||
]);
|
||||
|
||||
$this->success('处理成功');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user