🎨 优化文章和支付回调,新增返回分享用接口
This commit is contained in:
@@ -176,17 +176,17 @@ func (s *OrderService) BalancePay(p request.BalancePay) error {
|
||||
}
|
||||
// 计算会员的过期时间
|
||||
if user.VipExpireTime != "" {
|
||||
expireTime, _ := time.Parse("2006-01-02", user.VipExpireTime)
|
||||
expireTime, _ := time.Parse("2006-01-02 15:04:05", user.VipExpireTime)
|
||||
if expireTime.After(time.Now()) {
|
||||
// 如果会员未过期,则在原有的基础上增加时间
|
||||
user.VipExpireTime = expireTime.AddDate(0, 0, int(vipInfo.Expiration)).Format("2006-01-02")
|
||||
user.VipExpireTime = expireTime.AddDate(0, 0, int(vipInfo.Expiration)).Format("2006-01-02 15:04:05")
|
||||
} else {
|
||||
// 如果会员已过期,则从当前时间开始计算
|
||||
user.VipExpireTime = time.Now().AddDate(0, 0, int(vipInfo.Expiration)).Format("2006-01-02")
|
||||
user.VipExpireTime = time.Now().AddDate(0, 0, int(vipInfo.Expiration)).Format("2006-01-02 15:04:05")
|
||||
}
|
||||
} else {
|
||||
// 如果没有会员时间,则从当前时间开始计算
|
||||
user.VipExpireTime = time.Now().AddDate(0, 0, int(vipInfo.Expiration)).Format("2006-01-02")
|
||||
user.VipExpireTime = time.Now().AddDate(0, 0, int(vipInfo.Expiration)).Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
// 更新用户的会员状态
|
||||
@@ -216,8 +216,8 @@ func (s *OrderService) BalancePay(p request.BalancePay) error {
|
||||
teacherVipId, _ := strconv.ParseUint(id, 10, 64)
|
||||
teacherVip.TeacherVipId = uint(teacherVipId)
|
||||
teacherVip.UserId = uint(order.UserId)
|
||||
teacherVip.ExpireAt = time.Now().AddDate(0, 1, 0).Format("2006-01-02") // 会员有效期一个月
|
||||
teacherVip.IsExpire = 1 // 设置为未过期
|
||||
teacherVip.ExpireAt = time.Now().AddDate(0, 1, 0).Format("2006-01-02 15:04:05") // 会员有效期一个月
|
||||
teacherVip.IsExpire = 1 // 设置为未过期
|
||||
err = global.GVA_DB.Create(&teacherVip).Error
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("购买讲师会员回调处理失败:", zap.Error(err))
|
||||
|
||||
@@ -250,36 +250,6 @@ func (u *AppUserService) GetTeacherList(p common.PageInfo) (list []vo.TeacherInf
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 批量查询所有教师的粉丝数
|
||||
var teacherIDs []uint
|
||||
for _, t := range list {
|
||||
teacherIDs = append(teacherIDs, t.ID)
|
||||
}
|
||||
type FansCount struct {
|
||||
TeacherId uint
|
||||
Count int64
|
||||
}
|
||||
var fansCounts []FansCount
|
||||
if len(teacherIDs) > 0 {
|
||||
err = global.GVA_DB.Model(&app.Follow{}).
|
||||
Select("teacher_id, count(*) as count").
|
||||
Where("teacher_id IN ?", teacherIDs).
|
||||
Group("teacher_id").
|
||||
Scan(&fansCounts).Error
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("批量查询教师粉丝数失败", zap.Error(err))
|
||||
return nil, 0, err
|
||||
}
|
||||
}
|
||||
// 映射粉丝数
|
||||
fansMap := make(map[uint]int64)
|
||||
for _, fc := range fansCounts {
|
||||
fansMap[fc.TeacherId] = fc.Count
|
||||
}
|
||||
for i := range list {
|
||||
list[i].Follow = fansMap[list[i].ID]
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -320,16 +290,6 @@ func (u *AppUserService) GetFollowTeacherList(id uint, p common.PageInfo) (list
|
||||
return
|
||||
}
|
||||
|
||||
// 获取每个教师的粉丝数
|
||||
for i := range list {
|
||||
followCount, err := u.GetTeacherFansCount(list[i].ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询教师粉丝数失败", zap.Error(err))
|
||||
return nil, 0, err
|
||||
}
|
||||
list[i].Follow = followCount
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -407,6 +367,12 @@ func (u *AppUserService) GetVipTeacherList(p common.PageInfo, userId uint) (list
|
||||
global.GVA_LOG.Error("获取用户讲师包月信息失败:", zap.Error(err))
|
||||
return nil, 0, err
|
||||
}
|
||||
var TeacherVipIds []uint
|
||||
err = global.GVA_DB.Model(&app.UserTeacherVip{}).Where("user_id = ? and is_expire = 1", userId).Select("teacher_vip_id").Scan(&TeacherVipIds).Error
|
||||
if len(vipTeacherIds) == 0 {
|
||||
global.GVA_LOG.Error("获取讲师包月信息失败:", zap.Error(err))
|
||||
return nil, 0, nil
|
||||
}
|
||||
|
||||
db := global.GVA_DB.Model(&user.User{}).Where("user_type = ? and id in ?", 2, vipTeacherIds)
|
||||
|
||||
@@ -425,14 +391,26 @@ func (u *AppUserService) GetVipTeacherList(p common.PageInfo, userId uint) (list
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 获取每个教师的粉丝数
|
||||
// 获取用户包月信息
|
||||
var vipInfos []vo.TeacherVipInfo
|
||||
err = global.GVA_DB.Table("user_teacher_vip AS u").
|
||||
Select("u.teacher_id, a.title, u.expire_at").
|
||||
Joins("LEFT JOIN app_teacher_vip AS a ON u.teacher_vip_id = a.id").
|
||||
Where("u.user_id = ?", userId).
|
||||
Scan(&vipInfos).Error
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询用户包月信息失败", zap.Error(err))
|
||||
return nil, 0, err
|
||||
}
|
||||
// 1. 按TeacherId分组
|
||||
vipInfoMap := make(map[uint][]vo.TeacherVipInfo)
|
||||
for _, v := range vipInfos {
|
||||
vipInfoMap[v.TeacherId] = append(vipInfoMap[v.TeacherId], v)
|
||||
}
|
||||
|
||||
// 2. 给每个讲师赋值自己的VIPInfo
|
||||
for i := range list {
|
||||
followCount, err := u.GetTeacherFansCount(list[i].ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询教师粉丝数失败", zap.Error(err))
|
||||
return nil, 0, err
|
||||
}
|
||||
list[i].Follow = followCount
|
||||
list[i].VIPInfo = vipInfoMap[list[i].ID]
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
@@ -125,6 +125,19 @@ func (s ArticleService) APPGetArticle(id string, userId int) (article *vo.Articl
|
||||
|
||||
global.GVA_DB.Table("app_user").Select("avatar").Where("id = ?", article.TeacherId).Scan(&article.TeacherAvatar)
|
||||
|
||||
// 判断用户是否为SVIP
|
||||
if userId != 0 {
|
||||
var userInfo user.User
|
||||
err = global.GVA_DB.Model(&user.User{}).Where("id = ?", userId).First(&userInfo).Error
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询用户信息失败", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
if userInfo.IsVip == 1 && userInfo.UserLabel == 3 {
|
||||
return article, nil
|
||||
}
|
||||
}
|
||||
|
||||
// 判断是否免费
|
||||
if article.IsFree == 0 {
|
||||
// 如果不是免费文章,判断用户是否购买过
|
||||
|
||||
@@ -215,7 +215,7 @@ func (btService *BotService) BulkBot(p botReq.BulkBot, userName string) (err err
|
||||
var failFiles []string
|
||||
|
||||
for _, a := range p.Files {
|
||||
content := "<p><img src=" + a + " alt=\"" + a + "\" data-href=\"\" style=\"width: 100%;height: auto;\"/></p>"
|
||||
content := "<img src=" + a + " alt=\"" + a + "\" data-href=\"\" style=\"width: 100%;height: auto;\"/>"
|
||||
bots := bot.Bot{
|
||||
Keyword: getBotKeyWorld(a),
|
||||
Content: &content,
|
||||
|
||||
Reference in New Issue
Block a user