Merge remote-tracking branch 'origin/master' into internal
This commit is contained in:
+68
-17
@@ -1,11 +1,58 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// JSONInt64Slice is a custom type for handling []int64 as JSON in database
|
||||
type JSONInt64Slice []int64
|
||||
|
||||
// Scan implements sql.Scanner interface
|
||||
func (j *JSONInt64Slice) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
*j = []int64{}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Handle []byte
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
// Try to handle string
|
||||
str, ok := value.(string)
|
||||
if !ok {
|
||||
*j = []int64{}
|
||||
return nil
|
||||
}
|
||||
bytes = []byte(str)
|
||||
}
|
||||
|
||||
if len(bytes) == 0 {
|
||||
*j = []int64{}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Check if it's a JSON array
|
||||
if bytes[0] != '[' {
|
||||
// Not a JSON array, return empty slice
|
||||
*j = []int64{}
|
||||
return nil
|
||||
}
|
||||
|
||||
return json.Unmarshal(bytes, j)
|
||||
}
|
||||
|
||||
// Value implements driver.Valuer interface
|
||||
func (j JSONInt64Slice) Value() (driver.Value, error) {
|
||||
if len(j) == 0 {
|
||||
return "[]", nil
|
||||
}
|
||||
return json.Marshal(j)
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Id int64 `gorm:"primaryKey"`
|
||||
Password string `gorm:"type:varchar(100);not null;comment:User Password"`
|
||||
@@ -41,23 +88,27 @@ func (*User) TableName() string {
|
||||
}
|
||||
|
||||
type Subscribe struct {
|
||||
Id int64 `gorm:"primaryKey"`
|
||||
UserId int64 `gorm:"index:idx_user_id;not null;comment:User ID"`
|
||||
User User `gorm:"foreignKey:UserId;references:Id"`
|
||||
OrderId int64 `gorm:"index:idx_order_id;not null;comment:Order ID"`
|
||||
SubscribeId int64 `gorm:"index:idx_subscribe_id;not null;comment:Subscription ID"`
|
||||
StartTime time.Time `gorm:"default:CURRENT_TIMESTAMP(3);not null;comment:Subscription Start Time"`
|
||||
ExpireTime time.Time `gorm:"default:NULL;comment:Subscription Expire Time"`
|
||||
FinishedAt *time.Time `gorm:"default:NULL;comment:Finished Time"`
|
||||
Traffic int64 `gorm:"default:0;comment:Traffic"`
|
||||
Download int64 `gorm:"default:0;comment:Download Traffic"`
|
||||
Upload int64 `gorm:"default:0;comment:Upload Traffic"`
|
||||
Token string `gorm:"index:idx_token;unique;type:varchar(255);default:'';comment:Token"`
|
||||
UUID string `gorm:"type:varchar(255);unique;index:idx_uuid;default:'';comment:UUID"`
|
||||
Status uint8 `gorm:"type:tinyint(1);default:0;comment:Subscription Status: 0: Pending 1: Active 2: Finished 3: Expired 4: Deducted 5: stopped"`
|
||||
Note string `gorm:"type:varchar(500);default:'';comment:User note for subscription"`
|
||||
CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"`
|
||||
UpdatedAt time.Time `gorm:"comment:Update Time"`
|
||||
Id int64 `gorm:"primaryKey"`
|
||||
UserId int64 `gorm:"index:idx_user_id;not null;comment:User ID"`
|
||||
User User `gorm:"foreignKey:UserId;references:Id"`
|
||||
OrderId int64 `gorm:"index:idx_order_id;not null;comment:Order ID"`
|
||||
SubscribeId int64 `gorm:"index:idx_subscribe_id;not null;comment:Subscription ID"`
|
||||
NodeGroupId int64 `gorm:"index:idx_node_group_id;not null;default:0;comment:Node Group ID (single ID)"`
|
||||
GroupLocked *bool `gorm:"type:tinyint(1);not null;default:0;comment:Group Locked"`
|
||||
StartTime time.Time `gorm:"default:CURRENT_TIMESTAMP(3);not null;comment:Subscription Start Time"`
|
||||
ExpireTime time.Time `gorm:"default:NULL;comment:Subscription Expire Time"`
|
||||
FinishedAt *time.Time `gorm:"default:NULL;comment:Finished Time"`
|
||||
Traffic int64 `gorm:"default:0;comment:Traffic"`
|
||||
Download int64 `gorm:"default:0;comment:Download Traffic"`
|
||||
Upload int64 `gorm:"default:0;comment:Upload Traffic"`
|
||||
ExpiredDownload int64 `gorm:"default:0;comment:Expired period download traffic (bytes)"`
|
||||
ExpiredUpload int64 `gorm:"default:0;comment:Expired period upload traffic (bytes)"`
|
||||
Token string `gorm:"index:idx_token;unique;type:varchar(255);default:'';comment:Token"`
|
||||
UUID string `gorm:"type:varchar(255);unique;index:idx_uuid;default:'';comment:UUID"`
|
||||
Status uint8 `gorm:"type:tinyint(1);default:0;comment:Subscription Status: 0: Pending 1: Active 2: Finished 3: Expired 4: Deducted 5: stopped"`
|
||||
Note string `gorm:"type:varchar(500);default:'';comment:User note for subscription"`
|
||||
CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"`
|
||||
UpdatedAt time.Time `gorm:"comment:Update Time"`
|
||||
}
|
||||
|
||||
func (*Subscribe) TableName() string {
|
||||
|
||||
Reference in New Issue
Block a user