多笔立减

This commit is contained in:
ziming 2025-08-11 11:27:28 +08:00
parent c873859c1a
commit 4a65fa66c0
4 changed files with 43 additions and 3 deletions

View File

@ -1,12 +1,16 @@
package wechatrepoimpl package wechatrepoimpl
import ( import (
"errors"
"fmt"
"github.com/wechatpay-apiv3/wechatpay-go/core" "github.com/wechatpay-apiv3/wechatpay-go/core"
err2 "voucher/api/err"
"voucher/internal/biz/bo" "voucher/internal/biz/bo"
"voucher/internal/biz/wechatrepo" "voucher/internal/biz/wechatrepo"
"voucher/internal/conf" "voucher/internal/conf"
"voucher/internal/data" "voucher/internal/data"
"voucher/internal/pkg/wechat/srv/marketing" "voucher/internal/pkg/wechat/srv/marketing"
"voucher/internal/pkg/wechat/utils"
) )
type BankMultiActivityImpl struct { type BankMultiActivityImpl struct {
@ -37,6 +41,15 @@ func (w *BankMultiActivityImpl) Order(order *bo.OrderBo) (couponId string, err e
if err != nil { if err != nil {
var e *utils.ApiException
if errors.As(err, &e) {
apiErr, err3 := marketing.BuildErr(e.Body())
if err3 != nil {
return "", fmt.Errorf("ApiException analysis err: %+v", err3)
}
return "", err2.ErrorWechatFAIL("%s-%s", apiErr.Code, apiErr.Message)
}
return "", err return "", err
} }

View File

@ -1,5 +1,7 @@
package marketing package marketing
import "encoding/json"
type SendReq struct { type SendReq struct {
ActivityId *string `json:"activity_id"` ActivityId *string `json:"activity_id"`
StockId *string `json:"stock_id"` StockId *string `json:"stock_id"`
@ -11,3 +13,15 @@ type SendReq struct {
type SendResp struct { type SendResp struct {
CouponId *string `json:"coupon_id"` CouponId *string `json:"coupon_id"`
} }
// Err {"code":"INVALID_REQUEST","message":"对应单号已超出重试期;请查单确认后决定是否换单请求"}
type Err struct {
Code string `json:"code,omitempty"`
Message string `json:"message,omitempty"`
}
func BuildErr(body []byte) (*Err, error) {
ret := &Err{}
err := json.Unmarshal(body, &ret)
return ret, err
}

View File

@ -515,8 +515,8 @@ func (srv *MchConfig) Request2(host, method, path string, reqBody []byte) (respo
httpRequest.Header.Set("Authorization", authorization) httpRequest.Header.Set("Authorization", authorization)
hs, _ := json.Marshal(httpRequest.Header) //hs, _ := json.Marshal(httpRequest.Header)
fmt.Printf("\npath=%s\nreqBody=%s\nheaders=%s\n", path, string(reqBody), string(hs)) //fmt.Printf("\npath=%s\nreqBody=%s\nheaders=%s\n", path, string(reqBody), string(hs))
client := &http.Client{} client := &http.Client{}
httpResponse, err := client.Do(httpRequest) httpResponse, err := client.Do(httpRequest)

View File

@ -1,6 +1,7 @@
package test package test
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@ -57,7 +58,19 @@ func MarketingSend() {
response, err := marketing().Send(openId, request) response, err := marketing().Send(openId, request)
if err != nil { if err != nil {
fmt.Printf("请求失败: %+v\n", err)
var e *utils.ApiException
if errors.As(err, &e) {
apiErr, err3 := marketing2.BuildErr(e.Body())
if err3 != nil {
fmt.Printf("请求失败: %+v\n", err3)
} else {
fmt.Printf("请求失败: %s-%s\n", apiErr.Code, apiErr.Message)
}
}
return return
} }