cmb
This commit is contained in:
parent
4940e90a1e
commit
982e1c3877
|
|
@ -15,69 +15,64 @@ func (j *VoucherBiz) WechatNotifyConsumer(ctx context.Context, tag string, req *
|
|||
|
||||
return lock.NewMutex(j.rdb.Rdb, c.TTL).Lock(ctx, c.Key, func(ctx context.Context) error {
|
||||
|
||||
//req.PlainText.StockCreatorMchid = "1676203838"
|
||||
//req.PlainText.StockID = "20215869"
|
||||
//req.PlainText.CouponID = "96059179220"
|
||||
|
||||
if req.PlainText.Status.IsSended() {
|
||||
log.Warnf("券状态可用,忽略不处理,couponId:%s,stockId:%s,status:%s",
|
||||
req.PlainText.CouponID, req.PlainText.StockID, req.PlainText.Status.GetText())
|
||||
return nil
|
||||
}
|
||||
|
||||
//req.PlainText.StockCreatorMchid = "1676203838"
|
||||
//req.PlainText.StockID = "20215869"
|
||||
//req.PlainText.CouponID = "96059179220"
|
||||
|
||||
orderWechat, err := j.OrderWechatRepo.GetByMSCId(ctx, req.PlainText.StockCreatorMchid, req.PlainText.StockID, req.PlainText.CouponID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if req.PlainText.Status.IsUsed() {
|
||||
err = j.wechatVoucherUsed(ctx, orderWechat)
|
||||
} else if req.PlainText.Status.IsExpired() {
|
||||
err = j.wechatVoucherExpired(ctx, orderWechat)
|
||||
} else {
|
||||
err = fmt.Errorf("未知通知类型:%s", req.PlainText.Status.GetText())
|
||||
order, err := j.OrderRepo.GetByOrderNo(ctx, orderWechat.OrderNo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("根据订单号%s获取订单信息失败:%s", orderWechat.OrderNo, err.Error())
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if req.PlainText.Status.IsUsed() {
|
||||
if err = j.wechatVoucherUsed(ctx, order, orderWechat); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if req.PlainText.Status.IsExpired() {
|
||||
if err = j.wechatVoucherExpired(ctx, order, orderWechat); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("未知通知类型:%s", req.PlainText.Status.GetText())
|
||||
}
|
||||
|
||||
return j.PushNotifyMQ(ctx, orderWechat.OrderNo, orderWechat.OutRequestNo)
|
||||
})
|
||||
}
|
||||
|
||||
func (v *VoucherBiz) wechatVoucherUsed(ctx context.Context, orderWechat *bo.OrderWechatBo) error {
|
||||
func (v *VoucherBiz) wechatVoucherUsed(ctx context.Context, order *bo.OrderBo, orderWechat *bo.OrderWechatBo) error {
|
||||
|
||||
if orderWechat.Status.IsUse() {
|
||||
log.Warnf("券状态已是已使用,忽略不处理,orderNo:%s", orderWechat.OrderNo)
|
||||
return nil
|
||||
}
|
||||
|
||||
order, err := v.OrderRepo.GetByOrderNo(ctx, orderWechat.OrderNo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("根据订单号%s获取订单失败:%s", orderWechat.OrderNo, err.Error())
|
||||
}
|
||||
|
||||
if err = v.OrderWechatRepo.Used(ctx, orderWechat.ID); err != nil {
|
||||
if err := v.OrderWechatRepo.Used(ctx, orderWechat.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return v.OrderRepo.Used(ctx, order.ID)
|
||||
}
|
||||
|
||||
func (j *VoucherBiz) wechatVoucherExpired(ctx context.Context, orderWechat *bo.OrderWechatBo) error {
|
||||
func (j *VoucherBiz) wechatVoucherExpired(ctx context.Context, order *bo.OrderBo, orderWechat *bo.OrderWechatBo) error {
|
||||
|
||||
if orderWechat.Status.IsExpired() {
|
||||
log.Warnf("券状态已是已过期,忽略不处理,orderNo:%s", orderWechat.OrderNo)
|
||||
return nil
|
||||
}
|
||||
|
||||
order, err := j.OrderRepo.GetByOrderNo(ctx, orderWechat.OrderNo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = j.OrderWechatRepo.Expired(ctx, orderWechat.ID); err != nil {
|
||||
if err := j.OrderWechatRepo.Expired(ctx, orderWechat.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue