[游戏管理]-游戏奖励配置
This commit is contained in:
143
app/common/validate/GameRewardConfig.php
Normal file
143
app/common/validate/GameRewardConfig.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class GameRewardConfig extends Validate
|
||||
{
|
||||
protected $failException = true;
|
||||
|
||||
/**
|
||||
* 验证规则
|
||||
*/
|
||||
protected $rule = [
|
||||
'game_channel_id' => 'require|integer|gt:0',
|
||||
'tier_reward_form' => 'require|checkTierRewardForm',
|
||||
'bigwin_form' => 'require|checkBigwinForm',
|
||||
];
|
||||
|
||||
/**
|
||||
* 提示消息
|
||||
*/
|
||||
protected $message = [
|
||||
'game_channel_id.require' => '请选择渠道',
|
||||
'game_channel_id.integer' => '渠道参数格式错误',
|
||||
'game_channel_id.gt' => '渠道参数格式错误',
|
||||
'tier_reward_form.require' => '档位奖励表单不能为空',
|
||||
'bigwin_form.require' => '超级大奖表单不能为空',
|
||||
];
|
||||
|
||||
/**
|
||||
* 验证场景
|
||||
*/
|
||||
protected $scene = [
|
||||
'add' => ['game_channel_id', 'tier_reward_form', 'bigwin_form'],
|
||||
'edit' => ['game_channel_id', 'tier_reward_form', 'bigwin_form'],
|
||||
];
|
||||
|
||||
private function parseJsonArray(mixed $value, string $label): array|string
|
||||
{
|
||||
if (!is_string($value) || trim($value) === '') {
|
||||
return $label . '不能为空';
|
||||
}
|
||||
|
||||
try {
|
||||
$decoded = json_decode($value, true, 512, JSON_THROW_ON_ERROR);
|
||||
} catch (\Throwable $e) {
|
||||
return $label . '必须为合法 JSON';
|
||||
}
|
||||
|
||||
if (!is_array($decoded)) {
|
||||
return $label . '格式错误';
|
||||
}
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
protected function checkTierRewardForm($value, $rule, array $data = []): bool|string
|
||||
{
|
||||
$decoded = $this->parseJsonArray($value, '档位奖励表单');
|
||||
if (!is_array($decoded)) {
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
$expectedGrid = range(5, 30);
|
||||
if (count($decoded) !== 26) {
|
||||
return '档位奖励表单必须固定 26 条';
|
||||
}
|
||||
$allowTiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
|
||||
foreach ($decoded as $idx => $row) {
|
||||
$rowNo = $idx + 1;
|
||||
if (!is_array($row)) {
|
||||
return '档位奖励表单第' . $rowNo . '条格式错误';
|
||||
}
|
||||
$gridNumber = $row['grid_number'] ?? null;
|
||||
$uiText = $row['ui_text'] ?? null;
|
||||
$realEv = $row['real_ev'] ?? null;
|
||||
$tier = $row['tier'] ?? null;
|
||||
|
||||
if (!is_numeric($gridNumber)) {
|
||||
return '档位奖励表单第' . $rowNo . '条点数必须为数字';
|
||||
}
|
||||
$gridInt = intval(strval($gridNumber));
|
||||
if ($gridInt !== $expectedGrid[$idx]) {
|
||||
return '档位奖励表单点数必须固定为 5-30 且不可修改';
|
||||
}
|
||||
if (!is_string($uiText) || trim($uiText) === '') {
|
||||
return '档位奖励表单第' . $rowNo . '条显示文本不能为空';
|
||||
}
|
||||
if ($realEv === null || $realEv === '' || !is_numeric($realEv)) {
|
||||
return '档位奖励表单第' . $rowNo . '条实际中奖必须为数字';
|
||||
}
|
||||
if (!is_string($tier) || !in_array($tier, $allowTiers, true)) {
|
||||
return '档位奖励表单第' . $rowNo . '条档位只能是 T1-T5';
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function checkBigwinForm($value, $rule, array $data = []): bool|string
|
||||
{
|
||||
$decoded = $this->parseJsonArray($value, '超级大奖表单');
|
||||
if (!is_array($decoded)) {
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
$expectedGrid = [5, 10, 15, 20, 25, 30];
|
||||
if (count($decoded) !== 6) {
|
||||
return '超级大奖表单必须固定 6 条';
|
||||
}
|
||||
foreach ($decoded as $idx => $row) {
|
||||
$rowNo = $idx + 1;
|
||||
if (!is_array($row)) {
|
||||
return '超级大奖表单第' . $rowNo . '条格式错误';
|
||||
}
|
||||
|
||||
$gridNumber = $row['grid_number'] ?? null;
|
||||
$uiText = $row['ui_text'] ?? null;
|
||||
$realEv = $row['real_ev'] ?? null;
|
||||
$tier = $row['tier'] ?? null;
|
||||
|
||||
if (!is_numeric($gridNumber)) {
|
||||
return '超级大奖表单第' . $rowNo . '条点数必须为数字';
|
||||
}
|
||||
$gridInt = intval(strval($gridNumber));
|
||||
if ($gridInt !== $expectedGrid[$idx]) {
|
||||
return '超级大奖表单点数必须固定为 5、10、15、20、25、30 且不可修改';
|
||||
}
|
||||
|
||||
if (!is_string($uiText) || trim($uiText) === '') {
|
||||
return '超级大奖表单第' . $rowNo . '条显示文本不能为空';
|
||||
}
|
||||
if ($realEv === null || $realEv === '' || !is_numeric($realEv)) {
|
||||
return '超级大奖表单第' . $rowNo . '条实际中奖必须为数字';
|
||||
}
|
||||
if (!is_string($tier) || $tier !== 'BIGWIN') {
|
||||
return '超级大奖表单第' . $rowNo . '条档位必须为 BIGWIN';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user