* @version : HUOSDK 8.0 */ namespace huo\model\game; use huo\model\common\CommonModel; use huolib\constant\CacheConst; use huolib\tool\Time; use huomp\model\game\GameMiniModel; use think\Cache; class GamecategoryModel extends CommonModel { protected $name = 'game_category'; protected $cache_tag = CacheConst::TAG_GAME_LIST; protected $tgi_tag = CacheConst::TAG_GAME_LIST_INFO; /** * 关联游戏 */ public function game() { return $this->hasone(GameModel::className(), 'id', 'app_id')->field( 'id,name,classify as classify_label,status as status_label,icon' ); } /** * 关联game表 * * @return mixed */ public function gmini() { return $this->hasone(GameMiniModel::className(), 'app_id', 'app_id')->field('app_id,mini_app_id'); } public function joingame() { return $this->belongsTo('huo\model\game\GameModel', 'app_id', 'id')->setEagerlyType(0); } /** * 关联game_ext表 * * @return mixed */ public function gameext() { return $this->belongsTo('huo\model\game\GameextModel', 'app_id', 'app_id')->setEagerlyType(0); } /** * 关联game_rate表 * * @return mixed */ public function gamerate() { return $this->belongsTo('huo\model\rate\GameRateModel', 'app_id', 'app_id')->setEagerlyType(0); } /** * 关联game_rate表 * * @return mixed */ public function gamemini() { return $this->belongsTo('huomp\model\game\GameMiniModel', 'app_id', 'app_id')->field('app_id,mini_app_id,need_popup,entrance_image'); } /** * 关联game_version表 * * @return \think\model\relation\HasMany */ public function gv() { return $this->hasMany('huo\model\game\GameversionModel', 'app_id', 'app_id')->field('app_id,package_url'); } /** * 根据app_id 获取cate_id数组 * * @param $app_id * * @return array */ public function getCateIdsByAppId($app_id) { $_map = ['app_id' => $app_id]; return self::where($_map)->column('cate_id'); } /** * 添加数据 * * @param $data * * @return bool */ public function addData($data) { if (empty($data)) { return false; } $_data = $data; $_obj = self::create($_data, true); if ($_obj) { Cache::clear($this->cache_tag); Cache::clear($this->tgi_tag); return true; } return false; } /** * 更新数据 * * @param array $data 数据 * @param int $id ID * * @return bool */ public function updateData($data, $id) { $_map['id'] = $id; $_data = $data; $_rs = self::update($_data, $_map, true); if (false == $_rs) { return false; } Cache::clear($this->cache_tag); Cache::clear($this->tgi_tag); return true; } /** * 删除数据 * * @param array $_map 删除条件 * * @return int */ public function deleteDataByWhere($_map) { $_rs = self::where($_map)->delete(); if ($_rs) { Cache::clear($this->cache_tag); Cache::clear($this->tgi_tag); } return $_rs; } /** * 判断条件下信息是否存在 * * @param $cate_id * @param $app_id * * @return bool */ public function isGameExist($cate_id, $app_id) { $_map = ['cate_id' => $cate_id, 'app_id' => $app_id]; $_cache_key = $this->tgi_tag.md5(json_encode($_map)); list($_start_time, $_end_time) = Time::today(); $_diff_time = $_end_time - time(); $_rs = self::where($_map)->cache($_cache_key, $_diff_time, $this->tgi_tag)->find(); if (is_object($_rs)) { $_rs = $_rs->toArray(); } if (empty($_rs)) { return false; } return true; } /** * 获取类下的游戏ids * * @param $cate_id * * @return array */ public function getAppIdsByCateId($cate_id) { return self::where(['cate_id' => $cate_id])->column('app_id'); } }