正在显示
6 个修改的文件
包含
29 行增加
和
30 行删除
@@ -17,7 +17,7 @@ func (r *UserRepository) GetUsersById(uid int64) (v *models.User, err error) { | @@ -17,7 +17,7 @@ func (r *UserRepository) GetUsersById(uid int64) (v *models.User, err error) { | ||
17 | } | 17 | } |
18 | 18 | ||
19 | func (r *UserRepository) GetUsersByMobile(mobile string) (v *models.User, err error) { | 19 | func (r *UserRepository) GetUsersByMobile(mobile string) (v *models.User, err error) { |
20 | - return models.GetUsersByMobile(mobile) | 20 | + return models.GetUserByMobile(mobile) |
21 | } | 21 | } |
22 | 22 | ||
23 | func (r *UserRepository) UpdateUserInfo(m *models.User) (err error) { | 23 | func (r *UserRepository) UpdateUserInfo(m *models.User) (err error) { |
@@ -8,6 +8,7 @@ type IUserAuthRepository interface { | @@ -8,6 +8,7 @@ type IUserAuthRepository interface { | ||
8 | GetUserAuthByAuthCode(authCode string) (v *models.UserAuth, err error) | 8 | GetUserAuthByAuthCode(authCode string) (v *models.UserAuth, err error) |
9 | GetUserAuthByRefreshToken(refreshToken string) (v *models.UserAuth, err error) | 9 | GetUserAuthByRefreshToken(refreshToken string) (v *models.UserAuth, err error) |
10 | GetUserAuthByToken(refreshToken string) (v *models.UserAuth, err error) | 10 | GetUserAuthByToken(refreshToken string) (v *models.UserAuth, err error) |
11 | + AddUserAuth(m *models.UserAuth) (err error) | ||
11 | } | 12 | } |
12 | 13 | ||
13 | var _ IUserAuthRepository = (*UserAuthRepository)(nil) | 14 | var _ IUserAuthRepository = (*UserAuthRepository)(nil) |
@@ -22,6 +23,11 @@ func (r *UserAuthRepository) UpdateUserAuthById(m *models.UserAuth) (err error) | @@ -22,6 +23,11 @@ func (r *UserAuthRepository) UpdateUserAuthById(m *models.UserAuth) (err error) | ||
22 | return models.UpdateUserAuthById(m) | 23 | return models.UpdateUserAuthById(m) |
23 | } | 24 | } |
24 | 25 | ||
26 | +func (r *UserAuthRepository) AddUserAuth(m *models.UserAuth) (err error) { | ||
27 | + _, err = models.AddUserAuth(m) | ||
28 | + return | ||
29 | +} | ||
30 | + | ||
25 | func (r *UserAuthRepository) GetUserAuthByAuthCode(authCode string) (v *models.UserAuth, err error) { | 31 | func (r *UserAuthRepository) GetUserAuthByAuthCode(authCode string) (v *models.UserAuth, err error) { |
26 | return models.GetUserByAuthCode(authCode) | 32 | return models.GetUserByAuthCode(authCode) |
27 | } | 33 | } |
@@ -33,3 +33,8 @@ func (r *UserAuthMockRepository) GetUserAuthByToken(refreshToken string) (v *mod | @@ -33,3 +33,8 @@ func (r *UserAuthMockRepository) GetUserAuthByToken(refreshToken string) (v *mod | ||
33 | v = userAuth | 33 | v = userAuth |
34 | return | 34 | return |
35 | } | 35 | } |
36 | + | ||
37 | +func (r *UserAuthMockRepository) AddUserAuth(m *models.UserAuth) (err error) { | ||
38 | + //_,err =models.AddUserAuth(m) | ||
39 | + return | ||
40 | +} |
@@ -187,7 +187,7 @@ func GetUserAuthByToken(refreshToken string) (v *UserAuth, err error) { | @@ -187,7 +187,7 @@ func GetUserAuthByToken(refreshToken string) (v *UserAuth, err error) { | ||
187 | // Id doesn't exist | 187 | // Id doesn't exist |
188 | func GetUserAuthByUserId(uid int64) (v *UserAuth, err error) { | 188 | func GetUserAuthByUserId(uid int64) (v *UserAuth, err error) { |
189 | o := orm.NewOrm() | 189 | o := orm.NewOrm() |
190 | - sql := "select * from user_id where user_id=?" // | 190 | + sql := "select * from user_auth where user_id=?" // |
191 | if err = o.Raw(sql, uid).QueryRow(&v); err == nil { | 191 | if err = o.Raw(sql, uid).QueryRow(&v); err == nil { |
192 | return v, nil | 192 | return v, nil |
193 | } | 193 | } |
@@ -56,7 +56,7 @@ func GetUsersById(id int64) (v *User, err error) { | @@ -56,7 +56,7 @@ func GetUsersById(id int64) (v *User, err error) { | ||
56 | 56 | ||
57 | // GetAllUsers retrieves all Users matches certain condition. Returns empty list if | 57 | // GetAllUsers retrieves all Users matches certain condition. Returns empty list if |
58 | // no records exist | 58 | // no records exist |
59 | -func GetAllUsers(query map[string]string, fields []string, sortby []string, order []string, | 59 | +func GetAllUser(query map[string]string, fields []string, sortby []string, order []string, |
60 | offset int64, limit int64) (ml []interface{}, err error) { | 60 | offset int64, limit int64) (ml []interface{}, err error) { |
61 | o := orm.NewOrm() | 61 | o := orm.NewOrm() |
62 | qs := o.QueryTable(new(User)) | 62 | qs := o.QueryTable(new(User)) |
@@ -162,18 +162,9 @@ func DeleteUsers(id int64) (err error) { | @@ -162,18 +162,9 @@ func DeleteUsers(id int64) (err error) { | ||
162 | return | 162 | return |
163 | } | 163 | } |
164 | 164 | ||
165 | -func GetUsersByMobile(mobile string) (v *User, err error) { | 165 | +func GetUserKefu() (v []*User, err error) { |
166 | o := orm.NewOrm() | 166 | o := orm.NewOrm() |
167 | - sql := `select * from users where username=?` | ||
168 | - if err = o.Raw(sql, mobile).QueryRow(&v); err == nil { | ||
169 | - return v, nil | ||
170 | - } | ||
171 | - return nil, err | ||
172 | -} | ||
173 | - | ||
174 | -func GetUsersKefu() (v []*User, err error) { | ||
175 | - o := orm.NewOrm() | ||
176 | - sql := `select * from users where is_kefu = 1` | 167 | + sql := `select * from user where is_kefu = 1` |
177 | if _, err = o.Raw(sql).QueryRows(&v); err == nil { | 168 | if _, err = o.Raw(sql).QueryRows(&v); err == nil { |
178 | return v, nil | 169 | return v, nil |
179 | } | 170 | } |
@@ -182,18 +173,9 @@ func GetUsersKefu() (v []*User, err error) { | @@ -182,18 +173,9 @@ func GetUsersKefu() (v []*User, err error) { | ||
182 | 173 | ||
183 | func GetUserByMobile(mobile string) (v *User, err error) { | 174 | func GetUserByMobile(mobile string) (v *User, err error) { |
184 | o := orm.NewOrm() | 175 | o := orm.NewOrm() |
185 | - sql := "select * from users where phone=?" | 176 | + sql := "select * from user where phone=?" |
186 | if err = o.Raw(sql, mobile).QueryRow(&v); err == nil { | 177 | if err = o.Raw(sql, mobile).QueryRow(&v); err == nil { |
187 | return v, nil | 178 | return v, nil |
188 | } | 179 | } |
189 | return nil, err | 180 | return nil, err |
190 | } | 181 | } |
191 | - | ||
192 | -//func GetUserInfoByClientId(clintId string) (v *User, err error) { | ||
193 | -// o := orm.NewOrm() | ||
194 | -// sql := "select * from users where clientId=?" | ||
195 | -// if err = o.Raw(sql, clintId).QueryRow(&v); err == nil { | ||
196 | -// return v, nil | ||
197 | -// } | ||
198 | -// return nil, err | ||
199 | -//} |
@@ -4,6 +4,7 @@ import ( | @@ -4,6 +4,7 @@ import ( | ||
4 | "bytes" | 4 | "bytes" |
5 | "encoding/json" | 5 | "encoding/json" |
6 | "fmt" | 6 | "fmt" |
7 | + "github.com/astaxie/beego/orm" | ||
7 | "html/template" | 8 | "html/template" |
8 | "math/rand" | 9 | "math/rand" |
9 | "strings" | 10 | "strings" |
@@ -90,12 +91,17 @@ Success: | @@ -90,12 +91,17 @@ Success: | ||
90 | } | 91 | } |
91 | userAuth, err = repository.UserAuth.GetUserAuthByUserId(user.Id) | 92 | userAuth, err = repository.UserAuth.GetUserAuthByUserId(user.Id) |
92 | if err != nil { | 93 | if err != nil { |
93 | - log.Error(err) | ||
94 | - return | ||
95 | - } | ||
96 | - if userAuth.AuthCode == "" { | ||
97 | - userAuth.AuthCode = uid.NewV1().StringNoDash() | 94 | + if err == orm.ErrNoRows { |
95 | + userAuth = &models.UserAuth{ | ||
96 | + UserId: user.Id, | ||
97 | + } | ||
98 | + repository.UserAuth.AddUserAuth(userAuth) | ||
99 | + } else { | ||
100 | + log.Error(err) | ||
101 | + return | ||
102 | + } | ||
98 | } | 103 | } |
104 | + userAuth.AuthCode = uid.NewV1().StringNoDash() | ||
99 | if checkImResponse, err = CheckIm(&protocol.CheckImRequest{ | 105 | if checkImResponse, err = CheckIm(&protocol.CheckImRequest{ |
100 | Uid: fmt.Sprintf("%v", user.Id), | 106 | Uid: fmt.Sprintf("%v", user.Id), |
101 | Uname: user.NickName, | 107 | Uname: user.NickName, |
@@ -428,7 +434,7 @@ func imUserRefreshToken(request *protocol.CheckImRequest, rsp *protocol.CheckImR | @@ -428,7 +434,7 @@ func imUserRefreshToken(request *protocol.CheckImRequest, rsp *protocol.CheckImR | ||
428 | 434 | ||
429 | // 获取客服id | 435 | // 获取客服id |
430 | func imGetRandomCSAccount() (acid int64) { | 436 | func imGetRandomCSAccount() (acid int64) { |
431 | - kefus, err := models.GetUsersKefu() | 437 | + kefus, err := models.GetUserKefu() |
432 | if err != nil { | 438 | if err != nil { |
433 | log.Error(err) | 439 | log.Error(err) |
434 | return | 440 | return |
-
请 注册 或 登录 后发表评论