RankCommand.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Activity;
  4. use App\Models\User;
  5. use Carbon\Carbon;
  6. use Illuminate\Console\Command;
  7. use Illuminate\Support\Facades\Log;
  8. class RankCommand extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'RankCommand';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = 'Command description';
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return mixed
  35. */
  36. public function handle()
  37. {
  38. $season=Activity::where('is_new',1)->value('season');
  39. $data=User::where('status',1)
  40. ->join('enroll','enroll.user_id','=','user.id')
  41. ->where('enroll.is_pay',1)
  42. ->where('enroll.season',$season)
  43. ->orderByDesc('user.total')
  44. ->select('user.id','user.total')
  45. ->get();
  46. foreach ($data as $k=>$v){
  47. $user=User::find($v->id);
  48. $user->rank=$k+1;
  49. $user->save();
  50. }
  51. Log::error('{--------排名计算--------}'.Carbon::now()->toDateTimeString());
  52. }
  53. }