123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368 |
- <?php
- /**
- * AgentGame.php UTF-8
- * 渠道游戏
- *
- * @date : 2018/4/26 14:52
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @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;
- }
- }
|