完善日志和审计链路
This commit is contained in:
@@ -3,6 +3,8 @@ package dispute
|
||||
import (
|
||||
"time"
|
||||
|
||||
"hfb_sys/backend/internal/auditlog"
|
||||
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
@@ -36,10 +38,7 @@ type ArbitrateRequest struct {
|
||||
Remark string `json:"remark" binding:"required"`
|
||||
Amount float64 `json:"amount"`
|
||||
}
|
||||
type AuditMeta struct {
|
||||
IP string
|
||||
UserAgent string
|
||||
}
|
||||
type AuditMeta = auditlog.Meta
|
||||
|
||||
type PaginatedResult struct {
|
||||
Items []DisputeDTO `json:"items"`
|
||||
|
||||
@@ -100,10 +100,7 @@ func (h *Handler) AdminArbitrate(c *gin.Context) {
|
||||
response.BadRequest(c, "仲裁结果和备注不能为空")
|
||||
return
|
||||
}
|
||||
item, err := h.service.Arbitrate(adminID, id, req, AuditMeta{
|
||||
IP: c.ClientIP(),
|
||||
UserAgent: c.GetHeader("User-Agent"),
|
||||
})
|
||||
item, err := h.service.Arbitrate(adminID, id, req, auditMeta(c))
|
||||
if err != nil {
|
||||
writeDisputeError(c, err)
|
||||
return
|
||||
@@ -111,6 +108,14 @@ func (h *Handler) AdminArbitrate(c *gin.Context) {
|
||||
response.OK(c, item)
|
||||
}
|
||||
|
||||
func auditMeta(c *gin.Context) AuditMeta {
|
||||
return AuditMeta{
|
||||
IP: c.ClientIP(),
|
||||
UserAgent: c.GetHeader("User-Agent"),
|
||||
RequestID: middleware.GetRequestID(c),
|
||||
}
|
||||
}
|
||||
|
||||
func currentAdminID(c *gin.Context) (uint64, bool) {
|
||||
value, ok := c.Get(middleware.ContextAdminID)
|
||||
if !ok {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"hfb_sys/backend/internal/auditlog"
|
||||
"hfb_sys/backend/internal/model"
|
||||
"hfb_sys/backend/internal/modules/notification"
|
||||
"hfb_sys/backend/internal/modules/wallet"
|
||||
@@ -470,21 +471,15 @@ func disputeType(input string, isCheckoutDispute bool) string {
|
||||
}
|
||||
|
||||
func appendAuditLog(tx *gorm.DB, actorID uint64, action string, bizType string, bizID uint64, meta AuditMeta, detail map[string]any) error {
|
||||
raw, err := json.Marshal(detail)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
row := model.AuditLog{
|
||||
return auditlog.Append(tx, auditlog.Entry{
|
||||
ActorType: "admin",
|
||||
ActorID: actorID,
|
||||
Action: action,
|
||||
BizType: bizType,
|
||||
BizID: &bizID,
|
||||
IP: meta.IP,
|
||||
UserAgent: meta.UserAgent,
|
||||
Detail: datatypes.JSON(raw),
|
||||
}
|
||||
return tx.Create(&row).Error
|
||||
Meta: meta,
|
||||
Detail: detail,
|
||||
})
|
||||
}
|
||||
|
||||
func IsNotFound(err error) bool {
|
||||
|
||||
Reference in New Issue
Block a user