feat: add TenantLedger model and query generation

- Introduced TenantLedger model with fields for managing tenant transactions, including ID, TenantID, UserID, OrderID, transaction Type, Amount, and balance details.
- Implemented CRUD operations for TenantLedger with methods for Create, Update, Delete, and Reload.
- Generated query methods for TenantLedger to facilitate database interactions, including filtering, pagination, and aggregation functions.
- Established relationships with Order model for foreign key references.
This commit is contained in:
2025-12-18 13:12:26 +08:00
parent f93caefcb2
commit 1da84f2af3
42 changed files with 6468 additions and 265 deletions

View File

@@ -1,6 +1,10 @@
package consts
import "quyun/v2/app/requests"
import (
"time"
"quyun/v2/app/requests"
)
// Format
//
@@ -275,6 +279,10 @@ const (
// DefaultContentPreviewSeconds is the default preview duration in seconds when content.preview_seconds is unset/invalid.
// 默认试看时长(秒):当未配置或传入非法值时使用。
DefaultContentPreviewSeconds int32 = 60
// DefaultOrderRefundWindow is the default refundable time window starting from paid_at.
// 默认退款时间窗paid_at + 24h租户管理侧可以通过强制退款绕过该限制需审计
DefaultOrderRefundWindow = 24 * time.Hour
)
// content_prices
@@ -360,3 +368,101 @@ func ContentAccessStatusItems() []requests.KV {
}
return items
}
// orders
// swagger:enum OrderType
// ENUM( content_purchase, topup )
type OrderType string
// Description returns the Chinese label for the specific enum value.
func (t OrderType) Description() string {
switch t {
case OrderTypeContentPurchase:
return "购买内容"
case OrderTypeTopup:
return "充值"
default:
return "未知类型"
}
}
// OrderTypeItems returns the KV list for FE dropdowns.
func OrderTypeItems() []requests.KV {
values := OrderTypeValues()
items := make([]requests.KV, 0, len(values))
for _, v := range values {
items = append(items, requests.NewKV(string(v), v.Description()))
}
return items
}
// swagger:enum OrderStatus
// ENUM( created, paid, refunding, refunded, canceled, failed )
type OrderStatus string
// Description returns the Chinese label for the specific enum value.
func (t OrderStatus) Description() string {
switch t {
case OrderStatusCreated:
return "已创建"
case OrderStatusPaid:
return "已支付"
case OrderStatusRefunding:
return "退款中"
case OrderStatusRefunded:
return "已退款"
case OrderStatusCanceled:
return "已取消"
case OrderStatusFailed:
return "失败"
default:
return "未知状态"
}
}
// OrderStatusItems returns the KV list for FE dropdowns.
func OrderStatusItems() []requests.KV {
values := OrderStatusValues()
items := make([]requests.KV, 0, len(values))
for _, v := range values {
items = append(items, requests.NewKV(string(v), v.Description()))
}
return items
}
// tenant_ledgers
// swagger:enum TenantLedgerType
// ENUM( credit_topup, debit_purchase, credit_refund, freeze, unfreeze, adjustment )
type TenantLedgerType string
// Description returns the Chinese label for the specific enum value.
func (t TenantLedgerType) Description() string {
switch t {
case TenantLedgerTypeCreditTopup:
return "充值入账"
case TenantLedgerTypeDebitPurchase:
return "购买扣款"
case TenantLedgerTypeCreditRefund:
return "退款回滚"
case TenantLedgerTypeFreeze:
return "冻结"
case TenantLedgerTypeUnfreeze:
return "解冻"
case TenantLedgerTypeAdjustment:
return "人工调账"
default:
return "未知类型"
}
}
// TenantLedgerTypeItems returns the KV list for FE dropdowns.
func TenantLedgerTypeItems() []requests.KV {
values := TenantLedgerTypeValues()
items := make([]requests.KV, 0, len(values))
for _, v := range values {
items = append(items, requests.NewKV(string(v), v.Description()))
}
return items
}