| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace app\command;
- use app\model\system\SystemUser;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- class UserOff extends Command
- {
- protected static string $defaultName = 'user:off';
- protected static string $defaultDescription = '更新客服状态-10分钟无回调自动下线';
- protected function execute(InputInterface $input, OutputInterface $output): int
- {
- try {
- $output->writeln("开始更新客服状态====>" . getDateFull());
- $nextPage = 1;
- while (is_numeric($nextPage)) {
- $resp = (new SystemUser)->where(["type" => 3])->page($nextPage, 10)->select();
- if ($resp->isEmpty()) {
- $output->writeln("没有任务啦==" . getDateFull());
- $nextPage = null;
- return true;
- }
- $endTime = time();
- foreach ($resp as $item) {
- if (strtotime("+10 min",strtotime($item['last_active_at'])) < $endTime) {
- $output->writeln("客服下线=={$item['truename']}==".getDateFull());
- (new SystemUser)->where('id',$item['id'])->update(['is_line' => 0]);
- } else {
- $output->writeln("客服正常在线=={$item['truename']}==".getDateFull());
- }
- }
- $nextPage = $nextPage+1;
- $output->writeln("进入下一页=={$nextPage}==".getDateFull());
- }
- } catch (\Throwable $throwable) {
- echo getDateFull()."===更新客服状态\n";
- echo $throwable->getFile()."\n";
- echo $throwable->getLine()."\n";
- }
- return self::SUCCESS;
- }
- }
|