f
This commit is contained in:
@@ -36,6 +36,26 @@ var payload struct {
|
||||
OrderID int64 `json:"order_id"`
|
||||
}
|
||||
|
||||
// 仅通过异步回调回写结果的车辆接口 ApiID
|
||||
var asyncVehicleApiIDs = map[string]bool{
|
||||
"QCXG1U4U": true, // 车辆里程混合
|
||||
"QCXG3Y6B": true, // 车辆维保简版
|
||||
"QCXG3Z3L": true, // 车辆维保详细版
|
||||
"QCXGP00W": true, // 车辆出险详版
|
||||
}
|
||||
|
||||
func isAllAsyncVehicleQuery(responseData []service.APIResponseData) bool {
|
||||
if len(responseData) == 0 {
|
||||
return false
|
||||
}
|
||||
for _, r := range responseData {
|
||||
if !asyncVehicleApiIDs[r.ApiID] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (l *PaySuccessNotifyUserHandler) ProcessTask(ctx context.Context, t *asynq.Task) error {
|
||||
// 从任务的负载中解码数据
|
||||
if err := json.Unmarshal(t.Payload(), &payload); err != nil {
|
||||
@@ -152,7 +172,8 @@ func (l *PaySuccessNotifyUserHandler) ProcessTask(ctx context.Context, t *asynq.
|
||||
responseData = []service.APIResponseData{}
|
||||
} else {
|
||||
var processErr error
|
||||
responseData, processErr = l.svcCtx.ApiRequestService.ProcessRequests(decryptData, product.Id)
|
||||
// 传入订单号,用于在 ApiRequestService 中为异步车辆接口生成回调地址(return_url)
|
||||
responseData, processErr = l.svcCtx.ApiRequestService.ProcessRequests(decryptData, product.Id, order.OrderNo)
|
||||
if processErr != nil {
|
||||
return l.handleError(ctx, processErr, order, query)
|
||||
}
|
||||
@@ -160,18 +181,16 @@ func (l *PaySuccessNotifyUserHandler) ProcessTask(ctx context.Context, t *asynq.
|
||||
|
||||
// 计算成功模块的总成本价
|
||||
totalCostPrice := 0.0
|
||||
if responseData != nil {
|
||||
for _, item := range responseData {
|
||||
if item.Success {
|
||||
// 根据API ID查找功能模块
|
||||
feature, err := l.svcCtx.FeatureModel.FindOneByApiId(ctx, item.ApiID)
|
||||
if err != nil {
|
||||
logx.Errorf("查找功能模块失败, API ID: %s, 错误: %v", item.ApiID, err)
|
||||
continue
|
||||
}
|
||||
// 累加成本价
|
||||
totalCostPrice += feature.CostPrice
|
||||
for _, item := range responseData {
|
||||
if item.Success {
|
||||
// 根据API ID查找功能模块
|
||||
feature, err := l.svcCtx.FeatureModel.FindOneByApiId(ctx, item.ApiID)
|
||||
if err != nil {
|
||||
logx.Errorf("查找功能模块失败, API ID: %s, 错误: %v", item.ApiID, err)
|
||||
continue
|
||||
}
|
||||
// 累加成本价
|
||||
totalCostPrice += feature.CostPrice
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,11 +223,14 @@ func (l *PaySuccessNotifyUserHandler) ProcessTask(ctx context.Context, t *asynq.
|
||||
return l.handleError(ctx, err, order, query)
|
||||
}
|
||||
|
||||
query.QueryState = "success"
|
||||
updateQueryErr := l.svcCtx.QueryModel.UpdateWithVersion(ctx, nil, query)
|
||||
if updateQueryErr != nil {
|
||||
updateQueryErr = fmt.Errorf("修改查询状态失败: %v", updateQueryErr)
|
||||
return l.handleError(ctx, updateQueryErr, order, query)
|
||||
// 若当前产品全部为异步车辆接口(结果通过回调回写),则保持 pending,由回调再置为 success
|
||||
if !isAllAsyncVehicleQuery(responseData) {
|
||||
query.QueryState = "success"
|
||||
updateQueryErr := l.svcCtx.QueryModel.UpdateWithVersion(ctx, nil, query)
|
||||
if updateQueryErr != nil {
|
||||
updateQueryErr = fmt.Errorf("修改查询状态失败: %v", updateQueryErr)
|
||||
return l.handleError(ctx, updateQueryErr, order, query)
|
||||
}
|
||||
}
|
||||
|
||||
err = l.svcCtx.AgentService.AgentProcess(ctx, order)
|
||||
|
||||
Reference in New Issue
Block a user