run(function () use ($service) { $params = request()->validate([ 'page' => ['nullable', 'integer', 'min:1'], 'limit' => ['nullable', 'integer', 'min:1', 'max:100'], 'payment_company' => ['nullable', Rule::in(PaymentProviderCatalog::codes())], 'status' => ['nullable', 'integer', 'in:0,1'], 'data_type' => ['nullable', 'integer', 'in:1,2'], ]); return $service->listing($params); }); } public function status(PaymentProviderService $service) { return $this->run(function () use ($service) { $params = request()->validate([ 'payment_company' => ['required', Rule::in(PaymentProviderCatalog::codes())], 'status' => ['required', 'integer', 'in:0,1'], ]); $service->setStatus($params['payment_company'], (int)$params['status']); return []; }); } private function run(callable $callback) { try { return $this->success($callback()); } catch (ValidationException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first()); } catch (ModelNotFoundException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, '支付公司不存在'); } catch (\PDOException $e) { report($e); return $this->error(HttpStatus::CUSTOM_ERROR, '支付公司操作失败,请稍后重试'); } catch (\InvalidArgumentException | \RuntimeException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage()); } } }