1.新增默认彩金池配置

2.优化关联彩金池配置的名称显示
3.优化一键测试权重
4.优化底注配置
This commit is contained in:
2026-06-04 12:21:57 +08:00
parent 5d316ef7d6
commit dfb37dd33a
40 changed files with 845 additions and 177 deletions

View File

@@ -143,6 +143,8 @@ class PlayStartLogic
&& $poolProfitTotal >= $safetyLine
&& $configKill !== null;
$playerLinkedPool = $this->resolvePlayerLinkedPoolConfig($player, $configDeptId);
if ($ticketType === self::LOTTERY_TYPE_FREE) {
// 免费抽奖券:使用本渠道 name=free 奖池档位权重;无 free 时回退 default
$config = $configFree ?? $configType0;
@@ -151,9 +153,13 @@ class PlayStartLogic
$config = $configKill;
$usePoolWeights = true;
} else {
// 付费未触发杀分:按玩家 T*_weight 抽档lottery_config_id 记 default
// 付费未触发杀分:关联 playerDefault 时实时读该池权重;否则按玩家行内 T*_weight
$config = $configType0;
$usePoolWeights = false;
if ($playerLinkedPool !== null && $playerLinkedPool->isPlayerDefaultTemplate()) {
$usePoolWeights = true;
$config = $playerLinkedPool;
}
}
// 按档位 T1-T5 抽取后,从 DiceReward 表按当前方向取该档位数据,再按 weight 抽取一条得到 grid_number
@@ -263,6 +269,9 @@ class PlayStartLogic
$record = null;
$settledWinCoin = $winCoin;
$configId = (int) $config->id;
if ($ticketType === self::LOTTERY_TYPE_PAID && !$usePaidKill && $playerLinkedPool !== null) {
$configId = (int) $playerLinkedPool->id;
}
$type0ConfigId = (int) $configType0->id;
$rewardId = ($isWin === 1 && $superWinCoin > 0) ? 0 : $targetIndex; // 中豹子不记录原奖励配置 id
$configName = (string) ($config->name ?? '');
@@ -789,4 +798,24 @@ class PlayStartLogic
'grants_free_ticket' => $grantsFreeTicket,
];
}
/**
* 玩家已选彩金池配置(用于 playerDefault 运行时权重)
*/
private function resolvePlayerLinkedPoolConfig(DicePlayer $player, int $configDeptId): ?DiceLotteryPoolConfig
{
$linkedId = (int) ($player->lottery_config_id ?? 0);
if ($linkedId <= 0) {
return null;
}
$cfg = DiceLotteryPoolConfig::find($linkedId);
if (!$cfg) {
return null;
}
$poolDeptId = AdminScopeHelper::normalizeRecordDeptId($cfg->dept_id ?? null);
if ($poolDeptId !== AdminScopeHelper::normalizeRecordDeptId($configDeptId)) {
return null;
}
return $cfg;
}
}

View File

@@ -38,19 +38,23 @@ class DiceLotteryPoolConfigController extends BaseController
#[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:index')]
public function getOptions(Request $request): Response
{
$query = DiceLotteryPoolConfig::field('id,name,t1_weight,t2_weight,t3_weight,t4_weight,t5_weight')
$query = DiceLotteryPoolConfig::field('id,name,remark,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) {
$row = is_array($item) ? $item : $item->toArray();
$display = DiceLotteryPoolConfig::displayLabel($row);
return [
'id' => (int) $item['id'],
'name' => (string) ($item['name'] ?? ''),
't1_weight' => (int) ($item['t1_weight'] ?? 0),
't2_weight' => (int) ($item['t2_weight'] ?? 0),
't3_weight' => (int) ($item['t3_weight'] ?? 0),
't4_weight' => (int) ($item['t4_weight'] ?? 0),
't5_weight' => (int) ($item['t5_weight'] ?? 0),
'id' => (int) ($row['id'] ?? 0),
'name' => (string) ($row['name'] ?? ''),
'remark' => (string) ($row['remark'] ?? ''),
'display_name' => $display,
't1_weight' => (int) ($row['t1_weight'] ?? 0),
't2_weight' => (int) ($row['t2_weight'] ?? 0),
't3_weight' => (int) ($row['t3_weight'] ?? 0),
't4_weight' => (int) ($row['t4_weight'] ?? 0),
't5_weight' => (int) ($row['t5_weight'] ?? 0),
];
})->toArray();
return $this->success($data);

