更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -12,13 +12,10 @@ import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
)
|
||||
|
||||
// DefaultTenantStorageMB 租户默认附件空间(MB)。
|
||||
// 未配置基础额度、也没买套餐时按 500MB 兜底。
|
||||
const DefaultTenantStorageMB = 500
|
||||
|
||||
const bytesPerMB = 1024 * 1024
|
||||
|
||||
// StorageQuotaExceededError 附件空间不足
|
||||
type StorageQuotaExceededError struct {
|
||||
UsedBytes uint64
|
||||
QuotaBytes uint64
|
||||
@@ -34,13 +31,12 @@ func (e *StorageQuotaExceededError) Error() string {
|
||||
)
|
||||
}
|
||||
|
||||
// TenantStorageInfo 租户附件空间使用情况
|
||||
type TenantStorageInfo struct {
|
||||
Tid uint64 `json:"tid"`
|
||||
|
||||
BaseQuotaMB int `json:"base_quota_mb"` // 基础额度(租户字段,默认 500)
|
||||
PackageQuotaMB int `json:"package_quota_mb"` // 生效套餐容量(无套餐为 0)
|
||||
QuotaMB int `json:"quota_mb"` // 实际可用 = max(基础, 套餐)
|
||||
BaseQuotaMB int `json:"base_quota_mb"`
|
||||
PackageQuotaMB int `json:"package_quota_mb"`
|
||||
QuotaMB int `json:"quota_mb"`
|
||||
UsedBytes uint64 `json:"used_bytes"`
|
||||
QuotaBytes uint64 `json:"quota_bytes"`
|
||||
RemainingBytes uint64 `json:"remaining_bytes"`
|
||||
@@ -52,12 +48,6 @@ type TenantStorageInfo struct {
|
||||
DaysRemaining int `json:"days_remaining"`
|
||||
}
|
||||
|
||||
// SumTenantStorageUsed 统计租户已用附件空间(字节)。
|
||||
//
|
||||
// 注意:这里**不过滤 delete_time**。
|
||||
// 软删除只是标记 delete_time(回收站),记录仍然存在、磁盘仍然占用;
|
||||
// 只有「彻底删除」才会物理删行,此时统计自然减少 —— 即“彻底删除才释放空间”。
|
||||
// 只统计租户端上传(source=backend)的文件:平台端上传不占租户额度。
|
||||
func SumTenantStorageUsed(tid uint64) (uint64, error) {
|
||||
if tid == 0 {
|
||||
return 0, nil
|
||||
@@ -76,7 +66,6 @@ func SumTenantStorageUsed(tid uint64) (uint64, error) {
|
||||
return toUint64(rows[0]["total"]), nil
|
||||
}
|
||||
|
||||
// toUint64 兼容驱动返回的 int64 / uint64 / []byte / string
|
||||
func toUint64(v interface{}) uint64 {
|
||||
switch n := v.(type) {
|
||||
case int64:
|
||||
@@ -104,9 +93,6 @@ func toUint64(v interface{}) uint64 {
|
||||
}
|
||||
}
|
||||
|
||||
// GetActiveStorageOrder 取租户当前生效的附件空间订单。
|
||||
// 正常情况下同一时刻只有一条(购买不同规格时旧的会被置为 replaced),
|
||||
// 这里按容量倒序取第一条,兼容历史数据。
|
||||
func GetActiveStorageOrder(tid uint64) (*models.SystemTenantStorageOrder, error) {
|
||||
if tid == 0 {
|
||||
return nil, nil
|
||||
@@ -129,7 +115,6 @@ func GetActiveStorageOrder(tid uint64) (*models.SystemTenantStorageOrder, error)
|
||||
return &order, nil
|
||||
}
|
||||
|
||||
// GetTenantStorageInfo 查询租户附件空间使用情况
|
||||
func GetTenantStorageInfo(tid uint64) (*TenantStorageInfo, error) {
|
||||
info := &TenantStorageInfo{Tid: tid, BaseQuotaMB: DefaultTenantStorageMB}
|
||||
|
||||
@@ -183,8 +168,6 @@ func GetTenantStorageInfo(tid uint64) (*TenantStorageInfo, error) {
|
||||
return info, nil
|
||||
}
|
||||
|
||||
// EnsureTenantStorageQuota 上传前校验:已用 + 本次大小不得超过可用额度。
|
||||
// 超限返回 *StorageQuotaExceededError,调用方据此返回 403。
|
||||
func EnsureTenantStorageQuota(tid uint64, addBytes uint64) error {
|
||||
if tid == 0 || addBytes == 0 {
|
||||
return nil
|
||||
@@ -203,17 +186,10 @@ func EnsureTenantStorageQuota(tid uint64, addBytes uint64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// BuildStorageOrderNo 生成附件空间订单号
|
||||
func BuildStorageOrderNo(tid uint64) string {
|
||||
return fmt.Sprintf("ST%d%s%s", tid, time.Now().Format("20060102150405"), randomHex(4))
|
||||
}
|
||||
|
||||
// ActivateStorageOrder 支付成功后激活附件空间订单。
|
||||
//
|
||||
// 规则(与产品确认一致):
|
||||
// - 同一套餐续费:在现有到期时间上顺延,容量不变;
|
||||
// - 购买不同规格:新套餐立即生效,旧的已支付订单置为 replaced(只保留一个);
|
||||
// - 幂等:订单已是 paid 时直接返回。
|
||||
func ActivateStorageOrder(orderNo, payNo string) error {
|
||||
orderNo = strings.TrimSpace(orderNo)
|
||||
if orderNo == "" {
|
||||
@@ -239,7 +215,6 @@ func ActivateStorageOrder(orderNo, payNo string) error {
|
||||
start := now
|
||||
end := now.AddDate(0, 0, order.DurationDays)
|
||||
|
||||
// 同规格续费:从原到期时间顺延
|
||||
var sameOrder models.SystemTenantStorageOrder
|
||||
sameErr := models.Orm.QueryTable(new(models.SystemTenantStorageOrder)).
|
||||
Filter("tid", order.Tid).
|
||||
@@ -253,7 +228,6 @@ func ActivateStorageOrder(orderNo, payNo string) error {
|
||||
start = *sameOrder.EndTime
|
||||
end = start.AddDate(0, 0, order.DurationDays)
|
||||
} else {
|
||||
// 不同规格:旧的生效订单作废(只保留最大的一个)
|
||||
_, _ = models.Orm.QueryTable(new(models.SystemTenantStorageOrder)).
|
||||
Filter("tid", order.Tid).
|
||||
Filter("status", models.StorageOrderPaid).
|
||||
|
||||
Reference in new issue
Block a user