123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- <?php
- /**
- * Oacallback.php UTF-8
- *
- *
- * @date : 2017/6/16 10:08
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : guxiannong <gxn@huosdk.com>
- * @version : HUOOA 1.0
- */
- namespace api\oa\controller;
- class OaFirstFosterController extends OacallbackController {
- function _initialize() {
- parent::_initialize();
- $this->firstFosterCheck();
- $this->index();
- }
- public function firstFosterCheck() {
- $this->checkTypeId();
- $this->checkGameId();
- $this->checkUsername();
- $this->checkSerCode();
- $this->checkRoleName();
- $this->checkMemberRole();
- }
- /**
- * 检测请求类型 参数
- *
- * @return bool
- */
- public function checkTypeId() {
- if (!isset($this->param['type_id']) || empty($this->param['type_id'])) {
- return $this->oa_class->hs_api_responce('407', '类型ID错误');
- }
- return true;
- }
- /**
- * 游戏id参数
- *
- * @return bool
- */
- public function checkGameId() {
- if (empty($this->param['game_id'])) {
- return $this->oa_class->hs_api_responce('405', '游戏ID错误');
- }
- return true;
- }
- /**
- * 玩家账号检测
- *
- * @return bool
- */
- public function checkUsername() {
- if (empty($this->param['username'])) {
- return $this->oa_class->hs_api_responce('406', '玩家用户名错误');
- }
- return true;
- }
- /**
- * 渠道标识检测
- *
- * @return bool
- */
- public function checkSerCode() {
- if (empty($this->param['ser_code'])) {
- return $this->oa_class->hs_api_responce('415', '区服code错误');
- }
- return true;
- }
- /**
- * 玩家角色名参数检测
- *
- * @return bool
- */
- public function checkRoleName() {
- if (empty($this->param['role_name'])) {
- return $this->oa_class->hs_api_responce('415', '角色名错误');
- }
- return true;
- }
- /**
- * 检测玩家用户名和角色名对应关系
- */
- public function checkMemberRole() {
- $_oa_first_foster_class = new \huolib\oa\OaFirstFoster();
- $this->param = $_oa_first_foster_class->checkMemberRole($this->param);
- }
- /**
- *
- */
- public function index() {
- $this->firstFosterCheck();
- switch ($this->param['type_id']) {
- case 1:
- $this->gmFirst();
- break;
- case 2:
- $this->gmFoster();
- break;
- }
- }
- /**
- * 申请首充
- *
- * @return mixed
- */
- public function gmFirst() {/* 申请首充 */
- $this->checkIsFirst();
- /* 直接插入扶植记录表 */
- $_re = $this->addGmLog();
- /* 首充完直接发币?发完币绑定对应推广员 */
- if ($_re && 1 == 2) {
- }
- return $this->oa_class->hs_api_responce('200', '申请提交成功');
- }
- /**
- * 申请扶植
- *
- * @return mixed
- */
- public function gmFoster() {/* 申请扶植 */
- /* 直接插入扶植记录表 */
- $_re = $this->addGmLog();
- if (empty($_re)) {
- return $this->oa_class->hs_api_responce('502', '信息错误');
- }
- return $this->oa_class->hs_api_responce('200', '申请提交成功');
- }
- /**
- *检测是否首充
- */
- public function checkIsFirst() {
- $this->checkAgent();
- $this->checkPayFirst();
- }
- /**
- * 添加操作记录
- *
- * @return $this|int|string
- */
- public function addGmLog() {
- $_oa_first_foster_class = new \huolib\oa\OaFirstFoster();
- return $_oa_first_foster_class->addGmLog($this->param);
- }
- /**
- *
- * @return bool
- */
- public function updateMembers() {
- $_mem_map['id'] = $this->param['sdk_mem_id'];
- $_up_data = [];
- $_up_data['agentgame'] = $this->param['agentgame'];
- $_up_data['agent_id'] = $this->param['sdk_agent_id'];
- $_up_data['update_time'] = time();
- $_u_re = \think\Db::name('members')->where($_mem_map)->update($_up_data);
- if (empty($_u_re)) {
- return $this->oa_class->hs_api_responce('402', '更新用户归属错误');
- }
- return true;
- }
- /**
- * 检测渠道
- *
- * @return bool
- */
- public function checkAgent() {
- $_oa_first_foster_class = new \huolib\oa\OaFirstFoster();
- $this->param = $_oa_first_foster_class->checkAgent($this->param);
- return true;
- }
- /**
- * 判断是否首充
- *
- * @return $this|bool
- */
- public function checkPayFirst() {
- $_oa_first_foster_class = new \huolib\oa\OaFirstFoster();
- return $_oa_first_foster_class->checkPayFirst($this->param);
- }
- /**
- * 获取ip
- *
- * @param int $type
- * @param bool $adv
- *
- * @return mixed
- */
- public function get_client_ip($type = 0, $adv = false) {
- $type = $type ? 1 : 0;
- static $ip = null;
- if ($ip !== null) {
- return $ip[$type];
- }
- if ($adv) {
- if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
- $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
- $pos = array_search('unknown', $arr);
- if (false !== $pos) {
- unset($arr[$pos]);
- }
- $ip = trim($arr[0]);
- } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
- $ip = $_SERVER['HTTP_CLIENT_IP'];
- } elseif (isset($_SERVER['REMOTE_ADDR'])) {
- $ip = $_SERVER['REMOTE_ADDR'];
- }
- } elseif (isset($_SERVER['REMOTE_ADDR'])) {
- $ip = $_SERVER['REMOTE_ADDR'];
- }
- // IP地址合法验证
- $long = sprintf("%u", ip2long($ip));
- $ip = $long ? array($ip, $long) : array('0.0.0.0', 0);
- return $ip[$type];
- }
- }
|