This commit is contained in:
laodaming 2023-06-12 14:05:35 +08:00
parent 7d21c9ebc8
commit 53a3490837
24 changed files with 564 additions and 27 deletions

8
go.mod
View File

@ -8,9 +8,14 @@ require (
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/zeromicro/go-zero v1.5.2
golang.org/x/image v0.0.0-20190802002840-cff245a6509b
gorm.io/driver/mysql v1.5.1
gorm.io/gorm v1.25.1
)
require github.com/474420502/requests v1.22.0 // indirect
require (
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
)
require (
github.com/beorn7/perks v1.0.1 // indirect
@ -24,7 +29,6 @@ require (
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd // indirect
github.com/google/uuid v1.3.0 // indirect

16
go.sum
View File

@ -31,8 +31,6 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/474420502/requests v1.22.0 h1:dRQczuYg3K3GlaQgm8SZQLmpiKc+jlOKzN0LkAKXUAo=
github.com/474420502/requests v1.22.0/go.mod h1:043PKfW//QR069XTYG5WT7t+z+d+8/C5PJtfWzpsf+o=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
@ -107,8 +105,6 @@ github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt
github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@ -165,6 +161,10 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
@ -223,7 +223,6 @@ github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/gopher-lua v1.1.0 h1:BojcDhfyDWgU2f2TOzYK/g5p2gxMrku8oupLDqlnSqE=
github.com/zeromicro/go-zero v1.5.2 h1:vpMlZacCMtgdtYzKI3OMyhS6mZ9UQctiAh0J7gIq31I=
github.com/zeromicro/go-zero v1.5.2/go.mod h1:ndCd1nMMAdEMZgPfdm1fpavHUdBW0ykB6ckCRaSG10w=
@ -292,7 +291,6 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@ -336,7 +334,6 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@ -421,7 +418,6 @@ golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roY
golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@ -527,6 +523,10 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.5.1 h1:WUEH5VF9obL/lTtzjmML/5e6VfFR/788coz2uaVCAZw=
gorm.io/driver/mysql v1.5.1/go.mod h1:Jo3Xu7mMhCyj8dlrb3WoCaRd1FhsVh+yMXb1jUInf5o=
gorm.io/gorm v1.25.1 h1:nsSALe5Pr+cM3V1qwwQ7rOkw+6UeLrX5O4v3llhHa64=
gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

View File

@ -2,19 +2,20 @@ package svc
import (
{{.configImport}}
"github.com/zeromicro/go-zero/core/stores/sqlx"
"fusenapi/initalize"
"gorm.io/gorm"
)
type ServiceContext struct {
Config {{.config}}
{{.middleware}}
MysqlConn sqlx.SqlConn
MysqlConn *gorm.DB
}
func NewServiceContext(c {{.config}}) *ServiceContext {
return &ServiceContext{
Config: c,
MysqlConn: sqlx.NewMysql(c.SourceMysql),
MysqlConn: initalize.InitMysql(c.SourceMysql),
{{.middlewareAssignment}}
}
}

44
initalize/mysql.go Normal file
View File

@ -0,0 +1,44 @@
package initalize
import (
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/schema"
"time"
)
// SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
// 初始化mysql
func InitMysql(sourceMysql string) *gorm.DB {
dsn := sourceMysql + "?" + "charset=utf8mb4&parseTime=true"
db, err := gorm.Open(mysql.New(mysql.Config{
DSN: dsn, // DSN data source name
DefaultStringSize: 255, // string 类型字段的默认长度
DisableDatetimePrecision: true, // 禁用 datetime 精度MySQL 5.6 之前的数据库不支持
DontSupportRenameIndex: true, // 重命名索引时采用删除并新建的方式MySQL 5.7 之前的数据库和 MariaDB 不支持重命名索引
DontSupportRenameColumn: true, // 用 `change` 重命名列MySQL 8 之前的数据库和 MariaDB 不支持重命名列
SkipInitializeWithVersion: true, // 根据当前 MySQL 版本自动配置
}), &gorm.Config{
NamingStrategy: schema.NamingStrategy{
TablePrefix: "", // 表名前缀
SingularTable: true, // 使用单数表名
},
SkipDefaultTransaction: true,
})
if err != nil {
panic(err)
}
sqlDB, err := db.DB()
if err != nil {
panic(err)
}
// SetMaxIdleConns 设置空闲连接池中连接的最大数量
sqlDB.SetMaxIdleConns(10)
// SetMaxOpenConns 设置打开数据库连接的最大数量。
sqlDB.SetMaxOpenConns(50)
// SetConnMaxLifetime 设置了连接可复用的最大时间。
sqlDB.SetConnMaxLifetime(time.Minute * 20)
return db
}

18
model/gorm/fsaddressmodel.go Executable file
View File

@ -0,0 +1,18 @@
package gorm
type FsAddress struct {
Id int64 `gorm:"primary_key" json:"id"`
UserId *int64 `gorm:"default:0" json:"user_id"` // 用户ID
Name *string `gorm:"default:''" json:"name"` // 地址名称
FirstName *string `gorm:"default:''" json:"first_name"` // FirstName
LastName *string `gorm:"default:''" json:"last_name"` // LastName
Mobile *string `gorm:"default:''" json:"mobile"` // 手机号码
Street *string `gorm:"default:''" json:"street"` // 街道
Suite *string `gorm:"default:''" json:"suite"` // 房号
City *string `gorm:"default:''" json:"city"` // 城市
State *string `gorm:"default:''" json:"state"` // 州名
Country *string `gorm:"default:''" json:"country"` // 国家
ZipCode *string `gorm:"default:''" json:"zip_code"` // 邮编
Status *int64 `gorm:"default:1" json:"status"` // 1正常 0异常
IsDefault *int64 `gorm:"default:0" json:"is_default"` // 1默认地址0非默认地址
}

View File

@ -0,0 +1,12 @@
package gorm
type FsCanteenProduct struct {
Id int64 `gorm:"primary_key" json:"id"` // ID
CanteenType *int64 `gorm:"default:0" json:"canteen_type"` // 餐厅类别id
ProductId *int64 `gorm:"default:0" json:"product_id"` // 产品id
SizeId *int64 `gorm:"default:0" json:"size_id"` // 尺寸id
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
Status *int64 `gorm:"default:1" json:"status"` // 状态位 1启用0停用
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
Sid *string `gorm:"default:''" json:"sid"` // 前端带入的id
}

View File

@ -0,0 +1,9 @@
package 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"` // 添加时间
}

14
model/gorm/fsfaqmodel.go Executable file
View File

@ -0,0 +1,14 @@
package gorm
import "database/sql"
type FsFaq struct {
Id int64 `gorm:"primary_key" json:"id"`
TagId *int64 `gorm:"default:0" json:"tag_id"` // 分类ID
TagName *string `gorm:"default:''" json:"tag_name"` // 分类名称
Title *string `gorm:"default:''" json:"title"` // 标题
Content *string `gorm:"default:''" json:"content"` // 内容
Status *int64 `gorm:"default:1" json:"status"` // 状态(0:禁用1:启用)
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
Ctime *sql.NullInt64 `gorm:"default:0" json:"ctime"` // 添加时间
}

9
model/gorm/fsfontmodel.go Executable file
View File

@ -0,0 +1,9 @@
package 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"` // 排序
}

