优化管理员审核

This commit is contained in:
2026-04-24 10:44:46 +08:00
parent f7d0ee81f8
commit d69412a0f7
2 changed files with 35 additions and 24 deletions

View File

@@ -14,7 +14,7 @@ use Webman\Http\Request as WebmanRequest;
*/ */
class AdminWithdrawOrder extends Backend class AdminWithdrawOrder extends Backend
{ {
protected array $noNeedPermission = ['stats']; protected array $noNeedPermission = ['stats', 'approve', 'reject'];
protected ?object $model = null; protected ?object $model = null;
@@ -43,7 +43,7 @@ class AdminWithdrawOrder extends Backend
$table = strtolower($this->model->getTable()); $table = strtolower($this->model->getTable());
$mainShort = $alias[$table] ?? ''; $mainShort = $alias[$table] ?? '';
if ($mainShort !== '' && $this->auth && !$this->auth->isSuperAdmin()) { if ($mainShort !== '' && $this->auth && !$this->auth->isSuperAdmin()) {
$where[] = [$mainShort . '.channel_id', 'in', $this->getCurrentAdminTopChannelIds()]; $where[] = [$mainShort . '.channel_id', 'in', $this->getCurrentAdminChannelIds()];
} }
$res = $this->model $res = $this->model
->withJoin($this->withJoinTable, $this->withJoinType) ->withJoin($this->withJoinTable, $this->withJoinType)
@@ -58,8 +58,13 @@ class AdminWithdrawOrder extends Backend
->order($order) ->order($order)
->paginate($limit); ->paginate($limit);
$list = $res->items();
foreach ($list as $idx => $item) {
$list[$idx]['can_review'] = $this->canReviewOrder(is_array($item) ? $item : []) ? 1 : 0;
}
return $this->success('', [ return $this->success('', [
'list' => $res->items(), 'list' => $list,
'total' => $res->total(), 'total' => $res->total(),
'remark' => get_route_remark(), 'remark' => get_route_remark(),
]); ]);
@@ -166,7 +171,7 @@ class AdminWithdrawOrder extends Backend
} }
$query = Db::name('admin_withdraw_order'); $query = Db::name('admin_withdraw_order');
if ($this->auth && !$this->auth->isSuperAdmin()) { if ($this->auth && !$this->auth->isSuperAdmin()) {
$query->where('channel_id', 'in', $this->getCurrentAdminTopChannelIds()); $query->where('channel_id', 'in', $this->getCurrentAdminChannelIds());
} }
$rows = $query->field(['status', 'amount', 'actual_amount'])->select()->toArray(); $rows = $query->field(['status', 'amount', 'actual_amount'])->select()->toArray();
$total = count($rows); $total = count($rows);
@@ -229,39 +234,45 @@ class AdminWithdrawOrder extends Backend
if ($channelId <= 0) { if ($channelId <= 0) {
return false; return false;
} }
$allowed = $this->getCurrentAdminTopChannelIds(); $allowed = $this->getCurrentAdminChannelIds();
return in_array($channelId, $allowed, true); return in_array($channelId, $allowed, true);
} }
/** /**
* 当前管理员可审核的“顶级角色组(pid=0)”所属渠道 * 当前管理员可审核的渠道(优先取自身 channel_id同时兼容角色组继承链上的 channel_id
* *
* @return int[] * @return int[]
*/ */
private function getCurrentAdminTopChannelIds(): array private function getCurrentAdminChannelIds(): array
{ {
$uid = intval($this->auth->id ?? 0); $uid = intval($this->auth->id ?? 0);
if ($uid <= 0) { if ($uid <= 0) {
return [0]; return [0];
} }
$groupIds = Db::name('admin_group_access')->where('uid', $uid)->column('group_id');
if ($groupIds === []) {
return [0];
}
$rows = Db::name('admin_group')
->field(['id', 'pid', 'channel_id'])
->where('id', 'in', $groupIds)
->where('pid', 0)
->whereNotNull('channel_id')
->select()
->toArray();
$channelIds = []; $channelIds = [];
foreach ($rows as $row) {
$cid = intval($row['channel_id'] ?? 0); $selfChannelId = intval(Db::name('admin')->where('id', $uid)->value('channel_id') ?? 0);
if ($cid > 0) { if ($selfChannelId > 0) {
$channelIds[] = $cid; $channelIds[] = $selfChannelId;
}
$groupIds = Db::name('admin_group_access')->where('uid', $uid)->column('group_id');
if ($groupIds !== []) {
$groupIds = array_values(array_unique(array_merge($groupIds, $this->auth->getAdminChildGroups())));
$rows = Db::name('admin_group')
->field(['id', 'channel_id'])
->where('id', 'in', $groupIds)
->whereNotNull('channel_id')
->select()
->toArray();
foreach ($rows as $row) {
$cid = intval($row['channel_id'] ?? 0);
if ($cid > 0) {
$channelIds[] = $cid;
}
} }
} }
return $channelIds === [] ? [0] : array_values(array_unique($channelIds)); return $channelIds === [] ? [0] : array_values(array_unique($channelIds));
} }
} }

View File

@@ -101,7 +101,7 @@ const optButtons: OptButton[] = [
text: '', text: '',
type: 'success', type: 'success',
icon: 'el-icon-Check', icon: 'el-icon-Check',
display: (row: TableRow) => Number(row.status) === 0, display: (row: TableRow) => Number(row.status) === 0 && Number((row as anyObj).can_review ?? 0) === 1,
click: (row: TableRow) => void onReview(row as anyObj, 'approve'), click: (row: TableRow) => void onReview(row as anyObj, 'approve'),
}, },
{ {
@@ -111,7 +111,7 @@ const optButtons: OptButton[] = [
text: '', text: '',
type: 'danger', type: 'danger',
icon: 'el-icon-Close', icon: 'el-icon-Close',
display: (row: TableRow) => Number(row.status) === 0, display: (row: TableRow) => Number(row.status) === 0 && Number((row as anyObj).can_review ?? 0) === 1,
click: (row: TableRow) => void onReview(row as anyObj, 'reject'), click: (row: TableRow) => void onReview(row as anyObj, 'reject'),
}, },
] ]