You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
700 B
Go

5 months ago
package service
import (
"goftp/models"
"goftp/utils"
"time"
)
func UpdateDownloadCount(fileName string) bool {
5 months ago
file := models.FindFileByFileName(fileName)
if file != nil {
5 months ago
//文件存在
currentCount := file.Downloadcount
file.Downloadcount = currentCount + 1
file.LastDownloadtime = time.Now()
5 months ago
errUpdate := models.UpdateFile(file)
5 months ago
if errUpdate == nil {
return true
}
} else {
//文件不存在
insertFile := new(models.File)
insertFile.Id = utils.GetUuid()
insertFile.Name = fileName
insertFile.Downloadcount = 1
insertFile.LastDownloadtime = time.Now()
5 months ago
errInsert := models.InsertFile(insertFile)
5 months ago
if errInsert == nil {
return true
}
}
return false
}