product.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package service
  2. import (
  3. "cc-officialweb/models"
  4. "cc-officialweb/utils"
  5. )
  6. // GetIndexProductServe 首页获取产品服务
  7. func GetIndexProductServe(types string) []models.Products {
  8. var serve []models.Products
  9. tx := utils.DB.Where("type = ?", types).Where("is_index = ?", true).Find(&serve)
  10. if tx.Error != nil {
  11. return nil
  12. }
  13. return serve
  14. }
  15. // GetProduct 获取所有产品
  16. func GetProduct(ptype string) []models.Products {
  17. var serve []models.Products
  18. tx := utils.DB.Where("type = ?", "product").Where("ptype = ?", ptype).Find(&serve)
  19. if tx.Error != nil {
  20. return nil
  21. }
  22. return serve
  23. }
  24. func GetProductDetail(id int) models.Products {
  25. var server models.Products
  26. tx := utils.DB.Where("id = ?", id).First(&server)
  27. if tx.Error != nil {
  28. return server
  29. }
  30. return server
  31. }
  32. // AddProduct 添加产品
  33. func AddProduct(product models.ProductDto) bool {
  34. products := models.Products{
  35. Title: product.Title,
  36. Synopsis: product.Synopsis,
  37. Detail: product.Detail,
  38. Type: product.Type,
  39. Ptype: product.Ptype,
  40. IsIndex: product.IsIndex,
  41. Url: product.Url,
  42. ProductIntroduction: product.ProductIntroduction,
  43. TechnicalParameters: product.TechnicalParameters,
  44. Instructions: product.Instructions,
  45. SupportingSoftware: product.SupportingSoftware,
  46. OptionalAccessories: product.OptionalAccessories,
  47. IsActive: product.IsActive,
  48. }
  49. tx := utils.DB.Create(&products)
  50. if tx.RowsAffected > 0 {
  51. return true
  52. }
  53. return false
  54. }