1.优化后端管理员提现方式

2.优化后端
This commit is contained in:
2026-04-23 14:11:55 +08:00
parent aa1299c018
commit 378be9909d
9 changed files with 362 additions and 175 deletions

View File

@@ -21,16 +21,16 @@ class Dashboard extends Backend
return $response; return $response;
} }
$scope = $this->channelScopeOrNull(); $ownerAdminId = $this->ownerAdminIdOrNull();
$todayStart = strtotime(date('Y-m-d')); $todayStart = strtotime(date('Y-m-d'));
$todayEnd = $todayStart + 86400 - 1; $todayEnd = $todayStart + 86400 - 1;
$yesterdayStart = $todayStart - 86400; $yesterdayStart = $todayStart - 86400;
$yesterdayEnd = $todayStart - 1; $yesterdayEnd = $todayStart - 1;
$userTotal = $this->countUsers($scope); $userTotal = $this->countUsers($ownerAdminId);
$newToday = $this->countUsersInRange($scope, $todayStart, $todayEnd); $newToday = $this->countUsersInRange($ownerAdminId, $todayStart, $todayEnd);
$newYesterday = $this->countUsersInRange($scope, $yesterdayStart, $yesterdayEnd); $newYesterday = $this->countUsersInRange($ownerAdminId, $yesterdayStart, $yesterdayEnd);
$growthPct = null; $growthPct = null;
if ($newYesterday > 0) { if ($newYesterday > 0) {
$growthPct = round(($newToday - $newYesterday) / $newYesterday * 100, 1); $growthPct = round(($newToday - $newYesterday) / $newYesterday * 100, 1);
@@ -38,14 +38,14 @@ class Dashboard extends Backend
$growthPct = 100.0; $growthPct = 100.0;
} }
$depositAgg = $this->aggregateDepositToday($scope, $todayStart, $todayEnd); $depositAgg = $this->aggregateDepositToday($ownerAdminId, $todayStart, $todayEnd);
$withdrawPending = $this->countWithdrawPending($scope); $withdrawPending = $this->countWithdrawPending($ownerAdminId);
$betAgg = $this->aggregateBetToday($scope, $todayStart, $todayEnd); $betAgg = $this->aggregateBetToday($ownerAdminId, $todayStart, $todayEnd);
$trend = $this->buildSevenDayTrend($scope); $trend = $this->buildSevenDayTrend($ownerAdminId);
$channelShare = $this->buildChannelShare($scope); $channelShare = $this->buildChannelShare($ownerAdminId);
$depositAmountChannelShare = $this->buildDepositAmountChannelShare($scope); $depositAmountChannelShare = $this->buildDepositAmountChannelShare($ownerAdminId);
$recentUsers = $this->fetchRecentUsers($scope, 10); $recentUsers = $this->fetchRecentUsers($ownerAdminId, 10);
return $this->success('', [ return $this->success('', [
'remark' => get_route_remark(), 'remark' => get_route_remark(),
@@ -68,27 +68,27 @@ class Dashboard extends Backend
} }
/** /**
* @param int[]|null $scope null=超管不限制;非 null 时 whereIn channel_id * @param int|null $ownerAdminId null=超管不限制;非 null 时 where admin_id
*/ */
private function countUsers(?array $scope): int private function countUsers(?int $ownerAdminId): int
{ {
$q = Db::name('user'); $q = Db::name('user');
if ($scope !== null) { if ($ownerAdminId !== null) {
$q->whereIn('channel_id', $scope); $q->where('admin_id', '=', $ownerAdminId);
} }
return intval($q->count()); return intval($q->count());
} }
/** /**
* @param int[]|null $scope * @param int|null $ownerAdminId
*/ */
private function countUsersInRange(?array $scope, int $start, int $end): int private function countUsersInRange(?int $ownerAdminId, int $start, int $end): int
{ {
$q = Db::name('user') $q = Db::name('user')
->where('create_time', '>=', $start) ->where('create_time', '>=', $start)
->where('create_time', '<=', $end); ->where('create_time', '<=', $end);
if ($scope !== null) { if ($ownerAdminId !== null) {
$q->whereIn('channel_id', $scope); $q->where('admin_id', '=', $ownerAdminId);
} }
return intval($q->count()); return intval($q->count());
} }
@@ -96,17 +96,17 @@ class Dashboard extends Backend
/** /**
* 今日成功充值status=1按创建日落在今日与 mock 即时成功一致)。 * 今日成功充值status=1按创建日落在今日与 mock 即时成功一致)。
* *
* @param int[]|null $scope * @param int|null $ownerAdminId
* @return array{count:int, amount:string} * @return array{count:int, amount:string}
*/ */
private function aggregateDepositToday(?array $scope, int $todayStart, int $todayEnd): array private function aggregateDepositToday(?int $ownerAdminId, int $todayStart, int $todayEnd): array
{ {
$q = Db::name('deposit_order') $q = Db::name('deposit_order')
->where('status', 1) ->where('status', 1)
->where('create_time', '>=', $todayStart) ->where('create_time', '>=', $todayStart)
->where('create_time', '<=', $todayEnd); ->where('create_time', '<=', $todayEnd);
if ($scope !== null) { if ($ownerAdminId !== null) {
$q->whereIn('channel_id', $scope); $q->whereIn('user_id', $this->scopedUserIds($ownerAdminId));
} }
$rows = $q->fieldRaw('COUNT(*) AS c, COALESCE(SUM(CAST(amount AS DECIMAL(18,2))),0) AS s')->find(); $rows = $q->fieldRaw('COUNT(*) AS c, COALESCE(SUM(CAST(amount AS DECIMAL(18,2))),0) AS s')->find();
if (!is_array($rows)) { if (!is_array($rows)) {
@@ -120,13 +120,13 @@ class Dashboard extends Backend
} }
/** /**
* @param int[]|null $scope * @param int|null $ownerAdminId
*/ */
private function countWithdrawPending(?array $scope): int private function countWithdrawPending(?int $ownerAdminId): int
{ {
$q = Db::name('withdraw_order')->where('status', 0); $q = Db::name('withdraw_order')->where('status', 0);
if ($scope !== null) { if ($ownerAdminId !== null) {
$q->whereIn('channel_id', $scope); $q->whereIn('user_id', $this->scopedUserIds($ownerAdminId));
} }
return intval($q->count()); return intval($q->count());
} }
@@ -134,17 +134,17 @@ class Dashboard extends Backend
/** /**
* 今日投注创建时间在今日且订单未作废status 1 或 2 * 今日投注创建时间在今日且订单未作废status 1 或 2
* *
* @param int[]|null $scope * @param int|null $ownerAdminId
* @return array{count:int, amount:string} * @return array{count:int, amount:string}
*/ */
private function aggregateBetToday(?array $scope, int $todayStart, int $todayEnd): array private function aggregateBetToday(?int $ownerAdminId, int $todayStart, int $todayEnd): array
{ {
$q = Db::name('bet_order') $q = Db::name('bet_order')
->whereIn('status', [1, 2]) ->whereIn('status', [1, 2])
->where('create_time', '>=', $todayStart) ->where('create_time', '>=', $todayStart)
->where('create_time', '<=', $todayEnd); ->where('create_time', '<=', $todayEnd);
if ($scope !== null) { if ($ownerAdminId !== null) {
$q->whereIn('channel_id', $scope); $q->whereIn('user_id', $this->scopedUserIds($ownerAdminId));
} }
$rows = $q->fieldRaw('COUNT(*) AS c, COALESCE(SUM(CAST(total_amount AS DECIMAL(18,2))),0) AS s')->find(); $rows = $q->fieldRaw('COUNT(*) AS c, COALESCE(SUM(CAST(total_amount AS DECIMAL(18,2))),0) AS s')->find();
if (!is_array($rows)) { if (!is_array($rows)) {
@@ -157,10 +157,10 @@ class Dashboard extends Backend
} }
/** /**
* @param int[]|null $scope * @param int|null $ownerAdminId
* @return array{days:string[], new_users:int[], deposit_amount:string[], bet_amount:string[]} * @return array{days:string[], new_users:int[], deposit_amount:string[], bet_amount:string[]}
*/ */
private function buildSevenDayTrend(?array $scope): array private function buildSevenDayTrend(?int $ownerAdminId): array
{ {
$days = []; $days = [];
$newUsers = []; $newUsers = [];
@@ -172,14 +172,14 @@ class Dashboard extends Backend
$dayEnd = $dayStart + 86400 - 1; $dayEnd = $dayStart + 86400 - 1;
$days[] = date('m-d', $dayStart); $days[] = date('m-d', $dayStart);
$newUsers[] = $this->countUsersInRange($scope, $dayStart, $dayEnd); $newUsers[] = $this->countUsersInRange($ownerAdminId, $dayStart, $dayEnd);
$dq = Db::name('deposit_order') $dq = Db::name('deposit_order')
->where('status', 1) ->where('status', 1)
->where('create_time', '>=', $dayStart) ->where('create_time', '>=', $dayStart)
->where('create_time', '<=', $dayEnd); ->where('create_time', '<=', $dayEnd);
if ($scope !== null) { if ($ownerAdminId !== null) {
$dq->whereIn('channel_id', $scope); $dq->whereIn('user_id', $this->scopedUserIds($ownerAdminId));
} }
$drow = $dq->fieldRaw('COALESCE(SUM(CAST(amount AS DECIMAL(18,2))),0) AS s')->find(); $drow = $dq->fieldRaw('COALESCE(SUM(CAST(amount AS DECIMAL(18,2))),0) AS s')->find();
$dsum = is_array($drow) && isset($drow['s']) ? strval($drow['s']) : '0'; $dsum = is_array($drow) && isset($drow['s']) ? strval($drow['s']) : '0';
@@ -189,8 +189,8 @@ class Dashboard extends Backend
->whereIn('status', [1, 2]) ->whereIn('status', [1, 2])
->where('create_time', '>=', $dayStart) ->where('create_time', '>=', $dayStart)
->where('create_time', '<=', $dayEnd); ->where('create_time', '<=', $dayEnd);
if ($scope !== null) { if ($ownerAdminId !== null) {
$bq->whereIn('channel_id', $scope); $bq->whereIn('user_id', $this->scopedUserIds($ownerAdminId));
} }
$brow = $bq->fieldRaw('COALESCE(SUM(CAST(total_amount AS DECIMAL(18,2))),0) AS s')->find(); $brow = $bq->fieldRaw('COALESCE(SUM(CAST(total_amount AS DECIMAL(18,2))),0) AS s')->find();
$bsum = is_array($brow) && isset($brow['s']) ? strval($brow['s']) : '0'; $bsum = is_array($brow) && isset($brow['s']) ? strval($brow['s']) : '0';
@@ -208,14 +208,14 @@ class Dashboard extends Backend
/** /**
* 用户按渠道分布(取前 8 名,其余合并为「其他」)。 * 用户按渠道分布(取前 8 名,其余合并为「其他」)。
* *
* @param int[]|null $scope * @param int|null $ownerAdminId
* @return list<array{name:string, value:int}> * @return list<array{name:string, value:int}>
*/ */
private function buildChannelShare(?array $scope): array private function buildChannelShare(?int $ownerAdminId): array
{ {
$q = Db::name('user')->fieldRaw('channel_id, COUNT(*) AS c')->group('channel_id'); $q = Db::name('user')->fieldRaw('channel_id, COUNT(*) AS c')->group('channel_id');
if ($scope !== null) { if ($ownerAdminId !== null) {
$q->whereIn('channel_id', $scope); $q->where('admin_id', '=', $ownerAdminId);
} }
$rows = $q->orderRaw('c DESC')->select()->toArray(); $rows = $q->orderRaw('c DESC')->select()->toArray();
if ($rows === []) { if ($rows === []) {
@@ -257,17 +257,17 @@ class Dashboard extends Backend
/** /**
* 成功充值金额按订单归属渠道汇总status=1受渠道范围限制 * 成功充值金额按订单归属渠道汇总status=1受渠道范围限制
* *
* @param int[]|null $scope * @param int|null $ownerAdminId
* @return list<array{name:string, value:string}> value 为两位小数字符串,供前端饼图展示 * @return list<array{name:string, value:string}> value 为两位小数字符串,供前端饼图展示
*/ */
private function buildDepositAmountChannelShare(?array $scope): array private function buildDepositAmountChannelShare(?int $ownerAdminId): array
{ {
$q = Db::name('deposit_order') $q = Db::name('deposit_order')
->where('status', 1) ->where('status', 1)
->fieldRaw('channel_id, COALESCE(SUM(CAST(amount AS DECIMAL(18,2))),0) AS s') ->fieldRaw('channel_id, COALESCE(SUM(CAST(amount AS DECIMAL(18,2))),0) AS s')
->group('channel_id'); ->group('channel_id');
if ($scope !== null) { if ($ownerAdminId !== null) {
$q->whereIn('channel_id', $scope); $q->whereIn('user_id', $this->scopedUserIds($ownerAdminId));
} }
$rows = $q->select()->toArray(); $rows = $q->select()->toArray();
if ($rows === []) { if ($rows === []) {
@@ -322,17 +322,17 @@ class Dashboard extends Backend
} }
/** /**
* @param int[]|null $scope * @param int|null $ownerAdminId
* @return list<array{id:int, username:string, create_time:int, channel_name:string, head_image:string}> * @return list<array{id:int, username:string, create_time:int, channel_name:string, head_image:string}>
*/ */
private function fetchRecentUsers(?array $scope, int $limit): array private function fetchRecentUsers(?int $ownerAdminId, int $limit): array
{ {
$q = Db::name('user') $q = Db::name('user')
->field(['id', 'username', 'create_time', 'channel_id', 'head_image']) ->field(['id', 'username', 'create_time', 'channel_id', 'head_image'])
->order('id', 'desc') ->order('id', 'desc')
->limit($limit); ->limit($limit);
if ($scope !== null) { if ($ownerAdminId !== null) {
$q->whereIn('channel_id', $scope); $q->where('admin_id', '=', $ownerAdminId);
} }
$rows = $q->select()->toArray(); $rows = $q->select()->toArray();
if ($rows === []) { if ($rows === []) {
@@ -372,22 +372,31 @@ class Dashboard extends Backend
} }
/** /**
* 非超管:按管理员所属渠道过滤;未绑定渠道时按 channel_id IN (0) 与列表页一致 * 非超管:按当前管理员名下用户过滤
* 超管:返回 null表示 SQL 不加渠道条件。 * 超管:返回 null表示 SQL 不加管理员条件。
* *
* @return int[]|null * @return int|null
*/ */
private function channelScopeOrNull(): ?array private function ownerAdminIdOrNull(): ?int
{ {
if (!$this->auth || $this->auth->isSuperAdmin()) { if (!$this->auth || $this->auth->isSuperAdmin()) {
return null; return null;
} }
$admin = Db::name('admin')->field(['id', 'channel_id'])->where('id', $this->auth->id)->find(); $idRaw = $this->auth->id;
$ids = []; if ($idRaw === null || $idRaw === '' || !is_numeric(strval($idRaw))) {
if ($admin && !empty($admin['channel_id'])) { return 0;
$ids[] = $admin['channel_id']; }
$id = intval(strval($idRaw));
return $id > 0 ? $id : 0;
} }
return $ids !== [] ? array_values(array_unique($ids)) : [0]; /**
* @return int[]
*/
private function scopedUserIds(int $ownerAdminId): array
{
$ids = Db::name('user')->where('admin_id', '=', $ownerAdminId)->column('id');
$ids = array_map('intval', $ids);
return $ids === [] ? [0] : array_values(array_unique($ids));
} }
} }

View File

@@ -32,4 +32,32 @@ class UserNoticeRead extends Backend
$this->model = new \app\common\model\UserNoticeRead(); $this->model = new \app\common\model\UserNoticeRead();
return null; return null;
} }
protected function _index(): Response
{
if ($this->request && $this->request->get('select')) {
return $this->select($this->request);
}
list($where, $alias, $limit, $order) = $this->queryBuilder();
$table = strtolower($this->model->getTable());
$mainShort = $alias[$table] ?? '';
if ($mainShort !== '' && $this->auth && !$this->auth->isSuperAdmin()) {
$where[] = ['user.admin_id', '=', intval(strval($this->auth->id))];
}
$res = $this->model
->withJoin($this->withJoinTable, $this->withJoinType)
->with($this->withJoinTable)
->alias($alias)
->where($where)
->order($order)
->paginate($limit);
return $this->success('', [
'list' => $res->items(),
'total' => $res->total(),
'remark' => get_route_remark(),
]);
}
} }

View File

@@ -3,7 +3,6 @@
namespace app\admin\controller\order; namespace app\admin\controller\order;
use app\common\controller\Backend; use app\common\controller\Backend;
use support\think\Db;
use support\Response; use support\Response;
use Webman\Http\Request as WebmanRequest; use Webman\Http\Request as WebmanRequest;
@@ -79,8 +78,7 @@ class BetOrder 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()) {
$channelIds = $this->getScopedChannelIdsForFilter(); $where[] = ['user.admin_id', '=', intval(strval($this->auth->id))];
$where[] = [$mainShort . '.channel_id', 'in', $channelIds !== [] ? $channelIds : [0]];
} }
$res = $this->model $res = $this->model
@@ -103,25 +101,4 @@ class BetOrder 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));
}
} }

View File

@@ -3,7 +3,6 @@
namespace app\admin\controller\order; namespace app\admin\controller\order;
use app\common\controller\Backend; use app\common\controller\Backend;
use support\think\Db;
use support\Response; use support\Response;
use Webman\Http\Request as WebmanRequest; use Webman\Http\Request as WebmanRequest;
@@ -49,8 +48,7 @@ class DepositOrder 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()) {
$channelIds = $this->getScopedChannelIdsForFilter(); $where[] = ['user.admin_id', '=', intval(strval($this->auth->id))];
$where[] = [$mainShort . '.channel_id', 'in', $channelIds !== [] ? $channelIds : [0]];
} }
$this->appendDepositOrderIndexWhere($where, $mainShort); $this->appendDepositOrderIndexWhere($where, $mainShort);
@@ -115,7 +113,7 @@ class DepositOrder extends Backend
->withJoin($this->withJoinTable, $this->withJoinType) ->withJoin($this->withJoinTable, $this->withJoinType)
->with($this->withJoinTable) ->with($this->withJoinTable)
->visible([ ->visible([
'user' => ['username', 'phone'], 'user' => ['username', 'phone', 'admin_id'],
'channel' => ['name'], 'channel' => ['name'],
]) ])
->where($this->model->getTable() . '.id', $id) ->where($this->model->getTable() . '.id', $id)
@@ -131,36 +129,18 @@ class DepositOrder extends Backend
if (!$this->auth || $this->auth->isSuperAdmin()) { if (!$this->auth || $this->auth->isSuperAdmin()) {
return true; return true;
} }
$channelIds = $this->getScopedChannelIdsForFilter(); $userRow = $row['user'] ?? null;
if ($channelIds === []) { if (!is_array($userRow)) {
return false; return false;
} }
$raw = $row['channel_id'] ?? null; $adminIdRaw = $userRow['admin_id'] ?? null;
if ($raw === null || $raw === '') { if ($adminIdRaw === null || $adminIdRaw === '') {
return false; return false;
} }
if (!is_numeric(strval($raw))) { if (!is_numeric(strval($adminIdRaw))) {
return false; return false;
} }
return in_array(intval(strval($raw)), $channelIds, true); return intval(strval($adminIdRaw)) === intval(strval($this->auth->id));
} }
/**
* @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));
}
} }

View File

@@ -48,8 +48,7 @@ class WithdrawOrder 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()) {
$channelIds = $this->getScopedChannelIdsForFilter(); $where[] = ['user.admin_id', '=', intval(strval($this->auth->id))];
$where[] = [$mainShort . '.channel_id', 'in', $channelIds !== [] ? $channelIds : [0]];
} }
$res = $this->model $res = $this->model
@@ -386,17 +385,17 @@ class WithdrawOrder extends Backend
if (!$this->auth || $this->auth->isSuperAdmin()) { if (!$this->auth || $this->auth->isSuperAdmin()) {
return true; return true;
} }
$channelIds = $this->getScopedChannelIdsForFilter(); $uidRaw = is_array($row) ? ($row['user_id'] ?? null) : ($row->user_id ?? null);
if ($channelIds === []) { $uid = $this->intParam($uidRaw);
if ($uid <= 0) {
return false; return false;
} }
$raw = is_array($row) ? ($row['channel_id'] ?? null) : ($row->channel_id ?? null); $user = Db::name('user')->field(['id', 'admin_id'])->where('id', $uid)->find();
if ($raw === null || $raw === '') { if (!is_array($user)) {
// 无归属渠道的数据只有超管可见
return false; return false;
} }
$cid = $this->intParam($raw); $ownerAdminId = $this->intParam($user['admin_id'] ?? 0);
return in_array($cid, $channelIds, true); return $ownerAdminId > 0 && $ownerAdminId === $this->intParam($this->auth->id ?? 0);
} }
private function intParam($raw): int private function intParam($raw): int
@@ -453,22 +452,4 @@ class WithdrawOrder extends Backend
return $negative ? ('-' . $v) : $v; return $negative ? ('-' . $v) : $v;
} }
/**
* @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));
}
} }

View File

@@ -15,6 +15,11 @@ use Webman\Http\Request as WebmanRequest;
*/ */
class User extends Backend class User extends Backend
{ {
/**
* 这些接口只要求登录,不单独校验权限节点
*/
protected array $noNeedPermission = ['adminScopeTree'];
/** /**
* User模型对象 * User模型对象
* @var object|null * @var object|null
@@ -22,6 +27,11 @@ class User extends Backend
*/ */
protected ?object $model = null; 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|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']; protected array $withJoinTable = ['channel', 'admin'];
@@ -390,9 +400,17 @@ class User extends Backend
return $response; return $response;
} }
$currentAdminLeaf = $this->getCurrentAdminLeaf();
if ($currentAdminLeaf === null) {
return $this->error(__('Record not found'));
}
$groupIds = $this->getManageableAdminGroupIds(); $groupIds = $this->getManageableAdminGroupIds();
if ($groupIds === []) { if ($groupIds === []) {
return $this->success('', ['list' => []]); return $this->success('', [
'list' => [$currentAdminLeaf],
'current_admin_id' => $currentAdminLeaf['value'],
]);
} }
$groups = Db::name('admin_group') $groups = Db::name('admin_group')
@@ -488,12 +506,45 @@ class User extends Backend
foreach ($roots as $rid) { foreach ($roots as $rid) {
$tree[] = $buildNode($rid); $tree[] = $buildNode($rid);
} }
if (!isset($adminPrimary[intval(strval($currentAdminLeaf['value']))])) {
$tree[] = $currentAdminLeaf;
}
return $this->success('', [ return $this->success('', [
'list' => $tree, '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[] * @return int[]
*/ */

View File

@@ -3,7 +3,6 @@
namespace app\admin\controller\user; namespace app\admin\controller\user;
use app\common\controller\Backend; use app\common\controller\Backend;
use support\think\Db;
use support\Response; use support\Response;
use Webman\Http\Request as WebmanRequest; use Webman\Http\Request as WebmanRequest;
@@ -79,8 +78,7 @@ class UserWalletRecord 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()) {
$channelIds = $this->getScopedChannelIdsForFilter(); $where[] = ['user.admin_id', '=', intval(strval($this->auth->id))];
$where[] = [$mainShort . '.channel_id', 'in', $channelIds !== [] ? $channelIds : [0]];
} }
$res = $this->model $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));
}
} }

