优化游玩记录DicePlayRecord
This commit is contained in:
@@ -43,16 +43,18 @@ class DicePlayRecordLogic extends BaseLogic
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 roll_array 从数组转为 JSON 字符串
|
||||
* 将 roll_array 转为 JSON 字符串,并确保 roll_number 与摇取点数一致
|
||||
*/
|
||||
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);
|
||||
if (array_key_exists('roll_array', $data)) {
|
||||
$val = $data['roll_array'];
|
||||
if (is_array($val)) {
|
||||
$data['roll_array'] = json_encode($val, JSON_UNESCAPED_UNICODE);
|
||||
if (!isset($data['roll_number'])) {
|
||||
$data['roll_number'] = array_sum($val);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ use app\dice\model\reward_config\DiceRewardConfig;
|
||||
|
||||
/**
|
||||
* 奖励配置逻辑层
|
||||
* weight 仅 tier=BIGWIN 时可设定,保存时非 BIGWIN 强制 weight=0
|
||||
*/
|
||||
class DiceRewardConfigLogic extends BaseLogic
|
||||
{
|
||||
@@ -24,4 +25,36 @@ class DiceRewardConfigLogic extends BaseLogic
|
||||
$this->model = new DiceRewardConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增前:非 BIGWIN 时强制 weight=0
|
||||
*/
|
||||
public function add(array $data): mixed
|
||||
{
|
||||
$data = $this->normalizeWeightByTier($data);
|
||||
return parent::add($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改前:非 BIGWIN 时强制 weight=0
|
||||
*/
|
||||
public function edit($id, array $data): mixed
|
||||
{
|
||||
$data = $this->normalizeWeightByTier($data);
|
||||
return parent::edit($id, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅 tier=BIGWIN 时保留 weight(且限制 0-100),否则强制为 0
|
||||
*/
|
||||
private function normalizeWeightByTier(array $data): array
|
||||
{
|
||||
$tier = isset($data['tier']) ? (string) $data['tier'] : '';
|
||||
if ($tier !== 'BIGWIN') {
|
||||
$data['weight'] = 0;
|
||||
return $data;
|
||||
}
|
||||
$w = isset($data['weight']) ? (float) $data['weight'] : 0;
|
||||
$data['weight'] = max(0, min(100, $w));
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user