* @version : HUOSDK 8.0 */ namespace huo\model\game; use huo\model\common\CommonModel; use huolib\constant\CacheConst; use think\Cache; class GameOrderSwitchModel extends CommonModel { protected $pk = 'app_id'; protected $name = 'game_order_switch'; /* 开启自动写入时间戳字段 */ protected $autoWriteTimestamp = true; protected $cache_key_prefix = CacheConst::CACHE_GAME_ORDER_SWITCH_PREFIX; /** * 获取单条记录缓存key * * @param int $id ID * * @return string */ protected function getSingleCacheKey($id) { return $this->cache_key_prefix.$id; } /** * 添加数据 * * @param array $data 需要添加的数据 * * @return false|int 添加失败返回 false 添加成功 返回添加的ID */ public function addData($data) { $_data = $data; $_id = parent::parentAddData($_data); if (false === $_id) { return false; } /* TAG缓存操作 */ return $_id; } /** * 通过ID获取信息 * * @param int $id 主键ID * * @return array|false */ public function getInfoById($id) { /* 缓存操作 */ $_single_cache_key = $this->getSingleCacheKey($id); $_data = Cache::get($_single_cache_key); if (!empty($_data)) { return $_data; } $_data = parent::parentGetInfoById($id); if (empty($_data)) { return []; } Cache::set($_single_cache_key, $_data); return $_data; } /** * 更新单条数据 * * @param array $data 数据 * @param int $id ID * * @return bool */ public function updateData($data, $id) { $_data = $data; $_rs = parent::parentUpdateData($_data, $id); if (false === $_rs) { return false; } /* 缓存操作 */ $_single_cache_key = $this->getSingleCacheKey($id); Cache::rm($_single_cache_key); /* TAG缓存操作 */ return true; } /** * 删除单条数据 * * @param int $id ID * @param bool $is_complete 是否完成删除 * * @return bool */ public function deleteData($id, $is_complete = false) { $_rs = parent::parentDeleteData($id, $is_complete); if (false == $_rs) { return false; } /* 缓存操作 */ $_single_cache_key = $this->getSingleCacheKey($id); Cache::rm($_single_cache_key); /* TAG缓存操作 */ return $_rs; } /** * 关联game表 * * @return mixed */ public function game() { return $this->belongsTo('huo\model\game\GameModel', 'app_id')->field('id,name game_name,pay_switch'); } }