🎨 优化讲师包月模块

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

@@ -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
}