This commit is contained in:
Mrx
2026-01-26 15:17:04 +08:00
parent 53a97aa04f
commit 38b275d019
24 changed files with 860 additions and 52 deletions

View File

@@ -11,6 +11,7 @@ import (
"regexp"
"strings"
paylogic "tydata-server/app/main/api/internal/logic/pay"
"tydata-server/app/main/api/internal/service"
"tydata-server/app/main/api/internal/svc"
"tydata-server/app/main/api/internal/types"
"tydata-server/app/main/model"
@@ -45,12 +46,13 @@ func (l *PaySuccessNotifyUserHandler) ProcessTask(ctx context.Context, t *asynq.
if err != nil {
return fmt.Errorf("无效的订单ID: %d, %v", payload.OrderID, err)
}
env := os.Getenv("ENV")
if order.Status != "paid" && env != "development" {
err = fmt.Errorf("无效的订单: %d", payload.OrderID)
// 必须已支付才处理:仅支付宝/微信/苹果回调或 pay_method=test 的异步流程会将订单标为 paid此处不再按 ENV 放宽
if order.Status != "paid" {
err = fmt.Errorf("无效的订单状态(非已支付): orderID=%d, status=%s", payload.OrderID, order.Status)
logx.Errorf("处理任务失败,原因: %v", err)
return asynq.SkipRetry
}
env := os.Getenv("ENV")
product, err := l.svcCtx.ProductModel.FindOne(ctx, order.ProductId)
if err != nil {
return fmt.Errorf("找不到相关产品: orderID: %d, productID: %d", payload.OrderID, order.ProductId)
@@ -141,11 +143,20 @@ func (l *PaySuccessNotifyUserHandler) ProcessTask(ctx context.Context, t *asynq.
decryptData = updatedDecryptData
}
}
// 调用API请求服务
responseData, err := l.svcCtx.ApiRequestService.ProcessRequests(decryptData, product.Id)
if err != nil {
return l.handleError(ctx, err, order, query)
// 调用API请求服务开发环境下不调用其它产品使用默认空报告
var responseData []service.APIResponseData
if env == "development" {
// 开发环境:生成仅包含基本信息的默认空报告,不调用外部 API
// 空报告模式生成空的报告数据跳过API调用
logx.Infof("空报告模式:订单 %s (ID: %s) 跳过API调用生成空报告", order.OrderNo, order.Id)
// 空数组,表示没有数据;与 json.Marshal 配合得到 []
responseData = []service.APIResponseData{}
} else {
var processErr error
responseData, processErr = l.svcCtx.ApiRequestService.ProcessRequests(decryptData, product.Id)
if processErr != nil {
return l.handleError(ctx, processErr, order, query)
}
}
// 计算成功模块的总成本价