Ver código fonte

素材接口

urbanu 1 mês atrás
pai
commit
1993cd07ea
2 arquivos alterados com 39 adições e 46 exclusões
  1. 23 34
      apis/daytask/material.go
  2. 16 12
      commons/model/entity/dt_material.go

+ 23 - 34
apis/daytask/material.go

@@ -26,7 +26,8 @@ func (s *Server) MaterialList(c *gin.Context) {
 	ctx := s.FromContext(c)
 	db := s.DB()
 
-	categoryId := ctx.QueryInt64("categoryId", 0)
+	groupId := ctx.QueryInt64("groupId", 0)
+	materialType := ctx.QueryString("type", "")
 
 	paging := &services.Pagination{
 		Current: ctx.QueryInt64("current", 1),
@@ -35,28 +36,28 @@ func (s *Server) MaterialList(c *gin.Context) {
 
 	query := db.Model(&entity.DtMaterial{}).Where("status = ?", 1)
 
-	if categoryId > 0 {
-		query = query.Where("category_id = ?", categoryId)
+	if groupId > 0 {
+		query = query.Where("group_id = ?", groupId)
+	}
+
+	if materialType != "" {
+		query = query.Where("type = ?", materialType)
 	}
 
 	query.Count(&paging.Total)
 	paging.Computer()
 
 	type MaterialInfo struct {
-		Id          int64  `json:"id"`
-		Title       string `json:"title"`
-		TitleVi     string `json:"titleVi"`
-		Type        string `json:"type"`
-		Icon        string `json:"icon"`
-		Images      string `json:"images"`
-		Videos      string `json:"videos"`
-		TextContent string `json:"textContent"`
-		ViewCount   int    `json:"viewCount"`
-		CreatedAt   int64  `json:"createdAt"`
+		Id        int64  `json:"id"`
+		Name      string `json:"name"`
+		Url       string `json:"url"`
+		Content   string `json:"content"`
+		Type      string `json:"type"`
+		CreatedAt int64  `json:"createdAt"`
 	}
 
 	materials := make([]*MaterialInfo, 0)
-	query.Select("id, title, title_vi, type, icon, images, videos, text_content, view_count, created_at").
+	query.Select("id, name, url, content, type, created_at").
 		Order("sort ASC, id DESC").
 		Offset(int(paging.Start)).
 		Limit(int(paging.Size)).
@@ -88,25 +89,17 @@ func (s *Server) MaterialDetail(c *gin.Context) {
 		return
 	}
 
-	// 更新浏览次数
-	db.Model(&entity.DtMaterial{}).Where("id = ?", req.Id).
-		Update("view_count", material.ViewCount+1)
-
 	ctx.OK(gin.H{
-		"id":          material.Id,
-		"title":       material.Title,
-		"titleVi":     material.TitleVi,
-		"type":        material.Type,
-		"icon":        material.Icon,
-		"images":      material.Images,
-		"videos":      material.Videos,
-		"textContent": material.TextContent,
-		"viewCount":   material.ViewCount + 1,
-		"createdAt":   material.CreatedAt,
+		"id":        material.Id,
+		"name":      material.Name,
+		"url":       material.Url,
+		"content":   material.Content,
+		"type":      material.Type,
+		"createdAt": material.CreatedAt,
 	})
 }
 
-// MaterialLike 素材点赞 - 由于实体没有likeCount字段,改为增加浏览次数
+// MaterialLike 素材点赞
 func (s *Server) MaterialLike(c *gin.Context) {
 	ctx := s.FromContext(c)
 	db := s.DB()
@@ -126,11 +119,7 @@ func (s *Server) MaterialLike(c *gin.Context) {
 		return
 	}
 
-	// 更新浏览次数(用作点赞计数)
-	db.Model(&entity.DtMaterial{}).Where("id = ?", req.Id).
-		Update("view_count", material.ViewCount+1)
-
 	ctx.OK(gin.H{
-		"viewCount": material.ViewCount + 1,
+		"success": true,
 	})
 }

+ 16 - 12
commons/model/entity/dt_material.go

@@ -1,19 +1,23 @@
 package entity
 
-// DtMaterial 素材表
+// DtMaterial 素材表 (与admin端dt_material表结构一致)
 type DtMaterial struct {
 	MysqlBaseModel
-	Title       string `json:"title" gorm:"type:varchar(128);comment:素材标题"`
-	TitleVi     string `json:"titleVi" gorm:"type:varchar(128);comment:素材标题(越南语)"`
-	CategoryId  int64  `json:"categoryId" gorm:"index:idx_category_id;comment:分类ID"`
-	Type        string `json:"type" gorm:"type:varchar(32);index:idx_type;comment:类型: image/text/video"`
-	Images      string `json:"images" gorm:"type:text;comment:图片列表(JSON数组)"`
-	Videos      string `json:"videos" gorm:"type:text;comment:视频列表(JSON数组)"`
-	TextContent string `json:"textContent" gorm:"type:text;comment:文字内容"`
-	Icon        string `json:"icon" gorm:"type:varchar(255);comment:素材图标"`
-	ViewCount   int    `json:"viewCount" gorm:"default:0;comment:浏览次数"`
-	Status      int8   `json:"status" gorm:"default:1;comment:状态: 0=禁用 1=启用"`
-	Sort        int    `json:"sort" gorm:"default:0;comment:排序"`
+	Name     string `json:"name" gorm:"column:name;type:varchar(128);comment:文件名"`
+	Path     string `json:"path" gorm:"column:path;type:varchar(512);comment:文件路径"`
+	Url      string `json:"url" gorm:"column:url;type:varchar(512);comment:访问URL"`
+	Content  string `json:"content" gorm:"column:content;type:text;comment:文字内容(type=text时使用)"`
+	Type     string `json:"type" gorm:"column:type;type:varchar(32);index:idx_type;comment:类型: image/video/text"`
+	MimeType string `json:"mimeType" gorm:"column:mime_type;type:varchar(128);comment:MIME类型"`
+	Size     int64  `json:"size" gorm:"column:size;default:0;comment:文件大小(字节)"`
+	Width    int    `json:"width" gorm:"column:width;default:0;comment:宽度(图片/视频)"`
+	Height   int    `json:"height" gorm:"column:height;default:0;comment:高度(图片/视频)"`
+	Duration int    `json:"duration" gorm:"column:duration;default:0;comment:时长(视频/音频,秒)"`
+	Storage  string `json:"storage" gorm:"column:storage;type:varchar(32);default:local;comment:存储: local/oss/cos"`
+	GroupId  int64  `json:"groupId" gorm:"column:group_id;index:idx_group_id;comment:分组ID"`
+	AdminId  int64  `json:"adminId" gorm:"column:admin_id;default:0;comment:上传管理员ID"`
+	Status   int8   `json:"status" gorm:"column:status;default:1;comment:状态: 0=禁用 1=启用"`
+	Sort     int64  `json:"sort" gorm:"column:sort;default:0;comment:排序"`
 }
 
 func (*DtMaterial) TableName() string {