🎨 优化文章和支付回调,新增返回分享用接口

This commit is contained in:
2025-10-08 16:41:50 +08:00
parent f0ea189553
commit d593476c51
9 changed files with 94 additions and 83 deletions

View File

@@ -6,6 +6,7 @@ import (
common "git.echol.cn/loser/lckt/model/common/request"
user2 "git.echol.cn/loser/lckt/model/user"
"gorm.io/gorm"
"net/http"
"strconv"
"time"
@@ -586,3 +587,18 @@ func (a *AppUserApi) GetVipTeacherList(context *gin.Context) {
PageSize: p.PageSize,
}, "获取包月讲师列表成功", context)
}
func (a *AppUserApi) GetWechatJSSDKSign(context *gin.Context) {
//接收前端传递的url参数
url := context.Query("url")
jsapiList := []string{"chooseImage"}
debug := false
beta := false
openTagList := []string{"updateAppMessageShareData", "updateTimelineShareData", "onMenuShareAppMessage", "onMenuShareTimeline"}
data, err := wechat.WeOfficial.JSSDK.BuildConfig(context, jsapiList, debug, beta, openTagList, url)
if err != nil {
context.String(http.StatusBadRequest, err.Error())
return
}
context.JSON(http.StatusOK, data)
}

View File

@@ -17,10 +17,16 @@ type UserInfo struct {
}
type TeacherInfo struct {
ID uint `json:"id" form:"id"`
NickName string `json:"nick_name" form:"nick_name"`
Avatar string `json:"avatar" form:"avatar"`
Des string `json:"des" form:"des"`
Follow int64 `json:"follow" form:"follow"` // 粉丝数
Weight int `json:"weight" form:"weight"` // 权重
ID uint `json:"id" form:"id"`
NickName string `json:"nick_name" form:"nick_name"`
Avatar string `json:"avatar" form:"avatar"`
Des string `json:"des" form:"des"`
Weight int `json:"weight" form:"weight"` // 权重
VIPInfo []TeacherVipInfo `json:"vip_info" form:"vip_info"`
}
type TeacherVipInfo struct {
TeacherId uint `json:"teacher_id" form:"teacher_id"`
Title string `json:"title" form:"title"`
ExpireAt string `json:"expire_at" form:"expire_at"`
}

View File

@@ -22,13 +22,14 @@ func (s *UserRouter) InitAppUserRouter(AppAuthGroup, PublicRouter *gin.RouterGro
appUserRouter.GET("/balanceLog", userApi.GetBalanceLog) // 获取余额变动日志
}
{
publicRouter.POST("wxLogin", userApi.WechatLogin) // 微信登录
publicRouter.POST("bindWX", userApi.BindWechat) // 绑定微信
publicRouter.POST("bindPhone", userApi.BindPhone) // 获取用户信息
publicRouter.POST("pwdlogin", userApi.PwdLogin) // 密码登录
publicRouter.POST("sms/send", userApi.SendCode) // 发送短信验证码
publicRouter.POST("login", userApi.Login) // 短信验证码登录
publicRouter.POST("register", userApi.Register) // 注册
publicRouter.POST("wxLogin", userApi.WechatLogin) // 微信登录
publicRouter.POST("bindWX", userApi.BindWechat) // 绑定微信
publicRouter.POST("bindPhone", userApi.BindPhone) // 获取用户信息
publicRouter.POST("pwdlogin", userApi.PwdLogin) // 密码登录
publicRouter.POST("sms/send", userApi.SendCode) // 发送短信验证码
publicRouter.POST("login", userApi.Login) // 短信验证码登录
publicRouter.POST("register", userApi.Register) // 注册
publicRouter.GET("/wechat/js/sign", userApi.GetWechatJSSDKSign) // 获取微信JSSDK签名
}
// 讲师包月相关接口
{

View File

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

View File

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

View File

@@ -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 {
// 如果不是免费文章,判断用户是否购买过

View File

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

View File

@@ -3,15 +3,13 @@ package test
import (
"crypto/md5"
"fmt"
"git.echol.cn/loser/lckt/core"
"git.echol.cn/loser/lckt/global"
"git.echol.cn/loser/lckt/initialize"
"git.echol.cn/loser/lckt/task"
"go.uber.org/zap"
"golang.org/x/crypto/bcrypt"
"math/rand"
"net/http"
"net/url"
"strings"
"testing"
"time"
)
@@ -90,15 +88,14 @@ func TestTime(t *testing.T) {
}
func TestTask(t *testing.T) {
global.GVA_VP = core.Viper() // 初始化Viper
global.GVA_LOG = core.Zap() // 初始化zap日志库
zap.ReplaceGlobals(global.GVA_LOG)
global.GVA_DB = initialize.Gorm() // gorm连接数据库
initialize.DBList()
err := task.CheckVip(global.GVA_DB)
if err != nil {
fmt.Println("清理表失败", err.Error())
} else {
fmt.Println("清理表成功")
}
fmt.Println(GetTeacherName("https://lckt.oss-cn-hangzhou.aliyuncs.com/lckt/uploads/2025-09-12/阿弟_6CO8KB8HCSJL_1757684981.jpg"))
}
func GetTeacherName(url string) string {
lastSlash := strings.LastIndex(url, "/")
underscore := strings.Index(url[lastSlash+1:], "_")
if lastSlash == -1 || underscore == -1 {
return ""
}
return url[lastSlash+1 : lastSlash+1+underscore]
}

View File

@@ -279,8 +279,8 @@ func NotifyHandle(ctx *gin.Context) 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))