前台,回调增加支付金额,记录回调日志

This commit is contained in:
wolter 2024-08-14 13:37:27 +08:00
parent 6a977db12e
commit 2035af1580
2 changed files with 40 additions and 23 deletions

View File

@ -182,7 +182,7 @@ func queryOrder() {
case "REFUND":
// 退款 订单支付完成才能退款,所以支付单的状态是支付完成
status = common.ORDER_STATUS_PAYED
msg = "支付成功"
msg = "已支付,发生退款"
case "NOTPAY":
// 未支付
return
@ -191,7 +191,7 @@ func queryOrder() {
status = common.ORDER_STATUS_CLOSE
msg = "订单关闭"
}
// 回调通知下游 todo
// 回调通知下游
notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, status, int(result.Result.PayerTotal), msg)
//utils.Log(nil, "主动查询订单支付状态,回调下游", notifyResult)
if notifyResult.ErrCode != errorcode.Success {

View File

@ -37,16 +37,18 @@ type OrderNotifyResp struct {
}
type OrderNotifySendContent struct {
OrderId int64 `json:"order_id"`
OutTradeNo string `json:"out_trade_no"`
CompleteTime time.Time `json:"complete_time"`
OrderType int `json:"order-type"`
Status int `json:"status"`
Msg string `json:"msg"`
ErrCode int `json:"err_code"`
AppId int64 `json:"app_id"`
ChannelId int64 `json:"channel_id"`
MerchantId int64 `json:"merchant_id"`
OrderId int64 `json:"order_id"`
OutTradeNo string `json:"out_trade_no"`
CompleteTime string `json:"complete_time"`
OrderType int `json:"order_type"`
Status int `json:"status"`
Msg string `json:"msg"`
//ErrCode int `json:"err_code"`
AppId int64 `json:"app_id"`
ChannelId int64 `json:"channel_id"`
//MerchantId int64 `json:"merchant_id"`
Amount int `json:"amount"`
PayerTotal int `json:"payer_total"`
}
func NewOrderNotifyWithHandle(orderId int64, Status int, actualAmount int, msg string) *OrderNotifyResp {
@ -82,6 +84,7 @@ func (o *OrderNotify) Handle() (res *OrderNotifyResp) {
if o.Code != errorcode.Success {
return o.NotifyRespFail(o.Code)
}
o.CompleteTime = time.Now()
o.sendNotify(o.setBody())
if o.Code != errorcode.Success {
return o.NotifyRespFail(o.Code)
@ -101,22 +104,34 @@ func (o *OrderNotify) sendNotify(body *OrderNotifySendContent) {
return
}
var callbackStatus = common.STATUS_ENABLE
var response string
bodyByte, _ := sonic.Marshal(&body)
headers := make(map[string]string, 1)
headers["Content-Type"] = "application/json"
resByte, err := httpclient.FastHttpPost(o.app.NotifyUrl, headers, bodyByte, 0)
type errResp struct {
Url string `json:"url,omitempty"`
Response string `json:"response,omitempty"`
Error string `json:"error,omitempty"`
}
var errRespObj = errResp{}
// 处理错误
if err != nil || string(resByte) != "success" {
o.Code = errorcode.NotifySendFail
callbackStatus = common.STATUS_DISABLED
if err != nil {
response = " | url=" + o.app.NotifyUrl + " | error=" + err.Error()
} else {
response = " | url=" + o.app.NotifyUrl
errRespObj.Error = err.Error()
}
errRespObj.Url = o.app.NotifyUrl
utils.Log(nil, "回调通知失败error", string(resByte), err, errRespObj)
}
response = "response=" + string(resByte) + response
if len(resByte) > 255 {
resByte = resByte[0:255]
}
errRespObj.Response = string(resByte)
b, _ := sonic.Marshal(errRespObj)
// 记录回调日志
go func(orderId int64, status int, request, response string) {
repo := data.NewOrderCallbackLogRepo(ordercallbacklogmodel.GetInstance().GetDb())
@ -130,7 +145,7 @@ func (o *OrderNotify) sendNotify(body *OrderNotifySendContent) {
if insertErr != nil {
utils.Log(nil, "回调写入日志error", insertErr)
}
}(o.OrderId, callbackStatus, string(bodyByte), response)
}(o.OrderId, callbackStatus, string(bodyByte), string(b))
return
}
@ -138,14 +153,16 @@ func (o *OrderNotify) setBody() *OrderNotifySendContent {
return &OrderNotifySendContent{
OrderId: o.OrderId,
OutTradeNo: o.order.OutTradeNo,
CompleteTime: o.CompleteTime,
CompleteTime: o.CompleteTime.Format("2006-01-02 15:04:05"),
Status: o.order.Status,
OrderType: o.order.OrderType,
Msg: o.Msg,
ErrCode: o.Status,
AppId: o.order.AppId,
ChannelId: o.order.PayChannelId,
MerchantId: o.order.MerchantId,
//ErrCode: o.Status,
AppId: o.order.AppId,
ChannelId: o.order.PayChannelId,
//MerchantId: o.order.MerchantId,
Amount: o.order.Amount,
PayerTotal: o.order.PayerTotal,
}
}