animeic 1 年之前
父节点
当前提交
8fcb33004c

+ 0 - 51
pay/api/multiAlipayCallback.go

@@ -1,51 +0,0 @@
-package api
-
-import (
-	"fmt"
-	"net/http"
-	"pay/bus"
-	"pay/db/model"
-	"strings"
-
-	"github.com/go-pay/gopay/alipay"
-	"infish.cn/comm"
-)
-
-type MutliAliPayCallback struct {
-}
-
-func NewMutliAliPayCallback() PayCallback {
-	return &MutliAliPayCallback{}
-}
-
-// CallBack 阿里回调
-func (a *MutliAliPayCallback) CallBack(c *http.Request) (interface{}, error) {
-	fmt.Println("--------------------------------------------alipay-multi-callback----------------------------------------")
-	fmt.Println("---------------------------------------------------------------------------------------------------------")
-	notifyReq, err := alipay.ParseNotifyToBodyMap(c) // c.Request 是 gin 框架的写法
-	if err != nil {
-		return "fail", err
-	}
-
-	orderSlice := strings.Split(notifyReq["out_trade_no"].(string), "_")
-	payMode := 0 // 支付宝模式
-	res := &model.OrderMsg{Id: orderSlice[1], PayMode: &payMode, ModName: orderSlice[0]}
-
-	if notifyReq["trade_status"] == "TRADE_SUCCESS" {
-		fmt.Println("----------------success----------------------")
-		err = bus.NatsCenter.PushMessage(comm.NewAppPaySuccSubject(orderSlice[0]), res)
-		if err != nil {
-			fmt.Println("----------------success-err----------------------")
-			return "fail", err
-		}
-	} else {
-		fmt.Println("----------------fail----------------------")
-		err = bus.NatsCenter.PushMessage(comm.NewAppPayFailSubject(orderSlice[0]), res)
-		if err != nil {
-			fmt.Println("----------------fail-err----------------------")
-			return "fail", err
-		}
-	}
-	fmt.Println("----------------success-end----------------------")
-	return "success", nil
-}

+ 0 - 67
pay/api/multiWechatPayCallback.go

@@ -1,67 +0,0 @@
-package api
-
-import (
-	"fmt"
-	"net/http"
-	"pay/bus"
-	"pay/conf"
-	"pay/db/model"
-	"pay/utils"
-	"strings"
-
-	"github.com/go-pay/gopay/wechat/v3"
-	"infish.cn/comm"
-)
-
-type MutliWechatPayCallback struct {
-}
-
-func NewMutliWechatPayCallback() PayCallback {
-	return &MutliWechatPayCallback{}
-}
-
-func (w *MutliWechatPayCallback) CallBack(c *http.Request) (interface{}, error) {
-	fmt.Println("--------------------------------------------wechat-multi-callback----------------------------------------")
-	fmt.Println("---------------------------------------------------------------------------------------------------------")
-	notifyReq, err := wechat.V3ParseNotify(c)
-	if err != nil {
-		return "FAIL", err
-	}
-	multiCnf := utils.GetMultiPayConfig(conf.AppConfig)
-
-	// result, err := notifyReq.DecryptCipherText("BSNDcbbL5r122gEdoCSd9tGNIPNvjSxx")
-	result, err := notifyReq.DecryptCipherText(multiCnf.WechatPay.ApiV3Key)
-	if err != nil {
-		return "FAIL", err
-	}
-
-	// multiPayCnf := utils.GetMultiPayConfig(conf.AppConfig)
-	// refund, err := notifyReq.DecryptRefundCipherText(multiPayCnf.WechatPay.ApiV3Key)
-
-	// fmt.Printf("%#v\n", refund)
-	// {Mchid:"", OutTradeNo:"wechat_63116317f17ac790a0e71a81", TransactionId:"4200001591202209212097988473",
-	// OutRefundNo:"632ad588ba4c081d98c4016d", RefundId:"50302003512022092125115377323", RefundStatus:"SUCCESS",
-	// SuccessTime:"2022-09-21T17:12:49+08:00",
-	// UserReceivedAccount:"支付用户零钱", Amount:(*wechat.RefundAmount)(0xc00011f500)}
-
-	orderSlice := strings.Split(result.OutTradeNo, "_")
-	payMode := 1
-	res := &model.OrderMsg{Id: orderSlice[1], PayMode: &payMode, ModName: orderSlice[0]}
-	if result.TradeState == "SUCCESS" {
-		fmt.Println("----------------success----------------------")
-		err = bus.NatsCenter.PushMessage(comm.NewAppPaySuccSubject(orderSlice[0]), res)
-		if err != nil {
-			fmt.Println("----------------success-err----------------------")
-			return "FAIL", err
-		}
-	} else {
-		fmt.Println("----------------fail----------------------")
-		err = bus.NatsCenter.PushMessage(comm.NewAppPayFailSubject(orderSlice[0]), res)
-		if err != nil {
-			fmt.Println("----------------fail-err----------------------")
-			return "FAIL", err
-		}
-	}
-	fmt.Println("----------------success-end----------------------")
-	return "SUCCESS", nil
-}

+ 4 - 12
pay/api/pay.go

@@ -23,18 +23,10 @@ type PayCallback interface {
 	CallBack(c *http.Request) (interface{}, error)
 }
 
-func PayMod(payType int, category int) PayCallback {
-	if category == SINGLE {
-		if payType == ALIPAY {
-			return NewSingleAliPayCallback()
-		} else {
-			return NewSingleWechatPayCallback()
-		}
+func PayMod(payType int) PayCallback {
+	if payType == ALIPAY {
+		return NewSingleAliPayCallback()
 	} else {
-		if payType == ALIPAY {
-			return NewMutliAliPayCallback()
-		} else {
-			return NewMutliWechatPayCallback()
-		}
+		return NewSingleWechatPayCallback()
 	}
 }

+ 0 - 3
pay/api/router.go

@@ -15,9 +15,6 @@ func RegRouters(svc *Service) {
 	// 个体支付
 	PaySingle(payGroup)
 
-	// 多商户支付
-	PayMulti(payGroup)
-
 	// 支付点管理
 	PayPoint(payGroup)
 

+ 0 - 43
pay/api/service-multi-pay.go

@@ -1,43 +0,0 @@
-package api
-
-import (
-	"fmt"
-	"net/http"
-
-	"github.com/gin-gonic/gin"
-)
-
-func PayMulti(r *GinRouter) {
-
-	r.POST("/multi/alipay/callback", MultiAliCallBack)
-	r.POST("/multi/wechat/callback", MultiWechatCallBack)
-}
-
-func MultiAliCallBack(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-
-	fmt.Println(c)
-	// 默认走阿里支付
-	pay := PayMod(ALIPAY, MULTI)
-
-	res, err := pay.CallBack(c.Request)
-	if err != nil {
-		return false, NewError(err.Error())
-	}
-	c.String(http.StatusOK, res.(string))
-	return nil, nil
-}
-
-func MultiWechatCallBack(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-
-	// 微信回调
-	pay := PayMod(WECHATPAY, MULTI)
-
-	res, err := pay.CallBack(c.Request)
-	if err != nil {
-		// return false, NewError(err.Error())
-		c.JSON(http.StatusOK, gin.H{"code": res, "message": err.Error()})
-	}
-	c.JSON(http.StatusOK, gin.H{"code": res, "message": "成功"})
-	// c.JSON(http.StatusOK, &wechat.V3NotifyRsp{Code: res.(string), Message: err.Error()})
-	return nil, nil
-}

+ 2 - 2
pay/api/service-single-pay.go

@@ -16,7 +16,7 @@ func SingleAliCallBack(c *gin.Context, apictx *ApiSession) (interface{}, error)
 
 	fmt.Println(c)
 	// 默认走阿里支付
-	pay := PayMod(ALIPAY, SINGLE)
+	pay := PayMod(ALIPAY)
 
 	res, err := pay.CallBack(c.Request)
 	if err != nil {
@@ -29,7 +29,7 @@ func SingleAliCallBack(c *gin.Context, apictx *ApiSession) (interface{}, error)
 func SingleWechatCallBack(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	// 微信回调
-	pay := PayMod(WECHATPAY, SINGLE)
+	pay := PayMod(WECHATPAY)
 
 	res, err := pay.CallBack(c.Request)
 	if err != nil {

+ 1 - 0
pay/assettest.log

@@ -43,3 +43,4 @@
 {"level":"info","timestamp":"2023-07-07 14:21:10","message":"[初始化支付客户端]","service_name":"assettest"}
 {"level":"info","timestamp":"2023-07-07 14:36:21","message":"[初始化支付客户端]","service_name":"assettest"}
 {"level":"info","timestamp":"2023-07-07 14:47:56","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-07 15:30:44","message":"[初始化支付客户端]","service_name":"assettest"}

+ 0 - 167
pay/bus/multiAliPay.go

@@ -1,167 +0,0 @@
-package bus
-
-import (
-	"context"
-	"errors"
-	"fmt"
-	"pay/db"
-	"pay/db/model"
-	"pay/db/repo"
-	"pay/log"
-	"pay/pay"
-	"pay/utils"
-	"strconv"
-
-	"github.com/go-pay/gopay"
-	"github.com/go-pay/gopay/alipay"
-	cpay "infish.cn/comm/pay"
-)
-
-type MutliAliPay struct {
-}
-
-func NewMutliAliPay() PayInf {
-	return &MutliAliPay{}
-}
-
-func (a *MutliAliPay) Pay(ctx context.Context, orderMsg *cpay.OrderMsg) (interface{}, error) {
-	fmt.Println("====================二维码获取=====================")
-
-	// 初始化 BodyMap
-	orderId := orderMsg.Project + "_" + orderMsg.Id.Hex()
-	bm := make(gopay.BodyMap)
-	amount, err := strconv.ParseFloat(fmt.Sprintf("%.2f", *orderMsg.Amount), 64)
-	if err != nil {
-		return nil, errors.New("价格parse错误!")
-	}
-
-	if err != nil {
-		return nil, err
-	}
-
-	seller := &model.MultiSeller{}
-	fmt.Println("----------------------------alipay-pay-orderMsg------------------------------")
-	fmt.Printf("%#v\n", orderMsg)
-	// 设置默认收款
-	if orderMsg.SellerKey == "" {
-		orderMsg.SellerKey = "sku3d"
-	}
-
-	fmt.Println("----------------------------alipay-pay-sellerkey------------------------------")
-	println(orderMsg.SellerKey)
-	ok, err := repo.RepoSeachDoc(&repo.RepoSession{Ctx: ctx, Client: db.GMongoDb}, &repo.DocSearchOptions{
-		CollectName: "multi-sellers", //商家信息
-		Query:       repo.Map{"key": orderMsg.SellerKey},
-	}, seller)
-	fmt.Println("----------------------------aplipay-multi-sellers------------------------------")
-	fmt.Printf("%#v\n", seller)
-
-	if err != nil {
-		return nil, err
-	}
-	if !ok {
-		return nil, fmt.Errorf("当前商户 %s 支付模块没接入", orderMsg.SellerKey)
-	}
-
-	bm.Set("subject", orderMsg.Name).
-		Set("scene", "bar_code").
-		//Set("auth_code", util.RandomNumber(10))
-		Set("out_trade_no", orderId).
-		Set("total_amount", amount).
-		// 口碑门店,如果是第三方授权这里填写app_auth_token对应账号
-		// Set("seller_id", "2088441503441284"). // sku3d
-		Set("seller_id", seller.AlipaySellerId). // um
-		Set("timeout_express", "10m")
-	// 第三方授权方式 公共参数,不在此处设置
-	// Set("app_auth_token", "202209BB3b97baabe741463ea9d8068222ebfX05")
-
-	pay.MultiAlipayClient.SetAppAuthToken(seller.AlipayAuthToken)
-	res, err := pay.MultiAlipayClient.TradePrecreate(ctx, bm)
-
-	if err != nil {
-		if bizErr, ok := alipay.IsBizError(err); ok {
-			log.Errorf("%+v", bizErr)
-			// do something
-			return "", errors.New(bizErr.SubMsg)
-		}
-		log.Errorf("阿里支付信息%v,err:%v\n", bm, err)
-		return "", err
-	}
-	if res.Response.Msg != "Success" {
-		return "", errors.New(res.Response.ErrorResponse.SubMsg)
-	}
-	fmt.Printf("%#v\n", res.Response)
-	qrCode := res.Response.QrCode
-
-	return qrCode, nil
-	// {"errorNo":200,"result":"https://qr.alipay.com/bax07889ilukkegehj3e2505","errorDesc":""}
-
-}
-
-func (a *MutliAliPay) Close(ctx context.Context, orderMsg *cpay.OrderMsg) (bool, error) {
-
-	orderId := orderMsg.Project + "_" + orderMsg.Id.Hex()
-	bm := make(gopay.BodyMap)
-	bm.Set("out_trade_no", orderId)
-	tradeClose, err := pay.SingleAlipayClient.TradeClose(ctx, bm)
-	if err != nil {
-		return false, err
-	}
-	if tradeClose.Response.Code != "10000" {
-		return false, errors.New(tradeClose.Response.Msg)
-	}
-	return true, nil
-}
-
-// https://opendocs.alipay.com/apis/api_1/alipay.trade.refund
-func (m *MutliAliPay) ReFundPay(ctx context.Context, refund *model.ReFund) (interface{}, error) {
-	bm := make(gopay.BodyMap)
-	// 整数转换为小数
-	parseRefund, err := utils.IntToDecimal(*refund.Refund)
-	if err != nil {
-		return nil, err
-	}
-	bm.Set("out_trade_no", refund.TradeNo).
-		Set("refund_amount", parseRefund).
-		Set("refund_reason", refund.Reason).
-		Set("out_request_no", refund.Id.Hex())
-	res, err := pay.MultiAlipayClient.TradeRefund(ctx, bm)
-	if err != nil {
-		if bizErr, ok := alipay.IsBizError(err); ok {
-			log.Errorf("%+v", bizErr)
-			// do something
-			return false, err
-		}
-		return false, err
-	}
-	if res.Response.Msg != "Success" {
-		return false, errors.New(res.Response.SubMsg)
-	}
-
-	return true, nil
-
-}
-
-// 文档地址:https://opendocs.alipay.com/apis/api_1/alipay.trade.fastpay.refund.query
-func (m *MutliAliPay) ReFundQuery(ctx context.Context, refund *model.ReFund) (interface{}, error) {
-	bm := make(gopay.BodyMap)
-	bm.Set("out_trade_no", refund.TradeNo).
-		Set("out_request_no", refund.Id.Hex())
-	// Set("query_options", []string{})
-
-	res, err := pay.MultiAlipayClient.TradeFastPayRefundQuery(ctx, bm)
-	if err != nil {
-		if bizErr, ok := alipay.IsBizError(err); ok {
-			log.Errorf("%+v", bizErr)
-			// do something
-			return false, err
-		}
-		return false, err
-	}
-	if res.Response.Msg != "Success" {
-		return false, errors.New(res.Response.SubMsg)
-	}
-
-	return res.Response.RefundStatus, nil
-	// return res.Response, nil
-}

+ 0 - 87
pay/bus/multiPay.go

@@ -1,87 +0,0 @@
-package bus
-
-import (
-	"context"
-	"fmt"
-	"pay/db/model"
-	"pay/utils"
-
-	"github.com/nats-io/nats.go"
-	"infish.cn/comm"
-	"infish.cn/comm/pay"
-)
-
-type MultiPay struct{}
-
-func (m *MultiPay) CreateQr() *comm.NatsMsgReplyer {
-	utils.ConsoleFormat(pay.PayMultiQrApi)
-
-	return &comm.NatsMsgReplyer{
-		Subject: pay.PayMultiQrApi,
-		Entity:  func() interface{} { return &pay.OrderMsg{} },
-		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
-			m := entity.(*pay.OrderMsg)
-			pay := PayMod(int(*m.PayMod), MULTI)
-			ctx := context.Background()
-			res, err := pay.Pay(ctx, m)
-			return res, err
-		},
-	}
-}
-
-// 多商户关闭订单应答
-func (m *MultiPay) CloseOrder() *comm.NatsMsgReplyer {
-	utils.ConsoleFormat("comm.pay.multiPay.closeOrder")
-
-	return &comm.NatsMsgReplyer{
-		Subject: "comm.pay.multiPay.closeOrder",
-		Entity:  func() interface{} { return &pay.OrderMsg{} },
-		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
-			m := entity.(*pay.OrderMsg)
-			pay := PayMod(int(*m.PayMod), MULTI)
-			ctx := context.Background()
-			flag, err := pay.Close(ctx, m)
-			return flag, err
-		},
-	}
-}
-
-// 退款
-func (m *MultiPay) Refund() *comm.NatsMsgReplyer {
-	utils.ConsoleFormat("comm.pay.multiPay.refund")
-
-	return &comm.NatsMsgReplyer{
-		Subject: "comm.pay.multiPay.refund",
-		Entity:  func() interface{} { return &model.ReFund{} },
-		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
-			fmt.Println("------------------multipay-refund-----------------")
-			refund := entity.(*model.ReFund)
-			// ???适配缺失退款理由
-			if refund.Reason == "" {
-				refund.Reason = "默认退款"
-			}
-			pay := PayMod(int(*refund.PayMode), MULTI)
-			ctx := context.Background()
-			flag, err := pay.ReFundPay(ctx, refund)
-			return flag, err
-		},
-	}
-}
-
-// 退款查询
-func (m *MultiPay) RefundQuery() *comm.NatsMsgReplyer {
-	utils.ConsoleFormat("comm.pay.multiPay.refundQuery")
-
-	return &comm.NatsMsgReplyer{
-		Subject: "comm.pay.multiPay.refundQuery",
-		Entity:  func() interface{} { return &model.ReFund{} },
-		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
-			fmt.Println("------------------multipay-refund-query-----------------")
-			m := entity.(*model.ReFund)
-			pay := PayMod(int(*m.PayMode), MULTI)
-			ctx := context.Background()
-			status, err := pay.ReFundQuery(ctx, m)
-			return status, err
-		},
-	}
-}

+ 0 - 220
pay/bus/multiWechatPay.go

@@ -1,220 +0,0 @@
-package bus
-
-import (
-	"context"
-	"errors"
-	"fmt"
-	"pay/conf"
-	"pay/db"
-	"pay/db/model"
-	"pay/db/repo"
-	"pay/log"
-	"pay/pay"
-	"pay/utils"
-	"strconv"
-	"time"
-
-	"github.com/go-pay/gopay"
-	cpay "infish.cn/comm/pay"
-)
-
-type MutliWechatPay struct {
-}
-
-func NewMutliWechatPay() PayInf {
-	return &MutliWechatPay{}
-}
-
-func (w *MutliWechatPay) Pay(ctx context.Context, orderMsg *cpay.OrderMsg) (interface{}, error) {
-	// 测试um
-	// orderMsg.SellerKey = "um"
-	if orderMsg.SellerKey == "" || orderMsg.SellerKey == "sku3d" {
-		orderMsg.SellerKey = "sku3d"
-		singleWechatPay := new(SingleWechatPay)
-		return singleWechatPay.Pay(ctx, orderMsg)
-	}
-
-	log.Info("====================二维码获取=====================")
-	fmt.Println("====================二维码获取1=====================")
-	multiPayCnf := utils.GetMultiPayConfig(conf.AppConfig)
-
-	seller := &model.MultiSeller{}
-	fmt.Println("----------------------------wechat-pay-orderMsg------------------------------")
-	fmt.Printf("%#v\n", orderMsg)
-
-	// 设置默认收款
-
-	fmt.Println("----------------------------wechat-pay-sellerkey------------------------------")
-	println(orderMsg.SellerKey)
-	ok, err := repo.RepoSeachDoc(&repo.RepoSession{Ctx: ctx, Client: db.GMongoDb}, &repo.DocSearchOptions{
-		CollectName: "multi-sellers", //商家信息
-		Query:       repo.Map{"key": orderMsg.SellerKey},
-	}, seller)
-	fmt.Println("----------------------------wechat-multi-sellers------------------------------")
-	fmt.Printf("%#v\n", seller)
-
-	if err != nil {
-		return nil, err
-	}
-	if !ok {
-		return nil, fmt.Errorf("当前商户 %s 支付模块没接入", orderMsg.SellerKey)
-	}
-	amount, err := strconv.ParseFloat(fmt.Sprintf("%.2f", *orderMsg.Amount), 64)
-	if err != nil {
-		return nil, errors.New("价格parse错误!")
-	}
-
-	// 初始化 BodyMap
-	orderId := orderMsg.Project + "_" + orderMsg.Id.Hex()
-	bm := make(gopay.BodyMap)
-	bm.Set("sp_appid", multiPayCnf.WechatPay.AppId).
-		Set("sp_mchid", multiPayCnf.WechatPay.MchId).
-		Set("sub_mchid", seller.WechatSellerId).
-		Set("description", orderMsg.Name).
-		Set("out_trade_no", orderId).
-		Set("time_expire", time.Now().Add(10*time.Minute).Format(time.RFC3339)).
-		Set("notify_url", multiPayCnf.WechatPay.NotifyUrl).
-		SetBodyMap("amount", func(bm gopay.BodyMap) {
-			bm.Set("total", amount*100).
-				Set("currency", "CNY")
-		})
-
-	// 判断是电脑支付还是h5
-	var url string
-	if orderMsg.Os == "andriod" || orderMsg.Os == "iphone" || orderMsg.Os == "wap" {
-		bm.SetBodyMap("scene_info", func(bm gopay.BodyMap) {
-			bm.Set("payer_client_ip", orderMsg.Ip)
-			bm.SetBodyMap("h5_info", func(b gopay.BodyMap) {
-				b.Set("type", orderMsg.Ip)
-			})
-		})
-		res, err := pay.MultiWechatpayClient.V3PartnerTransactionH5(ctx, bm)
-		if err != nil {
-			return false, err
-		}
-
-		if res.Code != 0 {
-			return false, err
-		}
-		url = res.Response.H5Url
-	} else {
-		res, err := pay.MultiWechatpayClient.V3PartnerTransactionNative(ctx, bm)
-		if err != nil {
-			return false, err
-		}
-
-		if res.Code != 0 {
-			return false, err
-		}
-		url = res.Response.CodeUrl
-	}
-	return url, nil
-}
-
-func (a *MutliWechatPay) Close(ctx context.Context, orderMsg *cpay.OrderMsg) (bool, error) {
-	multiPayCnf := utils.GetMultiPayConfig(conf.AppConfig)
-	orderId := orderMsg.Project + "_" + orderMsg.Id.Hex()
-	bm := make(gopay.BodyMap)
-	bm.Set("sp_mchid", multiPayCnf.WechatPay.MchId).
-		Set("sub_mchid", orderMsg.SubId)
-	wxRsp, err := pay.MultiWechatpayClient.V3PartnerCloseOrder(ctx, orderId, bm)
-	if err != nil {
-		return false, err
-	}
-	if wxRsp.Code != 0 {
-		return false, errors.New(wxRsp.Error)
-	}
-	return true, nil
-}
-
-// 客户端对应必要参数 out_trade_no out_refund_no total refund payMode
-func (m *MutliWechatPay) ReFundPay(ctx context.Context, refund *model.ReFund) (interface{}, error) {
-	fmt.Println("----------------------------wechat-pay-refundPay------------------------------")
-
-	// ??? 适配账号缺失
-	if refund.SellerKey == "" || refund.SellerKey == "sku3d" {
-		fmt.Println("----------------------------comming-sing-wechtpay-refundPay------------------------------")
-		refund.SellerKey = "sku3d"
-		singleWechatPay := new(SingleWechatPay)
-		return singleWechatPay.ReFundPay(ctx, refund)
-	}
-	fmt.Println("----------------------------comming-multi-wechtpay-refundPay------------------------------")
-
-	seller := &model.MultiSeller{}
-	println(refund.SellerKey)
-	ok, err := repo.RepoSeachDoc(&repo.RepoSession{Ctx: ctx, Client: db.GMongoDb}, &repo.DocSearchOptions{
-		CollectName: "multi-sellers", //商家信息
-		Query:       repo.Map{"key": refund.SellerKey},
-	}, seller)
-	fmt.Println("----------------------------wechat-multi-seller------------------------------")
-	fmt.Printf("%#v\n", seller)
-
-	if err != nil {
-		return nil, err
-	}
-	if !ok {
-		return nil, fmt.Errorf("当前商户 %s 支付模块没接入", refund.SellerKey)
-	}
-
-	bm := make(gopay.BodyMap)
-	multiPayCnf := utils.GetMultiPayConfig(conf.AppConfig)
-
-	// 商品
-	goods := make([]gopay.BodyMap, 0)
-	gd := make(gopay.BodyMap)
-	gd.Set("merchant_goods_id", refund.ProductId.Hex()).
-		Set("goods_name", refund.ProductName).
-		Set("unit_price", refund.ProductPrice).
-		Set("refund_amount", refund.RefundAmount).
-		Set("refund_quantity", refund.RefundQuantity)
-	goods = append(goods, gd)
-
-	bm.Set("out_trade_no", refund.TradeNo).
-		Set("sub_mchid", multiPayCnf.WechatPay.SubMchId).
-		Set("out_refund_no", refund.Id.Hex()).
-		Set("reason", refund.Reason).
-		Set("notify_url", multiPayCnf.WechatPay.NotifyUrl).
-		SetBodyMap("amount", func(bm gopay.BodyMap) {
-			bm.Set("total", refund.Total).
-				Set("currency", "CNY").
-				Set("refund", refund.Refund)
-		})
-	// 商品相关
-	if len(refund.ProductId.Hex()) > 10 {
-		bm.Set("goods_detail", goods)
-	}
-
-	fmt.Println("-----------------------------------------")
-	fmt.Printf("bm--------------------------%#v\n", bm)
-
-	wxRsp, err := pay.MultiWechatpayClient.V3Refund(ctx, bm)
-
-	if err != nil {
-		return false, err
-	}
-	if wxRsp.Code != 0 {
-		return false, errors.New(wxRsp.Error)
-	}
-	// 退款状态
-	// refundStatus := wxRsp.Response.Status
-
-	return true, nil
-}
-
-// 退款状态查询
-func (m *MutliWechatPay) ReFundQuery(ctx context.Context, refund *model.ReFund) (interface{}, error) {
-	bm := make(gopay.BodyMap)
-	// 需要设置子商户id
-	multiPayCnf := utils.GetMultiPayConfig(conf.AppConfig)
-	bm.Set("sub_mchid", multiPayCnf.WechatPay.SubMchId)
-	res, err := pay.MultiWechatpayClient.V3RefundQuery(ctx, refund.Id.Hex(), bm)
-	if err != nil {
-		return nil, err
-	}
-	if res.Code != 0 {
-		return nil, errors.New(res.Error)
-	}
-
-	return res.Response.Status, nil
-	// return wxRsp.Response, nil
-}

+ 0 - 4
pay/bus/nats.go

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

+ 3 - 13
pay/bus/pay.go

@@ -2,7 +2,6 @@ package bus
 
 import (
 	"context"
-	"fmt"
 	"pay/db/model"
 
 	"infish.cn/comm/pay"
@@ -18,25 +17,16 @@ const (
 type PayInf interface {
 	Pay(context.Context, *pay.OrderMsg) (interface{}, error)
 	Close(context.Context, *pay.OrderMsg) (bool, error)
-	ReFundPay(ctx context.Context, refund *model.ReFund) (interface{}, error)
+	ReFundPay(ctx context.Context, refund *pay.ReFund) (interface{}, error)
 	ReFundQuery(ctx context.Context, refund *model.ReFund) (interface{}, error)
 }
 
 func PayMod(payType int, category int) PayInf {
-	if category == SINGLE && payType == ALIPAY {
-		fmt.Println("=================single aplipay====================")
+	if payType == ALIPAY {
 		return NewSingleAliPay()
-	} else if category == SINGLE && payType == WECHATPAY {
-		fmt.Println("=================single wechat====================")
+	} else if payType == WECHATPAY {
 		return NewSingleWechatPay()
 
-	} else if category == MULTI && payType == ALIPAY {
-		fmt.Println("=================multi aplipay====================")
-		return NewMutliAliPay()
-
-	} else if category == MULTI && payType == WECHATPAY {
-		fmt.Println("=================multi wechat====================")
-		return NewMutliWechatPay()
 	}
 	return nil
 }

+ 38 - 0
pay/bus/refund.go

@@ -0,0 +1,38 @@
+package bus
+
+import (
+	"context"
+	"pay/db"
+	"pay/db/repo"
+	"pay/utils"
+
+	"github.com/nats-io/nats.go"
+	"go.mongodb.org/mongo-driver/bson/primitive"
+	"infish.cn/comm"
+	"infish.cn/comm/pay"
+)
+
+// 创建订单退款申请
+func PayRefundCreate() *comm.NatsMsgReplyer {
+	refund := pay.ReFund{}
+	utils.ConsoleFormat(pay.PayRefundCreateApi)
+	return &comm.NatsMsgReplyer{
+		Subject: pay.PayRefundCreateApi,
+		Entity:  func() interface{} { return &refund },
+		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
+			refund := entity.(*pay.ReFund)
+			ctx := context.Background()
+			res, err := createRefund(ctx, refund)
+			return res, err
+		},
+	}
+}
+
+func createRefund(ctx context.Context, refund *pay.ReFund) (id primitive.ObjectID, err error) {
+	_id, err := repo.RepoAddDoc(&repo.RepoSession{Ctx: ctx, Client: db.GMongoDb}, repo.CollectionRefund, &refund)
+	if err != nil {
+		return primitive.NilObjectID, err
+	}
+	id, err = primitive.ObjectIDFromHex(_id)
+	return
+}

+ 4 - 6
pay/bus/singleAliPay.go

@@ -7,7 +7,6 @@ import (
 	"pay/db/model"
 	"pay/log"
 	"pay/pay"
-	"pay/utils"
 	"strconv"
 
 	"github.com/go-pay/gopay"
@@ -77,15 +76,14 @@ func (a *SingleAliPay) Close(ctx context.Context, orderMsg *cpay.OrderMsg) (bool
 }
 
 // https://opendocs.alipay.com/apis/api_1/alipay.trade.refund
-func (s *SingleAliPay) ReFundPay(ctx context.Context, refund *model.ReFund) (interface{}, error) {
+func (s *SingleAliPay) ReFundPay(ctx context.Context, refund *cpay.ReFund) (interface{}, error) {
 	bm := make(gopay.BodyMap)
-	// 整数转换为小数
-	parseRefund, err := utils.IntToDecimal(*refund.Refund)
+	amount, err := strconv.ParseFloat(fmt.Sprintf("%.2f", *refund.Amount), 64)
 	if err != nil {
-		return nil, err
+		return nil, errors.New("价格parse错误!")
 	}
 	bm.Set("out_trade_no", refund.TradeNo).
-		Set("refund_amount", parseRefund).
+		Set("refund_amount", amount).
 		Set("refund_reason", refund.Reason).
 		Set("out_request_no", refund.Id.Hex())
 	res, err := pay.SingleAlipayClient.TradeRefund(ctx, bm)

+ 1 - 1
pay/bus/singlePay.go

@@ -56,7 +56,7 @@ func (s *SinglePay) Refund() *comm.NatsMsgReplyer {
 
 	return &comm.NatsMsgReplyer{
 		Subject: pay.PaySingleRefundApi,
-		Entity:  func() interface{} { return &model.ReFund{} },
+		Entity:  func() interface{} { return &pay.ReFund{} },
 		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
 			refund := entity.(*model.ReFund)
 			// ???适配缺失退款理由

+ 12 - 8
pay/bus/singleWechatPay.go

@@ -85,18 +85,22 @@ func (a *SingleWechatPay) Close(ctx context.Context, orderMsg *cpay.OrderMsg) (b
 
 // https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_9.shtml
 // 客户端对应必要参数 out_trade_no out_refund_no total refund payMode
-func (s *SingleWechatPay) ReFundPay(ctx context.Context, refund *model.ReFund) (interface{}, error) {
+func (s *SingleWechatPay) ReFundPay(ctx context.Context, refund *cpay.ReFund) (interface{}, error) {
 	bm := make(gopay.BodyMap)
 	singlePayCnf := utils.GetSinglePayConfig(conf.AppConfig)
+	amount, err := strconv.ParseFloat(fmt.Sprintf("%.2f", *refund.Amount), 64)
+	if err != nil {
+		return nil, errors.New("价格parse错误!")
+	}
 
 	// 商品
 	goods := make([]gopay.BodyMap, 0)
 	gd := make(gopay.BodyMap)
-	gd.Set("merchant_goods_id", refund.ProductId.Hex()).
-		Set("goods_name", refund.ProductName).
-		Set("unit_price", refund.ProductPrice).
-		Set("refund_amount", refund.RefundAmount).
-		Set("refund_quantity", refund.RefundQuantity)
+	gd.Set("merchant_goods_id", refund.PointId.Hex()).
+		Set("goods_name", refund.PointName).
+		Set("unit_price", refund.PointPrice).
+		Set("refund_amount", refund.PointAmount).
+		Set("refund_quantity", refund.Quantity)
 	goods = append(goods, gd)
 
 	bm.Set("out_trade_no", refund.TradeNo).
@@ -106,10 +110,10 @@ func (s *SingleWechatPay) ReFundPay(ctx context.Context, refund *model.ReFund) (
 		SetBodyMap("amount", func(bm gopay.BodyMap) {
 			bm.Set("total", refund.Total).
 				Set("currency", "CNY").
-				Set("refund", refund.Refund)
+				Set("refund", amount*100)
 		})
 	// 商品相关
-	if len(refund.ProductId.Hex()) > 10 {
+	if !refund.PointId.IsZero() {
 		bm.Set("goods_detail", goods)
 	}
 

+ 2 - 0
pay/db/repo/repo.go

@@ -24,6 +24,8 @@ const (
 	CollectionOrder = "orders"
 	// 支付点管理
 	CollectionPoint = "points"
+	// 退款
+	CollectionRefund = "refunds"
 )
 
 type Map map[string]interface{}