33
model/gorm/fsproductmodel.go Executable file
View File

@ -0,0 +1,33 @@
package gorm
type FsProduct struct {
Id int64 `gorm:"primary_key" json:"id"`
Sn *string `gorm:"default:''" json:"sn"` // 商品编号 P98f087j
Type *int64 `gorm:"default:0" json:"type"` // 分类ID
Title *string `gorm:"default:''" json:"title"` // 名称
TitleCn *string `gorm:"default:''" json:"title_cn"` // 中文名称
Cover *string `gorm:"default:''" json:"cover"` // 封面图
Imgs *string `gorm:"default:''" json:"imgs"` // 一个或多个介绍图或视频
Keywords *string `gorm:"default:''" json:"keywords"` // 关键字
Intro *string `gorm:"default:''" json:"intro"` // 简要描述
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
SelledNum *int64 `gorm:"default:0" json:"selled_num"` // 已卖数量
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
View *int64 `gorm:"default:0" json:"view"` // 浏览量
SizeIds *string `gorm:"default:''" json:"size_ids"` // 尺寸 1,2,3,4
MaterialIds *string `gorm:"default:''" json:"material_ids"` // 材质 1,2,3
TagIds *string `gorm:"default:''" json:"tag_ids"` // 标签 逗号间隔
Status *int64 `gorm:"default:1" json:"status"` // 状态位 弃用
ProduceDays *int64 `gorm:"default:0" json:"produce_days"` // 生产天数
DeliveryDays *int64 `gorm:"default:0" json:"delivery_days"` // 运送天数
CoverImg *string `gorm:"default:''" json:"cover_img"` // 背景图
IsShelf *int64 `gorm:"default:1" json:"is_shelf"` // 是否上架
IsRecommend *int64 `gorm:"default:1" json:"is_recommend"` // 是否推荐
IsHot *int64 `gorm:"default:1" json:"is_hot"` // 是否热销
IsProtection *int64 `gorm:"default:1" json:"is_protection"` // 是否环保
IsMicrowave *int64 `gorm:"default:1" json:"is_microwave"` // 是否可微波炉
IsDel *int64 `gorm:"default:0" json:"is_del"` // 是否删除
RecommendProduct *string `gorm:"default:''" json:"recommend_product"` // 推荐产品id例如: 1,3,4,5
RecommendProductSort *string `gorm:"default:''" json:"recommend_product_sort"` // 推荐排序例如:1324
SceneIds *string `gorm:"default:''" json:"scene_ids"` // 关联的场景id
}

