gushou.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/models/time_line"
  7. "hongze/hongze_cygx/services"
  8. "hongze/hongze_cygx/utils"
  9. "time"
  10. )
  11. // 固收
  12. type GushouController struct {
  13. BaseAuthController
  14. }
  15. // @Title 固收时间线列表
  16. // @Description 固收时间线列表接口
  17. // @Param PageSize query int true "每页数据条数"
  18. // @Param CurrentIndex query int true "当前页页码,从1开始"
  19. // @Success 200 {object} models.GetCygxGushouTimeLineResp
  20. // @router /gushouTimeLine/list [get]
  21. func (this *GushouController) GushouTimeLineList() {
  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(time_line.GetCygxGushouTimeLineResp)
  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 := time_line.GetCygxGushouTimeLineCount(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.time_line_id DESC "
  55. list, err := time_line.GetCygxGushouTimeLineList(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.TimeRemoveHms2(v.PublishTime)
  63. v.Resource = 1
  64. v.Content = services.AnnotationHtml(v.Content)
  65. v.ChartPermissionName = utils.GU_SHOU_NAME
  66. }
  67. if len(list) == 0 {
  68. list = make([]*time_line.CygxGushouTimeLineResp, 0)
  69. }
  70. cf, err := models.GetConfigByCode(utils.CYGX_GUSHOU_TIME_LINE_STATUS)
  71. if err != nil {
  72. br.Msg = "获取失败"
  73. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  74. return
  75. }
  76. //如果不是弘则用户,并且设置了内部可见,那么数据就隐藏
  77. if user.CompanyId != utils.HZ_COMPANY_ID && cf.ConfigValue != "1" {
  78. list = make([]*time_line.CygxGushouTimeLineResp, 0)
  79. }
  80. page := paging.GetPaging(currentIndex, pageSize, total)
  81. resp.List = list
  82. resp.Paging = page
  83. br.Ret = 200
  84. br.Success = true
  85. br.Msg = "获取成功"
  86. br.Data = resp
  87. }
  88. // @Title 固收时间线点击记录
  89. // @Description 固收时间线点击记录接口
  90. // @Param request body models.GushouTimeLineTimeLineIdReq true "type json string"
  91. // @Success Ret=200 新增成功
  92. // @router /gushouTimeLine/history [post]
  93. func (this *GushouController) History() {
  94. br := new(models.BaseResponse).Init()
  95. defer func() {
  96. this.Data["json"] = br
  97. this.ServeJSON()
  98. }()
  99. user := this.User
  100. if user == nil {
  101. br.Msg = "请登录"
  102. br.ErrMsg = "请登录,用户信息为空"
  103. br.Ret = 408
  104. return
  105. }
  106. var req models.TacticsTimeLineTimeLineIdReq
  107. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  108. if err != nil {
  109. br.Msg = "参数解析异常!"
  110. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  111. return
  112. }
  113. timeLineId := req.TimeLineId
  114. if timeLineId == 0 {
  115. br.Msg = "时间线ID错误"
  116. return
  117. }
  118. var sellerName string
  119. sellerName, err = models.GetCompanySellerNameRai(user.CompanyId)
  120. if err != nil {
  121. br.Msg = "记录失败!"
  122. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  123. return
  124. }
  125. item := time_line.CygxGushouTimeLineHistory{
  126. TimeLineId: timeLineId,
  127. UserId: user.UserId,
  128. Mobile: user.Mobile,
  129. Email: user.Email,
  130. CompanyId: user.CompanyId,
  131. CompanyName: user.CompanyName,
  132. RealName: user.RealName,
  133. SellerName: sellerName,
  134. CreateTime: time.Now(),
  135. ModifyTime: time.Now(),
  136. }
  137. err = time_line.AddCygxGushouTimeLineHistory(&item)
  138. br.Ret = 200
  139. br.Success = true
  140. br.Msg = "获取成功"
  141. }