product_interior.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package controllers
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/paging"
  4. "hongze/hongze_cygx/models"
  5. "hongze/hongze_cygx/services"
  6. "hongze/hongze_cygx/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. if user.UserId == 0 {
  106. hasPermission = 1 //用户未登录(绑定登录信息)的时候也能展示 v12.2.1
  107. }
  108. //未设置全部可见的只能给弘则内部查看
  109. if detail.VisibleRange == 1 || user.CompanyId == utils.HZ_COMPANY_ID {
  110. resp.IsShow = true
  111. }
  112. resp.HasPermission = hasPermission
  113. if hasPermission != 1 || !resp.IsShow {
  114. br.Ret = 200
  115. br.Success = true
  116. br.Msg = "获取成功"
  117. br.Data = resp
  118. return
  119. }
  120. detail.PublishTime = utils.TimeRemoveHms2(detail.PublishTime)
  121. resp.Detail = detail
  122. detail.BodySlice, err = services.GetProductInteriorUrlBody(detail.Body, user)
  123. if err != nil {
  124. br.Msg = "获取信息失败"
  125. br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
  126. }
  127. resp.Disclaimers = utils.DISCLAIMERS // 免责声明
  128. go services.AddCygxProductInteriorHistory(user, productInteriorId)
  129. go services.ProductInteriorHistoryUserRmind(user, productInteriorId)
  130. br.Ret = 200
  131. br.Success = true
  132. br.Msg = "获取成功"
  133. br.Data = resp
  134. }