animeic 1 年之前
父節點
當前提交
b7e71aa195

+ 14 - 5
pay/Dockerfile

@@ -1,4 +1,17 @@
-FROM alpine 
+# FROM alpine 
+
+# RUN echo -e https://mirrors.ustc.edu.cn/alpine/v3.15/main > /etc/apk/repositories \
+#   && cat /etc/apk/repositories \
+# # 设置时区为上海
+#   && apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
+#   && echo "Asia/Shanghai" > /etc/timezone \
+#   && apk del tzdata \
+# # 解决apline 运行编译后的执行文件 not found错误
+# # 由于alpine镜像使用的是musl libc而不是gnu libc,/lib64/ 是不存在的。但他们是兼容的,可以创建个软连接
+#   && mkdir /lib64 \
+#   && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 \
+FROM hub.afina.studio/afina-studio/alpine
+# https://github.com/Docker-Hub-frolvlad/docker-alpine-glibc
 
 RUN echo -e https://mirrors.ustc.edu.cn/alpine/v3.15/main > /etc/apk/repositories \
   && cat /etc/apk/repositories \
@@ -6,10 +19,6 @@ RUN echo -e https://mirrors.ustc.edu.cn/alpine/v3.15/main > /etc/apk/repositorie
   && apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
   && echo "Asia/Shanghai" > /etc/timezone \
   && apk del tzdata \
-# 解决apline 运行编译后的执行文件 not found错误
-# 由于alpine镜像使用的是musl libc而不是gnu libc,/lib64/ 是不存在的。但他们是兼容的,可以创建个软连接
-  && mkdir /lib64 \
-  && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 \
   && mkdir -p /root/pay
 
 WORKDIR /root/pay

+ 92 - 0
pay/api/oreder.go

@@ -0,0 +1,92 @@
+package api
+
+// TODO 测试
+
+import (
+	"errors"
+	"pay/db/repo"
+	"pay/log"
+	"time"
+
+	"github.com/gin-gonic/gin"
+	"go.mongodb.org/mongo-driver/bson/primitive"
+
+	"infish.cn/comm/pay"
+)
+
+func PayOrder(r *GinRouter) {
+	r.POSTJWT("/order/create", CreateOrder)
+	r.POSTJWT("/order/delete/:id", DeleteOrder)
+	r.GET("/order/list", OrderList)
+	r.GET("/order/detail/:id", OrderDetail)
+	r.POSTJWT("/order/update", UpdateOrder)
+
+}
+
+func CreateOrder(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	var order pay.Order
+	err := c.ShouldBindJSON(&order)
+	if err != nil {
+		log.Error(err)
+		return nil, err
+	}
+	order.CreateTime = time.Now()
+	order.UpdateTime = time.Now()
+	return repo.RepoAddDoc(apictx.CreateRepoCtx(), "order", &order)
+}
+
+func DeleteOrder(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	_id := c.Param("id")
+	id, _ := primitive.ObjectIDFromHex(_id)
+	if id.IsZero() {
+		return nil, errors.New("id错误")
+	}
+	return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), "order", _id)
+}
+
+func OrderList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	page, size, query := UtilQueryPageSize(c)
+	return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
+		CollectName: "order",
+		Page:        page,
+		Size:        size,
+		Query:       query,
+	})
+}
+
+func OrderDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	_id := c.Param("id")
+
+	id, _ := primitive.ObjectIDFromHex(_id)
+	if id.IsZero() {
+		return nil, errors.New("id错误")
+	}
+	query := repo.Map{"_id": id}
+	order := &pay.Order{}
+	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+		CollectName: "order",
+		Query:       query,
+	}, order)
+	if err != nil {
+		log.Error(err)
+		return nil, err
+	}
+
+	if !found {
+		return nil, errors.New("未找到该数据")
+	}
+	return order, nil
+}
+
+func UpdateOrder(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	var order pay.Order
+	err := c.ShouldBindJSON(&order)
+	if err != nil {
+		log.Error(err)
+		return nil, err
+	}
+	if order.Id.IsZero() {
+		return nil, errors.New("id错误")
+	}
+	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), "order", order.Id.Hex(), &order)
+}

+ 33 - 15
pay/api/manage.go → pay/api/point.go

@@ -9,20 +9,38 @@ import (
 	"github.com/gin-gonic/gin"
 	"go.mongodb.org/mongo-driver/bson"
 	"go.mongodb.org/mongo-driver/bson/primitive"
-	"infish.cn/comm"
+	"infish.cn/comm/pay"
 )
 
-func PayManager(r *GinRouter) {
-	r.POSTJWT("/manage/create", CreatePay)
-	r.POSTJWT("/manage/delete/:id", DeletePay)
-	r.GET("/manage/list", PayList)
-	r.GET("/manage/detail/:id", PayDetail)
-	r.POSTJWT("/manage/update", UpdatePay)
+func PayPoint(r *GinRouter) {
+	r.POST("/point/create", CreatePay)
+	r.POSTJWT("/point/delete/:id", DeletePay)
+	r.GET("/point/list", PayList)
+	r.GET("/point/detail/:id", PayDetail)
+	r.POSTJWT("/point/update", UpdatePay)
 
 }
 
+//	type Pay struct {
+//		Id primitive.ObjectID `bson:"_id,omitempty" json:"_id,omitempty"`
+//		// 支付目标项目名 queenshow
+//		Project     string `bson:"project,omitempty" json:"project,omitempty"`
+//		ProductName string `bson:"productName,omitempty" json:"productName,omitempty"`
+//		// basic plus plus+
+//		Level string `bson:"level,omitempty" json:"level,omitempty"`
+//		// 支付项目包含的服务
+//		Rules []*PayRules `bson:"rules,omitempty" json:"rules,omitempty"`
+//		// 支持的支付类型 alipay wechatpay other
+//		Types []*PayTypes `bson:"types,omitempty" json:"types,omitempty"`
+//		// 价格 支付宝整数代表元 微信整数代表分 业务代码中转换,数据为int32, 如果32.15 price == 3215
+//		Price *int32 `bson:"price,omitempty" json:"price,omitempty"`
+//		// 排序
+//		Sort       *int32    `bson:"sort,omitempty" json:"sort,omitempty"`
+//		CreateTime time.Time `bson:"createTime,omitempty" json:"createTime,omitempty"`
+//		UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime,omitempty"`
+//	}
 func CreatePay(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	var pay comm.Pay
+	var pay pay.Point
 	err := c.ShouldBindJSON(&pay)
 	if err != nil {
 		log.Error(err)
@@ -30,7 +48,7 @@ func CreatePay(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	}
 	pay.CreateTime = time.Now()
 	pay.UpdateTime = time.Now()
-	return repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionPay, &pay)
+	return repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionPoint, &pay)
 }
 
 func DeletePay(c *gin.Context, apictx *ApiSession) (interface{}, error) {
@@ -39,13 +57,13 @@ func DeletePay(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	if id.IsZero() {
 		return nil, errors.New("id错误")
 	}
-	return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionPay, _id)
+	return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionPoint, _id)
 }
 
 func PayList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	page, size, query := UtilQueryPageSize(c)
 	return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
