[色子游戏]玩家抽奖记录-新增字段保存中奖详情记录信息
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user