123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654 |
- package dao
- import (
- "context"
- "database/sql"
- "fmt"
- "go-common/app/job/main/passport-user/model"
- xsql "go-common/library/database/sql"
- "go-common/library/log"
- )
- const (
- _addCountryCodeSQL = "INSERT INTO country_code (id,code,cname,rank,type,ename) VALUES(?,?,?,?,?,?)"
- _getAesKeySQL = "SELECT `key` FROM user_secret WHERE key_type = 2"
- _getSaltSQL = "SELECT `key` FROM user_secret WHERE key_type = 3"
- _getCountryCodeMapSQL = "SELECT id,code FROM country_code"
- _getUserTelSQL = "SELECT mid FROM user_tel WHERE mid > ? limit ?"
- _getUserEmailByMidSQL = "SELECT mid,email,verified,email_bind_time,ctime,mtime FROM user_email WHERE mid = ?"
- _getUserTelByMidSQL = "SELECT mid,tel,cid,tel_bind_time,ctime,mtime FROM user_tel WHERE mid = ?"
- _addUserBaseSQL = "INSERT INTO user_base (mid,userid,pwd,salt,status,deleted,mtime) VALUES(?,?,?,?,?,?,?)"
- _addUserEmailSQL = "INSERT INTO user_email (mid,email,verified,email_bind_time,mtime) VALUES(?,?,?,?,?)"
- _addUserTelSQL = "INSERT INTO user_tel (mid,tel,cid,tel_bind_time,mtime) VALUES(?,?,?,?,?)"
- _addUserSafeQuestionSQL = "INSERT INTO user_safe_question%02d (mid,safe_question,safe_answer,safe_bind_time) VALUES(?,?,?,?)"
- _addUserThirdBindSQL = "INSERT INTO user_third_bind (mid,openid,platform,token,expires) VALUES(?,?,?,?,?)"
- _updateUserBaseSQL = "UPDATE user_base SET userid=?,pwd=?,salt=?,status=? WHERE mid =?"
- _updateUserEmailSQL = "UPDATE user_email SET email=? WHERE mid =?"
- _updateUserEmailAndBindTimeSQL = "UPDATE user_email SET email=?,email_bind_time=? WHERE mid =?"
- _updateUserTelSQL = "UPDATE user_tel SET tel=?,cid=? WHERE mid =?"
- _updateUserTelAndBindTimeSQL = "UPDATE user_tel SET tel=?,cid=?,tel_bind_time=? WHERE mid =?"
- _updateUserSafeQuestionSQL = "UPDATE user_safe_question%02d SET safe_question=?,safe_answer=? WHERE mid =?"
- _updateUserThirdBindSQL = "UPDATE user_third_bind SET openid=?,token=?,expires=? WHERE mid =? and platform=?"
- _updateUserEmailVerifiedSQL = "UPDATE user_email SET verified=? WHERE mid =?"
- _updateUserEmailBindTimeSQL = "UPDATE user_email SET verified=?,email_bind_time=? WHERE mid =?"
- _updateUserTelBindTimeSQL = "UPDATE user_tel SET tel_bind_time=? WHERE mid =?"
- _insertUpdateUserRegOriginSQL = "INSERT INTO user_reg_origin%02d (mid,join_ip,join_ip_v6,port,join_time) VALUES (?,?,?,?,?) ON DUPLICATE KEY UPDATE join_ip=?,join_ip_v6=?,port=?,join_time=?"
- _insertUpdateUserRegOriginTypeSQL = "INSERT INTO user_reg_origin%02d (mid,origin,reg_type,appid,ctime,mtime) VALUES (?,?,?,?,?,?) ON DUPLICATE KEY UPDATE origin=?,reg_type=?,appid=?,ctime=?,mtime=?"
- _delUserBase = "UPDATE user_base SET deleted=1 WHERE mid =?"
- _delUserTel = "UPDATE user_tel SET tel=null,cid=null WHERE mid =?"
- _delUserEmail = "UPDATE user_email SET email=null WHERE mid =?"
- _getMidByTelSQL = "SELECT mid FROM user_tel WHERE tel = ? and cid = ?"
- _getMidByEmailSQL = "SELECT mid FROM user_email WHERE email = ?"
- _getUserBaseByMidSQL = "SELECT mid,userid,pwd,salt,status,ctime,mtime FROM user_base WHERE mid = ?"
- _getUserSafeQuestionByMidSQL = "SELECT mid,safe_question,safe_answer,safe_bind_time,ctime,mtime FROM user_safe_question%02d where mid = ?"
- _getUserThirdBindByMidSQL = "SELECT id,mid,openid,platform,token,expires,ctime,mtime FROM user_third_bind where mid = ?"
- _getUserThirdBindByMidAndPlatformSQL = "SELECT id,mid,openid,platform,token,expires,ctime,mtime FROM user_third_bind where mid = ? and platform = ? limit 1"
- _getUserRegOriginByMidSQL = "SELECT mid,join_ip,join_ip_v6,port,join_time,origin,reg_type,appid from user_reg_origin%02d where mid = ?"
- _insertUpdateUserBaseSQL = "INSERT INTO user_base (mid,userid,pwd,salt,status,deleted,mtime) VALUES (?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE userid=?,pwd=?,salt=?,status=?"
- _insertIgnoreUserSafeQuestionSQL = "INSERT IGNORE INTO user_safe_question%02d (mid,safe_question,safe_answer,safe_bind_time) VALUES(?,?,?,?)"
- _insertIgnoreUserRegOriginSQL = "INSERT IGNORE INTO user_reg_origin%02d (mid,join_ip,join_ip_v6,port,join_time) VALUES (?,?,?,?,?)"
- _delUserThirdBindSQL = "UPDATE user_third_bind SET openid='',token='',expires=0 WHERE mid =?"
- )
- // AddCountryCode add country code.
- func (d *Dao) AddCountryCode(c context.Context, a *model.CountryCode) (affected int64, err error) {
- var res sql.Result
- if res, err = d.userDB.Exec(c, _addCountryCodeSQL, a.ID, a.Code, a.Cname, a.Rank, a.Type, a.Ename); err != nil {
- log.Error("fail to add country code, countryCode(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // AesKey get aes key.
- func (d *Dao) AesKey(c context.Context) (res string, err error) {
- if err = d.encryptDB.QueryRow(c, _getAesKeySQL).Scan(&res); err != nil {
- log.Error("fail to get AesKey, dao.encryptDB.QueryRow(%s) error(%v)", _getAesKeySQL, err)
- return
- }
- return
- }
- // Salt get salt.
- func (d *Dao) Salt(c context.Context) (res string, err error) {
- if err = d.encryptDB.QueryRow(c, _getSaltSQL).Scan(&res); err != nil {
- log.Error("fail to get Salt, dao.encryptDB.QueryRow(%s) error(%v)", _getSaltSQL, err)
- return
- }
- return
- }
- // UserTel get user tel.
- func (d *Dao) UserTel(c context.Context, start, count int64) (res []*model.UserTel, err error) {
- var rows *xsql.Rows
- if rows, err = d.userDB.Query(c, _getUserTelSQL, start, count); err != nil {
- log.Error("fail to get UserTel, dao.userDB.Query(%s) error(%v)", _getUserTelSQL, err)
- return
- }
- defer rows.Close()
- for rows.Next() {
- r := new(model.UserTel)
- if err = rows.Scan(&r.Mid); err != nil {
- log.Error("row.Scan() error(%v)", err)
- res = nil
- return
- }
- res = append(res, r)
- }
- return
- }
- // GetUserEmailByMid get user email by mid.
- func (d *Dao) GetUserEmailByMid(c context.Context, mid int64) (res *model.UserEmail, err error) {
- res = &model.UserEmail{}
- if err = d.userDB.QueryRow(c, _getUserEmailByMidSQL, mid).Scan(&res.Mid, &res.Email, &res.Verified, &res.EmailBindTime, &res.CTime, &res.MTime); err != nil {
- if err == xsql.ErrNoRows {
- err = nil
- res = nil
- } else {
- log.Error("fail to get UserEmail by mid(%d), dao.encryptDB.QueryRow(%s) error(%v)", mid, _getUserEmailByMidSQL, err)
- }
- return
- }
- return
- }
- // GetUserTelByMid get user email by mid.
- func (d *Dao) GetUserTelByMid(c context.Context, mid int64) (res *model.UserTel, err error) {
- var cidPtr *string
- res = &model.UserTel{}
- if err = d.userDB.QueryRow(c, _getUserTelByMidSQL, mid).Scan(&res.Mid, &res.Tel, &cidPtr, &res.TelBindTime, &res.CTime, &res.MTime); err != nil {
- if err == xsql.ErrNoRows {
- err = nil
- res = nil
- } else {
- log.Error("fail to get UserTel by mid(%d), dao.encryptDB.QueryRow(%s) error(%v)", mid, _getUserTelByMidSQL, err)
- }
- return
- }
- if cidPtr != nil {
- res.Cid = *cidPtr
- }
- return
- }
- // AddUserBase add user base.
- func (d *Dao) AddUserBase(c context.Context, a *model.UserBase) (affected int64, err error) {
- var res sql.Result
- if res, err = d.userDB.Exec(c, _addUserBaseSQL, a.Mid, a.UserID, a.Pwd, a.Salt, a.Status, a.Deleted, a.MTime); err != nil {
- log.Error("fail to add user base, userBase(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // TxAddUserBase add user base.
- func (d *Dao) TxAddUserBase(tx *xsql.Tx, a *model.UserBase) (affected int64, err error) {
- var res sql.Result
- if res, err = tx.Exec(_addUserBaseSQL, a.Mid, a.UserID, a.Pwd, a.Salt, a.Status, a.Deleted, a.MTime); err != nil {
- log.Error("fail to add user base, userBase(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // AddUserEmail add user email.
- func (d *Dao) AddUserEmail(c context.Context, a *model.UserEmail) (affected int64, err error) {
- var (
- res sql.Result
- emailPtr *[]byte
- )
- if len(a.Email) != 0 {
- emailPtr = &a.Email
- }
- if res, err = d.userDB.Exec(c, _addUserEmailSQL, a.Mid, emailPtr, a.Verified, a.EmailBindTime, a.MTime); err != nil {
- log.Error("fail to add user email, userEmail(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // TxAddUserEmail add user email.
- func (d *Dao) TxAddUserEmail(tx *xsql.Tx, a *model.UserEmail) (affected int64, err error) {
- var (
- res sql.Result
- emailPtr *[]byte
- )
- if len(a.Email) != 0 {
- emailPtr = &a.Email
- }
- if res, err = tx.Exec(_addUserEmailSQL, a.Mid, emailPtr, a.Verified, a.EmailBindTime, a.MTime); err != nil {
- log.Error("fail to add user email, userEmail(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // AddUserTel add user tel.
- func (d *Dao) AddUserTel(c context.Context, a *model.UserTel) (affected int64, err error) {
- var (
- res sql.Result
- telPtr *[]byte
- cidPtr *string
- )
- if len(a.Tel) != 0 {
- telPtr = &a.Tel
- cidPtr = &a.Cid
- }
- if res, err = d.userDB.Exec(c, _addUserTelSQL, a.Mid, telPtr, cidPtr, a.TelBindTime, a.MTime); err != nil {
- log.Error("fail to add user tel, userTel(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // TxAddUserTel add user tel.
- func (d *Dao) TxAddUserTel(tx *xsql.Tx, a *model.UserTel) (affected int64, err error) {
- var (
- res sql.Result
- telPtr *[]byte
- cidPtr *string
- )
- if len(a.Tel) != 0 {
- telPtr = &a.Tel
- cidPtr = &a.Cid
- }
- if res, err = tx.Exec(_addUserTelSQL, a.Mid, telPtr, cidPtr, a.TelBindTime, a.MTime); err != nil {
- log.Error("fail to add user tel, userTel(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // AddUserSafeQuestion add user safe question.
- func (d *Dao) AddUserSafeQuestion(c context.Context, a *model.UserSafeQuestion) (affected int64, err error) {
- var res sql.Result
- if res, err = d.userDB.Exec(c, fmt.Sprintf(_addUserSafeQuestionSQL, tableIndex(a.Mid)), a.Mid, a.SafeQuestion, a.SafeAnswer, a.SafeBindTime); err != nil {
- log.Error("fail to add user safe question, userSafeQuestion(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // TxAddUserSafeQuestion add user safe question.
- func (d *Dao) TxAddUserSafeQuestion(tx *xsql.Tx, a *model.UserSafeQuestion) (affected int64, err error) {
- var res sql.Result
- if res, err = tx.Exec(fmt.Sprintf(_addUserSafeQuestionSQL, tableIndex(a.Mid)), a.Mid, a.SafeQuestion, a.SafeAnswer, a.SafeBindTime); err != nil {
- log.Error("fail to add user safe question, userSafeQuestion(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // AddUserThirdBind add user third bind.
- func (d *Dao) AddUserThirdBind(c context.Context, a *model.UserThirdBind) (affected int64, err error) {
- var res sql.Result
- if res, err = d.userDB.Exec(c, _addUserThirdBindSQL, a.Mid, a.OpenID, a.PlatForm, a.Token, a.Expires); err != nil {
- log.Error("fail to add user third bind, userThirdBind(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // TxAddUserThirdBind add user third bind.
- func (d *Dao) TxAddUserThirdBind(tx *xsql.Tx, a *model.UserThirdBind) (affected int64, err error) {
- var res sql.Result
- if res, err = tx.Exec(_addUserThirdBindSQL, a.Mid, a.OpenID, a.PlatForm, a.Token, a.Expires); err != nil {
- log.Error("fail to add user third bind, userThirdBind(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // UpdateUserBase update user base.
- func (d *Dao) UpdateUserBase(c context.Context, a *model.UserBase) (affected int64, err error) {
- var res sql.Result
- if res, err = d.userDB.Exec(c, _updateUserBaseSQL, a.UserID, a.Pwd, a.Salt, a.Status, a.Mid); err != nil {
- log.Error("fail to update user base, userBase(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // UpdateUserEmail update user email.
- func (d *Dao) UpdateUserEmail(c context.Context, a *model.UserEmail) (affected int64, err error) {
- var (
- res sql.Result
- emailPtr *[]byte
- )
- if len(a.Email) != 0 {
- emailPtr = &a.Email
- }
- if res, err = d.userDB.Exec(c, _updateUserEmailSQL, emailPtr, a.Mid); err != nil {
- log.Error("fail to update user email, userEmail(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // UpdateUserEmailAndBindTime update user email and bind time.
- func (d *Dao) UpdateUserEmailAndBindTime(c context.Context, a *model.UserEmail) (affected int64, err error) {
- var (
- res sql.Result
- emailPtr *[]byte
- )
- if len(a.Email) != 0 {
- emailPtr = &a.Email
- }
- if res, err = d.userDB.Exec(c, _updateUserEmailAndBindTimeSQL, emailPtr, a.EmailBindTime, a.Mid); err != nil {
- log.Error("fail to update user email and bind time, userEmail(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // TxUpdateUserEmail update user email.
- func (d *Dao) TxUpdateUserEmail(tx *xsql.Tx, a *model.UserEmail) (affected int64, err error) {
- var (
- res sql.Result
- emailPtr *[]byte
- )
- if len(a.Email) != 0 {
- emailPtr = &a.Email
- }
- if res, err = tx.Exec(_updateUserEmailSQL, emailPtr, a.Mid); err != nil {
- log.Error("fail to update user email, userEmail(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // UpdateUserTel update user tel.
- func (d *Dao) UpdateUserTel(c context.Context, a *model.UserTel) (affected int64, err error) {
- var (
- res sql.Result
- telPtr *[]byte
- cidPtr *string
- )
- if len(a.Tel) != 0 {
- telPtr = &a.Tel
- cidPtr = &a.Cid
- }
- if res, err = d.userDB.Exec(c, _updateUserTelSQL, telPtr, cidPtr, a.Mid); err != nil {
- log.Error("fail to update user tel, userTel(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // UpdateUserTelAndBindTime update user tel and bind time.
- func (d *Dao) UpdateUserTelAndBindTime(c context.Context, a *model.UserTel) (affected int64, err error) {
- var (
- res sql.Result
- telPtr *[]byte
- cidPtr *string
- )
- if len(a.Tel) != 0 {
- telPtr = &a.Tel
- cidPtr = &a.Cid
- }
- if res, err = d.userDB.Exec(c, _updateUserTelAndBindTimeSQL, telPtr, cidPtr, a.TelBindTime, a.Mid); err != nil {
- log.Error("fail to update user tel and bind time, userTel(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // UpdateUserSafeQuesion update user safe question.
- func (d *Dao) UpdateUserSafeQuesion(c context.Context, a *model.UserSafeQuestion) (affected int64, err error) {
- var res sql.Result
- if res, err = d.userDB.Exec(c, fmt.Sprintf(_updateUserSafeQuestionSQL, tableIndex(a.Mid)), a.SafeQuestion, a.SafeAnswer, a.Mid); err != nil {
- log.Error("fail to update user safe question, userSafeQuestion(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // TxUpdateUserSafeQuesion update user safe question.
- func (d *Dao) TxUpdateUserSafeQuesion(tx *xsql.Tx, a *model.UserSafeQuestion) (affected int64, err error) {
- var res sql.Result
- if res, err = tx.Exec(fmt.Sprintf(_updateUserSafeQuestionSQL, tableIndex(a.Mid)), a.SafeQuestion, a.SafeAnswer, a.Mid); err != nil {
- log.Error("fail to update user safe question, userSafeQuestion(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // UpdateUserThirdBind update user third bind.
- func (d *Dao) UpdateUserThirdBind(c context.Context, a *model.UserThirdBind) (affected int64, err error) {
- var res sql.Result
- if res, err = d.userDB.Exec(c, _updateUserThirdBindSQL, a.OpenID, a.Token, a.Expires, a.Mid, a.PlatForm); err != nil {
- log.Error("fail to update user third bind, userThirdBind(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // UpdateUserEmailVerified update user email verified.
- func (d *Dao) UpdateUserEmailVerified(c context.Context, a *model.UserEmail) (affected int64, err error) {
- var res sql.Result
- if res, err = d.userDB.Exec(c, _updateUserEmailVerifiedSQL, a.Verified, a.Mid); err != nil {
- log.Error("fail to update user email verified, userEmail(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // TxUpdateUserEmailVerified update user email verified.
- func (d *Dao) TxUpdateUserEmailVerified(tx *xsql.Tx, a *model.UserEmail) (affected int64, err error) {
- var res sql.Result
- if res, err = tx.Exec(_updateUserEmailVerifiedSQL, a.Verified, a.Mid); err != nil {
- log.Error("fail to update user email verified, userEmail(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // UpdateUserEmailBindTime update user email bind time.
- func (d *Dao) UpdateUserEmailBindTime(c context.Context, a *model.UserEmail) (affected int64, err error) {
- var res sql.Result
- if res, err = d.userDB.Exec(c, _updateUserEmailBindTimeSQL, a.Verified, a.EmailBindTime, a.Mid); err != nil {
- log.Error("fail to update user email bind time, userEmail(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // TxUpdateUserEmailBindTime update user email bind time.
- func (d *Dao) TxUpdateUserEmailBindTime(tx *xsql.Tx, a *model.UserEmail) (affected int64, err error) {
- var res sql.Result
- if res, err = tx.Exec(_updateUserEmailBindTimeSQL, a.Verified, a.EmailBindTime, a.Mid); err != nil {
- log.Error("fail to update user email bind time, userEmail(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // UpdateUserTelBindTime update user tel bind time.
- func (d *Dao) UpdateUserTelBindTime(c context.Context, a *model.UserTel) (affected int64, err error) {
- var res sql.Result
- if res, err = d.userDB.Exec(c, _updateUserTelBindTimeSQL, a.TelBindTime, a.Mid); err != nil {
- log.Error("fail to update user tel bind time, userTel(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // TxDelUserBase update user base deleted = 1.
- func (d *Dao) TxDelUserBase(tx *xsql.Tx, mid int64) (affected int64, err error) {
- var res sql.Result
- if res, err = tx.Exec(_delUserBase, mid); err != nil {
- log.Error("fail to del user base, mid(%d) dao.userDB.Exec() error(%+v)", mid, err)
- return
- }
- return res.RowsAffected()
- }
- // TxDelUserTel update user tel deleted = 1.
- func (d *Dao) TxDelUserTel(tx *xsql.Tx, mid int64) (affected int64, err error) {
- var res sql.Result
- if res, err = tx.Exec(_delUserTel, mid); err != nil {
- log.Error("fail to del user tel, mid(%d) dao.userDB.Exec() error(%+v)", mid, err)
- return
- }
- return res.RowsAffected()
- }
- // TxDelUserEmail update user email deleted = 1.
- func (d *Dao) TxDelUserEmail(tx *xsql.Tx, mid int64) (affected int64, err error) {
- var res sql.Result
- if res, err = tx.Exec(_delUserEmail, mid); err != nil {
- log.Error("fail to del user email, mid(%d) dao.userDB.Exec() error(%+v)", mid, err)
- return
- }
- return res.RowsAffected()
- }
- // TxInsertUpdateUserRegOrigin insert update user reg origin.
- func (d *Dao) TxInsertUpdateUserRegOrigin(tx *xsql.Tx, a *model.UserRegOrigin) (affected int64, err error) {
- var res sql.Result
- if res, err = tx.Exec(fmt.Sprintf(_insertUpdateUserRegOriginSQL, tableIndex(a.Mid)), a.Mid, a.JoinIP, a.JoinIPV6, a.Port, a.JoinTime, a.JoinIP, a.JoinIPV6, a.Port, a.JoinTime); err != nil {
- log.Error("fail to insert update user reg origin, userRegOrigin(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // InsertUpdateUserRegOriginType insert update user reg origin type.
- func (d *Dao) InsertUpdateUserRegOriginType(c context.Context, a *model.UserRegOrigin) (affected int64, err error) {
- var res sql.Result
- if res, err = d.userDB.Exec(c, fmt.Sprintf(_insertUpdateUserRegOriginTypeSQL, tableIndex(a.Mid)), a.Mid, a.Origin, a.RegType, a.AppID, a.CTime, a.MTime,
- a.Origin, a.RegType, a.AppID, a.CTime, a.MTime); err != nil {
- log.Error("fail to insert update user reg origin type, userRegOrigin(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // CountryCodeMap get country code map.
- func (d *Dao) CountryCodeMap(c context.Context) (res map[int64]string, err error) {
- var rows *xsql.Rows
- if rows, err = d.userDB.Query(c, _getCountryCodeMapSQL); err != nil {
- log.Error("fail to get CountryCodeMap, dao.userDB.Query(%s) error(%+v)", _getCountryCodeMapSQL, err)
- return
- }
- defer rows.Close()
- res = make(map[int64]string)
- for rows.Next() {
- var (
- id int64
- code string
- )
- if err = rows.Scan(&id, &code); err != nil {
- log.Error("row.Scan() error(%v)", err)
- res = nil
- return
- }
- res[id] = code
- }
- return
- }
- // GetMidByTel get mid by tel.
- func (d *Dao) GetMidByTel(c context.Context, a *model.UserTel) (mid int64, err error) {
- if err = d.userDB.QueryRow(c, _getMidByTelSQL, a.Tel, a.Cid).Scan(&mid); err != nil {
- log.Error("fail to get mid by tel, dao.userDB.QueryRow(%s) error(%+v)", _getMidByTelSQL, err)
- return
- }
- return
- }
- // GetMidByEmail get mid by email.
- func (d *Dao) GetMidByEmail(c context.Context, a *model.UserEmail) (mid int64, err error) {
- if err = d.userDB.QueryRow(c, _getMidByEmailSQL, a.Email).Scan(&mid); err != nil {
- log.Error("fail to get mid by email, dao.userDB.QueryRow(%s) error(%+v)", _getMidByEmailSQL, err)
- return
- }
- return
- }
- // GetUserBaseByMid get user base by mid.
- func (d *Dao) GetUserBaseByMid(c context.Context, mid int64) (res *model.UserBase, err error) {
- res = &model.UserBase{}
- if err = d.userDB.QueryRow(c, _getUserBaseByMidSQL, mid).Scan(&res.Mid, &res.UserID, &res.Pwd, &res.Salt, &res.Status, &res.CTime, &res.MTime); err != nil {
- if err == xsql.ErrNoRows {
- err = nil
- res = nil
- } else {
- log.Error("fail to get UserBase by mid(%d), dao.userDB.QueryRow(%s) error(%+v)", mid, _getUserBaseByMidSQL, err)
- }
- return
- }
- return
- }
- // GetUserSafeQuestionByMid get user safe question by mid.
- func (d *Dao) GetUserSafeQuestionByMid(c context.Context, mid int64) (res *model.UserSafeQuestion, err error) {
- res = &model.UserSafeQuestion{}
- if err = d.userDB.QueryRow(c, fmt.Sprintf(_getUserSafeQuestionByMidSQL, tableIndex(mid)), mid).Scan(&res.Mid, &res.SafeQuestion, &res.SafeAnswer, &res.SafeBindTime, &res.CTime, &res.MTime); err != nil {
- if err == xsql.ErrNoRows {
- err = nil
- res = nil
- } else {
- log.Error("fail to get UserSafeQuestion by mid(%d), dao.userDB.QueryRow(%s) error(%+v)", mid, _getUserSafeQuestionByMidSQL, err)
- }
- return
- }
- return
- }
- // GetUserThirdBindByMid get user third bind by mid.
- func (d *Dao) GetUserThirdBindByMid(c context.Context, mid int64) (res []*model.UserThirdBind, err error) {
- var rows *xsql.Rows
- if rows, err = d.userDB.Query(c, _getUserThirdBindByMidSQL, mid); err != nil {
- log.Error("fail to get UserThirdBind, dao.userDB.Query(%s) error(%+v)", _getUserThirdBindByMidSQL, err)
- return
- }
- defer rows.Close()
- for rows.Next() {
- r := new(model.UserThirdBind)
- if err = rows.Scan(&r.ID, &r.Mid, &r.OpenID, &r.PlatForm, &r.Token, &r.Expires, &r.CTime, &r.MTime); err != nil {
- log.Error("row.Scan() error(%v)", err)
- res = nil
- return
- }
- res = append(res, r)
- }
- return
- }
- // GetUserThirdBindByMidAndPlatform get user third bind by mid and platform.
- func (d *Dao) GetUserThirdBindByMidAndPlatform(c context.Context, mid, platform int64) (res *model.UserThirdBind, err error) {
- res = &model.UserThirdBind{}
- if err = d.userDB.QueryRow(c, _getUserThirdBindByMidAndPlatformSQL, mid, platform).Scan(&res.ID, &res.Mid, &res.OpenID, &res.PlatForm, &res.Token, &res.Expires, &res.CTime, &res.MTime); err != nil {
- if err == xsql.ErrNoRows {
- err = nil
- res = nil
- } else {
- log.Error("fail to get UserSafeQuestion by mid(%d) platform(%d), dao.userDB.QueryRow(%s) error(%+v)", mid, platform, _getUserThirdBindByMidAndPlatformSQL, err)
- }
- return
- }
- return
- }
- // GetUserRegOriginByMid get user reg origin by mid.
- func (d *Dao) GetUserRegOriginByMid(c context.Context, mid int64) (res *model.UserRegOrigin, err error) {
- res = &model.UserRegOrigin{}
- if err = d.userDB.QueryRow(c, fmt.Sprintf(_getUserRegOriginByMidSQL, tableIndex(mid)), mid).Scan(&res.Mid, &res.JoinIP, &res.JoinIPV6, &res.Port, &res.JoinTime, &res.Origin, &res.RegType, &res.AppID); err != nil {
- if err == xsql.ErrNoRows {
- err = nil
- res = nil
- } else {
- log.Error("fail to get UserRegOrigin by mid(%d), dao.userDB.QueryRow(%s) error(%+v)", mid, _getUserRegOriginByMidSQL, err)
- }
- return
- }
- return
- }
- // InsertUpdateUserBase insert update user base.
- func (d *Dao) InsertUpdateUserBase(c context.Context, a *model.UserBase) (affected int64, err error) {
- var res sql.Result
- if res, err = d.userDB.Exec(c, _insertUpdateUserBaseSQL, a.Mid, a.UserID, a.Pwd, a.Salt, a.Status, a.Deleted, a.MTime, a.UserID, a.Pwd, a.Salt, a.Status); err != nil {
- log.Error("fail to insert update user base, userBase(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // TxInsertIgnoreUserSafeQuestion insert ignore user safe question.
- func (d *Dao) TxInsertIgnoreUserSafeQuestion(tx *xsql.Tx, a *model.UserSafeQuestion) (affected int64, err error) {
- var res sql.Result
- if res, err = tx.Exec(fmt.Sprintf(_insertIgnoreUserSafeQuestionSQL, tableIndex(a.Mid)), a.Mid, a.SafeQuestion, a.SafeAnswer, a.SafeBindTime); err != nil {
- log.Error("fail to insert ignore user safe question, userSafeQuestion(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // TxInsertIgnoreUserRegOrigin insert ignore user reg origin.
- func (d *Dao) TxInsertIgnoreUserRegOrigin(tx *xsql.Tx, a *model.UserRegOrigin) (affected int64, err error) {
- var res sql.Result
- if res, err = tx.Exec(fmt.Sprintf(_insertIgnoreUserRegOriginSQL, tableIndex(a.Mid)), a.Mid, a.JoinIP, a.JoinIPV6, a.Port, a.JoinTime); err != nil {
- log.Error("fail to insert ignore user reg origin, userRegOrigin(%+v) dao.userDB.Exec() error(%+v)", a, err)
- return
- }
- return res.RowsAffected()
- }
- // DelUserThirdBind del user third bind.
- func (d *Dao) DelUserThirdBind(c context.Context, mid int64) (affected int64, err error) {
- var res sql.Result
- if res, err = d.userDB.Exec(c, _delUserThirdBindSQL, mid); err != nil {
- log.Error("fail to del user third bind, mid(%d) dao.userDB.Exec() error(%+v)", mid, err)
- return
- }
- return res.RowsAffected()
- }
- func tableIndex(mid int64) int64 {
- return mid % 100
- }
|