services.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package service
  2. import (
  3. "cc-officialweb/models"
  4. "cc-officialweb/utils"
  5. )
  6. // GetServicesByID 根据id获得最外层服务
  7. func GetServicesByID(id int) models.Products {
  8. var products models.Products
  9. tx := utils.DB.Where("id = ?", id).Where("type=?", "serve").First(&products)
  10. if tx.Error != nil {
  11. return products
  12. }
  13. return products
  14. }
  15. func GetServices() models.Products {
  16. var products models.Products
  17. tx := utils.DB.Where("type=?", "serve").First(&products)
  18. if tx.Error != nil {
  19. return products
  20. }
  21. return products
  22. }
  23. // GetService 根据id获得内层服务
  24. func GetService(productId int) []models.Server {
  25. var services []models.Server
  26. tx := utils.DB.Where("product_id=?", productId).Find(&services)
  27. if tx.Error != nil {
  28. return services
  29. }
  30. return services
  31. }
  32. // GetServiceDetail 根据id获得服务详情
  33. func GetServiceDetail(serId int) models.Server {
  34. var servicesDetail models.Server
  35. tx := utils.DB.Where("id=?", serId).First(&servicesDetail)
  36. if tx.Error != nil {
  37. return servicesDetail
  38. }
  39. return servicesDetail
  40. }
  41. // AddService 添加服务信息
  42. func AddService(serve models.Server) bool {
  43. tx := utils.DB.Create(&serve)
  44. if tx.RowsAffected > 0 {
  45. return true
  46. }
  47. return false
  48. }