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
@@ -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);