后台,查询支付和退款回调,订单查询fix

This commit is contained in:
wolter 2024-08-08 11:34:09 +08:00
parent c9c7bdbc16
commit 342a247c67
4 changed files with 70 additions and 19 deletions

View File

@ -2,10 +2,13 @@ package console
import (
"PaymentCenter/app/constants/common"
"PaymentCenter/app/constants/errorcode"
"PaymentCenter/app/data"
"PaymentCenter/app/http/entities"
"PaymentCenter/app/http/entities/backend"
"PaymentCenter/app/models/ordersmodel"
"PaymentCenter/app/models/orderthirdpaylogmodel"
"PaymentCenter/app/models/paychannelmodel"
"PaymentCenter/app/services/thirdpay/thirdpay_notify"
"PaymentCenter/app/third/paymentService"
"PaymentCenter/app/third/paymentService/payCommon"
@ -166,23 +169,47 @@ func queryOrder() {
// 查询成功,校验状态
var status int
if result.Code == payCommon.PAY_SUCCESS_CODE {
var msg string
switch result.Result.TradeState {
case "SUCCESS":
// 成功
status = common.ORDER_STATUS_PAYED
msg = "支付成功"
case "REFUND":
// 退款 订单支付完成才能退款,所以支付单的状态是支付完成
status = common.ORDER_STATUS_PAYED
msg = "支付成功"
case "NOTPAY":
// 未支付
return
case "CLOSED":
// 关闭
status = common.ORDER_STATUS_CLOSE
msg = "订单关闭"
}
// 回调通知下游 todo
notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, status, int(result.Result.PayerTotal), "")
utils.Log(nil, "主动查询订单支付状态,回调下游", notifyResult)
notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, status, int(result.Result.PayerTotal), msg)
//utils.Log(nil, "主动查询订单支付状态,回调下游", notifyResult)
if notifyResult.ErrCode != errorcode.Success {
utils.Log(nil, "主动查询订单支付状态,回调下游失败", notifyResult)
}
payCallback, _ := json.Marshal(result)
merchantCallback, _ := json.Marshal(notifyResult)
thirdRepo := data.NewOrderThirdPayLogRepo(paychannelmodel.GetInstance().GetDb())
log := orderthirdpaylogmodel.OrderThirdPayLog{
OrderId: orderInfo.Id,
PayCallback: string(payCallback),
Status: 1,
PayParam: "",
MerchantCallback: string(merchantCallback),
Type: common.THIRD_ORDER_TYPE_CALL_BACK,
}
// 写日志
_, err = thirdRepo.OrderThirdPayLogInsertOne(&log)
if err != nil {
utils.Log(nil, "主动查询订单支付状态,记录回调日志失败", log.OrderId, err)
}
}
}(orderInfo)
}
@ -261,6 +288,7 @@ func queryRefundOrder() {
var status int
if result.Code == payCommon.PAY_SUCCESS_CODE {
// 退款状态 0未申请1退款中2退款成功3退款失败
var msg string
switch result.Result.RefundStatus {
case 0:
// 未申请
@ -273,13 +301,35 @@ func queryRefundOrder() {
case 2:
// 退款成功
status = common.ORDER_STATUS_PAYED
msg = "退款成功"
case 3:
// 退款失败
status = common.ORDER_STATUS_FAILED
msg = "退款失败"
}
// 回调通知下游 todo
notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, status, int(result.Result.RefundFee), "")
utils.Log(nil, "主动查询退款订单状态,回调下游", notifyResult)
notifyResult := thirdpay_notify.NewOrderNotifyWithHandle(orderInfo.Id, status, int(result.Result.RefundFee), msg)
//utils.Log(nil, "主动查询退款订单状态,回调下游", notifyResult)
if notifyResult.ErrCode != errorcode.Success {
utils.Log(nil, "查询退款订单状态,回调下游失败", notifyResult)
}
payCallback, _ := json.Marshal(result)
merchantCallback, _ := json.Marshal(notifyResult)
thirdRepo := data.NewOrderThirdPayLogRepo(paychannelmodel.GetInstance().GetDb())
log := orderthirdpaylogmodel.OrderThirdPayLog{
OrderId: orderInfo.Id,
PayCallback: string(payCallback),
Status: 1,
PayParam: "",
MerchantCallback: string(merchantCallback),
Type: common.THIRD_ORDER_TYPE_CALL_BACK,
}
// 写日志
_, err = thirdRepo.OrderThirdPayLogInsertOne(&log)
if err != nil {
utils.Log(nil, "查询退款订单状态,记录回调日志失败", log.OrderId, err)
}
}
}(orderInfo)
}

