forked from lonng/nanoserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththird_account.go
51 lines (41 loc) · 1023 Bytes
/
third_account.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package db
import (
"github.com/lonnng/nanoserver/internal/errutil"
"github.com/lonnng/nanoserver/db/model"
)
func QueryThirdAccount(account, platform string) (*model.ThirdAccount, error) {
t := &model.ThirdAccount{ThirdAccount: account, Platform: platform}
has, err := DB.Get(t)
if err != nil {
return nil, err
}
if !has {
return nil, errutil.YXErrThirdAccountNotFound
}
return t, nil
}
func InsertThirdAccount(account *model.ThirdAccount, u *model.User) error {
session := DB.NewSession()
if err := session.Begin(); err != nil {
return err
}
defer session.Close()
if _, err := session.Insert(u); err != nil {
session.Rollback()
return err
}
// update uid
account.Uid = u.Id
if _, err := session.Insert(account); err != nil {
session.Rollback()
return err
}
return session.Commit()
}
func UpdateThirdAccount(account *model.ThirdAccount) error {
if account == nil {
return errutil.YXErrInvalidParameter
}
_, err := DB.Where("id=?", account.Id).Update(account)
return err
}