- 运费预下单接口:< 5 件允许创建运费订单,>= 5 件拒绝 - 批量发货接口:< 5 件时强制校验已支付运费订单 - 单件发货接口:同样强制校验已支付运费订单 - 运费订单 remark 存入 inventory_ids JSON 用于关联
61 lines
2.1 KiB
Go
Executable File
61 lines
2.1 KiB
Go
Executable File
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)
|
||
}
|
||
}
|