This commit is contained in:
2026-04-14 13:37:39 +08:00
parent c4dd44ae89
commit 2334588b26
11 changed files with 342 additions and 85 deletions
+3 -3
View File
@@ -139,7 +139,7 @@ func ApiPurchase(r *gin.RouterGroup) {
for _, b := range binds {
fileIDs = append(fileIDs, b.FileID)
}
var files []models.TabFileInfo_
var files []TabFileInfo_
if len(fileIDs) > 0 {
models.DB.Where("id IN ?", fileIDs).Find(&files)
}
@@ -448,7 +448,7 @@ func ApiPurchase(r *gin.RouterGroup) {
//绑定文件
for i := 0; i < len(jsondata.Photos); i++ {
findFile := models.TabFileInfo_{
findFile := TabFileInfo_{
Sha256: jsondata.Photos[i],
Type: "image",
}
@@ -588,7 +588,7 @@ func ApiPurchase(r *gin.RouterGroup) {
// 重建图片绑定:先删旧,再插新
models.DB.Where("order_id = ?", from.ID).Delete(&TabPurchaseFileBind{})
for _, hash := range from.Photos {
findFile := models.TabFileInfo_{Sha256: hash, Type: "image"}
findFile := TabFileInfo_{Sha256: hash, Type: "image"}
if models.DB.Where(&findFile).First(&findFile).Error == nil {
models.DB.Create(&TabPurchaseFileBind{
OrderID: from.ID,
+22 -3
View File
@@ -6,14 +6,33 @@ import (
"ops/models"
"path"
"path/filepath"
"time"
"github.com/gin-gonic/gin"
)
type TabFileInfo_ struct {
ID uint `gorm:"primaryKey;autoIncrement"`
Name string `gorm:"not null;size:256;index"` // 前端报告的文件名
Path string `gorm:"not null;size:300"` //
Sha256 string `gorm:"not null;size:64;index"` //
Mime string `gorm:"size:64;index"`
Type string `gorm:"size:64;index"`
Const uint `gorm:"default:1;index"`
Per uint `gorm:"default:1"`
UserID uint `gorm:"not null;index"`
Date time.Time `gorm:"type:datetime;default:CURRENT_TIMESTAMP"` // 默认当前时间
}
func file_save() {
}
func ApiFilesInit() {
models.DB.AutoMigrate(&TabFileInfo_{})
}
func ApiFiles(r *gin.RouterGroup) {
//getfile := r.Group("/get") //定义上传组
@@ -35,7 +54,7 @@ func ApiFiles(r *gin.RouterGroup) {
download = false
}
if isPartOK {
file_info := models.TabFileInfo_{
file_info := TabFileInfo_{
Sha256: hash,
}
if models.DB.Where(&file_info).First(&file_info).Error == nil {
@@ -107,14 +126,14 @@ func ApiFiles(r *gin.RouterGroup) {
}
//记录到数据库
//先检查数据库有没有数据
fund_file_info := models.TabFileInfo_{
fund_file_info := TabFileInfo_{
Name: filename,
Sha256: hash_str,
Mime: mimeType,
Type: "image",
UserID: user.ID,
}
fund_file_info2 := models.TabFileInfo_{}
fund_file_info2 := TabFileInfo_{}
models.DB.Where(&fund_file_info).Find(&fund_file_info2)
+1 -2
View File
@@ -3,7 +3,6 @@ package routers
import (
"encoding/json"
"fmt"
"ops/models"
"github.com/gin-gonic/gin"
)
@@ -35,7 +34,7 @@ func ReturnJson(ctx *gin.Context, errMsg string, data map[string]interface{}) {
}
func ReturnFile(ctx *gin.Context, file_info *models.TabFileInfo_, preview bool) {
func ReturnFile(ctx *gin.Context, file_info *TabFileInfo_, preview bool) {
if preview {
ctx.File(file_info.Path)
} else {