123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- /**
- * OauthOut.php UTF-8
- * 小程序登陆
- *
- * @date : 2018/8/17 15:02
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HuoMp 1.0
- */
- namespace huomp\controller\member;
- use huo\controller\agent\AgentCache;
- use huo\controller\common\Base;
- use huo\controller\game\GameCache;
- use huo\controller\member\MemAgent;
- use huo\controller\member\MemCache;
- use huo\controller\member\Oauth;
- use huo\controller\request\Channel;
- use huo\controller\request\Device;
- use huo\controller\request\Game;
- use huo\controller\request\Mem;
- use huolib\constant\AgentConst;
- use huolib\constant\CommonConst;
- use huolib\constant\FromConst;
- use huolib\constant\OauthConst;
- use huolib\constant\OrderConst;
- use huolib\status\MemberStatus;
- use huolib\tool\Rand;
- use huomp\controller\agent\AgentState;
- class OauthOut extends Base {
- /**
- * 小程序用户登陆注册
- *
- * @param string $code 第三方用户登录获取的code码
- * @param string $state 上级state码
- * @param Game $game_rq
- * @param Channel $channel
- * @param Device $device
- * @param Mem $member
- *
- * @return array
- */
- public function oauthLogin($code, $state, Game $game_rq, Channel $channel, Device $device, Mem $member) {
- $_code = $code;
- if (empty($_code)) {
- $_code = MemberStatus::INVALID_PARAMS;
- return $this->huoError($_code, MemberStatus::getMsg($_code));
- }
- $_parent_ag_id = (new AgentState())->getIdByCode($state);
- $_parent_agent_id = 0; /* 上级渠道ID */
- $_parent_mem_id = 0; /* 上级玩家ID */
- if (!empty($_parent_ag_id)) {
- $_ac_class = AgentCache::ins();
- $_parent_agent_id = $_ac_class->getAgentIdByAgId($_parent_ag_id);
- $_parent_mem_id = $_ac_class->getMemIdByAgentId($_parent_agent_id);
- }
- $_type = OauthConst::OAUTH_MP;
- $_oauth_class = new Oauth();
- $_game_info = (GameCache::ins())->getInfoByAppId($game_rq->getHAppId());
- $_ext_info = !empty($_game_info['ext_info']) ? $_game_info['ext_info'] : [];
- if (!empty($_parent_mem_id)) {
- $_parent_mem_data = (MemCache::ins())->getInfoById($_parent_mem_id);
- if (!empty($_parent_mem_data)) {
- //设置父级玩家ID
- $member->setParentMemId($_parent_mem_id);
- // $member->setAgentId($_parent_agent_id);
- // $channel->setAgentId($_parent_agent_id);
- }
- } elseif (!empty($_parent_agent_id) && empty($_parent_mem_id)) {
- $_agent_data = AgentCache::ins()->getInfoByAgentId($_parent_agent_id);
- $member->setAgentId($_parent_agent_id);
- $channel->setAgentId($_parent_agent_id);
- if (AgentConst::AGENT_ROLE_MP_AGENT == $_agent_data['role_id']) { //小程序渠道
- if (empty($_ext_info['agent_id']) && OrderConst::PAY_SWITCH_YES == $_agent_data['is_switch']) {
- //概率性切换玩家
- $_is_switch = $_agent_data['switch_rate'];
- $_arr = ['is_switch' => $_is_switch, 'no_switch' => CommonConst::NUMBER_100 - $_is_switch];
- $_key = Rand::getRand($_arr);
- if ('is_switch' == $_key) {
- $member->setSwitch(OrderConst::PAY_SWITCH_YES);
- }
- }
- }
- }
- /* 判断小程序马甲是否有游戏管理员 */
- if (!empty($_ext_info['agent_id']) && empty($_parent_agent_id)) {
- $member->setAgentId($_ext_info['agent_id']);
- $channel->setAgentId($_ext_info['agent_id']);
- }
- $from = FromConst::FROM_WEIXIN;
- $_rs = $_oauth_class->oauthLoginByCode($_type, $_code, $from, $game_rq, $channel, $device, $member);
- if (MemberStatus::NO_ERROR != $_rs['code']) {
- return $this->huoReturn($_rs);
- }
- $_mem_id = $_rs['data']['mem_id'];
- if (empty($_mem_id)) {
- $_code = MemberStatus::INNER_ERROR;
- return $this->huoError($_code, MemberStatus::getMsg($_code));
- }
- //生成玩家渠道
- // $_agent_id = (new MemAgent())->getMemAgentId($_mem_id);
- // if (empty($_agent_id)) {
- // $_code = MemberStatus::INNER_ERROR;
- //// return $this->huoError($_code, MemberStatus::getMsg($_code));
- // }
- // //新注册添加三款有奖励的游戏作为推广游戏
- // $_isReg = isset($_rs['data']['is_reg']) ? $_rs['data']['is_reg'] : 0;
- // if (!empty($_agent_id) && !empty($_isReg)) {
- // $_ids = (new AgentGameListLogic())->getRewardGame();
- // if (!empty($_ids)) {
- // foreach ($_ids as $_v) {
- // (new AgentGame())->addGame($_agent_id, $_v);
- // }
- // }
- // }
- return $this->huoReturn($_rs);
- }
- }
|