AdminMenu.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model\admin;
  4. use app\Request;
  5. use library\basic\BaseModel;
  6. use library\services\UtilService;
  7. use library\utils\Arr;
  8. use think\db\exception\DbException;
  9. use think\Model;
  10. /**
  11. * @mixin \think\Model
  12. */
  13. class AdminMenu extends BaseModel
  14. {
  15. private $_data;
  16. private $sassId = 0;
  17. public function setSassId($sassid) {
  18. $this->sassId = $sassid;
  19. }
  20. /**
  21. * 设置显示状态
  22. * @param $id
  23. * @param $status
  24. */
  25. public function setStatus($id,$status) {
  26. self::beginTrans();
  27. try{
  28. $this->where('id', $id)->save(['is_show'=>$status]);
  29. $this->where('pid',$id)->save(['is_show'=>$status]);
  30. self::commitTrans();
  31. return true;
  32. }catch (DbException $db) {
  33. self::rollbackTrans();
  34. return false;
  35. }
  36. }
  37. /**
  38. * 保存分类
  39. * @param $post
  40. * @return bool
  41. */
  42. public function saveMenu($post){
  43. if(!empty($post['id'])) {
  44. $this->where('id',$post['id'])->save($post);
  45. return true;
  46. } else {
  47. unset($post['id']);
  48. $bool = $this->insert($post);
  49. return $bool;
  50. }
  51. }
  52. /**
  53. * 删除栏目
  54. * @param $id
  55. */
  56. public function delMenu($id){
  57. $this->where('pid',$id)->delete();
  58. $this->where('id',$id)->delete();
  59. return true;
  60. }
  61. /**
  62. * 获取admin端用户菜单
  63. * @param $roule_id
  64. * @return array
  65. * @throws \think\db\exception\DataNotFoundException
  66. * @throws \think\db\exception\DbException
  67. * @throws \think\db\exception\ModelNotFoundException
  68. */
  69. public function getRoute($roule_id)
  70. {
  71. $adminRole = new AdminRole();
  72. $adminRole->setSassId($this->sassId);
  73. $rules = $adminRole->getRoleId($roule_id);
  74. $menuAr = $this->getArMenu(1);
  75. //判断权限
  76. // if($rules['is_system']) {
  77. $resultAr = Arr::toIviewUi($menuAr);
  78. // }
  79. $resultAr = array_merge([[
  80. 'header' => '0',
  81. 'icon' => 'md-home',
  82. 'is_header' => 0,
  83. 'path' => '/admin/index',
  84. 'title' => '主页'
  85. ]],$resultAr);
  86. return $resultAr;
  87. }
  88. /**
  89. * 获取分类数据
  90. * @return array
  91. * @throws \think\db\exception\DataNotFoundException
  92. * @throws \think\db\exception\DbException
  93. * @throws \think\db\exception\ModelNotFoundException
  94. */
  95. public function getArMenu($show = 0){
  96. $menus = $this->when(!empty($show), function ($query){
  97. $query->where(array('is_show'=>1));
  98. })->order("seq","desc")->select();
  99. $data = [];
  100. foreach ($menus as $item) {
  101. $data[] = $item->getData();
  102. }
  103. $menuAr = Arr::getTree($data);
  104. return $menuAr;
  105. }
  106. }