异步通知
This commit is contained in:
parent
091e0ef0ce
commit
3b672e7e05
|
|
@ -49,6 +49,8 @@ wechatNotifyMQ:
|
||||||
- voucher_notify_dev
|
- voucher_notify_dev
|
||||||
isOpenConsumer: false #是否启动消费 true/false
|
isOpenConsumer: false #是否启动消费 true/false
|
||||||
registerTagUrl: "https://wpcallbacks.api.1688sup.com/wechatPay/register_tag"
|
registerTagUrl: "https://wpcallbacks.api.1688sup.com/wechatPay/register_tag"
|
||||||
|
noticeStartDays: 7
|
||||||
|
noticeEndDays: 1
|
||||||
|
|
||||||
wechat:
|
wechat:
|
||||||
mchID: "1605446142" # 证书所属商户 蓝色兄弟服务商立减金配置
|
mchID: "1605446142" # 证书所属商户 蓝色兄弟服务商立减金配置
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,8 @@ wechatNotifyMQ:
|
||||||
- voucher_notify_dev
|
- voucher_notify_dev
|
||||||
isOpenConsumer: false #是否启动消费 true/false
|
isOpenConsumer: false #是否启动消费 true/false
|
||||||
registerTagUrl: "https://wpcallbacks.api.1688sup.com/wechatPay/register_tag"
|
registerTagUrl: "https://wpcallbacks.api.1688sup.com/wechatPay/register_tag"
|
||||||
|
noticeStartDays: 7
|
||||||
|
noticeEndDays: 1
|
||||||
|
|
||||||
wechat:
|
wechat:
|
||||||
mchID: "1605446142" # 证书所属商户 蓝色兄弟服务商立减金配置
|
mchID: "1605446142" # 证书所属商户 蓝色兄弟服务商立减金配置
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package biz
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-kratos/kratos/v2/log"
|
"github.com/go-kratos/kratos/v2/log"
|
||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
|
|
@ -17,6 +18,11 @@ func (v *VoucherBiz) OrderNotice(ctx context.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return v.ExecuteNotice(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *VoucherBiz) ExecuteNotice(ctx context.Context) error {
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
// 获取七天前的日期
|
// 获取七天前的日期
|
||||||
|
|
@ -41,8 +47,7 @@ func (v *VoucherBiz) OrderNotice(ctx context.Context) error {
|
||||||
if order.Type.IsCmb() {
|
if order.Type.IsCmb() {
|
||||||
|
|
||||||
if err := v.cmbOrderNotice(ctx, order); err != nil {
|
if err := v.cmbOrderNotice(ctx, order); err != nil {
|
||||||
log.Errorf("cmbOrderNotice err:%v", err)
|
log.Errorf("招行查询券订单状态发生错误,orderNo:%s,err:%v", order.OrderNo, err)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -57,13 +62,11 @@ func (v *VoucherBiz) OrderNotice(ctx context.Context) error {
|
||||||
func (v *VoucherBiz) isCanNotice(ctx context.Context) error {
|
func (v *VoucherBiz) isCanNotice(ctx context.Context) error {
|
||||||
|
|
||||||
if v.bc.Cmb.NoticeStartDays == 0 {
|
if v.bc.Cmb.NoticeStartDays == 0 {
|
||||||
log.Warnf("noticeStartDays eq 0")
|
return errors.New("noticeStartDays eq 0")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.bc.Cmb.NoticeEndDays == 0 {
|
if v.bc.Cmb.NoticeEndDays == 0 {
|
||||||
log.Warnf("noticeEndDays eq 0")
|
return errors.New("noticeEndDays eq 0")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cache := vo.CmbBatchNoticeCacheKey.BuildCache([]string{""})
|
cache := vo.CmbBatchNoticeCacheKey.BuildCache([]string{""})
|
||||||
|
|
|
||||||
|
|
@ -32,15 +32,11 @@ func (p *OrderRepoImpl) FindInBatches(ctx context.Context, w *bo.FindInBatchesUs
|
||||||
|
|
||||||
var results = make([]*model.Order, 0)
|
var results = make([]*model.Order, 0)
|
||||||
|
|
||||||
db := p.db.DB(ctx)
|
result := p.db.DB(ctx).
|
||||||
|
Where("last_use_time BETWEEN ? AND ?", w.StartTime, w.EndTime).
|
||||||
db.Where("type = ?", w.Type)
|
Where("type = ?", w.Type).
|
||||||
db.Where("status = ?", vo.OrderStatusUse)
|
Where("status = ?", vo.OrderStatusUse).
|
||||||
db.Where("last_use_time >= ?", w.StartTime)
|
FindInBatches(&results, 100, func(tx *gorm.DB, batch int) error {
|
||||||
db.Where("last_use_time <= ?", w.EndTime)
|
|
||||||
|
|
||||||
// 处理记录,批处理大小为100
|
|
||||||
result := db.FindInBatches(&results, 100, func(tx *gorm.DB, batch int) error {
|
|
||||||
// tx.RowsAffected 提供当前批处理中记录的计数(the count of records in the current batch)
|
// tx.RowsAffected 提供当前批处理中记录的计数(the count of records in the current batch)
|
||||||
// 'batch' 变量表示当前批号(the current batch number)
|
// 'batch' 变量表示当前批号(the current batch number)
|
||||||
// 返回 error 将阻止更多的批处理
|
// 返回 error 将阻止更多的批处理
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ func NewHTTPServer(
|
||||||
v1.POST("/decryptBody", voucherService.DecryptBody)
|
v1.POST("/decryptBody", voucherService.DecryptBody)
|
||||||
v1.POST("/queryWechatVoucherNotifyUrl", voucherService.QueryWechatVoucherNotifyUrl)
|
v1.POST("/queryWechatVoucherNotifyUrl", voucherService.QueryWechatVoucherNotifyUrl)
|
||||||
v1.POST("/setWechatVoucherNotifyUrl", voucherService.SetWechatVoucherNotifyUrl)
|
v1.POST("/setWechatVoucherNotifyUrl", voucherService.SetWechatVoucherNotifyUrl)
|
||||||
|
v1.POST("/test", voucherService.Test)
|
||||||
|
|
||||||
return srv
|
return srv
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -151,3 +151,12 @@ func (s *VoucherService) SetWechatVoucherNotifyUrl(ctx http.Context) error {
|
||||||
//})
|
//})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *VoucherService) Test(ctx http.Context) error {
|
||||||
|
|
||||||
|
if err := s.VoucherBiz.ExecuteNotice(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue