123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519 |
- <?php
- namespace huo\controller\pay;
- use huo\controller\common\Base;
- use huo\controller\game\Game;
- use huo\controller\game\GamePaySwitchCache;
- use huo\controller\member\MemCache;
- 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\logic\order\OrderLogic;
- use huo\model\game\GameServerSwitchModel;
- use huo\model\game\PsMemWhiteModel;
- use huo\model\member\MgRoleModel;
- use huolib\constant\GameConst;
- use huolib\constant\OrderConst;
- use huolib\tool\Ip;
- class PaySwitch extends Base {
-
- public function getPaySwitch(OrderRq $order, Role $role, Mem $mem, GameRq $game_rq, Channel $channel, Device $device
- ) {
- $_from = $device->getFrom();
- $_vb_id = $game_rq->getVbId();
- if (GameConst::GAME_IOS_SWITCH != $_from && GameConst::GAME_MP != $_from && empty($_vb_id)) {
- return OrderConst::PAY_SWITCH_NO;
- }
-
- $_app_id = $game_rq->getHAppId();
- $_switch_rule_app_id = $_app_id;
- $_game_class = new Game();
-
- if (!empty($_vb_id)) {
- $_switch_rule_app_id = $_vb_id;
- }
- $_pay_switch = $_game_class->getPaySwitchStatus($_switch_rule_app_id);
- if (OrderConst::PAY_SWITCH_NO == $_pay_switch) {
- return OrderConst::PAY_SWITCH_NO;
- }
-
- $_switch_rule = GamePaySwitchCache::ins()->getInfoByAppId($_switch_rule_app_id);
- if (empty($_switch_rule)) {
-
- return $_pay_switch;
- }
-
- $_rs = $this->inMemWhite($_switch_rule_app_id, $mem->getMemId());
- if (true == $_rs) {
-
- return $_pay_switch;
- }
-
- $_rs = $this->inIpWhite($device->getIp(), $_switch_rule['ip_white']);
- if (true == $_rs) {
-
- return $_pay_switch;
- }
-
- $_rs = $this->inArea($device->getIp(), $_switch_rule['area']);
- if (OrderConst::PAY_SWITCH_NO == $_rs) {
- $_mem_ext_info = MemCache::ins()->getMeInfoById($mem->getMemId());
-
- if (empty($_mem_ext_info['sum_money']) || 6 >= $_mem_ext_info['sum_money']) {
- return OrderConst::PAY_SWITCH_NO;
- }
- }
- $_client_id = $game_rq->getHVer();
-
- $_rs = $this->switchVersion($_client_id, $_switch_rule['no_switch_version']);
- if (OrderConst::PAY_SWITCH_NO == $_rs) {
- return OrderConst::PAY_SWITCH_NO;
- }
-
- $_rs = $this->switchTime($_switch_rule['start_time'], $_switch_rule['end_time']);
- if (OrderConst::PAY_SWITCH_NO == $_rs) {
- return OrderConst::PAY_SWITCH_NO;
- }
-
- $_rs = $this->switchIp($device->getIp(), $_switch_rule['is_domestic'], $_switch_rule['is_overseas']);
- if (OrderConst::PAY_SWITCH_NO == $_rs) {
- return OrderConst::PAY_SWITCH_NO;
- }
-
- $_os = $device->getOs();
- if (false !== strpos(strtolower($_os), 'android')) {
-
- $_rs = $this->switchFirst($mem->getMemId(), $_app_id, $_switch_rule['is_first']);
- if (OrderConst::PAY_SWITCH_NO == $_rs) {
- return OrderConst::PAY_SWITCH_NO;
- }
- }
-
-
- $_rs = $this->switchMoney($order->getProductRealPrice(), $_switch_rule['price']);
- if (OrderConst::PAY_SWITCH_NO == $_rs) {
- return OrderConst::PAY_SWITCH_NO;
- }
-
- $_rs = $this->switchOs($_os, $_switch_rule['system']);
- if (OrderConst::PAY_SWITCH_NO == $_rs) {
- return OrderConst::PAY_SWITCH_NO;
- }
-
- $_rs = $this->switchSever($_app_id, $role->getServerId());
- if (OrderConst::PAY_SWITCH_NO == $_rs) {
- return OrderConst::PAY_SWITCH_NO;
- }
-
- if (empty($_switch_rule['combat_num_mini']) && empty($_switch_rule['combat_num_max'])) {
-
- return OrderConst::PAY_SWITCH_YES;
- }
- $_combat_num = $role->getCombatNum();
- if (empty($_combat_num)) {
- $_data = (new MgRoleModel())->getDetailByMemGameServerRole(
- $mem->getMgMemId(), $_app_id, $role->getServerId(), $role->getRoleId()
- );
- $_combat_num = empty($_data['combat_num']) ? 0 : $_data['combat_num'];
- }
- $_rs = $this->switchCombat($_combat_num, $_switch_rule['combat_num_mini'], $_switch_rule['combat_num_max']);
- if (OrderConst::PAY_SWITCH_NO == $_rs) {
- return OrderConst::PAY_SWITCH_NO;
- }
- return OrderConst::PAY_SWITCH_YES;
- }
-
- public function getSwitch(GameRq $game_rq, Device $device) {
-
- $_app_id = $game_rq->getHAppId();
- $_pay_switch = (new Game())->getPaySwitchStatus($_app_id);
- if (OrderConst::PAY_SWITCH_NO == $_pay_switch) {
- return OrderConst::PAY_SWITCH_NO;
- }
-
- $_switch_rule = GamePaySwitchCache::ins()->getInfoByAppId($_app_id);
- if (empty($_switch_rule)) {
-
- return $_pay_switch;
- }
-
- $_rs = $this->inIpWhite($device->getIp(), $_switch_rule['ip_white']);
- if (true == $_rs) {
-
- return $_pay_switch;
- }
-
- $_rs = $this->inArea($device->getIp(), $_switch_rule['area']);
- if (OrderConst::PAY_SWITCH_NO == $_rs) {
- return OrderConst::PAY_SWITCH_NO;
- }
- $_client_id = $game_rq->getHVer();
-
- $_rs = $this->switchVersion($_client_id, $_switch_rule['no_switch_version']);
- if (OrderConst::PAY_SWITCH_NO == $_rs) {
- return OrderConst::PAY_SWITCH_NO;
- }
-
- $_rs = $this->switchTime($_switch_rule['start_time'], $_switch_rule['end_time']);
- if (OrderConst::PAY_SWITCH_NO == $_rs) {
- return OrderConst::PAY_SWITCH_NO;
- }
-
- $_rs = $this->switchIp($device->getIp(), $_switch_rule['is_domestic'], $_switch_rule['is_overseas']);
- if (OrderConst::PAY_SWITCH_NO == $_rs) {
- return OrderConst::PAY_SWITCH_NO;
- }
- $_os = $device->getOs();
-
- $_rs = $this->switchOs($_os, $_switch_rule['system']);
- if (OrderConst::PAY_SWITCH_NO == $_rs) {
- return OrderConst::PAY_SWITCH_NO;
- }
- return OrderConst::PAY_SWITCH_YES;
- }
-
- public function inArea($ip, $area) {
- if (empty($area)) {
-
- return OrderConst::PAY_SWITCH_YES;
- }
- $_area_array = explode('|', $area);
- if (empty($_area_array)) {
- return OrderConst::PAY_SWITCH_YES;
- }
- $_ip_arr = Ip::find($ip);
- if (empty($_ip_arr)) {
-
- return OrderConst::PAY_SWITCH_NO;
- }
- if (in_array($_ip_arr[2], $_area_array)) {
-
- return OrderConst::PAY_SWITCH_NO;
- }
- return OrderConst::PAY_SWITCH_YES;
- }
-
- public function inMemWhite($app_id, $mem_id) {
- $_data = (new PsMemWhiteModel())->getInfo($app_id, $mem_id);
- if (!empty($_data)) {
- return true;
- }
- return false;
- }
-
- public function inIpWhite($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;
- }
-
- public function switchCombat($combat_num, $combat_num_mini, $combat_num_max) {
- if (empty($combat_num)) {
-
- return OrderConst::PAY_SWITCH_NO;
- }
- if ($combat_num_mini < $combat_num && $combat_num < $combat_num_max) {
-
- return OrderConst::PAY_SWITCH_YES;
- }
- return OrderConst::PAY_SWITCH_NO;
- }
-
- public function switchSever($app_id, $sever_id) {
-
- if (empty($app_id) || empty($sever_id)) {
- return OrderConst::PAY_SWITCH_YES;
- }
- $_data = (new GameServerSwitchModel())->getInfo($app_id, $sever_id);
- if (empty($_data)) {
-
- return OrderConst::PAY_SWITCH_YES;
- }
- return $_data['is_switch'];
- }
-
- public function switchVersion($client_id = 0, $rule_clients = '') {
- if (empty($rule_clients) || empty($client_id)) {
-
- return OrderConst::PAY_SWITCH_YES;
- }
- $_rule_clients = trim($rule_clients, ',');
- if ($client_id == $_rule_clients) {
-
- return OrderConst::PAY_SWITCH_NO;
- }
- 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 OrderConst::PAY_SWITCH_NO;
- }
- }
- return OrderConst::PAY_SWITCH_YES;
- }
-
- public function switchOs($os = '', $rule_os = '') {
- if (empty($rule_os) || empty($os)) {
-
- return OrderConst::PAY_SWITCH_YES;
- }
- if (false !== strpos(strtolower($os), 'ios')
- && false !== strpos($rule_os, strval(GameConst::GAME_IOS))) {
-
- return OrderConst::PAY_SWITCH_YES;
- } elseif (false !== strpos(strtolower($os), 'android')
- && false !== strpos($rule_os, strval(GameConst::GAME_ANDROID))) {
-
- return OrderConst::PAY_SWITCH_YES;
- }
-
- if (false !== strpos(strtolower($os), 'ios')) {
- return OrderConst::PAY_SWITCH_IOS_NO;
- }
-
- return OrderConst::PAY_SWITCH_NO;
- }
-
- public function switchTime($start_time, $end_time) {
- if (empty($start_time)) {
- $start_time = '00:00:00';
- }
- if (empty($end_time)) {
- $end_time = '23:59:59';
- }
- if ($end_time == '00:00:00') {
- $end_time = '23:59:59';
- }
- if ($start_time == $end_time) {
- $start_time = '00:00:00';
- $end_time = '23:59:59';
- }
- $_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 OrderConst::PAY_SWITCH_NO;
- }
- return OrderConst::PAY_SWITCH_YES;
- }
-
- public function switchIp($ip, $is_domestic, $is_overseas) {
- if (empty($is_domestic) && empty($is_overseas)) {
- return OrderConst::PAY_SWITCH_YES;
- }
- if (OrderConst::PAY_SWITCH_YES == $is_domestic && OrderConst::PAY_SWITCH_YES == $is_overseas) {
- return OrderConst::PAY_SWITCH_YES;
- }
- $_ip_arr = Ip::find($ip);
- if (empty($_ip_arr)) {
-
- return OrderConst::PAY_SWITCH_NO;
- }
-
- $_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 && OrderConst::PAY_SWITCH_NO == $is_domestic) {
- return OrderConst::PAY_SWITCH_NO;
- }
- if (false == $_ip_is_domestic && OrderConst::PAY_SWITCH_NO == $is_overseas) {
- return OrderConst::PAY_SWITCH_NO;
- }
- return OrderConst::PAY_SWITCH_YES;
- }
-
- public function switchFirst($mem_id, $app_id, $is_first) {
- if (OrderConst::PAY_IS_FIRST != $is_first) {
- return OrderConst::PAY_SWITCH_YES;
- }
- $_map = [
- 'app_id' => $app_id,
- 'mem_id' => $mem_id,
- 'status' => OrderConst::PAY_STATUS_SUC
- ];
- $_rs = (new OrderLogic())->isFirstCharge($_map);
- if (true == $_rs) {
-
- return OrderConst::PAY_SWITCH_NO;
- }
- return OrderConst::PAY_SWITCH_YES;
- }
-
- public function switchMoney($amount, $rule_money = 0.00) {
- if (empty($rule_money)) {
-
- return OrderConst::PAY_SWITCH_YES;
- }
- if ($amount < $rule_money) {
-
- return OrderConst::PAY_SWITCH_NO;
- }
- return OrderConst::PAY_SWITCH_YES;
- }
- public function checkShowPay($pay_check, Device $device_rq) {
- $_pay_check = $pay_check;
- if (OrderConst::PAY_SWITCH_NO == $_pay_check) {
-
- $_os = $device_rq->getOs();
- if (false !== strpos(strtolower($_os), 'ios')) {
- $_pay_check = OrderConst::PAY_SWITCH_IOS_NO;
- }
- }
- return $_pay_check;
- }
- }
|