feat: remove shipping settings, use shipping templates for cart calculation
This commit is contained in:
@@ -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}})
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
Reference in New Issue
Block a user