AccountLogic.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | saiadmin [ saiadmin快速开发框架 ]
  4. // +----------------------------------------------------------------------
  5. // | Author: your name
  6. // +----------------------------------------------------------------------
  7. namespace app\v1\logic\customer;
  8. use plugin\saiadmin\basic\BaseLogic;
  9. use plugin\saiadmin\exception\ApiException;
  10. use plugin\saiadmin\utils\Helper;
  11. use app\v1\model\customer\Account;
  12. use support\Redis;
  13. use support\think\Db;
  14. /**
  15. * 账号信息逻辑层
  16. */
  17. class AccountLogic extends BaseLogic
  18. {
  19. /**
  20. * 构造函数
  21. */
  22. public function __construct()
  23. {
  24. $this->model = new Account();
  25. }
  26. /**
  27. * 获取IP地理位置
  28. */
  29. public function getIpLocation($ip): string
  30. {
  31. $ip2region = new \Ip2Region();
  32. try {
  33. $region = $ip2region->memorySearch($ip);
  34. } catch (\Exception $e) {
  35. return '未知';
  36. }
  37. list($country, $number, $province, $city, $network) = explode('|', $region['region']);
  38. if ($network === '内网IP') {
  39. return $network;
  40. }
  41. if ($country == '中国') {
  42. return $province.'-'.$city.':'.$network;
  43. } else if ($country == '0') {
  44. return '未知';
  45. } else {
  46. return $country;
  47. }
  48. }
  49. /**
  50. * 列表
  51. */
  52. public function list($query)
  53. {
  54. if($query['type'] == '1'){
  55. $uid = Db::connect('db_origin')->table('users')->where('user_name', $query['val'])->value('uid');
  56. $data = Db::connect('db_origin')->table('user_'.$uid%10)->where('uid', $uid)->select()->toArray();
  57. }else{
  58. $data = Db::connect('db_origin')->table('user_'.$query['val']%10)->where('uid', $query['val'])->select()->toArray();
  59. }
  60. $data = array_map(function($item){
  61. $item['login_ip'] = $item['login_ip'].$this->getIpLocation($item['login_ip']);
  62. $item['reg_ip'] = $item['reg_ip'].$this->getIpLocation($item['reg_ip']);
  63. $item['reg_time'] = date('Y-m-d H:i:s', $item['reg_time']);
  64. $item['login_time'] = date('Y-m-d H:i:s', $item['login_time']);
  65. unset($item['user_pwd']);
  66. return $item;
  67. }, $data);
  68. return $data;
  69. }
  70. /**
  71. * 修改密码
  72. */
  73. public function updatePwd($data)
  74. {
  75. $user_pwd = password_hash($data['user_pwd'], PASSWORD_DEFAULT);
  76. $result = Db::connect('db_origin')->table('user_'.$data['uid']%10)->where('uid', $data['uid'])->update(['user_pwd' => $user_pwd]);
  77. return $result;
  78. }
  79. /**
  80. * 修改手机
  81. */
  82. public function updateMobile($data)
  83. {
  84. $result = Db::connect('db_origin')->table('user_'.$data['uid']%10)->where('uid', $data['uid'])->update(['mobile' => $data['mobile']]);
  85. return $result;
  86. }
  87. /**
  88. * 修改真实名
  89. */
  90. public function updateReal($data)
  91. {
  92. $result = Db::connect('db_origin')->table('user_'.$data['uid']%10)->where('uid', $data['uid'])->update(['real_name' => $data['real_name'], 'id_card' => $data['id_card']]);
  93. return $result;
  94. }
  95. /**
  96. * 封禁列表
  97. */
  98. public function getBanList($query)
  99. {
  100. $saiType = request()->input('saiType', 'list');
  101. $page = request()->input('page', 1);
  102. $limit = request()->input('limit', 10);
  103. $orderBy = request()->input('orderBy', '');
  104. $orderType = request()->input('orderType', $this->orderType);
  105. if(empty($orderBy)) {
  106. $orderBy = $this->orderField !== '' ? $this->orderField : $this->model->getPk();
  107. }
  108. if ($saiType === 'all') {
  109. $data = Db::connect('db_game_log')->table('ban_log')->where($query)->order($orderBy, $orderType)->select()->toArray();
  110. }
  111. $data = Db::connect('db_game_log')->table('ban_log')->where($query)->order($orderBy, $orderType)->paginate($limit, false, ['page' => $page])->toArray();
  112. $data['data'] = array_map(function($item) {
  113. $item['action'] = $item['action'] == 1 ? '封禁' : '解封';
  114. $item['type'] = $item['type'] == 1 ? 'UID' : ($item['type'] == 2 ? 'IP' : '设备');
  115. return $item;
  116. }, $data['data']);
  117. $data['data'] = $this->trandformListColumn($data['data'],['auth']);
  118. return $data;
  119. }
  120. /**
  121. * 添加/解除封禁
  122. */
  123. public function saveBan($data)
  124. {
  125. $type = $data['type']; // 封禁类型
  126. $value = $data['value']; // 封禁值
  127. $action = $data['action']; // 操作
  128. $reason = $data['reason']; // 理由
  129. $auth_id = $data['auth_id']; // 操作人
  130. $data = Db::connect('db_game_log')->table('ban_log')->insert([
  131. 'type' => $type,
  132. 'value' => $value,
  133. 'action' => $action,
  134. 'reason' => $reason,
  135. 'auth_id' => $auth_id,
  136. ]);
  137. // 如果成功插入,则更新redis
  138. if($data){
  139. $key = $type==1 ? 'ban_uid' : ($type==2 ? 'ban_ip' : ($type==3 ? 'ban_device' : ''));
  140. $value = explode(',', $value);
  141. $action == 1 ? Redis::sAdd($key, ...$value) : Redis::sRem($key, ...$value);
  142. }
  143. return $data;
  144. }
  145. }