mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 07:32:48 +08:00
Query类value和column增加对调用field链式操作方法的处理
This commit is contained in:
@@ -81,7 +81,7 @@ class Query
|
|||||||
protected function builder()
|
protected function builder()
|
||||||
{
|
{
|
||||||
static $builder = [];
|
static $builder = [];
|
||||||
$driver = $this->driver;
|
$driver = $this->driver;
|
||||||
if (!isset($builder[$driver])) {
|
if (!isset($builder[$driver])) {
|
||||||
$class = '\\think\\db\\builder\\' . ucfirst($driver);
|
$class = '\\think\\db\\builder\\' . ucfirst($driver);
|
||||||
$builder[$driver] = new $class($this->connection);
|
$builder[$driver] = new $class($this->connection);
|
||||||
@@ -107,6 +107,9 @@ class Query
|
|||||||
$result = Cache::get($key);
|
$result = Cache::get($key);
|
||||||
}
|
}
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
|
if (isset($this->options['field'])) {
|
||||||
|
unset($this->options['field']);
|
||||||
|
}
|
||||||
$pdo = $this->field($field)->fetchPdo(true)->find();
|
$pdo = $this->field($field)->fetchPdo(true)->find();
|
||||||
$result = $pdo->fetchColumn();
|
$result = $pdo->fetchColumn();
|
||||||
if (isset($cache)) {
|
if (isset($cache)) {
|
||||||
@@ -137,6 +140,9 @@ class Query
|
|||||||
$result = Cache::get($guid);
|
$result = Cache::get($guid);
|
||||||
}
|
}
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
|
if (isset($this->options['field'])) {
|
||||||
|
unset($this->options['field']);
|
||||||
|
}
|
||||||
if ($key && '*' != $field) {
|
if ($key && '*' != $field) {
|
||||||
$field = $key . ',' . $field;
|
$field = $key . ',' . $field;
|
||||||
}
|
}
|
||||||
@@ -365,7 +371,7 @@ class Query
|
|||||||
}
|
}
|
||||||
if (count($join)) {
|
if (count($join)) {
|
||||||
// 有设置第二个元素则把第二元素作为表前缀
|
// 有设置第二个元素则把第二元素作为表前缀
|
||||||
$table = (string)current($join) . $table;
|
$table = (string) current($join) . $table;
|
||||||
} elseif (false === strpos($table, '.')) {
|
} elseif (false === strpos($table, '.')) {
|
||||||
// 加上默认的表前缀
|
// 加上默认的表前缀
|
||||||
$table = $prefix . $table;
|
$table = $prefix . $table;
|
||||||
@@ -497,7 +503,7 @@ class Query
|
|||||||
protected function parseWhereExp($operator, $field, $op, $condition, $param = [])
|
protected function parseWhereExp($operator, $field, $op, $condition, $param = [])
|
||||||
{
|
{
|
||||||
if ($field instanceof \Closure) {
|
if ($field instanceof \Closure) {
|
||||||
call_user_func_array($field, [& $this]);
|
call_user_func_array($field, [ & $this]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -640,16 +646,15 @@ class Query
|
|||||||
|
|
||||||
$class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\paginator\\driver\\') . ucwords($config['type']);
|
$class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\paginator\\driver\\') . ucwords($config['type']);
|
||||||
|
|
||||||
$page = isset($config['page']) ? (int)$config['page'] : call_user_func([
|
$page = isset($config['page']) ? (int) $config['page'] : call_user_func([
|
||||||
$class,
|
$class,
|
||||||
'getCurrentPage'
|
'getCurrentPage',
|
||||||
], $config['var_page']);
|
], $config['var_page']);
|
||||||
|
|
||||||
$page = $page < 1 ? 1 : $page;
|
$page = $page < 1 ? 1 : $page;
|
||||||
|
|
||||||
$config['path'] = isset($config['path']) ? $config['path'] : call_user_func([$class, 'getCurrentPath']);
|
$config['path'] = isset($config['path']) ? $config['path'] : call_user_func([$class, 'getCurrentPath']);
|
||||||
|
|
||||||
|
|
||||||
/** @var Paginator $paginator */
|
/** @var Paginator $paginator */
|
||||||
if (!$simple) {
|
if (!$simple) {
|
||||||
$options = $this->getOptions();
|
$options = $this->getOptions();
|
||||||
@@ -947,7 +952,7 @@ class Query
|
|||||||
if (!isset($_info[$guid])) {
|
if (!isset($_info[$guid])) {
|
||||||
$info = $this->connection->getFields($tableName);
|
$info = $this->connection->getFields($tableName);
|
||||||
$fields = array_keys($info);
|
$fields = array_keys($info);
|
||||||
$bind = $type = [];
|
$bind = $type = [];
|
||||||
foreach ($info as $key => $val) {
|
foreach ($info as $key => $val) {
|
||||||
// 记录字段类型
|
// 记录字段类型
|
||||||
$type[$key] = $val['type'];
|
$type[$key] = $val['type'];
|
||||||
@@ -1054,7 +1059,7 @@ class Query
|
|||||||
$relation = $key;
|
$relation = $key;
|
||||||
$with[$key] = $key;
|
$with[$key] = $key;
|
||||||
} elseif (is_string($relation) && strpos($relation, '.')) {
|
} elseif (is_string($relation) && strpos($relation, '.')) {
|
||||||
$with[$key] = $relation;
|
$with[$key] = $relation;
|
||||||
list($relation, $subRelation) = explode('.', $relation, 2);
|
list($relation, $subRelation) = explode('.', $relation, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1074,7 +1079,7 @@ class Query
|
|||||||
$this->join($joinTable . ' ' . $joinName, $name . '.' . $info['localKey'] . '=' . $joinName . '.' . $info['foreignKey'])->field(true, false, $joinTable, $joinName, $joinName . '__');
|
$this->join($joinTable . ' ' . $joinName, $name . '.' . $info['localKey'] . '=' . $joinName . '.' . $info['foreignKey'])->field(true, false, $joinTable, $joinName, $joinName . '__');
|
||||||
if ($closure) {
|
if ($closure) {
|
||||||
// 执行闭包查询
|
// 执行闭包查询
|
||||||
call_user_func_array($closure, [& $this]);
|
call_user_func_array($closure, [ & $this]);
|
||||||
}
|
}
|
||||||
$i++;
|
$i++;
|
||||||
} elseif ($closure) {
|
} elseif ($closure) {
|
||||||
@@ -1275,7 +1280,7 @@ class Query
|
|||||||
if ($data instanceof Query) {
|
if ($data instanceof Query) {
|
||||||
return $data->select();
|
return $data->select();
|
||||||
} elseif ($data instanceof \Closure) {
|
} elseif ($data instanceof \Closure) {
|
||||||
call_user_func_array($data, [& $this]);
|
call_user_func_array($data, [ & $this]);
|
||||||
}
|
}
|
||||||
// 分析查询表达式
|
// 分析查询表达式
|
||||||
$options = $this->parseExpress();
|
$options = $this->parseExpress();
|
||||||
@@ -1358,7 +1363,7 @@ class Query
|
|||||||
if ($data instanceof Query) {
|
if ($data instanceof Query) {
|
||||||
return $data->find();
|
return $data->find();
|
||||||
} elseif ($data instanceof \Closure) {
|
} elseif ($data instanceof \Closure) {
|
||||||
call_user_func_array($data, [& $this]);
|
call_user_func_array($data, [ & $this]);
|
||||||
}
|
}
|
||||||
// 分析查询表达式
|
// 分析查询表达式
|
||||||
$options = $this->parseExpress();
|
$options = $this->parseExpress();
|
||||||
@@ -1549,10 +1554,10 @@ class Query
|
|||||||
if (isset($options['page'])) {
|
if (isset($options['page'])) {
|
||||||
// 根据页数计算limit
|
// 根据页数计算limit
|
||||||
list($page, $listRows) = $options['page'];
|
list($page, $listRows) = $options['page'];
|
||||||
$page = $page > 0 ? $page : 1;
|
$page = $page > 0 ? $page : 1;
|
||||||
$listRows = $listRows > 0 ? $listRows : (is_numeric($options['limit']) ? $options['limit'] : 20);
|
$listRows = $listRows > 0 ? $listRows : (is_numeric($options['limit']) ? $options['limit'] : 20);
|
||||||
$offset = $listRows * ($page - 1);
|
$offset = $listRows * ($page - 1);
|
||||||
$options['limit'] = $offset . ',' . $listRows;
|
$options['limit'] = $offset . ',' . $listRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->options = [];
|
$this->options = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user