Promotion.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. /** 首充活动详情链接(PC / H5 / APP):GET 读取,POST 保存。 */
  27. public function firstDepositLinks(PromotionAdminService $s)
  28. {
  29. return $this->run(fn () => request()->isMethod('post') ? $s->saveFirstDepositLinks(request()->all()) : $s->firstDepositLinks());
  30. }
  31. public function detail(PromotionAdminService $s)
  32. {
  33. return $this->run(function () use ($s) {
  34. $p = request()->validate(['id' => ['required_without:type', 'integer', 'min:1'], 'type' => ['required_without:id', 'integer', 'in:7,9,10']]);
  35. return $s->detail(isset($p['id']) ? (int)$p['id'] : null, isset($p['type']) ? (int)$p['type'] : null);
  36. });
  37. }
  38. public function status(PromotionAdminService $s)
  39. {
  40. 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']); });
  41. }
  42. }