GamesCount.php 885 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Services;
  3. use App\Facade\TableName;
  4. use Illuminate\Support\Facades\DB;
  5. class GamesCount
  6. {
  7. // 游戏对局【局数】
  8. public function gameCount($UserID)
  9. {
  10. $openGames = config('games.openKGame');
  11. // 游戏名称
  12. $gameNames = DB::table(TableName::QPPlatformDB() . 'GameKindItem')
  13. ->whereIn('KindID', $openGames)
  14. ->select('KindName', 'KindID')
  15. ->pluck('KindName', 'KindID')->toArray();
  16. // 用户游戏局数
  17. $gameCount = DB::table(TableName::QPRecordDB() . 'RecordUserGameCount')
  18. ->where('UserID',$UserID)
  19. ->whereIn('GameID', $openGames)
  20. ->pluck('Cnt', 'GameID')->toArray();
  21. $data = [];
  22. foreach ($gameNames as $key => &$value){
  23. $data[$value] = $gameCount[$key] ?? 0;
  24. }
  25. return $data;
  26. }
  27. }