refactor: 规范状态码、抛出异常的使用

This commit is contained in:
xboard
2023-12-07 04:01:32 +08:00
parent c25803aa74
commit 189b247ad8
71 changed files with 663 additions and 910 deletions
@@ -10,21 +10,20 @@ class CommController extends Controller
{
public function config()
{
return response([
'data' => [
'tos_url' => admin_setting('tos_url'),
'is_email_verify' => (int)admin_setting('email_verify', 0) ? 1 : 0,
'is_invite_force' => (int)admin_setting('invite_force', 0) ? 1 : 0,
'email_whitelist_suffix' => (int)admin_setting('email_whitelist_enable', 0)
? $this->getEmailSuffix()
: 0,
'is_recaptcha' => (int)admin_setting('recaptcha_enable', 0) ? 1 : 0,
'recaptcha_site_key' => admin_setting('recaptcha_site_key'),
'app_description' => admin_setting('app_description'),
'app_url' => admin_setting('app_url'),
'logo' => admin_setting('logo'),
]
]);
$data = [
'tos_url' => admin_setting('tos_url'),
'is_email_verify' => (int)admin_setting('email_verify', 0) ? 1 : 0,
'is_invite_force' => (int)admin_setting('invite_force', 0) ? 1 : 0,
'email_whitelist_suffix' => (int)admin_setting('email_whitelist_enable', 0)
? $this->getEmailSuffix()
: 0,
'is_recaptcha' => (int)admin_setting('recaptcha_enable', 0) ? 1 : 0,
'recaptcha_site_key' => admin_setting('recaptcha_site_key'),
'app_description' => admin_setting('app_description'),
'app_url' => admin_setting('app_url'),
'logo' => admin_setting('logo'),
];
return $this->success($data);
}
private function getEmailSuffix()
@@ -17,13 +17,13 @@ class PaymentController extends Controller
try {
$paymentService = new PaymentService($method, null, $uuid);
$verify = $paymentService->notify($request->input());
if (!$verify) throw new ApiException(500, 'verify error');
if (!$verify) return $this->fail([422,'verify error']);
if (!$this->handle($verify['trade_no'], $verify['callback_no'])) {
throw new ApiException(500, 'handle error');
return $this->fail([400,'handle error']);
}
return(isset($verify['custom_result']) ? $verify['custom_result'] : 'success');
} catch (\Exception $e) {
throw new ApiException(500, 'fail');
return $this->fail([500,'fail']);
}
}
@@ -31,7 +31,7 @@ class PaymentController extends Controller
{
$order = Order::where('trade_no', $tradeNo)->first();
if (!$order) {
throw new ApiException(500, 'order is not found');
return $this->fail([400202,'order is not found']);
}
if ($order->status !== 0) return true;
$orderService = new OrderService($order);
@@ -11,8 +11,6 @@ class PlanController extends Controller
public function fetch(Request $request)
{
$plan = Plan::where('show', 1)->get();
return response([
'data' => $plan
]);
return $this->success($plan);
}
}
@@ -16,7 +16,7 @@ class TelegramController extends Controller
public function __construct(Request $request)
{
if ($request->input('access_token') !== md5(admin_setting('telegram_bot_token'))) {
throw new ApiException(401);
throw new ApiException('access_token is error', 401);
}
$this->telegramService = new TelegramService();