mirror of
https://github.com/serty2005/rmser.git
synced 2026-02-04 19:02:33 -06:00
добавлен биллинг и тарифы
добавлена интеграция с юкасса
This commit is contained in:
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