mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-14 19:40:53 +08:00
refactor: 规范Expection处理
This commit is contained in:
@@ -2,12 +2,11 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Jobs\OrderHandleJob;
|
||||
use App\Models\Order;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class OrderService
|
||||
@@ -45,7 +44,7 @@ class OrderService
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
abort(500, '开通失败');
|
||||
throw new ApiException(500, '开通失败');
|
||||
}
|
||||
}
|
||||
switch ((string)$order->period) {
|
||||
@@ -75,12 +74,12 @@ class OrderService
|
||||
|
||||
if (!$this->user->save()) {
|
||||
DB::rollBack();
|
||||
abort(500, '开通失败');
|
||||
throw new ApiException(500, '开通失败');
|
||||
}
|
||||
$order->status = 3;
|
||||
if (!$order->save()) {
|
||||
DB::rollBack();
|
||||
abort(500, '开通失败');
|
||||
throw new ApiException(500, '开通失败');
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
@@ -93,7 +92,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)) abort(500, '目前不允许更改订阅,请联系客服或提交工单操作');
|
||||
if (!(int)admin_setting('plan_change_enable', 1)) throw new ApiException(500, '目前不允许更改订阅,请联系客服或提交工单操作');
|
||||
$order->type = 3;
|
||||
if ((int)admin_setting('surplus_enable', 1)) $this->getSurplusValue($user, $order);
|
||||
if ($order->surplus_amount >= $order->total_amount) {
|
||||
|
||||
Reference in New Issue
Block a user