This commit is contained in:
李子铭 2025-03-14 11:51:49 +08:00
parent a8ccd564c7
commit 0d1870f5c8
3 changed files with 41 additions and 25 deletions

View File

@ -69,6 +69,10 @@ func (v *VoucherBiz) CmbQuery(ctx context.Context, orderNo string) (resp *v1.Cmb
return err return err
} }
if err = v.Query(ctx, order); err != nil {
return err
}
status, err := order.Status.GetCmbStatusText() status, err := order.Status.GetCmbStatusText()
if err != nil { if err != nil {
return err return err

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"github.com/go-kratos/kratos/v2/log"
"github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9"
"gorm.io/gorm" "gorm.io/gorm"
"voucher/internal/biz/bo" "voucher/internal/biz/bo"
@ -236,3 +237,37 @@ func (v *VoucherBiz) alarmText(_ context.Context, order *bo.OrderBo, errMsg stri
return fmt.Sprintf(msg, remarks) return fmt.Sprintf(msg, remarks)
} }
func (v *VoucherBiz) Query(ctx context.Context, order *bo.OrderBo) error {
status, err := v.WechatCpnRepo.Query(ctx, order)
if err != nil {
return err
}
if order.Status == status {
log.Warnf("券状态未改变:%s忽略不处理,orderNo:%s", order.Status.GetText(), order.OrderNo)
return nil
}
if err = v.UpdateOrderStatus(ctx, order.ID, status); err != nil {
return err
}
order.Status = status
return nil
}
func (v *VoucherBiz) UpdateOrderStatus(ctx context.Context, orderId uint64, status vo.OrderStatus) error {
if status.IsSuccess() {
return v.OrderRepo.Available(ctx, orderId)
} else if status.IsUse() {
return v.OrderRepo.Used(ctx, orderId)
} else if status.IsExpired() {
return v.OrderRepo.Expired(ctx, orderId)
}
return fmt.Errorf("notice 未知券状态,orderId:%d,statuText:%s", orderId, status.GetText())
}

View File

@ -104,33 +104,10 @@ func (v *VoucherBiz) isCanNotice(ctx context.Context) error {
func (v *VoucherBiz) cmbOrderNotice(ctx context.Context, order *bo.OrderBo) error { func (v *VoucherBiz) cmbOrderNotice(ctx context.Context, order *bo.OrderBo) error {
// 批量通知不做数据存储,量可能会很大很大 // 批量通知不做数据存储,量可能会很大很大
status, err := v.WechatCpnRepo.Query(ctx, order)
if err != nil {
return err
}
if order.Status == status { if err := v.Query(ctx, order); err != nil {
log.Warnf("notice 券状态未改变:%s忽略不处理,orderNo:%s", order.Status.GetText(), order.OrderNo)
return nil
}
if status.IsSuccess() {
if err = v.OrderRepo.Available(ctx, order.ID); err != nil {
return err return err
} }
} else if status.IsUse() {
if err = v.OrderRepo.Used(ctx, order.ID); err != nil {
return err
}
} else if status.IsExpired() {
if err = v.OrderRepo.Expired(ctx, order.ID); err != nil {
return err
}
} else {
return fmt.Errorf("notice 未知券状态,orderNo:%s,statuText:%s", order.OrderNo, status.GetText())
}
order.Status = status
event, err := order.Status.GetOrderNotifyEvent() event, err := order.Status.GetOrderNotifyEvent()
if err != nil { if err != nil {