| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 | 
							- <?php
 
- /**
 
-  * GameMiniLogic.php UTF-8
 
-  * 小程序逻辑
 
-  *
 
-  * @date    : 2018/8/9 17:25
 
-  *
 
-  * @license 这不是一个自由软件,未经授权不许任何使用和传播。
 
-  * @author  : wuyonghong <wyh@huosdk.com>
 
-  * @version : HuoMp 1.0
 
-  */
 
- 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;
 
-     /**
 
-      * 关联game表
 
-      *
 
-      * @return mixed
 
-      */
 
-     public function game() {
 
-         return $this->belongsTo('huo\model\game\GameModel', 'app_id', 'id')->field('id,name');
 
-     }
 
-     /**
 
-      * 添加数据
 
-      *
 
-      * @param $data
 
-      *
 
-      * @return bool
 
-      */
 
-     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;
 
-     }
 
-     /**
 
-      * 更新数据
 
-      *
 
-      * @param array $data 数据
 
-      * @param int   $id   应用ID
 
-      *
 
-      * @return bool
 
-      */
 
-     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;
 
-     }
 
-     /**
 
-      * 获取小程序信息
 
-      *
 
-      * @param int $app_id 应用ID
 
-      *
 
-      * @return array|bool|false
 
-      */
 
-     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;
 
-     }
 
- }
 
 
  |