This commit is contained in:
ziming 2025-05-27 16:11:14 +08:00
parent 2b10381a16
commit 8d11662035
4 changed files with 15 additions and 7 deletions

View File

@ -75,7 +75,7 @@ func (v *VoucherBiz) UpdateOrderStatus(ctx context.Context, orderId uint64, stat
} else if status.IsUse() { } else if status.IsUse() {
return v.OrderRepo.Used(ctx, orderId) return v.OrderRepo.Used(ctx, orderId, time.Now())
} else if status.IsExpired() { } else if status.IsExpired() {

View File

@ -2,6 +2,7 @@ package repo
import ( import (
"context" "context"
"time"
"voucher/internal/biz/bo" "voucher/internal/biz/bo"
"voucher/internal/biz/vo" "voucher/internal/biz/vo"
) )
@ -16,7 +17,7 @@ type OrderRepo interface {
Ing(ctx context.Context, id uint64) error Ing(ctx context.Context, id uint64) error
Success(ctx context.Context, id uint64, voucherNo string) error Success(ctx context.Context, id uint64, voucherNo string) error
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, usedTime 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
} }

View File

@ -30,7 +30,7 @@ func (v *VoucherBiz) WechatNotifyConsumer(ctx context.Context, tag string, req *
} else if req.PlainText.Status.IsUsed() { } else if req.PlainText.Status.IsUsed() {
if err = v.used(ctx, order); err != nil { if err = v.used(ctx, order, req.PlainText.ConsumeInformation.ConsumeTime); err != nil {
return err return err
} }
@ -90,9 +90,16 @@ func (v *VoucherBiz) createUseLog(ctx context.Context, order *bo.OrderBo, req *b
return nil return nil
} }
func (v *VoucherBiz) used(ctx context.Context, order *bo.OrderBo) error { func (v *VoucherBiz) used(ctx context.Context, order *bo.OrderBo, consumeTime string) error {
if err := v.OrderRepo.Used(ctx, order.ID); err != nil { var usedTime time.Time
if consumeTime != "" {
usedTime, _ = time.Parse(time.RFC3339, consumeTime)
} else {
usedTime = time.Now()
}
if err := v.OrderRepo.Used(ctx, order.ID, usedTime); err != nil {
return err return err
} }

View File

@ -256,7 +256,7 @@ func (p *OrderRepoImpl) Fail(ctx context.Context, id uint64, remark string) erro
return nil return nil
} }
func (p *OrderRepoImpl) Used(ctx context.Context, id uint64) error { func (p *OrderRepoImpl) Used(ctx context.Context, id uint64, usedTime time.Time) error {
now := time.Now() now := time.Now()
tx := p.DB(ctx). tx := p.DB(ctx).
@ -265,7 +265,7 @@ func (p *OrderRepoImpl) Used(ctx context.Context, id uint64) error {
}). }).
Updates(model.Order{ Updates(model.Order{
Status: vo.OrderStatusUse.GetValue(), Status: vo.OrderStatusUse.GetValue(),
LastUseTime: &now, LastUseTime: &usedTime,
UpdateTime: &now, UpdateTime: &now,
}) })