RecordServerGameCountYesterday.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Facade\TableName;
  4. use Carbon\Carbon;
  5. use Illuminate\Console\Command;
  6. use Illuminate\Support\Facades\DB;
  7. class RecordServerGameCountYesterday extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'record_server_game_count_yesterday';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '按天统计游戏人数-游戏房间去重过的用户';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return mixed
  34. */
  35. public function handle()
  36. {
  37. // 今日执行昨日数据
  38. $DateID = Carbon::yesterday()->format('Ymd');
  39. // 查找按天去重玩过游戏的人
  40. $list = DB::connection('write')->table(TableName::QPRecordDB() . 'RecordUserGameDayCount')
  41. ->where('DateID', $DateID)
  42. ->selectRaw('count(UserID) UserCount,GameID,sum(Cnt) Cnt')
  43. ->groupBy('GameID')
  44. ->get();
  45. foreach ($list as $value) {
  46. DB::connection('write')->table(TableName::QPRecordDB() . 'RecordServerGameCount')
  47. ->updateOrInsert(['DateID' => $DateID, 'GameID' => $value->GameID], ['DateID' => $DateID, 'GameID' => $value->GameID, 'Cnt' => $value->Cnt, 'UserCount' => $value->UserCount]);
  48. }
  49. }
  50. }