50], [['app_id'], 'string', 'max' => 20], [['url'], 'string', 'max' => 100], [['tree'], 'string', 'max' => 300], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'title' => '标题', 'app_id' => '应用id', 'pid' => '上级id', 'addons_name' => '插件标识', 'is_addon' => '是否插件[0=否,1=是]', 'url' => '路由', 'icon' => '样式', 'level' => '级别', 'dev' => '开发者[0:都可见;开发模式可见]', 'sort' => '排序', 'params' => '参数', 'tree' => '树', 'status' => '状态[-1:删除;0:禁用;1启用]', 'created_at' => '添加时间', 'updated_at' => '修改时间', ]; } //关联模型 public function getChild() { return $this->hasMany(self::class, ['pid' => 'id'])->where(['<>', 'status', StatusEnum::DELETE])->orderBy('sort asc,id asc'); } /** * * @Author bing * @DateTime 2021-08-26 10:56:02 * @param integer $cate_id * @param integer $pid * @param string $app_id * @return array|null * @copyright: Copyright (c) 2020 广东七件事集团 */ public static function getMenus(array $cond, array $with = [], bool $is_array = true, string $select = '*') { $query = self::find()->select($select); self::paramPack(['where' => $cond, 'with' => $with, 'order' => 'sort asc, id asc'], $query); $menu = $query->asArray($is_array)->all(); return $menu; } /** * 获取树状菜单 * @Author bing * @DateTime 2021-08-10 18:22:16 * @param array $menu 菜单 * @param integer $parentId * @param string $app_id APP_ID * @return array * @copyright: Copyright (c) 2020 广东七件事集团 */ public static function getTreeMenu(array $menu, int $pid = 0, string $route = '',string $mall_sign = '') { $tree = []; foreach ($menu as $k => $v) { $v['value'] = $v['id']; $v['label'] = $v['title']; $v['mall_sign'] = $mall_sign; if ($v['pid'] == $pid) { $tmp = $v; // 当前路由的菜单被选中 if ($route == $v['url']) $tmp['is_active'] = true; $children = self::getTreeMenu($menu, $v['id'], $route,$mall_sign); $children && $tmp['children'] = $children; //判断父级菜单是否被选中 if (isset($tmp['children']) && !empty($tmp['children'])) { foreach ($tmp['children'] as $child) { if (isset($child['is_active']) && $child['is_active'] == true) { $tmp['is_active'] = true; } } } $tree[] = $tmp; } } return $tree; } /** * 冻结账户权限 * @Author bing * @DateTime 2021-08-10 18:22:16 * @param array $menu 菜单 * @param integer $parentId * @param string $app_id APP_ID * @return array * @copyright: Copyright (c) 2020 广东七件事集团 */ public static function getFreezeMenu(array $menus,int $store_id) { $freeze_url_arr = [ 'happiness/client/index/index', 'happiness/client/cash/index', 'happiness/client/finance/index', ]; $store = happinessStore::findOne(['id'=>$store_id]); if(!empty($store['is_freeze'])){ $newMenus = []; foreach($menus as $item){ if(in_array($item['url'],$freeze_url_arr)){ $newMenus[] = $item; } } }else{ $newMenus = $menus; } return $newMenus; } }