完善购买和套餐功能
This commit is contained in:
@@ -151,6 +151,37 @@ func NormalizeModuleCode(code string) string {
|
||||
return strings.ToLower(strings.TrimSpace(code))
|
||||
}
|
||||
|
||||
// DayStart 取时间所在自然日的 0 点(有效期按「日」计算,不精确到秒)
|
||||
func DayStart(t time.Time) time.Time {
|
||||
return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
|
||||
}
|
||||
|
||||
// ProductOrderExpireAt 单品订单有效期截止时间(精确到日):
|
||||
// - 优先取落库的 expire_time(按日规范化到当天 0 点);
|
||||
// - 历史订单未落库时按「开通日 0 点 + 默认有效期(1 年)」兜底计算,保证老订单同样按 1 年到期;
|
||||
// - 两者都无(尚未开通)返回 nil,视为无到期时间。
|
||||
func ProductOrderExpireAt(order *models.PlatformProductOrder) *time.Time {
|
||||
if order == nil {
|
||||
return nil
|
||||
}
|
||||
if order.ExpireTime != nil {
|
||||
t := DayStart(*order.ExpireTime)
|
||||
return &t
|
||||
}
|
||||
if order.ActivateTime != nil {
|
||||
t := DayStart(*order.ActivateTime).AddDate(0, 0, models.ProductOrderDurationDays)
|
||||
return &t
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProductOrderExpired 单品订单是否已过有效期:
|
||||
// 到期日当天 0 点起即视为过期(到期后权益自动失效,需重新购买续费)。
|
||||
func ProductOrderExpired(order *models.PlatformProductOrder, now time.Time) bool {
|
||||
expire := ProductOrderExpireAt(order)
|
||||
return expire != nil && !now.Before(*expire)
|
||||
}
|
||||
|
||||
// GetTenantModuleCodes 获取租户已开通的功能模块编码集合(如 erp / oa / crm)。
|
||||
//
|
||||
// 权益由两部分组成:
|
||||
@@ -189,8 +220,21 @@ func GetTenantModuleCodes(tid uint64) map[string]bool {
|
||||
return codes
|
||||
}
|
||||
|
||||
productIDs := make([]uint64, 0, len(orders))
|
||||
// 只统计仍在有效期内的订单:到期后权益自动失效,需重新购买续费
|
||||
now := time.Now()
|
||||
validOrders := make([]models.PlatformProductOrder, 0, len(orders))
|
||||
for _, order := range orders {
|
||||
if ProductOrderExpired(&order, now) {
|
||||
continue
|
||||
}
|
||||
validOrders = append(validOrders, order)
|
||||
}
|
||||
if len(validOrders) == 0 {
|
||||
return codes
|
||||
}
|
||||
|
||||
productIDs := make([]uint64, 0, len(validOrders))
|
||||
for _, order := range validOrders {
|
||||
productIDs = append(productIDs, order.ProductID)
|
||||
}
|
||||
var products []models.PlatformProduct
|
||||
|
||||
Reference in New Issue
Block a user