diff --git a/application/common/behavior/InitHook.php b/application/common/behavior/InitHook.php index f6b57312..8bcdf19e 100644 --- a/application/common/behavior/InitHook.php +++ b/application/common/behavior/InitHook.php @@ -45,6 +45,10 @@ class InitHook { } protected function setRoute(){ + $list = db('Rewrite')->select(); + foreach ($list as $key => $value) { + $route[$value['rule']] = $value['url']; + } $model = db('Model'); $map = array( 'status' => array('gt',0), @@ -66,11 +70,6 @@ class InitHook { $route["user/".$value['name']."/del"] = "user/content/del?model_id=".$value['id']; $route["user/".$value['name']."/status"] = "user/content/status?model_id=".$value['id']; } - - $list = db('Rewrite')->select(); - foreach ($list as $key => $value) { - $route[$value['rule']] = $value['url']; - } \think\Route::rule($route); } } \ No newline at end of file diff --git a/application/common/model/Content.php b/application/common/model/Content.php index dfed75c6..f775adf4 100644 --- a/application/common/model/Content.php +++ b/application/common/model/Content.php @@ -36,15 +36,6 @@ class Content extends Base{ return $value ? strtotime($value) : time(); } - - protected function getCreateTimeAttr($value){ - return date('Y-m-d H:i:s',$value); - } - - protected function getUpdateTimeAttr($value){ - return date('Y-m-d H:i:s',$value); - } - public function extend($name){ $this->name = $name; return $this; diff --git a/core/library/think/Build.php b/core/library/think/Build.php index ef150c9e..76d82609 100644 --- a/core/library/think/Build.php +++ b/core/library/think/Build.php @@ -21,7 +21,7 @@ class Build * @param bool $suffix 类库后缀 * @return void */ - public static function run(array $build = [], $namespace = 'app', $suffix = false ) + public static function run(array $build = [], $namespace = 'app', $suffix = false) { // 锁定 $lockfile = APP_PATH . 'build.lock'; @@ -57,7 +57,7 @@ class Build foreach ($list as $dir) { if (!is_dir(APP_PATH . $dir)) { // 创建目录 - mkdir(APP_PATH . $dir, 0644, true); + mkdir(APP_PATH . $dir, 0755, true); } } } @@ -73,7 +73,7 @@ class Build foreach ($list as $file) { if (!is_dir(APP_PATH . dirname($file))) { // 创建目录 - mkdir(APP_PATH . dirname($file), 0644, true); + mkdir(APP_PATH . dirname($file), 0755, true); } if (!is_file(APP_PATH . $file)) { file_put_contents(APP_PATH . $file, 'php' == pathinfo($file, PATHINFO_EXTENSION) ? "error = "目录 {$path} 创建失败!"; diff --git a/core/library/think/Paginator.php b/core/library/think/Paginator.php index eba38587..7385ebb0 100644 --- a/core/library/think/Paginator.php +++ b/core/library/think/Paginator.php @@ -45,7 +45,7 @@ abstract class Paginator 'fragment' => '' ]; - public function __construct($items, $listRows, $currentPage = null, $simple = false, $total = null, $options = []) + protected function __construct($items, $listRows, $currentPage = null, $total = null, $simple = false, $options = []) { $this->options = array_merge($this->options, $options); @@ -71,12 +71,21 @@ abstract class Paginator $this->items = PaginatorCollection::make($items, $this); } - public function items() + /** + * @param $items + * @param $listRows + * @param null $currentPage + * @param bool $simple + * @param null $total + * @param array $options + * @return PaginatorCollection + */ + public static function make($items, $listRows, $currentPage = null, $total = null, $simple = false, $options = []) { - return $this->items; + $paginator = new static($items, $listRows, $currentPage, $total, $simple, $options); + return $paginator->items; } - protected function setCurrentPage($currentPage) { if (!$this->simple && $currentPage > $this->lastPage) { diff --git a/core/library/think/Route.php b/core/library/think/Route.php index 3ffed5fd..de0bc30c 100644 --- a/core/library/think/Route.php +++ b/core/library/think/Route.php @@ -443,7 +443,9 @@ class Route || (isset($option['except']) && in_array($key, $option['except']))) { continue; } - if (strpos($val[1], ':id') && isset($option['var'][$rule])) { + if (isset($last) && strpos($val[1], ':id') && isset($option['var'][$last])) { + $val[1] = str_replace(':id', ':' . $option['var'][$last], $val[1]); + } elseif (strpos($val[1], ':id') && isset($option['var'][$rule])) { $val[1] = str_replace(':id', ':' . $option['var'][$rule], $val[1]); } $item = ltrim($rule . $val[1], '/'); diff --git a/core/library/think/Url.php b/core/library/think/Url.php index a5190d7b..cf570af0 100644 --- a/core/library/think/Url.php +++ b/core/library/think/Url.php @@ -19,6 +19,9 @@ use think\Route; class Url { + // 生成URL地址的root + protected static $root; + /** * URL生成 支持路由反射 * @param string $url URL表达式, @@ -113,7 +116,7 @@ class Url // 检测域名 $domain = self::parseDomain($url, $domain); // URL组装 - $url = $domain . Request::instance()->root() . '/' . ltrim($url, '/'); + $url = $domain . (self::$root ?: Request::instance()->root()) . '/' . ltrim($url, '/'); return $url; } @@ -316,4 +319,11 @@ class Url { Cache::rm('think_route_map'); } -} \ No newline at end of file + + // 指定当前生成URL地址的root + public static function root($root) + { + self::$root = $root; + Request::instance()->root($root); + } +} diff --git a/core/library/think/db/Builder.php b/core/library/think/db/Builder.php index ab95753d..3f9f989a 100644 --- a/core/library/think/db/Builder.php +++ b/core/library/think/db/Builder.php @@ -28,7 +28,7 @@ abstract class Builder protected $options = []; // 数据库表达式 - protected $exp = ['eq' => '=', 'neq' => '<>', 'gt' => '>', 'egt' => '>=', 'lt' => '<', 'elt' => '<=', 'notlike' => 'NOT LIKE', 'like' => 'LIKE', 'in' => 'IN', 'exp' => 'EXP', 'notin' => 'NOT IN', 'not in' => 'NOT IN', 'between' => 'BETWEEN', 'not between' => 'NOT BETWEEN', 'notbetween' => 'NOT BETWEEN', 'exists' => 'EXISTS', 'notexists' => 'NOT EXISTS', 'not exists' => 'NOT EXISTS', 'null' => 'NULL', 'notnull' => 'NOT NULL', 'not null' => 'NOT NULL', '> time' => '> TIME', '< time' => '< TIME', 'between time' => 'BETWEEN TIME', 'not between time' => 'NOT BETWEEN TIME', 'notbetween time' => 'NOT BETWEEN TIME']; + protected $exp = ['eq' => '=', 'neq' => '<>', 'gt' => '>', 'egt' => '>=', 'lt' => '<', 'elt' => '<=', 'notlike' => 'NOT LIKE', 'like' => 'LIKE', 'in' => 'IN', 'exp' => 'EXP', 'notin' => 'NOT IN', 'not in' => 'NOT IN', 'between' => 'BETWEEN', 'not between' => 'NOT BETWEEN', 'notbetween' => 'NOT BETWEEN', 'exists' => 'EXISTS', 'notexists' => 'NOT EXISTS', 'not exists' => 'NOT EXISTS', 'null' => 'NULL', 'notnull' => 'NOT NULL', 'not null' => 'NOT NULL', '> time' => '> TIME', '< time' => '< TIME', '>= time' => '>= TIME', '<= time' => '<= TIME', 'between time' => 'BETWEEN TIME', 'not between time' => 'NOT BETWEEN TIME', 'notbetween time' => 'NOT BETWEEN TIME']; // SQL表达式 protected $selectSql = 'SELECT%DISTINCT% %FIELD% FROM %TABLE%%FORCE%%JOIN%%WHERE%%GROUP%%HAVING%%ORDER%%LIMIT% %UNION%%LOCK%%COMMENT%'; @@ -199,12 +199,13 @@ abstract class Builder /** * where分析 * @access protected - * @param mixed $where + * @param mixed $where 查询条件 + * @param array $options 查询参数 * @return string */ - protected function parseWhere($where, $table) + protected function parseWhere($where, $options) { - $whereStr = $this->buildWhere($where, $table); + $whereStr = $this->buildWhere($where, $options); return empty($whereStr) ? '' : ' WHERE ' . $whereStr; } @@ -212,23 +213,23 @@ abstract class Builder * 生成查询条件SQL * @access public * @param mixed $where - * @param string $table + * @param array $options * @return string */ - public function buildWhere($where, $table) + public function buildWhere($where, $options) { if (empty($where)) { $where = []; } if ($where instanceof Query) { - return $this->buildWhere($where->getOptions('where'), $table); + return $this->buildWhere($where->getOptions('where'), $options); } $whereStr = ''; // 获取字段信息 - $fields = $this->query->getTableInfo($table, 'fields'); - $binds = $this->query->getTableInfo($table, 'bind'); + $fields = $this->query->getTableInfo($options['table'], 'fields'); + $binds = $this->query->getTableInfo($options['table'], 'bind'); foreach ($where as $key => $val) { $str = []; foreach ($val as $field => $value) { @@ -240,14 +241,14 @@ abstract class Builder // 使用闭包查询 $query = new Query($this->connection); call_user_func_array($value, [ & $query]); - $str[] = ' ' . $key . ' ( ' . $this->buildWhere($query->getOptions('where'), $table) . ' )'; + $str[] = ' ' . $key . ' ( ' . $this->buildWhere($query->getOptions('where'), $options) . ' )'; } else { if (strpos($field, '|')) { // 不同字段使用相同查询条件(OR) $array = explode('|', $field); $item = []; foreach ($array as $k) { - $item[] = $this->parseWhereItem($k, $value); + $item[] = $this->parseWhereItem($k, $value, '', $options); } $str[] = ' ' . $key . ' ( ' . implode(' OR ', $item) . ' )'; } elseif (strpos($field, '&')) { @@ -255,13 +256,13 @@ abstract class Builder $array = explode('&', $field); $item = []; foreach ($array as $k) { - $item[] = $this->parseWhereItem($k, $value); + $item[] = $this->parseWhereItem($k, $value, '', $options); } $str[] = ' ' . $key . ' ( ' . implode(' AND ', $item) . ' )'; } else { // 对字段使用表达式查询 $field = is_string($field) ? $field : ''; - $str[] = ' ' . $key . ' ' . $this->parseWhereItem($field, $value, $key); + $str[] = ' ' . $key . ' ' . $this->parseWhereItem($field, $value, $key, $options); } } } @@ -272,7 +273,7 @@ abstract class Builder } // where子单元分析 - protected function parseWhereItem($field, $val, $rule = '') + protected function parseWhereItem($field, $val, $rule = '', $options = []) { // 字段分析 $key = $field ? $this->parseKey($field) : ''; @@ -293,7 +294,7 @@ abstract class Builder array_push($val, $item); } foreach ($val as $item) { - $str[] = $this->parseWhereItem($key, $item, $rule); + $str[] = $this->parseWhereItem($key, $item, $rule, $options); } return '( ' . implode(' ' . $rule . ' ', $str) . ' )'; } @@ -338,13 +339,13 @@ abstract class Builder } else { $whereStr .= $exp . ' (' . $value . ')'; } - } elseif (in_array($exp, ['< TIME', '> TIME'])) { - $whereStr .= $key . ' ' . substr($exp, 0, 1) . ' ' . $this->parseDateTime($value, $field); + } elseif (in_array($exp, ['< TIME', '> TIME', '<= TIME', '>= TIME'])) { + $whereStr .= $key . ' ' . substr($exp, 0, 2) . ' ' . $this->parseDateTime($value, $field, $options); } elseif (in_array($exp, ['BETWEEN TIME', 'NOT BETWEEN TIME'])) { if (is_string($value)) { $value = explode(',', $value); } - $whereStr .= $key . ' ' . substr($exp, 0, -4) . $this->parseDateTime($value[0], $field) . ' AND ' . $this->parseDateTime($value[1], $field); + $whereStr .= $key . ' ' . substr($exp, 0, -4) . $this->parseDateTime($value[0], $field, $options) . ' AND ' . $this->parseDateTime($value[1], $field, $options); } return $whereStr; } @@ -362,18 +363,24 @@ abstract class Builder * @access protected * @param string $value * @param string $key + * @param array $options * @return string */ - protected function parseDateTime($value, $key) + protected function parseDateTime($value, $key, $options = []) { // 获取时间字段类型 $type = $this->query->getTableInfo('', 'type'); - if (isset($type[$key])) { + if (isset($options['field_type'][$key])) { + $info = $options['field_type'][$key]; + } elseif (isset($type[$key])) { + $info = $type[$key]; + } + if (isset($info)) { $value = strtotime($value) ?: $value; - if (preg_match('/(datetime|timestamp)/is', $type[$key])) { + if (preg_match('/(datetime|timestamp)/is', $info)) { // 日期及时间戳类型 $value = date('Y-m-d H:i:s', $value); - } elseif (preg_match('/(date)/is', $type[$key])) { + } elseif (preg_match('/(date)/is', $info)) { // 日期及时间戳类型 $value = date('Y-m-d', $value); } @@ -546,7 +553,7 @@ abstract class Builder $this->parseDistinct($options['distinct']), $this->parseField($options['field']), $this->parseJoin($options['join']), - $this->parseWhere($options['where'], $options['table']), + $this->parseWhere($options['where'], $options), $this->parseGroup($options['group']), $this->parseHaving($options['having']), $this->parseOrder($options['order']), @@ -679,7 +686,7 @@ abstract class Builder $this->parseTable($options['table']), implode(',', $set), $this->parseJoin($options['join']), - $this->parseWhere($options['where'], $options['table']), + $this->parseWhere($options['where'], $options), $this->parseOrder($options['order']), $this->parseLimit($options['limit']), $this->parseLimit($options['lock']), @@ -703,7 +710,7 @@ abstract class Builder $this->parseTable($options['table']), !empty($options['using']) ? ' USING ' . $this->parseTable($options['using']) . ' ' : '', $this->parseJoin($options['join']), - $this->parseWhere($options['where'], $options['table']), + $this->parseWhere($options['where'], $options), $this->parseOrder($options['order']), $this->parseLimit($options['limit']), $this->parseLimit($options['lock']), diff --git a/core/library/think/db/Query.php b/core/library/think/db/Query.php index b589ff54..b1451de8 100644 --- a/core/library/think/db/Query.php +++ b/core/library/think/db/Query.php @@ -54,7 +54,7 @@ class Query * 架构函数 * @access public * @param Connection $connection 数据库对象实例 - * @param string $model 模型名 + * @param string $model 模型名 */ public function __construct(Connection $connection = null, $model = '') { @@ -67,8 +67,8 @@ class Query /** * 利用__call方法实现一些特殊的Model方法 * @access public - * @param string $method 方法名称 - * @param array $args 调用参数 + * @param string $method 方法名称 + * @param array $args 调用参数 * @return mixed * @throws DbException * @throws Exception @@ -176,10 +176,10 @@ class Query /** * 执行查询 返回数据集 * @access public - * @param string $sql sql指令 - * @param array $bind 参数绑定 - * @param boolean $master 是否在主服务器读操作 - * @param bool|string $class 指定返回的数据集对象 + * @param string $sql sql指令 + * @param array $bind 参数绑定 + * @param boolean $master 是否在主服务器读操作 + * @param bool|string $class 指定返回的数据集对象 * @return mixed * @throws BindParamException * @throws PDOException @@ -192,10 +192,10 @@ class Query /** * 执行语句 * @access public - * @param string $sql sql指令 - * @param array $bind 参数绑定 - * @param boolean $getLastInsID 是否获取自增ID - * @param boolean $sequence 自增序列名 + * @param string $sql sql指令 + * @param array $bind 参数绑定 + * @param boolean $getLastInsID 是否获取自增ID + * @param boolean $sequence 自增序列名 * @return int * @throws BindParamException * @throws PDOException @@ -294,9 +294,9 @@ class Query /** * 得到分表的的数据表名 * @access public - * @param array $data 操作的数据 - * @param string $field 分表依据的字段 - * @param array $rule 分表规则 + * @param array $data 操作的数据 + * @param string $field 分表依据的字段 + * @param array $rule 分表规则 * @return string */ public function getPartitionTableName($data, $field, $rule = []) @@ -357,7 +357,7 @@ class Query protected function builder() { static $builder = []; - $driver = $this->driver; + $driver = $this->driver; if (!isset($builder[$driver])) { $class = '\\think\\db\\builder\\' . ucfirst($driver); $builder[$driver] = new $class($this->connection); @@ -370,8 +370,8 @@ class Query /** * 得到某个字段的值 * @access public - * @param string $field 字段名 - * @param mixed $default 默认值 + * @param string $field 字段名 + * @param mixed $default 默认值 * @return mixed */ public function value($field, $default = null) @@ -410,8 +410,8 @@ class Query /** * 得到某个列的数组 * @access public - * @param string $field 字段名 多个字段用逗号分隔 - * @param string $key 索引 + * @param string $field 字段名 多个字段用逗号分隔 + * @param string $key 索引 * @return array */ public function column($field, $key = '') @@ -531,8 +531,8 @@ class Query * 设置记录的某个字段值 * 支持使用数据库字段和方法 * @access public - * @param string|array $field 字段名 - * @param mixed $value 字段值 + * @param string|array $field 字段名 + * @param mixed $value 字段值 * @return integer */ public function setField($field, $value = '') @@ -548,9 +548,9 @@ class Query /** * 字段值(延迟)增长 * @access public - * @param string $field 字段名 - * @param integer $step 增长值 - * @param integer $lazyTime 延时时间(s) + * @param string $field 字段名 + * @param integer $step 增长值 + * @param integer $lazyTime 延时时间(s) * @return integer|true * @throws Exception */ @@ -575,9 +575,9 @@ class Query /** * 字段值(延迟)减少 * @access public - * @param string $field 字段名 - * @param integer $step 减少值 - * @param integer $lazyTime 延时时间(s) + * @param string $field 字段名 + * @param integer $step 减少值 + * @param integer $lazyTime 延时时间(s) * @return integer|true * @throws Exception */ @@ -603,9 +603,9 @@ class Query * 延时更新检查 返回false表示需要延时 * 否则返回实际写入的数值 * @access public - * @param string $guid 写入标识 - * @param integer $step 写入步进值 - * @param integer $lazyTime 延时时间(s) + * @param string $guid 写入标识 + * @param integer $step 写入步进值 + * @param integer $lazyTime 延时时间(s) * @return false|integer */ protected function lazyWrite($guid, $step, $lazyTime) @@ -634,9 +634,9 @@ class Query /** * 查询SQL组装 join * @access public - * @param mixed $join 关联的表名 - * @param mixed $condition 条件 - * @param string $type JOIN类型 + * @param mixed $join 关联的表名 + * @param mixed $condition 条件 + * @param string $type JOIN类型 * @return $this */ public function join($join, $condition = null, $type = 'INNER') @@ -660,7 +660,7 @@ class Query } if (count($join)) { // 有设置第二个元素则把第二元素作为表前缀 - $table = (string) current($join) . $table; + $table = (string)current($join) . $table; } elseif (false === strpos($table, '.')) { // 加上默认的表前缀 $table = $prefix . $table; @@ -687,8 +687,8 @@ class Query /** * 查询SQL组装 union * @access public - * @param mixed $union - * @param boolean $all + * @param mixed $union + * @param boolean $all * @return $this */ public function union($union, $all = false) @@ -706,11 +706,11 @@ class Query /** * 指定查询字段 支持字段排除和指定数据表 * @access public - * @param mixed $field - * @param boolean $except 是否排除 - * @param string $tableName 数据表名 - * @param string $prefix 字段前缀 - * @param string $alias 别名前缀 + * @param mixed $field + * @param boolean $except 是否排除 + * @param string $tableName 数据表名 + * @param string $prefix 字段前缀 + * @param string $alias 别名前缀 * @return $this */ public function field($field, $except = false, $tableName = '', $prefix = '', $alias = '') @@ -751,10 +751,10 @@ class Query /** * 指定JOIN查询字段 * @access public - * @param string|array $table 数据表 - * @param string|array $field 查询字段 - * @param string|array $on JOIN条件 - * @param string $type JOIN类型 + * @param string|array $table 数据表 + * @param string|array $field 查询字段 + * @param string|array $on JOIN条件 + * @param string $type JOIN类型 * @return $this */ public function view($join, $field = null, $on = null, $type = 'INNER') @@ -807,9 +807,9 @@ class Query /** * 设置分表规则 * @access public - * @param array $data 操作的数据 - * @param string $field 分表依据的字段 - * @param array $rule 分表规则 + * @param array $data 操作的数据 + * @param string $field 分表依据的字段 + * @param array $rule 分表规则 * @return $this */ public function partition($data, $field, $rule = []) @@ -821,9 +821,9 @@ class Query /** * 指定AND查询条件 * @access public - * @param mixed $field 查询字段 - * @param mixed $op 查询表达式 - * @param mixed $condition 查询条件 + * @param mixed $field 查询字段 + * @param mixed $op 查询表达式 + * @param mixed $condition 查询条件 * @return $this */ public function where($field, $op = null, $condition = null) @@ -837,9 +837,9 @@ class Query /** * 指定OR查询条件 * @access public - * @param mixed $field 查询字段 - * @param mixed $op 查询表达式 - * @param mixed $condition 查询条件 + * @param mixed $field 查询字段 + * @param mixed $op 查询表达式 + * @param mixed $condition 查询条件 * @return $this */ public function whereOr($field, $op = null, $condition = null) @@ -853,9 +853,9 @@ class Query /** * 指定XOR查询条件 * @access public - * @param mixed $field 查询字段 - * @param mixed $op 查询表达式 - * @param mixed $condition 查询条件 + * @param mixed $field 查询字段 + * @param mixed $op 查询表达式 + * @param mixed $condition 查询条件 * @return $this */ public function whereXor($field, $op = null, $condition = null) @@ -869,11 +869,11 @@ class Query /** * 分析查询表达式 * @access public - * @param string $logic 查询逻辑 and or xor - * @param string|array|\Closure $field 查询字段 - * @param mixed $op 查询表达式 + * @param string $logic 查询逻辑 and or xor + * @param string|array|\Closure $field 查询字段 + * @param mixed $op 查询表达式 * @param mixed $condition 查询条件 - * @param array $param 查询参数 + * @param array $param 查询参数 * @return void */ protected function parseWhereExp($logic, $field, $op, $condition, $param = []) @@ -940,7 +940,7 @@ class Query /** * 指定分页 * @access public - * @param mixed $page 页数 + * @param mixed $page 页数 * @param mixed $listRows 每页数量 * @return $this */ @@ -955,16 +955,16 @@ class Query /** * 分页查询 - * @param int|null $listRows 每页数量 - * @param bool $simple 简洁模式 - * @param array $config 配置参数 - * page:当前页, - * path:url路径, - * query:url额外参数, - * fragment:url锚点, - * var_page:分页变量, - * list_rows:每页数量 - * type:分页类名 + * @param int|null $listRows 每页数量 + * @param bool $simple 简洁模式 + * @param array $config 配置参数 + * page:当前页, + * path:url路径, + * query:url额外参数, + * fragment:url锚点, + * var_page:分页变量, + * list_rows:每页数量 + * type:分页类名 * @return \think\paginator\Collection * @throws DbException */ @@ -972,8 +972,10 @@ class Query { $config = array_merge(Config::get('paginate'), $config); $listRows = $listRows ?: $config['list_rows']; - $class = false !== strpos($config['type'], '\\') ? $config['type'] : '\\think\\paginator\\driver\\' . ucwords($config['type']); - $page = isset($config['page']) ? (int) $config['page'] : call_user_func([ + + /** @var Paginator $class */ + $class = false !== strpos($config['type'], '\\') ? $config['type'] : '\\think\\paginator\\driver\\' . ucwords($config['type']); + $page = isset($config['page']) ? (int)$config['page'] : call_user_func([ $class, 'getCurrentPage', ], $config['var_page']); @@ -981,8 +983,7 @@ class Query $page = $page < 1 ? 1 : $page; $config['path'] = isset($config['path']) ? $config['path'] : call_user_func([$class, 'getCurrentPath']); - - /** @var Paginator $paginator */ + if (!$simple) { $options = $this->getOptions(); $total = $this->count(); @@ -992,8 +993,7 @@ class Query $total = null; } - $paginator = new $class($results, $listRows, $page, $simple, $total, $config); - return $paginator->items(); + return $class::make($results, $listRows, $page, $total, $simple, $config); } /** @@ -1023,8 +1023,8 @@ class Query /** * 指定排序 order('id','desc') 或者 order(['id'=>'desc','create_time'=>'desc']) * @access public - * @param string|array $field 排序字段 - * @param string $order 排序 + * @param string|array $field 排序字段 + * @param string $order 排序 * @return $this */ public function order($field, $order = null) @@ -1053,8 +1053,8 @@ class Query /** * 查询缓存 * @access public - * @param mixed $key 缓存key - * @param integer $expire 缓存有效期 + * @param mixed $key 缓存key + * @param integer $expire 缓存有效期 * @return $this */ public function cache($key = true, $expire = null) @@ -1241,9 +1241,9 @@ class Query /** * 查询日期或者时间 * @access public - * @param string $field 日期字段名 - * @param string $op 比较运算符或者表达式 - * @param string|array $range 比较范围 + * @param string $field 日期字段名 + * @param string $op 比较运算符或者表达式 + * @param string|array $range 比较范围 * @return $this */ public function whereTime($field, $op, $range = null) @@ -1287,11 +1287,23 @@ class Query return $this; } + /** + * 设置字段类型 + * @access public + * @param array $fieldType 字段类型信息 + * @return $this + */ + public function setFieldType($fieldType = []) + { + $this->options['field_type'] = $fieldType; + return $this; + } + /** * 获取数据表信息 * @access public * @param string $tableName 数据表名 留空自动获取 - * @param string $fetch 获取信息类型 包括 fields type bind pk + * @param string $fetch 获取信息类型 包括 fields type bind pk * @return mixed */ public function getTableInfo($tableName = '', $fetch = '') @@ -1314,7 +1326,7 @@ class Query if (!isset($this->info[$guid])) { $info = $this->connection->getFields($tableName); $fields = array_keys($info); - $bind = $type = []; + $bind = $type = []; foreach ($info as $key => $val) { // 记录字段类型 $type[$key] = $val['type']; @@ -1354,9 +1366,9 @@ class Query /** * 参数绑定 * @access public - * @param mixed $key 参数名 - * @param mixed $value 绑定变量值 - * @param integer $type 绑定类型 + * @param mixed $key 参数名 + * @param mixed $value 绑定变量值 + * @param integer $type 绑定类型 * @return $this */ public function bind($key, $value = false, $type = PDO::PARAM_STR) @@ -1432,7 +1444,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); } @@ -1467,7 +1479,7 @@ class Query if ($closure) { // 执行闭包查询 - call_user_func_array($closure, [ & $this]); + call_user_func_array($closure, [& $this]); //指定获取关联的字段 //需要在 回调中 调方法 withField 方法,如 // $query->where(['id'=>1])->withField('id,name'); @@ -1530,8 +1542,8 @@ class Query /** * 把主键值转换为查询条件 支持复合主键 * @access public - * @param array|string $data 主键数据 - * @param mixed $options 表达式参数 + * @param array|string $data 主键数据 + * @param mixed $options 表达式参数 * @return void * @throws Exception */ @@ -1575,10 +1587,10 @@ class Query /** * 插入记录 * @access public - * @param mixed $data 数据 - * @param boolean $replace 是否replace - * @param boolean $getLastInsID 是否获取自增ID - * @param string $sequence 自增序列名 + * @param mixed $data 数据 + * @param boolean $replace 是否replace + * @param boolean $getLastInsID 是否获取自增ID + * @param string $sequence 自增序列名 * @return integer|string */ public function insert(array $data, $replace = false, $getLastInsID = false, $sequence = null) @@ -1599,9 +1611,9 @@ class Query /** * 插入记录并获取自增ID * @access public - * @param mixed $data 数据 - * @param boolean $replace 是否replace - * @param string $sequence 自增序列名 + * @param mixed $data 数据 + * @param boolean $replace 是否replace + * @param string $sequence 自增序列名 * @return integer|string */ public function insertGetId(array $data, $replace = false, $sequence = null) @@ -1636,8 +1648,8 @@ class Query /** * 通过Select方式插入记录 * @access public - * @param string $fields 要插入的数据表字段名 - * @param string $table 要插入的数据表名 + * @param string $fields 要插入的数据表字段名 + * @param string $table 要插入的数据表名 * @return integer|string * @throws PDOException */ @@ -1724,7 +1736,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; } // 分析查询表达式 @@ -1807,7 +1819,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; } // 分析查询表达式 @@ -1923,9 +1935,9 @@ class Query /** * 分批数据返回处理 * @access public - * @param integer $count 每次处理的数据数量 - * @param callable $callback 处理回调方法 - * @param string $column 分批处理的字段名 + * @param integer $count 每次处理的数据数量 + * @param callable $callback 处理回调方法 + * @param string $column 分批处理的字段名 * @return boolean */ public function chunk($count, $callback, $column = null) @@ -2100,10 +2112,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 = []; diff --git a/core/library/think/model/Merge.php b/core/library/think/model/Merge.php index 2239af73..1bf634f4 100644 --- a/core/library/think/model/Merge.php +++ b/core/library/think/model/Merge.php @@ -224,7 +224,7 @@ class Merge extends Model } // 处理模型数据 - $data = $this->parseData($this->name, $this->data); + $data = $this->parseData($this->name, $this->data, true); // 写入主表数据 $result = $db->name($this->name)->strict(false)->insert($data, $replace); if ($result) { diff --git a/core/library/think/paginator/Collection.php b/core/library/think/paginator/Collection.php index 64fbb93b..82e88272 100644 --- a/core/library/think/paginator/Collection.php +++ b/core/library/think/paginator/Collection.php @@ -23,6 +23,8 @@ use think\Paginator; * @method string render() * @method Paginator fragment($fragment) * @method Paginator appends($key, $value) + * @method integer lastPage() + * @method boolean hasPages() */ class Collection extends \think\Collection { @@ -40,17 +42,7 @@ class Collection extends \think\Collection { return new static($items, $paginator); } - - public function setPaginator(Paginator $paginator) - { - $this->paginator = $paginator; - } - - public function getPaginator() - { - return $this->paginator; - } - + public function toArray() { if ($this->paginator) { diff --git a/core/library/think/template/driver/File.php b/core/library/think/template/driver/File.php index a049d683..1cd041af 100644 --- a/core/library/think/template/driver/File.php +++ b/core/library/think/template/driver/File.php @@ -26,7 +26,7 @@ class File // 检测模板目录 $dir = dirname($cacheFile); if (!is_dir($dir)) { - mkdir($dir, 0644, true); + mkdir($dir, 0755, true); } // 生成模板缓存文件 if (false === file_put_contents($cacheFile, $content)) {