82 lines
2.1 KiB
Go
82 lines
2.1 KiB
Go
package radio
|
|
|
|
import (
|
|
"sundynix-go/global"
|
|
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"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type SubscriptionApi struct{}
|
|
|
|
// GetSubscriptionList 获取订阅列表
|
|
// @Tags 订阅管理
|
|
// @Summary 获取我的订阅列表
|
|
// @Accept application/json
|
|
// @Produce application/json
|
|
// @Param data body request.GetSubscriptionList true "分页查询"
|
|
// @Success 200 {object} response.Response
|
|
// @Router /radio/subscription/list [post]
|
|
func (a *SubscriptionApi) GetSubscriptionList(c *gin.Context) {
|
|
userId := auth.GetUserId(c)
|
|
if userId == "" || userId == "0" {
|
|
response.FailWithMsg("用户未登录", c)
|
|
return
|
|
}
|
|
var req common.PageInfo
|
|
err := c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
response.FailWithMsg("参数错误: "+err.Error(), c)
|
|
return
|
|
}
|
|
list, total, err := subscriptionService.GetUserSubscription(userId, req)
|
|
if err != nil {
|
|
global.Logger.Error("获取订阅列表失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
response.OkWithData(response.PageResult{
|
|
List: list,
|
|
Total: total,
|
|
Page: req.Current,
|
|
}, c)
|
|
}
|
|
|
|
// UnlockChannel 解锁频道(拉起支付)
|
|
// @Tags 订阅管理
|
|
// @Summary 解锁频道
|
|
// @Param id query string true "id"
|
|
// @Param eventType query string true "eventType"
|
|
// @Produce application/json
|
|
// @Success 200 {object} response.Response
|
|
// @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
|
|
}
|
|
userId := auth.GetUserId(c)
|
|
if userId == "" || userId == "0" {
|
|
response.FailWithMsg("用户未登录", c)
|
|
return
|
|
}
|
|
res, no, err := subscriptionService.UnlockChannel(userId, req)
|
|
if err != nil {
|
|
global.Logger.Error("解锁频道失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), c)
|
|
return
|
|
}
|
|
response.OkWithData(radioRes.PrePayResult{
|
|
Payments: res,
|
|
OutTradeNo: no,
|
|
}, c)
|
|
}
|