feat: 支付闭环
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
common "sundynix-go/model/commom/request"
|
||||
"sundynix-go/model/commom/response"
|
||||
"sundynix-go/model/radio/request"
|
||||
radioRes "sundynix-go/model/radio/response"
|
||||
"sundynix-go/utils/auth"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -29,7 +30,6 @@ func (a *SubscriptionApi) GetSubscriptionList(c *gin.Context) {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
list, total, err := subscriptionService.GetUserSubscription(userId, req)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取订阅列表失败!", zap.Error(err))
|
||||
@@ -44,91 +44,30 @@ func (a *SubscriptionApi) GetSubscriptionList(c *gin.Context) {
|
||||
}, c)
|
||||
}
|
||||
|
||||
// CanSubscribe 检查是否可以订阅
|
||||
// UnlockChannel 解锁频道(拉起支付)
|
||||
// @Tags 订阅管理
|
||||
// @Summary 检查是否可以订阅
|
||||
// @Summary 解锁频道
|
||||
// @Param id query string true "id"
|
||||
// @Param eventType query string true "eventType"
|
||||
// @Produce application/json
|
||||
// @Param data body request.SubscribeChannel true "频道ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/subscription/can-subscribe [post]
|
||||
func (a *SubscriptionApi) CanSubscribe(c *gin.Context) {
|
||||
userId := auth.GetUserId(c)
|
||||
var req request.SubscribeChannel
|
||||
// @Router /radio/subscription/unlock [post]
|
||||
func (a *SubscriptionApi) UnlockChannel(c *gin.Context) {
|
||||
var req request.UnlockChannel
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
can, _, err := subscriptionService.CanSubscribe(userId, req.ChannelId)
|
||||
if err != nil {
|
||||
global.Logger.Error("检查订阅权限失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithData(can, c)
|
||||
}
|
||||
|
||||
// Subscribe 订阅频道
|
||||
// @Tags 订阅管理
|
||||
// @Summary 订阅频道
|
||||
// @Produce application/json
|
||||
// @Param data body request.SubscribeChannel true "频道ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/subscription/subscribe [post]
|
||||
func (a *SubscriptionApi) Subscribe(c *gin.Context) {
|
||||
userId := auth.GetUserId(c)
|
||||
var req request.SubscribeChannel
|
||||
err := c.ShouldBindJSON(&req)
|
||||
res, no, err := subscriptionService.UnlockChannel(userId, req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
can, reason, err := subscriptionService.CanSubscribe(userId, req.ChannelId)
|
||||
if err != nil {
|
||||
global.Logger.Error("订阅失败!", zap.Error(err))
|
||||
global.Logger.Error("解锁频道失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if !can {
|
||||
response.FailWithMsg(reason, c)
|
||||
return
|
||||
}
|
||||
|
||||
// 订阅类型 1:免费
|
||||
if err := subscriptionService.Subscribe(userId, req.ChannelId, 1); err != nil {
|
||||
global.Logger.Error("订阅失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithMsg("订阅成功", c)
|
||||
}
|
||||
|
||||
// Unsubscribe 退订频道
|
||||
// @Tags 订阅管理
|
||||
// @Summary 退订频道
|
||||
// @Produce application/json
|
||||
// @Param data body request.UnsubscribeChannel true "频道ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/subscription/unsubscribe [post]
|
||||
func (a *SubscriptionApi) Unsubscribe(c *gin.Context) {
|
||||
userId := auth.GetUserId(c)
|
||||
var req request.UnsubscribeChannel
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := subscriptionService.Unsubscribe(userId, req.ChannelId); err != nil {
|
||||
global.Logger.Error("退订失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithMsg("退订成功", c)
|
||||
response.OkWithData(radioRes.PrePayResult{
|
||||
Payments: res,
|
||||
OutTradeNo: no,
|
||||
}, c)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user