mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-11 23:19:05 +00:00
1. models 关系规范化; 2. 本地-在线 订单处理改写; 3. 优化用户界面节点的查表操作; 4. 半修复 VNet SSR版需要面板主动提交用户信息变动的问题;(节点等级,用户分组,Node信息修改 主动通知节点尚未添加); 5. 简化并提取出了 返利佣金相关处理逻辑;
58 lines
1.4 KiB
PHP
58 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Node;
|
|
use App\Models\User;
|
|
use App\Models\UserDataFlowLog;
|
|
use App\Models\UserHourlyDataFlow;
|
|
use Illuminate\Console\Command;
|
|
use Log;
|
|
|
|
class AutoStatisticsUserHourlyTraffic extends Command {
|
|
protected $signature = 'autoStatisticsUserHourlyTraffic';
|
|
protected $description = '自动统计用户每小时流量';
|
|
|
|
public function handle(): void {
|
|
$jobStartTime = microtime(true);
|
|
|
|
foreach(User::activeUser()->get() as $user){
|
|
// 统计一次所有节点的总和
|
|
$this->statisticsByNode($user->id);
|
|
|
|
// 统计每个节点产生的流量
|
|
foreach(Node::whereStatus(1)->orderBy('id')->get() as $node){
|
|
$this->statisticsByNode($user->id, $node->id);
|
|
}
|
|
}
|
|
|
|
$jobEndTime = microtime(true);
|
|
$jobUsedTime = round(($jobEndTime - $jobStartTime), 4);
|
|
|
|
Log::info('---【'.$this->description.'】完成---,耗时'.$jobUsedTime.'秒');
|
|
}
|
|
|
|
private function statisticsByNode($user_id, $node_id = 0): void {
|
|
$query = UserDataFlowLog::whereUserId($user_id)->whereBetween('log_time', [strtotime("-1 hour"), time()]);
|
|
|
|
if($node_id){
|
|
$query->whereNodeId($node_id);
|
|
}
|
|
|
|
$u = $query->sum('u');
|
|
$d = $query->sum('d');
|
|
$total = $u + $d;
|
|
|
|
if($total){ // 有数据才记录
|
|
$obj = new UserHourlyDataFlow();
|
|
$obj->user_id = $user_id;
|
|
$obj->node_id = $node_id;
|
|
$obj->u = $u;
|
|
$obj->d = $d;
|
|
$obj->total = $total;
|
|
$obj->traffic = flowAutoShow($total);
|
|
$obj->save();
|
|
}
|
|
}
|
|
}
|