接口调整

This commit is contained in:
李子铭 2025-03-13 11:14:44 +08:00
parent 866459211a
commit e9c99d7542
4 changed files with 40 additions and 11 deletions

View File

@ -16,5 +16,6 @@ type OrderRepo interface {
Success(ctx context.Context, id uint64, voucherNo string) error
Fail(ctx context.Context, id uint64, remark string) error
Used(ctx context.Context, id uint64) error
Available(ctx context.Context, id uint64) error
Expired(ctx context.Context, id uint64) error
}

View File

@ -21,7 +21,13 @@ func (v *VoucherBiz) WechatNotifyConsumer(ctx context.Context, tag string, req *
return err
}
if req.PlainText.Status.IsUsed() {
if req.PlainText.Status.IsSended() {
if err = v.available(ctx, order); err != nil {
return err
}
} else if req.PlainText.Status.IsUsed() {
if err = v.used(ctx, order); err != nil {
return err
@ -65,6 +71,18 @@ func (v *VoucherBiz) used(ctx context.Context, order *bo.OrderBo) error {
return v.OrderRepo.Used(ctx, order.ID)
}
func (v *VoucherBiz) available(ctx context.Context, order *bo.OrderBo) error {
if order.Status.IsSuccess() {
log.Warnf("券状态已是可使用,忽略不处理,orderNo:%s", order.OrderNo)
return nil
}
log.Warnf("券状态重置为可使用,orderNo:%s", order.OrderNo)
return v.OrderRepo.Available(ctx, order.ID)
}
func (j *VoucherBiz) expired(ctx context.Context, order *bo.OrderBo) error {
if order.Status.IsExpired() {

View File

@ -160,6 +160,26 @@ func (p *OrderRepoImpl) Success(ctx context.Context, id uint64, voucherNo string
return nil
}
func (p *OrderRepoImpl) Available(ctx context.Context, id uint64) error {
now := time.Now()
res := p.db.DB(ctx).
Where(model.Order{
ID: id,
Status: vo.OrderStatusUse.GetValue(),
}).
Updates(model.Order{
Status: vo.OrderStatusSuccess.GetValue(),
UpdateTime: &now,
})
if res.Error != nil {
return res.Error
}
return nil
}
func (p *OrderRepoImpl) Fail(ctx context.Context, id uint64, remark string) error {
now := time.Now()

View File

@ -3,7 +3,6 @@ package service
import (
"context"
"encoding/json"
"github.com/go-kratos/kratos/v2/log"
"voucher/internal/biz/bo"
)
@ -15,14 +14,5 @@ func (v *VoucherService) WechatNotifyConsumer(ctx context.Context, tag, msg stri
return err
}
if req.PlainText.Status.IsSended() {
log.Warnf("券状态可用,忽略不处理,couponId:%s,stockId:%s,status:%s",
req.PlainText.CouponID,
req.PlainText.StockID,
req.PlainText.Status.GetText(),
)
return nil
}
return v.VoucherBiz.WechatNotifyConsumer(ctx, tag, req)
}