animeic 1 year ago
parent
commit
6cbc6ad9df
3 changed files with 9 additions and 48 deletions
  1. 1 3
      pay/bus/nats.go
  2. 1 1
      pay/bus/pay.go
  3. 7 44
      pay/bus/singlePay.go

+ 1 - 3
pay/bus/nats.go

@@ -12,9 +12,7 @@ func NewNatsBus(app *conf.AppConf) *comm.NatsBus {
 
 	singlePay := new(SinglePay)
 
-	bus, _ := comm.NewNatsBus2(app.Nats.Url, app.Nats.MaxReconnect, app.Nats.ReconnDelaySecond, []*comm.NatsStreamWather{
-		singlePay.SuccPayStream(),
-	}, []*comm.NatsMsgReplyer{
+	bus, _ := comm.NewNatsBus2(app.Nats.Url, app.Nats.MaxReconnect, app.Nats.ReconnDelaySecond, []*comm.NatsStreamWather{}, []*comm.NatsMsgReplyer{
 		singlePay.CreateQr(),
 		singlePay.Refund(),
 		singlePay.RefundQuery(),

+ 1 - 1
pay/bus/pay.go

@@ -21,7 +21,7 @@ type PayInf interface {
 	ReFundQuery(ctx context.Context, refund *model.ReFund) (interface{}, error)
 }
 
-func PayMod(payType int, category int) PayInf {
+func PayMod(payType int) PayInf {
 	if payType == ALIPAY {
 		return NewSingleAliPay()
 	} else if payType == WECHATPAY {

+ 7 - 44
pay/bus/singlePay.go

@@ -2,11 +2,7 @@ package bus
 
 import (
 	"context"
-	"fmt"
-	"pay/db"
 	"pay/db/model"
-	"pay/db/repo"
-	"pay/log"
 	"pay/utils"
 
 	"github.com/nats-io/nats.go"
@@ -25,7 +21,7 @@ func (s *SinglePay) CreateQr() *comm.NatsMsgReplyer {
 		Entity:  func() interface{} { return &pay.OrderMsg{} },
 		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
 			m := entity.(*pay.OrderMsg)
-			pay := PayMod(int(*m.PayMod), SINGLE)
+			pay := PayMod(int(*m.PayMod))
 			ctx := context.Background()
 			res, err := pay.Pay(ctx, m)
 			return res, err
@@ -42,7 +38,7 @@ func (s *SinglePay) CloseOrder() *comm.NatsMsgReplyer {
 		Entity:  func() interface{} { return &pay.OrderMsg{} },
 		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
 			m := entity.(*pay.OrderMsg)
-			pay := PayMod(int(*m.PayMod), SINGLE)
+			pay := PayMod(int(*m.PayMod))
 			ctx := context.Background()
 			flag, err := pay.Close(ctx, m)
 			return flag, err
@@ -53,17 +49,17 @@ func (s *SinglePay) CloseOrder() *comm.NatsMsgReplyer {
 // 退款
 func (s *SinglePay) Refund() *comm.NatsMsgReplyer {
 	utils.ConsoleFormat(pay.PaySingleRefundApi)
-
+	refund := pay.ReFund{}
 	return &comm.NatsMsgReplyer{
 		Subject: pay.PaySingleRefundApi,
-		Entity:  func() interface{} { return &pay.ReFund{} },
+		Entity:  func() interface{} { return &refund },
 		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
-			refund := entity.(*model.ReFund)
+			refund := entity.(*pay.ReFund)
 			// ???适配缺失退款理由
 			if refund.Reason == "" {
 				refund.Reason = "默认退款"
 			}
-			pay := PayMod(int(*refund.PayMode), SINGLE)
+			pay := PayMod(int(*refund.PayMod))
 			ctx := context.Background()
 			flag, err := pay.ReFundPay(ctx, refund)
 			return flag, err
@@ -80,43 +76,10 @@ func (s *SinglePay) RefundQuery() *comm.NatsMsgReplyer {
 		Entity:  func() interface{} { return &model.ReFund{} },
 		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
 			m := entity.(*model.ReFund)
-			pay := PayMod(int(*m.PayMode), SINGLE)
+			pay := PayMod(int(*m.PayMode))
 			ctx := context.Background()
 			status, err := pay.ReFundQuery(ctx, m)
 			return status, err
 		},
 	}
 }
-
-// 支付成功
-func (s *SinglePay) SuccPayStream() *comm.NatsStreamWather {
-	res := &model.ResData{}
-	// "queenshow-pay-succ#queenshow.paysucc#queenshow-paysucc-queue
-	return &comm.NatsStreamWather{
-		Stream:        "queenshow-pay-succ",
-		Topic:         "queenshow.paysucc",
-		Queue:         "queenshow-paysucc-queue",
-		AckWaitMinute: int64(1),
-		Entity:        func() interface{} { return res },
-		Cb: func(msg *nats.Msg, entity interface{}) {
-			defer func() {
-				if err := recover(); err != nil {
-					log.Info("系统异常", err)
-				}
-			}()
-
-			session := &repo.RepoSession{Client: db.GMongoDb}
-			fmt.Println(session.Client.Database.Name())
-
-			// fmt.Println("===============购买结果返回=================")
-			// log.Info("===============购买结果返回=================")
-			// data := entity.(*model.ResData)
-			// orderMsg := data.Data.(map[string]interface{})
-			// flag, _ := Paied(data.Code, orderMsg["_id"].(string), int(orderMsg["payMode"].(float64)), session)
-			// if flag {
-			// 	msg.Ack()
-			// }
-		},
-	}
-
-}