model = new Account(); } /** * 获取IP地理位置 */ public function getIpLocation($ip): string { $ip2region = new \Ip2Region(); try { $region = $ip2region->memorySearch($ip); } catch (\Exception $e) { return '未知'; } list($country, $number, $province, $city, $network) = explode('|', $region['region']); if ($network === '内网IP') { return $network; } if ($country == '中国') { return $province.'-'.$city.':'.$network; } else if ($country == '0') { return '未知'; } else { return $country; } } /** * 列表 */ public function list($query) { if($query['type'] == '1'){ $uid = Db::connect('db_origin')->table('users')->where('user_name', $query['val'])->value('uid'); $data = Db::connect('db_origin')->table('user_'.$uid%10)->where('uid', $uid)->select()->toArray(); }else{ $data = Db::connect('db_origin')->table('user_'.$query['val']%10)->where('uid', $query['val'])->select()->toArray(); } $data = array_map(function($item){ $item['login_ip'] = $item['login_ip'].$this->getIpLocation($item['login_ip']); $item['reg_ip'] = $item['reg_ip'].$this->getIpLocation($item['reg_ip']); $item['reg_time'] = date('Y-m-d H:i:s', $item['reg_time']); $item['login_time'] = date('Y-m-d H:i:s', $item['login_time']); $item['pay_time'] = $item['pay_time'] == 0 ? '' : date('Y-m-d H:i:s', $item['pay_time']); $item['id_card'] = $item['id_card'] == '' ? '' : substr($item['id_card'], 0, 4).'****'.substr($item['id_card'], -4); unset($item['user_pwd']); return $item; }, $data); return $data; } /** * 修改密码 */ public function updatePwd($data) { $user_pwd = password_hash($data['user_pwd'], PASSWORD_DEFAULT); return Db::connect('db_origin')->table('user_'.$data['uid']%10)->where('uid', $data['uid'])->update(['user_pwd' => $user_pwd]); } /** * 修改手机 */ public function updateMobile($data) { return Db::connect('db_origin')->table('user_'.$data['uid']%10)->where('uid', $data['uid'])->update(['mobile' => $data['mobile']]); } /** * 修改真实名 */ public function updateReal($data) { 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']]); } /** * 封禁列表 */ public function getBanList($query) { $saiType = request()->input('saiType', 'list'); $page = request()->input('page', 1); $limit = request()->input('limit', 10); $orderBy = request()->input('orderBy', ''); $orderType = request()->input('orderType', $this->orderType); if(empty($orderBy)) { $orderBy = $this->orderField !== '' ? $this->orderField : $this->model->getPk(); } if ($saiType === 'all') { $data = Db::connect('db_game_log')->table('ban_log')->where($query)->order($orderBy, $orderType)->select()->toArray(); }else{ $data = Db::connect('db_game_log')->table('ban_log')->where($query)->order($orderBy, $orderType)->paginate($limit)->toArray(); } $data['data'] = array_map(function($item) { $item['action'] = $item['action'] == 1 ? '封禁' : '解封'; $item['type'] = $item['type'] == 1 ? 'UID' : ($item['type'] == 2 ? 'IP' : '设备'); return $item; }, $data['data']); $data['data'] = $this->trandformListColumn($data['data'],['auth']); return $data; } /** * 添加/解除封禁 */ public function saveBan($data) { $type = $data['type']; // 封禁类型 $value = $data['value']; // 封禁值 $action = $data['action']; // 操作 $reason = $data['reason']; // 理由 $auth_id = $data['auth_id']; // 操作人 $data = Db::connect('db_game_log')->table('ban_log')->insert([ 'type' => $type, 'value' => $value, 'action' => $action, 'reason' => $reason, 'auth_id' => $auth_id, ]); // 如果成功插入,则更新redis if($data){ $key = $type==1 ? 'ban_uid' : ($type==2 ? 'ban_ip' : ($type==3 ? 'ban_device' : '')); $value = explode(',', $value); $action == 1 ? Redis::sAdd($key, ...$value) : Redis::sRem($key, ...$value); } return $data; } }