[色子游戏]玩家抽奖记录-新增字段保存中奖详情记录信息
This commit is contained in:
@@ -48,6 +48,7 @@ class DicePlayRecordController extends BaseController
|
||||
['win_coin_max', ''],
|
||||
['reward_ui_text', ''],
|
||||
['reward_tier', ''],
|
||||
['direction', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$query->with([
|
||||
|
||||
@@ -24,4 +24,36 @@ class DicePlayRecordLogic extends BaseLogic
|
||||
$this->model = new DicePlayRecord();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加前:roll_array 转为 JSON 字符串(数据库为 string 类型)
|
||||
*/
|
||||
public function add(array $data): mixed
|
||||
{
|
||||
$data = $this->normalizeRollArray($data);
|
||||
return parent::add($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改前:roll_array 转为 JSON 字符串(数据库为 string 类型)
|
||||
*/
|
||||
public function edit($id, array $data): mixed
|
||||
{
|
||||
$data = $this->normalizeRollArray($data);
|
||||
return parent::edit($id, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 roll_array 从数组转为 JSON 字符串
|
||||
*/
|
||||
private function normalizeRollArray(array $data): array
|
||||
{
|
||||
if (!array_key_exists('roll_array', $data)) {
|
||||
return $data;
|
||||
}
|
||||
$val = $data['roll_array'];
|
||||
if (is_array($val)) {
|
||||
$data['roll_array'] = json_encode($val, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,12 @@ use think\model\relation\BelongsTo;
|
||||
* @property $lottery_type 抽奖类型
|
||||
* @property $is_win 中奖
|
||||
* @property $win_coin 赢取平台币
|
||||
* @property $direction 方向:0=顺时针,1=逆时针
|
||||
* @property $reward_config_id 奖励配置id
|
||||
* @property $lottery_id 奖池
|
||||
* @property $start_index 起始索引
|
||||
* @property $target_index 结束索引
|
||||
* @property $roll_array 摇取点数,格式:[1,2,3,4,5,6]
|
||||
* @property $lottery_name 奖池名
|
||||
* @property $create_time 创建时间
|
||||
* @property $update_time 修改时间
|
||||
@@ -157,4 +161,12 @@ class DicePlayRecord extends BaseModel
|
||||
$query->whereRaw('1=0');
|
||||
}
|
||||
}
|
||||
|
||||
/** 方向 0=顺时针 1=逆时针 */
|
||||
public function searchDirectionAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('direction', '=', $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ class DicePlayRecordValidate extends BaseValidate
|
||||
'is_win' => 'require',
|
||||
'win_coin' => 'require',
|
||||
'reward_config_id' => 'require',
|
||||
'roll_array' => 'require|checkRollArray',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -35,6 +36,7 @@ class DicePlayRecordValidate extends BaseValidate
|
||||
'is_win' => '中奖必须填写',
|
||||
'win_coin' => '赢取平台币必须填写',
|
||||
'reward_config_id' => '奖励配置必须填写',
|
||||
'roll_array.require' => '摇取点数必须填写',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -48,6 +50,7 @@ class DicePlayRecordValidate extends BaseValidate
|
||||
'is_win',
|
||||
'win_coin',
|
||||
'reward_config_id',
|
||||
'roll_array',
|
||||
],
|
||||
'update' => [
|
||||
'player_id',
|
||||
@@ -56,7 +59,36 @@ class DicePlayRecordValidate extends BaseValidate
|
||||
'is_win',
|
||||
'win_coin',
|
||||
'reward_config_id',
|
||||
'roll_array',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* 验证 roll_array:必须为 6 个元素,每个值在 1~6 之间
|
||||
* @param mixed $value
|
||||
* @param mixed $rule
|
||||
* @param array $data
|
||||
* @param string $field
|
||||
* @return bool|string
|
||||
*/
|
||||
protected function checkRollArray($value, $rule = '', array $data = [], string $field = '')
|
||||
{
|
||||
if (is_string($value)) {
|
||||
$decoded = json_decode($value, true);
|
||||
$value = is_array($decoded) ? $decoded : [];
|
||||
}
|
||||
if (!is_array($value)) {
|
||||
return '摇取点数必须为数组';
|
||||
}
|
||||
if (count($value) !== 6) {
|
||||
return '摇取点数必须为 6 个数';
|
||||
}
|
||||
foreach ($value as $i => $n) {
|
||||
$v = is_numeric($n) ? (int) $n : null;
|
||||
if ($v === null || $v < 1 || $v > 6) {
|
||||
return '摇取点数第' . ($i + 1) . '个值必须在 1~6 之间';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user