PayShow.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <?php
  2. /**
  3. * PayShow.php UTF-8
  4. * 支付显示判断
  5. *
  6. *
  7. * @date : 2019/8/27 21:14
  8. *
  9. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  10. * @author : dengcongshuai <dcs@huosdk.com>
  11. * @version : HUOSDK 8.0
  12. */
  13. namespace huo\controller\pay;
  14. use huo\controller\common\Base;
  15. use huo\controller\game\Game;
  16. use huo\controller\game\GamePayShowCache;
  17. use huo\controller\request\Channel;
  18. use huo\controller\request\Device;
  19. use huo\controller\request\Game as GameRq;
  20. use huo\controller\request\Mem;
  21. use huo\controller\request\Order as OrderRq;
  22. use huo\controller\request\Role;
  23. use huo\model\member\MgRoleModel;
  24. use huolib\constant\CommonConst;
  25. use huolib\constant\GameConst;
  26. use huolib\tool\Ip;
  27. class PayShow extends Base {
  28. /**
  29. * 判断支付显示
  30. *
  31. * @param OrderRq $order
  32. * @param Role $role
  33. * @param Mem $mem
  34. * @param GameRq $game_rq
  35. * @param Channel $channel
  36. * @param Device $device
  37. *
  38. * @return int 1 不显示 2 显示
  39. */
  40. public function getPayShow(OrderRq $order, Role $role, Mem $mem, GameRq $game_rq, Channel $channel, Device $device
  41. ) {
  42. $_from = $device->getFrom();
  43. if (GameConst::GAME_IOS_SWITCH != $_from && GameConst::GAME_MP != $_from) {
  44. return CommonConst::STATUS_YES;
  45. }
  46. /* 查询游戏是否是屏蔽 */
  47. $_app_id = $game_rq->getHAppId();
  48. $_pay_show = (new Game())->getPayShowStatus($_app_id);
  49. if (CommonConst::STATUS_NO == $_pay_show) {
  50. return CommonConst::STATUS_NO;
  51. }
  52. /* 获取屏蔽规则 */
  53. $_show_rule = GamePayShowCache::ins()->getInfoByAppId($_app_id);
  54. if (empty($_show_rule)) {
  55. return CommonConst::STATUS_YES;
  56. }
  57. /* 判断IP是否在黑名单 */
  58. $_rs = $this->inIpBlack($device->getIp(), $_show_rule['ip_black']);
  59. if (true == $_rs) {
  60. return CommonConst::STATUS_NO;
  61. }
  62. /* 判断城市是否屏蔽 */
  63. $_rs = $this->inArea($device->getIp(), $_show_rule['area']);
  64. if (true == $_rs) {
  65. return CommonConst::STATUS_NO;
  66. }
  67. $_client_id = $game_rq->getHVer();
  68. /* 判断版本是否屏蔽 */
  69. $_rs = $this->showVersion($_client_id, $_show_rule['no_show_version']);
  70. if (true == $_rs) {
  71. return CommonConst::STATUS_NO;
  72. }
  73. /* 根据时间判断是否屏蔽 */
  74. $_rs = $this->showTime($_show_rule['start_time'], $_show_rule['end_time']);
  75. if (true == $_rs) {
  76. return CommonConst::STATUS_NO;
  77. }
  78. /* 根据IP段判断是否切换 */
  79. $_rs = $this->showIp($device->getIp(), $_show_rule['is_domestic'], $_show_rule['is_overseas']);
  80. if (true == $_rs) {
  81. return CommonConst::STATUS_NO;
  82. }
  83. $_os = $device->getOs();
  84. /* 判断版本是否屏蔽 */
  85. $_rs = $this->showOs($_os, $_show_rule['system']);
  86. if (true == $_rs) {
  87. return CommonConst::STATUS_NO;
  88. }
  89. /* 连续登录天数判断屏蔽 */
  90. $_data = (new MgRoleModel())->getDetailByMemGameServerRole(
  91. $mem->getMgMemId(), $_app_id, $role->getServerId(), $role->getRoleId()
  92. );
  93. $_login_day = empty($_data['ext']['login_day']) ? 1 : $_data['ext']['login_day'];
  94. $_rs = $this->showLoginDay($_login_day, $_show_rule['login_day_mini'], $_show_rule['login_day_max']);
  95. if (true == $_rs) {
  96. return CommonConst::STATUS_NO;
  97. }
  98. /* 判断等级是否屏蔽 */
  99. $_role_level = $role->getRoleLevel();
  100. if (empty($_role_level)) {
  101. $_role_level = empty($_data['role_level']) ? 0 : $_data['role_level'];
  102. }
  103. $_rs = $this->showLevel($_role_level, $_show_rule['level_mini'], $_show_rule['level_max']);
  104. if (true == $_rs) {
  105. return CommonConst::STATUS_NO;
  106. }
  107. /* 判断战力是否切换 */
  108. $_combat_num = $role->getCombatNum();
  109. if (empty($_combat_num)) {
  110. $_combat_num = empty($_data['combat_num']) ? 0 : $_data['combat_num'];
  111. }
  112. $_rs = $this->showCombat($_combat_num, $_show_rule['combat_num_mini'], $_show_rule['combat_num_max']);
  113. if (true == $_rs) {
  114. return CommonConst::STATUS_NO;
  115. }
  116. return CommonConst::STATUS_YES;
  117. }
  118. /**
  119. * 判断是否在IP白名单
  120. *
  121. * @param string $ip 当前ip
  122. * @param string $area 不切换的城市名
  123. *
  124. * @return int
  125. */
  126. public function inArea($ip, $area) {
  127. if (empty($area)) {
  128. /* 没城市则返回切换 */
  129. return false;
  130. }
  131. $_area_array = explode('|', $area);
  132. if (empty($_area_array)) {
  133. return false;
  134. }
  135. $_ip_arr = Ip::find($ip);
  136. if (empty($_ip_arr)) {
  137. /* 未知IP不切换 */
  138. return false;
  139. }
  140. if (in_array($_ip_arr[2], $_area_array)) {
  141. /* 如果城市名在不切换城市 */
  142. return true;
  143. }
  144. return false;
  145. }
  146. /**
  147. * 判断是否在IP白名单
  148. *
  149. * @param string $ip 当前ip
  150. * @param string $ip_white ip白名单字符串
  151. *
  152. * @return bool
  153. */
  154. public function inIpBlack($ip, $ip_white) {
  155. if (empty($ip_white)) {
  156. /* 没白名单则返回跳过 */
  157. return false;
  158. }
  159. $_ip_array = explode('|', $ip_white);
  160. if (empty($_ip_array)) {
  161. return false;
  162. }
  163. if (in_array($ip, $_ip_array)) {
  164. return true;
  165. }
  166. return false;
  167. }
  168. /**
  169. * 判断连续登录天数是否屏蔽
  170. *
  171. * @param int $login_day_num 连续登录天数
  172. * @param int $login_day_mini 连续登录天数区间小值
  173. * @param int $login_day_max 连续登录天数区间大值
  174. *
  175. * @return bool
  176. */
  177. public function showLoginDay($login_day_num, $login_day_mini, $login_day_max) {
  178. if (empty($login_day_max)) {
  179. /* 未设置 不屏蔽 */
  180. return false;
  181. }
  182. if (empty($login_day_num) && !empty($login_day_max)) {
  183. /* 没有等级信息 屏蔽 */
  184. return true;
  185. }
  186. if ($login_day_mini <= $login_day_num && $login_day_num < $login_day_max) {
  187. /* 战力区间内屏蔽*/
  188. return true;
  189. }
  190. return false;
  191. }
  192. /**
  193. * 判断等级是否屏蔽
  194. *
  195. * @param int $level 角色等级
  196. * @param int $level_mini 等级区间小值
  197. * @param int $level_max 等级区间大值
  198. *
  199. * @return bool
  200. */
  201. public function showLevel($level, $level_mini, $level_max) {
  202. if (empty($level_max)) {
  203. /* 未设置 不屏蔽 */
  204. return false;
  205. }
  206. if (empty($level) && !empty($level_max)) {
  207. /* 没有等级信息 屏蔽 */
  208. return true;
  209. }
  210. if ($level_mini <= $level && $level < $level_max) {
  211. /* 战力区间内屏蔽*/
  212. return true;
  213. }
  214. return false;
  215. }
  216. /**
  217. * 判断战力是否切换
  218. *
  219. * @param int $combat_num 角色战力
  220. * @param int $combat_num_mini 战力区间小值
  221. * @param int $combat_num_max 战力区间大值
  222. *
  223. * @return bool
  224. */
  225. public function showCombat($combat_num, $combat_num_mini, $combat_num_max) {
  226. if (empty($combat_num_max)) {
  227. /* 未设置 不屏蔽 */
  228. return false;
  229. }
  230. if (empty($combat_num_max) && !empty($combat_num_max)) {
  231. /* 没有战力表示 屏蔽 */
  232. return true;
  233. }
  234. if ($combat_num_mini < $combat_num && $combat_num < $combat_num_max) {
  235. /* 战力区间内屏蔽*/
  236. return true;
  237. }
  238. return false;
  239. }
  240. /**
  241. * 判断版本号是否屏蔽
  242. *
  243. * @param int $client_id 版本ID
  244. * @param string $rule_clients 不切换的版本
  245. *
  246. * @return bool false 不屏蔽 true 屏蔽
  247. */
  248. public function showVersion($client_id = 0, $rule_clients = '') {
  249. if (empty($rule_clients) || empty($client_id)) {
  250. /* 没有设置不切换版本 全部切换 */
  251. return false;
  252. }
  253. $_rule_clients = trim($rule_clients, ',');
  254. if ($client_id == $_rule_clients) {
  255. /* 当前版本等于不切换版本 不切换 */
  256. return true;
  257. }
  258. if (false == strpos($rule_clients, ',')) {
  259. $_rule_clients_arr = explode(',', $_rule_clients);
  260. if (is_array($_rule_clients_arr) && in_array($client_id, $_rule_clients_arr)) {
  261. /* 当前版本在不切换版本内 不切换 */
  262. return true;
  263. }
  264. }
  265. return false;
  266. }
  267. /**
  268. * 判断操作系统是否切换
  269. *
  270. * @param string $os 操作系统
  271. * @param string $rule_os 切换的操作系统
  272. *
  273. * @return bool false 不屏蔽 true 屏蔽
  274. */
  275. public function showOs($os = '', $rule_os = '') {
  276. if (empty($rule_os) || empty($os)) {
  277. /* 没有设置不切换版本 全部切换 */
  278. return false;
  279. }
  280. if (false !== strpos(strtolower($os), 'ios')
  281. && false !== strpos($rule_os, strval(GameConst::GAME_IOS))) {
  282. return false;
  283. } elseif (false !== strpos(strtolower($os), 'android')
  284. && false !== strpos($rule_os, strval(GameConst::GAME_ANDROID))) {
  285. return false;
  286. }
  287. return true;
  288. }
  289. /**
  290. * 判断是否在时间范围内
  291. *
  292. * @param String $start_time
  293. * @param INT $end_time
  294. *
  295. * @return bool false 不屏蔽 true 屏蔽
  296. */
  297. public function showTime($start_time, $end_time) {
  298. if ($start_time == $end_time || $end_time == '00:00:00') {
  299. return false;
  300. }
  301. $_time = time();
  302. $_start_time = strtotime(date('Y-m-d').' '.$start_time);
  303. $_end_time = strtotime(date('Y-m-d').' '.$end_time);
  304. if ($_time > $_start_time && $_time < $_end_time) {
  305. return true;
  306. }
  307. return false;
  308. }
  309. /**
  310. * 判断IP是否是国内IP
  311. *
  312. * @param string $ip IP地址
  313. * @param int $is_domestic 国内是否屏蔽 1不屏蔽 2屏蔽
  314. * @param int $is_overseas 国外是否屏蔽 1切换 2屏蔽
  315. *
  316. * @return bool false 不屏蔽 true 屏蔽
  317. */
  318. public function showIp($ip, $is_domestic, $is_overseas) {
  319. if (empty($is_domestic) && empty($is_overseas)) {
  320. return false;
  321. }
  322. if (CommonConst::STATUS_NO == $is_domestic && CommonConst::STATUS_NO == $is_overseas) {
  323. return true;
  324. }
  325. $_ip_arr = Ip::find($ip);
  326. if (empty($_ip_arr)) {
  327. /* 未知IP不屏蔽 */
  328. return false;
  329. }
  330. /* 根据统计需要,港澳台地区放入海外处理 */
  331. $_domestic_except = array('台湾', '香港', '澳门');
  332. $_ip_is_domestic = false;
  333. if (is_array($_ip_arr) && '中国' == $_ip_arr[0]) {
  334. $_ip_is_domestic = true;
  335. if (!empty($_ip_arr[1]) && in_array($_ip_arr[1], $_domestic_except)) {
  336. $_ip_is_domestic = false;
  337. }
  338. }
  339. if (true == $_ip_is_domestic && CommonConst::STATUS_NO == $is_domestic) {
  340. return true;
  341. }
  342. if (false == $_ip_is_domestic && CommonConst::STATUS_NO == $is_overseas) {
  343. return true;
  344. }
  345. return false;
  346. }
  347. }