tactics.go 3.8 KB

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