View File

@ -0,0 +1,9 @@
package gorm
type FsProductModel3dLight struct {
Id int64 `gorm:"primary_key" json:"id"`
Name *string `gorm:"default:''" json:"name"` // 灯光名称
Info *string `gorm:"default:''" json:"info"` // 灯光数据json格式
Status *int64 `gorm:"default:1" json:"status"` // 状态值1显示0删除
Ctime *int64 `gorm:"default:0" json:"ctime"` // 创建时间
}

View File

@ -0,0 +1,22 @@
package gorm
type FsProductModel3d struct {
Id int64 `gorm:"primary_key" json:"id"`
ProductId *int64 `gorm:"default:0" json:"product_id"` // 产品ID
Tag *int64 `gorm:"default:1" json:"tag"` // 类别1模型2配件3场景
Title *string `gorm:"default:''" json:"title"` // 标题
Name *string `gorm:"default:''" json:"name"` // 详情页展示名称
ModelInfo *string `gorm:"default:''" json:"model_info"` // 模型详情
MaterialId *int64 `gorm:"default:0" json:"material_id"` // 材质ID
SizeId *int64 `gorm:"default:0" json:"size_id"` // 尺寸ID
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
Light *int64 `gorm:"default:0" json:"light"` // 灯光组
LightList *string `gorm:"default:''" json:"light_list"` // 灯光备选项
PartId *int64 `gorm:"default:0" json:"part_id"` // 配件选项id配件就是模型的id
PartList *string `gorm:"default:''" json:"part_list"` // 配件备选项
Status *int64 `gorm:"default:1" json:"status"` // 状态位 1显示 0删除
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
OptionTemplate *int64 `gorm:"default:0" json:"option_template"` // 配件绑定的公共模板
Price *int64 `gorm:"default:0" json:"price"` // 仅配件用,配件的价格, 单位:美分
Sku *string `gorm:"default:''" json:"sku"` // sku
}

View File

@ -0,0 +1,17 @@
package gorm
type FsProductPrice struct {
Id int64 `gorm:"primary_key" json:"id"`
Sn string `gorm:"default:''" json:"sn"` // 唯一编码
Title string `gorm:"default:''" json:"title"` // 标题描述
ProductId int64 `gorm:"default:0" json:"product_id"` // 产品ID
MaterialId int64 `gorm:"default:0" json:"material_id"` // 材质ID
SizeId int64 `gorm:"default:0" json:"size_id"` // 尺寸ID
EachBoxNum int64 `gorm:"default:0" json:"each_box_num"` // 每一箱的个数
EachBoxWeight float64 `gorm:"default:0" json:"each_box_weight"` // 每一箱的重量 单位KG
MinBuyNum int64 `gorm:"default:0" json:"min_buy_num"` // 最少购买量
StepNum string `gorm:"default:''" json:"step_num"` // 数量阶梯 eg:10,20,30
StepPrice string `gorm:"default:''" json:"step_price"` // 价格阶梯 eg:100,50,25
Status int64 `gorm:"default:1" json:"status"` // 是否可用
IsDefault int64 `gorm:"default:0" json:"is_default"` // 是否默认
}

