* @version : HUOSDK 8.0 */ namespace huo\controller\pay; use huo\controller\common\Base; use huo\controller\game\Game; use huo\controller\game\GamePayShowCache; use huo\controller\request\Channel; use huo\controller\request\Device; use huo\controller\request\Game as GameRq; use huo\controller\request\Mem; use huo\controller\request\Order as OrderRq; use huo\controller\request\Role; use huo\model\member\MgRoleModel; use huolib\constant\CommonConst; use huolib\constant\GameConst; use huolib\tool\Ip; class PayShow extends Base { /** * 判断支付显示 * * @param OrderRq $order * @param Role $role * @param Mem $mem * @param GameRq $game_rq * @param Channel $channel * @param Device $device * * @return int 1 不显示 2 显示 */ public function getPayShow(OrderRq $order, Role $role, Mem $mem, GameRq $game_rq, Channel $channel, Device $device ) { $_from = $device->getFrom(); if (GameConst::GAME_IOS_SWITCH != $_from && GameConst::GAME_MP != $_from) { return CommonConst::STATUS_YES; } /* 查询游戏是否是屏蔽 */ $_app_id = $game_rq->getHAppId(); $_pay_show = (new Game())->getPayShowStatus($_app_id); if (CommonConst::STATUS_NO == $_pay_show) { return CommonConst::STATUS_NO; } /* 获取屏蔽规则 */ $_show_rule = GamePayShowCache::ins()->getInfoByAppId($_app_id); if (empty($_show_rule)) { return CommonConst::STATUS_YES; } /* 判断IP是否在黑名单 */ $_rs = $this->inIpBlack($device->getIp(), $_show_rule['ip_black']); if (true == $_rs) { return CommonConst::STATUS_NO; } /* 判断城市是否屏蔽 */ $_rs = $this->inArea($device->getIp(), $_show_rule['area']); if (true == $_rs) { return CommonConst::STATUS_NO; } $_client_id = $game_rq->getHVer(); /* 判断版本是否屏蔽 */ $_rs = $this->showVersion($_client_id, $_show_rule['no_show_version']); if (true == $_rs) { return CommonConst::STATUS_NO; } /* 根据时间判断是否屏蔽 */ $_rs = $this->showTime($_show_rule['start_time'], $_show_rule['end_time']); if (true == $_rs) { return CommonConst::STATUS_NO; } /* 根据IP段判断是否切换 */ $_rs = $this->showIp($device->getIp(), $_show_rule['is_domestic'], $_show_rule['is_overseas']); if (true == $_rs) { return CommonConst::STATUS_NO; } $_os = $device->getOs(); /* 判断版本是否屏蔽 */ $_rs = $this->showOs($_os, $_show_rule['system']); if (true == $_rs) { return CommonConst::STATUS_NO; } /* 连续登录天数判断屏蔽 */ $_data = (new MgRoleModel())->getDetailByMemGameServerRole( $mem->getMgMemId(), $_app_id, $role->getServerId(), $role->getRoleId() ); $_login_day = empty($_data['ext']['login_day']) ? 1 : $_data['ext']['login_day']; $_rs = $this->showLoginDay($_login_day, $_show_rule['login_day_mini'], $_show_rule['login_day_max']); if (true == $_rs) { return CommonConst::STATUS_NO; } /* 判断等级是否屏蔽 */ $_role_level = $role->getRoleLevel(); if (empty($_role_level)) { $_role_level = empty($_data['role_level']) ? 0 : $_data['role_level']; } $_rs = $this->showLevel($_role_level, $_show_rule['level_mini'], $_show_rule['level_max']); if (true == $_rs) { return CommonConst::STATUS_NO; } /* 判断战力是否切换 */ $_combat_num = $role->getCombatNum(); if (empty($_combat_num)) { $_combat_num = empty($_data['combat_num']) ? 0 : $_data['combat_num']; } $_rs = $this->showCombat($_combat_num, $_show_rule['combat_num_mini'], $_show_rule['combat_num_max']); if (true == $_rs) { return CommonConst::STATUS_NO; } return CommonConst::STATUS_YES; } /** * 判断是否在IP白名单 * * @param string $ip 当前ip * @param string $area 不切换的城市名 * * @return int */ public function inArea($ip, $area) { if (empty($area)) { /* 没城市则返回切换 */ return false; } $_area_array = explode('|', $area); if (empty($_area_array)) { return false; } $_ip_arr = Ip::find($ip); if (empty($_ip_arr)) { /* 未知IP不切换 */ return false; } if (in_array($_ip_arr[2], $_area_array)) { /* 如果城市名在不切换城市 */ return true; } return false; } /** * 判断是否在IP白名单 * * @param string $ip 当前ip * @param string $ip_white ip白名单字符串 * * @return bool */ public function inIpBlack($ip, $ip_white) { if (empty($ip_white)) { /* 没白名单则返回跳过 */ return false; } $_ip_array = explode('|', $ip_white); if (empty($_ip_array)) { return false; } if (in_array($ip, $_ip_array)) { return true; } return false; } /** * 判断连续登录天数是否屏蔽 * * @param int $login_day_num 连续登录天数 * @param int $login_day_mini 连续登录天数区间小值 * @param int $login_day_max 连续登录天数区间大值 * * @return bool */ public function showLoginDay($login_day_num, $login_day_mini, $login_day_max) { if (empty($login_day_max)) { /* 未设置 不屏蔽 */ return false; } if (empty($login_day_num) && !empty($login_day_max)) { /* 没有等级信息 屏蔽 */ return true; } if ($login_day_mini <= $login_day_num && $login_day_num < $login_day_max) { /* 战力区间内屏蔽*/ return true; } return false; } /** * 判断等级是否屏蔽 * * @param int $level 角色等级 * @param int $level_mini 等级区间小值 * @param int $level_max 等级区间大值 * * @return bool */ public function showLevel($level, $level_mini, $level_max) { if (empty($level_max)) { /* 未设置 不屏蔽 */ return false; } if (empty($level) && !empty($level_max)) { /* 没有等级信息 屏蔽 */ return true; } if ($level_mini <= $level && $level < $level_max) { /* 战力区间内屏蔽*/ return true; } return false; } /** * 判断战力是否切换 * * @param int $combat_num 角色战力 * @param int $combat_num_mini 战力区间小值 * @param int $combat_num_max 战力区间大值 * * @return bool */ public function showCombat($combat_num, $combat_num_mini, $combat_num_max) { if (empty($combat_num_max)) { /* 未设置 不屏蔽 */ return false; } if (empty($combat_num_max) && !empty($combat_num_max)) { /* 没有战力表示 屏蔽 */ return true; } if ($combat_num_mini < $combat_num && $combat_num < $combat_num_max) { /* 战力区间内屏蔽*/ return true; } return false; } /** * 判断版本号是否屏蔽 * * @param int $client_id 版本ID * @param string $rule_clients 不切换的版本 * * @return bool false 不屏蔽 true 屏蔽 */ public function showVersion($client_id = 0, $rule_clients = '') { if (empty($rule_clients) || empty($client_id)) { /* 没有设置不切换版本 全部切换 */ return false; } $_rule_clients = trim($rule_clients, ','); if ($client_id == $_rule_clients) { /* 当前版本等于不切换版本 不切换 */ return true; } if (false == strpos($rule_clients, ',')) { $_rule_clients_arr = explode(',', $_rule_clients); if (is_array($_rule_clients_arr) && in_array($client_id, $_rule_clients_arr)) { /* 当前版本在不切换版本内 不切换 */ return true; } } return false; } /** * 判断操作系统是否切换 * * @param string $os 操作系统 * @param string $rule_os 切换的操作系统 * * @return bool false 不屏蔽 true 屏蔽 */ public function showOs($os = '', $rule_os = '') { if (empty($rule_os) || empty($os)) { /* 没有设置不切换版本 全部切换 */ return false; } if (false !== strpos(strtolower($os), 'ios') && false !== strpos($rule_os, strval(GameConst::GAME_IOS))) { return false; } elseif (false !== strpos(strtolower($os), 'android') && false !== strpos($rule_os, strval(GameConst::GAME_ANDROID))) { return false; } return true; } /** * 判断是否在时间范围内 * * @param String $start_time * @param INT $end_time * * @return bool false 不屏蔽 true 屏蔽 */ public function showTime($start_time, $end_time) { if ($start_time == $end_time || $end_time == '00:00:00') { return false; } $_time = time(); $_start_time = strtotime(date('Y-m-d').' '.$start_time); $_end_time = strtotime(date('Y-m-d').' '.$end_time); if ($_time > $_start_time && $_time < $_end_time) { return true; } return false; } /** * 判断IP是否是国内IP * * @param string $ip IP地址 * @param int $is_domestic 国内是否屏蔽 1不屏蔽 2屏蔽 * @param int $is_overseas 国外是否屏蔽 1切换 2屏蔽 * * @return bool false 不屏蔽 true 屏蔽 */ public function showIp($ip, $is_domestic, $is_overseas) { if (empty($is_domestic) && empty($is_overseas)) { return false; } if (CommonConst::STATUS_NO == $is_domestic && CommonConst::STATUS_NO == $is_overseas) { return true; } $_ip_arr = Ip::find($ip); if (empty($_ip_arr)) { /* 未知IP不屏蔽 */ return false; } /* 根据统计需要,港澳台地区放入海外处理 */ $_domestic_except = array('台湾', '香港', '澳门'); $_ip_is_domestic = false; if (is_array($_ip_arr) && '中国' == $_ip_arr[0]) { $_ip_is_domestic = true; if (!empty($_ip_arr[1]) && in_array($_ip_arr[1], $_domestic_except)) { $_ip_is_domestic = false; } } if (true == $_ip_is_domestic && CommonConst::STATUS_NO == $is_domestic) { return true; } if (false == $_ip_is_domestic && CommonConst::STATUS_NO == $is_overseas) { return true; } return false; } }