- 重构了dao.GetAuthBind和dao.GetUserBindAuthInfo
- AuthBind的唯一索引调整为"AuthID", "Type", "BindType", "DeletedAt"
This commit is contained in:
@@ -16,12 +16,12 @@ const (
|
||||
type AuthBind struct {
|
||||
ModelIDCULD
|
||||
|
||||
UserID string `orm:"size(48);column(user_id)" json:"userID"`
|
||||
AuthID string `orm:"size(48);column(auth_id)" json:"authID"`
|
||||
BindType int8 `json:"bindType"`
|
||||
Type string `orm:"size(16)" json:"type"`
|
||||
Status int8 `json:"status"`
|
||||
|
||||
AuthID string `orm:"size(48);column(auth_id)" json:"authID"`
|
||||
UserID string `orm:"size(48);column(user_id)" json:"userID"`
|
||||
Status int8 `json:"status"`
|
||||
AuthID2 string `orm:"size(48);column(auth_id2);index" json:"authID2"`
|
||||
AuthSecret string `orm:"size(48)" json:"-"`
|
||||
AuthSecret2 string `orm:"size(48)" json:"-"`
|
||||
@@ -31,7 +31,7 @@ type AuthBind struct {
|
||||
|
||||
func (*AuthBind) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"UserID", "Type", "DeletedAt"},
|
||||
[]string{"AuthID", "Type", "DeletedAt"},
|
||||
// []string{"UserID", "Type", "DeletedAt"}, // 这个其实UserID是属性,而不是key
|
||||
[]string{"AuthID", "Type", "BindType", "DeletedAt"},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,41 +7,27 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func GetAuthBind(db *DaoDB, userID string, bindType int, authType, authID string) (authBind *model.AuthBind, err error) {
|
||||
if userID == "" && authID == "" {
|
||||
return nil, errors.New("userID, authID, authID2不能全为空")
|
||||
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 = ?
|
||||
`
|
||||
WHERE t1.deleted_at = ? AND t1.status = ? AND t1.bind_type = ? AND t1.type = ? AND t1.auth_id = ?`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
model.AuthBindStatusNormal,
|
||||
}
|
||||
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 authType != "" {
|
||||
sql += " AND t1.type = ?"
|
||||
sqlParams = append(sqlParams, authType)
|
||||
}
|
||||
if authID != "" {
|
||||
sql += " AND t1.auth_id = ?"
|
||||
sqlParams = append(sqlParams, authID)
|
||||
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, authID2 string, typeList []string) (authList []*model.AuthBind, err error) {
|
||||
func GetUserBindAuthInfo(db *DaoDB, userID string, bindType int, typeList []string, authID, authID2 string) (authList []*model.AuthBind, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM auth_bind t1
|
||||
@@ -58,14 +44,18 @@ func GetUserBindAuthInfo(db *DaoDB, userID string, bindType int, authID2 string,
|
||||
sql += " AND t1.bind_type = ?"
|
||||
sqlParams = append(sqlParams, bindType)
|
||||
}
|
||||
if authID2 != "" {
|
||||
sql += " AND t1.auth_id2 = ?"
|
||||
sqlParams = append(sqlParams, authID2)
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
err = GetRows(db, &authList, sql, sqlParams...)
|
||||
return authList, err
|
||||
|
||||
Reference in New Issue
Block a user