View File

@ -0,0 +1,69 @@
package model
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"strings"
)
var _ FsProductSizeModel = (*customFsProductSizeModel)(nil)
type (
// FsProductSizeModel is an interface to be customized, add more methods here,
// and implement the added methods in customFsProductSizeModel.
FsProductSizeModel interface {
fsProductSizeModel
CountByStatus(ctx context.Context, status int) (total int, err error)
GetAllByProductIds(ctx context.Context, productIds []string, sort string) (resp []FsProductSize, err error)
GetAllByIds(ctx context.Context, ids []string, sort string) (resp []FsProductSize, err error)
}
customFsProductSizeModel struct {
*defaultFsProductSizeModel
}
)
// NewFsProductSizeModel returns a model for the database table.
func NewFsProductSizeModel(conn sqlx.SqlConn) FsProductSizeModel {
return &customFsProductSizeModel{
defaultFsProductSizeModel: newFsProductSizeModel(conn),
}
}
func (m *defaultFsProductSizeModel) CountByStatus(ctx context.Context, status int) (total int, err error) {
query := fmt.Sprintf("select %s from %s where `status` = ? limit 1", "count(*) as num", m.table)
err = m.conn.QueryRowCtx(ctx, &total, query, status)
if err != nil {
return 0, err
}
return
}
func (m *defaultFsProductSizeModel) GetAllByProductIds(ctx context.Context, productIds []string, sort string) (resp []FsProductSize, err error) {
query := fmt.Sprintf("select %s from %s where `product_id` in(?) and `status` = ? ", fsProductSizeRows, m.table)
switch sort {
case "sort-asc":
query = fmt.Sprintf("%s order by `sort` ASC", query)
case "sort-desc":
query = fmt.Sprintf("%s order by `sort` DESC", query)
}
err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(productIds, ","), 1)
if err != nil {
return nil, err
}
return
}
func (m *defaultFsProductSizeModel) GetAllByIds(ctx context.Context, ids []string, sort string) (resp []FsProductSize, err error) {
query := fmt.Sprintf("select %s from %s where `id` in (?) and `status` = ? ", fsProductSizeRows, m.table)
switch sort {
case "sort-asc":
query = fmt.Sprintf("%s order by `sort` ASC", query)
case "sort-desc":
query = fmt.Sprintf("%s order by `sort` DESC", query)
}
err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(ids, ","), 1)
if err != nil {
return nil, err
}
return
}

View File

@ -0,0 +1,40 @@
package model
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ FsProductTemplateTagsModel = (*customFsProductTemplateTagsModel)(nil)
type (
// FsProductTemplateTagsModel is an interface to be customized, add more methods here,
// and implement the added methods in customFsProductTemplateTagsModel.
FsProductTemplateTagsModel interface {
fsProductTemplateTagsModel
ListByIds(ctx context.Context, ids []string) (resp []FsProductTemplateTags, err error)
}
customFsProductTemplateTagsModel struct {
*defaultFsProductTemplateTagsModel
}
)
// NewFsProductTemplateTagsModel returns a model for the database table.
func NewFsProductTemplateTagsModel(conn sqlx.SqlConn) FsProductTemplateTagsModel {
return &customFsProductTemplateTagsModel{
defaultFsProductTemplateTagsModel: newFsProductTemplateTagsModel(conn),
}
}
func (m *defaultFsProductTemplateTagsModel) ListByIds(ctx context.Context, ids []string) (resp []FsProductTemplateTags, err error) {
if len(ids) == 0 {
return nil, nil
}
query := fmt.Sprintf("select %s from %s where `id` in (?) ", fsProductTemplateTagsRows, m.table)
err = m.conn.QueryRowsCtx(ctx, &resp, query, ids)
if err != nil {
return nil, err
}
return
}

View File

