UserUpgrade.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace app\data\command;
  3. use app\data\model\DataUser;
  4. use app\data\service\UserUpgradeService;
  5. use think\admin\Command;
  6. use think\admin\Exception;
  7. use think\console\Input;
  8. use think\console\Output;
  9. /**
  10. * 用户等级重算处理
  11. * Class UserLevel
  12. * @package app\data\command
  13. */
  14. class UserUpgrade extends Command
  15. {
  16. protected function configure()
  17. {
  18. $this->setName('xdata:UserUpgrade');
  19. $this->setDescription('批量重新计算用户等级');
  20. }
  21. /**
  22. * @param Input $input
  23. * @param Output $output
  24. * @return void
  25. * @throws Exception
  26. */
  27. protected function execute(Input $input, Output $output)
  28. {
  29. try {
  30. [$total, $count] = [DataUser::mk()->count(), 0];
  31. foreach (DataUser::mk()->field('id')->cursor() as $user) {
  32. $this->queue->message($total, ++$count, "正在计算用户 [{$user['id']}] 的等级");
  33. UserUpgradeService::upgrade($user['id']);
  34. $this->queue->message($total, $count, "完成计算用户 [{$user['id']}] 的等级", 1);
  35. }
  36. $this->setQueueSuccess("此次共重新计算 {$total} 个用户等级。");
  37. } catch (Exception $exception) {
  38. throw $exception;
  39. } catch (\Exception $exception) {
  40. $this->setQueueError($exception->getMessage());
  41. }
  42. }
  43. }