新增APP查询页

This commit is contained in:
liangzai 2025-03-14 02:56:27 +08:00
parent ece4b5d1b1
commit 0e6cb95499
11 changed files with 209 additions and 33 deletions

View File

@ -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)
}

View File

@ -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
@ -79,3 +80,4 @@ service main {
@handler querySingleTest
post /query/single/test (QuerySingleTestReq) returns (QuerySingleTestResp)
}

View File

@ -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"`
}

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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"),
)

View File

@ -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

View File

@ -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
}

View File

@ -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
}

View File

@ -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 {

View File

@ -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 {