俱乐部完善
This commit is contained in:
@@ -76,6 +76,12 @@ class Club extends Base
|
||||
} else {
|
||||
$query->where('role', '>', 0);
|
||||
}
|
||||
if (isset($params['nickname'])) {
|
||||
$query->where('nickname', 'LIKE', '%' . $params['nickname'] . '%');
|
||||
}
|
||||
if (isset($params['order'])) {
|
||||
$query->order($params['order'], $params['sort'] ?? NULL);
|
||||
}
|
||||
$res = $query->select();
|
||||
|
||||
$this->success('Success', $res);
|
||||
@@ -112,50 +118,57 @@ class Club extends Base
|
||||
if ($club['join_type'] > 1) {
|
||||
$this->error('该俱乐部不允许申请');
|
||||
}
|
||||
if (!empty(Menber::get(['club_id' => $club->id, 'user_id' => $this->auth->id]))) {
|
||||
$this->error('您已经是俱乐部成员,无需重复申请');
|
||||
$user = Menber::get(['club_id' => $club->id, 'user_id' => $this->auth->id]);
|
||||
if (empty($user)) {
|
||||
$user = new Menber;
|
||||
} else {
|
||||
if ($user['role'] > 0) {
|
||||
$this->error('您已经是俱乐部成员,无需重复申请');
|
||||
} else if ($user['role'] == -1) {
|
||||
$this->error('您已被管理员拉黑');
|
||||
}
|
||||
}
|
||||
if ($club['join_type'] == 0) {
|
||||
(new Menber)->allowField(true)->save([
|
||||
$user->allowField(true)->save([
|
||||
'club_id' => $club->id,
|
||||
'user_id' => $this->auth->id,
|
||||
'role' => 1
|
||||
]);
|
||||
$this->success('加入成功');
|
||||
} else {
|
||||
if (Apply::get(['type' => 1, 'user_id' => $this->auth->id, 'target_id' => $club->id, 'status' => 1])) {
|
||||
return $this->error('申请审核中');
|
||||
}
|
||||
$apply = new Apply;
|
||||
$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
|
||||
]);
|
||||
(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
|
||||
])
|
||||
]);
|
||||
}
|
||||
$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
|
||||
]);
|
||||
(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());
|
||||
}
|
||||
$this->success('已申请,请等候审核');
|
||||
$this->success('Success');
|
||||
}
|
||||
//join_type 0:'开放加入,无需审核',1:'开放申请,审核加入',2:'会员邀请,无需审核',3:'会员邀请,审核加入',4:'仅管理员邀请,无需审核'
|
||||
|
||||
@@ -169,57 +182,67 @@ class Club extends Base
|
||||
if (empty($club)) {
|
||||
return $this->error('俱乐部不存在');
|
||||
}
|
||||
$user = User::get($params['user_id']);
|
||||
if (empty($user)) {
|
||||
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('申请审核中');
|
||||
$invate = Menber::get(['user_id' => $params['user_id'], 'club_id' => $params['club_id']]);
|
||||
if (empty($invate)) {
|
||||
$invate = new Menber;
|
||||
} else {
|
||||
if ($invate['role'] > 0) {
|
||||
$this->error('用户已在俱乐部');
|
||||
} else if ($invate['role'] == -1) {
|
||||
$this->error('用户已被管理员拉黑');
|
||||
}
|
||||
}
|
||||
if ($menber['role'] > 1 || $club['join_type'] == 0 || $club['join_type'] == 2) { // 管理员或者开放加入
|
||||
(new Menber)->allowField(true)->save([
|
||||
$invate->allowField(true)->save([
|
||||
'club_id' => $club->id,
|
||||
'user_id' => $user->id,
|
||||
'role' => 1
|
||||
]);
|
||||
$this->success('邀请加入成功');
|
||||
} else {
|
||||
if (Apply::get(['type' => 1, 'user_id' => $this->auth->id, 'target_id' => $user->id, 'status' => 1])) {
|
||||
return $this->error('申请审核中');
|
||||
}
|
||||
$apply = new Apply;
|
||||
$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->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,
|
||||
])
|
||||
]);
|
||||
}
|
||||
$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->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());
|
||||
}
|
||||
$this->success('已邀请,请等候审核');
|
||||
$this->success('Success');
|
||||
}
|
||||
|
||||
// 获取申请列表
|
||||
@@ -270,7 +293,7 @@ class Club extends Base
|
||||
'role' => 1
|
||||
]);
|
||||
}
|
||||
$apply->save([
|
||||
$apply->allowField(true)->save([
|
||||
'status' => $params['status'],
|
||||
'reply' => $params['reply'] ?? ''
|
||||
]);
|
||||
@@ -279,6 +302,53 @@ class Club extends Base
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success('处理成功');
|
||||
$this->success('Success');
|
||||
}
|
||||
|
||||
// 设置成员角色
|
||||
public function setmember()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$user = Menber::where('club_id', $params['club_id'])
|
||||
->where('user_id', $this->auth->id)
|
||||
->where('role', '>', 1)->find();
|
||||
if (empty($user)) {
|
||||
$this->error('无权限');
|
||||
}
|
||||
if (isset($params['role']) && ($params['role'] < -1 || $params['role'] > 2)) {
|
||||
$this->error('非法角色');
|
||||
}
|
||||
$menber = Menber::where('club_id', $params['club_id'])->where('user_id', 'IN', explode(',', $params['user_id']))->select();
|
||||
if (empty($menber)) {
|
||||
$this->error('成员不存在');
|
||||
}
|
||||
if ($user['role'] != 3) {
|
||||
if (isset($params['role']) && $params['role'] > 1) {
|
||||
$this->error('只有会长才能设置管理员');
|
||||
}
|
||||
foreach ($menber as $m) {
|
||||
if ($m['role'] > 1) $this->error('只有会长才能修改管理员');
|
||||
}
|
||||
} else {
|
||||
foreach ($menber as $m) {
|
||||
if ($m['role'] == 3 && isset($params['role'])) {
|
||||
$this->error('不可修改会长角色');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$update = [];
|
||||
if (isset($params['role'])) $update['role'] = $params['role'];
|
||||
if (isset($params['remark'])) $update['remark'] = $params['remark'];
|
||||
if (isset($params['tags'])) $update['tags'] = $params['tags'];
|
||||
Db::startTrans();
|
||||
try {
|
||||
Menber::where('club_id', $params['club_id'])->where('user_id', 'IN', explode(',', $params['user_id']))->update($update);
|
||||
Db::commit();
|
||||
} catch (ValidateException | PDOException | Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success('Success');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user