From 965474a340b4ac0e501f2a8736b9895e5cffec76 Mon Sep 17 00:00:00 2001 From: ziming Date: Fri, 27 Mar 2026 14:47:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=87=E6=8D=A2=E4=B8=BB=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/coupon.go | 59 ++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/test/coupon.go b/test/coupon.go index 8cccda8..b930d62 100644 --- a/test/coupon.go +++ b/test/coupon.go @@ -10,7 +10,8 @@ import ( "os" "path/filepath" "time" - "voucher/internal/biz/do" + v1 "voucher/api/v1" + "voucher/internal/biz/vo" "voucher/internal/conf" "voucher/internal/data" ) @@ -169,7 +170,7 @@ func QueryProduct() { } req := cashcoupons.QueryStockRequest{ - StockId: core.String("21923564"), + StockId: core.String("21928191"), StockCreatorMchid: core.String("1100040695"), } @@ -180,8 +181,8 @@ func QueryProduct() { return } - j, _ := json.Marshal(resp) - fmt.Printf("\nresp:%s\n", string(j)) + originData, _ := json.Marshal(resp) + fmt.Printf("\nOriginData:%s\n", string(originData)) availableStock := *resp.StockUseRule.MaxCoupons - *resp.DistributedCoupons couponAmount := *resp.StockUseRule.FixedNormalCoupon.CouponAmount / 100 @@ -195,45 +196,51 @@ func QueryProduct() { fmt.Printf("\n剩余库存:%d", availableStock) fmt.Printf("\n剩余预算:%d", availableStock*couponAmount) - str, _ := json.Marshal(WxResp(resp)) - fmt.Printf("\nWxResp:%+v", string(str)) + WxResp(resp) return } -func WxResp(wxResp *cashcoupons.Stock) (reps *do.WxResp) { +func WxResp(wxResp *cashcoupons.Stock) { - availableStock := *wxResp.StockUseRule.MaxCoupons - *wxResp.DistributedCoupons - couponAmount := *wxResp.StockUseRule.FixedNormalCoupon.CouponAmount / 100 - - remainingBudget := availableStock * couponAmount - - stockUsageRate := float64(*wxResp.DistributedCoupons) / float64(*wxResp.StockUseRule.MaxCoupons) * 100 - - req := &do.WxResp{ - Amount: couponAmount, - AllBudget: *wxResp.StockUseRule.MaxAmount / 100, - AllStock: *wxResp.StockUseRule.MaxCoupons, - UsedStock: *wxResp.DistributedCoupons, - UsedBudget: *wxResp.DistributedCoupons * couponAmount, - AvailableStock: availableStock, - AvailableBudget: remainingBudget, - StockUsageRate: stockUsageRate, + xx := &v1.CmbQueryProductReply{ + RespCode: vo.CmbResponseStatusSuccess.GetValue(), + RespMsg: "成功", + ActivityName: *wxResp.StockName, + ActivityId: "CMB" + *wxResp.StockId, + Amount: "", + MinAmount: "", + AvailableType: "", + AvailableDays: "", // 动态有效期天数 + StartTime: "", + EndTime: "", + AvailableStock: "", + Detail: *wxResp.Description, } inputFormat := time.RFC3339 if wxResp.AvailableBeginTime != nil { + availableBeginTime, _ := time.Parse(inputFormat, *wxResp.AvailableBeginTime) - req.StartTime = &availableBeginTime + xx.StartTime = availableBeginTime.Format("2006-01-02 15:04:05.000") + xx.SaleStartTime = xx.StartTime } if wxResp.AvailableEndTime != nil { availableEndTime, _ := time.Parse(inputFormat, *wxResp.AvailableEndTime) - req.EndTime = &availableEndTime + xx.EndTime = availableEndTime.Format("2006-01-02 15:04:05.000") + xx.SaleEndTime = xx.EndTime } - return req + xx.Amount = fmt.Sprintf("%d", *wxResp.StockUseRule.FixedNormalCoupon.CouponAmount) + xx.MinAmount = fmt.Sprintf("%d", *wxResp.StockUseRule.FixedNormalCoupon.TransactionMinimum) + + availableStock := *wxResp.StockUseRule.MaxCoupons - *wxResp.DistributedCoupons + xx.AvailableStock = fmt.Sprintf("%d", availableStock) + + cmbData, _ := json.Marshal(xx) + fmt.Printf("\nCMB[%s]", string(cmbData)) } func QueryCallback(bc *conf.Bootstrap) {