接口调整

This commit is contained in:
李子铭 2025-03-12 18:22:47 +08:00
parent 98c3374bfb
commit 072c8c9fee
5 changed files with 21 additions and 23 deletions

View File

@ -121,6 +121,10 @@ func (s *CmbMixRepoImpl) GetRequest(_ context.Context, reqBo *bo.CmbRequestBo) (
func (s *CmbMixRepoImpl) GetMockRequest(_ context.Context, bizContent string) (*v1.CmbRequest, error) { 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 { if len(s.bc.Cmb.CmbSm2Pik) == 0 {
return nil, errors.New("mock cmb sm2 pik is empty") 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) { 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)
} }

View File

@ -26,8 +26,8 @@ type Order struct {
MerchantNo string `gorm:"column:merchant_no;not null;comment:创建批次号的商户号" json:"merchant_no"` // 创建批次号的商户号 MerchantNo string `gorm:"column:merchant_no;not null;comment:创建批次号的商户号" json:"merchant_no"` // 创建批次号的商户号
NotifyUrl string `gorm:"column:notify_url;not null;comment:回调地址" json:"notify_url"` 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:支付宝 Channel uint8 `gorm:"column:channel;not null;comment:1:微信 2:支付宝" json:"channel"` // 1:微信 2:支付宝
Remark string `gorm:"column:remark;not null" json:"remark"` Remark string `gorm:"column:remark;not null;comment:remark" json:"remark"`
Attach string `gorm:"column:attach;not null" json:"attach"` Attach string `gorm:"column:attach;not null;comment:attach" json:"attach"`
CreateTime *time.Time `gorm:"column:create_time" json:"create_time"` CreateTime *time.Time `gorm:"column:create_time" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time" json:"update_time"` UpdateTime *time.Time `gorm:"column:update_time" json:"update_time"`
} }

View File

@ -37,7 +37,7 @@ func (p *OrderRepoImpl) Create(ctx context.Context, req *bo.OrderBo) (*bo.OrderB
BatchNo: req.BatchNo, BatchNo: req.BatchNo,
Account: req.Account, Account: req.Account,
AccountType: req.AccountType.GetValue(), AccountType: req.AccountType.GetValue(),
Status: vo.OrderStatusWait.GetValue(), Status: req.Status.GetValue(),
Type: req.Type.GetValue(), Type: req.Type.GetValue(),
AppID: req.AppID, AppID: req.AppID,
MerchantNo: req.MerchantNo, MerchantNo: req.MerchantNo,
@ -173,7 +173,6 @@ func (p *OrderRepoImpl) Fail(ctx context.Context, id uint64, remark string) erro
res := p.db.DB(ctx). res := p.db.DB(ctx).
Where(model.Order{ Where(model.Order{
ID: id, ID: id,
Status: vo.OrderStatusIng.GetValue(),
}). }).
Updates(model.Order{ Updates(model.Order{
Status: vo.OrderStatusFail.GetValue(), Status: vo.OrderStatusFail.GetValue(),

View File

@ -35,7 +35,7 @@ func NewCpnRepoImpl(bc *conf.Bootstrap) (wechatrepo.WechatCpnRepo, error) {
return &CpnRepoImpl{bc: bc, Server: server}, nil 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{ req := cashcoupons.SendCouponRequest{
OutRequestNo: core.String(order.OrderNo), 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) client, err := data.GetClient(ctx, c.Server)
if err != nil { if err != nil {
return return "", err
} }
svc := cashcoupons.CouponApiService{Client: client} 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) bodyBytes, err := io.ReadAll(result.Response.Body)
if err != nil { if err != nil {
return return "", err
} }
log.Errorf("请求微信返回错误=%s", string(bodyBytes)) log.Errorf("请求微信返回错误=%s", string(bodyBytes))
if err = json.Unmarshal(bodyBytes, &ErrBody); err != nil { if err = json.Unmarshal(bodyBytes, &ErrBody); err != nil {
return return "", err
} }
err = fmt.Errorf(ErrBody.Message) return "", fmt.Errorf(ErrBody.Message)
return
} }
if result.Response.StatusCode != CodeSuccess { if result.Response.StatusCode != CodeSuccess {
err = fmt.Errorf("请求错误") return "", fmt.Errorf("请求错误,code:%s", result.Response.Status)
return
} }
couponId = *resp.CouponId return *resp.CouponId, nil
return
} }
func (c *CpnRepoImpl) Query(ctx context.Context, orderWechat *bo.OrderBo) (vo.OrderStatus, error) { func (c *CpnRepoImpl) Query(ctx context.Context, orderWechat *bo.OrderBo) (vo.OrderStatus, error) {

View File

@ -21,10 +21,10 @@ var CpnStatusTextMap = map[CpnStatus]string{
CpnStatusExpired: "已过期", CpnStatusExpired: "已过期",
} }
var CpnStatusMap = map[CpnStatus]vo.OrderWechatStatus{ var CpnStatusMap = map[CpnStatus]vo.OrderStatus{
CpnStatusAvailable: vo.OrderWechatStatusSuccess, CpnStatusAvailable: vo.OrderStatusSuccess,
CpnStatusUsed: vo.OrderWechatStatusUse, CpnStatusUsed: vo.OrderStatusUse,
CpnStatusExpired: vo.OrderWechatStatusExpired, CpnStatusExpired: vo.OrderStatusExpired,
} }
func (o CpnStatus) GetText() string { func (o CpnStatus) GetText() string {
@ -34,7 +34,7 @@ func (o CpnStatus) GetText() string {
return "未知" return "未知"
} }
func (o CpnStatus) GetStatus() (vo.OrderWechatStatus, error) { func (o CpnStatus) GetStatus() (vo.OrderStatus, error) {
if resultStatus, ok := CpnStatusMap[o]; ok { if resultStatus, ok := CpnStatusMap[o]; ok {
return resultStatus, nil return resultStatus, nil
} }