AutoUpdateUserLevel.php 1.1 KB

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