RecordServerGameCount.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Facade\TableName;
  4. use App\Services\Custom;
  5. use Illuminate\Console\Command;
  6. use Illuminate\Support\Facades\DB;
  7. class RecordServerGameCount 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';
  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. $DateID = date('Ymd');
  38. // 查找按天去重玩过游戏的人
  39. $list = DB::connection('write')->table(TableName::QPRecordDB() . 'RecordUserGameDayCount')
  40. ->where('DateID', $DateID)
  41. ->selectRaw('count(UserID) UserCount,GameID,sum(Cnt) Cnt')
  42. ->groupBy('GameID')
  43. ->get();
  44. foreach ($list as $value) {
  45. DB::connection('write')->table(TableName::QPRecordDB() . 'RecordServerGameCount')
  46. ->updateOrInsert(['DateID' => $DateID, 'GameID' => $value->GameID], ['DateID' => $DateID, 'GameID' => $value->GameID, 'Cnt' => $value->Cnt, 'UserCount' => $value->UserCount]);
  47. }
  48. try {
  49. (new Custom())->clearUnBackUser();
  50. }catch (\Exception $e){
  51. }
  52. }
  53. }