切换主体

This commit is contained in:
ziming 2026-03-26 13:44:05 +08:00
parent 9c465d1f52
commit 2ec6b62912
3 changed files with 26 additions and 5 deletions

View File

@ -10,6 +10,7 @@ type ProductRepo interface {
GetById(ctx context.Context, id int32) (*bo.ProductBo, error)
FindWarningBudget(ctx context.Context, fun func(ctx context.Context, rows []*bo.ProductBo) error) error
GetByBatchNo(ctx context.Context, batchNo string) (*bo.ProductBo, error)
GetByMchStockId(ctx context.Context, mchId, stockId string) (*bo.ProductBo, error)
GetByProductNo(ctx context.Context, productNo string) (*bo.ProductBo, error)
UpdateByWxResp(ctx context.Context, id int32, req *do.WxResp) error
}

View File

@ -11,6 +11,12 @@ import (
func (this *VoucherBiz) WechatNotifyConsumer(ctx context.Context, ip string, req *bo.WechatVoucherNotifyBo) error {
// 商品数据量较少,先查询商品是否存在,过滤多余的通知信息
_, err := this.ProductRepo.GetByMchStockId(ctx, req.PlainText.StockCreatorMchid, req.PlainText.StockID)
if err != nil {
return fmt.Errorf("商品查询错误 error: %w", err)
}
c := vo.WechatNotifyConsumeLockKey.BuildCache([]string{req.PlainText.StockCreatorMchid, req.PlainText.StockID, req.PlainText.CouponID})
return lock.NewMutex(this.rdb.Rdb, c.TTL).Lock(ctx, c.Key, func(ctx context.Context) error {

View File

@ -104,14 +104,28 @@ func (r *ProductRepoImpl) GetByBatchNo(ctx context.Context, batchNo string) (*bo
tx := db.Where(model.Product{BatchNo: batchNo}).First(&item)
if tx.Error != nil {
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
return nil, err2.ErrorDbNotFound("商品数据不存在")
}
return nil, fmt.Errorf("product db fail %w", tx.Error)
return nil, tx.Error
}
if tx.RowsAffected == 0 {
return nil, err2.ErrorDbNotFound("商品数据不存在")
return nil, gorm.ErrRecordNotFound
}
return r.ToBo(item), nil
}
func (r *ProductRepoImpl) GetByMchStockId(ctx context.Context, mchId, stockId string) (*bo.ProductBo, error) {
var item *model.Product
tx := r.db.DB(ctx).Where(model.Product{MchId: mchId, BatchNo: stockId}).First(&item)
if tx.Error != nil {
return nil, tx.Error
}
if tx.RowsAffected == 0 {
return nil, gorm.ErrRecordNotFound
}
return r.ToBo(item), nil