SimulationRenameMembers.php 1.3 KB

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Services\Simulation\SimulationMemberService;
  4. use Illuminate\Console\Command;
  5. class SimulationRenameMembers extends Command
  6. {
  7. protected $signature = 'simulation:rename-members {--dry-run : 只统计会改多少,不写库}';
  8. protected $description = '给早期创建的模拟会员改名:去掉账号 sim_ 前缀和“模拟”昵称,换成随机的真实风格;不清空数据,可重复执行';
  9. public function handle(): int
  10. {
  11. $dryRun = (bool) $this->option('dry-run');
  12. try {
  13. $counts = SimulationMemberService::renameLegacy($dryRun);
  14. } catch (\Throwable $e) {
  15. $this->error($e->getMessage());
  16. return self::FAILURE;
  17. }
  18. $labels = ['members' => '涉及的模拟会员', 'accounts' => '改账号', 'nicknames' => '改昵称', 'ips' => '改注册 IP', 'login_logs' => '登录日志',
  19. 'third_game_orders' => '第三方注单', 'withdraw_orders' => '提现单', 'sport_orders' => '体育注单'];
  20. $this->info($dryRun ? '试运行,没有修改任何数据。将要改动:' : '已完成。改动:');
  21. foreach ($counts as $key => $count) $this->line(sprintf(' %s:%d', $labels[$key] ?? $key, $count));
  22. return self::SUCCESS;
  23. }
  24. }