Merge branch 'develop' into orders
This commit is contained in:
commit
05e5842992
1
go.mod
1
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
|
||||
|
|
2
go.sum
2
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=
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(`
|
||||
<!DOCTYPE html>
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"`
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
8
server/websocket/etc/websocket.yaml
Normal file
8
server/websocket/etc/websocket.yaml
Normal file
|
@ -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
|
9
server/websocket/internal/config/config.go
Normal file
9
server/websocket/internal/config/config.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package config
|
||||
|
||||
import "github.com/zeromicro/go-zero/rest"
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
SourceMysql string
|
||||
Auth types.Auth
|
||||
}
|
58
server/websocket/internal/handler/datatransferhandler.go
Normal file
58
server/websocket/internal/handler/datatransferhandler.go
Normal file
|
@ -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
|
||||
}*/
|
||||
}
|
||||
}
|
22
server/websocket/internal/handler/routes.go
Normal file
22
server/websocket/internal/handler/routes.go
Normal file
|
@ -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),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
43
server/websocket/internal/logic/datatransferlogic.go
Normal file
43
server/websocket/internal/logic/datatransferlogic.go
Normal file
|
@ -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)
|
||||
}
|
61
server/websocket/internal/svc/servicecontext.go
Normal file
61
server/websocket/internal/svc/servicecontext.go
Normal file
|
@ -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))
|
||||
}
|
85
server/websocket/internal/types/types.go
Normal file
85
server/websocket/internal/types/types.go
Normal file
|
@ -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
|
||||
}
|
36
server/websocket/websocket.go
Normal file
36
server/websocket/websocket.go
Normal file
|
@ -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()
|
||||
}
|
|
@ -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"`
|
||||
|
|
25
server_api/websocket.api
Normal file
25
server_api/websocket.api
Normal file
|
@ -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"` //传递的消息
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user