View File

@@ -92,7 +92,7 @@ class DicePlayRecordController extends BaseController
#[Permission('玩家抽奖记录列表', 'dice:play_record:index:index')]
public function getLotteryConfigOptions(Request $request): Response
{
$query = DiceLotteryPoolConfig::field('id,name')->order('id', 'asc');
$query = DiceLotteryPoolConfig::field('id,name,remark')->order('id', 'asc');
$requestDeptId = AdminScopeHelper::pickRequestDeptId(
$request->input('dept_id'),
$request->all()
@@ -100,7 +100,13 @@ class DicePlayRecordController extends BaseController
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $requestDeptId);
$list = $query->select();
$data = $list->map(function ($item) {
return ['id' => (int) $item['id'], 'name' => (string) ($item['name'] ?? '')];
$row = is_array($item) ? $item : $item->toArray();
return [
'id' => (int) ($row['id'] ?? 0),
'name' => (string) ($row['name'] ?? ''),
'remark' => (string) ($row['remark'] ?? ''),
'display_name' => DiceLotteryPoolConfig::displayLabel($row),
];
})->toArray();
return $this->success($data);
}

View File

@@ -43,7 +43,7 @@ class DicePlayerController extends BaseController
#[Permission('玩家列表', 'dice:player:index:index')]
public function getLotteryConfigOptions(Request $request): Response
{
$query = DiceLotteryPoolConfig::field('id,name')->order('id', 'asc');
$query = DiceLotteryPoolConfig::field('id,name,remark')->order('id', 'asc');
$requestDeptId = AdminScopeHelper::pickRequestDeptId(
$request->input('dept_id'),
$request->all()
@@ -51,7 +51,13 @@ class DicePlayerController extends BaseController
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $requestDeptId);
$list = $query->select();
$data = $list->map(function ($item) {
return ['id' => (int) $item['id'], 'name' => (string) ($item['name'] ?? '')];
$row = is_array($item) ? $item : $item->toArray();
return [
'id' => (int) ($row['id'] ?? 0),
'name' => (string) ($row['name'] ?? ''),
'remark' => (string) ($row['remark'] ?? ''),
'display_name' => DiceLotteryPoolConfig::displayLabel($row),
];
})->toArray();
return $this->success($data);
}

View File

@@ -116,6 +116,7 @@ class DiceRewardController extends BaseController
'test_safety_line' => $post['test_safety_line'] ?? null,
'dept_id' => $post['dept_id'] ?? null,
'ante_config_id' => $post['ante_config_id'] ?? null,
'ante_random' => $post['ante_random'] ?? null,
];
$adminId = isset($this->adminInfo['id']) ? (int) $this->adminInfo['id'] : null;
$requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), $post);

View File

