Files
hfb_sys/backend/internal/modules/order/handler_admin.go
T
yml2213andClaude Opus 4.8 8192344027 优化号主交接超时卡死问题
- 号主交接超时(owner_timeout)后允许补提交交接说明,避免临时延误导致订单卡死
- 后台新增"重置交接"动作,可将超时订单恢复为待号主交接并刷新计时
- 交接超时改以进入待交接时刻为基准计算,新增 handoff_started_at 字段

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 04:16:31 +08:00

115 lines
2.4 KiB
Go

package order
import (
"context"
"hfb_sys/backend/internal/middleware"
"hfb_sys/backend/pkg/response"
"github.com/gin-gonic/gin"
)
func (h *Handler) AdminList(c *gin.Context) {
page, pageSize := parsePagination(c)
result, err := h.service.ListAdmin(c.Request.Context(), page, pageSize)
if err != nil {
writeOrderError(c, err)
return
}
response.OK(c, result)
}
func (h *Handler) AdminDetail(c *gin.Context) {
id, ok := parseID(c)
if !ok {
return
}
item, err := h.service.FindAdmin(c.Request.Context(), id)
if err != nil {
writeOrderError(c, err)
return
}
response.OK(c, item)
}
func (h *Handler) AdminHandoffRecords(c *gin.Context) {
id, ok := parseID(c)
if !ok {
return
}
items, err := h.service.HandoffRecordsAdmin(c.Request.Context(), id)
if err != nil {
writeOrderError(c, err)
return
}
response.OK(c, gin.H{"items": items})
}
func (h *Handler) AdminClose(c *gin.Context) {
h.adminAction(c, h.service.AdminClose, gin.H{"closed": true})
}
func (h *Handler) AdminMarkAbnormal(c *gin.Context) {
h.adminAction(c, h.service.AdminMarkAbnormal, gin.H{"abnormal": true})
}
func (h *Handler) AdminResetHandoff(c *gin.Context) {
h.adminAction(c, h.service.AdminResetHandoff, gin.H{"reset": true})
}
func (h *Handler) AdminRefund(c *gin.Context) {
orderID, ok := parseID(c)
if !ok {
return
}
item, err := h.service.AdminRefund(c.Request.Context(), orderID)
if err != nil {
writeOrderError(c, err)
return
}
response.OK(c, item)
}
func (h *Handler) AdminRefundStatus(c *gin.Context) {
orderID, ok := parseID(c)
if !ok {
return
}
item, err := h.service.AdminRefundStatus(c.Request.Context(), orderID)
if err != nil {
writeOrderError(c, err)
return
}
response.OK(c, item)
}
func (h *Handler) adminAction(c *gin.Context, fn func(context.Context, uint64, uint64, AdminActionRequest, AuditMeta) error, okData gin.H) {
adminID, ok := currentAdminID(c)
if !ok {
response.Unauthorized(c, "缺少管理员上下文")
return
}
id, ok := parseID(c)
if !ok {
return
}
var req AdminActionRequest
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, "操作原因不能为空")
return
}
if err := fn(c.Request.Context(), adminID, id, req, auditMeta(c)); err != nil {
writeOrderError(c, err)
return
}
response.OK(c, okData)
}
func auditMeta(c *gin.Context) AuditMeta {
return AuditMeta{
IP: c.ClientIP(),
UserAgent: c.GetHeader("User-Agent"),
RequestID: middleware.GetRequestID(c),
}
}