123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace huomp\logic\game;
- use huolib\constant\CacheConst;
- use huolib\constant\CommonConst;
- use huomp\model\common\CommonModel;
- use think\Cache;
- class GameMiniLogic extends CommonModel {
- protected $name = 'game_mini';
-
- protected $autoWriteTimestamp = true;
- protected $cache_tag = CacheConst::TAG_CACHE_GAME_MP;
- protected $cache_key_prefix = CacheConst::CACHE_GAME_MP_PREFIX;
-
- public function game() {
- return $this->belongsTo('huo\model\game\GameModel', 'app_id', 'id')->field('id,name');
- }
-
- public function addData($data) {
- if (empty($data) || empty($data['app_id'])) {
- return false;
- }
- $_data = $data;
- $_obj = self::create($_data, true);
- if ($_obj) {
- return true;
- }
- return false;
- }
-
- public function updateData($data, $id) {
- $_map['app_id'] = $id;
- $_data = $data;
- $_rs = self::update($_data, $_map, true);
- if (false == $_rs) {
- return false;
- }
- $_cache_key = $this->cache_key_prefix.$_data['app_id'];
- Cache::tag($this->cache_tag)->rm($_cache_key);
- return true;
- }
-
- public function getDataByAppId($app_id) {
- if (empty($app_id)) {
- return false;
- }
- $_cache_key = $this->cache_key_prefix.$app_id;
- $_data = Cache::tag($this->cache_tag)->get($_cache_key);
- if (!empty($_data)) {
- return $_data;
- }
- $_data = $this->where('app_id', $app_id)->find();
- if (is_object($_data)) {
- $_data = $_data->toArray();
- }
- Cache::tag($this->cache_tag)->set($_cache_key, $_data, CommonConst::CONST_DAY_SECONDS);
- return $_data;
- }
- }
|