View File

@ -9,6 +9,7 @@ import (
"encoding/base64"
"encoding/json"
"errors"
"github.com/bytedance/sonic"
"github.com/go-playground/locales/zh"
ut "github.com/go-playground/universal-translator"
"github.com/qit-team/snow-core/redis"
@ -111,8 +112,10 @@ func GenRequest(c *gin.Context, request interface{}) (msgs []string, err error)
if c.Request.Method == "GET" || c.Request.Method == "DELETE" {
err = c.ShouldBindQuery(request)
} else {
err = c.ShouldBindJSON(request)
err = c.ShouldBind(request)
}
var req, _ = sonic.Marshal(request)
utils.Log(c, c.FullPath(), "请求参数", string(req))
if err == nil {
validate := validator.New()

View File

@ -61,12 +61,10 @@ func Cors() gin.HandlerFunc {
func AdminAuth() gin.HandlerFunc {
return func(c *gin.Context) {
ip, _ := c.RemoteIP()
utils.Log(c, "请求地址RemoteIP()", ip.String(), config.GetConf().AdminGate)
clientIp := c.ClientIP()
utils.Log(c, "请求地址clientIp", clientIp)
utils.Log(c, "请求地址clientIp", clientIp, config.GetConf().AdminGate)
if config.GetConf().Debug == false && !utils.SliceInStr(ip.String(), config.GetConf().AdminGate) {
if config.GetConf().Debug == false && !utils.SliceInStr(clientIp, config.GetConf().AdminGate) {
c.Abort()
controllers.HandCodeRes(c, nil, errorcode.Forbidden)
return
@ -112,7 +110,7 @@ func ValidateRequest() gin.HandlerFunc {
handler = requestmapping.FrontRequestMapBeforeDecrypt[path]
}
if handler == nil {
utils.Log(c, "path", path)
utils.Log(c, "path", path, "未找到handler")
controllers.HandCodeRes(c, nil, errorcode.NotFound)
return
}

View File

@ -18,31 +18,31 @@ func OrderList(req backend.OrderList) (result []ordersmodel.OrdersBackendList, t
// 拼接查询条件
conn := builder.NewCond()
if req.Id > 0 {
conn = conn.And(builder.Eq{"id": req.Id})
conn = conn.And(builder.Eq{"orders.id": req.Id})
}
if req.MerchantId > 0 {
conn = conn.And(builder.Eq{"merchant_id": req.MerchantId})
conn = conn.And(builder.Eq{"orders.merchant_id": req.MerchantId})
}
if req.PayChannelId > 0 {
conn = conn.And(builder.Eq{"pay_channel_id": req.PayChannelId})
conn = conn.And(builder.Eq{"orders.pay_channel_id": req.PayChannelId})
}
if req.AppId > 0 {
conn = conn.And(builder.Eq{"app_id": req.AppId})
conn = conn.And(builder.Eq{"orders.app_id": req.AppId})
}
if req.OutTreadNo != "" {
conn = conn.And(builder.Like{"out_tread_no", req.OutTreadNo})
conn = conn.And(builder.Like{"orders.out_tread_no", req.OutTreadNo})
}
if req.Status > 0 {
conn = conn.And(builder.Eq{"status": req.Status})
conn = conn.And(builder.Eq{"orders.status": req.Status})
}
if req.OrderType > 0 {
conn = conn.And(builder.Eq{"order_type": req.OrderType})
conn = conn.And(builder.Eq{"orders.order_type": req.OrderType})
}
if !req.StartTime.IsZero() {
conn = conn.And(builder.Gte{"start_time": req.StartTime})
conn = conn.And(builder.Gte{"orders.create_time": req.StartTime})
}
if !req.EndTime.IsZero() {
conn = conn.And(builder.Lte{"end_time": req.EndTime})
conn = conn.And(builder.Lte{"orders.create_time": req.EndTime})
}
// 调用repo