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{