bindbox-game/internal/api/user/request_shipping_app.go
Zuncle 4353b0f053 fix(shipping): 反转运费规则为不满5件收运费,满5件包邮
- 运费预下单接口:< 5 件允许创建运费订单,>= 5 件拒绝
- 批量发货接口:< 5 件时强制校验已支付运费订单
- 单件发货接口:同样强制校验已支付运费订单
- 运费订单 remark 存入 inventory_ids JSON 用于关联
2026-03-31 21:08:33 +08:00

61 lines
2.1 KiB
Go
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package app
import (
"net/http"
"bindbox-game/internal/code"
"bindbox-game/internal/pkg/core"
)
type requestShippingRequest struct {
InventoryID int64 `json:"inventory_id"`
}
type requestShippingResponse struct {
AddressID int64 `json:"address_id"`
}
// RequestShipping 申请发货(使用默认地址)
// @Summary 申请发货
// @Description 用户已有默认地址时,申请对指定资产发货;单件发货需先支付运费;幂等校验已存在发货记录时返回已处理
// @Tags APP端.用户
// @Accept json
// @Produce json
// @Param user_id path integer true "用户ID"
// @Security LoginVerifyToken
// @Param RequestBody body requestShippingRequest true "请求参数资产ID"
// @Success 200 {object} requestShippingResponse
// @Failure 400 {object} code.Failure "参数错误/未设置默认地址/已处理"
// @Router /api/app/users/{user_id}/inventory/request-shipping [post]
func (h *handler) RequestShipping() core.HandlerFunc {
return func(ctx core.Context) {
req := new(requestShippingRequest)
rsp := new(requestShippingResponse)
if err := ctx.ShouldBindJSON(req); err != nil || req.InventoryID == 0 {
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "参数错误"))
return
}
userID := int64(ctx.SessionUserInfo().Id)
// 运费校验:单件发货一定 < 5 件,须已支付运费订单
paid, _ := h.readDB.Orders.WithContext(ctx.RequestContext()).
Where(
h.readDB.Orders.UserID.Eq(userID),
h.readDB.Orders.SourceType.Eq(shippingFeeSourceType),
h.readDB.Orders.Status.Eq(2),
).Count()
if paid == 0 {
ctx.AbortWithError(core.Error(http.StatusBadRequest, 150003, "不满5件需先支付运费"))
return
}
addrID, err := h.user.RequestShipping(ctx.RequestContext(), userID, req.InventoryID)
if err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, 10022, err.Error()))
return
}
rsp.AddressID = addrID
ctx.Payload(rsp)
}
}