bindbox-game/internal/api/user/request_shipping_batch_app.go
邹方成 45815bfb7d chore: 清理无用文件与优化代码结构
refactor(utils): 修复密码哈希比较逻辑错误
feat(user): 新增按状态筛选优惠券接口
docs: 添加虚拟发货与任务中心相关文档
fix(wechat): 修正Code2Session上下文传递问题
test: 补充订单折扣与积分转换测试用例
build: 更新配置文件与构建脚本
style: 清理多余的空行与注释
2025-12-18 17:35:55 +08:00

64 lines
2.4 KiB
Go
Raw 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 (
"bindbox-game/internal/code"
"bindbox-game/internal/pkg/core"
"bindbox-game/internal/pkg/validation"
"net/http"
)
type requestShippingBatchRequest struct {
InventoryIDs []int64 `json:"inventory_ids"`
AddressID *int64 `json:"address_id"`
}
type requestShippingBatchResponse struct {
AddressID int64 `json:"address_id"`
SuccessIDs []int64 `json:"success_ids"`
Skipped []map[string]any `json:"skipped"`
Failed []map[string]any `json:"failed"`
}
// RequestShippingBatch 批量申请发货(使用默认地址或指定地址)
// @Summary 批量申请发货
// @Description 为多个资产申请发货,校验所有权与状态;幂等:已申请的资产跳过
// @Tags APP端.用户
// @Accept json
// @Produce json
// @Security LoginVerifyToken
// @Param user_id path integer true "用户ID"
// @Param RequestBody body requestShippingBatchRequest true "请求参数资产ID列表与可选地址ID"
// @Success 200 {object} requestShippingBatchResponse
// @Failure 400 {object} code.Failure
// @Router /api/app/users/{user_id}/inventory/request-shipping-batch [post]
func (h *handler) RequestShippingBatch() core.HandlerFunc {
return func(ctx core.Context) {
req := new(requestShippingBatchRequest)
rsp := new(requestShippingBatchResponse)
if err := ctx.ShouldBindJSON(req); err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, validation.Error(err)))
return
}
if len(req.InventoryIDs) == 0 || len(req.InventoryIDs) > 100 {
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "invalid inventory_ids"))
return
}
userID := int64(ctx.SessionUserInfo().Id)
addrID, success, skipped, failed, err := h.user.RequestShippings(ctx.RequestContext(), userID, req.InventoryIDs, req.AddressID)
if err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, 10023, err.Error()))
return
}
rsp.AddressID = addrID
rsp.SuccessIDs = success
for _, s := range skipped {
rsp.Skipped = append(rsp.Skipped, map[string]any{"id": s.ID, "reason": s.Reason})
}
for _, f := range failed {
rsp.Failed = append(rsp.Failed, map[string]any{"id": f.ID, "reason": f.Reason})
}
ctx.Payload(rsp)
}
}