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 }