feat:订单增加上游交易号

This commit is contained in:
wolter 2026-08-20 20:09:29 +08:00
parent 4219e20d30
commit fe4d2d3977
11 changed files with 63 additions and 53 deletions

View File

@ -87,7 +87,7 @@ func closeOrder() {
}
orderIds = append(orderIds, orderInfo.Id)
// 回调通知下游
notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, response.Code, common.ORDER_STATUS_CLOSE, 0, 0, "长时间未支付关闭订单")
notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, response.Code, common.ORDER_STATUS_CLOSE, 0, 0, "长时间未支付关闭订单", "")
//utils.Log(nil, "主动查询订单支付状态,回调下游", notifyResult)
if notifyResult.ErrCode != errorcode.Success {
utils.Log(nil, "关闭订单,回调下游失败", fmt.Sprintf("%#v", notifyResult))
@ -305,7 +305,7 @@ func queryRefundOrder() {
msg = "退款失败"
}
// 回调通知下游 todo
notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, result.Code, status, int(result.Result.RefundFee), int(result.Result.RefundFee), msg)
notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, result.Code, status, int(result.Result.RefundFee), int(result.Result.RefundFee), msg, result.Result.TransactionId)
//utils.Log(nil, "主动查询退款订单状态,回调下游", notifyResult)
if notifyResult.ErrCode != errorcode.Success {
utils.Log(nil, "查询退款订单状态,回调下游失败", notifyResult)

View File

@ -59,13 +59,39 @@ func PsbcCallback(c *gin.Context) {
}
psbcConfig.AppID = payChannelModel.AppId
reqTraceId, amountTotal, payerTotal, status, err := paymentService.PsbcVerifyAndParseNotify(bodyStr, psbcConfig)
result, err := paymentService.PsbcVerifyAndParseNotify(bodyStr, psbcConfig)
if err != nil {
logger.Error(c, "PsbcCallback-回调数据验签失败", err.Error())
c.String(http.StatusBadRequest, "%s", "fail")
return
}
reqTraceId := result.ReqTraceId
var amountTotal int64
var payerTotal int64
var status string
if result.TxnAmt != "" {
amountFloat, err := strconv.ParseFloat(result.TxnAmt, 64)
if err == nil {
amountTotal = int64(amountFloat * 100)
payerTotal = amountTotal
}
}
orderSta := ""
if result.OrderSta != "" {
orderSta = result.OrderSta
}
switch orderSta {
case "03":
status = "SUCCESS"
case "04", "05":
status = "FAIL"
default:
status = "NOTPAY"
}
logger.Info(c, "PsbcCallback-解析邮储回调结果", fmt.Sprintf("reqTraceId:%s, amountTotal:%d, payerTotal:%d, status:%s", reqTraceId, amountTotal, payerTotal, status))
var orderStatus int
@ -93,7 +119,7 @@ func PsbcCallback(c *gin.Context) {
return
}
notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderId, errCode, orderStatus, int(amountTotal), int(payerTotal), msg)
notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderId, errCode, orderStatus, int(amountTotal), int(payerTotal), msg, result.OrderNo)
notifyResultJson, _ := json.Marshal(notifyResult)
go func() {

View File

@ -31,6 +31,7 @@ type Orders struct {
UpdateTime time.Time `xorm:"'update_time' timestamp updated"`
Status int `xorm:"'status' TINYINT"`
DeleteTime time.Time `xorm:"'delete_time' timestamp deleted"`
TransactionId string `xorm:"'transaction_id' varchar(50)"` // 支付成功后返回的第三方订单号
}
type OrdersBackendList struct {

View File

@ -240,6 +240,7 @@ func (w *Pay) Refund() {
RefundOrderId: w.Order.Id,
RefundReason: w.PayParam.Desc,
RefundAmount: int64(w.PayParam.Amount),
TransactionId: w.Order.TransactionId,
}
if refundFunc, ok = RefundWayList[w.PayParam.Channel.ChannelType]; !ok {
w.PayCode = errorcode.PayChannelNotBuild

View File

@ -79,7 +79,7 @@ func OrderQueryAndNotify(ctx context.Context, orderInfo *ordersmodel.OrdersLeftP
msg = "订单关闭"
}
// 回调通知下游
notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, result.Code, status, int(result.Result.AmountTotal), int(result.Result.PayerTotal), msg)
notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, result.Code, status, int(result.Result.AmountTotal), int(result.Result.PayerTotal), msg, result.Result.TransactionId)
//utils.Log(nil, "主动查询订单支付状态,回调下游", notifyResult)
if notifyResult.ErrCode != errorcode.Success {
utils.Log(nil, "主动查询订单支付状态,回调下游失败", fmt.Sprintf("%+v", notifyResult))

View File

@ -29,6 +29,7 @@ type OrderNotify struct {
ActualAmount int // 支付上游返回的订单金额,单位为分。该参数的值为支付时传入的
PayerTotal int // 用户实际支付金额,单位为分
Msg string
TransactionId string // 支付成功后返回的第三方订单号
CompleteTime time.Time
}
@ -57,7 +58,7 @@ type OrderNotifySendContent struct {
// actualAmount 订单支付总金额,支付时传入
// payerTotal 用户实际支付金额有优惠券的情况下payerTotal = actualAmount - 优惠金额)
func NewOrderNotifyWithHandle(orderId int64, code int, Status int, actualAmount int, payerTotal int, msg string) *OrderNotifyResp {
func NewOrderNotifyWithHandle(orderId int64, code int, Status int, actualAmount int, payerTotal int, msg string, transactionId string) *OrderNotifyResp {
orderNotify := &OrderNotify{
OrderId: orderId,
Status: Status,
@ -65,6 +66,7 @@ func NewOrderNotifyWithHandle(orderId int64, code int, Status int, actualAmount
Msg: msg,
Code: code,
PayerTotal: payerTotal,
TransactionId: transactionId,
}
return orderNotify.Handle()
}
@ -190,6 +192,7 @@ func (o *OrderNotify) updateOrder() {
o.order.Status = o.Status
o.order.ActualAmount = o.ActualAmount
o.order.PayerTotal = o.PayerTotal
o.order.TransactionId = o.TransactionId
o.Code = services.OrderUpdate(o.order, "status")
return
}

View File

@ -197,7 +197,7 @@ func ALiCallBack(notifyReq gopay.BodyMap, aliConfig AliPay) error {
return errors.New("订单状态异常,无法进行后续回调")
}
res := thirdpay_notify.NewOrderNotifyWithHandle(int64(orderId), errCode, orderStatus, amountTotal, payerTotal, msg)
res := thirdpay_notify.NewOrderNotifyWithHandle(int64(orderId), errCode, orderStatus, amountTotal, payerTotal, msg, notifyReq.Get("trade_no"))
merchantCallback, _ := json.Marshal(res)
// 记录日志
go func() {

View File

@ -48,8 +48,6 @@ func (c *Client) OrderQuery(orderNo string) (*OrderQueryResponse, error) {
return nil, fmt.Errorf("加密请求失败: %v", err)
}
BusiMainId = "202607301754241710448735"
encryptedBytes, _ := json.Marshal(encryptedReq)
url := c.cfg.OrderHost + c.cfg.MerchantId + ".htm?partnerTxSriNo=" + BusiMainId

View File

@ -78,16 +78,19 @@ type RefundRequest struct {
// RefundResponse 退款响应
type RefundResponse struct {
RespCode string `json:"code"`
RespMsg string `json:"respMsg"`
MchtNo string `json:"mchtNo"`
ReqDate string `json:"reqDate"`
ReqTraceId string `json:"reqTraceId"`
RespCd string `json:"respCd"`
TxnCode string `json:"txnCode"`
RespCode string `json:"respCode"`
RespDesc string `json:"respDesc"`
RespMsg string `json:"respMsg"`
SourceId string `json:"sourceId"`
ReqTraceId string `json:"ReqTraceId"`
Success bool `json:"success"`
TxnAmt string `json:"txnAmt"`
TxnCode string `json:"txnCode"`
RefundOrderNo string `json:"refundOrderNo"`
RefundOrderSta string `json:"refundOrderSta"`
MchtNo string `json:"mchtNo"`
TxnAmt string `json:"txnAmt"`
}
// BillQueryRequest 对账单查询请求

View File

@ -187,36 +187,14 @@ func PsbcCloseOrder(ctx context.Context, orderCloseRequest OrderCloseRequest) (O
}, nil
}
func PsbcVerifyAndParseNotify(rawBody string, psbcConfig PsbcPay) (reqTraceId string, amountTotal int64, payerTotal int64, status string, err error) {
func PsbcVerifyAndParseNotify(rawBody string, psbcConfig PsbcPay) (result *psbc.YouChuOrderNotifyRequest, err error) {
psbcClient := PsbcInitClient(psbcConfig)
result, err := psbcClient.VerifyAndParseNotify(rawBody)
result, err = psbcClient.VerifyAndParseNotify(rawBody)
if err != nil {
logger.Error(context.Background(), "PsbcVerifyAndParseNotify 发生错误", fmt.Sprintf("验签解密失败,错误信息:%s", err.Error()))
return
}
if result.TxnAmt != "" {
amountFloat, err := strconv.ParseFloat(result.TxnAmt, 64)
if err == nil {
amountTotal = int64(amountFloat * 100)
payerTotal = amountTotal
}
}
orderSta := ""
if result.OrderSta != "" {
orderSta = result.OrderSta
}
switch orderSta {
case "03":
status = "SUCCESS"
case "04", "05":
status = "FAIL"
default:
status = "NOTPAY"
}
return result.ReqTraceId, amountTotal, payerTotal, status, nil
return result, nil
}

View File

@ -214,7 +214,7 @@ func WxPayCallBack(notifyReq *wechat.V3NotifyReq, wxConfig WxPay) error {
// 触发下游回调的格式
orderId, _ := strconv.Atoi(CallBackInfo.OutTradeNo)
res := thirdpay_notify.NewOrderNotifyWithHandle(int64(orderId), errCode, orderStatus, int(CallBackInfo.Amount.Total), int(CallBackInfo.Amount.PayerTotal), msg)
res := thirdpay_notify.NewOrderNotifyWithHandle(int64(orderId), errCode, orderStatus, int(CallBackInfo.Amount.Total), int(CallBackInfo.Amount.PayerTotal), msg, CallBackInfo.TransactionId)
merchantCallback, _ := json.Marshal(res)
// 记录日志
go func() {