功能(菜单)接口
This commit is contained in:
@@ -1,10 +1,40 @@
|
|||||||
package cms
|
package cms
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetFunction(ctx *jxcontext.Context) (functions []*model.Function, err error) {
|
func GetFunction(ctx *jxcontext.Context) (functions []*model.Function, err error) {
|
||||||
return functions, err
|
return dao.GetFunction(dao.GetDB(), "", 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddFunction(ctx *jxcontext.Context, function *model.Function) (err error) {
|
||||||
|
var (
|
||||||
|
db = dao.GetDB()
|
||||||
|
)
|
||||||
|
if function == nil {
|
||||||
|
return fmt.Errorf("添加失败!function nil")
|
||||||
|
}
|
||||||
|
if function.Name == "" || function.Level == 0 {
|
||||||
|
return fmt.Errorf("添加失败!function 名称和等级必须有值!")
|
||||||
|
}
|
||||||
|
functions, err := dao.GetFunction(db, function.Name, function.Level)
|
||||||
|
if len(functions) > 0 {
|
||||||
|
return fmt.Errorf("添加失败!已存在相同名称的 fuction name : %v", function.Name)
|
||||||
|
}
|
||||||
|
dao.Begin(db)
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
dao.Rollback(db)
|
||||||
|
panic(r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
dao.WrapAddIDCULDEntity(&function, ctx.GetUserName())
|
||||||
|
err = dao.CreateEntity(db, function)
|
||||||
|
dao.Commit(db)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
27
business/model/dao/permission.go
Normal file
27
business/model/dao/permission.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package dao
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetFunction(db *DaoDB, name string, level int) (functions []*model.Function, err error) {
|
||||||
|
sql := `
|
||||||
|
SELECT *
|
||||||
|
FROM function
|
||||||
|
WHERE deleted_at = ?
|
||||||
|
`
|
||||||
|
sqlParams := []interface{}{
|
||||||
|
utils.DefaultTimeValue,
|
||||||
|
}
|
||||||
|
if name != "" {
|
||||||
|
sql += " AND name LIKE ?"
|
||||||
|
sqlParams = append(sqlParams, "%"+name+"%")
|
||||||
|
}
|
||||||
|
if level != 0 {
|
||||||
|
sql += " AND level = ?"
|
||||||
|
sqlParams = append(sqlParams, level)
|
||||||
|
}
|
||||||
|
err = GetRows(db, &functions, sql, sqlParams)
|
||||||
|
return functions, err
|
||||||
|
}
|
||||||
@@ -48,13 +48,13 @@ func GetJxShopUsers(ctx *jxcontext.Context, keyword string, offset, pageSize int
|
|||||||
sql += "LIMIT ? OFFSET ?"
|
sql += "LIMIT ? OFFSET ?"
|
||||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||||
sqlParams = append(sqlParams, pageSize, offset)
|
sqlParams = append(sqlParams, pageSize, offset)
|
||||||
for _, v := range requestList {
|
|
||||||
userMembers, _ := dao.GetUserMember(db, v.UserID, "", model.MemberTypeDiscountCard, model.YES)
|
|
||||||
v.UserMembers = userMembers
|
|
||||||
}
|
|
||||||
dao.Begin(db)
|
dao.Begin(db)
|
||||||
defer dao.Commit(db)
|
defer dao.Commit(db)
|
||||||
if err = dao.GetRows(db, &requestList, sql, sqlParams...); err == nil {
|
if err = dao.GetRows(db, &requestList, sql, sqlParams...); err == nil {
|
||||||
|
for _, v := range requestList {
|
||||||
|
userMembers, _ := dao.GetUserMember(db, v.UserID, "", model.MemberTypeDiscountCard, model.YES)
|
||||||
|
v.UserMembers = userMembers
|
||||||
|
}
|
||||||
return &model.PagedInfo{
|
return &model.PagedInfo{
|
||||||
TotalCount: dao.GetLastTotalRowCount(db),
|
TotalCount: dao.GetLastTotalRowCount(db),
|
||||||
Data: requestList,
|
Data: requestList,
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,7 +20,10 @@ type PowerController struct {
|
|||||||
// @router /AddFunction [post]
|
// @router /AddFunction [post]
|
||||||
func (c *PowerController) AddFunction() {
|
func (c *PowerController) AddFunction() {
|
||||||
c.callAddFunction(func(params *tPowerAddFunctionParams) (retVal interface{}, errCode string, err error) {
|
c.callAddFunction(func(params *tPowerAddFunctionParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
function := &model.Function{}
|
||||||
|
if err = utils.UnmarshalUseNumber([]byte(params.Payload), function); err == nil {
|
||||||
|
retVal, err = cms
|
||||||
|
}
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user