index.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package controllers
  2. import (
  3. "cc-officialweb/service"
  4. beego "github.com/beego/beego/v2/server/web"
  5. )
  6. type MainController struct {
  7. beego.Controller
  8. }
  9. func (c *MainController) Get() {
  10. var banner []string
  11. var success []string
  12. var honor []string
  13. //获取轮播图
  14. resource := service.GetResource("banner")
  15. for _, v := range resource {
  16. banner = append(banner, v.Url)
  17. }
  18. //获取成功案例轮播图
  19. exams := service.GetResource("example")
  20. for _, v := range exams {
  21. success = append(success, v.Url)
  22. }
  23. //资质荣耀
  24. honors := service.GetResource("honor")
  25. for _, v := range honors {
  26. honor = append(honor, v.Url)
  27. }
  28. //产品服务
  29. products := service.GetIndexProductServe("product")
  30. serve := service.GetIndexProductServe("serve")
  31. //数据大屏展示
  32. getData, err := service.GetData(true)
  33. if err == nil {
  34. c.Data["Datas"] = getData
  35. } else {
  36. c.Data["Datas"] = "未获得数据"
  37. }
  38. //友情链接
  39. links := service.GetAllLinks()
  40. if links != nil {
  41. c.Data["Links"] = links
  42. }
  43. //获取产品分类
  44. productType := service.GetProductType()
  45. if len(productType) == 0 {
  46. c.Data["productFirst"] = "暂无产品分类"
  47. } else {
  48. c.Data["productFirst"] = productType[0].Name
  49. }
  50. c.Data["productType"] = productType
  51. c.Data["honor"] = honor
  52. c.Data["banner"] = banner
  53. c.Data["example"] = success
  54. c.Data["Products"] = products
  55. c.Data["Serves"] = serve
  56. c.TplName = "index.html"
  57. }