Files
web_huangguo2_server/app/api/rechargeapi/recharge.go
T
2026-09-29 10:47:38 +08:00

86 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 rechargeapi
import (
"videoweb/app/service/rechargeser"
"videoweb/pub/common"
"videoweb/pub/common/enum/consts"
"videoweb/pub/common/ipaddr"
"videoweb/pub/common/srvdef"
"github.com/gin-gonic/gin"
)
type submitOrderReq struct {
PackageId int64 `json:"packageId" binding:"required"` // 购买套餐ID(会员畅享)
PayMode string `json:"payMode" binding:"required"` // 支付方式:alipay/wechat
}
// SubmitOrder 发起第三方支付下单
// @Tags 充值
// @Summary 创建 VIP 充值订单(第三方支付)
// @Accept json
// @Produce json
// @Param param body submitOrderReq true "下单参数"
// @Success 200 {object} rechargeser.SubmitOrderResp "支付链接"
// @Security ApiKeyAuth
// @Router /api/app/vip/pay [POST]
func SubmitOrder(ctx *gin.Context) {
var req submitOrderReq
if err := ctx.ShouldBind(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
userId := common.GetUserId(ctx)
sysType := ctx.GetString(consts.CtxSysType)
devType := ctx.GetString(consts.CtxDevType)
ip := ipaddr.ResolveClientIP(ctx)
user, serr := rechargeser.GetUserInfo(ctx, userId)
if serr != nil || user == nil {
common.ServerJSON(ctx, srvdef.ErrUserNotExsit, nil)
return
}
resp, serr := rechargeser.CreateOrder(ctx, userId, user.NickName, req.PackageId, req.PayMode, sysType, devType, ip, user.DistrictCode)
if serr != nil {
common.ServerJSON(ctx, serr.Code, serr.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
type orderHistoryReq struct {
Page int64 `json:"page" form:"page"`
PageSize int64 `json:"pageSize" form:"pageSize"`
}
// GetOrderHistory 查询当前用户 VIP 订单历史
// @Tags 充值
// @Summary 查询 VIP 充值记录
// @Accept json
// @Produce json
// @Param page query int false "页码(默认1)"
// @Param pageSize query int false "每页数量(默认10)"
// @Success 200 {array} vipordermod.VipOrder "订单列表"
// @Security ApiKeyAuth
// @Router /api/app/vip/orders [GET]
func GetOrderHistory(ctx *gin.Context) {
var req orderHistoryReq
_ = ctx.ShouldBindQuery(&req)
if req.Page <= 0 {
req.Page = 1
}
if req.PageSize <= 0 {
req.PageSize = 10
}
userId := common.GetUserId(ctx)
list, total, serr := rechargeser.GetOrderHistory(ctx, userId, req.Page, req.PageSize)
if serr != nil {
common.ServerJSON(ctx, serr.Code, serr.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, gin.H{"total": total, "list": list})
}