多笔立减金
This commit is contained in:
parent
d1fb805dff
commit
4508dfe00e
|
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
"github.com/go-kratos/kratos/v2/log"
|
||||
"gorm.io/gorm"
|
||||
"sync"
|
||||
err2 "voucher/api/err"
|
||||
v1 "voucher/api/v1"
|
||||
"voucher/internal/biz/bo"
|
||||
|
|
@ -28,6 +29,9 @@ type MultiBiz struct {
|
|||
MultiNotifyDataRepo repo.MultiNotifyDataRepo
|
||||
MultiNotifyLogRepo repo.MultiNotifyLogRepo
|
||||
CmbMixRepo mixrepos.CmbMixRepo
|
||||
|
||||
mu sync.RWMutex
|
||||
NonExistentBatchData map[string]bool
|
||||
}
|
||||
|
||||
func NewMultiBiz(
|
||||
|
|
@ -52,8 +56,29 @@ func NewMultiBiz(
|
|||
}
|
||||
}
|
||||
|
||||
func (this *MultiBiz) Get(uid string) bool {
|
||||
|
||||
if _, ok := this.NonExistentBatchData[uid]; ok {
|
||||
return ok
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (this *MultiBiz) Add(uid string) {
|
||||
|
||||
this.mu.Lock()
|
||||
defer this.mu.Unlock()
|
||||
|
||||
this.NonExistentBatchData[uid] = true
|
||||
}
|
||||
|
||||
func (biz *MultiBiz) Notify(ctx context.Context, ip, source string, req *bo.WechatVoucherNotifyBo) error {
|
||||
|
||||
if !biz.Get(req.PlainText.StockID) {
|
||||
return nil
|
||||
}
|
||||
|
||||
cl := vo.MultiNotifyLockKey.BuildCache([]string{
|
||||
source,
|
||||
req.PlainText.StockID,
|
||||
|
|
@ -65,9 +90,11 @@ func (biz *MultiBiz) Notify(ctx context.Context, ip, source string, req *bo.Wech
|
|||
_, err := biz.ProductRepo.GetByBatchNo(ctx, req.PlainText.StockID)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
biz.Add(req.PlainText.StockID)
|
||||
return nil
|
||||
}
|
||||
if err2.IsDbNotFound(err) {
|
||||
biz.Add(req.PlainText.StockID)
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
|
|
|
|||
Loading…
Reference in New Issue