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.
|
|
|
|
package service
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"goftp/models"
|
|
|
|
|
"goftp/utils"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func UpdateDownloadCount(fileName string) bool {
|
|
|
|
|
file := models.FindFileByFileName(fileName)
|
|
|
|
|
if file != 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
|
|
|
|
|
}
|