预警3
This commit is contained in:
parent
31fb6e77da
commit
b7c52ce699
|
|
@ -16,6 +16,7 @@ type ProductBo struct {
|
|||
Channel vo.Channel
|
||||
AvailableType vo.AvailableType
|
||||
AvailableDays uint32
|
||||
Amount int64
|
||||
WarningBudget int64
|
||||
StartTime *time.Time
|
||||
EndTime *time.Time
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package do
|
||||
|
||||
import "time"
|
||||
|
||||
type WxResp struct {
|
||||
Amount int64 // 券面额
|
||||
AllBudget int64 // 总预算
|
||||
AllStock int64 // 总库存
|
||||
UsedStock int64 // 已使用库存
|
||||
UsedBudget int64 // 已使用预算
|
||||
AvailableStock int64 // 可用库存
|
||||
RemainingBudget int64 // 剩余预算
|
||||
StartTime *time.Time
|
||||
EndTime *time.Time
|
||||
}
|
||||
|
||||
type WarningPerson struct {
|
||||
Mobile string `json:"mobile"`
|
||||
Name string `json:"name"`
|
||||
Tag string `json:"tag"`
|
||||
}
|
||||
|
|
@ -14,9 +14,6 @@ type WarningBudget struct {
|
|||
AvailableStock int64 // 可用库存
|
||||
RemainingBudget int64 // 剩余预算
|
||||
StockUsageRate float64 // 券使用率
|
||||
|
||||
StartTime *time.Time
|
||||
EndTime *time.Time
|
||||
}
|
||||
|
||||
type WarningBudgetLog struct {
|
||||
|
|
@ -24,13 +21,3 @@ type WarningBudgetLog struct {
|
|||
Num int
|
||||
LastTime time.Time
|
||||
}
|
||||
|
||||
type WarningPerson struct {
|
||||
Mobile string `json:"mobile"`
|
||||
Name string `json:"name"`
|
||||
Tag string `json:"tag"`
|
||||
}
|
||||
|
||||
type WarningSend struct {
|
||||
title, text string
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@ package biz
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/services/cashcoupons"
|
||||
"time"
|
||||
v1 "voucher/api/v1"
|
||||
"voucher/internal/biz/do"
|
||||
"voucher/internal/biz/vo"
|
||||
"voucher/internal/pkg/lock"
|
||||
)
|
||||
|
|
@ -78,3 +80,35 @@ func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (rep
|
|||
|
||||
return
|
||||
}
|
||||
|
||||
func (v *VoucherBiz) WxResp(wxResp *cashcoupons.Stock) (reps *do.WxResp) {
|
||||
|
||||
availableStock := *wxResp.StockUseRule.MaxCoupons - *wxResp.DistributedCoupons
|
||||
couponAmount := *wxResp.StockUseRule.FixedNormalCoupon.CouponAmount / 100
|
||||
|
||||
remainingBudget := availableStock * couponAmount
|
||||
|
||||
req := &do.WxResp{
|
||||
Amount: couponAmount,
|
||||
AllBudget: *wxResp.StockUseRule.MaxAmount / 100,
|
||||
AllStock: *wxResp.StockUseRule.MaxCoupons,
|
||||
UsedStock: *wxResp.DistributedCoupons,
|
||||
UsedBudget: *wxResp.DistributedCoupons * couponAmount,
|
||||
AvailableStock: availableStock,
|
||||
RemainingBudget: remainingBudget,
|
||||
}
|
||||
|
||||
inputFormat := time.RFC3339
|
||||
|
||||
if wxResp.AvailableBeginTime != nil {
|
||||
availableBeginTime, _ := time.Parse(inputFormat, *wxResp.AvailableBeginTime)
|
||||
req.StartTime = &availableBeginTime
|
||||
}
|
||||
|
||||
if wxResp.AvailableEndTime != nil {
|
||||
availableEndTime, _ := time.Parse(inputFormat, *wxResp.AvailableEndTime)
|
||||
req.EndTime = &availableEndTime
|
||||
}
|
||||
|
||||
return req
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,10 +22,7 @@ func (this *VoucherBiz) RegisterTag(ctx context.Context, batchNo string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
req, err := this.GetWarningBudget(stock, wxResp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req := this.WxResp(wxResp)
|
||||
|
||||
err = this.ProductRepo.UpdateWarningBudget(ctx, stock.ID, req)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -10,5 +10,5 @@ type ProductRepo interface {
|
|||
FindWarningBudget(ctx context.Context, fun func(ctx context.Context, rows []*bo.ProductBo) error) error
|
||||
GetByBatchNo(ctx context.Context, batchNo string) (*bo.ProductBo, error)
|
||||
GetByProductNo(ctx context.Context, productNo string) (*bo.ProductBo, error)
|
||||
UpdateWarningBudget(ctx context.Context, id int32, req *do.WarningBudget) error
|
||||
UpdateWarningBudget(ctx context.Context, id int32, req *do.WxResp) error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,18 +161,6 @@ func (v *VoucherBiz) GetWarningBudget(product *bo.ProductBo, wxResp *cashcoupons
|
|||
StockUsageRate: stockUsageRate,
|
||||
}
|
||||
|
||||
inputFormat := time.RFC3339
|
||||
|
||||
if wxResp.AvailableBeginTime != nil {
|
||||
availableBeginTime, _ := time.Parse(inputFormat, *wxResp.AvailableBeginTime)
|
||||
req.StartTime = &availableBeginTime
|
||||
}
|
||||
|
||||
if wxResp.AvailableEndTime != nil {
|
||||
availableEndTime, _ := time.Parse(inputFormat, *wxResp.AvailableEndTime)
|
||||
req.EndTime = &availableEndTime
|
||||
}
|
||||
|
||||
return req, nil
|
||||
}
|
||||
|
||||
|
|
@ -183,7 +171,7 @@ func (v *VoucherBiz) Calculate(ctx context.Context, product *bo.ProductBo, wxRes
|
|||
return err
|
||||
}
|
||||
|
||||
err = v.ProductRepo.UpdateWarningBudget(ctx, product.ID, req)
|
||||
err = v.ProductRepo.UpdateWarningBudget(ctx, product.ID, v.WxResp(wxResp))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ type Product struct {
|
|||
Channel uint8 `gorm:"column:channel;not null;comment:1:微信 2:支付宝" json:"channel"` // 1:微信 2:支付宝
|
||||
AvailableType uint8 `gorm:"column:available_type;not null;comment:1:固定有效期 2:动态有效期" json:"available_type"`
|
||||
AvailableDays uint32 `gorm:"column:available_days;not null;comment:领取后多少天内" json:"available_days"`
|
||||
Amount int64 `gorm:"column:amount;not null;default:0" json:"amount"`
|
||||
AllBudget int64 `gorm:"column:all_budget;not null;default:0" json:"all_budget"`
|
||||
RemainingBudget int64 `gorm:"column:remaining_budget;not null;default:0" json:"remaining_budget"`
|
||||
WarningBudget int64 `gorm:"column:warning_budget;not null;default:0" json:"warning_budget"` // 预警预算=0不做预警
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ func (r *ProductRepoImpl) FindWarningBudget(ctx context.Context, fun func(ctx co
|
|||
return nil
|
||||
}
|
||||
|
||||
func (r *ProductRepoImpl) UpdateWarningBudget(ctx context.Context, id int32, req *do.WarningBudget) error {
|
||||
func (r *ProductRepoImpl) UpdateWarningBudget(ctx context.Context, id int32, req *do.WxResp) error {
|
||||
|
||||
now := time.Now()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue