|
|
|
@ -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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|