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 }