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 support\think\Db;
use app\api\logic\GameLogic;
use app\api\logic\PlayStartLogic;
use app\api\util\ReturnCode;
use app\dice\helper\AdminScopeHelper;
use app\dice\model\config\DiceConfig;
use app\dice\model\ante_config\DiceAnteConfig;
use app\dice\model\play_record\DicePlayRecord;
@@ -34,7 +35,12 @@ class GameController extends BaseController
*/
public function config(Request $request): Response
{
$rows = DiceConfig::select('name', 'group', 'title', 'title_en', 'value', 'value_en', 'create_time', 'update_time')->get();
$configDeptId = $this->resolvePlayerConfigDeptIdFromRequest($request);
$rows = (new DiceConfig())
->field('name,group,title,title_en,value,value_en,create_time,update_time')
->where('dept_id', $configDeptId)
->select()
->toArray();
$lang = $request->header('lang', 'zh');
if (!is_string($lang) || $lang === '') {
$lang = 'zh';
@@ -43,15 +49,15 @@ class GameController extends BaseController
$isEn = $langLower === 'en' || str_starts_with($langLower, 'en-');
$data = [];
foreach ($rows as $row) {
$group = $row->group ?? '';
$group = $row['group'] ?? '';
if (!isset($data[$group])) {
$data[$group] = [];
}
$title = $row->title;
$value = $row->value;
$title = $row['title'] ?? '';
$value = $row['value'] ?? '';
if ($isEn) {
$titleEn = $row->title_en ?? '';
$valueEn = $row->value_en ?? '';
$titleEn = $row['title_en'] ?? '';
$valueEn = $row['value_en'] ?? '';
if ($titleEn !== '') {
$title = $titleEn;
}
@@ -60,11 +66,11 @@ class GameController extends BaseController
}
}
$data[$group][] = [
'name' => $row->name,
'name' => $row['name'] ?? '',
'title' => $title,
'value' => $value,
'create_time' => $row->create_time,
'update_time' => $row->update_time,
'create_time' => $row['create_time'] ?? '',
'update_time' => $row['update_time'] ?? '',
];
}
return $this->success($data);
@@ -107,7 +113,8 @@ class GameController extends BaseController
*/
public function lotteryPool(Request $request): Response
{
$list = DiceRewardConfig::getCachedList();
$configDeptId = $this->resolvePlayerConfigDeptIdFromRequest($request);
$list = DiceRewardConfig::getCachedList($configDeptId);
$list = array_values(array_filter($list, function ($row) {
return (string) ($row['tier'] ?? '') !== 'BIGWIN';
}));
@@ -145,9 +152,9 @@ class GameController extends BaseController
*/
public function anteConfig(Request $request): Response
{
// 用于后续抽奖校验:在接口中实例化 model后续逻辑可复用相同的数据读取方式。
$configDeptId = $this->resolvePlayerConfigDeptIdFromRequest($request);
$anteConfigModel = new DiceAnteConfig();
$rows = $anteConfigModel->order('id', 'asc')->select()->toArray();
$rows = $anteConfigModel->where('dept_id', $configDeptId)->order('id', 'asc')->select()->toArray();
return $this->success($rows);
}
@@ -200,7 +207,8 @@ class GameController extends BaseController
$rewardTier = array_key_exists('reward_tier', $data) ? (string) ($data['reward_tier'] ?? '') : '';
$targetIndex = array_key_exists('target_index', $data) ? (int) ($data['target_index'] ?? 0) : 0;
if ($rewardTier !== 'BIGWIN' && $targetIndex > 0) {
$configRow = DiceRewardConfig::getCachedById($targetIndex);
$configDeptId = AdminScopeHelper::resolvePlayerConfigDeptId($player);
$configRow = DiceRewardConfig::getCachedById($targetIndex, $configDeptId);
if ($configRow !== null) {
$uiText = '';
$uiTextEn = '';
@@ -273,4 +281,20 @@ class GameController extends BaseController
Db::execute('SELECT RELEASE_LOCK(?)', [$lockName]);
}
}
/**
* 从 token 注入的 player_id 解析所属渠道配置 ID
*/
private function resolvePlayerConfigDeptIdFromRequest(Request $request): int
{
$userId = (int) ($request->player_id ?? 0);
if ($userId <= 0) {
return AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
}
$player = DicePlayer::find($userId);
if (!$player) {
return AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
}
return AdminScopeHelper::resolvePlayerConfigDeptId($player);
}
}

View File

@@ -36,4 +36,26 @@ return [
'BATCH_DELETE_FORBIDDEN' => 'Batch delete is not allowed',
'SUPER_ADMIN_CANNOT_DELETE' => 'Super admin cannot be deleted',
'OLD_PASSWORD_WRONG' => 'Old password is incorrect',
'ADD_SUCCESS' => 'Added successfully',
'UPDATE_SUCCESS' => 'Updated successfully',
'DELETE_SUCCESS' => 'Deleted successfully',
'ADD_FAILED' => 'Add failed',
'UPDATE_FAILED' => 'Update failed',
'DELETE_FAILED' => 'Delete failed',
'NOT_FOUND' => 'Data not found',
'ANTE_MUST_POSITIVE' => 'Ante must be greater than 0',
'ANTE_NOT_ALLOWED' => 'Ante %s is not available for current channel, please select from ante config',
'ANTE_CONFIG_NOT_FOUND' => 'Ante config not found',
'ANTE_CONFIG_NOT_IN_CHANNEL' => 'Ante config does not belong to current channel',
'POOL_CONFIG_NOT_IN_CHANNEL' => 'Pool config does not belong to current channel',
'CHANNEL_DEPT_ID_REQUIRED' => 'Please select a channel, or assign a valid administrator/player for this record',
'INVALID_CHANNEL_DEPT_ID' => 'Invalid channel. Please reselect channel or administrator',
'PLAYER_USERNAME_DEPT_UNIQUE' => 'Username already exists in this channel',
'NO_PERMISSION_UPDATE' => 'No permission to update this record',
'NO_PERMISSION_VIEW' => 'No permission to view this record',
'NO_PERMISSION_OPERATE_PLAYER' => 'No permission to operate this player',
'PLEASE_SELECT_DATA' => 'Please select data to delete',
'OPERATION_SUCCESS' => 'Operation successful',
'TEST_DATA_CLEARED' => 'Test data cleared',
'CLEAR_FAILED' => 'Clear failed: %s',
];

View File

@@ -9,6 +9,28 @@ declare(strict_types=1);
return [
'success' => 'Success',
'fail' => 'Fail',
'add success' => 'Added successfully',
'update success' => 'Updated successfully',
'save success' => 'Saved successfully',
'delete success' => 'Deleted successfully',
'add failed' => 'Add failed',
'update failed' => 'Update failed',
'delete failed' => 'Delete failed',
'not found' => 'Data not found',
'operation success' => 'Operation successful',
'test data cleared' => 'Test data cleared',
'ante must be greater than 0' => 'Ante must be greater than 0',
'ante not allowed: %s' => 'Ante %s is not available for current channel, please select from ante config',
'pool config does not belong to current channel' => 'Pool config does not belong to current channel',
'no permission to update this record' => 'No permission to update this record',
'no permission to view this record' => 'No permission to view this record',
'no permission to operate this player' => 'No permission to operate this player',
'please select data to delete' => 'Please select data to delete',
'please select player' => 'Please select player',
'please login first' => 'Please login first',
'missing player_id' => 'Missing player_id',
'Player not found' => 'Player not found',
'record not found' => 'Record not found',
'username、password 不能为空' => 'username and password are required',
'请携带 token' => 'Please provide token',
'token 无效' => 'Invalid or expired token',

View File

@@ -36,5 +36,27 @@ return [
'BATCH_DELETE_FORBIDDEN' => '禁止批量删除操作',
'SUPER_ADMIN_CANNOT_DELETE' => '超级管理员禁止删除',
'OLD_PASSWORD_WRONG' => '原密码错误',
'ADD_SUCCESS' => '添加成功',
'UPDATE_SUCCESS' => '修改成功',
'DELETE_SUCCESS' => '删除成功',
'ADD_FAILED' => '添加失败',
'UPDATE_FAILED' => '修改失败',
'DELETE_FAILED' => '删除失败',
'NOT_FOUND' => '数据不存在',
'ANTE_MUST_POSITIVE' => '底注必须大于 0',
'ANTE_NOT_ALLOWED' => '底注 %s 在当前渠道不可用,请从底注配置中选择',
'ANTE_CONFIG_NOT_FOUND' => '底注配置不存在',
'ANTE_CONFIG_NOT_IN_CHANNEL' => '底注配置不属于当前渠道',
'POOL_CONFIG_NOT_IN_CHANNEL' => '奖池配置不属于当前渠道',
'CHANNEL_DEPT_ID_REQUIRED' => '请选择所属渠道,或为记录指定有效的所属管理员/玩家',
'INVALID_CHANNEL_DEPT_ID' => '渠道无效,请重新选择所属渠道或管理员',
'PLAYER_USERNAME_DEPT_UNIQUE' => '该渠道下用户名已存在',
'NO_PERMISSION_UPDATE' => '无权限修改该记录',
'NO_PERMISSION_VIEW' => '无权限查看该记录',
'NO_PERMISSION_OPERATE_PLAYER' => '无权限操作该玩家',
'PLEASE_SELECT_DATA' => '请选择要删除的数据',
'OPERATION_SUCCESS' => '操作成功',
'TEST_DATA_CLEARED' => '测试数据已清空',
'CLEAR_FAILED' => '清空失败:%s',
];

View File

@@ -6,6 +6,7 @@ namespace app\api\logic;
use app\api\cache\UserCache;
use app\api\util\ApiLang;
use app\api\service\LotteryService;
use app\dice\helper\AdminScopeHelper;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\play_record\DicePlayRecord;
use app\dice\model\ante_config\DiceAnteConfig;
@@ -64,6 +65,8 @@ class PlayStartLogic
throw new ApiException('User not found');
}
$configDeptId = AdminScopeHelper::resolvePlayerConfigDeptId($player);
$coin = (float) $player->coin;
if ($ante <= 0) {
throw new ApiException('ante must be a positive integer');
@@ -71,7 +74,7 @@ class PlayStartLogic
// 注数合规校验ante 必须存在于 dice_ante_config.mult
$anteConfigModel = new DiceAnteConfig();
$exists = $anteConfigModel->where('mult', $ante)->count();
$exists = $anteConfigModel->where('mult', $ante)->where('dept_id', $configDeptId)->count();
if ($exists <= 0) {
throw new ApiException('当前注数不合规,请选择正确的注数');
}
@@ -109,8 +112,8 @@ class PlayStartLogic
}
}
$configType0 = DiceLotteryPoolConfig::where('name', 'default')->find();
$configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->find();
$configType0 = DiceLotteryPoolConfig::where('name', 'default')->where('dept_id', $configDeptId)->find();
$configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->where('dept_id', $configDeptId)->find();
if (!$configType0) {
throw new ApiException('Lottery pool config not found (name=default required)');
}
@@ -120,7 +123,7 @@ class PlayStartLogic
// 游玩前余额校验(按 T4 惩罚最大值兜底):
// 门槛 = paidAmount(压注*1) + abs(T4最小real_ev)*ante
$t4List = DiceRewardConfig::getCachedByTier('T4');
$t4List = DiceRewardConfig::getCachedByTier('T4', $configDeptId);
$t4MinRealEv = null;
foreach ($t4List as $row) {
$ev = $row['real_ev'] ?? null;
@@ -155,7 +158,7 @@ class PlayStartLogic
: $configType0;
// 按档位 T1-T5 抽取后,从 DiceReward 表按当前方向取该档位数据,再按 weight 抽取一条得到 grid_number
$rewardInstance = DiceReward::getCachedInstance();
$rewardInstance = DiceReward::getCachedInstance($configDeptId);
$byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
$maxTierRetry = 10;
$chosen = null;
@@ -216,7 +219,7 @@ class PlayStartLogic
$superWinCoin = 0.0;
$rollArray = $this->generateNonSuperWinRollArrayWithSum($rollNumber);
} else {
$bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber);
$bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber, $configDeptId);
$alwaysSuperWin = in_array($rollNumber, self::SUPER_WIN_ALWAYS_GRID_NUMBERS, true);
$doSuperWin = $alwaysSuperWin;
if (!$doSuperWin) {
@@ -639,9 +642,9 @@ class PlayStartLogic
* @param array|null $customTierWeights 自定义档位权重 ['T1'=>x, 'T2'=>x, ...],非空时忽略 config 的档位权重
* @return array 可直接用于 DicePlayRecordTest::create 的字段 + tier用于统计档位概率
*/
public function simulateOnePlay($config, int $direction, int $lotteryType = 0, int $ante = 1, ?array $customTierWeights = null): array
public function simulateOnePlay($config, int $direction, int $lotteryType = 0, int $ante = 1, ?array $customTierWeights = null, ?int $configDeptId = null): array
{
$rewardInstance = DiceReward::getCachedInstance();
$rewardInstance = DiceReward::getCachedInstance($configDeptId);
$byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
$maxTierRetry = 10;
$chosen = null;
@@ -698,7 +701,7 @@ class PlayStartLogic
$superWinCoin = 0.0;
$rollArray = $this->generateNonSuperWinRollArrayWithSum($rollNumber);
} else {
$bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber);
$bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber, $configDeptId);
$alwaysSuperWin = in_array($rollNumber, self::SUPER_WIN_ALWAYS_GRID_NUMBERS, true);
$doSuperWin = $alwaysSuperWin;
if (!$doSuperWin) {

View File

@@ -5,7 +5,6 @@ namespace app\api\logic;
use app\dice\model\player\DicePlayer;
use app\api\cache\UserCache;
use plugin\saiadmin\app\model\system\SystemDept;
use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\exception\ApiException;
use Tinywan\Jwt\JwtToken;
@@ -44,46 +43,8 @@ class UserLogic
}
/**
* 根据 parent_id 向上遍历找到顶级部门parent_id=0
*/
private static function getTopDeptIdByParentId(int $deptId): ?int
{
$currentId = $deptId;
$visited = [];
while ($currentId > 0 && !isset($visited[$currentId])) {
$visited[$currentId] = true;
$dept = SystemDept::find($currentId);
if (!$dept) {
return null;
}
$parentId = (int) ($dept->parent_id ?? 0);
if ($parentId === 0) {
return $currentId;
}
$currentId = $parentId;
}
return $currentId > 0 ? $currentId : null;
}
/**
* 根据顶级部门 id递归获取其下所有部门 id含自身仅用 id 和 parent_id
*/
private static function getAllDeptIdsUnderTop(int $topId): array
{
$deptIds = [$topId];
$prevCount = 0;
while (count($deptIds) > $prevCount) {
$prevCount = count($deptIds);
$children = SystemDept::whereIn('parent_id', $deptIds)->column('id');
$deptIds = array_unique(array_merge($deptIds, array_map('intval', $children)));
}
return array_values($deptIds);
}
/**
* 根据 agent_id 获取当前管理员所在顶级部门下的所有管理员 ID 列表
* 使用 SystemDept 的 id 和 parent_id 字段遍历:先向上找顶级部门(parent_id=0),再向下收集所有子部门
* 用于 getGameUrl 接口判断 DicePlayer 是否属于该部门,同顶级部门下不重复创建玩家
* 根据 agent_id 获取同渠道下的所有管理员 ID 列表
* 用于 getGameUrl 接口判断 DicePlayer 是否属于该渠道,同渠道下不重复创建玩家
*
* @param string $agentId 代理标识sa_system_user.agent_id
* @return int[] 管理员 ID 列表,空数组表示未找到或无法解析
@@ -103,16 +64,8 @@ class UserLogic
return [(int) $admin->id];
}
$deptId = (int) $deptId;
$topId = self::getTopDeptIdByParentId($deptId);
if ($topId === null) {
return [(int) $admin->id];
}
$deptIds = self::getAllDeptIdsUnderTop($topId);
if (empty($deptIds)) {
$deptIds = [$deptId];
}
$adminIds = SystemUser::whereIn('dept_id', $deptIds)->column('id');
return array_map('intval', $adminIds);
$adminIds = SystemUser::where('dept_id', $deptId)->column('id');
return array_map('intval', $adminIds ?: [(int) $admin->id]);
}
/**
@@ -155,6 +108,10 @@ class UserLogic
$player->coin = $coin;
if ($adminId !== null && $adminId > 0) {
$player->admin_id = $adminId;
$adminUser = SystemUser::find($adminId);
if ($adminUser && !empty($adminUser->dept_id)) {
$player->dept_id = $adminUser->dept_id;
}
}
$player->save();
}

View File

@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace app\dice\basic;
use plugin\saiadmin\basic\think\BaseLogic;
/**
* 大富翁逻辑层基类:删除均为硬删除
*/
class DiceBaseLogic extends BaseLogic
{
/**
* @param mixed $ids
*/
public function destroy($ids): bool
{
return $this->model->destroy($ids, true);
}
}

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 '';
}
}

View File

@@ -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');
}

View File

@@ -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 {

View File

@@ -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');
}

View File

@@ -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');
}
}

View File

@@ -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');

View File

@@ -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');

View File

@@ -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'));
}
}

View File

@@ -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');

View File

@@ -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');

View File

@@ -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());

View File

@@ -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());

View File

@@ -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');

View File

