refactor(shopro): 优化代码中的用户 ID 处理逻辑

This commit is contained in:
2025-06-14 16:59:21 +08:00
parent 70baaa2fd5
commit 0432965b88
2 changed files with 6 additions and 5 deletions

View File

@@ -392,7 +392,8 @@ class Club extends Base
if (isset($params['role']) && ($params['role'] < -1 || $params['role'] > 2)) { if (isset($params['role']) && ($params['role'] < -1 || $params['role'] > 2)) {
$this->error('非法角色'); $this->error('非法角色');
} }
$menber = Menber::where('club_id', $params['club_id'])->where('user_id', 'IN', explode(',', $params['user_id']))->select(); $user_ids = explode(',', $params['user_id'] ?? '');
$menber = Menber::where('club_id', $params['club_id'])->where('user_id', 'IN', $user_ids)->select();
if (empty($menber)) { if (empty($menber)) {
$this->error('成员不存在'); $this->error('成员不存在');
} }
@@ -417,7 +418,7 @@ class Club extends Base
if (isset($params['tags'])) $update['tags'] = $params['tags']; if (isset($params['tags'])) $update['tags'] = $params['tags'];
Db::startTrans(); Db::startTrans();
try { try {
Menber::where('club_id', $params['club_id'])->where('user_id', 'IN', explode(',', $params['user_id']))->update($update); Menber::where('club_id', $params['club_id'])->where('user_id', 'IN', $user_ids)->update($update);
Db::commit(); Db::commit();
} catch (ValidateException | PDOException | Exception $e) { } catch (ValidateException | PDOException | Exception $e) {
Db::rollback(); Db::rollback();

View File

@@ -77,7 +77,7 @@ class Game extends Base
$this->model->where('id', $model['id'])->setInc('attention'); $this->model->where('id', $model['id'])->setInc('attention');
$model['cost'] = json_decode($model['cost'] ?? '[]', true); $model['cost'] = json_decode($model['cost'] ?? '[]', true);
$model['referee'] = explode(',', $model['referee']); $model['referee'] = explode(',', $model['referee'] ?? '');
$this->success('Success', $model); $this->success('Success', $model);
} }
@@ -261,7 +261,7 @@ class Game extends Base
$this->error('用户不存在'); $this->error('用户不存在');
} }
$game = $this->model->get($user['game_id']); $game = $this->model->get($user['game_id']);
$referee = explode(',', $game['referee']); //裁判 $referee = explode(',', $game['referee'] ?? ''); //裁判
$menber = Menber::where(['club_id' => $game['club_id'], 'user_id' => $this->auth->id])->where('role', '>', 1)->find(); $menber = Menber::where(['club_id' => $game['club_id'], 'user_id' => $this->auth->id])->where('role', '>', 1)->find();
if (empty($menber) && !in_array($this->auth->id, $referee)) { if (empty($menber) && !in_array($this->auth->id, $referee)) {
$this->error('您没有权限'); $this->error('您没有权限');
@@ -354,7 +354,7 @@ class Game extends Base
$this->error('对阵记录不存在'); $this->error('对阵记录不存在');
} }
$game = $this->model->get($match['game_id']); $game = $this->model->get($match['game_id']);
$referee = explode(',', $game['referee']); $referee = explode(',', $game['referee']?? '');
if (empty($referee)) { if (empty($referee)) {
$this->error('请先设置裁判'); $this->error('请先设置裁判');
} }