修复序列化代码

This commit is contained in:
eson
2023-06-15 16:08:43 +08:00
parent f3be74e78c
commit ab4e5852c1
51 changed files with 538 additions and 369 deletions

View 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} }

View 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
}

View 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} }

View 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
}
}

View 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} }

View 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
}

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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}
}

View File

@@ -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
}

View File

@@ -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
View File

@@ -0,0 +1,5 @@
package gmodel
import "gorm.io/gorm"
var ErrRecordNotFound = gorm.ErrRecordNotFound

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -1,9 +1,8 @@
package model
import (
"time"
"gorm.io/gorm"
"time"
)
type FsCart struct {

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的

View File

@@ -0,0 +1,2 @@
package model
// TODO: 使用model的属性做你想做的