重构优化套餐数据结构,修复提取计数问题
This commit is contained in:
@@ -60,10 +60,10 @@ func ListResourceShort(c *fiber.Ctx) error {
|
||||
do.Where(q.Resource.CreatedAt.Lte(*req.CreateBefore))
|
||||
}
|
||||
if req.ExpireAfter != nil {
|
||||
do.Where(q.ResourceShort.As(q.Resource.Short.Name()).Expire.Gte(*req.ExpireAfter))
|
||||
do.Where(q.ResourceShort.As(q.Resource.Short.Name()).ExpireAt.Gte(*req.ExpireAfter))
|
||||
}
|
||||
if req.ExpireBefore != nil {
|
||||
do.Where(q.ResourceShort.As(q.Resource.Short.Name()).Expire.Lte(*req.ExpireBefore))
|
||||
do.Where(q.ResourceShort.As(q.Resource.Short.Name()).ExpireAt.Lte(*req.ExpireBefore))
|
||||
}
|
||||
|
||||
resource, err := q.Resource.Where(do).
|
||||
@@ -141,10 +141,10 @@ func ListResourceLong(c *fiber.Ctx) error {
|
||||
do.Where(q.Resource.CreatedAt.Lte(*req.CreateBefore))
|
||||
}
|
||||
if req.ExpireAfter != nil {
|
||||
do.Where(q.ResourceLong.As(q.Resource.Long.Name()).Expire.Gte(*req.ExpireAfter))
|
||||
do.Where(q.ResourceLong.As(q.Resource.Long.Name()).ExpireAt.Gte(*req.ExpireAfter))
|
||||
}
|
||||
if req.ExpireBefore != nil {
|
||||
do.Where(q.ResourceLong.As(q.Resource.Long.Name()).Expire.Lte(*req.ExpireBefore))
|
||||
do.Where(q.ResourceLong.As(q.Resource.Long.Name()).ExpireAt.Lte(*req.ExpireBefore))
|
||||
}
|
||||
|
||||
resource, err := q.Resource.Where(do).
|
||||
@@ -204,10 +204,10 @@ func AllActiveResource(c *fiber.Ctx) error {
|
||||
q.Resource.Type.Eq(int(m.ResourceTypeShort)),
|
||||
q.ResourceShort.As(q.Resource.Short.Name()).Where(
|
||||
short.Type.Eq(int(m.ResourceModeTime)),
|
||||
short.Expire.Gte(now),
|
||||
short.ExpireAt.Gte(now),
|
||||
q.ResourceShort.As(q.Resource.Short.Name()).
|
||||
Where(short.DailyLast.Lt(u.Today())).
|
||||
Or(short.DailyLimit.GtCol(short.DailyUsed)),
|
||||
Where(short.LastAt.Lt(u.Today())).
|
||||
Or(short.Quota.GtCol(short.Daily)),
|
||||
).Or(
|
||||
short.Type.Eq(int(m.ResourceModeQuota)),
|
||||
short.Quota.GtCol(short.Used),
|
||||
@@ -216,10 +216,10 @@ func AllActiveResource(c *fiber.Ctx) error {
|
||||
q.Resource.Type.Eq(int(m.ResourceTypeLong)),
|
||||
q.ResourceLong.As(q.Resource.Long.Name()).Where(
|
||||
long.Type.Eq(int(m.ResourceModeTime)),
|
||||
long.Expire.Gte(now),
|
||||
long.ExpireAt.Gte(now),
|
||||
q.ResourceLong.As(q.Resource.Long.Name()).
|
||||
Where(long.DailyLast.Lt(u.Today())).
|
||||
Or(long.DailyLimit.GtCol(long.DailyUsed)),
|
||||
Where(long.LastAt.Lt(u.Today())).
|
||||
Or(long.Quota.GtCol(long.Daily)),
|
||||
).Or(
|
||||
long.Type.Eq(int(m.ResourceModeQuota)),
|
||||
long.Quota.GtCol(long.Used),
|
||||
@@ -282,39 +282,39 @@ func StatisticResourceFree(c *fiber.Ctx) error {
|
||||
|
||||
// 短效包量
|
||||
case resource.Type == m.ResourceTypeShort && resource.Short.Type == m.ResourceModeQuota:
|
||||
if u.Z(resource.Short.Quota) > resource.Short.Used {
|
||||
if resource.Short.Quota > resource.Short.Used {
|
||||
shortCount++
|
||||
shortQuotaSum += int(u.Z(resource.Short.Quota) - resource.Short.Used)
|
||||
shortQuotaSum += int(resource.Short.Quota - resource.Short.Used)
|
||||
}
|
||||
|
||||
// 长效包量
|
||||
case resource.Type == m.ResourceTypeLong && resource.Long.Type == m.ResourceModeQuota:
|
||||
if u.Z(resource.Long.Quota) > resource.Long.Used {
|
||||
if resource.Long.Quota > resource.Long.Used {
|
||||
longCount++
|
||||
longQuotaSum += int(u.Z(resource.Long.Quota) - resource.Long.Used)
|
||||
longQuotaSum += int(resource.Long.Quota - resource.Long.Used)
|
||||
}
|
||||
|
||||
// 短效包时
|
||||
case resource.Type == m.ResourceTypeShort && resource.Short.Type == m.ResourceModeTime:
|
||||
if time.Time(*resource.Short.Expire).After(time.Now()) {
|
||||
if resource.Short.DailyLast == nil || u.IsToday(time.Time(*resource.Short.DailyLast)) == false {
|
||||
if time.Time(*resource.Short.ExpireAt).After(time.Now()) {
|
||||
if resource.Short.LastAt == nil || u.IsToday(time.Time(*resource.Short.LastAt)) == false {
|
||||
shortCount++
|
||||
shortDailyFreeSum += int(resource.Short.DailyLimit)
|
||||
} else if resource.Short.DailyLimit > resource.Short.DailyUsed {
|
||||
shortDailyFreeSum += int(resource.Short.Quota)
|
||||
} else if resource.Short.Quota > resource.Short.Daily {
|
||||
shortCount++
|
||||
shortDailyFreeSum += int(resource.Short.DailyLimit - resource.Short.DailyUsed)
|
||||
shortDailyFreeSum += int(resource.Short.Quota - resource.Short.Daily)
|
||||
}
|
||||
}
|
||||
|
||||
// 长效包时
|
||||
case resource.Type == m.ResourceTypeLong && resource.Long.Type == m.ResourceModeTime:
|
||||
if time.Time(*resource.Long.Expire).After(time.Now()) {
|
||||
if resource.Long.DailyLast == nil || u.IsToday(time.Time(*resource.Long.DailyLast)) == false {
|
||||
if time.Time(*resource.Long.ExpireAt).After(time.Now()) {
|
||||
if resource.Long.LastAt == nil || u.IsToday(time.Time(*resource.Long.LastAt)) == false {
|
||||
longCount++
|
||||
longDailyFreeSum += int(resource.Long.DailyLimit)
|
||||
} else if resource.Long.DailyLimit > resource.Long.DailyUsed {
|
||||
longDailyFreeSum += int(resource.Long.Quota)
|
||||
} else if resource.Long.Quota > resource.Long.Daily {
|
||||
longCount++
|
||||
longDailyFreeSum += int(resource.Long.DailyLimit - resource.Long.DailyUsed)
|
||||
longDailyFreeSum += int(resource.Long.Quota - resource.Long.Daily)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -443,7 +443,11 @@ func ResourcePrice(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// 获取套餐价格
|
||||
amount, err := req.GetAmount()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.JSON(fiber.Map{
|
||||
"price": req.GetAmount().StringFixed(2),
|
||||
"price": amount.StringFixed(2),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user