70 lines
1.4 KiB
Go
70 lines
1.4 KiB
Go
package biz
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/go-kratos/kratos/v2/log"
|
|
"time"
|
|
"voucher/internal/biz/bo"
|
|
)
|
|
|
|
func (v *VoucherBiz) PushWechatQuery(ctx context.Context, productNo string) error {
|
|
|
|
product, err := v.ProductRepo.GetByProductNo(ctx, productNo)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
queue := v.bc.RdsMQ.GetWechatQuery()
|
|
if queue == nil {
|
|
return fmt.Errorf("队列不存在")
|
|
}
|
|
|
|
_, err = v.rdb.Rdb.RPush(ctx, queue.Name, product.BatchNo).Result()
|
|
if err != nil {
|
|
return fmt.Errorf("添加到队列失败:%v", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (v *VoucherBiz) WechatQuery(ctx context.Context, batchNo string) error {
|
|
|
|
if batchNo == "" {
|
|
return fmt.Errorf("batchNo is empty")
|
|
}
|
|
|
|
return v.OrderRepo.FinByStockIdInBatches(ctx, batchNo, func(ctx context.Context, rows []*bo.OrderBo) error {
|
|
|
|
for _, order := range rows {
|
|
|
|
if err := v.wechatQuery(ctx, order); err != nil {
|
|
log.Errorf("微信查询券订单状态发生错误,batchNo:%s,orderNo:%s,couponId:%s,appId:%s,openId:%s,err:%v",
|
|
batchNo, order.OrderNo, order.VoucherNo, order.AppID, order.Account, err)
|
|
}
|
|
|
|
}
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
return nil
|
|
})
|
|
|
|
}
|
|
|
|
func (v *VoucherBiz) wechatQuery(ctx context.Context, order *bo.OrderBo) error {
|
|
|
|
status, err := v.WechatCpnRepo.Query(ctx, order)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if status.IsUse() {
|
|
return v.used(ctx, order)
|
|
} else if status.IsExpired() {
|
|
return v.expired(ctx, order)
|
|
}
|
|
|
|
return nil
|
|
}
|