feat(admin): 新增管理后台前端资源文件 feat(api): 实现获取用户统计数据的API接口 - 添加获取用户道具卡数量、优惠券数量和积分余额的接口 - 实现设置默认地址和删除地址的接口 feat(service): 新增用户统计服务方法 - 实现GetUserStats方法查询用户统计数据 - 添加地址管理相关服务方法 fix(core): 修复静态资源路由问题 - 调整静态资源路由配置 - 优化404路由处理逻辑 chore: 更新前端构建配置 - 添加Windows平台构建命令 - 更新README构建说明
70 lines
2.4 KiB
Go
70 lines
2.4 KiB
Go
package app
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"bindbox-game/internal/code"
|
|
"bindbox-game/internal/pkg/core"
|
|
"bindbox-game/internal/pkg/validation"
|
|
usersvc "bindbox-game/internal/service/user"
|
|
)
|
|
|
|
type addAddressRequest struct {
|
|
Name string `json:"name"`
|
|
Mobile string `json:"mobile"`
|
|
Province string `json:"province"`
|
|
City string `json:"city"`
|
|
District string `json:"district"`
|
|
Address string `json:"address"`
|
|
IsDefault bool `json:"is_default"`
|
|
}
|
|
|
|
type addAddressResponse struct {
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
// AddUserAddress 新增用户地址
|
|
// @Summary 新增用户地址
|
|
// @Description 为当前登录用户新增收货地址,可选择设为默认
|
|
// @Tags APP端.用户
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param user_id path integer true "用户ID"
|
|
// @Security LoginVerifyToken
|
|
// @Param RequestBody body addAddressRequest true "请求参数"
|
|
// @Success 200 {object} addAddressResponse
|
|
// @Failure 400 {object} code.Failure "参数错误"
|
|
// @Failure 401 {object} code.Failure "未授权"
|
|
// @Failure 500 {object} code.Failure "服务器内部错误"
|
|
// @Router /api/app/users/{user_id}/addresses [post]
|
|
func (h *handler) AddUserAddress() core.HandlerFunc {
|
|
return func(ctx core.Context) {
|
|
req := new(addAddressRequest)
|
|
rsp := new(addAddressResponse)
|
|
if err := ctx.ShouldBindJSON(req); err != nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, validation.Error(err)))
|
|
return
|
|
}
|
|
if req.Name == "" || req.Mobile == "" || req.Province == "" || req.City == "" || req.District == "" || req.Address == "" {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "缺少必要参数"))
|
|
return
|
|
}
|
|
userID := int64(ctx.SessionUserInfo().Id)
|
|
in := usersvc.AddAddressInput{
|
|
Name: req.Name,
|
|
Mobile: req.Mobile,
|
|
Province: req.Province,
|
|
City: req.City,
|
|
District: req.District,
|
|
Address: req.Address,
|
|
IsDefault: req.IsDefault,
|
|
}
|
|
row, err := h.user.AddAddress(ctx.RequestContext(), userID, in)
|
|
if err != nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, 10011, err.Error()))
|
|
return
|
|
}
|
|
rsp.ID = row.ID
|
|
ctx.Payload(rsp)
|
|
}
|
|
} |