AccountLogic.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. print_r($data);
  61. $data = array_map(function($item){
  62. $item['login_ip'] = $item['login_ip'].$this->getIpLocation($item['login_ip']);
  63. $item['reg_ip'] = $item['reg_ip'].$this->getIpLocation($item['reg_ip']);
  64. $item['reg_time'] = date('Y-m-d H:i:s', $item['reg_time']);
  65. $item['login_time'] = date('Y-m-d H:i:s', $item['login_time']);
  66. unset($item['user_pwd']);
  67. return $item;
  68. }, $data);
  69. return $data;
  70. }
  71. /**
  72. * 修改密码
  73. */
  74. public function updatePwd($data)
  75. {
  76. $user_pwd = password_hash($data['user_pwd'], PASSWORD_DEFAULT);
  77. print_r($data);
  78. $result = Db::connect('db_origin')->table('user_'.$data['uid']%10)->where('uid', $data['uid'])->update(['user_pwd' => $user_pwd]);
  79. return $result;
  80. }
  81. /**
  82. * 修改手机
  83. */
  84. public function updateMobile($data)
  85. {
  86. $result = Db::connect('db_origin')->table('user_'.$data['uid']%10)->where('uid', $data['uid'])->update(['mobile' => $data['mobile']]);
  87. return $result;
  88. }
  89. /**
  90. * 修改真实名
  91. */
  92. public function updateReal($data)
  93. {
  94. $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']]);
  95. return $result;
  96. }
  97. /**
  98. * 封禁列表
  99. */
  100. public function getBanList($query)
  101. {
  102. $saiType = request()->input('saiType', 'list');
  103. $page = request()->input('page', 1);
  104. $limit = request()->input('limit', 10);
  105. $orderBy = request()->input('orderBy', '');
  106. $orderType = request()->input('orderType', $this->orderType);
  107. if(empty($orderBy)) {
  108. $orderBy = $this->orderField !== '' ? $this->orderField : $this->model->getPk();
  109. }
  110. if ($saiType === 'all') {
  111. $data = Db::connect('db_game_log')->table('ban_log')->where($query)->order($orderBy, $orderType)->select()->toArray();
  112. }
  113. $data = Db::connect('db_game_log')->table('ban_log')->where($query)->order($orderBy, $orderType)->paginate($limit, false, ['page' => $page])->toArray();
  114. $data['data'] = array_map(function($item) {
  115. $item['action'] = $item['action'] == 1 ? '封禁' : '解封';
  116. $item['type'] = $item['type'] == 1 ? 'UID' : ($item['type'] == 2 ? 'IP' : '设备');
  117. return $item;
  118. }, $data['data']);
  119. $data['data'] = $this->trandformListColumn($data['data'],['auth']);
  120. return $data;
  121. }
  122. /**
  123. * 添加/解除封禁
  124. */
  125. public function saveBan($data)
  126. {
  127. $type = $data['type']; // 封禁类型
  128. $value = $data['value']; // 封禁值
  129. $action = $data['action']; // 操作
  130. $reason = $data['reason']; // 理由
  131. $auth_id = $data['auth_id']; // 操作人
  132. $data = Db::connect('db_game_log')->table('ban_log')->insert([
  133. 'type' => $type,
  134. 'value' => $value,
  135. 'action' => $action,
  136. 'reason' => $reason,
  137. 'auth_id' => $auth_id,
  138. ]);
  139. // 如果成功插入,则更新redis
  140. if($data){
  141. $key = $type==1 ? 'ban_uid' : ($type==2 ? 'ban_ip' : ($type==3 ? 'ban_device' : ''));
  142. $value = explode(',', $value);
  143. $action == 1 ? Redis::sAdd($key, ...$value) : Redis::sRem($key, ...$value);
  144. }
  145. return $data;
  146. }
  147. }