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
710 B
Go

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