优化页面样式
This commit is contained in:
@@ -226,37 +226,46 @@ class DiceRewardLogic
|
||||
|
||||
/**
|
||||
* 更新 BIGWIN 档位某点数的权重(顺/逆时针同时更新);0=0% 中奖,10000=100% 中奖
|
||||
* 表 dice_reward 唯一键为 (direction, grid_number),同一点数同一方向仅一条记录,故先按该键查找再更新,避免重复插入
|
||||
*/
|
||||
public function updateBigwinWeight(int $gridNumber, int $weight): void
|
||||
{
|
||||
$weight = min(self::BIGWIN_WEIGHT_MAX, max(0, $weight));
|
||||
$config = DiceRewardConfig::where('tier', 'BIGWIN')
|
||||
->where('grid_number', $gridNumber)
|
||||
->find();
|
||||
if (! $config) {
|
||||
return;
|
||||
}
|
||||
$configArr = $config->toArray();
|
||||
foreach ([DiceReward::DIRECTION_CLOCKWISE, DiceReward::DIRECTION_COUNTERCLOCKWISE] as $direction) {
|
||||
// 优先更新已存在记录
|
||||
$affected = DiceReward::where('tier', 'BIGWIN')
|
||||
->where('direction', $direction)
|
||||
// 按唯一键 (direction, grid_number) 查找,存在则更新,不存在则插入
|
||||
$row = DiceReward::where('direction', $direction)
|
||||
->where('grid_number', $gridNumber)
|
||||
->update(['weight' => $weight]);
|
||||
|
||||
// 若不存在 BIGWIN 记录,则按当前 BIGWIN 配置懒加载创建一条 dice_reward 记录
|
||||
if ($affected === 0) {
|
||||
$config = DiceRewardConfig::where('tier', 'BIGWIN')
|
||||
->where('grid_number', $gridNumber)
|
||||
->find();
|
||||
if ($config) {
|
||||
$m = new DiceReward();
|
||||
$m->tier = 'BIGWIN';
|
||||
$m->direction = $direction;
|
||||
$m->grid_number = (int) $gridNumber;
|
||||
// 对于 BIGWIN,仅需保证 real_ev、weight、grid_number,start_index/end_index 取当前配置 id 即可
|
||||
$m->start_index = (int) $config->id;
|
||||
$m->end_index = (int) $config->id;
|
||||
$m->ui_text = (string) ($config->ui_text ?? '');
|
||||
$m->real_ev = (float) ($config->real_ev ?? 0);
|
||||
$m->remark = (string) ($config->remark ?? '');
|
||||
$m->type = $config->type ?? null;
|
||||
$m->weight = $weight > 0 ? $weight : self::WEIGHT_MIN;
|
||||
$m->save();
|
||||
}
|
||||
->find();
|
||||
if ($row) {
|
||||
$row->tier = 'BIGWIN';
|
||||
$row->weight = $weight > 0 ? $weight : self::WEIGHT_MIN;
|
||||
$row->start_index = (int) ($configArr['id'] ?? $row->start_index);
|
||||
$row->end_index = (int) ($configArr['id'] ?? $row->end_index);
|
||||
$row->ui_text = (string) ($configArr['ui_text'] ?? $row->ui_text);
|
||||
$row->real_ev = (float) ($configArr['real_ev'] ?? $row->real_ev);
|
||||
$row->remark = (string) ($configArr['remark'] ?? $row->remark);
|
||||
$row->type = $configArr['type'] ?? $row->type;
|
||||
$row->save();
|
||||
} else {
|
||||
$m = new DiceReward();
|
||||
$m->tier = 'BIGWIN';
|
||||
$m->direction = $direction;
|
||||
$m->grid_number = (int) $gridNumber;
|
||||
$m->start_index = (int) ($configArr['id'] ?? 0);
|
||||
$m->end_index = (int) ($configArr['id'] ?? 0);
|
||||
$m->ui_text = (string) ($configArr['ui_text'] ?? '');
|
||||
$m->real_ev = (float) ($configArr['real_ev'] ?? 0);
|
||||
$m->remark = (string) ($configArr['remark'] ?? '');
|
||||
$m->type = $configArr['type'] ?? null;
|
||||
$m->weight = $weight > 0 ? $weight : self::WEIGHT_MIN;
|
||||
$m->save();
|
||||
}
|
||||
}
|
||||
DiceReward::refreshCache();
|
||||
|
||||
Reference in New Issue
Block a user