重新优化中奖权重计算方式

This commit is contained in:
2026-03-11 15:40:15 +08:00
parent bb166350fd
commit 2af7fedcce
13 changed files with 330 additions and 322 deletions

View File

@@ -9,55 +9,49 @@ namespace app\dice\validate\reward_config;
use plugin\saiadmin\basic\BaseValidate;
/**
* 奖励配置验证器
* weight 仅当 tier=BIGWIN 时可设定,且严格限制 0-100%
* 奖励配置验证器DiceRewardConfig
* weight 1-10000各档位权重和不限制
*/
class DiceRewardConfigValidate extends BaseValidate
{
/**
* 定义验证规则
*/
private const WEIGHT_MIN = 1;
private const WEIGHT_MAX = 10000;
protected $rule = [
'grid_number' => 'require',
'ui_text' => 'require',
'real_ev' => 'require',
'tier' => 'require',
'weight' => 'checkWeight',
'grid_number' => 'require',
'ui_text' => 'require',
'real_ev' => 'require',
'tier' => 'require',
'weight' => 'checkWeight',
'n_start_index' => 'number',
's_start_index' => 'number',
];
/**
* 定义错误信息
*/
protected $message = [
'grid_number' => '色子点数必须填写',
'ui_text' => '前端显示文本必须填写',
'real_ev' => '真实资金结算必须填写',
'tier' => '所属档位必须填写',
'weight' => '权重仅 tier=BIGWIN 时可设定,且必须为 0-100',
'grid_number' => '色子点数必须填写',
'ui_text' => '前端显示文本必须填写',
'real_ev' => '真实资金结算必须填写',
'tier' => '所属档位必须填写',
'weight' => '权重必须为 1-10000',
'n_start_index' => '逆时针起始索引须为数字',
's_start_index' => '顺时针起始索引须为数字',
];
/**
* 定义场景
*/
protected $scene = [
'save' => ['grid_number', 'ui_text', 'real_ev', 'tier', 'weight'],
'update' => ['grid_number', 'ui_text', 'real_ev', 'tier', 'weight'],
'save' => ['grid_number', 'ui_text', 'real_ev', 'tier', 'weight', 'n_start_index', 's_start_index'],
'update' => ['grid_number', 'ui_text', 'real_ev', 'tier', 'weight', 'n_start_index', 's_start_index'],
];
/**
* weight仅 tier=BIGWIN 时可设定,严格限制 0-100%
* weight1-10000
*/
protected function checkWeight($value, $rule = '', $data = []): bool
{
$tier = isset($data['tier']) ? (string) $data['tier'] : '';
if ($tier !== 'BIGWIN') {
return true;
}
$num = is_numeric($value) ? (float) $value : null;
$num = is_numeric($value) ? (int) $value : null;
if ($num === null) {
return false;
}
if ($num < 0 || $num > 100) {
if ($num < self::WEIGHT_MIN || $num > self::WEIGHT_MAX) {
return false;
}
return true;