-		CollectName: repo.CollectionPay,
+		CollectName: repo.CollectionPoint,
 		Page:        page,
 		Size:        size,
 		Query:       query,
@@ -61,9 +79,9 @@ func PayDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		return nil, errors.New("id错误")
 	}
 	query := repo.Map{"_id": id}
-	pay := &comm.Pay{}
+	pay := &pay.Point{}
 	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-		CollectName: repo.CollectionPay,
+		CollectName: repo.CollectionPoint,
 		Query:       query,
 	}, pay)
 	if err != nil {
@@ -78,7 +96,7 @@ func PayDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 }
 
 func UpdatePay(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	var pay comm.Pay
+	var pay pay.Point
 	err := c.ShouldBindJSON(&pay)
 	if err != nil {
 		log.Error(err)
@@ -87,7 +105,7 @@ func UpdatePay(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	if pay.Id.IsZero() {
 		return nil, errors.New("id错误")
 	}
-	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionPay, pay.Id.Hex(), &pay)
+	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionPoint, pay.Id.Hex(), &pay)
 }
 
 func CreateQr(c *gin.Context, apictx *ApiSession) (interface{}, error) {

+ 5 - 2
pay/api/router.go

@@ -18,8 +18,11 @@ func RegRouters(svc *Service) {
 	// 多商户支付
 	PayMulti(payGroup)
 
-	// 支付管理
-	PayManager(payGroup)
+	// 支付点管理
+	PayPoint(payGroup)
+
+	// 支付订单
+	PayOrder(payGroup)
 
 	// 其他测试
 	payGroup.GET("/print", PrintParam)

+ 1 - 0
pay/api/singleWechatPayCallback.go

@@ -47,6 +47,7 @@ func (a *SingleWechatPayCallback) CallBack(c *http.Request) (interface{}, error)
 	if result.TradeState == "SUCCESS" {
 		fmt.Println("----------------success----------------------")
 		res := &model.OrderMsg{Id: orderSlice[1], PayMode: &payMode, ModName: orderSlice[0]}
+		// err = bus.NatsCenter.PushMessage(comm.NewAppPaySuccSubject(orderSlice[0]), res)
 		err = bus.NatsCenter.PushMessage(comm.NewAppPaySuccSubject(orderSlice[0]), res)
 		if err != nil {
 			fmt.Println("----------------success-err----------------------")

+ 7 - 7
pay/app.yaml

@@ -1,7 +1,7 @@
 port: 8888
 name: pay
 shopName: sku3d
-version: 1.0.0
+version: 2.0.0
 
 ssl: false
 sslCert: ./cert/server.crt
@@ -36,10 +36,10 @@ single:
       appId: 2021003132622153
       privateKey: MIIEpQIBAAKCAQEAmJW+3iUW1mDIo7H9F7XpOp7M0jGvnMXMnDJTazoaQxZd/p8KXx/JM3MIol/54wQabi64eJg30oy5xXjycoEf1F9ROnT2kGiYUKD9Q+qXAKSU1+zl814SIM8xP2kBe3bsTw4vpvePNn1TizRw7ex/Bm+0jdH1tmpuapLGF/9yZyf3MtkS2M4rfUrKfGgAlAlrWzut1lRS3ep++zV1LtWJLsJ8NBW0qEjVABnwjbCWVAz9oVE82+880PhUraF/2kSy8D90etFIoezbK+QjAvQELnLL+SEtUFP9RSX1rL3riphtS7YKszQdV7UT3lv6pXmAtODNQx88Xi8GwgPpaTd71wIDAQABAoIBAQCSx0HTKfR9Bp8bMMWZQGl59XZsIFWhRnkcLCEovbyzmlmS7OSqOsZuUpMUt6SG59SQ9yqG/057oNm3hzAaS/IVdheKVyc0JRmYPjVDVvApMyjnSUCuymg/3W+vYtCFNxH8vlXClNPUA90QxMJ5bQ2IYH5cCoQGFP3gUQ5z2Uvww/no2C649s9FJ8vtK1AM76emgeGRRpa1Fj5YCKtnJauBG5CxmfDn0TrvwKxZu2efByDcVXakps8wED+ixD4ZrIZCLqHsuWSA/TNlOrFm2Kuql39xBKBAmXmPiVIGIfTubZcy9UbMAFwzoL7tBsXjAnnTTQl06hHdms9gPMV+eJaRAoGBAMnOouqQ5XGyaSL/PMCcSdAy7/4c9nII+ecD9H/B2Qrr0YrGqiPNgtNVBWuviyb6tVbuQOJIb62M8MhpfGh0KSRTN8rauzIyFeNY21KIUhUA3GipyzWXS4CGGhfxRGA/BN0i74KE/6OvO5z1p1ECCYkhfQN+lo9uCVXtMrXPYMm/AoGBAMGPS6DNb4MlxKsityYf1DdGc9SVJgTgRgNf9I77jL5cYZ3flKiEczrPkTs/0uQpd66968I5wB4cN2aSCcJdGCiVvcspUB9ecNPDbsrxLD2HUxwaY0cRfz8Yq8Zo5m2SwCfIy11+OZMdZBUhwH72DR8oD7tzJp4/ae9vbKnMpWPpAoGBAL6ZPAOAkEOe9m+IUw+zTH+n7ES7hANV+Pi4Io8bPWt0J/cDBSRFcD86uKDpLerFtMmCwqM1OMzYJX2TK13YABd/xV0A0vZomYWcoaBEggm2Q3VSkEtwNm4PuctNIoAoZOaanU1PYcZttUbcOIdo/iqXB2Rqhba3fXe7TD6su0QvAoGBAIULMOmzq72SnU8gipE6+YyQ8ZciecKKQbWaJCiPwVsrdrGkd7Mpb2byO5plMVlBI5HJ255iQaqwrGflY63kfXGQE6fsmrUlHhqAz8vQ4B7ewIKlpK252iQNmizD9/dDEq+F9jsqQvrbDer0izL5f2V2DPJEoTvOzMsWZLOGBfzZAoGAFTxKcIPsD0M+HNxKcP7FVL+U8qNklDn6nwE6jydvxhezlRTUOYR/UR2n3LRanR4xl6j++r4vLJAUvjJYVwgk4fSEMgbE+Vy/HQYCq7mWklatahjyT4+j86nRvKWpHoPGdhAIS6S1J5PlWX5iyVs9PKkE7zNrPVJu5p9M+HUzg34=
       isProd: true
-      returnUrl: https://www.3dqueen.cn/comm/v1/pay/single/alipay/callback
-      notifyUrl: https://www.3dqueen.cn/comm/v1/pay/single/alipay/callback
-      # returnUrl: https://api.animeii.tech/pay/single/alipay/callback
-      # notifyUrl: https://api.animeii.tech/pay/single/alipay/callback
+      # returnUrl: https://www.3dqueen.cn/comm/v1/pay/single/alipay/callback
+      # notifyUrl: https://www.3dqueen.cn/comm/v1/pay/single/alipay/callback
+      returnUrl: https://api.afina.studio/pay/single/alipay/callback
+      notifyUrl: https://api.afina.studio/pay/single/alipay/callback
       appCertPath: ./crt/single/alipay/appCertPublicKey.crt
       aliPayRootCertPath: ./crt/single/alipay/alipayRootCert.crt
       aliPayPublicCertPath: ./crt/single/alipay/alipayCertPublicKey_RSA2.crt
@@ -50,8 +50,8 @@ single:
       serialNo: 690F2A694D2B6EFA2E4AEFE76E652CFC61867524
       apiV3Key: BSNDcbbL5r122gEdoCSd9tGNIPNvjSxx
       privateKey: ./crt/single/wechat/apiclient_key.pem
-      notifyUrl:  https://www.3dqueen.cn/comm/v1/pay/single/wechat/callback
-      # notifyUrl:  https://api.animeii.tech/pay/single/wechat/callback
+      # notifyUrl:  https://www.3dqueen.cn/comm/v1/pay/single/wechat/callback
+      notifyUrl:  https://api.afina.studio/pay/single/wechat/callback
 
 multi:
   - name: sku3d

+ 14 - 1
pay/assettest.log

@@ -1 +1,14 @@
-{"level":"info","timestamp":"2023-07-04 09:55:23","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-04 15:11:52","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-04 15:14:01","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-04 16:16:31","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-05 10:09:06","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-05 10:10:19","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-05 10:16:04","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"error","timestamp":"2023-07-05 10:16:06","message":"[invalid character 'ï' after object key:value pair]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-05 10:55:53","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-05 10:56:10","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-05 11:00:29","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-05 11:01:21","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-05 11:01:57","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-05 11:02:15","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-05 11:35:31","message":"[初始化支付客户端]","service_name":"assettest"}

+ 0 - 66
pay/bus/manage.go

@@ -1,66 +0,0 @@
-package bus
-
-import (
-	"context"
-	"pay/db"
-	"pay/db/repo"
-	"pay/utils"
-
-	"github.com/nats-io/nats.go"
-	"go.mongodb.org/mongo-driver/bson"
-	"infish.cn/comm"
-)
-
-// id, 支付数量 * price,userId ==> order --> createqr/refound... --> 为用户授权服务
-
-// 根据project获取列表,sort排序-->选择数量支付方式-->生成订单-->成功
-
-// 根据项目类型 获取支付列表
-// query := map[string]interface{}{"project":"queenshow"}
-func PayProjectList() *comm.NatsMsgReplyer {
-
-	utils.ConsoleFormat(comm.CommPayProjectListApi)
-	return &comm.NatsMsgReplyer{
-		Subject: comm.CommPayProjectListApi,
-		Entity:  func() interface{} { return map[string]interface{}{} },
-		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
-			query := entity.(map[string]interface{})
-			ctx := context.Background()
-			res, err := getPayProjects(ctx, query)
-			return res, err
-		},
-	}
-}
-
-func getPayProjects(ctx context.Context, query map[string]interface{}) (projects []*comm.Pay, err error) {
-	err = repo.RepoSeachDocs(&repo.RepoSession{Ctx: ctx, Client: db.GMongoDb}, &repo.DocSearchOptions{
-		CollectName: repo.CollectionPay,
-		Query:       query,
-		Sort:        bson.D{bson.E{Key: "sort", Value: 1}, bson.E{Key: "createTime", Value: -1}},
-	}, &projects)
-	return
-}
-
-// query := map[string]interface{}{"_id":"xxx"}
-func PayProjectDetail() *comm.NatsMsgReplyer {
-
-	utils.ConsoleFormat(comm.CommPayProjectDetailApi)
-	return &comm.NatsMsgReplyer{
-		Subject: comm.CommPayProjectDetailApi,
-		Entity:  func() interface{} { return map[string]interface{}{} },
-		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
-			query := entity.(map[string]interface{})
-			ctx := context.Background()
-			res, err := getPayProject(ctx, query)
-			return res, err
-		},
-	}
-}
-
-func getPayProject(ctx context.Context, query map[string]interface{}) (project *comm.Pay, err error) {
-	_, err = repo.RepoSeachDoc(&repo.RepoSession{Ctx: ctx, Client: db.GMongoDb}, &repo.DocSearchOptions{
-		CollectName: repo.CollectionPay,
-		Query:       query,
-	}, &project)
-	return
-}

+ 5 - 4
pay/bus/multiAliPay.go

@@ -13,6 +13,7 @@ import (
 
 	"github.com/go-pay/gopay"
 	"github.com/go-pay/gopay/alipay"
+	cpay "infish.cn/comm/pay"
 )
 
 type MutliAliPay struct {
@@ -22,11 +23,11 @@ func NewMutliAliPay() PayInf {
 	return &MutliAliPay{}
 }
 
-func (a *MutliAliPay) Pay(ctx context.Context, orderMsg *model.OrderMsg) (interface{}, error) {
+func (a *MutliAliPay) Pay(ctx context.Context, orderMsg *cpay.OrderMsg) (interface{}, error) {
 	fmt.Println("====================二维码获取=====================")
 
 	// 初始化 BodyMap
-	orderId := orderMsg.ModName + "_" + orderMsg.Id
+	orderId := orderMsg.Project + "_" + orderMsg.Id.Hex()
 	bm := make(gopay.BodyMap)
 	parseAmount, err := utils.IntToDecimal(int32(*orderMsg.Amount))
 
@@ -93,9 +94,9 @@ func (a *MutliAliPay) Pay(ctx context.Context, orderMsg *model.OrderMsg) (interf
 
 }
 
-func (a *MutliAliPay) Close(ctx context.Context, orderMsg *model.OrderMsg) (bool, error) {
+func (a *MutliAliPay) Close(ctx context.Context, orderMsg *cpay.OrderMsg) (bool, error) {
 
-	orderId := orderMsg.ModName + "_" + orderMsg.Id
+	orderId := orderMsg.Project + "_" + orderMsg.Id.Hex()
 	bm := make(gopay.BodyMap)
 	bm.Set("out_trade_no", orderId)
 	tradeClose, err := pay.SingleAlipayClient.TradeClose(ctx, bm)

+ 11 - 10
pay/bus/multiPay.go

@@ -8,6 +8,7 @@ import (
 
 	"github.com/nats-io/nats.go"
 	"infish.cn/comm"
+	"infish.cn/comm/pay"
 )
 
 type MultiPay struct{}
@@ -17,10 +18,10 @@ func (m *MultiPay) CreateQr() *comm.NatsMsgReplyer {
 
 	return &comm.NatsMsgReplyer{
 		Subject: comm.CommPayMallCreateQrApi,
-		Entity:  func() interface{} { return &model.OrderMsg{} },
-		Cb2: func(msg *nats.Msg, entity interface{}) (interface{}, error) {
-			m := entity.(*model.OrderMsg)
-			pay := PayMod(*m.PayMode, MULTI)
+		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
@@ -34,10 +35,10 @@ func (m *MultiPay) CloseOrder() *comm.NatsMsgReplyer {
 
 	return &comm.NatsMsgReplyer{
 		Subject: "comm.pay.multiPay.closeOrder",
-		Entity:  func() interface{} { return &model.OrderMsg{} },
-		Cb2: func(msg *nats.Msg, entity interface{}) (interface{}, error) {
-			m := entity.(*model.OrderMsg)
-			pay := PayMod(*m.PayMode, MULTI)
+		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
@@ -52,7 +53,7 @@ func (m *MultiPay) Refund() *comm.NatsMsgReplyer {
 	return &comm.NatsMsgReplyer{
 		Subject: "comm.pay.multiPay.refund",
 		Entity:  func() interface{} { return &model.ReFund{} },
-		Cb2: func(msg *nats.Msg, entity interface{}) (interface{}, error) {
+		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
 			fmt.Println("------------------multipay-refund-----------------")
 			refund := entity.(*model.ReFund)
 			// ???适配缺失退款理由
@@ -74,7 +75,7 @@ func (m *MultiPay) RefundQuery() *comm.NatsMsgReplyer {
 	return &comm.NatsMsgReplyer{
 		Subject: "comm.pay.multiPay.refundQuery",
 		Entity:  func() interface{} { return &model.ReFund{} },
-		Cb2: func(msg *nats.Msg, entity interface{}) (interface{}, error) {
+		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
 			fmt.Println("------------------multipay-refund-query-----------------")
 			m := entity.(*model.ReFund)
 			pay := PayMod(int(*m.PayMode), MULTI)

+ 5 - 4
pay/bus/multiWechatPay.go

@@ -14,6 +14,7 @@ import (
 	"time"
 
 	"github.com/go-pay/gopay"
+	cpay "infish.cn/comm/pay"
 )
 
 type MutliWechatPay struct {
@@ -23,7 +24,7 @@ func NewMutliWechatPay() PayInf {
 	return &MutliWechatPay{}
 }
 
-func (w *MutliWechatPay) Pay(ctx context.Context, orderMsg *model.OrderMsg) (interface{}, error) {
+func (w *MutliWechatPay) Pay(ctx context.Context, orderMsg *cpay.OrderMsg) (interface{}, error) {
 	// 测试um
 	// orderMsg.SellerKey = "um"
 	if orderMsg.SellerKey == "" || orderMsg.SellerKey == "sku3d" {
@@ -59,7 +60,7 @@ func (w *MutliWechatPay) Pay(ctx context.Context, orderMsg *model.OrderMsg) (int
 	}
 
 	// 初始化 BodyMap
-	orderId := orderMsg.ModName + "_" + orderMsg.Id
+	orderId := orderMsg.Project + "_" + orderMsg.Id.Hex()
 	bm := make(gopay.BodyMap)
 	bm.Set("sp_appid", multiPayCnf.WechatPay.AppId).
 		Set("sp_mchid", multiPayCnf.WechatPay.MchId).
@@ -105,9 +106,9 @@ func (w *MutliWechatPay) Pay(ctx context.Context, orderMsg *model.OrderMsg) (int
 	return url, nil
 }
 
-func (a *MutliWechatPay) Close(ctx context.Context, orderMsg *model.OrderMsg) (bool, error) {
+func (a *MutliWechatPay) Close(ctx context.Context, orderMsg *cpay.OrderMsg) (bool, error) {
 	multiPayCnf := utils.GetMultiPayConfig(conf.AppConfig)
-	orderId := orderMsg.ModName + "_" + orderMsg.Id
+	orderId := orderMsg.Project + "_" + orderMsg.Id.Hex()
 	bm := make(gopay.BodyMap)
 	bm.Set("sp_mchid", multiPayCnf.WechatPay.MchId).
 		Set("sub_mchid", orderMsg.SubId)

+ 5 - 3
pay/bus/nats.go

@@ -13,15 +13,17 @@ 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{}, []*comm.NatsMsgReplyer{
+	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(),
-		PayProjectList(),
-		PayProjectDetail(),
+		PayPointList(),
+		PayPointDetail(),
 	})
 	NatsCenter = bus
 	return NatsCenter

+ 65 - 0
pay/bus/order.go

@@ -0,0 +1,65 @@
+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"
+)
+
+// 根据项目类型 获取支付列表
+// query := map[string]interface{}{"project":"queenshow"}
+
+func PayOrderCreate() *comm.NatsMsgReplyer {
+	order := &pay.Order{}
+	utils.ConsoleFormat(pay.PayOrderCreateApi)
+	return &comm.NatsMsgReplyer{
+		Subject: pay.PayOrderCreateApi,
+		Entity:  func() interface{} { return &order },
+		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
+			order := entity.(*pay.Order)
+			ctx := context.Background()
+			res, err := createOrder(ctx, order)
+			return res, err
+		},
+	}
+}
+
+func createOrder(ctx context.Context, order *pay.Order) (id primitive.ObjectID, err error) {
+	_id, err := repo.RepoAddDoc(&repo.RepoSession{Ctx: ctx, Client: db.GMongoDb}, repo.CollectionOrder, &order)
+	if err != nil {
+		return primitive.NilObjectID, err
+	}
+	id, err = primitive.ObjectIDFromHex(_id)
+	return
+}
+
+// 获取订单信息
+// query := map[string]interface{}{"_id":"xxx"}
+func PayOrderDetail() *comm.NatsMsgReplyer {
+	qmap := make(map[string]interface{})
+	utils.ConsoleFormat(pay.PayOrderDetailApi)
+	return &comm.NatsMsgReplyer{
+		Subject: pay.PayOrderDetailApi,
+		Entity:  func() interface{} { return &qmap },
+		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
+			query := entity.(*map[string]interface{})
+			ctx := context.Background()
+			res, err := getPayOrder(ctx, *query)
+			return res, err
+		},
+	}
+}
+
+func getPayOrder(ctx context.Context, query map[string]interface{}) (order *pay.Order, err error) {
+	_, err = repo.RepoSeachDoc(&repo.RepoSession{Ctx: ctx, Client: db.GMongoDb}, &repo.DocSearchOptions{
+		CollectName: repo.CollectionOrder,
+		Query:       query,
+	}, &order)
+	return
+}

+ 4 - 334
pay/bus/pay.go

@@ -4,6 +4,8 @@ import (
 	"context"
 	"fmt"
 	"pay/db/model"
+
+	"infish.cn/comm/pay"
 )
 
 const (
@@ -14,8 +16,8 @@ const (
 )
 
 type PayInf interface {
-	Pay(context.Context, *model.OrderMsg) (interface{}, error)
-	Close(context.Context, *model.OrderMsg) (bool, error)
+	Pay(context.Context, *pay.OrderMsg) (interface{}, error)
+	Close(context.Context, *pay.OrderMsg) (bool, error)
 	ReFundPay(ctx context.Context, refund *model.ReFund) (interface{}, error)
 	ReFundQuery(ctx context.Context, refund *model.ReFund) (interface{}, error)
 }
@@ -38,335 +40,3 @@ func PayMod(payType int, category int) PayInf {
 	}
 	return nil
 }
-
-// TODO 以下均已更新到对应文件中
-
-// 单商户请求二维码应答
-// func CreateSingleQrCodeReplyer() *comm.NatsMsgReplyer {
-// 	orderMsg := &model.OrderMsg{}
-// 	return &comm.NatsMsgReplyer{
-// 		// Subject: "single.order.qr",
-// 		Subject: "pay.single-vip.qr",
-// 		Entity:  orderMsg,
-// 		Cb2: func(msg *nats.Msg, entity interface{}) (interface{}, error) {
-// 			m := entity.(*model.OrderMsg)
-// 			pay := PayMod(*m.PayMode, SINGLE)
-// 			ctx := context.Background()
-// 			res, err := pay.Pay(ctx, m)
-// 			return res, err
-// 		},
-// 	}
-// }
-
-// // 关闭订单应答
-// func CreateSingleCloseOrderReplyer() *comm.NatsMsgReplyer {
-// 	orderMsg := &model.OrderMsg{}
-// 	return &comm.NatsMsgReplyer{
-// 		// Subject: "single.order.close",
-// 		Subject: "pay.single-vip.close",
-// 		Entity:  orderMsg,
-// 		Cb2: func(msg *nats.Msg, entity interface{}) (interface{}, error) {
-// 			m := entity.(*model.OrderMsg)
-// 			pay := PayMod(*m.PayMode, SINGLE)
-// 			ctx := context.Background()
-// 			flag, err := pay.Close(ctx, m)
-// 			if !flag {
-// 				return "失败", err
-// 			}
-
-// 			return "成功", err
-// 		},
-// 	}
-// }
-
-// // 单商户 支付成功消息放入JetStream
-// func PushSingleResultMessage(res *model.ResData) bool {
-// 	msg := res.Data.(*model.OrderMsg)
-// 	for _, app := range conf.AppConfig.Single.App {
-// 		if msg.ModName == app.Name {
-// 			// 放入jetstream中
-// 			err := NatsCenter.PushMessage(app.Search.StreamAndTopic, msg)
-// 			if err != nil {
-// 				log.Info("消息存放到JetStream失败", err)
-// 				return false
-// 			}
-// 			return true
-// 		}
-// 	}
-
-// 	return false
-// }
-
-// // 单商户 获取二维码的订单号放入JetStream中
-// func PushSingleOrderMessage(msg *model.OrderMsg) bool {
-// 	for _, app := range conf.AppConfig.Single.App {
-// 		if msg.ModName == app.Name {
-// 			// 放入jetstream中
-// 			err := NatsCenter.PushMessage(app.Search.StreamAndTopic, msg)
-// 			if err != nil {
-// 				log.Info("消息存放到JetStream失败", err)
-// 				return false
-// 			}
-// 			return true
-// 		}
-// 	}
-// 	return false
-// }
-
-// // 单商户 支付宝微信查询是否支付成功
-// func SinglePayResultWatchers() []*comm.NatsStreamWather {
-
-// 	singlePayResultWatcher := make([]*comm.NatsStreamWather, 0, len(conf.AppConfig.Single.App))
-// 	for _, app := range conf.AppConfig.Single.App {
-// 		// 打印注册的watcher
-// 		utils.ConsoleFormat(app.Search.Topic, "stream", app.Search.Stream, app.Search.Queue)
-// 		singlePayResultWatcher = append(singlePayResultWatcher, NewSinglePayResultWatcher(app.Search.Stream, app.Search.Topic, app.Search.Queue))
-// 	}
-// 	return singlePayResultWatcher
-// }
-
-// func NewSinglePayResultWatcher(stream, topic, queue string) *comm.NatsStreamWather {
-// 	res := &model.OrderMsg{}
-
-// 	return &comm.NatsStreamWather{
-// 		Stream:        stream,
-// 		Topic:         topic,
-// 		Queue:         queue,
-// 		AckWaitMinute: int64(1),
-// 		Entity:        res,
-// 		Cb: func(msg *nats.Msg, entity interface{}) {
-// 			defer func() {
-// 				if err := recover(); err != nil {
-// 					log.Info("系统异常", err)
-// 				}
-// 			}()
-
-// 			orderMsg := entity.(*model.OrderMsg)
-
-// 			// 订单超时判断
-// 			if orderMsg.ExpireTime.Before(time.Now()) {
-// 				log.Info("===============================微信支付失败======================================")
-// 				fmt.Println("===============================微信支付失败======================================")
-// 				PushSingleResultMessage(model.TIMEOUT.SetData(orderMsg))
-// 				msg.Ack()
-// 				return
-// 			}
-
-// 			ctx := context.Background()
-// 			// 未支付去微信、支付宝查看,支付了则更新状态未支付
-// 			outTradeNo := orderMsg.ModName + "_" + orderMsg.Id
-// 			if *orderMsg.PayMode == ALIPAY {
-// 				bm := gopay.BodyMap{}
-// 				bm["out_trade_no"] = outTradeNo
-// 				res, err := pay.SingleAlipayClient.TradeQuery(ctx, bm)
-// 				if err != nil {
-// 					fmt.Println(err)
-// 					return
-// 				}
-// 				if res.Response.TradeStatus == "TRADE_SUCCESS" {
-// 					log.Info("===============================支付宝购买成功======================================")
-// 					fmt.Println("===============================支付宝购买成功======================================")
-// 					// 放入是成功的消息队列中
-// 					PushSingleResultMessage(model.SUCCESS.SetData(orderMsg))
-// 				} else {
-// 					log.Info("===============================支付宝购买失败======================================")
-// 					fmt.Println("===============================支付宝购买失败======================================")
-// 					// 放入是失败的消息队列中 SKU3DMember
-// 					PushSingleResultMessage(model.FAILD.SetData(orderMsg))
-// 				}
-
-// 			} else {
-// 				res, err := pay.SingleWechatpayClient.V3TransactionQueryOrder(ctx, wechat.OutTradeNo, outTradeNo)
-// 				if err != nil {
-// 					fmt.Println(err)
-// 					return
-// 				}
-// 				if res.Response.TradeState == "SUCCESS" {
-// 					log.Info("===============================微信购买成功======================================")
-// 					fmt.Println("===============================微信购买成功======================================")
-// 					// 放入是成功的消息队列中
-// 					PushSingleResultMessage(model.SUCCESS.SetData(orderMsg))
-// 				} else if res.Response.TradeState == "NOTPAY" {
-// 					log.Info("===============================微信还未支付======================================")
-// 					fmt.Println("===============================微信还未支付======================================")
-// 					return
-// 				} else {
-// 					// 放入是失败的消息队列中
-// 					log.Info("===============================微信支付失败======================================")
-// 					fmt.Println("===============================微信支付失败======================================")
-// 					PushSingleResultMessage(model.FAILD.SetData(orderMsg))
-// 				}
-// 			}
-
-// 			msg.Ack()
-// 		},
-// 	}
-// }
-
-// // 多商户 二维码应答
-// func CreateMultiQrCodeReplyer() *comm.NatsMsgReplyer {
-// 	orderMsg := &model.OrderMsg{}
-// 	return &comm.NatsMsgReplyer{
-// 		Subject: "comm.pay.multiPay.createqr",
-// 		//comm.pay.multiPay.createqr
-// 		Entity: orderMsg,
-// 		Cb2: func(msg *nats.Msg, entity interface{}) (interface{}, error) {
-
-// 			m := entity.(*model.OrderMsg)
-// 			pay := PayMod(*m.PayMode, MULTI)
-// 			ctx := context.Background()
-// 			res, err := pay.Pay(ctx, m)
-
-// 			return res, err
-// 		},
-// 	}
-// }
-
-// // 多商户关闭订单应答
-// func CreateMultiCloseOrderReplyer() *comm.NatsMsgReplyer {
-// 	orderMsg := &model.OrderMsg{}
-// 	return &comm.NatsMsgReplyer{
-// 		Subject: "pay.multi-vip.close",
-// 		Entity:  orderMsg,
-// 		Cb2: func(msg *nats.Msg, entity interface{}) (interface{}, error) {
-// 			m := entity.(*model.OrderMsg)
-// 			pay := PayMod(*m.PayMode, MULTI)
-// 			ctx := context.Background()
-// 			flag, err := pay.Close(ctx, m)
-// 			if !flag {
-// 				return "失败", err
-// 			}
-
-// 			return "成功", err
-// 		},
-// 	}
-// }
-
-// // 多商户 支付成功消息放入JetStream
-// func PushMultiResultMessage(res *model.ResData) bool {
-
-// 	msg := res.Data.(*model.OrderMsg)
-
-// 	for _, app := range conf.AppConfig.Multi.App {
-// 		if msg.ModName == app.Name {
-// 			// 放入jetstream中
-// 			err := NatsCenter.PushMessage(app.Result.StreamAndTopic, msg)
-
-// 			if err != nil {
-// 				log.Info("消息存放到JetStream失败", err)
-// 				return false
-// 			}
-// 			return true
-// 		}
-// 	}
-
-// 	return false
-// }
-
-// // 多商户 获取二维码的订单号放入JetStream中
-// func PushMultiOrderMessage(msg *model.OrderMsg) bool {
-// 	for _, app := range conf.AppConfig.Multi.App {
-// 		if msg.ModName == app.Name {
-// 			// 放入jetstream中
-// 			err := NatsCenter.PushMessage(app.Search.StreamAndTopic, msg)
-// 			if err != nil {
-// 				log.Info("消息存放到JetStream失败", err)
-// 				return false
-// 			}
-// 			return true
-// 		}
-// 	}
-// 	return false
-// }
-
-// // 多商户 支付宝微信查询是否支付成功
-// func MultiPayResultWatchers() []*comm.NatsStreamWather {
-
-// 	multiPayResultWatcher := make([]*comm.NatsStreamWather, 0, len(conf.AppConfig.Multi.App))
-// 	for _, app := range conf.AppConfig.Multi.App {
-// 		// 打印注册的watcher
-// 		utils.ConsoleFormat(app.Search.Topic, "stream", app.Search.Stream, app.Search.Queue)
-// 		multiPayResultWatcher = append(multiPayResultWatcher, NewMultiPayResultWatcher(app.Search.Stream, app.Search.Topic, app.Search.Queue))
-// 	}
-// 	return multiPayResultWatcher
-// }
-
-// func NewMultiPayResultWatcher(stream, topic, queue string) *comm.NatsStreamWather {
-// 	res := &model.OrderMsg{}
-
-// 	return &comm.NatsStreamWather{
-// 		Stream:        stream,
-// 		Topic:         topic,
-// 		Queue:         queue,
-// 		AckWaitMinute: int64(1),
-// 		Entity:        res,
-// 		Cb: func(msg *nats.Msg, entity interface{}) {
-// 			defer func() {
-// 				if err := recover(); err != nil {
-// 					log.Info("系统异常", err)
-// 				}
-// 			}()
-
-// 			orderMsg := entity.(*model.OrderMsg)
-
-// 			if orderMsg.ExpireTime.Before(time.Now()) {
-// 				log.Info("===============================微信支付失败======================================")
-// 				fmt.Println("===============================微信支付失败======================================")
-// 				PushMultiResultMessage(model.TIMEOUT.SetData(orderMsg))
-// 				msg.Ack()
-// 				return
-// 			}
-
-// 			ctx := context.Background()
-// 			// 3.3 未支付去微信、支付宝查看,支付了则更新状态未支付
-// 			outTradeNo := orderMsg.ModName + "_" + orderMsg.Id
-// 			if *orderMsg.PayMode == ALIPAY {
-// 				bm := gopay.BodyMap{}
-// 				bm["out_trade_no"] = outTradeNo
-// 				res, err := pay.MultiAlipayClient.TradeQuery(ctx, bm)
-// 				if err != nil {
-// 					fmt.Println(err)
-// 					return
-// 				}
-// 				if res.Response.TradeStatus == "TRADE_SUCCESS" {
-// 					log.Info("===============================支付宝购买成功======================================")
-// 					fmt.Println("===============================支付宝购买成功======================================")
-// 					// 放入是成功的消息队列中
-// 					PushMultiResultMessage(model.SUCCESS.SetData(orderMsg))
-// 				} else {
-// 					log.Info("===============================支付宝购买失败======================================")
-// 					fmt.Println("===============================支付宝购买失败======================================")
-// 					// 放入是失败的消息队列中 SKU3DMember
-// 					PushMultiResultMessage(model.FAILD.SetData(orderMsg))
-// 				}
-
-// 			} else {
-// 				bm := gopay.BodyMap{}
-// 				bm.Set("sp_mchid", conf.AppConfig.Multi.WechatPay.MchId)
-// 				bm.Set("sub_mchid", orderMsg.SubId)
-// 				res, err := pay.MultiWechatpayClient.V3PartnerQueryOrder(ctx, wechat.OutTradeNo, outTradeNo, bm)
-// 				if err != nil {
-// 					fmt.Println(err)
-// 					return
-// 				}
-// 				if res.Response.TradeState == "SUCCESS" {
-// 					log.Info("===============================微信购买成功======================================")
-// 					fmt.Println("===============================微信购买成功======================================")
-// 					// 放入是成功的消息队列中
-// 					PushMultiResultMessage(model.SUCCESS.SetData(orderMsg))
-// 				} else if res.Response.TradeState == "NOTPAY" {
-// 					log.Info("===============================微信还未支付======================================")
-// 					fmt.Println("===============================微信还未支付======================================")
-// 					return
-// 				} else {
-// 					// 放入是失败的消息队列中
-// 					log.Info("===============================微信支付失败======================================")
-// 					fmt.Println("===============================微信支付失败======================================")
-// 					PushMultiResultMessage(model.FAILD.SetData(orderMsg))
-// 				}
-// 			}
-
-// 			msg.Ack()
-// 		},
-// 	}
-// }

+ 101 - 0
pay/bus/point.go

@@ -0,0 +1,101 @@
+package bus
+
+import (
+	"context"
+	"fmt"
+	"pay/db"
+	"pay/db/repo"
+	"pay/utils"
+	"strconv"
+
+	"github.com/nats-io/nats.go"
+	"go.mongodb.org/mongo-driver/bson"
+	"infish.cn/comm"
+	"infish.cn/comm/pay"
+)
+
+// 根据项目类型 获取支付列表
+// query := map[string]interface{}{"project":"queenshow"}
+
+func PayPointList() *comm.NatsMsgReplyer {
+	qmap := make(map[string]interface{})
+	utils.ConsoleFormat(pay.PayPointListApi)
+	return &comm.NatsMsgReplyer{
+		Subject: pay.PayPointListApi,
+		Entity:  func() interface{} { return &qmap },
+		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
+			query := entity.(*map[string]interface{})
+			ctx := context.Background()
+			res, err := getPayPoints(ctx, *query)
+			return res, err
+		},
+	}
+}
+
+func getPayPoints(ctx context.Context, query map[string]interface{}) (projects []*pay.Point, err error) {
+	err = repo.RepoSeachDocs(&repo.RepoSession{Ctx: ctx, Client: db.GMongoDb}, &repo.DocSearchOptions{
+		CollectName: repo.CollectionPoint,
+		Query:       query,
+		Sort:        bson.D{bson.E{Key: "sort", Value: 1}, bson.E{Key: "createTime", Value: -1}},
+	}, &projects)
+	return
+}
+
+// query := map[string]interface{}{"_id":"xxx"}
+func PayPointDetail() *comm.NatsMsgReplyer {
+	qmap := make(map[string]interface{})
+	utils.ConsoleFormat(pay.PayPointDetailApi)
+	return &comm.NatsMsgReplyer{
+		Subject: pay.PayPointDetailApi,
+		Entity:  func() interface{} { return &qmap },
+		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
+			query := entity.(*map[string]interface{})
+			ctx := context.Background()
+			res, err := getPayPoint(ctx, *query)
+			return res, err
+		},
+	}
+}
+
+func getPayPoint(ctx context.Context, query map[string]interface{}) (project *pay.Point, err error) {
+	_, err = repo.RepoSeachDoc(&repo.RepoSession{Ctx: ctx, Client: db.GMongoDb}, &repo.DocSearchOptions{
+		CollectName: repo.CollectionPoint,
+		Query:       query,
+	}, &project)
+	return
+}
+
+// 获取支付价格
+// query := map[string]interface{}{"_id":"xxx"}
+func GetPointAmount() *comm.NatsMsgReplyer {
+	req := &pay.PointAmountReq{}
+	utils.ConsoleFormat(pay.PayPointAmountApi)
+	return &comm.NatsMsgReplyer{
+		Subject: pay.PayPointAmountApi,
+		Entity:  func() interface{} { return &req },
+		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
+			req := entity.(*pay.PointAmountReq)
+			ctx := context.Background()
+			res, err := getPointAmount(ctx, req)
+			return res, err
+		},
+	}
+}
+
+func getPointAmount(ctx context.Context, req *pay.PointAmountReq) (amount float64, err error) {
+	point := pay.Point{}
+	_, err = repo.RepoSeachDoc(&repo.RepoSession{Ctx: ctx, Client: db.GMongoDb}, &repo.DocSearchOptions{
+		CollectName: repo.CollectionPoint,
+		Query:       repo.Map{"_id": req.PointId},
+		Project:     []string{"price"},
+	}, &point)
+	if err != nil {
+		return amount, err
+	}
+
+	// 计算价格
+	_amount := *point.Price * float64(*req.Quantity)
+	amount, err = strconv.ParseFloat(fmt.Sprintf("%.2f", _amount), 64)
+
+	return
+}

+ 6 - 7
pay/bus/singleAliPay.go

@@ -3,7 +3,6 @@ package bus
 import (
 	"context"
 	"errors"
-	"fmt"
 	"pay/db/model"
 	"pay/log"
 	"pay/pay"
@@ -11,6 +10,8 @@ import (
 
 	"github.com/go-pay/gopay"
 	"github.com/go-pay/gopay/alipay"
+
+	cpay "infish.cn/comm/pay"
 )
 
 type SingleAliPay struct {
@@ -21,16 +22,14 @@ func NewSingleAliPay() PayInf {
 }
 
 // Pay 阿里支付
-func (a *SingleAliPay) Pay(ctx context.Context, orderMsg *model.OrderMsg) (interface{}, error) {
-	fmt.Println("====================二维码获取=====================")
-
+func (a *SingleAliPay) Pay(ctx context.Context, orderMsg *cpay.OrderMsg) (interface{}, error) {
 	// 初始化 BodyMap
 	bm := make(gopay.BodyMap)
 	parseAmount, err := utils.IntToDecimal(int32(*orderMsg.Amount))
 	if err != nil {
 		return nil, err
 	}
-	orderId := orderMsg.ModName + "_" + orderMsg.Id
+	orderId := orderMsg.Project + "_" + orderMsg.Id.Hex()
 	bm.Set("subject", orderMsg.Name).
 		Set("scene", "bar_code").
 		Set("out_trade_no", orderId).
@@ -60,9 +59,9 @@ func (a *SingleAliPay) Pay(ctx context.Context, orderMsg *model.OrderMsg) (inter
 	// }, nil
 }
 
-func (a *SingleAliPay) Close(ctx context.Context, orderMsg *model.OrderMsg) (bool, error) {
+func (a *SingleAliPay) Close(ctx context.Context, orderMsg *cpay.OrderMsg) (bool, error) {
 
-	orderId := orderMsg.ModName + "_" + orderMsg.Id
+	orderId := orderMsg.Project + "_" + orderMsg.Id.Hex()
 	bm := make(gopay.BodyMap)
 	bm.Set("out_trade_no", orderId)
 	tradeClose, err := pay.SingleAlipayClient.TradeClose(ctx, bm)

+ 56 - 18
pay/bus/singlePay.go

@@ -2,25 +2,30 @@ package bus
 
 import (
 	"context"
+	"fmt"
+	"pay/db"
 	"pay/db/model"
+	"pay/db/repo"
+	"pay/log"
 	"pay/utils"
 
 	"github.com/nats-io/nats.go"
 	"infish.cn/comm"
+	"infish.cn/comm/pay"
 )
 
 type SinglePay struct{}
 
 // 创建二维码
 func (s *SinglePay) CreateQr() *comm.NatsMsgReplyer {
-	utils.ConsoleFormat(comm.CommPaySku3dCreateQrApi)
+	utils.ConsoleFormat(pay.PaySingleQrApi)
 
 	return &comm.NatsMsgReplyer{
-		Subject: comm.CommPaySku3dCreateQrApi,
-		Entity:  func() interface{} { return &model.OrderMsg{} },
-		Cb2: func(msg *nats.Msg, entity interface{}) (interface{}, error) {
-			m := entity.(*model.OrderMsg)
-			pay := PayMod(*m.PayMode, SINGLE)
+		Subject: pay.PaySingleQrApi,
+		Entity:  func() interface{} { return &pay.OrderMsg{} },
+		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
+			m := entity.(*pay.OrderMsg)
+			pay := PayMod(int(*m.PayMod), SINGLE)
 			ctx := context.Background()
 			res, err := pay.Pay(ctx, m)
 			return res, err
@@ -30,14 +35,14 @@ func (s *SinglePay) CreateQr() *comm.NatsMsgReplyer {
 
 // 关闭订单应答
 func (s *SinglePay) CloseOrder() *comm.NatsMsgReplyer {
-	utils.ConsoleFormat("comm.pay.singlePay.closeOrder")
+	utils.ConsoleFormat(pay.PaySingleCloseOrderApi)
 
 	return &comm.NatsMsgReplyer{
-		Subject: "comm.pay.singlePay.closeOrder",
-		Entity:  func() interface{} { return &model.OrderMsg{} },
-		Cb2: func(msg *nats.Msg, entity interface{}) (interface{}, error) {
-			m := entity.(*model.OrderMsg)
-			pay := PayMod(*m.PayMode, SINGLE)
+		Subject: pay.PaySingleCloseOrderApi,
+		Entity:  func() interface{} { return &pay.OrderMsg{} },
+		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
+			m := entity.(*pay.OrderMsg)
+			pay := PayMod(int(*m.PayMod), SINGLE)
 			ctx := context.Background()
 			flag, err := pay.Close(ctx, m)
 			return flag, err
@@ -47,12 +52,12 @@ func (s *SinglePay) CloseOrder() *comm.NatsMsgReplyer {
 
 // 退款
 func (s *SinglePay) Refund() *comm.NatsMsgReplyer {
-	utils.ConsoleFormat("comm.pay.singlePay.refund")
+	utils.ConsoleFormat(pay.PaySingleRefundApi)
 
 	return &comm.NatsMsgReplyer{
-		Subject: "comm.pay.singlePay.refund",
+		Subject: pay.PaySingleRefundApi,
 		Entity:  func() interface{} { return &model.ReFund{} },
-		Cb2: func(msg *nats.Msg, entity interface{}) (interface{}, error) {
+		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
 			refund := entity.(*model.ReFund)
 			// ???适配缺失退款理由
 			if refund.Reason == "" {
@@ -68,12 +73,12 @@ func (s *SinglePay) Refund() *comm.NatsMsgReplyer {
 
 // 退款查询
 func (s *SinglePay) RefundQuery() *comm.NatsMsgReplyer {
-	utils.ConsoleFormat("comm.pay.singlePay.refundQuery")
+	utils.ConsoleFormat(pay.PaySingleRefundQueryApi)
 
 	return &comm.NatsMsgReplyer{
-		Subject: "comm.pay.singlePay.refundQuery",
+		Subject: pay.PaySingleRefundQueryApi,
 		Entity:  func() interface{} { return &model.ReFund{} },
-		Cb2: func(msg *nats.Msg, entity interface{}) (interface{}, error) {
+		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
 			m := entity.(*model.ReFund)
 			pay := PayMod(int(*m.PayMode), SINGLE)
 			ctx := context.Background()
@@ -82,3 +87,36 @@ func (s *SinglePay) RefundQuery() *comm.NatsMsgReplyer {
 		},
 	}
 }
+
+// 支付成功
+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()
+			// }
+		},
+	}
+
+}

+ 5 - 4
pay/bus/singleWechatPay.go

@@ -13,6 +13,7 @@ import (
 	"time"
 
 	"github.com/go-pay/gopay"
+	cpay "infish.cn/comm/pay"
 )
 
 type SingleWechatPay struct {
@@ -22,12 +23,12 @@ func NewSingleWechatPay() PayInf {
 	return &SingleWechatPay{}
 }
 
-func (a *SingleWechatPay) Pay(ctx context.Context, orderMsg *model.OrderMsg) (interface{}, error) {
+func (a *SingleWechatPay) Pay(ctx context.Context, orderMsg *cpay.OrderMsg) (interface{}, error) {
 
 	fmt.Println("====================single-wechat二维码获取=====================")
 
 	// 初始化 BodyMap
-	orderId := orderMsg.ModName + "_" + orderMsg.Id
+	orderId := orderMsg.Project + "_" + orderMsg.Id.Hex()
 	bm := make(gopay.BodyMap)
 	singlePayCnf := utils.GetSinglePayConfig(conf.AppConfig)
 
@@ -64,9 +65,9 @@ func (a *SingleWechatPay) Pay(ctx context.Context, orderMsg *model.OrderMsg) (in
 	return res.Response.CodeUrl, nil
 }
 
-func (a *SingleWechatPay) Close(ctx context.Context, orderMsg *model.OrderMsg) (bool, error) {
+func (a *SingleWechatPay) Close(ctx context.Context, orderMsg *cpay.OrderMsg) (bool, error) {
 
-	orderId := orderMsg.ModName + "_" + orderMsg.Id
+	orderId := orderMsg.Project + "_" + orderMsg.Id.Hex()
 	res, err := pay.SingleWechatpayClient.V3TransactionCloseOrder(ctx, orderId)
 	if err != nil {
 		return false, err

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

@@ -22,8 +22,8 @@ type RepoSession struct {
 const (
 	CollectionUser  = "users"
 	CollectionOrder = "orders"
-	// 支付管理
-	CollectionPay = "pay"
+	// 支付管理
+	CollectionPoint = "points"
 )
 
 type Map map[string]interface{}