123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- <?php
- /**
- * IdentifyPlatformLogModel.php UTF-8
- * 玩家实名认证平台记录
- *
- * @date : 2021/3/24 10:19
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : chenbingling <cbl@huosdk.com>
- * @version : HUOSDK-9.0
- */
- namespace huoIdentify\model;
- use huo\model\common\CommonModel;
- use huolib\constant\CacheConst;
- use think\Cache;
- class IdentifyPlatformLogModel extends CommonModel {
- protected $name = 'identify_platform_log';
- protected $pk = 'id';
- /* 开启自动写入时间戳字段 */
- protected $autoWriteTimestamp = true;
- protected $cache_key_prefix = CacheConst::CACHE_IDENTIFY_PLATFORM_LOG_PREFIX;
- protected $type
- = [
- 'id' => 'integer',
- 'mem_id' => 'integer',
- 'mg_mem_id' => 'integer',
- 'app_id' => 'integer',
- 'identify_from' => 'string',
- 'real_name' => 'string',
- 'id_card' => 'string',
- 'identify_pi' => 'string',
- 'status' => 'integer',
- 'create_time' => 'timestamp',
- 'update_time' => 'timestamp',
- ];
- /**
- * 获取单条记录缓存key
- *
- * @param int $id ID
- *
- * @return string :string
- */
- protected function getSingleCacheKey($id) {
- return $this->cache_key_prefix.$id;
- }
- /**
- * 获取单条记录缓存key
- *
- * @param $mg_mem_id
- * @param $identify_from
- *
- * @return string :string
- */
- protected function getCacheKeyByMgFrom($mg_mem_id, $identify_from) {
- return $this->cache_key_prefix.'mg_'.$mg_mem_id.'_f_'.$identify_from;
- }
- /**
- * 加入数据库
- *
- * @param array $data
- *
- * @return bool|int
- */
- public function addData($data) {
- $_data = $data;
- $_rs = parent::addData($_data);
- if (empty($_rs)) {
- return false;
- }
- return $_rs;
- }
- /**
- * 通过ID获取信息
- *
- * @param int $id 主键ID
- *
- * @return array
- */
- public function getInfoById($id) {
- /* 缓存操作 */
- $_single_cache_key = $this->getSingleCacheKey($id);
- $_data = Cache::get($_single_cache_key);
- if (!empty($_data)) {
- return $_data;
- }
- $_data = parent::getInfoById($id);
- if (empty($_data)) {
- return [];
- }
- Cache::set($_single_cache_key, $_data);
- return $_data;
- }
- /**
- * 更新单条数据
- *
- * @param array $data 数据
- * @param int $id ID
- *
- * @return bool
- */
- public function updateData($data, $id) {
- $_data = $data;
- $_rs = parent::updateData($_data, $id);
- if (false === $_rs) {
- return false;
- }
- /* 缓存操作 */
- $_single_cache_key = $this->getSingleCacheKey($id);
- Cache::rm($_single_cache_key);
- return true;
- }
- /**
- * 删除单条数据
- *
- * @param int $id ID
- * @param bool $is_complete 是否完成删除
- *
- * @return bool
- */
- public function deleteData($id, $is_complete = true) {
- $_old_data = $this->getInfoById($id);
- $_rs = parent::deleteData($id, $is_complete);
- if (false == $_rs) {
- return false;
- }
- /* 缓存操作 */
- $_single_cache_key = $this->getSingleCacheKey($id);
- Cache::rm($_single_cache_key);
- /* 删除玩家id 缓存 */
- $_cache_key = $this->getCacheKeyByMgFrom($_old_data['mg_mem_id'], $_old_data['identify_from']);
- Cache::rm($_cache_key);
- return $_rs;
- }
- /**
- * 根据玩家id 删除实名信息
- *
- * @param $mem_id
- *
- * @return bool
- */
- public function deleteDataByMemId($mem_id) {
- $_map = [
- 'mem_id' => $mem_id
- ];
- $_ids = $this->where($_map)->column('id');
- if (!empty($_ids)) {
- foreach ($_ids as $_id) {
- $this->deleteData($_id);
- }
- }
- return true;
- }
- /**
- * 根据玩家小号id和来源获取id
- *
- * @param $mg_mem_id
- * @param $identify_from
- *
- * @return int|mixed
- */
- public function getIdByMgFrom($mg_mem_id, $identify_from) {
- $_cache_key = $this->getCacheKeyByMgFrom($mg_mem_id, $identify_from);
- $_id = Cache::get($_cache_key);
- if (!empty($_id)) {
- return $_id;
- }
- $_map = [
- 'mg_mem_id' => $mg_mem_id,
- 'identify_from' => $identify_from,
- ];
- $_id = $this->where($_map)->value($this->pk);
- if (empty($_id)) {
- return 0;
- }
- Cache::set($_cache_key, $_id);
- return $_id;
- }
- /**
- * 获取Pi
- *
- * @param $mg_mem_id
- * @param $identify_from
- *
- * @return array|string
- */
- public function getInfoByMgFrom($mg_mem_id, $identify_from) {
- $_id = $this->getIdByMgFrom($mg_mem_id, $identify_from);
- if (empty($_id)) {
- return '';
- }
- $_data = $this->getInfoById($_id);
- return $_data;
- }
- /**
- * 获取Pi
- *
- * @param $mg_mem_id
- * @param $identify_from
- *
- * @return string
- */
- public function getPiByMgFrom($mg_mem_id, $identify_from) {
- $_data = $this->getInfoByMgFrom($mg_mem_id, $identify_from);
- return get_val($_data, 'identify_pi', '');
- }
- /**
- * 关联玩家
- */
- public function mem() {
- $_field = [
- 'id',
- 'username'
- ];
- return $this->belongsTo('\huo\model\member\MemberModel', 'mem_id', 'id')->field($_field);
- }
- /**
- * 关联游戏
- */
- public function game() {
- $_field = [
- 'id' => 'id',
- 'name' => 'name',
- 'classify' => 'classify',
- '`classify`' => 'classify_label',
- ];
- return $this->belongsTo('\huo\model\game\GameModel', 'app_id', 'id')->field($_field);
- }
- }
|