@ -0,0 +1,72 @@
package model
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"strings"
)
var _ FsProductTemplateV2Model = (*customFsProductTemplateV2Model)(nil)
type (
// FsProductTemplateV2Model is an interface to be customized, add more methods here,
// and implement the added methods in customFsProductTemplateV2Model.
FsProductTemplateV2Model interface {
fsProductTemplateV2Model
FindAllByCondition(ctx context.Context, productIds []string) (resp []FsProductTemplateV2, err error)
FindAllByModelIdsProduct(ctx context.Context, modelIds []string, productId int64, sort int) (resp []FsProductTemplateV2, err error)
FindAllByModelIds(ctx context.Context, modelIds []string, sort int) (resp []FsProductTemplateV2, err error)
}
customFsProductTemplateV2Model struct {
*defaultFsProductTemplateV2Model
}
)
// NewFsProductTemplateV2Model returns a model for the database table.
func NewFsProductTemplateV2Model(conn sqlx.SqlConn) FsProductTemplateV2Model {
return &customFsProductTemplateV2Model{
defaultFsProductTemplateV2Model: newFsProductTemplateV2Model(conn),
}
}
func (m *defaultFsProductTemplateV2Model) FindAllByCondition(ctx context.Context, productIds []string) (resp []FsProductTemplateV2, err error) {
query := fmt.Sprintf("select %s from %s where `id` in (?) and `is_del` = ? and `status` = ?", fsProductTemplateV2Rows, m.table)
if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(productIds, ","), 0, 1); err != nil {
return nil, err
}
return
}
func (m *defaultFsProductTemplateV2Model) FindAllByModelIdsProduct(ctx context.Context, modelIds []string, productId int64, sort int) (resp []FsProductTemplateV2, err error) {
if len(modelIds) == 0 {
return
}
query := fmt.Sprintf("select %s from %s where `model_id` in (?) and `product_id` = ? and `is_del` = ? and `status` = ?", fsProductTemplateV2Rows, m.table)
switch sort {
case 1:
query = fmt.Sprintf("%s order by `sort` ASC", query)
case 2:
query = fmt.Sprintf("%s order by `sort` DESC", query)
}
if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(modelIds, ","), productId, 0, 1); err != nil {
return nil, err
}
return
}
func (m *defaultFsProductTemplateV2Model) FindAllByModelIds(ctx context.Context, modelIds []string, sort int) (resp []FsProductTemplateV2, err error) {
if len(modelIds) == 0 {
return
}
query := fmt.Sprintf("select %s from %s where `model_id` in (?) and `is_del` = ? and `status` = ?", fsProductTemplateV2Rows, m.table)
switch sort {
case 1:
query = fmt.Sprintf("%s order by `sort` ASC", query)
case 2:
query = fmt.Sprintf("%s order by `sort` DESC", query)
}
if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(modelIds, ","), 0, 1); err != nil {
return nil, err
}
return
}

38
model/gorm/fsqrcodesetmodel.go Executable file
View File

@ -0,0 +1,38 @@
package model
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ FsQrcodeSetModel = (*customFsQrcodeSetModel)(nil)
type (
// FsQrcodeSetModel is an interface to be customized, add more methods here,
// and implement the added methods in customFsQrcodeSetModel.
FsQrcodeSetModel interface {
fsQrcodeSetModel
GetAll(ctx context.Context) (resp []FsQrcodeSet, err error)
}
customFsQrcodeSetModel struct {
*defaultFsQrcodeSetModel
}
)
// NewFsQrcodeSetModel returns a model for the database table.
func NewFsQrcodeSetModel(conn sqlx.SqlConn) FsQrcodeSetModel {
return &customFsQrcodeSetModel{
defaultFsQrcodeSetModel: newFsQrcodeSetModel(conn),
}
}
func (m *defaultFsQrcodeSetModel) GetAll(ctx context.Context) (resp []FsQrcodeSet, err error) {
query := fmt.Sprintf("select %s from %s where `status` = ?", fsQrcodeSetRows, m.table)
err = m.conn.QueryRowsCtx(ctx, &resp, query, 1)
if err != nil {
return nil, err
}
return
}

View File

@ -0,0 +1,38 @@
package model
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ FsStandardLogoModel = (*customFsStandardLogoModel)(nil)
type (
// FsStandardLogoModel is an interface to be customized, add more methods here,
// and implement the added methods in customFsStandardLogoModel.
FsStandardLogoModel interface {
fsStandardLogoModel
GetAll(ctx context.Context) (resp []FsStandardLogo, err error)
}
customFsStandardLogoModel struct {
*defaultFsStandardLogoModel
}
)
// NewFsStandardLogoModel returns a model for the database table.
func NewFsStandardLogoModel(conn sqlx.SqlConn) FsStandardLogoModel {
return &customFsStandardLogoModel{
defaultFsStandardLogoModel: newFsStandardLogoModel(conn),
}
}
func (m *defaultFsStandardLogoModel) GetAll(ctx context.Context) (resp []FsStandardLogo, err error) {
query := fmt.Sprintf("select %s from %s where `status` = ? ", fsStandardLogoRows, m.table)
err = m.conn.QueryRowsCtx(ctx, &resp, query, 1)
if err != nil {
return nil, err
}
return
}

