mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-12 23:48:53 +00:00
🚀 Refactor Blade
- Optimize Blade JavaScript code. - Refactored multiple admin controllers for improved validation, error handling, and query efficiency. - Added ProxyConfig trait to centralize proxy configuration options. - Updated NodeStatusDetection to use model relationships for heartbeat checks. - Improved category, label, and country management logic and error logging. - Added new Blade components for admin UI and updated language files and assets for better localization and frontend support. - Bug fixed & introduced more bug :)
This commit is contained in:
@@ -5,9 +5,11 @@ namespace App\Http\Controllers\User;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Invite;
|
||||
use App\Models\Order;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Response;
|
||||
use Log;
|
||||
use Str;
|
||||
|
||||
class InviteController extends Controller
|
||||
@@ -15,7 +17,7 @@ class InviteController extends Controller
|
||||
public function index(): Response|View
|
||||
{ // 邀请页面
|
||||
if (Order::uid()->active()->where('origin_amount', '>', 0)->doesntExist()) {
|
||||
return Response::view('auth.error', ['message' => trans('user.purchase.required').' <a class="btn btn-sm btn-danger" href="/">'.trans('common.back').'</a>'], 402);
|
||||
return response()->view('auth.error', ['message' => trans('user.purchase.required').' <a class="btn btn-sm btn-danger" href="/">'.trans('common.back').'</a>'], 402);
|
||||
}
|
||||
|
||||
return view('user.invite', [
|
||||
@@ -30,17 +32,26 @@ class InviteController extends Controller
|
||||
public function store(): JsonResponse
|
||||
{ // 生成邀请码
|
||||
$user = auth()->user();
|
||||
|
||||
// 检查用户是否还有邀请码配额
|
||||
if ($user->invite_num <= 0) {
|
||||
return response()->json(['status' => 'fail', 'message' => trans('user.invite.generate_failed')]);
|
||||
}
|
||||
$invite = $user->invites()->create([
|
||||
'code' => strtoupper(mb_substr(md5(microtime().Str::random()), 8, 12)),
|
||||
'dateline' => date('Y-m-d H:i:s', strtotime(sysConfig('user_invite_days').' days')),
|
||||
]);
|
||||
if ($invite) {
|
||||
$user->decrement('invite_num');
|
||||
|
||||
return response()->json(['status' => 'success', 'message' => trans('common.success_item', ['attribute' => trans('common.generate')])]);
|
||||
try {
|
||||
$invite = $user->invites()->create([
|
||||
'code' => strtoupper(Str::random(12)), // 简化邀请码生成逻辑
|
||||
'dateline' => now()->addDays((int) sysConfig('user_invite_days')),
|
||||
]);
|
||||
|
||||
if ($invite) {
|
||||
$user->decrement('invite_num');
|
||||
|
||||
return response()->json(['status' => 'success', 'message' => trans('common.success_item', ['attribute' => trans('common.generate')])]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// 记录异常但不暴露给用户
|
||||
Log::error('Failed to generate invite code: '.$e->getMessage());
|
||||
}
|
||||
|
||||
return response()->json(['status' => 'fail', 'message' => trans('common.failed_item', ['attribute' => trans('common.generate')])]);
|
||||
|
||||
Reference in New Issue
Block a user