| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- namespace App\Game;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\Redis;
- define('SPECIAL_MODE_GUEST', 1);
- define('SPECIAL_MODE_ZERO_MONEY', 2);//注册不送钱
- define('SPECIAL_DISABLE_PROMOTE_INSTALL', 4);//提示安装
- define('SPECIAL_MODE_PWA_BONUS', 8);//安装app送钱
- define('SPECIAL_MODE_SMS_BONUS', 16);//手机验证送钱
- define('SPECIAL_MODE_MAIL_BONUS', 32);//MAIL验证送钱
- define('SPECIAL_MODE_FIRSTPAY_OFF30', 64);//首冲打开30%bonus
- class WebChannelConfig extends Model
- {
- protected $table = 'webgame.WebChannelConfig';
- protected $primaryKey = 'ID';
- public $incrementing = true;
- protected $keyType = 'int';
- protected $connection = 'mysql';
- protected $fillable = [
- 'Channel', 'PackageName', 'Remarks', 'StateNo','SpecialMode', 'PlatformName', 'PlatformID','LoginOpen','RegOpen','BonusArr','ShadowChannel','LightApk','FullApk'
- ];
- private static $key='web_channel_config:';
- public $timestamps = false;
- protected $shadow_channel=0;
- public function SHADOW_CHANNEL()
- {
- if($this->shadow_channel)return $this->shadow_channel;
- $this->shadow_channel=$this->Channel;
- if(!empty($this->ShadowChannel)){
- $channels=explode('|',$this->ShadowChannel);
- $allRate=0;
- $rates=[];
- foreach ($channels as $channel){
- $channel=explode('%',$channel);
- $allRate+=$channel[0];
- $rates[$allRate]=$channel[1];
- }
- $rand=mt_rand(0, 100);
- foreach($rates as $rate=>$channel){
- if($rand<$rate){
- $this->shadow_channel=$channel;
- return $channel;
- }
- }
- }
- return $this->shadow_channel;
- }
- public function BONUS_PWA()
- {
- return explode('|',$this->BonusArr)[3]??00;
- }
- public function BONUS_VERIFY_PHONE()
- {
- return explode('|',$this->BonusArr)[1]??00;
- }
- public function BONUS_REG()
- {
- return explode('|',$this->BonusArr)[0]??00;
- }
- public function BONUS_VERIFY_EMAIL()
- {
- return explode('|',$this->BonusArr)[2]??00;
- }
- public static function GuestOpen($config)
- {
- return ($config->SpecialMode&SPECIAL_MODE_GUEST)==SPECIAL_MODE_GUEST;
- }
- public function isFistPay30()
- {
- return ($this->SpecialMode&SPECIAL_MODE_SMS_BONUS)==SPECIAL_MODE_SMS_BONUS;
- }
- public function isSmsBonus()
- {
- return ($this->SpecialMode&SPECIAL_MODE_SMS_BONUS)==SPECIAL_MODE_SMS_BONUS;
- }
- public function isDisablePromote()
- {
- return ($this->SpecialMode&SPECIAL_DISABLE_PROMOTE_INSTALL)==SPECIAL_DISABLE_PROMOTE_INSTALL;
- }
- public function isPwaBonus()
- {
- return ($this->SpecialMode&SPECIAL_MODE_PWA_BONUS)==SPECIAL_MODE_PWA_BONUS;
- }
- public function isGuestOpen()
- {
- return ($this->SpecialMode&SPECIAL_MODE_GUEST)==SPECIAL_MODE_GUEST;
- }
- public function isRegZeroMoneyOpen()
- {
- return ($this->SpecialMode&SPECIAL_MODE_ZERO_MONEY)==SPECIAL_MODE_ZERO_MONEY;
- }
- // 获取特定 Channel 的记录
- public static function getByChannel($channel)
- {
- $cacheKey = self::$key . $channel;
- // $cachedConfig = Redis::get($cacheKey);
- //
- // if ($cachedConfig) {
- // return new WebChannelConfig(json_decode($cachedConfig,true));
- // }
- $config = self::where('Channel', $channel)->first();
- if ($config) {
- Redis::setex($cacheKey, 60, $config->toJson());
- }
- return $config;
- }
- // 清除缓存
- public static function clearCache($channel)
- {
- $cacheKey = self::$key . $channel;
- Redis::del($cacheKey);
- }
- // 监听模型事件
- protected static function boot()
- {
- parent::boot();
- static::saved(function ($model) {
- self::clearCache($model->Channel);
- });
- static::deleted(function ($model) {
- self::clearCache($model->Channel);
- });
- }
- }
|