diff --git a/business/jxstore/cms/user2.go b/business/jxstore/cms/user2.go index 33aaa40f1..ea64440b3 100644 --- a/business/jxstore/cms/user2.go +++ b/business/jxstore/cms/user2.go @@ -276,15 +276,8 @@ func OnDingDingMsg(msg map[string]interface{}) (callbackResponse *dingdingapi.Ca return api.DingDingAPI.Err2CallbackResponse(nil) } -func GetUsers(ctx *jxcontext.Context, keyword string, userIDs []string, mobile string, fromTime, toTime string, timeType int, cityCodes, consumeTypes []int, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) { - // userList, totalCount, err := dao.GetUsers(dao.GetDB(), keyword, "", userIDs, jxutils.BatchString2Slice(mobile), offset, pageSize) - // if err == nil { - // pagedInfo = &model.PagedInfo{ - // TotalCount: totalCount, - // Data: userList, - // } - // } - return pagedInfo, err +func GetUsers(ctx *jxcontext.Context, keyword string, userID string, pop int, mobile string, fromTime, toTime string, timeType int, cityCodes, consumeTypes []int, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) { + return dao.GetUsers2(dao.GetDB(), keyword, userID, pop, mobile, utils.Str2Time(fromTime), utils.Str2Time(toTime), timeType, cityCodes, consumeTypes, offset, pageSize) } func GetUser(ctx *jxcontext.Context, userID string) (user *model.GetUserResult, err error) { diff --git a/business/model/dao/dao_user.go b/business/model/dao/dao_user.go index e1e27a9b9..e05cf5a21 100644 --- a/business/model/dao/dao_user.go +++ b/business/model/dao/dao_user.go @@ -114,6 +114,112 @@ func GetUsers(db *DaoDB, userType int, keyword, popUser string, userIDs, userID2 return userList, totalCount, err } +func GetUsers2(db *DaoDB, keyword string, userID string, pop int, mobile string, fromTime, toTime time.Time, timeType int, cityCodes, consumeTypes []int, offset, pageSize int) (pageInfo *model.PagedInfo, err error) { + var ( + userList []*model.User + ) + offset = jxutils.FormalizePageOffset(offset) + pageSize = jxutils.FormalizePageSize(pageSize) + sqlParams := []interface{}{} + sql := ` + SELECT SQL_CALC_FOUND_ROWS + a.* + FROM user a` + for _, v := range consumeTypes { + switch v { + case model.ConsumeTypePublishJob: + sql += " JOIN job b ON b.user_id = a.user_id" + if fromTime != utils.ZeroTimeValue { + if timeType == 2 { + sql += " AND b.created_at > ?" + sqlParams = append(sqlParams, fromTime) + } + } + if toTime != utils.ZeroTimeValue { + if timeType == 2 { + sql += " AND b.created_at < ?" + sqlParams = append(sqlParams, toTime) + } + } + case model.ConsumeTypeMember: + sql += " JOIN user_member c ON c.user_id = a.user_id" + if fromTime != utils.ZeroTimeValue { + if timeType == 2 { + sql += " AND c.created_at > ?" + sqlParams = append(sqlParams, fromTime) + } + } + if toTime != utils.ZeroTimeValue { + if timeType == 2 { + sql += " AND c.created_at < ?" + sqlParams = append(sqlParams, toTime) + } + } + case model.ConsumeTypeDelivery: + sql += " JOIN delivery_order d ON d.user_id = a.user_id" + if fromTime != utils.ZeroTimeValue { + if timeType == 2 { + sql += " AND d.created_at > ?" + sqlParams = append(sqlParams, fromTime) + } + } + if toTime != utils.ZeroTimeValue { + if timeType == 2 { + sql += " AND d.created_at < ?" + sqlParams = append(sqlParams, toTime) + } + } + } + } + sql += ` + WHERE a.status = 1 AND a.deleted_at = ?` + sqlParams = append(sqlParams, utils.DefaultTimeValue) + if userID != "" { + sql += " AND a.user_id = ?" + sqlParams = append(sqlParams, userID) + if pop == 1 { + sql += " AND a.pop_user = ?" + sqlParams = append(sqlParams, userID) + } + } + if len(cityCodes) > 0 { + sql += " AND a.city_code IN (" + GenQuestionMarks(len(cityCodes)) + ")" + sqlParams = append(sqlParams, cityCodes) + } + if mobile != "" { + sql += " AND a.mobile = ?" + sqlParams = append(sqlParams, mobile) + } + if keyword != "" { + keywordLike := "%" + keyword + "%" + sql += " AND (a.user_id LIKE ? OR a.mobile LIKE ? OR a.email LIKE ? OR a.name LIKE ?)" + sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike) + } + if fromTime != utils.ZeroTimeValue { + if timeType == 1 { + sql += " AND a.created_at > ?" + sqlParams = append(sqlParams, fromTime) + } + } + if toTime != utils.ZeroTimeValue { + if timeType == 1 { + sql += " AND a.created_at < ?" + sqlParams = append(sqlParams, toTime) + } + } + sql += " LIMIT ? OFFSET ?" + sqlParams = append(sqlParams, pageSize, offset) + Begin(db) + defer Commit(db) + if err = GetRows(db, &userList, sql, sqlParams...); err == nil { + pageInfo = &model.PagedInfo{ + TotalCount: GetLastTotalRowCount(db), + Data: userList, + } + } + return pageInfo, err +} + func GetUser(db *DaoDB, userID string) (user *model.GetUserResult, err error) { sqlParams := []interface{}{} sql := ` diff --git a/controllers/user2_controller.go b/controllers/user2_controller.go index c8d4d5acf..66ee7c8b8 100644 --- a/controllers/user2_controller.go +++ b/controllers/user2_controller.go @@ -65,7 +65,8 @@ func (c *User2Controller) GetBindAuthInfo() { // @Description 得到用户列表 // @Param token header string true "认证token" // @Param keyword query string false "关键字,可以部分匹配" -// @Param userIDs query string false "用户id列表" +// @Param userID query string false "用户id" +// @Param pop query int false "1为你邀请的,0为全部" // @Param cityCodes query string false "城市id列表" // @Param mobile query string false "用户手机,必须全匹配" // @Param fromTime query string false "开始时间" @@ -80,11 +81,10 @@ func (c *User2Controller) GetBindAuthInfo() { func (c *User2Controller) GetUsers() { c.callGetUsers(func(params *tUser2GetUsersParams) (retVal interface{}, errCode string, err error) { var ( - userIDs []string cityCodes, consumeTypes []int ) - if err = jxutils.Strings2Objs(params.UserIDs, &userIDs, params.CityCodes, &cityCodes); err == nil { - retVal, err = cms.GetUsers(params.Ctx, params.Keyword, userIDs, params.Mobile, params.FromTime, params.ToTime, params.TimeType, cityCodes, consumeTypes, params.Offset, params.PageSize) + if err = jxutils.Strings2Objs(params.CityCodes, &cityCodes, params.ConsumeTypes, &consumeTypes); err == nil { + retVal, err = cms.GetUsers(params.Ctx, params.Keyword, params.UserID, params.Pop, params.Mobile, params.FromTime, params.ToTime, params.TimeType, cityCodes, consumeTypes, params.Offset, params.PageSize) } return retVal, "", err })