You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
151 lines
3.7 KiB
151 lines
3.7 KiB
package global
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"pure/api/sys"
|
|
"pure/global"
|
|
"pure/model"
|
|
"pure/model/request"
|
|
"pure/model/response"
|
|
"pure/service"
|
|
"pure/utils"
|
|
)
|
|
|
|
// @Summary 获取用户收货地址列表【v1.0】
|
|
// @Security Bearer
|
|
// @Description
|
|
// @Tags 公用-收货地址
|
|
// @Success 200 {object} []model.Address "{"code": 0, "data": [...]}"
|
|
// @Success 200 {string} string "{"code": 1, "message": ""}"
|
|
// @Router /global/address [get]
|
|
func GetAddressList(c *gin.Context) {
|
|
var (
|
|
err error
|
|
userID string
|
|
req request.ReqAddress
|
|
data any
|
|
)
|
|
c.ShouldBind(&req)
|
|
userID = sys.GetUserUuid(c)
|
|
err, data = service.GetUserAddressList(userID, &req)
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
response.OkWithData(data, c)
|
|
}
|
|
|
|
// @Summary 添加收货地址【v1.0】
|
|
// @Security Bearer
|
|
// @Description
|
|
// @Tags 公用-收货地址
|
|
// @Param data body model.Address false "data..."
|
|
// @Success 200 {string} string "{"code": 0, "data": [...]}"
|
|
// @Success 200 {string} string "{"code": 1, "message": ""}"
|
|
// @Router /global/address [post]
|
|
func AddAddress(c *gin.Context) {
|
|
var (
|
|
err error
|
|
userID string
|
|
data model.Address
|
|
)
|
|
c.ShouldBindJSON(&data)
|
|
userID = sys.GetUserUuid(c)
|
|
err = service.AddUserAddressList(userID, &data)
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
response.OkWithMessage("添加成功", c)
|
|
}
|
|
|
|
// @Summary 修改收货地址【v1.0】
|
|
// @Security Bearer
|
|
// @Description
|
|
// @Tags 公用-收货地址
|
|
// @Param data body model.Address false "data..."
|
|
// @Success 200 {string} string "{"code": 0, "data": [...]}"
|
|
// @Success 200 {string} string "{"code": 1, "message": ""}"
|
|
// @Router /global/address [put]
|
|
func UpdateAddress(c *gin.Context) {
|
|
var (
|
|
err error
|
|
userID string
|
|
data model.Address
|
|
)
|
|
c.ShouldBindJSON(&data)
|
|
userID = sys.GetUserUuid(c)
|
|
err = service.UpdateAddress(userID, &data)
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
response.OkWithMessage("修改成功", c)
|
|
}
|
|
|
|
// @Summary 删除收货地址【v1.0】
|
|
// @Security Bearer
|
|
// @Description
|
|
// @Tags 公用-收货地址
|
|
// @Param data body global.BASE_ID false "data..."
|
|
// @Success 200 {string} string "{"code": 0, "data": [...]}"
|
|
// @Success 200 {string} string "{"code": 1, "message": ""}"
|
|
// @Router /global/address [delete]
|
|
func DeleteAddress(c *gin.Context) {
|
|
var (
|
|
err error
|
|
userID string
|
|
data global.BASE_ID
|
|
)
|
|
c.ShouldBindJSON(&data)
|
|
userID = sys.GetUserUuid(c)
|
|
err = service.DeleteAddress(userID, &data)
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
response.OkWithMessage("删除成功", c)
|
|
}
|
|
|
|
// @Summary 美国地区选择器【v1.0】
|
|
// @Security Bearer
|
|
// @Description
|
|
// @Tags 公用-收货地址
|
|
// @Success 200 {object} []model.UsSelect "{"code": 0, "data": [...]}"
|
|
// @Success 200 {string} string "{"code": 1, "message": ""}"
|
|
// @Router /global/usSelect [get]
|
|
func GetUsSelect(c *gin.Context) {
|
|
var (
|
|
err error
|
|
data any
|
|
)
|
|
err, data = service.GetUsSelect()
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
response.OkWithData(data, c)
|
|
}
|
|
|
|
// @Summary 查询物流信息
|
|
// @Security Bearer
|
|
// @Description
|
|
// @Tags track
|
|
// @Param data query request.IdReq false "params"
|
|
// @Success 200 {string} string "{"code": 1, "message": ""}"
|
|
// @Router /global/track [get]
|
|
func GetTrack(c *gin.Context) {
|
|
var info request.IdReq
|
|
_ = c.ShouldBindQuery(&info)
|
|
if err := utils.Verify(info, utils.IdVerify); err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
data, err := service.GetTrack(int64(info.ID))
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
response.OkWithData(data, c)
|
|
}
|
|
|