feat: 弃用腾讯tts,改用火山引擎tts

This commit is contained in:
Blizzard
2026-03-23 16:24:27 +08:00
parent f4bfe2d609
commit df74da48bd
12 changed files with 251 additions and 9 deletions
+1
View File
@@ -11,6 +11,7 @@ type ServiceGroup struct {
VipService
TTSService
AnalyticsService
UserService
}
var GroupApp = new(ServiceGroup)
+143
View File
@@ -0,0 +1,143 @@
package radio
import (
"sundynix-go/global"
common "sundynix-go/model/commom/request"
"sundynix-go/model/radio/response"
"sundynix-go/model/system"
)
type UserService struct{}
// GetRadioUserList 获取电台用户列表(带订阅/收听统计)
func (s *UserService) GetRadioUserList(info common.PageInfo, isVip int, keyword string) ([]response.RadioUserItem, int64, error) {
var total int64
var users []system.User
db := global.DB.Model(&system.User{})
// 关键字搜索
if keyword != "" {
db = db.Where("nick_name LIKE ? OR phone LIKE ? OR account LIKE ?",
"%"+keyword+"%", "%"+keyword+"%", "%"+keyword+"%")
}
// VIP 筛选: 1=VIP, 2=非VIP, 0或其他=全部
if isVip == 1 {
db = db.Where("is_vip = 1")
} else if isVip == 2 {
db = db.Where("is_vip = 0")
}
// 统计总数
if err := db.Count(&total).Error; err != nil {
return nil, 0, err
}
// 分页查询用户列表
if err := db.Preload("Avatar").
Scopes(info.Paginate()).
Order("created_at DESC").
Find(&users).Error; err != nil {
return nil, 0, err
}
// 批量获取用户ID
userIds := make([]string, len(users))
for i, u := range users {
userIds[i] = u.Id
}
if len(userIds) == 0 {
return []response.RadioUserItem{}, total, nil
}
// 批量查询订阅数
type UserCount struct {
UserId string
Count int64
}
var subCounts []UserCount
global.DB.Table("sundynix_radio_subscription").
Select("user_id, COUNT(*) as count").
Where("user_id IN ? AND status = 1 AND deleted_at IS NULL", userIds).
Group("user_id").
Scan(&subCounts)
subMap := make(map[string]int64)
for _, sc := range subCounts {
subMap[sc.UserId] = sc.Count
}
// 批量查询收听次数
var listenCounts []UserCount
global.DB.Table("sundynix_radio_listen_log").
Select("user_id, COUNT(*) as count").
Where("user_id IN ? AND deleted_at IS NULL", userIds).
Group("user_id").
Scan(&listenCounts)
listenMap := make(map[string]int64)
for _, lc := range listenCounts {
listenMap[lc.UserId] = lc.Count
}
// 批量查询收藏数
var favCounts []UserCount
global.DB.Table("sundynix_radio_favorite").
Select("user_id, COUNT(*) as count").
Where("user_id IN ? AND deleted_at IS NULL", userIds).
Group("user_id").
Scan(&favCounts)
favMap := make(map[string]int64)
for _, fc := range favCounts {
favMap[fc.UserId] = fc.Count
}
// 批量查询订单总额(分)
type UserAmount struct {
UserId string
TotalAmount int64
OrderCount int64
}
var orderStats []UserAmount
global.DB.Table("sundynix_order").
Select("user_id, SUM(amount) as total_amount, COUNT(*) as order_count").
Where("user_id IN ? AND status = 1 AND deleted_at IS NULL", userIds).
Group("user_id").
Scan(&orderStats)
amountMap := make(map[string]int64)
orderCountMap := make(map[string]int64)
for _, os := range orderStats {
amountMap[os.UserId] = os.TotalAmount
orderCountMap[os.UserId] = os.OrderCount
}
// 组装结果
result := make([]response.RadioUserItem, len(users))
for i, u := range users {
avatarUrl := ""
if u.Avatar != nil {
avatarUrl = u.Avatar.Url
}
result[i] = response.RadioUserItem{
Id: u.Id,
Name: u.Name,
NickName: u.NickName,
Account: u.Account,
Phone: u.Phone,
AvatarUrl: avatarUrl,
Gender: u.Gender,
IsVip: u.IsVip,
VipExpireAt: u.VipExpireAt,
LastLoginAt: u.LastLoginAt,
LastLoginIp: u.LastLoginIp,
CreatedAt: u.CreatedAt,
SubscribeCount: subMap[u.Id],
ListenCount: listenMap[u.Id],
FavoriteCount: favMap[u.Id],
TotalSpent: amountMap[u.Id],
OrderCount: orderCountMap[u.Id],
}
}
return result, total, nil
}
+8 -1
View File
@@ -20,6 +20,7 @@ import (
location "sundynix-go/utils/location"
"sundynix-go/utils/uniqueid"
"sundynix-go/utils/wechat"
"time"
"go.uber.org/zap"
"gorm.io/gorm"
@@ -72,6 +73,9 @@ func (userService *UserService) GetUserList(info systemReq.GetUserList) (list in
db := global.DB.Model(&system.User{})
var userList []system.User
if info.IsVip != nil {
db = db.Where("is_vip = ?", *info.IsVip)
}
if info.Account != "" {
db = db.Where("account LIKE ?", "%"+info.Account+"%")
}
@@ -82,7 +86,7 @@ func (userService *UserService) GetUserList(info systemReq.GetUserList) (list in
if err != nil {
return
}
err = db.Limit(limit).Offset(offset).Find(&userList).Error
err = db.Limit(limit).Offset(offset).Order("created_at desc").Find(&userList).Error
return userList, total, err
}
@@ -144,6 +148,7 @@ func (userService *UserService) MiniLogin(code, ip string) (result *system.User,
// 7. 根据openid查询用户 存在--> 更新session_key 返回数据
var user system.User
now := time.Now()
err = global.DB.Where("open_id = ?", wxResp.Openid).Preload("Avatar").First(&user).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
// 8. 使用 Transaction 闭包管理事务
@@ -154,6 +159,7 @@ func (userService *UserService) MiniLogin(code, ip string) (result *system.User,
OpenId: wxResp.Openid,
SessionKey: wxResp.SessionKey,
LastLoginIp: ip,
LastLoginAt: &now,
}
if err := tx.Create(&newUser).Error; err != nil {
return err
@@ -174,6 +180,7 @@ func (userService *UserService) MiniLogin(code, ip string) (result *system.User,
updateData := map[string]interface{}{
"session_key": wxResp.SessionKey,
"last_login_ip": ip,
"last_login_at": &now,
}
if err = global.DB.Model(&user).Updates(updateData).Error; err != nil {
global.Logger.Error("更新session_key失败", zap.Error(err))