AutoUpdateUserLevel.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\api\command;
  4. use app\common\service\UserService;
  5. use think\console\Command;
  6. use think\console\Input;
  7. use think\console\Output;
  8. /**
  9. * 用户自动升级 by wes 每间隔10分钟运行一次
  10. * Class AutoUpdateUserLevel
  11. * @package app\api\command
  12. */
  13. class AutoUpdateUserLevel extends Command
  14. {
  15. protected $cacheTime = 86400; // 一天
  16. protected function configure()
  17. {
  18. $this->setName('auto_update_user_level')
  19. ->setDescription('the auto_update_user_level command');
  20. }
  21. /**
  22. * 处理用户自动升级
  23. * @param Input $input
  24. * @param Output $output
  25. * @return int
  26. */
  27. protected function execute(Input $input, Output $output)
  28. {
  29. $result = UserService::make()->updateLevel();
  30. if(is_array($result)){
  31. echo json_encode($result, 256)."\n";
  32. }else{
  33. echo json_encode(['code'=>500,'msg'=> $result?$result:'处理失败',date('Y-m-d H:i:s')], 256)."\n";
  34. }
  35. return true;
  36. }
  37. }