1.新增时间筛选功能
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
# 数据库配置
|
||||
|
||||
DB_TYPE=mysql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3306
|
||||
|
||||
@@ -25,16 +25,13 @@ class DiceDashboardController extends BaseController
|
||||
#[Permission('工作台数据统计', 'core:console:list')]
|
||||
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'));
|
||||
$lastWeekStart = date('Y-m-d 00:00:00', strtotime('monday last week'));
|
||||
$lastWeekEnd = date('Y-m-d 23:59:59', strtotime('sunday last week'));
|
||||
[$thisStart, $thisEnd, $lastStart, $lastEnd] = $this->resolveDateRanges($request);
|
||||
|
||||
$adminInfo = $this->adminInfo ?? null;
|
||||
$filterDeptId = $request->input('dept_id');
|
||||
|
||||
$playerQueryThis = DicePlayer::whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]);
|
||||
$playerQueryLast = DicePlayer::whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
|
||||
$playerQueryThis = DicePlayer::whereBetween('create_time', [$thisStart, $thisEnd]);
|
||||
$playerQueryLast = DicePlayer::whereBetween('create_time', [$lastStart, $lastEnd]);
|
||||
AdminScopeHelper::applyAdminScope($playerQueryThis, $adminInfo, $filterDeptId);
|
||||
AdminScopeHelper::applyAdminScope($playerQueryLast, $adminInfo, $filterDeptId);
|
||||
$playerThis = $playerQueryThis->count();
|
||||
@@ -42,35 +39,35 @@ class DiceDashboardController extends BaseController
|
||||
|
||||
$chargeQueryThis = DicePlayerWalletRecord::where('type', 0)
|
||||
->where('coin', '>', 0)
|
||||
->whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]);
|
||||
->whereBetween('create_time', [$thisStart, $thisEnd]);
|
||||
$chargeQueryLast = DicePlayerWalletRecord::where('type', 0)
|
||||
->where('coin', '>', 0)
|
||||
->whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
|
||||
->whereBetween('create_time', [$lastStart, $lastEnd]);
|
||||
AdminScopeHelper::applyAdminScope($chargeQueryThis, $adminInfo, $filterDeptId);
|
||||
AdminScopeHelper::applyAdminScope($chargeQueryLast, $adminInfo, $filterDeptId);
|
||||
$chargeThis = $chargeQueryThis->sum('coin');
|
||||
$chargeLast = $chargeQueryLast->sum('coin');
|
||||
|
||||
$withdrawQueryThis = DicePlayerWalletRecord::where('type', 1)
|
||||
->whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]);
|
||||
->whereBetween('create_time', [$thisStart, $thisEnd]);
|
||||
$withdrawQueryLast = DicePlayerWalletRecord::where('type', 1)
|
||||
->whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
|
||||
->whereBetween('create_time', [$lastStart, $lastEnd]);
|
||||
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]);
|
||||
$playQueryThis = DicePlayRecord::whereBetween('create_time', [$thisStart, $thisEnd]);
|
||||
$playQueryLast = DicePlayRecord::whereBetween('create_time', [$lastStart, $lastEnd]);
|
||||
AdminScopeHelper::applyAdminScope($playQueryThis, $adminInfo, $filterDeptId);
|
||||
AdminScopeHelper::applyAdminScope($playQueryLast, $adminInfo, $filterDeptId);
|
||||
$playThis = $playQueryThis->count();
|
||||
$playLast = $playQueryLast->count();
|
||||
|
||||
$playerChange = $this->calcWeekChange($playerThis, $playerLast);
|
||||
$chargeChange = $this->calcWeekChange((float) $chargeThis, (float) $chargeLast);
|
||||
$withdrawChange = $this->calcWeekChange((float) $withdrawThis, (float) $withdrawLast);
|
||||
$playChange = $this->calcWeekChange($playThis, $playLast);
|
||||
$playerChange = $this->calcPeriodChange($playerThis, $playerLast);
|
||||
$chargeChange = $this->calcPeriodChange((float) $chargeThis, (float) $chargeLast);
|
||||
$withdrawChange = $this->calcPeriodChange((float) $withdrawThis, (float) $withdrawLast);
|
||||
$playChange = $this->calcPeriodChange($playThis, $playLast);
|
||||
|
||||
return $this->success([
|
||||
'player_count' => $playerThis,
|
||||
@@ -81,6 +78,7 @@ class DiceDashboardController extends BaseController
|
||||
'withdraw_amount_change' => $withdrawChange,
|
||||
'play_count' => $playThis,
|
||||
'play_count_change' => $playChange,
|
||||
'date' => $this->resolveRequestDate($request),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -179,8 +177,9 @@ class DiceDashboardController extends BaseController
|
||||
$q->field('id,username');
|
||||
},
|
||||
])
|
||||
->where('type', 0)
|
||||
->order('create_time', 'desc')
|
||||
->where('type', 0);
|
||||
$this->applyDashboardDateFilter($query, $request);
|
||||
$query->order('create_time', 'desc')
|
||||
->limit(50);
|
||||
AdminScopeHelper::applyAdminScope($query, $adminInfo, $request->input('dept_id'));
|
||||
$list = $query->select();
|
||||
@@ -204,8 +203,9 @@ class DiceDashboardController extends BaseController
|
||||
public function newPlayerList(Request $request): Response
|
||||
{
|
||||
$adminInfo = $this->adminInfo ?? null;
|
||||
$query = DicePlayer::field('username,coin,total_ticket_count,create_time')
|
||||
->order('create_time', 'desc')
|
||||
$query = DicePlayer::field('username,coin,total_ticket_count,create_time');
|
||||
$this->applyDashboardDateFilter($query, $request);
|
||||
$query->order('create_time', 'desc')
|
||||
->limit(50);
|
||||
AdminScopeHelper::applyAdminScope($query, $adminInfo, $request->input('dept_id'));
|
||||
$list = $query->select();
|
||||
@@ -235,8 +235,9 @@ class DiceDashboardController extends BaseController
|
||||
},
|
||||
])
|
||||
->where('status', 1)
|
||||
->field('id,player_id,reward_tier,win_coin,create_time')
|
||||
->order('create_time', 'desc')
|
||||
->field('id,player_id,reward_tier,win_coin,create_time');
|
||||
$this->applyDashboardDateFilter($query, $request);
|
||||
$query->order('create_time', 'desc')
|
||||
->limit(50);
|
||||
AdminScopeHelper::applyAdminScope($query, $adminInfo, $request->input('dept_id'));
|
||||
$list = $query->select();
|
||||
@@ -275,7 +276,7 @@ class DiceDashboardController extends BaseController
|
||||
return $labels;
|
||||
}
|
||||
|
||||
private function calcWeekChange($current, $last): float
|
||||
private function calcPeriodChange($current, $last): float
|
||||
{
|
||||
if ($last == 0) {
|
||||
return $current > 0 ? 100.0 : 0.0;
|
||||
@@ -283,6 +284,56 @@ class DiceDashboardController extends BaseController
|
||||
return round((($current - $last) / $last) * 100, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析工作台统计区间:有 date 按单日对比昨日,无 date 按本周对比上周
|
||||
*
|
||||
* @return array{0: string, 1: string, 2: string, 3: string}
|
||||
*/
|
||||
private function resolveDateRanges(Request $request): array
|
||||
{
|
||||
$date = $this->resolveRequestDate($request);
|
||||
if ($date === '') {
|
||||
return [
|
||||
date('Y-m-d 00:00:00', strtotime('monday this week')),
|
||||
date('Y-m-d 23:59:59', strtotime('sunday this week')),
|
||||
date('Y-m-d 00:00:00', strtotime('monday last week')),
|
||||
date('Y-m-d 23:59:59', strtotime('sunday last week')),
|
||||
];
|
||||
}
|
||||
|
||||
$lastDate = date('Y-m-d', strtotime($date . ' -1 day'));
|
||||
|
||||
return [
|
||||
$date . ' 00:00:00',
|
||||
$date . ' 23:59:59',
|
||||
$lastDate . ' 00:00:00',
|
||||
$lastDate . ' 23:59:59',
|
||||
];
|
||||
}
|
||||
|
||||
private function resolveRequestDate(Request $request): string
|
||||
{
|
||||
$date = trim((string) $request->input('date', ''));
|
||||
if ($date === '' || strtotime($date) === false) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return date('Y-m-d', strtotime($date));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $query
|
||||
*/
|
||||
private function applyDashboardDateFilter($query, Request $request, string $column = 'create_time'): void
|
||||
{
|
||||
$date = $this->resolveRequestDate($request);
|
||||
if ($date === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$query->whereBetween($column, [$date . ' 00:00:00', $date . ' 23:59:59']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 钱包流水 SQL 渠道条件;非超管无渠道时返回 __empty__
|
||||
*/
|
||||
|
||||
@@ -187,6 +187,8 @@ class DicePlayerController extends BaseController
|
||||
['status', ''],
|
||||
['coin', ''],
|
||||
['lottery_config_id', ''],
|
||||
['create_time_min', ''],
|
||||
['create_time_max', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
|
||||
@@ -48,10 +48,18 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
['create_time_max', ''],
|
||||
]);
|
||||
$deptId = $request->input('dept_id');
|
||||
$totalCoinChange = $this->logic->sumCoinBySearch($where, $this->adminInfo ?? null, $deptId);
|
||||
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $deptId);
|
||||
|
||||
$sumQuery = clone $query;
|
||||
$totalCoinChange = round((float) $sumQuery->sum('coin'), 2);
|
||||
|
||||
$inflowQuery = clone $query;
|
||||
$totalCoinInflow = round((float) $inflowQuery->where('coin', '>', 0)->sum('coin'), 2);
|
||||
|
||||
$outflowQuery = clone $query;
|
||||
$totalCoinOutflow = round((float) $outflowQuery->where('coin', '<', 0)->sum('coin'), 2);
|
||||
|
||||
$query->with([
|
||||
'dicePlayer',
|
||||
'operator',
|
||||
@@ -59,6 +67,8 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
|
||||
$data = $this->logic->getList($query);
|
||||
$data['total_coin_change'] = $totalCoinChange;
|
||||
$data['total_coin_inflow'] = $totalCoinInflow;
|
||||
$data['total_coin_outflow'] = $totalCoinOutflow;
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\logic\player_wallet_record;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use app\dice\basic\DiceBaseLogic;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
use app\dice\model\player_wallet_record\DicePlayerWalletRecord;
|
||||
@@ -28,18 +27,6 @@ class DicePlayerWalletRecordLogic extends DiceBaseLogic
|
||||
$this->setOrderType('DESC');
|
||||
}
|
||||
|
||||
/**
|
||||
* 按与列表相同的筛选条件汇总平台币变化(不含 with / 分页 / 排序)
|
||||
*/
|
||||
public function sumCoinBySearch(array $where, ?array $adminInfo, $requestDeptId = null): float
|
||||
{
|
||||
$query = $this->search($where);
|
||||
AdminScopeHelper::applyAdminScope($query, $adminInfo, $requestDeptId);
|
||||
$table = $this->model->getTable();
|
||||
$sum = $query->sum($table . '.coin');
|
||||
return round((float) $sum, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加数据(补全抽奖次数字段默认值)
|
||||
*/
|
||||
|
||||
@@ -224,6 +224,26 @@ class DicePlayer extends DiceModel
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册时间起始 搜索
|
||||
*/
|
||||
public function searchCreateTimeMinAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('create_time', '>=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册时间结束 搜索
|
||||
*/
|
||||
public function searchCreateTimeMaxAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('create_time', '<=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联彩金池配置
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user