Browse Source

no message

xingzai 8 months ago
parent
commit
1ea2869f90
2 changed files with 45 additions and 0 deletions
  1. 2 0
      controllers/order.go
  2. 43 0
      services/wx_pay.go

+ 2 - 0
controllers/order.go

@@ -550,6 +550,8 @@ func (this *OrderController) Cancel() {
 		return
 	}
 
+	go services.ExampleJsapiApiService_CloseOrder(orderDetail.OutTradeNo)
+
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "操作成功"

+ 43 - 0
services/wx_pay.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"fmt"
 	"github.com/wechatpay-apiv3/wechatpay-go/core"
+	"github.com/wechatpay-apiv3/wechatpay-go/services/payments/jsapi"
 	"github.com/wechatpay-apiv3/wechatpay-go/services/payments/native"
 	"hongze/hongze_web_mfyx/models/order"
 	"hongze/hongze_web_mfyx/utils"
@@ -104,3 +105,45 @@ type WechatPayCallback struct {
 		PayerCurrency string `json:"payer_currency"`
 	} `json:"amount"`
 }
+
+// 订单超时手动关闭订单
+func ExampleNativeApiService_CloseOrder(OutTradeNo string) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg(fmt.Sprint("订单超时手动关闭订单 失败 ExampleNativeApiService_CloseOrder, err:", err.Error(), "OutTradeNo:", OutTradeNo), 2)
+		}
+	}()
+
+	ctx := context.Background()
+	svc := native.NativeApiService{Client: utils.WechatCertClient}
+	_, err = svc.CloseOrder(ctx,
+		native.CloseOrderRequest{
+			OutTradeNo: core.String(OutTradeNo),
+			Mchid:      core.String(utils.Mchid),
+		},
+	)
+	return
+}
+
+// 订单超时手动关闭订单(两者功能更一样,与小程序端代码统一)
+func ExampleJsapiApiService_CloseOrder(OutTradeNo string) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg(fmt.Sprint("订单超时手动关闭订单 失败 ExampleJsapiApiService_CloseOrder, err:", err.Error(), "OutTradeNo:", OutTradeNo), 2)
+		}
+	}()
+
+	ctx := context.Background()
+	svc := jsapi.JsapiApiService{Client: utils.WechatCertClient}
+	_, err = svc.CloseOrder(ctx,
+		jsapi.CloseOrderRequest{
+			OutTradeNo: core.String(OutTradeNo),
+			Mchid:      core.String(utils.Mchid),
+		},
+	)
+	return
+}