123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- /**
- * GameReyunModel.php UTF-8
- * 热云游戏对照表
- *
- * @date : 2019/4/23 10:09
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : chenbingling <cbl@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace reyun\model;
- use huo\model\common\CommonModel;
- use huolib\constant\CacheConst;
- use think\Cache;
- class GameReyunModel extends CommonModel {
- protected $name = 'game_reyun';
- protected $cache_key_prefix = CacheConst::CACHE_GAME_REYUN_PREFIX;
- /**
- * 获取单条记录缓存key
- *
- * @param int $app_id 游戏ID
- *
- * @return string
- */
- protected function getSingleCacheKey($app_id) {
- return $this->cache_key_prefix.$app_id;
- }
- /**
- * 添加数据
- *
- * @param array $data 需要添加的数据
- *
- * @return false|int 添加失败返回 false 添加成功 返回添加的ID
- */
- public function addData($data) {
- if (empty($data)) {
- return false;
- }
- $_data = $data;
- $_model = new static();
- $_rs = $_model->allowField(true)->isUpdate(false)->save($_data, []);
- if (false !== $_rs) {
- return $_model->getLastInsID();
- }
- return false;
- }
- /**
- * 通过ID获取信息
- *
- * @param int $app_id 主键ID
- *
- * @return array|false
- */
- public function getInfoByAppId($app_id) {
- /* 缓存操作 */
- $_single_cache_key = $this->getSingleCacheKey($app_id);
- $_data = Cache::get($_single_cache_key);
- if (!empty($_data)) {
- return $_data;
- }
- $_map['app_id'] = $app_id;
- $_info = $this->where($_map)->find();
- if (false === $_info) {
- return [];
- }
- if (is_object($_info)) {
- $_info = $_info->toArray();
- }
- if (empty($_info)) {
- return [];
- }
- Cache::set($_single_cache_key, $_info);
- return $_info;
- }
- /**
- * 更新单条数据
- *
- * @param array $data 数据
- * @param int $app_id 游戏ID
- *
- * @return bool
- */
- public function updateDataByAppId($data, $app_id) {
- $_data = $data;
- $_map['app_id'] = $app_id;
- $_rs = $this->allowField(true)->isUpdate(true)->save($_data, $_map);
- if (false === $_rs) {
- return false;
- }
- /* 缓存操作 */
- $_single_cache_key = $this->getSingleCacheKey($app_id);
- Cache::rm($_single_cache_key);
- /* TAG缓存操作 */
- return true;
- }
- }
|