mirror of
				https://github.com/v2board/v2board.git
				synced 2025-11-01 01:41:47 +08:00 
			
		
		
		
	update: server/getServerLog to stat/getTrafficLog
This commit is contained in:
		| @@ -1,44 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Console\Commands; | ||||
|  | ||||
| use Illuminate\Console\Command; | ||||
| use Illuminate\Support\Facades\DB; | ||||
| use App\Models\ServerLog; | ||||
|  | ||||
| class ResetServerLog extends Command | ||||
| { | ||||
|     /** | ||||
|      * The name and signature of the console command. | ||||
|      * | ||||
|      * @var string | ||||
|      */ | ||||
|     protected $signature = 'reset:serverLog'; | ||||
|  | ||||
|     /** | ||||
|      * 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() | ||||
|     { | ||||
|         ServerLog::truncate(); | ||||
|     } | ||||
| } | ||||
| @@ -35,7 +35,6 @@ class Kernel extends ConsoleKernel | ||||
|         $schedule->command('check:ticket')->everyMinute(); | ||||
|         // reset | ||||
|         $schedule->command('reset:traffic')->daily(); | ||||
|         $schedule->command('reset:serverLog')->quarterly()->at('0:15'); | ||||
|         // send | ||||
|         $schedule->command('send:remindMail')->dailyAt('11:30'); | ||||
|         // horizon metrics | ||||
|   | ||||
| @@ -30,22 +30,4 @@ class ServerController extends Controller | ||||
|             'data' => $servers | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     public function getServerLogs(Request $request) | ||||
|     { | ||||
|         $serverLogModel = ServerLog::select([ | ||||
|             DB::raw('sum(u) as u'), | ||||
|             DB::raw('sum(d) as d'), | ||||
|             'log_at', | ||||
|             'user_id', | ||||
|             'rate' | ||||
|         ]) | ||||
|             ->where('user_id', $request->session()->get('id')) | ||||
|             ->where('log_at', '>=', strtotime(date('Y-m-1'))) | ||||
|             ->groupBy('log_at', 'user_id', 'rate') | ||||
|             ->orderBy('log_at', 'DESC'); | ||||
|         return response([ | ||||
|             'data' => $serverLogModel->get() | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										29
									
								
								app/Http/Controllers/User/StatController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								app/Http/Controllers/User/StatController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Http\Controllers\User; | ||||
|  | ||||
| use App\Http\Controllers\Controller; | ||||
| use App\Models\StatUser; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Facades\DB; | ||||
|  | ||||
| class StatController extends Controller | ||||
| { | ||||
|     public function getTrafficLog(Request $request) | ||||
|     { | ||||
|         $builder = StatUser::select([ | ||||
|             DB::raw('sum(u) as u'), | ||||
|             DB::raw('sum(d) as d'), | ||||
|             'record_at', | ||||
|             'user_id', | ||||
|             'server_rate' | ||||
|         ]) | ||||
|             ->where('user_id', $request->session()->get('id')) | ||||
|             ->where('record_at', '>=', strtotime(date('Y-m-1'))) | ||||
|             ->groupBy('record_at', 'user_id', 'server_rate') | ||||
|             ->orderBy('record_at', 'DESC'); | ||||
|         return response([ | ||||
|             'data' => $builder->get() | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
| @@ -10,11 +10,9 @@ use App\Utils\CacheKey; | ||||
| use Illuminate\Http\Request; | ||||
| use App\Models\User; | ||||
| use App\Models\Plan; | ||||
| use App\Models\ServerV2ray; | ||||
| use App\Models\Ticket; | ||||
| use App\Utils\Helper; | ||||
| use App\Models\Order; | ||||
| use App\Models\ServerLog; | ||||
| use Illuminate\Support\Facades\Cache; | ||||
|  | ||||
| class UserController extends Controller | ||||
|   | ||||
| @@ -48,7 +48,6 @@ class UserRoute | ||||
|             $router->post('/ticket/withdraw', 'User\\TicketController@withdraw'); | ||||
|             // Server | ||||
|             $router->get ('/server/fetch', 'User\\ServerController@fetch'); | ||||
|             $router->get ('/server/getServerLogs', 'User\\ServerController@getServerLogs'); | ||||
|             // Coupon | ||||
|             $router->post('/coupon/check', 'User\\CouponController@check'); | ||||
|             // Telegram | ||||
| @@ -59,6 +58,8 @@ class UserRoute | ||||
|             // Knowledge | ||||
|             $router->get ('/knowledge/fetch', 'User\\KnowledgeController@fetch'); | ||||
|             $router->get ('/knowledge/getCategory', 'User\\KnowledgeController@getCategory'); | ||||
|             // Stat | ||||
|             $router->get ('/stat/getTrafficLog', 'User\\StatController@getTrafficLog'); | ||||
|         }); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,58 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Jobs; | ||||
|  | ||||
| use App\Services\ServerService; | ||||
| use Illuminate\Bus\Queueable; | ||||
| use Illuminate\Contracts\Queue\ShouldQueue; | ||||
| use Illuminate\Foundation\Bus\Dispatchable; | ||||
| use Illuminate\Queue\InteractsWithQueue; | ||||
| use Illuminate\Queue\SerializesModels; | ||||
|  | ||||
| class ServerLogJob implements ShouldQueue | ||||
| { | ||||
|     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||||
|     protected $u; | ||||
|     protected $d; | ||||
|     protected $userId; | ||||
|     protected $server; | ||||
|     protected $protocol; | ||||
|  | ||||
|     public $tries = 3; | ||||
|     public $timeout = 3; | ||||
|  | ||||
|     /** | ||||
|      * Create a new job instance. | ||||
|      * | ||||
|      * @return void | ||||
|      */ | ||||
|     public function __construct($u, $d, $userId, $server, $protocol) | ||||
|     { | ||||
|         $this->onQueue('server_log'); | ||||
|         $this->u = $u; | ||||
|         $this->d = $d; | ||||
|         $this->userId = $userId; | ||||
|         $this->server = $server; | ||||
|         $this->protocol = $protocol; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Execute the job. | ||||
|      * | ||||
|      * @return void | ||||
|      */ | ||||
|     public function handle() | ||||
|     { | ||||
|         $serverService = new ServerService(); | ||||
|         if (!$serverService->log( | ||||
|             $this->userId, | ||||
|             $this->server->id, | ||||
|             $this->u, | ||||
|             $this->d, | ||||
|             $this->server->rate, | ||||
|             $this->protocol | ||||
|         )) { | ||||
|             throw new \Exception('日志记录失败'); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -87,7 +87,6 @@ class UserService | ||||
|     public function trafficFetch(int $u, int $d, int $userId, object $server, string $protocol) | ||||
|     { | ||||
|         TrafficFetchJob::dispatch($u, $d, $userId, $server, $protocol); | ||||
|         ServerLogJob::dispatch($u, $d, $userId, $server, $protocol); | ||||
|         StatServerJob::dispatch($u, $d, $server, $protocol, 'd'); | ||||
|         StatUserJob::dispatch($u, $d, $userId, $server, $protocol, 'd'); | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user