48 lines
1.6 KiB
Go
Executable File
48 lines
1.6 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)
|
||
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)
|
||
}
|
||
}
|