mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
完善分页
This commit is contained in:
@@ -229,8 +229,8 @@ class Query
|
||||
/**
|
||||
* 执行语句
|
||||
* @access public
|
||||
* @param string $sql sql指令
|
||||
* @param array $bind 参数绑定
|
||||
* @param string $sql sql指令
|
||||
* @param array $bind 参数绑定
|
||||
* @return int
|
||||
* @throws BindParamException
|
||||
* @throws PDOException
|
||||
@@ -243,7 +243,7 @@ class Query
|
||||
/**
|
||||
* 获取最近插入的ID
|
||||
* @access public
|
||||
* @param string $sequence 自增序列名
|
||||
* @param string $sequence 自增序列名
|
||||
* @return string
|
||||
*/
|
||||
public function getLastInsID($sequence = null)
|
||||
@@ -390,7 +390,7 @@ class Query
|
||||
* @access public
|
||||
* @param string $field 字段名
|
||||
* @param mixed $default 默认值
|
||||
* @param bool $force 强制转为数字类型
|
||||
* @param bool $force 强制转为数字类型
|
||||
* @return mixed
|
||||
*/
|
||||
public function value($field, $default = null, $force = false)
|
||||
@@ -694,7 +694,7 @@ class Query
|
||||
* 获取Join表名及别名 支持
|
||||
* ['prefix_table或者子查询'=>'alias'] 'prefix_table alias' 'table alias'
|
||||
* @access public
|
||||
* @param array|string $join
|
||||
* @param array|string $join
|
||||
* @return array|string
|
||||
*/
|
||||
protected function getJoinTable($join, &$alias = null)
|
||||
@@ -817,8 +817,8 @@ class Query
|
||||
/**
|
||||
* 字段值增长
|
||||
* @access public
|
||||
* @param string|array $field 字段名
|
||||
* @param integer $step 增长值
|
||||
* @param string|array $field 字段名
|
||||
* @param integer $step 增长值
|
||||
* @return $this
|
||||
*/
|
||||
public function inc($field, $step = 1)
|
||||
@@ -833,8 +833,8 @@ class Query
|
||||
/**
|
||||
* 字段值减少
|
||||
* @access public
|
||||
* @param string|array $field 字段名
|
||||
* @param integer $step 增长值
|
||||
* @param string|array $field 字段名
|
||||
* @param integer $step 增长值
|
||||
* @return $this
|
||||
*/
|
||||
public function dec($field, $step = 1)
|
||||
@@ -849,8 +849,8 @@ class Query
|
||||
/**
|
||||
* 使用表达式设置数据
|
||||
* @access public
|
||||
* @param string $field 字段名
|
||||
* @param string $value 字段值
|
||||
* @param string $field 字段名
|
||||
* @param string $value 字段值
|
||||
* @return $this
|
||||
*/
|
||||
public function exp($field, $value)
|
||||
@@ -975,8 +975,8 @@ class Query
|
||||
/**
|
||||
* 指定Null查询条件
|
||||
* @access public
|
||||
* @param mixed $field 查询字段
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @param mixed $field 查询字段
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @return $this
|
||||
*/
|
||||
public function whereNull($field, $logic = 'AND')
|
||||
@@ -988,8 +988,8 @@ class Query
|
||||
/**
|
||||
* 指定NotNull查询条件
|
||||
* @access public
|
||||
* @param mixed $field 查询字段
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @param mixed $field 查询字段
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @return $this
|
||||
*/
|
||||
public function whereNotNull($field, $logic = 'AND')
|
||||
@@ -1001,8 +1001,8 @@ class Query
|
||||
/**
|
||||
* 指定Exists查询条件
|
||||
* @access public
|
||||
* @param mixed $condition 查询条件
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @param mixed $condition 查询条件
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @return $this
|
||||
*/
|
||||
public function whereExists($condition, $logic = 'AND')
|
||||
@@ -1014,8 +1014,8 @@ class Query
|
||||
/**
|
||||
* 指定NotExists查询条件
|
||||
* @access public
|
||||
* @param mixed $condition 查询条件
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @param mixed $condition 查询条件
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @return $this
|
||||
*/
|
||||
public function whereNotExists($condition, $logic = 'AND')
|
||||
@@ -1027,9 +1027,9 @@ class Query
|
||||
/**
|
||||
* 指定In查询条件
|
||||
* @access public
|
||||
* @param mixed $field 查询字段
|
||||
* @param mixed $condition 查询条件
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @param mixed $field 查询字段
|
||||
* @param mixed $condition 查询条件
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @return $this
|
||||
*/
|
||||
public function whereIn($field, $condition, $logic = 'AND')
|
||||
@@ -1041,9 +1041,9 @@ class Query
|
||||
/**
|
||||
* 指定NotIn查询条件
|
||||
* @access public
|
||||
* @param mixed $field 查询字段
|
||||
* @param mixed $condition 查询条件
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @param mixed $field 查询字段
|
||||
* @param mixed $condition 查询条件
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @return $this
|
||||
*/
|
||||
public function whereNotIn($field, $condition, $logic = 'AND')
|
||||
@@ -1055,9 +1055,9 @@ class Query
|
||||
/**
|
||||
* 指定Like查询条件
|
||||
* @access public
|
||||
* @param mixed $field 查询字段
|
||||
* @param mixed $condition 查询条件
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @param mixed $field 查询字段
|
||||
* @param mixed $condition 查询条件
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @return $this
|
||||
*/
|
||||
public function whereLike($field, $condition, $logic = 'AND')
|
||||
@@ -1069,9 +1069,9 @@ class Query
|
||||
/**
|
||||
* 指定NotLike查询条件
|
||||
* @access public
|
||||
* @param mixed $field 查询字段
|
||||
* @param mixed $condition 查询条件
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @param mixed $field 查询字段
|
||||
* @param mixed $condition 查询条件
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @return $this
|
||||
*/
|
||||
public function whereNotLike($field, $condition, $logic = 'AND')
|
||||
@@ -1083,9 +1083,9 @@ class Query
|
||||
/**
|
||||
* 指定Between查询条件
|
||||
* @access public
|
||||
* @param mixed $field 查询字段
|
||||
* @param mixed $condition 查询条件
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @param mixed $field 查询字段
|
||||
* @param mixed $condition 查询条件
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @return $this
|
||||
*/
|
||||
public function whereBetween($field, $condition, $logic = 'AND')
|
||||
@@ -1097,9 +1097,9 @@ class Query
|
||||
/**
|
||||
* 指定NotBetween查询条件
|
||||
* @access public
|
||||
* @param mixed $field 查询字段
|
||||
* @param mixed $condition 查询条件
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @param mixed $field 查询字段
|
||||
* @param mixed $condition 查询条件
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @return $this
|
||||
*/
|
||||
public function whereNotBetween($field, $condition, $logic = 'AND')
|
||||
@@ -1111,9 +1111,9 @@ class Query
|
||||
/**
|
||||
* 指定Exp查询条件
|
||||
* @access public
|
||||
* @param mixed $field 查询字段
|
||||
* @param mixed $condition 查询条件
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @param mixed $field 查询字段
|
||||
* @param mixed $condition 查询条件
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @return $this
|
||||
*/
|
||||
public function whereExp($field, $condition, $logic = 'AND')
|
||||
@@ -1202,8 +1202,8 @@ class Query
|
||||
/**
|
||||
* 检查是否存在一个字段多次查询条件
|
||||
* @access public
|
||||
* @param string $field 查询字段
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @param string $field 查询字段
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @return bool
|
||||
*/
|
||||
private function checkMultiField($field, $logic)
|
||||
@@ -1214,8 +1214,8 @@ class Query
|
||||
/**
|
||||
* 去除某个查询条件
|
||||
* @access public
|
||||
* @param string $field 查询字段
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @param string $field 查询字段
|
||||
* @param string $logic 查询逻辑 and or xor
|
||||
* @return $this
|
||||
*/
|
||||
public function removeWhereField($field, $logic = 'AND')
|
||||
@@ -1230,7 +1230,7 @@ class Query
|
||||
/**
|
||||
* 去除查询参数
|
||||
* @access public
|
||||
* @param string|bool $option 参数名 true 表示去除所有参数
|
||||
* @param string|bool $option 参数名 true 表示去除所有参数
|
||||
* @return $this
|
||||
*/
|
||||
public function removeOption($option = true)
|
||||
@@ -1280,14 +1280,14 @@ class Query
|
||||
* @param int|array $listRows 每页数量 数组表示配置参数
|
||||
* @param int|bool $simple 是否简洁模式或者总记录数
|
||||
* @param array $config 配置参数
|
||||
* page:当前页,
|
||||
* path:url路径,
|
||||
* query:url额外参数,
|
||||
* fragment:url锚点,
|
||||
* var_page:分页变量,
|
||||
* list_rows:每页数量
|
||||
* type:分页类名
|
||||
* @return \think\paginator\Collection
|
||||
* page:当前页,
|
||||
* path:url路径,
|
||||
* query:url额外参数,
|
||||
* fragment:url锚点,
|
||||
* var_page:分页变量,
|
||||
* list_rows:每页数量
|
||||
* type:分页类名
|
||||
* @return \think\Paginator
|
||||
* @throws DbException
|
||||
*/
|
||||
public function paginate($listRows = null, $simple = false, $config = [])
|
||||
@@ -1317,9 +1317,9 @@ class Query
|
||||
|
||||
if (!isset($total) && !$simple) {
|
||||
$options = $this->getOptions();
|
||||
if (isset($options['order'])) {
|
||||
unset($this->options['order']);
|
||||
}
|
||||
|
||||
unset($this->options['order'], $this->options['limit'], $this->options['page'], $this->options['field']);
|
||||
|
||||
$bind = $this->bind;
|
||||
$total = $this->count();
|
||||
$results = $this->options($options)->bind($bind)->page($page, $listRows)->select();
|
||||
@@ -1710,7 +1710,7 @@ class Query
|
||||
}
|
||||
|
||||
list($guid) = explode(' ', $tableName);
|
||||
$db = $this->getConfig('database');
|
||||
$db = $this->getConfig('database');
|
||||
if (!isset(self::$info[$db . '.' . $guid])) {
|
||||
if (!strpos($guid, '.')) {
|
||||
$schema = $db . '.' . $guid;
|
||||
@@ -1724,7 +1724,7 @@ class Query
|
||||
$info = $this->connection->getFields($guid);
|
||||
}
|
||||
$fields = array_keys($info);
|
||||
$bind = $type = [];
|
||||
$bind = $type = [];
|
||||
foreach ($info as $key => $val) {
|
||||
// 记录字段类型
|
||||
$type[$key] = $val['type'];
|
||||
@@ -1889,7 +1889,7 @@ class Query
|
||||
$relation = $key;
|
||||
$with[$key] = $key;
|
||||
} elseif (is_string($relation) && strpos($relation, '.')) {
|
||||
$with[$key] = $relation;
|
||||
$with[$key] = $relation;
|
||||
list($relation, $subRelation) = explode('.', $relation, 2);
|
||||
}
|
||||
|
||||
@@ -1911,8 +1911,8 @@ class Query
|
||||
/**
|
||||
* 关联统计
|
||||
* @access public
|
||||
* @param string|array $relation 关联方法名
|
||||
* @param bool $subQuery 是否使用子查询
|
||||
* @param string|array $relation 关联方法名
|
||||
* @param bool $subQuery 是否使用子查询
|
||||
* @return $this
|
||||
*/
|
||||
public function withCount($relation, $subQuery = true)
|
||||
@@ -2227,7 +2227,7 @@ class Query
|
||||
if ($data instanceof Query) {
|
||||
return $data->select();
|
||||
} elseif ($data instanceof \Closure) {
|
||||
call_user_func_array($data, [ & $this]);
|
||||
call_user_func_array($data, [& $this]);
|
||||
$data = null;
|
||||
}
|
||||
// 分析查询表达式
|
||||
@@ -2327,7 +2327,7 @@ class Query
|
||||
if ($data instanceof Query) {
|
||||
return $data->find();
|
||||
} elseif ($data instanceof \Closure) {
|
||||
call_user_func_array($data, [ & $this]);
|
||||
call_user_func_array($data, [& $this]);
|
||||
$data = null;
|
||||
}
|
||||
// 分析查询表达式
|
||||
@@ -2659,10 +2659,10 @@ class Query
|
||||
if (isset($options['page'])) {
|
||||
// 根据页数计算limit
|
||||
list($page, $listRows) = $options['page'];
|
||||
$page = $page > 0 ? $page : 1;
|
||||
$listRows = $listRows > 0 ? $listRows : (is_numeric($options['limit']) ? $options['limit'] : 20);
|
||||
$offset = $listRows * ($page - 1);
|
||||
$options['limit'] = $offset . ',' . $listRows;
|
||||
$page = $page > 0 ? $page : 1;
|
||||
$listRows = $listRows > 0 ? $listRows : (is_numeric($options['limit']) ? $options['limit'] : 20);
|
||||
$offset = $listRows * ($page - 1);
|
||||
$options['limit'] = $offset . ',' . $listRows;
|
||||
}
|
||||
|
||||
$this->options = [];
|
||||
@@ -2672,8 +2672,8 @@ class Query
|
||||
/**
|
||||
* 注册回调方法
|
||||
* @access public
|
||||
* @param string $event 事件名
|
||||
* @param callable $callback 回调方法
|
||||
* @param string $event 事件名
|
||||
* @param callable $callback 回调方法
|
||||
* @return void
|
||||
*/
|
||||
public static function event($event, $callback)
|
||||
@@ -2684,8 +2684,8 @@ class Query
|
||||
/**
|
||||
* 触发事件
|
||||
* @access protected
|
||||
* @param string $event 事件名
|
||||
* @param mixed $options 当前查询参数
|
||||
* @param string $event 事件名
|
||||
* @param mixed $options 当前查询参数
|
||||
* @return bool
|
||||
*/
|
||||
protected function trigger($event, $options = [])
|
||||
|
||||
Reference in New Issue
Block a user