diff --git a/app/user/cmd/api/desc/product.api b/app/user/cmd/api/desc/product.api index af7aac1..0382a89 100644 --- a/app/user/cmd/api/desc/product.api +++ b/app/user/cmd/api/desc/product.api @@ -23,3 +23,11 @@ service main { get /en/:product_en (GetProductByEnRequest) returns (ProductResponse) } +@server ( + prefix: api/v1/product + group: product +) +service main { + @handler GetProductAppByEn + get /app_en/:product_en (GetProductByEnRequest) returns (ProductResponse) +} diff --git a/app/user/cmd/api/desc/query.api b/app/user/cmd/api/desc/query.api index 19edfd2..d477133 100644 --- a/app/user/cmd/api/desc/query.api +++ b/app/user/cmd/api/desc/query.api @@ -21,6 +21,9 @@ service main { @doc "query service agent" @handler queryServiceAgent post /query/service_agent/:product (QueryServiceReq) returns (QueryServiceResp) + + @handler queryServiceApp + post /query/service_app/:product (QueryServiceReq) returns (QueryServiceResp) } @server ( @@ -34,8 +37,6 @@ service main { post /query/service/:product (QueryServiceReq) returns (QueryServiceResp) } - - @server ( prefix: api/v1 group: query @@ -56,15 +57,15 @@ service main { @doc "查询详情 按订单号 付款查询时" @handler queryDetailByOrderId - get /query/orderId/:order_id (QueryDetailByOrderIdReq) returns (QueryDetailByOrderIdResp) + get /query/orderId/:order_id (QueryDetailByOrderIdReq) returns (QueryDetailByOrderIdResp) @doc "查询详情 按订单号" @handler queryDetailByOrderNo - get /query/orderNo/:order_no (QueryDetailByOrderNoReq) returns (QueryDetailByOrderNoResp) + get /query/orderNo/:order_no (QueryDetailByOrderNoReq) returns (QueryDetailByOrderNoResp) @doc "查询详情" @handler queryDetail - get /query/:id (QueryDetailReq) returns (QueryDetailResp) + get /query/:id (QueryDetailReq) returns (QueryDetailResp) @doc "重试查询" @handler queryRetry @@ -78,4 +79,5 @@ service main { service main { @handler querySingleTest post /query/single/test (QuerySingleTestReq) returns (QuerySingleTestResp) -} \ No newline at end of file +} + diff --git a/app/user/cmd/api/desc/query/query.api b/app/user/cmd/api/desc/query/query.api index b6702bb..1d3d3f5 100644 --- a/app/user/cmd/api/desc/query/query.api +++ b/app/user/cmd/api/desc/query/query.api @@ -21,6 +21,7 @@ type ( Product string `path:"product"` Data string `json:"data" validate:"required"` AgentIdentifier string `json:"agent_identifier,optional"` + App bool `json:"app,optional"` } QueryServiceResp { id string `json:"id"` @@ -121,6 +122,6 @@ type QuerySingleTestReq { type QuerySingleTestResp { Data interface{} `json:"data"` - Api string `json:"api"` + Api string `json:"api"` } diff --git a/app/user/cmd/api/internal/handler/product/getproductappbyenhandler.go b/app/user/cmd/api/internal/handler/product/getproductappbyenhandler.go new file mode 100644 index 0000000..f313714 --- /dev/null +++ b/app/user/cmd/api/internal/handler/product/getproductappbyenhandler.go @@ -0,0 +1,29 @@ +package product + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "tydata-server/app/user/cmd/api/internal/logic/product" + "tydata-server/app/user/cmd/api/internal/svc" + "tydata-server/app/user/cmd/api/internal/types" + "tydata-server/common/result" + "tydata-server/pkg/lzkit/validator" +) + +func GetProductAppByEnHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.GetProductByEnRequest + if err := httpx.Parse(r, &req); err != nil { + result.ParamErrorResult(r, w, err) + return + } + if err := validator.Validate(req); err != nil { + result.ParamValidateErrorResult(r, w, err) + return + } + l := product.NewGetProductAppByEnLogic(r.Context(), svcCtx) + resp, err := l.GetProductAppByEn(&req) + result.HttpResult(r, w, resp, err) + } +} diff --git a/app/user/cmd/api/internal/handler/query/queryserviceapphandler.go b/app/user/cmd/api/internal/handler/query/queryserviceapphandler.go new file mode 100644 index 0000000..1dce604 --- /dev/null +++ b/app/user/cmd/api/internal/handler/query/queryserviceapphandler.go @@ -0,0 +1,29 @@ +package query + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "tydata-server/app/user/cmd/api/internal/logic/query" + "tydata-server/app/user/cmd/api/internal/svc" + "tydata-server/app/user/cmd/api/internal/types" + "tydata-server/common/result" + "tydata-server/pkg/lzkit/validator" +) + +func QueryServiceAppHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.QueryServiceReq + if err := httpx.Parse(r, &req); err != nil { + result.ParamErrorResult(r, w, err) + return + } + if err := validator.Validate(req); err != nil { + result.ParamValidateErrorResult(r, w, err) + return + } + l := query.NewQueryServiceLogic(r.Context(), svcCtx) + resp, err := l.QueryService(&req) + result.HttpResult(r, w, resp, err) + } +} diff --git a/app/user/cmd/api/internal/handler/routes.go b/app/user/cmd/api/internal/handler/routes.go index 8c6bad0..e8d975e 100644 --- a/app/user/cmd/api/internal/handler/routes.go +++ b/app/user/cmd/api/internal/handler/routes.go @@ -182,6 +182,17 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { rest.WithPrefix("/api/v1/product"), ) + server.AddRoutes( + []rest.Route{ + { + Method: http.MethodGet, + Path: "/app_en/:product_en", + Handler: product.GetProductAppByEnHandler(serverCtx), + }, + }, + rest.WithPrefix("/api/v1/product"), + ) + server.AddRoutes( []rest.Route{ { @@ -190,6 +201,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/query/service_agent/:product", Handler: query.QueryServiceAgentHandler(serverCtx), }, + { + Method: http.MethodPost, + Path: "/query/service_app/:product", + Handler: query.QueryServiceAppHandler(serverCtx), + }, }, rest.WithPrefix("/api/v1"), ) diff --git a/app/user/cmd/api/internal/logic/agent/saveagentmembershipuserconfiglogic.go b/app/user/cmd/api/internal/logic/agent/saveagentmembershipuserconfiglogic.go index 7275b92..e02e2eb 100644 --- a/app/user/cmd/api/internal/logic/agent/saveagentmembershipuserconfiglogic.go +++ b/app/user/cmd/api/internal/logic/agent/saveagentmembershipuserconfiglogic.go @@ -2,7 +2,6 @@ package agent import ( "context" - "github.com/jinzhu/copier" "github.com/pkg/errors" "tydata-server/app/user/model" "tydata-server/common/ctxdata" @@ -41,10 +40,14 @@ func (l *SaveAgentMembershipUserConfigLogic) SaveAgentMembershipUserConfig(req * if err != nil && !errors.Is(err, model.ErrNotFound) { return err } - err = copier.Copy(&agentMembershipUserConfigModel, &req) - if err != nil { - return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "保存会员代理报告配置: %v", err) - } + //err = copier.Copy(&agentMembershipUserConfigModel, &req) + //if err != nil { + // return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "保存会员代理报告配置: %v", err) + //} + agentMembershipUserConfigModel.PriceRatio = req.PriceRatio + agentMembershipUserConfigModel.PriceIncreaseAmount = req.PriceIncreaseAmount + agentMembershipUserConfigModel.PriceRangeFrom = req.PriceRangeFrom + agentMembershipUserConfigModel.PriceRangeTo = req.PriceRangeTo if agentMembershipUserConfigModel == nil { agentMembershipUserConfigModel.UserId = userID agentMembershipUserConfigModel.AgentId = agentModel.Id diff --git a/app/user/cmd/api/internal/logic/product/getproductappbyenlogic.go b/app/user/cmd/api/internal/logic/product/getproductappbyenlogic.go new file mode 100644 index 0000000..4f5a49f --- /dev/null +++ b/app/user/cmd/api/internal/logic/product/getproductappbyenlogic.go @@ -0,0 +1,74 @@ +package product + +import ( + "context" + "github.com/Masterminds/squirrel" + "github.com/jinzhu/copier" + "github.com/pkg/errors" + "github.com/zeromicro/go-zero/core/mr" + "tydata-server/app/user/model" + "tydata-server/common/xerr" + + "tydata-server/app/user/cmd/api/internal/svc" + "tydata-server/app/user/cmd/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetProductAppByEnLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetProductAppByEnLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductAppByEnLogic { + return &GetProductAppByEnLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetProductAppByEnLogic) GetProductAppByEn(req *types.GetProductByEnRequest) (resp *types.ProductResponse, err error) { + productModel, err := l.svcCtx.ProductModel.FindOneByProductEn(l.ctx, req.ProductEn) + if err != nil { + return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "产品查询, 查找产品错误: %v", err) + } + + build := l.svcCtx.ProductFeatureModel.SelectBuilder().Where(squirrel.Eq{ + "product_id": productModel.Id, + }) + productFeatureAll, err := l.svcCtx.ProductFeatureModel.FindAll(l.ctx, build, "") + if err != nil { + return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "产品查询, 查找产品关联错误: %v", err) + } + var product types.Product + err = copier.Copy(&product, productModel) + if err != nil { + return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "用户信息, 用户信息结构体复制失败, %v", err) + } + mr.MapReduceVoid(func(source chan<- interface{}) { + for _, productFeature := range productFeatureAll { + source <- productFeature.FeatureId + } + }, func(item interface{}, writer mr.Writer[*model.Feature], cancel func(error)) { + id := item.(int64) + + feature, findFeatureErr := l.svcCtx.FeatureModel.FindOne(l.ctx, id) + if findFeatureErr != nil { + logx.WithContext(l.ctx).Errorf("产品查询, 查找关联feature错误: %d, err:%v", id, findFeatureErr) + return + } + if feature != nil && feature.Id > 0 { + writer.Write(feature) + } + }, func(pipe <-chan *model.Feature, cancel func(error)) { + for item := range pipe { + var feature types.Feature + _ = copier.Copy(&feature, item) + product.Features = append(product.Features, feature) + } + }) + + return &types.ProductResponse{Product: product}, nil +} diff --git a/app/user/cmd/api/internal/logic/query/queryserviceapplogic.go b/app/user/cmd/api/internal/logic/query/queryserviceapplogic.go new file mode 100644 index 0000000..0b544df --- /dev/null +++ b/app/user/cmd/api/internal/logic/query/queryserviceapplogic.go @@ -0,0 +1,30 @@ +package query + +import ( + "context" + + "tydata-server/app/user/cmd/api/internal/svc" + "tydata-server/app/user/cmd/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type QueryServiceAppLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewQueryServiceAppLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryServiceAppLogic { + return &QueryServiceAppLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *QueryServiceAppLogic) QueryServiceApp(req *types.QueryServiceReq) (resp *types.QueryServiceResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/app/user/cmd/api/internal/logic/query/queryservicelogic.go b/app/user/cmd/api/internal/logic/query/queryservicelogic.go index 9223005..aea27d0 100644 --- a/app/user/cmd/api/internal/logic/query/queryservicelogic.go +++ b/app/user/cmd/api/internal/logic/query/queryservicelogic.go @@ -40,30 +40,12 @@ func NewQueryServiceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Quer func (l *QueryServiceLogic) QueryService(req *types.QueryServiceReq) (resp *types.QueryServiceResp, err error) { if req.AgentIdentifier != "" { l.ctx = context.WithValue(l.ctx, "agentIdentifier", req.AgentIdentifier) - return l.PreprocessLogic(req, req.Product) + } else if req.App { + l.ctx = context.WithValue(l.ctx, "app", req.App) } return l.PreprocessLogic(req, req.Product) } -//func (l *QueryServiceLogic) agentParsing(req *types.QueryServiceReq) (*types.AgentIdentifier, error) { -// key, decodeErr := hex.DecodeString("8e3e7a2f60edb49221e953b9c029ed10") -// if decodeErr != nil { -// return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 获取AES密钥失败: %+v", decodeErr) -// } -// -// encrypted, err := crypto.AesDecryptURL(req.Product, key) -// if err != nil { -// return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, %v", err) -// } -// var agentIdentifier types.AgentIdentifier -// err = json.Unmarshal(encrypted, &agentIdentifier) -// if err != nil { -// return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务,反序列化失败 %v", err) -// } -// l.ctx = context.WithValue(l.ctx, "agent", req.Agent) -// return &agentIdentifier, nil -//} - var productProcessors = map[string]func(*QueryServiceLogic, *types.QueryServiceReq) (*types.QueryServiceResp, error){ "marriage": (*QueryServiceLogic).ProcessMarriageLogic, "homeservice": (*QueryServiceLogic).ProcessHomeServiceLogic, @@ -1387,7 +1369,8 @@ func (l *QueryServiceLogic) CacheData(params map[string]interface{}, Product str func (l *QueryServiceLogic) GetOrCreateUser(mobile string) (int64, error) { agentIdentifier, ok := l.ctx.Value("agentIdentifier").(string) - if !ok || agentIdentifier == "" { + app, appOk := l.ctx.Value("app").(bool) + if (!ok || agentIdentifier == "") && (!appOk || app == false) { // 不是代理查询 userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx) if getUidErr != nil { diff --git a/app/user/cmd/api/internal/types/types.go b/app/user/cmd/api/internal/types/types.go index 810eade..355e0cc 100644 --- a/app/user/cmd/api/internal/types/types.go +++ b/app/user/cmd/api/internal/types/types.go @@ -341,6 +341,7 @@ type QueryServiceReq struct { Product string `path:"product"` Data string `json:"data" validate:"required"` AgentIdentifier string `json:"agent_identifier,optional"` + App bool `json:"app,optional"` } type QueryServiceResp struct {