GamePaySwitchLogic.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. /**
  3. * GamePaySwitchLogic.php UTF-8
  4. * 支付切换逻辑处理
  5. *
  6. * @date : 2018/6/6 22:10
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\logic\game;
  13. use ban\model\DeviceBanModel;
  14. use ban\model\IpBanModel;
  15. use huo\controller\game\GamePaySwitchCache;
  16. use huo\model\common\CommonModel;
  17. use huo\model\game\GamePaySwitchModel;
  18. use huo\model\member\MemberModel;
  19. use huolib\constant\OrderConst;
  20. class GamePaySwitchLogic extends CommonModel {
  21. public $base_field
  22. = [
  23. 'app_id' => 'app_id',
  24. 'switch_app_id' => 'switch_app_id',
  25. 'pages' => 'pages',
  26. 'start_time' => 'start_time',
  27. 'end_time' => 'end_time',
  28. 'start_ip' => 'start_ip',
  29. 'end_ip' => 'end_ip',
  30. 'is_first' => 'is_first',
  31. 'price' => 'price',
  32. 'is_domestic' => 'is_domestic',
  33. 'is_overseas' => 'is_overseas',
  34. 'no_switch_version' => 'no_switch_version',
  35. 'system' => 'system',
  36. 'pay_type' => 'pay_type',
  37. 'combat_num_mini' => 'combat_num_mini',
  38. 'combat_num_max' => 'combat_num_max',
  39. 'ip_white' => 'ip_white',
  40. 'area' => 'area',
  41. 'money' => 'money',
  42. 'active_days' => 'active_days',
  43. 'mem_id' => 'mem_id',
  44. 'sum_money' => 'sum_money',
  45. ];
  46. public function getBaseField() {
  47. return $this->base_field;
  48. }
  49. /**
  50. * 切换规则列表
  51. *
  52. * @param int $app_id
  53. * @param string $page
  54. *
  55. * @return mixed
  56. */
  57. public function getLists($app_id = 0, $page = '') {
  58. $_map = [];
  59. if (!empty($app_id)) {
  60. $_map['app_id'] = $app_id;
  61. }
  62. $_model = new GamePaySwitchModel();
  63. $_count = $_model->where($_map)->count();
  64. if ($_count <= 0) {
  65. $_rdata['count'] = 0;
  66. $_rdata['list'] = [];
  67. } else {
  68. $_field = $this->base_field;
  69. $_switch_lists = $_model
  70. ->with('game')
  71. ->field($_field)
  72. ->where($_map)
  73. ->page($page)
  74. ->select();
  75. if (is_object($_switch_lists)) {
  76. $_switch_lists = $_switch_lists->toArray();
  77. }
  78. $_lists = [];
  79. foreach ($_switch_lists as $_v) {
  80. $_data = [];
  81. foreach ($_field as $_value) {
  82. $_data[$_value] = $_v[$_value];
  83. }
  84. $_data['game_name'] = '';
  85. $_data['pay_switch_text'] = '';
  86. if (!empty($_v['game'])) {
  87. $_data['game_name'] = empty($_v['game']['game_name']) ? '' : $_v['game']['game_name'];
  88. $_data['pay_switch_text'] = OrderConst::PAY_SWITCH_YES == $_v['game']['pay_switch'] ? lang('switch')
  89. : lang('not_switch');
  90. }
  91. $_lists[] = $_data;
  92. }
  93. $_rdata = [
  94. 'count' => $_count,
  95. 'list' => $_lists
  96. ];
  97. }
  98. return $_rdata;
  99. }
  100. /***
  101. * 添加切换规则
  102. *
  103. * @param $param
  104. *
  105. * @return false|int
  106. */
  107. public function addPaySwitch($param) {
  108. $_rs = (new GamePaySwitchModel())->allowField(true)->save($param);
  109. return $_rs;
  110. }
  111. /**
  112. * 获取规则信息
  113. *
  114. * @param $app_id
  115. *
  116. * @return bool
  117. */
  118. public function getInfoByAppId($app_id) {
  119. if (empty($app_id)) {
  120. return false;
  121. }
  122. $_map['app_id'] = $app_id;
  123. $_field = $this->base_field;
  124. $_rdata = (new GamePaySwitchModel())->field($_field)->where($_map)->find();
  125. if (is_object($_rdata)) {
  126. $_rdata = $_rdata->toArray();
  127. }
  128. return $_rdata;
  129. }
  130. /**
  131. * 更新规则信息
  132. *
  133. * @param $param
  134. * @param $app_id
  135. *
  136. * @return GamePaySwitchModel
  137. */
  138. public function updatePaySwitch($param, $app_id) {
  139. $_map['app_id'] = $app_id;
  140. $_rs = (new GamePaySwitchModel())->update($param, $_map, true);
  141. return $_rs;
  142. }
  143. /***
  144. * 查找切换规则是否已存在
  145. *
  146. * @param $app_id
  147. *
  148. * @return bool
  149. */
  150. public function checkGame($app_id) {
  151. $_info = GamePaySwitchCache::ins()->getInfoByAppId($app_id);
  152. if (empty($_info)) {
  153. return false;
  154. }
  155. return true;
  156. }
  157. /**
  158. * 获取IP白名单个数
  159. *
  160. * @return int
  161. */
  162. public function getIpWhiteCnt() {
  163. $_map['pay_switch'] = OrderConst::PAY_SWITCH_YES;
  164. return (new IpBanModel())->getCnt($_map);
  165. }
  166. /**
  167. * 获取IP黑名单个数
  168. *
  169. * @return int
  170. */
  171. public function getIpBlackCnt() {
  172. $_map['pay_switch'] = OrderConst::PAY_SWITCH_NO;
  173. return (new IpBanModel())->getCnt($_map);
  174. }
  175. /**
  176. * 获取玩家白名单个数
  177. *
  178. * @return int
  179. */
  180. public function getMemWhiteCnt() {
  181. $_map['pay_switch'] = OrderConst::PAY_SWITCH_YES;
  182. return (new MemberModel())->getCnt($_map);
  183. }
  184. /**
  185. * 获取玩家黑名单个数
  186. *
  187. * @return int
  188. */
  189. public function getMemBlackCnt() {
  190. $_map['pay_switch'] = OrderConst::PAY_SWITCH_NO;
  191. return (new MemberModel())->getCnt($_map);
  192. }
  193. /**
  194. * 获取IP切换状态
  195. *
  196. * @param string $ip IP地址
  197. *
  198. * @return int PAY_SWITCH_YES 1 切换 PAY_SWITCH_NO 2 不切换 PAY_SWITCH_NO_FOREVER 3 永不切换
  199. */
  200. public function getPaySwitchByIp($ip) {
  201. if (empty($ip)) {
  202. return OrderConst::PAY_SWITCH_NO;
  203. }
  204. return (new IpBanModel())->getPaySwitch($ip);
  205. }
  206. }