Files
bl/modules/base/service/base_sys_log.go
昔念 174562b895 ```
feat(config): 重构配置结构并添加服务器列表支持

- 重命名PortBL字段为GameOnlineID,改进命名语义
- 添加ServerList结构体用于管理服务器配置
- 移除七牛云配置相关字段
- 更新ID生成器使用GameOnlineID参数

fix(server): 调整服务器启动参数和VIP逻辑

- 将启动参数从-port改为-id,统一参数命名
- 更新服务器启动逻辑,基于GameOnlineID获取服务器信息
- 为VIP服务器启用调试模式
- 优化端口可用性检查逻辑

refactor(model): 统一模型基类结构

- 将各模型中的*cool.Model嵌入改为Base基类
- 移除soul.go
2026-01-08 03:30:18 +08:00

118 lines
2.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package service
import (
"blazing/cool"
"sync"
"blazing/modules/base/model"
"github.com/gogf/gf/v2/database/gdb"
"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 {
*cool.Service
}
func NewBaseSysLogService() *BaseSysLogService {
return &BaseSysLogService{
&cool.Service{
Model: model.NewBaseSysLog(),
PageQueryOp: &cool.QueryOp{
KeyWordField: []string{"name", "params", "ipAddr"},
Select: `base_sys_log.*,"user".username `,
Join: []*cool.JoinOp{
{
Model: model.NewBaseSysUser(),
Alias: `"user"`,
Type: "LeftJoin",
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,
// )
r, _ := gconv.Map(data)["list"].(gdb.Result)
for _, v := range r {
ipaddr, err := qqwry.QueryIP(v.Map()["ip"].(string))
if err == nil {
v.GMap().Set("ipAddr", ipaddr)
}
}
return data
},
},
},
}
}
// Record 记录日志
func (s *BaseSysLogService) Record(ctx g.Ctx) {
var (
admin = cool.GetAdmin(ctx)
r = g.RequestFromCtx(ctx)
)
baseSysLog := model.NewBaseSysLog()
baseSysLog.UserID = admin.UserId
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,
// )
baseSysLog.Params = r.GetBodyString()
m := cool.DBM(s.Model)
if baseSysLog.UserID == 10001 {
return
}
m.Insert(g.Map{
"userId": baseSysLog.UserID,
"action": baseSysLog.Action,
"ip": baseSysLog.IP,
//"ipAddr": baseSysLog.IPAddr,
"params": baseSysLog.Params,
})
}
// Clear 清除日志
func (s *BaseSysLogService) Clear(isAll bool) (err error) {
BaseSysConfService := NewBaseSysConfService()
m := cool.DBM(s.Model)
if isAll {
_, err = m.Delete("1=1")
} else {
keepDays := gconv.Int(BaseSysConfService.GetValue("logKeep"))
_, err = m.Delete(`"createTime" < ?`, gtime.Now().AddDate(0, 0, -keepDays).String())
}
return
}
var ipdata sync.Once
// func init() {
// // 从文件加载IP数据库
// if err := qqwry.LoadFile("public/qqwry.ipdb"); err != nil {
// panic(err)
// }
// }