IdentifyPlatformLogModel.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <?php
  2. /**
  3. * IdentifyPlatformLogModel.php UTF-8
  4. * 玩家实名认证平台记录
  5. *
  6. * @date : 2021/3/24 10:19
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : HUOSDK-9.0
  11. */
  12. namespace huoIdentify\model;
  13. use huo\model\common\CommonModel;
  14. use huolib\constant\CacheConst;
  15. use think\Cache;
  16. class IdentifyPlatformLogModel extends CommonModel {
  17. protected $name = 'identify_platform_log';
  18. protected $pk = 'id';
  19. /* 开启自动写入时间戳字段 */
  20. protected $autoWriteTimestamp = true;
  21. protected $cache_key_prefix = CacheConst::CACHE_IDENTIFY_PLATFORM_LOG_PREFIX;
  22. protected $type
  23. = [
  24. 'id' => 'integer',
  25. 'mem_id' => 'integer',
  26. 'mg_mem_id' => 'integer',
  27. 'app_id' => 'integer',
  28. 'identify_from' => 'string',
  29. 'real_name' => 'string',
  30. 'id_card' => 'string',
  31. 'identify_pi' => 'string',
  32. 'status' => 'integer',
  33. 'create_time' => 'timestamp',
  34. 'update_time' => 'timestamp',
  35. ];
  36. /**
  37. * 获取单条记录缓存key
  38. *
  39. * @param int $id ID
  40. *
  41. * @return string :string
  42. */
  43. protected function getSingleCacheKey($id) {
  44. return $this->cache_key_prefix.$id;
  45. }
  46. /**
  47. * 获取单条记录缓存key
  48. *
  49. * @param $mg_mem_id
  50. * @param $identify_from
  51. *
  52. * @return string :string
  53. */
  54. protected function getCacheKeyByMgFrom($mg_mem_id, $identify_from) {
  55. return $this->cache_key_prefix.'mg_'.$mg_mem_id.'_f_'.$identify_from;
  56. }
  57. /**
  58. * 加入数据库
  59. *
  60. * @param array $data
  61. *
  62. * @return bool|int
  63. */
  64. public function addData($data) {
  65. $_data = $data;
  66. $_rs = parent::addData($_data);
  67. if (empty($_rs)) {
  68. return false;
  69. }
  70. return $_rs;
  71. }
  72. /**
  73. * 通过ID获取信息
  74. *
  75. * @param int $id 主键ID
  76. *
  77. * @return array
  78. */
  79. public function getInfoById($id) {
  80. /* 缓存操作 */
  81. $_single_cache_key = $this->getSingleCacheKey($id);
  82. $_data = Cache::get($_single_cache_key);
  83. if (!empty($_data)) {
  84. return $_data;
  85. }
  86. $_data = parent::getInfoById($id);
  87. if (empty($_data)) {
  88. return [];
  89. }
  90. Cache::set($_single_cache_key, $_data);
  91. return $_data;
  92. }
  93. /**
  94. * 更新单条数据
  95. *
  96. * @param array $data 数据
  97. * @param int $id ID
  98. *
  99. * @return bool
  100. */
  101. public function updateData($data, $id) {
  102. $_data = $data;
  103. $_rs = parent::updateData($_data, $id);
  104. if (false === $_rs) {
  105. return false;
  106. }
  107. /* 缓存操作 */
  108. $_single_cache_key = $this->getSingleCacheKey($id);
  109. Cache::rm($_single_cache_key);
  110. return true;
  111. }
  112. /**
  113. * 删除单条数据
  114. *
  115. * @param int $id ID
  116. * @param bool $is_complete 是否完成删除
  117. *
  118. * @return bool
  119. */
  120. public function deleteData($id, $is_complete = true) {
  121. $_old_data = $this->getInfoById($id);
  122. $_rs = parent::deleteData($id, $is_complete);
  123. if (false == $_rs) {
  124. return false;
  125. }
  126. /* 缓存操作 */
  127. $_single_cache_key = $this->getSingleCacheKey($id);
  128. Cache::rm($_single_cache_key);
  129. /* 删除玩家id 缓存 */
  130. $_cache_key = $this->getCacheKeyByMgFrom($_old_data['mg_mem_id'], $_old_data['identify_from']);
  131. Cache::rm($_cache_key);
  132. return $_rs;
  133. }
  134. /**
  135. * 根据玩家id 删除实名信息
  136. *
  137. * @param $mem_id
  138. *
  139. * @return bool
  140. */
  141. public function deleteDataByMemId($mem_id) {
  142. $_map = [
  143. 'mem_id' => $mem_id
  144. ];
  145. $_ids = $this->where($_map)->column('id');
  146. if (!empty($_ids)) {
  147. foreach ($_ids as $_id) {
  148. $this->deleteData($_id);
  149. }
  150. }
  151. return true;
  152. }
  153. /**
  154. * 根据玩家小号id和来源获取id
  155. *
  156. * @param $mg_mem_id
  157. * @param $identify_from
  158. *
  159. * @return int|mixed
  160. */
  161. public function getIdByMgFrom($mg_mem_id, $identify_from) {
  162. $_cache_key = $this->getCacheKeyByMgFrom($mg_mem_id, $identify_from);
  163. $_id = Cache::get($_cache_key);
  164. if (!empty($_id)) {
  165. return $_id;
  166. }
  167. $_map = [
  168. 'mg_mem_id' => $mg_mem_id,
  169. 'identify_from' => $identify_from,
  170. ];
  171. $_id = $this->where($_map)->value($this->pk);
  172. if (empty($_id)) {
  173. return 0;
  174. }
  175. Cache::set($_cache_key, $_id);
  176. return $_id;
  177. }
  178. /**
  179. * 获取Pi
  180. *
  181. * @param $mg_mem_id
  182. * @param $identify_from
  183. *
  184. * @return array|string
  185. */
  186. public function getInfoByMgFrom($mg_mem_id, $identify_from) {
  187. $_id = $this->getIdByMgFrom($mg_mem_id, $identify_from);
  188. if (empty($_id)) {
  189. return '';
  190. }
  191. $_data = $this->getInfoById($_id);
  192. return $_data;
  193. }
  194. /**
  195. * 获取Pi
  196. *
  197. * @param $mg_mem_id
  198. * @param $identify_from
  199. *
  200. * @return string
  201. */
  202. public function getPiByMgFrom($mg_mem_id, $identify_from) {
  203. $_data = $this->getInfoByMgFrom($mg_mem_id, $identify_from);
  204. return get_val($_data, 'identify_pi', '');
  205. }
  206. /**
  207. * 关联玩家
  208. */
  209. public function mem() {
  210. $_field = [
  211. 'id',
  212. 'username'
  213. ];
  214. return $this->belongsTo('\huo\model\member\MemberModel', 'mem_id', 'id')->field($_field);
  215. }
  216. /**
  217. * 关联游戏
  218. */
  219. public function game() {
  220. $_field = [
  221. 'id' => 'id',
  222. 'name' => 'name',
  223. 'classify' => 'classify',
  224. '`classify`' => 'classify_label',
  225. ];
  226. return $this->belongsTo('\huo\model\game\GameModel', 'app_id', 'id')->field($_field);
  227. }
  228. }