workDesktop.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. package entity
  2. import (
  3. "database/sql"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "sort"
  8. "strconv"
  9. "strings"
  10. MC "app.yhyue.com/moapp/jybase/common"
  11. "app.yhyue.com/moapp/jybase/encrypt"
  12. "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
  13. "github.com/zeromicro/go-zero/core/logx"
  14. )
  15. // WorkDesktopMenu 工作桌面菜单信息
  16. type WorkDesktopMenu struct {
  17. MenuTree []*JYMenu //菜单
  18. UserId string //用户id
  19. NewUserId int64 //base_userid
  20. EntId int64 //企业id
  21. EntUserId int64 //企业用户id
  22. AppId string //appid 剑鱼:10000
  23. IntranetBool bool //是否开启内网访问模式
  24. Platform string //平台来源
  25. WorkStatus int64 //菜单分组
  26. AccountId int64 //账户id
  27. EntAccountId int64 //企业账户id
  28. PositionType int64 //职位类型 0:个人 1:企业
  29. PositionId int64 //职位id
  30. MgoUserId string //原mongo userId -- p278
  31. }
  32. // JYMenu 工作桌面菜单内容
  33. type JYMenu struct {
  34. Id int
  35. Name string //菜单名称
  36. Match string //滤镜过滤正则
  37. OrderId int //菜单排序id
  38. ParentId int //父级id
  39. PowerIds string //权限id
  40. CheckCode int //是否必须验证权限才显示菜单
  41. Url string //菜单跳转链接
  42. Icon string //菜单图标
  43. AdditionalInfo Additional //附加弹窗信息
  44. AppType string //菜单模式
  45. OpenType string //打开方式
  46. Status int //是否是可用服务
  47. PermissionCode string //功能代码
  48. CapitalCode string //留资代码
  49. CapitalInfo Additional //留资弹窗
  50. Children []*JYMenu //菜单s
  51. Authority int //权限逻辑备注 默认0:功能权限、资源权限、留资权限必须全部满足;1:功能权限或资源权限或留资权限满足其一就行;
  52. Level int //1:一级菜单;2:二级菜单;3:三级菜单;4:四级菜单
  53. }
  54. type Additional struct {
  55. Title string `json:"title"` //弹窗标题
  56. Content string `json:"content"` //弹窗提示信息
  57. ConfirmUrl string `json:"confirmUrl,optional"` //确认按钮跳转地址
  58. ConfirmText string `json:"confirmText,optional"` //确认按钮
  59. IsShowCancel bool `json:"isShowCancel,optional"` //是否显示取消按钮
  60. AppType string `json:"appType,optional,omitempty"` //跳转方式
  61. OpenType string `json:"openType,optional,omitempty"`
  62. }
  63. // GetMenuTreeData 获取有效菜单数据
  64. func (m *WorkDesktopMenu) GetMenuTreeData() error {
  65. //P278 身份切换
  66. positionType := ``
  67. switch m.PositionType { //职位类型 0:个人 1:企业
  68. case 0:
  69. positionType = `AND available <= 2`
  70. case 1:
  71. positionType = `AND available >= 2`
  72. }
  73. //tidb数据
  74. query := fmt.Sprintf(`SELECT * FROM `+ConfigJson.WorkTableOut+` WHERE appid=? AND status=%d %s ORDER BY id ASC`, m.WorkStatus, positionType)
  75. //是否开启内网访问数据权限---对应 api 配置文件
  76. if m.IntranetBool {
  77. query = fmt.Sprintf(`SELECT * FROM `+ConfigJson.WorkTableInside+` WHERE appid=? AND status>=0 %s ORDER BY id ASC`, positionType)
  78. }
  79. logx.Info("query:", query)
  80. menuData := BaseMysql.SelectBySql(query, m.AppId)
  81. if menuData == nil || len(*menuData) == 0 {
  82. return errors.New("查询数据异常")
  83. }
  84. for _, v := range *menuData {
  85. menu := &JYMenu{
  86. Id: MC.IntAll(v["id"]),
  87. Name: MC.ObjToString(v["name"]),
  88. Match: MC.ObjToString(v["match"]),
  89. OrderId: MC.IntAll(v["orderid"]),
  90. ParentId: MC.IntAll(v["parentid"]),
  91. PowerIds: MC.ObjToString(v["powerids"]),
  92. CheckCode: MC.IntAll(v["checkcode"]),
  93. Icon: MC.ObjToString(v["icon"]),
  94. AppType: MC.ObjToString(v["apptype"]),
  95. OpenType: MC.ObjToString(v["opentype"]),
  96. Status: MC.IntAll(v["status"]),
  97. PermissionCode: MC.ObjToString(v["permissioncode"]),
  98. CapitalCode: MC.ObjToString(v["capitalcode"]),
  99. Authority: MC.IntAll(v["authority"]),
  100. }
  101. var OpenType = map[string]string{}
  102. if err := json.Unmarshal([]byte(MC.ObjToString(v["opentype"])), &OpenType); err == nil {
  103. menu.OpenType = OpenType[m.Platform]
  104. }
  105. switch m.Platform {
  106. case "WX":
  107. menu.Url = MC.ObjToString(v["wxurl"])
  108. menu.PowerIds = MC.ObjToString(v["wxpids"])
  109. case "APP":
  110. menu.Url = MC.ObjToString(v["appurl"])
  111. menu.PowerIds = MC.ObjToString(v["apppids"])
  112. default:
  113. menu.Url = MC.ObjToString(v["pcurl"])
  114. }
  115. //菜单(移动端)是否需要显示:PC端菜单不需要在移动端显示;或移动端菜单不需要在PC端显示。
  116. if menu.Url == "-1" {
  117. continue
  118. }
  119. if additionalInfo := MC.ObjToString(v["additionalinfo"]); additionalInfo != "" {
  120. additional := Additional{}
  121. if json.Unmarshal([]byte(additionalInfo), &additional) == nil {
  122. menu.AdditionalInfo = additional
  123. }
  124. }
  125. if capitalInfo := MC.ObjToString(v["capitalinfo"]); capitalInfo != "" {
  126. additional := Additional{}
  127. if json.Unmarshal([]byte(capitalInfo), &additional) == nil {
  128. menu.CapitalInfo = additional
  129. }
  130. }
  131. if menu.Id > 0 {
  132. m.MenuTree = append(m.MenuTree, menu)
  133. }
  134. }
  135. return nil
  136. }
  137. // WorkMenuTree 菜单-格式化-tree
  138. func (m *WorkDesktopMenu) WorkMenuTree(parentId int) (jyMenu []*JYMenu) {
  139. jyMenu = make([]*JYMenu, 0)
  140. for _, mv := range m.MenuTree {
  141. if mv.ParentId == parentId {
  142. mv.Children = m.WorkMenuTree(mv.Id)
  143. sort.SliceStable(mv.Children, func(i, j int) bool {
  144. return mv.Children[i].OrderId < mv.Children[j].OrderId
  145. })
  146. jyMenu = append(jyMenu, mv)
  147. }
  148. }
  149. sort.SliceStable(jyMenu, func(i, j int) bool {
  150. return jyMenu[i].OrderId < jyMenu[j].OrderId
  151. })
  152. return
  153. }
  154. // WorkMenuFormat 菜单 格式化
  155. func (m *WorkDesktopMenu) WorkMenuFormat() ([]*pb.MenuList, error) {
  156. //logx.Info("树的长度:", len(m.MenuTree))
  157. menuList := make([]*pb.MenuList, 0)
  158. for _, mv := range m.MenuTree {
  159. //if mv.Id < 466 {
  160. // continue
  161. //}
  162. //0:默认展示;1:需验证权限,有权限展示;2:需验证权限,无权限也可展示(可用服务无权限不展示)
  163. usable := m.VerifyPermissions(mv.PowerIds)
  164. //checkCode==1 验证权限结果 无权限不显示
  165. if !usable && mv.CheckCode == 1 {
  166. continue
  167. }
  168. //GetResources(m.AppId, m.NewUserId, m.EntId, m.EntUserId)
  169. oneLevel := &pb.MenuList{
  170. Name: mv.Name,
  171. Icon: mv.Icon,
  172. Url: mv.Url,
  173. Id: encrypt.SE.EncodeString(strconv.Itoa(mv.Id)), //功能id加密
  174. Usable: usable, //MC.If(mv.PowerIds != "", usable && mv.CheckCode == 1, true).(bool),
  175. AppType: mv.AppType,
  176. OpenType: mv.OpenType,
  177. Child: []*pb.SecondLevelMenu{},
  178. TipInfo: &pb.TipInfo{
  179. Title: mv.AdditionalInfo.Title,
  180. Content: mv.AdditionalInfo.Content,
  181. ConfirmUrl: mv.AdditionalInfo.ConfirmUrl,
  182. ConfirmText: mv.AdditionalInfo.ConfirmText,
  183. IsShowCancel: mv.AdditionalInfo.IsShowCancel,
  184. AppType: mv.AdditionalInfo.AppType,
  185. OpenType: mv.AdditionalInfo.OpenType,
  186. },
  187. Match: MC.If(mv.Match != "", strings.Split(mv.Match, ","), []string{}).([]string),
  188. }
  189. if len(mv.Children) > 0 {
  190. for _, sv := range mv.Children {
  191. //0:默认展示;1:需验证权限,有权限展示;2:需验证权限,无权限也可展示(可用服务无权限不展示)
  192. usable := m.VerifyPermissions(sv.PowerIds)
  193. //checkCode==1 验证权限结果 无权限不显示
  194. if !usable && sv.CheckCode == 1 {
  195. continue
  196. }
  197. secondLevel := &pb.SecondLevelMenu{
  198. Name: sv.Name,
  199. Icon: sv.Icon,
  200. Url: sv.Url,
  201. Id: encrypt.SE.EncodeString(strconv.Itoa(sv.Id)), //功能id加密
  202. Usable: usable, //MC.If(sv.PowerIds != "", usable && sv.CheckCode == 1, true).(bool),
  203. Child: []*pb.ThreeLevelMenu{},
  204. AppType: sv.AppType,
  205. OpenType: sv.OpenType,
  206. TipInfo: &pb.TipInfo{
  207. Title: sv.AdditionalInfo.Title,
  208. Content: sv.AdditionalInfo.Content,
  209. ConfirmUrl: sv.AdditionalInfo.ConfirmUrl,
  210. ConfirmText: sv.AdditionalInfo.ConfirmText,
  211. IsShowCancel: sv.AdditionalInfo.IsShowCancel,
  212. AppType: sv.AdditionalInfo.AppType,
  213. OpenType: sv.AdditionalInfo.OpenType,
  214. },
  215. Match: MC.If(sv.Match != "", strings.Split(sv.Match, ","), []string{}).([]string),
  216. }
  217. if len(sv.Children) > 0 {
  218. for _, tv := range sv.Children {
  219. //附件下载包、采购单位画像记录、企业画像记录 如果是大会员 排除此三项菜单
  220. //灵活性降低
  221. if (strings.Contains(tv.Name, "附件下载包") && m.VerifyPermissions("3")) || (tv.Name == "采购单位画像记录" && m.VerifyPermissions("5")) || (tv.Name == "企业画像记录" && m.VerifyPermissions("4,12,13,19,20,21,23")) {
  222. continue
  223. }
  224. //0:默认展示;1:需验证权限,有权限展示;2:需验证权限,无权限也可展示(可用服务无权限不展示)
  225. usable := m.VerifyPermissions(tv.PowerIds)
  226. //checkCode==1 验证权限结果 无权限不显示
  227. if !usable && tv.CheckCode == 1 {
  228. continue
  229. }
  230. var (
  231. //数据库默认提示弹窗信息
  232. title, content, confirmUrl, confirmText, isShowCancel, appType, openType, feasibility = tv.AdditionalInfo.Title, tv.AdditionalInfo.Content, tv.AdditionalInfo.ConfirmUrl, tv.AdditionalInfo.ConfirmText, tv.AdditionalInfo.IsShowCancel, tv.AdditionalInfo.AppType, tv.AdditionalInfo.OpenType, usable
  233. )
  234. //三级菜单------
  235. if len(tv.Children) == 0 && (tv.CapitalCode != "" || tv.PermissionCode != "") {
  236. //用户是否需要留资
  237. //资源中台获取用户权限--没有权限:title等置空
  238. //ResourceLib.PowerHandle()
  239. title, content, confirmUrl, confirmText, appType, openType, isShowCancel, feasibility = CheckCapitalResources(tv, m, usable, m.VerifyPermissions(tv.PermissionCode))
  240. }
  241. threeLevel := &pb.ThreeLevelMenu{
  242. Name: tv.Name,
  243. Icon: tv.Icon,
  244. Url: tv.Url,
  245. Id: encrypt.SE.EncodeString(strconv.Itoa(tv.Id)), //功能id加密
  246. Usable: feasibility, //MC.If(tv.PowerIds != "", usable && tv.CheckCode == 1, true).(bool),
  247. AppType: tv.AppType,
  248. OpenType: tv.OpenType,
  249. TipInfo: &pb.TipInfo{
  250. Title: title,
  251. Content: content,
  252. ConfirmUrl: confirmUrl,
  253. ConfirmText: confirmText,
  254. IsShowCancel: isShowCancel,
  255. AppType: appType,
  256. OpenType: openType,
  257. },
  258. Match: MC.If(tv.Match != "", strings.Split(tv.Match, ","), []string{}).([]string),
  259. }
  260. if len(tv.Children) > 0 {
  261. L:
  262. for _, fv := range tv.Children {
  263. if fv.Name == "" {
  264. continue
  265. }
  266. if fv.CapitalCode != "" || fv.PermissionCode != "" {
  267. //用户是否需要留资
  268. //资源中台获取用户权限--没有权限:title等置空
  269. //ResourceLib.PowerHandle()
  270. //判断资源中台权限
  271. title, content, confirmUrl, confirmText, appType, openType, isShowCancel, feasibility = CheckCapitalResources(fv, m, usable, m.VerifyPermissions(fv.PermissionCode))
  272. }
  273. threeLevel.Url = MC.If(fv.Url != "", fv.Url, tv.Url).(string)
  274. threeLevel.Icon = MC.If(fv.Icon != "", fv.Icon, tv.Icon).(string)
  275. threeLevel.AppType = fv.AppType
  276. threeLevel.OpenType = fv.OpenType
  277. threeLevel.Usable = feasibility
  278. if title != "" {
  279. threeLevel.TipInfo = &pb.TipInfo{
  280. Title: title,
  281. Content: content,
  282. ConfirmUrl: confirmUrl,
  283. ConfirmText: confirmText,
  284. IsShowCancel: isShowCancel,
  285. AppType: appType,
  286. OpenType: openType,
  287. }
  288. }
  289. threeLevel.Match = MC.If(fv.Match != "", strings.Split(fv.Match, ","), []string{}).([]string)
  290. //四级菜单必须有顺序性,大会员》商机管理》超级订阅》免费用户
  291. name := MC.If(strings.Contains(fv.Name, "-"), strings.Split(fv.Name, "-")[0], "免费").(string)
  292. if len(UserRolePowers[name]) > 0 && m.VerifyPermissions(strings.Join(UserRolePowers[name], ",")) && m.VerifyPermissions(fv.PowerIds) {
  293. break L
  294. }
  295. }
  296. }
  297. //无资源中台权限 菜单不显示
  298. if !feasibility && tv.CheckCode == 1 {
  299. continue
  300. }
  301. if threeLevel != nil {
  302. secondLevel.Child = append(secondLevel.Child, threeLevel)
  303. }
  304. }
  305. }
  306. //二级菜单 有三级子菜单;才会显示
  307. if len(secondLevel.Child) == 0 && sv.CheckCode == 1 {
  308. continue
  309. }
  310. oneLevel.Child = append(oneLevel.Child, secondLevel)
  311. }
  312. }
  313. //一级菜单 有二级子菜单;才会显示
  314. if len(oneLevel.Child) == 0 && mv.CheckCode == 1 {
  315. continue
  316. }
  317. menuList = append(menuList, oneLevel)
  318. }
  319. //清用户内存信息
  320. func(baseUserid int64) {
  321. OverallLock.Lock()
  322. defer OverallLock.Unlock()
  323. userInfo := UserInfoMap[baseUserid]
  324. if userInfo != nil {
  325. userInfo.Lock.Lock()
  326. defer userInfo.Lock.Unlock()
  327. userInfo.Permissions = map[string]int{}
  328. userInfo.Capitals = map[string]int{}
  329. }
  330. }(m.NewUserId)
  331. //bytes, _ := json.MarshalIndent(menuList, "", " ")
  332. //fmt.Printf("%s\n", bytes)
  333. return menuList, nil
  334. }
  335. // VerifyPermissions 是否有权限可用此服务
  336. func (m *WorkDesktopMenu) VerifyPermissions(powerIds string) (b bool) {
  337. if powerIds == "" {
  338. return true
  339. }
  340. if len(strings.Split(powerIds, ",")) > 0 {
  341. userPower := m.AutoUserPowerInfo() //m.TimeOut, m.BigMemberOff,
  342. func(powerIds string) {
  343. for _, pv := range strings.Split(powerIds, ",") {
  344. if userPower[pv] > 0 {
  345. b = true
  346. break
  347. }
  348. }
  349. }(powerIds)
  350. }
  351. return
  352. }
  353. // WorkCommonly 常用功能
  354. var (
  355. WorkCommonly = "work_commonly"
  356. //WorkMenu = "work_menu"
  357. )
  358. // CommonlyUpdate 更新常用功能
  359. func CommonlyUpdate(in *pb.WorkDesktopComprehensiveReq) (B bool, M string) {
  360. //事务 1:查; 2: 存;3: 删;
  361. var (
  362. ids []string
  363. mk int
  364. )
  365. for _, mid := range strings.Split(in.MenuIds, ",") {
  366. if mid == "" {
  367. continue
  368. }
  369. mk++
  370. //常用功能数量限制
  371. if ConfigJson.CommonlySize > 0 && mk >= int(ConfigJson.CommonlySize) {
  372. break
  373. }
  374. //id 解密
  375. ids = append(ids, encrypt.SE.DecodeString(mid))
  376. }
  377. //更新此用户设置的常用功能
  378. if B = BaseMysql.ExecTx("常用功能批量更新", func(tx *sql.Tx) bool {
  379. //查询此用户常用功能是否已存在记录
  380. var (
  381. id = 0
  382. existingData *[]map[string]interface{}
  383. )
  384. //P278 身份切换 常用功能和职业id 绑定
  385. existingData = BaseMysql.SelectBySqlByTx(tx, `SELECT id FROM `+WorkCommonly+` WHERE base_userid = ? AND appid = ? AND field = ? AND userid = ? ORDER BY id DESC `, in.NewUserId, in.AppId, in.ActionMode, in.UserId)
  386. if existingData != nil && len(*existingData) > 0 {
  387. id = MC.IntAll((*existingData)[0]["id"])
  388. //} else {
  389. // //P278 之前版本查询逻辑
  390. // existingData = BaseMysql.SelectBySqlByTx(tx, `SELECT id FROM `+WorkCommonly+` WHERE base_userid = ? AND appid = ? AND field = ? ORDER BY id DESC `, in.NewUserId, in.AppId, in.ActionMode)
  391. // if existingData != nil && len(*existingData) > 0 {
  392. // id = MC.IntAll((*existingData)[0]["id"])
  393. // }
  394. }
  395. switch {
  396. case id > 0: //更新
  397. if BaseMysql.UpdateOrDeleteBySqlByTx(tx, `UPDATE `+WorkCommonly+` SET value = ?,userid = ? WHERE id = ?`, strings.Join(ids, ","), in.UserId, id) < 0 {
  398. logx.Info("常用功能-更新数据失败")
  399. return false
  400. }
  401. default: //插入
  402. if BaseMysql.InsertBySqlByTx(tx, `INSERT INTO `+WorkCommonly+` (appid,base_userid,platform,field,value,userid) VALUES (?,?,?,?,?,?)`, in.AppId, in.NewUserId, in.Platform, in.ActionMode, strings.Join(ids, ","), in.UserId) < 0 {
  403. logx.Info("常用功能-插入数据失败")
  404. return false
  405. }
  406. }
  407. return true
  408. }); !B {
  409. M = "常用功能更新数据失败"
  410. }
  411. return
  412. }
  413. // CommonlyFormat 常用功能 格式化
  414. func (m *WorkDesktopMenu) CommonlyFormat(childMenus map[int][]*JYMenu) ([]*pb.ThreeLevelMenu, []string, bool) {
  415. menuList := make([]*pb.ThreeLevelMenu, 0)
  416. subLevel := map[int]bool{}
  417. delBool := false //更新因超级订阅用户,又购买大会员得用户 导致附件下载包||采购单位画像记录||企业画像记录 不应该展示
  418. var saveIds []string
  419. for _, mv := range m.MenuTree {
  420. //三级菜单已处理,子级四级菜单不再处理
  421. //过滤子级 ++
  422. if subLevel[mv.ParentId] {
  423. continue
  424. }
  425. //三级下架菜单:mv.Status == 1
  426. if mv.Status == 1 {
  427. delBool = true
  428. continue
  429. }
  430. //附件下载包、采购单位画像记录、企业画像记录 如果是大会员 排除此三项菜单
  431. //灵活性降低
  432. if (mv.Name == "附件下载包" && m.VerifyPermissions("3")) || (mv.Name == "采购单位画像记录" && m.VerifyPermissions("5")) || (mv.Name == "企业画像记录" && m.VerifyPermissions("4,12,13,19,20,21,23")) {
  433. delBool = true
  434. continue
  435. }
  436. saveIds = append(saveIds, encrypt.SE.EncodeString(strconv.Itoa(mv.Id)))
  437. subLevel[mv.Id] = true
  438. //0:默认展示;1:需验证权限,有权限展示;2:需验证权限,无权限也可展示(可用服务无权限不展示)
  439. usable := m.VerifyPermissions(mv.PowerIds)
  440. feasibility := usable
  441. //三级菜单------
  442. if len(childMenus[mv.Id]) == 0 && (mv.CapitalCode != "" || mv.PermissionCode != "") {
  443. _, _, _, _, _, _, _, feasibility = CheckCapitalResources(mv, m, usable, m.VerifyPermissions(mv.PermissionCode))
  444. }
  445. oneLevel := &pb.ThreeLevelMenu{
  446. Name: mv.Name,
  447. Icon: mv.Icon,
  448. Url: mv.Url,
  449. Id: encrypt.SE.EncodeString(strconv.Itoa(mv.Id)), //功能id加密
  450. Usable: feasibility, //MC.If(mv.PowerIds != "", usable && mv.CheckCode == 1, true).(bool),
  451. AppType: mv.AppType,
  452. OpenType: mv.OpenType,
  453. TipInfo: &pb.TipInfo{
  454. Title: mv.AdditionalInfo.Title,
  455. Content: mv.AdditionalInfo.Content,
  456. ConfirmUrl: mv.AdditionalInfo.ConfirmUrl,
  457. ConfirmText: mv.AdditionalInfo.ConfirmText,
  458. IsShowCancel: mv.AdditionalInfo.IsShowCancel,
  459. AppType: mv.AppType,
  460. OpenType: mv.OpenType,
  461. },
  462. Match: MC.If(mv.Match != "", strings.Split(mv.Match, ","), []string{}).([]string),
  463. }
  464. //处理子级
  465. if childMenus[mv.Id] != nil && len(childMenus[mv.Id]) > 0 {
  466. childMenu := childMenus[mv.Id]
  467. sort.Slice(childMenu, func(i, j int) bool {
  468. return childMenu[i].OrderId < childMenu[j].OrderId
  469. })
  470. L:
  471. for _, cv := range childMenu {
  472. //cv.Status < 0 四级菜单 生效不再处理;因为常用功能设置保存的都是三级菜单id,如果三级菜单功能下架,只处理三级菜单。
  473. if cv.Name == "" || cv.ParentId != mv.Id || cv.Status < 0 {
  474. continue
  475. }
  476. if cv.CapitalCode != "" || cv.PermissionCode != "" {
  477. _, _, _, _, _, _, _, feasibility = CheckCapitalResources(cv, m, usable, m.VerifyPermissions(cv.PermissionCode))
  478. }
  479. oneLevel.Url = MC.If(cv.Url != "", cv.Url, mv.Url).(string)
  480. oneLevel.Icon = MC.If(cv.Icon != "", cv.Icon, mv.Icon).(string)
  481. oneLevel.AppType = cv.AppType
  482. oneLevel.OpenType = cv.OpenType
  483. oneLevel.Usable = feasibility
  484. if cv.AdditionalInfo.Title != "" {
  485. oneLevel.TipInfo = &pb.TipInfo{
  486. Title: cv.AdditionalInfo.Title,
  487. Content: cv.AdditionalInfo.Content,
  488. ConfirmUrl: cv.AdditionalInfo.ConfirmUrl,
  489. ConfirmText: cv.AdditionalInfo.ConfirmText,
  490. IsShowCancel: cv.AdditionalInfo.IsShowCancel,
  491. AppType: cv.AppType,
  492. OpenType: cv.OpenType,
  493. }
  494. }
  495. oneLevel.Match = MC.If(cv.Match != "", strings.Split(cv.Match, ","), []string{}).([]string)
  496. name := MC.If(strings.Contains(cv.Name, "-"), strings.Split(cv.Name, "-")[0], "免费").(string)
  497. if len(UserRolePowers[name]) > 0 && m.VerifyPermissions(strings.Join(UserRolePowers[name], ",")) {
  498. break L
  499. }
  500. }
  501. }
  502. //跨平台,非本平台功能,给用户提示信息
  503. if oneLevel.Url == "-1" {
  504. oneLevel.TipInfo = &pb.TipInfo{
  505. Title: ConfigJson.DefaultPopup[m.Platform].Title,
  506. Content: ConfigJson.DefaultPopup[m.Platform].Content,
  507. ConfirmUrl: ConfigJson.DefaultPopup[m.Platform].ConfirmUrl,
  508. ConfirmText: ConfigJson.DefaultPopup[m.Platform].ConfirmText,
  509. IsShowCancel: ConfigJson.DefaultPopup[m.Platform].IsShowCancel,
  510. }
  511. if oneLevel.TipInfo.ConfirmUrl == "" {
  512. oneLevel.TipInfo.AppType = ""
  513. oneLevel.TipInfo.OpenType = ""
  514. }
  515. oneLevel.Url = ""
  516. oneLevel.Usable = false
  517. }
  518. //1、当前平台有权限,清空提示信息
  519. //2、提示信息内容为空,清空提示信息
  520. if oneLevel.Usable || oneLevel.TipInfo.Content == "" {
  521. oneLevel.TipInfo = &pb.TipInfo{}
  522. }
  523. menuList = append(menuList, oneLevel)
  524. }
  525. return menuList, saveIds, delBool
  526. }