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 { start := time.Now() log.Warnf("微信券查询处理开始:%s,batchNo:%s", start.String(), batchNo) fmt.Printf("微信券查询处理开始:%s,batchNo:%s", start.String(), batchNo) num := 0 err := v.OrderRepo.FinSucByStockIdInBatches(ctx, batchNo, func(ctx context.Context, rows []*bo.OrderBo) error { for _, order := range rows { num += 1 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 }) log.Warnf("微信券查询处理耗时:%s,batchNo:%s,处理%d单", time.Now().Sub(start).String(), batchNo, num) fmt.Printf("微信券查询处理耗时:%s,batchNo:%s,处理%d单", time.Now().Sub(start).String(), batchNo, num) return err } 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 }