feat: 限制用户单日提问次数

This commit is contained in:
Blizzard
2026-04-24 17:07:52 +08:00
parent e9c93d4029
commit 3aae619af5
6 changed files with 56 additions and 4 deletions
+9
View File
@@ -46,3 +46,12 @@ func (s *AiChatHistoryService) DeleteHistory(userId, id string) error {
func (s *AiChatHistoryService) ClearHistory(userId string) error {
return global.DB.Where("user_id = ?", userId).Delete(&plantModel.AiChatHistory{}).Error
}
// GetTodayCount 获取用户今日问答数量
func (s *AiChatHistoryService) GetTodayCount(userId string) (int64, error) {
var count int64
err := global.DB.Model(&plantModel.AiChatHistory{}).
Where("user_id = ? AND DATE(created_at) = CURDATE()", userId).
Count(&count).Error
return count, err
}