animeic 1 жил өмнө
parent
commit
140ef29b5f

BIN
pay/__debug_bin


+ 68 - 80
pay/api/oreder.go

@@ -2,92 +2,80 @@ package api
 
 // TODO 测试
 
-import (
-	"errors"
-	"pay/db/repo"
-	"pay/log"
-	"time"
+// 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)
 
-	"github.com/gin-gonic/gin"
-	"go.mongodb.org/mongo-driver/bson/primitive"
+// }
 
-	"infish.cn/comm/pay"
-)
+// 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()
 
-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)
+// 	return repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionOrder, &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(), repo.CollectionOrder, _id)
+// }
 
-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()
+// func OrderList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+// 	page, size, query := UtilQueryPageSize(c)
+// 	return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
+// 		CollectName: repo.CollectionOrder,
+// 		Page:        page,
+// 		Size:        size,
+// 		Query:       query,
+// 	})
+// }
 
-	return repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionOrder, &order)
-}
+// func OrderDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+// 	_id := c.Param("id")
 
-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(), repo.CollectionOrder, _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: repo.CollectionOrder,
+// 		Query:       query,
+// 	}, order)
+// 	if err != nil {
+// 		log.Error(err)
+// 		return nil, err
+// 	}
 
-func OrderList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	page, size, query := UtilQueryPageSize(c)
-	return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
-		CollectName: repo.CollectionOrder,
-		Page:        page,
-		Size:        size,
-		Query:       query,
-	})
-}
+// 	if !found {
+// 		return nil, errors.New("未找到该数据")
+// 	}
+// 	return order, nil
+// }
 
-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: repo.CollectionOrder,
-		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(), repo.CollectionOrder, order.Id.Hex(), &order)
-}
+// 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(), repo.CollectionOrder, order.Id.Hex(), &order)
+// }

+ 0 - 18
pay/api/point.go

@@ -21,24 +21,6 @@ func PayPoint(r *GinRouter) {
 
 }
 
-//	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 pay.Point
 	err := c.ShouldBindJSON(&pay)

+ 1 - 1
pay/api/router.go

@@ -22,7 +22,7 @@ func RegRouters(svc *Service) {
 	PayPoint(payGroup)
 
 	// 支付订单
-	PayOrder(payGroup)
+	// PayOrder(payGroup)
 
 	// 其他测试
 	payGroup.GET("/print", PrintParam)

+ 19 - 0
pay/assettest.log

@@ -12,3 +12,22 @@
 {"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"}
+{"level":"info","timestamp":"2023-07-06 14:58:22","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 15:09:43","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 15:15:54","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 15:44:16","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 15:47:13","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 15:48:21","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 15:49:26","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 15:52:34","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 16:31:42","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 16:33:08","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 16:39:33","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 16:40:36","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 16:41:23","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 16:42:05","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 16:45:17","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 16:51:29","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 16:51:56","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 16:52:57","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 16:53:33","message":"[初始化支付客户端]","service_name":"assettest"}

+ 3 - 0
pay/bus/nats.go

@@ -24,6 +24,9 @@ func NewNatsBus(app *conf.AppConf) *comm.NatsBus {
 		singlePay.RefundQuery(),
 		PayPointList(),
 		PayPointDetail(),
+		GetPointAmount(),
+		PayOrderCreate(),
+		PayOrderDetail(),
 	})
 	NatsCenter = bus
 	return NatsCenter

+ 6 - 4
pay/bus/order.go

@@ -2,9 +2,11 @@ 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/primitive"
@@ -12,11 +14,9 @@ import (
 	"infish.cn/comm/pay"
 )
 
-// 根据项目类型 获取支付列表
-// query := map[string]interface{}{"project":"queenshow"}
-
+// 创建订单
 func PayOrderCreate() *comm.NatsMsgReplyer {
-	order := &pay.Order{}
+	order := pay.Order{}
 	utils.ConsoleFormat(pay.PayOrderCreateApi)
 	return &comm.NatsMsgReplyer{
 		Subject: pay.PayOrderCreateApi,
@@ -61,5 +61,7 @@ func getPayOrder(ctx context.Context, query map[string]interface{}) (order *pay.
 		CollectName: repo.CollectionOrder,
 		Query:       query,
 	}, &order)
+	amount, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", *order.RealAmount), 64)
+	order.RealAmount = &amount
 	return
 }

+ 1 - 1
pay/bus/point.go

@@ -72,7 +72,7 @@ func GetPointAmount() *comm.NatsMsgReplyer {
 	utils.ConsoleFormat(pay.PayPointAmountApi)
 	return &comm.NatsMsgReplyer{
 		Subject: pay.PayPointAmountApi,
-		Entity:  func() interface{} { return &req },
+		Entity:  func() interface{} { return req },
 		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
 			req := entity.(*pay.PointAmountReq)
 			ctx := context.Background()