feat:订单增加上游交易号
This commit is contained in:
parent
4219e20d30
commit
fe4d2d3977
|
|
@ -87,7 +87,7 @@ func closeOrder() {
|
||||||
}
|
}
|
||||||
orderIds = append(orderIds, orderInfo.Id)
|
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)
|
//utils.Log(nil, "主动查询订单支付状态,回调下游", notifyResult)
|
||||||
if notifyResult.ErrCode != errorcode.Success {
|
if notifyResult.ErrCode != errorcode.Success {
|
||||||
utils.Log(nil, "关闭订单,回调下游失败", fmt.Sprintf("%#v", notifyResult))
|
utils.Log(nil, "关闭订单,回调下游失败", fmt.Sprintf("%#v", notifyResult))
|
||||||
|
|
@ -305,7 +305,7 @@ func queryRefundOrder() {
|
||||||
msg = "退款失败"
|
msg = "退款失败"
|
||||||
}
|
}
|
||||||
// 回调通知下游 todo
|
// 回调通知下游 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)
|
//utils.Log(nil, "主动查询退款订单状态,回调下游", notifyResult)
|
||||||
if notifyResult.ErrCode != errorcode.Success {
|
if notifyResult.ErrCode != errorcode.Success {
|
||||||
utils.Log(nil, "查询退款订单状态,回调下游失败", notifyResult)
|
utils.Log(nil, "查询退款订单状态,回调下游失败", notifyResult)
|
||||||
|
|
|
||||||
|
|
@ -59,13 +59,39 @@ func PsbcCallback(c *gin.Context) {
|
||||||
}
|
}
|
||||||
psbcConfig.AppID = payChannelModel.AppId
|
psbcConfig.AppID = payChannelModel.AppId
|
||||||
|
|
||||||
reqTraceId, amountTotal, payerTotal, status, err := paymentService.PsbcVerifyAndParseNotify(bodyStr, psbcConfig)
|
result, err := paymentService.PsbcVerifyAndParseNotify(bodyStr, psbcConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(c, "PsbcCallback-回调数据验签失败", err.Error())
|
logger.Error(c, "PsbcCallback-回调数据验签失败", err.Error())
|
||||||
c.String(http.StatusBadRequest, "%s", "fail")
|
c.String(http.StatusBadRequest, "%s", "fail")
|
||||||
return
|
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))
|
logger.Info(c, "PsbcCallback-解析邮储回调结果", fmt.Sprintf("reqTraceId:%s, amountTotal:%d, payerTotal:%d, status:%s", reqTraceId, amountTotal, payerTotal, status))
|
||||||
|
|
||||||
var orderStatus int
|
var orderStatus int
|
||||||
|
|
@ -93,7 +119,7 @@ func PsbcCallback(c *gin.Context) {
|
||||||
return
|
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)
|
notifyResultJson, _ := json.Marshal(notifyResult)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ type Orders struct {
|
||||||
UpdateTime time.Time `xorm:"'update_time' timestamp updated"`
|
UpdateTime time.Time `xorm:"'update_time' timestamp updated"`
|
||||||
Status int `xorm:"'status' TINYINT"`
|
Status int `xorm:"'status' TINYINT"`
|
||||||
DeleteTime time.Time `xorm:"'delete_time' timestamp deleted"`
|
DeleteTime time.Time `xorm:"'delete_time' timestamp deleted"`
|
||||||
|
TransactionId string `xorm:"'transaction_id' varchar(50)"` // 支付成功后返回的第三方订单号
|
||||||
}
|
}
|
||||||
|
|
||||||
type OrdersBackendList struct {
|
type OrdersBackendList struct {
|
||||||
|
|
|
||||||
|
|
@ -240,6 +240,7 @@ func (w *Pay) Refund() {
|
||||||
RefundOrderId: w.Order.Id,
|
RefundOrderId: w.Order.Id,
|
||||||
RefundReason: w.PayParam.Desc,
|
RefundReason: w.PayParam.Desc,
|
||||||
RefundAmount: int64(w.PayParam.Amount),
|
RefundAmount: int64(w.PayParam.Amount),
|
||||||
|
TransactionId: w.Order.TransactionId,
|
||||||
}
|
}
|
||||||
if refundFunc, ok = RefundWayList[w.PayParam.Channel.ChannelType]; !ok {
|
if refundFunc, ok = RefundWayList[w.PayParam.Channel.ChannelType]; !ok {
|
||||||
w.PayCode = errorcode.PayChannelNotBuild
|
w.PayCode = errorcode.PayChannelNotBuild
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ func OrderQueryAndNotify(ctx context.Context, orderInfo *ordersmodel.OrdersLeftP
|
||||||
msg = "订单关闭"
|
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)
|
//utils.Log(nil, "主动查询订单支付状态,回调下游", notifyResult)
|
||||||
if notifyResult.ErrCode != errorcode.Success {
|
if notifyResult.ErrCode != errorcode.Success {
|
||||||
utils.Log(nil, "主动查询订单支付状态,回调下游失败", fmt.Sprintf("%+v", notifyResult))
|
utils.Log(nil, "主动查询订单支付状态,回调下游失败", fmt.Sprintf("%+v", notifyResult))
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,13 @@ type OrderNotify struct {
|
||||||
Code int
|
Code int
|
||||||
app *appmodel.App
|
app *appmodel.App
|
||||||
|
|
||||||
OrderId int64
|
OrderId int64
|
||||||
Status int //订单状态
|
Status int //订单状态
|
||||||
ActualAmount int // 支付上游返回的订单金额,单位为分。该参数的值为支付时传入的
|
ActualAmount int // 支付上游返回的订单金额,单位为分。该参数的值为支付时传入的
|
||||||
PayerTotal int // 用户实际支付金额,单位为分
|
PayerTotal int // 用户实际支付金额,单位为分
|
||||||
Msg string
|
Msg string
|
||||||
CompleteTime time.Time
|
TransactionId string // 支付成功后返回的第三方订单号
|
||||||
|
CompleteTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type OrderNotifyResp struct {
|
type OrderNotifyResp struct {
|
||||||
|
|
@ -57,14 +58,15 @@ type OrderNotifySendContent struct {
|
||||||
|
|
||||||
// actualAmount 订单支付总金额,支付时传入
|
// actualAmount 订单支付总金额,支付时传入
|
||||||
// payerTotal 用户实际支付金额,(有优惠券的情况下,payerTotal = 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{
|
orderNotify := &OrderNotify{
|
||||||
OrderId: orderId,
|
OrderId: orderId,
|
||||||
Status: Status,
|
Status: Status,
|
||||||
ActualAmount: actualAmount,
|
ActualAmount: actualAmount,
|
||||||
Msg: msg,
|
Msg: msg,
|
||||||
Code: code,
|
Code: code,
|
||||||
PayerTotal: payerTotal,
|
PayerTotal: payerTotal,
|
||||||
|
TransactionId: transactionId,
|
||||||
}
|
}
|
||||||
return orderNotify.Handle()
|
return orderNotify.Handle()
|
||||||
}
|
}
|
||||||
|
|
@ -190,6 +192,7 @@ func (o *OrderNotify) updateOrder() {
|
||||||
o.order.Status = o.Status
|
o.order.Status = o.Status
|
||||||
o.order.ActualAmount = o.ActualAmount
|
o.order.ActualAmount = o.ActualAmount
|
||||||
o.order.PayerTotal = o.PayerTotal
|
o.order.PayerTotal = o.PayerTotal
|
||||||
|
o.order.TransactionId = o.TransactionId
|
||||||
o.Code = services.OrderUpdate(o.order, "status")
|
o.Code = services.OrderUpdate(o.order, "status")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ func ALiCallBack(notifyReq gopay.BodyMap, aliConfig AliPay) error {
|
||||||
return errors.New("订单状态异常,无法进行后续回调")
|
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)
|
merchantCallback, _ := json.Marshal(res)
|
||||||
// 记录日志
|
// 记录日志
|
||||||
go func() {
|
go func() {
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,6 @@ func (c *Client) OrderQuery(orderNo string) (*OrderQueryResponse, error) {
|
||||||
return nil, fmt.Errorf("加密请求失败: %v", err)
|
return nil, fmt.Errorf("加密请求失败: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
BusiMainId = "202607301754241710448735"
|
|
||||||
|
|
||||||
encryptedBytes, _ := json.Marshal(encryptedReq)
|
encryptedBytes, _ := json.Marshal(encryptedReq)
|
||||||
url := c.cfg.OrderHost + c.cfg.MerchantId + ".htm?partnerTxSriNo=" + BusiMainId
|
url := c.cfg.OrderHost + c.cfg.MerchantId + ".htm?partnerTxSriNo=" + BusiMainId
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,16 +78,19 @@ type RefundRequest struct {
|
||||||
|
|
||||||
// RefundResponse 退款响应
|
// RefundResponse 退款响应
|
||||||
type RefundResponse struct {
|
type RefundResponse struct {
|
||||||
RespCode string `json:"code"`
|
MchtNo string `json:"mchtNo"`
|
||||||
RespMsg string `json:"respMsg"`
|
ReqDate string `json:"reqDate"`
|
||||||
|
ReqTraceId string `json:"reqTraceId"`
|
||||||
RespCd string `json:"respCd"`
|
RespCd string `json:"respCd"`
|
||||||
TxnCode string `json:"txnCode"`
|
RespCode string `json:"respCode"`
|
||||||
|
RespDesc string `json:"respDesc"`
|
||||||
|
RespMsg string `json:"respMsg"`
|
||||||
SourceId string `json:"sourceId"`
|
SourceId string `json:"sourceId"`
|
||||||
ReqTraceId string `json:"ReqTraceId"`
|
Success bool `json:"success"`
|
||||||
|
TxnAmt string `json:"txnAmt"`
|
||||||
|
TxnCode string `json:"txnCode"`
|
||||||
RefundOrderNo string `json:"refundOrderNo"`
|
RefundOrderNo string `json:"refundOrderNo"`
|
||||||
RefundOrderSta string `json:"refundOrderSta"`
|
RefundOrderSta string `json:"refundOrderSta"`
|
||||||
MchtNo string `json:"mchtNo"`
|
|
||||||
TxnAmt string `json:"txnAmt"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// BillQueryRequest 对账单查询请求
|
// BillQueryRequest 对账单查询请求
|
||||||
|
|
|
||||||
|
|
@ -187,36 +187,14 @@ func PsbcCloseOrder(ctx context.Context, orderCloseRequest OrderCloseRequest) (O
|
||||||
}, nil
|
}, 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)
|
psbcClient := PsbcInitClient(psbcConfig)
|
||||||
|
|
||||||
result, err := psbcClient.VerifyAndParseNotify(rawBody)
|
result, err = psbcClient.VerifyAndParseNotify(rawBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(context.Background(), "PsbcVerifyAndParseNotify 发生错误", fmt.Sprintf("验签解密失败,错误信息:%s", err.Error()))
|
logger.Error(context.Background(), "PsbcVerifyAndParseNotify 发生错误", fmt.Sprintf("验签解密失败,错误信息:%s", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if result.TxnAmt != "" {
|
return result, nil
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -214,7 +214,7 @@ func WxPayCallBack(notifyReq *wechat.V3NotifyReq, wxConfig WxPay) error {
|
||||||
|
|
||||||
// 触发下游回调的格式
|
// 触发下游回调的格式
|
||||||
orderId, _ := strconv.Atoi(CallBackInfo.OutTradeNo)
|
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)
|
merchantCallback, _ := json.Marshal(res)
|
||||||
// 记录日志
|
// 记录日志
|
||||||
go func() {
|
go func() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue