feat: 增加IP数据库调用

This commit is contained in:
Ying
2023-07-04 18:42:41 +08:00
parent 78160b8058
commit 4c1f46e36a
5 changed files with 267 additions and 15 deletions

View File

@@ -15,11 +15,9 @@ namespace app\admin\controller\system;
use app\admin\service\UserService;
use app\AdminController;
use app\common\exception\OperateException;
use app\common\library\Ip2Region;
use app\common\model\system\User as UserModel;
use app\common\model\system\UserGroup as UserGroupModel;
use support\Response;
use system\Random;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

View File

@@ -12,9 +12,9 @@ declare (strict_types=1);
namespace app\admin\service;
use app\common\exception\OperateException;
use app\common\library\Ip2Region;
use app\common\model\system\User;
use app\common\model\system\UserGroup;
use system\IpLocation;
use system\Random;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
@@ -54,14 +54,15 @@ class UserService
$list = $model->where($conditions)->order("id asc")->limit($limit)->page($page)->select();
// 循环处理数据
$userGroup = (new UserGroup)->select()->toArray();
$qqWry = new IpLocation();
foreach ($list as $key => $value) {
$value->hidden(['pwd', 'salt']);
try {
$region = Ip2Region::instance()->memorySearch($value['login_ip']);
$region = $qqWry->getLocation($value['login_ip']);
$region = $region['country'] . ' ' . $region['area'];
} catch (\Exception $e) {
$region = ['region' => '未知|未知|未知'];
$region = 'unKnown';
}
$region = explode('|',$region['region']);
$list[$key]['region'] = $region;
$result = list_search($userGroup,['id'=> $value['group_id']]);
if (!empty($result)) {