123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- namespace huomp\model\wallet;
- use huolib\constant\CacheConst;
- use huomp\model\common\CommonModel;
- use think\Cache;
- class MidasGmMemModel extends CommonModel {
- protected $table = 'mp_midas_gm_mem';
-
- protected $autoWriteTimestamp = true;
- protected $cache_tag = CacheConst::TAG_CACHE_MGM;
- protected $cache_key_prefix = CacheConst::CACHE_GAME_MGM_PREFIX;
-
- public function game() {
- return $this->belongsTo('huo\model\game\GameModel', 'app_id', 'id')->field('id,name');
- }
-
- public function mem() {
- return $this->belongsTo('huo\model\member\MemberModel', 'mem_id', 'id')->field('id,name');
- }
-
- public function addData($data) {
- if (empty($data) || empty($data['app_id']) || empty($data['mem_id'])) {
- return false;
- }
- $_data = $data;
- $_obj = self::create($_data, true);
- if ($_obj) {
- return true;
- }
- return false;
- }
-
- public function updateData($data, $id) {
- $_map['id'] = $id;
- $_data = $data;
- $_rs = self::update($_data, $_map, true);
- if (false == $_rs) {
- return false;
- }
- $_cache_key = $this->cache_key_prefix.$_data['mem_id'].$_data['app_id'];
- Cache::tag($this->cache_tag)->rm($_cache_key);
- return true;
- }
-
- public function getDataByMemApp($mem_id, $app_id) {
- if (empty($mem_id) || empty($app_id)) {
- return false;
- }
- $_cache_key = $this->cache_key_prefix.$mem_id.$app_id;
- $_data = Cache::tag($this->cache_tag)->get($_cache_key);
- if (!empty($_data)) {
- return $_data;
- }
- $_map['mem_id'] = $mem_id;
- $_map['app_id'] = $app_id;
- $_data = $this->where($_map)->find();
- if (is_object($_data)) {
- $_data = $_data->toArray();
- }
- Cache::tag($this->cache_tag)->set($_cache_key, $_data);
- return $_data;
- }
-
- public function getDataOrInsert($mem_id, $app_id) {
- $_data = $this->getDataByMemApp($mem_id, $app_id);
- if (empty($_data)) {
- $_data['mem_id'] = $mem_id;
- $_data['app_id'] = $app_id;
- $this->addData($_data);
- }
- return $this->getDataByMemApp($mem_id, $app_id);
- }
- }
|