refactor: 规范Expection处理

This commit is contained in:
xboard
2023-12-04 20:40:49 +08:00
parent aa0fe64afe
commit 0ab7dee52d
65 changed files with 625 additions and 362 deletions

View File

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