切换主体

This commit is contained in:
ziming 2026-03-27 14:47:37 +08:00
parent d308d56e79
commit 965474a340
1 changed files with 33 additions and 26 deletions

View File

@ -10,7 +10,8 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"time" "time"
"voucher/internal/biz/do" v1 "voucher/api/v1"
"voucher/internal/biz/vo"
"voucher/internal/conf" "voucher/internal/conf"
"voucher/internal/data" "voucher/internal/data"
) )
@ -169,7 +170,7 @@ func QueryProduct() {
} }
req := cashcoupons.QueryStockRequest{ req := cashcoupons.QueryStockRequest{
StockId: core.String("21923564"), StockId: core.String("21928191"),
StockCreatorMchid: core.String("1100040695"), StockCreatorMchid: core.String("1100040695"),
} }
@ -180,8 +181,8 @@ func QueryProduct() {
return return
} }
j, _ := json.Marshal(resp) originData, _ := json.Marshal(resp)
fmt.Printf("\nresp:%s\n", string(j)) fmt.Printf("\nOriginData:%s\n", string(originData))
availableStock := *resp.StockUseRule.MaxCoupons - *resp.DistributedCoupons availableStock := *resp.StockUseRule.MaxCoupons - *resp.DistributedCoupons
couponAmount := *resp.StockUseRule.FixedNormalCoupon.CouponAmount / 100 couponAmount := *resp.StockUseRule.FixedNormalCoupon.CouponAmount / 100
@ -195,45 +196,51 @@ func QueryProduct() {
fmt.Printf("\n剩余库存:%d", availableStock) fmt.Printf("\n剩余库存:%d", availableStock)
fmt.Printf("\n剩余预算:%d", availableStock*couponAmount) fmt.Printf("\n剩余预算:%d", availableStock*couponAmount)
str, _ := json.Marshal(WxResp(resp)) WxResp(resp)
fmt.Printf("\nWxResp:%+v", string(str))
return return
} }
func WxResp(wxResp *cashcoupons.Stock) (reps *do.WxResp) { func WxResp(wxResp *cashcoupons.Stock) {
availableStock := *wxResp.StockUseRule.MaxCoupons - *wxResp.DistributedCoupons xx := &v1.CmbQueryProductReply{
couponAmount := *wxResp.StockUseRule.FixedNormalCoupon.CouponAmount / 100 RespCode: vo.CmbResponseStatusSuccess.GetValue(),
RespMsg: "成功",
remainingBudget := availableStock * couponAmount ActivityName: *wxResp.StockName,
ActivityId: "CMB" + *wxResp.StockId,
stockUsageRate := float64(*wxResp.DistributedCoupons) / float64(*wxResp.StockUseRule.MaxCoupons) * 100 Amount: "",
MinAmount: "",
req := &do.WxResp{ AvailableType: "",
Amount: couponAmount, AvailableDays: "", // 动态有效期天数
AllBudget: *wxResp.StockUseRule.MaxAmount / 100, StartTime: "",
AllStock: *wxResp.StockUseRule.MaxCoupons, EndTime: "",
UsedStock: *wxResp.DistributedCoupons, AvailableStock: "",
UsedBudget: *wxResp.DistributedCoupons * couponAmount, Detail: *wxResp.Description,
AvailableStock: availableStock,
AvailableBudget: remainingBudget,
StockUsageRate: stockUsageRate,
} }
inputFormat := time.RFC3339 inputFormat := time.RFC3339
if wxResp.AvailableBeginTime != nil { if wxResp.AvailableBeginTime != nil {
availableBeginTime, _ := time.Parse(inputFormat, *wxResp.AvailableBeginTime) 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 { if wxResp.AvailableEndTime != nil {
availableEndTime, _ := time.Parse(inputFormat, *wxResp.AvailableEndTime) 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) { func QueryCallback(bc *conf.Bootstrap) {