user.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. package services
  2. import (
  3. "eta/eta_mini_crm/models"
  4. "eta/eta_mini_crm/utils"
  5. "time"
  6. )
  7. func GetUserPermissionById(userId int) (items []*models.ChartPermissionView, err error) {
  8. permissionIds, err := models.GetChartPermissionIdByUserId(userId)
  9. if err != nil {
  10. return
  11. }
  12. if len(permissionIds) == 0 {
  13. return
  14. }
  15. items, err = models.GetChartPermissionListByIds(permissionIds)
  16. if err != nil {
  17. return
  18. }
  19. return
  20. }
  21. func GetPotentialList(keyWord string, sellerDepartmentId int, applyStatus string, pageSize int, currentIndex int, sortParam string, sortType string, registerStartDate string, registerEndDate string, lastUpdateStartDate string, lastUpdateEndDate string, applyStartDate string, applyEndDate string) (userList []*models.UserView, total int, errMsg, msg string, err error) {
  22. var sortCondition string
  23. var condition string
  24. var pars []interface{}
  25. if keyWord != "" {
  26. condition += ` AND ( u.phone LIKE ? OR u.email LIKE ?) `
  27. pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
  28. }
  29. if sellerDepartmentId != 0 {
  30. condition += ` AND u.seller_department_id=? `
  31. pars = append(pars, sellerDepartmentId)
  32. }
  33. if applyStatus != "" {
  34. condition += ` AND u.apply_status=? `
  35. pars = append(pars, applyStatus)
  36. }
  37. if pageSize <= 0 {
  38. pageSize = utils.PageSize20
  39. }
  40. if currentIndex <= 0 {
  41. currentIndex = 1
  42. }
  43. if sortParam != "" && sortType != "" {
  44. sortCondition = " ORDER BY "
  45. var param, sort string
  46. switch sortParam {
  47. case "RegisterTime":
  48. param = "u.register_time"
  49. case "LastUpdateTime":
  50. param = "last_update_time"
  51. case "ReadCnt":
  52. param = "read_cnt"
  53. case "ApplyTime":
  54. param = "u.apply_time"
  55. }
  56. switch sortType {
  57. case "asc":
  58. sort = " ASC "
  59. case "desc":
  60. sort = " DESC "
  61. }
  62. if param != "" && sort != "" {
  63. sortCondition += param + " " + sort
  64. } else {
  65. sortCondition = ""
  66. }
  67. }
  68. if registerStartDate != "" {
  69. registerStartTime, er := time.Parse(utils.FormatDate, registerStartDate)
  70. if er != nil {
  71. err = er
  72. msg = "日期格式有误"
  73. return
  74. }
  75. condition += " AND u.register_time>=? "
  76. registerStartDateStr := registerStartTime.Format(utils.FormatDateTime)
  77. pars = append(pars, registerStartDateStr)
  78. }
  79. if registerEndDate != "" {
  80. registerEndTime, er := time.Parse(utils.FormatDate, registerEndDate)
  81. if er != nil {
  82. err = er
  83. msg = "日期格式有误"
  84. return
  85. }
  86. condition += " AND u.register_time<=? "
  87. // 结束时间包含今天
  88. registerEndTime = registerEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
  89. registerEndDateStr := registerEndTime.Format(utils.FormatDateTime)
  90. pars = append(pars, registerEndDateStr)
  91. }
  92. if lastUpdateStartDate != "" {
  93. lastUpdateStartTime, er := time.Parse(utils.FormatDate, lastUpdateStartDate)
  94. if er != nil {
  95. err = er
  96. msg = "日期格式有误"
  97. return
  98. }
  99. condition += " AND ur.create_time>=? "
  100. lastUpdateStartDateStr := lastUpdateStartTime.Format(utils.FormatDateTime)
  101. pars = append(pars, lastUpdateStartDateStr)
  102. }
  103. if lastUpdateEndDate != "" {
  104. lastUpdateEndTime, er := time.Parse(utils.FormatDate, lastUpdateEndDate)
  105. if er != nil {
  106. err = er
  107. msg = "日期格式有误"
  108. return
  109. }
  110. // 结束时间包含今天
  111. lastUpdateEndTime = lastUpdateEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
  112. lastUpdateEndDateStr := lastUpdateEndTime.Format(utils.FormatDateTime)
  113. condition += " AND ur.create_time<=? "
  114. pars = append(pars, lastUpdateEndDateStr)
  115. }
  116. if applyStartDate != "" {
  117. applyStartTime, er := time.Parse(utils.FormatDate, applyStartDate)
  118. if er != nil {
  119. err = er
  120. msg = "日期格式有误"
  121. return
  122. }
  123. condition += " AND u.apply_time>=? "
  124. applyStartDateStr := applyStartTime.Format(utils.FormatDateTime)
  125. pars = append(pars, applyStartDateStr)
  126. }
  127. if applyEndDate != "" {
  128. applyEndTime, er := time.Parse(utils.FormatDate, applyEndDate)
  129. if er != nil {
  130. err = er
  131. msg = "日期格式有误"
  132. return
  133. }
  134. // 结束时间包含今天
  135. applyEndTime = applyEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
  136. applyEndDateStr := applyEndTime.Format(utils.FormatDateTime)
  137. condition += " AND u.apply_time<=? "
  138. pars = append(pars, applyEndDateStr)
  139. }
  140. startSize := utils.StartIndex(currentIndex, pageSize)
  141. total, err = models.GetPotentialUserCountByConditonV2(condition, pars)
  142. if err != nil {
  143. errMsg = "获取用户列表统计失败"
  144. return
  145. }
  146. userList, err = models.GetPotentialUserIdsByConditonV2(condition, pars, sortCondition, startSize, pageSize)
  147. if err != nil {
  148. errMsg = "获取用户列表失败"
  149. return
  150. }
  151. return
  152. }