validate($this->scopeRules()); try { $result = LotteryOdds::list($this->key($input), $input['odds_template_id'] ?? null); if (!isset($input['game'])) { // The old Jisu screen expects gameplay at the parent and type at the leaf. $result['data'] = array_map(function ($node) use ($input) { unset($node['name']); foreach ($node['children'] as &$item) { $item['type'] = (int) $input['type']; } return $node; }, $result['data']); } return $this->success($result); } catch (DomainException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage()); } } public function saveTemplate() { $input = request()->validate(array_merge($this->scopeRules(), [ 'game' => ['required', 'in:jisu,lhc,canada28,jisu28'], 'names' => ['required_without:odds_template_id', 'array:zh,en,vi'], 'names.zh' => ['required_with:names', 'string', 'max:50'], 'names.en' => ['nullable', 'string', 'max:50'], 'names.vi' => ['nullable', 'string', 'max:50'], 'enabled' => ['sometimes', 'boolean'], 'make_default' => ['sometimes', 'boolean'], 'sort' => ['sometimes', 'integer', 'min:0', 'max:2147483647'], ])); try { return $this->success(LotteryOdds::saveTemplate($this->key($input), $input)); } catch (DomainException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage()); } } public function setOdds() { $pc28 = in_array(request()->input('game'), ['canada28', 'jisu28'], true); $input = request()->validate(array_merge($this->scopeRules(), [ 'odds_template_id' => ['required_with:game', 'nullable', 'integer', 'min:1'], 'id' => ['nullable', 'integer', 'min:1'], 'group_game' => ['nullable', 'string', 'min:1', 'max:100'], 'gameplay' => ['nullable', 'string', 'min:1', 'max:100'], 'odds' => ['required', 'regex:' . ($pc28 ? '/^\d{1,8}(\.\d{1,2})?$/' : '/^\d+(\.\d+)?$/')], 'mininum' => ['required', 'integer', 'min:0'], 'maxinum' => ['required', 'integer', 'gte:mininum'], ])); try { if (strlen((string) $input['odds']) > 10) { throw new DomainException('赔率长度超过限制'); } if (!isset($input['id'])) { $groupField = ($input['game'] ?? '') === 'lhc' ? 'group_game' : 'gameplay'; if (!isset($input[$groupField])) { throw new DomainException('请选择投注项或玩法分组'); } } if (!isset($input['game']) && !isset($input['type']) && isset($input['id'])) { $input['type'] ??= JisuGameplay::whereKey($input['id'])->value('type'); } LotteryOdds::setOdds($this->key($input), $input['odds_template_id'] ?? null, $input); return $this->success(); } catch (DomainException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage()); } } private function scopeRules(): array { return [ 'game' => ['nullable', 'in:jisu,lhc,canada28,jisu28'], 'type' => ['nullable', 'integer', 'min:1'], 'odds_template_id' => ['nullable', 'integer', 'min:1'], ]; } private function key(array $input): string { return LotteryOdds::gameKey($input['game'] ?? 'jisu', isset($input['type']) ? (int) $input['type'] : null); } }