新增记录群或者好友已使用的tokens信息

This commit is contained in:
李寻欢
2024-07-05 09:44:07 +08:00
parent 9e8c3f5e6f
commit f747bf5ead
3 changed files with 18 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ import (
"go-wechat/client"
"go-wechat/model/entity"
"go-wechat/model/vo"
"gorm.io/gorm"
"log"
"strings"
)
@@ -119,3 +120,16 @@ func updateLastActive(msg entity.Message) {
log.Printf("更新群或者好友活跃时间失败, 错误信息: %v", err)
}
}
// UpdateUsedAiTokens
// @description: 更新已使用的AI次数
// @param wxId 微信好友或者群聊Id
// @param tokens 新增的tokens额度
func UpdateUsedAiTokens(wxId string, tokens int) {
err := client.MySQL.Model(&entity.Friend{}).
Where("wxid = ?", wxId).
Update("`used_tokens`", gorm.Expr(" `used_tokens` + ?", tokens)).Error
if err != nil {
log.Printf("更新AI使用次数失败, 错误信息: %v", err)
}
}