1.优化后端管理员提现方式
2.优化后端
This commit is contained in:
@@ -15,6 +15,11 @@ use Webman\Http\Request as WebmanRequest;
|
||||
*/
|
||||
class User extends Backend
|
||||
{
|
||||
/**
|
||||
* 这些接口只要求登录,不单独校验权限节点
|
||||
*/
|
||||
protected array $noNeedPermission = ['adminScopeTree'];
|
||||
|
||||
/**
|
||||
* User模型对象
|
||||
* @var object|null
|
||||
@@ -22,6 +27,11 @@ class User extends Backend
|
||||
*/
|
||||
protected ?object $model = null;
|
||||
|
||||
/**
|
||||
* 渠道管理员仅可管理自己名下(admin_id=当前管理员)的用户
|
||||
*/
|
||||
protected bool|string|int $dataLimit = true;
|
||||
|
||||
protected array|string $preExcludeFields = ['id', 'uuid', 'create_time', 'update_time', 'invite_code', 'coin', 'total_deposit_coin', 'total_withdraw_coin', 'bet_flow_coin'];
|
||||
|
||||
protected array $withJoinTable = ['channel', 'admin'];
|
||||
@@ -390,9 +400,17 @@ class User extends Backend
|
||||
return $response;
|
||||
}
|
||||
|
||||
$currentAdminLeaf = $this->getCurrentAdminLeaf();
|
||||
if ($currentAdminLeaf === null) {
|
||||
return $this->error(__('Record not found'));
|
||||
}
|
||||
|
||||
$groupIds = $this->getManageableAdminGroupIds();
|
||||
if ($groupIds === []) {
|
||||
return $this->success('', ['list' => []]);
|
||||
return $this->success('', [
|
||||
'list' => [$currentAdminLeaf],
|
||||
'current_admin_id' => $currentAdminLeaf['value'],
|
||||
]);
|
||||
}
|
||||
|
||||
$groups = Db::name('admin_group')
|
||||
@@ -488,12 +506,45 @@ class User extends Backend
|
||||
foreach ($roots as $rid) {
|
||||
$tree[] = $buildNode($rid);
|
||||
}
|
||||
if (!isset($adminPrimary[intval(strval($currentAdminLeaf['value']))])) {
|
||||
$tree[] = $currentAdminLeaf;
|
||||
}
|
||||
|
||||
return $this->success('', [
|
||||
'list' => $tree,
|
||||
'current_admin_id' => $currentAdminLeaf['value'],
|
||||
]);
|
||||
}
|
||||
|
||||
private function getCurrentAdminLeaf(): ?array
|
||||
{
|
||||
$adminIdRaw = $this->auth->id ?? null;
|
||||
if ($adminIdRaw === null || $adminIdRaw === '' || !is_numeric(strval($adminIdRaw))) {
|
||||
return null;
|
||||
}
|
||||
$adminId = intval(strval($adminIdRaw));
|
||||
if ($adminId <= 0) {
|
||||
return null;
|
||||
}
|
||||
$row = Db::name('admin')
|
||||
->field(['id', 'username', 'channel_id', 'invite_code'])
|
||||
->where('id', $adminId)
|
||||
->find();
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
$invite = $row['invite_code'] ?? '';
|
||||
$invite = is_string($invite) ? $invite : '';
|
||||
$channelId = $row['channel_id'] ?? null;
|
||||
return [
|
||||
'value' => strval($adminId),
|
||||
'label' => strval($row['username'] ?? ('#' . strval($adminId))),
|
||||
'is_leaf' => true,
|
||||
'channel_id' => $channelId === null || $channelId === '' ? null : intval(strval($channelId)),
|
||||
'invite_code' => $invite,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace app\admin\controller\user;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use support\think\Db;
|
||||
use support\Response;
|
||||
use Webman\Http\Request as WebmanRequest;
|
||||
|
||||
@@ -79,8 +78,7 @@ class UserWalletRecord extends Backend
|
||||
$table = strtolower($this->model->getTable());
|
||||
$mainShort = $alias[$table] ?? '';
|
||||
if ($mainShort !== '' && $this->auth && !$this->auth->isSuperAdmin()) {
|
||||
$channelIds = $this->getScopedChannelIdsForFilter();
|
||||
$where[] = [$mainShort . '.channel_id', 'in', $channelIds !== [] ? $channelIds : [0]];
|
||||
$where[] = ['user.admin_id', '=', intval(strval($this->auth->id))];
|
||||
}
|
||||
|
||||
$res = $this->model
|
||||
@@ -103,27 +101,4 @@ class UserWalletRecord extends Backend
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 非超管:与渠道管理一致,仅本账号相关渠道
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
private function getScopedChannelIdsForFilter(): array
|
||||
{
|
||||
if (!$this->auth) {
|
||||
return [0];
|
||||
}
|
||||
if ($this->auth->isSuperAdmin()) {
|
||||
return [];
|
||||
}
|
||||
$admin = Db::name('admin')
|
||||
->field(['id', 'channel_id'])
|
||||
->where('id', $this->auth->id)
|
||||
->find();
|
||||
$ids = [];
|
||||
if ($admin && !empty($admin['channel_id'])) {
|
||||
$ids[] = $admin['channel_id'];
|
||||
}
|
||||
return array_values(array_unique($ids));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user