* @version : HuoMP 1.0 */ namespace huomp\model\homepage; use huolib\constant\CacheConst; use huomp\model\common\CommonModel; use think\Cache; class HomepageModel extends CommonModel { protected $table = 'mp_homepage'; // 开启自动写入时间戳字段 protected $autoWriteTimestamp = true; protected $cache_key_prefix = CacheConst::CACHE_GAME_MP_PREFIX; /** * 添加数据 * * @param $data * * @return bool */ public function addData($data) { if (empty($data)) { return false; } $_data = $data; $_obj = self::create($_data, true); if ($_obj) { return true; } return false; } /** * 更新数据 * * @param array $data 数据 * @param int $mem_id 玩家ID * * @return bool */ public function updateData($data, $mem_id) { $_map['mem_id'] = $mem_id; $_data = $data; $_rs = self::update($_data, $_map, true); if (false == $_rs) { return false; } $_cache_key = $this->cache_key_prefix.$_data['mem_id']; Cache::rm($_cache_key); return true; } /** * 获取Banner图 * * @param $mem_id * * @return array|bool|false */ public function getInfoByMemId($mem_id) { $_cache_key = $this->cache_key_prefix.$mem_id; $_data = Cache::get($_cache_key); if (!empty($_data)) { return $_data; } $_map['mem_id'] = $mem_id; $_info = $this->where($_map)->find(); if (false === $_info) { return false; } if (is_object($_info)) { $_info = $_info->toArray(); } Cache::set($_cache_key, $_info); return $_info; } }