Promotion.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\PromotionAdminService;
  6. use App\Support\PromotionAmountFormatter;
  7. use Illuminate\Support\Facades\Log;
  8. use Illuminate\Validation\ValidationException;
  9. class Promotion extends Controller
  10. {
  11. private function run(callable $callback)
  12. {
  13. try { return $this->success(PromotionAmountFormatter::response($callback())); }
  14. catch (ValidationException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first()); }
  15. catch (\Throwable $e) { Log::error('promotion_admin_failed', ['exception' => $e]); return $this->error(HttpStatus::CUSTOM_ERROR, '独立活动服务暂不可用'); }
  16. }
  17. public function index(PromotionAdminService $s) { return $this->run(fn () => $s->listing(request()->all())); }
  18. public function options(PromotionAdminService $s) { return $this->run(fn () => $s->options()); }
  19. public function submit(PromotionAdminService $s) { return $this->run(fn () => $s->save(request()->all())); }
  20. public function records(PromotionAdminService $s) { return $this->run(fn () => $s->records(request()->all())); }
  21. /** 全部首充活动共用的禁止投注游戏大类:GET 读取,POST 保存。 */
  22. public function firstDepositRestriction(PromotionAdminService $s)
  23. {
  24. return $this->run(fn () => request()->isMethod('post') ? $s->saveFirstDepositRestriction(request()->all()) : $s->firstDepositRestriction());
  25. }
  26. public function detail(PromotionAdminService $s)
  27. {
  28. return $this->run(function () use ($s) {
  29. $p = request()->validate(['id' => ['required_without:type', 'integer', 'min:1'], 'type' => ['required_without:id', 'integer', 'in:7,9,10']]);
  30. return $s->detail(isset($p['id']) ? (int)$p['id'] : null, isset($p['type']) ? (int)$p['type'] : null);
  31. });
  32. }
  33. public function status(PromotionAdminService $s)
  34. {
  35. return $this->run(function () use ($s) { $p = request()->validate(['id' => ['required', 'integer', 'min:1'], 'status' => ['required', 'integer', 'in:0,1']]); return $s->status((int)$p['id'], (int)$p['status']); });
  36. }
  37. }