AutoReportNode.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Components\Helpers;
  4. use App\Components\PushNotification;
  5. use App\Models\Node;
  6. use App\Models\NodeDailyDataFlow;
  7. use Illuminate\Console\Command;
  8. use Log;
  9. class AutoReportNode extends Command {
  10. protected $signature = 'autoReportNode';
  11. protected $description = '自动报告节点昨日使用情况';
  12. public function handle(): void {
  13. $jobStartTime = microtime(true);
  14. if(Helpers::systemConfig()['node_daily_report']){
  15. $nodeList = Node::query()->whereStatus(1)->get();
  16. if($nodeList->isNotEmpty()){
  17. $msg = "|节点|上行流量|下行流量|合计|\r\n| :------ | :------ | :------ |\r\n";
  18. foreach($nodeList as $node){
  19. $log = NodeDailyDataFlow::query()
  20. ->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. }