read('rebate'); } public function backflow() { return $this->read('backflow'); } public function saveRebate() { return $this->write('rebate'); } public function saveBackflow() { return $this->write('backflow'); } private function read(string $type) { return $this->run(fn () => RewardGrantSettingsService::get($type)); } private function write(string $type) { return $this->run(fn () => RewardGrantSettingsService::save($type, request()->all())); } private function run(callable $callback) { try { return $this->success($callback()); } catch (ValidationException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first()); } catch (Throwable $e) { Log::error('reward_grant_settings_failed', ['exception' => $e]); return $this->error(HttpStatus::CUSTOM_ERROR, '奖励发放设置暂不可用,请稍后重试'); } } }