From 072c8c9fee519735961c8afb9157ae5826b90d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Wed, 12 Mar 2025 18:22:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/data/mixrepoimpl/cmb.go | 6 +++++- internal/data/model/order.gen.go | 4 ++-- internal/data/repoimpl/order.go | 5 ++--- internal/data/wechatrepoimpl/cpn.go | 19 +++++++------------ internal/data/wechatrepoimpl/cpn_status.go | 10 +++++----- 5 files changed, 21 insertions(+), 23 deletions(-) diff --git a/internal/data/mixrepoimpl/cmb.go b/internal/data/mixrepoimpl/cmb.go index aa5d94c..cb59647 100644 --- a/internal/data/mixrepoimpl/cmb.go +++ b/internal/data/mixrepoimpl/cmb.go @@ -121,6 +121,10 @@ func (s *CmbMixRepoImpl) GetRequest(_ context.Context, reqBo *bo.CmbRequestBo) ( func (s *CmbMixRepoImpl) GetMockRequest(_ context.Context, bizContent string) (*v1.CmbRequest, error) { + if len(s.bc.Cmb.Sm2Puk) == 0 { + return nil, errors.New("mock sm2 puk is empty") + } + if len(s.bc.Cmb.CmbSm2Pik) == 0 { return nil, errors.New("mock cmb sm2 pik is empty") } @@ -238,5 +242,5 @@ func (s *CmbMixRepoImpl) Request(ctx context.Context, req *v1.CmbRequest, uri st } func (s *CmbMixRepoImpl) Decrypt(_ context.Context, encryptBody string) (string, error) { - return cmb.Decrypt(s.bc.Cmb.Sm2Prk, encryptBody) + return cmb.Decrypt(s.bc.Cmb.CmbSm2Pik, encryptBody) } diff --git a/internal/data/model/order.gen.go b/internal/data/model/order.gen.go index 63404f1..2dfd1be 100644 --- a/internal/data/model/order.gen.go +++ b/internal/data/model/order.gen.go @@ -26,8 +26,8 @@ type Order struct { MerchantNo string `gorm:"column:merchant_no;not null;comment:创建批次号的商户号" json:"merchant_no"` // 创建批次号的商户号 NotifyUrl string `gorm:"column:notify_url;not null;comment:回调地址" json:"notify_url"` Channel uint8 `gorm:"column:channel;not null;comment:1:微信 2:支付宝" json:"channel"` // 1:微信 2:支付宝 - Remark string `gorm:"column:remark;not null" json:"remark"` - Attach string `gorm:"column:attach;not null" json:"attach"` + Remark string `gorm:"column:remark;not null;comment:remark" json:"remark"` + Attach string `gorm:"column:attach;not null;comment:attach" json:"attach"` CreateTime *time.Time `gorm:"column:create_time" json:"create_time"` UpdateTime *time.Time `gorm:"column:update_time" json:"update_time"` } diff --git a/internal/data/repoimpl/order.go b/internal/data/repoimpl/order.go index 7d33a88..6161699 100644 --- a/internal/data/repoimpl/order.go +++ b/internal/data/repoimpl/order.go @@ -37,7 +37,7 @@ func (p *OrderRepoImpl) Create(ctx context.Context, req *bo.OrderBo) (*bo.OrderB BatchNo: req.BatchNo, Account: req.Account, AccountType: req.AccountType.GetValue(), - Status: vo.OrderStatusWait.GetValue(), + Status: req.Status.GetValue(), Type: req.Type.GetValue(), AppID: req.AppID, MerchantNo: req.MerchantNo, @@ -172,8 +172,7 @@ func (p *OrderRepoImpl) Fail(ctx context.Context, id uint64, remark string) erro res := p.db.DB(ctx). Where(model.Order{ - ID: id, - Status: vo.OrderStatusIng.GetValue(), + ID: id, }). Updates(model.Order{ Status: vo.OrderStatusFail.GetValue(), diff --git a/internal/data/wechatrepoimpl/cpn.go b/internal/data/wechatrepoimpl/cpn.go index a9be1c9..41a226f 100644 --- a/internal/data/wechatrepoimpl/cpn.go +++ b/internal/data/wechatrepoimpl/cpn.go @@ -35,7 +35,7 @@ func NewCpnRepoImpl(bc *conf.Bootstrap) (wechatrepo.WechatCpnRepo, error) { return &CpnRepoImpl{bc: bc, Server: server}, nil } -func (c *CpnRepoImpl) Order(ctx context.Context, order *bo.OrderBo) (couponId string, err error) { +func (c *CpnRepoImpl) Order(ctx context.Context, order *bo.OrderBo) (string, error) { req := cashcoupons.SendCouponRequest{ OutRequestNo: core.String(order.OrderNo), @@ -48,7 +48,7 @@ func (c *CpnRepoImpl) Order(ctx context.Context, order *bo.OrderBo) (couponId st client, err := data.GetClient(ctx, c.Server) if err != nil { - return + return "", err } svc := cashcoupons.CouponApiService{Client: client} @@ -59,28 +59,23 @@ func (c *CpnRepoImpl) Order(ctx context.Context, order *bo.OrderBo) (couponId st bodyBytes, err := io.ReadAll(result.Response.Body) if err != nil { - return + return "", err } log.Errorf("请求微信返回错误=%s", string(bodyBytes)) if err = json.Unmarshal(bodyBytes, &ErrBody); err != nil { - return + return "", err } - err = fmt.Errorf(ErrBody.Message) - - return + return "", fmt.Errorf(ErrBody.Message) } if result.Response.StatusCode != CodeSuccess { - err = fmt.Errorf("请求错误") - return + return "", fmt.Errorf("请求错误,code:%s", result.Response.Status) } - couponId = *resp.CouponId - - return + return *resp.CouponId, nil } func (c *CpnRepoImpl) Query(ctx context.Context, orderWechat *bo.OrderBo) (vo.OrderStatus, error) { diff --git a/internal/data/wechatrepoimpl/cpn_status.go b/internal/data/wechatrepoimpl/cpn_status.go index 3a08076..16351ee 100644 --- a/internal/data/wechatrepoimpl/cpn_status.go +++ b/internal/data/wechatrepoimpl/cpn_status.go @@ -21,10 +21,10 @@ var CpnStatusTextMap = map[CpnStatus]string{ CpnStatusExpired: "已过期", } -var CpnStatusMap = map[CpnStatus]vo.OrderWechatStatus{ - CpnStatusAvailable: vo.OrderWechatStatusSuccess, - CpnStatusUsed: vo.OrderWechatStatusUse, - CpnStatusExpired: vo.OrderWechatStatusExpired, +var CpnStatusMap = map[CpnStatus]vo.OrderStatus{ + CpnStatusAvailable: vo.OrderStatusSuccess, + CpnStatusUsed: vo.OrderStatusUse, + CpnStatusExpired: vo.OrderStatusExpired, } func (o CpnStatus) GetText() string { @@ -34,7 +34,7 @@ func (o CpnStatus) GetText() string { return "未知" } -func (o CpnStatus) GetStatus() (vo.OrderWechatStatus, error) { +func (o CpnStatus) GetStatus() (vo.OrderStatus, error) { if resultStatus, ok := CpnStatusMap[o]; ok { return resultStatus, nil }