AutoReportNode.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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(
  22. 'created_at',
  23. date(
  24. "Y-m-d",
  25. strtotime('-1 days')
  26. )
  27. )
  28. ->first();
  29. if ($log) {
  30. $msg .= '|' . $node->name . '|' . flowAutoShow(
  31. $log->u
  32. ) . '|' . flowAutoShow(
  33. $log->d
  34. ) . '|' . $log->traffic . "\r\n";
  35. } else {
  36. $msg .= '|' . $node->name . '|' . flowAutoShow(
  37. 0
  38. ) . '|' . flowAutoShow(0) . "|0B\r\n";
  39. }
  40. }
  41. PushNotification::send('节点昨日使用情况', $msg);
  42. }
  43. }
  44. $jobEndTime = microtime(true);
  45. $jobUsedTime = round(($jobEndTime - $jobStartTime), 4);
  46. Log::info(
  47. '---【' . $this->description . '】完成---,耗时' . $jobUsedTime . '秒'
  48. );
  49. }
  50. }