UserTest.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace app\command\test\ln;
  3. use think\console\Command;
  4. use think\console\Input;
  5. use think\console\Output;
  6. use think\facade\Db;
  7. class UserTest extends Command
  8. {
  9. protected function configure()
  10. {
  11. // 指令配置
  12. $this->setName('user')
  13. ->setDescription('用户脚本处理');
  14. }
  15. protected function execute(Input $input, Output $output)
  16. {
  17. //查询所有用户
  18. $user_list = Db::name('user')
  19. ->select()
  20. ->toArray();
  21. foreach ($user_list as $k => $v) {
  22. //查询已邀请的数量
  23. $spread_count = Db::name('user')
  24. ->select()
  25. ->where('spread_uid', $v['uid'])
  26. ->where('status', 1)
  27. ->where('is_del', 0)
  28. ->count();
  29. //更新邀请人数据
  30. Db::name('user')
  31. ->where('uid', $v['uid'])
  32. ->update([
  33. 'spread_count' => $spread_count,
  34. ]);
  35. $output->writeln("处理的用户ID {$v['uid']}, 修改邀请人数为 {$spread_count}");
  36. }
  37. }
  38. }