From 342a247c6711046840ee8765cf9e317d44e91b87 Mon Sep 17 00:00:00 2001 From: wolter Date: Thu, 8 Aug 2024 11:34:09 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=90=8E=E5=8F=B0=EF=BC=8C=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=94=AF=E4=BB=98=E5=92=8C=E9=80=80=E6=AC=BE=E5=9B=9E?= =?UTF-8?q?=E8=B0=83,=E8=AE=A2=E5=8D=95=E6=9F=A5=E8=AF=A2fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/console/command.go | 58 +++++++++++++++++++++++++++++++++--- app/http/controllers/base.go | 5 +++- app/http/middlewares/base.go | 8 ++--- app/services/order.go | 18 +++++------ 4 files changed, 70 insertions(+), 19 deletions(-) diff --git a/app/console/command.go b/app/console/command.go index 0e4ffc5..67596a3 100644 --- a/app/console/command.go +++ b/app/console/command.go @@ -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) } diff --git a/app/http/controllers/base.go b/app/http/controllers/base.go index b42fd4d..40331da 100644 --- a/app/http/controllers/base.go +++ b/app/http/controllers/base.go @@ -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() diff --git a/app/http/middlewares/base.go b/app/http/middlewares/base.go index 7f90056..b8b0c86 100644 --- a/app/http/middlewares/base.go +++ b/app/http/middlewares/base.go @@ -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 } diff --git a/app/services/order.go b/app/services/order.go index 18c43a5..ff46a96 100644 --- a/app/services/order.go +++ b/app/services/order.go @@ -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 From 627e1c852c432ea771340fee203053560979a859 Mon Sep 17 00:00:00 2001 From: wolter Date: Thu, 8 Aug 2024 14:19:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=90=8E=E5=8F=B0=EF=BC=8C=E5=AF=86?= =?UTF-8?q?=E9=92=A5=E5=AF=B9=E5=92=8Capi=E6=8E=A5=E5=8F=A3=E5=AF=B9?= =?UTF-8?q?=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/http/controllers/backend/app.go | 7 ++++--- app/http/entities/backend/app.go | 2 +- app/http/entities/backend/pay_channel.go | 12 ++++++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/http/controllers/backend/app.go b/app/http/controllers/backend/app.go index 6a66d5c..3ce31a6 100644 --- a/app/http/controllers/backend/app.go +++ b/app/http/controllers/backend/app.go @@ -2,6 +2,7 @@ package backend import ( "PaymentCenter/app/constants/errorcode" + "PaymentCenter/app/constants/pojo" "PaymentCenter/app/http/controllers" "PaymentCenter/app/http/entities" "PaymentCenter/app/http/entities/backend" @@ -62,11 +63,11 @@ func GenerateDecrypt(c *gin.Context) { var publicKey, privateKey string var err error switch req.KeyType { - case "sm2": + case pojo.SM2: publicKey, privateKey, err = sm2.GenerateSM2Key() - case "rsa": + case pojo.RSA: publicKey, privateKey, err = rsa.GenerateKey() - case "sm4": + case pojo.SM4: privateKey, publicKey = sm4.GenerateKey() default: controllers.HandCodeRes(c, "", errorcode.EncryptTypeNotFound) diff --git a/app/http/entities/backend/app.go b/app/http/entities/backend/app.go index 43b45f9..06f9f45 100644 --- a/app/http/entities/backend/app.go +++ b/app/http/entities/backend/app.go @@ -96,5 +96,5 @@ func (a *AppUpdateRequest) RequestToDb() (db appmodel.App) { } type GenerateDecryptKeyRequest struct { - KeyType string `json:"key_type" form:"key_type" label:"密钥类型"` + KeyType int32 `json:"key_type" form:"key_type" label:"密钥类型"` } diff --git a/app/http/entities/backend/pay_channel.go b/app/http/entities/backend/pay_channel.go index 4416175..a278b7b 100644 --- a/app/http/entities/backend/pay_channel.go +++ b/app/http/entities/backend/pay_channel.go @@ -27,8 +27,16 @@ func (p *PayChannelResponse) ResponseFromDb(db paychannelmodel.PayChannel) { p.MerchantId = db.MerchantId p.ChannelType = db.ChannelType p.AppId = db.AppId - p.ExpireTime = db.ExpireTime.Format("2006-01-02 15:04:05") - p.CreateTime = db.CreateTime.Format("2006-01-02 15:04:05") + if db.ExpireTime.IsZero() { + p.ExpireTime = "" + } else { + p.ExpireTime = db.ExpireTime.Format("2006-01-02 15:04:05") + } + if db.CreateTime.IsZero() { + p.CreateTime = "" + } else { + p.CreateTime = db.CreateTime.Format("2006-01-02 15:04:05") + } switch db.ChannelType { case common.PAY_CHANNEL_WECHAT_H5, common.PAY_CHANNEL_WECHAT_JSAPI, common.PAY_CHANNEL_WECHAT_NATIVE, common.PAY_CHANNEL_WECHAT_APP, common.PAY_CHANNEL_WECHAT_MINI: