diff --git a/thinkphp/.gitignore b/thinkphp/.gitignore
index 7e31ef510..f7775ba41 100644
--- a/thinkphp/.gitignore
+++ b/thinkphp/.gitignore
@@ -1,4 +1,8 @@
-/composer.lock
 /vendor
-.idea
+composer.phar
+composer.lock
 .DS_Store
+Thumbs.db
+/phpunit.xml
+/.idea
+/.vscode
\ No newline at end of file
diff --git a/thinkphp/library/think/App.php b/thinkphp/library/think/App.php
index ae87e5973..d928969b7 100644
--- a/thinkphp/library/think/App.php
+++ b/thinkphp/library/think/App.php
@@ -20,7 +20,7 @@ use think\route\Dispatch;
  */
 class App implements \ArrayAccess
 {
-    const VERSION = '5.1.6';
+    const VERSION = '5.1.7';
 
     /**
      * 当前模块路径
diff --git a/thinkphp/library/think/Loader.php b/thinkphp/library/think/Loader.php
index 168ed1f86..d8065f23c 100644
--- a/thinkphp/library/think/Loader.php
+++ b/thinkphp/library/think/Loader.php
@@ -17,7 +17,7 @@ class Loader
      * 类名映射信息
      * @var array
      */
-    protected static $map = [];
+    protected static $classMap = [];
 
     /**
      * 类库别名
@@ -76,12 +76,11 @@ class Loader
                 $declaredClass = get_declared_classes();
                 $composerClass = array_pop($declaredClass);
 
-                self::$prefixLengthsPsr4 = $composerClass::$prefixLengthsPsr4;
-
-                self::$prefixDirsPsr4 = property_exists($composerClass, 'prefixDirsPsr4') ? $composerClass::$prefixDirsPsr4 : [];
-
-                self::$prefixesPsr0 = property_exists($composerClass, 'prefixesPsr0') ? $composerClass::$prefixesPsr0 : [];
-                self::$map          = property_exists($composerClass, 'classMap') ? $composerClass::$classMap : [];
+                foreach (['prefixLengthsPsr4', 'prefixDirsPsr4', 'prefixesPsr0', 'classMap'] as $attr) {
+                    if (property_exists($composerClass, $attr)) {
+                        self::${$attr} = $composerClass::${$attr};
+                    }
+                }
             } else {
                 self::registerComposerLoader(self::$composerPath);
             }
@@ -129,9 +128,9 @@ class Loader
      */
     private static function findFile($class)
     {
-        if (!empty(self::$map[$class])) {
+        if (!empty(self::$classMap[$class])) {
             // 类库映射
-            return self::$map[$class];
+            return self::$classMap[$class];
         }
 
         // 查找 PSR-4
@@ -186,16 +185,16 @@ class Loader
             }
         }
 
-        return self::$map[$class] = false;
+        return self::$classMap[$class] = false;
     }
 
     // 注册classmap
     public static function addClassMap($class, $map = '')
     {
         if (is_array($class)) {
-            self::$map = array_merge(self::$map, $class);
+            self::$classMap = array_merge(self::$classMap, $class);
         } else {
-            self::$map[$class] = $map;
+            self::$classMap[$class] = $map;
         }
     }
 
diff --git a/thinkphp/library/think/Middleware.php b/thinkphp/library/think/Middleware.php
index b59b72375..296de275b 100644
--- a/thinkphp/library/think/Middleware.php
+++ b/thinkphp/library/think/Middleware.php
@@ -80,7 +80,12 @@ class Middleware
             throw new \InvalidArgumentException('The middleware is invalid');
         }
 
