mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-24 20:17:32 +08:00
refactor: 规范状态码、抛出异常的使用
This commit is contained in:
@@ -86,30 +86,30 @@ class CouponService
|
||||
public function check()
|
||||
{
|
||||
if (!$this->coupon || !$this->coupon->show) {
|
||||
throw new ApiException(500, __('Invalid coupon'));
|
||||
throw new ApiException(__('Invalid coupon'));
|
||||
}
|
||||
if ($this->coupon->limit_use <= 0 && $this->coupon->limit_use !== NULL) {
|
||||
throw new ApiException(500, __('This coupon is no longer available'));
|
||||
throw new ApiException(__('This coupon is no longer available'));
|
||||
}
|
||||
if (time() < $this->coupon->started_at) {
|
||||
throw new ApiException(500, __('This coupon has not yet started'));
|
||||
throw new ApiException(__('This coupon has not yet started'));
|
||||
}
|
||||
if (time() > $this->coupon->ended_at) {
|
||||
throw new ApiException(500, __('This coupon has expired'));
|
||||
throw new ApiException(__('This coupon has expired'));
|
||||
}
|
||||
if ($this->coupon->limit_plan_ids && $this->planId) {
|
||||
if (!in_array($this->planId, $this->coupon->limit_plan_ids)) {
|
||||
throw new ApiException(500, __('The coupon code cannot be used for this subscription'));
|
||||
throw new ApiException(__('The coupon code cannot be used for this subscription'));
|
||||
}
|
||||
}
|
||||
if ($this->coupon->limit_period && $this->period) {
|
||||
if (!in_array($this->period, $this->coupon->limit_period)) {
|
||||
throw new ApiException(500, __('The coupon code cannot be used for this period'));
|
||||
throw new ApiException(__('The coupon code cannot be used for this period'));
|
||||
}
|
||||
}
|
||||
if ($this->coupon->limit_use_with_user !== NULL && $this->userId) {
|
||||
if (!$this->checkLimitUseWithUser()) {
|
||||
throw new ApiException(500, __('The coupon can only be used :limit_use_with_user per person', [
|
||||
throw new ApiException(__('The coupon can only be used :limit_use_with_user per person', [
|
||||
'limit_use_with_user' => $this->coupon->limit_use_with_user
|
||||
]));
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ class OrderService
|
||||
}catch(\Exception $e){
|
||||
DB::rollBack();
|
||||
\Log::error($e);
|
||||
throw new ApiException(500, '开通失败');
|
||||
throw new ApiException('开通失败');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ class OrderService
|
||||
if ($order->period === 'reset_price') {
|
||||
$order->type = 4;
|
||||
} else if ($user->plan_id !== NULL && $order->plan_id !== $user->plan_id && ($user->expired_at > time() || $user->expired_at === NULL)) {
|
||||
if (!(int)admin_setting('plan_change_enable', 1)) throw new ApiException(500, '目前不允许更改订阅,请联系客服或提交工单操作');
|
||||
if (!(int)admin_setting('plan_change_enable', 1)) throw new ApiException('目前不允许更改订阅,请联系客服或提交工单操作');
|
||||
$order->type = 3;
|
||||
if ((int)admin_setting('surplus_enable', 1)) $this->getSurplusValue($user, $order);
|
||||
if ($order->surplus_amount >= $order->total_amount) {
|
||||
|
||||
@@ -17,7 +17,7 @@ class PaymentService
|
||||
{
|
||||
$this->method = $method;
|
||||
$this->class = '\\App\\Payments\\' . $this->method;
|
||||
if (!class_exists($this->class)) throw new ApiException(500, 'gate is not found');
|
||||
if (!class_exists($this->class)) throw new ApiException('gate is not found');
|
||||
if ($id) $payment = Payment::find($id)->toArray();
|
||||
if ($uuid) $payment = Payment::where('uuid', $uuid)->first()->toArray();
|
||||
$this->config = [];
|
||||
@@ -33,7 +33,7 @@ class PaymentService
|
||||
|
||||
public function notify($params)
|
||||
{
|
||||
if (!$this->config['enable']) throw new ApiException(500, 'gate is not enable');
|
||||
if (!$this->config['enable']) throw new ApiException('gate is not enable');
|
||||
return $this->payment->notify($params);
|
||||
}
|
||||
|
||||
|
||||
@@ -60,9 +60,9 @@ class TelegramService {
|
||||
$curl->get($this->api . $method . '?' . http_build_query($params));
|
||||
$response = $curl->response;
|
||||
$curl->close();
|
||||
if (!isset($response->ok)) throw new ApiException(500, '请求失败');
|
||||
if (!isset($response->ok)) throw new ApiException('请求失败');
|
||||
if (!$response->ok) {
|
||||
throw new ApiException(500, '来自TG的错误:' . $response->description);
|
||||
throw new ApiException('来自TG的错误:' . $response->description);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class TicketService {
|
||||
$ticket = Ticket::where('id', $ticketId)
|
||||
->first();
|
||||
if (!$ticket) {
|
||||
throw new ApiException(500, '工单不存在');
|
||||
throw new ApiException('工单不存在');
|
||||
}
|
||||
$ticket->status = 0;
|
||||
try{
|
||||
@@ -57,7 +57,7 @@ class TicketService {
|
||||
$ticket->reply_status = 1;
|
||||
}
|
||||
if (!$ticketMessage || !$ticket->save()) {
|
||||
throw new ApiException(500, '工单回复失败');
|
||||
throw new ApiException('工单回复失败');
|
||||
}
|
||||
DB::commit();
|
||||
}catch(\Exception $e){
|
||||
|
||||
Reference in New Issue
Block a user