Files
jx-callback/business/dao/dao_auth2.go
邹宗楠 c845eabe69 1
2022-08-11 14:23:06 +08:00

67 lines
1.8 KiB
Go

package dao
import (
"errors"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/model"
)
func GetAuthBind(db *DaoDB, bindType int, authType, authID string) (authBind *model.AuthBind, err error) {
if bindType == model.AuthBindTypeAll || authType == "" || authID == "" {
return nil, errors.New("bindType不是能all, authType和authID都要有值")
}
sql := `
SELECT *
FROM auth_bind t1
WHERE t1.deleted_at = ? AND t1.status = ? AND t1.bind_type = ? AND t1.type = ? AND t1.auth_id = ?`
sqlParams := []interface{}{
utils.DefaultTimeValue,
model.AuthBindStatusNormal,
bindType,
authType,
authID,
}
// globals.SugarLogger.Debugf("GetAuthBind sql:%s, sqlParams:%s", sql, utils.Format4Output(sqlParams, false))
err = GetRow(db, &authBind, sql, sqlParams...)
return authBind, err
}
func GetUserBindAuthInfo(db *DaoDB, userID string, bindType int, typeList []string, authID, authID2, typeID string) (authList []*model.AuthBind, err error) {
sql := `
SELECT *
FROM auth_bind t1
WHERE t1.deleted_at = ? AND t1.status = ?`
sqlParams := []interface{}{
utils.DefaultTimeValue,
model.UserStatusNormal,
}
if userID != "" {
sql += " AND t1.user_id = ?"
sqlParams = append(sqlParams, userID)
}
if bindType != model.AuthBindTypeAll {
sql += " AND t1.bind_type = ?"
sqlParams = append(sqlParams, bindType)
}
if len(typeList) > 0 {
sql += " AND t1.type IN (" + GenQuestionMarks(len(typeList)) + ")"
sqlParams = append(sqlParams, typeList)
}
if authID != "" {
sql += " AND t1.auth_id = ?"
sqlParams = append(sqlParams, authID)
}
if authID2 != "" {
sql += " AND t1.auth_id2 = ?"
sqlParams = append(sqlParams, authID2)
}
if typeID != "" {
sql += " AND t1.type_id = ?"
sqlParams = append(sqlParams, typeID)
}
sql += " ORDER BY t1.type"
err = GetRows(db, &authList, sql, sqlParams...)
return authList, err
}