66 lines
1.1 KiB
Go
66 lines
1.1 KiB
Go
package timeslicequery
|
|
|
|
import (
|
|
"context"
|
|
"voucher/internal/biz/bo"
|
|
)
|
|
|
|
func (v *Query) wechatQuery(ctx context.Context, order *bo.OrderBo, useNum *int) error {
|
|
|
|
status, err := v.wechatCpnRepo.Query(ctx, order)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if status.IsUse() {
|
|
if err = v.queryUsed(ctx, order); err != nil {
|
|
return err
|
|
}
|
|
*useNum += 1
|
|
} else if status.IsExpired() {
|
|
return v.queryExpired(ctx, order)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (v *Query) queryUsed(ctx context.Context, order *bo.OrderBo) error {
|
|
|
|
if order.Status.IsUse() {
|
|
return v.notify(ctx, order)
|
|
}
|
|
|
|
if err := v.orderRepo.Used(ctx, order.ID); err != nil {
|
|
return err
|
|
}
|
|
|
|
return v.notify(ctx, order)
|
|
}
|
|
|
|
func (v *Query) queryExpired(ctx context.Context, order *bo.OrderBo) error {
|
|
|
|
if order.Status.IsExpired() {
|
|
return nil
|
|
}
|
|
|
|
if err := v.orderRepo.Expired(ctx, order.ID); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil // 过期不做通知
|
|
}
|
|
|
|
func (v *Query) notify(ctx context.Context, order *bo.OrderBo) error {
|
|
|
|
order, err := v.orderRepo.GetByID(ctx, order.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if _, err = v.cmb.Notify(ctx, order); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|