🎨 新增讲师包月功能,优化支付回调

This commit is contained in:
2025-09-07 02:11:22 +08:00
parent 7bcc2370bd
commit df46c7ab29
16 changed files with 508 additions and 43 deletions

View File

@@ -4,6 +4,8 @@ import (
gfmt "fmt"
"git.echol.cn/loser/lckt/global"
"git.echol.cn/loser/lckt/model/app"
"git.echol.cn/loser/lckt/model/user"
"git.echol.cn/loser/lckt/model/vip"
"github.com/ArtisanCloud/PowerLibs/v3/fmt"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/models"
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment"
@@ -13,6 +15,8 @@ import (
"go.uber.org/zap"
"log"
"math/rand"
"strconv"
"strings"
"time"
)
@@ -198,6 +202,66 @@ func NotifyHandle(ctx *gin.Context) error {
return nil
}
order.Status = 2 // 设置订单状态为已支付
// 全站vip订单
if order.OrderType == 2 {
userInfo := user.User{}
err = global.GVA_DB.Model(&user.User{}).Where("id = ?", order.UserId).First(&userInfo).Error
if err != nil {
global.GVA_LOG.Error("查询用户信息失败", zap.Error(err))
return nil
}
// 更新用户的会员状态
userInfo.IsVip = 1
// 查询用户购买的会员信息
vipInfo := vip.Vip{}
err = global.GVA_DB.Model(&vip.Vip{}).Where("id = ?", order.VipId).First(&vipInfo).Error
if err != nil {
global.GVA_LOG.Error("查询会员信息失败", zap.Error(err))
return nil
}
// 计算会员的过期时间
if userInfo.VipExpireTime != "" {
expireTime, _ := time.Parse("2006-01-02", userInfo.VipExpireTime)
if expireTime.After(time.Now()) {
// 如果会员未过期,则在原有的基础上增加时间
userInfo.VipExpireTime = expireTime.AddDate(0, 0, int(vipInfo.Expiration)).Format("2006-01-02")
} else {
// 如果会员已过期,则从当前时间开始计算
userInfo.VipExpireTime = time.Now().AddDate(0, 0, int(vipInfo.Expiration)).Format("2006-01-02")
}
} else {
// 如果没有会员时间,则从当前时间开始计算
userInfo.VipExpireTime = time.Now().AddDate(0, 0, int(vipInfo.Expiration)).Format("2006-01-02")
}
err = global.GVA_DB.Save(&userInfo).Error
if err != nil {
global.GVA_LOG.Error("更新用户会员状态失败", zap.Error(err))
return nil
}
}
// 如果是讲师包月订单,更新讲师的会员状态
if order.OrderType == 3 {
// 逗号分割字符串
ids := strings.Split(order.TeacherVipId, ",")
for _, id := range ids {
teacherVip := app.UserTeacherVip{}
teacherVip.TeacherId = uint(order.TeacherId)
// 将id转为uint
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 // 设置为未过期
err = global.GVA_DB.Create(&teacherVip).Error
if err != nil {
global.GVA_LOG.Error("购买讲师会员回调处理失败:", zap.Error(err))
return err
}
}
}
err = global.GVA_DB.Save(&order).Error
if err != nil {
global.GVA_LOG.Error("更新订单状态失败", zap.Error(err))