123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <?php
- /**
- * GamecategoryModel.php UTF-8
- * 游戏与类型关联表
- *
- * @date : 2017/11/23 17:22
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @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');
- }
- }
|