From 52df088b8c2de8f81589d6ea78a6fe5bd0217438 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 12 Jun 2023 10:15:40 +0800 Subject: [PATCH 1/5] fix --- .../data-transfer/internal/handler/routes.go | 5 +++ .../internal/handler/uploadlogohandler.go | 37 +++++++++++++++++++ .../internal/logic/uploadlogologic.go | 30 +++++++++++++++ server/data-transfer/internal/types/types.go | 13 +++++++ server_api/data-transfer.api | 16 ++++++++ 5 files changed, 101 insertions(+) create mode 100644 server/data-transfer/internal/handler/uploadlogohandler.go create mode 100644 server/data-transfer/internal/logic/uploadlogologic.go diff --git a/server/data-transfer/internal/handler/routes.go b/server/data-transfer/internal/handler/routes.go index d47e16b2..80e849b9 100644 --- a/server/data-transfer/internal/handler/routes.go +++ b/server/data-transfer/internal/handler/routes.go @@ -27,6 +27,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/upload/qrcode", Handler: UploadQrcodeHandler(serverCtx), }, + { + Method: http.MethodPost, + Path: "/upload/up-logo", + Handler: UploadLogoHandler(serverCtx), + }, }, rest.WithJwt(serverCtx.Config.Auth.AccessSecret), ) diff --git a/server/data-transfer/internal/handler/uploadlogohandler.go b/server/data-transfer/internal/handler/uploadlogohandler.go new file mode 100644 index 00000000..4bde73ae --- /dev/null +++ b/server/data-transfer/internal/handler/uploadlogohandler.go @@ -0,0 +1,37 @@ +package handler + +import ( + "errors" + "net/http" + + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/rest/httpx" + + "fusenapi/server/data-transfer/internal/logic" + "fusenapi/server/data-transfer/internal/svc" + "fusenapi/server/data-transfer/internal/types" +) + +func UploadLogoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.UploadLogoReq + if err := httpx.Parse(r, &req); err != nil { + httpx.OkJsonCtx(r.Context(), w, &types.Response{ + Code: 510, + Message: "parameter error", + }) + logx.Info(err) + return + } + + l := logic.NewUploadLogoLogic(r.Context(), svcCtx) + resp := l.UploadLogo(&req) + if resp != nil { + httpx.OkJsonCtx(r.Context(), w, resp) + } else { + err := errors.New("server logic is error, resp must not be nil") + httpx.ErrorCtx(r.Context(), w, err) + logx.Error(err) + } + } +} diff --git a/server/data-transfer/internal/logic/uploadlogologic.go b/server/data-transfer/internal/logic/uploadlogologic.go new file mode 100644 index 00000000..7f9c26c3 --- /dev/null +++ b/server/data-transfer/internal/logic/uploadlogologic.go @@ -0,0 +1,30 @@ +package logic + +import ( + "context" + + "fusenapi/server/data-transfer/internal/svc" + "fusenapi/server/data-transfer/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type UploadLogoLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewUploadLogoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogoLogic { + return &UploadLogoLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq) (resp *types.Response) { + // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + + return resp.SetStatus(basic.CodeOK) +} diff --git a/server/data-transfer/internal/types/types.go b/server/data-transfer/internal/types/types.go index e176e1da..043ee41e 100644 --- a/server/data-transfer/internal/types/types.go +++ b/server/data-transfer/internal/types/types.go @@ -26,6 +26,19 @@ type UploadQrcodeRsp struct { Data string `json:"d"` } +type UploadLogoReq struct { + SkuId int64 `json:"skuId"` + IsRemoveBg bool `json:"is_remove_bg"` + Proportion int64 `json:"proportion"` +} + +type UploadLogoRsp struct { + NobgUrl string `json:"nobg_url"` + ThumbnailUrl string `json:"thumbnail_url"` + IsmaxProportion bool `json:"ismax_proportion"` + ImgColor []string `json:"img_color"` +} + type Response struct { Code int `json:"code"` Message string `json:"msg"` diff --git a/server_api/data-transfer.api b/server_api/data-transfer.api index 443759c3..893859e3 100644 --- a/server_api/data-transfer.api +++ b/server_api/data-transfer.api @@ -22,6 +22,9 @@ service data-transfer { //生成二维码 @handler UploadQrcodeHandler post /upload/qrcode (UploadQrcodeReq) returns (response); + //上传logo + @handler UploadLogoHandler + post /upload/up-logo (UploadLogoReq) returns (response); } //获取标准logo列表 @@ -43,4 +46,17 @@ type UploadQrcodeReq { type UploadQrcodeRsp { Link string `json:"link"` Data string `json:"d"` +} + +//上传logo +type UploadLogoReq { + SkuId int64 `json:"skuId"` + IsRemoveBg bool `json:"is_remove_bg"` + Proportion int64 `json:"proportion"` +} +type UploadLogoRsp { + NobgUrl string `json:"nobg_url"` + ThumbnailUrl string `json:"thumbnail_url"` + IsmaxProportion bool `json:"ismax_proportion"` + ImgColor []string `json:"img_color"` } \ No newline at end of file From 6919d7c02f52ac19066a652ff013f1dac149d4b5 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 12 Jun 2023 10:16:49 +0800 Subject: [PATCH 2/5] fix --- server/data-transfer/internal/logic/uploadlogologic.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/data-transfer/internal/logic/uploadlogologic.go b/server/data-transfer/internal/logic/uploadlogologic.go index 7f9c26c3..503e1eb6 100644 --- a/server/data-transfer/internal/logic/uploadlogologic.go +++ b/server/data-transfer/internal/logic/uploadlogologic.go @@ -2,6 +2,7 @@ package logic import ( "context" + "fusenapi/utils/basic" "fusenapi/server/data-transfer/internal/svc" "fusenapi/server/data-transfer/internal/types" From 7d21c9ebc8214fb3c711a081e3ca064af64f6f6b Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 12 Jun 2023 11:15:58 +0800 Subject: [PATCH 3/5] fix --- utils/placeholder/placeholder.go | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 utils/placeholder/placeholder.go diff --git a/utils/placeholder/placeholder.go b/utils/placeholder/placeholder.go deleted file mode 100644 index 4d62947f..00000000 --- a/utils/placeholder/placeholder.go +++ /dev/null @@ -1,12 +0,0 @@ -package sql_placeholder - -import "strings" - -// 获取对应长度占位符号 -func GetSqlPlaceholder(l uint) string { - s := make([]string, 0, int(l)) - for i := 0; i < int(l); i++ { - s = append(s, "?") - } - return strings.Join(s, ",") -} From 53a34908373d587941d9108cf421a14874128bf9 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 12 Jun 2023 14:05:35 +0800 Subject: [PATCH 4/5] fix --- go.mod | 8 ++- go.sum | 16 ++--- goctl_template/api/context.tpl | 7 +- initalize/mysql.go | 44 ++++++++++++ model/gorm/fsaddressmodel.go | 18 +++++ model/gorm/fscanteenproductmodel.go | 12 ++++ model/gorm/fscanteentypemodel.go | 9 +++ model/gorm/fsfaqmodel.go | 14 ++++ model/gorm/fsfontmodel.go | 9 +++ model/gorm/fsproductmodel.go | 33 +++++++++ model/gorm/fsproductmodel3dlightmodel.go | 9 +++ model/gorm/fsproductmodel3dmodel.go | 22 ++++++ model/gorm/fsproductpricemodel.go | 17 +++++ model/gorm/fsproductsizemodel.go | 69 ++++++++++++++++++ model/gorm/fsproducttemplatetagsmodel.go | 40 +++++++++++ model/gorm/fsproducttemplatev2model.go | 72 +++++++++++++++++++ model/gorm/fsqrcodesetmodel.go | 38 ++++++++++ model/gorm/fsstandardlogomodel.go | 38 ++++++++++ model/gorm/fstagsmodel.go | 48 +++++++++++++ model/gorm/fsusermodel.go | 36 ++++++++++ server/canteen/internal/handler/routes.go | 2 +- server/canteen/internal/svc/servicecontext.go | 7 +- .../internal/svc/servicecontext.go | 13 ++-- server/product/internal/svc/servicecontext.go | 10 +-- 24 files changed, 564 insertions(+), 27 deletions(-) create mode 100644 initalize/mysql.go create mode 100755 model/gorm/fsaddressmodel.go create mode 100755 model/gorm/fscanteenproductmodel.go create mode 100755 model/gorm/fscanteentypemodel.go create mode 100755 model/gorm/fsfaqmodel.go create mode 100755 model/gorm/fsfontmodel.go create mode 100755 model/gorm/fsproductmodel.go create mode 100755 model/gorm/fsproductmodel3dlightmodel.go create mode 100755 model/gorm/fsproductmodel3dmodel.go create mode 100755 model/gorm/fsproductpricemodel.go create mode 100755 model/gorm/fsproductsizemodel.go create mode 100755 model/gorm/fsproducttemplatetagsmodel.go create mode 100755 model/gorm/fsproducttemplatev2model.go create mode 100755 model/gorm/fsqrcodesetmodel.go create mode 100755 model/gorm/fsstandardlogomodel.go create mode 100755 model/gorm/fstagsmodel.go create mode 100755 model/gorm/fsusermodel.go diff --git a/go.mod b/go.mod index b54b45c3..3a42f1b7 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index a14fea8b..41e8e6b0 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/goctl_template/api/context.tpl b/goctl_template/api/context.tpl index 99773904..06a86199 100644 --- a/goctl_template/api/context.tpl +++ b/goctl_template/api/context.tpl @@ -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}} } } diff --git a/initalize/mysql.go b/initalize/mysql.go new file mode 100644 index 00000000..03eb2ccb --- /dev/null +++ b/initalize/mysql.go @@ -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 +} diff --git a/model/gorm/fsaddressmodel.go b/model/gorm/fsaddressmodel.go new file mode 100755 index 00000000..f6170030 --- /dev/null +++ b/model/gorm/fsaddressmodel.go @@ -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非默认地址 +} diff --git a/model/gorm/fscanteenproductmodel.go b/model/gorm/fscanteenproductmodel.go new file mode 100755 index 00000000..277b253e --- /dev/null +++ b/model/gorm/fscanteenproductmodel.go @@ -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 +} diff --git a/model/gorm/fscanteentypemodel.go b/model/gorm/fscanteentypemodel.go new file mode 100755 index 00000000..91d54fdb --- /dev/null +++ b/model/gorm/fscanteentypemodel.go @@ -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"` // 添加时间 +} diff --git a/model/gorm/fsfaqmodel.go b/model/gorm/fsfaqmodel.go new file mode 100755 index 00000000..e9baa0ab --- /dev/null +++ b/model/gorm/fsfaqmodel.go @@ -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"` // 添加时间 +} diff --git a/model/gorm/fsfontmodel.go b/model/gorm/fsfontmodel.go new file mode 100755 index 00000000..d5431cdb --- /dev/null +++ b/model/gorm/fsfontmodel.go @@ -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"` // 排序 +} diff --git a/model/gorm/fsproductmodel.go b/model/gorm/fsproductmodel.go new file mode 100755 index 00000000..2f2aa2fb --- /dev/null +++ b/model/gorm/fsproductmodel.go @@ -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 +} diff --git a/model/gorm/fsproductmodel3dlightmodel.go b/model/gorm/fsproductmodel3dlightmodel.go new file mode 100755 index 00000000..c97cfff3 --- /dev/null +++ b/model/gorm/fsproductmodel3dlightmodel.go @@ -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"` // 创建时间 +} diff --git a/model/gorm/fsproductmodel3dmodel.go b/model/gorm/fsproductmodel3dmodel.go new file mode 100755 index 00000000..5be73c90 --- /dev/null +++ b/model/gorm/fsproductmodel3dmodel.go @@ -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 +} diff --git a/model/gorm/fsproductpricemodel.go b/model/gorm/fsproductpricemodel.go new file mode 100755 index 00000000..6abdda92 --- /dev/null +++ b/model/gorm/fsproductpricemodel.go @@ -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"` // 是否默认 +} diff --git a/model/gorm/fsproductsizemodel.go b/model/gorm/fsproductsizemodel.go new file mode 100755 index 00000000..ac45e108 --- /dev/null +++ b/model/gorm/fsproductsizemodel.go @@ -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 +} diff --git a/model/gorm/fsproducttemplatetagsmodel.go b/model/gorm/fsproducttemplatetagsmodel.go new file mode 100755 index 00000000..a9462148 --- /dev/null +++ b/model/gorm/fsproducttemplatetagsmodel.go @@ -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 +} diff --git a/model/gorm/fsproducttemplatev2model.go b/model/gorm/fsproducttemplatev2model.go new file mode 100755 index 00000000..bf4220c8 --- /dev/null +++ b/model/gorm/fsproducttemplatev2model.go @@ -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 +} diff --git a/model/gorm/fsqrcodesetmodel.go b/model/gorm/fsqrcodesetmodel.go new file mode 100755 index 00000000..88567ee7 --- /dev/null +++ b/model/gorm/fsqrcodesetmodel.go @@ -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 +} diff --git a/model/gorm/fsstandardlogomodel.go b/model/gorm/fsstandardlogomodel.go new file mode 100755 index 00000000..6a6c05b8 --- /dev/null +++ b/model/gorm/fsstandardlogomodel.go @@ -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 +} diff --git a/model/gorm/fstagsmodel.go b/model/gorm/fstagsmodel.go new file mode 100755 index 00000000..ab53637c --- /dev/null +++ b/model/gorm/fstagsmodel.go @@ -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 +} diff --git a/model/gorm/fsusermodel.go b/model/gorm/fsusermodel.go new file mode 100755 index 00000000..ad370750 --- /dev/null +++ b/model/gorm/fsusermodel.go @@ -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 +} diff --git a/server/canteen/internal/handler/routes.go b/server/canteen/internal/handler/routes.go index 14302e3b..6e08ffc3 100644 --- a/server/canteen/internal/handler/routes.go +++ b/server/canteen/internal/handler/routes.go @@ -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), ) } diff --git a/server/canteen/internal/svc/servicecontext.go b/server/canteen/internal/svc/servicecontext.go index be0da7ad..d37c2866 100644 --- a/server/canteen/internal/svc/servicecontext.go +++ b/server/canteen/internal/svc/servicecontext.go @@ -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), } } diff --git a/server/data-transfer/internal/svc/servicecontext.go b/server/data-transfer/internal/svc/servicecontext.go index 0ca940d3..7b73cf42 100644 --- a/server/data-transfer/internal/svc/servicecontext.go +++ b/server/data-transfer/internal/svc/servicecontext.go @@ -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), } } diff --git a/server/product/internal/svc/servicecontext.go b/server/product/internal/svc/servicecontext.go index aaf1bc69..59781f54 100644 --- a/server/product/internal/svc/servicecontext.go +++ b/server/product/internal/svc/servicecontext.go @@ -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), } } From 9d7022ec1165a9fb1437eed355072eb9ce9bb084 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 12 Jun 2023 14:35:36 +0800 Subject: [PATCH 5/5] fix --- model/gorm/fsproductpricemodel.go | 26 +++---- model/gorm/fsproductsizemodel.go | 79 ++++----------------- model/gorm/fsproducttemplatetagsmodel.go | 44 ++---------- model/gorm/fsproducttemplatev2model.go | 88 +++++------------------- model/gorm/fsqrcodesetmodel.go | 50 ++++---------- model/gorm/fsstandardlogomodel.go | 43 ++---------- model/gorm/fstagsmodel.go | 59 ++++------------ model/gorm/fsusermodel.go | 62 ++++++++--------- 8 files changed, 111 insertions(+), 340 deletions(-) diff --git a/model/gorm/fsproductpricemodel.go b/model/gorm/fsproductpricemodel.go index 6abdda92..3045d291 100755 --- a/model/gorm/fsproductpricemodel.go +++ b/model/gorm/fsproductpricemodel.go @@ -1,17 +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"` // 是否默认 + 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"` // 是否默认 } diff --git a/model/gorm/fsproductsizemodel.go b/model/gorm/fsproductsizemodel.go index ac45e108..2d25c59c 100755 --- a/model/gorm/fsproductsizemodel.go +++ b/model/gorm/fsproductsizemodel.go @@ -1,69 +1,14 @@ -package model +package gorm -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 +type FsProductSize struct { + Id int64 `gorm:"primary_key" json:"id"` + ProductId *int64 `gorm:"default:0" json:"product_id"` // 产品ID + Title *string `gorm:"default:''" json:"title"` // 标题 10*10*20 + Cover *string `gorm:"default:''" json:"cover"` // 封面图 + CoverImg *string `gorm:"default:''" json:"cover_img"` // 背景图 + Capacity *string `gorm:"default:''" json:"capacity"` // 自己填的尺寸名称 + Status *int64 `gorm:"default:1" json:"status"` // 状态位 1显示 0删除 + Sort *int64 `gorm:"default:50" json:"sort"` // 排序 + Remark *string `gorm:"default:''" json:"remark"` // 备注信息 + PartsCanDeleted *int64 `gorm:"default:1" json:"parts_can_deleted"` // 配件是否可移除 1是0否 } diff --git a/model/gorm/fsproducttemplatetagsmodel.go b/model/gorm/fsproducttemplatetagsmodel.go index a9462148..b3e7a4a5 100755 --- a/model/gorm/fsproducttemplatetagsmodel.go +++ b/model/gorm/fsproducttemplatetagsmodel.go @@ -1,40 +1,8 @@ -package model +package gorm -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 +type FsProductTemplateTags struct { + Id int64 `gorm:"primary_key" json:"id"` // ID + Title *string `gorm:"default:''" json:"title"` // 标题 + Status *int64 `gorm:"default:1" json:"status"` // 状态 1:可用 0不可用 + CreateAt *int64 `gorm:"default:0" json:"create_at"` // 创建时间 } diff --git a/model/gorm/fsproducttemplatev2model.go b/model/gorm/fsproducttemplatev2model.go index bf4220c8..f9718866 100755 --- a/model/gorm/fsproducttemplatev2model.go +++ b/model/gorm/fsproducttemplatev2model.go @@ -1,72 +1,20 @@ -package model +package gorm -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 +type FsProductTemplateV2 struct { + Id int64 `gorm:"primary_key" json:"id"` + ProductId *int64 `gorm:"default:0" json:"product_id"` // 产品ID + ModelId *int64 `gorm:"default:0" json:"model_id"` // 模型ID + Title *string `gorm:"default:''" json:"title"` // 模板(sku),预留字段 + Name *string `gorm:"default:''" json:"name"` // 名称 + CoverImg *string `gorm:"default:''" json:"cover_img"` // 模板背景图 + TemplateInfo *string `gorm:"default:''" json:"template_info"` // 模板详情 + MaterialImg *string `gorm:"default:''" json:"material_img"` // 合成好的贴图 + Sort *int64 `gorm:"default:0" json:"sort"` // 排序 + LogoWidth *int64 `gorm:"default:0" json:"logo_width"` // logo图最大宽度 + LogoHeight *int64 `gorm:"default:0" json:"logo_height"` // logo图最大高度 + IsPublic *int64 `gorm:"default:0" json:"is_public"` // 是否可公用(1:可以,0:不可以) + Status *int64 `gorm:"default:1" json:"status"` // 状态1正常 2异常 + Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间 + Tag *string `gorm:"default:''" json:"tag"` // 标签(用户自填) + IsDel *int64 `gorm:"default:0" json:"is_del"` // 是否删除 1删除 } diff --git a/model/gorm/fsqrcodesetmodel.go b/model/gorm/fsqrcodesetmodel.go index 88567ee7..e831072c 100755 --- a/model/gorm/fsqrcodesetmodel.go +++ b/model/gorm/fsqrcodesetmodel.go @@ -1,38 +1,16 @@ -package model +package gorm -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 +type FsQrcodeSet struct { + Id int64 `gorm:"primary_key" json:"id"` // id + Name *string `gorm:"default:''" json:"name"` // 二维码组件名称 + Size *int64 `gorm:"default:0" json:"size"` // 二维码内容尺寸 + IndexX *int64 `gorm:"default:0" json:"index_x"` // x偏移量 + IndexY *int64 `gorm:"default:0" json:"index_y"` // y偏移量 + SvgWebsite *string `gorm:"default:''" json:"svg_website"` // website d数据 + SvgInstagram *string `gorm:"default:''" json:"svg_instagram"` // svg instagram d数据 + SvgFacebook *string `gorm:"default:''" json:"svg_facebook"` // svg facebook d数据 + Status *int64 `gorm:"default:1" json:"status"` // 状态 1正常 1删除 + AdminId *int64 `gorm:"default:0" json:"admin_id"` // 操作人 + Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间 + Utime *int64 `gorm:"default:0" json:"utime"` // 更新时间 } diff --git a/model/gorm/fsstandardlogomodel.go b/model/gorm/fsstandardlogomodel.go index 6a6c05b8..f19ccec5 100755 --- a/model/gorm/fsstandardlogomodel.go +++ b/model/gorm/fsstandardlogomodel.go @@ -1,38 +1,9 @@ -package model +package gorm -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 +type FsStandardLogo struct { + Id int64 `gorm:"primary_key" json:"id"` // ID + Name *string `gorm:"default:''" json:"name"` // logo名称 + Image *string `gorm:"default:''" json:"image"` // 图片地址 + Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间 + Status *int64 `gorm:"default:1" json:"status"` // 状态 1正常 0删除 } diff --git a/model/gorm/fstagsmodel.go b/model/gorm/fstagsmodel.go index ab53637c..51f45f09 100755 --- a/model/gorm/fstagsmodel.go +++ b/model/gorm/fstagsmodel.go @@ -1,48 +1,15 @@ -package model +package gorm -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 +type FsTags struct { + Id int64 `gorm:"primary_key" json:"id"` // ID + Title *string `gorm:"default:''" json:"title"` // 标题 + Level *int64 `gorm:"default:0" json:"level"` // 层级、分类 1 => 二维码分类 + ClickNum *int64 `gorm:"default:0" json:"click_num"` // 点击次数 + Sort *int64 `gorm:"default:0" json:"sort"` // 排序(从大到小) + CreateAt *int64 `gorm:"default:0" json:"create_at"` // 创建时间 + Icon *string `gorm:"default:''" json:"icon"` // 标签图标 + Status *int64 `gorm:"default:1" json:"status"` // 状态 1:可用 + Description *string `gorm:"default:''" json:"description"` // 介绍 Seo + RecommendProduct *string `gorm:"default:''" json:"recommend_product"` // 推荐产品id例如: 1,3,4,5 + RecommendProductSort *string `gorm:"default:''" json:"recommend_product_sort"` // 推荐排序例如:1324 } diff --git a/model/gorm/fsusermodel.go b/model/gorm/fsusermodel.go index ad370750..e8d2b7fe 100755 --- a/model/gorm/fsusermodel.go +++ b/model/gorm/fsusermodel.go @@ -1,36 +1,30 @@ -package model +package gorm -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 +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是否去除背景 }