123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- <?php
- /**
- * PsMemWhiteModel.php UTF-8
- * 支付切换玩家白名单
- *
- * @date : 2018/12/22 11:37
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : chenbingling <cbl@huosdk.com>
- * @version : HUOSDK 8.0
- */
- 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;
- /**
- * @return \think\model\relation\BelongsTo
- */
- public function game() {
- return $this->belongsTo('huo\model\game\GameModel', 'app_id', 'id')->field('id,name');
- }
- /**
- * 获取缓存key
- *
- * @param $app_id
- * @param $mem_id
- *
- * @return string
- */
- 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;
- }
- }
- /**
- * 获取详情
- *
- * @param $app_id
- * @param $mem_id
- *
- * @return mixed
- */
- 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;
- }
- /**
- * 修改信息
- *
- * @param $app_id
- * @param $mem_id
- * @param $data
- *
- * @return bool
- */
- 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;
- }
- /**
- * 根据ID更新数据
- *
- * @param $id
- * @param $data
- *
- * @return bool
- */
- 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;
- }
- /**
- * 删除数据
- *
- * @param $app_id
- * @param $mem_id
- *
- * @return int
- */
- 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;
- }
- /**
- * 获取白名单列表
- *
- * @param array $param 筛选条件入参
- * @param string $page 分页数据
- * @param string $order 排序条件
- *
- * @return array
- */
- 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;
- }
- }
|