获取有权限的菜单列表

@param bool $format 是否格式化返回
@param string $columns 要额外获取的字段

@return array
497583
public static function getMenus($format = true, $columns = '')
    {
        $res = [];
        $authInfo = self::getLoginInfo();
        if (!$authInfo) { //登录超时
            return $res;
        }

        $result = Model::getInstance()->table([self::$tables['menus'] => 'm'])
            ->columns(['distinct m.id', 'm.pid', 'm.title', 'm.url', 'm.params' . ($columns ? " ,{$columns}" : '')])
            ->when(!self::isSuperUser(), function ($model) use ($authInfo) {//当前登录用户是否为超级管理员
                $model->join([self::$tables['access'] => 'a'], 'a.menuid=m.id')
                    ->_and(function ($model) use ($authInfo) {
                        $model->whereIn('a.groupid', $authInfo['groupid'])
                            ->_or()
                            ->where('a.userid', $authInfo['id']);
                    });
            })->where('m.isshow', 1)
            ->orderBy('m.sort', 'DESC')
            ->orderBy('m.id', 'ASC')
            ->select(0, 5000);

        $res = $format ? Tree::getTreeNoFormat($result, 0) : $result;
        return $res;
    }
940439
protected function extractColumns($columns)
    {
        $schema = [];

        foreach ($columns as $name => $data) {
            $schema[$name] = $this->extractColumn($data);
        }

        return $schema;
    }
355377
public function mapColumnsWithValues($columns, $values)
    {
        // If $values is null, then use $columns to build it up
        if (is_null($values)) {

            if ($this->isAssoc($columns)) {

                // Incoming is associative array, split it up in two
                $values = array_values($columns);
                $columns = array_keys($columns);

            } else {

                // Create an array of '?' to match number of columns
                $max = count($columns);
                for ($i = 0; $i < $max; $i++) {
                    $values[] = '?';
                }
            }
        }

        return [$columns, $values];
    }
821232
public function checkExistsColumns($columns = [])
    {
        $this->connection();

        return $this->getSchema()->hasColumns($this->table, $columns);
    }
1280662
public function select_array(array $columns, $reset = false)
	{
		$this->_select = $reset ? $columns : array_merge($this->_select, $columns);

		return $this;
	}
699187
public function sqlDate($format, $column = null)
    {
        if (is_null($column)) {
            $column = 'current_timestamp';
        }

        $pattern = [
            'Y' => "YYYY",
            'y' => "YY",
            'M' => "Mon",
            'm' => "MM",
            'Q' => "Q",
            'q' => "Q",
            'D' => "DD",
            'd' => "DD",
            'h' => "HH",
            'H' => "HH24",
            'i' => "MI",
            's' => "SS",
            'a' => "AM",
            'A' => "AM",
        ];

        return sprintf(
            "TO_CHAR(%s,'%s')",
            $column,
            implode('', $this->prepareSqlDate($format, $pattern, ''))
        );
    }
1089764
protected function getSelectColumns(array $columns = array('*'))
	{
		if ($columns == array('*'))
		{
			$columns = array($this->related->getTable().'.*');
		}

		return array_merge($columns, array($this->parent->getTable().'.'.$this->firstKey));
	}
787804
public function setColumns(array $columns)
    {
        foreach ($columns as $id => $params) {
            if (!is_string($id) || strlen($id) < 1)
                throw new \Exception("Column ID should be a non-empty string");
            if (!isset($params['title']))
                throw new \Exception("No 'title' param for ID $id");
            if (!isset($params['type']))
                throw new \Exception("No 'type' param for ID $id");
            if (!in_array($params['type'], self::getAvailableTypes()))
                throw new \Exception("Unknown type '" . $params['type'] . "' for ID $id");
            if (!isset($params['filters']))
                throw new \Exception("No 'filters' param for ID $id");
            if (!isset($params['sortable']))
                throw new \Exception("No 'sortable' param for ID $id");
            if (!isset($params['visible']))
                throw new \Exception("No 'visible' param for ID $id");

            foreach ($params['filters'] as $filter) {
                if (!in_array($filter, self::getAvailableFilters()))
                    throw new \Exception("Unknown filter: $filter");
            }
        }

        $this->columns = $columns;
        return $this;
    }
85447
protected function getSelectColumns(array $columns = ['*'])
    {
        if ($columns == ['*']) {
            $columns = [$this->relatedMap->getTable().'.*'];
        }

        return array_merge($columns, $this->getAliasedPivotColumns());
    }
