mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-23 19:37:35 +08:00
refactor: 规范Expection处理
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\CouponGenerate;
|
||||
use App\Http\Requests\Admin\CouponSave;
|
||||
@@ -31,15 +32,15 @@ class CouponController extends Controller
|
||||
public function show(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数有误');
|
||||
throw new ApiException(422, '参数有误');
|
||||
}
|
||||
$coupon = Coupon::find($request->input('id'));
|
||||
if (!$coupon) {
|
||||
abort(500, '优惠券不存在');
|
||||
throw new ApiException(500, '优惠券不存在');
|
||||
}
|
||||
$coupon->show = $coupon->show ? 0 : 1;
|
||||
$coupon->show = !$coupon->show;
|
||||
if (!$coupon->save()) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
@@ -60,13 +61,13 @@ class CouponController extends Controller
|
||||
$params['code'] = Helper::randomChar(8);
|
||||
}
|
||||
if (!Coupon::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
throw new ApiException(500, '创建失败');
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Coupon::find($request->input('id'))->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +99,7 @@ class CouponController extends Controller
|
||||
return $item;
|
||||
}, $coupons))) {
|
||||
DB::rollBack();
|
||||
abort(500, '生成失败');
|
||||
throw new ApiException(500, '生成失败');
|
||||
}
|
||||
DB::commit();
|
||||
$data = "名称,类型,金额或比例,开始时间,结束时间,可用次数,可用于订阅,券码,生成时间\r\n";
|
||||
@@ -118,14 +119,14 @@ class CouponController extends Controller
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数有误');
|
||||
throw new ApiException(422, '参数有误');
|
||||
}
|
||||
$coupon = Coupon::find($request->input('id'));
|
||||
if (!$coupon) {
|
||||
abort(500, '优惠券不存在');
|
||||
throw new ApiException(500, '优惠券不存在');
|
||||
}
|
||||
if (!$coupon->delete()) {
|
||||
abort(500, '删除失败');
|
||||
throw new ApiException(500, '删除失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\KnowledgeSave;
|
||||
use App\Http\Requests\Admin\KnowledgeSort;
|
||||
@@ -15,7 +16,7 @@ class KnowledgeController extends Controller
|
||||
{
|
||||
if ($request->input('id')) {
|
||||
$knowledge = Knowledge::find($request->input('id'))->toArray();
|
||||
if (!$knowledge) abort(500, '知识不存在');
|
||||
if (!$knowledge) throw new ApiException(500, '知识不存在');
|
||||
return response([
|
||||
'data' => $knowledge
|
||||
]);
|
||||
@@ -40,13 +41,13 @@ class KnowledgeController extends Controller
|
||||
|
||||
if (!$request->input('id')) {
|
||||
if (!Knowledge::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
throw new ApiException(500, '创建失败');
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Knowledge::find($request->input('id'))->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,15 +59,15 @@ class KnowledgeController extends Controller
|
||||
public function show(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数有误');
|
||||
throw new ApiException(422, '参数有误');
|
||||
}
|
||||
$knowledge = Knowledge::find($request->input('id'));
|
||||
if (!$knowledge) {
|
||||
abort(500, '知识不存在');
|
||||
throw new ApiException(500, '知识不存在');
|
||||
}
|
||||
$knowledge->show = $knowledge->show ? 0 : 1;
|
||||
if (!$knowledge->save()) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
@@ -85,7 +86,7 @@ class KnowledgeController extends Controller
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
DB::commit();
|
||||
return response([
|
||||
@@ -96,14 +97,14 @@ class KnowledgeController extends Controller
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数有误');
|
||||
throw new ApiException(422, '参数有误');
|
||||
}
|
||||
$knowledge = Knowledge::find($request->input('id'));
|
||||
if (!$knowledge) {
|
||||
abort(500, '知识不存在');
|
||||
throw new ApiException(500, '知识不存在');
|
||||
}
|
||||
if (!$knowledge->delete()) {
|
||||
abort(500, '删除失败');
|
||||
throw new ApiException(500, '删除失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\NoticeSave;
|
||||
use App\Models\Notice;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class NoticeController extends Controller
|
||||
{
|
||||
@@ -27,13 +27,13 @@ class NoticeController extends Controller
|
||||
]);
|
||||
if (!$request->input('id')) {
|
||||
if (!Notice::create($data)) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Notice::find($request->input('id'))->update($data);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
@@ -46,15 +46,15 @@ class NoticeController extends Controller
|
||||
public function show(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数有误');
|
||||
throw new ApiException(422, '参数有误');
|
||||
}
|
||||
$notice = Notice::find($request->input('id'));
|
||||
if (!$notice) {
|
||||
abort(500, '公告不存在');
|
||||
throw new ApiException(500, '公告不存在');
|
||||
}
|
||||
$notice->show = $notice->show ? 0 : 1;
|
||||
if (!$notice->save()) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
@@ -65,14 +65,14 @@ class NoticeController extends Controller
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数错误');
|
||||
throw new ApiException(422, '参数错误');
|
||||
}
|
||||
$notice = Notice::find($request->input('id'));
|
||||
if (!$notice) {
|
||||
abort(500, '公告不存在');
|
||||
throw new ApiException(500, '公告不存在');
|
||||
}
|
||||
if (!$notice->delete()) {
|
||||
abort(500, '删除失败');
|
||||
throw new ApiException(500, '删除失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\OrderAssign;
|
||||
use App\Http\Requests\Admin\OrderFetch;
|
||||
@@ -40,7 +41,7 @@ class OrderController extends Controller
|
||||
public function detail(Request $request)
|
||||
{
|
||||
$order = Order::find($request->input('id'));
|
||||
if (!$order) abort(500, '订单不存在');
|
||||
if (!$order) throw new ApiException(500, '订单不存在');
|
||||
$order['commission_log'] = CommissionLog::where('trade_no', $order->trade_no)->get();
|
||||
if ($order->surplus_order_ids) {
|
||||
$order['surplus_orders'] = Order::whereIn('id', $order->surplus_order_ids)->get();
|
||||
@@ -83,13 +84,13 @@ class OrderController extends Controller
|
||||
$order = Order::where('trade_no', $request->input('trade_no'))
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, '订单不存在');
|
||||
throw new ApiException(500, '订单不存在');
|
||||
}
|
||||
if ($order->status !== 0) abort(500, '只能对待支付的订单进行操作');
|
||||
if ($order->status !== 0) throw new ApiException(500, '只能对待支付的订单进行操作');
|
||||
|
||||
$orderService = new OrderService($order);
|
||||
if (!$orderService->paid('manual_operation')) {
|
||||
abort(500, '更新失败');
|
||||
throw new ApiException(500, '更新失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
@@ -101,13 +102,13 @@ class OrderController extends Controller
|
||||
$order = Order::where('trade_no', $request->input('trade_no'))
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, '订单不存在');
|
||||
throw new ApiException(500, '订单不存在');
|
||||
}
|
||||
if ($order->status !== 0) abort(500, '只能对待支付的订单进行操作');
|
||||
if ($order->status !== 0) throw new ApiException(500, '只能对待支付的订单进行操作');
|
||||
|
||||
$orderService = new OrderService($order);
|
||||
if (!$orderService->cancel()) {
|
||||
abort(500, '更新失败');
|
||||
throw new ApiException(500, '更新失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
@@ -123,13 +124,13 @@ class OrderController extends Controller
|
||||
$order = Order::where('trade_no', $request->input('trade_no'))
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, '订单不存在');
|
||||
throw new ApiException(500, '订单不存在');
|
||||
}
|
||||
|
||||
try {
|
||||
$order->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '更新失败');
|
||||
throw new ApiException(500, '更新失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
@@ -143,16 +144,16 @@ class OrderController extends Controller
|
||||
$user = User::where('email', $request->input('email'))->first();
|
||||
|
||||
if (!$user) {
|
||||
abort(500, '该用户不存在');
|
||||
throw new ApiException(500, '该用户不存在');
|
||||
}
|
||||
|
||||
if (!$plan) {
|
||||
abort(500, '该订阅不存在');
|
||||
throw new ApiException(500, '该订阅不存在');
|
||||
}
|
||||
|
||||
$userService = new UserService();
|
||||
if ($userService->isNotCompleteOrderByUserId($user->id)) {
|
||||
abort(500, '该用户还有待支付的订单,无法分配');
|
||||
throw new ApiException(500, '该用户还有待支付的订单,无法分配');
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
@@ -178,7 +179,7 @@ class OrderController extends Controller
|
||||
|
||||
if (!$order->save()) {
|
||||
DB::rollback();
|
||||
abort(500, '订单创建失败');
|
||||
throw new ApiException(500, '订单创建失败');
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\PaymentSave;
|
||||
use App\Models\Payment;
|
||||
use App\Services\PaymentService;
|
||||
use App\Utils\Helper;
|
||||
@@ -50,9 +50,9 @@ class PaymentController extends Controller
|
||||
public function show(Request $request)
|
||||
{
|
||||
$payment = Payment::find($request->input('id'));
|
||||
if (!$payment) abort(500, '支付方式不存在');
|
||||
if (!$payment) throw new ApiException(500, '支付方式不存在');
|
||||
$payment->enable = !$payment->enable;
|
||||
if (!$payment->save()) abort(500, '保存失败');
|
||||
if (!$payment->save()) throw new ApiException(500, '保存失败');
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
@@ -61,7 +61,7 @@ class PaymentController extends Controller
|
||||
public function save(Request $request)
|
||||
{
|
||||
if (!admin_setting('app_url')) {
|
||||
abort(500, '请在站点配置中配置站点地址');
|
||||
throw new ApiException(500, '请在站点配置中配置站点地址');
|
||||
}
|
||||
$params = $request->validate([
|
||||
'name' => 'required',
|
||||
@@ -81,11 +81,11 @@ class PaymentController extends Controller
|
||||
]);
|
||||
if ($request->input('id')) {
|
||||
$payment = Payment::find($request->input('id'));
|
||||
if (!$payment) abort(500, '支付方式不存在');
|
||||
if (!$payment) throw new ApiException(500, '支付方式不存在');
|
||||
try {
|
||||
$payment->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, $e->getMessage());
|
||||
throw new ApiException(500, $e->getMessage());
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
@@ -93,7 +93,7 @@ class PaymentController extends Controller
|
||||
}
|
||||
$params['uuid'] = Helper::randomChar(8);
|
||||
if (!Payment::create($params)) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
@@ -103,7 +103,7 @@ class PaymentController extends Controller
|
||||
public function drop(Request $request)
|
||||
{
|
||||
$payment = Payment::find($request->input('id'));
|
||||
if (!$payment) abort(500, '支付方式不存在');
|
||||
if (!$payment) throw new ApiException(500, '支付方式不存在');
|
||||
return response([
|
||||
'data' => $payment->delete()
|
||||
]);
|
||||
@@ -122,7 +122,7 @@ class PaymentController extends Controller
|
||||
foreach ($request->input('ids') as $k => $v) {
|
||||
if (!Payment::find($v)->update(['sort' => $k + 1])) {
|
||||
DB::rollBack();
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\PlanSave;
|
||||
use App\Http\Requests\Admin\PlanSort;
|
||||
@@ -36,7 +37,7 @@ class PlanController extends Controller
|
||||
if ($request->input('id')) {
|
||||
$plan = Plan::find($request->input('id'));
|
||||
if (!$plan) {
|
||||
abort(500, '该订阅不存在');
|
||||
throw new ApiException(500, '该订阅不存在');
|
||||
}
|
||||
DB::beginTransaction();
|
||||
// update user group id and transfer
|
||||
@@ -51,7 +52,7 @@ class PlanController extends Controller
|
||||
$plan->update($params);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
DB::commit();
|
||||
return response([
|
||||
@@ -59,7 +60,7 @@ class PlanController extends Controller
|
||||
]);
|
||||
}
|
||||
if (!Plan::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
throw new ApiException(500, '创建失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
@@ -69,15 +70,15 @@ class PlanController extends Controller
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if (Order::where('plan_id', $request->input('id'))->first()) {
|
||||
abort(500, '该订阅下存在订单无法删除');
|
||||
throw new ApiException(500, '该订阅下存在订单无法删除');
|
||||
}
|
||||
if (User::where('plan_id', $request->input('id'))->first()) {
|
||||
abort(500, '该订阅下存在用户无法删除');
|
||||
throw new ApiException(500, '该订阅下存在用户无法删除');
|
||||
}
|
||||
if ($request->input('id')) {
|
||||
$plan = Plan::find($request->input('id'));
|
||||
if (!$plan) {
|
||||
abort(500, '该订阅ID不存在');
|
||||
throw new ApiException(500, '该订阅ID不存在');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
@@ -94,13 +95,13 @@ class PlanController extends Controller
|
||||
|
||||
$plan = Plan::find($request->input('id'));
|
||||
if (!$plan) {
|
||||
abort(500, '该订阅不存在');
|
||||
throw new ApiException(500, '该订阅不存在');
|
||||
}
|
||||
|
||||
try {
|
||||
$plan->update($updateData);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
@@ -114,7 +115,7 @@ class PlanController extends Controller
|
||||
foreach ($request->input('plan_ids') as $k => $v) {
|
||||
if (!Plan::find($v)->update(['sort' => $k + 1])) {
|
||||
DB::rollBack();
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Server;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Plan;
|
||||
use App\Models\ServerGroup;
|
||||
@@ -39,7 +40,7 @@ class GroupController extends Controller
|
||||
public function save(Request $request)
|
||||
{
|
||||
if (empty($request->input('name'))) {
|
||||
abort(500, '组名不能为空');
|
||||
throw new ApiException(500, '组名不能为空');
|
||||
}
|
||||
|
||||
if ($request->input('id')) {
|
||||
@@ -59,22 +60,22 @@ class GroupController extends Controller
|
||||
if ($request->input('id')) {
|
||||
$serverGroup = ServerGroup::find($request->input('id'));
|
||||
if (!$serverGroup) {
|
||||
abort(500, '组不存在');
|
||||
throw new ApiException(500, '组不存在');
|
||||
}
|
||||
}
|
||||
|
||||
$servers = ServerVmess::all();
|
||||
foreach ($servers as $server) {
|
||||
if (in_array($request->input('id'), $server->group_id)) {
|
||||
abort(500, '该组已被节点所使用,无法删除');
|
||||
throw new ApiException(500, '该组已被节点所使用,无法删除');
|
||||
}
|
||||
}
|
||||
|
||||
if (Plan::where('group_id', $request->input('id'))->first()) {
|
||||
abort(500, '该组已被订阅所使用,无法删除');
|
||||
throw new ApiException(500, '该组已被订阅所使用,无法删除');
|
||||
}
|
||||
if (User::where('group_id', $request->input('id'))->first()) {
|
||||
abort(500, '该组已被用户所使用,无法删除');
|
||||
throw new ApiException(500, '该组已被用户所使用,无法删除');
|
||||
}
|
||||
return response([
|
||||
'data' => $serverGroup->delete()
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Server;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServerHysteria;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -44,12 +45,12 @@ class HysteriaController extends Controller
|
||||
if ($request->input('id')) {
|
||||
$server = ServerHysteria::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
throw new ApiException(500, '服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
@@ -57,7 +58,7 @@ class HysteriaController extends Controller
|
||||
}
|
||||
|
||||
if (!ServerHysteria::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
throw new ApiException(500, '创建失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
@@ -70,7 +71,7 @@ class HysteriaController extends Controller
|
||||
if ($request->input('id')) {
|
||||
$server = ServerHysteria::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '节点ID不存在');
|
||||
throw new ApiException(500, '节点ID不存在');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
@@ -92,12 +93,12 @@ class HysteriaController extends Controller
|
||||
$server = ServerHysteria::find($request->input('id'));
|
||||
|
||||
if (!$server) {
|
||||
abort(500, '该服务器不存在');
|
||||
throw new ApiException(500, '该服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
@@ -110,10 +111,10 @@ class HysteriaController extends Controller
|
||||
$server = ServerHysteria::find($request->input('id'));
|
||||
$server->show = 0;
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
throw new ApiException(500, '服务器不存在');
|
||||
}
|
||||
if (!ServerHysteria::create($server->toArray())) {
|
||||
abort(500, '复制失败');
|
||||
throw new ApiException(500, '复制失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Server;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ServerService;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -33,7 +34,7 @@ class ManageController extends Controller
|
||||
foreach($v as $id => $sort) {
|
||||
if (!$model::find($id)->update(['sort' => $sort])) {
|
||||
DB::rollBack();
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Server;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServerRoute;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -47,10 +48,10 @@ class RouteController extends Controller
|
||||
'data' => true
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
}
|
||||
if (!ServerRoute::create($params)) abort(500, '创建失败');
|
||||
if (!ServerRoute::create($params)) throw new ApiException(500, '创建失败');
|
||||
return [
|
||||
'data' => true
|
||||
];
|
||||
@@ -59,8 +60,8 @@ class RouteController extends Controller
|
||||
public function drop(Request $request)
|
||||
{
|
||||
$route = ServerRoute::find($request->input('id'));
|
||||
if (!$route) abort(500, '路由不存在');
|
||||
if (!$route->delete()) abort(500, '删除失败');
|
||||
if (!$route) throw new ApiException(500, '路由不存在');
|
||||
if (!$route->delete()) throw new ApiException(500, '删除失败');
|
||||
return [
|
||||
'data' => true
|
||||
];
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Server;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\ServerShadowsocksSave;
|
||||
use App\Http\Requests\Admin\ServerShadowsocksUpdate;
|
||||
@@ -16,12 +17,12 @@ class ShadowsocksController extends Controller
|
||||
if ($request->input('id')) {
|
||||
$server = ServerShadowsocks::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
throw new ApiException(500, '服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
@@ -29,7 +30,7 @@ class ShadowsocksController extends Controller
|
||||
}
|
||||
|
||||
if (!ServerShadowsocks::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
throw new ApiException(500, '创建失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
@@ -42,7 +43,7 @@ class ShadowsocksController extends Controller
|
||||
if ($request->input('id')) {
|
||||
$server = ServerShadowsocks::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '节点ID不存在');
|
||||
throw new ApiException(500, '节点ID不存在');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
@@ -59,12 +60,12 @@ class ShadowsocksController extends Controller
|
||||
$server = ServerShadowsocks::find($request->input('id'));
|
||||
|
||||
if (!$server) {
|
||||
abort(500, '该服务器不存在');
|
||||
throw new ApiException(500, '该服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
@@ -77,10 +78,10 @@ class ShadowsocksController extends Controller
|
||||
$server = ServerShadowsocks::find($request->input('id'));
|
||||
$server->show = 0;
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
throw new ApiException(500, '服务器不存在');
|
||||
}
|
||||
if (!ServerShadowsocks::create($server->toArray())) {
|
||||
abort(500, '复制失败');
|
||||
throw new ApiException(500, '复制失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Server;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\ServerTrojanSave;
|
||||
use App\Http\Requests\Admin\ServerTrojanUpdate;
|
||||
@@ -17,12 +18,12 @@ class TrojanController extends Controller
|
||||
if ($request->input('id')) {
|
||||
$server = ServerTrojan::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
throw new ApiException(500, '服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
@@ -30,7 +31,7 @@ class TrojanController extends Controller
|
||||
}
|
||||
|
||||
if (!ServerTrojan::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
throw new ApiException(500, '创建失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
@@ -43,7 +44,7 @@ class TrojanController extends Controller
|
||||
if ($request->input('id')) {
|
||||
$server = ServerTrojan::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '节点ID不存在');
|
||||
throw new ApiException(500, '节点ID不存在');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
@@ -60,12 +61,12 @@ class TrojanController extends Controller
|
||||
$server = ServerTrojan::find($request->input('id'));
|
||||
|
||||
if (!$server) {
|
||||
abort(500, '该服务器不存在');
|
||||
throw new ApiException(500, '该服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
@@ -78,10 +79,10 @@ class TrojanController extends Controller
|
||||
$server = ServerTrojan::find($request->input('id'));
|
||||
$server->show = 0;
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
throw new ApiException(500, '服务器不存在');
|
||||
}
|
||||
if (!ServerTrojan::create($server->toArray())) {
|
||||
abort(500, '复制失败');
|
||||
throw new ApiException(500, '复制失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Server;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServerVless;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -61,12 +62,12 @@ class VlessController extends Controller
|
||||
if ($request->input('id')) {
|
||||
$server = ServerVless::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
throw new ApiException(500, '服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
@@ -74,7 +75,7 @@ class VlessController extends Controller
|
||||
}
|
||||
|
||||
if (!ServerVless::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
throw new ApiException(500, '创建失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
@@ -87,7 +88,7 @@ class VlessController extends Controller
|
||||
if ($request->input('id')) {
|
||||
$server = ServerVless::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '节点ID不存在');
|
||||
throw new ApiException(500, '节点ID不存在');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
@@ -104,12 +105,12 @@ class VlessController extends Controller
|
||||
$server = ServerVless::find($request->input('id'));
|
||||
|
||||
if (!$server) {
|
||||
abort(500, '该服务器不存在');
|
||||
throw new ApiException(500, '该服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
@@ -122,10 +123,10 @@ class VlessController extends Controller
|
||||
$server = ServerVless::find($request->input('id'));
|
||||
$server->show = 0;
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
throw new ApiException(500, '服务器不存在');
|
||||
}
|
||||
if (!ServerVless::create($server->toArray())) {
|
||||
abort(500, '复制失败');
|
||||
throw new ApiException(500, '复制失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Server;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\ServerVmessSave;
|
||||
use App\Http\Requests\Admin\ServerVmessUpdate;
|
||||
@@ -17,12 +18,12 @@ class VmessController extends Controller
|
||||
if ($request->input('id')) {
|
||||
$server = ServerVmess::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
throw new ApiException(500, '服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
@@ -30,7 +31,7 @@ class VmessController extends Controller
|
||||
}
|
||||
|
||||
if (!ServerVmess::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
throw new ApiException(500, '创建失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
@@ -43,7 +44,7 @@ class VmessController extends Controller
|
||||
if ($request->input('id')) {
|
||||
$server = ServerVmess::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '节点ID不存在');
|
||||
throw new ApiException(500, '节点ID不存在');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
@@ -60,12 +61,12 @@ class VmessController extends Controller
|
||||
$server = ServerVmess::find($request->input('id'));
|
||||
|
||||
if (!$server) {
|
||||
abort(500, '该服务器不存在');
|
||||
throw new ApiException(500, '该服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
@@ -78,10 +79,10 @@ class VmessController extends Controller
|
||||
$server = ServerVmess::find($request->input('id'));
|
||||
$server->show = 0;
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
throw new ApiException(500, '服务器不存在');
|
||||
}
|
||||
if (!ServerVmess::create($server->toArray())) {
|
||||
abort(500, '复制失败');
|
||||
throw new ApiException(500, '复制失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ThemeService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class ThemeController extends Controller
|
||||
@@ -59,11 +59,11 @@ class ThemeController extends Controller
|
||||
'config' => 'required'
|
||||
]);
|
||||
$payload['config'] = json_decode(base64_decode($payload['config']), true);
|
||||
if (!$payload['config'] || !is_array($payload['config'])) abort(500, '参数有误');
|
||||
if (!$payload['config'] || !is_array($payload['config'])) throw new ApiException(422, '参数有误');
|
||||
$themeConfigFile = public_path("theme/{$payload['name']}/config.json");
|
||||
if (!File::exists($themeConfigFile)) abort(500, '主题不存在');
|
||||
if (!File::exists($themeConfigFile)) throw new ApiException(500, '主题不存在');
|
||||
$themeConfig = json_decode(File::get($themeConfigFile), true);
|
||||
if (!isset($themeConfig['configs']) || !is_array($themeConfig)) abort(500, '主题配置文件有误');
|
||||
if (!isset($themeConfig['configs']) || !is_array($themeConfig)) throw new ApiException(500, '主题配置文件有误');
|
||||
$validateFields = array_column($themeConfig['configs'], 'field_name');
|
||||
$config = [];
|
||||
foreach ($validateFields as $validateField) {
|
||||
@@ -77,7 +77,7 @@ class ThemeController extends Controller
|
||||
admin_setting(["theme_{$payload['name']}" => $config]);
|
||||
// sleep(2);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketMessage;
|
||||
use App\Models\User;
|
||||
use App\Services\TicketService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TicketController extends Controller
|
||||
{
|
||||
@@ -19,7 +18,7 @@ class TicketController extends Controller
|
||||
$ticket = Ticket::where('id', $request->input('id'))
|
||||
->first();
|
||||
if (!$ticket) {
|
||||
abort(500, '工单不存在');
|
||||
throw new ApiException(500, '工单不存在');
|
||||
}
|
||||
$ticket['message'] = TicketMessage::where('ticket_id', $ticket->id)->get();
|
||||
for ($i = 0; $i < count($ticket['message']); $i++) {
|
||||
@@ -58,10 +57,10 @@ class TicketController extends Controller
|
||||
public function reply(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数错误');
|
||||
throw new ApiException(422, '参数错误');
|
||||
}
|
||||
if (empty($request->input('message'))) {
|
||||
abort(500, '消息不能为空');
|
||||
throw new ApiException(500, '消息不能为空');
|
||||
}
|
||||
$ticketService = new TicketService();
|
||||
$ticketService->replyByAdmin(
|
||||
@@ -77,16 +76,16 @@ class TicketController extends Controller
|
||||
public function close(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数错误');
|
||||
throw new ApiException(422, '参数错误');
|
||||
}
|
||||
$ticket = Ticket::where('id', $request->input('id'))
|
||||
->first();
|
||||
if (!$ticket) {
|
||||
abort(500, '工单不存在');
|
||||
throw new ApiException(500, '工单不存在');
|
||||
}
|
||||
$ticket->status = 1;
|
||||
if (!$ticket->save()) {
|
||||
abort(500, '关闭失败');
|
||||
throw new ApiException(500, '关闭失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\UserFetch;
|
||||
use App\Http\Requests\Admin\UserGenerate;
|
||||
@@ -20,7 +21,7 @@ class UserController extends Controller
|
||||
public function resetSecret(Request $request)
|
||||
{
|
||||
$user = User::find($request->input('id'));
|
||||
if (!$user) abort(500, '用户不存在');
|
||||
if (!$user) throw new ApiException(500, '用户不存在');
|
||||
$user->token = Helper::guid();
|
||||
$user->uuid = Helper::guid(true);
|
||||
return response([
|
||||
@@ -85,7 +86,7 @@ class UserController extends Controller
|
||||
public function getUserInfoById(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数错误');
|
||||
throw new ApiException(422, '参数错误');
|
||||
}
|
||||
$user = User::find($request->input('id'));
|
||||
if ($user->invite_user_id) {
|
||||
@@ -101,10 +102,10 @@ class UserController extends Controller
|
||||
$params = $request->validated();
|
||||
$user = User::find($request->input('id'));
|
||||
if (!$user) {
|
||||
abort(500, '用户不存在');
|
||||
throw new ApiException(500, '用户不存在');
|
||||
}
|
||||
if (User::where('email', $params['email'])->first() && $user->email !== $params['email']) {
|
||||
abort(500, '邮箱已被使用');
|
||||
throw new ApiException(500, '邮箱已被使用');
|
||||
}
|
||||
if (isset($params['password'])) {
|
||||
$params['password'] = password_hash($params['password'], PASSWORD_DEFAULT);
|
||||
@@ -115,7 +116,7 @@ class UserController extends Controller
|
||||
if (isset($params['plan_id'])) {
|
||||
$plan = Plan::find($params['plan_id']);
|
||||
if (!$plan) {
|
||||
abort(500, '订阅计划不存在');
|
||||
throw new ApiException(500, '订阅计划不存在');
|
||||
}
|
||||
$params['group_id'] = $plan->group_id;
|
||||
}
|
||||
@@ -136,7 +137,7 @@ class UserController extends Controller
|
||||
try {
|
||||
$user->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
@@ -177,7 +178,7 @@ class UserController extends Controller
|
||||
if ($request->input('plan_id')) {
|
||||
$plan = Plan::find($request->input('plan_id'));
|
||||
if (!$plan) {
|
||||
abort(500, '订阅计划不存在');
|
||||
throw new ApiException(500, '订阅计划不存在');
|
||||
}
|
||||
}
|
||||
$user = [
|
||||
@@ -190,11 +191,11 @@ class UserController extends Controller
|
||||
'token' => Helper::guid()
|
||||
];
|
||||
if (User::where('email', $user['email'])->first()) {
|
||||
abort(500, '邮箱已存在于系统中');
|
||||
throw new ApiException(500, '邮箱已存在于系统中');
|
||||
}
|
||||
$user['password'] = password_hash($request->input('password') ?? $user['email'], PASSWORD_DEFAULT);
|
||||
if (!User::create($user)) {
|
||||
abort(500, '生成失败');
|
||||
throw new ApiException(500, '生成失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
@@ -210,7 +211,7 @@ class UserController extends Controller
|
||||
if ($request->input('plan_id')) {
|
||||
$plan = Plan::find($request->input('plan_id'));
|
||||
if (!$plan) {
|
||||
abort(500, '订阅计划不存在');
|
||||
throw new ApiException(500, '订阅计划不存在');
|
||||
}
|
||||
}
|
||||
$users = [];
|
||||
@@ -232,7 +233,7 @@ class UserController extends Controller
|
||||
DB::beginTransaction();
|
||||
if (!User::insert($users)) {
|
||||
DB::rollBack();
|
||||
abort(500, '生成失败');
|
||||
throw new ApiException(500, '生成失败');
|
||||
}
|
||||
DB::commit();
|
||||
$data = "账号,密码,过期时间,UUID,创建时间,订阅地址\r\n";
|
||||
@@ -283,7 +284,7 @@ class UserController extends Controller
|
||||
'banned' => 1
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '处理失败');
|
||||
throw new ApiException(500, '处理失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Guest;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Order;
|
||||
use App\Services\OrderService;
|
||||
@@ -16,13 +17,13 @@ class PaymentController extends Controller
|
||||
try {
|
||||
$paymentService = new PaymentService($method, null, $uuid);
|
||||
$verify = $paymentService->notify($request->input());
|
||||
if (!$verify) abort(500, 'verify error');
|
||||
if (!$verify) throw new ApiException(500, 'verify error');
|
||||
if (!$this->handle($verify['trade_no'], $verify['callback_no'])) {
|
||||
abort(500, 'handle error');
|
||||
throw new ApiException(500, 'handle error');
|
||||
}
|
||||
return(isset($verify['custom_result']) ? $verify['custom_result'] : 'success');
|
||||
} catch (\Exception $e) {
|
||||
abort(500, 'fail');
|
||||
throw new ApiException(500, 'fail');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +31,7 @@ class PaymentController extends Controller
|
||||
{
|
||||
$order = Order::where('trade_no', $tradeNo)->first();
|
||||
if (!$order) {
|
||||
abort(500, 'order is not found');
|
||||
throw new ApiException(500, 'order is not found');
|
||||
}
|
||||
if ($order->status !== 0) return true;
|
||||
$orderService = new OrderService($order);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Guest;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\TelegramService;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -15,7 +16,7 @@ class TelegramController extends Controller
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
if ($request->input('access_token') !== md5(admin_setting('telegram_bot_token'))) {
|
||||
abort(401);
|
||||
throw new ApiException(401);
|
||||
}
|
||||
|
||||
$this->telegramService = new TelegramService();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Passport;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Passport\AuthForget;
|
||||
use App\Http\Requests\Passport\AuthLogin;
|
||||
@@ -23,7 +24,7 @@ class AuthController extends Controller
|
||||
public function loginWithMailLink(Request $request)
|
||||
{
|
||||
if (!(int)admin_setting('login_with_mail_link_enable')) {
|
||||
abort(404);
|
||||
throw new ApiException(404);
|
||||
}
|
||||
$params = $request->validate([
|
||||
'email' => 'required|email:strict',
|
||||
@@ -31,7 +32,7 @@ class AuthController extends Controller
|
||||
]);
|
||||
|
||||
if (Cache::get(CacheKey::get('LAST_SEND_LOGIN_WITH_MAIL_LINK_TIMESTAMP', $params['email']))) {
|
||||
abort(500, __('Sending frequently, please try again later'));
|
||||
throw new ApiException(500, __('Sending frequently, please try again later'));
|
||||
}
|
||||
|
||||
$user = User::where('email', $params['email'])->first();
|
||||
@@ -78,7 +79,7 @@ class AuthController extends Controller
|
||||
if ((int)admin_setting('register_limit_by_ip_enable', 0)) {
|
||||
$registerCountByIP = Cache::get(CacheKey::get('REGISTER_IP_RATE_LIMIT', $request->ip())) ?? 0;
|
||||
if ((int)$registerCountByIP >= (int)admin_setting('register_limit_count', 3)) {
|
||||
abort(500, __('Register frequently, please try again after :minute minute', [
|
||||
throw new ApiException(500, __('Register frequently, please try again after :minute minute', [
|
||||
'minute' => admin_setting('register_limit_expire', 60)
|
||||
]));
|
||||
}
|
||||
@@ -87,7 +88,7 @@ class AuthController extends Controller
|
||||
$recaptcha = new ReCaptcha(admin_setting('recaptcha_key'));
|
||||
$recaptchaResp = $recaptcha->verify($request->input('recaptcha_data'));
|
||||
if (!$recaptchaResp->isSuccess()) {
|
||||
abort(500, __('Invalid code is incorrect'));
|
||||
throw new ApiException(500, __('Invalid code is incorrect'));
|
||||
}
|
||||
}
|
||||
if ((int)admin_setting('email_whitelist_enable', 0)) {
|
||||
@@ -95,36 +96,36 @@ class AuthController extends Controller
|
||||
$request->input('email'),
|
||||
admin_setting('email_whitelist_suffix', Dict::EMAIL_WHITELIST_SUFFIX_DEFAULT))
|
||||
) {
|
||||
abort(500, __('Email suffix is not in the Whitelist'));
|
||||
throw new ApiException(500, __('Email suffix is not in the Whitelist'));
|
||||
}
|
||||
}
|
||||
if ((int)admin_setting('email_gmail_limit_enable', 0)) {
|
||||
$prefix = explode('@', $request->input('email'))[0];
|
||||
if (strpos($prefix, '.') !== false || strpos($prefix, '+') !== false) {
|
||||
abort(500, __('Gmail alias is not supported'));
|
||||
throw new ApiException(500, __('Gmail alias is not supported'));
|
||||
}
|
||||
}
|
||||
if ((int)admin_setting('stop_register', 0)) {
|
||||
abort(500, __('Registration has closed'));
|
||||
throw new ApiException(500, __('Registration has closed'));
|
||||
}
|
||||
if ((int)admin_setting('invite_force', 0)) {
|
||||
if (empty($request->input('invite_code'))) {
|
||||
abort(500, __('You must use the invitation code to register'));
|
||||
throw new ApiException(500, __('You must use the invitation code to register'));
|
||||
}
|
||||
}
|
||||
if ((int)admin_setting('email_verify', 0)) {
|
||||
if (empty($request->input('email_code'))) {
|
||||
abort(500, __('Email verification code cannot be empty'));
|
||||
throw new ApiException(500, __('Email verification code cannot be empty'));
|
||||
}
|
||||
if ((string)Cache::get(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email'))) !== (string)$request->input('email_code')) {
|
||||
abort(500, __('Incorrect email verification code'));
|
||||
throw new ApiException(500, __('Incorrect email verification code'));
|
||||
}
|
||||
}
|
||||
$email = $request->input('email');
|
||||
$password = $request->input('password');
|
||||
$exist = User::where('email', $email)->first();
|
||||
if ($exist) {
|
||||
abort(500, __('Email already exists'));
|
||||
throw new ApiException(500, __('Email already exists'));
|
||||
}
|
||||
$user = new User();
|
||||
$user->email = $email;
|
||||
@@ -140,7 +141,7 @@ class AuthController extends Controller
|
||||
->first();
|
||||
if (!$inviteCode) {
|
||||
if ((int)admin_setting('invite_force', 0)) {
|
||||
abort(500, __('Invalid invitation code'));
|
||||
throw new ApiException(500, __('Invalid invitation code'));
|
||||
}
|
||||
} else {
|
||||
$user->invite_user_id = $inviteCode->user_id ? $inviteCode->user_id : null;
|
||||
@@ -164,7 +165,7 @@ class AuthController extends Controller
|
||||
}
|
||||
|
||||
if (!$user->save()) {
|
||||
abort(500, __('Register failed'));
|
||||
throw new ApiException(500, __('Register failed'));
|
||||
}
|
||||
if ((int)admin_setting('email_verify', 0)) {
|
||||
Cache::forget(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email')));
|
||||
@@ -196,7 +197,7 @@ class AuthController extends Controller
|
||||
if ((int)admin_setting('password_limit_enable', 1)) {
|
||||
$passwordErrorCount = (int)Cache::get(CacheKey::get('PASSWORD_ERROR_LIMIT', $email), 0);
|
||||
if ($passwordErrorCount >= (int)admin_setting('password_limit_count', 5)) {
|
||||
abort(500, __('There are too many password errors, please try again after :minute minutes.', [
|
||||
throw new ApiException(500, __('There are too many password errors, please try again after :minute minutes.', [
|
||||
'minute' => admin_setting('password_limit_expire', 60)
|
||||
]));
|
||||
}
|
||||
@@ -204,7 +205,7 @@ class AuthController extends Controller
|
||||
|
||||
$user = User::where('email', $email)->first();
|
||||
if (!$user) {
|
||||
abort(500, __('Incorrect email or password'));
|
||||
throw new ApiException(500, __('Incorrect email or password'));
|
||||
}
|
||||
if (!Helper::multiPasswordVerify(
|
||||
$user->password_algo,
|
||||
@@ -219,11 +220,11 @@ class AuthController extends Controller
|
||||
60 * (int)admin_setting('password_limit_expire', 60)
|
||||
);
|
||||
}
|
||||
abort(500, __('Incorrect email or password'));
|
||||
throw new ApiException(500, __('Incorrect email or password'));
|
||||
}
|
||||
|
||||
if ($user->banned) {
|
||||
abort(500, __('Your account has been suspended'));
|
||||
throw new ApiException(500, __('Your account has been suspended'));
|
||||
}
|
||||
|
||||
$authService = new AuthService($user);
|
||||
@@ -248,14 +249,14 @@ class AuthController extends Controller
|
||||
$key = CacheKey::get('TEMP_TOKEN', $request->input('verify'));
|
||||
$userId = Cache::get($key);
|
||||
if (!$userId) {
|
||||
abort(500, __('Token error'));
|
||||
throw new ApiException(500, __('Token error'));
|
||||
}
|
||||
$user = User::find($userId);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not '));
|
||||
throw new ApiException(500, __('The user does not '));
|
||||
}
|
||||
if ($user->banned) {
|
||||
abort(500, __('Your account has been suspended'));
|
||||
throw new ApiException(500, __('Your account has been suspended'));
|
||||
}
|
||||
Cache::forget($key);
|
||||
$authService = new AuthService($user);
|
||||
@@ -268,10 +269,10 @@ class AuthController extends Controller
|
||||
public function getQuickLoginUrl(Request $request)
|
||||
{
|
||||
$authorization = $request->input('auth_data') ?? $request->header('authorization');
|
||||
if (!$authorization) abort(403, '未登录或登陆已过期');
|
||||
if (!$authorization) throw new ApiException(403, '未登录或登陆已过期');
|
||||
|
||||
$user = AuthService::decryptAuthData($authorization);
|
||||
if (!$user) abort(403, '未登录或登陆已过期');
|
||||
if (!$user) throw new ApiException(403, '未登录或登陆已过期');
|
||||
|
||||
$code = Helper::guid();
|
||||
$key = CacheKey::get('TEMP_TOKEN', $code);
|
||||
@@ -291,20 +292,20 @@ class AuthController extends Controller
|
||||
{
|
||||
$forgetRequestLimitKey = CacheKey::get('FORGET_REQUEST_LIMIT', $request->input('email'));
|
||||
$forgetRequestLimit = (int)Cache::get($forgetRequestLimitKey);
|
||||
if ($forgetRequestLimit >= 3) abort(500, __('Reset failed, Please try again later'));
|
||||
if ($forgetRequestLimit >= 3) throw new ApiException(500, __('Reset failed, Please try again later'));
|
||||
if ((string)Cache::get(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email'))) !== (string)$request->input('email_code')) {
|
||||
Cache::put($forgetRequestLimitKey, $forgetRequestLimit ? $forgetRequestLimit + 1 : 1, 300);
|
||||
abort(500, __('Incorrect email verification code'));
|
||||
throw new ApiException(500, __('Incorrect email verification code'));
|
||||
}
|
||||
$user = User::where('email', $request->input('email'))->first();
|
||||
if (!$user) {
|
||||
abort(500, __('This email is not registered in the system'));
|
||||
throw new ApiException(500, __('This email is not registered in the system'));
|
||||
}
|
||||
$user->password = password_hash($request->input('password'), PASSWORD_DEFAULT);
|
||||
$user->password_algo = NULL;
|
||||
$user->password_salt = NULL;
|
||||
if (!$user->save()) {
|
||||
abort(500, __('Reset failed'));
|
||||
throw new ApiException(500, __('Reset failed'));
|
||||
}
|
||||
Cache::forget(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email')));
|
||||
return response([
|
||||
|
||||
@@ -2,17 +2,15 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Passport;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Passport\CommSendEmailVerify;
|
||||
use App\Jobs\SendEmailJob;
|
||||
use App\Models\InviteCode;
|
||||
use App\Models\User;
|
||||
use App\Utils\CacheKey;
|
||||
use App\Utils\Dict;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use ReCaptcha\ReCaptcha;
|
||||
|
||||
class CommController extends Controller
|
||||
@@ -30,12 +28,12 @@ class CommController extends Controller
|
||||
$recaptcha = new ReCaptcha(admin_setting('recaptcha_key'));
|
||||
$recaptchaResp = $recaptcha->verify($request->input('recaptcha_data'));
|
||||
if (!$recaptchaResp->isSuccess()) {
|
||||
abort(500, __('Invalid code is incorrect'));
|
||||
throw new ApiException(500, __('Invalid code is incorrect'));
|
||||
}
|
||||
}
|
||||
$email = $request->input('email');
|
||||
if (Cache::get(CacheKey::get('LAST_SEND_EMAIL_VERIFY_TIMESTAMP', $email))) {
|
||||
abort(500, __('Email verification code has been sent, please request again later'));
|
||||
throw new ApiException(500, __('Email verification code has been sent, please request again later'));
|
||||
}
|
||||
$code = rand(100000, 999999);
|
||||
$subject = admin_setting('app_name', 'XBoard') . __('Email verification code');
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Server;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServerVmess;
|
||||
use App\Services\ServerService;
|
||||
@@ -9,8 +10,6 @@ use App\Services\UserService;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/*
|
||||
* V2ray Aurora
|
||||
@@ -23,10 +22,10 @@ class DeepbworkController extends Controller
|
||||
{
|
||||
$token = $request->input('token');
|
||||
if (empty($token)) {
|
||||
abort(500, 'token is null');
|
||||
throw new ApiException(500, 'token is null');
|
||||
}
|
||||
if ($token !== admin_setting('server_token')) {
|
||||
abort(500, 'token is error');
|
||||
throw new ApiException(500, 'token is error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +36,7 @@ class DeepbworkController extends Controller
|
||||
$nodeId = $request->input('node_id');
|
||||
$server = ServerVmess::find($nodeId);
|
||||
if (!$server) {
|
||||
abort(500, 'fail');
|
||||
throw new ApiException(500, 'fail');
|
||||
}
|
||||
Cache::put(CacheKey::get('SERVER_VMESS_LAST_CHECK_AT', $server->id), time(), 3600);
|
||||
$serverService = new ServerService();
|
||||
@@ -97,12 +96,12 @@ class DeepbworkController extends Controller
|
||||
$nodeId = $request->input('node_id');
|
||||
$localPort = $request->input('local_port');
|
||||
if (empty($nodeId) || empty($localPort)) {
|
||||
abort(500, '参数错误');
|
||||
throw new ApiException(422, '参数错误');
|
||||
}
|
||||
try {
|
||||
$json = $this->getV2RayConfig($nodeId, $localPort);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, $e->getMessage());
|
||||
throw new ApiException(500, $e->getMessage());
|
||||
}
|
||||
|
||||
return(json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
@@ -112,7 +111,7 @@ class DeepbworkController extends Controller
|
||||
{
|
||||
$server = ServerVmess::find($nodeId);
|
||||
if (!$server) {
|
||||
abort(500, '节点不存在');
|
||||
throw new ApiException(500, '节点不存在');
|
||||
}
|
||||
$json = json_decode(self::V2RAY_CONFIG);
|
||||
$json->log->loglevel = (int)admin_setting('server_log_enable') ? 'debug' : 'none';
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Server;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServerShadowsocks;
|
||||
use App\Services\ServerService;
|
||||
@@ -20,10 +21,10 @@ class ShadowsocksTidalabController extends Controller
|
||||
{
|
||||
$token = $request->input('token');
|
||||
if (empty($token)) {
|
||||
abort(500, 'token is null');
|
||||
throw new ApiException(500, 'token is null');
|
||||
}
|
||||
if ($token !== admin_setting('server_token')) {
|
||||
abort(500, 'token is error');
|
||||
throw new ApiException(500, 'token is error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +35,7 @@ class ShadowsocksTidalabController extends Controller
|
||||
$nodeId = $request->input('node_id');
|
||||
$server = ServerShadowsocks::find($nodeId);
|
||||
if (!$server) {
|
||||
abort(500, 'fail');
|
||||
throw new ApiException(500, 'fail');
|
||||
}
|
||||
Cache::put(CacheKey::get('SERVER_SHADOWSOCKS_LAST_CHECK_AT', $server->id), time(), 3600);
|
||||
$serverService = new ServerService();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Server;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServerTrojan;
|
||||
use App\Services\ServerService;
|
||||
@@ -9,8 +10,6 @@ use App\Services\UserService;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/*
|
||||
* Tidal Lab Trojan
|
||||
@@ -23,10 +22,10 @@ class TrojanTidalabController extends Controller
|
||||
{
|
||||
$token = $request->input('token');
|
||||
if (empty($token)) {
|
||||
abort(500, 'token is null');
|
||||
throw new ApiException(500, 'token is null');
|
||||
}
|
||||
if ($token !== admin_setting('server_token')) {
|
||||
abort(500, 'token is error');
|
||||
throw new ApiException(500, 'token is error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +36,7 @@ class TrojanTidalabController extends Controller
|
||||
$nodeId = $request->input('node_id');
|
||||
$server = ServerTrojan::find($nodeId);
|
||||
if (!$server) {
|
||||
abort(500, 'fail');
|
||||
throw new ApiException(500, 'fail');
|
||||
}
|
||||
Cache::put(CacheKey::get('SERVER_TROJAN_LAST_CHECK_AT', $server->id), time(), 3600);
|
||||
$serverService = new ServerService();
|
||||
@@ -93,12 +92,12 @@ class TrojanTidalabController extends Controller
|
||||
$nodeId = $request->input('node_id');
|
||||
$localPort = $request->input('local_port');
|
||||
if (empty($nodeId) || empty($localPort)) {
|
||||
abort(500, '参数错误');
|
||||
throw new ApiException(422, '参数错误');
|
||||
}
|
||||
try {
|
||||
$json = $this->getTrojanConfig($nodeId, $localPort);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, $e->getMessage());
|
||||
throw new ApiException(500, $e->getMessage());
|
||||
}
|
||||
|
||||
return(json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
@@ -108,7 +107,7 @@ class TrojanTidalabController extends Controller
|
||||
{
|
||||
$server = ServerTrojan::find($nodeId);
|
||||
if (!$server) {
|
||||
abort(500, '节点不存在');
|
||||
throw new ApiException(500, '节点不存在');
|
||||
}
|
||||
|
||||
$json = json_decode(self::TROJAN_CONFIG);
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Staff;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\NoticeSave;
|
||||
use App\Models\Notice;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class NoticeController extends Controller
|
||||
{
|
||||
@@ -26,13 +26,13 @@ class NoticeController extends Controller
|
||||
]);
|
||||
if (!$request->input('id')) {
|
||||
if (!Notice::create($data)) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Notice::find($request->input('id'))->update($data);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
@@ -43,14 +43,14 @@ class NoticeController extends Controller
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数错误');
|
||||
throw new ApiException(422, '参数错误');
|
||||
}
|
||||
$notice = Notice::find($request->input('id'));
|
||||
if (!$notice) {
|
||||
abort(500, '公告不存在');
|
||||
throw new ApiException(500, '公告不存在');
|
||||
}
|
||||
if (!$notice->delete()) {
|
||||
abort(500, '删除失败');
|
||||
throw new ApiException(500, '删除失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Staff;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketMessage;
|
||||
@@ -16,7 +17,7 @@ class TicketController extends Controller
|
||||
$ticket = Ticket::where('id', $request->input('id'))
|
||||
->first();
|
||||
if (!$ticket) {
|
||||
abort(500, '工单不存在');
|
||||
throw new ApiException(500, '工单不存在');
|
||||
}
|
||||
$ticket['message'] = TicketMessage::where('ticket_id', $ticket->id)->get();
|
||||
for ($i = 0; $i < count($ticket['message']); $i++) {
|
||||
@@ -48,10 +49,10 @@ class TicketController extends Controller
|
||||
public function reply(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数错误');
|
||||
throw new ApiException(422, '参数错误');
|
||||
}
|
||||
if (empty($request->input('message'))) {
|
||||
abort(500, '消息不能为空');
|
||||
throw new ApiException(500, '消息不能为空');
|
||||
}
|
||||
$ticketService = new TicketService();
|
||||
$ticketService->replyByAdmin(
|
||||
@@ -67,16 +68,16 @@ class TicketController extends Controller
|
||||
public function close(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数错误');
|
||||
throw new ApiException(422, '参数错误');
|
||||
}
|
||||
$ticket = Ticket::where('id', $request->input('id'))
|
||||
->first();
|
||||
if (!$ticket) {
|
||||
abort(500, '工单不存在');
|
||||
throw new ApiException(500, '工单不存在');
|
||||
}
|
||||
$ticket->status = 1;
|
||||
if (!$ticket->save()) {
|
||||
abort(500, '关闭失败');
|
||||
throw new ApiException(500, '关闭失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\Staff;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\UserSendMail;
|
||||
use App\Http\Requests\Staff\UserUpdate;
|
||||
@@ -15,13 +16,13 @@ class UserController extends Controller
|
||||
public function getUserInfoById(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数错误');
|
||||
throw new ApiException(422, '参数错误');
|
||||
}
|
||||
$user = User::where('is_admin', 0)
|
||||
->where('id', $request->input('id'))
|
||||
->where('is_staff', 0)
|
||||
->first();
|
||||
if (!$user) abort(500, '用户不存在');
|
||||
if (!$user) throw new ApiException(500, '用户不存在');
|
||||
return response([
|
||||
'data' => $user
|
||||
]);
|
||||
@@ -32,10 +33,10 @@ class UserController extends Controller
|
||||
$params = $request->validated();
|
||||
$user = User::find($request->input('id'));
|
||||
if (!$user) {
|
||||
abort(500, '用户不存在');
|
||||
throw new ApiException(500, '用户不存在');
|
||||
}
|
||||
if (User::where('email', $params['email'])->first() && $user->email !== $params['email']) {
|
||||
abort(500, '邮箱已被使用');
|
||||
throw new ApiException(500, '邮箱已被使用');
|
||||
}
|
||||
if (isset($params['password'])) {
|
||||
$params['password'] = password_hash($params['password'], PASSWORD_DEFAULT);
|
||||
@@ -46,7 +47,7 @@ class UserController extends Controller
|
||||
if (isset($params['plan_id'])) {
|
||||
$plan = Plan::find($params['plan_id']);
|
||||
if (!$plan) {
|
||||
abort(500, '订阅计划不存在');
|
||||
throw new ApiException(500, '订阅计划不存在');
|
||||
}
|
||||
$params['group_id'] = $plan->group_id;
|
||||
}
|
||||
@@ -54,7 +55,7 @@ class UserController extends Controller
|
||||
try {
|
||||
$user->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
throw new ApiException(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
@@ -97,7 +98,7 @@ class UserController extends Controller
|
||||
'banned' => 1
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '处理失败');
|
||||
throw new ApiException(500, '处理失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\User;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Payment;
|
||||
use App\Utils\Dict;
|
||||
@@ -33,7 +34,7 @@ class CommController extends Controller
|
||||
$payment = Payment::where('id', $request->input('id'))
|
||||
->where('payment', 'StripeCredit')
|
||||
->first();
|
||||
if (!$payment) abort(500, 'payment is not found');
|
||||
if (!$payment) throw new ApiException(500, 'payment is not found');
|
||||
return response([
|
||||
'data' => $payment->config['stripe_pk_live']
|
||||
]);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\User;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\CouponService;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -11,7 +12,7 @@ class CouponController extends Controller
|
||||
public function check(Request $request)
|
||||
{
|
||||
if (empty($request->input('code'))) {
|
||||
abort(500, __('Coupon cannot be empty'));
|
||||
throw new ApiException(500, __('Coupon cannot be empty'));
|
||||
}
|
||||
$couponService = new CouponService($request->input('code'));
|
||||
$couponService->setPlanId($request->input('plan_id'));
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\User;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CommissionLog;
|
||||
use App\Models\InviteCode;
|
||||
@@ -15,7 +16,7 @@ class InviteController extends Controller
|
||||
public function save(Request $request)
|
||||
{
|
||||
if (InviteCode::where('user_id', $request->user['id'])->where('status', 0)->count() >= admin_setting('invite_gen_limit', 5)) {
|
||||
abort(500, __('The maximum number of creations has been reached'));
|
||||
throw new ApiException(500, __('The maximum number of creations has been reached'));
|
||||
}
|
||||
$inviteCode = new InviteCode();
|
||||
$inviteCode->user_id = $request->user['id'];
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\User;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Knowledge;
|
||||
use App\Models\User;
|
||||
@@ -18,7 +19,7 @@ class KnowledgeController extends Controller
|
||||
->where('show', 1)
|
||||
->first()
|
||||
->toArray();
|
||||
if (!$knowledge) abort(500, __('Article does not exist'));
|
||||
if (!$knowledge) throw new ApiException(500, __('Article does not exist'));
|
||||
$user = User::find($request->user['id']);
|
||||
$userService = new UserService();
|
||||
if (!$userService->isAvailable($user)) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\User;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\User\OrderSave;
|
||||
use App\Models\Order;
|
||||
@@ -53,12 +54,12 @@ class OrderController extends Controller
|
||||
->where('trade_no', $request->input('trade_no'))
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, __('Order does not exist or has been paid'));
|
||||
throw new ApiException(500, __('Order does not exist or has been paid'));
|
||||
}
|
||||
$order['plan'] = Plan::find($order->plan_id);
|
||||
$order['try_out_plan_id'] = (int)admin_setting('try_out_plan_id');
|
||||
if (!$order['plan']) {
|
||||
abort(500, __('Subscription plan does not exist'));
|
||||
throw new ApiException(500, __('Subscription plan does not exist'));
|
||||
}
|
||||
if ($order->surplus_order_ids) {
|
||||
$order['surplus_orders'] = Order::whereIn('id', $order->surplus_order_ids)->get();
|
||||
@@ -72,7 +73,7 @@ class OrderController extends Controller
|
||||
{
|
||||
$userService = new UserService();
|
||||
if ($userService->isNotCompleteOrderByUserId($request->user['id'])) {
|
||||
abort(500, __('You have an unpaid or pending order, please try again later or cancel it'));
|
||||
throw new ApiException(500, __('You have an unpaid or pending order, please try again later or cancel it'));
|
||||
}
|
||||
|
||||
$planService = new PlanService($request->input('plan_id'));
|
||||
@@ -81,36 +82,36 @@ class OrderController extends Controller
|
||||
$user = User::find($request->user['id']);
|
||||
|
||||
if (!$plan) {
|
||||
abort(500, __('Subscription plan does not exist'));
|
||||
throw new ApiException(500, __('Subscription plan does not exist'));
|
||||
}
|
||||
|
||||
if ($user->plan_id !== $plan->id && !$planService->haveCapacity() && $request->input('period') !== 'reset_price') {
|
||||
abort(500, __('Current product is sold out'));
|
||||
throw new ApiException(500, __('Current product is sold out'));
|
||||
}
|
||||
|
||||
if ($plan[$request->input('period')] === NULL) {
|
||||
abort(500, __('This payment period cannot be purchased, please choose another period'));
|
||||
throw new ApiException(500, __('This payment period cannot be purchased, please choose another period'));
|
||||
}
|
||||
|
||||
if ($request->input('period') === 'reset_price') {
|
||||
if (!$userService->isAvailable($user) || $plan->id !== $user->plan_id) {
|
||||
abort(500, __('Subscription has expired or no active subscription, unable to purchase Data Reset Package'));
|
||||
throw new ApiException(500, __('Subscription has expired or no active subscription, unable to purchase Data Reset Package'));
|
||||
}
|
||||
}
|
||||
|
||||
if ((!$plan->show && !$plan->renew) || (!$plan->show && $user->plan_id !== $plan->id)) {
|
||||
if ($request->input('period') !== 'reset_price') {
|
||||
abort(500, __('This subscription has been sold out, please choose another subscription'));
|
||||
throw new ApiException(500, __('This subscription has been sold out, please choose another subscription'));
|
||||
}
|
||||
}
|
||||
|
||||
if (!$plan->renew && $user->plan_id == $plan->id && $request->input('period') !== 'reset_price') {
|
||||
abort(500, __('This subscription cannot be renewed, please change to another subscription'));
|
||||
throw new ApiException(500, __('This subscription cannot be renewed, please change to another subscription'));
|
||||
}
|
||||
|
||||
|
||||
if (!$plan->show && $plan->renew && !$userService->isAvailable($user)) {
|
||||
abort(500, __('This subscription has expired, please change to another subscription'));
|
||||
throw new ApiException(500, __('This subscription has expired, please change to another subscription'));
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
@@ -126,7 +127,7 @@ class OrderController extends Controller
|
||||
$couponService = new CouponService($request->input('coupon_code'));
|
||||
if (!$couponService->use($order)) {
|
||||
DB::rollBack();
|
||||
abort(500, __('Coupon failed'));
|
||||
throw new ApiException(500, __('Coupon failed'));
|
||||
}
|
||||
$order->coupon_id = $couponService->getId();
|
||||
}
|
||||
@@ -141,14 +142,14 @@ class OrderController extends Controller
|
||||
if ($remainingBalance > 0) {
|
||||
if (!$userService->addBalance($order->user_id, - $order->total_amount)) {
|
||||
DB::rollBack();
|
||||
abort(500, __('Insufficient balance'));
|
||||
throw new ApiException(500, __('Insufficient balance'));
|
||||
}
|
||||
$order->balance_amount = $order->total_amount;
|
||||
$order->total_amount = 0;
|
||||
} else {
|
||||
if (!$userService->addBalance($order->user_id, - $user->balance)) {
|
||||
DB::rollBack();
|
||||
abort(500, __('Insufficient balance'));
|
||||
throw new ApiException(500, __('Insufficient balance'));
|
||||
}
|
||||
$order->balance_amount = $user->balance;
|
||||
$order->total_amount = $order->total_amount - $user->balance;
|
||||
@@ -157,7 +158,7 @@ class OrderController extends Controller
|
||||
|
||||
if (!$order->save()) {
|
||||
DB::rollback();
|
||||
abort(500, __('Failed to create order'));
|
||||
throw new ApiException(500, __('Failed to create order'));
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
@@ -176,26 +177,26 @@ class OrderController extends Controller
|
||||
->where('status', 0)
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, __('Order does not exist or has been paid'));
|
||||
throw new ApiException(500, __('Order does not exist or has been paid'));
|
||||
}
|
||||
// free process
|
||||
if ($order->total_amount <= 0) {
|
||||
$orderService = new OrderService($order);
|
||||
if (!$orderService->paid($order->trade_no)) abort(500, '');
|
||||
if (!$orderService->paid($order->trade_no)) throw new ApiException(500, '');
|
||||
return response([
|
||||
'type' => -1,
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
$payment = Payment::find($method);
|
||||
if (!$payment || $payment->enable !== 1) abort(500, __('Payment method is not available'));
|
||||
if (!$payment || $payment->enable !== 1) throw new ApiException(500, __('Payment method is not available'));
|
||||
$paymentService = new PaymentService($payment->payment, $payment->id);
|
||||
$order->handling_amount = NULL;
|
||||
if ($payment->handling_fee_fixed || $payment->handling_fee_percent) {
|
||||
$order->handling_amount = round(($order->total_amount * ($payment->handling_fee_percent / 100)) + $payment->handling_fee_fixed);
|
||||
}
|
||||
$order->payment_id = $method;
|
||||
if (!$order->save()) abort(500, __('Request failed, please try again later'));
|
||||
if (!$order->save()) throw new ApiException(500, __('Request failed, please try again later'));
|
||||
$result = $paymentService->pay([
|
||||
'trade_no' => $tradeNo,
|
||||
'total_amount' => isset($order->handling_amount) ? ($order->total_amount + $order->handling_amount) : $order->total_amount,
|
||||
@@ -215,7 +216,7 @@ class OrderController extends Controller
|
||||
->where('user_id', $request->user['id'])
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, __('Order does not exist'));
|
||||
throw new ApiException(500, __('Order does not exist'));
|
||||
}
|
||||
return response([
|
||||
'data' => $order->status
|
||||
@@ -244,20 +245,20 @@ class OrderController extends Controller
|
||||
public function cancel(Request $request)
|
||||
{
|
||||
if (empty($request->input('trade_no'))) {
|
||||
abort(500, __('Invalid parameter'));
|
||||
throw new ApiException(500, __('Invalid parameter'));
|
||||
}
|
||||
$order = Order::where('trade_no', $request->input('trade_no'))
|
||||
->where('user_id', $request->user['id'])
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, __('Order does not exist'));
|
||||
throw new ApiException(500, __('Order does not exist'));
|
||||
}
|
||||
if ($order->status !== 0) {
|
||||
abort(500, __('You can only cancel pending orders'));
|
||||
throw new ApiException(500, __('You can only cancel pending orders'));
|
||||
}
|
||||
$orderService = new OrderService($order);
|
||||
if (!$orderService->cancel()) {
|
||||
abort(500, __('Cancel failed'));
|
||||
throw new ApiException(500, __('Cancel failed'));
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\User;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
@@ -17,10 +18,10 @@ class PlanController extends Controller
|
||||
if ($request->input('id')) {
|
||||
$plan = Plan::where('id', $request->input('id'))->first();
|
||||
if (!$plan) {
|
||||
abort(500, __('Subscription plan does not exist'));
|
||||
throw new ApiException(500, __('Subscription plan does not exist'));
|
||||
}
|
||||
if ((!$plan->show && !$plan->renew) || (!$plan->show && $user->plan_id !== $plan->id)) {
|
||||
abort(500, __('Subscription plan does not exist'));
|
||||
throw new ApiException(500, __('Subscription plan does not exist'));
|
||||
}
|
||||
return response([
|
||||
'data' => $plan
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\User;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\User\TicketSave;
|
||||
use App\Http\Requests\User\TicketWithdraw;
|
||||
@@ -23,7 +24,7 @@ class TicketController extends Controller
|
||||
->where('user_id', $request->user['id'])
|
||||
->first();
|
||||
if (!$ticket) {
|
||||
abort(500, __('Ticket does not exist'));
|
||||
throw new ApiException(500, __('Ticket does not exist'));
|
||||
}
|
||||
$ticket['message'] = TicketMessage::where('ticket_id', $ticket->id)->get();
|
||||
for ($i = 0; $i < count($ticket['message']); $i++) {
|
||||
@@ -49,7 +50,7 @@ class TicketController extends Controller
|
||||
{
|
||||
DB::beginTransaction();
|
||||
if ((int)Ticket::where('status', 0)->where('user_id', $request->user['id'])->lockForUpdate()->count()) {
|
||||
abort(500, __('There are other unresolved tickets'));
|
||||
throw new ApiException(500, __('There are other unresolved tickets'));
|
||||
}
|
||||
$ticket = Ticket::create(array_merge($request->only([
|
||||
'subject',
|
||||
@@ -59,7 +60,7 @@ class TicketController extends Controller
|
||||
]));
|
||||
if (!$ticket) {
|
||||
DB::rollback();
|
||||
abort(500, __('Failed to open ticket'));
|
||||
throw new ApiException(500, __('Failed to open ticket'));
|
||||
}
|
||||
$ticketMessage = TicketMessage::create([
|
||||
'user_id' => $request->user['id'],
|
||||
@@ -68,7 +69,7 @@ class TicketController extends Controller
|
||||
]);
|
||||
if (!$ticketMessage) {
|
||||
DB::rollback();
|
||||
abort(500, __('Failed to open ticket'));
|
||||
throw new ApiException(500, __('Failed to open ticket'));
|
||||
}
|
||||
DB::commit();
|
||||
$this->sendNotify($ticket, $request->input('message'));
|
||||
@@ -80,22 +81,22 @@ class TicketController extends Controller
|
||||
public function reply(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, __('Invalid parameter'));
|
||||
throw new ApiException(500, __('Invalid parameter'));
|
||||
}
|
||||
if (empty($request->input('message'))) {
|
||||
abort(500, __('Message cannot be empty'));
|
||||
throw new ApiException(500, __('Message cannot be empty'));
|
||||
}
|
||||
$ticket = Ticket::where('id', $request->input('id'))
|
||||
->where('user_id', $request->user['id'])
|
||||
->first();
|
||||
if (!$ticket) {
|
||||
abort(500, __('Ticket does not exist'));
|
||||
throw new ApiException(500, __('Ticket does not exist'));
|
||||
}
|
||||
if ($ticket->status) {
|
||||
abort(500, __('The ticket is closed and cannot be replied'));
|
||||
throw new ApiException(500, __('The ticket is closed and cannot be replied'));
|
||||
}
|
||||
if ($request->user['id'] == $this->getLastMessage($ticket->id)->user_id) {
|
||||
abort(500, __('Please wait for the technical enginneer to reply'));
|
||||
throw new ApiException(500, __('Please wait for the technical enginneer to reply'));
|
||||
}
|
||||
$ticketService = new TicketService();
|
||||
if (!$ticketService->reply(
|
||||
@@ -103,7 +104,7 @@ class TicketController extends Controller
|
||||
$request->input('message'),
|
||||
$request->user['id']
|
||||
)) {
|
||||
abort(500, __('Ticket reply failed'));
|
||||
throw new ApiException(500, __('Ticket reply failed'));
|
||||
}
|
||||
$this->sendNotify($ticket, $request->input('message'));
|
||||
return response([
|
||||
@@ -115,17 +116,17 @@ class TicketController extends Controller
|
||||
public function close(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, __('Invalid parameter'));
|
||||
throw new ApiException(500, __('Invalid parameter'));
|
||||
}
|
||||
$ticket = Ticket::where('id', $request->input('id'))
|
||||
->where('user_id', $request->user['id'])
|
||||
->first();
|
||||
if (!$ticket) {
|
||||
abort(500, __('Ticket does not exist'));
|
||||
throw new ApiException(500, __('Ticket does not exist'));
|
||||
}
|
||||
$ticket->status = 1;
|
||||
if (!$ticket->save()) {
|
||||
abort(500, __('Close failed'));
|
||||
throw new ApiException(500, __('Close failed'));
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
@@ -142,18 +143,18 @@ class TicketController extends Controller
|
||||
public function withdraw(TicketWithdraw $request)
|
||||
{
|
||||
if ((int)admin_setting('withdraw_close_enable', 0)) {
|
||||
abort(500, 'user.ticket.withdraw.not_support_withdraw');
|
||||
throw new ApiException(500, 'user.ticket.withdraw.not_support_withdraw');
|
||||
}
|
||||
if (!in_array(
|
||||
$request->input('withdraw_method'),
|
||||
admin_setting('commission_withdraw_method',Dict::WITHDRAW_METHOD_WHITELIST_DEFAULT)
|
||||
)) {
|
||||
abort(500, __('Unsupported withdrawal method'));
|
||||
throw new ApiException(500, __('Unsupported withdrawal method'));
|
||||
}
|
||||
$user = User::find($request->user['id']);
|
||||
$limit = admin_setting('commission_withdraw_limit', 100);
|
||||
if ($limit > ($user->commission_balance / 100)) {
|
||||
abort(500, __('The current required minimum withdrawal commission is :limit', ['limit' => $limit]));
|
||||
throw new ApiException(500, __('The current required minimum withdrawal commission is :limit', ['limit' => $limit]));
|
||||
}
|
||||
DB::beginTransaction();
|
||||
$subject = __('[Commission Withdrawal Request] This ticket is opened by the system');
|
||||
@@ -164,7 +165,7 @@ class TicketController extends Controller
|
||||
]);
|
||||
if (!$ticket) {
|
||||
DB::rollback();
|
||||
abort(500, __('Failed to open ticket'));
|
||||
throw new ApiException(500, __('Failed to open ticket'));
|
||||
}
|
||||
$message = sprintf("%s\r\n%s",
|
||||
__('Withdrawal method') . ":" . $request->input('withdraw_method'),
|
||||
@@ -177,7 +178,7 @@ class TicketController extends Controller
|
||||
]);
|
||||
if (!$ticketMessage) {
|
||||
DB::rollback();
|
||||
abort(500, __('Failed to open ticket'));
|
||||
throw new ApiException(500, __('Failed to open ticket'));
|
||||
}
|
||||
DB::commit();
|
||||
$this->sendNotify($ticket, $message);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\V1\User;
|
||||
|
||||
use App\Exceptions\ApiException;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\User\UserChangePassword;
|
||||
use App\Http\Requests\User\UserTransfer;
|
||||
@@ -23,7 +24,7 @@ class UserController extends Controller
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
throw new ApiException(500, __('The user does not exist'));
|
||||
}
|
||||
$authService = new AuthService($user);
|
||||
return response([
|
||||
@@ -35,7 +36,7 @@ class UserController extends Controller
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
throw new ApiException(500, __('The user does not exist'));
|
||||
}
|
||||
$authService = new AuthService($user);
|
||||
return response([
|
||||
@@ -60,7 +61,7 @@ class UserController extends Controller
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
throw new ApiException(500, __('The user does not exist'));
|
||||
}
|
||||
if (!Helper::multiPasswordVerify(
|
||||
$user->password_algo,
|
||||
@@ -68,13 +69,13 @@ class UserController extends Controller
|
||||
$request->input('old_password'),
|
||||
$user->password)
|
||||
) {
|
||||
abort(500, __('The old password is wrong'));
|
||||
throw new ApiException(500, __('The old password is wrong'));
|
||||
}
|
||||
$user->password = password_hash($request->input('new_password'), PASSWORD_DEFAULT);
|
||||
$user->password_algo = NULL;
|
||||
$user->password_salt = NULL;
|
||||
if (!$user->save()) {
|
||||
abort(500, __('Save failed'));
|
||||
throw new ApiException(500, __('Save failed'));
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
@@ -103,7 +104,7 @@ class UserController extends Controller
|
||||
])
|
||||
->first();
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
throw new ApiException(500, __('The user does not exist'));
|
||||
}
|
||||
$user['avatar_url'] = 'https://cdn.v2ex.com/gravatar/' . md5($user->email) . '?s=64&d=identicon';
|
||||
return response([
|
||||
@@ -143,12 +144,12 @@ class UserController extends Controller
|
||||
])
|
||||
->first();
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
throw new ApiException(500, __('The user does not exist'));
|
||||
}
|
||||
if ($user->plan_id) {
|
||||
$user['plan'] = Plan::find($user->plan_id);
|
||||
if (!$user['plan']) {
|
||||
abort(500, __('Subscription plan does not exist'));
|
||||
throw new ApiException(500, __('Subscription plan does not exist'));
|
||||
}
|
||||
}
|
||||
$user['subscribe_url'] = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}");
|
||||
@@ -163,12 +164,12 @@ class UserController extends Controller
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
throw new ApiException(500, __('The user does not exist'));
|
||||
}
|
||||
$user->uuid = Helper::guid(true);
|
||||
$user->token = Helper::guid();
|
||||
if (!$user->save()) {
|
||||
abort(500, __('Reset failed'));
|
||||
throw new ApiException(500, __('Reset failed'));
|
||||
}
|
||||
return response([
|
||||
'data' => Helper::getSubscribeUrl('/api/v1/client/subscribe?token=' . $user->token)
|
||||
@@ -184,12 +185,12 @@ class UserController extends Controller
|
||||
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
throw new ApiException(500, __('The user does not exist'));
|
||||
}
|
||||
try {
|
||||
$user->update($updateData);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, __('Save failed'));
|
||||
throw new ApiException(500, __('Save failed'));
|
||||
}
|
||||
|
||||
return response([
|
||||
@@ -201,15 +202,15 @@ class UserController extends Controller
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
throw new ApiException(500, __('The user does not exist'));
|
||||
}
|
||||
if ($request->input('transfer_amount') > $user->commission_balance) {
|
||||
abort(500, __('Insufficient commission balance'));
|
||||
throw new ApiException(500, __('Insufficient commission balance'));
|
||||
}
|
||||
$user->commission_balance = $user->commission_balance - $request->input('transfer_amount');
|
||||
$user->balance = $user->balance + $request->input('transfer_amount');
|
||||
if (!$user->save()) {
|
||||
abort(500, __('Transfer failed'));
|
||||
throw new ApiException(500, __('Transfer failed'));
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
@@ -220,7 +221,7 @@ class UserController extends Controller
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
throw new ApiException(500, __('The user does not exist'));
|
||||
}
|
||||
|
||||
$code = Helper::guid();
|
||||
|
||||
Reference in New Issue
Block a user