* @version : HUOSDK 8.0 */ namespace web\pc\logic; use huo\model\common\CommonModel; use huo\model\game\GameModel as huoGameModel; use huo\model\game\CategoryModel; use huo\model\game\GiftModel; use huo\model\game\GameclassifyModel; use huo\model\game\GamecategoryModel; use huolib\constant\CommonConst; use huolib\constant\GameConst; class GameLogic extends CommonModel { /** * @param array $where * @param string $page * @param string $order * * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getList($where = [], $page = '10', $order = '') { $map['status'] = GameConst::GAME_STATUS_ON; $map['is_delete'] = CommonConst::CONST_NOT_DELETE; $map['classify'] = ['neq', GameConst::GAME_H5]; if (isset($where['id']) && !empty($where['id'])) { $map['id'] = $where['id']; } if (isset($where['type']) && !empty($where['type'])) { $_ids = $this->strToArr($where['type']); foreach ($_ids as $_k => $_v) { $_ids[$_k] = intval($_v); } $_find_category = CategoryModel::whereIn('id', $_ids)->column('id'); if (empty($_find_category)) { return [ 'count' => 0, 'list' => [] ]; } $_app_ids = GamecategoryModel::whereIn('cate_id', $_find_category)->column('app_id'); $map['id'] = ['in', $_app_ids]; } if (isset($where['classify']) && !empty($where['classify'])) { $map['classify'] = $where['classify']; } if (isset($where['name']) && !empty($where['name'])) { $map['name'] = ['like', "%{$where['name']}%"]; } if (isset($where['fine']) && !empty($where['fine'])) { $map['fine_order'] = ['neq', 0]; } if (isset($where['hot']) && !empty($where['hot'])) { $map['hot_order'] = ['neq', 0]; } $_count = huoGameModel::where($map)->count(); if (empty($_count)) { return [ 'count' => 0, 'list' => [] ]; } $_order = $this->orderFilter($order); // $_games = huoGameModel::with('ext')->with('gv')->where($map)->order($_order)->paginate($page); $_games = huoGameModel::with('ext')->with('gv')->where($map)->order($_order)->page($page) ->select();//->toArray() // $_page = $_games->render(); $_list = []; $_cate_model = new CategoryModel(); foreach ($_games as $_game) { $_data = null; $_data['gameid'] = $_game['id']; $_data['icon'] = $_game['icon']; $_data['gamename'] = $_game['name']; $_data['type'] = $_cate_model->getNameByIds($_game['category']); $_data['size'] = empty($_game['gv'][0]['size']) ? 0 : $_game['gv'][0]['size']; $_data['down_cnt'] = empty($_game['ext']['down_cnt']) ? 0 : $_game['ext']['down_cnt']; $_data['star_cnt'] = empty($_game['ext']['star_cnt']) ? 0 : $_game['ext']['star_cnt']; $_data['hot'] = empty($_game['hot_order']) ? 1 : 2; /* 2热门1普通 */ $_data['down_url'] = isset($_game['gv'][0]['package_url']) ? $_game['gv'][0]['package_url'] : ''; $_data['gift_cnt'] = $this->getGiftCnt($_game['id']); $_data['package_name'] = $_game['package_name']; $_data['classify'] = $_game['classify']; $_data['classify_name'] = $this->getClassifyName($_game['classify']); $_data['publicity'] = $_game['publicity']; $_data['hot_image'] = ''; // $_data['hot_image'] = $this->getImage($_game['hot_image']); // $_data['fine_image'] = $this->getImage($_game['fine_image']); $_list[] = $_data; } $_rdata['count'] = $_count; $_rdata['list'] = $_list; return $_rdata; } /** * 获取分类列表 * @param $_cates * @param $page * @param $_order * * @return array|mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getCateList($_cates, $page, $_order) { if (empty($_cates)) { return [ 'count' => 0, 'list' => [] ]; } // 设置id,ids if (!empty($_cates)) { $_ids = $this->strToArr($_cates); foreach ($_ids as $_k => $_v) { $_ids[$_k] = intval($_v); } } $_find_category = CategoryModel::whereIn('id', $_ids)->column('id'); if (empty($_find_category)) { return [ 'count' => 0, 'list' => [] ]; } $_app_ids = GamecategoryModel::whereIn('cate_id', $_find_category)->column('app_id'); $_map['id'] = ['in', $_app_ids]; $_param['page'] = $page; $_param['order'] = $_order; return $this->getList($_map, $page, $_order); } /** * 根据游戏获取礼包数量 * * @param int $app_id * * @return int|string */ public function getGiftCnt($app_id = 0) { $_map['remain_cnt'] = ['gt', 0]; $_map['end_time'] = ['gt', time()]; $_map['app_id'] = $app_id; $_cnt = GiftModel::where($_map)->count(); if (empty($_cnt)) { return 0; } return $_cnt; } /** * 获取游戏详情 * @param $where * @param string $field * * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getDetail($where, $field = '') { $_game = huoGameModel::with('ext')->with('gv')->field($field)->where($where)->find(); $_cate_model = new CategoryModel(); $_gift_class = new GiftLogic(); $_data['gameid'] = $_game['id']; $_data['icon'] = $_game['icon']; $_data['gamename'] = $_game['name']; $_data['type'] = $_cate_model->getNameByIds($_game['category']); $_data['category'] = $_game['category']; $_data['size'] = isset($_game['gv'][0]['size']) ? $_game['gv'][0]['size'] : ''; $_data['down_cnt'] = empty($_game['ext']['down_cnt']) ? 0 : $_game['ext']['down_cnt']; $_data['star_cnt'] = empty($_game['ext']['star_cnt']) ? 0 : $_game['ext']['star_cnt']; $_data['hot'] = empty($_game['hot_order']) ? 1 : 2; /* 2热门1普通 */ $_data['down_url'] = isset($_game['gv'][0]['package_url']) ? $_game['gv'][0]['package_url'] : ''; // $_data['down_url'] = url('v8/game/down',['gameid'=>$_game['id']]); $_data['gift_cnt'] = $this->getGiftCnt($_game['id']); $_data['gift_list'] = $_gift_class->getGifts(0, ['app_id' => $_game['id']], '1,4'); $_data['package_name'] = $_game['package_name']; $_data['desc'] = $_game['description']; $_data['run_time'] = $_game['run_time']; $_data['language'] = $_game['language']; $_data['publicity'] = $_game['publicity']; $_data['classify'] = $_game['classify']; $_data['classify_name'] = $this->getClassifyName($_game['classify']); $_data['image'] = $this->getImages($_game['image']); return $_data; } public function getImages($value) { $_images = $value; if (!empty($_images)) { foreach ($_images as $_key => $_image) { $_images[$_key] = cmf_get_image_url($_image['url']); } } return $_images; } public function getImage($value) { $_images = $value; if (!empty($_images)) { $_images = cmf_get_image_url($_images); } return $_images; } /** * 获取类型 * @param array $where * @param string $page * @param string $order * * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getCategory($where = [], $page = '1,10', $order = '') { $_cate_model = new CategoryModel(); if (!empty($where['parent_id'])) { $_datas = $_cate_model->getList($where['parent_id'], $order); } else { $_datas = $_cate_model->getList(0, $order); } $_count = count($_datas); if (empty($_count)) { $_rdata['count'] = 0; $_rdata['list'] = []; } else { $_rdata['count'] = $_count; $_rdata['list'] = $_datas; } return $_rdata; } public function getClassifyName($classify) { $_map['id'] = $classify; $_name = GameclassifyModel::where($_map)->value('name'); return $_name; } public function gamePlatfromClass() { $_rdata = [ GameConst::GAME_ANDROID => 'Android', GameConst::GAME_IOS => 'IOS', ]; // $_map['status'] = 2; // $_rdata = GameclassifyModel::where($_map)->column('name', 'id'); return $_rdata; } public function getSimilarList($app_id = 0, $_cates, $page, $_order) { if ($app_id == 0) { $this->getCateList($_cates, $page, $_order); } if (empty($_cates)) { return [ 'count' => 0, 'list' => [] ]; } // 设置id,ids if (!empty($_cates)) { $_ids = $this->strToArr($_cates); foreach ($_ids as $_k => $_v) { $_ids[$_k] = intval($_v); } } $_find_category = CategoryModel::whereIn('id', $_ids)->column('id'); if (empty($_find_category)) { return [ 'count' => 0, 'list' => [] ]; } $_app_ids = GamecategoryModel::whereIn('cate_id', $_find_category)->group('app_id')->column('app_id'); foreach ($_app_ids as $_k => $_v) { if ($_v == $app_id) { unset($_app_ids[$_k]); } } if (empty($_app_ids)) { return [ 'count' => 0, 'list' => [] ]; } $_map['id'] = ['in', $_app_ids]; $_param['page'] = $page; $_param['order'] = $_order; return $this->getList($_map, $page, $_order); } }