fix
This commit is contained in:
@@ -2,10 +2,12 @@ package pay
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"jnc-server/app/main/api/internal/svc"
|
||||
"jnc-server/app/main/api/internal/types"
|
||||
"jnc-server/common/xerr"
|
||||
"jnc-server/pkg/lzkit/lzUtils"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -38,12 +40,61 @@ func (l *PaymentCheckLogic) PaymentCheck(req *types.PaymentCheckReq) (resp *type
|
||||
Status: order.Status,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
// 查询订单(包括代理订单)
|
||||
order, err := l.svcCtx.OrderModel.FindOneByOrderNo(l.ctx, req.OrderNo)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询订单失败: %v", err)
|
||||
}
|
||||
|
||||
// 如果订单状态是 pending 且支付平台是易支付,主动查询易支付订单状态
|
||||
if order.Status == "pending" && order.PaymentPlatform == "easypay_alipay" {
|
||||
// 检查易支付服务是否启用
|
||||
if l.svcCtx.EasyPayService != nil {
|
||||
// 主动查询易支付订单状态
|
||||
queryResp, queryErr := l.svcCtx.EasyPayService.QueryOrderStatus(l.ctx, req.OrderNo)
|
||||
if queryErr != nil {
|
||||
logx.Errorf("主动查询易支付订单状态失败,订单号: %s, 错误: %v", req.OrderNo, queryErr)
|
||||
// 查询失败不影响返回,继续返回当前订单状态
|
||||
} else {
|
||||
// 如果易支付返回订单已支付(status == 1),更新本地订单状态
|
||||
if queryResp.Status == 1 {
|
||||
logx.Infof("主动查询发现易支付订单已支付,订单号: %s,开始更新订单状态", req.OrderNo)
|
||||
|
||||
// 重新查询订单(获取最新版本号)
|
||||
order, err = l.svcCtx.OrderModel.FindOneByOrderNo(l.ctx, req.OrderNo)
|
||||
if err != nil {
|
||||
logx.Errorf("更新订单状态前重新查询订单失败: %v", err)
|
||||
} else if order.Status == "pending" {
|
||||
// 更新订单状态
|
||||
order.Status = "paid"
|
||||
order.PayTime = lzUtils.TimeToNullTime(time.Now())
|
||||
if queryResp.TradeNo != "" {
|
||||
order.PlatformOrderId = lzUtils.StringToNullString(queryResp.TradeNo)
|
||||
}
|
||||
|
||||
if updateErr := l.svcCtx.OrderModel.UpdateWithVersion(l.ctx, nil, order); updateErr != nil {
|
||||
logx.Errorf("主动查询后更新订单状态失败: %v", updateErr)
|
||||
} else {
|
||||
logx.Infof("主动查询后成功更新订单状态为已支付,订单号: %s", req.OrderNo)
|
||||
|
||||
// 发送异步任务处理后续流程
|
||||
if asyncErr := l.svcCtx.AsynqService.SendQueryTask(order.Id); asyncErr != nil {
|
||||
logx.Errorf("主动查询后发送异步任务失败: %v", asyncErr)
|
||||
}
|
||||
|
||||
// 返回更新后的状态
|
||||
return &types.PaymentCheckResp{
|
||||
Type: "query",
|
||||
Status: "paid",
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &types.PaymentCheckResp{
|
||||
Type: "query",
|
||||
Status: order.Status,
|
||||
|
||||
Reference in New Issue
Block a user