产品和权限编码格式整理优化

This commit is contained in:
2026-04-08 15:46:59 +08:00
parent 3fb3a8026f
commit 3040b10eed
6 changed files with 45 additions and 31 deletions

View File

@@ -70,7 +70,9 @@ insert into permission (parent_id, name, description, sort) values
-- resource 子权限 -- resource 子权限
insert into permission (parent_id, name, description, sort) values insert into permission (parent_id, name, description, sort) values
((select id from permission where name = 'resource' and deleted_at is null), 'resource:read', '读取用户套餐列表', 1), ((select id from permission where name = 'resource' and deleted_at is null), 'resource:read', '读取用户套餐列表', 1),
((select id from permission where name = 'resource' and deleted_at is null), 'resource:write', '写入用户套餐', 2); ((select id from permission where name = 'resource' and deleted_at is null), 'resource:write', '写入用户套餐', 2),
((select id from permission where name = 'resource' and deleted_at is null), 'resource:short', '短效动态套餐', 3),
((select id from permission where name = 'resource' and deleted_at is null), 'resource:long', '长效动态套餐', 4);
-- user 子权限 -- user 子权限
insert into permission (parent_id, name, description, sort) values insert into permission (parent_id, name, description, sort) values
@@ -110,15 +112,18 @@ insert into permission (parent_id, name, description, sort) values
insert into permission (parent_id, name, description, sort) values insert into permission (parent_id, name, description, sort) values
((select id from permission where name = 'product_sku:write' and deleted_at is null), 'product_sku:write:status', '更改产品套餐状态', 1); ((select id from permission where name = 'product_sku:write' and deleted_at is null), 'product_sku:write:status', '更改产品套餐状态', 1);
-- resource:read 子权限 -- resource:short 子权限
insert into permission (parent_id, name, description, sort) values insert into permission (parent_id, name, description, sort) values
((select id from permission where name = 'resource:read' and deleted_at is null), 'resource:read:short:of-user', '读取指定用户短效套餐列表', 1), ((select id from permission where name = 'resource:short' and deleted_at is null), 'resource:short:read', '读取用户短效动态套餐列表', 1);
((select id from permission where name = 'resource:read' and deleted_at is null), 'resource:read:long:of-user', '读取指定用户的长效套餐列表', 2);
-- resource:long 子权限
insert into permission (parent_id, name, description, sort) values
((select id from permission where name = 'resource:long' and deleted_at is null), 'resource:long:read', '读取用户长效动态套餐列表', 1);
-- user:read 子权限 -- user:read 子权限
insert into permission (parent_id, name, description, sort) values insert into permission (parent_id, name, description, sort) values
((select id from permission where name = 'user:read' and deleted_at is null), 'user:read:one', '读取单个用户', 1), ((select id from permission where name = 'user:read' and deleted_at is null), 'user:read:one', '读取单个用户', 1),
((select id from permission where name = 'user:read' and deleted_at is null), 'user:read:not-bind', '读取未绑定管理员的用户列表', 2); ((select id from permission where name = 'user:read' and deleted_at is null), 'user:read:not_bind', '读取未绑定管理员的用户列表', 2);
-- user:write 子权限 -- user:write 子权限
insert into permission (parent_id, name, description, sort) values insert into permission (parent_id, name, description, sort) values
@@ -127,19 +132,19 @@ insert into permission (parent_id, name, description, sort) values
-- batch:read 子权限 -- batch:read 子权限
insert into permission (parent_id, name, description, sort) values insert into permission (parent_id, name, description, sort) values
((select id from permission where name = 'batch:read' and deleted_at is null), 'batch:read:of-user', '读取指定用户的批次列表', 1); ((select id from permission where name = 'batch:read' and deleted_at is null), 'batch:read:of_user', '读取指定用户的批次列表', 1);
-- channel:read 子权限 -- channel:read 子权限
insert into permission (parent_id, name, description, sort) values insert into permission (parent_id, name, description, sort) values
((select id from permission where name = 'channel:read' and deleted_at is null), 'channel:read:of-user', '读取指定用户的 IP 列表', 1); ((select id from permission where name = 'channel:read' and deleted_at is null), 'channel:read:of_user', '读取指定用户的 IP 列表', 1);
-- trade:read 子权限 -- trade:read 子权限
insert into permission (parent_id, name, description, sort) values insert into permission (parent_id, name, description, sort) values
((select id from permission where name = 'trade:read' and deleted_at is null), 'trade:read:of-user', '读取指定用户的交易列表', 1); ((select id from permission where name = 'trade:read' and deleted_at is null), 'trade:read:of_user', '读取指定用户的交易列表', 1);
-- bill:read 子权限 -- bill:read 子权限
insert into permission (parent_id, name, description, sort) values insert into permission (parent_id, name, description, sort) values
((select id from permission where name = 'bill:read' and deleted_at is null), 'bill:read:of-user', '读取指定用户的账单列表', 1); ((select id from permission where name = 'bill:read' and deleted_at is null), 'bill:read:of_user', '读取指定用户的账单列表', 1);
-- -------------------------- -- --------------------------
-- level 4 -- level 4
@@ -150,4 +155,12 @@ insert into permission (parent_id, name, description, sort) values
((select id from permission where name = 'user:write:balance' and deleted_at is null), 'user:write:balance:inc', '增加用户余额', 1), ((select id from permission where name = 'user:write:balance' and deleted_at is null), 'user:write:balance:inc', '增加用户余额', 1),
((select id from permission where name = 'user:write:balance' and deleted_at is null), 'user:write:balance:dec', '减少用户余额', 2); ((select id from permission where name = 'user:write:balance' and deleted_at is null), 'user:write:balance:dec', '减少用户余额', 2);
-- resource:short:read 子权限
insert into permission (parent_id, name, description, sort) values
((select id from permission where name = 'resource:short:read' and deleted_at is null), 'resource:short:read:of_user', '读取指定用户的短效动态套餐列表', 1);
-- resource:long:read 子权限
insert into permission (parent_id, name, description, sort) values
((select id from permission where name = 'resource:long:read' and deleted_at is null), 'resource:long:read:of_user', '读取指定用户的长效动态套餐列表', 1);
-- endregion -- endregion

View File

@@ -26,16 +26,22 @@ const (
ScopeDiscountRead = string("discount:read") // 读取折扣列表 ScopeDiscountRead = string("discount:read") // 读取折扣列表
ScopeDiscountWrite = string("discount:write") // 写入折扣 ScopeDiscountWrite = string("discount:write") // 写入折扣
ScopeResource = string("resource") // 用户套餐 ScopeResource = string("resource") // 用户套餐
ScopeResourceRead = string("resource:read") // 读取用户套餐列表 ScopeResourceRead = string("resource:read") // 读取用户套餐列表
ScopeResourceReadShortOfUser = string("resource:read:short:of-user") // 读取指定用户的短效套餐列表 ScopeResourceWrite = string("resource:write") // 写入用户套餐
ScopeResourceReadLongOfUser = string("resource:read:long:of-user") // 读取指定用户的长效套餐列表
ScopeResourceWrite = string("resource:write") // 写入用户套餐 ScopeResourceShort = string("resource:short") // 短效动态套餐
ScopeResourceShortRead = string("resource:short:read") // 读取用户短效动态套餐列表
ScopeResourceShortReadOfUser = string("resource:short:read:of_user") // 读取指定用户的短效动态套餐列表
ScopeResourceLong = string("resource:long") // 长效动态套餐
ScopeResourceLongRead = string("resource:long:read") // 读取用户长效动态套餐列表
ScopeResourceLongReadOfUser = string("resource:long:read:of_user") // 读取指定用户的长效动态套餐列表
ScopeUser = string("user") // 用户 ScopeUser = string("user") // 用户
ScopeUserRead = string("user:read") // 读取用户列表 ScopeUserRead = string("user:read") // 读取用户列表
ScopeUserReadOne = string("user:read:one") // 读取单个用户 ScopeUserReadOne = string("user:read:one") // 读取单个用户
ScopeUserReadNotBind = string("user:read:not-bind") // 读取未绑定管理员的用户列表 ScopeUserReadNotBind = string("user:read:not_bind") // 读取未绑定管理员的用户列表
ScopeUserWrite = string("user:write") // 写入用户 ScopeUserWrite = string("user:write") // 写入用户
ScopeUserWriteBalance = string("user:write:balance") // 写入用户余额 ScopeUserWriteBalance = string("user:write:balance") // 写入用户余额
ScopeUserWriteBalanceInc = string("user:write:balance:inc") // 增加用户余额 ScopeUserWriteBalanceInc = string("user:write:balance:inc") // 增加用户余额
@@ -48,21 +54,21 @@ const (
ScopeBatch = string("batch") // 批次 ScopeBatch = string("batch") // 批次
ScopeBatchRead = string("batch:read") // 读取批次列表 ScopeBatchRead = string("batch:read") // 读取批次列表
ScopeBatchReadOfUser = string("batch:read:of-user") // 读取指定用户的批次列表 ScopeBatchReadOfUser = string("batch:read:of_user") // 读取指定用户的批次列表
ScopeBatchWrite = string("batch:write") // 写入批次 ScopeBatchWrite = string("batch:write") // 写入批次
ScopeChannel = string("channel") // IP ScopeChannel = string("channel") // IP
ScopeChannelRead = string("channel:read") // 读取 IP 列表 ScopeChannelRead = string("channel:read") // 读取 IP 列表
ScopeChannelReadOfUser = string("channel:read:of-user") // 读取指定用户的 IP 列表 ScopeChannelReadOfUser = string("channel:read:of_user") // 读取指定用户的 IP 列表
ScopeChannelWrite = string("channel:write") // 写入 IP ScopeChannelWrite = string("channel:write") // 写入 IP
ScopeTrade = string("trade") // 交易 ScopeTrade = string("trade") // 交易
ScopeTradeRead = string("trade:read") // 读取交易列表 ScopeTradeRead = string("trade:read") // 读取交易列表
ScopeTradeReadOfUser = string("trade:read:of-user") // 读取指定用户的交易列表 ScopeTradeReadOfUser = string("trade:read:of_user") // 读取指定用户的交易列表
ScopeTradeWrite = string("trade:write") // 写入交易 ScopeTradeWrite = string("trade:write") // 写入交易
ScopeBill = string("bill") // 账单 ScopeBill = string("bill") // 账单
ScopeBillRead = string("bill:read") // 读取账单列表 ScopeBillRead = string("bill:read") // 读取账单列表
ScopeBillReadOfUser = string("bill:read:of-user") // 读取指定用户的账单列表 ScopeBillReadOfUser = string("bill:read:of_user") // 读取指定用户的账单列表
ScopeBillWrite = string("bill:write") // 写入账单 ScopeBillWrite = string("bill:write") // 写入账单
) )

View File

@@ -209,7 +209,7 @@ type PageResourceLongReq struct {
// PageResourceShortByAdmin 分页查询全部短效套餐 // PageResourceShortByAdmin 分页查询全部短效套餐
func PageResourceShortByAdmin(c *fiber.Ctx) error { func PageResourceShortByAdmin(c *fiber.Ctx) error {
_, err := auth.GetAuthCtx(c).PermitAdmin(core.ScopeResourceRead) _, err := auth.GetAuthCtx(c).PermitAdmin(core.ScopeResourceShortRead)
if err != nil { if err != nil {
return err return err
} }
@@ -303,7 +303,7 @@ type PageResourceShortByAdminReq struct {
// PageResourceLongByAdmin 分页查询全部长效套餐 // PageResourceLongByAdmin 分页查询全部长效套餐
func PageResourceLongByAdmin(c *fiber.Ctx) error { func PageResourceLongByAdmin(c *fiber.Ctx) error {
_, err := auth.GetAuthCtx(c).PermitAdmin(core.ScopeResourceRead) _, err := auth.GetAuthCtx(c).PermitAdmin(core.ScopeResourceLongRead)
if err != nil { if err != nil {
return err return err
} }
@@ -395,7 +395,7 @@ type PageResourceLongByAdminReq struct {
// PageResourceShortOfUserByAdmin 分页查询指定用户的短效套餐 // PageResourceShortOfUserByAdmin 分页查询指定用户的短效套餐
func PageResourceShortOfUserByAdmin(c *fiber.Ctx) error { func PageResourceShortOfUserByAdmin(c *fiber.Ctx) error {
_, err := auth.GetAuthCtx(c).PermitAdmin(core.ScopeResourceReadShortOfUser) _, err := auth.GetAuthCtx(c).PermitAdmin(core.ScopeResourceShortReadOfUser)
if err != nil { if err != nil {
return err return err
} }
@@ -466,7 +466,7 @@ type PageResourceShortOfUserByAdminReq struct {
// PageResourceLongOfUserByAdmin 分页查询指定用户的长效套餐 // PageResourceLongOfUserByAdmin 分页查询指定用户的长效套餐
func PageResourceLongOfUserByAdmin(c *fiber.Ctx) error { func PageResourceLongOfUserByAdmin(c *fiber.Ctx) error {
_, err := auth.GetAuthCtx(c).PermitAdmin(core.ScopeResourceReadLongOfUser) _, err := auth.GetAuthCtx(c).PermitAdmin(core.ScopeResourceLongReadOfUser)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -13,11 +13,6 @@ var Product = &productService{}
type productService struct{} type productService struct{}
// 获取产品价格
func (s *productService) GetPrice(code string) {
q.ProductSku.Where(q.ProductSku.Code.Eq(code)).Find()
}
// 获取所有产品 // 获取所有产品
func (s *productService) AllProducts() ([]*m.Product, error) { func (s *productService) AllProducts() ([]*m.Product, error) {
return q.Product. return q.Product.

View File

@@ -30,7 +30,7 @@ func (s *productSkuService) Page(req *core.PageReq, productId *int32) (result []
do = append(do, q.ProductSku.ProductID.Eq(*productId)) do = append(do, q.ProductSku.ProductID.Eq(*productId))
} }
return q.ProductSku. return q.ProductSku.
Joins(q.ProductSku.Discount). Joins(q.ProductSku.Discount, q.ProductSku.Product).
Where(do...). Where(do...).
Order(q.ProductSku.ID). Order(q.ProductSku.ID).
FindByPage(req.GetOffset(), req.GetLimit()) FindByPage(req.GetOffset(), req.GetLimit())

View File

@@ -252,13 +252,13 @@ func (data *CreateResourceData) Code() string {
case data.Type == m.ResourceTypeShort && data.Short != nil: case data.Type == m.ResourceTypeShort && data.Short != nil:
return fmt.Sprintf( return fmt.Sprintf(
"mode=%s,live=%d,expire=%d", "mode=%s&live=%d&expire=%d",
data.Short.Mode.Code(), data.Short.Live, u.Else(data.Short.Expire, 0), data.Short.Mode.Code(), data.Short.Live, u.Else(data.Short.Expire, 0),
) )
case data.Type == m.ResourceTypeLong && data.Long != nil: case data.Type == m.ResourceTypeLong && data.Long != nil:
return fmt.Sprintf( return fmt.Sprintf(
"mode=%s,live=%d,expire=%d", "mode=%s&live=%d&expire=%d",
data.Long.Mode.Code(), data.Long.Live, u.Else(data.Long.Expire, 0), data.Long.Mode.Code(), data.Long.Live, u.Else(data.Long.Expire, 0),
) )
} }