GameCard.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace App\Game;
  3. use App\Game\Config\GameBasicConfig;
  4. use App\Game\Services\RouteService;
  5. use Illuminate\Database\Eloquent\Builder;
  6. use Illuminate\Database\Eloquent\Model;
  7. use Illuminate\Support\Facades\Redis;
  8. class GameCard extends Model
  9. {
  10. protected $connection='mysql';
  11. const TABLE = 'webgame.games';
  12. protected $table = self::TABLE;
  13. public $timestamps = false;
  14. protected $fillable = ['gid','img','img_pt','img_es','level_info', 'link', 'online', 'desc','brand','title','state'];
  15. public static $OuroGameInfo_KEY="OuroGameInfos";
  16. public static function setOuroGameInfo($gameInfo)
  17. {
  18. self::$_gameinfo=$gameInfo;
  19. Redis::set(self::$OuroGameInfo_KEY,json_encode($gameInfo));
  20. }
  21. private static $_gameinfo=null;
  22. public static function getOuroGameInfo(){
  23. if(self::$_gameinfo==null){
  24. if(Redis::exists(self::$OuroGameInfo_KEY)){
  25. self::$_gameinfo=json_decode(Redis::get(self::$OuroGameInfo_KEY),true);
  26. }
  27. }
  28. return self::$_gameinfo;
  29. }
  30. public static function GetGameByID($id){
  31. $card=GameCard::where('id',$id)->first();
  32. if($card){
  33. $card=self::formatGames([$card])[0];
  34. }
  35. return $card;
  36. }
  37. public static function formatGames($games)
  38. {
  39. $cdn_org=["cdn.moeda777.com"];
  40. $cdn_replace="24680.imgix.net";
  41. $img_add_param="?auto=format,compress&cs=srgb&dpr=2&w=140";
  42. $img_add_param="";
  43. //处理多语言
  44. $locale=GlobalUserInfo::getLocale();
  45. //处理房间信息
  46. $ouroGameInfos=self::getOuroGameInfo();
  47. foreach($games as $game){
  48. //不是http开头,补齐
  49. if(!strstr($game->link,"http")){
  50. $game->link=GameBasicConfig::$ApiServer.$game->link;
  51. }
  52. if($game->brand=="PG"&&RouteService::isTestSite()){
  53. $game->link=str_replace('pgpro','pg',$game->link);
  54. }
  55. if(isset($ouroGameInfos)&&$game->brand=="OURO777"&&!empty($game->gid)){
  56. if(GlobalUserInfo::$me) {
  57. $score=GlobalUserInfo::getScoreByUserID(GlobalUserInfo::$me->UserID);
  58. if($score>=0) {
  59. if (isset($ouroGameInfos[$game->gid]) && !empty($ouroGameInfos[$game->gid])) {
  60. $game->level_info = $ouroGameInfos[$game->gid];
  61. }
  62. }
  63. }
  64. }
  65. // if($locale=='en'){
  66. // unset($game->img_pt,$game->img_es);
  67. // continue;
  68. // }
  69. if($locale=="pt"&&!empty($game->img_pt)){
  70. $game->img=$game->img_pt;
  71. }elseif($locale=="es"){
  72. if(!empty($game->img_es)){
  73. $game->img=$game->img_es;
  74. }elseif (!empty($game->img_pt)){
  75. $game->img=$game->img_pt;
  76. }
  77. }
  78. unset($game->img_pt,$game->img_es);
  79. $game->img=str_replace($cdn_org,$cdn_replace,$game->img).$img_add_param;
  80. }
  81. return $games;
  82. }
  83. /**
  84. * 关闭state检查
  85. * @var bool
  86. */
  87. public static $enableStateCheck=true;
  88. protected static function boot()
  89. {
  90. parent::boot();
  91. if(self::$enableStateCheck) {
  92. static::addGlobalScope('where', function (Builder $builder) {
  93. // $builder->where('state', 1);
  94. $builder->whereRaw(RouteService::getStateToWhereRaw());
  95. });
  96. }
  97. }
  98. }