60 lines
1.9 KiB
PHP
60 lines
1.9 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | saiadmin [ saiadmin快速开发框架 ]
|
||
// +----------------------------------------------------------------------
|
||
// | Author: your name
|
||
// +----------------------------------------------------------------------
|
||
namespace app\dice\validate\reward_config;
|
||
|
||
use plugin\saiadmin\basic\BaseValidate;
|
||
|
||
/**
|
||
* 奖励配置验证器(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',
|
||
'n_start_index' => 'number',
|
||
's_start_index' => 'number',
|
||
];
|
||
|
||
protected $message = [
|
||
'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', 'n_start_index', 's_start_index'],
|
||
'update' => ['grid_number', 'ui_text', 'real_ev', 'tier', 'weight', 'n_start_index', 's_start_index'],
|
||
];
|
||
|
||
/**
|
||
* weight:1-10000
|
||
*/
|
||
protected function checkWeight($value, $rule = '', $data = []): bool
|
||
{
|
||
$num = is_numeric($value) ? (int) $value : null;
|
||
if ($num === null) {
|
||
return false;
|
||
}
|
||
if ($num < self::WEIGHT_MIN || $num > self::WEIGHT_MAX) {
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
}
|