- 新增 internal/sitecode 包:FromRequest 头优先解析、FromQueryThenHeader 探测接口专用、ExtractHost/IsLocalHost 提取 Host 域名 - 替换 auth/order/listing/chat/notification/withdrawal/wallet/distribution 八模块 17 处各自内联的解析逻辑,统一优先级与 TrimSpace 行为 - 修复 notification 漏 TrimSpace、探测接口会话头压过显式 query、 GetPublicSiteInfo 把 localhost Host 当站点域名查库等不一致 - 顺手清理 auth 中无引用的 extractHost 死代码 - gofmt 修复 withdrawal/presenter、chat/file/payment 测试四个历史遗留格式问题
123 lines
2.6 KiB
Go
123 lines
2.6 KiB
Go
package order
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"hfb_sys/backend/internal/sitecode"
|
|
"hfb_sys/backend/pkg/response"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func (h *Handler) Create(c *gin.Context) {
|
|
userID, ok := currentUserID(c)
|
|
if !ok {
|
|
response.Unauthorized(c, "缺少用户上下文")
|
|
return
|
|
}
|
|
var req CreateRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.BadRequest(c, "订单信息不完整")
|
|
return
|
|
}
|
|
if strings.TrimSpace(req.DistributionSiteCode) == "" {
|
|
req.DistributionSiteCode = sitecode.FromRequest(c)
|
|
}
|
|
item, err := h.service.Create(c.Request.Context(), userID, req)
|
|
if err != nil {
|
|
writeOrderError(c, err)
|
|
return
|
|
}
|
|
response.Created(c, item)
|
|
}
|
|
|
|
func (h *Handler) List(c *gin.Context) {
|
|
userID, ok := currentUserID(c)
|
|
if !ok {
|
|
response.Unauthorized(c, "缺少用户上下文")
|
|
return
|
|
}
|
|
page, pageSize := parsePagination(c)
|
|
siteCode := sitecode.FromRequest(c)
|
|
items, err := h.service.ListForUser(c.Request.Context(), userID, page, pageSize, siteCode)
|
|
if err != nil {
|
|
writeOrderError(c, err)
|
|
return
|
|
}
|
|
response.OK(c, items)
|
|
}
|
|
|
|
func (h *Handler) ListSellerHandoffs(c *gin.Context) {
|
|
userID, ok := currentUserID(c)
|
|
if !ok {
|
|
response.Unauthorized(c, "缺少用户上下文")
|
|
return
|
|
}
|
|
page, pageSize := parsePagination(c)
|
|
siteCode := sitecode.FromRequest(c)
|
|
items, err := h.service.ListSellerHandoffs(c.Request.Context(), userID, SellerHandoffQuery{
|
|
Page: page,
|
|
PageSize: pageSize,
|
|
Status: c.Query("status"),
|
|
SiteCode: siteCode,
|
|
})
|
|
if err != nil {
|
|
writeOrderError(c, err)
|
|
return
|
|
}
|
|
response.OK(c, items)
|
|
}
|
|
|
|
func (h *Handler) Detail(c *gin.Context) {
|
|
userID, ok := currentUserID(c)
|
|
if !ok {
|
|
response.Unauthorized(c, "缺少用户上下文")
|
|
return
|
|
}
|
|
id, ok := parseID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
siteCode := sitecode.FromRequest(c)
|
|
item, err := h.service.FindForUser(c.Request.Context(), userID, id, siteCode)
|
|
if err != nil {
|
|
writeOrderError(c, err)
|
|
return
|
|
}
|
|
response.OK(c, item)
|
|
}
|
|
|
|
func (h *Handler) Cancel(c *gin.Context) {
|
|
userID, ok := currentUserID(c)
|
|
if !ok {
|
|
response.Unauthorized(c, "缺少用户上下文")
|
|
return
|
|
}
|
|
id, ok := parseID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
if err := h.service.Cancel(c.Request.Context(), userID, id); err != nil {
|
|
writeOrderError(c, err)
|
|
return
|
|
}
|
|
response.OK(c, gin.H{"cancelled": true})
|
|
}
|
|
|
|
func (h *Handler) Pay(c *gin.Context) {
|
|
userID, ok := currentUserID(c)
|
|
if !ok {
|
|
response.Unauthorized(c, "缺少用户上下文")
|
|
return
|
|
}
|
|
id, ok := parseID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
if err := h.service.Pay(c.Request.Context(), userID, id); err != nil {
|
|
writeOrderError(c, err)
|
|
return
|
|
}
|
|
response.OK(c, gin.H{"paid": true})
|
|
}
|