123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- <?php
- namespace huo\model\game;
- use huo\model\common\CommonModel;
- use huolib\constant\CacheConst;
- use huolib\constant\CommonConst;
- use think\Cache;
- class PsMemWhiteModel extends CommonModel {
- protected $name = 'ps_mem_white';
- protected $autoWriteTimestamp = true;
- protected $key = CacheConst::CACHE_PAY_SWITCH_MEM_WHITE_PREFIX;
-
- public function game() {
- return $this->belongsTo('huo\model\game\GameModel', 'app_id', 'id')->field('id,name');
- }
-
- protected function getKey($app_id, $mem_id) {
- $_key = $this->key.$app_id.'_'.$mem_id;
- return $_key;
- }
- public function addData($data) {
- $_data = [];
- $_data['app_id'] = get_val($data, 'app_id', 0);
- $_data['mem_id'] = get_val($data, 'mem_id', 0);
- $_data['username'] = get_val($data, 'username', '');
- $_data['nickname'] = get_val($data, 'nickname', '');
- if ($_obj = self::create($_data, true)) {
- $_data['id'] = $_obj->id;
- $_key = $this->getKey($_data['app_id'], $_data['mem_id']);
- Cache::set($_key, json_encode($_data), CommonConst::CONST_DAY_SECONDS);
- return $_data;
- } else {
- return false;
- }
- }
-
- public function getInfo($app_id, $mem_id) {
- $_key = $this->getKey($app_id, $mem_id);
- $_data = Cache::get($_key);
- if (!empty($_data)) {
- return json_decode($_data, true);
- }
- $_map = [
- 'app_id' => $app_id,
- 'mem_id' => $mem_id,
- ];
- $_data = $this->where($_map)->find();
- if (is_object($_data)) {
- $_data = $_data->toArray();
- }
- if (empty($_data)) {
- return [];
- }
- Cache::set($_key, json_encode($_data), CommonConst::CONST_DAY_SECONDS);
- return $_data;
- }
-
- public function updateDataPsMemWhite($app_id, $mem_id, $data) {
- $_key = $this->getKey($app_id, $mem_id);
- $_data = $this->getInfo($app_id, $mem_id);
- $_data = array_merge($_data, $data);
- $_map = [
- 'app_id' => $app_id,
- 'mem_id' => $mem_id,
- ];
- $_rs = $this->where($_map)->update($_data);
- if (false == $_rs) {
- return false;
- }
- Cache::set($_key, json_encode($_data), CommonConst::CONST_DAY_SECONDS);
- return true;
- }
-
- public function updateById($id, $data) {
- $_data = parent::getInfoById($id);
- $_data = array_merge($_data, $data);
- $_map = ['id' => $id];
- $_rs = $this->where($_map)->update($_data);
- if (false == $_rs) {
- return false;
- }
- $_key = $this->getKey($_data['app_id'], $_data['mem_id']);
- Cache::set($_key, json_encode($_data), CommonConst::CONST_DAY_SECONDS);
- return true;
- }
-
- public function delData($app_id, $mem_id) {
- $_map = ['app_id' => $app_id, 'mem_id' => $mem_id];
- $_rs = $this->where($_map)->delete();
- if (true == $_rs) {
- $_key = $this->getKey($app_id, $mem_id);
- Cache::rm($_key);
- }
- return $_rs;
- }
-
- public function getList($param = [], $page = '1,10', $order = '-create_time') {
- $_return = ['count' => 0, 'list' => []];
- if (empty($param['app_id'])) {
- return $_return;
- }
- $_map = ['app_id' => $param['app_id']];
- if (!empty($param['start_time']) && !empty($param['end_time'])) {
- $_map['create_time'] = ['between', [strtotime($param['start_time']),
- strtotime($param['end_time']) + CommonConst::CONST_DAY_SECONDS]];
- } elseif (!empty($param['start_time'])) {
- $_map['create_time'] = ['egt', strtotime($param['start_time'])];
- } elseif (!empty($param['end_time'])) {
- $_map['create_time'] = ['elt', strtotime($param['end_time']) + CommonConst::CONST_DAY_SECONDS];
- }
- if (!empty($param['mem_id'])) {
- $_map['mem_id'] = $param['mem_id'];
- }
- if (!empty($param['username'])) {
- $_map['username'] = $param['username'];
- }
- if (!empty($param['nickname'])) {
- $_map['nickname'] = $param['nickname'];
- }
- $_count = $this->where($_map)->count();
- if (empty($_count)) {
- return $_return;
- }
- $_order = $this->orderFilter($order);
- $_data = $this->with('game')->where($_map)->order($_order)->page($page)->select();
- if (is_object($_data)) {
- $_data = $_data->toArray();
- }
- if (empty($_data)) {
- return $_return;
- }
- $_return['count'] = $_count;
- $_return['list'] = $_data;
- return $_return;
- }
- }
|