This commit is contained in:
ziming 2025-07-01 18:21:36 +08:00
parent e9c1c63a69
commit 144341501d
2 changed files with 31 additions and 10 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"github.com/go-kratos/kratos/v2/log" "github.com/go-kratos/kratos/v2/log"
"github.com/wechatpay-apiv3/wechatpay-go/services/cashcoupons" "github.com/wechatpay-apiv3/wechatpay-go/services/cashcoupons"
"strconv"
"strings" "strings"
"time" "time"
"voucher/internal/biz/bo" "voucher/internal/biz/bo"
@ -151,9 +152,26 @@ func (this *VoucherBiz) WarningSend(ctx context.Context, product *bo.ProductBo,
return err return err
} }
buildTemplateParams(product, w)
return nil return nil
} }
func buildTemplateParams(product *bo.ProductBo, req *do.WxResp) map[string]string {
return map[string]string{
"stock_name": product.BatchName,
"stock_no": product.ProductNo,
"amount": strconv.Itoa(int(req.Amount)),
"all_budget": strconv.Itoa(int(req.AllBudget)),
"all_stock": strconv.Itoa(int(req.AllStock)),
"used_stock": strconv.Itoa(int(req.UsedStock)),
"used_budget": strconv.Itoa(int(req.UsedBudget)),
"available_budget": strconv.Itoa(int(req.AvailableBudget)),
"available_stock": strconv.Itoa(int(req.AvailableStock)),
"budget_usage_rate": fmt.Sprintf("%.1f", req.StockUsageRate),
}
}
func formatAsCard(product *bo.ProductBo, req *do.WxResp) string { func formatAsCard(product *bo.ProductBo, req *do.WxResp) string {
var card strings.Builder var card strings.Builder

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"strconv" "strconv"
"testing" "testing"
"voucher/internal/biz/bo"
"voucher/internal/biz/do" "voucher/internal/biz/do"
) )
@ -43,20 +44,22 @@ func TestSendSMS(t *testing.T) {
} }
func TestWarningSend(t *testing.T) { func TestWarningSend(t *testing.T) {
req := do.WarningBudget{ req := &do.WxResp{
StockName: "招行2元立减金",
StockId: "20627186",
StockNo: "CMB20627186",
Amount: 2, Amount: 2,
AllBudget: 70010, AllBudget: 70010,
AllStock: 35005, AllStock: 35005,
UsedStock: 9390, UsedStock: 9390,
UsedBudget: 18780, UsedBudget: 18780,
AvailableStock: 25615, AvailableStock: 25615,
RemainingBudget: 51230, AvailableBudget: 51230,
StockUsageRate: 20, StockUsageRate: 20,
} }
params := buildTemplateParams(&req)
product := &bo.ProductBo{
ProductNo: "CMB20627186",
BatchName: "招行2元立减金",
}
params := buildTemplateParams(product, req)
js, _ := json.Marshal(params) js, _ := json.Marshal(params)
@ -75,16 +78,16 @@ func TestWarningSend(t *testing.T) {
} }
} }
func buildTemplateParams(req *do.WarningBudget) map[string]string { func buildTemplateParams(product *bo.ProductBo, req *do.WxResp) map[string]string {
return map[string]string{ return map[string]string{
"stock_name": req.StockName, "stock_name": product.BatchName,
"stock_no": req.StockNo, "stock_no": product.ProductNo,
"amount": strconv.Itoa(int(req.Amount)), "amount": strconv.Itoa(int(req.Amount)),
"all_budget": strconv.Itoa(int(req.AllBudget)), "all_budget": strconv.Itoa(int(req.AllBudget)),
"all_stock": strconv.Itoa(int(req.AllStock)), "all_stock": strconv.Itoa(int(req.AllStock)),
"used_stock": strconv.Itoa(int(req.UsedStock)), "used_stock": strconv.Itoa(int(req.UsedStock)),
"used_budget": strconv.Itoa(int(req.UsedBudget)), "used_budget": strconv.Itoa(int(req.UsedBudget)),
"available_budget": strconv.Itoa(int(req.RemainingBudget)), "available_budget": strconv.Itoa(int(req.AvailableBudget)),
"available_stock": strconv.Itoa(int(req.AvailableStock)), "available_stock": strconv.Itoa(int(req.AvailableStock)),
"budget_usage_rate": fmt.Sprintf("%.1f", req.StockUsageRate), "budget_usage_rate": fmt.Sprintf("%.1f", req.StockUsageRate),
} }