This commit is contained in:
ziming 2025-05-20 17:16:56 +08:00
parent bb5e9ee0e9
commit 07f15ce605
7 changed files with 51 additions and 55 deletions

1
go.mod
View File

@ -74,6 +74,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/sirupsen/logrus v1.4.0 // indirect github.com/sirupsen/logrus v1.4.0 // indirect
github.com/stretchr/testify v1.10.0 // indirect
github.com/tidwall/gjson v1.13.0 // indirect github.com/tidwall/gjson v1.13.0 // indirect
github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect github.com/tidwall/pretty v1.2.0 // indirect

8
go.sum
View File

@ -133,7 +133,6 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
@ -235,8 +234,9 @@ github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
@ -245,8 +245,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tidwall/gjson v1.13.0 h1:3TFY9yxOQShrvmjdM76K+jc66zJeT6D3/VFFYCGQf7M= github.com/tidwall/gjson v1.13.0 h1:3TFY9yxOQShrvmjdM76K+jc66zJeT6D3/VFFYCGQf7M=
github.com/tidwall/gjson v1.13.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/gjson v1.13.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=

View File

@ -27,6 +27,8 @@ type OrderBo struct {
LastUseTime *time.Time LastUseTime *time.Time
CreateTime *time.Time CreateTime *time.Time
UpdateTime *time.Time UpdateTime *time.Time
MiniMum int32
} }
type OrderCreateReqBo struct { type OrderCreateReqBo struct {

View File

@ -13,6 +13,7 @@ type ProductBo struct {
BatchName string BatchName string
BatchNo string BatchNo string
MchId string MchId string
MiniMum int32
Channel vo.Channel Channel vo.Channel
AvailableType vo.AvailableType AvailableType vo.AvailableType
AvailableDays uint32 AvailableDays uint32

View File

@ -27,9 +27,9 @@ func (v *VoucherBiz) CmbOrder(ctx context.Context, request *v1.CmbRequest) (*v1.
return nil, err return nil, err
} }
// 通知kg if err = v.bbToWx(ctx, order, reply); err != nil {
b, _ := json.Marshal(reply) log.Errorf("处理请求kg报错:%s", err.Error())
_ = v.bbToWx(ctx, order, string(b)) }
return reply, nil return reply, nil
} }
@ -41,8 +41,6 @@ func (c *VoucherBiz) cmbOrder(ctx context.Context, request *v1.CmbRequest) (*bo.
return nil, err return nil, err
} }
ctx2 := context.Background()
boReq := &bo.OrderCreateReqBo{ boReq := &bo.OrderCreateReqBo{
OutBizNo: bizContent.TransactionId, OutBizNo: bizContent.TransactionId,
ProductNo: bizContent.ActivityId, ProductNo: bizContent.ActivityId,
@ -54,7 +52,7 @@ func (c *VoucherBiz) cmbOrder(ctx context.Context, request *v1.CmbRequest) (*bo.
NotifyUrl: c.bc.Cmb.NotifyUrl, NotifyUrl: c.bc.Cmb.NotifyUrl,
} }
order, err := c.Order(ctx2, boReq, bizContent) order, err := c.Order(ctx, boReq, bizContent)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -77,6 +75,7 @@ func (v *VoucherBiz) Order(ctx context.Context, req *bo.OrderCreateReqBo, cmbReq
if order != nil { if order != nil {
order.MiniMum = product.MiniMum
if order.Status.IsFail() { if order.Status.IsFail() {
if err4 := v.orderRetry(ctx, order); err4 != nil { if err4 := v.orderRetry(ctx, order); err4 != nil {
@ -89,9 +88,10 @@ func (v *VoucherBiz) Order(ctx context.Context, req *bo.OrderCreateReqBo, cmbReq
order, err = v.order(ctx, req, product, cmbReq) order, err = v.order(ctx, req, product, cmbReq)
if err != nil { if err != nil {
return order, err return nil, err
} }
order.MiniMum = product.MiniMum
return order, nil return order, nil
} }
@ -102,24 +102,20 @@ func (v *VoucherBiz) order(ctx context.Context, req *bo.OrderCreateReqBo, produc
return nil, err return nil, err
} }
// 通知kx
_ = v.cmbToBB(ctx, cmbReq) _ = v.cmbToBB(ctx, cmbReq)
// 注册通知标签 order.MerchantNo 批次创建商户, order.BatchNo 商品批次号
if err = v.registerNotifyTag(ctx, order.MerchantNo, order.BatchNo); err != nil { if err = v.registerNotifyTag(ctx, order.MerchantNo, order.BatchNo); err != nil {
return nil, err return nil, err
} }
// 真实发放 voucherNo, err := v.WechatCpnRepo.Order(ctx, order)
//voucherNo, err := v.WechatCpnRepo.Order(ctx, order) if err != nil {
//if err != nil { if err3 := v.fail(ctx, order, err); err3 != nil {
// if err3 := v.fail(ctx, order, err); err3 != nil { return nil, err3
// return nil, err3 }
// } return nil, err
// return nil, err }
//}
voucherNo := order.OrderNo // mock成功
if err = v.success(ctx, order, voucherNo); err != nil { if err = v.success(ctx, order, voucherNo); err != nil {
return order, err return order, err
} }
@ -234,7 +230,12 @@ func (v *VoucherBiz) cmbToBB(ctx context.Context, cmbReq *v1.CmbOrderRequest) er
return v.KxMixRepo.Request(ctx, req.GetNotice()) return v.KxMixRepo.Request(ctx, req.GetNotice())
} }
func (v *VoucherBiz) bbToWx(ctx context.Context, order *bo.OrderBo, cmbRes string) error { func (v *VoucherBiz) bbToWx(ctx context.Context, order *bo.OrderBo, cmbReply *v1.CmbReply) error {
b, err := json.Marshal(cmbReply)
if err != nil {
return err
}
wxRes, err := json.Marshal(map[string]string{"coupon_id": order.VoucherNo}) wxRes, err := json.Marshal(map[string]string{"coupon_id": order.VoucherNo})
if err != nil { if err != nil {
@ -247,10 +248,10 @@ func (v *VoucherBiz) bbToWx(ctx context.Context, order *bo.OrderBo, cmbRes strin
AppId: order.AppID, AppId: order.AppID,
StockCreatorMhId: order.MerchantNo, StockCreatorMhId: order.MerchantNo,
CouponValue: 0, CouponValue: 0,
CouponMinimum: 0, CouponMinimum: order.MiniMum,
CouponId: order.VoucherNo, CouponId: order.VoucherNo,
WxRes: string(wxRes), WxRes: string(wxRes),
CmbRes: cmbRes, CmbRes: string(b),
TransactionId: order.OutBizNo, TransactionId: order.OutBizNo,
} }

View File

@ -3,9 +3,12 @@ package mixrepoimpl
import ( import (
"context" "context"
"github.com/go-kratos/kratos/v2/log" "github.com/go-kratos/kratos/v2/log"
"net/http"
"time"
"voucher/internal/biz/kog" "voucher/internal/biz/kog"
"voucher/internal/biz/mixrepos" "voucher/internal/biz/mixrepos"
"voucher/internal/conf" "voucher/internal/conf"
"voucher/internal/pkg/request"
) )
// KxMixRepoImpl kog 空港 // KxMixRepoImpl kog 空港
@ -21,35 +24,22 @@ func (s *KxMixRepoImpl) Request(ctx context.Context, req *kog.Notice) error {
body, err := req.Marshal() body, err := req.Marshal()
if err != nil { if err != nil {
log.Errorf("请求kx Marshal 报错:%s", err.Error())
return err return err
} }
log.Warnf("请求kx,reqBody:%s", string(body)) h := http.Header{
"Content-Type": []string{"application/json"},
}
//h := http.Header{ url := s.bc.Cmb.KxNoticeUrl
// "Content-Type": []string{"application/json"},
//}
//url := s.bc.Cmb.KxNoticeUrl
//
//_, bodyBytes, err := request.Post(ctx, url, body, request.WithHeaders(h), request.WithTimeout(time.Second*20))
//if err != nil {
// log.Errorf("请求kx报错,url:%s,body:%s,err:%v", url, string(body), err)
// return err
//}
//
//log.Warnf("请求kx,url:%s,reqBody:%s,respBody:%s", url, string(body), string(bodyBytes))
//var response *v1.CmbReply _, bodyBytes, err := request.Post(ctx, url, body, request.WithHeaders(h), request.WithTimeout(time.Second*20))
//if err = json.Unmarshal(bodyBytes, &response); err != nil { if err != nil {
// log.Errorf("请求kx返回数据解析报错:%s,url:%s,reqBody:%s,respBody:%s", err.Error(), url, string(bodyBytes)) log.Errorf("请求kx报错,url:%s,body:%s,err:%v", url, string(body), err)
// return err return nil
//} }
//
//if response.RespCode != vo.CmbResponseStatusSuccess.GetValue() { log.Warnf("请求kx,url:%s,reqBody:%s,respBody:%s", url, string(body), string(bodyBytes))
// log.Errorf("请求kx返回报错:msg:%s,url:%s,respBody:%s", response.RespMsg, url, string(bodyBytes))
// return fmt.Errorf(response.RespMsg)
//}
return nil return nil
} }

View File

@ -13,12 +13,13 @@ const TableNameProduct = "product"
// Product mapped from table <product> // Product mapped from table <product>
type Product struct { type Product struct {
ID int32 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"` ID int32 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
Name string `gorm:"column:name;not null;comment:商品名称" json:"name"` // 商品名称 Name string `gorm:"column:name;not null;comment:商品名称" json:"name"` // 商品名称
ProductNo string `gorm:"column:product_no;not null;comment:商品编号" json:"product_no"` // 商品编号 ProductNo string `gorm:"column:product_no;not null;comment:商品编号" json:"product_no"` // 商品编号
BatchName string `gorm:"column:batch_name;not null;comment:批次名称" json:"batch_name"` // 批次名称 BatchName string `gorm:"column:batch_name;not null;comment:批次名称" json:"batch_name"` // 批次名称
BatchNo string `gorm:"column:batch_no;not null;comment:立减金批次号" json:"batch_no"` // 立减金批次号 BatchNo string `gorm:"column:batch_no;not null;comment:立减金批次号" json:"batch_no"` // 立减金批次号
MchId string `gorm:"column:mch_id;not null;comment:商户号,创建批次的商户号" json:"mch_id"` // 商户号,创建批次的商户号 MchId string `gorm:"column:mch_id;not null;comment:商户号,创建批次的商户号" json:"mch_id"` // 商户号,创建批次的商户号
Channel uint8 `gorm:"column:channel;not null;comment:1:微信 2:支付宝" json:"channel"` // 1:微信 2:支付宝 MiniMum int32 `gorm:"column:mini_mum;not null;comment:面额发券批次门槛,单位:分" json:"mini_mum"` // 面额发券批次门槛,单位:分
Channel uint8 `gorm:"column:channel;not null;comment:1:微信 2:支付宝" json:"channel"` // 1:微信 2:支付宝
AvailableType uint8 `gorm:"column:available_type;not null;comment:1:固定有效期 2:动态有效期" json:"available_type"` AvailableType uint8 `gorm:"column:available_type;not null;comment:1:固定有效期 2:动态有效期" json:"available_type"`
AvailableDays uint32 `gorm:"column:available_days;not null;comment:领取后多少天内" json:"available_days"` AvailableDays uint32 `gorm:"column:available_days;not null;comment:领取后多少天内" json:"available_days"`
CreateTime *time.Time `gorm:"column:create_time;not null" json:"create_time"` CreateTime *time.Time `gorm:"column:create_time;not null" json:"create_time"`