AutoReportNode.php 1.5 KB

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