product_interior.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package controllers
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/paging"
  4. "hongze/hongze_clpt/models"
  5. "hongze/hongze_clpt/services"
  6. "hongze/hongze_clpt/utils"
  7. )
  8. // 产品内测
  9. type ProductInteriorController struct {
  10. BaseAuthController
  11. }
  12. // @Title 列表
  13. // @Description 列表接口
  14. // @Param PageSize query int true "每页数据条数"
  15. // @Param CurrentIndex query int true "当前页页码,从1开始"
  16. // @Success Ret=200 {object} cygx.GetCygxTacticsTimeLineResp
  17. // @router /list [get]
  18. func (this *ProductInteriorController) List() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. user := this.User
  25. if user == nil {
  26. br.Msg = "请登录"
  27. br.ErrMsg = "请登录,用户信息为空"
  28. br.Ret = 408
  29. return
  30. }
  31. resp := new(models.GetCygxProductInteriorResp)
  32. pageSize, _ := this.GetInt("PageSize")
  33. currentIndex, _ := this.GetInt("CurrentIndex")
  34. var startSize int
  35. if pageSize <= 0 {
  36. pageSize = utils.PageSize20
  37. }
  38. if currentIndex <= 0 {
  39. currentIndex = 1
  40. }
  41. startSize = utils.StartIndex(currentIndex, pageSize)
  42. var condition string
  43. var pars []interface{}
  44. condition += ` AND art.status = 1 `
  45. total, err := models.GetCygxProductInteriorCount(condition, pars)
  46. if err != nil {
  47. br.Msg = "获取失败"
  48. br.ErrMsg = "获取失败,Err:" + err.Error()
  49. return
  50. }
  51. condition += " ORDER BY art.publish_time DESC , art.product_interior_id DESC "
  52. list, err := models.GetCygxProductInteriorList(condition, pars, startSize, pageSize)
  53. if err != nil {
  54. br.Msg = "获取失败"
  55. br.ErrMsg = "获取失败,Err:" + err.Error()
  56. return
  57. }
  58. for _, v := range list {
  59. v.PublishTime = utils.TimeRemoveHms(v.PublishTime)
  60. }
  61. page := paging.GetPaging(currentIndex, pageSize, total)
  62. resp.List = list
  63. resp.Paging = page
  64. br.Ret = 200
  65. br.Success = true
  66. br.Msg = "获取成功"
  67. br.Data = resp
  68. }
  69. // @Title 详情
  70. // @Description 获取详情接口
  71. // @Param ProductInteriorId query int true "ID"
  72. // @Success Ret=200 {object} cygx.GetCygxProductInteriorDetailResp
  73. // @router /detail [get]
  74. func (this *ProductInteriorController) Detail() {
  75. br := new(models.BaseResponse).Init()
  76. defer func() {
  77. this.Data["json"] = br
  78. this.ServeJSON()
  79. }()
  80. user := this.User
  81. if user == nil {
  82. br.Msg = "请登录"
  83. br.ErrMsg = "请登录,用户信息为空"
  84. br.Ret = 408
  85. return
  86. }
  87. resp := new(models.GetCygxProductInteriorDetailResp)
  88. productInteriorId, _ := this.GetInt("ProductInteriorId")
  89. if productInteriorId < 1 {
  90. br.Msg = "请输入详情ID"
  91. return
  92. }
  93. detail, err := models.GetCygxProductInteriorDetail(productInteriorId)
  94. if err != nil {
  95. br.Msg = "详情不存在"
  96. br.ErrMsg = "获取失败,Err:" + err.Error()
  97. return
  98. }
  99. //判断用户权限
  100. hasPermission, err := services.GetUserhasPermission(user)
  101. if err != nil {
  102. br.Msg = "获取信息失败"
  103. br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
  104. }
  105. //未设置全部可见的只能给弘则内部查看
  106. if detail.VisibleRange == 1 || user.CompanyId == utils.HZ_COMPANY_ID {
  107. resp.IsShow = true
  108. }
  109. resp.HasPermission = hasPermission
  110. if hasPermission != 1 || !resp.IsShow {
  111. br.Ret = 200
  112. br.Success = true
  113. br.Msg = "获取成功"
  114. br.Data = resp
  115. return
  116. }
  117. detail.PublishTime = utils.TimeRemoveHms2(detail.PublishTime)
  118. detail.ShareImg = utils.PRODUCT_INTERIOR_SHARE_IMG
  119. resp.Detail = detail
  120. detail.BodySlice = services.GetProductInteriorUrlBody(detail.Body)
  121. resp.Disclaimers = utils.DISCLAIMERS_PRODUCT_INTERIOR // 免责声明
  122. go services.AddCygxProductInteriorHistory(user, productInteriorId)
  123. go services.ProductInteriorHistoryUserRmind(user, productInteriorId)
  124. br.Ret = 200
  125. br.Success = true
  126. br.Msg = "获取成功"
  127. br.Data = resp
  128. }