修复 model 生成脚本,统一时间字段类型为 common.LocalDateTime

This commit is contained in:
2025-04-28 09:15:49 +08:00
parent 3e837b5fec
commit 129f842153
14 changed files with 38 additions and 44 deletions

View File

@@ -102,8 +102,5 @@ func main() {
} }
func genBasic(name string, opts ...gen.ModelOpt) any { func genBasic(name string, opts ...gen.ModelOpt) any {
return g.GenerateModel(name, return g.GenerateModel(name, opts...)
gen.FieldType("created_at", "common.LocalDateTime"),
gen.FieldType("updated_at", "common.LocalDateTime"),
)
} }

View File

@@ -6,7 +6,6 @@ package models
import ( import (
"platform/web/common" "platform/web/common"
"time"
"gorm.io/gorm" "gorm.io/gorm"
) )
@@ -23,7 +22,7 @@ type Admin struct {
Phone string `gorm:"column:phone;comment:手机号码" json:"phone"` // 手机号码 Phone string `gorm:"column:phone;comment:手机号码" json:"phone"` // 手机号码
Email string `gorm:"column:email;comment:邮箱" json:"email"` // 邮箱 Email string `gorm:"column:email;comment:邮箱" json:"email"` // 邮箱
Status int32 `gorm:"column:status;not null;default:1;comment:状态1-正常0-禁用" json:"status"` // 状态1-正常0-禁用 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"` // 最后登录地址 LastLoginHost string `gorm:"column:last_login_host;comment:最后登录地址" json:"last_login_host"` // 最后登录地址
LastLoginAgent string `gorm:"column:last_login_agent;comment:最后登录代理" json:"last_login_agent"` // 最后登录代理 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"` // 创建时间 CreatedAt common.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间

View File

@@ -6,7 +6,6 @@ package models
import ( import (
"platform/web/common" "platform/web/common"
"time"
"gorm.io/gorm" "gorm.io/gorm"
) )
@@ -26,7 +25,7 @@ type Channel struct {
AuthPass bool `gorm:"column:auth_pass;not null;comment:密码认证" json:"auth_pass"` // 密码认证 AuthPass bool `gorm:"column:auth_pass;not null;comment:密码认证" json:"auth_pass"` // 密码认证
Username string `gorm:"column:username;comment:用户名" json:"username"` // 用户名 Username string `gorm:"column:username;comment:用户名" json:"username"` // 用户名
Password string `gorm:"column:password;comment:密码" json:"password"` // 密码 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"` // 创建时间 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"` // 更新时间 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"` // 删除时间 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间

View File

@@ -6,7 +6,6 @@ package models
import ( import (
"platform/web/common" "platform/web/common"
"time"
"gorm.io/gorm" "gorm.io/gorm"
) )
@@ -15,7 +14,7 @@ const TableNameCoupon = "coupon"
// Coupon mapped from table <coupon> // Coupon mapped from table <coupon>
type Coupon struct { 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"` // 创建时间 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"` // 更新时间 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"` // 删除时间 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间

View File

@@ -4,20 +4,18 @@
package models package models
import ( import "platform/web/common"
"time"
)
const TableNameResourcePsr = "resource_psr" const TableNameResourcePsr = "resource_psr"
// ResourcePsr mapped from table <resource_psr> // ResourcePsr mapped from table <resource_psr>
type ResourcePsr struct { type ResourcePsr struct {
ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:ID" json:"id"` // ID 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 ResourceID int32 `gorm:"column:resource_id;not null;comment:套餐ID" json:"resource_id"` // 套餐ID
Live int32 `gorm:"column:live;comment:轮换周期(秒)" json:"live"` // 轮换周期(秒) Live int32 `gorm:"column:live;comment:轮换周期(秒)" json:"live"` // 轮换周期(秒)
Conn int32 `gorm:"column:conn;comment:最大连接数" json:"conn"` // 最大连接数 Conn int32 `gorm:"column:conn;comment:最大连接数" json:"conn"` // 最大连接数
Expire time.Time `gorm:"column:expire;comment:过期时间" json:"expire"` // 过期时间 Expire common.LocalDateTime `gorm:"column:expire;comment:过期时间" json:"expire"` // 过期时间
Used bool `gorm:"column:used;comment:是否已使用" json:"used"` // 是否已使用 Used bool `gorm:"column:used;comment:是否已使用" json:"used"` // 是否已使用
} }
// TableName ResourcePsr's table name // TableName ResourcePsr's table name

View File

@@ -6,7 +6,6 @@ package models
import ( import (
"platform/web/common" "platform/web/common"
"time"
"gorm.io/gorm" "gorm.io/gorm"
) )
@@ -30,7 +29,7 @@ type User struct {
IDToken string `gorm:"column:id_token;comment:身份验证标识" json:"id_token"` // 身份验证标识 IDToken string `gorm:"column:id_token;comment:身份验证标识" json:"id_token"` // 身份验证标识
ContactQq string `gorm:"column:contact_qq;comment:QQ联系方式" json:"contact_qq"` // QQ联系方式 ContactQq string `gorm:"column:contact_qq;comment:QQ联系方式" json:"contact_qq"` // QQ联系方式
ContactWechat string `gorm:"column:contact_wechat;comment:微信联系方式" json:"contact_wechat"` // 微信联系方式 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"` // 最后登录地址 LastLoginHost string `gorm:"column:last_login_host;comment:最后登录地址" json:"last_login_host"` // 最后登录地址
LastLoginAgent string `gorm:"column:last_login_agent;comment:最后登录代理" json:"last_login_agent"` // 最后登录代理 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"` // 创建时间 CreatedAt common.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间

View File

@@ -35,7 +35,7 @@ func newAdmin(db *gorm.DB, opts ...gen.DOOption) admin {
_admin.Phone = field.NewString(tableName, "phone") _admin.Phone = field.NewString(tableName, "phone")
_admin.Email = field.NewString(tableName, "email") _admin.Email = field.NewString(tableName, "email")
_admin.Status = field.NewInt32(tableName, "status") _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.LastLoginHost = field.NewString(tableName, "last_login_host")
_admin.LastLoginAgent = field.NewString(tableName, "last_login_agent") _admin.LastLoginAgent = field.NewString(tableName, "last_login_agent")
_admin.CreatedAt = field.NewField(tableName, "created_at") _admin.CreatedAt = field.NewField(tableName, "created_at")
@@ -59,7 +59,7 @@ type admin struct {
Phone field.String // 手机号码 Phone field.String // 手机号码
Email field.String // 邮箱 Email field.String // 邮箱
Status field.Int32 // 状态1-正常0-禁用 Status field.Int32 // 状态1-正常0-禁用
LastLogin field.Time // 最后登录时间 LastLogin field.Field // 最后登录时间
LastLoginHost field.String // 最后登录地址 LastLoginHost field.String // 最后登录地址
LastLoginAgent field.String // 最后登录代理 LastLoginAgent field.String // 最后登录代理
CreatedAt field.Field // 创建时间 CreatedAt field.Field // 创建时间
@@ -89,7 +89,7 @@ func (a *admin) updateTableName(table string) *admin {
a.Phone = field.NewString(table, "phone") a.Phone = field.NewString(table, "phone")
a.Email = field.NewString(table, "email") a.Email = field.NewString(table, "email")
a.Status = field.NewInt32(table, "status") 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.LastLoginHost = field.NewString(table, "last_login_host")
a.LastLoginAgent = field.NewString(table, "last_login_agent") a.LastLoginAgent = field.NewString(table, "last_login_agent")
a.CreatedAt = field.NewField(table, "created_at") a.CreatedAt = field.NewField(table, "created_at")

View File

@@ -38,7 +38,7 @@ func newChannel(db *gorm.DB, opts ...gen.DOOption) channel {
_channel.AuthPass = field.NewBool(tableName, "auth_pass") _channel.AuthPass = field.NewBool(tableName, "auth_pass")
_channel.Username = field.NewString(tableName, "username") _channel.Username = field.NewString(tableName, "username")
_channel.Password = field.NewString(tableName, "password") _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.CreatedAt = field.NewField(tableName, "created_at")
_channel.UpdatedAt = field.NewField(tableName, "updated_at") _channel.UpdatedAt = field.NewField(tableName, "updated_at")
_channel.DeletedAt = field.NewField(tableName, "deleted_at") _channel.DeletedAt = field.NewField(tableName, "deleted_at")
@@ -65,7 +65,7 @@ type channel struct {
AuthPass field.Bool // 密码认证 AuthPass field.Bool // 密码认证
Username field.String // 用户名 Username field.String // 用户名
Password field.String // 密码 Password field.String // 密码
Expiration field.Time // 过期时间 Expiration field.Field // 过期时间
CreatedAt field.Field // 创建时间 CreatedAt field.Field // 创建时间
UpdatedAt field.Field // 更新时间 UpdatedAt field.Field // 更新时间
DeletedAt field.Field // 删除时间 DeletedAt field.Field // 删除时间
@@ -98,7 +98,7 @@ func (c *channel) updateTableName(table string) *channel {
c.AuthPass = field.NewBool(table, "auth_pass") c.AuthPass = field.NewBool(table, "auth_pass")
c.Username = field.NewString(table, "username") c.Username = field.NewString(table, "username")
c.Password = field.NewString(table, "password") 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.CreatedAt = field.NewField(table, "created_at")
c.UpdatedAt = field.NewField(table, "updated_at") c.UpdatedAt = field.NewField(table, "updated_at")
c.DeletedAt = field.NewField(table, "deleted_at") c.DeletedAt = field.NewField(table, "deleted_at")

View File

@@ -27,7 +27,7 @@ func newCoupon(db *gorm.DB, opts ...gen.DOOption) coupon {
tableName := _coupon.couponDo.TableName() tableName := _coupon.couponDo.TableName()
_coupon.ALL = field.NewAsterisk(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.CreatedAt = field.NewField(tableName, "created_at")
_coupon.UpdatedAt = field.NewField(tableName, "updated_at") _coupon.UpdatedAt = field.NewField(tableName, "updated_at")
_coupon.DeletedAt = field.NewField(tableName, "deleted_at") _coupon.DeletedAt = field.NewField(tableName, "deleted_at")
@@ -48,7 +48,7 @@ type coupon struct {
couponDo couponDo
ALL field.Asterisk ALL field.Asterisk
ExpireAt field.Time // 过期时间 ExpireAt field.Field // 过期时间
CreatedAt field.Field // 创建时间 CreatedAt field.Field // 创建时间
UpdatedAt field.Field // 更新时间 UpdatedAt field.Field // 更新时间
DeletedAt field.Field // 删除时间 DeletedAt field.Field // 删除时间
@@ -75,7 +75,7 @@ func (c coupon) As(alias string) *coupon {
func (c *coupon) updateTableName(table string) *coupon { func (c *coupon) updateTableName(table string) *coupon {
c.ALL = field.NewAsterisk(table) 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.CreatedAt = field.NewField(table, "created_at")
c.UpdatedAt = field.NewField(table, "updated_at") c.UpdatedAt = field.NewField(table, "updated_at")
c.DeletedAt = field.NewField(table, "deleted_at") c.DeletedAt = field.NewField(table, "deleted_at")

View File

@@ -31,7 +31,7 @@ func newResourcePsr(db *gorm.DB, opts ...gen.DOOption) resourcePsr {
_resourcePsr.ResourceID = field.NewInt32(tableName, "resource_id") _resourcePsr.ResourceID = field.NewInt32(tableName, "resource_id")
_resourcePsr.Live = field.NewInt32(tableName, "live") _resourcePsr.Live = field.NewInt32(tableName, "live")
_resourcePsr.Conn = field.NewInt32(tableName, "conn") _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.Used = field.NewBool(tableName, "used")
_resourcePsr.fillFieldMap() _resourcePsr.fillFieldMap()
@@ -47,7 +47,7 @@ type resourcePsr struct {
ResourceID field.Int32 // 套餐ID ResourceID field.Int32 // 套餐ID
Live field.Int32 // 轮换周期(秒) Live field.Int32 // 轮换周期(秒)
Conn field.Int32 // 最大连接数 Conn field.Int32 // 最大连接数
Expire field.Time // 过期时间 Expire field.Field // 过期时间
Used field.Bool // 是否已使用 Used field.Bool // 是否已使用
fieldMap map[string]field.Expr fieldMap map[string]field.Expr
@@ -69,7 +69,7 @@ func (r *resourcePsr) updateTableName(table string) *resourcePsr {
r.ResourceID = field.NewInt32(table, "resource_id") r.ResourceID = field.NewInt32(table, "resource_id")
r.Live = field.NewInt32(table, "live") r.Live = field.NewInt32(table, "live")
r.Conn = field.NewInt32(table, "conn") 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.Used = field.NewBool(table, "used")
r.fillFieldMap() r.fillFieldMap()

View File

@@ -42,7 +42,7 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) user {
_user.IDToken = field.NewString(tableName, "id_token") _user.IDToken = field.NewString(tableName, "id_token")
_user.ContactQq = field.NewString(tableName, "contact_qq") _user.ContactQq = field.NewString(tableName, "contact_qq")
_user.ContactWechat = field.NewString(tableName, "contact_wechat") _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.LastLoginHost = field.NewString(tableName, "last_login_host")
_user.LastLoginAgent = field.NewString(tableName, "last_login_agent") _user.LastLoginAgent = field.NewString(tableName, "last_login_agent")
_user.CreatedAt = field.NewField(tableName, "created_at") _user.CreatedAt = field.NewField(tableName, "created_at")
@@ -73,7 +73,7 @@ type user struct {
IDToken field.String // 身份验证标识 IDToken field.String // 身份验证标识
ContactQq field.String // QQ联系方式 ContactQq field.String // QQ联系方式
ContactWechat field.String // 微信联系方式 ContactWechat field.String // 微信联系方式
LastLogin field.Time // 最后登录时间 LastLogin field.Field // 最后登录时间
LastLoginHost field.String // 最后登录地址 LastLoginHost field.String // 最后登录地址
LastLoginAgent field.String // 最后登录代理 LastLoginAgent field.String // 最后登录代理
CreatedAt field.Field // 创建时间 CreatedAt field.Field // 创建时间
@@ -110,7 +110,7 @@ func (u *user) updateTableName(table string) *user {
u.IDToken = field.NewString(table, "id_token") u.IDToken = field.NewString(table, "id_token")
u.ContactQq = field.NewString(table, "contact_qq") u.ContactQq = field.NewString(table, "contact_qq")
u.ContactWechat = field.NewString(table, "contact_wechat") 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.LastLoginHost = field.NewString(table, "last_login_host")
u.LastLoginAgent = field.NewString(table, "last_login_agent") u.LastLoginAgent = field.NewString(table, "last_login_agent")
u.CreatedAt = field.NewField(table, "created_at") u.CreatedAt = field.NewField(table, "created_at")

View File

@@ -3,6 +3,7 @@ package services
import ( import (
"context" "context"
"errors" "errors"
"platform/web/common"
m "platform/web/models" m "platform/web/models"
q "platform/web/queries" q "platform/web/queries"
"time" "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.LastLoginHost = ip
user.LastLoginAgent = agent user.LastLoginAgent = agent
if err := tx.User.Omit(q.User.AdminID).Save(user); err != nil { if err := tx.User.Omit(q.User.AdminID).Save(user); err != nil {

View File

@@ -299,7 +299,7 @@ func (s *channelService) CreateChannel(
step = time.Now() step = time.Now()
now := 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) _addr, channels, err := assignPort(q, edgeAssigns, auth.Payload.Id, protocol, authType, expiration, filter)
if err != nil { if err != nil {
return err return err
@@ -426,7 +426,7 @@ func assignEdge(q *q.Query, count int, filter NodeFilterConfig) (*AssignEdgeResu
q.Channel.ProxyPort). q.Channel.ProxyPort).
Where( Where(
q.Channel.ProxyID.In(proxyIds...), q.Channel.ProxyID.In(proxyIds...),
q.Channel.Expiration.Gt(time.Now())). q.Channel.Expiration.Gt(common.LocalDateTime(time.Now()))).
Group( Group(
q.Channel.ProxyPort, q.Channel.ProxyPort,
q.Channel.ProxyID). q.Channel.ProxyID).
@@ -547,7 +547,7 @@ func assignPort(
userId int32, userId int32,
protocol ChannelProtocol, protocol ChannelProtocol,
authType ChannelAuthType, authType ChannelAuthType,
expiration time.Time, expiration common.LocalDateTime,
filter NodeFilterConfig, filter NodeFilterConfig,
) ([]*PortInfo, []*models.Channel, error) { ) ([]*PortInfo, []*models.Channel, error) {
var step time.Time var step time.Time
@@ -745,9 +745,10 @@ func cache(ctx context.Context, channels []*models.Channel) error {
if err != nil { if err != nil {
return err 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{ zList = append(zList, redis.Z{
Score: float64(channel.Expiration.Unix()), Score: float64(expiration.Unix()),
Member: channel.ID, Member: channel.ID,
}) })
} }

View File

@@ -45,7 +45,8 @@ func (s *transactionService) PrepareTransaction(ctx context.Context, q *q.Query,
return nil, err 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. _, err = q.Coupon.
Where(q.Coupon.ID.Eq(coupon.ID)). Where(q.Coupon.ID.Eq(coupon.ID)).
Update(q.Coupon.Status, 2) Update(q.Coupon.Status, 2)
@@ -71,7 +72,7 @@ func (s *transactionService) PrepareTransaction(ctx context.Context, q *q.Query,
// 指定用户的优惠券 // 指定用户的优惠券
case coupon.UserID == uid: case coupon.UserID == uid:
amount = amount - coupon.Amount amount = amount - coupon.Amount
if coupon.ExpireAt.IsZero() { if time.Time(coupon.ExpireAt).IsZero() {
_, err = q.Coupon. _, err = q.Coupon.
Where(q.Coupon.ID.Eq(coupon.ID)). Where(q.Coupon.ID.Eq(coupon.ID)).
Update(q.Coupon.Status, 1) Update(q.Coupon.Status, 1)