| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- namespace App\Http\Controllers\admin;
- use App\Constants\HttpStatus;
- use App\Http\Controllers\Controller;
- use App\Services\PromotionAdminService;
- use App\Support\PromotionAmountFormatter;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Validation\ValidationException;
- class Promotion extends Controller
- {
- private function run(callable $callback)
- {
- try { return $this->success(PromotionAmountFormatter::response($callback())); }
- catch (ValidationException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first()); }
- catch (\Throwable $e) { Log::error('promotion_admin_failed', ['exception' => $e]); return $this->error(HttpStatus::CUSTOM_ERROR, '独立活动服务暂不可用'); }
- }
- public function index(PromotionAdminService $s) { return $this->run(fn () => $s->listing(request()->all())); }
- public function options(PromotionAdminService $s) { return $this->run(fn () => $s->options()); }
- public function submit(PromotionAdminService $s) { return $this->run(fn () => $s->save(request()->all())); }
- public function records(PromotionAdminService $s) { return $this->run(fn () => $s->records(request()->all())); }
- /** 全部首充活动共用的禁止投注游戏大类:GET 读取,POST 保存。 */
- public function firstDepositRestriction(PromotionAdminService $s)
- {
- return $this->run(fn () => request()->isMethod('post') ? $s->saveFirstDepositRestriction(request()->all()) : $s->firstDepositRestriction());
- }
- public function detail(PromotionAdminService $s)
- {
- return $this->run(function () use ($s) {
- $p = request()->validate(['id' => ['required_without:type', 'integer', 'min:1'], 'type' => ['required_without:id', 'integer', 'in:7,9,10']]);
- return $s->detail(isset($p['id']) ? (int)$p['id'] : null, isset($p['type']) ? (int)$p['type'] : null);
- });
- }
- public function status(PromotionAdminService $s)
- {
- 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']); });
- }
- }
|