diff --git a/app/common/model/User.php b/app/common/model/User.php index 30e9f82..5102c79 100644 --- a/app/common/model/User.php +++ b/app/common/model/User.php @@ -5,6 +5,7 @@ use think\Model; use think\model\concern\SoftDelete; use think\facade\Db; use think\facade\Session; +use taoler\com\Api; class User extends Model { @@ -52,6 +53,24 @@ class User extends Model //将用户数据写入Session Session::set('user_id',$user['id']); Session::set('user_name',$user['name']); + $ip = request()->ip(); + $url = 'http://ip-api.com/json/'.$ip.'?lang=zh-CN'; + //$url = 'http://ip-api.com/json/?lang=zh-CN'; + $add = Api::urls($url); + if($add->status == 'success'){ + $city = $add->city; + } else { + $city ='未知'; + } + + Db::name('user')->where('id',$user['id'])->update( + [ + 'city' => $city, + 'last_login_ip' => $ip, + 'last_login_time' => time() + ] + ); + //查询结果1表示有用户,用户名密码正确 return 1; }else{ diff --git a/extend/taoler/com/Api.php b/extend/taoler/com/Api.php new file mode 100644 index 0000000..fd2d68a --- /dev/null +++ b/extend/taoler/com/Api.php @@ -0,0 +1,26 @@ +-1,'msg'=>'800']); + } + $ch =curl_init (); + curl_setopt($ch,CURLOPT_URL, $url); + curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 20); + curl_setopt($ch,CURLOPT_POST, 1); + $data = curl_exec($ch); + $httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE); + curl_close($ch); + if($httpCode == '200'){ + return json_decode($data); + } else { + return json(['code'=>-1,'msg'=>'Զ̷ʧ']); + } + } +} \ No newline at end of file diff --git a/public/static/admin/modules/useradmin.js b/public/static/admin/modules/useradmin.js index 75fefe5..13b514c 100644 --- a/public/static/admin/modules/useradmin.js +++ b/public/static/admin/modules/useradmin.js @@ -26,7 +26,9 @@ layui.define(['table', 'form'], function(exports){ ,{field: 'email', title: '邮箱'} ,{field: 'sex', width: 60, title: '性别',templet: '#sex'} ,{field: 'ip', title: '登录IP'} - ,{field: 'jointime', title: '申请时间', sort: true} + ,{field: 'city', title: '城市'} + ,{field: 'logintime', title: '最后登录', sort: true} + ,{field: 'jointime', title: '注册时间', sort: true} ,{field: 'check', title: '状态', templet: '#buttonCheck', minWidth: 80, align: 'center'} ,{field: 'auth', title: '超级管理员', templet: '#buttonAuth', minWidth: 80, align: 'center'} ,{title: '操作', width: 150, align:'center', fixed: 'right', toolbar: '#table-useradmin-webuser'}