1.将部门修改为渠道,并且所有dice_表关联渠道表
2.将所有配置表,记录表设置关联渠道 3.优化后台页面设置
This commit is contained in:
@@ -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 '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\ante_config;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use app\dice\logic\ante_config\DiceAnteConfigLogic;
|
||||
use app\dice\model\ante_config\DiceAnteConfig;
|
||||
use app\dice\validate\ante_config\DiceAnteConfigValidate;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
@@ -34,10 +36,32 @@ class DiceAnteConfigController extends BaseController
|
||||
['is_default', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 底注下拉选项(按渠道),供一键测试权重等使用
|
||||
*/
|
||||
#[Permission('底注配置列表', 'dice:ante_config:index:index')]
|
||||
public function getOptions(Request $request): Response
|
||||
{
|
||||
$query = DiceAnteConfig::field('id,name,title,mult,is_default')->order('mult', 'asc')->order('id', 'asc');
|
||||
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$list = $query->select();
|
||||
$data = $list->map(static function ($item) {
|
||||
return [
|
||||
'id' => (int) $item['id'],
|
||||
'name' => (string) ($item['name'] ?? ''),
|
||||
'title' => (string) ($item['title'] ?? ''),
|
||||
'mult' => (int) ($item['mult'] ?? 0),
|
||||
'is_default' => (int) ($item['is_default'] ?? 0),
|
||||
];
|
||||
})->toArray();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
#[Permission('底注配置读取', 'dice:ante_config:index:read')]
|
||||
public function read(Request $request): Response
|
||||
{
|
||||
@@ -52,6 +76,7 @@ class DiceAnteConfigController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
AdminScopeHelper::prepareConfigSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
|
||||
$result = $this->logic->add($data);
|
||||
return $result ? $this->success('add success') : $this->fail('add failed');
|
||||
}
|
||||
@@ -60,8 +85,19 @@ class DiceAnteConfigController extends BaseController
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
if ($data === [] || $data === null) {
|
||||
$data = $request->all();
|
||||
}
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
$requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), is_array($data) ? $data : []);
|
||||
$model = $this->logic->read($data['id'] ?? 0);
|
||||
if ($model) {
|
||||
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
|
||||
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $requestDeptId)) {
|
||||
return $this->fail('no permission to update this record');
|
||||
}
|
||||
}
|
||||
$result = $this->logic->edit($data['id'], $data, $this->adminInfo ?? null, $requestDeptId);
|
||||
return $result ? $this->success('update success') : $this->fail('update failed');
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\config;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\config\DiceConfigLogic;
|
||||
use app\dice\validate\config\DiceConfigValidate;
|
||||
@@ -42,6 +43,7 @@ class DiceConfigController extends BaseController
|
||||
['title', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
@@ -74,6 +76,7 @@ class DiceConfigController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
AdminScopeHelper::prepareConfigSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('add success');
|
||||
@@ -91,8 +94,20 @@ class DiceConfigController extends BaseController
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
if ($data === [] || $data === null) {
|
||||
$data = $request->all();
|
||||
}
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
$requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), is_array($data) ? $data : []);
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $requestDeptId);
|
||||
$model = $this->logic->read($data['id'] ?? 0);
|
||||
if ($model) {
|
||||
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
|
||||
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $requestDeptId)) {
|
||||
return $this->fail('no permission to update this record');
|
||||
}
|
||||
}
|
||||
$result = $this->logic->edit($data['id'], $data, $this->adminInfo ?? null, $requestDeptId);
|
||||
if ($result) {
|
||||
return $this->success('update success');
|
||||
} else {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\game;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use app\dice\logic\game\DiceGameLogic;
|
||||
use app\dice\validate\game\DiceGameValidate;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
@@ -33,6 +34,7 @@ class DiceGameController extends BaseController
|
||||
['status', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
@@ -54,6 +56,7 @@ class DiceGameController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
AdminScopeHelper::prepareConfigSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
|
||||
$result = $this->logic->add($data);
|
||||
if (!$result) {
|
||||
return $this->fail('add failed');
|
||||
@@ -65,8 +68,19 @@ class DiceGameController extends BaseController
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
if ($data === [] || $data === null) {
|
||||
$data = $request->all();
|
||||
}
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
$requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), is_array($data) ? $data : []);
|
||||
$model = $this->logic->read($data['id'] ?? 0);
|
||||
if ($model) {
|
||||
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
|
||||
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $requestDeptId)) {
|
||||
return $this->fail('no permission to update this record');
|
||||
}
|
||||
}
|
||||
$result = $this->logic->edit($data['id'], $data, $this->adminInfo ?? null, $requestDeptId);
|
||||
if (!$result) {
|
||||
return $this->fail('update failed');
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
namespace app\dice\controller\lottery_pool_config;
|
||||
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\lottery_pool_config\DiceLotteryPoolConfigLogic;
|
||||
use app\dice\validate\lottery_pool_config\DiceLotteryPoolConfigValidate;
|
||||
@@ -37,9 +38,10 @@ class DiceLotteryPoolConfigController extends BaseController
|
||||
#[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:index')]
|
||||
public function getOptions(Request $request): Response
|
||||
{
|
||||
$list = DiceLotteryPoolConfig::field('id,name,t1_weight,t2_weight,t3_weight,t4_weight,t5_weight')
|
||||
->order('id', 'asc')
|
||||
->select();
|
||||
$query = DiceLotteryPoolConfig::field('id,name,t1_weight,t2_weight,t3_weight,t4_weight,t5_weight')
|
||||
->order('id', 'asc');
|
||||
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$list = $query->select();
|
||||
$data = $list->map(function ($item) {
|
||||
return [
|
||||
'id' => (int) $item['id'],
|
||||
@@ -67,6 +69,7 @@ class DiceLotteryPoolConfigController extends BaseController
|
||||
['type', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
@@ -99,6 +102,7 @@ class DiceLotteryPoolConfigController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
AdminScopeHelper::prepareConfigSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('add success');
|
||||
@@ -116,8 +120,19 @@ class DiceLotteryPoolConfigController extends BaseController
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
if ($data === [] || $data === null) {
|
||||
$data = $request->all();
|
||||
}
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
$requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), is_array($data) ? $data : []);
|
||||
$model = $this->logic->read($data['id'] ?? 0);
|
||||
if ($model) {
|
||||
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
|
||||
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $requestDeptId)) {
|
||||
return $this->fail('no permission to update this record');
|
||||
}
|
||||
}
|
||||
$result = $this->logic->edit($data['id'], $data, $this->adminInfo ?? null, $requestDeptId);
|
||||
if ($result) {
|
||||
return $this->success('update success');
|
||||
} else {
|
||||
@@ -152,7 +167,8 @@ class DiceLotteryPoolConfigController extends BaseController
|
||||
#[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:getCurrentPool')]
|
||||
public function getCurrentPool(Request $request): Response
|
||||
{
|
||||
$data = $this->logic->getCurrentPool();
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$data = $this->logic->getCurrentPool($deptId);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
@@ -163,7 +179,12 @@ class DiceLotteryPoolConfigController extends BaseController
|
||||
public function updateCurrentPool(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->logic->updateCurrentPool($data);
|
||||
if ($data === [] || $data === null) {
|
||||
$data = $request->all();
|
||||
}
|
||||
$requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), is_array($data) ? $data : []);
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $requestDeptId);
|
||||
$this->logic->updateCurrentPool($data, $deptId);
|
||||
return $this->success('save success');
|
||||
}
|
||||
|
||||
@@ -173,7 +194,8 @@ class DiceLotteryPoolConfigController extends BaseController
|
||||
#[Permission('色子奖池配置修改', 'dice:lottery_pool_config:index:resetProfitAmount')]
|
||||
public function resetProfitAmount(Request $request): Response
|
||||
{
|
||||
$this->logic->resetProfitAmount();
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$this->logic->resetProfitAmount($deptId);
|
||||
return $this->success('reset success');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class DicePlayRecordController extends BaseController
|
||||
['direction', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$query->with([
|
||||
'dicePlayer',
|
||||
'diceLotteryPoolConfig',
|
||||
@@ -78,7 +78,7 @@ class DicePlayRecordController extends BaseController
|
||||
public function getPlayerOptions(Request $request): Response
|
||||
{
|
||||
$query = DicePlayer::field('id,username');
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$list = $query->select();
|
||||
$data = $list->map(function ($item) {
|
||||
return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
|
||||
@@ -92,9 +92,15 @@ class DicePlayRecordController extends BaseController
|
||||
#[Permission('玩家抽奖记录列表', 'dice:play_record:index:index')]
|
||||
public function getLotteryConfigOptions(Request $request): Response
|
||||
{
|
||||
$list = DiceLotteryPoolConfig::field('id,name')->select();
|
||||
$query = DiceLotteryPoolConfig::field('id,name')->order('id', 'asc');
|
||||
$requestDeptId = AdminScopeHelper::pickRequestDeptId(
|
||||
$request->input('dept_id'),
|
||||
$request->all()
|
||||
);
|
||||
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $requestDeptId);
|
||||
$list = $query->select();
|
||||
$data = $list->map(function ($item) {
|
||||
return ['id' => $item['id'], 'name' => $item['name'] ?? ''];
|
||||
return ['id' => (int) $item['id'], 'name' => (string) ($item['name'] ?? '')];
|
||||
})->toArray();
|
||||
return $this->success($data);
|
||||
}
|
||||
@@ -112,8 +118,7 @@ class DicePlayRecordController extends BaseController
|
||||
if (!$model) {
|
||||
return $this->fail('not found');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null)) {
|
||||
return $this->fail('no permission to view this record');
|
||||
}
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
@@ -130,6 +135,7 @@ class DicePlayRecordController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
AdminScopeHelper::prepareBusinessSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('add success');
|
||||
@@ -148,6 +154,13 @@ class DicePlayRecordController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$model = $this->logic->read($data['id'] ?? 0);
|
||||
if ($model) {
|
||||
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
|
||||
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $request->input('dept_id'))) {
|
||||
return $this->fail('no permission to update this record');
|
||||
}
|
||||
}
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('update success');
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\play_record_test;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\play_record_test\DicePlayRecordTestLogic;
|
||||
use app\dice\validate\play_record_test\DicePlayRecordTestValidate;
|
||||
@@ -50,6 +51,7 @@ class DicePlayRecordTestController extends BaseController
|
||||
['roll_number', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$query->with(['diceLotteryPoolConfig']);
|
||||
|
||||
// 按当前筛选条件统计:平台总盈利 = 付费金额(paid_amount 求和) - 玩家总收益(win_coin 求和)
|
||||
@@ -92,6 +94,7 @@ class DicePlayRecordTestController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
AdminScopeHelper::prepareBusinessSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('add success');
|
||||
@@ -110,6 +113,13 @@ class DicePlayRecordTestController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$model = $this->logic->read($data['id'] ?? 0);
|
||||
if ($model) {
|
||||
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
|
||||
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $request->input('dept_id'))) {
|
||||
return $this->fail('no permission to update this record');
|
||||
}
|
||||
}
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('update success');
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace app\dice\controller\player;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use plugin\saiadmin\app\model\system\SystemDept;
|
||||
use plugin\saiadmin\app\model\system\SystemUser;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\player\DicePlayerLogic;
|
||||
@@ -42,7 +43,13 @@ class DicePlayerController extends BaseController
|
||||
#[Permission('玩家列表', 'dice:player:index:index')]
|
||||
public function getLotteryConfigOptions(Request $request): Response
|
||||
{
|
||||
$list = DiceLotteryPoolConfig::field('id,name')->order('id', 'asc')->select();
|
||||
$query = DiceLotteryPoolConfig::field('id,name')->order('id', 'asc');
|
||||
$requestDeptId = AdminScopeHelper::pickRequestDeptId(
|
||||
$request->input('dept_id'),
|
||||
$request->all()
|
||||
);
|
||||
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $requestDeptId);
|
||||
$list = $query->select();
|
||||
$data = $list->map(function ($item) {
|
||||
return ['id' => (int) $item['id'], 'name' => (string) ($item['name'] ?? '')];
|
||||
})->toArray();
|
||||
@@ -57,12 +64,17 @@ class DicePlayerController extends BaseController
|
||||
#[Permission('玩家列表', 'dice:player:index:index')]
|
||||
public function getSystemUserOptions(Request $request): Response
|
||||
{
|
||||
$query = SystemUser::field('id,username,realname')->where('status', 1)->order('id', 'asc');
|
||||
if (isset($this->adminInfo['id']) && (int) $this->adminInfo['id'] > 1) {
|
||||
$deptList = $this->adminInfo['deptList'] ?? [];
|
||||
if (!empty($deptList)) {
|
||||
$query->auth($deptList);
|
||||
$query = SystemUser::field('id,username,realname,dept_id')->where('status', 1)->order('id', 'asc');
|
||||
$requestDeptId = AdminScopeHelper::pickRequestDeptId(
|
||||
$request->input('dept_id'),
|
||||
$request->all()
|
||||
);
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null) {
|
||||
if ($allowedIds === []) {
|
||||
return $this->success([]);
|
||||
}
|
||||
$query->whereIn('id', $allowedIds);
|
||||
}
|
||||
$list = $query->select();
|
||||
$data = $list->map(function ($item) {
|
||||
@@ -71,12 +83,89 @@ class DicePlayerController extends BaseController
|
||||
'id' => (int) $item['id'],
|
||||
'username' => (string) ($item['username'] ?? ''),
|
||||
'realname' => (string) ($item['realname'] ?? ''),
|
||||
'dept_id' => isset($item['dept_id']) ? (int) $item['dept_id'] : null,
|
||||
'label' => $label ?: (string) $item['id'],
|
||||
];
|
||||
})->toArray();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 超管:按渠道树状展示全部管理员;非超管:同 getSystemUserOptions 扁平列表
|
||||
*/
|
||||
#[Permission('玩家列表', 'dice:player:index:index')]
|
||||
public function getSystemUserTreeOptions(Request $request): Response
|
||||
{
|
||||
if (!AdminScopeHelper::isSuperAdmin($this->adminInfo ?? null)) {
|
||||
return $this->getSystemUserOptions($request);
|
||||
}
|
||||
|
||||
$users = SystemUser::field('id,username,realname,dept_id')
|
||||
->where('status', 1)
|
||||
->order('id', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$depts = SystemDept::field('id,name')
|
||||
->where('status', 1)
|
||||
->order('id', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$deptNameMap = [];
|
||||
foreach ($depts as $dept) {
|
||||
$deptNameMap[(int) $dept['id']] = (string) ($dept['name'] ?? $dept['id']);
|
||||
}
|
||||
|
||||
$grouped = [];
|
||||
$unassigned = [];
|
||||
foreach ($users as $user) {
|
||||
$item = [
|
||||
'id' => (int) $user['id'],
|
||||
'username' => (string) ($user['username'] ?? ''),
|
||||
'realname' => (string) ($user['realname'] ?? ''),
|
||||
'dept_id' => isset($user['dept_id']) ? (int) $user['dept_id'] : null,
|
||||
];
|
||||
$label = trim($item['realname']) ?: $item['username'];
|
||||
$item['label'] = $label ?: (string) $item['id'];
|
||||
$deptId = $item['dept_id'] ?? 0;
|
||||
if ($deptId > 0 && isset($deptNameMap[$deptId])) {
|
||||
if (!isset($grouped[$deptId])) {
|
||||
$grouped[$deptId] = [];
|
||||
}
|
||||
$grouped[$deptId][] = $item;
|
||||
} else {
|
||||
$unassigned[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
$tree = [];
|
||||
foreach ($depts as $dept) {
|
||||
$deptId = (int) $dept['id'];
|
||||
$children = $grouped[$deptId] ?? [];
|
||||
if ($children === []) {
|
||||
continue;
|
||||
}
|
||||
$tree[] = [
|
||||
'id' => 'dept_' . $deptId,
|
||||
'label' => (string) ($dept['name'] ?? $deptId),
|
||||
'disabled' => true,
|
||||
'children' => $children,
|
||||
];
|
||||
}
|
||||
|
||||
if ($unassigned !== []) {
|
||||
$tree[] = [
|
||||
'id' => 'dept_unassigned',
|
||||
'label' => '__unassigned__',
|
||||
'disabled' => true,
|
||||
'children' => $unassigned,
|
||||
];
|
||||
}
|
||||
|
||||
return $this->success($tree);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
@@ -94,7 +183,7 @@ class DicePlayerController extends BaseController
|
||||
['lottery_config_id', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$query->with(['diceLotteryPoolConfig']);
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
@@ -113,8 +202,7 @@ class DicePlayerController extends BaseController
|
||||
if (!$model) {
|
||||
return $this->fail('not found');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null)) {
|
||||
return $this->fail('no permission to view this record');
|
||||
}
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
@@ -130,20 +218,32 @@ class DicePlayerController extends BaseController
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
// 类型转化
|
||||
if (empty($data['admin_id']) && isset($this->adminInfo['id']) && (int) $this->adminInfo['id'] > 0) {
|
||||
$data['admin_id'] = (int) $this->adminInfo['id'];
|
||||
}
|
||||
$result = $this->logic->add($data);
|
||||
if ($result && isset($result['id'])) {
|
||||
// 出于安全:删除该玩家缓存,后续 API 按需重建
|
||||
UserCache::deleteUser($result['id']);
|
||||
$player = DicePlayer::find($result['id']);
|
||||
AdminScopeHelper::prepareBusinessSaveData(
|
||||
$data,
|
||||
$this->adminInfo ?? null,
|
||||
$request->input('dept_id'),
|
||||
$data
|
||||
);
|
||||
$this->validate('save', $data);
|
||||
try {
|
||||
$result = $this->logic->add($data);
|
||||
} catch (\Throwable $e) {
|
||||
if (self::isDeptUsernameDuplicateException($e)) {
|
||||
return $this->fail('PLAYER_USERNAME_DEPT_UNIQUE');
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
$playerId = is_array($result) ? ($result['id'] ?? null) : $result;
|
||||
if ($playerId) {
|
||||
UserCache::deleteUser($playerId);
|
||||
$player = DicePlayer::find($playerId);
|
||||
if ($player && $player->username !== '') {
|
||||
UserCache::deletePlayerByUsername($player->username);
|
||||
}
|
||||
return $this->success('add success');
|
||||
return $this->success('ADD_SUCCESS');
|
||||
}
|
||||
return $this->fail('add failed');
|
||||
}
|
||||
@@ -157,14 +257,16 @@ class DicePlayerController extends BaseController
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$model = $this->logic->read($data['id'] ?? 0);
|
||||
if ($model) {
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null, $request->input('dept_id'))) {
|
||||
return $this->fail('no permission to update this record');
|
||||
}
|
||||
if (!isset($data['dept_id']) || $data['dept_id'] === '' || $data['dept_id'] === null) {
|
||||
$data['dept_id'] = $model->dept_id ?? null;
|
||||
}
|
||||
}
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
// 出于安全:删除该玩家缓存,后续 API 按需重建
|
||||
@@ -173,7 +275,7 @@ class DicePlayerController extends BaseController
|
||||
if ($player && $player->username !== '') {
|
||||
UserCache::deletePlayerByUsername($player->username);
|
||||
}
|
||||
return $this->success('update success');
|
||||
return $this->success('UPDATE_SUCCESS');
|
||||
}
|
||||
return $this->fail('update failed');
|
||||
}
|
||||
@@ -196,8 +298,7 @@ class DicePlayerController extends BaseController
|
||||
}
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null, $request->input('dept_id'))) {
|
||||
return $this->fail('no permission to update this record');
|
||||
}
|
||||
}
|
||||
@@ -227,8 +328,7 @@ class DicePlayerController extends BaseController
|
||||
if (!$player) {
|
||||
return $this->fail('not found');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($player->admin_id ?? 0), $allowedIds, true)) {
|
||||
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $player->dept_id ?? null)) {
|
||||
return $this->fail('no permission to view this record');
|
||||
}
|
||||
if ((int) ($player->status ?? 1) === 0) {
|
||||
@@ -281,13 +381,12 @@ class DicePlayerController extends BaseController
|
||||
return $this->fail('please select data to delete');
|
||||
}
|
||||
$ids = is_array($ids) ? $ids : explode(',', (string) $ids);
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null) {
|
||||
$models = $this->logic->model->whereIn('id', $ids)->column('admin_id', 'id');
|
||||
$deptId = AdminScopeHelper::getDeptId($this->adminInfo ?? null);
|
||||
if ($deptId !== null) {
|
||||
$models = $this->logic->model->whereIn('id', $ids)->column('dept_id', 'id');
|
||||
$validIds = [];
|
||||
foreach ($ids as $id) {
|
||||
$adminId = (int) ($models[$id] ?? 0);
|
||||
if (in_array($adminId, $allowedIds, true)) {
|
||||
if (AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $models[$id] ?? null)) {
|
||||
$validIds[] = $id;
|
||||
}
|
||||
}
|
||||
@@ -311,4 +410,17 @@ class DicePlayerController extends BaseController
|
||||
return $this->fail('delete failed');
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否违反 dice_player (dept_id, username) 唯一索引
|
||||
*/
|
||||
private static function isDeptUsernameDuplicateException(\Throwable $e): bool
|
||||
{
|
||||
$message = $e->getMessage();
|
||||
if ($message === '') {
|
||||
return false;
|
||||
}
|
||||
return str_contains($message, 'uk_dice_player_dept_username')
|
||||
|| (str_contains($message, 'Duplicate entry') && str_contains($message, 'username'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class DicePlayerTicketRecordController extends BaseController
|
||||
['create_time_max', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$query->with([
|
||||
'dicePlayer',
|
||||
]);
|
||||
@@ -70,7 +70,7 @@ class DicePlayerTicketRecordController extends BaseController
|
||||
public function getPlayerOptions(Request $request): Response
|
||||
{
|
||||
$query = DicePlayer::field('id,username');
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$list = $query->select();
|
||||
$data = $list->map(function ($item) {
|
||||
return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
|
||||
@@ -91,8 +91,7 @@ class DicePlayerTicketRecordController extends BaseController
|
||||
if (!$model) {
|
||||
return $this->fail('not found');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null, $request->input('dept_id'))) {
|
||||
return $this->fail('no permission to view this record');
|
||||
}
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
@@ -109,6 +108,7 @@ class DicePlayerTicketRecordController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
AdminScopeHelper::prepareBusinessSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('add success');
|
||||
@@ -127,6 +127,13 @@ class DicePlayerTicketRecordController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$model = $this->logic->read($data['id'] ?? 0);
|
||||
if ($model) {
|
||||
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
|
||||
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $request->input('dept_id'))) {
|
||||
return $this->fail('no permission to update this record');
|
||||
}
|
||||
}
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('update success');
|
||||
|
||||
@@ -47,13 +47,18 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
['create_time_min', ''],
|
||||
['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);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $deptId);
|
||||
$query->with([
|
||||
'dicePlayer',
|
||||
'operator',
|
||||
]);
|
||||
|
||||
$data = $this->logic->getList($query);
|
||||
$data['total_coin_change'] = $totalCoinChange;
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
@@ -66,7 +71,7 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
public function getPlayerOptions(Request $request): Response
|
||||
{
|
||||
$query = DicePlayer::field('id,username');
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$list = $query->select();
|
||||
$data = $list->map(function ($item) {
|
||||
return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
|
||||
@@ -87,12 +92,11 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
if ($playerId === null || $playerId === '') {
|
||||
return $this->fail('missing player_id');
|
||||
}
|
||||
$player = DicePlayer::field('coin,admin_id')->where('id', $playerId)->find();
|
||||
$player = DicePlayer::field('coin,dept_id')->where('id', $playerId)->find();
|
||||
if (!$player) {
|
||||
return $this->fail('Player not found');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($player->admin_id ?? 0), $allowedIds, true)) {
|
||||
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $player->dept_id ?? null)) {
|
||||
return $this->fail('no permission to operate this player');
|
||||
}
|
||||
return $this->success(['wallet_before' => (float) $player['coin']]);
|
||||
@@ -111,8 +115,7 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
if (!$model) {
|
||||
return $this->fail('not found');
|
||||
}
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null)) {
|
||||
return $this->fail('no permission to view this record');
|
||||
}
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
@@ -166,12 +169,9 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
return $this->fail('please login first');
|
||||
}
|
||||
|
||||
$player = DicePlayer::field('admin_id')->where('id', $playerId)->find();
|
||||
if ($player) {
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($player->admin_id ?? 0), $allowedIds, true)) {
|
||||
return $this->fail('no permission to operate this player');
|
||||
}
|
||||
$player = DicePlayer::field('dept_id')->where('id', $playerId)->find();
|
||||
if ($player && !AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $player->dept_id ?? null, $request->input('dept_id'))) {
|
||||
return $this->fail('no permission to operate this player');
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -182,6 +182,24 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('玩家钱包流水添加', 'dice:player_wallet_record:index:save')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
AdminScopeHelper::prepareBusinessSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('add success');
|
||||
}
|
||||
return $this->fail('add failed');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param Request $request
|
||||
@@ -192,6 +210,13 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$model = $this->logic->read($data['id'] ?? 0);
|
||||
if ($model) {
|
||||
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
|
||||
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $request->input('dept_id'))) {
|
||||
return $this->fail('no permission to update this record');
|
||||
}
|
||||
}
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('update success');
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\reward;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use app\dice\logic\reward\DiceRewardLogic;
|
||||
use app\dice\logic\reward_config_record\DiceRewardConfigRecordLogic;
|
||||
use app\dice\model\reward\DiceReward;
|
||||
@@ -42,11 +43,18 @@ class DiceRewardController extends BaseController
|
||||
$orderType = $request->input('orderType', 'asc');
|
||||
|
||||
$logic = new DiceRewardLogic();
|
||||
$data = $logic->getListWithConfig($direction, [
|
||||
'tier' => $tier,
|
||||
'orderField' => $orderField,
|
||||
'orderType' => $orderType,
|
||||
], $page, $limit);
|
||||
$data = $logic->getListWithConfig(
|
||||
$direction,
|
||||
[
|
||||
'tier' => $tier,
|
||||
'orderField' => $orderField,
|
||||
'orderType' => $orderType,
|
||||
],
|
||||
$page,
|
||||
$limit,
|
||||
$this->adminInfo ?? null,
|
||||
$request->input('dept_id')
|
||||
);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
@@ -61,8 +69,10 @@ class DiceRewardController extends BaseController
|
||||
if (!in_array($direction, [DiceReward::DIRECTION_CLOCKWISE, DiceReward::DIRECTION_COUNTERCLOCKWISE], true)) {
|
||||
$direction = DiceReward::DIRECTION_CLOCKWISE;
|
||||
}
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
|
||||
DiceReward::refreshCache($deptId);
|
||||
$logic = new DiceRewardLogic();
|
||||
$data = $logic->getListGroupedByTierForDirection($direction);
|
||||
$data = $logic->getListGroupedByTierForDirection($direction, $deptId);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
@@ -74,9 +84,10 @@ class DiceRewardController extends BaseController
|
||||
#[Permission('奖励对照列表', 'dice:reward:index:index')]
|
||||
public function weightRatioListWithDirection(Request $request): Response
|
||||
{
|
||||
DiceReward::refreshCache();
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
|
||||
DiceReward::refreshCache($deptId);
|
||||
$logic = new DiceRewardLogic();
|
||||
$data = $logic->getListGroupedByTierWithDirection();
|
||||
$data = $logic->getListGroupedByTierWithDirection($deptId);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
@@ -103,11 +114,14 @@ class DiceRewardController extends BaseController
|
||||
'chain_free_mode' => $post['chain_free_mode'] ?? null,
|
||||
'kill_mode_enabled' => $post['kill_mode_enabled'] ?? null,
|
||||
'test_safety_line' => $post['test_safety_line'] ?? null,
|
||||
'dept_id' => $post['dept_id'] ?? null,
|
||||
'ante_config_id' => $post['ante_config_id'] ?? null,
|
||||
];
|
||||
$adminId = isset($this->adminInfo['id']) ? (int) $this->adminInfo['id'] : null;
|
||||
$requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), $post);
|
||||
try {
|
||||
$logic = new DiceRewardConfigRecordLogic();
|
||||
$recordId = $logic->createWeightTestRecord($params, $adminId);
|
||||
$recordId = $logic->createWeightTestRecord($params, $adminId, $this->adminInfo ?? null, $requestDeptId);
|
||||
return $this->success(['record_id' => $recordId]);
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
@@ -167,8 +181,9 @@ class DiceRewardController extends BaseController
|
||||
return $this->fail('parameter items must be an array');
|
||||
}
|
||||
try {
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$logic = new DiceRewardLogic();
|
||||
$logic->batchUpdateWeights($items);
|
||||
$logic->batchUpdateWeights($items, $deptId);
|
||||
return $this->success('save success');
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
@@ -191,8 +206,9 @@ class DiceRewardController extends BaseController
|
||||
return $this->fail('parameter items must be an array');
|
||||
}
|
||||
try {
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$logic = new DiceRewardLogic();
|
||||
$logic->batchUpdateWeightsByDirection($direction, $items);
|
||||
$logic->batchUpdateWeightsByDirection($direction, $items, $deptId);
|
||||
return $this->success('save success');
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
|
||||
@@ -6,9 +6,11 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\reward_config;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\reward_config\DiceRewardConfigLogic;
|
||||
use app\dice\logic\reward\DiceRewardLogic;
|
||||
use app\dice\model\reward\DiceReward;
|
||||
use app\dice\validate\reward_config\DiceRewardConfigValidate;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
@@ -46,7 +48,9 @@ class DiceRewardConfigController extends BaseController
|
||||
['tier', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$data = $this->logic->getList($query);
|
||||
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
// 奖励索引 + 大奖权重共约 32 条,配置页需一次返回本渠道全部数据
|
||||
$data = $query->order('id', 'asc')->select()->toArray();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
@@ -78,6 +82,7 @@ class DiceRewardConfigController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
AdminScopeHelper::prepareConfigSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('add success');
|
||||
@@ -95,8 +100,19 @@ class DiceRewardConfigController extends BaseController
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
if ($data === [] || $data === null) {
|
||||
$data = $request->all();
|
||||
}
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
$requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), is_array($data) ? $data : []);
|
||||
$model = $this->logic->read($data['id'] ?? 0);
|
||||
if ($model) {
|
||||
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
|
||||
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $requestDeptId)) {
|
||||
return $this->fail('no permission to update this record');
|
||||
}
|
||||
}
|
||||
$result = $this->logic->edit($data['id'], $data, $this->adminInfo ?? null, $requestDeptId);
|
||||
if ($result) {
|
||||
return $this->success('update success');
|
||||
} else {
|
||||
@@ -123,7 +139,9 @@ class DiceRewardConfigController extends BaseController
|
||||
foreach ($items as $item) {
|
||||
$this->validate('batch_update', array_merge($item, ['id' => $item['id']]));
|
||||
}
|
||||
$this->logic->batchUpdate($items);
|
||||
$requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), $request->post());
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $requestDeptId);
|
||||
$this->logic->batchUpdate($items, $deptId);
|
||||
return $this->success('save success');
|
||||
}
|
||||
|
||||
@@ -139,7 +157,7 @@ class DiceRewardConfigController extends BaseController
|
||||
if (empty($ids)) {
|
||||
return $this->fail('please select data to delete');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
$result = $this->logic->destroy($ids, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
if ($result) {
|
||||
return $this->success('delete success');
|
||||
} else {
|
||||
@@ -155,8 +173,10 @@ class DiceRewardConfigController extends BaseController
|
||||
#[Permission('奖励配置列表', 'dice:reward_config:index:index')]
|
||||
public function weightRatioList(Request $request): Response
|
||||
{
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
|
||||
DiceReward::refreshCache($deptId);
|
||||
$rewardLogic = new DiceRewardLogic();
|
||||
$data = $rewardLogic->getListGroupedByTierWithDirection();
|
||||
$data = $rewardLogic->getListGroupedByTierWithDirection($deptId);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
@@ -174,8 +194,9 @@ class DiceRewardConfigController extends BaseController
|
||||
return $this->fail('parameter items must be an array');
|
||||
}
|
||||
try {
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$rewardLogic = new DiceRewardLogic();
|
||||
$rewardLogic->batchUpdateWeights($items);
|
||||
$rewardLogic->batchUpdateWeights($items, $deptId);
|
||||
return $this->success('save success');
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
@@ -199,7 +220,8 @@ class DiceRewardConfigController extends BaseController
|
||||
if ($err !== null) {
|
||||
return $this->fail($err);
|
||||
}
|
||||
$this->logic->batchUpdateBigwinWeight($items);
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$this->logic->batchUpdateBigwinWeight($items, $deptId);
|
||||
return $this->success('save success');
|
||||
}
|
||||
|
||||
@@ -214,7 +236,8 @@ class DiceRewardConfigController extends BaseController
|
||||
{
|
||||
try {
|
||||
$rewardLogic = new DiceRewardLogic();
|
||||
$result = $rewardLogic->createRewardReferenceFromConfig();
|
||||
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$result = $rewardLogic->createRewardReferenceFromConfig($deptId);
|
||||
return $this->success($result, 'create reward mapping success');
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace app\dice\controller\reward_config_record;
|
||||
|
||||
use app\dice\logic\reward_config_record\DiceRewardConfigRecordLogic;
|
||||
use app\dice\validate\reward_config_record\DiceRewardConfigRecordValidate;
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\app\model\system\SystemUser;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
@@ -42,6 +43,7 @@ class DiceRewardConfigRecordController extends BaseController
|
||||
['ante', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
@@ -96,6 +98,7 @@ class DiceRewardConfigRecordController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
AdminScopeHelper::prepareBusinessSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('add success');
|
||||
@@ -114,6 +117,13 @@ class DiceRewardConfigRecordController extends BaseController
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$model = $this->logic->read($data['id'] ?? 0);
|
||||
if ($model) {
|
||||
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
|
||||
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $request->input('dept_id'))) {
|
||||
return $this->fail('no permission to update this record');
|
||||
}
|
||||
}
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('update success');
|
||||
|
||||
Reference in New Issue
Block a user