AutoReportNode.php 1.4 KB

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