| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 | 
							- <?php
 
- namespace app\admin\model;
 
- use support\Db;
 
- use support\Model;
 
- /**
 
-  * 角色模型
 
-  * Class Users
 
-  * @package app\admin\model
 
-  */
 
- class SystemMenu extends Model
 
- {
 
-     const STATUS_DEL_NO = '1';
 
-     const STATUS_DEL_YES = '2';
 
-     const STATUS_DEL = [
 
-         self::STATUS_DEL_NO => '正常',
 
-         self::STATUS_DEL_YES => '删除'
 
-     ];
 
-     const MENU_MENU = '1';
 
-     const MENU_RULE = '2';
 
-     const MENU_TYPE = [
 
-         self::MENU_MENU => '菜单',
 
-         self::MENU_RULE => '权限'
 
-     ];
 
-     const MENU_SHOW_NO = '0';
 
-     const MENU_SHOW_YES = '1';
 
-     const MENU_SHOW = [
 
-         self::MENU_SHOW_NO => '隐藏',
 
-         self::MENU_SHOW_YES => '显示'
 
-     ];
 
-     const MENU_LEVEL_ONE = '1';
 
-     const MENU_LEVEL_TWO = '2';
 
-     const MENU_LEVEL_THE = '3';
 
-     /**
 
-      * The table associated with the model.
 
-      *
 
-      * @var string
 
-      */
 
-     protected $table = 'system_menu';
 
-     public $timestamps = false;
 
-     /**
 
-      * Notes:父级模型关联
 
-      * @return \Illuminate\Database\Eloquent\Relations\HasMany
 
-      * User: yym
 
-      * Date: 2022/9/21
 
-      */
 
-     public function children()
 
-     {
 
-         $where = array(
 
-             'menu_status' => static::STATUS_DEL_NO,
 
-             'menu_is_show' => static::MENU_SHOW_YES,
 
-             'menu_is_menu' => static::MENU_MENU
 
-         );
 
-         return $this->hasMany(static::class, 'menu_pid', 'menu_id')->where($where)->select(['menu_id', 'menu_pid', 'menu_path', 'menu_icon', 'menu_name', 'menu_route'])->orderBy('menu_sort', 'desc');
 
-     }
 
-     /**
 
-      * Notes:获取菜单列表
 
-      * @param string $keywords
 
-      * @param int $page
 
-      * @param int $limit
 
-      * @return array
 
-      * User: ZQ
 
-      * Date: 2022/9/14
 
-      */
 
-     public static function getMenuList(string $keywords)
 
-     {
 
-         $list = static::select('*')->where(['menu_status'=>static::STATUS_DEL_NO])
 
-             ->when($keywords != '', function ($query) use ($keywords){
 
-                 $query->where('menu_name', 'like', '%' . $keywords . '%');
 
-             })
 
-             ->orderBy('menu_create_time','DESC')
 
-             ->get();
 
-         $count = static::where(['menu_status'=>static::STATUS_DEL_NO])
 
-             ->when($keywords != '', function ($query) use ($keywords){
 
-                 $query->where('menu_name', 'like', '%' . $keywords . '%');
 
-             })
 
-             ->count();
 
-         return $list;
 
-     }
 
-     /**
 
-      * Notes:获取菜单
 
-      * @param int $menu_pid
 
-      * @return array
 
-      * User: ZQ
 
-      * Date: 2022/9/13
 
-      */
 
-     public static function getMenus(int $menu_pid)
 
-     {
 
-         $list = static::select('*')
 
-             ->where(['menu_pid' => $menu_pid, 'menu_status' => static::STATUS_DEL_NO])
 
-             ->orderBy('menu_sort','DESC')
 
-             ->get();
 
-         return $list;
 
-     }
 
-     /**
 
-      * Notes:三级菜单
 
-      * @param int $menu_pid
 
-      * @return array
 
-      * User: ZQ
 
-      * Date: 2022/9/15
 
-      */
 
-     public static function getLevel($menu_pid)
 
-     {
 
-         $list = static::select(['menu_id as value','menu_name as label'])
 
-             ->where(['menu_pid' => $menu_pid, 'menu_status' => static::STATUS_DEL_NO])
 
-             ->orderBy('menu_sort','DESC')
 
-             ->get();
 
-         return $list;
 
-     }
 
-     /**
 
-      * Notes:获取菜单
 
-      * @param int $menus
 
-      * @return array
 
-      * User: ZQ
 
-      * Date: 2022/9/13
 
-      */
 
-     public static function menusMation($menus)
 
-     {
 
-         $list = static::where(['menu_status'=>static::STATUS_DEL_NO])
 
-             ->when($menus != '', function ($query) use ($menus){
 
-                 $query->whereIn('menu_id', $menus);
 
-             })
 
-             ->get();
 
-         return $list;
 
-     }
 
-     /**
 
-      * Notes:获取角色对应权限菜单
 
-      * @param array $menu_ids
 
-      * @return array
 
-      * User: yym
 
-      * Date: 2022/9/21
 
-      */
 
-     public static function getMenuListRule(array $menu_ids)
 
-     {
 
-         return static::where(['menu_status' => static::STATUS_DEL_NO])
 
-             ->whereIn('menu_id', $menu_ids)
 
-             ->get()
 
-             ->toArray();
 
-     }
 
-     /**
 
-      * Notes:菜单列表
 
-      * @param array $menu_list_ids
 
-      * @return array
 
-      * User: yym
 
-      * Date: 2022/9/21
 
-      */
 
-     public static function getHomeMenuList(array $menu_list_ids)
 
-     {
 
-         $where = array(
 
-             'menu_status' => static::STATUS_DEL_NO,
 
-             'menu_is_show' => static::MENU_SHOW_YES,
 
-             'menu_is_menu' => static::MENU_MENU,
 
-             'level' => STATIC::MENU_LEVEL_ONE
 
-         );
 
-         return static::where($where)
 
-             ->select(['menu_id', 'menu_pid', 'menu_path', 'menu_icon', 'menu_name', 'menu_route'])
 
-             ->when(!empty($menu_list_ids), function ($query) use ($menu_list_ids){
 
-                 $query->whereIn('menu_id', $menu_list_ids);
 
-             })
 
-             ->with(['children' => function($query) use ($menu_list_ids){
 
-                 $query->with('children')->when(!empty($menu_list_ids), function ($query1) use ($menu_list_ids){
 
-                     $query1->whereIn('menu_id', $menu_list_ids);
 
-                 });
 
-             }])
 
-             ->orderBy('menu_sort', 'desc')
 
-             ->get()
 
-             ->toArray();
 
-     }
 
-     /**
 
-      * Notes:查询指定条件下的某个字段内容
 
-      * @param int $menu_id
 
-      * @param string $field
 
-      * User: yym
 
-      * Date: 2022/9/27
 
-      */
 
-     public static function getParentValue(int $menu_id, string $field = 'level')
 
-     {
 
-         return static::where(['menu_id' => $menu_id])->value($field);
 
-     }
 
-     /**
 
-      * Notes:获取父级菜单编号 处理成数组形式
 
-      * @param int $menu_pid
 
-      * @return array|false|mixed
 
-      * User: yym
 
-      * Date: 2022/9/26
 
-      */
 
-     public function getParentMenuId(int $menu_pid)
 
-     {
 
-         $parent = array();
 
-         $parent = $this->getParentPid($menu_pid);
 
-         if(!empty($parent))
 
-         {
 
-             $parent = array_merge([$menu_pid], $parent);
 
-             array_pop($parent);
 
-         }
 
-         return array_reverse($parent);
 
-     }
 
-     /**
 
-      * Notes:递归查询父级ID
 
-      * @param $menu_id
 
-      * @param array $date
 
-      * @return array|false|mixed
 
-      * User: yym
 
-      * Date: 2022/9/26
 
-      */
 
-     public function getParentPid($menu_id, $date=[]){
 
-         if(empty($menu_id) && empty($date))
 
-         {
 
-             return array();
 
-         }
 
-         if(empty($menu_id) && !empty($date)){
 
-             return $date;
 
-         }
 
-         $parentIds = array();
 
-         $parentIds = SystemMenu::select('menu_pid')->where(['menu_id' => $menu_id, 'menu_status' => SystemMenu::STATUS_DEL_NO])->get()->toArray();
 
-         $subIds = array();
 
-         $subIds = array_column($parentIds, 'menu_pid');
 
-         $subIds = array_unique($subIds);
 
-         if(count($subIds)>0)
 
-         {
 
-             foreach($subIds as $val)
 
-             {
 
-                 $date[] = $val;
 
-                 $date = $this->getParentPid($val, $date); //注意写$date 返回给上级
 
-             }
 
-         }
 
-         if(count($date)>0)
 
-         {
 
-             return $date;
 
-         }else{
 
-             return false;
 
-         }
 
-     }
 
- }
 
 
  |