RanksCommand.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Enroll;
  4. use Carbon\Carbon;
  5. use Illuminate\Console\Command;
  6. use Illuminate\Support\Facades\DB;
  7. use Illuminate\Support\Facades\Log;
  8. class RanksCommand extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'RanksCommand';
  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. /**如果当前时间在赛季内,则进行排名**/
  39. // if ($now>$re['round_start_time']&& $now<$re['round_end_time']){
  40. Log::error('开始排名');
  41. /*
  42. * 批发商排名
  43. * **/
  44. // $crown=DB::table('inte_user')
  45. // ->where('tag','3')->orderByDesc('integral')->orderByDesc('id')->get();
  46. // foreach ($crown as $k=>$v){
  47. // DB::table('inte_user')->where('id',$v->id)->update(['rank'=>$k+1]);
  48. // }
  49. $director_c=DB::table('inte_user')->where('tag',3)->pluck('id')->toArray();
  50. // foreach ($director as $k=>$v){
  51. // DB::table('user')->where('id',$v->id)->update(['rank'=>$k+1,'rank_end'=>$v->rank]);
  52. // }
  53. $directors_c=implode(',',$director_c);
  54. DB::select('UPDATE inte_user
  55. JOIN (SELECT
  56. obj.id,obj.integral,@rownum := @rownum + 1 AS rownum
  57. FROM
  58. (
  59. SELECT
  60. id,
  61. integral
  62. FROM
  63. `inte_user`
  64. where tag="3"
  65. and
  66. inte_user.id IN ('.$directors_c.')
  67. ORDER BY
  68. integral DESC
  69. ) AS obj,
  70. (SELECT @rownum := 0) r
  71. ) ranks ON (ranks.id = inte_user.id)
  72. SET inte_user.rank = ranks.rownum where inte_user.id IN ('.$directors_c.')');
  73. // Log::error('排名结束');
  74. // Log::error(Carbon::now()->timestamp-$now);
  75. $director=DB::table('inte_user')->where('tag',2)->pluck('id')->toArray();
  76. // foreach ($director as $k=>$v){
  77. // DB::table('user')->where('id',$v->id)->update(['rank'=>$k+1,'rank_end'=>$v->rank]);
  78. // }
  79. $directors=implode(',',$director);
  80. DB::select('UPDATE inte_user
  81. JOIN (SELECT
  82. obj.id,obj.integral,@rownum := @rownum + 1 AS rownum
  83. FROM
  84. (
  85. SELECT
  86. id,
  87. integral
  88. FROM
  89. `inte_user`
  90. where tag="2"
  91. and
  92. inte_user.id IN ('.$directors.')
  93. ORDER BY
  94. integral DESC
  95. ) AS obj,
  96. (SELECT @rownum := 0) r
  97. ) ranks ON (ranks.id = inte_user.id)
  98. SET inte_user.rank = ranks.rownum where inte_user.id IN ('.$directors.')');
  99. Log::error('排名结束');
  100. // }
  101. }
  102. }