diff --git a/internal/data/repoimpl/order.go b/internal/data/repoimpl/order.go index 8342f1d..14fea1a 100644 --- a/internal/data/repoimpl/order.go +++ b/internal/data/repoimpl/order.go @@ -92,7 +92,7 @@ func (p *OrderRepoImpl) GetByOutBizNo(ctx context.Context, t vo.OrderType, outBi info := &model.Order{} - db := p.DB(ctx) + db := p.db.DB(ctx).WithContext(ctx).Model(model.Order{}) tx := db.Where(model.Order{Type: t.GetValue(), OutBizNo: outBizNo}).First(&info) if tx.Error != nil { @@ -122,9 +122,11 @@ func (p *OrderRepoImpl) GetByID(ctx context.Context, id uint64) (*bo.OrderBo, er tx := p.DB(ctx).Where(model.Order{ID: id}).First(&info) if tx.Error != nil { + if errors.Is(tx.Error, gorm.ErrRecordNotFound) { return nil, err2.ErrorDbNotFound("订单数据不存在") } + return nil, fmt.Errorf("order db fail %w", tx.Error) } diff --git a/internal/data/repoimpl/product.go b/internal/data/repoimpl/product.go index b592885..62a5814 100644 --- a/internal/data/repoimpl/product.go +++ b/internal/data/repoimpl/product.go @@ -85,7 +85,7 @@ func (r *ProductRepoImpl) GetByProductNo(ctx context.Context, productNo string) func (r *ProductRepoImpl) getByProductNo(ctx context.Context, item *model.Product, productNo string) (*model.Product, error) { - db := r.DB(ctx) + db := r.db.DB(ctx).WithContext(ctx).Model(model.Product{}) tx := db.Where(model.Product{ProductNo: productNo}).First(&item) if tx.Error != nil {