UserOff.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\command;
  3. use app\model\system\SystemUser;
  4. use Symfony\Component\Console\Command\Command;
  5. use Symfony\Component\Console\Input\InputInterface;
  6. use Symfony\Component\Console\Output\OutputInterface;
  7. class UserOff extends Command
  8. {
  9. protected static string $defaultName = 'user:off';
  10. protected static string $defaultDescription = '更新客服状态-10分钟无回调自动下线';
  11. protected function execute(InputInterface $input, OutputInterface $output): int
  12. {
  13. try {
  14. $output->writeln("开始更新客服状态====>" . getDateFull());
  15. $nextPage = 1;
  16. while (is_numeric($nextPage)) {
  17. $resp = (new SystemUser)->where(["type" => 3])->page($nextPage, 10)->select();
  18. if ($resp->isEmpty()) {
  19. $output->writeln("没有任务啦==" . getDateFull());
  20. $nextPage = null;
  21. return true;
  22. }
  23. $endTime = time();
  24. foreach ($resp as $item) {
  25. if (strtotime("+10 min",strtotime($item['last_active_at'])) < $endTime) {
  26. $output->writeln("客服下线=={$item['truename']}==".getDateFull());
  27. (new SystemUser)->where('id',$item['id'])->update(['is_line' => 0]);
  28. } else {
  29. $output->writeln("客服正常在线=={$item['truename']}==".getDateFull());
  30. }
  31. }
  32. $nextPage = $nextPage+1;
  33. $output->writeln("进入下一页=={$nextPage}==".getDateFull());
  34. }
  35. } catch (\Throwable $throwable) {
  36. echo getDateFull()."===更新客服状态\n";
  37. echo $throwable->getFile()."\n";
  38. echo $throwable->getLine()."\n";
  39. }
  40. return self::SUCCESS;
  41. }
  42. }