| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace app\command\test\ln;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use think\facade\Db;
- class UserTest extends Command
- {
- protected function configure()
- {
- // 指令配置
- $this->setName('user')
- ->setDescription('用户脚本处理');
- }
- protected function execute(Input $input, Output $output)
- {
- //查询所有用户
- $user_list = Db::name('user')
- ->select()
- ->toArray();
- foreach ($user_list as $k => $v) {
- //查询已邀请的数量
- $spread_count = Db::name('user')
- ->select()
- ->where('spread_uid', $v['uid'])
- ->where('status', 1)
- ->where('is_del', 0)
- ->count();
- //更新邀请人数据
- Db::name('user')
- ->where('uid', $v['uid'])
- ->update([
- 'spread_count' => $spread_count,
- ]);
- $output->writeln("处理的用户ID {$v['uid']}, 修改邀请人数为 {$spread_count}");
- }
- }
- }
|