This commit is contained in:
1
2026-01-06 15:22:20 +00:00
parent f0d9dfe0e8
commit 69a2d9e510
3 changed files with 42 additions and 26 deletions

View File

@@ -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)
// }
// }