|
|
@@ -34,7 +34,7 @@ func UserisExistByMobile(Db *xorm.Engine, n string) (bool, error) { |
|
|
|
// UserInByUIDByLevel is In查询 以及是否是有效用户 |
|
|
|
func UserInByUIDByLevel(Db *xorm.Engine, ids []int, levelID interface{}) (*[]model.User, error) { |
|
|
|
var m []model.User |
|
|
|
if err := Db.In("uid", ids).Where("level = ?", levelID). |
|
|
|
if err := Db.In("id", ids).Where("level = ?", levelID). |
|
|
|
Find(&m); err != nil { |
|
|
|
return nil, logx.Warn(err) |
|
|
|
} |
|
|
@@ -44,7 +44,7 @@ func UserInByUIDByLevel(Db *xorm.Engine, ids []int, levelID interface{}) (*[]mod |
|
|
|
// UserFindByMobile search user by mobile |
|
|
|
func UserFindByMobile(Db *xorm.Engine, mobile string) (*model.User, error) { |
|
|
|
var m model.User |
|
|
|
if has, err := Db.Where("phone LIKE ? AND delete_at = 0", "%"+mobile). |
|
|
|
if has, err := Db.Where("phone LIKE ? ", "%"+mobile). |
|
|
|
Get(&m); err != nil || has == false { |
|
|
|
return nil, logx.Warn(err) |
|
|
|
} |
|
|
@@ -54,7 +54,7 @@ func UserFindByMobile(Db *xorm.Engine, mobile string) (*model.User, error) { |
|
|
|
// UserFindExistByMobile search user by mobile |
|
|
|
func UserFindExistByMobile(Db *xorm.Engine, mobile string) (*model.User, bool, error) { |
|
|
|
var m model.User |
|
|
|
has, err := Db.Where("(phone = ? OR uid = ?) AND delete_at = 0", mobile, mobile).Get(&m) |
|
|
|
has, err := Db.Where("(phone = ? OR id = ?) ", mobile, mobile).Get(&m) |
|
|
|
if err != nil { |
|
|
|
logx.Infof("UserFindExistByMobile err") |
|
|
|
return nil, false, logx.Warn(err) |
|
|
@@ -65,7 +65,7 @@ func UserFindExistByMobile(Db *xorm.Engine, mobile string) (*model.User, bool, e |
|
|
|
// UserFindByMobile search user by mobile |
|
|
|
func UserFindByMobileAll(Db *xorm.Engine, mobile string) (*model.User, error) { |
|
|
|
var m model.User |
|
|
|
if has, err := Db.Where("(phone = ? OR uid = ?)", mobile, mobile). |
|
|
|
if has, err := Db.Where("(phone = ? OR id = ?)", mobile, mobile). |
|
|
|
Get(&m); err != nil || has == false { |
|
|
|
return nil, logx.Warn(err) |
|
|
|
} |
|
|
@@ -110,13 +110,13 @@ func UsersFindByNickNameLike(Db *xorm.Engine, nickname string) (*[]model.User, e |
|
|
|
func UsersInByIds(Db *xorm.Engine, ids []int, limit, start int) (*[]model.User, error) { |
|
|
|
var m []model.User |
|
|
|
if limit == 0 && start == 0 { |
|
|
|
if err := Db.In("uid", ids). |
|
|
|
if err := Db.In("id", ids). |
|
|
|
Find(&m); err != nil { |
|
|
|
return nil, logx.Warn(err) |
|
|
|
} |
|
|
|
return &m, nil |
|
|
|
} |
|
|
|
if err := Db.In("uid", ids).Limit(limit, start). |
|
|
|
if err := Db.In("id", ids).Limit(limit, start). |
|
|
|
Find(&m); err != nil { |
|
|
|
return nil, logx.Warn(err) |
|
|
|
} |
|
|
@@ -127,13 +127,13 @@ func UsersInByIds(Db *xorm.Engine, ids []int, limit, start int) (*[]model.User, |
|
|
|
func UsersInByIdsWhereLv(Db *xorm.Engine, ids []int, lv interface{}, limit, start int) (*[]model.User, error) { |
|
|
|
var m []model.User |
|
|
|
if limit == 0 && start == 0 { |
|
|
|
if err := Db.Where("level = ?", lv).In("uid", ids). |
|
|
|
if err := Db.Where("level = ?", lv).In("id", ids). |
|
|
|
Find(&m); err != nil { |
|
|
|
return nil, logx.Warn(err) |
|
|
|
} |
|
|
|
return &m, nil |
|
|
|
} |
|
|
|
if err := Db.Where("level = ?", lv).In("uid", ids).Limit(limit, start). |
|
|
|
if err := Db.Where("level = ?", lv).In("id", ids).Limit(limit, start). |
|
|
|
Find(&m); err != nil { |
|
|
|
return nil, logx.Warn(err) |
|
|
|
} |
|
|
@@ -144,13 +144,13 @@ func UsersInByIdsWhereLv(Db *xorm.Engine, ids []int, lv interface{}, limit, star |
|
|
|
func UsersInByIdsByAscWhereLv(Db *xorm.Engine, ids []int, lv interface{}, limit, start int, c string) (*[]model.User, error) { |
|
|
|
var m []model.User |
|
|
|
if limit == 0 && start == 0 { |
|
|
|
if err := Db.Where("level = ?", lv).In("uid", ids).Asc(c). |
|
|
|
if err := Db.Where("level = ?", lv).In("id", ids).Asc(c). |
|
|
|
Find(&m); err != nil { |
|
|
|
return nil, logx.Warn(err) |
|
|
|
} |
|
|
|
return &m, nil |
|
|
|
} |
|
|
|
if err := Db.Where("level = ?", lv).In("uid", ids).Asc(c).Limit(limit, start). |
|
|
|
if err := Db.Where("level = ?", lv).In("id", ids).Asc(c).Limit(limit, start). |
|
|
|
Find(&m); err != nil { |
|
|
|
return nil, logx.Warn(err) |
|
|
|
} |
|
|
@@ -161,13 +161,13 @@ func UsersInByIdsByAscWhereLv(Db *xorm.Engine, ids []int, lv interface{}, limit, |
|
|
|
func UsersInByIdsByDescWhereLv(Db *xorm.Engine, ids []int, lv interface{}, limit, start int, c string) (*[]model.User, error) { |
|
|
|
var m []model.User |
|
|
|
if limit == 0 && start == 0 { |
|
|
|
if err := Db.Where("level = ?", lv).In("uid", ids).Desc(c). |
|
|
|
if err := Db.Where("level = ?", lv).In("id", ids).Desc(c). |
|
|
|
Find(&m); err != nil { |
|
|
|
return nil, logx.Warn(err) |
|
|
|
} |
|
|
|
return &m, nil |
|
|
|
} |
|
|
|
if err := Db.Where("level = ?", lv).In("uid", ids).Desc(c).Limit(limit, start). |
|
|
|
if err := Db.Where("level = ?", lv).In("id", ids).Desc(c).Limit(limit, start). |
|
|
|
Find(&m); err != nil { |
|
|
|
return nil, logx.Warn(err) |
|
|
|
} |
|
|
@@ -187,7 +187,7 @@ func UserFindByArkidUserName(Db *xorm.Engine, name string) (*model.User, error) |
|
|
|
// UserFindByID is find user byid |
|
|
|
func UserFindByID(Db *xorm.Engine, id interface{}) (*model.User, error) { |
|
|
|
var m model.User |
|
|
|
if _, err := Db.Where("uid = ?", id). |
|
|
|
if _, err := Db.Where("id = ?", id). |
|
|
|
Get(&m); err != nil { |
|
|
|
return nil, logx.Warn(err) |
|
|
|
} |
|
|
@@ -196,7 +196,7 @@ func UserFindByID(Db *xorm.Engine, id interface{}) (*model.User, error) { |
|
|
|
|
|
|
|
func UserFindByIDs(Db *xorm.Engine, uids []int) (*[]model.User, error) { |
|
|
|
var m []model.User |
|
|
|
if err := Db.In("uid", uids).Find(&m); err != nil { |
|
|
|
if err := Db.In("id", uids).Find(&m); err != nil { |
|
|
|
return nil, logx.Warn(err) |
|
|
|
} |
|
|
|
return &m, nil |
|
|
@@ -206,13 +206,13 @@ func UserFindByIDs(Db *xorm.Engine, uids []int) (*[]model.User, error) { |
|
|
|
func UsersInByIdsByDesc(Db *xorm.Engine, ids []int, limit, start int, c string) (*[]model.User, error) { |
|
|
|
var m []model.User |
|
|
|
if limit == 0 && start == 0 { |
|
|
|
if err := Db.In("uid", ids).Desc(c). |
|
|
|
if err := Db.In("id", ids).Desc(c). |
|
|
|
Find(&m); err != nil { |
|
|
|
return nil, logx.Warn(err) |
|
|
|
} |
|
|
|
return &m, nil |
|
|
|
} |
|
|
|
if err := Db.In("uid", ids).Desc(c).Limit(limit, start). |
|
|
|
if err := Db.In("id", ids).Desc(c).Limit(limit, start). |
|
|
|
Find(&m); err != nil { |
|
|
|
return nil, logx.Warn(err) |
|
|
|
} |
|
|
@@ -223,13 +223,13 @@ func UsersInByIdsByDesc(Db *xorm.Engine, ids []int, limit, start int, c string) |
|
|
|
func UsersInByIdsByAsc(Db *xorm.Engine, ids []int, limit, start int, c string) (*[]model.User, error) { |
|
|
|
var m []model.User |
|
|
|
if limit == 0 && start == 0 { |
|
|
|
if err := Db.In("uid", ids).Asc(c). |
|
|
|
if err := Db.In("id", ids).Asc(c). |
|
|
|
Find(&m); err != nil { |
|
|
|
return nil, logx.Warn(err) |
|
|
|
} |
|
|
|
return &m, nil |
|
|
|
} |
|
|
|
if err := Db.In("uid", ids).Asc(c).Limit(limit, start). |
|
|
|
if err := Db.In("id", ids).Asc(c).Limit(limit, start). |
|
|
|
Find(&m); err != nil { |
|
|
|
return nil, logx.Warn(err) |
|
|
|
} |
|
|
@@ -248,7 +248,7 @@ func UserInsert(Db *xorm.Engine, user *model.User) (int64, error) { |
|
|
|
// UserIsExistByMobile is mobile exist |
|
|
|
func UserIsExistByMobile(Db *xorm.Engine, mobile string) (bool, error) { |
|
|
|
//fmt.Println(mobile) |
|
|
|
has, err := Db.Where("phone = ? OR uid = ?", mobile, mobile).Exist(&model.User{}) |
|
|
|
has, err := Db.Where("phone = ? OR id = ?", mobile, mobile).Exist(&model.User{}) |
|
|
|
fmt.Println(has, mobile) |
|
|
|
if err != nil { |
|
|
|
return false, err |
|
|
@@ -258,7 +258,7 @@ func UserIsExistByMobile(Db *xorm.Engine, mobile string) (bool, error) { |
|
|
|
|
|
|
|
// UserIsExistByID is mobile exist by id |
|
|
|
func UserIsExistByID(Db *xorm.Engine, id string) (bool, error) { |
|
|
|
has, err := Db.Where("uid = ?", id).Exist(&model.User{}) |
|
|
|
has, err := Db.Where("id = ?", id).Exist(&model.User{}) |
|
|
|
if err != nil { |
|
|
|
return false, err |
|
|
|
} |
|
|
@@ -266,15 +266,15 @@ func UserIsExistByID(Db *xorm.Engine, id string) (bool, error) { |
|
|
|
} |
|
|
|
|
|
|
|
// UserUpdate is update user |
|
|
|
func UserUpdate(Db *xorm.Engine, uid interface{}, user *model.User, forceColums ...string) (int64, error) { |
|
|
|
func UserUpdate(Db *xorm.Engine, id interface{}, user *model.User, forceColums ...string) (int64, error) { |
|
|
|
var ( |
|
|
|
affected int64 |
|
|
|
err error |
|
|
|
) |
|
|
|
if forceColums != nil { |
|
|
|
affected, err = Db.Where("uid=?", uid).Cols(forceColums...).Update(user) |
|
|
|
affected, err = Db.Where("id=?", id).Cols(forceColums...).Update(user) |
|
|
|
} else { |
|
|
|
affected, err = Db.Where("uid=?", uid).Update(user) |
|
|
|
affected, err = Db.Where("id=?", id).Update(user) |
|
|
|
} |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
@@ -287,12 +287,12 @@ func UpdateUserFinValid() { |
|
|
|
} |
|
|
|
|
|
|
|
// UserDelete is delete user |
|
|
|
func UserDelete(Db *xorm.Engine, uid interface{}) (int64, error) { |
|
|
|
return Db.Where("uid = ?", uid).Delete(model.User{}) |
|
|
|
func UserDelete(Db *xorm.Engine, id interface{}) (int64, error) { |
|
|
|
return Db.Where("id = ?", id).Delete(model.User{}) |
|
|
|
} |
|
|
|
|
|
|
|
func UserDeleteWithSess(sess *xorm.Session, uid interface{}) (int64, error) { |
|
|
|
return sess.Where("uid = ?", uid).Delete(model.User{}) |
|
|
|
func UserDeleteWithSess(sess *xorm.Session, id interface{}) (int64, error) { |
|
|
|
return sess.Where("id = ?", id).Delete(model.User{}) |
|
|
|
} |
|
|
|
|
|
|
|
func UserFindByLevel(eg *xorm.Engine, level int) []model.User { |
|
|
|