1.将部门修改为渠道,并且所有dice_表关联渠道表
2.将所有配置表,记录表设置关联渠道 3.优化后台页面设置
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user