修改DiceLotteryPoolConfig-type改为name映射

This commit is contained in:
2026-03-17 17:09:10 +08:00
parent d4cf708bc1
commit e7b8f4cae9
18 changed files with 64 additions and 115 deletions

View File

@@ -39,9 +39,9 @@ return [
'配置ID %s 不存在或档位为空' => 'Config ID %s not found or tier is empty',
'该方向下暂无可用路径配置' => 'No path config available for this direction',
// Dice / pool config
'奖池配置不存在(需 type=0' => 'Lottery pool config not found (type=0 required)',
'奖池配置不存在(需 name=default' => 'Lottery pool config not found (name=default required)',
'暂无可用奖励配置' => 'No available reward config',
'未找到 type=0 的奖池配置,请先创建' => 'No type=0 pool config found, please create one first',
'未找到 name=default 的奖池配置,请先创建' => 'No name=default pool config found, please create one first',
// Dice / wallet & tickets
'参数错误:需要有效的 player_id 和 type3=加点4=扣点)' => 'Invalid params: player_id and type are required (3=add, 4=deduct)',
'平台币变动必须大于 0' => 'Coin change must be greater than 0',

View File

@@ -71,10 +71,10 @@ class PlayStartLogic
$lotteryService = LotteryService::getOrCreate($playerId);
$ticketType = LotteryService::drawTicketType($paid, $free);
$configType0 = DiceLotteryPoolConfig::where('type', 0)->find();
$configType1 = DiceLotteryPoolConfig::where('type', 1)->find();
$configType0 = DiceLotteryPoolConfig::where('name', 'default')->find();
$configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->find();
if (!$configType0) {
throw new ApiException('奖池配置不存在(需 type=0');
throw new ApiException('奖池配置不存在(需 name=default');
}
// 玩家累计盈利:仅统计 lottery_config_id=type=0 的成功对局(中奖金额-100*局数)

View File

@@ -56,8 +56,8 @@ class LotteryService
if (!$player) {
throw new \RuntimeException('玩家不存在');
}
$config0 = DiceLotteryPoolConfig::where('type', 0)->find();
$config1 = DiceLotteryPoolConfig::where('type', 1)->find();
$config0 = DiceLotteryPoolConfig::where('name', 'default')->find();
$config1 = DiceLotteryPoolConfig::where('name', 'killScore')->find();
$s = new self($playerId);
$s->configType0Id = $config0 ? (int) $config0->id : null;
$s->configType1Id = $config1 ? (int) $config1->id : null;

View File

@@ -30,22 +30,20 @@ class DiceLotteryPoolConfigController extends BaseController
}
/**
* 获取 DiceLotteryPoolConfig 列表数据,用于 lottery_config_id 下拉(值为 id显示为 name并附带 type、T1-T5 档位权重
* type0=付费抽奖券1=免费抽奖券;一键测试权重中付费默认选 type=0免费默认选 type=1
* 获取 DiceLotteryPoolConfig 列表数据,用于 lottery_config_id 下拉(值为 id显示为 name并附带 T1-T5 档位权重
* @param Request $request
* @return Response 返回 [ ['id' => int, 'name' => string, 'type' => int, 't1_weight' => int, ... 't5_weight' => int], ... ]
* @return Response 返回 [ ['id' => int, 'name' => string, 't1_weight' => int, ... 't5_weight' => int], ... ]
*/
#[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:index')]
public function getOptions(Request $request): Response
{
$list = DiceLotteryPoolConfig::field('id,name,type,t1_weight,t2_weight,t3_weight,t4_weight,t5_weight')
$list = DiceLotteryPoolConfig::field('id,name,t1_weight,t2_weight,t3_weight,t4_weight,t5_weight')
->order('id', 'asc')
->select();
$data = $list->map(function ($item) {
return [
'id' => (int) $item['id'],
'name' => (string) ($item['name'] ?? ''),
'type' => (int) ($item['type'] ?? 0),
't1_weight' => (int) ($item['t1_weight'] ?? 0),
't2_weight' => (int) ($item['t2_weight'] ?? 0),
't3_weight' => (int) ($item['t3_weight'] ?? 0),

View File

@@ -38,11 +38,11 @@ class DiceLotteryPoolConfigLogic extends BaseLogic
*/
public function getCurrentPool(): array
{
$configType0 = DiceLotteryPoolConfig::where('type', 0)->find();
$configType0 = DiceLotteryPoolConfig::where('name', 'default')->find();
if (!$configType0) {
throw new ApiException('未找到 type=0 的奖池配置,请先创建');
throw new ApiException('未找到 name=default 的奖池配置,请先创建');
}
$configType1 = DiceLotteryPoolConfig::where('type', 1)->find();
$configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->find();
$row0 = $configType0->toArray();
$profitAmount = isset($row0['profit_amount']) ? (float) $row0['profit_amount'] : (isset($row0['ev']) ? (float) $row0['ev'] : 0.0);
$pool = [

View File

@@ -333,7 +333,7 @@ class DiceRewardConfigLogic extends BaseLogic
$config = DiceLotteryPoolConfig::find($lotteryConfigId);
}
if (!$config) {
$config = DiceLotteryPoolConfig::where('type', 0)->find();
$config = DiceLotteryPoolConfig::where('name', 'default')->find();
}
if ($config) {
$tierWeights = [

View File

@@ -16,7 +16,6 @@ use plugin\saiadmin\basic\think\BaseModel;
* @property $id ID
* @property $name 名称
* @property $remark 备注
* @property $type 奖池类型
* @property $safety_line 安全线
* @property $kill_enabled 是否启用杀分0=关闭 1=开启
* @property $create_time 创建时间
@@ -50,13 +49,4 @@ class DiceLotteryPoolConfig extends BaseModel
$query->where('name', 'like', '%'.$value.'%');
}
/**
* 奖池类型 搜索type=0/1/2 等)
*/
public function searchTypeAttr($query, $value)
{
if ($value !== '' && $value !== null) {
$query->where('type', '=', $value);
}
}
}

View File

@@ -78,26 +78,26 @@ class DicePlayer extends BaseModel
if ($name === null || $name === '') {
$model->setAttr('name', $uid);
}
// 创建玩家时:未指定则自动保存 lottery_config_id 为 DiceLotteryPoolConfig type=0 的 id没有则为 0
// 创建玩家时:未指定则自动保存 lottery_config_id 为 DiceLotteryPoolConfig name=default 的 id没有则为 0
try {
$lotteryConfigId = $model->getAttr('lottery_config_id');
} catch (\Throwable $e) {
$lotteryConfigId = null;
}
if ($lotteryConfigId === null || $lotteryConfigId === '' || (int) $lotteryConfigId === 0) {
$config = DiceLotteryPoolConfig::where('type', 0)->find();
$config = DiceLotteryPoolConfig::where('name', 'default')->find();
$model->setAttr('lottery_config_id', $config ? (int) $config->id : 0);
}
// 彩金池权重默认取 type=0 的奖池配置
// 彩金池权重默认取 name=default 的奖池配置
self::setDefaultWeightsFromLotteryConfig($model);
}
/**
* 从 DiceLotteryPoolConfig type=0 取 t1_weightt5_weight 作为玩家未设置时的默认值
* 从 DiceLotteryPoolConfig name=default 取 t1_weightt5_weight 作为玩家未设置时的默认值
*/
protected static function setDefaultWeightsFromLotteryConfig(DicePlayer $model): void
{
$config = DiceLotteryPoolConfig::where('type', 0)->find();
$config = DiceLotteryPoolConfig::where('name', 'default')->find();
if (!$config) {
return;
}