多笔立减金

This commit is contained in:
ziming 2025-12-11 18:29:23 +08:00
parent d01900b519
commit 43bf445f8b
2 changed files with 25 additions and 8 deletions

View File

@ -3,21 +3,22 @@ package bo
import (
"encoding/json"
"fmt"
"github.com/go-playground/validator/v10"
"time"
"voucher/internal/biz/vo"
)
// ConsumeInformation 定义消费信息结构体
type ConsumeInformation struct {
ConsumeTime time.Time `json:"consume_time"` // 核销时间
ConsumeTime time.Time `json:"consume_time" validate:"required"` // 核销时间
ConsumeMchid string `json:"consume_mchid"` // 核销商户号
TransactionID string `json:"transaction_id"` // 微信支付交易单号
ConsumeAmount int `json:"consume_amount"` // 核销金额(单位:分)
TransactionID string `json:"transaction_id" validate:"required"` // 微信支付交易单号
ConsumeAmount int `json:"consume_amount" validate:"required"` // 核销金额(单位:分)
}
// PlainText 定义明文数据结构体
type PlainText struct {
StockCreatorMchid string `json:"stock_creator_mchid"`
StockCreatorMchid string `json:"stock_creator_mchid" validate:"required"`
StockID string `json:"stock_id"`
CouponID string `json:"coupon_id"`
CouponName string `json:"coupon_name"`
@ -32,14 +33,14 @@ type PlainText struct {
}
type WechatVoucherNotifyBo struct {
ID string `json:"id"`
ID string `json:"id" validate:"required"`
CreateTime string `json:"create_time"`
ResourceType string `json:"resource_type"`
EventType string `json:"event_type"`
EventType string `json:"event_type" validate:"required"`
Summary string `json:"summary"`
OriginalType string `json:"original_type"`
AssociatedData string `json:"associated_data"`
PlainText PlainText `json:"plain_text"`
PlainText PlainText `json:"plain_text" validate:"required"`
}
func (d *WechatVoucherNotifyBo) Str() (string, error) {
@ -51,3 +52,14 @@ func (d *WechatVoucherNotifyBo) Str() (string, error) {
return string(b), nil
}
func (c *WechatVoucherNotifyBo) Validate() error {
if err := validator.New().Struct(c); err != nil {
for _, err = range err.(validator.ValidationErrors) {
return err
}
}
return nil
}

View File

@ -69,6 +69,11 @@ func (srv *TripartiteService) QiXingNotify(ctx http.Context) error {
return srv.ResponseErr(ctx, fmt.Sprintf("json unmarshal wxNotifyData error: %v", err))
}
if err = wxNotifyData.Validate(); err != nil {
log.Errorf("qixing notify wxNotifyData validate err ip:%s,error:%v,body:%s", ip, err, string(bodyBytes))
return srv.ResponseErr(ctx, fmt.Sprintf("validate wxNotifyData error: %v", err))
}
err = srv.multiBiz.Notify(ctx, "qixing_"+wxNotifyData.PlainText.StockCreatorMchid, wxNotifyData)
if err != nil {
log.Errorf("qixing notify run err ip:%s,error:%v,body:%s", ip, err, string(bodyBytes))