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}"); } } }