记录操作日志

This commit is contained in:
陈俊宏 2024-08-06 15:41:57 +08:00
parent 7ee666e459
commit 2927161585
3 changed files with 88 additions and 7 deletions

View File

@ -215,7 +215,7 @@ func queryOrder() {
OrderId: orderInfo.Id,
PayCallback: string(body),
Status: 0,
MerchantParam: "",
PayParam: "",
MerchantCallback: "",
}
_, err = orderLogRepo.OrderThirdPayLogInsertOne(&log)

View File

@ -31,4 +31,11 @@ const (
PAY_CHANNLE_TYPE_WECHAT = 1 // 支付类型: 微信
PAY_CHANNLE_TYPE_ZFB = 2 // 支付类型:支付宝
THIRD_ORDER_TYPE_PAY = 1 // 发起支付
THIRD_ORDER_TYPE_ORDER_QUERY = 2 // 查询订单
THIRD_ORDER_TYPE_REFUND = 3 // 发起退款
THIRD_ORDER_TYPE_REFUND_QUERY = 4 // 退款查询
THIRD_ORDER_TYPE_CLOSE = 5 // 关闭订单
THIRD_ORDER_TYPE_CALL_BACK = 6 // 支付回调
)

View File

@ -1,8 +1,13 @@
package paymentService
import (
"PaymentCenter/app/constants/common"
"PaymentCenter/app/data"
"PaymentCenter/app/models/orderthirdpaylogmodel"
"PaymentCenter/app/models/paychannelmodel"
"PaymentCenter/app/third/paymentService/payCommon"
"context"
"encoding/json"
"github.com/qit-team/snow-core/log/logger"
"strconv"
)
@ -41,7 +46,7 @@ type PayOrderResponse struct {
}
// PaymentService 统一发起支付
func PaymentService(c context.Context, payOrderRequest PayOrderRequest) (payOrderResponse PayOrderResponse) {
func PaymentService(c context.Context, payOrderRequest PayOrderRequest) PayOrderResponse {
logger.Info(c, "PaymentService 收到支付请求", payOrderRequest)
var err error
var info string
@ -64,11 +69,20 @@ func PaymentService(c context.Context, payOrderRequest PayOrderRequest) (payOrde
ErrorMsg: err.Error(),
}
}
return PayOrderResponse{
payOrderResponse := PayOrderResponse{
Code: payCommon.PAY_SUCCESS_CODE,
ErrorMsg: "",
Result: info,
}
// 记录日志
go func() {
orderId := payOrderRequest.OrderId
payCallback := info
payParam, _ := json.Marshal(payOrderRequest)
merchantCallback, _ := json.Marshal(payOrderResponse)
saveLog(orderId, common.THIRD_ORDER_TYPE_PAY, payCallback, string(payParam), string(merchantCallback))
}()
return payOrderResponse
}
type PayOrderQueryRequest struct {
@ -117,10 +131,21 @@ func PayOrderQuery(c context.Context, payOrderQueryRequest PayOrderQueryRequest)
ErrorMsg: err.Error(),
}
}
return PayOrderQueryResponse{
payOrderQueryResponse := PayOrderQueryResponse{
Code: payCommon.PAY_SUCCESS_CODE,
Result: info,
}
// 记录日志
go func() {
orderId := payOrderQueryRequest.OrderId
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))
}()
return payOrderQueryResponse
}
type OrderRefundRequest struct {
@ -171,10 +196,21 @@ func OrderRefund(c context.Context, orderRefundRequest OrderRefundRequest) Order
ErrorMsg: err.Error(),
}
}
return OrderRefundResponse{
orderRefundResponse := OrderRefundResponse{
Code: payCommon.PAY_SUCCESS_CODE,
Result: info,
}
// 记录日志
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))
}()
return orderRefundResponse
}
type OrderRefundQueryRequest struct {
@ -212,10 +248,21 @@ func OrderRefundQuery(c context.Context, orderRefundQueryRequest OrderRefundQuer
ErrorMsg: err.Error(),
}
}
return OrderRefundQueryResponse{
orderRefundQueryResponse := OrderRefundQueryResponse{
Code: payCommon.PAY_SUCCESS_CODE,
Result: info,
}
// 记录日志
go func() {
orderId := orderRefundQueryRequest.OrderId
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))
}()
return orderRefundQueryResponse
}
type OrderCloseRequest struct {
@ -258,8 +305,35 @@ func OrderClose(c context.Context, orderCloseRequest OrderCloseRequest) OrderClo
ErrorMsg: err.Error(),
}
}
return OrderCloseResponse{
orderCloseResponse := OrderCloseResponse{
Code: payCommon.PAY_SUCCESS_CODE,
Result: info,
}
// 记录日志
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))
}()
return orderCloseResponse
}
// saveLog 记录操作日志
func saveLog(orderId int64, OType int, payCallback string, PayParam string, MerchantCallback string) {
thirdRepo := data.NewOrderThirdPayLogRepo(paychannelmodel.GetInstance().GetDb())
log := orderthirdpaylogmodel.OrderThirdPayLog{
OrderId: orderId,
PayCallback: payCallback,
Status: 0,
PayParam: PayParam,
MerchantCallback: MerchantCallback,
Type: OType,
}
_, err := thirdRepo.OrderThirdPayLogInsertOne(&log)
if err != nil {
return
}
}