🎨 优化讲师包月模块

This commit is contained in:
2025-10-11 16:16:42 +08:00
parent ed962c26b9
commit 99779e6415
3 changed files with 36 additions and 5 deletions

View File

@@ -7,6 +7,7 @@ import (
common "git.echol.cn/loser/lckt/model/common/request"
r "git.echol.cn/loser/lckt/model/common/response"
"git.echol.cn/loser/lckt/utils"
"git.echol.cn/loser/lckt/utils/user_jwt"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
@@ -78,7 +79,9 @@ func (a *TeacherVip) GetTeacherVipList(context *gin.Context) {
return
}
vips, total, err := teacherVipService.GetTeacherVipList(p)
userId := user_jwt.GetUserID(context)
vips, total, err := teacherVipService.GetTeacherVipList(p, userId)
if err != nil {
global.GVA_LOG.Error("获取讲师VIP列表失败", zap.Error(err))
r.FailWithMessage("获取讲师VIP列表失败", context)

View File

@@ -26,7 +26,7 @@ func initBizRouter(routers ...*gin.RouterGroup) {
}
{
articleRouter := router.RouterGroupApp.Article
articleRouter.InitBotRouter(privateGroup, publicGroup, appGroup)
articleRouter.InitBotRouter(privateGroup, appGroup)
}
{
userRouter := router.RouterGroupApp.User

View File

@@ -5,20 +5,22 @@ import (
"git.echol.cn/loser/lckt/global"
"git.echol.cn/loser/lckt/model/app"
"git.echol.cn/loser/lckt/model/app/request"
"git.echol.cn/loser/lckt/model/app/vo"
user2 "git.echol.cn/loser/lckt/model/user"
"go.uber.org/zap"
"gorm.io/gorm"
)
type TeacherVipService struct{}
// GetTeacherVipList 获取讲师包月列表
func (u *TeacherVipService) GetTeacherVipList(p request.GetTeacherVipList) (list []app.TeacherVip, total int64, err error) {
func (u *TeacherVipService) GetTeacherVipList(p request.GetTeacherVipList, userId uint) (list []vo.TeacherVipList, total int64, err error) {
limit := p.PageSize
offset := (p.Page - 1) * p.PageSize
db := global.GVA_DB.Model(&app.TeacherVip{})
if p.TeacherId != 0 {
db.Where("teacher_id = ? ", p.TeacherId)
db = db.Where("teacher_id = ? ", p.TeacherId)
}
if p.Keyword != "" {
@@ -30,11 +32,37 @@ func (u *TeacherVipService) GetTeacherVipList(p request.GetTeacherVipList) (list
global.GVA_LOG.Error("查询讲师包月总数失败", zap.Error(err))
return nil, 0, err
}
err = db.Limit(limit).Offset(offset).Find(&list).Error
var teacherVips []app.TeacherVip
err = db.Limit(limit).Offset(offset).Find(&teacherVips).Error
if err != nil {
global.GVA_LOG.Error("查询讲师包月列表失败", zap.Error(err))
return nil, 0, err
}
list = make([]vo.TeacherVipList, len(teacherVips))
for i, vip := range teacherVips {
list[i] = vo.TeacherVipList{
TeacherVip: vip,
}
}
for i := range list {
var userVip app.UserTeacherVip
err = global.GVA_DB.Where("user_id = ? AND teacher_vip_id = ?", userId, list[i].ID).First(&userVip).Error
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
global.GVA_LOG.Error("查询用户讲师VIP失败", zap.Error(err))
return
}
if errors.Is(err, gorm.ErrRecordNotFound) {
err = nil
list[i].IsBuy = 0
continue
}
list[i].IsBuy = 1
list[i].ExpireAt = userVip.ExpireAt
list[i].IsExpire = userVip.IsExpire
}
return
}