product_interior.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package controllers
  2. import (
  3. "fmt"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/services"
  7. "hongze/hongze_cygx/utils"
  8. "regexp"
  9. "strings"
  10. )
  11. // 产品内测
  12. type ProductInteriorController struct {
  13. BaseAuthController
  14. }
  15. // @Title 列表
  16. // @Description 列表接口
  17. // @Param PageSize query int true "每页数据条数"
  18. // @Param CurrentIndex query int true "当前页页码,从1开始"
  19. // @Success Ret=200 {object} cygx.GetCygxTacticsTimeLineResp
  20. // @router /list [get]
  21. func (this *ProductInteriorController) List() {
  22. br := new(models.BaseResponse).Init()
  23. defer func() {
  24. this.Data["json"] = br
  25. this.ServeJSON()
  26. }()
  27. user := this.User
  28. if user == nil {
  29. br.Msg = "请登录"
  30. br.ErrMsg = "请登录,用户信息为空"
  31. br.Ret = 408
  32. return
  33. }
  34. resp := new(models.GetCygxProductInteriorResp)
  35. pageSize, _ := this.GetInt("PageSize")
  36. currentIndex, _ := this.GetInt("CurrentIndex")
  37. var startSize int
  38. if pageSize <= 0 {
  39. pageSize = utils.PageSize20
  40. }
  41. if currentIndex <= 0 {
  42. currentIndex = 1
  43. }
  44. startSize = utils.StartIndex(currentIndex, pageSize)
  45. var condition string
  46. var pars []interface{}
  47. condition += ` AND art.status = 1 `
  48. total, err := models.GetCygxProductInteriorCount(condition, pars)
  49. if err != nil {
  50. br.Msg = "获取失败"
  51. br.ErrMsg = "获取失败,Err:" + err.Error()
  52. return
  53. }
  54. condition += " ORDER BY art.publish_time DESC , art.product_interior_id DESC "
  55. list, err := models.GetCygxProductInteriorList(condition, pars, startSize, pageSize)
  56. if err != nil {
  57. br.Msg = "获取失败"
  58. br.ErrMsg = "获取失败,Err:" + err.Error()
  59. return
  60. }
  61. for _, v := range list {
  62. v.PublishTime = utils.TimeRemoveHms(v.PublishTime)
  63. }
  64. page := paging.GetPaging(currentIndex, pageSize, total)
  65. resp.List = list
  66. resp.Paging = page
  67. br.Ret = 200
  68. br.Success = true
  69. br.Msg = "获取成功"
  70. br.Data = resp
  71. }
  72. // @Title 详情
  73. // @Description 获取详情接口
  74. // @Param ProductInteriorId query int true "ID"
  75. // @Success Ret=200 {object} cygx.GetCygxProductInteriorDetailResp
  76. // @router /detail [get]
  77. func (this *ProductInteriorController) Detail() {
  78. br := new(models.BaseResponse).Init()
  79. defer func() {
  80. this.Data["json"] = br
  81. this.ServeJSON()
  82. }()
  83. user := this.User
  84. if user == nil {
  85. br.Msg = "请登录"
  86. br.ErrMsg = "请登录,用户信息为空"
  87. br.Ret = 408
  88. return
  89. }
  90. resp := new(models.GetCygxProductInteriorDetailResp)
  91. productInteriorId, _ := this.GetInt("ProductInteriorId")
  92. if productInteriorId < 1 {
  93. br.Msg = "请输入详情ID"
  94. return
  95. }
  96. detail, err := models.GetCygxProductInteriorDetail(productInteriorId)
  97. if err != nil {
  98. br.Msg = "详情不存在"
  99. br.ErrMsg = "获取失败,Err:" + err.Error()
  100. return
  101. }
  102. //判断用户权限
  103. hasPermission, err := services.GetUserhasPermission(user)
  104. if err != nil {
  105. br.Msg = "获取信息失败"
  106. br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
  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. body := detail.Body
  123. var randStrStart = "start_cygx_{|}"
  124. var randStr = "start_cygx_{|}_end_cygx"
  125. urlMap := make(map[string]string)
  126. var hrefRegexp = regexp.MustCompile(utils.RegularUrl)
  127. match := hrefRegexp.FindAllString(body, -1)
  128. if match != nil {
  129. for _, v := range match {
  130. body = strings.Replace(body, fmt.Sprint("href=\"", v, "\""), "", -1)
  131. body = strings.Replace(body, fmt.Sprint("<a >"), "", -1)
  132. body = strings.Replace(body, fmt.Sprint("</a>"), "", -1)
  133. body = strings.Replace(body, v, randStrStart+v+randStr, -1)
  134. urlMap[v] = v
  135. }
  136. }
  137. sliceBody := strings.Split(body, randStr)
  138. var sliceBodyUrl []string
  139. for _, v := range sliceBody {
  140. sliceUrl := strings.Split(v, randStrStart)
  141. for _, url := range sliceUrl {
  142. if url == "" {
  143. continue
  144. }
  145. sliceBodyUrl = append(sliceBodyUrl, url)
  146. }
  147. }
  148. for _, v := range sliceBodyUrl {
  149. detail.BodySlice = append(detail.BodySlice, services.GetProductInteriorUrl(v, urlMap))
  150. }
  151. go services.AddCygxProductInteriorHistory(user, productInteriorId)
  152. br.Ret = 200
  153. br.Success = true
  154. br.Msg = "获取成功"
  155. br.Data = resp
  156. }