diff --git a/model/sca_auth_casbin_rule.go b/model/sca_auth_casbin_rule.go new file mode 100644 index 0000000..c37ff3a --- /dev/null +++ b/model/sca_auth_casbin_rule.go @@ -0,0 +1,17 @@ +package model + +// ScaAuthCasbinRule 角色/权限/用户关系表 +type ScaAuthCasbinRule struct { + Id uint64 `gorm:"column:id;type:bigint(20) unsigned;primary_key;AUTO_INCREMENT" json:"id"` + Ptype string `gorm:"column:ptype;type:varchar(100)" json:"ptype"` + V0 string `gorm:"column:v0;type:varchar(100)" json:"v0"` + V1 string `gorm:"column:v1;type:varchar(100)" json:"v1"` + V2 string `gorm:"column:v2;type:varchar(100)" json:"v2"` + V3 string `gorm:"column:v3;type:varchar(100)" json:"v3"` + V4 string `gorm:"column:v4;type:varchar(100)" json:"v4"` + V5 string `gorm:"column:v5;type:varchar(100)" json:"v5"` +} + +func (m *ScaAuthCasbinRule) TableName() string { + return "sca_auth_casbin_rule" +} diff --git a/model/sca_auth_permission.go b/model/sca_auth_permission.go index 4982e34..d15c72e 100644 --- a/model/sca_auth_permission.go +++ b/model/sca_auth_permission.go @@ -43,7 +43,7 @@ func (permission *ScaAuthPermission) UnmarshalBinary(data []byte) error { return json.Unmarshal(data, permission) } func (permission *ScaAuthPermission) BeforeCreate(tx *gorm.DB) (err error) { - userId, b := global.DB.Get("user_id") + userId, b := tx.Get("user_id") if !b { global.LOG.Error("user_id is not in global.DB") return fmt.Errorf("user_id is not in global.DB") @@ -60,7 +60,7 @@ func (permission *ScaAuthPermission) BeforeCreate(tx *gorm.DB) (err error) { } func (permission *ScaAuthPermission) BeforeUpdate(tx *gorm.DB) (err error) { - userId, b := global.DB.Get("user_id") + userId, b := tx.Get("user_id") if !b { global.LOG.Error("user_id is not in global.DB") return fmt.Errorf("user_id is not in global.DB") diff --git a/model/sca_auth_role.go b/model/sca_auth_role.go index 60027d5..2f810a5 100644 --- a/model/sca_auth_role.go +++ b/model/sca_auth_role.go @@ -36,7 +36,7 @@ func (role *ScaAuthRole) UnmarshalBinary(data []byte) error { } func (role *ScaAuthRole) BeforeCreate(tx *gorm.DB) (err error) { - userId, b := global.DB.Get("user_id") + userId, b := tx.Get("user_id") if !b { creator := "system" role.CreatedBy = &creator @@ -54,7 +54,7 @@ func (role *ScaAuthRole) BeforeCreate(tx *gorm.DB) (err error) { } func (role *ScaAuthRole) BeforeUpdate(tx *gorm.DB) (err error) { - userId, b := global.DB.Get("user_id") + userId, b := tx.Get("user_id") if !b { creator := "system" role.CreatedBy = &creator diff --git a/model/sca_auth_user.go b/model/sca_auth_user.go index 71ae7f1..b80b658 100644 --- a/model/sca_auth_user.go +++ b/model/sca_auth_user.go @@ -46,7 +46,7 @@ func (user *ScaAuthUser) UnmarshalBinary(data []byte) error { return json.Unmarshal(data, user) } func (user *ScaAuthUser) BeforeCreate(tx *gorm.DB) (err error) { - userId, b := global.DB.Get("user_id") + userId, b := tx.Get("user_id") if !b { creator := "system" user.CreatedBy = &creator @@ -64,7 +64,7 @@ func (user *ScaAuthUser) BeforeCreate(tx *gorm.DB) (err error) { } func (user *ScaAuthUser) BeforeUpdate(tx *gorm.DB) (err error) { - userId, b := global.DB.Get("user_id") + userId, b := tx.Get("user_id") if !b { creator := "system" user.CreatedBy = &creator diff --git a/model/sca_auth_user_device.go b/model/sca_auth_user_device.go index e91129a..c73a07a 100644 --- a/model/sca_auth_user_device.go +++ b/model/sca_auth_user_device.go @@ -38,7 +38,7 @@ func (*ScaAuthUserDevice) TableName() string { } func (device *ScaAuthUserDevice) BeforeUpdate(tx *gorm.DB) (err error) { - userId, b := global.DB.Get("user_id") + userId, b := tx.Get("user_id") if !b { global.LOG.Error("user_id is not found in global.DB") return fmt.Errorf("user_id is not found in global.DB") diff --git a/model/sca_auth_user_social.go b/model/sca_auth_user_social.go index 138122d..bb302b2 100644 --- a/model/sca_auth_user_social.go +++ b/model/sca_auth_user_social.go @@ -29,7 +29,7 @@ func (*ScaAuthUserSocial) TableName() string { } func (social *ScaAuthUserSocial) BeforeUpdate(tx *gorm.DB) (err error) { - userId, b := global.DB.Get("user_id") + userId, b := tx.Get("user_id") if !b { global.LOG.Error("user_id is not found in global.DB") return fmt.Errorf("user_id is not found in global.DB") diff --git a/model/sca_comment_likes.go b/model/sca_comment_likes.go new file mode 100644 index 0000000..32fd331 --- /dev/null +++ b/model/sca_comment_likes.go @@ -0,0 +1,12 @@ +package model + +// ScaCommentLikes 评论点赞表 +type ScaCommentLikes struct { + Id int64 `gorm:"column:id;type:bigint(20);primary_key" json:"id"` + UserId string `gorm:"column:user_id;type:varchar(20);comment:用户ID;NOT NULL" json:"user_id"` + CommentId int64 `gorm:"column:comment_id;type:bigint(20);comment:评论ID" json:"comment_id"` +} + +func (like *ScaCommentLikes) TableName() string { + return "sca_comment_likes" +} diff --git a/model/sca_comment_reply.go b/model/sca_comment_reply.go new file mode 100644 index 0000000..1ebcd26 --- /dev/null +++ b/model/sca_comment_reply.go @@ -0,0 +1,39 @@ +package model + +import ( + "gorm.io/gorm" + "time" +) + +// ScaCommentReply 评论表 +type ScaCommentReply struct { + Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT;comment:主键id" json:"id"` + UserId string `gorm:"column:user_id;type:varchar(20);comment:评论用户id" json:"user_id"` + TopicId string `gorm:"column:topic_id;type:varchar(20);comment:评论话题id" json:"topic_id"` + TopicType int `gorm:"column:topic_type;type:int(11);comment:话题类型" json:"topic_type"` + Content string `gorm:"column:content;type:longtext;comment:评论内容" json:"content"` + CommentType int `gorm:"column:comment_type;type:int(11);comment:评论类型 0评论 1 回复" json:"comment_type"` + ReplyId string `gorm:"column:reply_id;type:varchar(20);comment:回复目标id" json:"reply_id"` + ReplyUser string `gorm:"column:reply_user;type:varchar(20);comment:回复人id" json:"reply_user"` + Username string `gorm:"column:username;type:varchar(20);comment:评论用户昵称" json:"username"` + Avatar string `gorm:"column:avatar;type:longtext;comment:评论用户头像" json:"avatar"` + Author int `gorm:"column:author;type:int(11);comment:评论回复是否作者 0否 1是" json:"author"` + Likes int64 `gorm:"column:likes;type:bigint(20);comment:点赞数" json:"likes"` + ReplyCount int64 `gorm:"column:reply_count;type:bigint(20);comment:回复数量" json:"reply_count"` + PicUrls string `gorm:"column:pic_urls;type:longtext;comment:图片链接" json:"pic_urls"` + CreatedTime time.Time `gorm:"column:created_time;type:datetime;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_time"` + UpdateTime time.Time `gorm:"column:update_time;type:datetime;default:CURRENT_TIMESTAMP;comment:更新时间" json:"update_time"` + Deleted int `gorm:"column:deleted;type:int(11);default:0;comment:是否删除 0未删除 1 已删除" json:"deleted"` + CreatedBy string `gorm:"column:created_by;type:varchar(32);comment:创建人" json:"created_by"` + UpdateBy string `gorm:"column:update_by;type:varchar(32);comment:更新人" json:"update_by"` +} + +func (comment *ScaCommentReply) TableName() string { + return "sca_comment_reply" +} + +// BeforeCreate 创建前回调 +func (comment *ScaCommentReply) BeforeCreate(tx *gorm.DB) (err error) { + comment.CreatedBy = comment.UserId + return nil +}