AutoReportNode.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 static $systemConfig;
  12. protected $signature = 'autoReportNode';
  13. protected $description = '自动报告节点昨日使用情况';
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. self::$systemConfig = Helpers::systemConfig();
  18. }
  19. public function handle()
  20. {
  21. $jobStartTime = microtime(TRUE);
  22. if(self::$systemConfig['node_daily_report']){
  23. $nodeList = SsNode::query()->where('status', 1)->get();
  24. if(!$nodeList->isEmpty()){
  25. $msg = "|节点|上行流量|下行流量|合计|\r\n| :------ | :------ | :------ |\r\n";
  26. foreach($nodeList as $node){
  27. $log = SsNodeTrafficDaily::query()
  28. ->where('node_id', $node->id)
  29. ->where('created_at', '>=', date('Y-m-d 00:00:00', strtotime("-1 day")))
  30. ->where('created_at', '<=', date('Y-m-d 23:59:59', strtotime("-1 day")))
  31. ->first();
  32. if($log){
  33. $msg .= '|'.$node->name.'|'.flowAutoShow($log->u).'|'.flowAutoShow($log->d).'|'.$log->traffic."\r\n";
  34. }else{
  35. $msg .= '|'.$node->name.'|'.flowAutoShow(0).'|'.flowAutoShow(0)."|0B\r\n";
  36. }
  37. }
  38. PushNotification::send('节点日报', $msg);
  39. }
  40. }
  41. $jobEndTime = microtime(TRUE);
  42. $jobUsedTime = round(($jobEndTime-$jobStartTime), 4);
  43. Log::info('---【'.$this->description.'】完成---,耗时'.$jobUsedTime.'秒');
  44. }
  45. }