FixTrackLog.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\command;
  3. use Symfony\Component\Console\Command\Command;
  4. use Symfony\Component\Console\Input\InputInterface;
  5. use Symfony\Component\Console\Input\InputOption;
  6. use Symfony\Component\Console\Input\InputArgument;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. use support\Redis;
  9. use App\services\TrackService;
  10. class FixTrackLog extends Command
  11. {
  12. protected static $defaultName = 'fix_track_log';
  13. protected static $defaultDescription = '根据 /app/runtime/logs/tarck/ 下的文件修复日志';
  14. /**
  15. * @return void
  16. */
  17. protected function configure()
  18. {
  19. //$this->addArgument('file', InputArgument::OPTIONAL, '文件路径及其名称');
  20. $this->addOption('file', 'file', InputOption::VALUE_REQUIRED, '要解析的文件名称');
  21. }
  22. /**
  23. * @param InputInterface $input
  24. * @param OutputInterface $output
  25. * @return int
  26. */
  27. protected function execute(InputInterface $input, OutputInterface $output)
  28. {
  29. $file = $input->getOption('file');
  30. $fileData = function($file) {
  31. $content = fopen($file, 'r');
  32. //if (!$file) die('file does not exist or cannot be opened');
  33. while (($line = fgets($content)) !== false) {
  34. yield $line;
  35. }
  36. fclose($content);
  37. };
  38. foreach ($fileData($file) as $line) {
  39. $line = explode(": ", $line);
  40. $paramsc = $line[count($line)-1];
  41. $params = json_decode($paramsc,true);
  42. if (!is_array($params)) {
  43. $output->writeln('不是json:'.$params);
  44. }
  45. // $res = TrackService::confirm($params);
  46. // if ($res) {
  47. // continue;
  48. // }
  49. TrackService::TiktokRedisDeal([$paramsc]);
  50. }
  51. return 1;
  52. }
  53. }