|
|
@ -228,14 +228,15 @@ func Close(outTradeNo string) error { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
//const CALLBACK_REFUND_URL = "https://api.ouxuanhudong.com/PcClient/common/WeChatOauthCtl/callbackRefund"
|
|
|
|
const CallbackRefundUrl = "https://api.ouxuanhudong.com/PcClient/common/WeChatOauthCtl/callbackRefund" |
|
|
|
|
|
|
|
func Refund(reason, outTradeNo string) (*pay.RefundResponse, error) { |
|
|
|
func Refund(reason, outTradeNo string) (map[string]string, error) { |
|
|
|
userOrder := new(models.UserOrder) |
|
|
|
exist, err := userOrder.GetByOutTradeNo(outTradeNo) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
if !exist { |
|
|
|
return nil, fmt.Errorf("订单不存在") |
|
|
|
} |
|
|
@ -243,28 +244,28 @@ func Refund(reason, outTradeNo string) (*pay.RefundResponse, error) { |
|
|
|
|
|
|
|
outRefundNo := utils.RandomStr(64) |
|
|
|
nonceStr := utils.RandomStr(32) |
|
|
|
res, err := pay.Refund2(client, &pay.RefundRequest{ |
|
|
|
TransactionId: "", |
|
|
|
OutTradeNo: outTradeNo, |
|
|
|
OutRefundNo: outRefundNo, |
|
|
|
TotalFee: userOrder.TotalFee, |
|
|
|
RefundFee: userOrder.TotalFee, |
|
|
|
NonceStr: nonceStr, |
|
|
|
SignType: pay_core.SignType_MD5, |
|
|
|
RefundFeeType: "CNY", |
|
|
|
RefundDesc: reason, |
|
|
|
}) |
|
|
|
body := make(map[string]string, 0) |
|
|
|
body["out_trade_no"] = outTradeNo |
|
|
|
body["out_refund_no"] = outRefundNo |
|
|
|
body["total_fee"] = fmt.Sprint(userOrder.TotalFee) |
|
|
|
body["refund_fee"] = fmt.Sprint(userOrder.TotalFee) |
|
|
|
body["nonce_str"] = nonceStr |
|
|
|
body["sign_type"] = pay_core.SignType_MD5 |
|
|
|
body["refund_desc"] = reason |
|
|
|
body["notify_url"] = CallbackRefundUrl |
|
|
|
|
|
|
|
res, err := pay.Refund(client, body) |
|
|
|
//
|
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
userOrder.Status = 3 |
|
|
|
_, err = userOrder.UpdateStatusByOutTradeNo(outTradeNo, userOrder.Status) |
|
|
|
_, err = models.Update(userOrder.Id, userOrder, "status") |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
PutOrderDelayQueue(userOrder) // 退款查询
|
|
|
|
go PutOrderDelayQueue(userOrder) // 退款查询
|
|
|
|
return res, nil |
|
|
|
} |
|
|
|
|
|
|
|