AutoReportNode.php 1.3 KB

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