package service import ( "cc-officialweb/models" "cc-officialweb/utils" ) // GetIndexProductServe 首页获取产品服务 func GetIndexProductServe(types string) []models.Products { var serve []models.Products tx := utils.DB.Where("type = ?", types).Where("is_index = ?", true).Find(&serve) if tx.Error != nil { return nil } return serve } // GetProduct 获取所有产品 func GetProduct(ptype string) []models.Products { var serve []models.Products tx := utils.DB.Where("type = ?", "product").Where("ptype = ?", ptype).Find(&serve) if tx.Error != nil { return nil } return serve } func GetProductDetail(id int) models.Products { var server models.Products tx := utils.DB.Where("id = ?", id).First(&server) if tx.Error != nil { return server } return server } // AddProduct 添加产品 func AddProduct(product models.ProductDto) bool { products := models.Products{ Title: product.Title, Synopsis: product.Synopsis, Detail: product.Detail, Type: product.Type, Ptype: product.Ptype, IsIndex: product.IsIndex, Url: product.Url, ProductIntroduction: product.ProductIntroduction, TechnicalParameters: product.TechnicalParameters, Instructions: product.Instructions, SupportingSoftware: product.SupportingSoftware, OptionalAccessories: product.OptionalAccessories, IsActive: product.IsActive, } tx := utils.DB.Create(&products) if tx.RowsAffected > 0 { return true } return false }