update: new auth

This commit is contained in:
tokumeikoi 2022-07-19 03:11:36 +08:00
parent dc27410c12
commit adf465696a
22 changed files with 132 additions and 167 deletions

View File

@ -1,53 +0,0 @@
<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
class CheckUser extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'check:user';
/**
* The console command description.
*
* @var string
*/
protected $description = '用户检查任务';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->resetExpiredUserPlan();
}
private function resetExpiredUserPlan($day = 14)
{
User::where('expired_at', '<', $day * 86400)
->whereNotNull('expired_at')
->update([
'plan_id' => NULL,
'group_id' => NULL
]);
}
}

View File

@ -33,7 +33,6 @@ class Kernel extends ConsoleKernel
$schedule->command('check:order')->everyMinute(); $schedule->command('check:order')->everyMinute();
$schedule->command('check:commission')->everyMinute(); $schedule->command('check:commission')->everyMinute();
$schedule->command('check:ticket')->everyMinute(); $schedule->command('check:ticket')->everyMinute();
$schedule->command('check:user')->daily();
// reset // reset
$schedule->command('reset:traffic')->daily(); $schedule->command('reset:traffic')->daily();
$schedule->command('reset:log')->daily(); $schedule->command('reset:log')->daily();

View File

@ -39,7 +39,7 @@ class ConfigController extends Controller
public function testSendMail(Request $request) public function testSendMail(Request $request)
{ {
$obj = new SendEmailJob([ $obj = new SendEmailJob([
'email' => $request->user->email, 'email' => $request->user['email'],
'subject' => 'This is v2board test email', 'subject' => 'This is v2board test email',
'template_name' => 'notify', 'template_name' => 'notify',
'template_value' => [ 'template_value' => [

View File

@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Requests\Admin\PlanSave; use App\Http\Requests\Admin\PlanSave;
use App\Http\Requests\Admin\PlanSort; use App\Http\Requests\Admin\PlanSort;
use App\Http\Requests\Admin\PlanUpdate; use App\Http\Requests\Admin\PlanUpdate;
use App\Services\PlanService;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Plan; use App\Models\Plan;
@ -16,17 +17,7 @@ class PlanController extends Controller
{ {
public function fetch(Request $request) public function fetch(Request $request)
{ {
$counts = User::select( $counts = PlanService::countActiveUsers();
DB::raw("plan_id"),
DB::raw("count(*) as count")
)
->where('plan_id', '!=', NULL)
->where(function ($query) {
$query->where('expired_at', '>=', time())
->orWhere('expired_at', NULL);
})
->groupBy("plan_id")
->get();
$plans = Plan::orderBy('sort', 'ASC')->get(); $plans = Plan::orderBy('sort', 'ASC')->get();
foreach ($plans as $k => $v) { foreach ($plans as $k => $v) {
$plans[$k]->count = 0; $plans[$k]->count = 0;

View File

@ -68,7 +68,7 @@ class TicketController extends Controller
$ticketService->replyByAdmin( $ticketService->replyByAdmin(
$request->input('id'), $request->input('id'),
$request->input('message'), $request->input('message'),
$request->user->id $request->user['id']
); );
return response([ return response([
'data' => true 'data' => true

View File

@ -57,7 +57,7 @@ class TicketController extends Controller
$ticketService->replyByAdmin( $ticketService->replyByAdmin(
$request->input('id'), $request->input('id'),
$request->input('message'), $request->input('message'),
$request->user->id $request->user['id']
); );
return response([ return response([
'data' => true 'data' => true

View File

@ -16,7 +16,7 @@ class CouponController extends Controller
} }
$couponService = new CouponService($request->input('code')); $couponService = new CouponService($request->input('code'));
$couponService->setPlanId($request->input('plan_id')); $couponService->setPlanId($request->input('plan_id'));
$couponService->setUserId($request->user->id); $couponService->setUserId($request->user['id']);
$couponService->check(); $couponService->check();
return response([ return response([
'data' => $couponService->getCoupon() 'data' => $couponService->getCoupon()

View File

@ -14,11 +14,11 @@ class InviteController extends Controller
{ {
public function save(Request $request) public function save(Request $request)
{ {
if (InviteCode::where('user_id', $request->user->id)->where('status', 0)->count() >= config('v2board.invite_gen_limit', 5)) { if (InviteCode::where('user_id', $request->user['id'])->where('status', 0)->count() >= config('v2board.invite_gen_limit', 5)) {
abort(500, __('The maximum number of creations has been reached')); abort(500, __('The maximum number of creations has been reached'));
} }
$inviteCode = new InviteCode(); $inviteCode = new InviteCode();
$inviteCode->user_id = $request->user->id; $inviteCode->user_id = $request->user['id'];
$inviteCode->code = Helper::randomChar(8); $inviteCode->code = Helper::randomChar(8);
return response([ return response([
'data' => $inviteCode->save() 'data' => $inviteCode->save()
@ -28,7 +28,7 @@ class InviteController extends Controller
public function details(Request $request) public function details(Request $request)
{ {
return response([ return response([
'data' => CommissionLog::where('invite_user_id', $request->user->id) 'data' => CommissionLog::where('invite_user_id', $request->user['id'])
->where('get_amount', '>', 0) ->where('get_amount', '>', 0)
->select([ ->select([
'id', 'id',
@ -43,26 +43,26 @@ class InviteController extends Controller
public function fetch(Request $request) public function fetch(Request $request)
{ {
$codes = InviteCode::where('user_id', $request->user->id) $codes = InviteCode::where('user_id', $request->user['id'])
->where('status', 0) ->where('status', 0)
->get(); ->get();
$commission_rate = config('v2board.invite_commission', 10); $commission_rate = config('v2board.invite_commission', 10);
$user = User::find($request->user->id); $user = User::find($request->user['id']);
if ($user->commission_rate) { if ($user->commission_rate) {
$commission_rate = $user->commission_rate; $commission_rate = $user->commission_rate;
} }
$stat = [ $stat = [
//已注册用户数 //已注册用户数
(int)User::where('invite_user_id', $request->user->id)->count(), (int)User::where('invite_user_id', $request->user['id'])->count(),
//有效的佣金 //有效的佣金
(int)Order::where('status', 3) (int)Order::where('status', 3)
->where('commission_status', 2) ->where('commission_status', 2)
->where('invite_user_id', $request->user->id) ->where('invite_user_id', $request->user['id'])
->sum('commission_balance'), ->sum('commission_balance'),
//确认中的佣金 //确认中的佣金
(int)Order::where('status', 3) (int)Order::where('status', 3)
->where('commission_status', 0) ->where('commission_status', 0)
->where('invite_user_id', $request->user->id) ->where('invite_user_id', $request->user['id'])
->sum('commission_balance'), ->sum('commission_balance'),
//佣金比例 //佣金比例
(int)$commission_rate, (int)$commission_rate,

View File

@ -19,14 +19,9 @@ class KnowledgeController extends Controller
->first() ->first()
->toArray(); ->toArray();
if (!$knowledge) abort(500, __('Article does not exist')); if (!$knowledge) abort(500, __('Article does not exist'));
$user = User::find($request->user->id); $user = User::find($request->user['id']);
$userService = new UserService(); $userService = new UserService();
if ($userService->isAvailable($user)) { if (!$userService->isAvailable($user)) {
$appleId = config('v2board.apple_id');
$appleIdPassword = config('v2board.apple_id_password');
} else {
$appleId = __('No active subscription. Unable to use our provided Apple ID');
$appleIdPassword = __('No active subscription. Unable to use our provided Apple ID');
$this->formatAccessData($knowledge['body']); $this->formatAccessData($knowledge['body']);
} }
$subscribeUrl = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}"); $subscribeUrl = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}");

View File

@ -29,7 +29,7 @@ class OrderController extends Controller
{ {
public function fetch(Request $request) public function fetch(Request $request)
{ {
$model = Order::where('user_id', $request->user->id) $model = Order::where('user_id', $request->user['id'])
->orderBy('created_at', 'DESC'); ->orderBy('created_at', 'DESC');
if ($request->input('status') !== null) { if ($request->input('status') !== null) {
$model->where('status', $request->input('status')); $model->where('status', $request->input('status'));
@ -50,7 +50,7 @@ class OrderController extends Controller
public function detail(Request $request) public function detail(Request $request)
{ {
$order = Order::where('user_id', $request->user->id) $order = Order::where('user_id', $request->user['id'])
->where('trade_no', $request->input('trade_no')) ->where('trade_no', $request->input('trade_no'))
->first(); ->first();
if (!$order) { if (!$order) {
@ -72,14 +72,14 @@ class OrderController extends Controller
public function save(OrderSave $request) public function save(OrderSave $request)
{ {
$userService = new UserService(); $userService = new UserService();
if ($userService->isNotCompleteOrderByUserId($request->user->id)) { if ($userService->isNotCompleteOrderByUserId($request->user['id'])) {
abort(500, __('You have an unpaid or pending order, please try again later or cancel it')); abort(500, __('You have an unpaid or pending order, please try again later or cancel it'));
} }
$planService = new PlanService($request->input('plan_id')); $planService = new PlanService($request->input('plan_id'));
$plan = $planService->plan; $plan = $planService->plan;
$user = User::find($request->user->id); $user = User::find($request->user['id']);
if (!$plan) { if (!$plan) {
abort(500, __('Subscription plan does not exist')); abort(500, __('Subscription plan does not exist'));
@ -94,7 +94,7 @@ class OrderController extends Controller
} }
if ($request->input('period') === 'reset_price') { if ($request->input('period') === 'reset_price') {
if (!$user->plan_id) { if (!$user->plan_id || $user->expired_at < time() || $user->expired_at !== NULL) {
abort(500, __('Subscription has expired or no active subscription, unable to purchase Data Reset Package')); abort(500, __('Subscription has expired or no active subscription, unable to purchase Data Reset Package'));
} else { } else {
if ($user->plan_id !== $plan->id) { if ($user->plan_id !== $plan->id) {
@ -121,7 +121,7 @@ class OrderController extends Controller
DB::beginTransaction(); DB::beginTransaction();
$order = new Order(); $order = new Order();
$orderService = new OrderService($order); $orderService = new OrderService($order);
$order->user_id = $request->user->id; $order->user_id = $request->user['id'];
$order->plan_id = $plan->id; $order->plan_id = $plan->id;
$order->period = $request->input('period'); $order->period = $request->input('period');
$order->trade_no = Helper::generateOrderNo(); $order->trade_no = Helper::generateOrderNo();
@ -177,7 +177,7 @@ class OrderController extends Controller
$tradeNo = $request->input('trade_no'); $tradeNo = $request->input('trade_no');
$method = $request->input('method'); $method = $request->input('method');
$order = Order::where('trade_no', $tradeNo) $order = Order::where('trade_no', $tradeNo)
->where('user_id', $request->user->id) ->where('user_id', $request->user['id'])
->where('status', 0) ->where('status', 0)
->first(); ->first();
if (!$order) { if (!$order) {
@ -216,7 +216,7 @@ class OrderController extends Controller
{ {
$tradeNo = $request->input('trade_no'); $tradeNo = $request->input('trade_no');
$order = Order::where('trade_no', $tradeNo) $order = Order::where('trade_no', $tradeNo)
->where('user_id', $request->user->id) ->where('user_id', $request->user['id'])
->first(); ->first();
if (!$order) { if (!$order) {
abort(500, __('Order does not exist')); abort(500, __('Order does not exist'));
@ -249,7 +249,7 @@ class OrderController extends Controller
abort(500, __('Invalid parameter')); abort(500, __('Invalid parameter'));
} }
$order = Order::where('trade_no', $request->input('trade_no')) $order = Order::where('trade_no', $request->input('trade_no'))
->where('user_id', $request->user->id) ->where('user_id', $request->user['id'])
->first(); ->first();
if (!$order) { if (!$order) {
abort(500, __('Order does not exist')); abort(500, __('Order does not exist'));

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\User; use App\Models\User;
use App\Services\PlanService;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\Plan; use App\Models\Plan;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@ -12,7 +13,7 @@ class PlanController extends Controller
{ {
public function fetch(Request $request) public function fetch(Request $request)
{ {
$user = User::find($request->user->id); $user = User::find($request->user['id']);
if ($request->input('id')) { if ($request->input('id')) {
$plan = Plan::where('id', $request->input('id'))->first(); $plan = Plan::where('id', $request->input('id'))->first();
if (!$plan) { if (!$plan) {
@ -24,29 +25,16 @@ class PlanController extends Controller
return response([ return response([
'data' => $plan 'data' => $plan
]); ]);
} else {
$counts = User::select(
DB::raw("plan_id"),
DB::raw("count(*) as count")
)
->where('plan_id', '!=', NULL)
->where(function ($query) {
$query->where('expired_at', '>=', time())
->orWhere('expired_at', NULL);
})
->groupBy("plan_id")
->get()
->keyBy('plan_id');
} }
$counts = PlanService::countActiveUsers();
$plans = Plan::where('show', 1) $plans = Plan::where('show', 1)
->orderBy('sort', 'ASC') ->orderBy('sort', 'ASC')
->get(); ->get();
if (isset($counts)) { foreach ($plans as $k => $v) {
foreach ($plans as $k => $v) { if ($plans[$k]->capacity_limit === NULL) continue;
if ($plans[$k]->capacity_limit === NULL) continue; if (!isset($counts[$plans[$k]->id])) continue;
if (!isset($counts[$plans[$k]->id])) continue; $plans[$k]->capacity_limit = $plans[$k]->capacity_limit - $counts[$plans[$k]->id]->count;
$plans[$k]->capacity_limit = $plans[$k]->capacity_limit - $counts[$plans[$k]->id]->count;
}
} }
return response([ return response([
'data' => $plans 'data' => $plans

View File

@ -19,7 +19,7 @@ class ServerController extends Controller
{ {
public function fetch(Request $request) public function fetch(Request $request)
{ {
$user = User::find($request->user->id); $user = User::find($request->user['id']);
$servers = []; $servers = [];
$userService = new UserService(); $userService = new UserService();
if ($userService->isAvailable($user)) { if ($userService->isAvailable($user)) {

View File

@ -18,7 +18,7 @@ class StatController extends Controller
'user_id', 'user_id',
'server_rate' 'server_rate'
]) ])
->where('user_id', $request->user->id) ->where('user_id', $request->user['id'])
->where('record_at', '>=', strtotime(date('Y-m-1'))) ->where('record_at', '>=', strtotime(date('Y-m-1')))
->orderBy('record_at', 'DESC'); ->orderBy('record_at', 'DESC');
return response([ return response([

View File

@ -22,6 +22,6 @@ class TelegramController extends Controller
public function unbind(Request $request) public function unbind(Request $request)
{ {
$user = User::where('user_id', $request->user->id)->first(); $user = User::where('user_id', $request->user['id'])->first();
} }
} }

View File

@ -21,7 +21,7 @@ class TicketController extends Controller
{ {
if ($request->input('id')) { if ($request->input('id')) {
$ticket = Ticket::where('id', $request->input('id')) $ticket = Ticket::where('id', $request->input('id'))
->where('user_id', $request->user->id) ->where('user_id', $request->user['id'])
->first(); ->first();
if (!$ticket) { if (!$ticket) {
abort(500, __('Ticket does not exist')); abort(500, __('Ticket does not exist'));
@ -38,7 +38,7 @@ class TicketController extends Controller
'data' => $ticket 'data' => $ticket
]); ]);
} }
$ticket = Ticket::where('user_id', $request->user->id) $ticket = Ticket::where('user_id', $request->user['id'])
->orderBy('created_at', 'DESC') ->orderBy('created_at', 'DESC')
->get(); ->get();
return response([ return response([
@ -49,21 +49,21 @@ class TicketController extends Controller
public function save(TicketSave $request) public function save(TicketSave $request)
{ {
DB::beginTransaction(); DB::beginTransaction();
if ((int)Ticket::where('status', 0)->where('user_id', $request->user->id)->lockForUpdate()->count()) { if ((int)Ticket::where('status', 0)->where('user_id', $request->user['id'])->lockForUpdate()->count()) {
abort(500, __('There are other unresolved tickets')); abort(500, __('There are other unresolved tickets'));
} }
$ticket = Ticket::create(array_merge($request->only([ $ticket = Ticket::create(array_merge($request->only([
'subject', 'subject',
'level' 'level'
]), [ ]), [
'user_id' => $request->user->id 'user_id' => $request->user['id']
])); ]));
if (!$ticket) { if (!$ticket) {
DB::rollback(); DB::rollback();
abort(500, __('Failed to open ticket')); abort(500, __('Failed to open ticket'));
} }
$ticketMessage = TicketMessage::create([ $ticketMessage = TicketMessage::create([
'user_id' => $request->user->id, 'user_id' => $request->user['id'],
'ticket_id' => $ticket->id, 'ticket_id' => $ticket->id,
'message' => $request->input('message') 'message' => $request->input('message')
]); ]);
@ -87,7 +87,7 @@ class TicketController extends Controller
abort(500, __('Message cannot be empty')); abort(500, __('Message cannot be empty'));
} }
$ticket = Ticket::where('id', $request->input('id')) $ticket = Ticket::where('id', $request->input('id'))
->where('user_id', $request->user->id) ->where('user_id', $request->user['id'])
->first(); ->first();
if (!$ticket) { if (!$ticket) {
abort(500, __('Ticket does not exist')); abort(500, __('Ticket does not exist'));
@ -95,14 +95,14 @@ class TicketController extends Controller
if ($ticket->status) { if ($ticket->status) {
abort(500, __('The ticket is closed and cannot be replied')); abort(500, __('The ticket is closed and cannot be replied'));
} }
if ($request->user->id == $this->getLastMessage($ticket->id)->user_id) { if ($request->user['id'] == $this->getLastMessage($ticket->id)->user_id) {
abort(500, __('Please wait for the technical enginneer to reply')); abort(500, __('Please wait for the technical enginneer to reply'));
} }
$ticketService = new TicketService(); $ticketService = new TicketService();
if (!$ticketService->reply( if (!$ticketService->reply(
$ticket, $ticket,
$request->input('message'), $request->input('message'),
$request->user->id $request->user['id']
)) { )) {
abort(500, __('Ticket reply failed')); abort(500, __('Ticket reply failed'));
} }
@ -119,7 +119,7 @@ class TicketController extends Controller
abort(500, __('Invalid parameter')); abort(500, __('Invalid parameter'));
} }
$ticket = Ticket::where('id', $request->input('id')) $ticket = Ticket::where('id', $request->input('id'))
->where('user_id', $request->user->id) ->where('user_id', $request->user['id'])
->first(); ->first();
if (!$ticket) { if (!$ticket) {
abort(500, __('Ticket does not exist')); abort(500, __('Ticket does not exist'));
@ -154,7 +154,7 @@ class TicketController extends Controller
)) { )) {
abort(500, __('Unsupported withdrawal method')); abort(500, __('Unsupported withdrawal method'));
} }
$user = User::find($request->user->id); $user = User::find($request->user['id']);
$limit = config('v2board.commission_withdraw_limit', 100); $limit = config('v2board.commission_withdraw_limit', 100);
if ($limit > ($user->commission_balance / 100)) { if ($limit > ($user->commission_balance / 100)) {
abort(500, __('The current required minimum withdrawal commission is :limit', ['limit' => $limit])); abort(500, __('The current required minimum withdrawal commission is :limit', ['limit' => $limit]));
@ -164,7 +164,7 @@ class TicketController extends Controller
$ticket = Ticket::create([ $ticket = Ticket::create([
'subject' => $subject, 'subject' => $subject,
'level' => 2, 'level' => 2,
'user_id' => $request->user->id 'user_id' => $request->user['id']
]); ]);
if (!$ticket) { if (!$ticket) {
DB::rollback(); DB::rollback();
@ -175,7 +175,7 @@ class TicketController extends Controller
__('Withdrawal account') . "" . $request->input('withdraw_account') __('Withdrawal account') . "" . $request->input('withdraw_account')
); );
$ticketMessage = TicketMessage::create([ $ticketMessage = TicketMessage::create([
'user_id' => $request->user->id, 'user_id' => $request->user['id'],
'ticket_id' => $ticket->id, 'ticket_id' => $ticket->id,
'message' => $message 'message' => $message
]); ]);

View File

@ -21,9 +21,9 @@ class UserController extends Controller
public function checkLogin(Request $request) public function checkLogin(Request $request)
{ {
$data = [ $data = [
'is_login' => $request->user->id ? true : false 'is_login' => $request->user['id'] ? true : false
]; ];
if ($request->user->is_admin) { if ($request->user['is_admin']) {
$data['is_admin'] = true; $data['is_admin'] = true;
} }
return response([ return response([
@ -33,7 +33,7 @@ class UserController extends Controller
public function changePassword(UserChangePassword $request) public function changePassword(UserChangePassword $request)
{ {
$user = User::find($request->user->id); $user = User::find($request->user['id']);
if (!$user) { if (!$user) {
abort(500, __('The user does not exist')); abort(500, __('The user does not exist'));
} }
@ -58,7 +58,7 @@ class UserController extends Controller
public function info(Request $request) public function info(Request $request)
{ {
$user = User::where('id', $request->user->id) $user = User::where('id', $request->user['id'])
->select([ ->select([
'email', 'email',
'transfer_enable', 'transfer_enable',
@ -90,12 +90,12 @@ class UserController extends Controller
{ {
$stat = [ $stat = [
Order::where('status', 0) Order::where('status', 0)
->where('user_id', $request->user->id) ->where('user_id', $request->user['id'])
->count(), ->count(),
Ticket::where('status', 0) Ticket::where('status', 0)
->where('user_id', $request->user->id) ->where('user_id', $request->user['id'])
->count(), ->count(),
User::where('invite_user_id', $request->user->id) User::where('invite_user_id', $request->user['id'])
->count() ->count()
]; ];
return response([ return response([
@ -105,7 +105,7 @@ class UserController extends Controller
public function getSubscribe(Request $request) public function getSubscribe(Request $request)
{ {
$user = User::where('id', $request->user->id) $user = User::where('id', $request->user['id'])
->select([ ->select([
'plan_id', 'plan_id',
'token', 'token',
@ -135,7 +135,7 @@ class UserController extends Controller
public function resetSecurity(Request $request) public function resetSecurity(Request $request)
{ {
$user = User::find($request->user->id); $user = User::find($request->user['id']);
if (!$user) { if (!$user) {
abort(500, __('The user does not exist')); abort(500, __('The user does not exist'));
} }
@ -156,7 +156,7 @@ class UserController extends Controller
'remind_traffic' 'remind_traffic'
]); ]);
$user = User::find($request->user->id); $user = User::find($request->user['id']);
if (!$user) { if (!$user) {
abort(500, __('The user does not exist')); abort(500, __('The user does not exist'));
} }
@ -173,7 +173,7 @@ class UserController extends Controller
public function transfer(UserTransfer $request) public function transfer(UserTransfer $request)
{ {
$user = User::find($request->user->id); $user = User::find($request->user['id']);
if (!$user) { if (!$user) {
abort(500, __('The user does not exist')); abort(500, __('The user does not exist'));
} }
@ -192,7 +192,7 @@ class UserController extends Controller
public function getQuickLoginUrl(Request $request) public function getQuickLoginUrl(Request $request)
{ {
$user = User::find($request->user->id); $user = User::find($request->user['id']);
if (!$user) { if (!$user) {
abort(500, __('The user does not exist')); abort(500, __('The user does not exist'));
} }

View File

@ -34,9 +34,9 @@ class Kernel extends HttpKernel
// \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, // \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
// \Illuminate\Session\Middleware\StartSession::class, // \Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class, // \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class, // \Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class, // \App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class, // \Illuminate\Routing\Middleware\SubstituteBindings::class,
], ],
'api' => [ 'api' => [

View File

@ -3,7 +3,7 @@
namespace App\Http\Middleware; namespace App\Http\Middleware;
use Closure; use Closure;
use Laravel\Horizon\Horizon; use Illuminate\Support\Facades\Cache;
class Admin class Admin
{ {
@ -20,14 +20,23 @@ class Admin
if (!$authorization) abort(403, '未登录或登陆已过期'); if (!$authorization) abort(403, '未登录或登陆已过期');
$authData = explode(':', base64_decode($authorization)); $authData = explode(':', base64_decode($authorization));
if (!isset($authData[1]) || !isset($authData[0])) abort(403, '鉴权失败,请重新登入'); if (!Cache::has($authorization)) {
$user = \App\Models\User::where('password', $authData[1]) if (!isset($authData[1]) || !isset($authData[0])) abort(403, '鉴权失败,请重新登入');
->where('email', $authData[0]) $user = \App\Models\User::where('password', $authData[1])
->first(); ->where('email', $authData[0])
if (!$user) abort(403, '鉴权失败,请重新登入'); ->select([
if (!$user->is_admin) abort(403, '未登录或登陆已过期'); 'id',
'email',
'is_admin',
'is_staff'
])
->first();
if (!$user) abort(403, '鉴权失败,请重新登入');
if (!$user->is_admin) abort(403, '鉴权失败,请重新登入');
Cache::put($authorization, $user->toArray(), 3600);
}
$request->merge([ $request->merge([
'user' => $user 'user' => Cache::get($authorization)
]); ]);
return $next($request); return $next($request);
} }

View File

@ -3,6 +3,7 @@
namespace App\Http\Middleware; namespace App\Http\Middleware;
use Closure; use Closure;
use Illuminate\Support\Facades\Cache;
class Staff class Staff
{ {
@ -19,14 +20,23 @@ class Staff
if (!$authorization) abort(403, '未登录或登陆已过期'); if (!$authorization) abort(403, '未登录或登陆已过期');
$authData = explode(':', base64_decode($authorization)); $authData = explode(':', base64_decode($authorization));
if (!isset($authData[1]) || !isset($authData[0])) abort(403, '鉴权失败,请重新登入'); if (!Cache::has($authorization)) {
$user = \App\Models\User::where('password', $authData[1]) if (!isset($authData[1]) || !isset($authData[0])) abort(403, '鉴权失败,请重新登入');
->where('email', $authData[0]) $user = \App\Models\User::where('password', $authData[1])
->first(); ->where('email', $authData[0])
if (!$user) abort(403, '鉴权失败,请重新登入'); ->select([
if (!$user->is_staff) abort(403, '未登录或登陆已过期'); 'id',
'email',
'is_admin',
'is_staff'
])
->first();
if (!$user) abort(403, '鉴权失败,请重新登入');
if (!$user->is_staff) abort(403, '鉴权失败,请重新登入');
Cache::put($authorization, $user->toArray(), 3600);
}
$request->merge([ $request->merge([
'user' => $user 'user' => Cache::get($authorization)
]); ]);
return $next($request); return $next($request);
} }

View File

@ -2,8 +2,8 @@
namespace App\Http\Middleware; namespace App\Http\Middleware;
use App\Utils\Helper;
use Closure; use Closure;
use Illuminate\Support\Facades\Cache;
class User class User
{ {
@ -20,13 +20,22 @@ class User
if (!$authorization) abort(403, '未登录或登陆已过期'); if (!$authorization) abort(403, '未登录或登陆已过期');
$authData = explode(':', base64_decode($authorization)); $authData = explode(':', base64_decode($authorization));
if (!isset($authData[1]) || !isset($authData[0])) abort(403, '鉴权失败,请重新登入'); if (!Cache::has($authorization)) {
$user = \App\Models\User::where('password', $authData[1]) if (!isset($authData[1]) || !isset($authData[0])) abort(403, '鉴权失败,请重新登入');
->where('email', $authData[0]) $user = \App\Models\User::where('password', $authData[1])
->first(); ->where('email', $authData[0])
if (!$user) abort(403, '鉴权失败,请重新登入'); ->select([
'id',
'email',
'is_admin',
'is_staff'
])
->first();
if (!$user) abort(403, '鉴权失败,请重新登入');
Cache::put($authorization, $user->toArray(), 3600);
}
$request->merge([ $request->merge([
'user' => $user 'user' => Cache::get($authorization)
]); ]);
return $next($request); return $next($request);
} }

View File

@ -48,10 +48,10 @@ class StatServerJob implements ShouldQueue
// //
} }
$data = StatServer::where('record_at', $recordAt) $data = StatServer::lockForUpdate()
->where('record_at', $recordAt)
->where('server_id', $this->server->id) ->where('server_id', $this->server->id)
->where('server_type', $this->protocol) ->where('server_type', $this->protocol)
->lockForUpdate()
->first(); ->first();
if ($data) { if ($data) {
try { try {

View File

@ -4,6 +4,7 @@ namespace App\Services;
use App\Models\Plan; use App\Models\Plan;
use App\Models\User; use App\Models\User;
use Illuminate\Support\Facades\DB;
class PlanService class PlanService
{ {
@ -20,4 +21,20 @@ class PlanService
$count = User::where('plan_id', $this->plan->plan_id)->count(); $count = User::where('plan_id', $this->plan->plan_id)->count();
return $this->plan->capacity_limit - $count; return $this->plan->capacity_limit - $count;
} }
public static function countActiveUsers()
{
return User::select(
DB::raw("plan_id"),
DB::raw("count(*) as count")
)
->where('plan_id', '!=', NULL)
->where(function ($query) {
$query->where('expired_at', '>=', time())
->orWhere('expired_at', NULL);
})
->groupBy("plan_id")
->get()
->keyBy('plan_id');
}
} }