Compare commits

..

2 Commits

4 changed files with 78 additions and 44 deletions

View File

@ -45,6 +45,10 @@ const (
THIRD_ORDER_TYPE_REFUND_QUERY = 4 // 退款查询
THIRD_ORDER_TYPE_CLOSE = 5 // 关闭订单
THIRD_ORDER_TYPE_CALL_BACK = 6 // 支付回调
THIRD_ORDER_LOG_STATUS_COMMON = 0 // 第三方日志状态 未知
THIRD_ORDER_LOG_STATUS_FAIL = 1 // 第三方日志状态 失败
THIRD_ORDER_LOG_STATUS_SUCCESS = 2 // 第三方日志状态 成功
)
var PayChannelList = map[int]string{

View File

@ -132,7 +132,8 @@ func ALiCallBack(notifyReq gopay.BodyMap, aliConfig AliPay) error {
go func() {
payCallback, _ := json.Marshal(notifyReq)
payParam := "{}"
SaveLog(int64(orderId), common.THIRD_ORDER_TYPE_CALL_BACK, string(payCallback), payParam, string(merchantCallback))
status := common.THIRD_ORDER_LOG_STATUS_SUCCESS
SaveLog(int64(orderId), common.THIRD_ORDER_TYPE_CALL_BACK, string(payCallback), payParam, "{}", status)
}()
if res.ErrCode != errorcode.Success {

View File

@ -51,6 +51,7 @@ func PaymentService(c context.Context, payOrderRequest PayOrderRequest) PayOrder
logger.Info(c, "PaymentService 收到支付请求", payOrderRequest)
var err error
var info string
var payOrderResponse PayOrderResponse
switch payOrderRequest.ChannelType {
case payCommon.PAY_CHANNEL_WECHAT_H5:
// 微信H5支付
@ -59,29 +60,35 @@ func PaymentService(c context.Context, payOrderRequest PayOrderRequest) PayOrder
// 支付宝H5支付
info, err = ALiH5PayInfo(c, payOrderRequest)
default:
return PayOrderResponse{
payOrderResponse = PayOrderResponse{
Code: payCommon.PAY_NOT_FOUND_CODE,
ErrorMsg: "暂不支持该支付渠道,请后续再使用",
}
}
logStatus := common.THIRD_ORDER_LOG_STATUS_FAIL
if err != nil {
return PayOrderResponse{
payOrderResponse = PayOrderResponse{
Code: payCommon.PAY_ERROR_CODE,
ErrorMsg: err.Error(),
}
}
payOrderResponse := PayOrderResponse{
logStatus = common.THIRD_ORDER_LOG_STATUS_FAIL
} else {
payOrderResponse = PayOrderResponse{
Code: payCommon.PAY_SUCCESS_CODE,
ErrorMsg: "",
Result: info,
}
logStatus = common.THIRD_ORDER_LOG_STATUS_SUCCESS
}
// 记录日志
go func() {
orderId := payOrderRequest.OrderId
payCallback := fmt.Sprintf("{%s}", info)
payParam, _ := json.Marshal(payOrderRequest)
merchantCallback, _ := json.Marshal(payOrderResponse)
SaveLog(orderId, common.THIRD_ORDER_TYPE_PAY, payCallback, string(payParam), string(merchantCallback))
SaveLog(orderId, common.THIRD_ORDER_TYPE_PAY, payCallback, string(payParam), string(merchantCallback), logStatus)
}()
return payOrderResponse
}
@ -114,6 +121,7 @@ type PayOrderQueryInfo struct {
func PayOrderQuery(c context.Context, payOrderQueryRequest PayOrderQueryRequest) PayOrderQueryResponse {
var err error
var info PayOrderQueryInfo
var payOrderQueryResponse PayOrderQueryResponse
switch payOrderQueryRequest.PayChannel {
case payCommon.PAY_CHANNLE_TYPE_WECHAT:
// 微信H5支付
@ -121,22 +129,26 @@ func PayOrderQuery(c context.Context, payOrderQueryRequest PayOrderQueryRequest)
case payCommon.PAY_CHANNLE_TYPE_ZFB:
info, err = ALiOrderQuery(c, payOrderQueryRequest.Ali, strconv.FormatInt(payOrderQueryRequest.OrderId, 10))
default:
return PayOrderQueryResponse{
payOrderQueryResponse = PayOrderQueryResponse{
Code: payCommon.PAY_ERROR_CODE,
ErrorMsg: "暂不支持该支付渠道,请后续再使用",
}
}
logStatus := common.THIRD_ORDER_LOG_STATUS_FAIL
if err != nil {
return PayOrderQueryResponse{
payOrderQueryResponse = PayOrderQueryResponse{
Code: payCommon.PAY_ERROR_CODE,
ErrorMsg: err.Error(),
}
}
payOrderQueryResponse := PayOrderQueryResponse{
logStatus = common.THIRD_ORDER_LOG_STATUS_FAIL
} else {
payOrderQueryResponse = PayOrderQueryResponse{
Code: payCommon.PAY_SUCCESS_CODE,
Result: info,
}
logStatus = common.THIRD_ORDER_LOG_STATUS_SUCCESS
}
// 记录日志
go func() {
@ -144,7 +156,7 @@ func PayOrderQuery(c context.Context, payOrderQueryRequest PayOrderQueryRequest)
payCallback, _ := json.Marshal(info)
payParam, _ := json.Marshal(payOrderQueryRequest)
merchantCallback, _ := json.Marshal(payOrderQueryResponse)
SaveLog(orderId, common.THIRD_ORDER_TYPE_ORDER_QUERY, string(payCallback), string(payParam), string(merchantCallback))
SaveLog(orderId, common.THIRD_ORDER_TYPE_ORDER_QUERY, string(payCallback), string(payParam), string(merchantCallback), logStatus)
}()
return payOrderQueryResponse
}
@ -179,6 +191,7 @@ func OrderRefund(c context.Context, orderRefundRequest OrderRefundRequest) Order
logger.Info(c, "PaymentService 收到退款请求", orderRefundRequest)
var err error
var info OrderRefundInfo
var orderRefundResponse OrderRefundResponse
switch orderRefundRequest.PayChannel {
case payCommon.PAY_CHANNLE_TYPE_WECHAT:
// 微信H5支付
@ -186,31 +199,35 @@ func OrderRefund(c context.Context, orderRefundRequest OrderRefundRequest) Order
case payCommon.PAY_CHANNLE_TYPE_ZFB:
info, err = AliRefundOrder(c, orderRefundRequest)
default:
return OrderRefundResponse{
orderRefundResponse = OrderRefundResponse{
Code: payCommon.PAY_ERROR_CODE,
ErrorMsg: "暂不支持该支付渠道,请后续再使用",
}
}
logStatus := common.THIRD_ORDER_LOG_STATUS_FAIL
if err != nil {
return OrderRefundResponse{
orderRefundResponse = OrderRefundResponse{
Code: payCommon.PAY_ERROR_CODE,
ErrorMsg: err.Error(),
}
}
orderRefundResponse := OrderRefundResponse{
logStatus = common.THIRD_ORDER_LOG_STATUS_FAIL
} else {
orderRefundResponse = OrderRefundResponse{
Code: payCommon.PAY_SUCCESS_CODE,
Result: info,
}
logStatus = common.THIRD_ORDER_LOG_STATUS_SUCCESS
}
// 记录日志
go func() {
orderId := orderRefundRequest.OrderId
payCallback, _ := json.Marshal(info)
payParam, _ := json.Marshal(orderRefundRequest)
merchantCallback, _ := json.Marshal(orderRefundResponse)
SaveLog(orderId, common.THIRD_ORDER_TYPE_REFUND, string(payCallback), string(payParam), string(merchantCallback))
SaveLog(orderId, common.THIRD_ORDER_TYPE_REFUND, string(payCallback), string(payParam), string(merchantCallback), logStatus)
}()
return orderRefundResponse
}
@ -231,6 +248,7 @@ type OrderRefundQueryResponse struct {
func OrderRefundQuery(c context.Context, orderRefundQueryRequest OrderRefundQueryRequest) OrderRefundQueryResponse {
var err error
var info OrderRefundInfo
var orderRefundQueryResponse OrderRefundQueryResponse
switch orderRefundQueryRequest.PayChannel {
case payCommon.PAY_CHANNLE_TYPE_WECHAT:
// 微信H5支付
@ -238,21 +256,26 @@ func OrderRefundQuery(c context.Context, orderRefundQueryRequest OrderRefundQuer
case payCommon.PAY_CHANNLE_TYPE_ZFB:
info, err = AliRefundOrderQuery(c, orderRefundQueryRequest)
default:
return OrderRefundQueryResponse{
orderRefundQueryResponse = OrderRefundQueryResponse{
Code: payCommon.PAY_ERROR_CODE,
ErrorMsg: "暂不支持该支付渠道,请后续再使用",
}
}
logStatus := common.THIRD_ORDER_LOG_STATUS_FAIL
if err != nil {
return OrderRefundQueryResponse{
orderRefundQueryResponse = OrderRefundQueryResponse{
Code: payCommon.PAY_ERROR_CODE,
ErrorMsg: err.Error(),
}
}
orderRefundQueryResponse := OrderRefundQueryResponse{
logStatus = common.THIRD_ORDER_LOG_STATUS_FAIL
} else {
orderRefundQueryResponse = OrderRefundQueryResponse{
Code: payCommon.PAY_SUCCESS_CODE,
Result: info,
}
logStatus = common.THIRD_ORDER_LOG_STATUS_SUCCESS
}
// 记录日志
go func() {
@ -260,9 +283,8 @@ func OrderRefundQuery(c context.Context, orderRefundQueryRequest OrderRefundQuer
payCallback, _ := json.Marshal(info)
payParam, _ := json.Marshal(orderRefundQueryRequest)
merchantCallback, _ := json.Marshal(orderRefundQueryResponse)
SaveLog(orderId, common.THIRD_ORDER_TYPE_REFUND_QUERY, string(payCallback), string(payParam), string(merchantCallback))
SaveLog(orderId, common.THIRD_ORDER_TYPE_REFUND_QUERY, string(payCallback), string(payParam), string(merchantCallback), logStatus)
}()
return orderRefundQueryResponse
}
@ -288,6 +310,7 @@ func OrderClose(c context.Context, orderCloseRequest OrderCloseRequest) OrderClo
logger.Info(c, "PaymentService 收到关闭订单请求", orderCloseRequest)
var err error
var info OrderCloseInfo
var orderCloseResponse OrderCloseResponse
switch orderCloseRequest.PayChannel {
case payCommon.PAY_CHANNLE_TYPE_WECHAT:
// 微信H5支付
@ -295,40 +318,45 @@ func OrderClose(c context.Context, orderCloseRequest OrderCloseRequest) OrderClo
case payCommon.PAY_CHANNLE_TYPE_ZFB:
info, err = AliCloseOrder(c, orderCloseRequest)
default:
return OrderCloseResponse{
orderCloseResponse = OrderCloseResponse{
Code: payCommon.PAY_ERROR_CODE,
ErrorMsg: "暂不支持该支付渠道,请后续再使用",
}
}
logStatus := common.THIRD_ORDER_LOG_STATUS_FAIL
if err != nil {
return OrderCloseResponse{
orderCloseResponse = OrderCloseResponse{
Code: payCommon.PAY_ERROR_CODE,
ErrorMsg: err.Error(),
}
}
orderCloseResponse := OrderCloseResponse{
logStatus = common.THIRD_ORDER_LOG_STATUS_FAIL
} else {
orderCloseResponse = OrderCloseResponse{
Code: payCommon.PAY_SUCCESS_CODE,
Result: info,
}
logStatus = common.THIRD_ORDER_LOG_STATUS_SUCCESS
}
// 记录日志
go func() {
orderId := orderCloseRequest.OrderId
payCallback, _ := json.Marshal(info)
payParam, _ := json.Marshal(orderCloseRequest)
merchantCallback, _ := json.Marshal(orderCloseResponse)
SaveLog(orderId, common.THIRD_ORDER_TYPE_CLOSE, string(payCallback), string(payParam), string(merchantCallback))
SaveLog(orderId, common.THIRD_ORDER_TYPE_CLOSE, string(payCallback), string(payParam), string(merchantCallback), logStatus)
}()
return orderCloseResponse
}
// SaveLog 记录操作日志
func SaveLog(orderId int64, OType int, payCallback string, PayParam string, MerchantCallback string) {
func SaveLog(orderId int64, OType int, payCallback string, PayParam string, MerchantCallback string, status int) {
thirdRepo := data.NewOrderThirdPayLogRepo(paychannelmodel.GetInstance().GetDb())
log := orderthirdpaylogmodel.OrderThirdPayLog{
OrderId: orderId,
PayCallback: payCallback,
Status: 0,
Status: status,
PayParam: PayParam,
MerchantCallback: MerchantCallback,
Type: OType,

View File

@ -166,7 +166,8 @@ func WxPayCallBack(notifyReq *wechat.V3NotifyReq, wxConfig WxPay) error {
go func() {
payCallback, _ := json.Marshal(CallBackInfo)
payParam := "{}"
SaveLog(int64(orderId), common.THIRD_ORDER_TYPE_CALL_BACK, string(payCallback), payParam, string(merchantCallback))
status := common.THIRD_ORDER_LOG_STATUS_SUCCESS
SaveLog(int64(orderId), common.THIRD_ORDER_TYPE_CALL_BACK, string(payCallback), payParam, "{}", status)
}()
if res.ErrCode != errorcode.Success {