@@ -3,21 +3,75 @@ declare(strict_types=1);
namespace app\dice\helper;
use app\dice\model\player\DicePlayer;
use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\exception\ApiException;
/**
* 管理员数据范围辅助类
* 用于获取当前管理员及其部门下属管理员可访问的数据范围
* 大富翁数据范围:按渠道 dept_id 隔离(关联 sa_system_dept
*/
class AdminScopeHelper
{
/** 超管查看默认配置模板 */
public const DEFAULT_TEMPLATE_DEPT = 0;
/**
* 获取当前管理员可访问的 admin_id 列表
* 超级管理员(id=1) 返回 null 表示不限制
* 普通管理员返回其本人及部门下属管理员的 id 列表
* 当前管理员所属渠道 ID超级管理员(id=1) 返回 null 表示不限制
*/
public static function getDeptId(?array $adminInfo): ?int
{
if (empty($adminInfo) || !isset($adminInfo['id'])) {
return null;
}
$adminId = (int) $adminInfo['id'];
if ($adminId <= 1) {
return null;
}
$deptList = $adminInfo['deptList'] ?? [];
if (!empty($deptList['id'])) {
return (int) $deptList['id'];
}
if (!empty($adminInfo['dept_id'])) {
return (int) $adminInfo['dept_id'];
}
return 0;
}
public static function isSuperAdmin(?array $adminInfo): bool
{
return !empty($adminInfo['id']) && (int) $adminInfo['id'] <= 1;
}
/**
* 解析配置类接口的渠道 ID请求参数 dept_id
* 超管0 或空=默认模板(null)>0=指定渠道
* 普通管理员:固定本渠道
*/
public static function resolveConfigDeptId(?array $adminInfo, $requestDeptId): int
{
$scopeDeptId = self::getDeptId($adminInfo);
if ($scopeDeptId !== null) {
return $scopeDeptId > 0 ? $scopeDeptId : self::DEFAULT_TEMPLATE_DEPT;
}
if ($requestDeptId === null || $requestDeptId === '') {
return self::DEFAULT_TEMPLATE_DEPT;
}
$id = (int) $requestDeptId;
if ($id === self::DEFAULT_TEMPLATE_DEPT) {
return self::DEFAULT_TEMPLATE_DEPT;
}
return $id > 0 ? $id : self::DEFAULT_TEMPLATE_DEPT;
}
public static function isTemplateDeptId($deptId): bool
{
return $deptId === null || $deptId === '' || (int) $deptId === self::DEFAULT_TEMPLATE_DEPT;
}
/**
* 同渠道下可访问的管理员 ID
*
* @param array|null $adminInfo 当前登录管理员信息(含 id、deptList
* @return int[]|null null=不限制(超级管理员),否则为可访问的 admin_id 数组
* @return int[]|null null=不限制
*/
public static function getAllowedAdminIds(?array $adminInfo): ?array
{
@@ -28,33 +82,285 @@ class AdminScopeHelper
if ($adminId <= 1) {
return null;
}
$deptList = $adminInfo['deptList'] ?? [];
if (empty($deptList) || !isset($deptList['id'])) {
$deptId = self::getDeptId($adminInfo);
if ($deptId === null) {
return null;
}
if ($deptId <= 0) {
return [$adminId];
}
$query = SystemUser::field('id');
$query->auth($deptList);
$ids = $query->column('id');
return array_map('intval', $ids ?: []);
$ids = SystemUser::where('dept_id', $deptId)->column('id');
return array_map('intval', $ids ?: [$adminId]);
}
public static function fillDeptId(array &$data, ?array $adminInfo, $requestDeptId = null): void
{
if (isset($data['dept_id']) && $data['dept_id'] !== '' && $data['dept_id'] !== null) {
return;
}
$deptId = self::resolveConfigDeptId($adminInfo, $requestDeptId ?? ($data['filter_dept_id'] ?? null));
if ($deptId > 0) {
$data['dept_id'] = $deptId;
} elseif (!isset($data['dept_id']) || self::isTemplateDeptId($data['dept_id'])) {
$data['dept_id'] = self::DEFAULT_TEMPLATE_DEPT;
}
}
/**
* 对查询应用 admin_id 范围过滤
*
* @param object $query ThinkORM 查询对象
* @param array|null $adminInfo 当前登录管理员信息
* @return void
* 业务数据新增:按渠道写入 dept_id玩家、记录等
* 优先级:已有 dept_id → 所属管理员 admin_id → 请求渠道 → 当前登录人渠道
*/
public static function applyAdminScope($query, ?array $adminInfo): void
public static function fillBusinessDeptId(array &$data, ?array $adminInfo, $requestDeptId = null): void
{
$allowedIds = self::getAllowedAdminIds($adminInfo);
if ($allowedIds === null) {
if (isset($data['dept_id']) && $data['dept_id'] !== '' && $data['dept_id'] !== null) {
$data['dept_id'] = (int) $data['dept_id'];
if ($data['dept_id'] > 0) {
return;
}
}
if (!empty($data['player_id'])) {
$playerDeptId = self::resolveDeptIdByPlayerId($data['player_id']);
if ($playerDeptId !== null && $playerDeptId > 0) {
$data['dept_id'] = $playerDeptId;
return;
}
}
if (!empty($data['admin_id'])) {
$ownerDeptId = self::resolveDeptIdByAdminId($data['admin_id']);
if ($ownerDeptId !== null && $ownerDeptId > 0) {
$data['dept_id'] = $ownerDeptId;
return;
}
}
$deptId = self::resolveBusinessDeptId($adminInfo, $requestDeptId);
if ($deptId !== null && $deptId > 0) {
$data['dept_id'] = $deptId;
return;
}
if (empty($allowedIds)) {
$scopeDeptId = self::getDeptId($adminInfo);
if ($scopeDeptId !== null && $scopeDeptId > 0) {
$data['dept_id'] = $scopeDeptId;
}
}
/**
* 业务新增:解析请求渠道并填充 dept_id缺失时抛错
*/
public static function prepareBusinessSaveData(
array &$data,
?array $adminInfo,
$inputDeptId = null,
array $body = []
): void {
$requestDeptId = self::pickRequestDeptId($inputDeptId, $body);
self::fillBusinessDeptId($data, $adminInfo, $requestDeptId);
self::assertBusinessDeptId($data);
}
/**
* 配置新增:解析请求渠道并填充 dept_id
*/
public static function prepareConfigSaveData(
array &$data,
?array $adminInfo,
$inputDeptId = null,
array $body = []
): void {
$requestDeptId = self::pickRequestDeptId($inputDeptId, $body);
self::fillDeptId($data, $adminInfo, $requestDeptId);
}
/**
* 业务表 dept_id 必须 > 0非默认模板
*/
public static function assertBusinessDeptId(array $data): void
{
if (!isset($data['dept_id']) || $data['dept_id'] === '' || $data['dept_id'] === null) {
throw new ApiException('CHANNEL_DEPT_ID_REQUIRED');
}
if ((int) $data['dept_id'] <= 0) {
throw new ApiException('INVALID_CHANNEL_DEPT_ID');
}
}
/**
* 根据玩家 ID 解析所属渠道
*/
public static function resolveDeptIdByPlayerId($playerId): ?int
{
if ($playerId === null || $playerId === '') {
return null;
}
$player = DicePlayer::field('dept_id,admin_id')->find($playerId);
if (!$player || $player->isEmpty()) {
return null;
}
$deptId = $player->dept_id ?? null;
if ($deptId !== null && $deptId !== '' && (int) $deptId > 0) {
return (int) $deptId;
}
if (!empty($player->admin_id)) {
return self::resolveDeptIdByAdminId($player->admin_id);
}
return null;
}
/**
* 根据后台管理员 ID 解析所属渠道
*/
public static function resolveDeptIdByAdminId($adminId): ?int
{
if ($adminId === null || $adminId === '') {
return null;
}
$admin = SystemUser::find($adminId);
if (!$admin || $admin->isEmpty()) {
return null;
}
$deptId = $admin->dept_id ?? null;
if ($deptId !== null && $deptId !== '' && (int) $deptId > 0) {
return (int) $deptId;
}
return null;
}
/**
* 规范化记录上的 dept_idnull 视为默认模板 0
*/
public static function normalizeRecordDeptId($recordDeptId): int
{
if ($recordDeptId === null || $recordDeptId === '') {
return self::DEFAULT_TEMPLATE_DEPT;
}
return (int) $recordDeptId;
}
/**
* 玩家端读取游戏配置时使用的渠道 ID玩家 dept_id 优先,否则按所属管理员)
*/
public static function resolvePlayerConfigDeptId($player): int
{
$deptId = null;
$adminId = null;
if (is_array($player)) {
$deptId = $player['dept_id'] ?? null;
$adminId = $player['admin_id'] ?? null;
} elseif (is_object($player)) {
$deptId = $player->dept_id ?? null;
$adminId = $player->admin_id ?? null;
}
if ($deptId !== null && $deptId !== '' && (int) $deptId > 0) {
return (int) $deptId;
}
if ($adminId !== null && $adminId !== '') {
$fromAdmin = self::resolveDeptIdByAdminId($adminId);
if ($fromAdmin !== null && $fromAdmin > 0) {
return $fromAdmin;
}
}
return self::DEFAULT_TEMPLATE_DEPT;
}
/**
* 从请求参数或请求体中解析 dept_id兼容 PUT JSON 仅出现在 body 的情况)
*/
public static function pickRequestDeptId($inputDeptId, array $body = [])
{
if ($inputDeptId !== null && $inputDeptId !== '') {
return $inputDeptId;
}
if (isset($body['dept_id']) && $body['dept_id'] !== '' && $body['dept_id'] !== null) {
return $body['dept_id'];
}
return null;
}
public static function canAccessDept(?array $adminInfo, $recordDeptId, $requestDeptId = null): bool
{
$recordDeptId = self::normalizeRecordDeptId($recordDeptId);
$scopeDeptId = self::getDeptId($adminInfo);
if ($scopeDeptId === null) {
if ($requestDeptId === null || $requestDeptId === '') {
return true;
}
$target = self::resolveConfigDeptId($adminInfo, $requestDeptId);
if (self::isTemplateDeptId($target)) {
return self::isTemplateDeptId($recordDeptId);
}
return $recordDeptId === $target;
}
if ($recordDeptId === self::DEFAULT_TEMPLATE_DEPT && $scopeDeptId > 0) {
return false;
}
return $recordDeptId === $scopeDeptId;
}
/**
* 业务页渠道 ID超管通过请求 dept_id 筛选;未传或 <=0 时不限制
*/
public static function resolveBusinessDeptId(?array $adminInfo, $requestDeptId): ?int
{
$scopeDeptId = self::getDeptId($adminInfo);
if ($scopeDeptId !== null) {
return $scopeDeptId > 0 ? $scopeDeptId : null;
}
if ($requestDeptId === null || $requestDeptId === '') {
return null;
}
$id = (int) $requestDeptId;
return $id > 0 ? $id : null;
}
/**
* 业务数据列表(玩家、记录、工作台等)
*/
public static function applyAdminScope($query, ?array $adminInfo, $requestDeptId = null): void
{
if (self::getDeptId($adminInfo) === null) {
$target = self::resolveBusinessDeptId($adminInfo, $requestDeptId);
if ($target !== null && $target > 0) {
$query->where('dept_id', $target);
}
return;
}
$deptId = self::getDeptId($adminInfo);
if ($deptId <= 0) {
$query->whereRaw('1=0');
return;
}
$query->whereIn('admin_id', $allowedIds);
$query->where('dept_id', $deptId);
}
/**
* 配置类列表:超管按所选渠道/默认模板筛选
*/
public static function applyConfigScope($query, ?array $adminInfo, $requestDeptId = null, string $deptColumn = 'dept_id'): void
{
$targetDeptId = self::resolveConfigDeptId($adminInfo, $requestDeptId);
$scopeDeptId = self::getDeptId($adminInfo);
if ($scopeDeptId !== null && !self::isSuperAdmin($adminInfo)) {
if ($scopeDeptId <= 0) {
$query->whereRaw('1=0');
return;
}
$query->where($deptColumn, $scopeDeptId);
return;
}
if (self::isTemplateDeptId($targetDeptId)) {
$templateId = self::DEFAULT_TEMPLATE_DEPT;
$query->where(function ($q) use ($templateId, $deptColumn) {
$q->where($deptColumn, $templateId)->whereOr($deptColumn, null);
});
return;
}
$query->where($deptColumn, $targetDeptId);
}
}

View File

@@ -0,0 +1,139 @@
<?php
declare(strict_types=1);
namespace app\dice\helper;
use plugin\saiadmin\exception\ApiException;
/**
* 配置类数据按渠道隔离的更新(防止 find(id) 误更新其他渠道同业务主键行)
*/
class ConfigScopeEditHelper
{
/**
* 在查询上附加渠道条件
*/
public static function applyDeptIdWhere($query, int $deptId, string $column = 'dept_id'): void
{
if (AdminScopeHelper::isTemplateDeptId($deptId)) {
$query->where(function ($q) use ($deptId, $column) {
$q->where($column, $deptId);
if (method_exists($q, 'orWhereNull')) {
$q->orWhereNull($column);
} else {
$q->whereOr($column, null);
}
});
return;
}
$query->where($column, $deptId);
}
/**
* 按主键 + 渠道更新配置行
*
* @param Model $model 模型实例(用于取表名、主键)
* @param mixed $primaryKeyValue 列表/表单中的主键值
* @param int $deptId 渠道 ID0=默认模板)
* @param array $data 更新字段
* @param array $forbidden 禁止写入的字段名
*/
/**
* 按主键更新(主键全局唯一表如 dice_lottery_pool_config
* 以库中记录的 dept_id 为准,避免请求未带 dept_id 时误按默认模板 0 查找失败
*/
public static function updateByPkAndDept(
object $model,
$primaryKeyValue,
int $requestDeptId,
array $data,
array $forbidden = ['id', 'dept_id', 'create_time', 'update_time', 'delete_time', 'row_id'],
?array $adminInfo = null,
$rawRequestDeptId = null
): bool {
foreach ($forbidden as $field) {
unset($data[$field]);
}
if ($data === []) {
return true;
}
$pk = self::resolvePk($model);
$record = $model->where($pk, $primaryKeyValue)->find();
if ($record === null) {
throw new ApiException('data not found');
}
$recordDeptId = AdminScopeHelper::normalizeRecordDeptId(
is_array($record) ? ($record['dept_id'] ?? null) : ($record->dept_id ?? null)
);
if ($adminInfo !== null && ! AdminScopeHelper::canAccessDept($adminInfo, $recordDeptId, $rawRequestDeptId)) {
throw new ApiException('no permission to update this record');
}
if ($rawRequestDeptId !== null && $rawRequestDeptId !== '') {
$targetDeptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $rawRequestDeptId);
if ($targetDeptId !== $recordDeptId) {
throw new ApiException('record does not belong to selected channel');
}
}
$query = $model->where($pk, $primaryKeyValue);
self::applyDeptIdWhere($query, $recordDeptId);
$affected = $query->update($data);
return $affected !== false;
}
/**
* dice_reward_config / dice_config业务 id025 等)+ 渠道更新
*/
public static function updateByBusinessIdAndDept(
object $model,
int $businessId,
int $deptId,
array $data,
array $forbidden = ['id', 'dept_id', 'create_time', 'update_time', 'delete_time', 'row_id']
): bool {
foreach ($forbidden as $field) {
unset($data[$field]);
}
if ($data === []) {
return true;
}
$query = $model->where('id', $businessId);
self::applyDeptIdWhere($query, $deptId);
$record = (clone $query)->find();
if ($record === null) {
throw new ApiException('config id=' . $businessId . ' not found for current channel');
}
$affected = $query->update($data);
return $affected !== false;
}
/**
* 列表/读取:按主键 + 渠道取单条(避免 find(pk) 命中其他渠道)
*/
private static function resolvePk(object $model): string
{
if (method_exists($model, 'getPk')) {
return (string) $model->getPk();
}
if (method_exists($model, 'getKeyName')) {
return (string) $model->getKeyName();
}
return 'id';
}
public static function findByPkAndDept(object $model, $primaryKeyValue, int $deptId)
{
$pk = self::resolvePk($model);
$query = $model->where($pk, $primaryKeyValue);
self::applyDeptIdWhere($query, $deptId);
return $query->find();
}
}

View File

@@ -6,13 +6,15 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\ante_config;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\ante_config\DiceAnteConfig;
use plugin\saiadmin\basic\think\BaseLogic;
use app\dice\basic\DiceBaseLogic;
/**
* 底注配置逻辑层
*/
class DiceAnteConfigLogic extends BaseLogic
class DiceAnteConfigLogic extends DiceBaseLogic
{
public function __construct()
{
@@ -23,21 +25,32 @@ class DiceAnteConfigLogic extends BaseLogic
{
return $this->transaction(function () use ($data) {
$this->normalizeDefaultField($data);
$deptId = AdminScopeHelper::resolveConfigDeptId(null, $data['dept_id'] ?? AdminScopeHelper::DEFAULT_TEMPLATE_DEPT);
if ((int) ($data['is_default'] ?? 0) === 1) {
$this->clearOtherDefaults();
$this->clearOtherDefaults(null, $deptId);
}
return parent::add($data);
});
}
public function edit($id, array $data): mixed
public function edit($id, array $data, ?array $adminInfo = null, $requestDeptId = null): mixed
{
return $this->transaction(function () use ($id, $data) {
$pickedDeptId = AdminScopeHelper::pickRequestDeptId($requestDeptId, $data);
$deptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $pickedDeptId);
return $this->transaction(function () use ($id, $data, $deptId, $adminInfo, $pickedDeptId) {
$this->normalizeDefaultField($data);
if ((int) ($data['is_default'] ?? 0) === 1) {
$this->clearOtherDefaults((int) $id);
$this->clearOtherDefaults((int) $id, $deptId);
}
return parent::edit($id, $data);
return ConfigScopeEditHelper::updateByPkAndDept(
$this->model,
$id,
$deptId,
$data,
['id', 'dept_id', 'create_time', 'update_time', 'delete_time', 'row_id'],
$adminInfo,
$pickedDeptId
);
});
}
@@ -79,9 +92,10 @@ class DiceAnteConfigLogic extends BaseLogic
$data['is_default'] = ((int) $data['is_default']) === 1 ? 1 : 0;
}
private function clearOtherDefaults(?int $excludeId = null): void
private function clearOtherDefaults(?int $excludeId = null, int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): void
{
$query = $this->model->where('is_default', 1);
ConfigScopeEditHelper::applyDeptIdWhere($query, $deptId);
if ($excludeId !== null && $excludeId > 0) {
$query->where('id', '<>', $excludeId);
}

View File

@@ -6,6 +6,8 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\config;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use plugin\saiadmin\basic\eloquent\BaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
@@ -14,7 +16,7 @@ use app\dice\model\config\DiceConfig;
/**
* 摇色子配置逻辑层
*/
class DiceConfigLogic extends BaseLogic
class DiceConfigLogic extends DiceBaseLogic
{
/**
* 构造函数
@@ -24,4 +26,13 @@ class DiceConfigLogic extends BaseLogic
$this->model = new DiceConfig();
}
public function edit($id, array $data, ?array $adminInfo = null, $requestDeptId = null): mixed
{
$deptId = AdminScopeHelper::resolveConfigDeptId(
$adminInfo,
AdminScopeHelper::pickRequestDeptId($requestDeptId, $data)
);
return ConfigScopeEditHelper::updateByBusinessIdAndDept($this->model, (int) $id, $deptId, $data);
}
}

View File

@@ -4,16 +4,33 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\game;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use plugin\saiadmin\basic\eloquent\BaseLogic;
use app\dice\model\game\DiceGame;
/**
* 游戏管理逻辑层
*/
class DiceGameLogic extends BaseLogic
class DiceGameLogic extends DiceBaseLogic
{
public function __construct()
{
$this->model = new DiceGame();
}
public function edit($id, array $data, ?array $adminInfo = null, $requestDeptId = null): mixed
{
$pickedDeptId = AdminScopeHelper::pickRequestDeptId($requestDeptId, $data);
$deptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $pickedDeptId);
return ConfigScopeEditHelper::updateByPkAndDept(
$this->model,
$id,
$deptId,
$data,
['id', 'dept_id', 'create_time', 'update_time', 'delete_time', 'row_id'],
$adminInfo,
$pickedDeptId
);
}
}

View File

@@ -6,8 +6,10 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\lottery_pool_config;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use plugin\saiadmin\basic\think\BaseLogic;
use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use support\think\Cache;
@@ -15,7 +17,7 @@ use support\think\Cache;
/**
* 色子奖池配置逻辑层
*/
class DiceLotteryPoolConfigLogic extends BaseLogic
class DiceLotteryPoolConfigLogic extends DiceBaseLogic
{
/** Redis 当前彩金池type=0 实例key无则按 type=0 创建 */
private const REDIS_KEY_CURRENT_POOL = 'api:game:lottery_pool:default';
@@ -30,19 +32,55 @@ class DiceLotteryPoolConfigLogic extends BaseLogic
$this->model = new DiceLotteryPoolConfig();
}
/**
* 按渠道隔离更新(主键 id 全局唯一,仍校验 dept_id 防止越权)
*/
public function edit($id, array $data, ?array $adminInfo = null, $requestDeptId = null): mixed
{
$pickedDeptId = AdminScopeHelper::pickRequestDeptId($requestDeptId, $data);
$deptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $pickedDeptId);
return ConfigScopeEditHelper::updateByPkAndDept(
$this->model,
$id,
$deptId,
$data,
['id', 'dept_id', 'create_time', 'update_time', 'delete_time', 'row_id'],
$adminInfo,
$pickedDeptId
);
}
/**
* 获取当前彩金池type=0+ 杀分权重为 type=1 的只读展示
* profit_amount 每次从 DB 实时读取t1_weightt5_weight 来自 type=1杀分权重不可在弹窗内修改
*
* @return array{id:int,name:string,safety_line:int,kill_enabled:int,t1_weight:int,...,t5_weight:int,profit_amount:float}
*/
public function getCurrentPool(): array
public function getCurrentPool(int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): array
{
$configType0 = DiceLotteryPoolConfig::where('name', 'default')->find();
$query0 = DiceLotteryPoolConfig::where('name', 'default');
if (AdminScopeHelper::isTemplateDeptId($deptId)) {
$query0->where(function ($q) {
$q->where('dept_id', AdminScopeHelper::DEFAULT_TEMPLATE_DEPT)
->whereOr('dept_id', null);
});
} else {
$query0->where('dept_id', $deptId);
}
$configType0 = $query0->find();
if (!$configType0) {
throw new ApiException('No name=default pool config found, please create one first');
}
$configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->find();
$query1 = DiceLotteryPoolConfig::where('name', 'killScore');
if (AdminScopeHelper::isTemplateDeptId($deptId)) {
$query1->where(function ($q) {
$q->where('dept_id', AdminScopeHelper::DEFAULT_TEMPLATE_DEPT)
->whereOr('dept_id', null);
});
} else {
$query1->where('dept_id', $deptId);
}
$configType1 = $query1->find();
$row0 = $configType0->toArray();
$profitAmount = isset($row0['profit_amount']) ? (float) $row0['profit_amount'] : (isset($row0['ev']) ? (float) $row0['ev'] : 0.0);
$pool = [
@@ -66,9 +104,9 @@ class DiceLotteryPoolConfigLogic extends BaseLogic
*
* @param array{safety_line?:int,kill_enabled?:int} $data
*/
public function updateCurrentPool(array $data): void
public function updateCurrentPool(array $data, int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): void
{
$pool = $this->getCurrentPool();
$pool = $this->getCurrentPool($deptId);
$id = (int) $pool['id'];
if (!array_key_exists('safety_line', $data) && !array_key_exists('kill_enabled', $data)) {
return;
@@ -83,17 +121,21 @@ class DiceLotteryPoolConfigLogic extends BaseLogic
if ($update === []) {
return;
}
DiceLotteryPoolConfig::where('id', $id)->update($update);
$query = DiceLotteryPoolConfig::where('id', $id);
ConfigScopeEditHelper::applyDeptIdWhere($query, $deptId);
$query->update($update);
}
/**
* 重置当前彩金池的玩家累计盈利:将 profit_amount 置为 0并刷新 Redis 缓存
*/
public function resetProfitAmount(): void
public function resetProfitAmount(int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): void
{
$pool = $this->getCurrentPool();
$pool = $this->getCurrentPool($deptId);
$id = (int) $pool['id'];
DiceLotteryPoolConfig::where('id', $id)->update(['profit_amount' => 0]);
$query = DiceLotteryPoolConfig::where('id', $id);
ConfigScopeEditHelper::applyDeptIdWhere($query, $deptId);
$query->update(['profit_amount' => 0]);
$pool['profit_amount'] = 0.0;
Cache::set(self::REDIS_KEY_CURRENT_POOL, json_encode($pool), self::EXPIRE);
}

View File

@@ -6,7 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\play_record;
use plugin\saiadmin\basic\think\BaseLogic;
use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use app\dice\model\play_record\DicePlayRecord;
@@ -14,7 +14,7 @@ use app\dice\model\play_record\DicePlayRecord;
/**
* 玩家抽奖记录逻辑层
*/
class DicePlayRecordLogic extends BaseLogic
class DicePlayRecordLogic extends DiceBaseLogic
{
/**
* 构造函数

View File

@@ -6,7 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\play_record_test;
use plugin\saiadmin\basic\think\BaseLogic;
use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use app\dice\model\play_record_test\DicePlayRecordTest;
@@ -14,7 +14,7 @@ use app\dice\model\play_record_test\DicePlayRecordTest;
/**
* 玩家抽奖记录(测试数据)逻辑层
*/
class DicePlayRecordTestLogic extends BaseLogic
class DicePlayRecordTestLogic extends DiceBaseLogic
{
/**
* 构造函数

View File

@@ -6,7 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\player;
use plugin\saiadmin\basic\think\BaseLogic;
use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use app\dice\model\player\DicePlayer;
@@ -14,7 +14,7 @@ use app\dice\model\player\DicePlayer;
/**
* 大富翁-玩家逻辑层
*/
class DicePlayerLogic extends BaseLogic
class DicePlayerLogic extends DiceBaseLogic
{
/** 密码加密盐(可与 config 统一) */
private const PASSWORD_SALT = 'dice_player_salt_2024';

View File

@@ -6,7 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\player_ticket_record;
use plugin\saiadmin\basic\think\BaseLogic;
use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use app\dice\model\player_ticket_record\DicePlayerTicketRecord;
@@ -14,7 +14,7 @@ use app\dice\model\player_ticket_record\DicePlayerTicketRecord;
/**
* 抽奖券获取记录逻辑层
*/
class DicePlayerTicketRecordLogic extends BaseLogic
class DicePlayerTicketRecordLogic extends DiceBaseLogic
{
/**
* 构造函数

View File

@@ -6,7 +6,8 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\player_wallet_record;
use plugin\saiadmin\basic\think\BaseLogic;
use app\dice\helper\AdminScopeHelper;
use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException;
use app\dice\model\player_wallet_record\DicePlayerWalletRecord;
use app\dice\model\player\DicePlayer;
@@ -15,7 +16,7 @@ use app\api\cache\UserCache;
/**
* 玩家钱包流水逻辑层
*/
class DicePlayerWalletRecordLogic extends BaseLogic
class DicePlayerWalletRecordLogic extends DiceBaseLogic
{
/**
* 构造函数
@@ -27,6 +28,18 @@ class DicePlayerWalletRecordLogic extends BaseLogic
$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);
}
/**
* 添加数据(补全抽奖次数字段默认值)
*/
@@ -83,9 +96,11 @@ class DicePlayerWalletRecordLogic extends BaseLogic
}
$playerAdminId = ($player->admin_id ?? null) ? (int) $player->admin_id : null;
$playerDeptId = ($player->dept_id ?? null) ? (int) $player->dept_id : null;
$record = [
'player_id' => $playerId,
'admin_id' => $playerAdminId,
'dept_id' => $playerDeptId,
'coin' => $type === 3 ? $coin : -$coin,
'type' => $type,
'wallet_before' => $walletBefore,

View File

@@ -4,6 +4,8 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\reward;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\reward\DiceReward;
use app\dice\model\reward_config\DiceRewardConfig;
use plugin\saiadmin\exception\ApiException;
@@ -29,8 +31,14 @@ class DiceRewardLogic
* @param int $limit
* @return array{total: int, per_page: int, current_page: int, data: array}
*/
public function getListWithConfig(int $direction, array $where, int $page = 1, int $limit = 10): array
{
public function getListWithConfig(
int $direction,
array $where,
int $page = 1,
int $limit = 10,
?array $adminInfo = null,
$requestDeptId = null
): array {
$tier = isset($where['tier']) ? trim((string) $where['tier']) : '';
$orderField = isset($where['orderField']) && $where['orderField'] !== '' ? (string) $where['orderField'] : 'r.tier';
$orderType = isset($where['orderType']) && strtoupper((string) $where['orderType']) === 'DESC' ? 'desc' : 'asc';
@@ -41,6 +49,10 @@ class DiceRewardLogic
->order($orderField, $orderType)
->order('r.end_index', 'asc');
if ($adminInfo !== null) {
AdminScopeHelper::applyConfigScope($query, $adminInfo, $requestDeptId, 'r.dept_id');
}
if ($tier !== '') {
$query->where('r.tier', $tier);
}
@@ -74,7 +86,7 @@ class DiceRewardLogic
* @param int $direction 0=顺时针 1=逆时针
* @param array<int, array{id: int, weight: int}> $items id 为 end_indexDiceRewardConfig.id
*/
public function batchUpdateWeightsByDirection(int $direction, array $items): void
public function batchUpdateWeightsByDirection(int $direction, array $items, ?int $deptId = null): void
{
if (empty($items)) {
return;
@@ -90,23 +102,36 @@ class DiceRewardLogic
}
$weight = max(self::WEIGHT_MIN, min(self::WEIGHT_MAX, $weight));
$tier = DiceRewardConfig::where('id', $id)->value('tier');
$configQuery = DiceRewardConfig::where('id', $id);
if ($deptId !== null) {
ConfigScopeEditHelper::applyDeptIdWhere($configQuery, $deptId);
}
$tier = $configQuery->value('tier');
if ($tier === null || $tier === '') {
throw new ApiException(\app\api\util\ApiLang::translateParams('配置ID %s 不存在或档位为空', [$id]));
}
$tier = (string) $tier;
$affected = DiceReward::where('tier', $tier)->where('direction', $direction)->where('end_index', $id)->update(['weight' => $weight]);
$rewardQuery = DiceReward::where('tier', $tier)
->where('direction', $direction)
->where('end_index', $id);
if ($deptId !== null) {
ConfigScopeEditHelper::applyDeptIdWhere($rewardQuery, $deptId);
}
$affected = $rewardQuery->update(['weight' => $weight]);
if ($affected === 0) {
$m = new DiceReward();
$m->tier = $tier;
$m->direction = $direction;
$m->end_index = $id;
$m->weight = $weight;
if ($deptId !== null && $deptId > 0) {
$m->dept_id = $deptId;
}
$m->save();
}
}
DiceReward::refreshCache();
DiceReward::refreshCache($deptId);
}
/**
@@ -114,11 +139,11 @@ class DiceRewardLogic
* @param int $direction 0=顺时针 1=逆时针
* @return array<string, array> 键 T1|T2|...|BIGWIN值为该档位下带 weight 的行数组
*/
public function getListGroupedByTierForDirection(int $direction): array
public function getListGroupedByTierForDirection(int $direction, ?int $deptId = null): array
{
$configInstance = DiceRewardConfig::getCachedInstance();
$configInstance = DiceRewardConfig::getCachedInstance($deptId);
$byTier = $configInstance['by_tier'] ?? [];
$rewardInstance = DiceReward::getCachedInstance();
$rewardInstance = DiceReward::getCachedInstance($deptId);
$byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
$result = [];
@@ -153,9 +178,9 @@ class DiceRewardLogic
*
* @return array<string, array{0: array, 1: array}>
*/
public function getListGroupedByTierWithDirection(): array
public function getListGroupedByTierWithDirection(?int $deptId = null): array
{
$rewardInstance = DiceReward::getCachedInstance();
$rewardInstance = DiceReward::getCachedInstance($deptId);
$byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
$result = [];
@@ -185,7 +210,7 @@ class DiceRewardLogic
* @param array<int, array{id: int, weight: int}> $items 每项 id 为 dice_reward 表主键weight 为 1-10000
* @throws ApiException
*/
public function batchUpdateWeights(array $items): void
public function batchUpdateWeights(array $items, ?int $deptId = null): void
{
if (empty($items)) {
return;
@@ -203,13 +228,24 @@ class DiceRewardLogic
}
$weight = isset($item['weight']) ? (int) $item['weight'] : self::WEIGHT_MIN;
$weight = max(self::WEIGHT_MIN, min(self::WEIGHT_MAX, $weight));
$model = DiceReward::find($id);
$query = DiceReward::where('id', $id);
if ($deptId !== null) {
if (AdminScopeHelper::isTemplateDeptId($deptId)) {
$query->where(function ($q) {
$q->where('dept_id', AdminScopeHelper::DEFAULT_TEMPLATE_DEPT)
->whereOr('dept_id', null);
});
} else {
$query->where('dept_id', $deptId);
}
}
$model = $query->find();
if ($model !== null) {
$model->weight = $weight;
$model->save();
}
}
DiceReward::refreshCache();
DiceReward::refreshCache($deptId);
}
/** BIGWIN 权重范围0=0% 中奖10000=100% 中奖grid_number=5/30 固定 100% 不可改 */
@@ -219,9 +255,9 @@ class DiceRewardLogic
* 按 grid_number 获取 BIGWIN 档位权重(取顺时针方向,用于编辑展示)
* 若 DiceReward 无该点数则 5/30 返回 10000其余返回 0
*/
public function getBigwinWeightByGridNumber(int $gridNumber): int
public function getBigwinWeightByGridNumber(int $gridNumber, ?int $deptId = null): int
{
$inst = DiceReward::getCachedInstance();
$inst = DiceReward::getCachedInstance($deptId);
$rows = $inst['by_tier_direction']['BIGWIN'][DiceReward::DIRECTION_CLOCKWISE] ?? [];
foreach ($rows as $row) {
if ((int) ($row['grid_number'] ?? 0) === $gridNumber) {
@@ -235,21 +271,24 @@ class DiceRewardLogic
* 更新 BIGWIN 档位某点数的权重(顺/逆时针同时更新0=0% 中奖10000=100% 中奖
* 表 dice_reward 唯一键为 (direction, grid_number),同一点数同一方向仅一条记录,故先按该键查找再更新,避免重复插入
*/
public function updateBigwinWeight(int $gridNumber, int $weight): void
public function updateBigwinWeight(int $gridNumber, int $weight, ?int $deptId = null): void
{
$weight = min(self::BIGWIN_WEIGHT_MAX, max(0, $weight));
$config = DiceRewardConfig::where('tier', 'BIGWIN')
->where('grid_number', $gridNumber)
->find();
if ($deptId === null) {
$deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
}
$configQuery = DiceRewardConfig::where('tier', 'BIGWIN')->where('grid_number', $gridNumber);
ConfigScopeEditHelper::applyDeptIdWhere($configQuery, $deptId);
$config = $configQuery->find();
if (! $config) {
return;
}
$configArr = $config->toArray();
foreach ([DiceReward::DIRECTION_CLOCKWISE, DiceReward::DIRECTION_COUNTERCLOCKWISE] as $direction) {
// 按唯一键 (direction, grid_number) 查找,存在则更新,不存在则插入
$row = DiceReward::where('direction', $direction)
->where('grid_number', $gridNumber)
->find();
$rowQuery = DiceReward::where('direction', $direction)->where('grid_number', $gridNumber);
ConfigScopeEditHelper::applyDeptIdWhere($rowQuery, $deptId);
$row = $rowQuery->find();
if ($row) {
$row->tier = 'BIGWIN';
$row->weight = $weight > 0 ? $weight : self::WEIGHT_MIN;
@@ -272,10 +311,13 @@ class DiceRewardLogic
$m->remark = (string) ($configArr['remark'] ?? '');
$m->type = $configArr['type'] ?? null;
$m->weight = $weight > 0 ? $weight : self::WEIGHT_MIN;
if (!AdminScopeHelper::isTemplateDeptId($deptId)) {
$m->dept_id = $deptId;
}
$m->save();
}
}
DiceReward::refreshCache();
DiceReward::refreshCache($deptId);
}
/** 盘面格数(用于顺时针/逆时针计算 end_index */
@@ -309,9 +351,19 @@ class DiceRewardLogic
* @return array{created_clockwise: int, created_counterclockwise: int, updated_clockwise: int, updated_counterclockwise: int, skipped: int}
* @throws ApiException
*/
public function createRewardReferenceFromConfig(): array
public function createRewardReferenceFromConfig(?int $deptId = null): array
{
$list = DiceRewardConfig::order('id', 'asc')->select()->toArray();
$configQuery = DiceRewardConfig::order('id', 'asc');
if ($deptId === null || $deptId === \app\dice\helper\AdminScopeHelper::DEFAULT_TEMPLATE_DEPT) {
$templateId = \app\dice\helper\AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
$configQuery->where(function ($q) use ($templateId) {
$q->where('dept_id', $templateId)->whereOr('dept_id', 'null');
});
$deptId = null;
} else {
$configQuery->where('dept_id', $deptId);
}
$list = $configQuery->select()->toArray();
if (empty($list)) {
throw new ApiException('Reward config is empty, please maintain dice_reward_config first');
}
@@ -326,8 +378,12 @@ class DiceRewardLogic
}
$table = (new DiceReward())->getTable();
Db::execute('DELETE FROM `' . $table . '`');
DiceReward::refreshCache();
if ($deptId === null) {
Db::table($table)->whereNull('dept_id')->delete();
} else {
Db::table($table)->where('dept_id', $deptId)->delete();
}
DiceReward::refreshCache($deptId ?? AdminScopeHelper::DEFAULT_TEMPLATE_DEPT);
// 按 id 排序后,盘面位置 0..25 对应 $list[$pos],避免 config.id 非 0-25/1-26 时取模结果找不到
$gridToPosition = [];
@@ -379,7 +435,13 @@ class DiceRewardLogic
'remark' => $configCw['remark'] ?? '',
'type' => isset($configCw['type']) ? (int) $configCw['type'] : 0,
];
$existing = DiceReward::where('direction', DiceReward::DIRECTION_CLOCKWISE)->where('grid_number', $gridNumber)->find();
$existingQuery = DiceReward::where('direction', DiceReward::DIRECTION_CLOCKWISE)->where('grid_number', $gridNumber);
if ($deptId === null) {
$existingQuery->whereNull('dept_id');
} else {
$existingQuery->where('dept_id', $deptId);
}
$existing = $existingQuery->find();
if ($existing) {
DiceReward::where('id', $existing->id)->update($payloadCw);
$updatedCw++;
@@ -395,6 +457,9 @@ class DiceRewardLogic
$m->real_ev = $configCw['real_ev'] ?? null;
$m->remark = $configCw['remark'] ?? '';
$m->type = isset($configCw['type']) ? (int) $configCw['type'] : 0;
if ($deptId !== null) {
$m->dept_id = $deptId;
}
$m->save();
$createdCw++;
}
@@ -419,7 +484,13 @@ class DiceRewardLogic
'remark' => $configCcw['remark'] ?? '',
'type' => isset($configCcw['type']) ? (int) $configCcw['type'] : 0,
];
$existing = DiceReward::where('direction', DiceReward::DIRECTION_COUNTERCLOCKWISE)->where('grid_number', $gridNumber)->find();
$existingQuery = DiceReward::where('direction', DiceReward::DIRECTION_COUNTERCLOCKWISE)->where('grid_number', $gridNumber);
if ($deptId === null) {
$existingQuery->whereNull('dept_id');
} else {
$existingQuery->where('dept_id', $deptId);
}
$existing = $existingQuery->find();
if ($existing) {
DiceReward::where('id', $existing->id)->update($payloadCcw);
$updatedCcw++;
@@ -435,6 +506,9 @@ class DiceRewardLogic
$m->real_ev = $configCcw['real_ev'] ?? null;
$m->remark = $configCcw['remark'] ?? '';
$m->type = isset($configCcw['type']) ? (int) $configCcw['type'] : 0;
if ($deptId !== null) {
$m->dept_id = $deptId;
}
$m->save();
$createdCcw++;
}
@@ -442,7 +516,7 @@ class DiceRewardLogic
}
}
DiceReward::refreshCache();
DiceReward::refreshCache($deptId ?? AdminScopeHelper::DEFAULT_TEMPLATE_DEPT);
return [
'created_clockwise' => $createdCw,
'created_counterclockwise' => $createdCcw,

View File

@@ -6,11 +6,13 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\reward_config;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\logic\reward\DiceRewardLogic;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\reward\DiceRewardConfig;
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
use plugin\saiadmin\basic\think\BaseLogic;
use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use support\Log;
@@ -19,7 +21,7 @@ use support\Log;
* 奖励配置逻辑层DiceRewardConfig
* weight 1-10000各档位权重和不限制
*/
class DiceRewardConfigLogic extends BaseLogic
class DiceRewardConfigLogic extends DiceBaseLogic
{
/** weight 取值范围 */
private const WEIGHT_MIN = 1;
@@ -36,18 +38,23 @@ class DiceRewardConfigLogic extends BaseLogic
public function add(array $data): mixed
{
$result = parent::add($data);
DiceRewardConfig::refreshCache();
$deptId = AdminScopeHelper::normalizeRecordDeptId($data['dept_id'] ?? null);
DiceRewardConfig::refreshCache($deptId);
return $result;
}
/**
* 修改:保存后刷新缓存BIGWIN 的 weight 直接写入 dice_reward_config 表,抽奖时从 Config 读取
* 修改:按业务 id + 渠道更新;保存后刷新该渠道缓存
*/
public function edit($id, array $data): mixed
public function edit($id, array $data, ?array $adminInfo = null, $requestDeptId = null): mixed
{
$result = parent::edit($id, $data);
DiceRewardConfig::refreshCache();
return $result;
$deptId = AdminScopeHelper::resolveConfigDeptId(
$adminInfo,
AdminScopeHelper::pickRequestDeptId($requestDeptId, $data)
);
ConfigScopeEditHelper::updateByBusinessIdAndDept($this->model, (int) $id, $deptId, $data);
DiceRewardConfig::refreshCache($deptId);
return true;
}
/**
@@ -152,8 +159,9 @@ class DiceRewardConfigLogic extends BaseLogic
/**
* 批量更新奖励索引配置grid_number、ui_text、real_ev、tier、remark不含 weightBIGWIN 权重单独接口)
* @param array $items 每项 [id, grid_number?, ui_text?, real_ev?, tier?, remark?]
* @param int $deptId 渠道 ID0=默认模板)
*/
public function batchUpdate(array $items): void
public function batchUpdate(array $items, int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): void
{
foreach ($items as $row) {
if (! array_key_exists('id', $row) || $row['id'] === null || $row['id'] === '') {
@@ -167,10 +175,18 @@ class DiceRewardConfigLogic extends BaseLogic
}
}
if (! empty($data)) {
parent::edit($id, $data);
$this->updateByBusinessIdAndDept($id, $deptId, $data);
}
}
DiceRewardConfig::refreshCache();
DiceRewardConfig::refreshCache($deptId);
}
/**
* 按业务 id025与渠道更新单条配置
*/
private function updateByBusinessIdAndDept(int $businessId, int $deptId, array $data): void
{
ConfigScopeEditHelper::updateByBusinessIdAndDept($this->model, $businessId, $deptId, $data);
}
/**
@@ -201,8 +217,9 @@ class DiceRewardConfigLogic extends BaseLogic
/**
* 批量更新 BIGWIN 档位权重(仅写 dice_reward_config 表,不操作 dice_reward
* @param array $items 每项 [grid_number => 5-30, weight => 0-10000]
* @param int $deptId 渠道 ID0=默认模板)
*/
public function batchUpdateBigwinWeight(array $items): void
public function batchUpdateBigwinWeight(array $items, int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): void
{
$weightMin = 0;
$weightMax = 10000;
@@ -213,21 +230,33 @@ class DiceRewardConfigLogic extends BaseLogic
continue;
}
$weight = max($weightMin, min($weightMax, $weight));
$this->model->where('tier', 'BIGWIN')
->where('grid_number', $gridNumber)
->update(['weight' => $weight]);
$query = $this->model->where('tier', 'BIGWIN')->where('grid_number', $gridNumber);
if (AdminScopeHelper::isTemplateDeptId($deptId)) {
$query->where(function ($q) {
$q->where('dept_id', AdminScopeHelper::DEFAULT_TEMPLATE_DEPT)
->whereOr('dept_id', null);
});
} else {
$query->where('dept_id', $deptId);
}
$exists = (clone $query)->find();
if ($exists === null) {
throw new ApiException('BIGWIN grid_number=' . $gridNumber . ' not found for current channel');
}
$query->update(['weight' => $weight]);
}
DiceRewardConfig::refreshCache();
DiceRewardConfig::refreshCache($deptId);
}
/**
* 删除后刷新缓存
*/
public function destroy($ids): bool
public function destroy($ids, ?array $adminInfo = null, $requestDeptId = null): bool
{
$deptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $requestDeptId);
$result = parent::destroy($ids);
if ($result) {
DiceRewardConfig::refreshCache();
DiceRewardConfig::refreshCache($deptId);
}
return $result;
}
@@ -403,6 +432,12 @@ class DiceRewardConfigLogic extends BaseLogic
$record->lottery_config_id = $config ? (int) $config->id : null;
$record->result_counts = $counts;
$record->admin_id = $adminId;
if ($adminId > 0) {
$admin = \plugin\saiadmin\app\model\system\SystemUser::find($adminId);
if ($admin && !empty($admin->dept_id)) {
$record->dept_id = $admin->dept_id;
}
}
$record->create_time = date('Y-m-d H:i:s');
$record->save();
$recordId = (int) $record->id;

View File

@@ -4,12 +4,15 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\reward_config_record;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\api\util\ApiLang;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\ante_config\DiceAnteConfig;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\reward\DiceReward;
use app\dice\model\reward\DiceRewardConfig;
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
use plugin\saiadmin\basic\think\BaseLogic;
use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\app\model\system\SystemUser;
@@ -17,7 +20,7 @@ use plugin\saiadmin\app\model\system\SystemUser;
* 奖励配置权重测试记录逻辑层
*
*/
class DiceRewardConfigRecordLogic extends BaseLogic
class DiceRewardConfigRecordLogic extends DiceBaseLogic
{
public function __construct()
{
@@ -88,6 +91,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
throw new ApiException('Test record not found');
}
$record = is_array($record) ? $record : $record->toArray();
$configDeptId = AdminScopeHelper::normalizeRecordDeptId($record['dept_id'] ?? null);
$snapshot = $record['weight_config_snapshot'] ?? null;
if (is_string($snapshot)) {
@@ -112,9 +116,9 @@ class DiceRewardConfigRecordLogic extends BaseLogic
$tier = $tierFromDb !== null ? (string) $tierFromDb : '';
}
// 仅按方向 + 点数更新 DiceReward若存在则更新不存在才插入避免唯一键冲突
$reward = DiceReward::where('direction', $direction)
->where('grid_number', $gridNumber)
->find();
$rewardQuery = DiceReward::where('direction', $direction)->where('grid_number', $gridNumber);
ConfigScopeEditHelper::applyDeptIdWhere($rewardQuery, $configDeptId);
$reward = $rewardQuery->find();
if ($reward) {
$reward->weight = $weight;
// 若快照中有 tier补齐 tier 信息
@@ -130,10 +134,13 @@ class DiceRewardConfigRecordLogic extends BaseLogic
$m->direction = $direction;
$m->grid_number = $gridNumber;
$m->weight = $weight;
if (!AdminScopeHelper::isTemplateDeptId($configDeptId)) {
$m->dept_id = $configDeptId;
}
$m->save();
}
}
DiceReward::refreshCache();
DiceReward::refreshCache($configDeptId);
}
// 使用记录中的 bigwin_weight JSON 将 BIGWIN 概率导入到 DiceRewardConfig
@@ -152,11 +159,11 @@ class DiceRewardConfigRecordLogic extends BaseLogic
if ($weight < 0) {
$weight = 0;
}
DiceRewardConfig::where('tier', 'BIGWIN')
->where('grid_number', $gridNumber)
->update(['weight' => $weight]);
$bigwinQuery = DiceRewardConfig::where('tier', 'BIGWIN')->where('grid_number', $gridNumber);
ConfigScopeEditHelper::applyDeptIdWhere($bigwinQuery, $configDeptId);
$bigwinQuery->update(['weight' => $weight]);
}
DiceRewardConfig::refreshCache();
DiceRewardConfig::refreshCache($configDeptId);
}
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
@@ -225,7 +232,8 @@ class DiceRewardConfigRecordLogic extends BaseLogic
DiceLotteryPoolConfig::where('id', $freeTargetId)->update($update);
}
DiceRewardConfig::refreshCache();
DiceRewardConfig::refreshCache($configDeptId);
DiceReward::refreshCache($configDeptId);
DiceRewardConfig::clearRequestInstance();
}
@@ -237,8 +245,12 @@ class DiceRewardConfigRecordLogic extends BaseLogic
* @return int 记录 ID
* @throws ApiException
*/
public function createWeightTestRecord(array|int $params, mixed $adminIdOrFreeS = null, mixed $freeSOrFreeN = null, mixed $freeN = null): int
{
public function createWeightTestRecord(
array|int $params,
mixed $adminIdOrFreeS = null,
?array $adminInfo = null,
$requestDeptId = null
): int {
$adminId = null;
if (!is_array($params)) {
// 兼容旧版调用createWeightTestRecord(paid_s_count, paid_n_count)
@@ -249,15 +261,14 @@ class DiceRewardConfigRecordLogic extends BaseLogic
} else {
$adminId = $adminIdOrFreeS !== null && $adminIdOrFreeS !== '' ? (int) $adminIdOrFreeS : null;
}
$deptId = $this->resolveWeightTestDeptId(
$adminInfo,
AdminScopeHelper::pickRequestDeptId($requestDeptId, is_array($params) ? $params : []),
is_array($params) ? $params : []
);
$allowed = [100, 500, 1000, 5000];
$ante = isset($params['ante']) ? intval($params['ante']) : 1;
if ($ante <= 0) {
throw new ApiException('ante must be greater than 0');
}
$anteExists = DiceAnteConfig::where('mult', $ante)->count();
if ($anteExists <= 0) {
throw new ApiException('ante not allowed: ' . $ante);
}
$ante = $this->resolveWeightTestAnte($params, $deptId);
$lotteryConfigId = isset($params['lottery_config_id']) ? (int) $params['lottery_config_id'] : 0;
$paidConfigId = isset($params['paid_lottery_config_id']) ? (int) $params['paid_lottery_config_id'] : 0;
@@ -296,8 +307,8 @@ class DiceRewardConfigRecordLogic extends BaseLogic
$paidTierWeights = null;
$freeTierWeights = null;
// 来自 DiceReward 的当前权重快照(按方向+点数),用于权重测试模拟
$instance = DiceReward::getCachedInstance();
// 来自当前渠道的 DiceReward 权重快照(按方向+点数),用于权重测试模拟
$instance = DiceReward::getCachedInstance($deptId);
$byTierDirection = $instance['by_tier_direction'] ?? [];
foreach ($byTierDirection as $tier => $byDir) {
foreach ($byDir as $dir => $rows) {
@@ -316,7 +327,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
// BIGWIN 概率快照从 DiceRewardConfig 读取(例如豹子号配置)
// JSON 结构 {"grid_number": weight, ...}
$bigwinWeights = [];
$bigwinConfigs = DiceRewardConfig::getCachedByTier('BIGWIN');
$bigwinConfigs = DiceRewardConfig::getCachedByTier('BIGWIN', $deptId);
foreach ($bigwinConfigs as $cfg) {
$grid = isset($cfg['grid_number']) ? (int) $cfg['grid_number'] : 0;
if ($grid <= 0) {
@@ -327,10 +338,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
}
if ($paidConfigId > 0) {
$config = DiceLotteryPoolConfig::find($paidConfigId);
if (!$config) {
throw new ApiException('Paid pool config not found');
}
$config = $this->findPoolConfigInDept($paidConfigId, $deptId, 'Paid pool config not found');
$tierWeightsSnapshot['paid'] = [
'T1' => (int) ($config->t1_weight ?? 0),
'T2' => (int) ($config->t2_weight ?? 0),
@@ -359,10 +367,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
}
if ($freeConfigId > 0) {
$config = DiceLotteryPoolConfig::find($freeConfigId);
if (!$config) {
throw new ApiException('Free pool config not found');
}
$config = $this->findPoolConfigInDept($freeConfigId, $deptId, 'Free pool config not found');
$tierWeightsSnapshot['free'] = [
'T1' => (int) ($config->t1_weight ?? 0),
'T2' => (int) ($config->t2_weight ?? 0),
@@ -428,9 +433,94 @@ class DiceRewardConfigRecordLogic extends BaseLogic
$record->bigwin_weight = $bigwinWeights ?: null;
$record->ante = $ante;
$record->admin_id = $adminId;
$record->dept_id = $deptId;
$record->create_time = date('Y-m-d H:i:s');
$record->save();
return (int) $record->id;
}
/**
* 解析一键测试所属渠道:请求 dept_id > 奖池配置 dept_id > 渠道管理员本渠道
*/
private function resolveWeightTestDeptId(?array $adminInfo, $requestDeptId, array $params): int
{
$deptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $requestDeptId);
if (! AdminScopeHelper::isTemplateDeptId($deptId)) {
return $deptId;
}
foreach (['paid_lottery_config_id', 'free_lottery_config_id', 'lottery_config_id'] as $key) {
$poolId = isset($params[$key]) ? (int) $params[$key] : 0;
if ($poolId <= 0) {
continue;
}
$pool = DiceLotteryPoolConfig::find($poolId);
if (! $pool) {
continue;
}
$poolDeptId = AdminScopeHelper::normalizeRecordDeptId($pool->dept_id ?? null);
if (! AdminScopeHelper::isTemplateDeptId($poolDeptId)) {
return $poolDeptId;
}
}
$scopeDeptId = AdminScopeHelper::getDeptId($adminInfo);
if ($scopeDeptId !== null && $scopeDeptId > 0) {
return $scopeDeptId;
}
return $deptId;
}
/**
* 校验奖池配置属于当前渠道
*/
private function findPoolConfigInDept(int $poolId, int $deptId, string $notFoundMsg): DiceLotteryPoolConfig
{
$config = DiceLotteryPoolConfig::find($poolId);
if (!$config) {
throw new ApiException($notFoundMsg);
}
$poolDeptId = AdminScopeHelper::normalizeRecordDeptId($config->dept_id ?? null);
if ($poolDeptId !== $deptId) {
throw new ApiException('POOL_CONFIG_NOT_IN_CHANNEL');
}
return $config;
}
/**
* 解析一键测试底注:优先 ante_config_id否则按 mult + 渠道校验
*/
private function resolveWeightTestAnte(array $params, int $deptId): int
{
$anteConfigId = isset($params['ante_config_id']) ? (int) $params['ante_config_id'] : 0;
if ($anteConfigId > 0) {
$config = DiceAnteConfig::find($anteConfigId);
if (! $config) {
throw new ApiException('ANTE_CONFIG_NOT_FOUND');
}
$configDeptId = AdminScopeHelper::normalizeRecordDeptId($config->dept_id ?? null);
if ($configDeptId !== $deptId) {
throw new ApiException('ANTE_CONFIG_NOT_IN_CHANNEL');
}
$mult = (int) ($config->mult ?? 0);
if ($mult <= 0) {
throw new ApiException('ANTE_MUST_POSITIVE');
}
return $mult;
}
$ante = isset($params['ante']) ? (int) $params['ante'] : 0;
if ($ante <= 0) {
throw new ApiException('ANTE_MUST_POSITIVE');
}
$anteQuery = DiceAnteConfig::where('mult', $ante);
ConfigScopeEditHelper::applyDeptIdWhere($anteQuery, $deptId);
if ($anteQuery->count() <= 0) {
throw new ApiException(ApiLang::translateParams('ANTE_NOT_ALLOWED', [$ante]));
}
return $ante;
}
}

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace app\dice\logic\reward_config_record;
use app\api\logic\PlayStartLogic;
use app\dice\helper\AdminScopeHelper;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\play_record_test\DicePlayRecordTest;
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
@@ -19,9 +20,13 @@ use support\think\Db;
class WeightTestRunner
{
private const BATCH_SIZE = 10;
/** 本次测试所属渠道(与 dice_reward_config_record.dept_id 一致) */
private int $runDeptId = 0;
/** 测试记录写库白名单字段 */
private const PLAY_RECORD_TEST_COLUMNS = [
'reward_config_record_id',
'dept_id',
'admin_id',
'lottery_config_id',
'lottery_type',
@@ -61,10 +66,15 @@ class WeightTestRunner
return;
}
$configType0 = DiceLotteryPoolConfig::where('name', 'default')->find();
$configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->find();
$this->runDeptId = $this->resolveRunDeptId($recordId, $record);
$deptId = $this->runDeptId;
DiceReward::setRequestDeptId($deptId);
DiceRewardConfig::clearRequestInstance();
$configType0 = DiceLotteryPoolConfig::findByNameForDept('default', $deptId);
$configType1 = DiceLotteryPoolConfig::findByNameForDept('killScore', $deptId);
if (!$configType0) {
$this->markFailed($recordId, '彩金池配置 name=default 不存在');
$this->markFailed($recordId, '彩金池配置 name=default 不存在(当前渠道)');
return;
}
@@ -79,12 +89,12 @@ class WeightTestRunner
$freePoolConfigId = (int) ($record->free_lottery_config_id ?? 0);
$paidPoolConfig = $paidPoolConfigId > 0 ? DiceLotteryPoolConfig::find($paidPoolConfigId) : $configType0;
if (!$paidPoolConfig) {
if (!$paidPoolConfig || AdminScopeHelper::normalizeRecordDeptId($paidPoolConfig->dept_id ?? null) !== $deptId) {
$paidPoolConfig = $configType0;
}
$freePoolConfig = $freePoolConfigId > 0 ? DiceLotteryPoolConfig::find($freePoolConfigId) : $configType1;
if (!$freePoolConfig) {
$freePoolConfig = $configType0;
if (!$freePoolConfig || AdminScopeHelper::normalizeRecordDeptId($freePoolConfig->dept_id ?? null) !== $deptId) {
$freePoolConfig = $configType1 ?: $configType0;
}
if ($paidTierWeightsCustom !== null && array_sum($paidTierWeightsCustom) <= 0) {
@@ -118,6 +128,7 @@ class WeightTestRunner
try {
$this->runChainFreeMode(
$recordId,
$deptId,
$playLogic,
$paidS,
$paidN,
@@ -145,6 +156,9 @@ class WeightTestRunner
} catch (\Throwable $e) {
Log::error('WeightTestRunner exception: ' . $e->getMessage(), ['record_id' => $recordId, 'trace' => $e->getTraceAsString()]);
$this->markFailed($recordId, $e->getMessage());
} finally {
DiceReward::clearRequestInstance();
DiceRewardConfig::clearRequestInstance();
}
}
@@ -153,6 +167,7 @@ class WeightTestRunner
*/
private function runChainFreeMode(
int $recordId,
int $deptId,
PlayStartLogic $playLogic,
int $paidS,
int $paidN,
@@ -199,12 +214,12 @@ class WeightTestRunner
$customWeights = $freeTierWeightsCustom;
}
$row = $playLogic->simulateOnePlay($cfg, $dir, $lotteryType, $playAnte, $customWeights);
$row = $playLogic->simulateOnePlay($cfg, $dir, $lotteryType, $playAnte, $customWeights, $deptId);
$winCoin = (float) ($row['win_coin'] ?? 0);
$paidAmount = (float) ($row['paid_amount'] ?? 0);
$playerProfitTotal += $winCoin - $paidAmount;
$this->aggregate($row, $resultCounts, $tierCounts);
$buffer[] = $this->rowForInsert($row, $recordId);
$buffer[] = $this->rowForInsert($row, $recordId, $deptId);
$done++;
if (!empty($row['grants_free_ticket'])) {
@@ -217,6 +232,58 @@ class WeightTestRunner
}
}
/**
* 解析本次测试渠道:优先读库字段,避免 ORM 字段缓存未含 dept_id 时读不到
*/
private function resolveRunDeptId(int $recordId, DiceRewardConfigRecord $record): int
{
$recordTable = (new DiceRewardConfigRecord())->getTable();
$fromDb = Db::table($recordTable)->where('id', $recordId)->value('dept_id');
$deptId = AdminScopeHelper::normalizeRecordDeptId($fromDb);
if (! AdminScopeHelper::isTemplateDeptId($deptId)) {
return $deptId;
}
$deptId = AdminScopeHelper::normalizeRecordDeptId($record->dept_id ?? null);
if (! AdminScopeHelper::isTemplateDeptId($deptId)) {
return $deptId;
}
return $this->resolveDeptIdFromRecordPools($record, $deptId);
}
/**
* 历史记录 dept_id=0 时,从关联奖池配置反推并回写
*/
private function resolveDeptIdFromRecordPools(DiceRewardConfigRecord $record, int $fallbackDeptId): int
{
foreach (
[
(int) ($record->paid_lottery_config_id ?? 0),
(int) ($record->free_lottery_config_id ?? 0),
(int) ($record->lottery_config_id ?? 0),
] as $poolId
) {
if ($poolId <= 0) {
continue;
}
$pool = DiceLotteryPoolConfig::find($poolId);
if (! $pool) {
continue;
}
$poolDeptId = AdminScopeHelper::normalizeRecordDeptId($pool->dept_id ?? null);
if (! AdminScopeHelper::isTemplateDeptId($poolDeptId)) {
if (AdminScopeHelper::normalizeRecordDeptId($record->dept_id ?? null) !== $poolDeptId) {
$record->dept_id = $poolDeptId;
$record->save();
}
return $poolDeptId;
}
}
return $fallbackDeptId;
}
private function aggregate(array $row, array &$resultCounts, array &$tierCounts): void
{
$grid = (int) ($row['roll_number_for_count'] ?? $row['roll_number'] ?? 0);
@@ -229,10 +296,14 @@ class WeightTestRunner
}
}
private function rowForInsert(array $row, int $rewardConfigRecordId): array
private function rowForInsert(array $row, int $rewardConfigRecordId, int $deptId): array
{
$bindDeptId = ! AdminScopeHelper::isTemplateDeptId($this->runDeptId)
? $this->runDeptId
: $deptId;
$out = [
'reward_config_record_id' => $rewardConfigRecordId,
'dept_id' => $bindDeptId,
];
$keys = [
'admin_id', 'lottery_config_id', 'lottery_type', 'is_win', 'win_coin',
@@ -254,7 +325,7 @@ class WeightTestRunner
return;
}
$this->insertBuffer($buffer);
$buffer = [];
array_splice($buffer, 0, count($buffer));
$this->updateProgress($recordId, $done, $resultCounts, $tierCounts, $recordTotalPlayCount);
}
@@ -263,6 +334,7 @@ class WeightTestRunner
if (empty($rows)) {
return;
}
$table = (new DicePlayRecordTest())->getTable();
foreach ($rows as $row) {
if (!is_array($row)) {
continue;
@@ -273,6 +345,9 @@ class WeightTestRunner
$payload[$column] = $row[$column];
}
}
if (! AdminScopeHelper::isTemplateDeptId($this->runDeptId)) {
$payload['dept_id'] = $this->runDeptId;
}
if (!array_key_exists('create_time', $payload) || $payload['create_time'] === null || $payload['create_time'] === '') {
$payload['create_time'] = date('Y-m-d H:i:s');
}
@@ -282,10 +357,26 @@ class WeightTestRunner
if ($payload === []) {
continue;
}
Db::name((new DicePlayRecordTest())->getTable())->insert($payload);
// strict(false):表结构新增 dept_id 后,避免连接层字段缓存未刷新导致插入被丢弃
Db::table($table)->strict(false)->insert($payload);
}
}
/**
* 将本批测试明细 dept_id 与主记录对齐(修复历史 worker 未写入 dept_id 的情况)
*/
private function syncPlayRecordTestDeptId(int $recordId, int $deptId): void
{
if (AdminScopeHelper::isTemplateDeptId($deptId)) {
return;
}
DicePlayRecordTest::where('reward_config_record_id', $recordId)
->where(function ($query) {
$query->whereNull('dept_id')->whereOr('dept_id', AdminScopeHelper::DEFAULT_TEMPLATE_DEPT);
})
->update(['dept_id' => $deptId]);
}
private function updateProgress(int $recordId, int $overPlayCount, array $resultCounts, array $tierCounts, ?int $totalPlayCount = null): void
{
$record = DiceRewardConfigRecord::find($recordId);
@@ -308,6 +399,13 @@ class WeightTestRunner
{
$record = DiceRewardConfigRecord::find($recordId);
if ($record) {
$deptId = AdminScopeHelper::normalizeRecordDeptId($record->dept_id ?? null);
if (AdminScopeHelper::isTemplateDeptId($deptId) && ! AdminScopeHelper::isTemplateDeptId($this->runDeptId)) {
$deptId = $this->runDeptId;
$record->dept_id = $deptId;
}
$this->syncPlayRecordTestDeptId($recordId, $deptId);
// 平台盈利通过关联测试记录统计
$platformProfit = DiceRewardConfigRecord::computePlatformProfitFromRelated($recordId);
// 落点统计也通过关联测试记录重新统计,避免模拟过程异常导致为空

View File

@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace app\dice\model;
use plugin\saiadmin\basic\think\BaseModel as SaiBaseModel;
/**
* 大富翁模块模型基类:删除均为硬删除(物理删除)
*/
abstract class DiceModel extends SaiBaseModel
{
/**
* @param mixed $data
*/
public static function destroy($data, bool $force = true): bool
{
return parent::destroy($data, true);
}
public function delete(): bool
{
return $this->force()->delete();
}
}

View File

@@ -6,7 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\model\ante_config;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\model\DiceModel;
/**
* 底注配置模型
@@ -19,7 +19,7 @@ use plugin\saiadmin\basic\think\BaseModel;
* @property string $create_time 创建时间
* @property string $update_time 更新时间
*/
class DiceAnteConfig extends BaseModel
class DiceAnteConfig extends DiceModel
{
protected $pk = 'id';

View File

@@ -6,7 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\model\config;
use plugin\saiadmin\basic\eloquent\BaseModel;
use app\dice\model\DiceModel;
/**
* 摇色子配置模型
@@ -23,7 +23,7 @@ use plugin\saiadmin\basic\eloquent\BaseModel;
* @property $create_time 创建时间
* @property $update_time 修改时间
*/
class DiceConfig extends BaseModel
class DiceConfig extends DiceModel
{
/**
* 数据表主键

View File

@@ -4,14 +4,14 @@
// +----------------------------------------------------------------------
namespace app\dice\model\game;
use plugin\saiadmin\basic\eloquent\BaseModel;
use app\dice\model\DiceModel;
/**
* 游戏管理模型
*
* dice_game 游戏配置表
*/
class DiceGame extends BaseModel
class DiceGame extends DiceModel
{
protected $primaryKey = 'id';

View File

@@ -6,7 +6,9 @@
// +----------------------------------------------------------------------
namespace app\dice\model\lottery_pool_config;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\DiceModel;
/**
* 色子奖池配置模型
@@ -27,7 +29,7 @@ use plugin\saiadmin\basic\think\BaseModel;
* @property $t5_weight T5池权重
* @property $profit_amount 池子累计盈利(每局付费按 win_coin-paid_amount免费按 win_coin 累加;仅展示不可编辑)
*/
class DiceLotteryPoolConfig extends BaseModel
class DiceLotteryPoolConfig extends DiceModel
{
/**
* 数据表主键
@@ -41,6 +43,16 @@ class DiceLotteryPoolConfig extends BaseModel
*/
protected $table = 'dice_lottery_pool_config';
/**
* 按名称与渠道查找奖池配置(一键测试等场景,避免命中其他渠道同名配置)
*/
public static function findByNameForDept(string $name, int $deptId): ?self
{
$query = (new self())->where('name', $name);
ConfigScopeEditHelper::applyDeptIdWhere($query, AdminScopeHelper::normalizeRecordDeptId($deptId));
return $query->find();
}
/**
* 名称 搜索
*/

View File

@@ -9,7 +9,7 @@ namespace app\dice\model\play_record;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\player\DicePlayer;
use app\dice\model\reward\DiceRewardConfig;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\model\DiceModel;
use think\model\relation\BelongsTo;
/**
@@ -41,7 +41,7 @@ use think\model\relation\BelongsTo;
* @property $create_time 创建时间
* @property $update_time 修改时间
*/
class DicePlayRecord extends BaseModel
class DicePlayRecord extends DiceModel
{
/**
* 数据表主键

View File

@@ -6,7 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\model\play_record_test;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\model\DiceModel;
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use think\model\relation\BelongsTo;
@@ -37,7 +37,7 @@ use think\model\relation\BelongsTo;
* @property $admin_id 所属管理员
* @property int|null $reward_config_record_id 关联 DiceRewardConfigRecord.id权重测试记录
*/
class DicePlayRecordTest extends BaseModel
class DicePlayRecordTest extends DiceModel
{
/**
* 数据表主键

View File

@@ -6,7 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\model\player;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\model\DiceModel;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
/**
@@ -15,7 +15,8 @@ use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
* dice_player 大富翁-玩家
*
* @property $id ID
* @property $username 用户名
* @property $dept_id 所属渠道ID
* @property $username 用户名(同渠道内唯一)
* @property $phone 手机
* @property $uid uid
* @property $name 昵称
@@ -37,7 +38,7 @@ use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
* @property $update_time 更新时间
* @property $delete_time 删除时间
*/
class DicePlayer extends BaseModel
class DicePlayer extends DiceModel
{
/**
* 数据表主键

View File

@@ -7,7 +7,7 @@
namespace app\dice\model\player_ticket_record;
use app\dice\model\player\DicePlayer;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\model\DiceModel;
use think\model\relation\BelongsTo;
/**
@@ -27,7 +27,7 @@ use think\model\relation\BelongsTo;
* @property $create_time 创建时间
* @property $update_time 修改时间
*/
class DicePlayerTicketRecord extends BaseModel
class DicePlayerTicketRecord extends DiceModel
{
/**
* 数据表主键

View File

@@ -7,7 +7,7 @@
namespace app\dice\model\player_wallet_record;
use app\dice\model\player\DicePlayer;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\model\DiceModel;
use plugin\saiadmin\app\model\system\SystemUser;
use think\model\relation\BelongsTo;
@@ -31,7 +31,7 @@ use think\model\relation\BelongsTo;
* @property $create_time 创建时间
* @property $update_time 修改时间
*/
class DicePlayerWalletRecord extends BaseModel
class DicePlayerWalletRecord extends DiceModel
{
/**
* 数据表主键

View File

@@ -4,7 +4,9 @@
// +----------------------------------------------------------------------
namespace app\dice\model\reward;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\DiceModel;
use support\think\Cache;
/**
@@ -25,42 +27,70 @@ use support\think\Cache;
* @property $remark 备注(来自config)
* @property $type 奖励类型(来自config)
*/
class DiceReward extends BaseModel
class DiceReward extends DiceModel
{
/** 方向:顺时针 */
public const DIRECTION_CLOCKWISE = 0;
/** 方向:逆时针 */
public const DIRECTION_COUNTERCLOCKWISE = 1;
/** 缓存键:奖励对照实例 */
/** 缓存键前缀:奖励对照实例(按渠道分键) */
private const CACHE_KEY_INSTANCE = 'dice:reward:instance';
private const CACHE_TTL = 86400 * 30;
private static ?array $instance = null;
private static ?int $requestDeptId = null;
protected $table = 'dice_reward';
/** 主键 id 自增,唯一约束 (direction, grid_number) */
protected $pk = 'id';
private static function cacheKeyForDept(int $deptId): string
{
return self::CACHE_KEY_INSTANCE . ':' . $deptId;
}
private static function resolveDeptId(?int $deptId): int
{
if ($deptId !== null) {
return AdminScopeHelper::normalizeRecordDeptId($deptId);
}
if (self::$requestDeptId !== null) {
return self::$requestDeptId;
}
return AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
}
/**
* 请求级设置当前渠道(一键测试 worker 内调用 simulateOnePlay 前设置)
*/
public static function setRequestDeptId(?int $deptId): void
{
self::$requestDeptId = $deptId !== null
? AdminScopeHelper::normalizeRecordDeptId($deptId)
: null;
}
/**
* 获取奖励对照实例(按档位+方向索引,用于抽奖与权重配比)
* 优先从共享缓存读取,保证多进程(如一键测试 worker与数据库一致
* @return array{list: array, by_tier_direction: array}
*/
public static function getCachedInstance(): array
public static function getCachedInstance(?int $deptId = null): array
{
$instance = Cache::get(self::CACHE_KEY_INSTANCE);
$deptId = self::resolveDeptId($deptId);
$cacheKey = self::cacheKeyForDept($deptId);
$instance = Cache::get($cacheKey);
if ($instance !== null && is_array($instance)) {
self::$instance = $instance;
return $instance;
}
if (self::$instance !== null) {
if (self::$instance !== null && self::$requestDeptId === $deptId) {
return self::$instance;
}
self::refreshCache();
$instance = Cache::get(self::CACHE_KEY_INSTANCE);
self::refreshCache($deptId);
$instance = Cache::get($cacheKey);
self::$instance = is_array($instance) ? $instance : self::buildEmptyInstance();
return self::$instance;
}
@@ -69,9 +99,9 @@ class DiceReward extends BaseModel
* 按档位+方向取权重列表(用于抽奖:该档位该方向下 end_index => weight
* @return array<int, int> end_index => weight
*/
public static function getCachedByTierAndDirection(string $tier, int $direction): array
public static function getCachedByTierAndDirection(string $tier, int $direction, ?int $deptId = null): array
{
$inst = self::getCachedInstance();
$inst = self::getCachedInstance($deptId);
$byTierDirection = $inst['by_tier_direction'] ?? [];
$list = $byTierDirection[$tier][$direction] ?? [];
$result = [];
@@ -84,11 +114,14 @@ class DiceReward extends BaseModel
}
/**
* 重新从数据库加载并写入缓存;修改/新增/删除后需调用以实例化
* 按渠道从数据库加载并写入缓存
*/
public static function refreshCache(): void
public static function refreshCache(?int $deptId = null): void
{
$list = (new self())->order('tier')->order('direction')->order('end_index')->select()->toArray();
$deptId = self::resolveDeptId($deptId);
$query = (new self())->order('tier')->order('direction')->order('end_index');
ConfigScopeEditHelper::applyDeptIdWhere($query, $deptId);
$list = $query->select()->toArray();
$byTierDirection = [];
foreach ($list as $row) {
$tier = isset($row['tier']) ? (string) $row['tier'] : '';
@@ -103,11 +136,12 @@ class DiceReward extends BaseModel
$byTierDirection[$tier][$direction][] = $row;
}
}
self::$instance = [
$instance = [
'list' => $list,
'by_tier_direction' => $byTierDirection,
];
Cache::set(self::CACHE_KEY_INSTANCE, self::$instance, self::CACHE_TTL);
self::$instance = $instance;
Cache::set(self::cacheKeyForDept($deptId), $instance, self::CACHE_TTL);
}
private static function buildEmptyInstance(): array
@@ -121,20 +155,29 @@ class DiceReward extends BaseModel
public static function clearRequestInstance(): void
{
self::$instance = null;
self::$requestDeptId = null;
}
private static function refreshCacheForModel($model): void
{
$deptId = AdminScopeHelper::normalizeRecordDeptId(
is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null)
);
self::refreshCache($deptId);
}
public static function onAfterInsert($model): void
{
self::refreshCache();
self::refreshCacheForModel($model);
}
public static function onAfterUpdate($model): void
{
self::refreshCache();
self::refreshCacheForModel($model);
}
public static function onAfterDelete($model): void
{
self::refreshCache();
self::refreshCacheForModel($model);
}
}

View File

@@ -6,8 +6,10 @@
// +----------------------------------------------------------------------
namespace app\dice\model\reward_config;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\reward\DiceReward;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\model\DiceModel;
use support\think\Cache;
/**
@@ -27,7 +29,7 @@ use support\think\Cache;
* @property $create_time 创建时间
* @property $update_time 修改时间
*/
class DiceRewardConfig extends BaseModel
class DiceRewardConfig extends DiceModel
{
/** 缓存键:彩金池奖励列表实例 */
private const CACHE_KEY_INSTANCE = 'dice:reward_config:instance';
@@ -45,31 +47,35 @@ class DiceRewardConfig extends BaseModel
* 优先从共享缓存读取,保证多进程(如一键测试 worker能拿到最新配置与数据库一致
* @return array{list: array, by_tier: array, by_tier_grid: array, min_real_ev: float}
*/
public static function getCachedInstance(): array
public static function getCachedInstance(?int $deptId = null): array
{
$instance = Cache::get(self::CACHE_KEY_INSTANCE);
if ($deptId === null) {
$deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
}
$cacheKey = self::cacheKeyForDept($deptId);
$instance = Cache::get($cacheKey);
if ($instance !== null && is_array($instance)) {
self::$instance = $instance;
return $instance;
}
if (self::$instance !== null) {
return self::$instance;
}
self::refreshCache();
$instance = Cache::get(self::CACHE_KEY_INSTANCE);
self::$instance = is_array($instance) ? $instance : self::buildEmptyInstance();
return self::$instance;
self::refreshCache($deptId);
$instance = Cache::get($cacheKey);
return is_array($instance) ? $instance : self::buildEmptyInstance();
}
public static function getCachedList(): array
private static function cacheKeyForDept(int $deptId): string
{
$inst = self::getCachedInstance();
return self::CACHE_KEY_INSTANCE . ':' . $deptId;
}
public static function getCachedList(?int $deptId = null): array
{
$inst = self::getCachedInstance($deptId);
return $inst['list'] ?? [];
}
public static function getCachedById(int $id): ?array
public static function getCachedById(int $id, ?int $deptId = null): ?array
{
$list = self::getCachedList();
$list = self::getCachedList($deptId);
foreach ($list as $row) {
if (isset($row['id']) && (int) $row['id'] === $id) {
return $row;
@@ -79,11 +85,16 @@ class DiceRewardConfig extends BaseModel
}
/**
* 重新从数据库加载并写入缓存(按档位+权重抽 grid_number含 by_tier、by_tier_grid
* 按渠道从数据库加载并写入缓存(避免多渠道配置混在同一缓存键
*/
public static function refreshCache(): void
public static function refreshCache(?int $deptId = null): void
{
$list = (new self())->order('id', 'asc')->select()->toArray();
if ($deptId === null) {
$deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
}
$query = (new self())->order('id', 'asc');
ConfigScopeEditHelper::applyDeptIdWhere($query, $deptId);
$list = $query->select()->toArray();
$byTier = [];
$byTierGrid = [];
foreach ($list as $row) {
@@ -103,13 +114,16 @@ class DiceRewardConfig extends BaseModel
}
}
$minRealEv = empty($list) ? 0.0 : (float) min(array_column($list, 'real_ev'));
self::$instance = [
$instance = [
'list' => $list,
'by_tier' => $byTier,
'by_tier_grid' => $byTierGrid,
'min_real_ev' => $minRealEv,
];
Cache::set(self::CACHE_KEY_INSTANCE, self::$instance, self::CACHE_TTL);
Cache::set(self::cacheKeyForDept($deptId), $instance, self::CACHE_TTL);
if ($deptId === AdminScopeHelper::DEFAULT_TEMPLATE_DEPT) {
self::$instance = $instance;
}
}
private static function buildEmptyInstance(): array
@@ -125,9 +139,9 @@ class DiceRewardConfig extends BaseModel
/**
* 按档位+色子点数取一条(用于 BIGWIN
*/
public static function getCachedByTierAndGridNumber(string $tier, int $gridNumber): ?array
public static function getCachedByTierAndGridNumber(string $tier, int $gridNumber, ?int $deptId = null): ?array
{
$inst = self::getCachedInstance();
$inst = self::getCachedInstance($deptId);
$byTierGrid = $inst['by_tier_grid'] ?? [];
$tierData = $byTierGrid[$tier] ?? [];
$row = $tierData[$gridNumber] ?? null;
@@ -143,9 +157,9 @@ class DiceRewardConfig extends BaseModel
/**
* 从缓存按档位取奖励列表(不含权重,仅配置)
*/
public static function getCachedByTier(string $tier): array
public static function getCachedByTier(string $tier, ?int $deptId = null): array
{
$inst = self::getCachedInstance();
$inst = self::getCachedInstance($deptId);
$byTier = $inst['by_tier'] ?? [];
return $byTier[$tier] ?? [];
}
@@ -155,10 +169,10 @@ class DiceRewardConfig extends BaseModel
* @param int $direction 0=顺时针, 1=逆时针
* @return array 每行含 id, grid_number, real_ev, tier, weight 等
*/
public static function getCachedByTierForDirection(string $tier, int $direction): array
public static function getCachedByTierForDirection(string $tier, int $direction, ?int $deptId = null): array
{
$list = self::getCachedByTier($tier);
$weightMap = DiceReward::getCachedByTierAndDirection($tier, $direction);
$list = self::getCachedByTier($tier, $deptId);
$weightMap = DiceReward::getCachedByTierAndDirection($tier, $direction, $deptId);
foreach ($list as $i => $row) {
$id = isset($row['id']) ? (int) $row['id'] : 0;
$list[$i]['weight'] = $weightMap[$id] ?? 1;
@@ -171,19 +185,27 @@ class DiceRewardConfig extends BaseModel
self::$instance = null;
}
private static function refreshCacheForModel($model): void
{
$deptId = AdminScopeHelper::normalizeRecordDeptId(
is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null)
);
self::refreshCache($deptId);
}
public static function onAfterInsert($model): void
{
self::refreshCache();
self::refreshCacheForModel($model);
}
public static function onAfterUpdate($model): void
{
self::refreshCache();
self::refreshCacheForModel($model);
}
public static function onAfterDelete($model): void
{
self::refreshCache();
self::refreshCacheForModel($model);
}
public function searchGridNumberMinAttr($query, $value)

View File

@@ -4,7 +4,7 @@
// +----------------------------------------------------------------------
namespace app\dice\model\reward_config;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\model\DiceModel;
/**
* 权重配比测试记录模型
@@ -20,7 +20,7 @@ use plugin\saiadmin\basic\think\BaseModel;
* @property int|null $admin_id 执行测试的管理员ID
* @property string|null $create_time 创建时间
*/
class DiceRewardConfigRecord extends BaseModel
class DiceRewardConfigRecord extends DiceModel
{
protected $pk = 'id';

View File

@@ -7,7 +7,7 @@
namespace app\dice\model\reward_config_record;
use app\dice\model\play_record_test\DicePlayRecordTest;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\model\DiceModel;
use think\model\relation\HasMany;
/**
@@ -43,7 +43,7 @@ use think\model\relation\HasMany;
* @property int|null $admin_id 执行测试的管理员ID
* @property string|null $create_time 创建时间
*/
class DiceRewardConfigRecord extends BaseModel
class DiceRewardConfigRecord extends DiceModel
{
/** 状态:失败 */
public const STATUS_FAIL = -1;

View File

@@ -0,0 +1,497 @@
<?php
declare(strict_types=1);
namespace app\dice\service;
use app\dice\helper\AdminScopeHelper;
use app\dice\logic\reward\DiceRewardLogic;
use app\dice\model\reward\DiceReward;
use app\dice\model\reward_config\DiceRewardConfig;
use plugin\saiadmin\app\model\system\SystemDept;
use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\exception\ApiException;
use support\think\Db;
/**
* 渠道默认配置复制、补齐与关联删除
* 默认配置dept_id = 0与超管「默认配置模板」一致
*/
class DiceChannelConfigService
{
/** 需 (dept_id, id) 复合唯一的配置表 */
private const COMPOSITE_KEY_TABLES = [
'dice_config',
'dice_reward_config',
];
/** 从默认模板复制的配置表 */
private const CONFIG_TABLES = [
'dice_config',
'dice_ante_config',
'dice_lottery_pool_config',
'dice_reward_config',
'dice_game',
];
/** 复制时必须保留主键 id非自增或固定 0-25 */
private const TABLES_KEEP_ID = [
'dice_config',
'dice_reward_config',
];
/** 可关联删除的业务表 */
private const RELATION_TABLES = [
'dice_config' => ['label' => '游戏键值配置', 'group' => 'configs'],
'dice_ante_config' => ['label' => '底注配置', 'group' => 'configs'],
'dice_lottery_pool_config' => ['label' => '彩金池配置', 'group' => 'configs'],
'dice_reward_config' => ['label' => '奖励索引配置', 'group' => 'configs'],
'dice_reward' => ['label' => '中奖概率(奖励对照)', 'group' => 'configs'],
'dice_game' => ['label' => '游戏管理', 'group' => 'configs'],
'dice_player' => ['label' => '玩家', 'group' => 'players'],
'dice_play_record' => ['label' => '抽奖记录', 'group' => 'records'],
'dice_play_record_test' => ['label' => '测试抽奖记录', 'group' => 'records'],
'dice_player_wallet_record' => ['label' => '钱包流水', 'group' => 'records'],
'dice_player_ticket_record' => ['label' => '票券记录', 'group' => 'records'],
'dice_reward_config_record' => ['label' => '权重测试记录', 'group' => 'records'],
];
/**
* 默认模板 dept_id 统一为 0并为固定 id 的配置表建立 (dept_id, id) 唯一约束
*/
public function ensureConfigCompositeKeys(): void
{
foreach (array_merge(self::CONFIG_TABLES, ['dice_reward']) as $table) {
if ($this->tableHasColumn($table, 'dept_id')) {
Db::table($table)->whereNull('dept_id')->update(['dept_id' => AdminScopeHelper::DEFAULT_TEMPLATE_DEPT]);
}
}
foreach (self::COMPOSITE_KEY_TABLES as $table) {
if (!$this->tableHasColumn($table, 'dept_id')) {
continue;
}
if (!$this->tableHasColumn($table, 'row_id')) {
if ($table === 'dice_reward_config') {
Db::execute(
'ALTER TABLE `dice_reward_config`'
. ' MODIFY `id` int(11) NOT NULL COMMENT \'ID\','
. ' ADD COLUMN `row_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT FIRST,'
. ' DROP PRIMARY KEY,'
. ' ADD PRIMARY KEY (`row_id`)'
);
} else {
Db::execute(
'ALTER TABLE `dice_config`'
. ' ADD COLUMN `row_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT FIRST,'
. ' DROP PRIMARY KEY,'
. ' ADD PRIMARY KEY (`row_id`)'
);
}
}
$indexes = Db::query("SHOW INDEX FROM `{$table}` WHERE Key_name = 'uk_dept_config'");
if (empty($indexes)) {
Db::execute("ALTER TABLE `{$table}` ADD UNIQUE KEY `uk_dept_config` (`dept_id`, `id`)");
}
}
$this->ensureDeptScopedUniqueIndexes();
}
/**
* 将全局唯一键改为按渠道 (dept_id, 业务键) 唯一,便于复制默认模板
*/
private function ensureDeptScopedUniqueIndexes(): void
{
if ($this->tableHasColumn('dice_lottery_pool_config', 'dept_id')) {
$old = Db::query("SHOW INDEX FROM `dice_lottery_pool_config` WHERE Key_name = 'dice_lottery_poll_config_unique'");
if (!empty($old)) {
Db::execute('ALTER TABLE `dice_lottery_pool_config` DROP INDEX `dice_lottery_poll_config_unique`');
}
$uk = Db::query("SHOW INDEX FROM `dice_lottery_pool_config` WHERE Key_name = 'uk_dept_name'");
if (empty($uk)) {
Db::execute('ALTER TABLE `dice_lottery_pool_config` ADD UNIQUE KEY `uk_dept_name` (`dept_id`, `name`)');
}
}
if ($this->tableHasColumn('dice_game', 'dept_id')) {
foreach (['uk_dice_game_code', 'uk_dice_game_key'] as $idx) {
$exists = Db::query("SHOW INDEX FROM `dice_game` WHERE Key_name = '{$idx}'");
if (!empty($exists)) {
Db::execute("ALTER TABLE `dice_game` DROP INDEX `{$idx}`");
}
}
$ukCode = Db::query("SHOW INDEX FROM `dice_game` WHERE Key_name = 'uk_dept_game_code'");
if (empty($ukCode)) {
Db::execute('ALTER TABLE `dice_game` ADD UNIQUE KEY `uk_dept_game_code` (`dept_id`, `game_code`)');
}
$ukKey = Db::query("SHOW INDEX FROM `dice_game` WHERE Key_name = 'uk_dept_game_key'");
if (empty($ukKey)) {
Db::execute('ALTER TABLE `dice_game` ADD UNIQUE KEY `uk_dept_game_key` (`dept_id`, `game_key`)');
}
}
if ($this->tableHasColumn('dice_reward', 'dept_id')) {
$old = Db::query("SHOW INDEX FROM `dice_reward` WHERE Key_name = 'uk_direction_grid_number'");
if (!empty($old)) {
Db::execute('ALTER TABLE `dice_reward` DROP INDEX `uk_direction_grid_number`');
}
$uk = Db::query("SHOW INDEX FROM `dice_reward` WHERE Key_name = 'uk_dept_direction_grid'");
if (empty($uk)) {
Db::execute('ALTER TABLE `dice_reward` ADD UNIQUE KEY `uk_dept_direction_grid` (`dept_id`, `direction`, `grid_number`)');
}
}
}
/**
* 将当前无 dept_id 的配置标记为默认模板(仅执行一次迁移)
*/
public function markLegacyConfigAsDefault(): int
{
$this->ensureConfigCompositeKeys();
$total = 0;
foreach (self::CONFIG_TABLES as $table) {
if (!$this->tableHasColumn($table, 'dept_id')) {
continue;
}
$total += $this->countByDept($table, AdminScopeHelper::DEFAULT_TEMPLATE_DEPT);
}
return $total;
}
/**
* 为单个渠道从默认模板复制配置(已存在则跳过)
*/
public function copyDefaultConfigToDept(int $deptId): array
{
if ($deptId <= 0) {
throw new ApiException('Invalid channel id');
}
$result = ['dept_id' => $deptId, 'copied' => [], 'skipped' => [], 'merged' => []];
foreach (self::CONFIG_TABLES as $table) {
if (!$this->tableHasColumn($table, 'dept_id')) {
continue;
}
if (in_array($table, self::TABLES_KEEP_ID, true)) {
$merged = $this->syncCompositeIdTableFromDefault($table, $deptId);
if ($merged > 0) {
$result['merged'][$table] = $merged;
} elseif ($this->countByDept($table, $deptId) > 0) {
$result['skipped'][] = $table;
}
continue;
}
if ($this->countByDept($table, $deptId) > 0) {
$result['skipped'][] = $table;
continue;
}
$rows = $this->defaultTemplateRows($table);
if (empty($rows)) {
continue;
}
foreach ($rows as $row) {
$row = (array) $row;
unset($row['id'], $row['row_id'], $row['create_time'], $row['update_time'], $row['delete_time']);
$row['dept_id'] = $deptId;
Db::table($table)->insert($row);
}
$result['copied'][] = $table;
}
$this->ensureRewardReferenceForDept($deptId);
DiceRewardConfig::refreshCache($deptId);
return $result;
}
/**
* 按业务 id 从默认模板补齐配置dice_config / dice_reward_config
*/
private function syncCompositeIdTableFromDefault(string $table, int $deptId): int
{
$templateRows = $this->defaultTemplateRows($table);
if (empty($templateRows)) {
return 0;
}
$inserted = 0;
foreach ($templateRows as $row) {
$row = (array) $row;
if (!isset($row['id'])) {
continue;
}
$businessId = $row['id'];
$exists = Db::table($table)->where('dept_id', $deptId)->where('id', $businessId)->count();
if ($exists > 0) {
continue;
}
unset($row['row_id'], $row['create_time'], $row['update_time'], $row['delete_time']);
$row['dept_id'] = $deptId;
Db::table($table)->insert($row);
$inserted++;
}
return $inserted;
}
/**
* 渠道已有奖励索引时,自动生成 dice_reward 对照表
*/
public function ensureRewardReferenceForDept(int $deptId): void
{
if ($deptId <= 0 || !$this->tableHasColumn('dice_reward', 'dept_id')) {
return;
}
if ($this->countByDept('dice_reward_config', $deptId) <= 0) {
return;
}
if ($this->countByDept('dice_reward', $deptId) > 0) {
return;
}
$logic = new DiceRewardLogic();
$logic->createRewardReferenceFromConfig($deptId);
}
/**
* 复制默认 dice_reward 到渠道
*/
public function copyDefaultRewardsToDept(int $deptId): void
{
$this->ensureRewardReferenceForDept($deptId);
if (!$this->tableHasColumn('dice_reward', 'dept_id')) {
return;
}
if ($this->countByDept('dice_reward', $deptId) > 0) {
return;
}
if ($this->countByDept('dice_reward_config', $deptId) > 0) {
return;
}
$rows = $this->defaultTemplateRows('dice_reward');
foreach ($rows as $row) {
$row = (array) $row;
unset($row['id'], $row['row_id']);
unset($row['create_time'], $row['update_time'], $row['delete_time']);
$row['dept_id'] = $deptId;
Db::table('dice_reward')->insert($row);
}
}
/**
* 为所有已有渠道补齐缺失配置
*/
public function syncAllChannelsFromDefault(): array
{
$deptIds = SystemDept::column('id');
$summary = [];
foreach ($deptIds as $deptId) {
$deptId = (int) $deptId;
if ($deptId <= 0) {
continue;
}
$summary[$deptId] = $this->copyDefaultConfigToDept($deptId);
}
return $summary;
}
/**
* 修复已删除渠道 ID、无管理员关联的遗留数据归并到首个顶级渠道
*/
public function repairOrphanDeptReferences(): array
{
$validDeptIds = array_map('intval', SystemDept::column('id') ?: []);
if (empty($validDeptIds)) {
return [];
}
$rootDeptId = min($validDeptIds);
$stats = [];
$inList = implode(',', $validDeptIds);
$stats['sa_system_user'] = Db::execute(
"UPDATE sa_system_user SET dept_id = {$rootDeptId}
WHERE dept_id IS NOT NULL AND dept_id > 0 AND dept_id NOT IN ({$inList})"
);
$bizTables = [
'dice_player',
'dice_play_record',
'dice_play_record_test',
'dice_player_wallet_record',
'dice_player_ticket_record',
'dice_reward_config_record',
];
foreach ($bizTables as $table) {
if (!$this->tableHasColumn($table, 'dept_id')) {
continue;
}
$stats[$table . '_invalid_dept'] = Db::execute(
"UPDATE `{$table}` SET dept_id = {$rootDeptId}
WHERE dept_id IS NOT NULL AND dept_id > 0 AND dept_id NOT IN ({$inList})"
);
}
return $stats;
}
/**
* 根据管理员/玩家回填 dept_id
*/
public function backfillDataDeptId(): array
{
$stats = $this->repairOrphanDeptReferences();
if ($this->tableHasColumn('dice_player', 'dept_id') && $this->tableHasColumn('dice_player', 'admin_id')) {
$stats['dice_player'] = Db::execute(
'UPDATE dice_player p INNER JOIN sa_system_user u ON p.admin_id = u.id
SET p.dept_id = u.dept_id WHERE (p.dept_id IS NULL OR p.dept_id = 0) AND u.dept_id IS NOT NULL AND u.dept_id > 0'
);
}
$validDeptIds = SystemDept::column('id') ?: [];
if (!empty($validDeptIds) && $this->tableHasColumn('dice_player', 'dept_id')) {
$rootDeptId = (int) min($validDeptIds);
$stats['dice_player_legacy'] = Db::table('dice_player')
->where(function ($q) {
$q->whereNull('dept_id')->whereOr('dept_id', 0);
})
->update(['dept_id' => $rootDeptId]);
}
$stats = array_merge($stats, $this->backfillRecordDeptIdByPlayer('dice_play_record'));
$stats = array_merge($stats, $this->backfillRecordDeptIdByAdmin('dice_play_record'));
$stats = array_merge($stats, $this->backfillRecordDeptIdByPlayer('dice_player_wallet_record'));
$stats = array_merge($stats, $this->backfillRecordDeptIdByPlayer('dice_player_ticket_record'));
$stats = array_merge($stats, $this->backfillRecordDeptIdByAdmin('dice_play_record_test'));
if (!empty($validDeptIds) && $this->tableHasColumn('dice_play_record_test', 'dept_id')) {
$rootDeptId = (int) min($validDeptIds);
$stats['dice_play_record_test_legacy'] = Db::table('dice_play_record_test')
->where(function ($q) {
$q->whereNull('dept_id')->whereOr('dept_id', 0);
})
->update(['dept_id' => $rootDeptId]);
}
if ($this->tableHasColumn('dice_reward_config_record', 'dept_id')) {
$stats['dice_reward_config_record'] = Db::execute(
'UPDATE dice_reward_config_record r INNER JOIN sa_system_user u ON r.admin_id = u.id
SET r.dept_id = u.dept_id WHERE (r.dept_id IS NULL OR r.dept_id = 0) AND u.dept_id IS NOT NULL AND u.dept_id > 0'
);
}
return $stats;
}
/**
* 删除渠道前关联数据统计
*/
public function getDestroyPreview(array $deptIds): array
{
$items = [];
foreach ($deptIds as $deptId) {
$deptId = (int) $deptId;
if ($deptId <= 0) {
continue;
}
$dept = SystemDept::find($deptId);
$row = [
'dept_id' => $deptId,
'dept_name' => $dept ? $dept->name : '',
'user_count' => SystemUser::where('dept_id', $deptId)->count(),
'relations' => [],
];
foreach (self::RELATION_TABLES as $table => $meta) {
if (!$this->tableHasColumn($table, 'dept_id')) {
continue;
}
$count = $this->countByDept($table, $deptId);
if ($count > 0) {
$row['relations'][] = [
'table' => $table,
'label' => $meta['label'],
'group' => $meta['group'],
'count' => $count,
];
}
}
$items[] = $row;
}
return $items;
}
/**
* 删除渠道及勾选的关联数据
*
* @param array $deleteTables 要删除的表名列表
*/
public function destroyDeptWithRelations(int $deptId, array $deleteTables): void
{
if ($deptId <= 0) {
throw new ApiException('Invalid channel id');
}
$userCount = SystemUser::where('dept_id', $deptId)->count();
if ($userCount > 0) {
throw new ApiException('This channel has users, please delete or transfer them first');
}
$allowed = array_keys(self::RELATION_TABLES);
foreach ($deleteTables as $table) {
if (!in_array($table, $allowed, true)) {
continue;
}
if (!$this->tableHasColumn($table, 'dept_id')) {
continue;
}
Db::table($table)->where('dept_id', $deptId)->delete();
}
SystemDept::destroy($deptId, true);
DiceRewardConfig::refreshCache($deptId);
DiceReward::refreshCache($deptId);
}
/**
* @return array<int, array<string, mixed>>
*/
private function defaultTemplateRows(string $table): array
{
$templateId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
$rows = Db::table($table)->where('dept_id', $templateId)->select()->toArray();
if (!empty($rows)) {
return $rows;
}
return Db::table($table)->whereNull('dept_id')->select()->toArray();
}
private function backfillRecordDeptIdByPlayer(string $table): array
{
if (!$this->tableHasColumn($table, 'dept_id') || !$this->tableHasColumn($table, 'player_id')) {
return [];
}
return [
$table => Db::execute(
"UPDATE `{$table}` r INNER JOIN dice_player p ON r.player_id = p.id
SET r.dept_id = p.dept_id WHERE (r.dept_id IS NULL OR r.dept_id = 0) AND p.dept_id IS NOT NULL AND p.dept_id > 0"
),
];
}
private function backfillRecordDeptIdByAdmin(string $table): array
{
if (!$this->tableHasColumn($table, 'dept_id') || !$this->tableHasColumn($table, 'admin_id')) {
return [];
}
return [
$table => Db::execute(
"UPDATE `{$table}` r INNER JOIN sa_system_user u ON r.admin_id = u.id
SET r.dept_id = u.dept_id WHERE (r.dept_id IS NULL OR r.dept_id = 0) AND u.dept_id IS NOT NULL AND u.dept_id > 0"
),
];
}
private function countByDept(string $table, ?int $deptId): int
{
$query = Db::table($table);
if ($deptId === null || $deptId === AdminScopeHelper::DEFAULT_TEMPLATE_DEPT) {
$templateId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
$query->where(function ($q) use ($templateId) {
$q->where('dept_id', $templateId)->whereOr('dept_id', 'null');
});
} else {
$query->where('dept_id', $deptId);
}
return $query->count();
}
private function tableHasColumn(string $table, string $column): bool
{
try {
$fields = Db::getFields($table);
return isset($fields[$column]);
} catch (\Throwable $e) {
return false;
}
}
}

View File

@@ -6,6 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\validate\player;
use app\dice\model\player\DicePlayer;
use plugin\saiadmin\basic\BaseValidate;
/**
@@ -17,7 +18,7 @@ class DicePlayerValidate extends BaseValidate
* 定义验证规则
*/
protected $rule = [
'username' => 'require',
'username' => 'require|unique:' . DicePlayer::class . ',username^dept_id',
'name' => 'require',
'phone' => 'require',
'password' => 'require',
@@ -30,6 +31,7 @@ class DicePlayerValidate extends BaseValidate
*/
protected $message = [
'username' => '用户名必须填写',
'username.unique' => 'PLAYER_USERNAME_DEPT_UNIQUE',
'name' => '昵称必须填写',
'phone' => '手机号必须填写',
'password' => '密码必须填写',

View File

@@ -6,7 +6,7 @@ return [
// 登录成功返回的连接地址前缀,如 https://127.0.0.1:6777
'login_url_base' => env('API_LOGIN_URL_BASE', 'https://127.0.0.1:6777'),
// 游戏地址,用于 /api/v1/getGameUrl 返回拼接 token
'game_url' => env('GAME_URL', 'dice-game.h55555game.top'),
'game_url' => env('GAME_URL', 'dice-v3-game.h55555game.top'),
// 按 username 存储的登录会话 Redis key 前缀,用于 token 中间件校验
'session_username_prefix' => env('API_SESSION_USERNAME_PREFIX', 'api:user:session:'),
// 登录会话过期时间(秒),默认 7 天

View File

@@ -14,7 +14,7 @@ use support\Request;
use support\Response;
/**
* 部门控制器
* 渠道控制器
*/
class SystemDeptController extends BaseController
{
@@ -33,7 +33,7 @@ class SystemDeptController extends BaseController
* @param Request $request
* @return Response
*/
#[Permission('部门数据列表', 'core:dept:index')]
#[Permission('渠道数据列表', 'core:dept:index')]
public function index(Request $request) : Response
{
$where = $request->more([
@@ -50,7 +50,7 @@ class SystemDeptController extends BaseController
* @param Request $request
* @return Response
*/
#[Permission('部门数据读取', 'core:dept:read')]
#[Permission('渠道数据读取', 'core:dept:read')]
public function read(Request $request) : Response
{
$id = $request->input('id', '');
@@ -68,7 +68,7 @@ class SystemDeptController extends BaseController
* @param Request $request
* @return Response
*/
#[Permission('部门数据添加', 'core:dept:save')]
#[Permission('渠道数据添加', 'core:dept:save')]
public function save(Request $request): Response
{
$data = $request->post();
@@ -86,7 +86,7 @@ class SystemDeptController extends BaseController
* @param Request $request
* @return Response
*/
#[Permission('部门数据修改','core:dept:update')]
#[Permission('渠道数据修改','core:dept:update')]
public function update(Request $request): Response
{
$data = $request->post();
@@ -104,23 +104,58 @@ class SystemDeptController extends BaseController
* @param Request $request
* @return Response
*/
#[Permission('部门数据删除','core:dept:destroy')]
#[Permission('渠道数据删除','core:dept:destroy')]
public function destroy(Request $request) : Response
{
$ids = $request->post('ids', '');
if (empty($ids)) {
return $this->fail('please select data to delete');
}
$deleteTables = $request->post('delete_tables', []);
if (!is_array($deleteTables)) {
$deleteTables = [];
}
$idList = is_array($ids) ? $ids : explode(',', (string) $ids);
if (!empty($deleteTables)) {
foreach ($idList as $deptId) {
$this->logic->destroyWithRelations((int) $deptId, $deleteTables);
}
return $this->success('delete success');
}
$result = $this->logic->destroy($ids);
if ($result) {
return $this->success('delete success');
} else {
return $this->fail('delete failed');
}
return $this->fail('delete failed');
}
/**
* 可操作部门
* 删除渠道前关联数据预览
*/
#[Permission('渠道数据删除', 'core:dept:destroy')]
public function destroyPreview(Request $request): Response
{
$ids = $request->input('ids', '');
if ($ids === '' || $ids === null) {
return $this->fail('please select data');
}
$idList = is_array($ids) ? $ids : explode(',', (string) $ids);
$data = $this->logic->getDestroyPreview($idList);
return $this->success($data);
}
/**
* 为所有渠道补齐默认配置
*/
#[Permission('渠道数据修改', 'core:dept:update')]
public function syncChannelConfigs(Request $request): Response
{
$data = $this->logic->syncAllChannelConfigs();
return $this->success($data, 'sync success');
}
/**
* 可操作渠道
* @param Request $request
* @return Response
*/

View File

@@ -6,10 +6,8 @@
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\controller\system;
use plugin\saiadmin\app\model\system\SystemUserRole;
use app\dice\helper\AdminScopeHelper;
use plugin\saiadmin\basic\BaseController;
use plugin\saiadmin\app\cache\UserInfoCache;
use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\app\validate\system\SystemRoleValidate;
use plugin\saiadmin\app\logic\system\SystemRoleLogic;
use plugin\saiadmin\service\Permission;
@@ -17,13 +15,10 @@ use support\Request;
use support\Response;
/**
* 角色控制器
* 角色控制器(按渠道隔离)
*/
class SystemRoleController extends BaseController
{
/**
* 构造
*/
public function __construct()
{
$this->logic = new SystemRoleLogic();
@@ -31,11 +26,6 @@ class SystemRoleController extends BaseController
parent::__construct();
}
/**
* 数据列表
* @param Request $request
* @return Response
*/
#[Permission('角色数据列表', 'core:role:index')]
public function index(Request $request): Response
{
@@ -44,19 +34,14 @@ class SystemRoleController extends BaseController
['code', ''],
['status', ''],
]);
$query = $this->logic->search($where);
$levelArr = array_column($this->adminInfo['roleList'], 'level');
$maxLevel = max($levelArr);
$query->where('level', '<', $maxLevel);
$data = $this->logic->getList($query);
$requestDeptId = AdminScopeHelper::pickRequestDeptId(
$request->input('dept_id'),
$request->all()
);
$data = $this->logic->indexList($where, $requestDeptId);
return $this->success($data);
}
/**
* 读取数据
* @param Request $request
* @return Response
*/
#[Permission('角色数据读取', 'core:role:read')]
public function read(Request $request): Response
{
@@ -64,53 +49,49 @@ class SystemRoleController extends BaseController
$model = $this->logic->read($id);
if ($model) {
$data = is_array($model) ? $model : $model->toArray();
$role = $this->logic->model->find($id);
if ($role) {
$this->logic->assertRoleWritable($role);
}
return $this->success($data);
} else {
return $this->fail('not found');
}
return $this->fail('not found');
}
/**
* 保存数据
* @param Request $request
* @return Response
*/
#[Permission('角色数据添加', 'core:role:save')]
public function save(Request $request): Response
{
$data = $request->post();
$data['dept_id'] = $this->logic->resolveRequestDeptId(
AdminScopeHelper::pickRequestDeptId($data['dept_id'] ?? null, $data)
);
$this->validate('save', $data);
$result = $this->logic->add($data);
if ($result) {
return $this->success('add success');
} else {
return $this->fail('add failed');
}
return $this->fail('add failed');
}
/**
* 更新数据
* @param Request $request
* @return Response
*/
#[Permission('角色数据修改', 'core:role:update')]
public function update(Request $request): Response
{
$data = $request->post();
$role = $this->logic->model->find($data['id'] ?? 0);
if ($role) {
$this->logic->assertRoleWritable($role);
if (!isset($data['dept_id']) || $data['dept_id'] === '' || $data['dept_id'] === null) {
$data['dept_id'] = $role->dept_id;
}
}
$this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data);
if ($result) {
return $this->success('update success');
} else {
return $this->fail('update failed');
}
return $this->fail('update failed');
}
/**
* 删除数据
* @param Request $request
* @return Response
*/
#[Permission('角色数据删除', 'core:role:destroy')]
public function destroy(Request $request): Response
{
@@ -121,16 +102,10 @@ class SystemRoleController extends BaseController
$result = $this->logic->destroy($ids);
if ($result) {
return $this->success('delete success');
} else {
return $this->fail('delete failed');
}
return $this->fail('delete failed');
}
/**
* 根据角色获取菜单
* @param Request $request
* @return Response
*/
#[Permission('角色数据列表', 'core:role:index')]
public function getMenuByRole(Request $request): Response
{
@@ -139,11 +114,6 @@ class SystemRoleController extends BaseController
return $this->success($data);
}
/**
* 菜单权限
* @param Request $request
* @return Response
*/
#[Permission('角色菜单权限', 'core:role:menu')]
public function menuPermission(Request $request): Response
{
@@ -153,16 +123,14 @@ class SystemRoleController extends BaseController
return $this->success('operation success');
}
/**
* 可操作角色
* @param Request $request
* @return Response
*/
public function accessRole(Request $request): Response
{
$where = ['status' => 1];
$data = $this->logic->accessRole($where);
$requestDeptId = AdminScopeHelper::pickRequestDeptId(
$request->input('dept_id'),
$request->all()
);
$data = $this->logic->accessRole($where, $requestDeptId);
return $this->success($data);
}
}

View File

@@ -2,129 +2,123 @@
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: sai <1430792918@qq.com>
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\logic\system;
use app\dice\service\DiceChannelConfigService;
use plugin\saiadmin\app\service\SystemRoleChannelService;
use plugin\saiadmin\basic\think\BaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\app\model\system\SystemDept;
use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\utils\Helper;
use plugin\saiadmin\utils\Arr;
/**
* 部门逻辑层
* 渠道逻辑层(表 sa_system_dept
*/
class SystemDeptLogic extends BaseLogic
{
/**
* 构造函数
*/
public function __construct()
{
$this->model = new SystemDept();
}
/**
* 添加数据
*/
public function add($data): mixed
{
$data = $this->handleData($data);
$this->model->save($data);
return $this->model->getKey();
$deptId = (int) $this->model->getKey();
if ($deptId > 0) {
(new DiceChannelConfigService())->copyDefaultConfigToDept($deptId);
(new SystemRoleChannelService())->copyDefaultRolesToDept($deptId, false);
}
return $deptId;
}
/**
* 修改数据
*/
public function edit($id, $data): mixed
{
$oldLevel = $data['level'] . $id . ',';
$data = $this->handleData($data);
if ($data['parent_id'] == $id) {
throw new ApiException('Parent department cannot be the same as current department');
}
if (in_array($id, explode(',', $data['level']))) {
throw new ApiException('Cannot set parent department to a child of current department');
}
$newLevel = $data['level'] . $id . ',';
$deptIds = $this->model->where('level', 'like', $oldLevel . '%')->column('id');
return $this->transaction(function () use ($deptIds, $oldLevel, $newLevel, $data, $id) {
$this->model->whereIn('id', $deptIds)->exp('level', "REPLACE(level, '$oldLevel', '$newLevel')")->update([]);
return $this->model->update($data, ['id' => $id]);
});
return $this->model->update($data, ['id' => $id]);
}
/**
* 数据删除
*/
public function destroy($ids): bool
{
$num = $this->model->where('parent_id', 'in', $ids)->count();
if ($num > 0) {
throw new ApiException('This department has sub-departments, please delete them first');
} else {
$count = SystemUser::where('dept_id', 'in', $ids)->count();
if ($count > 0) {
throw new ApiException('This department has users, please delete or transfer them first');
}
return $this->model->destroy($ids);
$count = SystemUser::where('dept_id', 'in', $ids)->count();
if ($count > 0) {
throw new ApiException('This channel has users, please delete or transfer them first');
}
return $this->model->destroy($ids);
}
/**
* 数据处理
* 带关联选项删除渠道
*/
public function destroyWithRelations(int $deptId, array $deleteTables): bool
{
(new SystemRoleChannelService())->deleteRolesByDept($deptId);
(new DiceChannelConfigService())->destroyDeptWithRelations($deptId, $deleteTables);
return true;
}
public function getDestroyPreview(array $deptIds): array
{
return (new DiceChannelConfigService())->getDestroyPreview($deptIds);
}
public function syncAllChannelConfigs(): array
{
$config = (new DiceChannelConfigService())->syncAllChannelsFromDefault();
$roles = (new SystemRoleChannelService())->syncAllChannelsFromDefault();
return ['config' => $config, 'roles' => $roles];
}
protected function handleData($data)
{
// 处理上级部门
if (empty($data['parent_id']) || $data['parent_id'] == 0) {
$data['level'] = '0';
$data['parent_id'] = 0;
} else {
$parentMenu = SystemDept::findOrEmpty($data['parent_id']);
$data['level'] = $parentMenu['level'] . $parentMenu['id'] . ',';
}
$data['level'] = '0';
$data['parent_id'] = 0;
return $data;
}
/**
* 数据树形化
* @param array $where
* @return array
*/
public function tree(array $where = []): array
{
$query = $this->search($where);
$request = request();
if ($request && $request->input('tree', 'false') === 'true') {
$query->field('id, id as value, name as label, parent_id');
}
$query->order('sort', 'desc');
$query->with(['leader']);
$data = $this->getAll($query);
return Helper::makeTree($data);
return $this->getAll($query);
}
/**
* 可操作部门
* @param array $where
* @return array
*/
public function accessDept(array $where = []): array
{
$query = $this->search($where);
// 超级管理员(id=1)可查看全部部门,普通管理员按部门权限过滤
if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) {
$query->auth($this->adminInfo['deptList'] ?? []);
$deptId = $this->resolveAccessibleDeptId();
if ($deptId > 0) {
$query->where('id', $deptId);
} else {
return [];
}
}
$query->field('id, id as value, name as label, parent_id');
$query->field('id, id as value, name as label');
$query->order('sort', 'desc');
$data = $this->getAll($query);
return Helper::makeTree($data);
return $this->getAll($query);
}
/**
* 当前管理员可操作的渠道 IDdeptList 缺失时回退 dept_id
*/
public function resolveAccessibleDeptId(?array $adminInfo = null): int
{
$adminInfo = $adminInfo ?? $this->adminInfo ?? [];
if (empty($adminInfo['id']) || (int) $adminInfo['id'] <= 1) {
return 0;
}
$deptList = $adminInfo['deptList'] ?? [];
if (is_array($deptList) && isset($deptList['id']) && (int) $deptList['id'] > 0) {
return (int) $deptList['id'];
}
$deptId = $adminInfo['dept_id'] ?? null;
if ($deptId !== null && $deptId !== '' && (int) $deptId > 0) {
return (int) $deptId;
}
return 0;
}
}

View File

@@ -6,121 +6,133 @@
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\logic\system;
use app\dice\helper\AdminScopeHelper;
use plugin\saiadmin\app\cache\UserMenuCache;
use plugin\saiadmin\app\model\system\SystemRole;
use plugin\saiadmin\app\service\SystemRoleChannelService;
use plugin\saiadmin\basic\think\BaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use support\think\Cache;
use support\think\Db;
/**
* 角色逻辑层
* 角色逻辑层(按渠道 dept_id 隔离)
*/
class SystemRoleLogic extends BaseLogic
{
/**
* 构造函数
*/
public function __construct()
{
$this->model = new SystemRole();
}
/**
* 添加数据
* 分页列表(按渠道过滤)
*/
public function indexList(array $where, $requestDeptId = null): array
{
$query = $this->search($where);
$this->applyDeptScope($query, $requestDeptId);
$levelArr = array_column($this->adminInfo['roleList'] ?? [], 'level');
if (!empty($levelArr)) {
$maxLevel = max($levelArr);
$query->where('level', '<', $maxLevel);
}
$query->where('id', '<>', SystemRoleChannelService::SUPER_ADMIN_ROLE_ID);
return $this->getList($query);
}
public function add($data): bool
{
$data = $this->handleData($data);
$deptId = AdminScopeHelper::normalizeRecordDeptId($data['dept_id'] ?? null);
$data['dept_id'] = $deptId;
$this->assertCodeUniqueInDept($data['code'] ?? '', $deptId, null);
return $this->model->save($data);
}
/**
* 修改数据
*/
public function edit($id, $data): bool
{
$model = $this->model->findOrEmpty($id);
if ($model->isEmpty()) {
throw new ApiException('Data not found');
}
$this->assertRoleWritable($model);
$data = $this->handleData($data);
$deptId = AdminScopeHelper::normalizeRecordDeptId($model->dept_id ?? $data['dept_id'] ?? null);
$data['dept_id'] = $deptId;
$this->assertCodeUniqueInDept($data['code'] ?? '', $deptId, (int) $id);
return $model->save($data);
}
/**
* 删除数据
*/
public function destroy($ids): bool
{
// 越权保护
$levelArr = array_column($this->adminInfo['roleList'], 'level');
$maxLevel = max($levelArr);
$levelArr = array_column($this->adminInfo['roleList'] ?? [], 'level');
$maxLevel = !empty($levelArr) ? max($levelArr) : 100;
$num = SystemRole::where('level', '>=', $maxLevel)->whereIn('id', $ids)->count();
if ($num > 0) {
throw new ApiException('Cannot operate roles with higher level than current account');
} else {
return $this->model->destroy($ids);
$idList = is_array($ids) ? $ids : explode(',', (string) $ids);
foreach ($idList as $roleId) {
$roleId = (int) $roleId;
if ($roleId === SystemRoleChannelService::SUPER_ADMIN_ROLE_ID) {
throw new ApiException('Cannot delete super admin role');
}
$role = $this->model->find($roleId);
if (!$role) {
continue;
}
$this->assertRoleWritable($role);
if ((int) ($role->level ?? 0) >= $maxLevel) {
throw new ApiException('Cannot operate roles with higher level than current account');
}
}
return $this->model->destroy($ids);
}
/**
* 数据处理
*/
protected function handleData($data)
{
// 越权保护
$levelArr = array_column($this->adminInfo['roleList'], 'level');
$maxLevel = max($levelArr);
if ($data['level'] >= $maxLevel) {
throw new ApiException('Cannot operate roles with higher level than current account');
$levelArr = array_column($this->adminInfo['roleList'] ?? [], 'level');
if (!empty($levelArr)) {
$maxLevel = max($levelArr);
if (($data['level'] ?? 0) >= $maxLevel) {
throw new ApiException('Cannot operate roles with higher level than current account');
}
}
return $data;
}
/**
* 可操作角色
* @param array $where
* @return array
*/
public function accessRole(array $where = []): array
public function accessRole(array $where = [], $requestDeptId = null): array
{
$query = $this->search($where);
// 越权保护
$levelArr = array_column($this->adminInfo['roleList'], 'level');
$maxLevel = max($levelArr);
$query->where('level', '<', $maxLevel);
$this->applyDeptScope($query, $requestDeptId);
$levelArr = array_column($this->adminInfo['roleList'] ?? [], 'level');
if (!empty($levelArr)) {
$maxLevel = max($levelArr);
$query->where('level', '<', $maxLevel);
}
$query->where('id', '<>', SystemRoleChannelService::SUPER_ADMIN_ROLE_ID);
$query->order('sort', 'desc');
return $this->getAll($query);
}
/**
* 根据角色数组获取菜单
* @param $ids
* @return array
*/
public function getMenuIdsByRoleIds($ids): array
{
if (empty($ids))
if (empty($ids)) {
return [];
}
return $this->model->where('id', 'in', $ids)->with([
'menus' => function ($query) {
$query->where('status', 1)->order('sort', 'desc');
}
])->select()->toArray();
}
/**
* 根据角色获取菜单
* @param $id
* @return array
*/
public function getMenuByRole($id): array
{
$role = $this->model->findOrEmpty($id);
if ($role->isEmpty()) {
throw new ApiException('Data not found');
}
$this->assertRoleWritable($role);
$menus = $role->menus ?: [];
return [
'id' => $id,
@@ -128,14 +140,14 @@ class SystemRoleLogic extends BaseLogic
];
}
/**
* 保存菜单权限
* @param $id
* @param $menu_ids
* @return mixed
*/
public function saveMenuPermission($id, $menu_ids): mixed
{
$role = $this->model->findOrEmpty($id);
if ($role->isEmpty()) {
throw new ApiException('Data not found');
}
$this->assertRoleWritable($role);
return $this->transaction(function () use ($id, $menu_ids) {
$role = $this->model->findOrEmpty($id);
if ($role) {
@@ -147,10 +159,90 @@ class SystemRoleLogic extends BaseLogic
}
$cache = config('plugin.saiadmin.saithink.button_cache');
$tag = $cache['role'] . $id;
Cache::tag($tag)->clear(); // 清理权限缓存-角色TAG
UserMenuCache::clearMenuCache(); // 清理菜单缓存
Cache::tag($tag)->clear();
UserMenuCache::clearMenuCache();
return true;
});
}
/**
* 解析并校验当前请求应操作的渠道 ID
*/
public function resolveRequestDeptId($requestDeptId): int
{
if ((int) ($this->adminInfo['id'] ?? 0) === 1) {
return AdminScopeHelper::resolveConfigDeptId($this->adminInfo, $requestDeptId);
}
$deptLogic = new SystemDeptLogic();
$deptLogic->init($this->adminInfo);
return $deptLogic->resolveAccessibleDeptId();
}
/**
* 列表/下拉按渠道过滤
*/
protected function applyDeptScope($query, $requestDeptId = null): void
{
if (!$this->tableHasDeptIdColumn()) {
return;
}
if ((int) ($this->adminInfo['id'] ?? 0) === 1) {
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo, $requestDeptId);
$query->where('dept_id', $deptId);
return;
}
$deptLogic = new SystemDeptLogic();
$deptLogic->init($this->adminInfo);
$deptId = $deptLogic->resolveAccessibleDeptId();
if ($deptId > 0) {
$query->where('dept_id', $deptId);
}
}
/**
* 校验角色属于当前可操作渠道
*/
public function assertRoleWritable($role): void
{
if (!$this->tableHasDeptIdColumn()) {
return;
}
$roleDeptId = AdminScopeHelper::normalizeRecordDeptId($role->dept_id ?? null);
if ((int) ($role->id ?? 0) === SystemRoleChannelService::SUPER_ADMIN_ROLE_ID) {
throw new ApiException('Cannot operate super admin role');
}
if ((int) ($this->adminInfo['id'] ?? 0) === 1) {
return;
}
$deptLogic = new SystemDeptLogic();
$deptLogic->init($this->adminInfo);
$scopeDeptId = $deptLogic->resolveAccessibleDeptId();
if ($scopeDeptId > 0 && $roleDeptId !== $scopeDeptId) {
throw new ApiException('No permission to operate this channel role');
}
}
protected function assertCodeUniqueInDept(string $code, int $deptId, ?int $excludeId): void
{
if ($code === '') {
return;
}
$query = SystemRole::where('code', $code)->where('dept_id', $deptId);
if ($excludeId !== null && $excludeId > 0) {
$query->where('id', '<>', $excludeId);
}
if ($query->count() > 0) {
throw new ApiException('Role code already exists in this channel');
}
}
protected function tableHasDeptIdColumn(): bool
{
try {
$fields = Db::getFields((new SystemRole())->getTable());
return isset($fields['dept_id']);
} catch (\Throwable $e) {
return false;
}
}
}

View File

@@ -40,9 +40,16 @@ class SystemUserLogic extends BaseLogic
{
$query = $this->search($where);
$query->with(['depts']);
// 超级管理员(id=1)可查看全部用户,普通管理员按部门权限过滤
// 超级管理员(id=1)可查看全部用户,渠道管理员按本渠道过滤
if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) {
$query->auth($this->adminInfo['deptList'] ?? []);
$deptLogic = new SystemDeptLogic();
$deptLogic->init($this->adminInfo);
$deptId = $deptLogic->resolveAccessibleDeptId();
if ($deptId > 0) {
$query->where('dept_id', $deptId);
} else {
$query->auth($this->adminInfo['deptList'] ?? []);
}
}
return $this->getList($query);
}
@@ -70,6 +77,12 @@ class SystemUserLogic extends BaseLogic
$data = $admin->hidden(['password'])->toArray();
$data['roleList'] = $admin->roles->toArray() ?: [];
$data['deptList'] = $admin->depts ? $admin->depts->toArray() : [];
if (empty($data['deptList']) && ! empty($admin->dept_id)) {
$dept = SystemDept::find($admin->dept_id);
if ($dept && ! $dept->isEmpty()) {
$data['deptList'] = $dept->toArray();
}
}
return $data;
}

View File

@@ -9,15 +9,15 @@ namespace plugin\saiadmin\app\model\system;
use plugin\saiadmin\basic\think\BaseModel;
/**
* 部门模型
* 渠道模型
*
* sa_system_dept 部门
* sa_system_dept 渠道
*
* @property $id 编号
* @property $parent_id 父级ID0为根节点
* @property $name 部门名称
* @property $code 部门编码
* @property $leader_id 部门负责人ID
* @property $parent_id 父级ID扁平渠道固定为0
* @property $name 渠道名称
* @property $code 渠道编码
* @property $leader_id 渠道负责人ID
* @property $level 祖级列表,格式: 0,1,5,
* @property $sort 排序,数字越小越靠前
* @property $status 状态: 1启用, 0禁用
@@ -38,24 +38,21 @@ class SystemDept extends BaseModel
protected $table = 'sa_system_dept';
/**
* 权限范围
* 权限范围(扁平渠道,仅本渠道)
*/
public function scopeAuth($query, $value)
{
if (!empty($value) && isset($value['id'])) {
$deptIds = [$value['id']];
$level = $value['level'] ?? '';
if ($level !== '' && $level !== null) {
$deptLevel = $level . $value['id'] . ',';
$ids = static::whereLike('level', $deptLevel . '%')->column('id');
$deptIds = array_merge($deptIds, $ids);
}
$query->whereIn('id', $deptIds);
if (is_array($value) && isset($value['id']) && (int) $value['id'] > 0) {
$query->where('id', $value['id']);
return;
}
if (is_numeric($value) && (int) $value > 0) {
$query->where('id', (int) $value);
}
}
/**
* 部门领导
* 渠道负责人
*/
public function leader()
{

View File

@@ -13,7 +13,8 @@ use plugin\saiadmin\basic\think\BaseModel;
*
* sa_system_role 角色表
*
* @property $id
* @property $id
* @property int $dept_id 所属渠道ID0=默认模板
* @property $name 角色名称
* @property $code 角色标识,如: hr_manager
* @property $level 角色级别:用于行政控制,不可操作级别大于自己的角色
@@ -41,6 +42,14 @@ class SystemRole extends BaseModel
*/
protected $table = 'sa_system_role';
/** 按渠道筛选 */
public function searchDeptIdAttr($query, $value): void
{
if ($value !== '' && $value !== null) {
$query->where('dept_id', '=', $value);
}
}
/**
* 权限范围
*/

View File

@@ -24,7 +24,7 @@ use plugin\saiadmin\basic\think\BaseModel;
* @property $phone 手机号
* @property $signed 个性签名
* @property $dashboard 工作台
* @property $dept_id 主归属部门
* @property $dept_id 主归属渠道
* @property $is_super 是否超级管理员: 1是
* @property $status 状态: 1启用, 2禁用
* @property $remark 备注
@@ -82,16 +82,12 @@ class SystemUser extends BaseModel
}
/**
* 权限范围 - 过滤部门用户
* 权限范围 - 过滤同渠道用户
*/
public function scopeAuth($query, $value)
{
if (!empty($value)) {
$deptIds = [$value['id']];
$deptLevel = $value['level'] . $value['id'] . ',';
$dept_ids = SystemDept::whereLike('level', $deptLevel . '%')->column('id');
$deptIds = array_merge($deptIds, $dept_ids);
$query->whereIn('dept_id', $deptIds);
if (!empty($value) && isset($value['id'])) {
$query->where('dept_id', $value['id']);
}
}
@@ -104,7 +100,7 @@ class SystemUser extends BaseModel
}
/**
* 通过中间表关联部门
* 关联渠道
*/
public function depts()
{

View File

@@ -0,0 +1,257 @@
<?php
declare(strict_types=1);
namespace plugin\saiadmin\app\service;
use plugin\saiadmin\app\model\system\SystemDept;
use plugin\saiadmin\app\model\system\SystemRole;
use plugin\saiadmin\exception\ApiException;
use support\think\Db;
/**
* 渠道角色:从默认模板复制指定角色、同步与删除
*/
class SystemRoleChannelService
{
/** 全局超级管理员角色,不参与渠道复制 */
public const SUPER_ADMIN_ROLE_ID = 1;
/**
* 为渠道从默认模板复制三个代理角色(缺失则补齐,不整包跳过)
*/
public function copyDefaultRolesToDept(int $deptId, bool $pruneExtra = false): array
{
if ($deptId <= 0) {
throw new ApiException('Invalid channel id');
}
if (!$this->tableHasColumn('sa_system_role', 'dept_id')) {
return ['dept_id' => $deptId, 'copied' => 0, 'skipped' => 0, 'pruned' => 0, 'message' => 'dept_id column missing'];
}
$templates = $this->defaultTemplateRoles();
if (empty($templates)) {
return ['dept_id' => $deptId, 'copied' => 0, 'skipped' => 0, 'pruned' => 0, 'message' => 'no template roles'];
}
$copied = 0;
$skipped = 0;
foreach ($templates as $template) {
$template = (array) $template;
$templateId = (int) ($template['id'] ?? 0);
$code = (string) ($template['code'] ?? '');
if ($templateId <= 0 || $code === '') {
continue;
}
if ($this->roleExists($deptId, $code)) {
$skipped++;
continue;
}
$newId = $this->insertRoleFromTemplate($template, $deptId);
if ($newId > 0) {
$this->copyRoleMenus($templateId, $newId);
$copied++;
}
}
$pruned = 0;
if ($pruneExtra) {
$pruned = $this->pruneExtraChannelRoles($deptId);
}
return ['dept_id' => $deptId, 'copied' => $copied, 'skipped' => $skipped, 'pruned' => $pruned];
}
/**
* 为所有已启用渠道补齐三个默认角色,并移除多余历史角色
*/
public function syncAllChannelsFromDefault(): array
{
$deptIds = SystemDept::where('status', 1)->where('id', '>', 0)->column('id');
$result = [];
foreach ($deptIds as $deptId) {
$result[(int) $deptId] = $this->copyDefaultRolesToDept((int) $deptId, true);
}
return $result;
}
/**
* 删除渠道下全部角色及菜单关联
*/
public function deleteRolesByDept(int $deptId): int
{
if ($deptId <= 0) {
return 0;
}
$roleIds = SystemRole::where('dept_id', $deptId)->column('id');
if (empty($roleIds)) {
return 0;
}
Db::name('sa_system_user_role')->whereIn('role_id', $roleIds)->delete();
Db::name('sa_system_role_menu')->whereIn('role_id', $roleIds)->delete();
Db::name('sa_system_role_dept')->whereIn('role_id', $roleIds)->delete();
return SystemRole::destroy($roleIds);
}
/**
* 将用户已绑定的模板角色映射到其渠道对应角色(仅三个默认 code
*/
public function remapUserRolesToChannelRoles(): int
{
if (!$this->tableHasColumn('sa_system_role', 'dept_id')) {
return 0;
}
$codes = $this->getDefaultChannelRoleCodes();
if (empty($codes)) {
return 0;
}
$codeList = "'" . implode("','", array_map('addslashes', $codes)) . "'";
return Db::execute(
'UPDATE `sa_system_user_role` ur
INNER JOIN `sa_system_user` u ON ur.user_id = u.id
INNER JOIN `sa_system_role` r_old ON ur.role_id = r_old.id
INNER JOIN `sa_system_role` r_new ON r_new.dept_id = u.dept_id AND r_new.code = r_old.code
SET ur.role_id = r_new.id
WHERE u.dept_id > 0
AND r_old.dept_id = 0
AND r_old.code IN (' . $codeList . ')
AND r_old.id <> ' . self::SUPER_ADMIN_ROLE_ID
);
}
/**
* @return string[]
*/
public function getDefaultChannelRoleCodes(): array
{
$codes = config('plugin.saiadmin.saithink.channel_default_role_codes', []);
if (!is_array($codes) || $codes === []) {
return ['yijidaili', 'erjidaili', 'sanjidaili'];
}
$out = [];
foreach ($codes as $code) {
$code = trim((string) $code);
if ($code !== '') {
$out[] = $code;
}
}
return $out;
}
/**
* 删除渠道下不在默认三个 code 内、且未被用户绑定的角色
*/
public function pruneExtraChannelRoles(int $deptId): int
{
if ($deptId <= 0) {
return 0;
}
$allowed = $this->getDefaultChannelRoleCodes();
if (empty($allowed)) {
return 0;
}
$query = SystemRole::where('dept_id', $deptId)->whereNotIn('code', $allowed);
$roleIds = $query->column('id');
if (empty($roleIds)) {
return 0;
}
$usedIds = Db::name('sa_system_user_role')->whereIn('role_id', $roleIds)->column('role_id');
$usedMap = array_flip($usedIds ?: []);
$pruned = 0;
foreach ($roleIds as $roleId) {
if (isset($usedMap[$roleId])) {
continue;
}
Db::name('sa_system_role_menu')->where('role_id', $roleId)->delete();
Db::name('sa_system_role_dept')->where('role_id', $roleId)->delete();
SystemRole::destroy($roleId);
$pruned++;
}
return $pruned;
}
/**
* @return array<int, array<string, mixed>>
*/
private function defaultTemplateRoles(): array
{
$codes = $this->getDefaultChannelRoleCodes();
if (empty($codes)) {
return [];
}
$query = Db::table('sa_system_role')
->where('id', '<>', self::SUPER_ADMIN_ROLE_ID)
->whereIn('code', $codes);
if ($this->tableHasColumn('sa_system_role', 'dept_id')) {
$query->where('dept_id', 0);
}
$rows = $query->order('sort', 'desc')->select()->toArray();
if (count($rows) === count($codes)) {
return $rows;
}
// 按配置顺序返回,缺失的 code 跳过
$byCode = [];
foreach ($rows as $row) {
$byCode[(string) ($row['code'] ?? '')] = $row;
}
$ordered = [];
foreach ($codes as $code) {
if (isset($byCode[$code])) {
$ordered[] = $byCode[$code];
}
}
return $ordered;
}
private function insertRoleFromTemplate(array $template, int $deptId): int
{
unset(
$template['id'],
$template['create_time'],
$template['update_time'],
$template['delete_time']
);
$template['dept_id'] = $deptId;
$now = date('Y-m-d H:i:s');
if (!isset($template['create_time'])) {
$template['create_time'] = $now;
}
if (!isset($template['update_time'])) {
$template['update_time'] = $now;
}
return (int) Db::table('sa_system_role')->insertGetId($template);
}
private function copyRoleMenus(int $fromRoleId, int $toRoleId): void
{
$menuIds = Db::name('sa_system_role_menu')->where('role_id', $fromRoleId)->column('menu_id');
if (empty($menuIds)) {
return;
}
$rows = [];
foreach ($menuIds as $menuId) {
$rows[] = ['role_id' => $toRoleId, 'menu_id' => $menuId];
}
Db::name('sa_system_role_menu')->limit(100)->insertAll($rows);
}
private function roleExists(int $deptId, string $code): bool
{
return SystemRole::where('dept_id', $deptId)->where('code', $code)->count() > 0;
}
private function tableHasColumn(string $table, string $column): bool
{
try {
$fields = Db::getFields($table);
return isset($fields[$column]);
} catch (\Throwable $e) {
return false;
}
}
}

View File

@@ -9,7 +9,7 @@ namespace plugin\saiadmin\app\validate\system;
use plugin\saiadmin\basic\BaseValidate;
/**
* 部门验证器
* 渠道验证器
*/
class SystemDeptValidate extends BaseValidate
{
@@ -25,7 +25,7 @@ class SystemDeptValidate extends BaseValidate
* 定义错误信息
*/
protected $message = [
'name' => '部门名称必须填写',
'name' => '渠道名称必须填写',
'status' => '状态必须填写',
];

View File

@@ -19,7 +19,7 @@ class SystemRoleValidate extends BaseValidate
*/
protected $rule = [
'name' => 'require|max:16',
'code' => 'require|alphaDash|unique:' . SystemRole::class,
'code' => 'require|alphaDash|unique:' . SystemRole::class . ',code^dept_id',
'status' => 'require',
];

View File

@@ -6,6 +6,7 @@
// +----------------------------------------------------------------------
namespace plugin\saiadmin\basic;
use app\api\util\ApiLang;
use support\Request;
use support\Response;
@@ -36,6 +37,7 @@ class OpenController
if (is_string($data)) {
$msg = $data;
}
$msg = ApiLang::translate($msg, request());
return json(['code' => 200, 'message' => $msg, 'data' => $data], $option);
}
@@ -47,6 +49,7 @@ class OpenController
*/
public function fail(string $msg = 'fail', int $code = 400): Response
{
$msg = ApiLang::translate($msg, request());
return json(['code' => $code, 'message' => $msg]);
}

View File

@@ -50,9 +50,11 @@ Route::group('/core', function () {
Route::get("/role/getMenuByRole", [\plugin\saiadmin\app\controller\system\SystemRoleController::class, 'getMenuByRole']);
Route::post("/role/menuPermission", [\plugin\saiadmin\app\controller\system\SystemRoleController::class, 'menuPermission']);
// 部门管理
// 渠道管理
fastRoute("dept", \plugin\saiadmin\app\controller\system\SystemDeptController::class);
Route::get("/dept/accessDept", [\plugin\saiadmin\app\controller\system\SystemDeptController::class, 'accessDept']);
Route::get("/dept/destroyPreview", [\plugin\saiadmin\app\controller\system\SystemDeptController::class, 'destroyPreview']);
Route::post("/dept/syncChannelConfigs", [\plugin\saiadmin\app\controller\system\SystemDeptController::class, 'syncChannelConfigs']);
// 菜单管理
fastRoute('menu', \plugin\saiadmin\app\controller\system\SystemMenuController::class);
@@ -90,6 +92,7 @@ Route::group('/core', function () {
Route::put('/dice/player/DicePlayer/updateStatus', [\app\dice\controller\player\DicePlayerController::class, 'updateStatus']);
Route::get('/dice/player/DicePlayer/getLotteryConfigOptions', [\app\dice\controller\player\DicePlayerController::class, 'getLotteryConfigOptions']);
Route::get('/dice/player/DicePlayer/getSystemUserOptions', [\app\dice\controller\player\DicePlayerController::class, 'getSystemUserOptions']);
Route::get('/dice/player/DicePlayer/getSystemUserTreeOptions', [\app\dice\controller\player\DicePlayerController::class, 'getSystemUserTreeOptions']);
Route::get('/dice/player/DicePlayer/getGameUrl', [\app\dice\controller\player\DicePlayerController::class, 'getGameUrl']);
fastRoute('dice/play_record/DicePlayRecord', \app\dice\controller\play_record\DicePlayRecordController::class);
Route::get('/dice/play_record/DicePlayRecord/getPlayerOptions', [\app\dice\controller\play_record\DicePlayRecordController::class, 'getPlayerOptions']);
@@ -116,6 +119,7 @@ Route::group('/core', function () {
Route::post('/dice/reward_config/DiceRewardConfig/runWeightTest', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'runWeightTest']);
fastRoute('dice/game/DiceGame', \app\dice\controller\game\DiceGameController::class);
fastRoute('dice/ante_config/DiceAnteConfig', \app\dice\controller\ante_config\DiceAnteConfigController::class);
Route::get('/dice/ante_config/DiceAnteConfig/getOptions', [\app\dice\controller\ante_config\DiceAnteConfigController::class, 'getOptions']);
fastRoute('dice/lottery_pool_config/DiceLotteryPoolConfig', \app\dice\controller\lottery_pool_config\DiceLotteryPoolConfigController::class);
Route::get('/dice/lottery_pool_config/DiceLotteryPoolConfig/getOptions', [\app\dice\controller\lottery_pool_config\DiceLotteryPoolConfigController::class, 'getOptions']);
Route::get('/dice/lottery_pool_config/DiceLotteryPoolConfig/getCurrentPool', [\app\dice\controller\lottery_pool_config\DiceLotteryPoolConfigController::class, 'getCurrentPool']);

View File

@@ -72,4 +72,13 @@ return [
'attr' => 'saiadmin:reflection_cache:attr_',
],
/**
* 新建渠道时从默认模板复制的角色 code须存在于 dept_id=0 的模板角色)
*/
'channel_default_role_codes' => [
'yijidaili',
'erjidaili',
'sanjidaili',
],
];

View File

@@ -254,6 +254,7 @@ return [
'This category has sub-categories, please delete them first' => 'This category has sub-categories, please delete them first',
'This department has sub-departments, please delete them first' => 'This department has sub-departments, please delete them first',
'This department has users, please delete or transfer them first' => 'This department has users, please delete or transfer them first',
'This channel has users, please delete or transfer them first' => 'This channel has users, please delete or transfer them first',
'This dict code already exists' => 'This dict code already exists',
'This menu has sub-menus, please delete them first' => 'This menu has sub-menus, please delete them first',
'Timestamp expired or invalid, please sync time' => 'Timestamp expired or invalid, please sync time',

View File

@@ -254,6 +254,7 @@ return [
'This category has sub-categories, please delete them first' => '该部门下存在子分类,请先删除子分类',
'This department has sub-departments, please delete them first' => '该部门下存在子部门,请先删除子部门',
'This department has users, please delete or transfer them first' => '该部门下存在用户,请先删除或者转移用户',
'This channel has users, please delete or transfer them first' => '该渠道下存在用户,请先删除或者转移用户',
'This dict code already exists' => '该字典标识已存在',
'This menu has sub-menus, please delete them first' => '该菜单下存在子菜单,请先删除子菜单',
'Timestamp expired or invalid, please sync time' => '时间戳已过期或无效,请同步时间',