@@ -24,6 +24,7 @@ class DiceAnteConfigLogic extends DiceBaseLogic
public function add(array $data): mixed
{
return $this->transaction(function () use ($data) {
$this->applyNameTitleFromMult($data);
$this->normalizeDefaultField($data);
$deptId = AdminScopeHelper::resolveConfigDeptId(null, $data['dept_id'] ?? AdminScopeHelper::DEFAULT_TEMPLATE_DEPT);
if ((int) ($data['is_default'] ?? 0) === 1) {
@@ -38,6 +39,7 @@ class DiceAnteConfigLogic extends DiceBaseLogic
$pickedDeptId = AdminScopeHelper::pickRequestDeptId($requestDeptId, $data);
$deptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $pickedDeptId);
return $this->transaction(function () use ($id, $data, $deptId, $adminInfo, $pickedDeptId) {
$this->applyNameTitleFromMult($data);
$this->normalizeDefaultField($data);
if ((int) ($data['is_default'] ?? 0) === 1) {
$this->clearOtherDefaults((int) $id, $deptId);
@@ -92,6 +94,21 @@ class DiceAnteConfigLogic extends DiceBaseLogic
$data['is_default'] = ((int) $data['is_default']) === 1 ? 1 : 0;
}
/** 名称、标题随底注倍率自动设为 xN */
private function applyNameTitleFromMult(array &$data): void
{
if (!array_key_exists('mult', $data)) {
return;
}
$mult = (int) $data['mult'];
if ($mult <= 0) {
return;
}
$label = 'x' . $mult;
$data['name'] = $label;
$data['title'] = $label;
}
private function clearOtherDefaults(?int $excludeId = null, int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): void
{
$query = $this->model->where('is_default', 1);

View File

@@ -598,41 +598,100 @@ class DiceRewardLogic
if ($configCw !== null) {
$tier = isset($configCw['tier']) ? trim((string) $configCw['tier']) : '';
if ($tier !== '') {
$rows[] = [
'tier' => $tier,
'direction' => DiceReward::DIRECTION_CLOCKWISE,
'weight' => self::WEIGHT_MIN,
'grid_number' => $gridNumber,
'start_index' => $startId,
'end_index' => isset($configCw['id']) ? (int) $configCw['id'] : 0,
'ui_text' => $configCw['ui_text'] ?? '',
'real_ev' => $configCw['real_ev'] ?? null,
'remark' => $configCw['remark'] ?? '',
'type' => isset($configCw['type']) ? (int) $configCw['type'] : 0,
];
$rows[] = $this->buildReferenceRowFromLandingConfig(
$tier,
$configCw,
DiceReward::DIRECTION_CLOCKWISE,
$gridNumber,
$startId
);
}
}
if ($configCcw !== null) {
$tier = isset($configCcw['tier']) ? trim((string) $configCcw['tier']) : '';
if ($tier !== '') {
$rows[] = [
'tier' => $tier,
'direction' => DiceReward::DIRECTION_COUNTERCLOCKWISE,
'weight' => self::WEIGHT_MIN,
'grid_number' => $gridNumber,
'start_index' => $startId,
'end_index' => isset($configCcw['id']) ? (int) $configCcw['id'] : 0,
'ui_text' => $configCcw['ui_text'] ?? '',
'real_ev' => $configCcw['real_ev'] ?? null,
'remark' => $configCcw['remark'] ?? '',
'type' => isset($configCcw['type']) ? (int) $configCcw['type'] : 0,
];
$rows[] = $this->buildReferenceRowFromLandingConfig(
$tier,
$configCcw,
DiceReward::DIRECTION_COUNTERCLOCKWISE,
$gridNumber,
$startId
);
}
}
}
return ['rows' => $rows, 'skipped' => $skipped];
}
/**
* 对照表落点行:档位按结算金额推断,备注与奖励配置页规则一致
*
* @param array<string, mixed> $landingConfig
* @return array<string, mixed>
*/
private function buildReferenceRowFromLandingConfig(
string $tier,
array $landingConfig,
int $direction,
int $gridNumber,
int $startId
): array {
$realEv = isset($landingConfig['real_ev']) ? (float) $landingConfig['real_ev'] : 0.0;
if ($tier !== 'BIGWIN') {
$inferred = $this->inferTierFromRealEv($realEv);
if ($inferred !== '') {
$tier = $inferred;
}
}
return [
'tier' => $tier,
'direction' => $direction,
'weight' => self::WEIGHT_MIN,
'grid_number' => $gridNumber,
'start_index' => $startId,
'end_index' => isset($landingConfig['id']) ? (int) $landingConfig['id'] : 0,
'ui_text' => $landingConfig['ui_text'] ?? '',
'real_ev' => $landingConfig['real_ev'] ?? null,
'remark' => $this->defaultRemarkForTier($tier),
'type' => isset($landingConfig['type']) ? (int) $landingConfig['type'] : 0,
];
}
/**
* 按结算金额推断档位(与前端 generateIndexByRules 一致)
*/
private function inferTierFromRealEv(float $realEv): string
{
if ($realEv > 2) {
return 'T1';
}
if ($realEv > 1) {
return 'T2';
}
if ($realEv > 0) {
return 'T3';
}
if ($realEv < 0) {
return 'T4';
}
return 'T5';
}
/**
* 档位默认备注
*/
private function defaultRemarkForTier(string $tier): string
{
return match ($tier) {
'T1', 'BIGWIN' => '大奖',
'T2' => '小赚',
'T3' => '抽水',
'T4' => '惩罚',
'T5' => '再来一次',
default => '',
};
}
/**
* 读出当前 dice_reward用于对比/复用权重。key = "direction:grid_number"
* @return array<string, array<string, mixed>>

View File

@@ -283,7 +283,12 @@ class DiceRewardConfigRecordLogic extends DiceBaseLogic
$paidN = isset($params['paid_n_count']) ? (int) $params['paid_n_count'] : 0;
$chainFreeMode = !empty($params['chain_free_mode']);
$killModeEnabled = !empty($params['kill_mode_enabled']);
$testSafetyLine = isset($params['test_safety_line']) ? (int) $params['test_safety_line'] : 5000;
if (array_key_exists('test_safety_line', $params) && $params['test_safety_line'] !== null && $params['test_safety_line'] !== '') {
$testSafetyLine = (int) $params['test_safety_line'];
} else {
$defaultPool = DiceLotteryPoolConfig::findByNameForDept('default', $deptId);
$testSafetyLine = (int) ($defaultPool->safety_line ?? 0);
}
if ($testSafetyLine < 0) {
throw new ApiException('test_safety_line must be greater than or equal to 0');
}
@@ -405,6 +410,9 @@ class DiceRewardConfigRecordLogic extends DiceBaseLogic
if ($chainFreeMode) {
$tierWeightsSnapshot['chain_free_mode'] = true;
}
if (!empty($params['ante_random'])) {
$tierWeightsSnapshot['ante_random'] = true;
}
$record = new DiceRewardConfigRecord();
$plannedPaidSpins = $paidS + $paidN;
@@ -494,6 +502,21 @@ class DiceRewardConfigRecordLogic extends DiceBaseLogic
*/
private function resolveWeightTestAnte(array $params, int $deptId): int
{
if (!empty($params['ante_random'])) {
$anteQuery = DiceAnteConfig::field('id,mult')->order('mult', 'asc');
ConfigScopeEditHelper::applyDeptIdWhere($anteQuery, $deptId);
$rows = $anteQuery->select()->toArray();
if ($rows === []) {
throw new ApiException('No ante config in current channel');
}
$picked = $rows[random_int(0, count($rows) - 1)];
$mult = (int) ($picked['mult'] ?? 0);
if ($mult <= 0) {
throw new ApiException('ANTE_MUST_POSITIVE');
}
return $mult;
}
$anteConfigId = isset($params['ante_config_id']) ? (int) $params['ante_config_id'] : 0;
if ($anteConfigId > 0) {
$config = DiceAnteConfig::find($anteConfigId);

View File

@@ -17,7 +17,8 @@ use app\dice\model\DiceModel;
*
* @property $id ID
* @property $name 名称
* @property $remark 备注
* @property $remark 奖池名称(后台展示名)
* @property $config_note 配置备注
* @property $safety_line 安全线
* @property $kill_enabled 是否启用杀分0=关闭 1=开启
* @property $create_time 创建时间
@@ -31,6 +32,9 @@ use app\dice\model\DiceModel;
*/
class DiceLotteryPoolConfig extends DiceModel
{
/** 玩家默认彩金池(新玩家关联;付费未杀分时运行时读取该池 T1T5 权重) */
public const NAME_PLAYER_DEFAULT = 'playerDefault';
/**
* 数据表主键
* @var string
@@ -43,6 +47,9 @@ class DiceLotteryPoolConfig extends DiceModel
*/
protected $table = 'dice_lottery_pool_config';
/** 列表/关联 JSON 附带奖池展示名 */
protected $append = ['display_name'];
/**
* 按名称与渠道查找奖池配置(一键测试等场景,避免命中其他渠道同名配置)
*/
@@ -53,12 +60,57 @@ class DiceLotteryPoolConfig extends DiceModel
return $query->find();
}
/**
* 是否玩家默认模板池(运行时按该池权重抽档,改池配置即对所有关联玩家生效)
*/
public function isPlayerDefaultTemplate(): bool
{
return (string) ($this->name ?? '') === self::NAME_PLAYER_DEFAULT;
}
/**
* 后台展示用奖池名称:优先 remark否则 name
*
* @param array<string, mixed>|self $row
*/
public static function displayLabel($row): string
{
// 禁止对模型实例 toArray()append display_name 会再次触发本方法,导致内存耗尽
if ($row instanceof self) {
$data = $row->getData();
$remark = trim((string) ($data['remark'] ?? ''));
if ($remark !== '') {
return $remark;
}
return trim((string) ($data['name'] ?? ''));
}
$remark = trim((string) ($row['remark'] ?? ''));
if ($remark !== '') {
return $remark;
}
return trim((string) ($row['name'] ?? ''));
}
public function getDisplayNameAttr(): string
{
$data = $this->getData();
$remark = trim((string) ($data['remark'] ?? ''));
if ($remark !== '') {
return $remark;
}
return trim((string) ($data['name'] ?? ''));
}
/**
* 名称 搜索
*/
public function searchNameAttr($query, $value)
{
$query->where('name', 'like', '%'.$value.'%');
$like = '%' . $value . '%';
$query->where(function ($q) use ($like) {
$q->where('name', 'like', $like)
->whereOr('remark', 'like', $like);
});
}
}

View File

@@ -88,13 +88,17 @@ class DicePlayRecord extends DiceModel
}
}
/** 按彩金池配置名称模糊diceLotteryPoolConfig.name */
/** 按彩金池奖池名称或内部标识模糊搜索 */
public function searchLotteryConfigNameAttr($query, $value)
{
if ($value === '' || $value === null) {
return;
}
$ids = DiceLotteryPoolConfig::where('name', 'like', '%' . $value . '%')->column('id');
$like = '%' . $value . '%';
$ids = DiceLotteryPoolConfig::where(function ($q) use ($like) {
$q->where('name', 'like', $like)
->whereOr('remark', 'like', $like);
})->column('id');
if (!empty($ids)) {
$query->whereIn('lottery_config_id', $ids);
} else {

View File

@@ -6,6 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\model\player;
use app\dice\helper\AdminScopeHelper;
use app\dice\model\DiceModel;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
@@ -84,44 +85,61 @@ class DicePlayer extends DiceModel
if ($name === null || $name === '') {
$model->setAttr('name', $uid);
}
// 创建玩家时:未指定则自动保存 lottery_config_id 为 DiceLotteryPoolConfig name=default 的 id,没有则为 0
// 创建玩家时:未指定则关联 name=playerDefault玩家默认彩金池,没有则为 0
try {
$lotteryConfigId = $model->getAttr('lottery_config_id');
} catch (\Throwable $e) {
$lotteryConfigId = null;
}
if ($lotteryConfigId === null || $lotteryConfigId === '' || (int) $lotteryConfigId === 0) {
$config = self::findDefaultLotteryConfigForPlayer($model);
$config = self::findPlayerDefaultLotteryConfigForPlayer($model);
$model->setAttr('lottery_config_id', $config ? (int) $config->id : 0);
}
// 彩金池权重默认取 name=default 的奖池配置
// 展示用权重从玩家关联的彩金池复制playerDefault 在抽奖时仍实时读池配置
self::setDefaultWeightsFromLotteryConfig($model);
}
/**
* 按玩家所属渠道查找 default 彩金池配置
* 按玩家所属渠道查找玩家默认彩金池name=playerDefault
*/
protected static function findDefaultLotteryConfigForPlayer(DicePlayer $model): ?DiceLotteryPoolConfig
protected static function findPlayerDefaultLotteryConfigForPlayer(DicePlayer $model): ?DiceLotteryPoolConfig
{
$query = DiceLotteryPoolConfig::where('name', 'default');
try {
$deptId = $model->getAttr('dept_id');
if ($deptId !== null && $deptId !== '' && $deptId > 0) {
$query->where('dept_id', $deptId);
}
} catch (\Throwable $e) {
// ignore
$deptId = null;
}
return $query->find();
$normalizedDeptId = AdminScopeHelper::resolvePlayerConfigDeptId($model);
if ($deptId !== null && $deptId !== '' && (int) $deptId > 0) {
$normalizedDeptId = (int) $deptId;
}
$config = DiceLotteryPoolConfig::findByNameForDept(
DiceLotteryPoolConfig::NAME_PLAYER_DEFAULT,
$normalizedDeptId
);
if ($config) {
return $config;
}
return DiceLotteryPoolConfig::findByNameForDept('default', $normalizedDeptId);
}
/**
* 从 DiceLotteryPoolConfig name=default 取 t1_weightt5_weight 作为玩家未设置时的默认值
* 从玩家关联彩金池(或 playerDefault / default取 t1_weightt5_weight 作为未设置时的默认值
*/
protected static function setDefaultWeightsFromLotteryConfig(DicePlayer $model): void
{
$config = self::findDefaultLotteryConfigForPlayer($model);
$config = null;
try {
$lotteryConfigId = (int) $model->getAttr('lottery_config_id');
} catch (\Throwable $e) {
$lotteryConfigId = 0;
}
if ($lotteryConfigId > 0) {
$config = DiceLotteryPoolConfig::find($lotteryConfigId);
}
if (!$config) {
$config = self::findPlayerDefaultLotteryConfigForPlayer($model);
}
if (!$config) {
return;
}

View File

@@ -5,6 +5,7 @@ namespace app\dice\service;
use app\dice\helper\AdminScopeHelper;
use app\dice\logic\reward\DiceRewardLogic;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\reward\DiceReward;
use app\dice\model\reward_config\DiceRewardConfig;
use plugin\saiadmin\app\model\system\SystemDept;
@@ -209,9 +210,99 @@ class DiceChannelConfigService
}
$this->ensureRewardReferenceForDept($deptId);
DiceRewardConfig::refreshCache($deptId);
$this->ensurePlayerDefaultPoolForDept($deptId);
$this->migratePlayersDefaultPoolToPlayerDefault($deptId);
return $result;
}
/**
* 为渠道补齐玩家默认彩金池 name=playerDefault权重复制自 default
*/
public function ensurePlayerDefaultPoolForDept(int $deptId): ?int
{
if (!$this->tableHasColumn('dice_lottery_pool_config', 'dept_id')) {
return null;
}
$exists = Db::table('dice_lottery_pool_config')
->where('dept_id', $deptId)
->where('name', DiceLotteryPoolConfig::NAME_PLAYER_DEFAULT)
->count();
if ($exists > 0) {
return (int) Db::table('dice_lottery_pool_config')
->where('dept_id', $deptId)
->where('name', DiceLotteryPoolConfig::NAME_PLAYER_DEFAULT)
->value('id');
}
$defaultRow = Db::table('dice_lottery_pool_config')
->where('dept_id', $deptId)
->where('name', 'default')
->find();
if (!$defaultRow) {
return null;
}
$defaultRow = (array) $defaultRow;
unset($defaultRow['id'], $defaultRow['row_id'], $defaultRow['create_time'], $defaultRow['update_time'], $defaultRow['delete_time']);
$defaultRow['name'] = DiceLotteryPoolConfig::NAME_PLAYER_DEFAULT;
$defaultRow['remark'] = '默认';
$defaultRow['safety_line'] = 0;
$defaultRow['kill_enabled'] = 0;
$defaultRow['profit_amount'] = 0;
$defaultRow['dept_id'] = $deptId;
return (int) Db::table('dice_lottery_pool_config')->insertGetId($defaultRow);
}
/**
* 将仍关联 name=default 的玩家改为关联 playerDefault杀分逻辑仍用 default 池)
*/
public function migratePlayersDefaultPoolToPlayerDefault(int $deptId): int
{
if (!$this->tableHasColumn('dice_player', 'dept_id')
|| !$this->tableHasColumn('dice_player', 'lottery_config_id')) {
return 0;
}
$playerDefaultId = Db::table('dice_lottery_pool_config')
->where('dept_id', $deptId)
->where('name', DiceLotteryPoolConfig::NAME_PLAYER_DEFAULT)
->value('id');
if (!$playerDefaultId) {
return 0;
}
$defaultPoolId = Db::table('dice_lottery_pool_config')
->where('dept_id', $deptId)
->where('name', 'default')
->value('id');
if (!$defaultPoolId) {
return 0;
}
return Db::table('dice_player')
->where('dept_id', $deptId)
->where('lottery_config_id', (int) $defaultPoolId)
->update(['lottery_config_id' => (int) $playerDefaultId]);
}
/**
* 为全部渠道与默认模板补齐 playerDefault 奖池并迁移玩家关联
*/
public function ensurePlayerDefaultPoolsAllChannels(): array
{
$deptIds = [AdminScopeHelper::DEFAULT_TEMPLATE_DEPT];
foreach (SystemDept::column('id') as $id) {
$id = (int) $id;
if ($id > 0) {
$deptIds[] = $id;
}
}
$deptIds = array_values(array_unique($deptIds));
$summary = [];
foreach ($deptIds as $deptId) {
$summary[$deptId] = [
'pool_id' => $this->ensurePlayerDefaultPoolForDept($deptId),
'players_migrated' => $this->migratePlayersDefaultPoolToPlayerDefault($deptId),
];
}
return $summary;
}
/**
* 按业务 id 从默认模板补齐配置dice_config / dice_reward_config
*/
@@ -297,6 +388,7 @@ class DiceChannelConfigService
}
$summary[$deptId] = $this->copyDefaultConfigToDept($deptId);
}
$summary['_player_default_pools'] = $this->ensurePlayerDefaultPoolsAllChannels();
return $summary;
}

View File

@@ -18,6 +18,8 @@ class DiceLotteryPoolConfigValidate extends BaseValidate
*/
protected $rule = [
'name' => 'require',
'remark' => 'max:200',
'config_note' => 'max:500',
't1_weight' => 'require',
't2_weight' => 'require',
't3_weight' => 'require',
@@ -43,6 +45,8 @@ class DiceLotteryPoolConfigValidate extends BaseValidate
protected $scene = [
'save' => [
'name',
'remark',
'config_note',
't1_weight',
't2_weight',
't3_weight',
@@ -51,6 +55,8 @@ class DiceLotteryPoolConfigValidate extends BaseValidate
],
'update' => [
'name',
'remark',
'config_note',
't1_weight',
't2_weight',
't3_weight',