feat: 互动处理

This commit is contained in:
Blizzard
2026-03-05 16:54:25 +08:00
parent 74b252550b
commit 2583b5f302
30 changed files with 412 additions and 119 deletions
+8
View File
@@ -54,6 +54,10 @@ func (a *ChannelApi) GetFreeChannelList(c *gin.Context) {
// @Router /radio/channel/list [post]
func (a *ChannelApi) GetChannelList(c *gin.Context) {
userId := auth.GetUserId(c)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
var req request.GetChannelList
err := c.ShouldBindJSON(&req)
if err != nil {
@@ -86,6 +90,10 @@ func (a *ChannelApi) GetChannelList(c *gin.Context) {
// @Router /radio/channel/detail [get]
func (a *ChannelApi) GetChannelDetail(c *gin.Context) {
userId := auth.GetUserId(c)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
id := c.Query("id")
if id == "" {
response.FailWithMsg("参数错误: id不能为空", c)
+2
View File
@@ -9,6 +9,7 @@ type ApiGroup struct {
SubscriptionApi
InteractionApi
PayApi
VipApi
}
var ApiGroupApp = new(ApiGroup)
@@ -20,4 +21,5 @@ var (
subscriptionService = service.GroupApp.RadioServiceGroup.SubscriptionService
interactionService = service.GroupApp.RadioServiceGroup.InteractionService
payService = service.GroupApp.RadioServiceGroup.PayService
vipService = service.GroupApp.RadioServiceGroup.VipService
)
+44
View File
@@ -21,6 +21,10 @@ type InteractionApi struct{}
// @Router /history/add [post]
func (a *InteractionApi) AddHistory(c *gin.Context) {
userId := auth.GetUserId(c)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
var req request.AddHistory
err := c.ShouldBindJSON(&req)
if err != nil {
@@ -52,6 +56,10 @@ func (a *InteractionApi) DeleteHistory(c *gin.Context) {
return
}
userId := auth.GetUserId(c)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
err = interactionService.DeleteHistory(userId, req.ProgramId)
if err != nil {
global.Logger.Error("删除收听历史失败!", zap.Error(err))
@@ -69,6 +77,10 @@ func (a *InteractionApi) DeleteHistory(c *gin.Context) {
// @Router /history/deleteAllHistory [get]
func (a *InteractionApi) DeleteAllHistory(c *gin.Context) {
userId := auth.GetUserId(c)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
err := interactionService.DeleteAllHistory(userId)
if err != nil {
global.Logger.Error("删除所有收听历史失败!", zap.Error(err))
@@ -87,6 +99,10 @@ func (a *InteractionApi) DeleteAllHistory(c *gin.Context) {
// @Router /history/list [post]
func (a *InteractionApi) GetHistoryList(c *gin.Context) {
userId := auth.GetUserId(c)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
var req request.GetHistoryList
err := c.ShouldBindJSON(&req)
if err != nil {
@@ -117,6 +133,10 @@ func (a *InteractionApi) GetHistoryList(c *gin.Context) {
// @Router /like/toggle [post]
func (a *InteractionApi) ToggleLike(c *gin.Context) {
userId := auth.GetUserId(c)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
var req request.ToggleLike
err := c.ShouldBindJSON(&req)
if err != nil {
@@ -143,6 +163,10 @@ func (a *InteractionApi) ToggleLike(c *gin.Context) {
// @Router /favorite/list [post]
func (a *InteractionApi) GetFavoriteList(c *gin.Context) {
userId := auth.GetUserId(c)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
var req request.GetFavoriteList
err := c.ShouldBindJSON(&req)
if err != nil {
@@ -173,6 +197,10 @@ func (a *InteractionApi) GetFavoriteList(c *gin.Context) {
// @Router /favorite/add [post]
func (a *InteractionApi) AddFavorite(c *gin.Context) {
userId := auth.GetUserId(c)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
var req request.AddFavorite
err := c.ShouldBindJSON(&req)
if err != nil {
@@ -198,6 +226,10 @@ func (a *InteractionApi) AddFavorite(c *gin.Context) {
// @Router /favorite/remove [post]
func (a *InteractionApi) RemoveFavorite(c *gin.Context) {
userId := auth.GetUserId(c)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
var req request.RemoveFavorite
err := c.ShouldBindJSON(&req)
if err != nil {
@@ -223,6 +255,10 @@ func (a *InteractionApi) RemoveFavorite(c *gin.Context) {
// @Router /favorite/removeAll [get]
func (a *InteractionApi) RemoveAllFavorite(c *gin.Context) {
userId := auth.GetUserId(c)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
err := interactionService.RemoveAllFavorite(userId)
if err != nil {
global.Logger.Error("清空所有收藏失败!", zap.Error(err))
@@ -270,6 +306,10 @@ func (a *InteractionApi) GetCommentList(c *gin.Context) {
// @Router /comment/add [post]
func (a *InteractionApi) AddComment(c *gin.Context) {
userId := auth.GetUserId(c)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
var req request.AddComment
err := c.ShouldBindJSON(&req)
if err != nil {
@@ -295,6 +335,10 @@ func (a *InteractionApi) AddComment(c *gin.Context) {
// @Router /comment/delete [post]
func (a *InteractionApi) DeleteComment(c *gin.Context) {
userId := auth.GetUserId(c)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
var req request.DeleteComment
err := c.ShouldBindJSON(&req)
if err != nil {
+9 -1
View File
@@ -23,6 +23,10 @@ type PayApi struct{}
func (a *PayApi) PrePay(c *gin.Context) {
orderId := c.Query("orderId")
userId := auth.GetUserId(c)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
res, err := payService.PrePay(orderId, userId)
if err != nil {
global.Logger.Error("支付失败", zap.Error(err))
@@ -32,7 +36,7 @@ func (a *PayApi) PrePay(c *gin.Context) {
response.OkWithData(res, c)
}
// QueryPay 查询支付
// QueryPay 查询订阅支付状态
// @Tags 微信支付
// @Summary 支付
// @Security BasicAuth
@@ -43,6 +47,10 @@ func (a *PayApi) PrePay(c *gin.Context) {
func (a *PayApi) QueryPay(c *gin.Context) {
outTradeNo := c.Query("outTradeNo")
userId := auth.GetUserId(c)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
res, err := payService.QueryPay(outTradeNo, userId)
if err != nil {
global.Logger.Error("支付失败", zap.Error(err))
+4
View File
@@ -57,6 +57,10 @@ func (a *ProgramApi) GetProgramDetail(c *gin.Context) {
return
}
userId := auth.GetUserId(c)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
program, err := programService.GetProgramById(id, userId)
if err != nil {
global.Logger.Error("获取节目详情失败!", zap.Error(err))
+8
View File
@@ -24,6 +24,10 @@ type SubscriptionApi struct{}
// @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 {
@@ -60,6 +64,10 @@ func (a *SubscriptionApi) UnlockChannel(c *gin.Context) {
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))
+74
View File
@@ -0,0 +1,74 @@
package radio
import (
"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"
)
type VipApi struct{}
// UpdateVipConfig 更新VIP配置
// @Tags VIP管理
// @Summary 更新VIP配置
// @Accept application/json
// @Produce application/json
// @Param data body request.UpdateVipConfig true "VIP配置信息"
// @Success 200 {object} response.Response
// @Router /vip/config/update [post]
func (a *VipApi) UpdateVipConfig(c *gin.Context) {
var req request.UpdateVipConfig
err := c.ShouldBindJSON(&req)
if err != nil {
response.FailWithMsg("参数错误: "+err.Error(), c)
return
}
err = vipService.UpdateVipConfig(req)
if err != nil {
response.FailWithMsg(err.Error(), c)
return
}
response.OkWithMsg("更新成功", c)
}
// VipConfigDetail 获取VIP配置详情
// @Tags VIP管理
// @Summary 获取VIP配置详情
// @Produce application/json
// @Param id query string true "id"
// @Success 200 {object} response.Response
// @Router /vip/config/detail [get]
func (a *VipApi) VipConfigDetail(c *gin.Context) {
vipConfig, err := vipService.VipConfigDetail()
if err != nil {
response.FailWithMsg(err.Error(), c)
return
}
response.OkWithData(vipConfig, c)
}
// VipVip 开通vip
// @Tags VIP管理
// @Summary 开通vip
// @Produce application/json
// @Success 200 {object} response.Response
// @Router /vip/vip [post]
func (a *VipApi) VipVip(c *gin.Context) {
userId := auth.GetUserId(c)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
res, no, err := vipService.VipVip(userId)
if err != nil {
response.FailWithMsg(err.Error(), c)
return
}
response.OkWithData(radioRes.PrePayResult{
Payments: res,
OutTradeNo: no,
}, c)
}
+4
View File
@@ -56,6 +56,10 @@ func (a *AuthApi) Login(c *gin.Context) {
func (a *AuthApi) Logout(c *gin.Context) {
token := auth.GetToken(c)
userId := auth.GetUserId(c)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
err := jwtService.PutBlacklist(userId, token)
if err != nil {
global.Logger.Error("登出失败!", zap.Error(err))
+8
View File
@@ -138,6 +138,10 @@ func (m *MenuApi) GetAllMenuTree(c *gin.Context) {
// @Router /menu/getUserMenuTree [get]
func (m *MenuApi) GetUserMenuTree(c *gin.Context) {
userId := auth.GetUserId(c)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
routes, err := menuService.GetUserRoutes(userId)
if err != nil {
global.Logger.Error("获取用户菜单失败!", zap.Error(err))
@@ -156,6 +160,10 @@ func (m *MenuApi) GetUserMenuTree(c *gin.Context) {
// @Router /menu/route [get]
func (m *MenuApi) Route(c *gin.Context) {
userId := auth.GetUserId(c)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
routes, err := menuService.GetUserRoutes(userId)
if err != nil {
global.Logger.Error("获取用户菜单失败!", zap.Error(err))
+3
View File
@@ -24,6 +24,9 @@ type UserApi struct {
// @Router /user/info [get]
func (u *UserApi) CurrentUser(c *gin.Context) {
userId := auth.GetUserId(c)
if userId == "" {
}
user, err := userService.GetUserById(userId)
if err != nil {
global.Logger.Error("获取用户信息失败!", zap.Error(err))