123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace App\Console\Commands;
- use App\Models\Enroll;
- use Carbon\Carbon;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- class RanksCommand extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'RanksCommand';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Command description';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- /**如果当前时间在赛季内,则进行排名**/
- // if ($now>$re['round_start_time']&& $now<$re['round_end_time']){
- Log::error('开始排名');
- /*
- * 批发商排名
- * **/
- // $crown=DB::table('inte_user')
- // ->where('tag','3')->orderByDesc('integral')->orderByDesc('id')->get();
- // foreach ($crown as $k=>$v){
- // DB::table('inte_user')->where('id',$v->id)->update(['rank'=>$k+1]);
- // }
- $director_c=DB::table('inte_user')->where('tag',3)->pluck('id')->toArray();
- // foreach ($director as $k=>$v){
- // DB::table('user')->where('id',$v->id)->update(['rank'=>$k+1,'rank_end'=>$v->rank]);
- // }
- $directors_c=implode(',',$director_c);
- DB::select('UPDATE inte_user
- JOIN (SELECT
- obj.id,obj.integral,@rownum := @rownum + 1 AS rownum
- FROM
- (
- SELECT
- id,
- integral
- FROM
- `inte_user`
- where tag="3"
- and
- inte_user.id IN ('.$directors_c.')
- ORDER BY
- integral DESC
- ) AS obj,
- (SELECT @rownum := 0) r
- ) ranks ON (ranks.id = inte_user.id)
- SET inte_user.rank = ranks.rownum where inte_user.id IN ('.$directors_c.')');
- // Log::error('排名结束');
- // Log::error(Carbon::now()->timestamp-$now);
- $director=DB::table('inte_user')->where('tag',2)->pluck('id')->toArray();
- // foreach ($director as $k=>$v){
- // DB::table('user')->where('id',$v->id)->update(['rank'=>$k+1,'rank_end'=>$v->rank]);
- // }
- $directors=implode(',',$director);
- DB::select('UPDATE inte_user
- JOIN (SELECT
- obj.id,obj.integral,@rownum := @rownum + 1 AS rownum
- FROM
- (
- SELECT
- id,
- integral
- FROM
- `inte_user`
- where tag="2"
- and
- inte_user.id IN ('.$directors.')
- ORDER BY
- integral DESC
- ) AS obj,
- (SELECT @rownum := 0) r
- ) ranks ON (ranks.id = inte_user.id)
- SET inte_user.rank = ranks.rownum where inte_user.id IN ('.$directors.')');
- Log::error('排名结束');
- // }
- }
- }
|