youtu_ecpm/api/gin/service/app_user_info.go

42 lines
1.2 KiB
Go
Raw Normal View History

2025-01-18 17:56:36 +08:00
package service
import (
"context"
"errors"
2025-01-20 00:11:11 +08:00
"gitea.youtukeji.com.cn/xiabin/youtu_ecpm/dao/model"
"gitea.youtukeji.com.cn/xiabin/youtu_ecpm/dao/query"
2025-01-18 19:02:58 +08:00
"github.com/gin-gonic/gin"
2025-01-18 17:56:36 +08:00
"gorm.io/gorm"
)
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
}
2025-01-18 19:02:58 +08:00
func (a *AppUserInfo) GetUserById(c *gin.Context, id uint64) (*model.AppUserInfo, error) {
return a.q.AppUserInfo.WithContext(c).Where(a.q.AppUserInfo.ID.Eq(id)).Take()
}