切换主体

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"
"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) {