123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- /**
- * MemFakerModel.php UTF-8
- * 玩家假数据
- *
- * @date : 2018/6/27 17:57
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : luowei <lwl@huosdk.com>
- * @version : HuoMp 1.0
- */
- namespace huomp\model\fill;
- use huolib\constant\CacheConst;
- use huolib\constant\CommonConst;
- use huomp\model\common\CommonModel;
- use think\Cache;
- class MemFakerModel extends CommonModel {
- protected $cache_key_prefix = CacheConst::CACHE_MEM_RANK_FAKER_PREFIX;
- protected $tag = CacheConst::CACHE_MEM_RANK_FAKER_TAG;
- protected $table = 'mp_mem_faker';
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = true;
- /**
- * @param array $data
- *
- * @return bool|mixed
- */
- public function addData($data = []) {
- if ($_obj = self::create($data, true)) {
- Cache::clear($this->tag);
- return $_obj->id;
- } else {
- return false;
- }
- }
- /**
- * @param array $data
- * @param int $id
- *
- * @return bool|mixed
- */
- public function updateData($data, $id) {
- $_map['id'] = $id;
- $_data = $data;
- $_rs = self::update($_data, $_map, true);
- if (false === $_rs) {
- return false;
- } else {
- $_cache_key = $this->cache_key_prefix.$id;
- Cache::rm($_cache_key);
- return true;
- }
- }
- /**
- * @param int $id
- *
- * @return array|false
- */
- public function getDetail($id) {
- $_cache_key = $this->cache_key_prefix.$id;
- $_data = Cache::get($_cache_key);
- if (!empty($_data)) {
- return json_decode($_data, true);
- }
- $_map['id'] = $id;
- $_data = $this->where($_map)->find();
- if (empty($_data)) {
- return [];
- }
- if (is_object($_data)) {
- $_data = $_data->toArray();
- }
- if (!empty($_data)) {
- Cache::tag($this->tag, $_cache_key)->set($_cache_key, json_encode($_data));
- }
- return $_data;
- }
- /**
- * 获取列表
- *
- * @param array $ids
- *
- * @return array
- */
- public function getList($ids = []) {
- $_map = [];
- if (!empty($ids)) {
- $_map['id'] = ['in', $ids];
- }
- $_map['is_delete'] = CommonConst::CONST_NOT_DELETE;
- return self::where($_map)->select()->toArray();
- }
- /**
- * 获取头像列表
- */
- public function getAvatars() {
- $_cache_key = $this->cache_key_prefix.'avatars';
- $_data = Cache::get($_cache_key);
- if (!empty($_data)) {
- return json_decode($_data, true);
- }
- $_avatars = $this->column('avatar');
- if (!empty($_avatars)) {
- Cache::tag($this->tag, $_cache_key)->set($_cache_key, json_encode($_avatars));
- }
- return $_avatars;
- }
- }
|