This commit is contained in:
李子铭 2025-03-20 11:33:46 +08:00
parent 44ca97b7d0
commit 090663c725
2 changed files with 25 additions and 23 deletions

View File

@ -2,6 +2,7 @@ package repoimpl
import ( import (
"context" "context"
"fmt"
"gorm.io/gorm" "gorm.io/gorm"
"time" "time"
"unicode/utf8" "unicode/utf8"
@ -86,7 +87,7 @@ func (p *OrderRepoImpl) GetByOutBizNo(ctx context.Context, t vo.OrderType, outBi
tx := p.DB(ctx).Where(model.Order{Type: t.GetValue(), OutBizNo: outBizNo}).Find(&info) tx := p.DB(ctx).Where(model.Order{Type: t.GetValue(), OutBizNo: outBizNo}).Find(&info)
if tx.Error != nil { if tx.Error != nil {
return nil, tx.Error return nil, fmt.Errorf("db fail %w", tx.Error)
} }
if tx.RowsAffected == 0 { if tx.RowsAffected == 0 {
@ -102,7 +103,7 @@ func (p *OrderRepoImpl) GetByID(ctx context.Context, id uint64) (*bo.OrderBo, er
tx := p.DB(ctx).Where(model.Order{ID: id}).Find(&info) tx := p.DB(ctx).Where(model.Order{ID: id}).Find(&info)
if tx.Error != nil { if tx.Error != nil {
return nil, tx.Error return nil, fmt.Errorf("db fail %w", tx.Error)
} }
if tx.RowsAffected == 0 { if tx.RowsAffected == 0 {
@ -118,7 +119,7 @@ func (p *OrderRepoImpl) GetByOrderNo(ctx context.Context, orderNo string) (*bo.O
tx := p.DB(ctx).Where(model.Order{OrderNo: orderNo}).Find(&info) tx := p.DB(ctx).Where(model.Order{OrderNo: orderNo}).Find(&info)
if tx.Error != nil { if tx.Error != nil {
return nil, tx.Error return nil, fmt.Errorf("db fail %w", tx.Error)
} }
if tx.RowsAffected == 0 { if tx.RowsAffected == 0 {
@ -134,7 +135,7 @@ func (p *OrderRepoImpl) GetByMBV(ctx context.Context, merchantNo, batchNo, vouch
tx := p.DB(ctx).Where(model.Order{MerchantNo: merchantNo, BatchNo: batchNo, VoucherNo: voucherNo}).Find(&info) tx := p.DB(ctx).Where(model.Order{MerchantNo: merchantNo, BatchNo: batchNo, VoucherNo: voucherNo}).Find(&info)
if tx.Error != nil { if tx.Error != nil {
return nil, tx.Error return nil, fmt.Errorf("db fail %w", tx.Error)
} }
if tx.RowsAffected == 0 { if tx.RowsAffected == 0 {
@ -147,7 +148,7 @@ func (p *OrderRepoImpl) GetByMBV(ctx context.Context, merchantNo, batchNo, vouch
func (p *OrderRepoImpl) Ing(ctx context.Context, id uint64) error { func (p *OrderRepoImpl) Ing(ctx context.Context, id uint64) error {
now := time.Now() now := time.Now()
res := p.db.DB(ctx). tx := p.db.DB(ctx).
Where(model.Order{ Where(model.Order{
ID: id, ID: id,
Status: vo.OrderStatusWait.GetValue(), Status: vo.OrderStatusWait.GetValue(),
@ -157,8 +158,8 @@ func (p *OrderRepoImpl) Ing(ctx context.Context, id uint64) error {
UpdateTime: &now, UpdateTime: &now,
}) })
if res.Error != nil { if tx.Error != nil {
return res.Error return fmt.Errorf("db fail %w", tx.Error)
} }
return nil return nil
@ -167,7 +168,7 @@ func (p *OrderRepoImpl) Ing(ctx context.Context, id uint64) error {
func (p *OrderRepoImpl) Success(ctx context.Context, id uint64, voucherNo string) error { func (p *OrderRepoImpl) Success(ctx context.Context, id uint64, voucherNo string) error {
now := time.Now() now := time.Now()
res := p.db.DB(ctx). tx := p.db.DB(ctx).
Where(model.Order{ Where(model.Order{
ID: id, ID: id,
Status: vo.OrderStatusIng.GetValue(), Status: vo.OrderStatusIng.GetValue(),
@ -179,8 +180,8 @@ func (p *OrderRepoImpl) Success(ctx context.Context, id uint64, voucherNo string
UpdateTime: &now, UpdateTime: &now,
}) })
if res.Error != nil { if tx.Error != nil {
return res.Error return fmt.Errorf("db fail %w", tx.Error)
} }
return nil return nil
@ -189,7 +190,7 @@ func (p *OrderRepoImpl) Success(ctx context.Context, id uint64, voucherNo string
func (p *OrderRepoImpl) Available(ctx context.Context, id uint64) error { func (p *OrderRepoImpl) Available(ctx context.Context, id uint64) error {
now := time.Now() now := time.Now()
res := p.db.DB(ctx). tx := p.db.DB(ctx).
Where(model.Order{ Where(model.Order{
ID: id, ID: id,
Status: vo.OrderStatusUse.GetValue(), Status: vo.OrderStatusUse.GetValue(),
@ -200,8 +201,8 @@ func (p *OrderRepoImpl) Available(ctx context.Context, id uint64) error {
UpdateTime: &now, UpdateTime: &now,
}) })
if res.Error != nil { if tx.Error != nil {
return res.Error return fmt.Errorf("db fail %w", tx.Error)
} }
return nil return nil
@ -217,7 +218,7 @@ func (p *OrderRepoImpl) Fail(ctx context.Context, id uint64, remark string) erro
} }
} }
res := p.db.DB(ctx). tx := p.db.DB(ctx).
Where(model.Order{ Where(model.Order{
ID: id, ID: id,
}). }).
@ -227,8 +228,8 @@ func (p *OrderRepoImpl) Fail(ctx context.Context, id uint64, remark string) erro
UpdateTime: &now, UpdateTime: &now,
}) })
if res.Error != nil { if tx.Error != nil {
return res.Error return fmt.Errorf("db fail %w", tx.Error)
} }
return nil return nil
@ -237,7 +238,7 @@ func (p *OrderRepoImpl) Fail(ctx context.Context, id uint64, remark string) erro
func (p *OrderRepoImpl) Used(ctx context.Context, id uint64) error { func (p *OrderRepoImpl) Used(ctx context.Context, id uint64) error {
now := time.Now() now := time.Now()
res := p.db.DB(ctx). tx := p.db.DB(ctx).
Where(model.Order{ Where(model.Order{
ID: id, ID: id,
}). }).
@ -247,8 +248,8 @@ func (p *OrderRepoImpl) Used(ctx context.Context, id uint64) error {
UpdateTime: &now, UpdateTime: &now,
}) })
if res.Error != nil { if tx.Error != nil {
return res.Error return fmt.Errorf("db fail %w", tx.Error)
} }
return nil return nil
@ -257,7 +258,7 @@ func (p *OrderRepoImpl) Used(ctx context.Context, id uint64) error {
func (p *OrderRepoImpl) Expired(ctx context.Context, id uint64) error { func (p *OrderRepoImpl) Expired(ctx context.Context, id uint64) error {
now := time.Now() now := time.Now()
res := p.db.DB(ctx). tx := p.db.DB(ctx).
Where(model.Order{ Where(model.Order{
ID: id, ID: id,
}). }).
@ -266,8 +267,8 @@ func (p *OrderRepoImpl) Expired(ctx context.Context, id uint64) error {
UpdateTime: &now, UpdateTime: &now,
}) })
if res.Error != nil { if tx.Error != nil {
return res.Error return fmt.Errorf("db fail %w", tx.Error)
} }
return nil return nil

View File

@ -2,6 +2,7 @@ package repoimpl
import ( import (
"context" "context"
"fmt"
"gorm.io/gorm" "gorm.io/gorm"
err2 "voucher/api/err" err2 "voucher/api/err"
"voucher/internal/biz/bo" "voucher/internal/biz/bo"
@ -31,7 +32,7 @@ func (r *ProductRepoImpl) GetByPNO(ctx context.Context, PNO string) (*bo.Product
tx := r.DB(ctx).Where(model.Product{ProductNo: PNO}).Find(&item) tx := r.DB(ctx).Where(model.Product{ProductNo: PNO}).Find(&item)
if tx.Error != nil { if tx.Error != nil {
return nil, tx.Error return nil, fmt.Errorf("db fail %w", tx.Error)
} }
if tx.RowsAffected == 0 { if tx.RowsAffected == 0 {