diff --git a/go.mod b/go.mod index f586919c..6d45a2e4 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/bwmarrin/snowflake v0.3.0 github.com/golang-jwt/jwt v3.2.2+incompatible github.com/google/uuid v1.3.0 + github.com/gorilla/websocket v1.5.0 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/stripe/stripe-go/v74 v74.26.0 diff --git a/go.sum b/go.sum index 1fef35de..959acd49 100644 --- a/go.sum +++ b/go.sum @@ -165,6 +165,8 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0/go.mod h1:hgWBS7lorOAVIJEQMi4ZsPv9hVvWI6+ch50m39Pf2Ks= github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0 h1:1JYBfzqrWPcCclBwxFCPAou9n+q86mfnu7NAeHfte7A= diff --git a/goctl_template/api/handler.tpl b/goctl_template/api/handler.tpl index 1a6b35da..604bf136 100644 --- a/goctl_template/api/handler.tpl +++ b/goctl_template/api/handler.tpl @@ -26,7 +26,7 @@ func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc { {{if .HasResp}}resp{{end}} := l.{{.Call}}({{if .HasRequest}}&req, {{end}}userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/goctl_template/api/logic.tpl b/goctl_template/api/logic.tpl index e1504e4e..63413717 100644 --- a/goctl_template/api/logic.tpl +++ b/goctl_template/api/logic.tpl @@ -25,8 +25,9 @@ func New{{.logic}}(ctx context.Context, svcCtx *svc.ServiceContext) *{{.logic}} // func (l *{{.logic}}) BeforeLogic(w http.ResponseWriter, r *http.Request) { // } -// 处理逻辑后 w,r 如:重定向 -// func (l *{{.logic}}) AfterLogic(w http.ResponseWriter, r *http.Request) { +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *{{.logic}}) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) // } func (l *{{.logic}}) {{.function}}({{.request}}, userinfo *auth.UserInfo) (resp *basic.Response) { diff --git a/goctl_template_backend/api/handler.tpl b/goctl_template_backend/api/handler.tpl index 4b289117..f836b128 100644 --- a/goctl_template_backend/api/handler.tpl +++ b/goctl_template_backend/api/handler.tpl @@ -25,7 +25,7 @@ func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc { {{if .HasResp}}resp{{end}} := l.{{.Call}}({{if .HasRequest}}&req, {{end}}userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/goctl_template_backend/api/logic.tpl b/goctl_template_backend/api/logic.tpl index e1504e4e..d32190f1 100644 --- a/goctl_template_backend/api/logic.tpl +++ b/goctl_template_backend/api/logic.tpl @@ -25,10 +25,12 @@ func New{{.logic}}(ctx context.Context, svcCtx *svc.ServiceContext) *{{.logic}} // func (l *{{.logic}}) BeforeLogic(w http.ResponseWriter, r *http.Request) { // } -// 处理逻辑后 w,r 如:重定向 -// func (l *{{.logic}}) AfterLogic(w http.ResponseWriter, r *http.Request) { +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *{{.logic}}) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) // } + func (l *{{.logic}}) {{.function}}({{.request}}, userinfo *auth.UserInfo) (resp *basic.Response) { // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) // userinfo 传入值时, 一定不为null diff --git a/server/assistant/internal/handler/redirecthandler.go b/server/assistant/internal/handler/redirecthandler.go index c309c6d9..ec6724de 100644 --- a/server/assistant/internal/handler/redirecthandler.go +++ b/server/assistant/internal/handler/redirecthandler.go @@ -28,7 +28,7 @@ func RedirectHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.Redirect(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/assistant/internal/logic/redirectlogic.go b/server/assistant/internal/logic/redirectlogic.go index e913a752..a637f429 100644 --- a/server/assistant/internal/logic/redirectlogic.go +++ b/server/assistant/internal/logic/redirectlogic.go @@ -36,7 +36,7 @@ func NewRedirectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Redirect // } // 处理逻辑后 w,r 如:重定向 -func (l *RedirectLogic) AfterLogic(w http.ResponseWriter, r *http.Request) { +func (l *RedirectLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { if l.RedirectUrl != "" { html := fmt.Sprintf(` diff --git a/server/backend/internal/handler/quotationdetailhandler.go b/server/backend/internal/handler/quotationdetailhandler.go index ce9928ea..adbb9621 100644 --- a/server/backend/internal/handler/quotationdetailhandler.go +++ b/server/backend/internal/handler/quotationdetailhandler.go @@ -27,7 +27,7 @@ func QuotationDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.QuotationDetail(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/canteen/internal/handler/getcanteendetailhandler.go b/server/canteen/internal/handler/getcanteendetailhandler.go index 24bfc2cb..81ac03df 100644 --- a/server/canteen/internal/handler/getcanteendetailhandler.go +++ b/server/canteen/internal/handler/getcanteendetailhandler.go @@ -28,7 +28,7 @@ func GetCanteenDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetCanteenDetail(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/canteen/internal/handler/savecanteentypeproducthandler.go b/server/canteen/internal/handler/savecanteentypeproducthandler.go index 9cce2b29..5ca34dda 100644 --- a/server/canteen/internal/handler/savecanteentypeproducthandler.go +++ b/server/canteen/internal/handler/savecanteentypeproducthandler.go @@ -28,7 +28,7 @@ func SaveCanteenTypeProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc resp := l.SaveCanteenTypeProduct(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/data-transfer/internal/handler/getqrcodesetlisthandler.go b/server/data-transfer/internal/handler/getqrcodesetlisthandler.go index a5dedcf2..050c768c 100644 --- a/server/data-transfer/internal/handler/getqrcodesetlisthandler.go +++ b/server/data-transfer/internal/handler/getqrcodesetlisthandler.go @@ -28,7 +28,7 @@ func GetQrCodeSetListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetQrCodeSetList(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/data-transfer/internal/handler/getstandardlogolisthandler.go b/server/data-transfer/internal/handler/getstandardlogolisthandler.go index 48716664..db38259d 100644 --- a/server/data-transfer/internal/handler/getstandardlogolisthandler.go +++ b/server/data-transfer/internal/handler/getstandardlogolisthandler.go @@ -28,7 +28,7 @@ func GetStandardLogoListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetStandardLogoList(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/home-user-auth/internal/handler/acceptcookiehandler.go b/server/home-user-auth/internal/handler/acceptcookiehandler.go index ea24b81b..88e8944a 100644 --- a/server/home-user-auth/internal/handler/acceptcookiehandler.go +++ b/server/home-user-auth/internal/handler/acceptcookiehandler.go @@ -28,7 +28,7 @@ func AcceptCookieHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.AcceptCookie(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/home-user-auth/internal/handler/useraddaddresshandler.go b/server/home-user-auth/internal/handler/useraddaddresshandler.go index 5b2c6c3d..84354a6d 100644 --- a/server/home-user-auth/internal/handler/useraddaddresshandler.go +++ b/server/home-user-auth/internal/handler/useraddaddresshandler.go @@ -28,7 +28,7 @@ func UserAddAddressHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.UserAddAddress(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/home-user-auth/internal/handler/useraddresslisthandler.go b/server/home-user-auth/internal/handler/useraddresslisthandler.go index f0e51bf7..9060da40 100644 --- a/server/home-user-auth/internal/handler/useraddresslisthandler.go +++ b/server/home-user-auth/internal/handler/useraddresslisthandler.go @@ -28,7 +28,7 @@ func UserAddressListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.UserAddressList(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/home-user-auth/internal/handler/userbasicinfohandler.go b/server/home-user-auth/internal/handler/userbasicinfohandler.go index 070fc961..85e7ca17 100644 --- a/server/home-user-auth/internal/handler/userbasicinfohandler.go +++ b/server/home-user-auth/internal/handler/userbasicinfohandler.go @@ -28,7 +28,7 @@ func UserBasicInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.UserBasicInfo(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/home-user-auth/internal/handler/usercontactservicehandler.go b/server/home-user-auth/internal/handler/usercontactservicehandler.go index 3e1129b5..511d170f 100644 --- a/server/home-user-auth/internal/handler/usercontactservicehandler.go +++ b/server/home-user-auth/internal/handler/usercontactservicehandler.go @@ -28,7 +28,7 @@ func UserContactServiceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.UserContactService(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/home-user-auth/internal/handler/useremailregisterhandler.go b/server/home-user-auth/internal/handler/useremailregisterhandler.go index a245432e..5d274809 100644 --- a/server/home-user-auth/internal/handler/useremailregisterhandler.go +++ b/server/home-user-auth/internal/handler/useremailregisterhandler.go @@ -28,7 +28,7 @@ func UserEmailRegisterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.UserEmailRegister(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/home-user-auth/internal/handler/userfontshandler.go b/server/home-user-auth/internal/handler/userfontshandler.go index 04ce08bf..a98156e2 100644 --- a/server/home-user-auth/internal/handler/userfontshandler.go +++ b/server/home-user-auth/internal/handler/userfontshandler.go @@ -28,7 +28,7 @@ func UserFontsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.UserFonts(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/home-user-auth/internal/handler/usergettypehandler.go b/server/home-user-auth/internal/handler/usergettypehandler.go index c1b6fef4..9558f557 100644 --- a/server/home-user-auth/internal/handler/usergettypehandler.go +++ b/server/home-user-auth/internal/handler/usergettypehandler.go @@ -28,7 +28,7 @@ func UserGetTypeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.UserGetType(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/home-user-auth/internal/handler/usergoogleloginhandler.go b/server/home-user-auth/internal/handler/usergoogleloginhandler.go index 07e3c998..154b2450 100644 --- a/server/home-user-auth/internal/handler/usergoogleloginhandler.go +++ b/server/home-user-auth/internal/handler/usergoogleloginhandler.go @@ -28,7 +28,7 @@ func UserGoogleLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.UserGoogleLogin(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/home-user-auth/internal/handler/userloginhandler.go b/server/home-user-auth/internal/handler/userloginhandler.go index e880a060..d08232d6 100644 --- a/server/home-user-auth/internal/handler/userloginhandler.go +++ b/server/home-user-auth/internal/handler/userloginhandler.go @@ -28,7 +28,7 @@ func UserLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.UserLogin(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/home-user-auth/internal/handler/useroderdeletehandler.go b/server/home-user-auth/internal/handler/useroderdeletehandler.go index cd21c047..91cd7501 100644 --- a/server/home-user-auth/internal/handler/useroderdeletehandler.go +++ b/server/home-user-auth/internal/handler/useroderdeletehandler.go @@ -28,7 +28,7 @@ func UserOderDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.UserOderDelete(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/home-user-auth/internal/handler/userordercancelhandler.go b/server/home-user-auth/internal/handler/userordercancelhandler.go index f0065089..65402d98 100644 --- a/server/home-user-auth/internal/handler/userordercancelhandler.go +++ b/server/home-user-auth/internal/handler/userordercancelhandler.go @@ -28,7 +28,7 @@ func UserOrderCancelHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.UserOrderCancel(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/home-user-auth/internal/handler/userorderlisthandler.go b/server/home-user-auth/internal/handler/userorderlisthandler.go index e31f6ff8..f59f11da 100644 --- a/server/home-user-auth/internal/handler/userorderlisthandler.go +++ b/server/home-user-auth/internal/handler/userorderlisthandler.go @@ -28,7 +28,7 @@ func UserOrderListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.UserOrderList(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/home-user-auth/internal/handler/usersavebasicinfohandler.go b/server/home-user-auth/internal/handler/usersavebasicinfohandler.go index 362999fb..c29d60ab 100644 --- a/server/home-user-auth/internal/handler/usersavebasicinfohandler.go +++ b/server/home-user-auth/internal/handler/usersavebasicinfohandler.go @@ -28,7 +28,7 @@ func UserSaveBasicInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.UserSaveBasicInfo(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/home-user-auth/internal/handler/userstatusconfighandler.go b/server/home-user-auth/internal/handler/userstatusconfighandler.go index 63447b0c..bb70d0d3 100644 --- a/server/home-user-auth/internal/handler/userstatusconfighandler.go +++ b/server/home-user-auth/internal/handler/userstatusconfighandler.go @@ -28,7 +28,7 @@ func UserStatusConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.UserStatusConfig(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/home-user-auth/internal/logic/useremailregisterlogic.go b/server/home-user-auth/internal/logic/useremailregisterlogic.go index 34c29487..eb276e5b 100644 --- a/server/home-user-auth/internal/logic/useremailregisterlogic.go +++ b/server/home-user-auth/internal/logic/useremailregisterlogic.go @@ -31,7 +31,7 @@ func NewUserEmailRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) // } // 处理逻辑后 w,r 如:重定向 -// func (l *UserEmailRegisterLogic) AfterLogic(w http.ResponseWriter, r *http.Request) { +// func (l *UserEmailRegisterLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { // } func (l *UserEmailRegisterLogic) UserEmailRegister(req *types.RequestEmailRegister, userinfo *auth.UserInfo) (resp *basic.Response) { diff --git a/server/home-user-auth/internal/logic/usergoogleloginlogic.go b/server/home-user-auth/internal/logic/usergoogleloginlogic.go index 50b7683b..8c31f753 100644 --- a/server/home-user-auth/internal/logic/usergoogleloginlogic.go +++ b/server/home-user-auth/internal/logic/usergoogleloginlogic.go @@ -45,7 +45,7 @@ func NewUserGoogleLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *U // log.Println(r, w) // } -func (l *UserGoogleLoginLogic) AfterLogic(w http.ResponseWriter, r *http.Request) { +func (l *UserGoogleLoginLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { rurl := fmt.Sprintf( l.svcCtx.Config.MainAddress+"/oauth?token=%s&is_registered=%t®ister_token=%s", diff --git a/server/home-user-auth/internal/logic/userloginlogic.go b/server/home-user-auth/internal/logic/userloginlogic.go index 24d0b669..a8900591 100644 --- a/server/home-user-auth/internal/logic/userloginlogic.go +++ b/server/home-user-auth/internal/logic/userloginlogic.go @@ -23,7 +23,6 @@ type UserLoginLogic struct { svcCtx *svc.ServiceContext token string - resp *basic.Response } func NewUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLoginLogic { @@ -34,12 +33,12 @@ func NewUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLog } } -func (l *UserLoginLogic) AfterLogic(w http.ResponseWriter, r *http.Request) { +func (l *UserLoginLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { if l.token != "" { w.Header().Add("Authorization", fmt.Sprintf("Bearer %s", l.token)) } - httpx.OkJsonCtx(r.Context(), w, l.resp) + httpx.OkJsonCtx(r.Context(), w, resp) } func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin, userinfo *auth.UserInfo) (resp *basic.Response) { @@ -79,7 +78,6 @@ func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin, userinfo *auth.U } l.token = jwtToken - l.resp = resp.SetStatus(basic.CodeOK, data) // 返回认证成功的状态码以及数据对象 data 和 JWT Token。 return resp.SetStatus(basic.CodeOK, data) diff --git a/server/inventory/internal/handler/getcloudlisthandler.go b/server/inventory/internal/handler/getcloudlisthandler.go index 436c1bca..90708969 100644 --- a/server/inventory/internal/handler/getcloudlisthandler.go +++ b/server/inventory/internal/handler/getcloudlisthandler.go @@ -28,7 +28,7 @@ func GetCloudListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetCloudList(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/inventory/internal/handler/getpickuplisthandler.go b/server/inventory/internal/handler/getpickuplisthandler.go index 6d1c2ff4..ffe7fb4f 100644 --- a/server/inventory/internal/handler/getpickuplisthandler.go +++ b/server/inventory/internal/handler/getpickuplisthandler.go @@ -28,7 +28,7 @@ func GetPickupListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetPickupList(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/inventory/internal/handler/supplementhandler.go b/server/inventory/internal/handler/supplementhandler.go index 0e5f08f4..67bf8cd0 100644 --- a/server/inventory/internal/handler/supplementhandler.go +++ b/server/inventory/internal/handler/supplementhandler.go @@ -28,7 +28,7 @@ func SupplementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.Supplement(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/inventory/internal/handler/takehandler.go b/server/inventory/internal/handler/takehandler.go index 96007a4e..bb1d285c 100644 --- a/server/inventory/internal/handler/takehandler.go +++ b/server/inventory/internal/handler/takehandler.go @@ -28,7 +28,7 @@ func TakeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.Take(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/map-library/internal/handler/getmaplibrarylisthandler.go b/server/map-library/internal/handler/getmaplibrarylisthandler.go index 8c6c6364..4b75d285 100644 --- a/server/map-library/internal/handler/getmaplibrarylisthandler.go +++ b/server/map-library/internal/handler/getmaplibrarylisthandler.go @@ -28,7 +28,7 @@ func GetMapLibraryListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetMapLibraryList(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/map-library/internal/handler/savemaplibraryhandler.go b/server/map-library/internal/handler/savemaplibraryhandler.go index caee5c8c..952b2877 100644 --- a/server/map-library/internal/handler/savemaplibraryhandler.go +++ b/server/map-library/internal/handler/savemaplibraryhandler.go @@ -28,7 +28,7 @@ func SaveMapLibraryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.SaveMapLibrary(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/orders/internal/handler/getorderdetailhandler.go b/server/orders/internal/handler/getorderdetailhandler.go index b998c5e8..8423debc 100644 --- a/server/orders/internal/handler/getorderdetailhandler.go +++ b/server/orders/internal/handler/getorderdetailhandler.go @@ -28,7 +28,7 @@ func GetOrderDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetOrderDetail(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/orders/internal/handler/getorderinvoicehandler.go b/server/orders/internal/handler/getorderinvoicehandler.go index 77f5ef61..4135c24f 100644 --- a/server/orders/internal/handler/getorderinvoicehandler.go +++ b/server/orders/internal/handler/getorderinvoicehandler.go @@ -28,7 +28,7 @@ func GetOrderInvoiceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetOrderInvoice(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/orders/internal/logic/getorderdetaillogic.go b/server/orders/internal/logic/getorderdetaillogic.go index 966decc3..fc6e72f7 100644 --- a/server/orders/internal/logic/getorderdetaillogic.go +++ b/server/orders/internal/logic/getorderdetaillogic.go @@ -204,16 +204,22 @@ func (l *GetOrderDetailLogic) GetOrderDetail(req *types.GetOrderDetailReq, useri } //首款 if payIndex, ok := mapPay[1]; ok { - data.PayInfo.Deposit = types.Deposit{ - Method: *payList[payIndex].Brand, - TransNo: *payList[payIndex].TradeNo, + data.PayInfo = &types.PayInfo{ + Deposit: types.Deposit{ + Method: *payList[payIndex].Brand, + TransNo: *payList[payIndex].TradeNo, + }, + Final: types.Deposit{}, } } //尾款 if payIndex, ok := mapPay[2]; ok { - data.PayInfo.Final = types.Deposit{ - Method: *payList[payIndex].Brand, - TransNo: *payList[payIndex].TradeNo, + data.PayInfo = &types.PayInfo{ + Deposit: types.Deposit{}, + Final: types.Deposit{ + Method: *payList[payIndex].Brand, + TransNo: *payList[payIndex].TradeNo, + }, } } return resp.SetStatusWithMessage(basic.CodeOK, "success", data) diff --git a/server/product-model/internal/handler/getmodeldetailhandler.go b/server/product-model/internal/handler/getmodeldetailhandler.go index 7b2ea338..36af4891 100644 --- a/server/product-model/internal/handler/getmodeldetailhandler.go +++ b/server/product-model/internal/handler/getmodeldetailhandler.go @@ -27,7 +27,7 @@ func GetModelDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetModelDetail(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product-model/internal/handler/getmodelotherinfohandler.go b/server/product-model/internal/handler/getmodelotherinfohandler.go index 87e6d308..35b6c80a 100644 --- a/server/product-model/internal/handler/getmodelotherinfohandler.go +++ b/server/product-model/internal/handler/getmodelotherinfohandler.go @@ -27,7 +27,7 @@ func GetModelOtherInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetModelOtherInfo(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product-model/internal/handler/updateproductmodelhandler.go b/server/product-model/internal/handler/updateproductmodelhandler.go index cf105bda..14376d63 100644 --- a/server/product-model/internal/handler/updateproductmodelhandler.go +++ b/server/product-model/internal/handler/updateproductmodelhandler.go @@ -27,7 +27,7 @@ func UpdateProductModelHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.UpdateProductModel(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product-template/internal/handler/addbasemaphandler.go b/server/product-template/internal/handler/addbasemaphandler.go index 1e5942c9..f9113743 100644 --- a/server/product-template/internal/handler/addbasemaphandler.go +++ b/server/product-template/internal/handler/addbasemaphandler.go @@ -27,7 +27,7 @@ func AddBaseMapHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.AddBaseMap(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product-template/internal/handler/getbasemaplisthandler.go b/server/product-template/internal/handler/getbasemaplisthandler.go index 22c7296f..bf2e723b 100644 --- a/server/product-template/internal/handler/getbasemaplisthandler.go +++ b/server/product-template/internal/handler/getbasemaplisthandler.go @@ -27,7 +27,7 @@ func GetBaseMapListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetBaseMapList(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product-template/internal/handler/gettemplatevdetailhandler.go b/server/product-template/internal/handler/gettemplatevdetailhandler.go index e7cef6dd..80335cf8 100644 --- a/server/product-template/internal/handler/gettemplatevdetailhandler.go +++ b/server/product-template/internal/handler/gettemplatevdetailhandler.go @@ -27,7 +27,7 @@ func GetTemplatevDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetTemplatevDetail(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product-template/internal/handler/savebasemaphandler.go b/server/product-template/internal/handler/savebasemaphandler.go index e3e41831..0655529b 100644 --- a/server/product-template/internal/handler/savebasemaphandler.go +++ b/server/product-template/internal/handler/savebasemaphandler.go @@ -27,7 +27,7 @@ func SaveBaseMapHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.SaveBaseMap(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product-template/internal/handler/updatetemplatehandler.go b/server/product-template/internal/handler/updatetemplatehandler.go index 3f4da440..a7ce9584 100644 --- a/server/product-template/internal/handler/updatetemplatehandler.go +++ b/server/product-template/internal/handler/updatetemplatehandler.go @@ -27,7 +27,7 @@ func UpdateTemplateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.UpdateTemplate(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/handler/designgatherhandler.go b/server/product/internal/handler/designgatherhandler.go index 516fac2f..5108a59d 100644 --- a/server/product/internal/handler/designgatherhandler.go +++ b/server/product/internal/handler/designgatherhandler.go @@ -28,7 +28,7 @@ func DesignGatherHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.DesignGather(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/handler/getfittingbypidhandler.go b/server/product/internal/handler/getfittingbypidhandler.go index adbd78ff..8c48642c 100644 --- a/server/product/internal/handler/getfittingbypidhandler.go +++ b/server/product/internal/handler/getfittingbypidhandler.go @@ -28,7 +28,7 @@ func GetFittingByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetFittingByPid(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/handler/getlastproductdesignhandler.go b/server/product/internal/handler/getlastproductdesignhandler.go index 79c32f1a..e2f656a8 100644 --- a/server/product/internal/handler/getlastproductdesignhandler.go +++ b/server/product/internal/handler/getlastproductdesignhandler.go @@ -28,7 +28,7 @@ func GetLastProductDesignHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetLastProductDesign(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/handler/getlightbypidhandler.go b/server/product/internal/handler/getlightbypidhandler.go index 9184c2ba..2763fabd 100644 --- a/server/product/internal/handler/getlightbypidhandler.go +++ b/server/product/internal/handler/getlightbypidhandler.go @@ -28,7 +28,7 @@ func GetLightByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetLightByPid(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/handler/getmodelbypidhandler.go b/server/product/internal/handler/getmodelbypidhandler.go index ab97af0f..8457bd0c 100644 --- a/server/product/internal/handler/getmodelbypidhandler.go +++ b/server/product/internal/handler/getmodelbypidhandler.go @@ -28,7 +28,7 @@ func GetModelByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetModelByPid(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/handler/getpricebypidhandler.go b/server/product/internal/handler/getpricebypidhandler.go index f98054ac..254799fe 100644 --- a/server/product/internal/handler/getpricebypidhandler.go +++ b/server/product/internal/handler/getpricebypidhandler.go @@ -28,7 +28,7 @@ func GetPriceByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetPriceByPid(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/handler/getproductdesignhandler.go b/server/product/internal/handler/getproductdesignhandler.go index 02fef73d..42862fb8 100644 --- a/server/product/internal/handler/getproductdesignhandler.go +++ b/server/product/internal/handler/getproductdesignhandler.go @@ -28,7 +28,7 @@ func GetProductDesignHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetProductDesign(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/handler/getproductinfohandler.go b/server/product/internal/handler/getproductinfohandler.go index 7d01c0ee..e195b2c1 100644 --- a/server/product/internal/handler/getproductinfohandler.go +++ b/server/product/internal/handler/getproductinfohandler.go @@ -28,7 +28,7 @@ func GetProductInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetProductInfo(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/handler/getproductlisthandler.go b/server/product/internal/handler/getproductlisthandler.go index a71fefc7..41360ef6 100644 --- a/server/product/internal/handler/getproductlisthandler.go +++ b/server/product/internal/handler/getproductlisthandler.go @@ -28,7 +28,7 @@ func GetProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetProductList(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/handler/getrecommandproductlisthandler.go b/server/product/internal/handler/getrecommandproductlisthandler.go index 00509d37..332ece32 100644 --- a/server/product/internal/handler/getrecommandproductlisthandler.go +++ b/server/product/internal/handler/getrecommandproductlisthandler.go @@ -28,7 +28,7 @@ func GetRecommandProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc resp := l.GetRecommandProductList(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/handler/getrenderdesignhandler.go b/server/product/internal/handler/getrenderdesignhandler.go index 1a7d8ebd..967f7d05 100644 --- a/server/product/internal/handler/getrenderdesignhandler.go +++ b/server/product/internal/handler/getrenderdesignhandler.go @@ -28,7 +28,7 @@ func GetRenderDesignHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetRenderDesign(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/handler/getrendersettingbypidhandler.go b/server/product/internal/handler/getrendersettingbypidhandler.go index 818f3d07..d6802345 100644 --- a/server/product/internal/handler/getrendersettingbypidhandler.go +++ b/server/product/internal/handler/getrendersettingbypidhandler.go @@ -28,7 +28,7 @@ func GetRenderSettingByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetRenderSettingByPid(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/handler/getsizebypidhandler.go b/server/product/internal/handler/getsizebypidhandler.go index 38b9c2d8..a17f18e8 100644 --- a/server/product/internal/handler/getsizebypidhandler.go +++ b/server/product/internal/handler/getsizebypidhandler.go @@ -28,7 +28,7 @@ func GetSizeByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetSizeByPid(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/handler/getsizebyproducthandler.go b/server/product/internal/handler/getsizebyproducthandler.go index 9bc8db8b..0451933b 100644 --- a/server/product/internal/handler/getsizebyproducthandler.go +++ b/server/product/internal/handler/getsizebyproducthandler.go @@ -28,7 +28,7 @@ func GetSizeByProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetSizeByProduct(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/handler/getsuccessrecommandhandler.go b/server/product/internal/handler/getsuccessrecommandhandler.go index b6f5055b..63bdeae3 100644 --- a/server/product/internal/handler/getsuccessrecommandhandler.go +++ b/server/product/internal/handler/getsuccessrecommandhandler.go @@ -28,7 +28,7 @@ func GetSuccessRecommandHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetSuccessRecommand(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/handler/gettagproductlisthandler.go b/server/product/internal/handler/gettagproductlisthandler.go index 02043645..199c0f01 100644 --- a/server/product/internal/handler/gettagproductlisthandler.go +++ b/server/product/internal/handler/gettagproductlisthandler.go @@ -28,7 +28,7 @@ func GetTagProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetTagProductList(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/handler/gettemplatebypidhandler.go b/server/product/internal/handler/gettemplatebypidhandler.go index 94268c3c..9dc538ea 100644 --- a/server/product/internal/handler/gettemplatebypidhandler.go +++ b/server/product/internal/handler/gettemplatebypidhandler.go @@ -28,7 +28,7 @@ func GetTemplateByPidHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.GetTemplateByPid(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/handler/homepagerecommendproductlisthandler.go b/server/product/internal/handler/homepagerecommendproductlisthandler.go index 674580a3..1cad5f91 100644 --- a/server/product/internal/handler/homepagerecommendproductlisthandler.go +++ b/server/product/internal/handler/homepagerecommendproductlisthandler.go @@ -28,7 +28,7 @@ func HomePageRecommendProductListHandler(svcCtx *svc.ServiceContext) http.Handle resp := l.HomePageRecommendProductList(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/handler/otherproductlisthandler.go b/server/product/internal/handler/otherproductlisthandler.go index 43022089..e5ad758b 100644 --- a/server/product/internal/handler/otherproductlisthandler.go +++ b/server/product/internal/handler/otherproductlisthandler.go @@ -28,7 +28,7 @@ func OtherProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.OtherProductList(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/handler/savedesignhandler.go b/server/product/internal/handler/savedesignhandler.go index 79e05c9a..51249a28 100644 --- a/server/product/internal/handler/savedesignhandler.go +++ b/server/product/internal/handler/savedesignhandler.go @@ -28,7 +28,7 @@ func SaveDesignHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.SaveDesign(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 8a185eea..27ce7ba5 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -100,7 +100,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR IsDel: &pIsDel, IsShelf: &pIsShelf, Status: &pStatus, - OrderBy: "`sort` DESC", + OrderBy: "`is_recommend` DESC,`sort` ASC", }) if err != nil { logx.Error(err) @@ -223,11 +223,9 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) TagProductList: nil, TypeName: *tagInfo.Title, TypeId: tagInfo.Id, - Level: int64(lenLevel), - LevelPrefix: *tagInfo.LevelPrefix, Icon: *tagInfo.Icon, Sort: *tagInfo.Sort, - Description: *tagInfo.Description, + LevelPrefix: *tagInfo.LevelPrefix, ChildTagList: make([]*types.TagItem, 0, 50), } //携带产品 @@ -243,8 +241,10 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) Size: req.Size, User: req.User, }) - //赋值 - tagTem.TagProductList = productListRsp + //tag中产品 + for _, tmpProduct := range productListRsp { + tagTem.TagProductList = append(tagTem.TagProductList, tmpProduct) + } } //加入分类 req.MapTagLevel[*tagInfo.LevelPrefix] = &tagTem @@ -255,6 +255,7 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) // 组织等级从属关系 func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagLevel map[string]*types.TagItem) []types.TagItem { mapTop := make(map[string]struct{}) + //设置归属关系 for prefix, tagItem := range mapTagLevel { prefixSlice := strings.Split(prefix, "/") //存储最高等级 @@ -275,6 +276,18 @@ func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagL }) mapTagLevel[parentPrefix] = parent } + //把子类的产品列表变成产品id列表并且把产品列表都放到最顶级父级中 + for _, v := range mapTagLevel { + if _, ok := mapTop[v.LevelPrefix]; ok { + continue + } + topPrefixSlic := strings.Split(v.LevelPrefix, "/")[:minLevel] + topPrefix := strings.Join(topPrefixSlic, "/") + for k, tmpProduct := range v.TagProductList { + v.TagProductList[k] = tmpProduct.(types.TagProduct).ProductId + mapTagLevel[topPrefix].TagProductList = append(mapTagLevel[topPrefix].TagProductList, tmpProduct) + } + } //最终值提取最高级别那一层出来 rspList := make([]types.TagItem, 0, len(mapTagLevel)) for prefix, _ := range mapTop { @@ -326,12 +339,10 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL ProductId: productInfo.Id, Sn: *productInfo.Sn, Title: *productInfo.Title, - Intro: *productInfo.Intro, - IsEnv: *productInfo.IsProtection, - IsMicro: *productInfo.IsMicrowave, SizeNum: uint32(sizeNum), MinPrice: minPrice, HaveOptionalFitting: haveOptionalFitting, + Recommended: *productInfo.IsRecommend > 0, } //千人千面处理 r := image.ThousandFaceImageFormatReq{ @@ -348,7 +359,6 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL } image.ThousandFaceImageFormat(&r) item.Cover = r.Cover - item.CoverImg = r.CoverImg item.CoverDefault = r.CoverDefault //加入分类产品切片 productListRsp = append(productListRsp, item) diff --git a/server/product/internal/logic/homepagerecommendproductlistlogic.go b/server/product/internal/logic/homepagerecommendproductlistlogic.go index 60c4cdb0..899de460 100644 --- a/server/product/internal/logic/homepagerecommendproductlistlogic.go +++ b/server/product/internal/logic/homepagerecommendproductlistlogic.go @@ -146,12 +146,9 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty haveOptionalFitting = true } item := types.HomePageRecommendProductListRsp{ - ProductId: productInfo.Id, + Id: productInfo.Id, Sn: *productInfo.Sn, Title: *productInfo.Title, - Intro: *productInfo.Intro, - IsEnv: *productInfo.IsProtection, - IsMicro: *productInfo.IsMicrowave, SizeNum: uint32(sizeNum), MinPrice: minPrice, HaveOptionalFitting: haveOptionalFitting, @@ -171,7 +168,6 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty } image.ThousandFaceImageFormat(&r) item.Cover = r.Cover - item.CoverImg = r.CoverImg item.CoverDefault = r.CoverDefault //加入分类产品切片 listRsp = append(listRsp, item) diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index 8109fec5..f2d27f0a 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -258,15 +258,13 @@ type GetTagProductListRsp struct { } type TagItem struct { - TypeName string `json:"type_name"` - TypeId int64 `json:"type_id"` - Description string `json:"description"` - Level int64 `json:"level"` - LevelPrefix string `json:"level_prefix"` - Icon string `json:"icon"` - Sort int64 `json:"sort"` - TagProductList []TagProduct `json:"tag_product_list"` //分类下的产品 - ChildTagList []*TagItem `json:"child_tag_list"` + TypeName string `json:"type_name"` + TypeId int64 `json:"type_id"` + Icon string `json:"icon"` + Sort int64 `json:"sort"` + LevelPrefix string `json:"level_prefix"` + TagProductList []interface{} `json:"tag_product_list"` //分类下的产品 + ChildTagList []*TagItem `json:"child_tag_list"` } type TagProduct struct { @@ -274,14 +272,11 @@ type TagProduct struct { Sn string `json:"sn"` Title string `json:"title"` Cover string `json:"cover"` - Intro string `json:"intro"` - CoverImg string `json:"cover_img"` - IsEnv int64 `json:"is_env"` - IsMicro int64 `json:"is_micro"` SizeNum uint32 `json:"size_num"` MinPrice int64 `json:"min_price"` CoverDefault string `json:"cover_default"` HaveOptionalFitting bool `json:"have_optional_fitting"` + Recommended bool `json:"recommended"` } type GetRenderDesignReq struct { @@ -392,14 +387,10 @@ type HomePageRecommendProductListReq struct { } type HomePageRecommendProductListRsp struct { - ProductId int64 `json:"product_id"` + Id int64 `json:"id"` Sn string `json:"sn"` Title string `json:"title"` Cover string `json:"cover"` - Intro string `json:"intro"` - CoverImg string `json:"cover_img"` - IsEnv int64 `json:"is_env"` - IsMicro int64 `json:"is_micro"` SizeNum uint32 `json:"size_num"` MinPrice int64 `json:"min_price"` CoverDefault string `json:"cover_default"` diff --git a/server/render/internal/handler/readimageshandler.go b/server/render/internal/handler/readimageshandler.go index e387ea0f..4156ab0f 100644 --- a/server/render/internal/handler/readimageshandler.go +++ b/server/render/internal/handler/readimageshandler.go @@ -28,7 +28,7 @@ func ReadImagesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.ReadImages(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/render/internal/handler/tounityhandler.go b/server/render/internal/handler/tounityhandler.go index e3cb5d28..80191459 100644 --- a/server/render/internal/handler/tounityhandler.go +++ b/server/render/internal/handler/tounityhandler.go @@ -28,7 +28,7 @@ func ToUnityHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.ToUnity(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/render/internal/logic/readimageslogic.go b/server/render/internal/logic/readimageslogic.go index 9ab23d58..e7d36441 100644 --- a/server/render/internal/logic/readimageslogic.go +++ b/server/render/internal/logic/readimageslogic.go @@ -31,7 +31,7 @@ func NewReadImagesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ReadIm // } // 处理逻辑后 w,r 如:重定向 -// func (l *ReadImagesLogic) AfterLogic(w http.ResponseWriter, r *http.Request) { +// func (l *ReadImagesLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { // } func (l *ReadImagesLogic) ReadImages(req *types.RequestReadImages, userinfo *auth.UserInfo) (resp *basic.Response) { diff --git a/server/render/internal/logic/tounitylogic.go b/server/render/internal/logic/tounitylogic.go index f9ae5f29..bacf7b98 100644 --- a/server/render/internal/logic/tounitylogic.go +++ b/server/render/internal/logic/tounitylogic.go @@ -31,7 +31,7 @@ func NewToUnityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ToUnityLo // } // 处理逻辑后 w,r 如:重定向 -// func (l *ToUnityLogic) AfterLogic(w http.ResponseWriter, r *http.Request) { +// func (l *ToUnityLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { // } func (l *ToUnityLogic) ToUnity(req *types.RequestToUnity, userinfo *auth.UserInfo) (resp *basic.Response) { diff --git a/server/shopping-cart-confirmation/internal/handler/cartaddhandler.go b/server/shopping-cart-confirmation/internal/handler/cartaddhandler.go index 26c2c676..b09b01e4 100644 --- a/server/shopping-cart-confirmation/internal/handler/cartaddhandler.go +++ b/server/shopping-cart-confirmation/internal/handler/cartaddhandler.go @@ -28,7 +28,7 @@ func CartAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.CartAdd(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/shopping-cart-confirmation/internal/handler/cartdeletehandler.go b/server/shopping-cart-confirmation/internal/handler/cartdeletehandler.go index c294d394..47cc9f8a 100644 --- a/server/shopping-cart-confirmation/internal/handler/cartdeletehandler.go +++ b/server/shopping-cart-confirmation/internal/handler/cartdeletehandler.go @@ -28,7 +28,7 @@ func CartDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.CartDelete(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/shopping-cart-confirmation/internal/handler/cartlisthandler.go b/server/shopping-cart-confirmation/internal/handler/cartlisthandler.go index 7632c87a..1066bc19 100644 --- a/server/shopping-cart-confirmation/internal/handler/cartlisthandler.go +++ b/server/shopping-cart-confirmation/internal/handler/cartlisthandler.go @@ -28,7 +28,7 @@ func CartListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.CartList(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/shopping-cart-confirmation/internal/handler/cartnumberhandler.go b/server/shopping-cart-confirmation/internal/handler/cartnumberhandler.go index 5aa85d0b..4ff7632d 100644 --- a/server/shopping-cart-confirmation/internal/handler/cartnumberhandler.go +++ b/server/shopping-cart-confirmation/internal/handler/cartnumberhandler.go @@ -28,7 +28,7 @@ func CartNumberHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.CartNumber(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/shopping-cart-confirmation/internal/handler/cartorderdetailhandler.go b/server/shopping-cart-confirmation/internal/handler/cartorderdetailhandler.go index a1bb344b..94b4b738 100644 --- a/server/shopping-cart-confirmation/internal/handler/cartorderdetailhandler.go +++ b/server/shopping-cart-confirmation/internal/handler/cartorderdetailhandler.go @@ -28,7 +28,7 @@ func CartOrderDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.CartOrderDetail(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/shopping-cart-confirmation/internal/handler/changeordermethodhandler.go b/server/shopping-cart-confirmation/internal/handler/changeordermethodhandler.go index ce58d809..dc8d6ec4 100644 --- a/server/shopping-cart-confirmation/internal/handler/changeordermethodhandler.go +++ b/server/shopping-cart-confirmation/internal/handler/changeordermethodhandler.go @@ -28,7 +28,7 @@ func ChangeOrderMethodHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.ChangeOrderMethod(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/shopping-cart-confirmation/internal/handler/createorderhandler.go b/server/shopping-cart-confirmation/internal/handler/createorderhandler.go index 75083e14..8ecb0f07 100644 --- a/server/shopping-cart-confirmation/internal/handler/createorderhandler.go +++ b/server/shopping-cart-confirmation/internal/handler/createorderhandler.go @@ -28,7 +28,7 @@ func CreateOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.CreateOrder(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/upload/internal/handler/uploadfilefrontendhandler.go b/server/upload/internal/handler/uploadfilefrontendhandler.go index 6a0a4440..f70b1e96 100644 --- a/server/upload/internal/handler/uploadfilefrontendhandler.go +++ b/server/upload/internal/handler/uploadfilefrontendhandler.go @@ -28,7 +28,7 @@ func UploadFileFrontendHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.UploadFileFrontend(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/upload/internal/handler/uploadqrcodehandler.go b/server/upload/internal/handler/uploadqrcodehandler.go index f5908197..6223728c 100644 --- a/server/upload/internal/handler/uploadqrcodehandler.go +++ b/server/upload/internal/handler/uploadqrcodehandler.go @@ -28,7 +28,7 @@ func UploadQrcodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.UploadQrcode(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/upload/internal/handler/uploadupfilehandler.go b/server/upload/internal/handler/uploadupfilehandler.go index ae41d8b9..625e7d14 100644 --- a/server/upload/internal/handler/uploadupfilehandler.go +++ b/server/upload/internal/handler/uploadupfilehandler.go @@ -28,7 +28,7 @@ func UploadUpFileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.UploadUpFile(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/webset/internal/handler/websetsettinghandler.go b/server/webset/internal/handler/websetsettinghandler.go index 16f13892..b8b0a606 100644 --- a/server/webset/internal/handler/websetsettinghandler.go +++ b/server/webset/internal/handler/websetsettinghandler.go @@ -28,7 +28,7 @@ func WebSetSettingHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.WebSetSetting(&req, userinfo) - if !basic.AfterLogic(w, r, rl) { + if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/webset/internal/logic/websetsettinglogic.go b/server/webset/internal/logic/websetsettinglogic.go index 50da5798..c8fca38f 100644 --- a/server/webset/internal/logic/websetsettinglogic.go +++ b/server/webset/internal/logic/websetsettinglogic.go @@ -34,7 +34,7 @@ func NewWebSetSettingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Web // } // 处理逻辑后 w,r 如:重定向 -// func (l *WebSetSettingLogic) AfterLogic(w http.ResponseWriter, r *http.Request) { +// func (l *WebSetSettingLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { // } func (l *WebSetSettingLogic) WebSetSetting(req *types.RequestWebSet, userinfo *auth.UserInfo) (resp *basic.Response) { diff --git a/server/websocket/etc/websocket.yaml b/server/websocket/etc/websocket.yaml new file mode 100644 index 00000000..d22f03a7 --- /dev/null +++ b/server/websocket/etc/websocket.yaml @@ -0,0 +1,8 @@ +Name: websocket +Host: 0.0.0.0 +Port: 8888 +SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest +Auth: + AccessSecret: fusen2023 + AccessExpire: 2592000 + RefreshAfter: 1592000 \ No newline at end of file diff --git a/server/websocket/internal/config/config.go b/server/websocket/internal/config/config.go new file mode 100644 index 00000000..b24bb7d7 --- /dev/null +++ b/server/websocket/internal/config/config.go @@ -0,0 +1,9 @@ +package config + +import "github.com/zeromicro/go-zero/rest" + +type Config struct { + rest.RestConf + SourceMysql string + Auth types.Auth +} diff --git a/server/websocket/internal/handler/datatransferhandler.go b/server/websocket/internal/handler/datatransferhandler.go new file mode 100644 index 00000000..4534d041 --- /dev/null +++ b/server/websocket/internal/handler/datatransferhandler.go @@ -0,0 +1,58 @@ +package handler + +import ( + "fusenapi/server/websocket/internal/svc" + "github.com/gorilla/websocket" + "net/http" + "sync" +) + +var ( + //升级 + upgrade = websocket.Upgrader{ + //允许跨域 + CheckOrigin: func(r *http.Request) bool { + return true + }, + } + //连接map池 + mapConn = sync.Map{} +) + +type wsConnectItem struct { + conn *websocket.Conn //websocket的连接 + renImage sync.Map //需要渲染的图片 +} + +func DataTransferHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + /*// 解析JWT token,并对空用户进行判断 + claims, err := svcCtx.ParseJwtToken(r) + // 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + logx.Info("unauthorized:", err.Error()) // 记录错误日志 + w.Write([]byte("connect failed:unauthorized")) + return + } + var userInfo *auth.UserInfo + if claims != nil { + // 从token中获取对应的用户信息 + userInfo, err = auth.GetUserInfoFormMapClaims(claims) + // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + return + } + } else { + // 如果claims为nil,则认为用户身份为白板用户 + w.Write([]byte("connect failed:unauthorized!!")) + return + } + //升级websocket + conn, err := upgrade.Upgrade(w, r, r.Header) + if err != nil { + logx.Error("http upgrade websocket err:", err) + w.Write([]byte("http upgrade websocket err")) + return + }*/ + } +} diff --git a/server/websocket/internal/handler/routes.go b/server/websocket/internal/handler/routes.go new file mode 100644 index 00000000..fd3200e4 --- /dev/null +++ b/server/websocket/internal/handler/routes.go @@ -0,0 +1,22 @@ +// Code generated by goctl. DO NOT EDIT. +package handler + +import ( + "net/http" + + "fusenapi/server/websocket/internal/svc" + + "github.com/zeromicro/go-zero/rest" +) + +func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { + server.AddRoutes( + []rest.Route{ + { + Method: http.MethodGet, + Path: "/api/websocket/data_transfer", + Handler: DataTransferHandler(serverCtx), + }, + }, + ) +} diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go new file mode 100644 index 00000000..7b5db86b --- /dev/null +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -0,0 +1,43 @@ +package logic + +import ( + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "context" + + "fusenapi/server/websocket/internal/svc" + "fusenapi/server/websocket/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type DataTransferLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewDataTransferLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DataTransferLogic { + return &DataTransferLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *DataTransferLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *DataTransferLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } + +func (l *DataTransferLogic) DataTransfer(req *types.DataTransferReq, userinfo *auth.UserInfo) (resp *basic.Response) { + // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + // userinfo 传入值时, 一定不为null + + return resp.SetStatus(basic.CodeOK) +} diff --git a/server/websocket/internal/svc/servicecontext.go b/server/websocket/internal/svc/servicecontext.go new file mode 100644 index 00000000..9a22471e --- /dev/null +++ b/server/websocket/internal/svc/servicecontext.go @@ -0,0 +1,61 @@ +package svc + +import ( + "errors" + "fmt" + "fusenapi/server/websocket/internal/config" + "net/http" + + "fusenapi/initalize" + "fusenapi/model/gmodel" + + "github.com/golang-jwt/jwt" + "gorm.io/gorm" +) + +type ServiceContext struct { + Config config.Config + + MysqlConn *gorm.DB + AllModels *gmodel.AllModelsGen +} + +func NewServiceContext(c config.Config) *ServiceContext { + + return &ServiceContext{ + Config: c, + MysqlConn: initalize.InitMysql(c.SourceMysql), + AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)), + } +} + +func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) { + AuthKey := r.Header.Get("Authorization") + if AuthKey == "" { + return nil, nil + } + AuthKey = AuthKey[7:] + + if len(AuthKey) <= 50 { + return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) + } + + token, err := jwt.Parse(AuthKey, func(token *jwt.Token) (interface{}, error) { + // 检查签名方法是否为 HS256 + if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok { + return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) + } + // 返回用于验证签名的密钥 + return []byte(svcCtx.Config.Auth.AccessSecret), nil + }) + if err != nil { + return nil, errors.New(fmt.Sprint("Error parsing token:", err)) + } + + // 验证成功返回 + if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid { + return claims, nil + } + + return nil, errors.New(fmt.Sprint("Invalid token", err)) +} diff --git a/server/websocket/internal/types/types.go b/server/websocket/internal/types/types.go new file mode 100644 index 00000000..06201d39 --- /dev/null +++ b/server/websocket/internal/types/types.go @@ -0,0 +1,85 @@ +// Code generated by goctl. DO NOT EDIT. +package types + +import ( + "fusenapi/utils/basic" +) + +type DataTransferReq struct { + MsgType string `json:"msg_type"` //消息类型 + Message interface{} `json:"message"` //传递的消息 +} + +type DataTransferRsp struct { + MsgType string `json:"msg_type"` //消息类型 + Message interface{} `json:"message"` //传递的消息 +} + +type Request struct { +} + +type Response struct { + Code int `json:"code"` + Message string `json:"msg"` + Data interface{} `json:"data"` +} + +type Auth struct { + AccessSecret string `json:"accessSecret"` + AccessExpire int64 `json:"accessExpire"` + RefreshAfter int64 `json:"refreshAfter"` +} + +type File struct { + Filename string `fsfile:"filename"` + Header map[string][]string `fsfile:"header"` + Size int64 `fsfile:"size"` + Data []byte `fsfile:"data"` +} + +type Meta struct { + TotalCount int64 `json:"totalCount"` + PageCount int64 `json:"pageCount"` + CurrentPage int `json:"currentPage"` + PerPage int `json:"perPage"` +} + +// Set 设置Response的Code和Message值 +func (resp *Response) Set(Code int, Message string) *Response { + return &Response{ + Code: Code, + Message: Message, + } +} + +// Set 设置整个Response +func (resp *Response) SetWithData(Code int, Message string, Data interface{}) *Response { + return &Response{ + Code: Code, + Message: Message, + Data: Data, + } +} + +// SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数 +func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) *Response { + newResp := &Response{ + Code: sr.Code, + } + if len(data) == 1 { + newResp.Data = data[0] + } + return newResp +} + +// SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数 +func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) *Response { + newResp := &Response{ + Code: sr.Code, + Message: msg, + } + if len(data) == 1 { + newResp.Data = data[0] + } + return newResp +} diff --git a/server/websocket/websocket.go b/server/websocket/websocket.go new file mode 100644 index 00000000..c5e7bdd0 --- /dev/null +++ b/server/websocket/websocket.go @@ -0,0 +1,36 @@ +package main + +import ( + "flag" + "fmt" + "net/http" + "time" + + "fusenapi/utils/auth" + + "fusenapi/server/websocket/internal/config" + "fusenapi/server/websocket/internal/handler" + "fusenapi/server/websocket/internal/svc" + + "github.com/zeromicro/go-zero/core/conf" + "github.com/zeromicro/go-zero/rest" +) + +var configFile = flag.String("f", "etc/websocket.yaml", "the config file") + +func main() { + flag.Parse() + + var c config.Config + conf.MustLoad(*configFile, &c) + c.Timeout = int64(time.Second * 15) + server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { + })) + defer server.Stop() + + ctx := svc.NewServiceContext(c) + handler.RegisterHandlers(server, ctx) + + fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port) + server.Start() +} diff --git a/server_api/product.api b/server_api/product.api index a7160506..48ac5a50 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -308,29 +308,24 @@ type GetTagProductListRsp { TagList []TagItem `json:"tag_list"` } type TagItem { - TypeName string `json:"type_name"` - TypeId int64 `json:"type_id"` - Description string `json:"description"` - Level int64 `json:"level"` - LevelPrefix string `json:"level_prefix"` - Icon string `json:"icon"` - Sort int64 `json:"sort"` - TagProductList []TagProduct `json:"tag_product_list"` //分类下的产品 - ChildTagList []*TagItem `json:"child_tag_list"` + TypeName string `json:"type_name"` + TypeId int64 `json:"type_id"` + Icon string `json:"icon"` + Sort int64 `json:"sort"` + LevelPrefix string `json:"level_prefix"` + TagProductList []interface{} `json:"tag_product_list"` //分类下的产品 + ChildTagList []*TagItem `json:"child_tag_list"` } type TagProduct { ProductId int64 `json:"product_id"` Sn string `json:"sn"` Title string `json:"title"` Cover string `json:"cover"` - Intro string `json:"intro"` - CoverImg string `json:"cover_img"` - IsEnv int64 `json:"is_env"` - IsMicro int64 `json:"is_micro"` SizeNum uint32 `json:"size_num"` MinPrice int64 `json:"min_price"` CoverDefault string `json:"cover_default"` HaveOptionalFitting bool `json:"have_optional_fitting"` + Recommended bool `json:"recommended"` } //获取云渲染设计方案信息 type GetRenderDesignReq { @@ -434,14 +429,10 @@ type HomePageRecommendProductListReq { Size uint32 `form:"size"` } type HomePageRecommendProductListRsp { - ProductId int64 `json:"product_id"` + Id int64 `json:"id"` Sn string `json:"sn"` Title string `json:"title"` Cover string `json:"cover"` - Intro string `json:"intro"` - CoverImg string `json:"cover_img"` - IsEnv int64 `json:"is_env"` - IsMicro int64 `json:"is_micro"` SizeNum uint32 `json:"size_num"` MinPrice int64 `json:"min_price"` CoverDefault string `json:"cover_default"` diff --git a/server_api/websocket.api b/server_api/websocket.api new file mode 100644 index 00000000..786e67e7 --- /dev/null +++ b/server_api/websocket.api @@ -0,0 +1,25 @@ +syntax = "v1" + +info ( + title: "websocket"// TODO: add title + desc: // TODO: add description + author: "" + email: "" +) + +import "basic.api" +service websocket { + //websocket数据交互 + @handler DataTransferHandler + get /api/websocket/data_transfer(DataTransferReq) returns (response); +} + +//websocket数据交互 +type DataTransferReq { + MsgType string `json:"msg_type"` //消息类型 + Message interface{} `json:"message"` //传递的消息 +} +type DataTransferRsp { + MsgType string `json:"msg_type"` //消息类型 + Message interface{} `json:"message"` //传递的消息 +} \ No newline at end of file diff --git a/utils/basic/request_parse.go b/utils/basic/request_parse.go index 54504d6b..e1eddff7 100644 --- a/utils/basic/request_parse.go +++ b/utils/basic/request_parse.go @@ -27,11 +27,11 @@ func BeforeLogic(w http.ResponseWriter, r *http.Request, l reflect.Value) (isNex return true } -func AfterLogic(w http.ResponseWriter, r *http.Request, l reflect.Value) bool { +func AfterLogic(w http.ResponseWriter, r *http.Request, l reflect.Value, resp *Response) bool { m := l.MethodByName("AfterLogic") if m.IsValid() { - m.Call([]reflect.Value{reflect.ValueOf(w), reflect.ValueOf(r)}) + m.Call([]reflect.Value{reflect.ValueOf(w), reflect.ValueOf(r), reflect.ValueOf(resp)}) return true } return false