diff --git a/scripts/sql/fill.sql b/scripts/sql/fill.sql index 3b3a20e..eec4f71 100644 --- a/scripts/sql/fill.sql +++ b/scripts/sql/fill.sql @@ -70,7 +70,9 @@ insert into permission (parent_id, name, description, sort) values -- resource 子权限 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: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 子权限 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 ((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 - ((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:read' and deleted_at is null), 'resource:read:long:of-user', '读取指定用户的长效套餐列表', 2); + ((select id from permission where name = 'resource:short' and deleted_at is null), 'resource:short:read', '读取用户短效动态套餐列表', 1); + +-- 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 子权限 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:not-bind', '读取未绑定管理员的用户列表', 2); + ((select id from permission where name = 'user:read' and deleted_at is null), 'user:read:not_bind', '读取未绑定管理员的用户列表', 2); -- user:write 子权限 insert into permission (parent_id, name, description, sort) values @@ -127,19 +132,19 @@ insert into permission (parent_id, name, description, sort) values -- batch:read 子权限 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 子权限 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 子权限 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 子权限 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 @@ -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: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 diff --git a/web/core/scopes.go b/web/core/scopes.go index d032d28..793c7bd 100644 --- a/web/core/scopes.go +++ b/web/core/scopes.go @@ -26,16 +26,22 @@ const ( ScopeDiscountRead = string("discount:read") // 读取折扣列表 ScopeDiscountWrite = string("discount:write") // 写入折扣 - ScopeResource = string("resource") // 用户套餐 - ScopeResourceRead = string("resource:read") // 读取用户套餐列表 - ScopeResourceReadShortOfUser = string("resource:read:short:of-user") // 读取指定用户的短效套餐列表 - ScopeResourceReadLongOfUser = string("resource:read:long:of-user") // 读取指定用户的长效套餐列表 - ScopeResourceWrite = string("resource:write") // 写入用户套餐 + ScopeResource = string("resource") // 用户套餐 + ScopeResourceRead = string("resource:read") // 读取用户套餐列表 + 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") // 用户 ScopeUserRead = string("user:read") // 读取用户列表 ScopeUserReadOne = string("user:read:one") // 读取单个用户 - ScopeUserReadNotBind = string("user:read:not-bind") // 读取未绑定管理员的用户列表 + ScopeUserReadNotBind = string("user:read:not_bind") // 读取未绑定管理员的用户列表 ScopeUserWrite = string("user:write") // 写入用户 ScopeUserWriteBalance = string("user:write:balance") // 写入用户余额 ScopeUserWriteBalanceInc = string("user:write:balance:inc") // 增加用户余额 @@ -48,21 +54,21 @@ const ( ScopeBatch = string("batch") // 批次 ScopeBatchRead = string("batch:read") // 读取批次列表 - ScopeBatchReadOfUser = string("batch:read:of-user") // 读取指定用户的批次列表 + ScopeBatchReadOfUser = string("batch:read:of_user") // 读取指定用户的批次列表 ScopeBatchWrite = string("batch:write") // 写入批次 ScopeChannel = string("channel") // 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 ScopeTrade = string("trade") // 交易 ScopeTradeRead = string("trade:read") // 读取交易列表 - ScopeTradeReadOfUser = string("trade:read:of-user") // 读取指定用户的交易列表 + ScopeTradeReadOfUser = string("trade:read:of_user") // 读取指定用户的交易列表 ScopeTradeWrite = string("trade:write") // 写入交易 ScopeBill = string("bill") // 账单 ScopeBillRead = string("bill:read") // 读取账单列表 - ScopeBillReadOfUser = string("bill:read:of-user") // 读取指定用户的账单列表 + ScopeBillReadOfUser = string("bill:read:of_user") // 读取指定用户的账单列表 ScopeBillWrite = string("bill:write") // 写入账单 ) diff --git a/web/handlers/resource.go b/web/handlers/resource.go index 8febacf..efc8f56 100644 --- a/web/handlers/resource.go +++ b/web/handlers/resource.go @@ -209,7 +209,7 @@ type PageResourceLongReq struct { // PageResourceShortByAdmin 分页查询全部短效套餐 func PageResourceShortByAdmin(c *fiber.Ctx) error { - _, err := auth.GetAuthCtx(c).PermitAdmin(core.ScopeResourceRead) + _, err := auth.GetAuthCtx(c).PermitAdmin(core.ScopeResourceShortRead) if err != nil { return err } @@ -303,7 +303,7 @@ type PageResourceShortByAdminReq struct { // PageResourceLongByAdmin 分页查询全部长效套餐 func PageResourceLongByAdmin(c *fiber.Ctx) error { - _, err := auth.GetAuthCtx(c).PermitAdmin(core.ScopeResourceRead) + _, err := auth.GetAuthCtx(c).PermitAdmin(core.ScopeResourceLongRead) if err != nil { return err } @@ -395,7 +395,7 @@ type PageResourceLongByAdminReq struct { // PageResourceShortOfUserByAdmin 分页查询指定用户的短效套餐 func PageResourceShortOfUserByAdmin(c *fiber.Ctx) error { - _, err := auth.GetAuthCtx(c).PermitAdmin(core.ScopeResourceReadShortOfUser) + _, err := auth.GetAuthCtx(c).PermitAdmin(core.ScopeResourceShortReadOfUser) if err != nil { return err } @@ -466,7 +466,7 @@ type PageResourceShortOfUserByAdminReq struct { // PageResourceLongOfUserByAdmin 分页查询指定用户的长效套餐 func PageResourceLongOfUserByAdmin(c *fiber.Ctx) error { - _, err := auth.GetAuthCtx(c).PermitAdmin(core.ScopeResourceReadLongOfUser) + _, err := auth.GetAuthCtx(c).PermitAdmin(core.ScopeResourceLongReadOfUser) if err != nil { return err } diff --git a/web/services/product.go b/web/services/product.go index 9ec66c3..5b7ee66 100644 --- a/web/services/product.go +++ b/web/services/product.go @@ -13,11 +13,6 @@ var Product = &productService{} 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) { return q.Product. diff --git a/web/services/product_sku.go b/web/services/product_sku.go index 7121b58..2f7bfe7 100644 --- a/web/services/product_sku.go +++ b/web/services/product_sku.go @@ -30,7 +30,7 @@ func (s *productSkuService) Page(req *core.PageReq, productId *int32) (result [] do = append(do, q.ProductSku.ProductID.Eq(*productId)) } return q.ProductSku. - Joins(q.ProductSku.Discount). + Joins(q.ProductSku.Discount, q.ProductSku.Product). Where(do...). Order(q.ProductSku.ID). FindByPage(req.GetOffset(), req.GetLimit()) diff --git a/web/services/resource.go b/web/services/resource.go index 3068478..2a69bf5 100644 --- a/web/services/resource.go +++ b/web/services/resource.go @@ -252,13 +252,13 @@ func (data *CreateResourceData) Code() string { case data.Type == m.ResourceTypeShort && data.Short != nil: 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), ) case data.Type == m.ResourceTypeLong && data.Long != nil: 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), ) }