feat: 实现企业卡授权和授权记录管理功能
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m9s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m9s
主要功能: - 添加企业卡授权/回收接口 (POST /enterprises/:id/allocate-cards, recall-cards) - 添加授权记录管理接口 (GET/PUT /authorizations) - 实现代理用户数据权限过滤(只能查看自己店铺下企业的授权记录) - 添加 GORM callback 支持授权记录表的数据权限过滤 技术改进: - 原生 SQL 查询手动添加数据权限过滤(ListWithJoin, GetByIDWithJoin) - 移除卡授权预检接口(allocate-cards/preview),保留内部方法 - 完善单元测试和集成测试覆盖
This commit is contained in:
@@ -7,16 +7,20 @@ import (
|
||||
)
|
||||
|
||||
// EnterpriseCardAuthorization 企业卡授权模型
|
||||
// 记录企业被授权可见的卡,卡的归属(owner)始终是代理商店铺
|
||||
// 注意:不使用 BaseModel,因为已有 AuthorizedBy/RevokedBy 字段
|
||||
type EnterpriseCardAuthorization struct {
|
||||
gorm.Model
|
||||
BaseModel `gorm:"embedded"`
|
||||
EnterpriseID uint `gorm:"column:enterprise_id;index;not null;comment:企业ID" json:"enterprise_id"`
|
||||
IotCardID uint `gorm:"column:iot_card_id;index;not null;comment:IoT卡ID" json:"iot_card_id"`
|
||||
ShopID uint `gorm:"column:shop_id;index;not null;comment:店铺ID(授权方)" json:"shop_id"`
|
||||
AuthorizedBy uint `gorm:"column:authorized_by;not null;comment:授权人ID" json:"authorized_by"`
|
||||
AuthorizedAt *time.Time `gorm:"column:authorized_at;default:now();comment:授权时间" json:"authorized_at"`
|
||||
Status int `gorm:"column:status;type:int;default:1;comment:状态 1=有效 0=已回收" json:"status"`
|
||||
ID uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"deleted_at,omitempty"`
|
||||
EnterpriseID uint `gorm:"column:enterprise_id;not null;comment:被授权企业ID" json:"enterprise_id"`
|
||||
CardID uint `gorm:"column:card_id;not null;comment:被授权卡ID" json:"card_id"`
|
||||
AuthorizedBy uint `gorm:"column:authorized_by;not null;comment:授权人账号ID" json:"authorized_by"`
|
||||
AuthorizedAt time.Time `gorm:"column:authorized_at;not null;default:CURRENT_TIMESTAMP;comment:授权时间" json:"authorized_at"`
|
||||
AuthorizerType int `gorm:"column:authorizer_type;not null;comment:授权人类型:2=平台用户 3=代理账号" json:"authorizer_type"`
|
||||
RevokedBy *uint `gorm:"column:revoked_by;comment:回收人账号ID" json:"revoked_by"`
|
||||
RevokedAt *time.Time `gorm:"column:revoked_at;comment:回收时间" json:"revoked_at"`
|
||||
Remark string `gorm:"column:remark;type:varchar(500);default:'';comment:授权备注" json:"remark"`
|
||||
}
|
||||
|
||||
func (EnterpriseCardAuthorization) TableName() string {
|
||||
|
||||
Reference in New Issue
Block a user