-        $class = false === strpos($middleware, '\\') ? Container::get('app')->getNamespace() . '\\http\\middleware\\' . $middleware : $middleware;
+        if (false === strpos($middleware, '\\')) {
+            $value = Container::get('config')->get('middleware.' . $middleware);
+            $class = $value ?: Container::get('app')->getNamespace() . '\\http\\middleware\\' . $middleware;
+        } else {
+            $class = $middleware;
+        }
 
         if (strpos($class, ':')) {
             list($class, $param) = explode(':', $class, 2);
diff --git a/thinkphp/library/think/Response.php b/thinkphp/library/think/Response.php
index 071d075c7..59660a9d4 100644
--- a/thinkphp/library/think/Response.php
+++ b/thinkphp/library/think/Response.php
@@ -97,9 +97,7 @@ class Response
      */
     public static function create($data = '', $type = '', $code = 200, array $header = [], $options = [])
     {
-        $type = empty($type) ? 'null' : strtolower($type);
-
-        $class = false !== strpos($type, '\\') ? $type : '\\think\\response\\' . ucfirst($type);
+        $class = false !== strpos($type, '\\') ? $type : '\\think\\response\\' . ucfirst(strtolower($type));
 
         if (class_exists($class)) {
             return new $class($data, $code, $header, $options);
diff --git a/thinkphp/library/think/Validate.php b/thinkphp/library/think/Validate.php
index 90c5d8333..4abfc6b25 100644
--- a/thinkphp/library/think/Validate.php
+++ b/thinkphp/library/think/Validate.php
@@ -198,6 +198,7 @@ class Validate
      * @param  array $rules 验证规则
      * @param  array $message 验证提示信息
      * @param  array $field 验证字段描述信息
+     * @return Validate
      */
     public static function make(array $rules = [], array $message = [], array $field = [])
     {
@@ -1437,7 +1438,7 @@ class Validate
      * 获取数据验证的场景
      * @access protected
      * @param  string $scene  验证场景
-     * @return array
+     * @return void
      */
     protected function getScene($scene = '')
     {
diff --git a/thinkphp/library/think/db/Builder.php b/thinkphp/library/think/db/Builder.php
index 239a02138..d6a5df4e7 100644
--- a/thinkphp/library/think/db/Builder.php
+++ b/thinkphp/library/think/db/Builder.php
@@ -115,7 +115,10 @@ abstract class Builder
         foreach ($data as $key => $val) {
             $item = $this->parseKey($query, $key);
 
-            if (!is_scalar($val) && (in_array($key, (array) $query->getOptions('json')) || 'json' == $this->connection->getFieldsType($options['table'], $key))) {
+            if ($val instanceof Expression) {
+                $result[$item] = $val->getValue();
+                continue;
+            } elseif (!is_scalar($val) && (in_array($key, (array) $query->getOptions('json')) || 'json' == $this->connection->getFieldsType($options['table'], $key))) {
                 $val = json_encode($val);
             } elseif (is_object($val) && method_exists($val, '__toString')) {
                 // 对象数据写入
@@ -134,21 +137,17 @@ abstract class Builder
                 $result[$item] = 'NULL';
             } elseif (is_array($val) && !empty($val)) {
                 switch ($val[0]) {
-                    case 'exp':
-                        if (isset($val[2]) && $query->getSecureKey() == $val[2]) {
-                            $result[$item] = $val[1];
-                        }
+                    case 'INC':
+                        $result[$item] = $item . ' + ' . floatval($val[1]);
                         break;
-                    case 'inc':
-                        if ($key == $val[1]) {
-                            $result[$item] = $this->parseKey($query, $val[1]) . ' + ' . floatval($val[2]);
-                        }
+                    case 'DEC':
+                        $result[$item] = $item . ' - ' . floatval($val[1]);
                         break;
-                    case 'dec':
-                        if ($key == $val[1]) {
-                            $result[$item] = $this->parseKey($query, $val[1]) . ' - ' . floatval($val[2]);
+                    default:
+                        $value = $this->parseArrayData($query, $val);
+                        if ($value) {
+                            $result[$item] = $value;
                         }
-                        break;
                 }
             } elseif (is_scalar($val)) {
                 // 过滤非标量数据
@@ -159,6 +158,18 @@ abstract class Builder
         return $result;
     }
 
+    /**
+     * 数组数据解析
+     * @access protected
+     * @param  Query     $query     查询对象
+     * @param  array     $data
+     * @return mixed
+     */
+    protected function parseArrayData(Query $query, $data)
+    {
+        return false;
+    }
+
     /**
      * 数据绑定处理
      * @access protected
@@ -175,9 +186,12 @@ abstract class Builder
         if (0 === strpos($data, ':') && $query->isBind(substr($data, 1))) {
             return $data;
         }
+
         $key  = str_replace(['.', '->'], '_', $key);
         $name = 'data__' . $key . $suffix;
+
         $query->bind($name, $data, isset($bind[$key]) ? $bind[$key] : PDO::PARAM_STR);
+
         return ':' . $name;
     }
 
@@ -209,7 +223,9 @@ abstract class Builder
             $array = [];
 
             foreach ($fields as $key => $field) {
-                if (!is_numeric($key)) {
+                if ($field instanceof Expression) {
+                    $array[] = $field->getValue();
+                } elseif (!is_numeric($key)) {
                     $array[] = $this->parseKey($query, $key) . ' AS ' . $this->parseKey($query, $field);
                 } else {
                     $array[] = $this->parseKey($query, $field);
@@ -296,6 +312,11 @@ abstract class Builder
             $str = [];
 
             foreach ($val as $value) {
+                if ($value instanceof Expression) {
+                    $str[] = ' ' . $logic . ' ( ' . $value->getValue() . ' )';
+                    continue;
+                }
+
                 if (is_array($value)) {
                     if (key($value) !== 0) {
                         throw new Exception('where express error:' . var_export($value, true));
@@ -363,7 +384,7 @@ abstract class Builder
 
         // 查询规则和条件
         if (!is_array($val)) {
-            $val = is_null($val) ? ['null', ''] : ['=', $val];
+            $val = is_null($val) ? ['NULL', ''] : ['=', $val];
         }
 
         list($exp, $value) = $val;
@@ -400,7 +421,9 @@ abstract class Builder
             $bindName = md5($bindName);
         }
 
-        if (is_object($value) && method_exists($value, '__toString')) {
+        if ($value instanceof Expression) {
+
+        } elseif (is_object($value) && method_exists($value, '__toString')) {
             // 对象数据写入
             $value = $value->__toString();
         }
@@ -478,10 +501,10 @@ abstract class Builder
      * @param  integer   $bindType
      * @return string
      */
-    protected function parseExp(Query $query, $key, $exp, $value, $field, $bindName, $bindType)
+    protected function parseExp(Query $query, $key, $exp, Expression $value, $field, $bindName, $bindType)
     {
         // 表达式查询
-        return '( ' . $key . ' ' . $value . ' )';
+        return '( ' . $key . ' ' . $value->getValue() . ' )';
     }
 
     /**
@@ -806,7 +829,9 @@ abstract class Builder
             $array = [];
 
             foreach ($order as $key => $val) {
-                if (is_array($val)) {
+                if ($val instanceof Expression) {
+                    $array[] = $val->getValue();
+                } elseif (is_array($val)) {
                     if (isset($val['sort'])) {
                         $sort = ' ' . $val['sort'];
                         unset($val['sort']);
diff --git a/thinkphp/library/think/db/Expression.php b/thinkphp/library/think/db/Expression.php
new file mode 100644
index 000000000..f1b92abd7
--- /dev/null
+++ b/thinkphp/library/think/db/Expression.php
@@ -0,0 +1,48 @@
+<?php
+// +----------------------------------------------------------------------
+// | ThinkPHP [ WE CAN DO IT JUST THINK ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: liu21st <liu21st@gmail.com>
+// +----------------------------------------------------------------------
+
+namespace think\db;
+
+class Expression
+{
+    /**
+     * 查询表达式
+     *
+     * @var string
+     */
+    protected $value;
+
+    /**
+     * 创建一个查询表达式
+     *
+     * @param  string  $value
+     * @return void
+     */
+    public function __construct($value)
+    {
+        $this->value = $value;
+    }
+
+    /**
+     * 获取表达式
+     *
+     * @return string
+     */
+    public function getValue()
+    {
+        return $this->value;
+    }
+
+    public function __toString()
+    {
+        return (string) $this->value;
+    }
+}
diff --git a/thinkphp/library/think/db/Query.php b/thinkphp/library/think/db/Query.php
index 1d96724fc..98efcfa66 100644
--- a/thinkphp/library/think/db/Query.php
+++ b/thinkphp/library/think/db/Query.php
@@ -58,12 +58,6 @@ class Query
      */
     protected $pk;
 
-    /**
-     * 查询安全Key
-     * @var string
-     */
-    protected $secureKey;
-
     /**
      * 当前数据表前缀
      * @var string
@@ -127,8 +121,7 @@ class Query
             $this->connection = $connection;
         }
 
-        $this->prefix    = $this->connection->getConfig('prefix');
-        $this->secureKey = Container::get('request')->secureKey();
+        $this->prefix = $this->connection->getConfig('prefix');
     }
 
     /**
@@ -271,16 +264,6 @@ class Query
         return $this->name ?: $this->model->getName();
     }
 
-    /**
-     * 获取查询安全Key
-     * @access public
-     * @return string
-     */
-    public function getSecureKey()
-    {
-        return $this->secureKey;
-    }
-
     /**
      * 得到当前或者指定名称的数据表
      * @access public
@@ -725,7 +708,7 @@ class Query
             }
         }
 
-        return $this->setField($field, ['inc', $field, $step]);
+        return $this->setField($field, ['INC', $step]);
     }
 
     /**
@@ -757,9 +740,9 @@ class Query
                 return true;
             }
 
-            $value = ['inc', $field, $step];
+            $value = ['INC', $step];
         } else {
-            $value = ['dec', $field, $step];
+            $value = ['DEC', $step];
         }
 
         return $this->setField($field, $value);
@@ -948,9 +931,16 @@ class Query
     {
         if (empty($field)) {
             return $this;
+        } elseif ($field instanceof Expression) {
+            $this->options['field'][] = $field;
+            return $this;
         }
 
         if (is_string($field)) {
+            if (preg_match('/[\<\'\"\(]/', $field)) {
+                return $this->fieldRaw($field);
+            }
+
             $field = array_map('trim', explode(',', $field));
         }
 
@@ -984,6 +974,24 @@ class Query
         return $this;
     }
 
+    /**
+     * 表达式方式指定查询字段
+     * @access public
+     * @param  string $field    字段名
+     * @param  array  $bind     参数绑定
+     * @return $this
+     */
+    public function fieldRaw($field, array $bind = [])
+    {
+        $this->options['field'][] = $this->raw($field);
+
+        if ($bind) {
+            $this->bind($bind);
+        }
+
+        return $this;
+    }
+
     /**
      * 设置数据排除字段
      * @access public
@@ -1020,12 +1028,18 @@ class Query
      * @param  integer      $step  增长值
      * @return $this
      */
-    public function inc($field, $step = 1)
+    public function inc($field, $step = 1, $op = 'INC')
     {
         $fields = is_string($field) ? explode(',', $field) : $field;
 
-        foreach ($fields as $field) {
-            $this->data($field, ['inc', $field, $step]);
+        foreach ($fields as $field => $val) {
+            if (is_numeric($field)) {
+                $field = $val;
+            } else {
+                $step = $val;
+            }
+
+            $this->data($field, [$op, $step]);
         }
 
         return $this;
@@ -1040,13 +1054,7 @@ class Query
      */
     public function dec($field, $step = 1)
     {
-        $fields = is_string($field) ? explode(',', $field) : $field;
-
-        foreach ($fields as $field) {
-            $this->data($field, ['dec', $field, $step]);
-        }
-
-        return $this;
+        return $this->inc($field, $step, 'DEC');
     }
 
     /**
@@ -1058,10 +1066,21 @@ class Query
      */
     public function exp($field, $value)
     {
-        $this->data($field, ['exp', $value, $this->secureKey]);
+        $this->data($field, $this->raw($value));
         return $this;
     }
 
+    /**
+     * 使用表达式设置数据
+     * @access public
+     * @param  mixed $value 表达式
+     * @return Expression
+     */
+    public function raw($value)
+    {
+        return new Expression($value);
+    }
+
     /**
      * 指定JOIN查询字段
      * @access public
@@ -1190,7 +1209,7 @@ class Query
      */
     public function whereNull($field, $logic = 'AND')
     {
-        return $this->parseWhereExp($logic, $field, 'null', null, [], true);
+        return $this->parseWhereExp($logic, $field, 'NULL', null, [], true);
     }
 
     /**
@@ -1202,7 +1221,7 @@ class Query
      */
     public function whereNotNull($field, $logic = 'AND')
     {
-        return $this->parseWhereExp($logic, $field, 'notnull', null, [], true);
+        return $this->parseWhereExp($logic, $field, 'NOTNULL', null, [], true);
     }
 
     /**
@@ -1214,7 +1233,7 @@ class Query
      */
     public function whereExists($condition, $logic = 'AND')
     {
-        $this->options['where'][strtoupper($logic)][] = ['', 'exists', $condition];
+        $this->options['where'][strtoupper($logic)][] = ['', 'EXISTS', $condition];
         return $this;
     }
 
@@ -1227,7 +1246,7 @@ class Query
      */
     public function whereNotExists($condition, $logic = 'AND')
     {
-        $this->options['where'][strtoupper($logic)][] = ['', 'not exists', $condition];
+        $this->options['where'][strtoupper($logic)][] = ['', 'NOT EXISTS', $condition];
         return $this;
     }
 
@@ -1241,7 +1260,7 @@ class Query
      */
     public function whereIn($field, $condition, $logic = 'AND')
     {
-        return $this->parseWhereExp($logic, $field, 'in', $condition, [], true);
+        return $this->parseWhereExp($logic, $field, 'IN', $condition, [], true);
     }
 
     /**
@@ -1254,7 +1273,7 @@ class Query
      */
     public function whereNotIn($field, $condition, $logic = 'AND')
     {
-        return $this->parseWhereExp($logic, $field, 'not in', $condition, [], true);
+        return $this->parseWhereExp($logic, $field, 'NOT IN', $condition, [], true);
     }
 
     /**
@@ -1267,7 +1286,7 @@ class Query
      */
     public function whereLike($field, $condition, $logic = 'AND')
     {
-        return $this->parseWhereExp($logic, $field, 'like', $condition, [], true);
+        return $this->parseWhereExp($logic, $field, 'LIKE', $condition, [], true);
     }
 
     /**
@@ -1280,7 +1299,7 @@ class Query
      */
     public function whereNotLike($field, $condition, $logic = 'AND')
     {
-        return $this->parseWhereExp($logic, $field, 'not like', $condition, [], true);
+        return $this->parseWhereExp($logic, $field, 'NOT LIKE', $condition, [], true);
     }
 
     /**
@@ -1293,7 +1312,7 @@ class Query
      */
     public function whereBetween($field, $condition, $logic = 'AND')
     {
-        return $this->parseWhereExp($logic, $field, 'between', $condition, [], true);
+        return $this->parseWhereExp($logic, $field, 'BETWEEN', $condition, [], true);
     }
 
     /**
@@ -1306,7 +1325,7 @@ class Query
      */
     public function whereNotBetween($field, $condition, $logic = 'AND')
     {
-        return $this->parseWhereExp($logic, $field, 'not between', $condition, [], true);
+        return $this->parseWhereExp($logic, $field, 'NOT BETWEEN', $condition, [], true);
     }
 
     /**
@@ -1325,7 +1344,7 @@ class Query
             $operator = '=';
         }
 
-        return $this->whereExp($field1, $operator . ' ' . $field2, $logic);
+        return $this->whereExp($field1, $operator . ' ' . $field2, [], $logic);
     }
 
     /**
@@ -1348,14 +1367,50 @@ class Query
      * 指定Exp查询条件
      * @access public
      * @param  mixed  $field     查询字段
-     * @param  mixed  $condition 查询条件
+     * @param  string $condition 查询条件
      * @param  array  $bind      参数绑定
      * @param  string $logic     查询逻辑 and or xor
      * @return $this
      */
     public function whereExp($field, $condition, $bind = [], $logic = 'AND')
     {
-        return $this->parseWhereExp($logic, $field, 'exp', $condition, $bind, true);
+        $this->options['where'][$logic][] = [$field, 'EXP', $this->raw($condition)];
+
+        if ($bind) {
+            $this->bind($bind);
+        }
+        return $this;
+    }
+
+    /**
+     * 指定表达式查询条件
+     * @access public
+     * @param  string $where  查询条件
+     * @param  array  $bind   参数绑定
+     * @param  string $logic  查询逻辑 and or xor
+     * @return $this
+     */
+    public function whereRaw($where, array $bind = [], $logic = 'AND')
+    {
+        $this->options['where'][$logic][] = $this->raw($where);
+
+        if ($bind) {
+            $this->bind($bind);
+        }
+
+        return $this;
+    }
+
+    /**
+     * 指定表达式查询条件 OR
+     * @access public
+     * @param  string $where  查询条件
+     * @param  array  $bind   参数绑定
+     * @return $this
+     */
+    public function whereOrRaw($where, array $bind = [])
+    {
+        return $this->whereRaw($where, $bind, 'OR');
     }
 
     /**
@@ -1382,13 +1437,11 @@ class Query
             $field = $this->options['via'] . '.' . $field;
         }
 
-        if ($strict) {
+        if ($field instanceof Expression) {
+            return $this->whereRaw($field, is_array($op) ? $op : []);
+        } elseif ($strict) {
             // 使用严格模式查询
             $where = [$field, $op, $condition];
-            if ('exp' == strtolower($op) && !empty($param)) {
-                // 参数绑定
-                $this->bind($param);
-            }
         } elseif (is_array($field)) {
             // 解析数组批量查询
             return $this->parseArrayWhereItems($field, $logic);
@@ -1396,7 +1449,13 @@ class Query
             $where = $field;
             $field = '';
         } elseif (is_string($field)) {
-            // 解析条件单元
+            if (preg_match('/[,=\<\'\"\(\s]/', $field)) {
+                return $this->whereRaw($field, $op);
+            } elseif (is_string($op) && strtolower($op) == 'exp') {
+                $bind = isset($param[2]) && is_array($param[2]) ? $param[2] : null;
+                return $this->whereExp($field, $condition, $bind, $logic);
+            }
+
             $where = $this->parseWhereItem($logic, $field, $op, $condition, $param);
         }
 
@@ -1423,30 +1482,17 @@ class Query
      */
     protected function parseWhereItem($logic, $field, $op, $condition, $param = [])
     {
-        if (preg_match('/[,=\<\'\"\(\s]/', $field)) {
-            $where = ['', 'exp', $field];
-            if (is_array($op)) {
-                // 参数绑定
-                $this->bind($op);
-            }
-        } elseif (is_array($op)) {
+        if (is_array($op)) {
             // 同一字段多条件查询
             array_unshift($param, $field);
             $where = $param;
         } elseif ($field && is_null($condition)) {
-            if (in_array(strtolower($op), ['null', 'notnull', 'not null'])) {
+            if (in_array(strtoupper($op), ['NULL', 'NOTNULL', 'NOT NULL'], true)) {
                 // null查询
                 $where = [$field, $op, ''];
             } else {
                 // 字段相等查询
-                $where = is_null($op) ? [$field, 'null', ''] : [$field, '=', $op];
-            }
-        } elseif (strtolower($op) == 'exp') {
-            $bind  = isset($param[2]) && is_array($param[2]) ? $param[2] : null;
-            $where = [$field, 'exp', $condition, $bind];
-            if ($bind) {
-                // 参数绑定
-                $this->bind($bind);
+                $where = is_null($op) ? [$field, 'NULL', ''] : [$field, '=', $op];
             }
         } else {
             $where = $field ? [$field, $op, $condition] : null;
@@ -1468,7 +1514,7 @@ class Query
             $where = [];
             foreach ($field as $key => $val) {
                 if (is_null($val)) {
-                    $where[$key] = [$key, 'null', ''];
+                    $where[$key] = [$key, 'NULL', ''];
                 } else {
                     $where[$key] = !is_scalar($val) ? $val : [$key, '=', $val];
                 }
@@ -1721,6 +1767,9 @@ class Query
     {
         if (empty($field)) {
             return $this;
+        } elseif ($field instanceof Expression) {
+            $this->options['order'][] = $field;
+            return $this;
         }
 
         if (is_string($field)) {
@@ -1753,6 +1802,24 @@ class Query
         return $this;
     }
 
+    /**
+     * 表达式方式指定Field排序
+     * @access public
+     * @param  string $field 排序字段
+     * @param  array  $bind  参数绑定
+     * @return $this
+     */
+    public function orderRaw($field, array $bind = [])
+    {
+        $this->options['order'][] = $this->raw($field);
+
+        if ($bind) {
+            $this->bind($bind);
+        }
+
+        return $this;
+    }
+
     /**
      * 指定Field排序 order('id',[1,2,3],'desc')
      * @access public
diff --git a/thinkphp/library/think/db/builder/Mysql.php b/thinkphp/library/think/db/builder/Mysql.php
index d13ac0168..f5cd5f400 100644
--- a/thinkphp/library/think/db/builder/Mysql.php
+++ b/thinkphp/library/think/db/builder/Mysql.php
@@ -176,17 +176,15 @@ class Mysql extends Builder
     /**
      * 数组数据解析
      * @access protected
-     * @param  array  $data
+     * @param  Query     $query     查询对象
+     * @param  array     $data
      * @return mixed
      */
-    protected function parseArrayData($data)
+    protected function parseArrayData(Query $query, $data)
     {
         list($type, $value) = $data;
 
         switch (strtolower($type)) {
-            case 'exp':
-                $result = $value;
-                break;
             case 'point':
                 $fun   = isset($data[2]) ? $data[2] : 'GeomFromText';
                 $point = isset($data[3]) ? $data[3] : 'POINT';
diff --git a/thinkphp/library/think/model/relation/BelongsToMany.php b/thinkphp/library/think/model/relation/BelongsToMany.php
index 203c198b5..674249264 100644
--- a/thinkphp/library/think/model/relation/BelongsToMany.php
+++ b/thinkphp/library/think/model/relation/BelongsToMany.php
@@ -364,7 +364,7 @@ class BelongsToMany extends Relation
     {
         return $this->belongsToManyQuery($this->foreignKey, $this->localKey, [
             [
-                'pivot.' . $this->localKey, 'exp', '=' . $this->parent->getTable() . '.' . $this->parent->getPk(),
+                'pivot.' . $this->localKey, 'exp', $this->query->raw('=' . $this->parent->getTable() . '.' . $this->parent->getPk()),
             ],
         ])->fetchSql()->$aggregate($field);
     }
diff --git a/thinkphp/library/think/model/relation/HasMany.php b/thinkphp/library/think/model/relation/HasMany.php
index 3a8822981..aecc25452 100644
--- a/thinkphp/library/think/model/relation/HasMany.php
+++ b/thinkphp/library/think/model/relation/HasMany.php
@@ -181,7 +181,7 @@ class HasMany extends Relation
         }
 
         return $this->query
-            ->where($this->foreignKey, 'exp', '=' . $this->parent->getTable() . '.' . $this->parent->getPk())
+            ->whereExp($this->foreignKey, '=' . $this->parent->getTable() . '.' . $this->parent->getPk())
             ->fetchSql()
             ->$aggregate($field);
     }
diff --git a/thinkphp/library/think/model/relation/MorphMany.php b/thinkphp/library/think/model/relation/MorphMany.php
index 2b489113d..a50ed8dc8 100644
--- a/thinkphp/library/think/model/relation/MorphMany.php
+++ b/thinkphp/library/think/model/relation/MorphMany.php
@@ -224,10 +224,8 @@ class MorphMany extends Relation
         }
 
         return $this->query
-            ->where([
-                [$this->morphKey, 'exp', '=' . $this->parent->getTable() . '.' . $this->parent->getPk()],
-                [$this->morphType, '=', $this->type],
-            ])
+            ->whereExp($this->morphKey, '=' . $this->parent->getTable() . '.' . $this->parent->getPk())
+            ->where($this->morphType, '=', $this->type)
             ->fetchSql()
             ->$aggregate($field);
     }
diff --git a/thinkphp/library/think/route/Resource.php b/thinkphp/library/think/route/Resource.php
index 6873132ee..d280cb0b1 100644
--- a/thinkphp/library/think/route/Resource.php
+++ b/thinkphp/library/think/route/Resource.php
@@ -56,23 +56,6 @@ class Resource extends RuleGroup
         }
     }
 
-    /**
-     * 解析资源路由规则
-     * @access public
-     * @param  mixed        $rule    路由规则
-     * @return void
-     */
-    public function parseGroupRule($rule)
-    {
-        $origin = $this->router->getGroup();
-        $this->router->setGroup($this);
-
-        // 生成资源路由的路由规则
-        $this->buildResourceRule($this->resource, $this->option);
-
-        $this->router->setGroup($origin);
-    }
-
     /**
      * 生成资源路由规则
      * @access protected
@@ -82,6 +65,9 @@ class Resource extends RuleGroup
      */
     protected function buildResourceRule($rule, $option = [])
     {
+        $origin = $this->router->getGroup();
+        $this->router->setGroup($this);
+
         if (strpos($rule, '.')) {
             // 注册嵌套资源路由
             $array = explode('.', $rule);
@@ -112,6 +98,8 @@ class Resource extends RuleGroup
 
             $this->addRule(trim($val[1], '/'), $this->route . '/' . $val[2], $val[0], $option);
         }
+
+        $this->router->setGroup($origin);
     }
 
     /**
diff --git a/thinkphp/library/think/route/RuleGroup.php b/thinkphp/library/think/route/RuleGroup.php
index 333c49977..4f2f7d147 100644
--- a/thinkphp/library/think/route/RuleGroup.php
+++ b/thinkphp/library/think/route/RuleGroup.php
@@ -128,7 +128,9 @@ class RuleGroup extends Rule
         }
 
         // 解析分组路由
-        if ($this->rule) {
+        if ($this instanceof Resource) {
+            $this->buildResourceRule($this->resource, $this->option);
+        } elseif ($this->rule) {
             if ($this->rule instanceof Response) {
                 return new ResponseDispatch($this->rule);
             }
@@ -194,7 +196,7 @@ class RuleGroup extends Rule
      */
     protected function getMethodRules($method)
     {
-        return array_merge($this->rules['*'], $this->rules[$method]);
+        return array_merge($this->rules[$method], $this->rules['*']);
     }
 
     /**
diff --git a/thinkphp/library/think/route/dispatch/View.php b/thinkphp/library/think/route/dispatch/View.php
index 85ef9d283..852c8b9a1 100644
--- a/thinkphp/library/think/route/dispatch/View.php
+++ b/thinkphp/library/think/route/dispatch/View.php
@@ -11,7 +11,7 @@
 
 namespace think\route\dispatch;
 
-use think\Container;
+use think\Response;
 use think\route\Dispatch;
 
 class View extends Dispatch
@@ -21,8 +21,6 @@ class View extends Dispatch
         // 渲染模板输出
         $vars = array_merge($this->app['request']->param(), $this->param);
 
-        return Container::get('view')
-            ->init(Container::get('config')->pull('template'))
-            ->fetch($this->dispatch, $vars);
+        return Response::create($this->dispatch, 'view')->assign($vars);
     }
 }
diff --git a/vendor/autoload.php b/vendor/autoload.php
index 6d221f7ea..0bc28dcdb 100644
--- a/vendor/autoload.php
+++ b/vendor/autoload.php
@@ -4,4 +4,4 @@
 
 require_once __DIR__ . '/composer/autoload_real.php';
 
-return ComposerAutoloaderInit16a1d698c2cb58308d7cf1296b2e92f9::getLoader();
+return ComposerAutoloaderInitef233a8780a2db8cb038f052f6e06773::getLoader();
diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php
index 3013d3746..15e54e6d0 100644
--- a/vendor/composer/autoload_real.php
+++ b/vendor/composer/autoload_real.php
@@ -2,7 +2,7 @@
 
 // autoload_real.php @generated by Composer
 
-class ComposerAutoloaderInit16a1d698c2cb58308d7cf1296b2e92f9
+class ComposerAutoloaderInitef233a8780a2db8cb038f052f6e06773
 {
     private static $loader;
 
@@ -19,15 +19,15 @@ class ComposerAutoloaderInit16a1d698c2cb58308d7cf1296b2e92f9
             return self::$loader;
         }
 
-        spl_autoload_register(array('ComposerAutoloaderInit16a1d698c2cb58308d7cf1296b2e92f9', 'loadClassLoader'), true, true);
+        spl_autoload_register(array('ComposerAutoloaderInitef233a8780a2db8cb038f052f6e06773', 'loadClassLoader'), true, true);
         self::$loader = $loader = new \Composer\Autoload\ClassLoader();
-        spl_autoload_unregister(array('ComposerAutoloaderInit16a1d698c2cb58308d7cf1296b2e92f9', 'loadClassLoader'));
+        spl_autoload_unregister(array('ComposerAutoloaderInitef233a8780a2db8cb038f052f6e06773', 'loadClassLoader'));
 
         $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
         if ($useStaticLoader) {
             require_once __DIR__ . '/autoload_static.php';
 
-            call_user_func(\Composer\Autoload\ComposerStaticInit16a1d698c2cb58308d7cf1296b2e92f9::getInitializer($loader));
+            call_user_func(\Composer\Autoload\ComposerStaticInitef233a8780a2db8cb038f052f6e06773::getInitializer($loader));
         } else {
             $map = require __DIR__ . '/autoload_namespaces.php';
             foreach ($map as $namespace => $path) {
@@ -48,19 +48,19 @@ class ComposerAutoloaderInit16a1d698c2cb58308d7cf1296b2e92f9
         $loader->register(true);
 
         if ($useStaticLoader) {
-            $includeFiles = Composer\Autoload\ComposerStaticInit16a1d698c2cb58308d7cf1296b2e92f9::$files;
+            $includeFiles = Composer\Autoload\ComposerStaticInitef233a8780a2db8cb038f052f6e06773::$files;
         } else {
             $includeFiles = require __DIR__ . '/autoload_files.php';
         }
         foreach ($includeFiles as $fileIdentifier => $file) {
-            composerRequire16a1d698c2cb58308d7cf1296b2e92f9($fileIdentifier, $file);
+            composerRequireef233a8780a2db8cb038f052f6e06773($fileIdentifier, $file);
         }
 
         return $loader;
     }
 }
 
-function composerRequire16a1d698c2cb58308d7cf1296b2e92f9($fileIdentifier, $file)
+function composerRequireef233a8780a2db8cb038f052f6e06773($fileIdentifier, $file)
 {
     if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
         require $file;
diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php
index 2a2ed938e..ddc9469cf 100644
--- a/vendor/composer/autoload_static.php
+++ b/vendor/composer/autoload_static.php
@@ -4,7 +4,7 @@
 
 namespace Composer\Autoload;
 
-class ComposerStaticInit16a1d698c2cb58308d7cf1296b2e92f9
+class ComposerStaticInitef233a8780a2db8cb038f052f6e06773
 {
     public static $files = array (
         '1cfd2761b63b0a29ed23657ea394cb2d' => __DIR__ . '/..' . '/topthink/think-captcha/src/helper.php',
@@ -257,9 +257,9 @@ class ComposerStaticInit16a1d698c2cb58308d7cf1296b2e92f9
     public static function getInitializer(ClassLoader $loader)
     {
         return \Closure::bind(function () use ($loader) {
-            $loader->prefixLengthsPsr4 = ComposerStaticInit16a1d698c2cb58308d7cf1296b2e92f9::$prefixLengthsPsr4;
-            $loader->prefixDirsPsr4 = ComposerStaticInit16a1d698c2cb58308d7cf1296b2e92f9::$prefixDirsPsr4;
-            $loader->classMap = ComposerStaticInit16a1d698c2cb58308d7cf1296b2e92f9::$classMap;
+            $loader->prefixLengthsPsr4 = ComposerStaticInitef233a8780a2db8cb038f052f6e06773::$prefixLengthsPsr4;
+            $loader->prefixDirsPsr4 = ComposerStaticInitef233a8780a2db8cb038f052f6e06773::$prefixDirsPsr4;
+            $loader->classMap = ComposerStaticInitef233a8780a2db8cb038f052f6e06773::$classMap;
 
         }, null, ClassLoader::class);
     }
diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json
index 3634df492..8bddbe978 100644
--- a/vendor/composer/installed.json
+++ b/vendor/composer/installed.json
@@ -175,17 +175,17 @@
     },
     {
         "name": "topthink/framework",
-        "version": "v5.1.6",
-        "version_normalized": "5.1.6.0",
+        "version": "v5.1.7",
+        "version_normalized": "5.1.7.0",
         "source": {
             "type": "git",
             "url": "https://github.com/top-think/framework.git",
-            "reference": "f737a05ec7c21eb77a624478d97a172dade8fa67"
+            "reference": "cc946e535f1a0336a83ca75d65c696d39567f861"
         },
         "dist": {
             "type": "zip",
-            "url": "https://files.phpcomposer.com/files/top-think/framework/f737a05ec7c21eb77a624478d97a172dade8fa67.zip",
-            "reference": "f737a05ec7c21eb77a624478d97a172dade8fa67",
+            "url": "https://files.phpcomposer.com/files/top-think/framework/cc946e535f1a0336a83ca75d65c696d39567f861.zip",
+            "reference": "cc946e535f1a0336a83ca75d65c696d39567f861",
             "shasum": ""
         },
         "require": {
@@ -201,7 +201,7 @@
             "sebastian/phpcpd": "2.*",
             "squizlabs/php_codesniffer": "2.*"
         },
-        "time": "2018-03-26T10:43:20+00:00",
+        "time": "2018-03-28T10:06:49+00:00",
         "type": "think-framework",
         "installation-source": "dist",
         "notification-url": "https://packagist.org/downloads/",