123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- /**
- * CpaReversalController.php UTF-8
- * 渠道二维码倒量
- *
- * @date : 2019/3/21 19:51
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : chenbingling <cbl@huosdk.com>
- * @version : HuoMp 1.0
- */
- namespace huomp\controller\cpa_reversal;
- use huo\controller\agent\AgentCache;
- use huo\controller\common\Base;
- use huo\controller\member\Oauth;
- use huo\controller\queue\CpaReversalQueue;
- use huo\controller\request\Game;
- use huo\model\member\MemoauthModel;
- use huolib\constant\FromConst;
- use huolib\constant\MemConst;
- use huolib\constant\OauthConst;
- use huolib\status\CommonStatus;
- use huomp\controller\agent\AgentState;
- use huomp\model\agent\AgentAdsCfgModel;
- class CpaReversalController extends Base {
- /**
- * 倒量处理
- *
- * @param $code
- * @param $_ext
- * @param Game $game_rq
- *
- * @return array
- */
- public function reversal($code, $_ext, Game $game_rq) {
- $_wx_code = $code;
- $_url_param = parse_url(urldecode($_ext));
- parse_str($_url_param['query'], $_query_arr);
- if (empty($_query_arr['huo_state'])) {
- $_code = CommonStatus::INVALID_PARAMS;
- return $this->huoError(CommonStatus::getMsg($_code), [], $_code);
- }
- $_ag_id = (new AgentState())->getIdByCode($_query_arr['huo_state']);
- $_agent_id = AgentCache::ins()->getAgentIdByAgId($_ag_id);
- //参数校验,成功返回配置
- $_cfg = $this->checkParam($_agent_id, $_query_arr);
- if (false == $_cfg) {
- $_code = CommonStatus::INVALID_PARAMS;
- return $this->huoError(CommonStatus::getMsg($_code), [], $_code);
- }
- $_type = OauthConst::OAUTH_MP;
- $_from = FromConst::FROM_WEIXIN;
- $_oauth_data = (new Oauth())->getOauthDataByCode($_type, $_wx_code, $_from, $game_rq->getHAppId());
- $_queue_data = $_query_arr; //队列数据
- $_queue_data['event'] = $_cfg['agent_code'];
- $_queue_data['mp_id'] = $game_rq->getMpId();
- $_queue_data['agent_id'] = $_agent_id;
- if (is_numeric($_oauth_data)) {
- /* 有注册玩家 */
- $_mem_id = $_oauth_data;
- $_queue_data['mem_id'] = $_mem_id;
- $_mo_data = (new MemoauthModel())->getInfoByMpMemId($game_rq->getMpId(), $_mem_id);
- $_queue_data['openid'] = empty($_mo_data['openid']) ? '' : $_mo_data['openid'];
- $_queue_data['status'] = MemConst::MEMBER_OLD;
- } else {
- $_queue_data['openid'] = $_oauth_data['openid'];
- $_queue_data['status'] = MemConst::MEMBER_NEW;
- }
- $_rs = (new CpaReversalQueue($_queue_data))->pushQueue();
- return $_rs;
- }
- /**
- * 参数校验
- *
- * @param $agent_id
- * @param array $param
- *
- * @return bool|array
- */
- public function checkParam($agent_id, $param = []) {
- $_cfg = $this->getAgentCfg($agent_id);
- if (empty($_cfg['url_param'])) {
- return false;
- }
- foreach ($_cfg['url_param'] as $_key) {
- if (empty($param[$_key])) {
- return false;
- }
- }
- return $_cfg;
- }
- /**
- * 获取渠道参数
- *
- * @param $agent_id
- *
- * @return array|bool
- */
- public function getAgentCfg($agent_id) {
- if (empty($agent_id)) {
- return false;
- }
- $_cfg = (new AgentAdsCfgModel())->getInfoByAgentId($agent_id);
- if (empty($_cfg)) {
- return false;
- }
- if (!empty($_cfg['url_param'])) {
- $_cfg['url_param'] = explode(',', $_cfg['url_param']);
- }
- return $_cfg;
- }
- }
|