mirror of
https://github.com/serty2005/rmser.git
synced 2026-02-04 19:02:33 -06:00
добавлен биллинг и тарифы
добавлена интеграция с юкасса
This commit is contained in:
@@ -65,7 +65,11 @@ type RMSServer struct {
|
||||
RootGroupGUID *uuid.UUID `gorm:"type:uuid" json:"root_group_guid"`
|
||||
AutoProcess bool `gorm:"default:false" json:"auto_process"`
|
||||
|
||||
// Billing / Stats
|
||||
// Billing
|
||||
Balance int `gorm:"default:0" json:"balance"`
|
||||
PaidUntil *time.Time `json:"paid_until"`
|
||||
|
||||
// Stats
|
||||
InvoiceCount int `gorm:"default:0" json:"invoice_count"`
|
||||
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
@@ -77,10 +81,12 @@ type Repository interface {
|
||||
// Users
|
||||
GetOrCreateUser(telegramID int64, username, first, last string) (*User, error)
|
||||
GetUserByTelegramID(telegramID int64) (*User, error)
|
||||
GetUserByID(id uuid.UUID) (*User, error)
|
||||
|
||||
// ConnectServer - Основной метод подключения.
|
||||
// Реализует логику: Новый URL -> Owner, Старый URL -> Operator.
|
||||
ConnectServer(userID uuid.UUID, url, login, encryptedPass, name string) (*RMSServer, error)
|
||||
GetServerByURL(url string) (*RMSServer, error)
|
||||
GetServerByID(id uuid.UUID) (*RMSServer, error)
|
||||
|
||||
SaveServerSettings(server *RMSServer) error
|
||||
|
||||
@@ -106,7 +112,10 @@ type Repository interface {
|
||||
AddUserToServer(serverID, userID uuid.UUID, role Role) error
|
||||
RemoveUserFromServer(serverID, userID uuid.UUID) error
|
||||
|
||||
// Billing & Stats
|
||||
IncrementInvoiceCount(serverID uuid.UUID) error
|
||||
UpdateBalance(serverID uuid.UUID, amountChange int, newPaidUntil *time.Time) error
|
||||
DecrementBalance(serverID uuid.UUID) error
|
||||
|
||||
// Super Admin Functions
|
||||
GetAllServersSystemWide() ([]RMSServer, error)
|
||||
|
||||
57
internal/domain/billing/entity.go
Normal file
57
internal/domain/billing/entity.go
Normal file
@@ -0,0 +1,57 @@
|
||||
// internal/domain/billing/entity.go
|
||||
|
||||
package billing
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type TariffType string
|
||||
|
||||
const (
|
||||
TariffPack TariffType = "PACK" // Пакет накладных
|
||||
TariffSubscription TariffType = "SUBSCRIPTION" // Подписка (безлимит на время)
|
||||
)
|
||||
|
||||
type OrderStatus string
|
||||
|
||||
const (
|
||||
StatusPending OrderStatus = "PENDING"
|
||||
StatusPaid OrderStatus = "PAID"
|
||||
StatusCanceled OrderStatus = "CANCELED"
|
||||
)
|
||||
|
||||
// Tariff - Описание услуги
|
||||
type Tariff struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type TariffType `json:"type"`
|
||||
Price float64 `json:"price"`
|
||||
InvoicesCount int `json:"invoices_count"` // Для PACK - сколько штук, для SUBSCRIPTION - 1000 (лимит)
|
||||
DurationDays int `json:"duration_days"`
|
||||
}
|
||||
|
||||
// Order - Заказ на покупку тарифа
|
||||
type Order struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
||||
UserID uuid.UUID `gorm:"type:uuid;not null;index" json:"user_id"` // Кто платит
|
||||
TargetServerID uuid.UUID `gorm:"type:uuid;not null;index" json:"target_server_id"` // Кому начисляем
|
||||
TariffID string `gorm:"type:varchar(50);not null" json:"tariff_id"`
|
||||
Amount float64 `gorm:"type:numeric(19,4);not null" json:"amount"`
|
||||
Status OrderStatus `gorm:"type:varchar(20);default:'PENDING'" json:"status"`
|
||||
|
||||
PaymentID string `gorm:"type:varchar(100)" json:"payment_id"` // ID транзакции в ЮКассе
|
||||
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// Repository для работы с заказами
|
||||
type Repository interface {
|
||||
CreateOrder(order *Order) error
|
||||
GetOrder(id uuid.UUID) (*Order, error)
|
||||
UpdateOrderStatus(id uuid.UUID, status OrderStatus, paymentID string) error
|
||||
GetActiveOrdersByUser(userID uuid.UUID) ([]Order, error)
|
||||
}
|
||||
Reference in New Issue
Block a user