package utils import ( "context" "lone-services/pkg/logRedis" "time" jsoniter "github.com/json-iterator/go" "github.com/zeromicro/go-zero/core/logx" ) const ( LogActionTypeAdd = 1 //增加 LogActionTypeEdit = 2 //编辑 LogActionTypeDel = 3 //删除 LogActionTypeOut = 4 //强退 LogActionTypeDown = 5 //下载 LogActionTypeStatus = 6 //状态 LogActionTypePassword = 7 //修改密码 LogActionTypeSort = 8 //排序 //增加、删除、修改时需要改 services.log中的返回值 LogActionModuleAdmin = "管理员管理" LogActionModuleRole = "角色管理" LogActionModuleService = "服务管理" LogActionModuleAuthority = "权限管理" LogActionModuleProduct = "产品管理" LogActionModuleUser = "用户管理" LogActionModuleOrder = "订单管理" LogActionModuleSale = "销售管理" LogActionModuleTask = "提成与任务管理" LogActionModuleAccount = "结算管理" LogActionModulePay = "支付管理" LogActionModuleStore = "服务商管理" LogActionModuleExpress = "快递管理" LogActionModuleEquipment = "设备管理" LogActionModuleAd = "广告管理" LogActionModuleCustomService = "客服管理" LogActionModuleWorkWeChat = "企业微信管理" LogActionModuleOther = "其他管理" LogActionModulePrison = "监狱管理" LogActionModuleThirdParty = "第三方管理" LogActionModuleBill = "票据管理" LogActionModuleWarehouse = "仓库管理" LogActionModuleBuy = "采购管理" LogActionModuleLog = "日志管理" LogActionModuleFactory = "工厂管理" ) type ActionLog struct { Content string `json:"content"` AdminId int64 `json:"admin_id"` AdminName string `json:"admin_name"` Type int32 `json:"type"` ModuleName string `json:"module_name"` Ip string `json:"ip"` BrowserInfo string `json:"browser_info"` BrowserName string `json:"browser_name"` BrowserVersion string `json:"browser_version"` Reason string `json:"reason"` CreateTime string `json:"create_time"` } type ActionAdd struct { NewContent interface{} `json:"new_content"` OldContent interface{} `json:"old_content"` Reason string `json:"reason"` Type int32 `json:"type"` ModuleName string `json:"module_name"` } type LoginLog struct { AdminId int64 `json:"admin_id"` Ip string `json:"ip"` Name string `json:"name"` BrowserInfo string `json:"browser_info"` BrowserName string `json:"browser_name"` BrowserVersion string `json:"browser_version"` Status int32 `json:"status"` CreateTime string `json:"create_time"` Reason string `json:"reason"` } const LoginReasonOK = "OK" const LogActionQueueKey = "log:queue:action" const LogLoginQueueKey = "log:queue:login" func SetActionLog(adminInfo UserInfo, info ActionAdd) { content := map[string]interface{}{ "old_content": info.OldContent, "new_content": info.NewContent, } jsonData, _ := jsoniter.Marshal(content) log := ActionLog{ Content: string(jsonData), AdminId: adminInfo.ID, AdminName: adminInfo.Name, Type: info.Type, ModuleName: info.ModuleName, Ip: adminInfo.ClientIP, BrowserInfo: adminInfo.UserAgent, BrowserName: adminInfo.BrowserName, BrowserVersion: adminInfo.BrowserVer, Reason: info.Reason, CreateTime: Now().Format(time.DateTime), } logJson, err := jsoniter.Marshal(log) if err != nil { logx.Errorf("marshal ActionLog failed: %v", err) return } logRedis.LogRedisClient.LPush(context.Background(), LogActionQueueKey, string(logJson)).Result() } func SetLoginLog(adminInfo UserInfo, status bool, reason string) { st := 2 if status { st = 1 } log := LoginLog{ AdminId: adminInfo.ID, Name: adminInfo.Name, Ip: adminInfo.ClientIP, BrowserInfo: adminInfo.UserAgent, BrowserName: adminInfo.BrowserName, BrowserVersion: adminInfo.BrowserVer, Status: int32(st), CreateTime: Now().Format(time.DateTime), Reason: reason, } logJson, err := jsoniter.Marshal(log) if err != nil { logx.Errorf("marshal ActionLog failed: %v", err) return } logRedis.LogRedisClient.LPush(context.Background(), LogLoginQueueKey, string(logJson)).Result() }