fix:支付
This commit is contained in:
parent
95cbaea69a
commit
6c2fba2b3a
|
@ -56,18 +56,20 @@ const (
|
|||
type OrderStatusCode int64
|
||||
|
||||
const (
|
||||
ORDERSTATUSUNPAIDDEPOSIT OrderStatusCode = 0 // 0,未支付定金
|
||||
ORDERSTATUSDIRECTMAILORDERED OrderStatusCode = 10100 // 10100,直邮单--已下单
|
||||
ORDERSTATUSDIRECTMAILCANCEL OrderStatusCode = 10101 // 10101,直邮单--已取消
|
||||
ORDERSTATUSDIRECTMAILSTARTPRODUCTION OrderStatusCode = 10200 // 10200,直邮单--开始生产
|
||||
ORDERSTATUSDIRECTMAILCOMPLETEPRODUCTION OrderStatusCode = 10300 // 10300,直邮单--生产完成
|
||||
ORDERSTATUSDIRECTMAILSHIPPED OrderStatusCode = 10400 // 10400,直邮单--已发货
|
||||
ORDERSTATUSDIRECTMAILARRIVED OrderStatusCode = 10500 // 10500,直邮单--已到达
|
||||
ORDERSTATUSCLOUDSTOREORDERED OrderStatusCode = 20100 // 20100,云仓单--已下单
|
||||
ORDERSTATUSCLOUDSTORECANCEL OrderStatusCode = 20101 // 20101,云仓单--已取消
|
||||
ORDERSTATUSCLOUDSTORESTARTPRODUCTION OrderStatusCode = 20200 // 20200,云仓单--开始生产
|
||||
ORDERSTATUSCLOUDSTOREOMPLETEPRODUCTION OrderStatusCode = 20300 // 20300,云仓单--生产完成
|
||||
ORDERSTATUSCLOUDSTOREARRIVEDWAREHOUSE OrderStatusCode = 20400 // 20400,云仓单--直达仓库
|
||||
ORDERSTATUSUNPAIDDEPOSIT OrderStatusCode = 0 // 0,未支付定金
|
||||
ORDERSTATUSDIRECTMAILORDERED OrderStatusCode = 10100 // 10100,直邮单--已下单
|
||||
ORDERSTATUSDIRECTMAILORDEREDMAINING OrderStatusCode = 10100001 // 10100001,直邮单--已下单--尾款
|
||||
ORDERSTATUSDIRECTMAILCANCEL OrderStatusCode = 10101 // 10101,直邮单--已取消
|
||||
ORDERSTATUSDIRECTMAILSTARTPRODUCTION OrderStatusCode = 10200 // 10200,直邮单--开始生产
|
||||
ORDERSTATUSDIRECTMAILCOMPLETEPRODUCTION OrderStatusCode = 10300 // 10300,直邮单--生产完成
|
||||
ORDERSTATUSDIRECTMAILSHIPPED OrderStatusCode = 10400 // 10400,直邮单--已发货
|
||||
ORDERSTATUSDIRECTMAILARRIVED OrderStatusCode = 10500 // 10500,直邮单--已到达
|
||||
ORDERSTATUSCLOUDSTOREORDERED OrderStatusCode = 20100 // 20100,云仓单--已下单
|
||||
ORDERSTATUSCLOUDSTOREORDEREDMAINING OrderStatusCode = 20100001 // 20100001,云仓单--已下单-尾款
|
||||
ORDERSTATUSCLOUDSTORECANCEL OrderStatusCode = 20101 // 20101,云仓单--已取消
|
||||
ORDERSTATUSCLOUDSTORESTARTPRODUCTION OrderStatusCode = 20200 // 20200,云仓单--开始生产
|
||||
ORDERSTATUSCLOUDSTOREOMPLETEPRODUCTION OrderStatusCode = 20300 // 20300,云仓单--生产完成
|
||||
ORDERSTATUSCLOUDSTOREARRIVEDWAREHOUSE OrderStatusCode = 20400 // 20400,云仓单--直达仓库
|
||||
)
|
||||
|
||||
// 订单状态名称
|
||||
|
@ -85,8 +87,8 @@ var OrderStatusUserCLOUDSTORE []OrderStatusCode
|
|||
func init() {
|
||||
// 订单状态名称
|
||||
PayStatusMessage = make(map[PayStatusCode]string)
|
||||
PayStatusMessage[PAYSTATUSUNPAID] = "Paid"
|
||||
PayStatusMessage[PAYSTATUSPAID] = "Unpaid"
|
||||
PayStatusMessage[PAYSTATUSUNPAID] = "Unpaid"
|
||||
PayStatusMessage[PAYSTATUSPAID] = "Paid"
|
||||
PayStatusMessage[PAYSTATUSREFUNDED] = "Refunded"
|
||||
|
||||
// 订单状态名称
|
||||
|
|
|
@ -219,26 +219,26 @@ func (l *StripeWebhookLogic) HandleChargeRefunded(chargeRefunded *stripe.Charge)
|
|||
}
|
||||
|
||||
// session完成
|
||||
func (l *StripeWebhookLogic) handlePaymentSessionCompleted(sessionId string, tradeNo string) (err error) {
|
||||
// 查询支付记录
|
||||
payModel := gmodel.NewFsPayModel(l.svcCtx.MysqlConn)
|
||||
rsbPay := payModel.RowSelectBuilder(nil)
|
||||
rsbPay = rsbPay.Where("session_id = ?", sessionId)
|
||||
payInfo, err := payModel.FindOneByQuery(l.ctx, rsbPay, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if *payInfo.PayStatus == 0 {
|
||||
*payInfo.TradeNo = tradeNo
|
||||
_, err = payModel.CreateOrUpdate(l.ctx, payInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return errors.New("pay status 1")
|
||||
}
|
||||
return err
|
||||
}
|
||||
// func (l *StripeWebhookLogic) handlePaymentSessionCompleted(sessionId string, tradeNo string) (err error) {
|
||||
// // 查询支付记录
|
||||
// payModel := gmodel.NewFsPayModel(l.svcCtx.MysqlConn)
|
||||
// rsbPay := payModel.RowSelectBuilder(nil)
|
||||
// rsbPay = rsbPay.Where("session_id = ?", sessionId)
|
||||
// payInfo, err := payModel.FindOneByQuery(l.ctx, rsbPay, nil)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// if *payInfo.PayStatus == 0 {
|
||||
// *payInfo.TradeNo = tradeNo
|
||||
// _, err = payModel.CreateOrUpdate(l.ctx, payInfo)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// } else {
|
||||
// return errors.New("pay status 1")
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
// 付款成功
|
||||
func (l *StripeWebhookLogic) HandleChargeSucceeded(charge *stripe.Charge, eventId string) error {
|
||||
|
@ -254,7 +254,7 @@ func (l *StripeWebhookLogic) HandleChargeSucceeded(charge *stripe.Charge, eventI
|
|||
case "product_order":
|
||||
res, err := l.svcCtx.Repositories.NewOrder.PaymentSuccessful(l.ctx, &repositories.PaymentSuccessfulReq{
|
||||
EventId: eventId,
|
||||
PaymentMethod: 1,
|
||||
PaymentMethod: "stripe",
|
||||
Charge: charge,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -47,7 +47,7 @@ type (
|
|||
}
|
||||
|
||||
PayInfo struct {
|
||||
PayMethod int64 `json:"pay_method"` // 交易方式
|
||||
PayMethod string `json:"pay_method"` // 交易方式
|
||||
PayTime time.Time `json:"pay_time"` // 支付时间
|
||||
Status gmodel.PayStatus `json:"status"` // 当前状态
|
||||
StatusLink []gmodel.PayStatus `json:"status_link"` // 状态链路
|
||||
|
@ -79,7 +79,7 @@ type (
|
|||
/* 支付成功 */
|
||||
PaymentSuccessfulReq struct {
|
||||
EventId string
|
||||
PaymentMethod int64
|
||||
PaymentMethod string
|
||||
Charge *stripe.Charge
|
||||
}
|
||||
PaymentSuccessfulRes struct{}
|
||||
|
@ -174,6 +174,15 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess
|
|||
var payAmount int64
|
||||
var payTitle string
|
||||
var payTime time.Time
|
||||
|
||||
var paymentMethod int64 = 1
|
||||
if in.PaymentMethod == "stripe" {
|
||||
paymentMethod = 1
|
||||
}
|
||||
if in.PaymentMethod == "paypal" {
|
||||
paymentMethod = 2
|
||||
}
|
||||
|
||||
if in.Charge != nil {
|
||||
charge := in.Charge
|
||||
orderSn, ok = charge.Metadata["order_sn"]
|
||||
|
@ -238,20 +247,30 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess
|
|||
payInfo.PayMethod = in.PaymentMethod
|
||||
payInfo.PayTime = payTime
|
||||
payInfo.TradeNo = tradeSn
|
||||
|
||||
// 当前状态
|
||||
var statusCode constants.OrderStatusCode
|
||||
var statusCodePre constants.OrderStatusCode
|
||||
if payStage == "deposit" {
|
||||
if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDIRECTMAIL {
|
||||
// 直邮
|
||||
statusCode = constants.ORDERSTATUSDIRECTMAILORDERED
|
||||
}
|
||||
if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDSCLOUDSTORE {
|
||||
// 云仓
|
||||
statusCode = constants.ORDERSTATUSCLOUDSTOREORDERED
|
||||
}
|
||||
payStageInt = 1
|
||||
orderPayStatusCode = constants.ORDERPAYSTATUSPAIDDEPOSIT
|
||||
status = gmodel.OrderStatus{
|
||||
Ctime: &ntime,
|
||||
Utime: &ntime,
|
||||
StatusCode: constants.ORDERSTATUSDIRECTMAILORDERED,
|
||||
StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSDIRECTMAILORDERED],
|
||||
StatusCode: statusCode,
|
||||
StatusTitle: constants.OrderStatusMessage[statusCode],
|
||||
}
|
||||
statusLink = order.UpdateOrderStatusLink(ress.OrderDetailOriginal.OrderInfo.StatusLink, gmodel.OrderStatus{
|
||||
Utime: &ntime,
|
||||
StatusCode: constants.ORDERSTATUSDIRECTMAILORDERED,
|
||||
StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSDIRECTMAILORDERED],
|
||||
StatusCode: statusCode,
|
||||
StatusTitle: constants.OrderStatusMessage[statusCode],
|
||||
})
|
||||
payInfo.Status = gmodel.PayStatus{
|
||||
StatusCode: int64(constants.PAYSTATUSPAID),
|
||||
|
@ -265,19 +284,38 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess
|
|||
}
|
||||
}
|
||||
if payStage == "remaining_balance" {
|
||||
if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDIRECTMAIL {
|
||||
// 直邮
|
||||
statusCodePre = constants.ORDERSTATUSDIRECTMAILORDERED
|
||||
statusCode = constants.ORDERSTATUSDIRECTMAILORDEREDMAINING
|
||||
}
|
||||
if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDSCLOUDSTORE {
|
||||
// 云仓
|
||||
statusCodePre = constants.ORDERSTATUSCLOUDSTOREORDERED
|
||||
statusCode = constants.ORDERSTATUSCLOUDSTOREORDEREDMAINING
|
||||
}
|
||||
payStageInt = 2
|
||||
orderPayStatusCode = constants.ORDERPAYSTATUSPAIDDREMAINING
|
||||
status = gmodel.OrderStatus{
|
||||
Ctime: &ntime,
|
||||
Utime: &ntime,
|
||||
StatusCode: constants.ORDERSTATUSCLOUDSTOREORDERED,
|
||||
StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSCLOUDSTOREORDERED],
|
||||
|
||||
var statusChildren []*gmodel.OrderStatus
|
||||
// 更新订单状态链路--子状态
|
||||
for oStatusLinkKey, oStatusLink := range ress.OrderDetail.OrderInfo.StatusLink {
|
||||
if oStatusLink.StatusCode == statusCodePre {
|
||||
statusChildren = append(oStatusLink.Children, &gmodel.OrderStatus{
|
||||
Ctime: &ntime,
|
||||
Utime: &ntime,
|
||||
StatusCode: statusCode,
|
||||
StatusTitle: constants.OrderStatusMessage[statusCode],
|
||||
})
|
||||
ress.OrderDetail.OrderInfo.StatusLink[oStatusLinkKey].Children = statusChildren
|
||||
}
|
||||
}
|
||||
statusLink = order.UpdateOrderStatusLink(ress.OrderDetailOriginal.OrderInfo.StatusLink, gmodel.OrderStatus{
|
||||
Utime: &ntime,
|
||||
StatusCode: constants.ORDERSTATUSCLOUDSTOREORDERED,
|
||||
StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSCLOUDSTOREORDERED],
|
||||
})
|
||||
|
||||
if ress.OrderDetail.OrderInfo.Status.StatusCode == constants.ORDERSTATUSDIRECTMAILORDERED || ress.OrderDetail.OrderInfo.Status.StatusCode == constants.ORDERSTATUSCLOUDSTOREORDERED {
|
||||
status = ress.OrderDetail.OrderInfo.Status
|
||||
status.Children = statusChildren
|
||||
}
|
||||
|
||||
payInfo.StatusLink = append(ress.OrderDetail.OrderAmount.RemainingBalance.StatusLink, payInfo.Status)
|
||||
uOrderDetail["order_amount"] = struct {
|
||||
RemainingBalance PayInfo `json:"remaining_balance"`
|
||||
|
@ -294,7 +332,7 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess
|
|||
TradeSn: &tradeSn,
|
||||
PayAmount: &payAmount,
|
||||
PayStatus: &payStatus,
|
||||
PaymentMethod: &in.PaymentMethod,
|
||||
PaymentMethod: &paymentMethod,
|
||||
PayStage: &payStageInt,
|
||||
CardSn: &card,
|
||||
CardBrand: &brand,
|
||||
|
@ -1037,7 +1075,6 @@ func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel
|
|||
orderDetail.OrderProduct[orderProductKey].TotalPrice = order.GetAmountInfoFormat(&orderProduct.TotalPrice)
|
||||
orderDetail.OrderProduct[orderProductKey].TotalPrice = order.GetAmountInfoFormat(&orderProduct.TotalPrice)
|
||||
orderDetail.OrderProduct[orderProductKey].PurchaseQuantity = order.GetPurchaseQuantity(&orderProduct.PurchaseQuantity)
|
||||
orderDetail.OrderProduct[orderProductKey].ShoppingCartSnapshot = nil
|
||||
orderDetail.OrderProduct[orderProductKey].ProductSnapshot = nil
|
||||
}
|
||||
orderDetail.OrderInfo.StatusLink = order.GetOrderStatusLinkUser(orderDetail.OrderInfo.DeliveryMethod, orderDetail.OrderInfo.StatusLink)
|
||||
|
@ -1046,7 +1083,6 @@ func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel
|
|||
orderDetail.OrderAmount.Subtotal = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Subtotal)
|
||||
orderDetail.OrderAmount.Total = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Total)
|
||||
orderDetail.PayTimeout = time.Duration(orderDetail.OrderInfo.Ctime.Add(orderDetail.PayTimeout).UTC().Unix() - time.Now().UTC().Unix())
|
||||
|
||||
}
|
||||
|
||||
return &DetailRes{
|
||||
|
|
Loading…
Reference in New Issue
Block a user