OaFirstFosterController.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. /**
  3. * Oacallback.php UTF-8
  4. *
  5. *
  6. * @date : 2017/6/16 10:08
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : guxiannong <gxn@huosdk.com>
  10. * @version : HUOOA 1.0
  11. */
  12. namespace api\oa\controller;
  13. class OaFirstFosterController extends OacallbackController {
  14. function _initialize() {
  15. parent::_initialize();
  16. $this->firstFosterCheck();
  17. $this->index();
  18. }
  19. public function firstFosterCheck() {
  20. $this->checkTypeId();
  21. $this->checkGameId();
  22. $this->checkUsername();
  23. $this->checkSerCode();
  24. $this->checkRoleName();
  25. $this->checkMemberRole();
  26. }
  27. /**
  28. * 检测请求类型 参数
  29. *
  30. * @return bool
  31. */
  32. public function checkTypeId() {
  33. if (!isset($this->param['type_id']) || empty($this->param['type_id'])) {
  34. return $this->oa_class->hs_api_responce('407', '类型ID错误');
  35. }
  36. return true;
  37. }
  38. /**
  39. * 游戏id参数
  40. *
  41. * @return bool
  42. */
  43. public function checkGameId() {
  44. if (empty($this->param['game_id'])) {
  45. return $this->oa_class->hs_api_responce('405', '游戏ID错误');
  46. }
  47. return true;
  48. }
  49. /**
  50. * 玩家账号检测
  51. *
  52. * @return bool
  53. */
  54. public function checkUsername() {
  55. if (empty($this->param['username'])) {
  56. return $this->oa_class->hs_api_responce('406', '玩家用户名错误');
  57. }
  58. return true;
  59. }
  60. /**
  61. * 渠道标识检测
  62. *
  63. * @return bool
  64. */
  65. public function checkSerCode() {
  66. if (empty($this->param['ser_code'])) {
  67. return $this->oa_class->hs_api_responce('415', '区服code错误');
  68. }
  69. return true;
  70. }
  71. /**
  72. * 玩家角色名参数检测
  73. *
  74. * @return bool
  75. */
  76. public function checkRoleName() {
  77. if (empty($this->param['role_name'])) {
  78. return $this->oa_class->hs_api_responce('415', '角色名错误');
  79. }
  80. return true;
  81. }
  82. /**
  83. * 检测玩家用户名和角色名对应关系
  84. */
  85. public function checkMemberRole() {
  86. $_oa_first_foster_class = new \huolib\oa\OaFirstFoster();
  87. $this->param = $_oa_first_foster_class->checkMemberRole($this->param);
  88. }
  89. /**
  90. *
  91. */
  92. public function index() {
  93. $this->firstFosterCheck();
  94. switch ($this->param['type_id']) {
  95. case 1:
  96. $this->gmFirst();
  97. break;
  98. case 2:
  99. $this->gmFoster();
  100. break;
  101. }
  102. }
  103. /**
  104. * 申请首充
  105. *
  106. * @return mixed
  107. */
  108. public function gmFirst() {/* 申请首充 */
  109. $this->checkIsFirst();
  110. /* 直接插入扶植记录表 */
  111. $_re = $this->addGmLog();
  112. /* 首充完直接发币?发完币绑定对应推广员 */
  113. if ($_re && 1 == 2) {
  114. }
  115. return $this->oa_class->hs_api_responce('200', '申请提交成功');
  116. }
  117. /**
  118. * 申请扶植
  119. *
  120. * @return mixed
  121. */
  122. public function gmFoster() {/* 申请扶植 */
  123. /* 直接插入扶植记录表 */
  124. $_re = $this->addGmLog();
  125. if (empty($_re)) {
  126. return $this->oa_class->hs_api_responce('502', '信息错误');
  127. }
  128. return $this->oa_class->hs_api_responce('200', '申请提交成功');
  129. }
  130. /**
  131. *检测是否首充
  132. */
  133. public function checkIsFirst() {
  134. $this->checkAgent();
  135. $this->checkPayFirst();
  136. }
  137. /**
  138. * 添加操作记录
  139. *
  140. * @return $this|int|string
  141. */
  142. public function addGmLog() {
  143. $_oa_first_foster_class = new \huolib\oa\OaFirstFoster();
  144. return $_oa_first_foster_class->addGmLog($this->param);
  145. }
  146. /**
  147. *
  148. * @return bool
  149. */
  150. public function updateMembers() {
  151. $_mem_map['id'] = $this->param['sdk_mem_id'];
  152. $_up_data = [];
  153. $_up_data['agentgame'] = $this->param['agentgame'];
  154. $_up_data['agent_id'] = $this->param['sdk_agent_id'];
  155. $_up_data['update_time'] = time();
  156. $_u_re = \think\Db::name('members')->where($_mem_map)->update($_up_data);
  157. if (empty($_u_re)) {
  158. return $this->oa_class->hs_api_responce('402', '更新用户归属错误');
  159. }
  160. return true;
  161. }
  162. /**
  163. * 检测渠道
  164. *
  165. * @return bool
  166. */
  167. public function checkAgent() {
  168. $_oa_first_foster_class = new \huolib\oa\OaFirstFoster();
  169. $this->param = $_oa_first_foster_class->checkAgent($this->param);
  170. return true;
  171. }
  172. /**
  173. * 判断是否首充
  174. *
  175. * @return $this|bool
  176. */
  177. public function checkPayFirst() {
  178. $_oa_first_foster_class = new \huolib\oa\OaFirstFoster();
  179. return $_oa_first_foster_class->checkPayFirst($this->param);
  180. }
  181. /**
  182. * 获取ip
  183. *
  184. * @param int $type
  185. * @param bool $adv
  186. *
  187. * @return mixed
  188. */
  189. public function get_client_ip($type = 0, $adv = false) {
  190. $type = $type ? 1 : 0;
  191. static $ip = null;
  192. if ($ip !== null) {
  193. return $ip[$type];
  194. }
  195. if ($adv) {
  196. if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  197. $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
  198. $pos = array_search('unknown', $arr);
  199. if (false !== $pos) {
  200. unset($arr[$pos]);
  201. }
  202. $ip = trim($arr[0]);
  203. } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
  204. $ip = $_SERVER['HTTP_CLIENT_IP'];
  205. } elseif (isset($_SERVER['REMOTE_ADDR'])) {
  206. $ip = $_SERVER['REMOTE_ADDR'];
  207. }
  208. } elseif (isset($_SERVER['REMOTE_ADDR'])) {
  209. $ip = $_SERVER['REMOTE_ADDR'];
  210. }
  211. // IP地址合法验证
  212. $long = sprintf("%u", ip2long($ip));
  213. $ip = $long ? array($ip, $long) : array('0.0.0.0', 0);
  214. return $ip[$type];
  215. }
  216. }