orderNotice定时任务

This commit is contained in:
李子铭 2025-03-19 09:30:53 +08:00
parent 33a9f1516b
commit 3eaffae096
2 changed files with 58 additions and 40 deletions

View File

@ -39,19 +39,64 @@ func (v *VoucherBiz) WechatNotifyConsumer(ctx context.Context, tag string, req *
return err
}
} else {
return fmt.Errorf("未知通知类型:%s", req.PlainText.Status.GetText())
}
if order.Type.IsCmb() {
return v.cmbNotify(ctx, order.ID)
}
return nil
return fmt.Errorf("未知通知类型:%s", req.PlainText.Status.GetText())
})
}
func (v *VoucherBiz) used(ctx context.Context, order *bo.OrderBo) error {
if order.Status.IsUse() {
log.Warnf("券状态已是已使用,忽略不处理,orderNo:%s", order.OrderNo)
return nil
}
if err := v.OrderRepo.Used(ctx, order.ID); err != nil {
return err
}
return v.notify(ctx, order)
}
func (v *VoucherBiz) available(ctx context.Context, order *bo.OrderBo) error {
if order.Status.IsSuccess() {
log.Warnf("券状态已是可使用,忽略不处理,orderNo:%s", order.OrderNo)
return nil
}
if err := v.OrderRepo.Available(ctx, order.ID); err != nil {
return err
}
return v.notify(ctx, order)
}
func (v *VoucherBiz) expired(ctx context.Context, order *bo.OrderBo) error {
if order.Status.IsExpired() {
log.Warnf("券状态已是已过期,忽略不处理,orderNo:%s", order.OrderNo)
return nil
}
if err := v.OrderRepo.Expired(ctx, order.ID); err != nil {
return err
}
return v.notify(ctx, order)
}
func (v *VoucherBiz) notify(ctx context.Context, order *bo.OrderBo) error {
if order.Type.IsCmb() {
return v.cmbNotify(ctx, order.ID)
}
return fmt.Errorf("未知渠道订单类型:%s", order.Type.GetText())
}
func (v *VoucherBiz) cmbNotify(ctx context.Context, orderId uint64) error {
order, err := v.OrderRepo.GetByID(ctx, orderId)
@ -72,35 +117,3 @@ func (v *VoucherBiz) cmbNotify(ctx context.Context, orderId uint64) error {
return nil
}
func (v *VoucherBiz) used(ctx context.Context, order *bo.OrderBo) error {
if order.Status.IsUse() {
log.Warnf("券状态已是已使用,忽略不处理,orderNo:%s", order.OrderNo)
return nil
}
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() {
log.Warnf("券状态已是已过期,忽略不处理,orderNo:%s", order.OrderNo)
return nil
}
return j.OrderRepo.Expired(ctx, order.ID)
}

View File

@ -11,6 +11,11 @@ func (s *VoucherService) CronNotice(ctx context.Context) error {
c, ok := s.bc.Cron.CommandMap["orderNotice"]
if !ok {
log.Warn("orderNotice定时任务未找到")
return nil
}
if !c.IsOpen {
log.Warn("orderNotice定时任务未开启")
return nil
}