分站公开列表和详情展示当前货架加价;下单写入 base_price / shelf_markup / markup_site_id 快照并计入实付。 支付分账改用快照加价,不再误用 PlatformFeeCent;结账不退加价,事后改价不影响历史订单。
122 lines
2.9 KiB
Go
122 lines
2.9 KiB
Go
package order
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"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 = strings.TrimSpace(c.GetHeader("X-Distribution-Site-Code"))
|
|
}
|
|
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 := strings.TrimSpace(firstNonEmpty(c.GetHeader("X-Distribution-Site-Code"), c.Query("distribution_site_code"), c.Query("site_code")))
|
|
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 := strings.TrimSpace(firstNonEmpty(c.GetHeader("X-Distribution-Site-Code"), c.Query("distribution_site_code"), c.Query("site_code")))
|
|
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 := strings.TrimSpace(firstNonEmpty(c.GetHeader("X-Distribution-Site-Code"), c.Query("distribution_site_code"), c.Query("site_code")))
|
|
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})
|
|
}
|