| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 | <?php/** * GameMiniListLogic.php UTF-8 * 小程序游戏列表逻辑 * * @date    : 2018/8/15 17:27 * * @license 这不是一个自由软件,未经授权不许任何使用和传播。 * @author  : luowei <lw@huosdk.com> * @version : HuoMP 1.0 */namespace huomp\logic\game;use huo\controller\common\CommonFunc;use huo\controller\game\GameCache;use huo\model\agent\AgentGameModel;use huo\model\game\GamecategoryModel;use huo\model\member\MemGameModel;use huo\model\slide\SlideItemModel;use huo\model\slide\SlideModel;use huo\model\user\UserModel;use huolib\constant\CategoryConst;use huolib\constant\CommonConst;use huolib\constant\DeviceTypeConst;use huolib\constant\GameConst;use huolib\tool\Time;use huomp\model\common\CommonModel;use huomp\model\game\GameMiniModel;class GameMiniListLogic extends CommonModel {    /**     * @param array $param     *     * @return array     */    protected function getWhere($param = []) {        $_map = [];        if (!empty($param['status'])) {            $_map['joingame.status'] = $param['status'];        }        if (!empty($param['classify'])) {            $_map['joingame.classify'] = $param['classify'];        }        if (!empty($param['promote_switch'])) {            $_map['joingame.promote_switch'] = $param['promote_switch'];        }        $_map['joingame.is_delete'] = CommonConst::CONST_NOT_DELETE;        return $_map;    }    protected function getOrder($order_type) {        switch ($order_type) {            case GameConst::RANK_TYPE_DOWN:                $_order = '-gameext.down_cnt';                break;            case GameConst::RANK_TYPE_HOT_SALE:                $_order = '-gameext.pay_user_cnt';                break;            case GameConst::RANK_TYPE_RECOMMEND:                $_order = '-gameext.pay_user_cnt';                break;            case GameConst::RANK_TYPE_COMMISSION:                $_order = '-gamerate.mem_agent_reward';                break;            default:                $_order = '-gameext.down_cnt';        }        return $_order;    }    /**     * 获取记录     *     * @param        $agent_id     * @param array  $param     * @param string $page     * @param int    $order_type     *     * @return array     */    public function getGameMiniList($agent_id, $param = [], $page = '1,10', $order_type = GameConst::RANK_TYPE_RECOMMEND    ) {        $_map = $this->getWhere($param);        $_order = $this->getOrder($order_type);        $_field = [];        return $this->getList($agent_id, $_field, $_map, $page, $_order);    }    /**     * 获取列表     *     * @param int    $agent_id     * @param array  $field     * @param array  $where     * @param string $page     * @param string $order     *     */    public function getList($agent_id = 0, $field = [], $where, $page = '1,10', $order = '-create_time') {        /* 获取玩家id */        $_mem_id = (new UserModel())->getMemIdById($agent_id);        $_map = $where;        $_model = new GameMiniModel();        $_count = $_model->with('joingame,gameext,gamerate')->where($_map)->count();        if (empty($_count)) {            return [                'count' => 0,                'list'  => []            ];        }        $_field = $field;        if (empty($field)) {            $_field = [];        }        $_order = $_model->orderFilter($order);        $_datas = $_model            ->with('joingame,gameext,gamerate,gv')            ->where($_map)            ->field($_field)            ->order($_order)            ->page($page)            ->select();        if (is_object($_datas)) {            $_datas = $_datas->toArray();        }        if (empty($_datas)) {            return [                'count' => $_count,                'list'  => []            ];        }        $_data = [];        $_app_cache = new GameCache();        $_agent_game_model = new AgentGameModel();        $_gold_rmb_rate = CommonFunc::getGoldRmbRate();        foreach ($_datas as $_k => $_game_mini) {            $_app_info = $_app_cache->getInfoByAppId($_game_mini['app_id']);            $_mem_agent_reward = !empty($_game_mini['gamerate']) ? $_game_mini['gamerate']['mem_agent_reward'] : 0;            $_mem_reward = !empty($_game_mini['gamerate']) ? $_game_mini['gamerate']['mem_reward'] : 0;            $_is_add = false;            if (!empty($agent_id)) {                $_agent_game_info = $_agent_game_model->getInfoByAgentIdAppId($agent_id, $_game_mini['app_id']);            }            if (!empty($_agent_game_info) && $_agent_game_info['is_delete'] == CommonConst::CONST_NOT_DELETE) {                $_is_add = true;            }            /* 判定是否获取过收益 *///            $_integral = (new Income())->getOpenGain($_mem_id, $_game_mini['app_id']);//            $_has_open = false;//            if (is_numeric($_integral)) {//                $_has_open = true;//            }            $_has_open = true;            //判断是否为试玩列表游戏            $_rs = (new GamecategoryModel())->isGameExist(CategoryConst::CATE_CATE_RP, $_game_mini['app_id']);            if ($_rs) {                list($today_start, $today_end) = Time::today();                $_mem_game_model = new MemGameModel();                $_rs = $_mem_game_model->hasOpen($_mem_id, $_game_mini['app_id'], $today_start);                if (!$_rs) {                    $_has_open = false;                }            }            $_share_data = !empty($_app_info['ext_info']['share_img']) ? $_app_info['ext_info']['share_img'] : [];            $_share_title = '';            $_share_img = '';            if (!empty($_share_data)) {                if (false === is_array($_share_data)) {                    $_share_data = (array)$_share_data;                }                $_key = array_rand($_share_data, 1);                if (!empty($_share_data[$_key]['url'])) {                    $_share_title = get_val($_share_data[$_key], 'title', '');                    $_share_img = cmf_get_image_url($_share_data[$_key]['url']);                }            }            $_data[] = [                'game_id'            => $_game_mini['app_id'],                'mini_app_id'        => $_game_mini['mini_app_id'],                'gamename'           => !empty($_app_info) ? $_app_info['name'] : '',                'icon'               => !empty($_app_info) ? cmf_get_image_url($_app_info['icon']) : '',                'oneword'            => !empty($_app_info) ? $_app_info['publicity'] : '',                'down_cnt'           => !empty($_game_mini['gameext']) ? $_game_mini['gameext']['down_cnt'] : 0,                'mem_agent_reward'   => $_mem_agent_reward,                'mem_reward'         => $_mem_reward,                'mem_agent_integral' => intval($_mem_agent_reward * $_gold_rmb_rate),                'mem_integral'       => intval($_mem_reward * $_gold_rmb_rate),                'is_add'             => $_is_add ? CommonConst::CONST_TRUE : CommonConst::CONST_FALSE,                'is_play'            => $_has_open ? CommonConst::CONST_TRUE : CommonConst::CONST_FALSE,                'url'                => !empty($_game_mini['gv']) ? $_game_mini['gv'][0]['package_url'] : '',                'share_title'        => $_share_title,                'share_img'          => $_share_img,                'need_popup'         => $_game_mini['need_popup'],                'entrance_image'     => cmf_get_image_preview_url($_game_mini['entrance_image'])            ];        }        return [            'count' => $_count,            'list'  => $_data        ];    }    /**     * 获取轮播小程序游戏列表     */    public function getSlideList() {        $_codes = (new SlideModel())->getSlideCodesByDevice(DeviceTypeConst::DEVICE_TYPE_MP);        $_cnt = 0;        $_list = [];        $_sl_model = new SlideItemModel();        foreach ($_codes as $_k => $_v) {            $_data = $_sl_model->getAdsByCode($_v);            $_count = count($_data);            $_cnt += $_count;            $_list = array_merge($_list, $_data);        }        return [            'count' => $_cnt,            'list'  => $_list,        ];    }}
 |