前台,回调增加支付金额,记录回调日志
This commit is contained in:
		
							parent
							
								
									6a977db12e
								
							
						
					
					
						commit
						2035af1580
					
				| 
						 | 
					@ -182,7 +182,7 @@ func queryOrder() {
 | 
				
			||||||
					case "REFUND":
 | 
										case "REFUND":
 | 
				
			||||||
						// 退款	订单支付完成才能退款,所以支付单的状态是支付完成
 | 
											// 退款	订单支付完成才能退款,所以支付单的状态是支付完成
 | 
				
			||||||
						status = common.ORDER_STATUS_PAYED
 | 
											status = common.ORDER_STATUS_PAYED
 | 
				
			||||||
						msg = "支付成功"
 | 
											msg = "已支付,发生退款"
 | 
				
			||||||
					case "NOTPAY":
 | 
										case "NOTPAY":
 | 
				
			||||||
						// 未支付
 | 
											// 未支付
 | 
				
			||||||
						return
 | 
											return
 | 
				
			||||||
| 
						 | 
					@ -191,7 +191,7 @@ func queryOrder() {
 | 
				
			||||||
						status = common.ORDER_STATUS_CLOSE
 | 
											status = common.ORDER_STATUS_CLOSE
 | 
				
			||||||
						msg = "订单关闭"
 | 
											msg = "订单关闭"
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					// 回调通知下游	todo
 | 
										// 回调通知下游
 | 
				
			||||||
					notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, status, int(result.Result.PayerTotal), msg)
 | 
										notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, status, int(result.Result.PayerTotal), msg)
 | 
				
			||||||
					//utils.Log(nil, "主动查询订单支付状态,回调下游", notifyResult)
 | 
										//utils.Log(nil, "主动查询订单支付状态,回调下游", notifyResult)
 | 
				
			||||||
					if notifyResult.ErrCode != errorcode.Success {
 | 
										if notifyResult.ErrCode != errorcode.Success {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -37,16 +37,18 @@ type OrderNotifyResp struct {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type OrderNotifySendContent struct {
 | 
					type OrderNotifySendContent struct {
 | 
				
			||||||
	OrderId      int64     `json:"order_id"`
 | 
						OrderId      int64  `json:"order_id"`
 | 
				
			||||||
	OutTradeNo   string    `json:"out_trade_no"`
 | 
						OutTradeNo   string `json:"out_trade_no"`
 | 
				
			||||||
	CompleteTime time.Time `json:"complete_time"`
 | 
						CompleteTime string `json:"complete_time"`
 | 
				
			||||||
	OrderType    int       `json:"order-type"`
 | 
						OrderType    int    `json:"order_type"`
 | 
				
			||||||
	Status       int       `json:"status"`
 | 
						Status       int    `json:"status"`
 | 
				
			||||||
	Msg          string    `json:"msg"`
 | 
						Msg          string `json:"msg"`
 | 
				
			||||||
	ErrCode      int       `json:"err_code"`
 | 
						//ErrCode      int    `json:"err_code"`
 | 
				
			||||||
	AppId        int64     `json:"app_id"`
 | 
						AppId     int64 `json:"app_id"`
 | 
				
			||||||
	ChannelId    int64     `json:"channel_id"`
 | 
						ChannelId int64 `json:"channel_id"`
 | 
				
			||||||
	MerchantId   int64     `json:"merchant_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 {
 | 
					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 {
 | 
						if o.Code != errorcode.Success {
 | 
				
			||||||
		return o.NotifyRespFail(o.Code)
 | 
							return o.NotifyRespFail(o.Code)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						o.CompleteTime = time.Now()
 | 
				
			||||||
	o.sendNotify(o.setBody())
 | 
						o.sendNotify(o.setBody())
 | 
				
			||||||
	if o.Code != errorcode.Success {
 | 
						if o.Code != errorcode.Success {
 | 
				
			||||||
		return o.NotifyRespFail(o.Code)
 | 
							return o.NotifyRespFail(o.Code)
 | 
				
			||||||
| 
						 | 
					@ -101,22 +104,34 @@ func (o *OrderNotify) sendNotify(body *OrderNotifySendContent) {
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	var callbackStatus = common.STATUS_ENABLE
 | 
						var callbackStatus = common.STATUS_ENABLE
 | 
				
			||||||
	var response string
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bodyByte, _ := sonic.Marshal(&body)
 | 
						bodyByte, _ := sonic.Marshal(&body)
 | 
				
			||||||
	headers := make(map[string]string, 1)
 | 
						headers := make(map[string]string, 1)
 | 
				
			||||||
	headers["Content-Type"] = "application/json"
 | 
						headers["Content-Type"] = "application/json"
 | 
				
			||||||
	resByte, err := httpclient.FastHttpPost(o.app.NotifyUrl, headers, bodyByte, 0)
 | 
						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" {
 | 
						if err != nil || string(resByte) != "success" {
 | 
				
			||||||
		o.Code = errorcode.NotifySendFail
 | 
							o.Code = errorcode.NotifySendFail
 | 
				
			||||||
		callbackStatus = common.STATUS_DISABLED
 | 
							callbackStatus = common.STATUS_DISABLED
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			response = " | url=" + o.app.NotifyUrl + " | error=" + err.Error()
 | 
								errRespObj.Error = err.Error()
 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			response = " | url=" + o.app.NotifyUrl
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							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) {
 | 
						go func(orderId int64, status int, request, response string) {
 | 
				
			||||||
		repo := data.NewOrderCallbackLogRepo(ordercallbacklogmodel.GetInstance().GetDb())
 | 
							repo := data.NewOrderCallbackLogRepo(ordercallbacklogmodel.GetInstance().GetDb())
 | 
				
			||||||
| 
						 | 
					@ -130,7 +145,7 @@ func (o *OrderNotify) sendNotify(body *OrderNotifySendContent) {
 | 
				
			||||||
		if insertErr != nil {
 | 
							if insertErr != nil {
 | 
				
			||||||
			utils.Log(nil, "回调写入日志error", insertErr)
 | 
								utils.Log(nil, "回调写入日志error", insertErr)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}(o.OrderId, callbackStatus, string(bodyByte), response)
 | 
						}(o.OrderId, callbackStatus, string(bodyByte), string(b))
 | 
				
			||||||
	return
 | 
						return
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -138,14 +153,16 @@ func (o *OrderNotify) setBody() *OrderNotifySendContent {
 | 
				
			||||||
	return &OrderNotifySendContent{
 | 
						return &OrderNotifySendContent{
 | 
				
			||||||
		OrderId:      o.OrderId,
 | 
							OrderId:      o.OrderId,
 | 
				
			||||||
		OutTradeNo:   o.order.OutTradeNo,
 | 
							OutTradeNo:   o.order.OutTradeNo,
 | 
				
			||||||
		CompleteTime: o.CompleteTime,
 | 
							CompleteTime: o.CompleteTime.Format("2006-01-02 15:04:05"),
 | 
				
			||||||
		Status:       o.order.Status,
 | 
							Status:       o.order.Status,
 | 
				
			||||||
		OrderType:    o.order.OrderType,
 | 
							OrderType:    o.order.OrderType,
 | 
				
			||||||
		Msg:          o.Msg,
 | 
							Msg:          o.Msg,
 | 
				
			||||||
		ErrCode:      o.Status,
 | 
							//ErrCode:      o.Status,
 | 
				
			||||||
		AppId:        o.order.AppId,
 | 
							AppId:     o.order.AppId,
 | 
				
			||||||
		ChannelId:    o.order.PayChannelId,
 | 
							ChannelId: o.order.PayChannelId,
 | 
				
			||||||
		MerchantId:   o.order.MerchantId,
 | 
							//MerchantId: o.order.MerchantId,
 | 
				
			||||||
 | 
							Amount:     o.order.Amount,
 | 
				
			||||||
 | 
							PayerTotal: o.order.PayerTotal,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue