feat(server): implement server management handlers and database schema
This commit is contained in:
+51
-51
@@ -7,20 +7,44 @@ import (
|
||||
|
||||
type Type uint8
|
||||
|
||||
/*
|
||||
|
||||
Log Types:
|
||||
1X Message Logs
|
||||
2X Subscription Logs
|
||||
3X User Logs
|
||||
4X Traffic Ranking Logs
|
||||
*/
|
||||
|
||||
const (
|
||||
TypeEmailMessage Type = iota + 1 // Message log
|
||||
TypeMobileMessage // Mobile message log
|
||||
TypeSubscribe // Subscription log
|
||||
TypeSubscribeTraffic // Subscription traffic log
|
||||
TypeServerTraffic // Server traffic log
|
||||
TypeLogin // Login log
|
||||
TypeRegister // Registration log
|
||||
TypeBalance // Balance log
|
||||
TypeCommission // Commission log
|
||||
TypeResetSubscribe // Reset subscription log
|
||||
TypeGift // Gift log
|
||||
TypeUserTrafficRank // Top 10 User traffic rank log
|
||||
TypeServerTrafficRank // Top 10 Server traffic rank log
|
||||
TypeEmailMessage Type = 10 // Message log
|
||||
TypeMobileMessage Type = 11 // Mobile message log
|
||||
TypeSubscribe Type = 20 // Subscription log
|
||||
TypeSubscribeTraffic Type = 21 // Subscription traffic log
|
||||
TypeServerTraffic Type = 22 // Server traffic log
|
||||
TypeResetSubscribe Type = 23 // Reset subscription log
|
||||
TypeLogin Type = 30 // Login log
|
||||
TypeRegister Type = 31 // Registration log
|
||||
TypeBalance Type = 32 // Balance log
|
||||
TypeCommission Type = 33 // Commission log
|
||||
TypeGift Type = 34 // Gift log
|
||||
TypeUserTrafficRank Type = 40 // Top 10 User traffic rank log
|
||||
TypeServerTrafficRank Type = 41 // Top 10 Server traffic rank log
|
||||
)
|
||||
const (
|
||||
ResetSubscribeTypeAuto uint16 = 231 // Auto reset
|
||||
ResetSubscribeTypeAdvance uint16 = 232 // Advance reset
|
||||
ResetSubscribeTypePaid uint16 = 233 // Paid reset
|
||||
BalanceTypeRecharge uint16 = 321 // Recharge
|
||||
BalanceTypeWithdraw uint16 = 322 // Withdraw
|
||||
BalanceTypePayment uint16 = 323 // Payment
|
||||
BalanceTypeRefund uint16 = 324 // Refund
|
||||
BalanceTypeReward uint16 = 325 // Reward
|
||||
CommissionTypePurchase uint16 = 331 // Purchase
|
||||
CommissionTypeRenewal uint16 = 332 // Renewal
|
||||
CommissionTypeRefund uint16 = 333 // Gift
|
||||
GiftTypeIncrease uint16 = 341 // Increase
|
||||
GiftTypeReduce uint16 = 342 // Reduce
|
||||
)
|
||||
|
||||
// Uint8 converts Type to uint8.
|
||||
@@ -95,6 +119,7 @@ func (s *Traffic) Unmarshal(data []byte) error {
|
||||
|
||||
// Login represents a login log entry.
|
||||
type Login struct {
|
||||
Method string `json:"method"`
|
||||
LoginIP string `json:"login_ip"`
|
||||
UserAgent string `json:"user_agent"`
|
||||
Success bool `json:"success"`
|
||||
@@ -147,10 +172,10 @@ func (r *Register) Unmarshal(data []byte) error {
|
||||
|
||||
// Subscribe represents a subscription log entry.
|
||||
type Subscribe struct {
|
||||
Token string `json:"token"`
|
||||
UserAgent string `json:"user_agent"`
|
||||
ClientIP string `json:"client_ip"`
|
||||
SubscribeId int64 `json:"subscribe_id"`
|
||||
Token string `json:"token"`
|
||||
UserAgent string `json:"user_agent"`
|
||||
ClientIP string `json:"client_ip"`
|
||||
UserSubscribeId int64 `json:"user_subscribe_id"`
|
||||
}
|
||||
|
||||
// Marshal implements the json.Marshaler interface for Subscribe.
|
||||
@@ -170,15 +195,10 @@ func (s *Subscribe) Unmarshal(data []byte) error {
|
||||
return json.Unmarshal(data, aux)
|
||||
}
|
||||
|
||||
const (
|
||||
ResetSubscribeTypeAuto uint8 = 1
|
||||
ResetSubscribeTypeAdvance uint8 = 2
|
||||
ResetSubscribeTypePaid uint8 = 3
|
||||
)
|
||||
|
||||
// ResetSubscribe represents a reset subscription log entry.
|
||||
type ResetSubscribe struct {
|
||||
Type uint8 `json:"type"`
|
||||
Type uint16 `json:"type"`
|
||||
UserId int64 `json:"user_id"`
|
||||
OrderNo string `json:"order_no,omitempty"`
|
||||
ResetAt int64 `json:"reset_at"`
|
||||
}
|
||||
@@ -200,22 +220,13 @@ func (r *ResetSubscribe) Unmarshal(data []byte) error {
|
||||
return json.Unmarshal(data, aux)
|
||||
}
|
||||
|
||||
const (
|
||||
BalanceTypeRecharge uint8 = 1 // Recharge
|
||||
BalanceTypeWithdraw uint8 = 2 // Withdraw
|
||||
BalanceTypePayment uint8 = 3 // Payment
|
||||
BalanceTypeRefund uint8 = 4 // Refund
|
||||
BalanceTypeReward uint8 = 5 // Reward
|
||||
)
|
||||
|
||||
// Balance represents a balance log entry.
|
||||
type Balance struct {
|
||||
Id int64 `json:"id"`
|
||||
Type uint8 `json:"type"`
|
||||
Amount int64 `json:"amount"`
|
||||
OrderId int64 `json:"order_id,omitempty"`
|
||||
Balance int64 `json:"balance"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
Type uint16 `json:"type"`
|
||||
Amount int64 `json:"amount"`
|
||||
OrderId int64 `json:"order_id,omitempty"`
|
||||
Balance int64 `json:"balance"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
// Marshal implements the json.Marshaler interface for Balance.
|
||||
@@ -235,15 +246,9 @@ func (b *Balance) Unmarshal(data []byte) error {
|
||||
return json.Unmarshal(data, aux)
|
||||
}
|
||||
|
||||
const (
|
||||
CommissionTypePurchase uint8 = 1 // Purchase
|
||||
CommissionTypeRenewal uint8 = 2 // Renewal
|
||||
CommissionTypeRefund uint8 = 3 // Gift
|
||||
)
|
||||
|
||||
// Commission represents a commission log entry.
|
||||
type Commission struct {
|
||||
Type uint8 `json:"type"`
|
||||
Type uint16 `json:"type"`
|
||||
Amount int64 `json:"amount"`
|
||||
OrderNo string `json:"order_no"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
@@ -266,14 +271,9 @@ func (c *Commission) Unmarshal(data []byte) error {
|
||||
return json.Unmarshal(data, aux)
|
||||
}
|
||||
|
||||
const (
|
||||
GiftTypeIncrease uint8 = 1 // Increase
|
||||
GiftTypeReduce uint8 = 2 // Reduce
|
||||
)
|
||||
|
||||
// Gift represents a gift log entry.
|
||||
type Gift struct {
|
||||
Type uint8 `json:"type"`
|
||||
Type uint16 `json:"type"`
|
||||
OrderNo string `json:"order_no"`
|
||||
SubscribeId int64 `json:"subscribe_id"`
|
||||
Amount int64 `json:"amount"`
|
||||
|
||||
@@ -16,6 +16,7 @@ type FilterParams struct {
|
||||
Page int
|
||||
Size int
|
||||
Type uint8
|
||||
Data string
|
||||
Search string
|
||||
ObjectID int64
|
||||
}
|
||||
@@ -43,6 +44,11 @@ func (m *customSystemLogModel) FilterSystemLog(ctx context.Context, filter *Filt
|
||||
if filter.Type != 0 {
|
||||
tx = tx.Where("`type` = ?", filter.Type)
|
||||
}
|
||||
|
||||
if filter.Data != "" {
|
||||
tx = tx.Where("`data` = ?", filter.Data)
|
||||
}
|
||||
|
||||
if filter.ObjectID != 0 {
|
||||
tx = tx.Where("`object_id` = ?", filter.ObjectID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user