feat : login
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-01-25 17:03:14 +08:00
parent bb95dc0172
commit da57f02191
12 changed files with 277 additions and 3 deletions
@@ -0,0 +1,11 @@
package model
type Business struct {
address string
point float64
tags string
pictures []string
Uuid string
Phone string
Scripts *[]Scripts `json:"tags,omitempty" gorm:"many2many:business_scripts;foreignKey:Uuid;joinForeignKey:CategoryUid;References:Uuid;JoinReferences:TagUid" valid:"no_empty"`
}
@@ -0,0 +1,13 @@
package model
//todo:建立一个公共的model
type Dm struct {
address string
point float64
tags string
pictures []string
Uuid string
Phone string
Scripts *[]Scripts `json:"tags,omitempty" gorm:"many2many:business_scripts;foreignKey:Uuid;joinForeignKey:CategoryUid;References:Uuid;JoinReferences:TagUid" valid:"no_empty"`
}
@@ -0,0 +1,4 @@
package model
type model struct {
}
@@ -0,0 +1,30 @@
package model
import (
"context"
"git.icechen.cn/monorepo/backend/pkg/orm"
"time"
)
type Token struct {
Tokenid string `json:"tokenid" gorm:"column:tokenid"` // token 唯一id
OpenID string `json:"openId" gorm:"column:openId"`
TypeID string `json:"typeId" gorm:"column:typeId"`
ExpireTime time.Time `json:"expire_time" gorm:"column:expire_time"`
Level int `json:"level" gorm:"column:level"`
}
func (m *Token) TableName() string {
return "token"
}
func NewToken(ctx context.Context, token *Token) error {
db, err := orm.GetContextDB(ctx)
if err != nil {
return err
}
if err = db.Create(token).Error; err != nil {
return err
}
return nil
}
@@ -0,0 +1,42 @@
package model
import (
"context"
"git.icechen.cn/monorepo/backend/pkg/orm"
)
type User struct {
NickName string `json:"nick_name" gorm:"column:nick_name"` // 用户昵称
AvatarUrl string `json:"avatar_url" gorm:"column:avatar_url"` // 用户头像图片的 URL。URL 最后一个数值代表正方形头像大小(有 0、46、64、96、132 数值可选,0 代表 640x640 的正方形头像,46 表示 46x46 的正方形头像,剩余数值以此类推。默认132),用户没有头像时该项为空。若用户更换头像,原有头像 URL 将失效。
Openid string `json:"openid" gorm:"column:openid"` // 用户唯一标识
SessionKey string `json:"session_key" gorm:"column:session_key"` // 会话密钥
Typeid string `json:"typeid" gorm:"column:typeid"` // 某个小程序的唯一id,配置文件里面的key
}
func (m *User) TableName() string {
return "user"
}
func GetUserInfo(ctx context.Context, typeId, openId string) (*User, error) {
db, err := orm.GetContextDB(ctx)
if err != nil {
return nil, err
}
i := new(User)
affected := db.First(i, "typeid = ? AND openid = ?", typeId, openId).RowsAffected
if affected == 1 {
return i, nil
}
return nil, nil
}
func NewUser(ctx context.Context, user *User) error {
db, err := orm.GetContextDB(ctx)
if err != nil {
return err
}
if err = db.Create(user).Error; err != nil {
return err
}
return nil
}