From fead7c6ae99d2128db2305071fe26a8b628fbcac Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Fri, 22 Sep 2023 10:39:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/order/internal/types/types.go | 4 +- server_api/order.api | 4 +- service/repositories/order.go | 59 +++++++++++++++++++--------- utils/pay/stripe.go | 1 + 4 files changed, 46 insertions(+), 22 deletions(-) diff --git a/server/order/internal/types/types.go b/server/order/internal/types/types.go index a27a0c52..2e62f077 100644 --- a/server/order/internal/types/types.go +++ b/server/order/internal/types/types.go @@ -11,12 +11,12 @@ type OrderDetailReq struct { type CreateOrderReq struct { CartIds []int64 `json:"cart_ids"` - DeliveryMethod int64 `json:"delivery_method,options=[1,2]"` + DeliveryMethod int64 `json:"delivery_method,optional,options=[1,2],default=2"` } type CreatePrePaymentByDepositReq struct { OrderSn string `json:"order_sn"` - DeliveryMethod int64 `json:"delivery_method,options=[1,2]"` + DeliveryMethod int64 `json:"delivery_method,optional,options=[1,2],default=2"` DeliveryAddress *DeliveryAddress `json:"delivery_address,optional"` } diff --git a/server_api/order.api b/server_api/order.api index 571f615f..bd1292a4 100644 --- a/server_api/order.api +++ b/server_api/order.api @@ -34,12 +34,12 @@ type OrderDetailReq { type CreateOrderReq { CartIds []int64 `json:"cart_ids"` - DeliveryMethod int64 `json:"delivery_method,options=[1,2]"` + DeliveryMethod int64 `json:"delivery_method,optional,options=[1,2],default=2"` } type CreatePrePaymentByDepositReq { OrderSn string `json:"order_sn"` - DeliveryMethod int64 `json:"delivery_method,options=[1,2]"` + DeliveryMethod int64 `json:"delivery_method,optional,options=[1,2],default=2"` DeliveryAddress *DeliveryAddress `json:"delivery_address,optional"` } diff --git a/service/repositories/order.go b/service/repositories/order.go index 13e5e0db..098676bd 100644 --- a/service/repositories/order.go +++ b/service/repositories/order.go @@ -34,6 +34,8 @@ type ( Create(ctx context.Context, in *CreateReq) (res *CreateRes, err error) // 预支付--定金 CreatePrePaymentByDeposit(ctx context.Context, in *CreatePrePaymentByDepositReq) (res *CreatePrePaymentByDepositRes, err error) + // 预支付--定金 + CreatePrePaymentByBalance(ctx context.Context, in *CreatePrePaymentByBalanceReq) (res *CreatePrePaymentByBalanceRes, err error) // 列表 List(ctx context.Context, in *ListReq) (res *ListRes, err error) // 详情 @@ -69,7 +71,7 @@ type ( UserId int64 `json:"user_id"` OrderSn string `json:"order_sn"` DeliveryMethod int64 `json:"delivery_method"` - DeliveryAddress *OrderAddress `json:"delivery_address"` // 收货地址 + DeliveryAddress *OrderAddress `json:"delivery_address"` } CreatePrePaymentByDepositRes struct { ErrorCode basic.StatusResponse @@ -78,6 +80,23 @@ type ( } /* 预支付--定金 */ + /* 预支付--尾款 */ + CreatePrePaymentByBalanceReq struct { + StripeKey string `json:"stripe_key"` + Currency string `json:"currency"` + Country string `json:"country"` + UserId int64 `json:"user_id"` + OrderSn string `json:"order_sn"` + DeliveryMethod int64 `json:"delivery_method"` + DeliveryAddress *OrderAddress `json:"delivery_address"` + } + CreatePrePaymentByBalanceRes struct { + ErrorCode basic.StatusResponse + OrderDetail gmodel.OrderDetail + OrderPay OrderPay + } + /* 预支付--尾款 */ + /* 下单 */ CreateReq struct { ExpectedDeliveryTime time.Time `json:"expected_delivery_time"` // 预计到货时间 @@ -122,6 +141,11 @@ type ( /* 列表 */ ) +// 预支付--尾款 +func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *CreatePrePaymentByBalanceReq) (res *CreatePrePaymentByBalanceRes, err error) { + return nil, nil +} + // 预支付--定金 func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *CreatePrePaymentByDepositReq) (res *CreatePrePaymentByDepositRes, err error) { var errorCode basic.StatusResponse @@ -223,6 +247,22 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create } } } + + if len(uOrderDetail) > 0 { + err = fssql.MetadataOrderPATCH(d.MysqlConn, sql, in.OrderSn, gmodel.FsOrder{}, uOrderDetail, "id = ?", order.Id) + if err != nil { + errorCode = *basic.CodeServiceErr + logx.Errorf("create prePayment deposit failed MetadataOrderPATCH, err: %v", err) + return &CreatePrePaymentByDepositRes{ + ErrorCode: errorCode, + }, result.Error + } + } + + ress.OrderDetail.OrderInfo.Utime = &ntime + ress.OrderDetail.OrderInfo.DeliveryMethod = in.DeliveryMethod + ress.OrderDetail.DeliveryAddress = orderAddress + // 支付初始化 amount := int64(ress.OrderDetailOriginal.OrderAmount.Deposit.PayAmount.Current.CurrentAmount.(float64) / float64(10)) payConfig := &pay.Config{} @@ -245,24 +285,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create return &CreatePrePaymentByDepositRes{ ErrorCode: errorCode, }, nil - } else { - //uOrderDetail["order_amount"] = map[type]type } - if len(uOrderDetail) > 0 { - err = fssql.MetadataOrderPATCH(d.MysqlConn, sql, in.OrderSn, gmodel.FsOrder{}, uOrderDetail, "id = ?", order.Id) - if err != nil { - errorCode = *basic.CodeServiceErr - logx.Errorf("create prePayment deposit failed MetadataOrderPATCH, err: %v", err) - return &CreatePrePaymentByDepositRes{ - ErrorCode: errorCode, - }, result.Error - } - } - - ress.OrderDetail.OrderInfo.Utime = &ntime - ress.OrderDetail.OrderInfo.DeliveryMethod = in.DeliveryMethod - ress.OrderDetail.DeliveryAddress = orderAddress - return &CreatePrePaymentByDepositRes{ OrderDetail: ress.OrderDetail, OrderPay: OrderPay{ diff --git a/utils/pay/stripe.go b/utils/pay/stripe.go index 75325677..43cf28d3 100644 --- a/utils/pay/stripe.go +++ b/utils/pay/stripe.go @@ -79,6 +79,7 @@ func (stripePay *Stripe) GeneratePrepayment(req *GeneratePrepaymentReq) (res *Ge case "intent": // 密钥方式 params := &stripe.PaymentIntentParams{ + Params: stripe.Params{Metadata: map[string]string{"order_sn": req.OrderSn}}, Amount: stripe.Int64(req.Amount), Currency: stripe.String(string(req.Currency)), PaymentMethodTypes: stripe.StringSlice([]string{ From bb645ce6f686e2a04d9d556c19b5452e8475fc3a Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 22 Sep 2023 10:41:38 +0800 Subject: [PATCH 2/2] fix --- .../internal/logic/datatransferlogic.go | 2 +- .../internal/logic/ws_render_image.go | 28 +++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index fa7a9258..37e15346 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -192,7 +192,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use userId: userInfo.UserId, guestId: userInfo.GuestId, extendRenderProperty: extendRenderProperty{ - renderChan: make(chan []byte, renderChanLen), + renderChan: make(chan websocket_data.RenderImageReqMsg, renderChanLen), }, } //保存连接 diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 4f17c851..1bd4f40c 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -30,16 +30,26 @@ type renderProcessor struct { // 云渲染属性 type extendRenderProperty struct { - renderChan chan []byte //渲染消息入口的缓冲队列 + renderChan chan websocket_data.RenderImageReqMsg //渲染消息入口的缓冲队列 + colorSelectedIndex int //选择颜色索引 + templateTag string //模板标签 } // 处理分发到这里的数据 func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) { //logx.Info("开始处理渲染任务消息:", string(data)) + var renderImageData websocket_data.RenderImageReqMsg + if err := json.Unmarshal(data, &renderImageData); err != nil { + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "数据格式错误", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) + logx.Error("invalid format of websocket render image message", err) + return + } select { case <-w.closeChan: //已经关闭 return - case w.extendRenderProperty.renderChan <- data: //发入到缓冲队列 + case w.extendRenderProperty.renderChan <- renderImageData: //发入到缓冲队列 + w.extendRenderProperty.colorSelectedIndex = renderImageData.RenderData.TemplateTagColor.SelectedColorIndex + w.extendRenderProperty.templateTag = renderImageData.RenderData.TemplateTag return } } @@ -51,26 +61,28 @@ func (w *wsConnectItem) consumeRenderImageData() { logx.Error("func renderImage err:", err) } }() - var data []byte for { select { case <-w.closeChan: //已关闭 return - case data = <-w.extendRenderProperty.renderChan: //消费数据 - w.renderImage(data) + case data := <-w.extendRenderProperty.renderChan: //消费数据 + //属性相同则发送渲染,不同则抛弃 + if data.RenderData.TemplateTag == w.extendRenderProperty.templateTag && data.RenderData.TemplateTagColor.SelectedColorIndex == w.extendRenderProperty.colorSelectedIndex { + w.renderImage(data) + } } } } // 执行渲染任务 -func (w *wsConnectItem) renderImage(data []byte) { +func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageReqMsg) { //logx.Info("消费渲染数据:", string(data)) - var renderImageData websocket_data.RenderImageReqMsg + /*var renderImageData websocket_data.RenderImageReqMsg if err := json.Unmarshal(data, &renderImageData); err != nil { w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "数据格式错误", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) logx.Error("invalid format of websocket render image message", err) return - } + }*/ if renderImageData.RenderData.Logo == "" { w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "请传入logo", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) return