1
This commit is contained in:
@@ -2,14 +2,13 @@ package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"blazing/modules/base/model"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/xiaoqidun/qqwry"
|
||||
)
|
||||
|
||||
type BaseSysLogService struct {
|
||||
@@ -31,6 +30,16 @@ func NewBaseSysLogService() *BaseSysLogService {
|
||||
Condition: `"user".id = base_sys_log."userId"`,
|
||||
},
|
||||
},
|
||||
ModifyResult: func(ctx g.Ctx, data interface{}) interface{} {
|
||||
// baseSysLog.IPAddr = fmt.Sprintf("国家:%s,省份:%s,城市:%s,区县:%s,运营商:%s\n",
|
||||
// location.Country,
|
||||
// location.Province,
|
||||
// location.City,
|
||||
// location.District,
|
||||
// location.ISP,
|
||||
// )
|
||||
return data
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -47,19 +56,19 @@ func (s *BaseSysLogService) Record(ctx g.Ctx) {
|
||||
baseSysLog.Action = r.Method + ":" + r.URL.Path
|
||||
baseSysLog.IP = r.GetClientIp()
|
||||
|
||||
// 从内存或缓存查询IP
|
||||
location, err := qqwry.QueryIP(baseSysLog.IP)
|
||||
if err != nil {
|
||||
fmt.Printf("错误:%v\n", err)
|
||||
return
|
||||
}
|
||||
baseSysLog.IPAddr = fmt.Sprintf("国家:%s,省份:%s,城市:%s,区县:%s,运营商:%s\n",
|
||||
location.Country,
|
||||
location.Province,
|
||||
location.City,
|
||||
location.District,
|
||||
location.ISP,
|
||||
)
|
||||
// // 从内存或缓存查询IP
|
||||
// location, err := qqwry.QueryIP(baseSysLog.IP)
|
||||
// if err != nil {
|
||||
// fmt.Printf("错误:%v\n", err)
|
||||
// return
|
||||
// }
|
||||
// baseSysLog.IPAddr = fmt.Sprintf("国家:%s,省份:%s,城市:%s,区县:%s,运营商:%s\n",
|
||||
// location.Country,
|
||||
// location.Province,
|
||||
// location.City,
|
||||
// location.District,
|
||||
// location.ISP,
|
||||
// )
|
||||
baseSysLog.Params = r.GetBodyString()
|
||||
m := cool.DBM(s.Model)
|
||||
if baseSysLog.UserID == 10001 {
|
||||
@@ -69,7 +78,7 @@ func (s *BaseSysLogService) Record(ctx g.Ctx) {
|
||||
"userId": baseSysLog.UserID,
|
||||
"action": baseSysLog.Action,
|
||||
"ip": baseSysLog.IP,
|
||||
"ipAddr": baseSysLog.IPAddr,
|
||||
//"ipAddr": baseSysLog.IPAddr,
|
||||
"params": baseSysLog.Params,
|
||||
})
|
||||
}
|
||||
@@ -87,10 +96,12 @@ func (s *BaseSysLogService) Clear(isAll bool) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func init() {
|
||||
// 从文件加载IP数据库
|
||||
if err := qqwry.LoadFile("public/qqwry.ipdb"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var ipdata sync.Once
|
||||
|
||||
}
|
||||
// func init() {
|
||||
// // 从文件加载IP数据库
|
||||
// if err := qqwry.LoadFile("public/qqwry.ipdb"); err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user