user_admin_share_history.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package cygx
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/paging"
  4. "hongze/hz_crm_api/controllers"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/cygx"
  7. "hongze/hz_crm_api/utils"
  8. "strconv"
  9. )
  10. // 分享记录
  11. type UserAdminShareHistoryController struct {
  12. controllers.BaseAuthController
  13. }
  14. // @Title 分享记录列表
  15. // @Description 分享记录列表接口
  16. // @Param PageSize query int true "每页数据条数"
  17. // @Param CurrentIndex query int true "当前页页码,从1开始"
  18. // @Param StartDate query string false "开始时间 ,列如2021-03-06 "
  19. // @Param EndDate query string false "结束时间,列如2021-03-06 "
  20. // @Param AdminId query string false "销售ID "
  21. // @Param KeyWord query string false "搜索关键词"
  22. // @Param Action query string false "用户行为"
  23. // @Success Ret=200 {object} cygx.GetCygxUserAdminShareHistoryListResp
  24. // @router /mfyx/admin/share/list [get]
  25. func (this *UserAdminShareHistoryController) OrderList() {
  26. br := new(models.BaseResponse).Init()
  27. defer func() {
  28. this.Data["json"] = br
  29. this.ServeJSON()
  30. }()
  31. sysUser := this.SysUser
  32. if sysUser == nil {
  33. br.Msg = "请登录"
  34. br.ErrMsg = "请登录,SysUser Is Empty"
  35. br.Ret = 408
  36. return
  37. }
  38. resp := new(cygx.GetCygxUserAdminShareHistoryListResp)
  39. pageSize, _ := this.GetInt("PageSize")
  40. currentIndex, _ := this.GetInt("CurrentIndex")
  41. startDate := this.GetString("StartDate")
  42. endDate := this.GetString("EndDate")
  43. adminId := this.GetString("AdminId")
  44. keyWord := this.GetString("KeyWord")
  45. action := this.GetString("Action")
  46. var startSize int
  47. if pageSize <= 0 {
  48. pageSize = utils.PageSize20
  49. }
  50. if currentIndex <= 0 {
  51. currentIndex = 1
  52. }
  53. startSize = utils.StartIndex(currentIndex, pageSize)
  54. var condition string
  55. var pars []interface{}
  56. condition += ` AND company_id != 16 ` // 过滤弘则
  57. if startDate != "" && endDate != "" { //时间范围
  58. startDate += " 00:00:00"
  59. endDate += " 23:59:59"
  60. condition += ` AND create_time BETWEEN ? AND ? `
  61. pars = append(pars, startDate, endDate)
  62. }
  63. if adminId != "" { //所属销售筛选
  64. condition += ` AND share_id IN (` + adminId + `) `
  65. }
  66. //用户行为搜索
  67. //if action == "查看专栏" || action == "查看报告" || action == "查看活动" || action == "注册" {
  68. if action != "" {
  69. condition += " AND action = ? "
  70. pars = append(pars, action)
  71. }
  72. //如果不是权益管理员和admin,就做可见权限限制
  73. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  74. condition += ` AND share_id IN (` + strconv.Itoa(sysUser.AdminId) + `) `
  75. }
  76. if keyWord != "" { //用户姓名,手机号
  77. keyWord = "%" + keyWord + "%"
  78. condition += ` AND (mobile LIKE ? OR real_name LIKE ? ) `
  79. pars = append(pars, keyWord, keyWord)
  80. }
  81. total, err := cygx.GetCygxUserAdminShareHistoryCount(condition, pars)
  82. if err != nil {
  83. br.Msg = "获取失败"
  84. br.ErrMsg = "获取失败,Err:" + err.Error()
  85. return
  86. }
  87. condition += " ORDER BY user_admin_share_history_id DESC "
  88. list, err := cygx.GetCygxUserAdminShareHistoryList(condition, pars, startSize, pageSize)
  89. if err != nil {
  90. br.Msg = "获取失败"
  91. br.ErrMsg = "获取失败,Err:" + err.Error()
  92. return
  93. }
  94. var mobiles []string
  95. for _, v := range list {
  96. mobiles = append(mobiles, v.Mobile)
  97. }
  98. listUser, err := models.GetWxUserRaiSllerListByUserMobile(mobiles)
  99. if err != nil {
  100. br.Msg = "获取失败"
  101. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  102. return
  103. }
  104. //获取用户当前最新的公司信息
  105. mapWxUserSller := make(map[string]*models.WxUserSller)
  106. for _, v := range listUser {
  107. mapWxUserSller[v.Mobile] = v
  108. }
  109. for _, v := range list {
  110. switch v.Source {
  111. case utils.CYGX_OBJ_ARTICLE: //文章详情
  112. v.HttpUrl = utils.CYGX_MFYX_URL + "/material/info/" + strconv.Itoa(v.SourceId)
  113. case utils.CYGX_OBJ_ACTIVITY, utils.CYGX_OBJ_ACTIVITYVIDEO, utils.CYGX_OBJ_ACTIVITYVOICE: //活动详情
  114. v.HttpUrl = utils.CYGX_MFYX_URL + "/activity/detail/" + strconv.Itoa(v.SourceId)
  115. case utils.CYGX_OBJ_YANXUANSPECIAL: //研选专栏
  116. v.HttpUrl = utils.CYGX_MFYX_URL + "/column/detail/" + strconv.Itoa(v.SourceId)
  117. }
  118. switch v.RegisterPlatform {
  119. case 5:
  120. v.RegisterPlatformText = "研选小程序"
  121. case 6:
  122. v.RegisterPlatformText = "研选网页版"
  123. }
  124. mapItem := mapWxUserSller[v.Mobile]
  125. if mapItem != nil {
  126. v.CompanyName = mapItem.CompanyName
  127. v.CompanyId = mapItem.CompanyId
  128. v.RealName = mapItem.RealName
  129. } else {
  130. v.RealName = "--"
  131. v.CompanyName = "--"
  132. v.CompanyId = 1
  133. }
  134. }
  135. page := paging.GetPaging(currentIndex, pageSize, total)
  136. resp.Paging = page
  137. resp.List = list
  138. br.Ret = 200
  139. br.Success = true
  140. br.Msg = "获取成功"
  141. br.Data = resp
  142. }