AccountLogic.php 5.1 KB

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