1.将部门修改为渠道,并且所有dice_表关联渠道表

2.将所有配置表,记录表设置关联渠道
3.优化后台页面设置
This commit is contained in:
2026-05-19 09:49:02 +08:00
parent 085454fb78
commit dd264b1e97
143 changed files with 4741 additions and 1254 deletions

View File

@@ -10,6 +10,7 @@ use app\dice\model\play_record\DicePlayRecord;
use app\dice\model\reward\DiceRewardConfig;
use plugin\saiadmin\basic\BaseController;
use plugin\saiadmin\service\Permission;
use support\Request;
use support\Response;
use support\think\Db;
@@ -22,7 +23,7 @@ class DiceDashboardController extends BaseController
* 工作台卡片统计:玩家注册、充值、提现、游玩次数(含较上周对比)
*/
#[Permission('工作台数据统计', 'core:console:list')]
public function statistics(): Response
public function statistics(Request $request): Response
{
$thisWeekStart = date('Y-m-d 00:00:00', strtotime('monday this week'));
$thisWeekEnd = date('Y-m-d 23:59:59', strtotime('sunday this week'));
@@ -30,11 +31,12 @@ class DiceDashboardController extends BaseController
$lastWeekEnd = date('Y-m-d 23:59:59', strtotime('sunday last week'));
$adminInfo = $this->adminInfo ?? null;
$filterDeptId = $request->input('dept_id');
$playerQueryThis = DicePlayer::whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]);
$playerQueryLast = DicePlayer::whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
AdminScopeHelper::applyAdminScope($playerQueryThis, $adminInfo);
AdminScopeHelper::applyAdminScope($playerQueryLast, $adminInfo);
AdminScopeHelper::applyAdminScope($playerQueryThis, $adminInfo, $filterDeptId);
AdminScopeHelper::applyAdminScope($playerQueryLast, $adminInfo, $filterDeptId);
$playerThis = $playerQueryThis->count();
$playerLast = $playerQueryLast->count();
@@ -44,8 +46,8 @@ class DiceDashboardController extends BaseController
$chargeQueryLast = DicePlayerWalletRecord::where('type', 0)
->where('coin', '>', 0)
->whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
AdminScopeHelper::applyAdminScope($chargeQueryThis, $adminInfo);
AdminScopeHelper::applyAdminScope($chargeQueryLast, $adminInfo);
AdminScopeHelper::applyAdminScope($chargeQueryThis, $adminInfo, $filterDeptId);
AdminScopeHelper::applyAdminScope($chargeQueryLast, $adminInfo, $filterDeptId);
$chargeThis = $chargeQueryThis->sum('coin');
$chargeLast = $chargeQueryLast->sum('coin');
@@ -53,15 +55,15 @@ class DiceDashboardController extends BaseController
->whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]);
$withdrawQueryLast = DicePlayerWalletRecord::where('type', 1)
->whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
AdminScopeHelper::applyAdminScope($withdrawQueryThis, $adminInfo);
AdminScopeHelper::applyAdminScope($withdrawQueryLast, $adminInfo);
AdminScopeHelper::applyAdminScope($withdrawQueryThis, $adminInfo, $filterDeptId);
AdminScopeHelper::applyAdminScope($withdrawQueryLast, $adminInfo, $filterDeptId);
$withdrawThis = $withdrawQueryThis->sum(Db::raw('ABS(coin)'));
$withdrawLast = $withdrawQueryLast->sum(Db::raw('ABS(coin)'));
$playQueryThis = DicePlayRecord::whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]);
$playQueryLast = DicePlayRecord::whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
AdminScopeHelper::applyAdminScope($playQueryThis, $adminInfo);
AdminScopeHelper::applyAdminScope($playQueryLast, $adminInfo);
AdminScopeHelper::applyAdminScope($playQueryThis, $adminInfo, $filterDeptId);
AdminScopeHelper::applyAdminScope($playQueryLast, $adminInfo, $filterDeptId);
$playThis = $playQueryThis->count();
$playLast = $playQueryLast->count();
@@ -86,13 +88,11 @@ class DiceDashboardController extends BaseController
* 近期玩家充值统计近10天每日充值金额
*/
#[Permission('工作台数据统计', 'core:console:list')]
public function rechargeChart(): Response
public function rechargeChart(Request $request): Response
{
$adminInfo = $this->adminInfo ?? null;
$allowedIds = AdminScopeHelper::getAllowedAdminIds($adminInfo);
$adminCondition = '';
if ($allowedIds !== null) {
if (empty($allowedIds)) {
$deptCondition = $this->buildWalletSqlDeptCondition($adminInfo, $request->input('dept_id'));
if ($deptCondition === '__empty__') {
$data = [];
foreach (range(0, 9) as $n) {
$data[] = ['recharge_date' => date('Y-m-d', strtotime("-{$n} days")), 'recharge_amount' => 0];
@@ -102,9 +102,6 @@ class DiceDashboardController extends BaseController
'recharge_amount' => array_map('floatval', array_column($data, 'recharge_amount')),
'recharge_date' => array_column($data, 'recharge_date'),
]);
}
$idsStr = implode(',', array_map('intval', $allowedIds));
$adminCondition = " AND w.admin_id IN ({$idsStr})";
}
$sql = "
SELECT
@@ -117,7 +114,7 @@ class DiceDashboardController extends BaseController
UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) a
) d
LEFT JOIN dice_player_wallet_record w
ON DATE(w.create_time) = d.date AND w.type = 0 AND w.coin > 0 {$adminCondition}
ON DATE(w.create_time) = d.date AND w.type = 0 AND w.coin > 0 {$deptCondition}
GROUP BY d.date
ORDER BY d.date ASC
";
@@ -132,13 +129,11 @@ class DiceDashboardController extends BaseController
* 月度玩家充值汇总当年1-12月每月充值金额
*/
#[Permission('工作台数据统计', 'core:console:list')]
public function rechargeBarChart(): Response
public function rechargeBarChart(Request $request): Response
{
$adminInfo = $this->adminInfo ?? null;
$allowedIds = AdminScopeHelper::getAllowedAdminIds($adminInfo);
$adminCondition = '';
if ($allowedIds !== null) {
if (empty($allowedIds)) {
$deptCondition = $this->buildWalletSqlDeptCondition($adminInfo, $request->input('dept_id'));
if ($deptCondition === '__empty__') {
$data = [];
for ($m = 1; $m <= 12; $m++) {
$data[] = ['recharge_month' => sprintf('%02d月', $m), 'recharge_amount' => 0];
@@ -147,9 +142,6 @@ class DiceDashboardController extends BaseController
'recharge_amount' => array_map('floatval', array_column($data, 'recharge_amount')),
'recharge_month' => array_column($data, 'recharge_month'),
]);
}
$idsStr = implode(',', array_map('intval', $allowedIds));
$adminCondition = " AND w.admin_id IN ({$idsStr})";
}
$sql = "
SELECT
@@ -163,7 +155,7 @@ class DiceDashboardController extends BaseController
LEFT JOIN dice_player_wallet_record w
ON YEAR(w.create_time) = YEAR(CURDATE())
AND MONTH(w.create_time) = m.month_num
AND w.type = 0 AND w.coin > 0 {$adminCondition}
AND w.type = 0 AND w.coin > 0 {$deptCondition}
GROUP BY m.month_num
ORDER BY m.month_num ASC
";
@@ -179,7 +171,7 @@ class DiceDashboardController extends BaseController
* 返回:玩家账号(DicePlayer.username)、充值金额(coin)、充值时间(create_time)
*/
#[Permission('工作台数据统计', 'core:console:list')]
public function walletRecordList(): Response
public function walletRecordList(Request $request): Response
{
$adminInfo = $this->adminInfo ?? null;
$query = DicePlayerWalletRecord::with([
@@ -190,7 +182,7 @@ class DiceDashboardController extends BaseController
->where('type', 0)
->order('create_time', 'desc')
->limit(50);
AdminScopeHelper::applyAdminScope($query, $adminInfo);
AdminScopeHelper::applyAdminScope($query, $adminInfo, $request->input('dept_id'));
$list = $query->select();
$rows = [];
foreach ($list as $row) {
@@ -209,13 +201,13 @@ class DiceDashboardController extends BaseController
* 返回:玩家账号(username)、余额(coin)、抽奖券(total_ticket_count)
*/
#[Permission('工作台数据统计', 'core:console:list')]
public function newPlayerList(): Response
public function newPlayerList(Request $request): Response
{
$adminInfo = $this->adminInfo ?? null;
$query = DicePlayer::field('username,coin,total_ticket_count,create_time')
->order('create_time', 'desc')
->limit(50);
AdminScopeHelper::applyAdminScope($query, $adminInfo);
AdminScopeHelper::applyAdminScope($query, $adminInfo, $request->input('dept_id'));
$list = $query->select();
$rows = [];
foreach ($list as $row) {
@@ -234,7 +226,7 @@ class DiceDashboardController extends BaseController
* 返回:玩家账号、中奖档位、赢取平台币、游玩时间
*/
#[Permission('工作台数据统计', 'core:console:list')]
public function playRecordList(): Response
public function playRecordList(Request $request): Response
{
$adminInfo = $this->adminInfo ?? null;
$query = DicePlayRecord::with([
@@ -246,7 +238,7 @@ class DiceDashboardController extends BaseController
->field('id,player_id,reward_tier,win_coin,create_time')
->order('create_time', 'desc')
->limit(50);
AdminScopeHelper::applyAdminScope($query, $adminInfo);
AdminScopeHelper::applyAdminScope($query, $adminInfo, $request->input('dept_id'));
$list = $query->select();
$tierLabels = $this->buildRewardTierLabels();
$rows = [];
@@ -290,4 +282,23 @@ class DiceDashboardController extends BaseController
}
return round((($current - $last) / $last) * 100, 1);
}
/**
* 钱包流水 SQL 渠道条件;非超管无渠道时返回 __empty__
*/
private function buildWalletSqlDeptCondition(?array $adminInfo, $requestDeptId): string
{
if (AdminScopeHelper::getDeptId($adminInfo) !== null) {
$deptId = AdminScopeHelper::getDeptId($adminInfo);
if ($deptId <= 0) {
return '__empty__';
}
return ' AND w.dept_id = ' . $deptId;
}
$target = AdminScopeHelper::resolveBusinessDeptId($adminInfo, $requestDeptId);
if ($target !== null && $target > 0) {
return ' AND w.dept_id = ' . $target;
}
return '';
}
}