SyncUserType.php 871 B

1234567891011121314151617181920212223
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Support\MemberAudience;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Facades\DB;
  6. class SyncUserType extends Command
  7. {
  8. protected $signature = 'users:sync-type';
  9. protected $description = '给前台新注册的游客(from = 2)补上 user_type = 1;游客转正后改回 0。后台模拟会员(2)不动';
  10. public function handle(): int
  11. {
  12. if (!MemberAudience::enabled()) return self::SUCCESS;
  13. $guests = DB::table('users')->where('from', '2')->where('user_type', 0)->update(['user_type' => 1]);
  14. $normal = DB::table('users')->where('user_type', 1)->where(fn ($q) => $q->whereNull('from')->orWhere('from', '<>', '2'))->update(['user_type' => 0]);
  15. if ($guests || $normal) $this->info("游客 +{$guests},转正 {$normal}");
  16. return self::SUCCESS;
  17. }
  18. }