1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- 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
- }
|