37 lines
994 B
Go
37 lines
994 B
Go
|
package service
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"errors"
|
||
|
"gorm.io/gorm"
|
||
|
"youtu_ecpm/dao/model"
|
||
|
"youtu_ecpm/dao/query"
|
||
|
)
|
||
|
|
||
|
type AppUserInfo struct {
|
||
|
q *query.Query
|
||
|
}
|
||
|
|
||
|
func NewAppUserInfo(q *query.Query) *AppUserInfo {
|
||
|
return &AppUserInfo{q: q}
|
||
|
}
|
||
|
|
||
|
func (a *AppUserInfo) SaveUserInfoByRes(c context.Context, res *model.AppUserInfo) (err error) {
|
||
|
|
||
|
m, err := a.q.AppUserInfo.WithContext(c).Where(a.q.AppUserInfo.Openid.Eq(res.Openid), a.q.AppAccount.AppID.Eq(res.Openid)).Join(a.q.AppAccount, a.q.AppAccount.ID.EqCol(a.q.AppUserInfo.AppAccountID)).Take()
|
||
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
if m == nil || m.ID == 0 {
|
||
|
err = a.q.AppUserInfo.WithContext(c).Create(res)
|
||
|
}
|
||
|
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (a *AppUserInfo) UpdateUserNickNameAndImageUrl(ctx context.Context, id uint64, nickname string, url string) (err error) {
|
||
|
_, err = a.q.AppUserInfo.WithContext(ctx).Where(a.q.AppUserInfo.ID.Eq(id)).Updates(&model.AppUserInfo{ID: id, Nickname: nickname, Avatar: url})
|
||
|
return
|
||
|
}
|