123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- package services
- import (
- "eta/eta_mini_crm/models"
- "eta/eta_mini_crm/utils"
- "time"
- )
- func GetUserPermissionById(userId int) (items []*models.ChartPermissionView, err error) {
- permissionIds, err := models.GetChartPermissionIdByUserId(userId)
- if err != nil {
- return
- }
- if len(permissionIds) == 0 {
- return
- }
- items, err = models.GetChartPermissionListByIds(permissionIds)
- if err != nil {
- return
- }
- return
- }
- 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) {
- var sortCondition string
- var condition string
- var pars []interface{}
- if keyWord != "" {
- condition += ` AND ( u.phone LIKE ? OR u.email LIKE ?) `
- pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
- }
- if sellerDepartmentId != 0 {
- condition += ` AND u.seller_department_id=? `
- pars = append(pars, sellerDepartmentId)
- }
- if applyStatus != "" {
- condition += ` AND u.apply_status=? `
- pars = append(pars, applyStatus)
- }
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- if sortParam != "" && sortType != "" {
- sortCondition = " ORDER BY "
- var param, sort string
- switch sortParam {
- case "RegisterTime":
- param = "u.register_time"
- case "LastUpdateTime":
- param = "last_update_time"
- case "ReadCnt":
- param = "read_cnt"
- case "ApplyTime":
- param = "u.apply_time"
- }
- switch sortType {
- case "asc":
- sort = " ASC "
- case "desc":
- sort = " DESC "
- }
- if param != "" && sort != "" {
- sortCondition += param + " " + sort
- } else {
- sortCondition = ""
- }
- }
- if registerStartDate != "" {
- registerStartTime, er := time.Parse(utils.FormatDate, registerStartDate)
- if er != nil {
- err = er
- msg = "日期格式有误"
- return
- }
- condition += " AND u.register_time>=? "
- registerStartDateStr := registerStartTime.Format(utils.FormatDateTime)
- pars = append(pars, registerStartDateStr)
- }
- if registerEndDate != "" {
- registerEndTime, er := time.Parse(utils.FormatDate, registerEndDate)
- if er != nil {
- err = er
- msg = "日期格式有误"
- return
- }
- condition += " AND u.register_time<=? "
- // 结束时间包含今天
- registerEndTime = registerEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
- registerEndDateStr := registerEndTime.Format(utils.FormatDateTime)
- pars = append(pars, registerEndDateStr)
- }
- if lastUpdateStartDate != "" {
- lastUpdateStartTime, er := time.Parse(utils.FormatDate, lastUpdateStartDate)
- if er != nil {
- err = er
- msg = "日期格式有误"
- return
- }
- condition += " AND ur.create_time>=? "
- lastUpdateStartDateStr := lastUpdateStartTime.Format(utils.FormatDateTime)
- pars = append(pars, lastUpdateStartDateStr)
- }
- if lastUpdateEndDate != "" {
- lastUpdateEndTime, er := time.Parse(utils.FormatDate, lastUpdateEndDate)
- if er != nil {
- err = er
- msg = "日期格式有误"
- return
- }
- // 结束时间包含今天
- lastUpdateEndTime = lastUpdateEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
- lastUpdateEndDateStr := lastUpdateEndTime.Format(utils.FormatDateTime)
- condition += " AND ur.create_time<=? "
- pars = append(pars, lastUpdateEndDateStr)
- }
- if applyStartDate != "" {
- applyStartTime, er := time.Parse(utils.FormatDate, applyStartDate)
- if er != nil {
- err = er
- msg = "日期格式有误"
- return
- }
- condition += " AND u.apply_time>=? "
- applyStartDateStr := applyStartTime.Format(utils.FormatDateTime)
- pars = append(pars, applyStartDateStr)
- }
- if applyEndDate != "" {
- applyEndTime, er := time.Parse(utils.FormatDate, applyEndDate)
- if er != nil {
- err = er
- msg = "日期格式有误"
- return
- }
- // 结束时间包含今天
- applyEndTime = applyEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
- applyEndDateStr := applyEndTime.Format(utils.FormatDateTime)
- condition += " AND u.apply_time<=? "
- pars = append(pars, applyEndDateStr)
- }
- startSize := utils.StartIndex(currentIndex, pageSize)
- total, err = models.GetPotentialUserCountByConditonV2(condition, pars)
- if err != nil {
- errMsg = "获取用户列表统计失败"
- return
- }
- userList, err = models.GetPotentialUserIdsByConditonV2(condition, pars, sortCondition, startSize, pageSize)
- if err != nil {
- errMsg = "获取用户列表失败"
- return
- }
- return
- }
|