diff --git a/server/home-user-auth/internal/logic/userordercancellogic.go b/server/home-user-auth/internal/logic/userordercancellogic.go index 3fad53bb..13211fcf 100644 --- a/server/home-user-auth/internal/logic/userordercancellogic.go +++ b/server/home-user-auth/internal/logic/userordercancellogic.go @@ -76,16 +76,17 @@ func (l *UserOrderCancelLogic) UserOrderCancel(req *types.UserOrderCancelReq, us var nowTime = time.Now().Unix() var payList []handlers.PayInfo // 事务处理 - err = orderModel.Trans(l.ctx, func(ctx context.Context, connGorm *gorm.DB) (err error) { + ctx := l.ctx + err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error { // 修改订单信息 - orderModelTS := gmodel.NewFsOrderModel(connGorm) + orderModelTS := gmodel.NewFsOrderModel(tx) err = orderModelTS.Update(ctx, orderInfo) if err != nil { return err } // 新增退款记录 var isRefund int64 = 0 - refundReasonModelTS := gmodel.NewFsRefundReasonModel(connGorm) + refundReasonModelTS := gmodel.NewFsRefundReasonModel(tx) refundReasonModelTS.CreateOrUpdate(ctx, &gmodel.FsRefundReason{ IsRefund: &isRefund, RefundReasonId: &req.RefundReasonId, @@ -95,7 +96,7 @@ func (l *UserOrderCancelLogic) UserOrderCancel(req *types.UserOrderCancelReq, us }) // 退款申请 // 退款申请--查询支付信息 - fsPayModelTS := gmodel.NewFsPayModel(connGorm) + fsPayModelTS := gmodel.NewFsPayModel(tx) rbFsPay := fsPayModelTS.RowSelectBuilder(nil).Where("order_number = ?", orderInfo.Sn).Where("pay_status =?", constants.PAYSTATUS_SUCCESS).Where("is_refund =?", 0) payInfoList, err := fsPayModelTS.FindAll(ctx, rbFsPay, nil, "") if err != nil { diff --git a/server/pay/internal/logic/orderpaymentintentlogic.go b/server/pay/internal/logic/orderpaymentintentlogic.go index a5cb71bc..fdc608ad 100644 --- a/server/pay/internal/logic/orderpaymentintentlogic.go +++ b/server/pay/internal/logic/orderpaymentintentlogic.go @@ -107,7 +107,8 @@ func (l *OrderPaymentIntentLogic) OrderPaymentIntent(req *types.OrderPaymentInte var resData types.OrderPaymentIntentRes // 事务处理 - err = orderModel.Trans(l.ctx, func(ctx context.Context, connGorm *gorm.DB) error { + ctx := l.ctx + err = l.svcCtx.MysqlConn.Transaction(func(connGorm *gorm.DB) error { // 支付记录--处理 //支付记录改为一条订单多条,分首款尾款 var payStatus int64 = 0 var orderSource int64 = 1 diff --git a/server/pay/internal/logic/stripewebhooklogic.go b/server/pay/internal/logic/stripewebhooklogic.go index 038c2bce..5f327ab5 100644 --- a/server/pay/internal/logic/stripewebhooklogic.go +++ b/server/pay/internal/logic/stripewebhooklogic.go @@ -153,13 +153,13 @@ func (l *StripeWebhookLogic) HandlePayEventCreate(fsPayEvent *gmodel.FsPayEvent) func (l *StripeWebhookLogic) HandleChargeRefunded(chargeRefunded *stripe.Charge) (err error) { // 退款成功 if chargeRefunded.Status == "succeeded" { - orderModel := gmodel.NewFsOrderModel(l.svcCtx.MysqlConn) - err = orderModel.Trans(l.ctx, func(ctx context.Context, connGorm *gorm.DB) (err error) { + ctx := l.ctx + err = l.svcCtx.MysqlConn.Transaction(func(connGorm *gorm.DB) error { // 查询支付记录 payModelT := gmodel.NewFsPayModel(connGorm) payModelTRSB := payModelT.RowSelectBuilder(nil) payModelTRSB1 := payModelTRSB.Where("trade_no = ?", chargeRefunded.PaymentIntent.ID).Where("pay_status = ?", constants.PAYSTATUS_SUCCESS).Where("is_refund = ?", 0) - payInfo, err := payModelT.FindOneByQuery(l.ctx, payModelTRSB1, nil) + payInfo, err := payModelT.FindOneByQuery(ctx, payModelTRSB1, nil) if err != nil { return err } @@ -295,7 +295,8 @@ func (l *StripeWebhookLogic) HandlePaymentIntentSucceeded(paymentIntent *stripe. } } - err = orderModel.Trans(l.ctx, func(ctx context.Context, connGorm *gorm.DB) (err error) { + ctx := l.ctx + err = l.svcCtx.MysqlConn.Transaction(func(connGorm *gorm.DB) error { // 更新支付信息 payModelT := gmodel.NewFsPayModel(connGorm) *payInfo.PayStatus = 1 diff --git a/server/upload/internal/logic/uploadcallbacklogic.go b/server/upload/internal/logic/uploadcallbacklogic.go index a8b93eaf..4c67de50 100644 --- a/server/upload/internal/logic/uploadcallbacklogic.go +++ b/server/upload/internal/logic/uploadcallbacklogic.go @@ -64,8 +64,8 @@ func (l *UploadCallbackLogic) UploadCallback(req *types.UploadCallbackReq, useri bucketName = basic.StorageBucketName } - resourceModel := gmodel.NewFsResourceModel(l.svcCtx.MysqlConn) - err := resourceModel.Trans(l.ctx, func(ctx context.Context, connGorm *gorm.DB) (err error) { + ctx := l.ctx + err := l.svcCtx.MysqlConn.Transaction(func(connGorm *gorm.DB) error { resourceModelTS := gmodel.NewFsResourceModel(l.svcCtx.MysqlConn) resourceInfo, err := resourceModelTS.FindOneById(ctx, req.ResourceId) if err != nil { diff --git a/utils/file/upload.go b/utils/file/upload.go index f6f6a1d6..5665bf10 100644 --- a/utils/file/upload.go +++ b/utils/file/upload.go @@ -163,8 +163,8 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro var resourceId string = req.FileHash var uploadBaseRes = UploadBaseRes{} - resourceModel := gmodel.NewFsResourceModel(upload.MysqlConn) - err := resourceModel.Trans(upload.Ctx, func(ctx context.Context, connGorm *gorm.DB) error { + ctx := upload.Ctx + err := upload.MysqlConn.Transaction(func(connGorm *gorm.DB) error { resourceModelTS := gmodel.NewFsResourceModel(connGorm) resourceInfo, err := resourceModelTS.FindOneById(ctx, resourceId) if err == nil && resourceInfo.ResourceId != "" {