View File

@@ -6,17 +6,55 @@
:buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']" :buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
:quick-search-placeholder="t('Quick search placeholder', { fields: t('channel.quick Search Fields') })" :quick-search-placeholder="t('Quick search placeholder', { fields: t('channel.quick Search Fields') })"
></TableHeader> ></TableHeader>
<div class="channel-top-actions">
<div class="channel-stats-cards">
<el-card shadow="never" class="channel-stat-card">
<div class="label">{{ t('channel.settle_stats_channel_total') }}</div>
<div class="value">{{ settleStats.channel_total }}</div>
</el-card>
<el-card shadow="never" class="channel-stat-card">
<div class="label">{{ t('channel.settle_stats_enabled') }}</div>
<div class="value">{{ settleStats.enabled_count }}</div>
</el-card>
<el-card shadow="never" class="channel-stat-card">
<div class="label">{{ t('channel.settle_stats_pending_dividend') }}</div>
<div class="value">{{ settleStats.carryover_positive_count }}</div>
</el-card>
<el-card shadow="never" class="channel-stat-card">
<div class="label">{{ t('channel.settle_stats_pending_amount') }}</div>
<div class="value">{{ settleStats.carryover_positive_total }}</div>
</el-card>
</div>
<div class="channel-action-row">
<el-radio-group v-model="settleFilterMode" size="small" @change="onSettleFilterChange">
<el-radio-button label="all">{{ t('channel.settle_filter_all') }}</el-radio-button>
<el-radio-button label="with_balance">{{ t('channel.settle_filter_with_balance') }}</el-radio-button>
<el-radio-button label="no_balance">{{ t('channel.settle_filter_no_balance') }}</el-radio-button>
<el-radio-button label="enabled">{{ t('channel.settle_filter_enabled') }}</el-radio-button>
<el-radio-button label="disabled">{{ t('channel.settle_filter_disabled') }}</el-radio-button>
</el-radio-group>
<el-button v-if="auth('batchSettlePending')" type="warning" @click="onBatchSettlePending">
{{ t('channel.batch_settle_pending') }}
</el-button>
</div>
</div>
<Table ref="tableRef"></Table> <Table ref="tableRef"></Table>
<PopupForm /> <PopupForm />
<el-dialog class="ba-operate-dialog" :close-on-click-modal="false" :model-value="manualSettle.visible" @close="closeManualSettleDialog"> <el-dialog
class="ba-operate-dialog manual-settle-dialog"
:close-on-click-modal="false"
:model-value="manualSettle.visible"
width="860px"
@close="closeManualSettleDialog"
>
<template #header> <template #header>
<div class="title">{{ t('channel.manual_settle') }}</div> <div class="title">{{ t('channel.manual_settle') }}</div>
</template> </template>
<div v-loading="manualSettle.previewLoading" class="manual-settle-dialog-body"> <div v-loading="manualSettle.previewLoading" class="manual-settle-dialog-body">
<el-form :model="manualSettle.form" label-width="140px"> <el-form :model="manualSettle.form" label-width="140px" class="manual-settle-form">
<el-form-item :label="t('channel.manual_settle_settlement_no')"> <el-form-item :label="t('channel.manual_settle_settlement_no')">
<el-input v-model="manualSettle.form.settlement_no" readonly /> <el-input v-model="manualSettle.form.settlement_no" readonly />
</el-form-item> </el-form-item>
@@ -44,8 +82,8 @@
<el-form-item :label="t('channel.manual_settle_commission_amount')"> <el-form-item :label="t('channel.manual_settle_commission_amount')">
<el-input v-model="manualSettle.form.commission_amount" readonly /> <el-input v-model="manualSettle.form.commission_amount" readonly />
</el-form-item> </el-form-item>
<el-form-item :label="t('channel.share_config')"> <el-form-item :label="t('channel.share_config')" class="manual-settle-form-item-full">
<el-table :data="manualSettle.form.commission_split" border size="small" class="w100"> <el-table :data="manualSettle.form.commission_split" border size="small" class="w100" max-height="220">
<el-table-column prop="admin_username" :label="t('channel.admin__username')" min-width="100" /> <el-table-column prop="admin_username" :label="t('channel.admin__username')" min-width="100" />
<el-table-column prop="share_rate" :label="t('channel.share_rate_percent')" min-width="90"> <el-table-column prop="share_rate" :label="t('channel.share_rate_percent')" min-width="90">
<template #default="scope">{{ scope.row.share_rate }}%</template> <template #default="scope">{{ scope.row.share_rate }}%</template>
@@ -53,16 +91,18 @@
<el-table-column prop="commission_amount" :label="t('channel.manual_settle_commission_amount')" min-width="110" /> <el-table-column prop="commission_amount" :label="t('channel.manual_settle_commission_amount')" min-width="110" />
</el-table> </el-table>
</el-form-item> </el-form-item>
<el-form-item :label="t('channel.manual_settle_remark')"> <el-form-item :label="t('channel.manual_settle_remark')" class="manual-settle-form-item-full">
<el-input v-model="manualSettle.form.remark" type="textarea" :rows="2" /> <el-input v-model="manualSettle.form.remark" type="textarea" :rows="2" />
</el-form-item> </el-form-item>
</el-form> </el-form>
</div> </div>
<template #footer> <template #footer>
<div class="manual-settle-footer">
<el-button @click="closeManualSettleDialog">{{ t('Cancel') }}</el-button> <el-button @click="closeManualSettleDialog">{{ t('Cancel') }}</el-button>
<el-button type="primary" :disabled="manualSettle.previewLoading" :loading="manualSettle.loading" @click="submitManualSettle"> <el-button type="primary" :disabled="manualSettle.previewLoading" :loading="manualSettle.loading" @click="submitManualSettle">
{{ t('Save') }} {{ t('Save') }}
</el-button> </el-button>
</div>
</template> </template>
</el-dialog> </el-dialog>
@@ -115,7 +155,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, onMounted, provide, reactive, useTemplateRef } from 'vue' import { computed, onMounted, provide, reactive, ref, useTemplateRef } from 'vue'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import PopupForm from './popupForm.vue' import PopupForm from './popupForm.vue'
@@ -207,6 +247,15 @@ const shareDialog = reactive({
channelId: 0, channelId: 0,
list: [] as Array<{ admin_id: number; username: string; role_group_name: string; role_level: number; status: number; share_rate: number | null }>, list: [] as Array<{ admin_id: number; username: string; role_group_name: string; role_level: number; status: number; share_rate: number | null }>,
}) })
const settleFilterMode = ref<'all' | 'with_balance' | 'no_balance' | 'enabled' | 'disabled'>('all')
const settleStats = reactive({
channel_total: 0,
enabled_count: 0,
disabled_count: 0,
carryover_positive_count: 0,
carryover_total: '0.00',
carryover_positive_total: '0.00',
})
const shareEnabledTotal = computed(() => { const shareEnabledTotal = computed(() => {
let sum = 0 let sum = 0
@@ -370,6 +419,35 @@ const submitManualSettle = async () => {
} }
} }
const onBatchSettlePending = async () => {
await createAxios(
{
url: '/admin/channel/batchSettlePending',
method: 'post',
},
{ showSuccessMessage: true }
)
await loadSettleStats()
baTable.onTableHeaderAction('refresh', { event: 'batch-settle' })
}
const onSettleFilterChange = () => {
baTable.getData()
}
const loadSettleStats = async () => {
const res = await createAxios({ url: '/admin/channel/settleStats', method: 'get' })
if (res.code !== 1 || !res.data) {
return
}
settleStats.channel_total = Number(res.data.channel_total ?? 0)
settleStats.enabled_count = Number(res.data.enabled_count ?? 0)
settleStats.disabled_count = Number(res.data.disabled_count ?? 0)
settleStats.carryover_positive_count = Number(res.data.carryover_positive_count ?? 0)
settleStats.carryover_total = String(res.data.carryover_total ?? '0.00')
settleStats.carryover_positive_total = String(res.data.carryover_positive_total ?? '0.00')
}
const baTable = new baTableClass( const baTable = new baTableClass(
new baTableApi('/admin/channel/'), new baTableApi('/admin/channel/'),
{ {
@@ -564,6 +642,27 @@ const baTable = new baTableClass(
} }
) )
baTable.before.getData = () => {
const filter = baTable.table.filter || {}
const searchRaw = filter.search
const search = Array.isArray(searchRaw) ? searchRaw.filter((item: any) => item && item.field !== 'carryover_balance' && item.field !== 'status') : []
if (settleFilterMode.value === 'with_balance') {
search.push({ field: 'carryover_balance', operator: 'gt', val: 0 })
} else if (settleFilterMode.value === 'no_balance') {
search.push({ field: 'carryover_balance', operator: 'elt', val: 0 })
} else if (settleFilterMode.value === 'enabled') {
search.push({ field: 'status', operator: 'eq', val: 1 })
} else if (settleFilterMode.value === 'disabled') {
search.push({ field: 'status', operator: 'eq', val: 0 })
}
filter.search = search
baTable.table.filter = filter
}
baTable.after.getData = () => {
void loadSettleStats()
}
provide('baTable', baTable) provide('baTable', baTable)
onMounted(() => { onMounted(() => {
@@ -573,6 +672,7 @@ onMounted(() => {
baTable.initSort() baTable.initSort()
baTable.dragSort() baTable.dragSort()
}) })
void loadSettleStats()
}) })
</script> </script>
@@ -597,4 +697,71 @@ onMounted(() => {
.share-group-empty { .share-group-empty {
color: var(--el-text-color-placeholder); color: var(--el-text-color-placeholder);
} }
.channel-top-actions {
margin: 8px 0 12px;
}
.channel-stats-cards {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 10px;
margin-bottom: 10px;
}
.channel-stat-card .label {
font-size: 12px;
color: var(--el-text-color-secondary);
}
.channel-stat-card .value {
margin-top: 6px;
font-size: 20px;
font-weight: 600;
color: var(--el-text-color-primary);
}
.channel-action-row {
display: flex;
justify-content: space-between;
gap: 10px;
align-items: center;
flex-wrap: wrap;
}
.manual-settle-dialog-body {
max-height: min(70vh, 680px);
overflow: auto;
padding-right: 2px;
}
.manual-settle-form {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
column-gap: 16px;
}
.manual-settle-form :deep(.el-form-item) {
margin-bottom: 12px;
}
.manual-settle-form-item-full {
grid-column: 1 / -1;
}
.manual-settle-footer {
display: flex;
justify-content: flex-end;
gap: 8px;
}
@media (max-width: 900px) {
.channel-stats-cards {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.manual-settle-form {
grid-template-columns: 1fr;
}
}
</style> </style>

View File

@@ -210,6 +210,7 @@ type TreeNode = {
const adminScopeTree = ref<TreeNode[]>([]) const adminScopeTree = ref<TreeNode[]>([])
const adminIdToChannelId = ref<Record<string, number>>({}) const adminIdToChannelId = ref<Record<string, number>>({})
const adminIdToInviteCode = ref<Record<string, string>>({}) const adminIdToInviteCode = ref<Record<string, string>>({})
const currentAdminId = ref('')
const treeProps = { const treeProps = {
value: 'value', value: 'value',
@@ -309,6 +310,8 @@ const loadAdminScopeTree = async () => {
method: 'get', method: 'get',
}) })
const list = (res.data?.list ?? []) as TreeNode[] const list = (res.data?.list ?? []) as TreeNode[]
const currentIdRaw = res.data?.current_admin_id
currentAdminId.value = currentIdRaw === undefined || currentIdRaw === null ? '' : String(currentIdRaw)
adminScopeTree.value = list adminScopeTree.value = list
const { mapCh, mapInv } = buildAdminMapsFromTree(list) const { mapCh, mapInv } = buildAdminMapsFromTree(list)
@@ -316,6 +319,14 @@ const loadAdminScopeTree = async () => {
adminIdToInviteCode.value = mapInv adminIdToInviteCode.value = mapInv
await nextTick() await nextTick()
if (
baTable.form.operate === 'Add' &&
baTable.form.items &&
(baTable.form.items.admin_id === undefined || baTable.form.items.admin_id === null || baTable.form.items.admin_id === '') &&
currentAdminId.value !== ''
) {
baTable.form.items.admin_id = currentAdminId.value
}
const aid = baTable.form.items?.admin_id const aid = baTable.form.items?.admin_id
if (aid !== undefined && aid !== null && aid !== '') { if (aid !== undefined && aid !== null && aid !== '') {
onAdminTreeChange(aid as string | number) onAdminTreeChange(aid as string | number)
@@ -398,6 +409,14 @@ watch(
(op) => { (op) => {
if (op === 'Add') { if (op === 'Add') {
syncRiskFromFlags(0) syncRiskFromFlags(0)
if (
baTable.form.items &&
(baTable.form.items.admin_id === undefined || baTable.form.items.admin_id === null || baTable.form.items.admin_id === '') &&
currentAdminId.value !== ''
) {
baTable.form.items.admin_id = currentAdminId.value
onAdminTreeChange(currentAdminId.value)
}
} }
} }
) )