48
model/gorm/fstagsmodel.go Executable file
View File

@ -0,0 +1,48 @@
package model
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"strings"
)
var _ FsTagsModel = (*customFsTagsModel)(nil)
type (
// FsTagsModel is an interface to be customized, add more methods here,
// and implement the added methods in customFsTagsModel.
FsTagsModel interface {
fsTagsModel
GetAllByLevel(ctx context.Context, level int) (resp []FsTags, err error)
GetAllByIds(ctx context.Context, ids []string) (resp []FsTags, err error)
}
customFsTagsModel struct {
*defaultFsTagsModel
}
)
// NewFsTagsModel returns a model for the database table.
func NewFsTagsModel(conn sqlx.SqlConn) FsTagsModel {
return &customFsTagsModel{
defaultFsTagsModel: newFsTagsModel(conn),
}
}
func (m *defaultFsTagsModel) GetAllByLevel(ctx context.Context, level int) (resp []FsTags, err error) {
query := fmt.Sprintf("select %s from %s where `level` = ? and `status` = ?", fsTagsRows, m.table)
err = m.conn.QueryRowsCtx(ctx, &resp, query, level, 1)
if err != nil {
return nil, err
}
return
}
func (m *defaultFsTagsModel) GetAllByIds(ctx context.Context, ids []string) (resp []FsTags, err error) {
query := fmt.Sprintf("select %s from %s where `id` in (?) and `status` = ?", fsTagsRows, m.table)
err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(ids, ","), 1)
if err != nil {
return nil, err
}
return
}

36
model/gorm/fsusermodel.go Executable file
View File

@ -0,0 +1,36 @@
package model
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ FsUserModel = (*customFsUserModel)(nil)
type (
// FsUserModel is an interface to be customized, add more methods here,
// and implement the added methods in customFsUserModel.
FsUserModel interface {
fsUserModel
UpdateVerificationToken(ctx context.Context, userid int64, token string) error
}
customFsUserModel struct {
*defaultFsUserModel
}
)
// NewFsUserModel returns a model for the database table.
func NewFsUserModel(conn sqlx.SqlConn) FsUserModel {
return &customFsUserModel{
defaultFsUserModel: newFsUserModel(conn),
}
}
func (m *defaultFsUserModel) UpdateVerificationToken(ctx context.Context, userid int64, verificationToken string) error {
query := fmt.Sprintf("update %s set `verification_token` = ? where `id` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, query, verificationToken, userid)
return err
}

View File

@ -23,6 +23,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Handler: SaveCanteenTypeProductHandler(serverCtx),
},
},
//rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
)
}

View File

@ -1,19 +1,20 @@
package svc
import (
"fusenapi/initalize"
"fusenapi/server/canteen/internal/config"
"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),
}
}

View File

@ -1,19 +1,20 @@
package svc
import (
config2 "fusenapi/server/data-transfer/internal/config"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"fusenapi/initalize"
"fusenapi/server/data-transfer/internal/config"
"gorm.io/gorm"
)
type ServiceContext struct {
Config config2.Config
Config config.Config
MysqlConn sqlx.SqlConn
MysqlConn *gorm.DB
}
func NewServiceContext(c config2.Config) *ServiceContext {
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
MysqlConn: sqlx.NewMysql(c.SourceMysql),
MysqlConn: initalize.InitMysql(c.SourceMysql),
}
}

View File

@ -1,18 +1,20 @@
package svc
import (
"fusenapi/initalize"
"fusenapi/server/product/internal/config"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"gorm.io/gorm"
)
type ServiceContext struct {
Config config.Config
MysqlConn sqlx.SqlConn
Config config.Config
MysqlConn *gorm.DB
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
MysqlConn: sqlx.NewMysql(c.DataSource),
MysqlConn: initalize.InitMysql(c.SourceMysql),
}
}