/***************************************************
** @Desc : c file for ...
** @Time : 2019/8/21 11:18
** @Author : yuebin
** @File : get
** @Last Modified by : yuebin
** @Last Modified time: 2019/8/21 11:18
** @Software: GoLand
****************************************************/
package controllers
import (
"boss/common"
"boss/datas"
"boss/models/accounts"
"boss/models/agent"
"boss/models/merchant"
"boss/models/notify"
"boss/models/order"
"boss/models/payfor"
"boss/models/road"
"boss/models/system"
"boss/models/user"
"fmt"
"sort"
"strconv"
"strings"
)
type GetController struct {
BaseController
DisplayCount int
CurrentPage int
TotalPage int
JumpPage int
Offset int
}
/*
* 处理分页的函数
*/
func (c *GetController) GetCutPage(l int) {
c.DisplayCount, _ = c.GetInt("displayCount")
c.CurrentPage, _ = c.GetInt("currentPage")
c.TotalPage, _ = c.GetInt("totalPage")
c.JumpPage, _ = c.GetInt("jumpPage")
if c.CurrentPage == 0 {
c.CurrentPage = 1
}
if c.DisplayCount == 0 {
c.DisplayCount = 20
}
if c.JumpPage > 0 {
c.CurrentPage = c.JumpPage
}
if l > 0 {
c.TotalPage = l / c.DisplayCount
if l%c.DisplayCount > 0 {
c.TotalPage += 1
}
} else {
c.TotalPage = 0
c.CurrentPage = 0
}
//假如当前页超过了总页数
if c.CurrentPage > c.TotalPage {
c.CurrentPage = c.TotalPage
}
//计算出偏移量
c.Offset = (c.CurrentPage - 1) * c.DisplayCount
}
func (c *GetController) GetMenu() {
firstMenuSearch := strings.TrimSpace(c.GetString("firstMenuSearch"))
params := make(map[string]string)
params["first_menu__icontains"] = firstMenuSearch
c.GetCutPage(system.GetMenuLenByMap(params))
menuDataJSON := new(datas.MenuDataJSON)
menuDataJSON.DisplayCount = c.DisplayCount
menuDataJSON.CurrentPage = c.CurrentPage
menuDataJSON.TotalPage = c.TotalPage
if c.Offset < 0 {
menuDataJSON.Code = -1
menuDataJSON.MenuList = make([]system.MenuInfo, 0)
c.GenerateJSON(menuDataJSON)
return
}
menuInfoList := system.GetMenuOffsetByMap(params, c.DisplayCount, c.Offset)
sort.Sort(system.MenuInfoSlice(menuInfoList))
for i, m := range menuInfoList {
secondMenuInfoList := system.GetSecondMenuListByFirstMenuUid(m.MenuUid)
smenus := ""
for j := 0; j < len(secondMenuInfoList); j++ {
smenus += secondMenuInfoList[j].SecondMenu
if j != (len(secondMenuInfoList) - 1) {
smenus += "||"
}
}
m.SecondMenu = smenus
menuInfoList[i] = m
}
menuDataJSON.Code = 200
menuDataJSON.MenuList = menuInfoList
menuDataJSON.StartIndex = c.Offset
if len(menuInfoList) == 0 {
menuDataJSON.Msg = "获取菜单列表失败"
}
c.GenerateJSON(menuDataJSON)
}
func (c *GetController) GetFirstMenu() {
menuDataJSON := new(datas.MenuDataJSON)
menuList := system.GetMenuAll()
if len(menuList) == 0 {
menuDataJSON.Code = -1
} else {
menuDataJSON.Code = 200
}
sort.Sort(system.MenuInfoSlice(menuList))
menuDataJSON.MenuList = menuList
c.GenerateJSON(menuDataJSON)
}
/*
*获取所有的二级菜单
*/
func (c *GetController) GetSecondMenu() {
firstMenuSearch := strings.TrimSpace(c.GetString("firstMenuSerach"))
secondMenuSearch := strings.TrimSpace(c.GetString("secondMenuSerach"))
params := make(map[string]string)
params["first_menu__icontains"] = firstMenuSearch
params["second_menu__icontains"] = secondMenuSearch
l := system.GetSecondMenuLenByMap(params)
c.GetCutPage(l)
secondMenuDataJSON := new(datas.SecondMenuDataJSON)
secondMenuDataJSON.DisplayCount = c.DisplayCount
secondMenuDataJSON.Code = 200
secondMenuDataJSON.CurrentPage = c.CurrentPage
secondMenuDataJSON.TotalPage = c.TotalPage
if c.Offset < 0 {
secondMenuDataJSON.SecondMenuList = make([]system.SecondMenuInfo, 0)
c.GenerateJSON(secondMenuDataJSON)
return
}
secondMenuList := system.GetSecondMenuByMap(params, c.DisplayCount, c.Offset)
sort.Sort(system.SecondMenuSlice(secondMenuList))
secondMenuDataJSON.SecondMenuList = secondMenuList
secondMenuDataJSON.StartIndex = c.Offset
if len(secondMenuList) == 0 {
secondMenuDataJSON.Msg = "获取二级菜单失败"
}
c.GenerateJSON(secondMenuDataJSON)
}
func (c *GetController) GetSecondMenus() {
firstMenuUid := strings.TrimSpace(c.GetString("firMenuUid"))
secondMenuDataJSON := new(datas.SecondMenuDataJSON)
secondMenuList := system.GetSecondMenuListByFirstMenuUid(firstMenuUid)
secondMenuDataJSON.Code = 200
secondMenuDataJSON.SecondMenuList = secondMenuList
c.GenerateJSON(secondMenuDataJSON)
}
func (c *GetController) GetOneMenu() {
menuUid := c.GetString("menuUid")
dataJSON := new(datas.MenuDataJSON)
menuInfo := system.GetMenuInfoByMenuUid(menuUid)
if menuInfo.MenuUid == "" {
dataJSON.Code = -1
dataJSON.Msg = "该菜单项不存在"
} else {
dataJSON.MenuList = make([]system.MenuInfo, 0)
dataJSON.MenuList = append(dataJSON.MenuList, menuInfo)
dataJSON.Code = 200
}
c.Data["json"] = dataJSON
_ = c.ServeJSONP()
}
func (c *GetController) GetPowerItem() {
powerID := c.GetString("powerID")
powerItem := c.GetString("powerItem")
params := make(map[string]string)
params["power_uid__icontains"] = powerID
params["power_item_icontains"] = powerItem
l := system.GetPowerItemLenByMap(params)
c.GetCutPage(l)
powerItemDataJSON := new(datas.PowerItemDataJSON)
powerItemDataJSON.DisplayCount = c.DisplayCount
powerItemDataJSON.Code = 200
powerItemDataJSON.CurrentPage = c.CurrentPage
powerItemDataJSON.TotalPage = c.TotalPage
if c.Offset < 0 {
powerItemDataJSON.PowerItemList = make([]system.PowerInfo, 0)
c.GenerateJSON(powerItemDataJSON)
return
}
powerItemDataJSON.StartIndex = c.Offset
powerItemList := system.GetPowerItemByMap(params, c.DisplayCount, c.Offset)
sort.Sort(system.PowerInfoSlice(powerItemList))
powerItemDataJSON.PowerItemList = powerItemList
c.GenerateJSON(powerItemDataJSON)
}
func (c *GetController) GetRole() {
roleName := strings.TrimSpace(c.GetString("roleName"))
params := make(map[string]string)
params["role_name__icontains"] = roleName
l := system.GetRoleLenByMap(params)
c.GetCutPage(l)
roleInfoDataJSON := new(datas.RoleInfoDataJSON)
roleInfoDataJSON.DisplayCount = c.DisplayCount
roleInfoDataJSON.Code = 200
roleInfoDataJSON.CurrentPage = c.CurrentPage
roleInfoDataJSON.TotalPage = c.TotalPage
if c.Offset < 0 {
roleInfoDataJSON.RoleInfoList = make([]system.RoleInfo, 0)
c.GenerateJSON(roleInfoDataJSON)
return
}
roleInfoDataJSON.StartIndex = c.Offset
roleInfoDataJSON.RoleInfoList = system.GetRoleByMap(params, c.DisplayCount, c.Offset)
c.GenerateJSON(roleInfoDataJSON)
}
func (c *GetController) GetAllRole() {
roleInfoDataJSON := new(datas.RoleInfoDataJSON)
roleInfoList := system.GetRole()
fmt.Println(roleInfoList)
if len(roleInfoList) == 0 {
roleInfoDataJSON.Code = -1
} else {
roleInfoDataJSON.Code = 200
roleInfoDataJSON.RoleInfoList = roleInfoList
}
c.GenerateJSON(roleInfoDataJSON)
}
func (c *GetController) GetDeployTree() {
roleUid := strings.TrimSpace(c.GetString("roleUid"))
roleInfo := system.GetRoleByRoleUid(roleUid)
allFirstMenu := system.GetMenuAll()
sort.Sort(system.MenuInfoSlice(allFirstMenu))
allSecondMenu := system.GetSecondMenuList()
sort.Sort(system.SecondMenuSlice(allSecondMenu))
allPower := system.GetPower()
deployTreeJSON := new(datas.DeployTreeJSON)
deployTreeJSON.Code = 200
deployTreeJSON.AllFirstMenu = allFirstMenu
deployTreeJSON.AllSecondMenu = allSecondMenu
deployTreeJSON.AllPower = allPower
deployTreeJSON.ShowFirstMenuUid = make(map[string]bool)
for _, v := range strings.Split(roleInfo.ShowFirstUid, "||") {
deployTreeJSON.ShowFirstMenuUid[v] = true
}
deployTreeJSON.ShowSecondMenuUid = make(map[string]bool)
for _, v := range strings.Split(roleInfo.ShowSecondUid, "||") {
deployTreeJSON.ShowSecondMenuUid[v] = true
}
deployTreeJSON.ShowPowerUid = make(map[string]bool)
for _, v := range strings.Split(roleInfo.ShowPowerUid, "||") {
deployTreeJSON.ShowPowerUid[v] = true
}
c.GenerateJSON(deployTreeJSON)
}
/*
* �