多笔立减金
This commit is contained in:
parent
947c4e5e5c
commit
d3584edec5
|
|
@ -110,12 +110,7 @@ func (biz *MultiBiz) Run(ctx context.Context, source string, req *bo.WechatVouch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nl, err := biz.nlCreate(ctx, req, mnd, order)
|
return biz.run(ctx, req, mnd, order)
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("创建通知日志错误 error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return biz.Request(ctx, mnd, nl)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (biz *MultiBiz) RetryRunByMultiNotifyDataId(ctx context.Context, multiNotifyDataId int64) error {
|
func (biz *MultiBiz) RetryRunByMultiNotifyDataId(ctx context.Context, multiNotifyDataId int64) error {
|
||||||
|
|
@ -135,6 +130,25 @@ func (biz *MultiBiz) RetryRunByMultiNotifyDataId(ctx context.Context, multiNotif
|
||||||
return fmt.Errorf("通知数据 json unmarshal 错误 error: %v", err)
|
return fmt.Errorf("通知数据 json unmarshal 错误 error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return biz.run(ctx, req, mnd, order)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (biz *MultiBiz) run(ctx context.Context, req *bo.WechatVoucherNotifyBo, mnd *bo.MultiNotifyDataBo, order *bo.OrderBo) error {
|
||||||
|
|
||||||
|
if req.PlainText.Status.IsUsed() {
|
||||||
|
if order.Status.IsUse() && req.PlainText.ConsumeInformation.ConsumeTime != *order.LastUseTime {
|
||||||
|
if err := biz.OrderRepo.OverUsed(ctx, order.ID, req.PlainText.ConsumeInformation.ConsumeTime); err != nil {
|
||||||
|
return fmt.Errorf("订单使用完成修改发生错误 error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if req.PlainText.ConsumeInformation.ConsumeTime != *order.LastUseTime {
|
||||||
|
if err := biz.OrderRepo.LastUsed(ctx, order.ID, req.PlainText.ConsumeInformation.ConsumeTime); err != nil {
|
||||||
|
return fmt.Errorf("订单使用修改发生错误 error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nl, err := biz.nlCreate(ctx, req, mnd, order)
|
nl, err := biz.nlCreate(ctx, req, mnd, order)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("创建通知日志错误 error: %v", err)
|
return fmt.Errorf("创建通知日志错误 error: %v", err)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
"voucher/internal/biz/bo"
|
"voucher/internal/biz/bo"
|
||||||
"voucher/internal/biz/do"
|
"voucher/internal/biz/do"
|
||||||
"voucher/internal/biz/vo"
|
"voucher/internal/biz/vo"
|
||||||
|
|
@ -25,6 +26,8 @@ type OrderRepo interface {
|
||||||
Fail(ctx context.Context, id uint64, remark string) error
|
Fail(ctx context.Context, id uint64, remark string) error
|
||||||
Used(ctx context.Context, id uint64) error
|
Used(ctx context.Context, id uint64) error
|
||||||
NotifyUsed(ctx context.Context, id uint64, transactionId string) error
|
NotifyUsed(ctx context.Context, id uint64, transactionId string) error
|
||||||
|
LastUsed(ctx context.Context, id uint64, lastUseTime time.Time) error
|
||||||
|
OverUsed(ctx context.Context, id uint64, lastUseTime time.Time) error
|
||||||
Available(ctx context.Context, id uint64) error
|
Available(ctx context.Context, id uint64) error
|
||||||
Expired(ctx context.Context, id uint64) error
|
Expired(ctx context.Context, id uint64) error
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -453,6 +453,47 @@ func (p *OrderRepoImpl) Used(ctx context.Context, id uint64) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *OrderRepoImpl) LastUsed(ctx context.Context, id uint64, lastUseTime time.Time) error {
|
||||||
|
now := time.Now()
|
||||||
|
|
||||||
|
tx := p.DB(ctx).
|
||||||
|
Where(model.Order{
|
||||||
|
ID: id,
|
||||||
|
}).
|
||||||
|
Updates(model.Order{
|
||||||
|
Remark: "核销",
|
||||||
|
LastUseTime: &lastUseTime,
|
||||||
|
UpdateTime: &now,
|
||||||
|
})
|
||||||
|
|
||||||
|
if tx.Error != nil {
|
||||||
|
return fmt.Errorf("update db fail %w", tx.Error)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *OrderRepoImpl) OverUsed(ctx context.Context, id uint64, lastUseTime time.Time) error {
|
||||||
|
now := time.Now()
|
||||||
|
|
||||||
|
tx := p.DB(ctx).
|
||||||
|
Where(model.Order{
|
||||||
|
ID: id,
|
||||||
|
}).
|
||||||
|
Updates(model.Order{
|
||||||
|
Status: vo.OrderStatusUse.GetValue(),
|
||||||
|
Remark: "核销完成",
|
||||||
|
LastUseTime: &lastUseTime,
|
||||||
|
UpdateTime: &now,
|
||||||
|
})
|
||||||
|
|
||||||
|
if tx.Error != nil {
|
||||||
|
return fmt.Errorf("update db fail %w", tx.Error)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (p *OrderRepoImpl) NotifyUsed(ctx context.Context, id uint64, transactionId string) error {
|
func (p *OrderRepoImpl) NotifyUsed(ctx context.Context, id uint64, transactionId string) error {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue