修复 model 生成脚本,统一时间字段类型为 common.LocalDateTime
This commit is contained in:
@@ -102,8 +102,5 @@ func main() {
|
||||
}
|
||||
|
||||
func genBasic(name string, opts ...gen.ModelOpt) any {
|
||||
return g.GenerateModel(name,
|
||||
gen.FieldType("created_at", "common.LocalDateTime"),
|
||||
gen.FieldType("updated_at", "common.LocalDateTime"),
|
||||
)
|
||||
return g.GenerateModel(name, opts...)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ package models
|
||||
|
||||
import (
|
||||
"platform/web/common"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -23,7 +22,7 @@ type Admin struct {
|
||||
Phone string `gorm:"column:phone;comment:手机号码" json:"phone"` // 手机号码
|
||||
Email string `gorm:"column:email;comment:邮箱" json:"email"` // 邮箱
|
||||
Status int32 `gorm:"column:status;not null;default:1;comment:状态:1-正常,0-禁用" json:"status"` // 状态:1-正常,0-禁用
|
||||
LastLogin time.Time `gorm:"column:last_login;comment:最后登录时间" json:"last_login"` // 最后登录时间
|
||||
LastLogin common.LocalDateTime `gorm:"column:last_login;comment:最后登录时间" json:"last_login"` // 最后登录时间
|
||||
LastLoginHost string `gorm:"column:last_login_host;comment:最后登录地址" json:"last_login_host"` // 最后登录地址
|
||||
LastLoginAgent string `gorm:"column:last_login_agent;comment:最后登录代理" json:"last_login_agent"` // 最后登录代理
|
||||
CreatedAt common.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间
|
||||
|
||||
@@ -6,7 +6,6 @@ package models
|
||||
|
||||
import (
|
||||
"platform/web/common"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -26,7 +25,7 @@ type Channel struct {
|
||||
AuthPass bool `gorm:"column:auth_pass;not null;comment:密码认证" json:"auth_pass"` // 密码认证
|
||||
Username string `gorm:"column:username;comment:用户名" json:"username"` // 用户名
|
||||
Password string `gorm:"column:password;comment:密码" json:"password"` // 密码
|
||||
Expiration time.Time `gorm:"column:expiration;not null;comment:过期时间" json:"expiration"` // 过期时间
|
||||
Expiration common.LocalDateTime `gorm:"column:expiration;not null;comment:过期时间" json:"expiration"` // 过期时间
|
||||
CreatedAt common.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt common.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
|
||||
@@ -6,7 +6,6 @@ package models
|
||||
|
||||
import (
|
||||
"platform/web/common"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -15,7 +14,7 @@ const TableNameCoupon = "coupon"
|
||||
|
||||
// Coupon mapped from table <coupon>
|
||||
type Coupon struct {
|
||||
ExpireAt time.Time `gorm:"column:expire_at;comment:过期时间" json:"expire_at"` // 过期时间
|
||||
ExpireAt common.LocalDateTime `gorm:"column:expire_at;comment:过期时间" json:"expire_at"` // 过期时间
|
||||
CreatedAt common.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt common.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
|
||||
@@ -4,20 +4,18 @@
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
import "platform/web/common"
|
||||
|
||||
const TableNameResourcePsr = "resource_psr"
|
||||
|
||||
// ResourcePsr mapped from table <resource_psr>
|
||||
type ResourcePsr struct {
|
||||
ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:ID" json:"id"` // ID
|
||||
ResourceID int32 `gorm:"column:resource_id;not null;comment:套餐ID" json:"resource_id"` // 套餐ID
|
||||
Live int32 `gorm:"column:live;comment:轮换周期(秒)" json:"live"` // 轮换周期(秒)
|
||||
Conn int32 `gorm:"column:conn;comment:最大连接数" json:"conn"` // 最大连接数
|
||||
Expire time.Time `gorm:"column:expire;comment:过期时间" json:"expire"` // 过期时间
|
||||
Used bool `gorm:"column:used;comment:是否已使用" json:"used"` // 是否已使用
|
||||
ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:ID" json:"id"` // ID
|
||||
ResourceID int32 `gorm:"column:resource_id;not null;comment:套餐ID" json:"resource_id"` // 套餐ID
|
||||
Live int32 `gorm:"column:live;comment:轮换周期(秒)" json:"live"` // 轮换周期(秒)
|
||||
Conn int32 `gorm:"column:conn;comment:最大连接数" json:"conn"` // 最大连接数
|
||||
Expire common.LocalDateTime `gorm:"column:expire;comment:过期时间" json:"expire"` // 过期时间
|
||||
Used bool `gorm:"column:used;comment:是否已使用" json:"used"` // 是否已使用
|
||||
}
|
||||
|
||||
// TableName ResourcePsr's table name
|
||||
|
||||
@@ -6,7 +6,6 @@ package models
|
||||
|
||||
import (
|
||||
"platform/web/common"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -30,7 +29,7 @@ type User struct {
|
||||
IDToken string `gorm:"column:id_token;comment:身份验证标识" json:"id_token"` // 身份验证标识
|
||||
ContactQq string `gorm:"column:contact_qq;comment:QQ联系方式" json:"contact_qq"` // QQ联系方式
|
||||
ContactWechat string `gorm:"column:contact_wechat;comment:微信联系方式" json:"contact_wechat"` // 微信联系方式
|
||||
LastLogin time.Time `gorm:"column:last_login;comment:最后登录时间" json:"last_login"` // 最后登录时间
|
||||
LastLogin common.LocalDateTime `gorm:"column:last_login;comment:最后登录时间" json:"last_login"` // 最后登录时间
|
||||
LastLoginHost string `gorm:"column:last_login_host;comment:最后登录地址" json:"last_login_host"` // 最后登录地址
|
||||
LastLoginAgent string `gorm:"column:last_login_agent;comment:最后登录代理" json:"last_login_agent"` // 最后登录代理
|
||||
CreatedAt common.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间
|
||||
|
||||
@@ -35,7 +35,7 @@ func newAdmin(db *gorm.DB, opts ...gen.DOOption) admin {
|
||||
_admin.Phone = field.NewString(tableName, "phone")
|
||||
_admin.Email = field.NewString(tableName, "email")
|
||||
_admin.Status = field.NewInt32(tableName, "status")
|
||||
_admin.LastLogin = field.NewTime(tableName, "last_login")
|
||||
_admin.LastLogin = field.NewField(tableName, "last_login")
|
||||
_admin.LastLoginHost = field.NewString(tableName, "last_login_host")
|
||||
_admin.LastLoginAgent = field.NewString(tableName, "last_login_agent")
|
||||
_admin.CreatedAt = field.NewField(tableName, "created_at")
|
||||
@@ -59,7 +59,7 @@ type admin struct {
|
||||
Phone field.String // 手机号码
|
||||
Email field.String // 邮箱
|
||||
Status field.Int32 // 状态:1-正常,0-禁用
|
||||
LastLogin field.Time // 最后登录时间
|
||||
LastLogin field.Field // 最后登录时间
|
||||
LastLoginHost field.String // 最后登录地址
|
||||
LastLoginAgent field.String // 最后登录代理
|
||||
CreatedAt field.Field // 创建时间
|
||||
@@ -89,7 +89,7 @@ func (a *admin) updateTableName(table string) *admin {
|
||||
a.Phone = field.NewString(table, "phone")
|
||||
a.Email = field.NewString(table, "email")
|
||||
a.Status = field.NewInt32(table, "status")
|
||||
a.LastLogin = field.NewTime(table, "last_login")
|
||||
a.LastLogin = field.NewField(table, "last_login")
|
||||
a.LastLoginHost = field.NewString(table, "last_login_host")
|
||||
a.LastLoginAgent = field.NewString(table, "last_login_agent")
|
||||
a.CreatedAt = field.NewField(table, "created_at")
|
||||
|
||||
@@ -38,7 +38,7 @@ func newChannel(db *gorm.DB, opts ...gen.DOOption) channel {
|
||||
_channel.AuthPass = field.NewBool(tableName, "auth_pass")
|
||||
_channel.Username = field.NewString(tableName, "username")
|
||||
_channel.Password = field.NewString(tableName, "password")
|
||||
_channel.Expiration = field.NewTime(tableName, "expiration")
|
||||
_channel.Expiration = field.NewField(tableName, "expiration")
|
||||
_channel.CreatedAt = field.NewField(tableName, "created_at")
|
||||
_channel.UpdatedAt = field.NewField(tableName, "updated_at")
|
||||
_channel.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
@@ -65,7 +65,7 @@ type channel struct {
|
||||
AuthPass field.Bool // 密码认证
|
||||
Username field.String // 用户名
|
||||
Password field.String // 密码
|
||||
Expiration field.Time // 过期时间
|
||||
Expiration field.Field // 过期时间
|
||||
CreatedAt field.Field // 创建时间
|
||||
UpdatedAt field.Field // 更新时间
|
||||
DeletedAt field.Field // 删除时间
|
||||
@@ -98,7 +98,7 @@ func (c *channel) updateTableName(table string) *channel {
|
||||
c.AuthPass = field.NewBool(table, "auth_pass")
|
||||
c.Username = field.NewString(table, "username")
|
||||
c.Password = field.NewString(table, "password")
|
||||
c.Expiration = field.NewTime(table, "expiration")
|
||||
c.Expiration = field.NewField(table, "expiration")
|
||||
c.CreatedAt = field.NewField(table, "created_at")
|
||||
c.UpdatedAt = field.NewField(table, "updated_at")
|
||||
c.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
@@ -27,7 +27,7 @@ func newCoupon(db *gorm.DB, opts ...gen.DOOption) coupon {
|
||||
|
||||
tableName := _coupon.couponDo.TableName()
|
||||
_coupon.ALL = field.NewAsterisk(tableName)
|
||||
_coupon.ExpireAt = field.NewTime(tableName, "expire_at")
|
||||
_coupon.ExpireAt = field.NewField(tableName, "expire_at")
|
||||
_coupon.CreatedAt = field.NewField(tableName, "created_at")
|
||||
_coupon.UpdatedAt = field.NewField(tableName, "updated_at")
|
||||
_coupon.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
@@ -48,7 +48,7 @@ type coupon struct {
|
||||
couponDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ExpireAt field.Time // 过期时间
|
||||
ExpireAt field.Field // 过期时间
|
||||
CreatedAt field.Field // 创建时间
|
||||
UpdatedAt field.Field // 更新时间
|
||||
DeletedAt field.Field // 删除时间
|
||||
@@ -75,7 +75,7 @@ func (c coupon) As(alias string) *coupon {
|
||||
|
||||
func (c *coupon) updateTableName(table string) *coupon {
|
||||
c.ALL = field.NewAsterisk(table)
|
||||
c.ExpireAt = field.NewTime(table, "expire_at")
|
||||
c.ExpireAt = field.NewField(table, "expire_at")
|
||||
c.CreatedAt = field.NewField(table, "created_at")
|
||||
c.UpdatedAt = field.NewField(table, "updated_at")
|
||||
c.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
@@ -31,7 +31,7 @@ func newResourcePsr(db *gorm.DB, opts ...gen.DOOption) resourcePsr {
|
||||
_resourcePsr.ResourceID = field.NewInt32(tableName, "resource_id")
|
||||
_resourcePsr.Live = field.NewInt32(tableName, "live")
|
||||
_resourcePsr.Conn = field.NewInt32(tableName, "conn")
|
||||
_resourcePsr.Expire = field.NewTime(tableName, "expire")
|
||||
_resourcePsr.Expire = field.NewField(tableName, "expire")
|
||||
_resourcePsr.Used = field.NewBool(tableName, "used")
|
||||
|
||||
_resourcePsr.fillFieldMap()
|
||||
@@ -47,7 +47,7 @@ type resourcePsr struct {
|
||||
ResourceID field.Int32 // 套餐ID
|
||||
Live field.Int32 // 轮换周期(秒)
|
||||
Conn field.Int32 // 最大连接数
|
||||
Expire field.Time // 过期时间
|
||||
Expire field.Field // 过期时间
|
||||
Used field.Bool // 是否已使用
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
@@ -69,7 +69,7 @@ func (r *resourcePsr) updateTableName(table string) *resourcePsr {
|
||||
r.ResourceID = field.NewInt32(table, "resource_id")
|
||||
r.Live = field.NewInt32(table, "live")
|
||||
r.Conn = field.NewInt32(table, "conn")
|
||||
r.Expire = field.NewTime(table, "expire")
|
||||
r.Expire = field.NewField(table, "expire")
|
||||
r.Used = field.NewBool(table, "used")
|
||||
|
||||
r.fillFieldMap()
|
||||
|
||||
@@ -42,7 +42,7 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) user {
|
||||
_user.IDToken = field.NewString(tableName, "id_token")
|
||||
_user.ContactQq = field.NewString(tableName, "contact_qq")
|
||||
_user.ContactWechat = field.NewString(tableName, "contact_wechat")
|
||||
_user.LastLogin = field.NewTime(tableName, "last_login")
|
||||
_user.LastLogin = field.NewField(tableName, "last_login")
|
||||
_user.LastLoginHost = field.NewString(tableName, "last_login_host")
|
||||
_user.LastLoginAgent = field.NewString(tableName, "last_login_agent")
|
||||
_user.CreatedAt = field.NewField(tableName, "created_at")
|
||||
@@ -73,7 +73,7 @@ type user struct {
|
||||
IDToken field.String // 身份验证标识
|
||||
ContactQq field.String // QQ联系方式
|
||||
ContactWechat field.String // 微信联系方式
|
||||
LastLogin field.Time // 最后登录时间
|
||||
LastLogin field.Field // 最后登录时间
|
||||
LastLoginHost field.String // 最后登录地址
|
||||
LastLoginAgent field.String // 最后登录代理
|
||||
CreatedAt field.Field // 创建时间
|
||||
@@ -110,7 +110,7 @@ func (u *user) updateTableName(table string) *user {
|
||||
u.IDToken = field.NewString(table, "id_token")
|
||||
u.ContactQq = field.NewString(table, "contact_qq")
|
||||
u.ContactWechat = field.NewString(table, "contact_wechat")
|
||||
u.LastLogin = field.NewTime(table, "last_login")
|
||||
u.LastLogin = field.NewField(table, "last_login")
|
||||
u.LastLoginHost = field.NewString(table, "last_login_host")
|
||||
u.LastLoginAgent = field.NewString(table, "last_login_agent")
|
||||
u.CreatedAt = field.NewField(table, "created_at")
|
||||
|
||||
@@ -3,6 +3,7 @@ package services
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"platform/web/common"
|
||||
m "platform/web/models"
|
||||
q "platform/web/queries"
|
||||
"time"
|
||||
@@ -121,7 +122,7 @@ func (s *authService) OauthPassword(ctx context.Context, _ *m.Client, data *Gran
|
||||
}
|
||||
|
||||
// 更新用户的登录时间
|
||||
user.LastLogin = time.Now()
|
||||
user.LastLogin = common.LocalDateTime(time.Now())
|
||||
user.LastLoginHost = ip
|
||||
user.LastLoginAgent = agent
|
||||
if err := tx.User.Omit(q.User.AdminID).Save(user); err != nil {
|
||||
|
||||
@@ -299,7 +299,7 @@ func (s *channelService) CreateChannel(
|
||||
step = time.Now()
|
||||
|
||||
now := time.Now()
|
||||
expiration := now.Add(time.Duration(resource.Live) * time.Second)
|
||||
expiration := common.LocalDateTime(now.Add(time.Duration(resource.Live) * time.Second))
|
||||
_addr, channels, err := assignPort(q, edgeAssigns, auth.Payload.Id, protocol, authType, expiration, filter)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -426,7 +426,7 @@ func assignEdge(q *q.Query, count int, filter NodeFilterConfig) (*AssignEdgeResu
|
||||
q.Channel.ProxyPort).
|
||||
Where(
|
||||
q.Channel.ProxyID.In(proxyIds...),
|
||||
q.Channel.Expiration.Gt(time.Now())).
|
||||
q.Channel.Expiration.Gt(common.LocalDateTime(time.Now()))).
|
||||
Group(
|
||||
q.Channel.ProxyPort,
|
||||
q.Channel.ProxyID).
|
||||
@@ -547,7 +547,7 @@ func assignPort(
|
||||
userId int32,
|
||||
protocol ChannelProtocol,
|
||||
authType ChannelAuthType,
|
||||
expiration time.Time,
|
||||
expiration common.LocalDateTime,
|
||||
filter NodeFilterConfig,
|
||||
) ([]*PortInfo, []*models.Channel, error) {
|
||||
var step time.Time
|
||||
@@ -745,9 +745,10 @@ func cache(ctx context.Context, channels []*models.Channel) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pipe.Set(ctx, chKey(channel), string(marshal), time.Until(channel.Expiration))
|
||||
expiration := time.Time(channel.Expiration)
|
||||
pipe.Set(ctx, chKey(channel), string(marshal), time.Until(expiration))
|
||||
zList = append(zList, redis.Z{
|
||||
Score: float64(channel.Expiration.Unix()),
|
||||
Score: float64(expiration.Unix()),
|
||||
Member: channel.ID,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -45,7 +45,8 @@ func (s *transactionService) PrepareTransaction(ctx context.Context, q *q.Query,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !coupon.ExpireAt.IsZero() && coupon.ExpireAt.Before(time.Now()) {
|
||||
var expireAt = time.Time(coupon.ExpireAt)
|
||||
if !expireAt.IsZero() && expireAt.Before(time.Now()) {
|
||||
_, err = q.Coupon.
|
||||
Where(q.Coupon.ID.Eq(coupon.ID)).
|
||||
Update(q.Coupon.Status, 2)
|
||||
@@ -71,7 +72,7 @@ func (s *transactionService) PrepareTransaction(ctx context.Context, q *q.Query,
|
||||
// 指定用户的优惠券
|
||||
case coupon.UserID == uid:
|
||||
amount = amount - coupon.Amount
|
||||
if coupon.ExpireAt.IsZero() {
|
||||
if time.Time(coupon.ExpireAt).IsZero() {
|
||||
_, err = q.Coupon.
|
||||
Where(q.Coupon.ID.Eq(coupon.ID)).
|
||||
Update(q.Coupon.Status, 1)
|
||||
|
||||
Reference in New Issue
Block a user