| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500 | <?php/** * GameList.php UTF-8 * * * @date    : 2018/5/3 17:55 * * @license 这不是一个自由软件,未经授权不许任何使用和传播。 * @author  : wuyonghong <wyh@huosdk.com> * @version : HUOSDK 8.0 */namespace huo\controller\game;use huo\controller\agent\Agent;use huo\controller\common\Base;use huo\controller\gift\GiftCache;use huo\controller\rate\Rate;use huo\controller\rate\RateCache;use huo\logic\agent\AgentGameLogic;use huo\logic\agent\AgentLogic;use huo\logic\game\GameLogic;use huo\model\agent\AgentGameModel;use huolib\constant\AgentConst;use huolib\constant\GameConst;use huolib\status\GameStatus;use huolib\utils\GameUtils;class GameList extends Base {    /**     * 获取推荐游戏列表     *     * @param string $from     * @param string $page     *     * @return array     */    public function getRcmdList($from = '', $page = '1,10') {        $_param['hot'] = GameConst::GAME_IS_HOT;        $_map['classify'] = $from;        return $this->getList($_param, $page, $_map);    }    /**     * 获取新游列表     *     * @param string $from     * @param string $page     *     * @return array     */    public function getNewList($from = '', $page = '1,10') {        $_param['is_new'] = GameConst::GAME_IS_NEW;        $_map['classify'] = $from;        return $this->getList($_param, $page, $_map);    }    /**     * 获取热门列表     *     * @param string $from     * @param string $page     *     * @return array     */    public function getHotList($from = '', $page = '1,10') {        $_param['hot'] = GameConst::GAME_IS_HOT;        $_map = [];        if (!empty($from)) {            $_map['classify'] = $from;        }        return $this->getList($_param, $page, $_map);    }    /**     * 渠道渠道申请游戏列表     *     * @param int    $agent_id     * @param array  $param     * @param string $page     *     * @return array     */    public function getAgentApplyList($agent_id, $param = [], $page = '1,10') {        $_map = $param;        $_map['agent_id'] = $agent_id;        if (!empty($_map['classify'])) {            $_classify = $_map['classify'];            if (3 == substr($_classify, 0, 1)) {                $_map['classify'] = [                    ['eq', 3],                    ['between', [300, 399]],                    'or'                ];            } elseif (4 == substr($_classify, 0, 1) && 401 != $_classify) {                $_map['classify'] = [                    ['eq', 4],                    ['between', [400, 499]],                    'or'                ];            } else {                $_map['classify'] = $_classify;            }        }        $_data = (new AgentGameLogic())->getAgentGames($_map, $page);        if (false == is_array($_data)) {            return $_data;        }        $_list = $_data['list'];        if (!empty($_list)) {            unset($_data['list']);            $_data['list'] = $this->getGameExtInfo($_list);        }        $_code = GameStatus::NO_ERROR;        return $this->huoSuccess($_code, GameStatus::getMsg($_code), $_data);    }    /**     * 下级渠道列表     *     * @param int    $agent_id     * @param array  $param     * @param string $page     *     * @return array     */    public function getSubAgentList($agent_id, $param = [], $page = '1,10') {        $_agent_arr = (new AgentLogic())->getAgentIds($agent_id, false, [4]);        $_map = $param;        $_map['agent_id'] = ['in', $_agent_arr];        $_data = (new AgentGameLogic())->getAgentGames($_map, $page);        if (false == is_array($_data)) {            return $_data;        }        $_list = $_data['list'];        if (!empty($_list)) {            unset($_data['list']);            $_data['list'] = $this->getSelfGameExtInfo($agent_id, $_list);        }        $_code = GameStatus::NO_ERROR;        return $this->huoSuccess($_code, GameStatus::getMsg($_code), $_data);    }    /**     * @param int   $agent_id     * @param array $data     *     * @return mixed     */    public function getSelfGameExtInfo($agent_id, $data) {        if (empty($data)) {            return $data;        }        $_rate_class = RateCache::ins();        foreach ($data as $_k => $_v) {            $_self_rate = $_rate_class->getInfoByAppIdAgentId($_v['game_id'], $agent_id);            if (empty($_self_rate)) {                $_self_rate = $_rate_class->getInfoByAppId($_v['game_id']);            }            $data[$_k]['sub_agent_rate'] = $_v['agent_rate'];            $data[$_k]['sub_agent_rebate'] = $_v['agent_rebate'];            if (false == $_self_rate) {                $data[$_k]['agent_rate'] = 1;                $data[$_k]['agent_rebate'] = 0;                continue;            }            $data[$_k]['agent_rate'] = $_self_rate['agent_rate'];            $data[$_k]['agent_rebate'] = $_self_rate['agent_rebate'];        }        return $data;    }    /**     * 获取渠道可申请游戏列表     *     * @param        $agent_id     * @param array  $param     * @param string $page     *     * @return array     */    public function getAgentNoApplyList($agent_id, $param = [], $page = '1,10') {        $_game_ids = (new AgentGameModel())->getGameIdsByAgentId($agent_id);        $_map = [];        $_classify = $param['classify'];        if (!empty($_classify)) {            if (3 == substr($_classify, 0, 1)) {                $_map['classify'] = [                    ['eq', 3],                    ['between', [300, 399]],                    'or'                ];            } elseif (4 == substr($_classify, 0, 1) && 401 != $_classify) {                $_map['classify'] = [                    ['eq', 4],                    ['between', [400, 499]],                    'or'                ];            } else {                $_map['classify'] = $_classify;            }        }        $_order = '-list_order';        $_map['promote_switch'] = ['in', [GameConst::GAME_PROMOTE_SWITCH_CAN, GameConst::GAME_PROMOTE_SWITCH_CHECK]];        if (!empty($_game_ids)) {            $_map['id'] = ['not in', $_game_ids];        }        $_data = $this->getGameListDetail($_map, $page, $_order);        if (is_numeric($_data)) {            $_code = $_data;            return $this->huoError($_code, GameStatus::getMsg($_code));        }        $_code = GameStatus::NO_ERROR;        if (empty($_data['list'])) {            return $this->huoSuccess($_code, GameStatus::getMsg($_code), $_data);        }        $_list = $_data['list'];        unset($_data['list']);        $_data['list'] = $this->getGameRateExt($agent_id, $_list);        return $this->huoSuccess($_code, GameStatus::getMsg($_code), $_data);    }    /**     * @param int $agent_id     * @param     $data     *     * @return mixed     */    public function getGameRateExt($agent_id, $data) {        if (empty($data)) {            return $data;        }        $_role_type = (new Agent())->getRoleType($agent_id);        $_rate_class = RateCache::ins();        foreach ($data as $_k => $_v) {            $_game_rate = $_rate_class->getInfoByAppId($_v['game_id']);            if (false == $_game_rate) {                $data[$_k]['agent_rate'] = 1;                $data[$_k]['agent_rebate'] = 0;                $data[$_k]['benefit_type'] = 0;                continue;            }            $data[$_k]['agent_rate'] = AgentConst::ROLE_TYPE_GROUP == $_role_type ? $_game_rate['agent_rate']                : $_game_rate['sub_agent_rate'];            $data[$_k]['agent_rebate'] = AgentConst::ROLE_TYPE_GROUP == $_role_type ? $_game_rate['agent_rebate']                : $_game_rate['sub_agent_rebate'];            $data[$_k]['benefit_type'] = $_game_rate['benefit_type'];        }        return $data;    }    /**     * 获取热门列表     *     * @param int    $mem_id 玩家ID     * @param string $from     * @param string $page     *     * @return array     */    public function getPlayedList($mem_id = 0, $from = '', $page = '1,10') {        $_game_logic = new GameLogic();        $_id_arr = $_game_logic->getMemGameIDs($mem_id, $from, $page);        if (is_numeric($_id_arr)) {            $_code = $_id_arr;            return $this->huoError($_code, GameStatus::getMsg($_code));        }        $_count = $_id_arr['count'];        $_list = $_id_arr['list'];        $_param['is_new'] = GameConst::GAME_IS_NEW;        $_map['id'] = ['in', $_list];        $_rdata = $this->getList($_param, $page, $_map);        if (!empty($_rdata['data']) && is_array($_rdata['data'])) {            $_rdata['data']['count'] = $_count;            return $this->huoSuccess($_rdata['code'], $_rdata['msg'], $_rdata['data']);        } else {            return $_rdata;        }    }    /**     * 获取开服游戏列表     *     * @param int    $server_type 开服类型     * @param string $from     * @param string $page     *     * @param int    $app_id      游戏ID     *     * @return array     */    public function getServerList($server_type = 0, $from = '', $page = '1,10', $app_id = 0) {        $_chk_rs = GameUtils::checkServerType($server_type);        if (GameStatus::NO_ERROR != $_chk_rs) {            return $this->huoError($_chk_rs, GameStatus::getMsg($_chk_rs));        }        $_game_logic = new GameLogic();        $_server_arr = $_game_logic->getServerList($server_type, $from, $page, $app_id);        if (is_numeric($_server_arr)) {            $_code = $_server_arr;            return $this->huoError($_code, GameStatus::getMsg($_code));        }        /* 附加游戏信息 *///        $_app_id_arr = [];//        $_count = $_server_arr['count'];//        $_list = $_server_arr['list'];//        foreach ($_list as $_key => $_val) {//            $_app_id_arr[] = $_val['app_id'];//        }//        $_map['id'] = ['in', $_app_id_arr];//        $_rdata = $this->getGameListDetail($_map, $page);//        if (empty($_count)) {//            $_code = GameStatus::SERVER_CNT_ZERO;//            return $this->huoError($_code, GameStatus::getMsg($_code));//        }        $_server_arr['list'] = $this->getGameExtInfo($_server_arr['list']);//        // TODO: liuhongliang 2018/5/9 合并开服信息到游戏详情信息中???//        foreach ($_list as $_key => $_val) {//            $_server_arr['list'][$_key] = array_merge($_val,$_rdata['list'][$_val['app_id']]);//        }        $_code = GameStatus::NO_ERROR;        return $this->huoSuccess($_code, GameStatus::getMsg($_code), $_server_arr);    }    /**     * 获取游戏列表     *     * @param array  $param     * @param string $page     *     * @param array  $where     *     * @return array     */    public function getList($param = [], $page, $where = []) {        $_map = $where;        $_order = '-run_time';        if (isset($param['hot']) && GameConst::GAME_IS_HOT == $param['hot']) {            /* hottest默认排序按照最近一段时间的下载量,加一个指定游戏规则 */            $_order = '+hot_order';        } else if (isset($param['rank']) && GameConst::GAME_IS_RANK == $param['rank']) {            /* Ranking默认规则可以是游戏评价,然后加一个制定规则;所有都是指定游戏的规则优先 */            $_order = '-list_order';        } else if (isset($param['is_new']) && GameConst::GAME_IS_NEW == $param['is_new']) {            /* New games默认排序规则可以按照上架时间,然后加一个规则就是我们指定的游戏优先 */            $_order = '-run_time';        } else if (isset($param['remd']) && GameConst::GAME_IS_NEW == $param['is_new']) {            /* remd games默认排序规则可以按照上架时间,然后加一个规则就是我们指定的游戏优先 */            $_order = '-like_order';        } else if (isset($param['down_sort'])) {            /* 下载排行榜排序 */            $_order = '-ext.down_cnt';        } else if (isset($param['pay_sort'])) {            /* 支付人数排序 */            $_order = '-ext.pay_user_cnt';        } else if (isset($param['is_fine'])) {            /* 精品排序 */            $_order = '-fine_order';        }        if (!empty($param['is_single']) && GameConst::GAME_IS_SINGLE == $param['is_single']) {            $_map['is_single'] = 2;        }        if (!empty($param['type'])) {            $_cates = $param['type'];            $_data = $_data = (new GameLogic())->getCateList($_cates, $page, $_order);//            $this->huoReturn($_data);            $_code = GameStatus::NO_ERROR;            return $this->huoSuccess($_code, GameStatus::getMsg($_code), $_data);        }        if (!empty($param['keywords'])) {            $_map['name|en_name'] = ['like', '%'.$param['keywords'].'%'];        }        if (!empty($param['classify'])) {            $_map['classify'] = $param['classify'];        }        if (!empty($param['is_bt']) && GameConst::GAME_IS_BT == $param['is_bt']) {            $_map['is_bt'] = GameConst::GAME_IS_BT;        } else if (!empty($param['is_rate'])) {            $_map['is_bt'] = GameConst::GAME_NOT_BT;        }        $_data = $this->getGameListDetail($_map, $page, $_order);        if (is_numeric($_data)) {            $_code = $_data;            $_data = [                'count' => 0,                'list'  => []            ];            return $this->huoError($_code, GameStatus::getMsg($_code), $_data);        }        $_code = GameStatus::NO_ERROR;        return $this->huoSuccess($_code, GameStatus::getMsg($_code), $_data);    }    /**     * @param array  $map     * @param string $page     * @param string $_order     *     * @param array  $field     *     * @return mixed     */    public function getGameListDetail($map = [], $page = '', $_order = '', $field = []) {        $_data = (new GameLogic())->getList($map, $page, $_order, $field);        if (false == is_array($_data)) {            return $_data;        }        $_list = $_data['list'];        if (empty($_list)) {            return $_data;        }        unset($_data['list']);        $_data['list'] = $this->getGameExtInfo($_list);        return $_data;    }    /**     * 获取礼包扩展信息     *     * @param array $data     *     * @return array     */    public function getGameExtInfo($data = []) {        if (empty($data)) {            return $data;        }        $_cate_class = CategoryCache::ins();        $_gift_class = GiftCache::ins();        $_rate_class = (new Rate(0));        foreach ($data as $_k => $_v) {            if (empty($_v['type'])) {                $data[$_k]['type'] = null;            } else {                $data[$_k]['type'] = $_cate_class->getNameByIds(GameConst::CATEGORY_TYPE_CATE, $_v['type']);            }            if (empty($_v['tags'])) {                $data[$_k]['tags'] = null;            } else {                $data[$_k]['tags'] = $_cate_class->getNameByIds(GameConst::CATEGORY_TYPE_TAG, $_v['tags']);            }            $data[$_k]['gift_cnt'] = $_gift_class->getGiftCntByGameId($_v['game_id']);            $_rate_class->setGameRate($_v['game_id']);            $data[$_k]['rate'] = $_rate_class->getFirstMemRate();        }        return $data;    }    /**     * 查询拥有礼包的游戏列表     *     * @param array  $map     * @param string $page     *     * @return array     */    public function getHasGiftList($page = '1,10') {        $_map = [            'ext.real_gift_cnt' => ['>', 0],        ];        return (new GameLogic())->getList($_map, $page);    }    /**     * 获取排行游戏列表     *     * @param int $rank_type 1为下载榜,2为畅销榜,3为热搜榜(取推荐)     */    public function getRankList($rank_type = 1, $page) {        if (1 == $rank_type) {            $_param['down_sort'] = true;        } elseif (2 == $rank_type) {            $_param['pay_sort'] = true;        } else {            $_param['remd'] = GameConst::GAME_IS_NEW;            return $this->getList($_param, $page);        }        return $this->getList($_param, $page);    }}
 |