feat: remove shipping settings, use shipping templates for cart calculation
Build and Push Docker Image / build-and-push (push) Successful in 1m0s
Build and Push Docker Image / deploy (push) Successful in 7s

This commit is contained in:
nuyue
2026-07-12 20:01:03 +08:00
parent d7716b463b
commit bdefa34d41
6 changed files with 112 additions and 14 deletions
@@ -258,3 +258,20 @@ func CalculateShippingFee(templateID *uint, weight float64, quantity int, subtot
return template.FirstFee + additionalCount*template.AdditionalFee, nil
}
// CalculateForUser 用户端计算运费接口
func (h *ShippingTemplateHandler) CalculateForUser(c *gin.Context) {
var req schemas.CalculateShippingRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
fee, err := CalculateShippingFee(req.TemplateID, req.Weight, req.Quantity, req.Subtotal, req.Province)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "计算运费失败"})
return
}
c.JSON(http.StatusOK, gin.H{"data": gin.H{"shipping_fee": fee}})
}
+1
View File
@@ -72,6 +72,7 @@ func SetupRoutes(r *gin.Engine) {
api.GET("/settings/public", systemHandler.GetPublicSettings)
api.GET("/payment-channels", paymentChannelHandler.PublicList)
api.POST("/payment/bepusdt/notify", paymentHandler.BepUsdtNotify)
api.POST("/shipping/calculate", shippingTemplateHandler.CalculateForUser)
authed := api.Group("")
authed.Use(middlewares.AuthMiddleware())
@@ -26,4 +26,13 @@ type UpdateShippingTemplateRequest struct {
Provinces []string `json:"provinces"`
IsDefault *bool `json:"is_default"`
SortOrder *int `json:"sort_order"`
}
// CalculateShippingRequest 计算运费请求
type CalculateShippingRequest struct {
TemplateID *uint `json:"template_id"`
Weight float64 `json:"weight"`
Quantity int `json:"quantity"`
Subtotal float64 `json:"subtotal"`
Province string `json:"province"`
}