* @version : HUOSDK 8.0 */ namespace huo\controller\agent; use huo\controller\common\Base; use huo\controller\game\GameCache; use huo\controller\game\Gamepack; use huo\controller\rate\Rate; use huo\controller\rate\RateCache; use huo\controller\rate\RateCheck; use huo\model\agent\AgentGameModel; use huo\model\rate\AgentGameRateModel; use huolib\constant\AgentConst; use huolib\constant\CommonConst; use huolib\constant\GameConst; use huolib\status\AgentStatus; use huolib\status\GameStatus; use huolib\status\RateStatus; use think\Log; class AgentGame extends Base { /** * 添加渠道游戏 * * @param $agent_id * @param mixed $app_ids * * @return array|bool */ public function addAgentGames($agent_id, $app_ids) { if (empty($app_ids)) { $_code = GameStatus::GAME_ID_EMPTY; return $this->huoError($_code, GameStatus::getMsg($_code)); } $_app_ids = $app_ids; if (is_numeric($app_ids)) { $_app_ids = [$app_ids]; } $_rs = false; foreach ($_app_ids as $_app_id) { $_rs = $this->addGame($agent_id, $_app_id); } if (false == $_rs) { $_code = AgentStatus::ADD_GAME_ERROR; return $this->huoError($_code, AgentStatus::getMsg($_code)); } $_code = AgentStatus::NO_ERROR; return $this->huoError($_code, AgentStatus::getMsg($_code)); } /** * 添加渠道游戏 * * @param $agent_id * @param $app_id * * @param bool $set_qr_code * * @return bool */ public function addGame($agent_id, $app_id, $set_qr_code = true) { $_game_info = GameCache::ins()->getInfoByAppId($app_id); if (empty($_game_info)) { return false; } $_ag_model = new AgentGameModel(); $_ag_info = $_ag_model->getInfoByAgentIdAppId($agent_id, $app_id); if (!empty($_ag_info)) { if ($_ag_info['is_delete'] == CommonConst::CONST_DELETED) { //已被删除,则设置为正常 $_ag_info['is_delete'] = CommonConst::CONST_NOT_DELETE; $_ag_info['delete_time'] = 0; $_ag_model->updateData($_ag_info, $_ag_info['id']); } //已经添加过该游戏,直接返回 return true; } $_ag_data['agent_id'] = $agent_id; $_ag_data['app_id'] = $app_id; $_ag_data['agent_game'] = $_game_info['en_abbr']."_".$agent_id; $_ag_data['status'] = GameConst::AG_STATUES_SUC; if ($_game_info['classify'] == GameConst::GAME_MP) { $_ag_data['status'] = GameConst::AG_STATUES_SUC; } // if (GameConst::GAME_PROMOTE_SWITCH_CHECK == $_game_info['promote_switch']) { // $_ag_data['status'] = GameConst::AG_STATUES_CHECK; // } $_ag_id = $_ag_model->addData($_ag_data); if (empty($_ag_id)) { return false; } if ($set_qr_code == true) { /* 小程序或者小游戏 直接生成推广二维码 */ (new \huomp\controller\agent\AgentGame())->setQrUrl($_ag_id); } return $this->addAgentGameRate($_ag_id, $app_id, $agent_id); } /** * 添加渠道游戏优惠信息 * * @param $ag_id * @param $app_id * @param $agent_id * * @return bool */ public function addAgentGameRate($ag_id, $app_id, $agent_id) { /* 添加渠道游戏折扣 */ $_agr_data['ag_id'] = $ag_id; $_agr_data['agent_id'] = $agent_id; $_agr_data['app_id'] = $app_id; $_agent_class = new Agent(); $_role_type = $_agent_class->getRoleType($agent_id); $_parent_id = $_agent_class->getParentId($agent_id); $_rc_class = RateCache::ins(); if (AgentConst::ROLE_TYPE_GROUP == $_role_type) { $_rate_data = $_rc_class->getInfoByAppId($app_id); $_agr_data['agent_rebate'] = $_rate_data['agent_rebate']; $_agr_data['sub_agent_rebate'] = $_rate_data['sub_agent_rebate']; $_agr_data['agent_rate'] = $_rate_data['agent_rate']; $_agr_data['sub_agent_rate'] = $_rate_data['sub_agent_rate']; $_agr_data['agent_reward'] = $_rate_data['agent_reward']; $_agr_data['sub_agent_reward'] = $_rate_data['sub_agent_reward']; } elseif (AgentConst::ROLE_TYPE_AGENT == $_role_type) { $_rate_data = $_rc_class->getInfoByAppIdAgentId($app_id, $_parent_id); if (empty($_rate_data)) { $_rate_data = $_rc_class->getInfoByAppId($app_id); } $_agr_data['agent_rebate'] = $_rate_data['sub_agent_rebate']; $_agr_data['sub_agent_rebate'] = 0; $_agr_data['agent_rate'] = $_rate_data['sub_agent_rate']; $_agr_data['sub_agent_rate'] = 1; $_agr_data['agent_reward'] = $_rate_data['sub_agent_reward']; $_agr_data['sub_agent_reward'] = 0; } else { if (AgentConst::ROLE_TYPE_MEMBER == $_role_type) { $_agent_info = (new AgentCache())->getInfoByAgentId($agent_id); if (AgentConst::AGENT_ROLE_MP_MEMBER == $_agent_info['role_id']) { //小游戏玩家渠道 $_rate_data = $_rc_class->getInfoByAppIdAgentId($app_id, $_parent_id); if (empty($_rate_data)) { $_rate_data = $_rc_class->getInfoByAppId($app_id); } $_agr_data['agent_rebate'] = $_rate_data['agent_rebate']; $_agr_data['sub_agent_rebate'] = $_rate_data['sub_agent_rebate']; $_agr_data['agent_rate'] = $_rate_data['agent_rate']; $_agr_data['sub_agent_rate'] = $_rate_data['sub_agent_rate']; $_agr_data['mem_agent_reward'] = $_rate_data['mem_agent_reward']; $_agr_data['mem_reward'] = $_rate_data['mem_reward']; } else { return false; } } else { return false; } } $_agr_data['benefit_type'] = $_rate_data['benefit_type']; $_agr_data['agent_benefit_type'] = $_rate_data['agent_benefit_type']; $_agr_data['mem_rate'] = $_rate_data['mem_rate']; $_agr_data['first_mem_rate'] = $_rate_data['first_mem_rate']; $_agr_data['mem_rebate'] = $_rate_data['mem_rebate']; $_agr_data['mem_rebate'] = $_rate_data['mem_rebate']; $_agr_data['first_mem_rebate'] = $_rate_data['first_mem_rebate']; $_rs = (new AgentGameRateModel())->addData($_agr_data); if (empty($_rs)) { return false; } return true; } /** * 编辑渠道优惠 * * @param $ag_id * @param $sub_agent_rate * @param $sub_agent_rebate * @param $mem_first * @param $mem_refill * * @return array */ public function editAgRate($ag_id, $sub_agent_rate, $sub_agent_rebate, $mem_first, $mem_refill) { if (empty($ag_id)) { $_code = RateStatus::INVALID_PARAMS; return $this->huoError($_code, RateStatus::getMsg($_code)); } $_agr_data['sub_agent_rate'] = $sub_agent_rate; $_agr_data['sub_agent_rebate'] = $sub_agent_rebate; $_ac_class = AgentCache::ins(); $_app_id = $_ac_class->getAppIdByAgId($ag_id); $_rate_class = new Rate($_app_id); $_benefit_type = $_rate_class->getBenefitType(); if (GameConst::RATE_BENEFIT_RATE == $_benefit_type) { $_agr_data['first_mem_rebate'] = 0; $_agr_data['mem_rebate'] = 0; $_agr_data['first_mem_rate'] = $mem_first; $_agr_data['mem_rate'] = $mem_refill; } elseif (GameConst::RATE_BENEFIT_REBATE == $_benefit_type) { $_agr_data['first_mem_rebate'] = $mem_first; $_agr_data['mem_rebate'] = $mem_refill; $_agr_data['first_mem_rate'] = 1; $_agr_data['mem_rate'] = 1; } return $this->setGameRate($ag_id, $_agr_data); } /** * 编辑下级渠道折扣 * * @param $ag_id * @param $agent_rate * @param $agent_rebate * @param $mem_first * @param $mem_refill * * @return array */ public function editSubAgRate($ag_id, $agent_rate, $agent_rebate, $mem_first, $mem_refill) { if (empty($ag_id)) { $_code = RateStatus::INVALID_PARAMS; return $this->huoError($_code, RateStatus::getMsg($_code)); } $_agr_data['agent_rate'] = $agent_rate; $_agr_data['agent_rebate'] = $agent_rebate; $_ac_class = AgentCache::ins(); $_app_id = $_ac_class->getAppIdByAgId($ag_id); $_rate_class = new Rate($_app_id); $_benefit_type = $_rate_class->getBenefitType(); if (GameConst::RATE_BENEFIT_RATE == $_benefit_type) { $_agr_data['first_mem_rebate'] = 0; $_agr_data['mem_rebate'] = 0; $_agr_data['first_mem_rate'] = $mem_first; $_agr_data['mem_rate'] = $mem_refill; } elseif (GameConst::RATE_BENEFIT_REBATE == $_benefit_type) { $_agr_data['first_mem_rebate'] = $mem_first; $_agr_data['mem_rebate'] = $mem_refill; $_agr_data['first_mem_rate'] = 1; $_agr_data['mem_rate'] = 1; } return $this->setGameRate($ag_id, $_agr_data); } /** * 设置游戏渠道优惠 * * @param $ag_id * @param $rate_data * * @return array */ public function setGameRate($ag_id, $rate_data) { if (empty($ag_id)) { $_code = RateStatus::INVALID_PARAMS; return $this->huoError($_code, RateStatus::getMsg($_code)); } $_ac_class = AgentCache::ins(); $_agent_id = $_ac_class->getAgentIdByAgId($ag_id); $_app_id = $_ac_class->getAppIdByAgId($ag_id); $_role_type = (new Agent())->getRoleType($_agent_id); $_rchk_class = new RateCheck(); if (AgentConst::ROLE_TYPE_AGENT == $_role_type) { $_rchk_rs = $_rchk_class->checkAgentParam($_app_id, $_agent_id, $rate_data); } else { $_rchk_rs = $_rchk_class->checkGroupParam($_app_id, $_agent_id, $rate_data); } if (RateStatus::NO_ERROR != $_rchk_rs['code']) { return $this->huoReturn($_rchk_rs); } $_rc_class = RateCache::ins(); $_agr_data = $_rc_class->getInfoByAppIdAgentId($_app_id, $_agent_id); $_agr_data = array_merge($_agr_data, $rate_data); $_rs = $_rc_class->updateAgRate($_app_id, $_agent_id, $_agr_data); if (false == $_rs) { $_code = RateStatus::CACHE_ERROR; return $this->huoError($_code, RateStatus::getMsg($_code)); } $_code = RateStatus::NO_ERROR; return $this->huoSuccess($_code, RateStatus::getMsg($_code)); } /** * 渠道游戏分包 * * @param $agent_id * @param $ag_id * * @return array */ public function pack($agent_id, $ag_id) { $_ag_cache = AgentCache::ins(); $_ag_data = $_ag_cache->getAgInfoByAgId($agent_id); $_check_status = $_ag_data['status']; if (GameConst::AG_STATUES_CHECK == $_check_status) { $_code = GameStatus::GAME_PENDING_REVIEW; return $this->huoSuccess($_code, RateStatus::getMsg($_code)); } $ag_info = $_ag_cache->getAgInfoByAgId($ag_id); if (empty($ag_info)) { $_code = GameStatus::GAME_NOT_EXISTS; return $this->huoSuccess($_code, RateStatus::getMsg($_code)); } $game_info = (new GameCache())->getInfoByAppId($ag_info['app_id']); $_game_package = new Gamepack($ag_info['app_id']); $_game_package->setAgentId($agent_id); $_game_package->setPinyin($game_info['en_abbr']); $_game_package->setAgentgame($ag_info['agent_game']); $_game_package->setImageUrl($game_info['icon']); $result = $_game_package->pack(); if (GameConst::GAME_PACK_SUCCESS == $result['code']) { $_ag_data = []; $_ag_data['status'] = GameConst::AG_STATUES_SUC; $_ag_data['package_url'] = $result['data']['url']; (new AgentCache())->updateAg($ag_id, $_ag_data); $result['code'] = GameStatus::NO_ERROR; } else { Log::write($result, Log::ERROR); $result['code'] = GameStatus::GAME_PACK_ERROR; } return $result; } public function getDownUrl($app_id, $agent_id) { } /** * 获取渠道的所有游戏id * * @param $agent_id * * @return array */ public function getGameIds($agent_id) { $_map = $agent_id; if (!is_array($agent_id)) { $_map = ['agent_id' => $agent_id]; } $_ids = (new AgentGameModel())->where($_map)->column('app_id'); return $_ids; } }