| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace App\Http\Controllers\admin;
- use App\Constants\HttpStatus;
- use App\Http\Controllers\Controller;
- use App\Services\RewardGrantSettingsService;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Validation\ValidationException;
- use Throwable;
- class RewardGrantSettings extends Controller
- {
- public function rebate() { return $this->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, '奖励发放设置暂不可用,请稍后重试');
- }
- }
- }
|