Ethan преди 3 месеца
родител
ревизия
bc645fd4ea
променени са 5 файла, в които са добавени 40 реда и са изтрити 1 реда
  1. 7 0
      app/dao/product_dao.go
  2. 11 0
      app/entity/info_product_category.go
  3. 19 0
      app/service/product_service.go
  4. 1 0
      app/vo/re_product_preview.go
  5. 2 1
      route/init.go

+ 7 - 0
app/dao/product_dao.go

@@ -120,3 +120,10 @@ func (d ProductDAO) GetProductByProjectId(projectId string) (*entity.Product, er
 	}
 	return &productInfo, nil
 }
+
+// 获取商品类目
+func (d ProductDAO) GetProductCategorys() ([]entity.InfoProductCategory, error) {
+	var infoProductCategorys []entity.InfoProductCategory
+	err := Db.Model(&entity.InfoProductCategory{}).Find(&infoProductCategorys).Order("id").Error
+	return infoProductCategorys, err
+}

+ 11 - 0
app/entity/info_product_category.go

@@ -0,0 +1,11 @@
+// Code generated by sql2gorm. DO NOT EDIT.
+package entity
+
+type InfoProductCategory struct {
+	ID              int64  `gorm:"column:id;primary_key;AUTO_INCREMENT"` // 商品类型id
+	ProductCategory string `gorm:"column:product_category;NOT NULL"`     // 商品类型
+}
+
+func (m *InfoProductCategory) TableName() string {
+	return "info_product_category"
+}

+ 19 - 0
app/service/product_service.go

@@ -40,8 +40,13 @@ func (p ProductService) GetTaskProductsByUserId(param vo.GetAllProductParam) (vo
 		return result, err
 	}
 	var reProducts []vo.ReProductPreview
+	var creatorName string
 	for _, product := range products {
 		photoUrl, e := dao.ProductPhotoDAO{}.GetMainPhotoByProductID(product.ProductID)
+		enterprise, err := dao.EnterpriseDao{}.GetEnterprise(product.EnterpriseID)
+		if err == nil && enterprise != nil {
+			creatorName = enterprise.BusinessName
+		}
 		if e != nil {
 			photoUrl = ""
 		}
@@ -54,6 +59,7 @@ func (p ProductService) GetTaskProductsByUserId(param vo.GetAllProductParam) (vo
 			ProductDetail:   product.ProductDetail,
 			CreatedAt:       product.CreatedAt.Format("2006-01-02 15:04:05"),
 			PhotoUrl:        photoUrl,
+			CreateName:      creatorName,
 		}
 		reProducts = append(reProducts, reProduct)
 	}
@@ -195,3 +201,16 @@ func (p ProductService) DeleteProduct(param *vo.ProductUpdateParam) (int64, erro
 	}
 	return param.ProductId, nil
 }
+
+// 获取商品类目
+func (p ProductService) GetProductCategorys() ([]string, error) {
+	var categorys []string
+	productCategorys, err := dao.ProductDAO{}.GetProductCategorys()
+	if err != nil {
+		return nil, err
+	}
+	for _, productCategory := range productCategorys {
+		categorys = append(categorys, productCategory.ProductCategory)
+	}
+	return categorys, nil
+}

+ 1 - 0
app/vo/re_product_preview.go

@@ -9,4 +9,5 @@ type ReProductPreview struct {
 	ProductDetail   string  `json:"productDetail"`
 	CreatedAt       string  `json:"createdAt"`
 	PhotoUrl        string  `json:"photoUrl"`
+	CreateName      string  `json:"createName"`
 }

+ 2 - 1
route/init.go

@@ -351,6 +351,7 @@ func InitRoute(r *gin.Engine) {
 	// 账号管理
 	common := r.Group("/youngee/b/common")
 	{
-		common.POST("/platform", controller.CommonController{}.CooperationPlatform) // 获取合作平台icon
+		common.POST("/platform", controller.CommonController{}.CooperationPlatform)     // 获取合作平台icon
+		common.POST("/product/category", controller.CommonController{}.ProductCategory) // 获取商品类目
 	}
 }