- 订单列表使用独立最小 DTO 并分页,号主待办提供独立接口与统计 - 用户 token 增加版本控制,冻结/改密/退出即时撤销会话 - 移除 URL token 传参,SSE 与接口统一使用 HttpOnly Cookie - 私有文件按上传归属与业务关联授权,收款凭证转私有访问并校验归属 - 公开商品接口返回最小字段,隐藏号主身份与内部状态 - 每日清理超过 30 天未关联业务的上传归属,上传归属失败时补偿删除对象
113 lines
2.3 KiB
Go
113 lines
2.3 KiB
Go
package order
|
|
|
|
import (
|
|
"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
|
|
}
|
|
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)
|
|
items, err := h.service.ListForUser(c.Request.Context(), userID, page, pageSize)
|
|
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)
|
|
items, err := h.service.ListSellerHandoffs(c.Request.Context(), userID, SellerHandoffQuery{
|
|
Page: page,
|
|
PageSize: pageSize,
|
|
Status: c.Query("status"),
|
|
})
|
|
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
|
|
}
|
|
item, err := h.service.FindForUser(c.Request.Context(), userID, id)
|
|
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})
|
|
}
|