public static function flushCacheConfig()
 {
     $data = AdminConfig::find()->all();
     if (is_array($data) && !empty($data)) {
         foreach ($data as $one) {
             $key = $one['key'];
             $value = $one['value'];
             $cache_key = self::ADMIN_CONFIG_CONFIX . $key;
             CCache::set($cache_key, $value);
         }
     }
 }
 public function getCurrentRoleKeys()
 {
     $identity = Yii::$app->user->identity;
     $role_id = $identity->role;
     $AdminRole = new AdminRole();
     # 缓存读取role key
     if (!CCache::get(CCache::ALL_ROLE_KEY_CACHE_HANDLE)) {
         CCache::set(CCache::ALL_ROLE_KEY_CACHE_HANDLE, $AdminRole->getAllRoleMenuRoleKey());
     }
     $roleKeys = CCache::get(CCache::ALL_ROLE_KEY_CACHE_HANDLE);
     //var_dump($roleKeys);exit;
     return isset($roleKeys[$role_id]) ? $roleKeys[$role_id] : '';
 }
 public static function getMenuArr()
 {
     if ($menuArr = CCache::get(self::MENU_CACHE_ARR)) {
         return $menuArr;
     } else {
         $menuArr = [];
         $data = AdminMenu::find()->select(['name', 'role_key'])->all();
         foreach ($data as $one) {
             $menuArr[$one['role_key']] = $one['name'];
         }
         $menuArr['/fecadmin/index'] = '主界面';
         $menuArr['/fecadmin/login'] = '******';
         $menuArr['/fecadmin/logout'] = '账号退出';
         CCache::set(self::MENU_CACHE_ARR, $menuArr);
         return $menuArr;
     }
 }
 public function getCurrentRoleKeys()
 {
     $identity = Yii::$app->user->identity;
     $user_id = $identity->id;
     $roles = AdminUserRole::find()->asArray()->where(['user_id' => $user_id])->all();
     $AdminRole = new AdminRole();
     # 缓存读取role key
     if (!CCache::get(CCache::ALL_ROLE_KEY_CACHE_HANDLE)) {
         if (!CCache::set(CCache::ALL_ROLE_KEY_CACHE_HANDLE, $AdminRole->getAllRoleMenuRoleKey())) {
             throw new InvalidValueException('save role key to cache error,check your cache if it can write!');
         }
     }
     $roleKeys = CCache::get(CCache::ALL_ROLE_KEY_CACHE_HANDLE);
     //var_dump($roleKeys);exit;
     //$role_ids = [];
     $menu_roles = [];
     if (!empty($roles)) {
         foreach ($roles as $role) {
             $role_id = $role['role_id'];
             $menu_role = isset($roleKeys[$role_id]) ? $roleKeys[$role_id] : [];
             $menu_roles = array_merge($menu_roles, $menu_role);
         }
     }
     return $menu_roles;
 }
 public function reflush()
 {
     $cacheStr = CRequest::param("ids");
     $cacheArr = explode(",", $cacheStr);
     foreach ($cacheArr as $cacheType) {
         $cacheType = trim($cacheType);
         if ($cacheType == all_cache) {
             CCache::flushAll();
         }
     }
     echo json_encode(array("statusCode" => "200", "message" => "reflush cache success"));
     exit;
 }