WebChannelConfig.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. namespace App\Game;
  3. use App\Game\Services\RouteService;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Support\Facades\Redis;
  6. define('SPECIAL_MODE_GUEST', 1);
  7. define('SPECIAL_MODE_ZERO_MONEY', 2);//注册不送钱
  8. define('SPECIAL_DISABLE_PROMOTE_INSTALL', 4);//提示安装
  9. //define('SPECIAL_MODE_ENABLE_INSURE_SCORE', 8);//直接启用第二货币 GameScoreInfo InsureScore
  10. define('SPECIAL_MODE_REG_TO_REALMONEY', 16);//默认注册送的钱是真钱不是第二货币
  11. define('SPECIAL_MODE_MAIL_BONUS', 32);//MAIL验证送钱
  12. define('SPECIAL_MODE_FIRSTPAY_OFF30', 64);//首冲打开30%bonus
  13. define('SPECIAL_MODE_DEBUG_EVENT', 128);//是否开启事件日志上保
  14. define('SPECIAL_MODE_REGION_UNIQUE', 256);//是否开启区域独立模式
  15. define('SPECIAL_MODE_FB_JUMP_LATER', 512);//fb内浏览器弹出时机靠后
  16. define('SPECIAL_MODE_FB_JUMP_LATER2', 1024);//fb内浏览器弹出时机靠后
  17. class WebChannelConfig extends Model
  18. {
  19. protected $table = 'webgame.WebChannelConfig';
  20. protected $primaryKey = 'ID';
  21. public $incrementing = true;
  22. protected $keyType = 'int';
  23. protected $connection = 'mysql';
  24. protected $fillable = [
  25. 'Channel', 'PackageName', 'RegionID', 'Remarks', 'StateNo','SpecialMode', 'PlatformName', 'PlatformID', 'PlatformToken', 'LoginOpen','RegOpen','BonusArr','ShadowChannel','LightApk','FullApk'
  26. ];
  27. private static $key='web_channel_config:';
  28. public $timestamps = false;
  29. protected $shadow_channel=0;
  30. public function SHADOW_CHANNEL()
  31. {
  32. if($this->shadow_channel)return $this->shadow_channel;
  33. $this->shadow_channel=$this->Channel;
  34. if(!empty($this->ShadowChannel)){
  35. $channels=explode('|',$this->ShadowChannel);
  36. $allRate=0;
  37. $rates=[];
  38. foreach ($channels as $channel){
  39. $channel=explode('%',$channel);
  40. $allRate+=$channel[0];
  41. $rates[$allRate]=$channel[1];
  42. }
  43. $rand=mt_rand(0, 100);
  44. foreach($rates as $rate=>$channel){
  45. if($rand<$rate){
  46. $this->shadow_channel=$channel;
  47. return $channel;
  48. }
  49. }
  50. }
  51. return $this->shadow_channel;
  52. }
  53. public function BONUS_PWA()
  54. {
  55. return explode('|',$this->BonusArr)[3]??00;
  56. }
  57. public function BONUS_VERIFY_PHONE()
  58. {
  59. return explode('|',$this->BonusArr)[1]??00;
  60. }
  61. public function BONUS_REG()
  62. {
  63. return explode('|',$this->BonusArr)[0]??00;
  64. }
  65. public function BONUS_VERIFY_EMAIL()
  66. {
  67. return explode('|',$this->BonusArr)[2]??00;
  68. }
  69. public function isRealMoneyReg()
  70. {
  71. return ($this->SpecialMode&SPECIAL_MODE_REG_TO_REALMONEY)==SPECIAL_MODE_REG_TO_REALMONEY;
  72. }
  73. public static function GuestOpen($config)
  74. {
  75. return ($config->SpecialMode&SPECIAL_MODE_GUEST)==SPECIAL_MODE_GUEST;
  76. }
  77. public function isDisablePromote()
  78. {
  79. return ($this->SpecialMode&SPECIAL_DISABLE_PROMOTE_INSTALL)==SPECIAL_DISABLE_PROMOTE_INSTALL;
  80. }
  81. public function isDebugEvent()
  82. {
  83. return ($this->SpecialMode&SPECIAL_MODE_DEBUG_EVENT)==SPECIAL_MODE_DEBUG_EVENT;
  84. }
  85. public function isFbJumpLater(){
  86. if(($this->SpecialMode&SPECIAL_MODE_FB_JUMP_LATER2)==SPECIAL_MODE_FB_JUMP_LATER2)return 2;
  87. if(($this->SpecialMode&SPECIAL_MODE_FB_JUMP_LATER)==SPECIAL_MODE_FB_JUMP_LATER)return 1;
  88. return 0;
  89. }
  90. public function isRegionUnique()
  91. {
  92. if(($this->SpecialMode&SPECIAL_MODE_REGION_UNIQUE)==SPECIAL_MODE_REGION_UNIQUE&&!empty($this->RegionID)){
  93. return $this->RegionID;
  94. }else{
  95. $region_config=RouteService::getRegionConfig();
  96. if($region_config&&$region_config->isAllChannelsUnique()){
  97. return $region_config->RegionID;
  98. }
  99. return "";
  100. }
  101. }
  102. public function isGuestOpen()
  103. {
  104. return ($this->SpecialMode&SPECIAL_MODE_GUEST)==SPECIAL_MODE_GUEST;
  105. }
  106. public function isRegZeroMoneyOpen()
  107. {
  108. return ($this->SpecialMode&SPECIAL_MODE_ZERO_MONEY)==SPECIAL_MODE_ZERO_MONEY;
  109. }
  110. // 获取特定 Channel 的记录
  111. public static function getByChannel($channel)
  112. {
  113. $cacheKey = self::$key . $channel;
  114. $cachedConfig = Redis::get($cacheKey);
  115. if ($cachedConfig) {
  116. return new self(json_decode($cachedConfig,true));
  117. }
  118. $config = self::where('Channel', $channel)->first();
  119. if ($config) {
  120. Redis::setex($cacheKey, 300, $config->toJson());
  121. }
  122. return $config;
  123. }
  124. // 清除缓存
  125. public static function clearCache($channel)
  126. {
  127. $cacheKey = self::$key . $channel;
  128. Redis::del($cacheKey);
  129. }
  130. // 监听模型事件
  131. protected static function boot()
  132. {
  133. parent::boot();
  134. static::saved(function ($model) {
  135. self::clearCache($model->Channel);
  136. });
  137. static::deleted(function ($model) {
  138. self::clearCache($model->Channel);
  139. });
  140. }
  141. }