WebChannelConfig.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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_PWA_BONUS', 8);//安装app送钱
  10. define('SPECIAL_MODE_SMS_BONUS', 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 static function GuestOpen($config)
  70. {
  71. return ($config->SpecialMode&SPECIAL_MODE_GUEST)==SPECIAL_MODE_GUEST;
  72. }
  73. public function isFistPay30()
  74. {
  75. return ($this->SpecialMode&SPECIAL_MODE_SMS_BONUS)==SPECIAL_MODE_SMS_BONUS;
  76. }
  77. public function isSmsBonus()
  78. {
  79. return ($this->SpecialMode&SPECIAL_MODE_SMS_BONUS)==SPECIAL_MODE_SMS_BONUS;
  80. }
  81. public function isDisablePromote()
  82. {
  83. return ($this->SpecialMode&SPECIAL_DISABLE_PROMOTE_INSTALL)==SPECIAL_DISABLE_PROMOTE_INSTALL;
  84. }
  85. public function isPwaBonus()
  86. {
  87. return ($this->SpecialMode&SPECIAL_MODE_PWA_BONUS)==SPECIAL_MODE_PWA_BONUS;
  88. }
  89. public function isDebugEvent()
  90. {
  91. return ($this->SpecialMode&SPECIAL_MODE_DEBUG_EVENT)==SPECIAL_MODE_DEBUG_EVENT;
  92. }
  93. public function isFbJumpLater(){
  94. if(($this->SpecialMode&SPECIAL_MODE_FB_JUMP_LATER2)==SPECIAL_MODE_FB_JUMP_LATER2)return 2;
  95. if(($this->SpecialMode&SPECIAL_MODE_FB_JUMP_LATER)==SPECIAL_MODE_FB_JUMP_LATER)return 1;
  96. return 0;
  97. }
  98. public function isRegionUnique()
  99. {
  100. if(($this->SpecialMode&SPECIAL_MODE_REGION_UNIQUE)==SPECIAL_MODE_REGION_UNIQUE&&!empty($this->RegionID)){
  101. return $this->RegionID;
  102. }else{
  103. $region_config=RouteService::getRegionConfig();
  104. if($region_config&&$region_config->isAllChannelsUnique()){
  105. return $region_config->RegionID;
  106. }
  107. return "";
  108. }
  109. }
  110. public function isGuestOpen()
  111. {
  112. return ($this->SpecialMode&SPECIAL_MODE_GUEST)==SPECIAL_MODE_GUEST;
  113. }
  114. public function isRegZeroMoneyOpen()
  115. {
  116. return ($this->SpecialMode&SPECIAL_MODE_ZERO_MONEY)==SPECIAL_MODE_ZERO_MONEY;
  117. }
  118. // 获取特定 Channel 的记录
  119. public static function getByChannel($channel)
  120. {
  121. $cacheKey = self::$key . $channel;
  122. $cachedConfig = Redis::get($cacheKey);
  123. if ($cachedConfig) {
  124. return new self(json_decode($cachedConfig,true));
  125. }
  126. $config = self::where('Channel', $channel)->first();
  127. if ($config) {
  128. Redis::setex($cacheKey, 300, $config->toJson());
  129. }
  130. return $config;
  131. }
  132. // 清除缓存
  133. public static function clearCache($channel)
  134. {
  135. $cacheKey = self::$key . $channel;
  136. Redis::del($cacheKey);
  137. }
  138. // 监听模型事件
  139. protected static function boot()
  140. {
  141. parent::boot();
  142. static::saved(function ($model) {
  143. self::clearCache($model->Channel);
  144. });
  145. static::deleted(function ($model) {
  146. self::clearCache($model->Channel);
  147. });
  148. }
  149. }