修复序列化代码
This commit is contained in:
parent
f3be74e78c
commit
ab4e5852c1
|
@ -1,118 +0,0 @@
|
|||
package main
|
||||
|
||||
const (
|
||||
_ int = iota
|
||||
LongVarBinary
|
||||
LongVarChar
|
||||
GeometryCollection
|
||||
GeomCollection
|
||||
LineString
|
||||
MultiLineString
|
||||
MultiPoint
|
||||
MultiPolygon
|
||||
Point
|
||||
Polygon
|
||||
Json
|
||||
Geometry
|
||||
Enum
|
||||
Set
|
||||
Bit
|
||||
Time
|
||||
Timestamp
|
||||
DateTime
|
||||
Binary
|
||||
VarBinary
|
||||
Blob
|
||||
Year
|
||||
Decimal
|
||||
Dec
|
||||
Fixed
|
||||
Numeric
|
||||
Float
|
||||
Float4
|
||||
Float8
|
||||
Double
|
||||
Real
|
||||
TinyInt
|
||||
SmallInt
|
||||
MediumInt
|
||||
Int
|
||||
Integer
|
||||
BigInt
|
||||
MiddleInt
|
||||
Int1
|
||||
Int2
|
||||
Int3
|
||||
Int4
|
||||
Int8
|
||||
Date
|
||||
TinyBlob
|
||||
MediumBlob
|
||||
LongBlob
|
||||
Bool
|
||||
Boolean
|
||||
Serial
|
||||
NVarChar
|
||||
NChar
|
||||
Char
|
||||
Character
|
||||
VarChar
|
||||
TinyText
|
||||
Text
|
||||
MediumText
|
||||
LongText
|
||||
)
|
||||
|
||||
var SQLTypeToGoTypeMap = map[int]string{
|
||||
LongVarBinary: "[]byte",
|
||||
Binary: "[]byte",
|
||||
VarBinary: "[]byte",
|
||||
Blob: "[]byte",
|
||||
TinyBlob: "[]byte",
|
||||
MediumBlob: "[]byte",
|
||||
LongBlob: "[]byte",
|
||||
|
||||
LongVarChar: "*string",
|
||||
NVarChar: "*string",
|
||||
NChar: "*string",
|
||||
Char: "*string",
|
||||
Character: "*string",
|
||||
VarChar: "*string",
|
||||
TinyText: "*string",
|
||||
Text: "*string",
|
||||
MediumText: "*string",
|
||||
LongText: "*string",
|
||||
|
||||
Time: "*time.Time",
|
||||
Timestamp: "*time.Time",
|
||||
DateTime: "*time.Time",
|
||||
Date: "*time.Time",
|
||||
|
||||
Year: "*int64",
|
||||
TinyInt: "*int64",
|
||||
SmallInt: "*int64",
|
||||
MediumInt: "*int64",
|
||||
Int: "*int64",
|
||||
Integer: "*int64",
|
||||
BigInt: "*int64",
|
||||
MiddleInt: "*int64",
|
||||
Int1: "*int64",
|
||||
Int2: "*int64",
|
||||
Int3: "*int64",
|
||||
Int4: "*int64",
|
||||
Int8: "*int64",
|
||||
Serial: "*int64",
|
||||
|
||||
Decimal: "*float64",
|
||||
Dec: "*float64",
|
||||
Fixed: "*float64",
|
||||
Numeric: "*float64",
|
||||
Float: "*float64",
|
||||
Float4: "*float64",
|
||||
Float8: "*float64",
|
||||
Double: "*float64",
|
||||
Real: "*float64",
|
||||
|
||||
Bool: "*bool",
|
||||
Boolean: "*bool",
|
||||
}
|
|
@ -16,7 +16,7 @@ import (
|
|||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
var targerDir = "ddl"
|
||||
var ddlDir = "ddl"
|
||||
var genDir = "model/gmodel_gen"
|
||||
|
||||
func toPascalCase(s string) string {
|
||||
|
@ -28,15 +28,27 @@ func toPascalCase(s string) string {
|
|||
}
|
||||
|
||||
func main() {
|
||||
var name string
|
||||
var name string // 需要序列化的单独文件名
|
||||
var gdir string // 需要修改的序列化路径 model
|
||||
var ddir string // 需要修改的序列化路径 ddl
|
||||
flag.StringVar(&name, "name", "", "输入需要序列化的ddl文件名, 不需要后缀.ddl")
|
||||
flag.StringVar(&gdir, "mdir", "", "输入需要生成model的Go文件所在目录")
|
||||
flag.StringVar(&ddir, "ddir", "", "输入需要生成ddl的Go文件所在目录")
|
||||
flag.Parse()
|
||||
|
||||
if gdir != "" {
|
||||
genDir = gdir
|
||||
}
|
||||
|
||||
if ddir != "" {
|
||||
ddlDir = ddir
|
||||
}
|
||||
|
||||
if name != "" {
|
||||
name = fmt.Sprintf("%s/%s.sql", targerDir, name)
|
||||
name = fmt.Sprintf("%s/%s.sql", ddlDir, name)
|
||||
GenFromPath(name)
|
||||
} else {
|
||||
matches, err := filepath.Glob(fmt.Sprintf("%s/*.sql", targerDir))
|
||||
matches, err := filepath.Glob(fmt.Sprintf("%s/*.sql", ddlDir))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -128,6 +140,134 @@ func GenFromPath(pth string) {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// log.Println(fcontent)
|
||||
|
||||
fcontent = "package model\n// TODO: 使用model的属性做你想做的"
|
||||
genGoFileName = fmt.Sprintf("%s/%s_logic.go", genDir, table.Name)
|
||||
f2, err := os.OpenFile(genGoFileName, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
f2.WriteString(fcontent)
|
||||
err = f2.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
_ int = iota
|
||||
LongVarBinary
|
||||
LongVarChar
|
||||
GeometryCollection
|
||||
GeomCollection
|
||||
LineString
|
||||
MultiLineString
|
||||
MultiPoint
|
||||
MultiPolygon
|
||||
Point
|
||||
Polygon
|
||||
Json
|
||||
Geometry
|
||||
Enum
|
||||
Set
|
||||
Bit
|
||||
Time
|
||||
Timestamp
|
||||
DateTime
|
||||
Binary
|
||||
VarBinary
|
||||
Blob
|
||||
Year
|
||||
Decimal
|
||||
Dec
|
||||
Fixed
|
||||
Numeric
|
||||
Float
|
||||
Float4
|
||||
Float8
|
||||
Double
|
||||
Real
|
||||
TinyInt
|
||||
SmallInt
|
||||
MediumInt
|
||||
Int
|
||||
Integer
|
||||
BigInt
|
||||
MiddleInt
|
||||
Int1
|
||||
Int2
|
||||
Int3
|
||||
Int4
|
||||
Int8
|
||||
Date
|
||||
TinyBlob
|
||||
MediumBlob
|
||||
LongBlob
|
||||
Bool
|
||||
Boolean
|
||||
Serial
|
||||
NVarChar
|
||||
NChar
|
||||
Char
|
||||
Character
|
||||
VarChar
|
||||
TinyText
|
||||
Text
|
||||
MediumText
|
||||
LongText
|
||||
)
|
||||
|
||||
var SQLTypeToGoTypeMap = map[int]string{
|
||||
LongVarBinary: "[]byte",
|
||||
Binary: "[]byte",
|
||||
VarBinary: "[]byte",
|
||||
Blob: "[]byte",
|
||||
TinyBlob: "[]byte",
|
||||
MediumBlob: "[]byte",
|
||||
LongBlob: "[]byte",
|
||||
|
||||
LongVarChar: "*string",
|
||||
NVarChar: "*string",
|
||||
NChar: "*string",
|
||||
Char: "*string",
|
||||
Character: "*string",
|
||||
VarChar: "*string",
|
||||
TinyText: "*string",
|
||||
Text: "*string",
|
||||
MediumText: "*string",
|
||||
LongText: "*string",
|
||||
|
||||
Time: "*time.Time",
|
||||
Timestamp: "*time.Time",
|
||||
DateTime: "*time.Time",
|
||||
Date: "*time.Time",
|
||||
|
||||
Year: "*int64",
|
||||
TinyInt: "*int64",
|
||||
SmallInt: "*int64",
|
||||
MediumInt: "*int64",
|
||||
Int: "*int64",
|
||||
Integer: "*int64",
|
||||
BigInt: "*int64",
|
||||
MiddleInt: "*int64",
|
||||
Int1: "*int64",
|
||||
Int2: "*int64",
|
||||
Int3: "*int64",
|
||||
Int4: "*int64",
|
||||
Int8: "*int64",
|
||||
Serial: "*int64",
|
||||
|
||||
Decimal: "*float64",
|
||||
Dec: "*float64",
|
||||
Fixed: "*float64",
|
||||
Numeric: "*float64",
|
||||
Float: "*float64",
|
||||
Float4: "*float64",
|
||||
Float8: "*float64",
|
||||
Double: "*float64",
|
||||
Real: "*float64",
|
||||
|
||||
Bool: "*bool",
|
||||
Boolean: "*bool",
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
func TestMain(t *testing.T) {
|
||||
// args := []string{"-name", "fs_guest"}
|
||||
targerDir = "../" + targerDir
|
||||
ddlDir = "../" + ddlDir
|
||||
genDir = "../" + genDir
|
||||
// os.Args = []string{"cmd", "-name=fs_guest"}
|
||||
|
||||
|
|
16
model/gmodel/fs_canteen_type_gen.go
Normal file
16
model/gmodel/fs_canteen_type_gen.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package gmodel
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type FsCanteenType struct {
|
||||
Id int64 `gorm:"primary_key" json:"id"` // ID
|
||||
Name *string `gorm:"" json:"name"` // 餐厅名字
|
||||
Sort *int64 `gorm:"" json:"sort"` // 排序
|
||||
Status *int64 `gorm:"" json:"status"` // 状态位 1启用0停用
|
||||
Ctime *int64 `gorm:"" json:"ctime"` // 添加时间
|
||||
}
|
||||
type FsCanteenTypeModel struct{ db *gorm.DB }
|
||||
|
||||
func NewFsCanteenTypeModel(db *gorm.DB) *FsCanteenTypeModel { return &FsCanteenTypeModel{db} }
|
24
model/gmodel/fs_canteen_type_logic.go
Normal file
24
model/gmodel/fs_canteen_type_logic.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package gmodel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// FsGetTypeCanteenType GetType返回前端的结构
|
||||
type FsGetTypeCanteenType struct {
|
||||
Id int64 `db:"id" json:"key"` // ID
|
||||
Name string `db:"name" json:"name"` // 餐厅名字
|
||||
}
|
||||
|
||||
// TODO: 使用model的属性做你想做的
|
||||
|
||||
func (c *FsCanteenTypeModel) FindGetType(ctx context.Context, id int64) (resp []*FsGetTypeCanteenType, err error) {
|
||||
err = c.db.WithContext(ctx).Model(&FsGetTypeCanteenType{}).Select("id,name").Order("sort desc").Where("`id` = ? and `status` = ? ", id, 1).Find(&resp).Error
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
16
model/gmodel/fs_font_gen.go
Normal file
16
model/gmodel/fs_font_gen.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package gmodel
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type FsFont struct {
|
||||
Id int64 `gorm:"primary_key" json:"id"` // id
|
||||
Title *string `gorm:"" json:"title"` // 字体名字
|
||||
LinuxFontname *string `gorm:"" json:"linux_fontname"` // linux对应字体名
|
||||
FilePath *string `gorm:"" json:"file_path"` // 字体文件路径
|
||||
Sort *int64 `gorm:"" json:"sort"` // 排序
|
||||
}
|
||||
type FsFontModel struct{ db *gorm.DB }
|
||||
|
||||
func NewFsFontModel(db *gorm.DB) *FsFontModel { return &FsFontModel{db} }
|
21
model/gmodel/fs_font_logic.go
Normal file
21
model/gmodel/fs_font_logic.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package gmodel
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
// TODO: 使用model的属性做你想做的
|
||||
|
||||
func (m *FsFontModel) FindAllOrderSortByDesc(ctx context.Context) ([]*FsFont, error) {
|
||||
|
||||
var fonts []*FsFont
|
||||
err := m.db.Model(&FsFont{}).Order("sort desc").Find(&fonts).Error
|
||||
switch err {
|
||||
case nil:
|
||||
return fonts, nil
|
||||
case ErrRecordNotFound:
|
||||
return nil, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
37
model/gmodel/fs_user_gen.go
Normal file
37
model/gmodel/fs_user_gen.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type FsUser struct {
|
||||
Id int64 `gorm:"primary_key" json:"id"` // ID
|
||||
FaceId *int64 `gorm:"" json:"face_id"` // facebook的userid
|
||||
Sub *int64 `gorm:"" json:"sub"` // google的sub
|
||||
FirstName *string `gorm:"" json:"first_name"` // FirstName
|
||||
LastName *string `gorm:"" json:"last_name"` // LastName
|
||||
Username *string `gorm:"" json:"username"` // 用户名
|
||||
Company *string `gorm:"" json:"company"` // 公司名称
|
||||
Mobile *string `gorm:"" json:"mobile"` // 手机号码
|
||||
AuthKey *string `gorm:"" json:"auth_key"` //
|
||||
PasswordHash *string `gorm:"" json:"password_hash"` //
|
||||
VerificationToken *string `gorm:"" json:"verification_token"` //
|
||||
PasswordResetToken *string `gorm:"" json:"password_reset_token"` //
|
||||
Email *string `gorm:"" json:"email"` // 邮箱
|
||||
Type *int64 `gorm:"" json:"type"` // 1普通餐厅 2连锁餐厅
|
||||
Status *int64 `gorm:"" json:"status"` // 1正常 0不正常
|
||||
IsDel *int64 `gorm:"" json:"is_del"` // 是否删除 1删除
|
||||
CreatedAt *int64 `gorm:"" json:"created_at"` // 添加时间
|
||||
UpdatedAt *int64 `gorm:"" json:"updated_at"` // 更新时间
|
||||
IsOrderStatusEmail *int64 `gorm:"" json:"is_order_status_email"` // 订单状态改变时是否接收邮件
|
||||
IsEmailAdvertisement *int64 `gorm:"" json:"is_email_advertisement"` // 是否接收邮件广告
|
||||
IsOrderStatusPhone *int64 `gorm:"" json:"is_order_status_phone"` // 订单状态改变是是否接收电话
|
||||
IsPhoneAdvertisement *int64 `gorm:"" json:"is_phone_advertisement"` // 是否接收短信广告
|
||||
IsOpenRender *int64 `gorm:"" json:"is_open_render"` // 是否打开个性化渲染(1:开启,0:关闭)
|
||||
IsThousandFace *int64 `gorm:"" json:"is_thousand_face"` // 是否已经存在千人千面(1:存在,0:不存在)
|
||||
IsLowRendering *int64 `gorm:"" json:"is_low_rendering"` // 是否开启低渲染模型渲染
|
||||
IsRemoveBg *int64 `gorm:"" json:"is_remove_bg"` // 用户上传logo是否去除背景
|
||||
}
|
||||
type FsUserModel struct{ db *gorm.DB }
|
||||
|
||||
func NewFsUserModel(db *gorm.DB) *FsUserModel { return &FsUserModel{db} }
|
22
model/gmodel/fs_user_logic.go
Normal file
22
model/gmodel/fs_user_logic.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package gmodel
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
// TODO: 使用model的属性做你想做的
|
||||
|
||||
func (u *FsUserModel) FindUserByEmail(ctx context.Context, emailname string) (resp *FsUser, err error) {
|
||||
err = u.db.WithContext(ctx).Model(&FsUser{}).Where("`email` = ?", emailname).First(resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (u *FsUserModel) FindUserById(ctx context.Context, Id int64) (resp *FsUser, err error) {
|
||||
err = u.db.WithContext(ctx).Model(&FsUser{}).Where("`id` = ? and is_del = ?", Id, 0).First(resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (u *FsUserModel) UpdateUserBasicInfoById(ctx context.Context, Id int64, user *FsUser) (resp *FsUser, err error) {
|
||||
err = u.db.WithContext(ctx).Model(&FsUser{}).Where("`id` = ? and is_del = ? and status = ?", user.Id, 0, 1).Updates(user).Error
|
||||
return resp, err
|
||||
}
|
|
@ -3,6 +3,7 @@ package gmodel
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
|
@ -37,6 +38,7 @@ func (a *FsAddressModel) GetOne(ctx context.Context, id int64, userId int64) (re
|
|||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (a *FsAddressModel) GetUserAllAddress(ctx context.Context, userId int64) (resp []FsAddress, err error) {
|
||||
err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`user_id` = ? and `status` = ?", userId, 1).Order("`id` DESC").Find(&resp).Error
|
||||
if err != nil {
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
package gmodel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type FsCanteenType struct {
|
||||
Id int64 `gorm:"primary_key" json:"id"` // ID
|
||||
Name *string `gorm:"default:''" json:"name"` // 餐厅名字
|
||||
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
|
||||
Status *int64 `gorm:"default:1" json:"status"` // 状态位 1启用0停用
|
||||
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
|
||||
}
|
||||
type FsCanteenTypeModel struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewFsCanteenTypeModel(db *gorm.DB) *FsCanteenTypeModel {
|
||||
return &FsCanteenTypeModel{db}
|
||||
}
|
||||
|
||||
func (c *FsCanteenTypeModel) FindOne(ctx context.Context, id int64) (resp FsCanteenType, err error) {
|
||||
err = c.db.WithContext(ctx).Model(&FsCanteenType{}).Where("`id` = ? and `status` = ? ", id, 1).First(&resp).Error
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return FsCanteenType{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package gmodel
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
type FsFont struct {
|
||||
Id int64 `gorm:"primary_key" json:"id"` // id
|
||||
Title *string `gorm:"default:''" json:"title"` // 字体名字
|
||||
LinuxFontname *string `gorm:"default:''" json:"linux_fontname"` // linux对应字体名
|
||||
FilePath *string `gorm:"default:''" json:"file_path"` // 字体文件路径
|
||||
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
|
||||
}
|
||||
type FsFontModel struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewFsFontModel(db *gorm.DB) *FsFontModel {
|
||||
return &FsFontModel{db}
|
||||
}
|
|
@ -1,14 +1,52 @@
|
|||
package gmodel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fusenapi/utils/auth"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type FsGuest struct {
|
||||
GuestId int64 `gorm:"" json:"guest_id"` // ID
|
||||
AuthKey *string `gorm: json:"auth_key"` // jwt token
|
||||
Status *int64 `gorm: json:"status"` // 1正常 0不正常
|
||||
IsDel *int64 `gorm: json:"is_del"` // 是否删除 1删除
|
||||
CreatedAt *int64 `gorm: json:"created_at"` // 添加时间
|
||||
UpdatedAt *int64 `gorm: json:"updated_at"` // 更新时间
|
||||
IsOpenRender *int64 `gorm: json:"is_open_render"` // 是否打开个性化渲染(1:开启,0:关闭)
|
||||
IsThousandFace *int64 `gorm: json:"is_thousand_face"` // 是否已经存在千人千面(1:存在,0:不存在)
|
||||
IsLowRendering *int64 `gorm: json:"is_low_rendering"` // 是否开启低渲染模型渲染
|
||||
IsRemoveBg *int64 `gorm: json:"is_remove_bg"` // 用户上传logo是否去除背景
|
||||
GuestId int64 `gorm:"primary_key" json:"guest_id"` // 游客ID
|
||||
AuthKey *string `gorm:"" json:"auth_key"` // jwt token
|
||||
Status *int64 `gorm:"" json:"status"` // 1正常 0不正常
|
||||
IsDel *int64 `gorm:"" json:"is_del"` // 是否删除 1删除
|
||||
CreatedAt *int64 `gorm:"" json:"created_at"` // 添加时间
|
||||
UpdatedAt *int64 `gorm:"" json:"updated_at"` // 更新时间
|
||||
IsOpenRender *int64 `gorm:"" json:"is_open_render"` // 是否打开个性化渲染(1:开启,0:关闭)
|
||||
IsThousandFace *int64 `gorm:"" json:"is_thousand_face"` // 是否已经存在千人千面(1:存在,0:不存在)
|
||||
IsLowRendering *int64 `gorm:"" json:"is_low_rendering"` // 是否开启低渲染模型渲染
|
||||
IsRemoveBg *int64 `gorm:"" json:"is_remove_bg"` // 用户上传logo是否去除背景
|
||||
}
|
||||
type FsGuestModel struct{ db *gorm.DB }
|
||||
|
||||
func NewFsGuestModel(db *gorm.DB) *FsGuestModel { return &FsGuestModel{db} }
|
||||
|
||||
func (m *FsGuestModel) GenerateGuestID(ctx context.Context, AccessSecret *string) (authKey string, err error) {
|
||||
|
||||
err = m.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
now := time.Now().Unix()
|
||||
var record = &FsGuest{}
|
||||
tx.Create(record)
|
||||
|
||||
authKey, err = auth.GenerateJwtToken(AccessSecret, now, 31536000, 0, record.GuestId)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
record.AuthKey = &authKey
|
||||
record.CreatedAt = &now
|
||||
tx.Updates(record)
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return authKey, nil
|
||||
}
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
package gmodel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type FsUser struct {
|
||||
Id int64 `gorm:"primary_key" json:"id"` // ID
|
||||
FaceId int64 `gorm:"default:0" json:"face_id"` // facebook的userid
|
||||
Sub int64 `gorm:"default:0" json:"sub"` // google的sub
|
||||
FirstName string `gorm:"default:''" json:"first_name"` // FirstName
|
||||
LastName string `gorm:"default:''" json:"last_name"` // LastName
|
||||
Username string `gorm:"default:''" json:"username"` // 用户名
|
||||
Company string `gorm:"default:''" json:"company"` // 公司名称
|
||||
Mobile string `gorm:"default:''" json:"mobile" ` // 手机号码
|
||||
AuthKey string `gorm:"default:''" json:"auth_key"`
|
||||
PasswordHash string `gorm:"default:''" json:"password_hash"`
|
||||
VerificationToken string `gorm:"default:''" json:"verification_token"`
|
||||
PasswordResetToken string `gorm:"default:''" json:"password_reset_token"`
|
||||
Email string `gorm:"default:''" json:"email"` // 邮箱
|
||||
Type int64 `gorm:"default:1" json:"type"` // 1普通餐厅 2连锁餐厅
|
||||
Status int64 `gorm:"default:1" json:"status"` // 1正常 0不正常
|
||||
IsDel int64 `gorm:"default:0" json:"is_del"` // 是否删除 1删除
|
||||
CreatedAt int64 `gorm:"default:0" json:"created_at"` // 添加时间
|
||||
UpdatedAt int64 `gorm:"default:0" json:"updated_at"` // 更新时间
|
||||
IsOrderStatusEmail int64 `gorm:"default:0" json:"is_order_status_email"` // 订单状态改变时是否接收邮件
|
||||
IsEmailAdvertisement int64 `gorm:"default:0" json:"is_email_advertisement"` // 是否接收邮件广告
|
||||
IsOrderStatusPhone int64 `gorm:"default:0" json:"is_order_status_phone"` // 订单状态改变是是否接收电话
|
||||
IsPhoneAdvertisement int64 `gorm:"default:0" json:"is_phone_advertisement"` // 是否接收短信广告
|
||||
IsOpenRender int64 `gorm:"default:0" json:"is_open_render"` // 是否打开个性化渲染(1:开启,0:关闭)
|
||||
IsThousandFace int64 `gorm:"default:0" json:"is_thousand_face"` // 是否已经存在千人千面(1:存在,0:不存在)
|
||||
IsLowRendering int64 `gorm:"default:0" json:"is_low_rendering"` // 是否开启低渲染模型渲染
|
||||
IsRemoveBg int64 `gorm:"default:1" json:"is_remove_bg"` // 用户上传logo是否去除背景
|
||||
}
|
||||
type FsUserModel struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewFsUserModel(db *gorm.DB) *FsUserModel {
|
||||
return &FsUserModel{db}
|
||||
}
|
||||
|
||||
func (u *FsUserModel) FindOne(ctx context.Context, id int64) (resp FsUser, err error) {
|
||||
err = u.db.WithContext(ctx).Model(&FsUser{}).Where("`id` = ? and is_del = ?", id, 0).First(&resp).Error
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return FsUser{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
5
model/gmodel/var.go
Normal file
5
model/gmodel/var.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
package gmodel
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
var ErrRecordNotFound = gorm.ErrRecordNotFound
|
2
model/gmodel_gen/fs_address_logic.go
Normal file
2
model/gmodel_gen/fs_address_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_canteen_product_logic.go
Normal file
2
model/gmodel_gen/fs_canteen_product_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_canteen_type_logic.go
Normal file
2
model/gmodel_gen/fs_canteen_type_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
|
@ -1,9 +1,8 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type FsCart struct {
|
||||
|
|
2
model/gmodel_gen/fs_cart_logic.go
Normal file
2
model/gmodel_gen/fs_cart_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_faq_logic.go
Normal file
2
model/gmodel_gen/fs_faq_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_font_logic.go
Normal file
2
model/gmodel_gen/fs_font_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_guest_logic.go
Normal file
2
model/gmodel_gen/fs_guest_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_map_library_logic.go
Normal file
2
model/gmodel_gen/fs_map_library_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_order_detail_logic.go
Normal file
2
model/gmodel_gen/fs_order_detail_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_order_detail_template_logic.go
Normal file
2
model/gmodel_gen/fs_order_detail_template_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_order_logic.go
Normal file
2
model/gmodel_gen/fs_order_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_product_design_logic.go
Normal file
2
model/gmodel_gen/fs_product_design_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_product_logic.go
Normal file
2
model/gmodel_gen/fs_product_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_product_model3d_light_logic.go
Normal file
2
model/gmodel_gen/fs_product_model3d_light_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_product_model3d_logic.go
Normal file
2
model/gmodel_gen/fs_product_model3d_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_product_price_logic.go
Normal file
2
model/gmodel_gen/fs_product_price_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_product_size_logic.go
Normal file
2
model/gmodel_gen/fs_product_size_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_product_template_tags_logic.go
Normal file
2
model/gmodel_gen/fs_product_template_tags_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_product_template_v2_logic.go
Normal file
2
model/gmodel_gen/fs_product_template_v2_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_qrcode_set_logic.go
Normal file
2
model/gmodel_gen/fs_qrcode_set_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_standard_logo_logic.go
Normal file
2
model/gmodel_gen/fs_standard_logo_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_tags_logic.go
Normal file
2
model/gmodel_gen/fs_tags_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
2
model/gmodel_gen/fs_user_logic.go
Normal file
2
model/gmodel_gen/fs_user_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package model
|
||||
// TODO: 使用model的属性做你想做的
|
|
@ -1,6 +1,7 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
|
@ -31,8 +32,15 @@ func (l *AcceptCookieLogic) AcceptCookie(req *types.Request, userinfo *auth.User
|
|||
// userinfo 传入值时, 一定不为null
|
||||
idtyp := userinfo.GetIdType()
|
||||
if idtyp == auth.IDTYPE_Guest {
|
||||
return resp.SetStatus(basic.CodeDupGuestErr)
|
||||
return resp.SetStatus(basic.CodeGuestDupErr)
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
m := gmodel.NewFsGuestModel(l.svcCtx.MysqlConn)
|
||||
token, err := m.GenerateGuestID(l.ctx, &l.svcCtx.Config.Auth.AccessSecret)
|
||||
if err != nil {
|
||||
return resp.SetStatus(basic.CodeGuestGenErr)
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK, types.DataGuest{
|
||||
Token: token,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package logic
|
|||
import (
|
||||
"context"
|
||||
|
||||
"fusenapi/model"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
|
@ -28,7 +28,7 @@ func NewUserAddressListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *U
|
|||
|
||||
func (l *UserAddressListLogic) UserAddressList(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
m := model.NewFsAddressModel(l.svcCtx.MysqlConn)
|
||||
m := gmodel.NewFsAddressModel(l.svcCtx.MysqlConn)
|
||||
userinfo.GetIdType()
|
||||
// user := auth.GetUserInfoFormCtx(l.ctx)
|
||||
// if user.UserId == 0 {
|
||||
|
@ -36,7 +36,7 @@ func (l *UserAddressListLogic) UserAddressList(req *types.Request, userinfo *aut
|
|||
// }
|
||||
// user.UserId = 22
|
||||
// model里设置了 返回值. 和 types 里的一至可以直接返回
|
||||
data, err := m.FindDataAddressList(l.ctx, 22)
|
||||
data, err := m.GetUserAllAddress(l.ctx, 22)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
||||
|
|
|
@ -2,7 +2,7 @@ package logic
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fusenapi/model"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
|
@ -26,14 +26,37 @@ func NewUserBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Use
|
|||
}
|
||||
|
||||
func (l *UserBasicInfoLogic) UserBasicInfo(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
loginInfo := auth.GetUserInfoFormCtx(l.ctx)
|
||||
if loginInfo.UserId == 0 {
|
||||
return resp.SetStatus(basic.CodeOK, "parse login info err ")
|
||||
|
||||
if !userinfo.IsUser() {
|
||||
// 返回未授权
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
}
|
||||
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, loginInfo.UserId)
|
||||
|
||||
m := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
||||
|
||||
user, err := m.FindUserById(l.ctx, userinfo.UserId)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.Set(510, err.Error())
|
||||
return resp.SetStatus(basic.CodeServiceErr)
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK, fsUserModel)
|
||||
|
||||
// $userInfo->type = $userInfo->type != 0 ? $userInfo->type : '';
|
||||
// $userInfo->is_order_status_email = (boolean)$userInfo->is_order_status_email;
|
||||
// $userInfo->is_email_advertisement = (boolean)$userInfo->is_email_advertisement;
|
||||
// $userInfo->is_order_status_phone = (boolean)$userInfo->is_order_status_phone;
|
||||
// $userInfo->is_phone_advertisement = (boolean)$userInfo->is_phone_advertisement;
|
||||
// $userInfo->is_open_render = (boolean)$userInfo->is_open_render;
|
||||
// $userInfo->is_low_rendering = (boolean)$userInfo->is_low_rendering;
|
||||
// $userInfo->is_remove_bg = (boolean)$userInfo->is_remove_bg;
|
||||
|
||||
return resp.SetStatus(basic.CodeOK, types.DataUserBasicInfo{
|
||||
Type: *user.Type,
|
||||
IsOrderStatusEmail: *user.IsOrderStatusEmail > 0,
|
||||
IsEmailAdvertisement: *user.IsEmailAdvertisement > 0,
|
||||
IsOrderStatusPhone: *user.IsOrderStatusPhone > 0,
|
||||
IsPhoneAdvertisement: *user.IsPhoneAdvertisement > 0,
|
||||
IsOpenRender: *user.IsOpenRender > 0,
|
||||
IsLowRendering: *user.IsLowRendering > 0,
|
||||
IsRemoveBg: *user.IsRemoveBg > 0,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -3,13 +3,14 @@ package logic
|
|||
import (
|
||||
"context"
|
||||
|
||||
"fusenapi/model"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UserFontsLogic struct {
|
||||
|
@ -27,11 +28,10 @@ func NewUserFontsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserFon
|
|||
}
|
||||
|
||||
func (l *UserFontsLogic) UserFonts(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
data, err := model.NewFsFontModel(l.svcCtx.MysqlConn).FindAllOrderSortByDesc(l.ctx)
|
||||
if err != nil {
|
||||
data, err := gmodel.NewFsFontModel(l.svcCtx.MysqlConn).FindAllOrderSortByDesc(l.ctx)
|
||||
if err != gorm.ErrRecordNotFound && err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeOK, data)
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package logic
|
|||
import (
|
||||
"context"
|
||||
|
||||
"fusenapi/model"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
|
@ -28,8 +28,12 @@ func NewUserGetTypeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserG
|
|||
|
||||
func (l *UserGetTypeLogic) UserGetType(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
|
||||
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
}
|
||||
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
data, err := model.NewFsCanteenTypeModel(l.svcCtx.MysqlConn).FindGetType(l.ctx)
|
||||
data, err := gmodel.NewFsCanteenTypeModel(l.svcCtx.MysqlConn).FindGetType(l.ctx, userinfo.UserId)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return
|
||||
|
|
|
@ -4,13 +4,14 @@ import (
|
|||
"context"
|
||||
"time"
|
||||
|
||||
"fusenapi/model"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UserLoginLogic struct {
|
||||
|
@ -29,26 +30,23 @@ func NewUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLog
|
|||
|
||||
func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin) (resp *basic.Response, jwtToken string) {
|
||||
// 创建一个 FsUserModel 对象 m 并实例化之,该对象用于操作 MySQL 数据库中的用户数据表。
|
||||
m := model.NewFsUserModel(l.svcCtx.MysqlConn)
|
||||
m := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
||||
|
||||
// 在用户数据表中根据登录名查找用户记录,并返回 UserModel 类型的结构体对象 userModel。
|
||||
userModel, err := m.FindOneByEmail(l.ctx, req.Name)
|
||||
|
||||
// 如果在用户数据表中没有找到登录名匹配的用户记录,则抛出 ErrNotFound 错误并返回未认证的状态码以及错误信息。
|
||||
if err == model.ErrNotFound {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error()), jwtToken
|
||||
// 在用户数据表中根据登录名(email)查找用户记录,并返回 UserModel 类型的结构体对象 userModel。
|
||||
user, err := m.FindUserByEmail(l.ctx, req.Name)
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return resp.SetStatus(basic.CodeEmailNotFoundErr), ""
|
||||
}
|
||||
|
||||
// 如果在用户数据表中找到了登录名匹配的用户记录,则判断密码是否匹配。
|
||||
if userModel.PasswordHash != req.Password {
|
||||
if *user.PasswordHash != req.Password {
|
||||
logx.Info("密码错误")
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "密码错误"), jwtToken
|
||||
return resp.SetStatus(basic.CodePasswordErr), jwtToken
|
||||
}
|
||||
|
||||
// 如果密码匹配,则生成 JWT Token。
|
||||
nowSec := time.Now().Unix()
|
||||
jwtToken, err = auth.GenerateJwtToken(&l.svcCtx.Config.Auth.AccessSecret, l.svcCtx.Config.Auth.AccessExpire, nowSec, int64(userModel.Id), 0)
|
||||
jwtToken, err = auth.GenerateJwtToken(&l.svcCtx.Config.Auth.AccessSecret, l.svcCtx.Config.Auth.AccessExpire, nowSec, user.Id, 0)
|
||||
|
||||
// 如果生成 JWT Token 失败,则抛出错误并返回未认证的状态码。
|
||||
if err != nil {
|
||||
|
@ -56,9 +54,6 @@ func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin) (resp *basic.Res
|
|||
return resp.SetStatus(basic.CodeUnAuth), jwtToken
|
||||
}
|
||||
|
||||
// 更新 MySQL 数据库中用户记录对应的 VerificationToken 字段值为生成的 JWT Token。
|
||||
err = m.UpdateVerificationToken(l.ctx, userModel.Id, jwtToken)
|
||||
|
||||
// 如果更新 VerificationToken 字段失败,则返回未认证的状态码。
|
||||
if err != nil {
|
||||
return resp.SetStatus(basic.CodeUnAuth), jwtToken
|
||||
|
|
|
@ -2,9 +2,9 @@ package logic
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
|
||||
"fusenapi/model"
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
"fusenapi/utils/basic"
|
||||
|
@ -27,19 +27,16 @@ func NewUserSaveBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
|||
}
|
||||
|
||||
func (l *UserSaveBasicInfoLogic) UserSaveBasicInfo(req *types.RequestBasicInfoForm, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
loginInfo := auth.GetUserInfoFormCtx(l.ctx)
|
||||
if loginInfo.UserId == 0 {
|
||||
return resp.SetStatus(basic.CodeOK, "parse login info err ")
|
||||
}
|
||||
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, loginInfo.UserId)
|
||||
if err != nil {
|
||||
if err == model.ErrNotFound {
|
||||
|
||||
return resp
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp
|
||||
if !userinfo.IsUser() {
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK, fsUserModel)
|
||||
m := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
||||
user, err := m.FindUserById(l.ctx, userinfo.UserId)
|
||||
if err == gmodel.ErrRecordNotFound {
|
||||
return resp.SetStatus(basic.CodeUserIdNotFoundErr)
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
|
|
@ -3,22 +3,23 @@ package svc
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/initalize"
|
||||
"fusenapi/server/home-user-auth/internal/config"
|
||||
"net/http"
|
||||
|
||||
"github.com/golang-jwt/jwt"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
MysqlConn sqlx.SqlConn
|
||||
MysqlConn *gorm.DB
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
MysqlConn: sqlx.NewMysql(c.SourceMysql),
|
||||
MysqlConn: initalize.InitMysql(c.SourceMysql),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ type RequestBasicInfoForm struct {
|
|||
Company string `form:"company,optional" db:"company"` // 公司名称
|
||||
Mobile string `form:"mobile,optional" db:"mobile"` // 手机号码
|
||||
Email string `form:"email" db:"email"` // 邮箱
|
||||
Status int64 `form:"status,optional" db:"status"` // 1正常 0不正常
|
||||
IsOrderStatusEmail int64 `form:"is_order_status_email,optional" db:"is_order_status_email"` // 订单状态改变时是否接收邮件
|
||||
IsEmailAdvertisement int64 `form:"is_email_advertisement,optional" db:"is_email_advertisement"` // 是否接收邮件广告
|
||||
IsOrderStatusPhone int64 `form:"is_order_status_phone,optional" db:"is_order_status_phone"` // 订单状态改变是是否接收电话
|
||||
|
@ -22,7 +21,6 @@ type RequestBasicInfoForm struct {
|
|||
IsOpenRender int64 `form:"is_open_render,optional" db:"is_open_render"` // 是否打开个性化渲染(1:开启,0:关闭)
|
||||
IsLowRendering int64 `form:"is_low_rendering,optional" db:"is_low_rendering"` // 是否开启低渲染模型渲染
|
||||
IsRemoveBg int64 `form:"is_remove_bg,optional" db:"is_remove_bg"` // 用户上传logo是否去除背景
|
||||
NewPassword string `form:"new_password,optional" db:"new_password"` // new_password 如果存在新密码
|
||||
}
|
||||
|
||||
type RequestUserLogin struct {
|
||||
|
@ -31,37 +29,23 @@ type RequestUserLogin struct {
|
|||
}
|
||||
|
||||
type DataUserLogin struct {
|
||||
Token string `json:"token"` // 充值密码token
|
||||
JwtToken string `json:"jwt_token"` // jwt 的Token
|
||||
Token string `json:"token"` // 登录jwt token
|
||||
}
|
||||
|
||||
type DataGuest struct {
|
||||
Token string `json:"token"` // 登录jwt token
|
||||
}
|
||||
|
||||
type DataUserBasicInfo struct {
|
||||
Id int64 `db:"id"` // ID
|
||||
FaceId int64 `db:"face_id"` // facebook的userid
|
||||
Sub int64 `db:"sub"` // google的sub
|
||||
FirstName string `db:"first_name"` // FirstName
|
||||
LastName string `db:"last_name"` // LastName
|
||||
Username string `db:"username"` // 用户名
|
||||
Company string `db:"company"` // 公司名称
|
||||
Mobile string `db:"mobile"` // 手机号码
|
||||
AuthKey string `db:"auth_key"`
|
||||
PasswordHash string `db:"password_hash"`
|
||||
VerificationToken string `db:"verification_token"`
|
||||
PasswordResetToken string `db:"password_reset_token"`
|
||||
Email string `db:"email"` // 邮箱
|
||||
Type int64 `db:"type"` // 1普通餐厅 2连锁餐厅
|
||||
Status int64 `db:"status"` // 1正常 0不正常
|
||||
IsDel int64 `db:"is_del"` // 是否删除 1删除
|
||||
CreatedAt int64 `db:"created_at"` // 添加时间
|
||||
UpdatedAt int64 `db:"updated_at"` // 更新时间
|
||||
IsOrderStatusEmail int64 `db:"is_order_status_email"` // 订单状态改变时是否接收邮件
|
||||
IsEmailAdvertisement int64 `db:"is_email_advertisement"` // 是否接收邮件广告
|
||||
IsOrderStatusPhone int64 `db:"is_order_status_phone"` // 订单状态改变是是否接收电话
|
||||
IsPhoneAdvertisement int64 `db:"is_phone_advertisement"` // 是否接收短信广告
|
||||
IsOpenRender int64 `db:"is_open_render"` // 是否打开个性化渲染(1:开启,0:关闭)
|
||||
IsThousandFace int64 `db:"is_thousand_face"` // 是否已经存在千人千面(1:存在,0:不存在)
|
||||
IsLowRendering int64 `db:"is_low_rendering"` // 是否开启低渲染模型渲染
|
||||
IsRemoveBg int64 `db:"is_remove_bg"` // 用户上传logo是否去除背景
|
||||
Type int64 `db:"type"` // 1普通餐厅 2连锁餐厅
|
||||
IsOrderStatusEmail bool `db:"is_order_status_email"` // 订单状态改变时是否接收邮件
|
||||
IsEmailAdvertisement bool `db:"is_email_advertisement"` // 是否接收邮件广告
|
||||
IsOrderStatusPhone bool `db:"is_order_status_phone"` // 订单状态改变是是否接收电话
|
||||
IsPhoneAdvertisement bool `db:"is_phone_advertisement"` // 是否接收短信广告
|
||||
IsOpenRender bool `db:"is_open_render"` // 是否打开个性化渲染(1:开启,0:关闭)
|
||||
IsThousandFace bool `db:"is_thousand_face"` // 是否已经存在千人千面(1:存在,0:不存在)
|
||||
IsLowRendering bool `db:"is_low_rendering"` // 是否开启低渲染模型渲染
|
||||
IsRemoveBg bool `db:"is_remove_bg"` // 用户上传logo是否去除背景
|
||||
}
|
||||
|
||||
type DataGetType struct {
|
||||
|
|
|
@ -38,25 +38,24 @@ service home-user-auth {
|
|||
|
||||
@handler UserAddressListHandler
|
||||
get /user/address-list(request) returns (response);
|
||||
|
||||
}
|
||||
|
||||
type RequestBasicInfoForm {
|
||||
FirstName string `form:"first_name,optional" db:"first_name"` // FirstName
|
||||
LastName string `form:"last_name,optional" db:"last_name"` // LastName
|
||||
Company string `form:"company,optional" db:"company"` // 公司名称
|
||||
Mobile string `form:"mobile,optional" db:"mobile"` // 手机号码
|
||||
Email string `form:"email" db:"email"` // 邮箱
|
||||
Status int64 `form:"status,optional" db:"status"` // 1正常 0不正常
|
||||
IsOrderStatusEmail int64 `form:"is_order_status_email,optional" db:"is_order_status_email"` // 订单状态改变时是否接收邮件
|
||||
IsEmailAdvertisement int64 `form:"is_email_advertisement,optional" db:"is_email_advertisement"` // 是否接收邮件广告
|
||||
IsOrderStatusPhone int64 `form:"is_order_status_phone,optional" db:"is_order_status_phone"` // 订单状态改变是是否接收电话
|
||||
IsPhoneAdvertisement int64 `form:"is_phone_advertisement,optional" db:"is_phone_advertisement"` // 是否接收短信广告
|
||||
IsOpenRender int64 `form:"is_open_render,optional" db:"is_open_render"` // 是否打开个性化渲染(1:开启,0:关闭)
|
||||
IsLowRendering int64 `form:"is_low_rendering,optional" db:"is_low_rendering"` // 是否开启低渲染模型渲染
|
||||
IsRemoveBg int64 `form:"is_remove_bg,optional" db:"is_remove_bg"` // 用户上传logo是否去除背景
|
||||
FirstName string `form:"first_name,optional" db:"first_name"` // FirstName
|
||||
LastName string `form:"last_name,optional" db:"last_name"` // LastName
|
||||
Company string `form:"company,optional" db:"company"` // 公司名称
|
||||
Mobile string `form:"mobile,optional" db:"mobile"` // 手机号码
|
||||
Email string `form:"email" db:"email"` // 邮箱
|
||||
// Status int64 `form:"status,optional" db:"status"` // 1正常 0不正常
|
||||
IsOrderStatusEmail int64 `form:"is_order_status_email,optional" db:"is_order_status_email"` // 订单状态改变时是否接收邮件
|
||||
IsEmailAdvertisement int64 `form:"is_email_advertisement,optional" db:"is_email_advertisement"` // 是否接收邮件广告
|
||||
IsOrderStatusPhone int64 `form:"is_order_status_phone,optional" db:"is_order_status_phone"` // 订单状态改变是是否接收电话
|
||||
IsPhoneAdvertisement int64 `form:"is_phone_advertisement,optional" db:"is_phone_advertisement"` // 是否接收短信广告
|
||||
IsOpenRender int64 `form:"is_open_render,optional" db:"is_open_render"` // 是否打开个性化渲染(1:开启,0:关闭)
|
||||
IsLowRendering int64 `form:"is_low_rendering,optional" db:"is_low_rendering"` // 是否开启低渲染模型渲染
|
||||
IsRemoveBg int64 `form:"is_remove_bg,optional" db:"is_remove_bg"` // 用户上传logo是否去除背景
|
||||
|
||||
NewPassword string `form:"new_password,optional" db:"new_password"` // new_password 如果存在新密码
|
||||
// NewPassword string `form:"new_password,optional" db:"new_password"` // new_password 如果存在新密码
|
||||
}
|
||||
|
||||
// UserLoginHandler 用户登录请求结构
|
||||
|
@ -67,40 +66,30 @@ type RequestUserLogin {
|
|||
|
||||
// UserLoginHandler 用户登录请求结构
|
||||
type DataUserLogin {
|
||||
Token string `json:"token"` // 充值密码token
|
||||
JwtToken string `json:"jwt_token"` // jwt 的Token
|
||||
Token string `json:"token"` // 登录jwt token
|
||||
}
|
||||
|
||||
// DataGuest 游客获取toekn请求结构
|
||||
type DataGuest {
|
||||
Token string `json:"token"` // 登录jwt token
|
||||
}
|
||||
|
||||
// UserBasicInfoHandler 返回data结构
|
||||
type DataUserBasicInfo {
|
||||
Id int64 `db:"id"` // ID
|
||||
FaceId int64 `db:"face_id"` // facebook的userid
|
||||
Sub int64 `db:"sub"` // google的sub
|
||||
FirstName string `db:"first_name"` // FirstName
|
||||
LastName string `db:"last_name"` // LastName
|
||||
Username string `db:"username"` // 用户名
|
||||
Company string `db:"company"` // 公司名称
|
||||
Mobile string `db:"mobile"` // 手机号码
|
||||
AuthKey string `db:"auth_key"`
|
||||
PasswordHash string `db:"password_hash"`
|
||||
VerificationToken string `db:"verification_token"`
|
||||
PasswordResetToken string `db:"password_reset_token"`
|
||||
Email string `db:"email"` // 邮箱
|
||||
Type int64 `db:"type"` // 1普通餐厅 2连锁餐厅
|
||||
Status int64 `db:"status"` // 1正常 0不正常
|
||||
IsDel int64 `db:"is_del"` // 是否删除 1删除
|
||||
CreatedAt int64 `db:"created_at"` // 添加时间
|
||||
UpdatedAt int64 `db:"updated_at"` // 更新时间
|
||||
IsOrderStatusEmail int64 `db:"is_order_status_email"` // 订单状态改变时是否接收邮件
|
||||
IsEmailAdvertisement int64 `db:"is_email_advertisement"` // 是否接收邮件广告
|
||||
IsOrderStatusPhone int64 `db:"is_order_status_phone"` // 订单状态改变是是否接收电话
|
||||
IsPhoneAdvertisement int64 `db:"is_phone_advertisement"` // 是否接收短信广告
|
||||
IsOpenRender int64 `db:"is_open_render"` // 是否打开个性化渲染(1:开启,0:关闭)
|
||||
IsThousandFace int64 `db:"is_thousand_face"` // 是否已经存在千人千面(1:存在,0:不存在)
|
||||
IsLowRendering int64 `db:"is_low_rendering"` // 是否开启低渲染模型渲染
|
||||
IsRemoveBg int64 `db:"is_remove_bg"` // 用户上传logo是否去除背景
|
||||
Type int64 `db:"type"` // 1普通餐厅 2连锁餐厅
|
||||
IsOrderStatusEmail bool `db:"is_order_status_email"` // 订单状态改变时是否接收邮件
|
||||
IsEmailAdvertisement bool `db:"is_email_advertisement"` // 是否接收邮件广告
|
||||
IsOrderStatusPhone bool `db:"is_order_status_phone"` // 订单状态改变是是否接收电话
|
||||
IsPhoneAdvertisement bool `db:"is_phone_advertisement"` // 是否接收短信广告
|
||||
IsOpenRender bool `db:"is_open_render"` // 是否打开个性化渲染(1:开启,0:关闭)
|
||||
IsThousandFace bool `db:"is_thousand_face"` // 是否已经存在千人千面(1:存在,0:不存在)
|
||||
IsLowRendering bool `db:"is_low_rendering"` // 是否开启低渲染模型渲染
|
||||
IsRemoveBg bool `db:"is_remove_bg"` // 用户上传logo是否去除背景
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// /user/get-type reponse.data 结构
|
||||
type DataGetType {
|
||||
Id int64 `db:"id" json:"key"` // ID
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
@ -40,14 +38,28 @@ func (info *UserInfo) GetIdType() IDTYPE {
|
|||
return IDTYPE_Onlooker
|
||||
}
|
||||
|
||||
// 获取登录信息
|
||||
func GetUserInfoFormCtx(ctx context.Context) UserInfo {
|
||||
uid, err := ctx.Value("user_id").(json.Number).Int64()
|
||||
if err != nil {
|
||||
logx.Error("parse uid form context err:", err.Error())
|
||||
return UserInfo{}
|
||||
// IsUser 用户是不是登录用户
|
||||
func (info *UserInfo) IsUser() bool {
|
||||
return info.UserId != 0
|
||||
}
|
||||
|
||||
// IsGuest 用户是不是游客
|
||||
func (info *UserInfo) IsGuest() bool {
|
||||
// 必须判断登录用户在前, 用户可能会携带以前是游客到注册的身份
|
||||
if info.UserId != 0 {
|
||||
return false
|
||||
}
|
||||
return UserInfo{UserId: uid}
|
||||
|
||||
if info.GuestId != 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// IsOnlooker 白板用户: 非登录用户, 非游客, 判断为白板用户
|
||||
func (info *UserInfo) IsOnlooker() bool {
|
||||
return info.UserId != 0 && info.GuestId != 0
|
||||
}
|
||||
|
||||
// 获取登录信息
|
||||
|
|
|
@ -13,9 +13,16 @@ var (
|
|||
CodeServiceErr = &StatusResponse{510, "server logic error"} // server logic 错误
|
||||
CodeUnAuth = &StatusResponse{401, "unauthorized"} // 未授权
|
||||
|
||||
CodeUpdateErr = &StatusResponse{5000, "update database error"} // update database logic 错误
|
||||
CodeDupGuestErr = &StatusResponse{5001, "the user is already a guest user and does not need to apply again"} // 用户已经是guest用户不需要重复申请 错误
|
||||
CodeRequestParamsErr = &StatusResponse{5002, "invalid request param"} // api参数校验 错误
|
||||
CodeUpdateErr = &StatusResponse{5000, "update database error"} // update database logic 错误
|
||||
CodeRequestParamsErr = &StatusResponse{5002, "invalid request param"} // api参数校验 错误
|
||||
|
||||
CodeEmailNotFoundErr = &StatusResponse{5050, "the email was not found"} // email 不存在
|
||||
CodeUserIdNotFoundErr = &StatusResponse{5051, "the user was not found"} // email 不存在
|
||||
CodePasswordErr = &StatusResponse{5052, "invalid password"} // 密码错误
|
||||
|
||||
CodeGuestDupErr = &StatusResponse{5010, "the user is already a guest user and does not need to apply again"} // 用户已经是guest用户不需要重复申请 错误
|
||||
CodeGuestGenErr = &StatusResponse{5011, "serialization failed for guest_id of the visitor"} // 游客guest_id序列化失败
|
||||
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
|
|
Loading…
Reference in New Issue
Block a user