32560
private function transformColumns($columns)
    {
        return array_map(function ($column) {
            return [
                'Field' => $column->column_name,
                'Type' => $column->data_type,
                'Null' => $column->is_nullable,
                'Key' => $column->ordinal_position,
                'Default' => $column->column_default,
//                'Extra' => $column->Extra
            ];
        }, $columns);
    }
848537
protected function getSelectColumns(array $columns = ['*'])
	{
		if ($columns == ['*']) {
			$columns = [$this->related->getTable().'.*'];
		}

		return array_merge($columns, $this->getAliasedPivotColumns());
	}
1166410
public function setColumns($columns)
    {
        if (is_string($columns)) {
            $columns = explode(',', $columns);
            $columns = ArrayMethods::trim($columns);
        }
        return $this->setColumnNames($columns);
    }
576285
public static function getFill(array $columns) {
        $pk = false;
        $rules = $labels = $property = [];
        foreach ($columns as $key => $value) {
            $labels[$value['Field']] = ucwords(str_replace('_', ' ', $value['Field']));
            $property[$value['Field']] = static::converterType($value['Type']);
            if ($value['Key'] == 'PRI'
//                || $value['Key'] == 'UNI'
            ) {
                $pk = $value['Field'];
            }
            if ($value['Extra'] === 'auto_increment') {
                continue;
            }
            $rules[$value['Field']] = static::getValidate($value);
        }
        return [
            $pk,
            $rules,
            $labels,
            $property
        ];
    }
622684
public function get($columns = ['*'])
    {
        $original = $this->columns;

        if (is_null($original)) {
            $this->columns = $columns;
        }

        // encrypted columns replace their default (original) columns
        if ($this->encryptionModel instanceof Model
            && method_exists($this->encryptionModel, 'getEncryptKey')
        ) {
            $model = $this->encryptionModel;
            $modelEncryptionColumns = $model::getEncryptedFields();
            if (!empty($modelEncryptionColumns)) {
                if ($columns == ['*']) {
                    $this->columns = [];

                    /*
                     * Select all visible columns (avoid select *)
                     */
                    $visibles = array_diff(array_merge($model->getFillable(), $model->getGuarded()), $model->getHidden());
                    $unencryptedVisibles = array_unique(array_diff($visibles, array_column($this->encryptionColumns, 'column')));
                    sort($unencryptedVisibles);

                    $primaryKey = [
                        $model->getKeyName()
                    ];

                    $attributes = array_merge($primaryKey, $unencryptedVisibles);

                    if ($model->usesTimestamps()) {
                        $attributes[] = $model->getCreatedAtColumn();
                        $attributes[] = $model->getUpdatedAtColumn();
                    }

                    // add all visible unencrypted columns
                    foreach ($attributes as $attribute) {
                        $this->columns[] = $attribute;
                    }

                    // add all encrypted columns
                    $this->columns = array_merge($this->columns, array_column($this->encryptionColumns, 'select'));
                } else {
                    $this->columns = [];

                    // add all visible unencrypted columns
                    $encryptionColumnNames = array_column($this->encryptionColumns, 'column');
                    foreach ($columns as $column) {
                        if (!in_array($column, $encryptionColumnNames)) {
                            $this->columns[] = $column;
                        }
                    }
                    // add the encrypted columns (and decrypted, if 'withDecryptionKey' was given)
                    foreach ($this->encryptionColumns as $encryptionColumn){
                        if (in_array($encryptionColumn['column'], $columns)) {
                            $this->columns[] = $encryptionColumn['select'];
                        }
                    }
                }
            }
        }

        $results = $this->processor->processSelect($this, $this->runSelect());

        $this->columns = $original;

        return collect($results);
    }
273437
public static function all( $columns = ['*'] )
	{
		$columns = is_array( $columns ) ? $columns : func_get_args();

		$instance = new static;

		return $instance->newQuery()->get( $columns );
	}
663767
public static function select(array $columns = ['*'], ...$joinsColumns)
    {
        $query               = new static(Query\Type::SELECT);
        $query->columns['t'] = $columns;

        $alias = 'j1';
        foreach ($joinsColumns as $joinColumns) {
            $query->columns[$alias] = (array)$joinColumns;
            $alias++;
        }

        return $query;
    }
511456
protected function _get($columns = '*')
    {
        $data = $this->db->select($this->table, $columns, $this->where);

        if (empty($data)) {
            return false;
        }

        return $this->getModelObjects($data);
    }