AutoReportNode.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Components\Helpers;
  4. use App\Components\PushNotification;
  5. use App\Models\SsNode;
  6. use App\Models\SsNodeTrafficDaily;
  7. use Illuminate\Console\Command;
  8. use Log;
  9. class AutoReportNode extends Command {
  10. protected $signature = 'autoReportNode';
  11. protected $description = '自动报告节点昨日使用情况';
  12. public function __construct() {
  13. parent::__construct();
  14. }
  15. public function handle() {
  16. $jobStartTime = microtime(true);
  17. if(Helpers::systemConfig()['node_daily_report']){
  18. $nodeList = SsNode::query()->whereStatus(1)->get();
  19. if(!$nodeList->isEmpty()){
  20. $msg = "|节点|上行流量|下行流量|合计|\r\n| :------ | :------ | :------ |\r\n";
  21. foreach($nodeList as $node){
  22. $log = SsNodeTrafficDaily::query()
  23. ->whereNodeId($node->id)
  24. ->where('created_at', '>=', date('Y-m-d 00:00:00', strtotime("-1 day")))
  25. ->where('created_at', '<=', date('Y-m-d 23:59:59', strtotime("-1 day")))
  26. ->first();
  27. if($log){
  28. $msg .= '|'.$node->name.'|'.flowAutoShow($log->u).'|'.flowAutoShow($log->d).'|'.$log->traffic."\r\n";
  29. }else{
  30. $msg .= '|'.$node->name.'|'.flowAutoShow(0).'|'.flowAutoShow(0)."|0B\r\n";
  31. }
  32. }
  33. PushNotification::send('节点日报', $msg);
  34. }
  35. }
  36. $jobEndTime = microtime(true);
  37. $jobUsedTime = round(($jobEndTime - $jobStartTime), 4);
  38. Log::info('---【'.$this->description.'】完成---,耗时'.$jobUsedTime.'秒');
  39. }
  40. }