Files
jx-callback/business/model/dao/dao_user2.go
2019-08-14 11:32:20 +08:00

67 lines
1.9 KiB
Go

package dao
import (
"fmt"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/model"
)
func GetUserByID(db *DaoDB, fieldName, fieldValue string) (user *model.User, err error) {
sql := fmt.Sprintf(`
SELECT *
FROM user t1
WHERE t1.deleted_at = ? AND t1.status = ? AND t1.%s = ?
`, fieldName)
sqlParams := []interface{}{
utils.DefaultTimeValue,
model.UserStatusNormal,
fieldValue,
}
// globals.SugarLogger.Debugf("GetUserByID sql:%s, sqlParams:%s", sql, utils.Format4Output(sqlParams, false))
err = GetRow(db, &user, sql, sqlParams...)
return user, err
}
func GetUsers(db *DaoDB, userType int, keyword string, userIDs []string, userID2, mobile string, offset, pageSize int) (userList []*model.User, totalCount int, err error) {
offset = FormalizePageOffset(offset)
pageSize = FormalizePageSize(pageSize)
if userType == 0 {
userType = 255
}
sql := `
SELECT SQL_CALC_FOUND_ROWS
t1.*
FROM user t1
WHERE t1.status = 1 AND t1.deleted_at = ? AND t1.type & ? <> 0`
sqlParams := []interface{}{
utils.DefaultTimeValue,
userType,
}
if len(userIDs) > 0 {
sql += " AND t1.user_id IN (" + GenQuestionMarks(len(userIDs)) + ")"
sqlParams = append(sqlParams, userIDs)
}
if userID2 != "" {
sql += " AND t1.user_id2 = ?"
sqlParams = append(sqlParams, userID2)
}
if mobile != "" {
sql += " AND t1.mobile = ?"
sqlParams = append(sqlParams, mobile)
}
if keyword != "" {
keywordLike := "%" + keyword + "%"
sql += " AND (t1.user_id2 LIKE ? OR t1.mobile LIKE ? OR t1.email LIKE ? OR t1.name LIKE ?)"
sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike)
}
sql += " LIMIT ? OFFSET ?"
sqlParams = append(sqlParams, pageSize, offset)
Begin(db)
defer Rollback(db)
if err = GetRows(db, &userList, sql, sqlParams...); err == nil {
totalCount = GetLastTotalRowCount(db)
}
return userList, totalCount, err
}