123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468 |
- <?php
- /**
- * GameMiniCateListLogic.php UTF-8
- * 游戏分类列表
- *
- * @date : 2018/9/13 11:37
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HuoMp 1.0
- */
- namespace huomp\logic\game;
- use huo\controller\common\CommonFunc;
- use huo\controller\integral\IaCache;
- use huo\model\game\GamecategoryModel;
- use huo\model\member\MemGameModel;
- use huolib\constant\CacheConst;
- use huolib\constant\CategoryConst;
- use huolib\constant\CommonConst;
- use huolib\constant\GameConst;
- use huolib\constant\IaConst;
- use huolib\constant\OptionConst;
- use huolib\tool\StrUtils;
- use huolib\tool\Time;
- use huomp\logic\share\ShareLogic;
- use huomp\model\common\CommonModel;
- use think\Cache;
- class GameMiniCateListLogic 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['cate_id'])) {
- $_map['gamecategory_model.cate_id'] = $param['cate_id'];
- }
- if (!empty($param['promote_switch'])) {
- $_map['joingame.promote_switch'] = $param['promote_switch'];
- }
- 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;
- case GameConst::RANK_TYPE_LIST_ORDER:
- $_order = '-gamecategory_model.list_order';
- break;
- case GameConst::RANK_TYPE_FIND_TIME:
- $_order = '-gamecategory_model.find_time,-gamecategory_model.list_order';
- break;
- default:
- $_order = '-gameext.down_cnt';
- }
- return $_order;
- }
- /**
- * 获取记录
- *
- * @param array $param
- * @param string $page
- * @param int $order_type
- *
- * @return array
- */
- public function getCateGameList(
- $param = [], $page = '1,10', $order_type = GameConst::RANK_TYPE_LIST_ORDER
- ) {
- $_map = $this->getWhere($param);
- $_map['gamecategory_model.find_time'] = ['egt', 0];
- $_order = $this->getOrder($order_type);
- $_field = [];
- $_game_data = $this->getList($_field, $_map, $page, $_order);
- $_game_list = [];
- $_item_cnt = get_val($param, 'item_cnt', 0);
- $_mem_agent_integral = 0;
- $_mem_agent_reward = 0;
- $_ia_data = IaCache::ins()->getIa(IaConst::IA_PLAY_3);
- if (!empty($_ia_data['integral'])) {
- $_gold_rmb_rate = CommonFunc::getGoldRmbRate();
- $_mem_agent_integral = $_ia_data['integral'];
- $_mem_agent_reward = StrUtils::formatNumber($_mem_agent_integral / $_gold_rmb_rate);
- }
- $_mem_game_model = new MemGameModel();
- $_gc_model = new GamecategoryModel();
- list($today_start, $today_end) = Time::today();
- foreach ($_game_data['list'] as $_k => $_v) {
- $_v_add = $_v;
- if (2 == $_item_cnt) {
- $_v_add['icon'] = empty($_v['fine_image']) ? $_v_add['icon'] : $_v['fine_image'];
- }
- $_has_open = true;
- $_mem_id = get_val($param, 'mem_id', 0);
- /* 判定是否获取过收益 */
- // $_integral = (new Income())->getOpenGain($_mem_id, $_v['game_id']);
- // if (is_numeric($_integral)) {
- // $_has_open = true;
- // }
- //判断是否为试玩列表游戏
- $_rs = $_gc_model->isGameExist(CategoryConst::CATE_CATE_RP, $_v['game_id']);
- if ($_rs) {
- $_rs = $_mem_game_model->hasOpen($_mem_id, $_v['game_id'], $today_start);
- if (!$_rs) {
- $_has_open = false;
- }
- $_v_add['mem_agent_integral'] = $_mem_agent_integral;
- $_v_add['mem_agent_reward'] = $_mem_agent_reward;
- }
- $_v_add['is_add'] = $_has_open ? CommonConst::CONST_TRUE : CommonConst::CONST_FALSE;
- $_game_list[] = $_v_add;
- }
- return [
- 'count' => $_game_data['count'],
- 'list' => $_game_list,
- ];
- }
- /**
- * 获取记录
- *
- * @param array $param
- * @param string $page
- * @param int $order_type
- *
- * @return array
- */
- public function getFindGameList(
- $param = [], $page = '1,10', $order_type = GameConst::RANK_TYPE_FIND_TIME
- ) {
- $_map = $this->getWhere($param);
- $_order = $this->getOrder($order_type);
- $_field = [];
- $_date = date('Y-m-d');
- $_game_data = $this->getList($_field, $_map, $page, $_order);
- $_game_list = [];
- $_game_cnt = 0;
- $_cnt = 0;
- $_list = [];
- $_mem_logic = new MemGameLogic();
- $_gc_model = new GamecategoryModel();
- $_mem_game_model = new MemGameModel();
- list($today_start, $today_end) = Time::today();
- foreach ($_game_data['list'] as $_k => $_v) {
- $_in_date = date('Y-m-d', $_v['find_time']);
- if ($_date != $_in_date) {
- if (!empty($_game_list)) {
- $_list[] = [
- 'date' => $_date,
- 'game_cnt' => $_game_cnt,
- 'gamelist' => $_game_list,
- ];
- $_cnt++;
- }
- $_game_cnt = 0;
- $_game_list = [];
- $_date = $_in_date;
- }
- $_v_add = $_v;
- // /* 判定是否获取过收益 */
- // $_integral = (new Income())->getOpenGain($param['mem_id'], $_v['game_id']);
- // $_has_open = false;
- // if (is_numeric($_integral)) {
- // $_has_open = true;
- // }
- $_has_open = true;
- $_mem_id = $param['mem_id'];
- //判断是否为试玩列表游戏
- $_rs = $_gc_model->isGameExist(CategoryConst::CATE_CATE_RP, $_v['game_id']);
- if ($_rs) {
- $_rs = $_mem_game_model->hasOpen($_mem_id, $_v['game_id'], $today_start);
- if (!$_rs) {
- $_has_open = false;
- }
- }
- $_v_add['is_add'] = $_has_open ? CommonConst::CONST_TRUE : CommonConst::CONST_FALSE;
- $_v_add['player'] = $_mem_logic->getPlayer($_mem_id, $_v['game_id']);
- $_game_list[] = $_v_add;
- $_game_cnt++;
- }
- $_rdata = [
- 'count' => $_cnt,
- 'list' => $_list,
- ];
- return $_rdata;
- }
- /**
- * 获取记录
- *
- * @param int $_mem_id
- * @param array $param
- * @param string $page
- * @param int $order_type
- *
- * @return array
- */
- public function getRpGameList($_mem_id, $param = [], $page = '1,10', $order_type = GameConst::RANK_TYPE_LIST_ORDER
- ) {
- $_map = $this->getWhere($param);
- $_order = $this->getOrder($order_type);
- $_field = [];
- $_game_data = $this->getList($_field, $_map, $page, $_order);
- if (empty($_game_data['count'])) {
- return $_game_data;
- }
- $_list = [];
- $_share_logic = new ShareLogic();
- $_ia_cache = IaCache::ins();
- foreach ($_game_data['list'] as $_k => $_v) {
- /* 获取试玩状态 */
- $_status = $this->getRpStatus($_mem_id, $_v['game_id']);
- $_mem_agent_integral = 0;
- $_mem_agent_reward = 0;
- $_ia_data = $_ia_cache->getIa(IaConst::IA_PLAY_3);
- if (!empty($_ia_data['integral'])) {
- $_gold_rmb_rate = CommonFunc::getGoldRmbRate();
- $_mem_agent_integral = $_ia_data['integral'];
- $_mem_agent_reward = StrUtils::formatNumber($_mem_agent_integral / $_gold_rmb_rate);
- }
- $_share_setting = $_share_logic->getShareSetting($_v['game_id']);
- $_list[] = [
- 'game_id' => $_v['game_id'],
- 'mini_app_id' => $_v['mini_app_id'],
- 'gamename' => $_v['gamename'],
- 'icon' => $_v['icon'],
- 'oneword' => $_v['oneword'],
- 'down_cnt' => $_v['down_cnt'],
- 'mem_agent_reward' => $_mem_agent_reward,
- 'mem_agent_integral' => $_mem_agent_integral,
- 'rp_image' => $_v['rp_image'],
- 'status' => $_status,
- 'need_popup' => $_v['need_popup'],
- 'entrance_image' => $_v['entrance_image'],
- 'player' => (new MemGameLogic())->getPlayer($_mem_id, $_v['game_id']),
- 'share_title' => $_share_setting[OptionConst::SETTING_SHARE_TITLE],
- 'share_img' => cmf_get_image_preview_url(
- $_share_setting[OptionConst::SETTING_SHARE_IMG_GAME]
- ),
- ];
- }
- $_rdata = [
- 'count' => $_game_data['count'],
- 'list' => $_list,
- ];
- return $_rdata;
- }
- /**
- * 获取记录
- *
- * @param int $_mem_id
- * @param array $param
- * @param string $page
- * @param int $order_type
- *
- * @return array
- */
- public function getPlayGameList($_mem_id, $param = [], $page = '1,10', $order_type = GameConst::RANK_TYPE_LIST_ORDER
- ) {
- $_map = $this->getWhere($param);
- $_order = $this->getOrder($order_type);
- $_field = [];
- $_game_data = $this->getList($_field, $_map, $page, $_order);
- if (empty($_game_data['count'])) {
- return $_game_data;
- }
- $_list = [];
- $_share_logic = new ShareLogic();
- $_gc_model = new GamecategoryModel();
- $_ia_cache = IaCache::ins();
- $_mg_logic = new MemGameLogic();
- foreach ($_game_data['list'] as $_k => $_v) {
- /* 获取试玩状态 */
- $_status = $this->getRpStatus($_mem_id, $_v['game_id']);
- $_mem_agent_integral = 0;
- $_mem_agent_reward = 0;
- $_rs = $_gc_model->isGameExist(CategoryConst::CATE_CATE_RP, $_v['game_id']);
- if ($_rs) {
- $_ia_data = $_ia_cache->getIa(IaConst::IA_PLAY_3);
- if (!empty($_ia_data['integral'])) {
- $_gold_rmb_rate = CommonFunc::getGoldRmbRate();
- $_mem_agent_integral = $_ia_data['integral'];
- $_mem_agent_reward = StrUtils::formatNumber($_mem_agent_integral / $_gold_rmb_rate);
- }
- }
- $_share_setting = $_share_logic->getShareSetting($_v['game_id']);
- $_list[] = [
- 'game_id' => $_v['game_id'],
- 'mini_app_id' => $_v['mini_app_id'],
- 'gamename' => $_v['gamename'],
- 'icon' => $_v['icon'],
- 'oneword' => $_v['oneword'],
- 'down_cnt' => $_v['down_cnt'],
- 'mem_agent_reward' => $_mem_agent_reward,
- 'mem_agent_integral' => $_mem_agent_integral,
- 'rp_image' => $_v['rp_image'],
- 'status' => $_status,
- 'need_popup' => $_v['need_popup'],
- 'entrance_image' => $_v['entrance_image'],
- 'single_tag' => $_v['single_tag'],
- 'player' => $_mg_logic->getPlayer($_mem_id, $_v['game_id']),
- 'share_title' => $_share_setting[OptionConst::SETTING_SHARE_TITLE],
- 'share_img' => cmf_get_image_preview_url(
- $_share_setting[OptionConst::SETTING_SHARE_IMG_GAME]
- ),
- ];
- }
- $_rdata = [
- 'count' => $_game_data['count'],
- 'list' => $_list,
- ];
- return $_rdata;
- }
- /**
- * 获取列表
- *
- * @param array $field
- * @param array $where
- * @param string $page
- * @param string $order
- *
- */
- public function getList($field = [], $where, $page = '1,10', $order = '-create_time') {
- $_cache_key = CacheConst::CACHE_GAME_LIST_PREFIX.md5(json_encode(array($field, $where, $page, $order)));
- $_cache_tag = CacheConst::TAG_GAME_LIST;
- $_rdata = json_decode(Cache::tag($_cache_tag)->get($_cache_key), true);
- if (!empty($_rdata)) {
- return $_rdata;
- }
- $_map = $where;
- $_model = new GamecategoryModel();
- $_count = $_model->with('joingame,gameext,gamerate')->with('gamemini')->where($_map)->count();
- if (empty($_count)) {
- $_rdata = [
- 'count' => 0,
- 'list' => []
- ];
- Cache::tag($_cache_tag, $_cache_key)->set($_cache_key, json_encode($_rdata));
- return $_rdata;
- }
- $_field = $field;
- if (empty($field)) {
- $_field = [];
- }
- $_order = $_model->orderFilter($order);
- $_datas = $_model
- ->with('joingame,gameext,gamerate')
- ->with('gamemini,gv')
- ->where($_map)
- ->field($_field)
- ->order($_order)
- ->page($page)
- ->select();
- if (is_object($_datas)) {
- $_datas = $_datas->toArray();
- }
- if (empty($_datas)) {
- $_rdata = [
- 'count' => 0,
- 'list' => []
- ];
- Cache::tag($_cache_tag, $_cache_key)->set($_cache_key, json_encode($_rdata));
- return $_rdata;
- }
- $_data = [];
- $_gold_rmb_rate = CommonFunc::getGoldRmbRate();
- foreach ($_datas as $_k => $_v) {
- $_mem_reward = !empty($_v['gamerate']) ? $_v['gamerate']['mem_reward'] : 0;
- $_need_popup = empty($_v['gamemini']['need_popup']) ? GameConst::RATE_MP_NEED_POPUP_NOT
- : $_v['gamemini']['need_popup'];
- $_entrance_image = '';
- if (GameConst::RATE_MP_NEED_POPUP == $_need_popup) {
- $_entrance_image = empty($_v['gamemini']['entrance_image']) ? '' : $_v['gamemini']['entrance_image'];
- }
- $_single_tag = !empty($_v['joingame']['ext_info']) ? explode('|', $_v['joingame']['single_tag']) : [];
- $_is_add = false;
- $_data[] = [
- 'game_id' => $_v['app_id'],
- 'single_tag' => $_single_tag,
- 'find_time' => $_v['find_time'],
- 'fine_image' => !empty($_v['joingame']['ext_info'])
- && !empty($_v['joingame']['ext_info']['fine_image']) ? cmf_get_image_url(
- $_v['joingame']['ext_info']['fine_image']
- ) : '',
- 'find_image' => !empty($_v['joingame']['ext_info'])
- && !empty($_v['joingame']['ext_info']['find_image']) ? cmf_get_image_url(
- $_v['joingame']['ext_info']['find_image']
- ) : '',
- 'rp_image' => !empty($_v['joingame']['ext_info'])
- && !empty($_v['joingame']['ext_info']['rp_image']) ? cmf_get_image_url(
- $_v['joingame']['ext_info']['rp_image']
- ) : '',
- 'mini_app_id' => $_v['gamemini']['mini_app_id'],
- 'gamename' => !empty($_v['joingame']['name']) ? $_v['joingame']['name'] : '',
- 'icon' => !empty($_v['joingame']['icon']) ? cmf_get_image_url($_v['joingame']['icon'])
- : '',
- 'oneword' => !empty($_v['joingame']['publicity']) ? $_v['joingame']['publicity'] : '',
- 'down_cnt' => !empty($_v['gameext']['down_cnt']) ? $_v['gameext']['down_cnt'] : 0,
- 'mem_agent_reward' => $_mem_reward,
- 'mem_agent_integral' => intval($_mem_reward * $_gold_rmb_rate),
- 'is_add' => $_is_add ? CommonConst::CONST_TRUE : CommonConst::CONST_FALSE,
- 'url' => empty($_v['gv']) ? '' : $_v['gv'][0]['package_url'],
- 'need_popup' => $_need_popup,
- 'entrance_image' => cmf_get_image_preview_url($_entrance_image),
- ];
- }
- $_rdata = [
- 'count' => $_count,
- 'list' => $_data
- ];
- Cache::tag($_cache_tag, $_cache_key)->set($_cache_key, json_encode($_rdata));
- return $_rdata;
- }
- /**
- * 获取游戏试玩状态
- *
- * @param $mem_id
- * @param $app_id
- *
- * @return int 1 未完成 2 已完成
- */
- public function getRpStatus($mem_id, $app_id) {
- if (empty($mem_id) || empty($app_id)) {
- return IaConst::IA_STATUS_SUC;
- }
- list($today_start, $today_end) = Time::today();
- $_rs = (new MemGameModel())->hasOpen($mem_id, $app_id, $today_start);
- if (false == $_rs) {
- return IaConst::IA_STATUS_NOT;
- }
- return IaConst::IA_STATUS_SUC;
- }
- }
|