Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
commit
baa0cc1644
@ -3,7 +3,7 @@ package constants
|
||||
// 订单类型
|
||||
const (
|
||||
DELIVERYMETHODDIRECTMAIL int64 = 1
|
||||
DELIVERYMETHODDSCLOUDSTORE int64 = 1
|
||||
DELIVERYMETHODDSCLOUDSTORE int64 = 2
|
||||
)
|
||||
|
||||
// 货币
|
||||
|
@ -47,7 +47,7 @@ func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth
|
||||
OriginalCurrency: string(constants.CURRENCYUSD),
|
||||
UserId: userinfo.UserId,
|
||||
CartIds: req.CartIds,
|
||||
DeliveryMethod: req.DeliveryMethod,
|
||||
DeliveryMethod: constants.DELIVERYMETHODDSCLOUDSTORE,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/service/repositories"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
@ -38,7 +39,22 @@ func (l *CreatePrePaymentByBalanceLogic) CreatePrePaymentByBalance(req *types.Cr
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
res, err := l.svcCtx.Repositories.NewOrder.CreatePrePaymentByBalance(l.ctx, &repositories.CreatePrePaymentByBalanceReq{
|
||||
UserId: userinfo.UserId,
|
||||
OrderSn: req.OrderSn,
|
||||
Country: "US",
|
||||
Currency: "usd",
|
||||
StripeKey: l.svcCtx.Config.PayConfig.Stripe.Key,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return resp.SetStatus(&res.ErrorCode)
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
|
||||
"order_detail": res.OrderDetail,
|
||||
"order_pay": res.OrderPay,
|
||||
})
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
|
@ -10,8 +10,7 @@ type OrderDetailReq struct {
|
||||
}
|
||||
|
||||
type CreateOrderReq struct {
|
||||
CartIds []int64 `json:"cart_ids"`
|
||||
DeliveryMethod int64 `json:"delivery_method,optional,options=[1,2],default=2"`
|
||||
CartIds []int64 `json:"cart_ids"`
|
||||
}
|
||||
|
||||
type CreatePrePaymentByDepositReq struct {
|
||||
|
@ -192,7 +192,9 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
|
||||
userId: userInfo.UserId,
|
||||
guestId: userInfo.GuestId,
|
||||
extendRenderProperty: extendRenderProperty{
|
||||
renderChan: make(chan websocket_data.RenderImageReqMsg, renderChanLen),
|
||||
renderChan: make(chan websocket_data.RenderImageReqMsg, renderChanLen),
|
||||
colorSelectedIndex: 0,
|
||||
templateTag: "",
|
||||
},
|
||||
}
|
||||
//保存连接
|
||||
|
@ -22,6 +22,8 @@ import (
|
||||
var (
|
||||
//每个websocket渲染任务缓冲队列长度默认值
|
||||
renderChanLen = 500
|
||||
//每个websocket渲染并发数
|
||||
renderChanConcurrency = 25
|
||||
)
|
||||
|
||||
// 渲染处理器
|
||||
@ -58,9 +60,12 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
|
||||
func (w *wsConnectItem) consumeRenderImageData() {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
logx.Error("func renderImage err:", err)
|
||||
logx.Error("func consumeRenderImageData err:", err)
|
||||
}
|
||||
}()
|
||||
//限制并发
|
||||
limitChan := make(chan struct{}, renderChanConcurrency)
|
||||
defer close(limitChan)
|
||||
for {
|
||||
select {
|
||||
case <-w.closeChan: //已关闭
|
||||
@ -74,20 +79,24 @@ func (w *wsConnectItem) consumeRenderImageData() {
|
||||
if data.RenderData.TemplateTagColor.SelectedColorIndex != w.extendRenderProperty.colorSelectedIndex {
|
||||
continue
|
||||
}
|
||||
w.renderImage(data)
|
||||
limitChan <- struct{}{}
|
||||
go func(d websocket_data.RenderImageReqMsg) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
logx.Error("func renderImage err:", err)
|
||||
}
|
||||
}()
|
||||
defer func() {
|
||||
<-limitChan
|
||||
}()
|
||||
w.renderImage(d)
|
||||
}(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 执行渲染任务
|
||||
func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageReqMsg) {
|
||||
//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
|
||||
}*/
|
||||
if renderImageData.RenderData.Logo == "" {
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "请传入logo", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
||||
return
|
||||
|
@ -33,8 +33,8 @@ type OrderDetailReq {
|
||||
}
|
||||
|
||||
type CreateOrderReq {
|
||||
CartIds []int64 `json:"cart_ids"`
|
||||
DeliveryMethod int64 `json:"delivery_method,optional,options=[1,2],default=2"`
|
||||
CartIds []int64 `json:"cart_ids"`
|
||||
// DeliveryMethod int64 `json:"delivery_method,optional,options=[1,2],default=2"`
|
||||
}
|
||||
|
||||
type CreatePrePaymentByDepositReq {
|
||||
|
@ -82,13 +82,11 @@ 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"`
|
||||
StripeKey string `json:"stripe_key"`
|
||||
Currency string `json:"currency"`
|
||||
Country string `json:"country"`
|
||||
UserId int64 `json:"user_id"`
|
||||
OrderSn string `json:"order_sn"`
|
||||
}
|
||||
CreatePrePaymentByBalanceRes struct {
|
||||
ErrorCode basic.StatusResponse
|
||||
@ -143,7 +141,83 @@ type (
|
||||
|
||||
// 预支付--尾款
|
||||
func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *CreatePrePaymentByBalanceReq) (res *CreatePrePaymentByBalanceRes, err error) {
|
||||
return nil, nil
|
||||
var errorCode basic.StatusResponse
|
||||
var order gmodel.FsOrder
|
||||
model := d.MysqlConn.Where("is_del = ?", 0)
|
||||
if in.UserId != 0 {
|
||||
model.Where("user_id = ?", in.UserId)
|
||||
}
|
||||
if in.OrderSn != "" {
|
||||
model.Where("order_sn = ?", in.OrderSn)
|
||||
}
|
||||
result := model.Take(&order)
|
||||
if result.Error != nil {
|
||||
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||
errorCode = *basic.CodeErrOrderCreatePrePaymentInfoNoFound
|
||||
} else {
|
||||
errorCode = *basic.CodeServiceErr
|
||||
}
|
||||
logx.Errorf("create prePayment balance failed, err: %v", err)
|
||||
return &CreatePrePaymentByBalanceRes{
|
||||
ErrorCode: errorCode,
|
||||
}, result.Error
|
||||
}
|
||||
// 非未支付
|
||||
if *order.PayStatus != int64(constants.ORDERPAYSTATUSPAIDDEPOSIT) {
|
||||
errorCode = *basic.CodeErrOrderCreatePrePaymentNoUnPaid
|
||||
err = errors.New("order balance pay status is not unPaid")
|
||||
logx.Errorf("create prePayment balance failed, err: %v", err)
|
||||
return &CreatePrePaymentByBalanceRes{
|
||||
ErrorCode: errorCode,
|
||||
}, err
|
||||
}
|
||||
|
||||
ress, err := d.OrderDetailHandler(ctx, &order)
|
||||
if err != nil {
|
||||
logx.Errorf("create prePayment balance failed DetailOrderDetailHandler, err: %v", err)
|
||||
errorCode = *basic.CodeServiceErr
|
||||
return &CreatePrePaymentByBalanceRes{
|
||||
ErrorCode: errorCode,
|
||||
}, err
|
||||
}
|
||||
// 支付初始化
|
||||
amount := int64(ress.OrderDetailOriginal.OrderAmount.RemainingBalance.PayAmount.Current.CurrentAmount.(float64) / float64(10))
|
||||
payConfig := &pay.Config{}
|
||||
payConfig.Stripe.PayType = "intent"
|
||||
payConfig.Stripe.Key = in.StripeKey
|
||||
var generatePrepaymentReq = &pay.GeneratePrepaymentReq{
|
||||
OrderSn: in.OrderSn,
|
||||
ProductName: "支付尾款后期统一调整",
|
||||
Amount: amount,
|
||||
Currency: "usd",
|
||||
Quantity: 1,
|
||||
ProductDescription: "支付尾款后期统一调整",
|
||||
}
|
||||
payDriver := pay.NewPayDriver(1, payConfig)
|
||||
|
||||
prepaymentRes, err := payDriver.GeneratePrepayment(generatePrepaymentReq)
|
||||
if err != nil {
|
||||
logx.Errorf("create prePayment balance failed GeneratePrepayment, err: %v", err)
|
||||
errorCode = *basic.CodeServiceErr
|
||||
return &CreatePrePaymentByBalanceRes{
|
||||
ErrorCode: errorCode,
|
||||
}, nil
|
||||
}
|
||||
return &CreatePrePaymentByBalanceRes{
|
||||
OrderDetail: ress.OrderDetail,
|
||||
OrderPay: OrderPay{
|
||||
ClientSecret: prepaymentRes.ClientSecret,
|
||||
Country: in.Country,
|
||||
Currency: in.Currency,
|
||||
Method: payConfig.Stripe.PayType,
|
||||
OrderSn: in.OrderSn,
|
||||
PayStage: 1,
|
||||
Total: OrderPayTotal{
|
||||
Amount: amount,
|
||||
Label: "支付尾款后期统一调整",
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// 预支付--定金
|
||||
@ -172,7 +246,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
|
||||
|
||||
// 非未支付
|
||||
if *order.PayStatus != int64(constants.ORDERPAYSTATUSUNPAIDDEPOSIT) {
|
||||
errorCode = *basic.CodeErrOrderCreatePrePaymentInfoNoFound
|
||||
errorCode = *basic.CodeErrOrderCreatePrePaymentNoUnPaid
|
||||
err = errors.New("order pay status is not unPaidDeposit")
|
||||
logx.Errorf("create prePayment deposit failed, err: %v", err)
|
||||
return &CreatePrePaymentByDepositRes{
|
||||
@ -185,6 +259,8 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
|
||||
ctime := *order.Ctime
|
||||
ctimeTimeOut := ctime.Add(30 * time.Minute).UTC().Unix()
|
||||
ntimeTimeOut := ntime.Unix()
|
||||
|
||||
// 测试超时支付不限制
|
||||
if ctimeTimeOut == ntimeTimeOut {
|
||||
errorCode = *basic.CodeErrOrderCreatePrePaymentTimeout
|
||||
err = errors.New("order pay timeout")
|
||||
@ -270,11 +346,11 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
|
||||
payConfig.Stripe.Key = in.StripeKey
|
||||
var generatePrepaymentReq = &pay.GeneratePrepaymentReq{
|
||||
OrderSn: in.OrderSn,
|
||||
ProductName: "支付标题",
|
||||
ProductName: "支付首款",
|
||||
Amount: amount,
|
||||
Currency: "usd",
|
||||
Quantity: 1,
|
||||
ProductDescription: "支付描述",
|
||||
ProductDescription: "支付首款",
|
||||
}
|
||||
payDriver := pay.NewPayDriver(1, payConfig)
|
||||
|
||||
|
@ -108,8 +108,9 @@ var (
|
||||
CodeErrOrderCreatProductAccessoryAbsent = &StatusResponse{5305, "create order failed, accessory of product is absent"} // 订单创建失败,商品配件不存在
|
||||
CodeErrOrderCreatePrePaymentParam = &StatusResponse{5306, "create payment failed, the shipping address is illegal"} // 订单创建失败,商品配件不存在
|
||||
CodeErrOrderCreatePrePaymentInfoNoFound = &StatusResponse{5307, "create payment failed, order info not found"}
|
||||
CodeErrOrderCreatePrePaymentPaidDeposit = &StatusResponse{5308, "create payment failed, order is paid"}
|
||||
CodeErrOrderCreatePrePaymentTimeout = &StatusResponse{5309, "create payment failed, timeout"}
|
||||
CodeErrOrderCreatePrePaymentNoUnPaid = &StatusResponse{5308, "create payment failed, order is not unpaid"}
|
||||
CodeErrOrderCreatePrePaymentPaid = &StatusResponse{5309, "create payment failed, order is paid"}
|
||||
CodeErrOrderCreatePrePaymentTimeout = &StatusResponse{5310, "create payment failed, timeout"}
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
|
Loading…
x
Reference in New Issue
Block a user