product-detail.go 660 B

12345678910111213141516171819202122232425262728293031
  1. package controllers
  2. import (
  3. "cc-officialweb/service"
  4. beego "github.com/beego/beego/v2/server/web"
  5. "strconv"
  6. )
  7. type DetailController struct {
  8. beego.Controller
  9. }
  10. func (d *DetailController) Get() {
  11. id := d.Ctx.Input.Param(":id")
  12. atoi, err := strconv.Atoi(id)
  13. if err != nil {
  14. d.Redirect("/", 302)
  15. }
  16. detail := service.GetProductDetail(atoi)
  17. productType := service.GetProductType()
  18. if len(productType) == 0 {
  19. d.Data["productFirst"] = "暂无产品分类"
  20. } else {
  21. d.Data["productFirst"] = productType[0].Name
  22. }
  23. d.Data["productType"] = productType
  24. d.Data["detail"] = detail
  25. d.Data["showSection"] = true
  26. d.TplName = "product-detail.html"
  27. }