瀏覽代碼

同步Library组件,支持 Model 快捷操作

邹景立 3 年之前
父節點
當前提交
bec782fd37

+ 14 - 10
vendor/composer/installed.json

@@ -594,17 +594,17 @@
         },
         {
             "name": "topthink/think-helper",
-            "version": "v3.1.4",
-            "version_normalized": "3.1.4.0",
+            "version": "v3.1.5",
+            "version_normalized": "3.1.5.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/top-think/think-helper.git",
-                "reference": "c28d37743bda4a0455286ca85b17b5791d626e10"
+                "reference": "f98e3ad44acd27ae85a4d923b1bdfd16c6d8d905"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/top-think/think-helper/zipball/c28d37743bda4a0455286ca85b17b5791d626e10",
-                "reference": "c28d37743bda4a0455286ca85b17b5791d626e10",
+                "url": "https://api.github.com/repos/top-think/think-helper/zipball/f98e3ad44acd27ae85a4d923b1bdfd16c6d8d905",
+                "reference": "f98e3ad44acd27ae85a4d923b1bdfd16c6d8d905",
                 "shasum": "",
                 "mirrors": [
                     {
@@ -616,7 +616,7 @@
             "require": {
                 "php": ">=7.1.0"
             },
-            "time": "2019-11-08T08:01:10+00:00",
+            "time": "2021-06-21T06:17:31+00:00",
             "type": "library",
             "installation-source": "dist",
             "autoload": {
@@ -638,6 +638,10 @@
                 }
             ],
             "description": "The ThinkPHP6 Helper Package",
+            "support": {
+                "issues": "https://github.com/top-think/think-helper/issues",
+                "source": "https://github.com/top-think/think-helper/tree/v3.1.5"
+            },
             "install-path": "../topthink/think-helper"
         },
         {
@@ -849,12 +853,12 @@
             "source": {
                 "type": "git",
                 "url": "https://github.com/zoujingli/ThinkLibrary.git",
-                "reference": "283b25735511092a6c1c48e4d55b919cf1e09e30"
+                "reference": "611043ad1974ab0926868bb44b1b2491fee13114"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/283b25735511092a6c1c48e4d55b919cf1e09e30",
-                "reference": "283b25735511092a6c1c48e4d55b919cf1e09e30",
+                "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/611043ad1974ab0926868bb44b1b2491fee13114",
+                "reference": "611043ad1974ab0926868bb44b1b2491fee13114",
                 "shasum": "",
                 "mirrors": [
                     {
@@ -871,7 +875,7 @@
                 "ext-mbstring": "*",
                 "topthink/framework": "^6.0"
             },
-            "time": "2021-06-18T08:57:57+00:00",
+            "time": "2021-06-22T07:23:58+00:00",
             "default-branch": true,
             "type": "library",
             "extra": {

+ 6 - 6
vendor/composer/installed.php

@@ -5,7 +5,7 @@
         'type' => 'project',
         'install_path' => __DIR__ . '/../../',
         'aliases' => array(),
-        'reference' => '43a8afea8902a5269d27519ebb31caa0705e2c82',
+        'reference' => '9b4e299239c063b71f431d974c0754fadb9a6624',
         'name' => 'zoujingli/thinkadmin',
         'dev' => false,
     ),
@@ -92,12 +92,12 @@
             'dev_requirement' => false,
         ),
         'topthink/think-helper' => array(
-            'pretty_version' => 'v3.1.4',
-            'version' => '3.1.4.0',
+            'pretty_version' => 'v3.1.5',
+            'version' => '3.1.5.0',
             'type' => 'library',
             'install_path' => __DIR__ . '/../topthink/think-helper',
             'aliases' => array(),
-            'reference' => 'c28d37743bda4a0455286ca85b17b5791d626e10',
+            'reference' => 'f98e3ad44acd27ae85a4d923b1bdfd16c6d8d905',
             'dev_requirement' => false,
         ),
         'topthink/think-orm' => array(
@@ -144,7 +144,7 @@
             'aliases' => array(
                 0 => '9999999-dev',
             ),
-            'reference' => '283b25735511092a6c1c48e4d55b919cf1e09e30',
+            'reference' => '611043ad1974ab0926868bb44b1b2491fee13114',
             'dev_requirement' => false,
         ),
         'zoujingli/thinkadmin' => array(
@@ -153,7 +153,7 @@
             'type' => 'project',
             'install_path' => __DIR__ . '/../../',
             'aliases' => array(),
-            'reference' => '43a8afea8902a5269d27519ebb31caa0705e2c82',
+            'reference' => '9b4e299239c063b71f431d974c0754fadb9a6624',
             'dev_requirement' => false,
         ),
         'zoujingli/wechat-developer' => array(

+ 1 - 1
vendor/services.php

@@ -1,5 +1,5 @@
 <?php 
-// This file is automatically generated at:2021-06-18 16:59:49
+// This file is automatically generated at:2021-06-22 15:29:50
 declare (strict_types = 1);
 return array (
   0 => 'think\\admin\\Library',

+ 12 - 8
vendor/topthink/think-helper/src/Collection.php

@@ -242,15 +242,17 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
      * @access public
      * @param mixed  $value 元素
      * @param string $key   KEY
-     * @return void
+     * @return $this
      */
-    public function push($value, string $key = null): void
+    public function push($value, string $key = null)
     {
         if (is_null($key)) {
             $this->items[] = $value;
         } else {
             $this->items[$key] = $value;
         }
+
+        return $this;
     }
 
     /**
@@ -277,15 +279,17 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
      * @access public
      * @param mixed  $value 元素
      * @param string $key   KEY
-     * @return void
+     * @return $this
      */
-    public function unshift($value, string $key = null): void
+    public function unshift($value, string $key = null)
     {
         if (is_null($key)) {
             array_unshift($this->items, $value);
         } else {
             $this->items = [$key => $value] + $this->items;
         }
+
+        return $this;
     }
 
     /**
@@ -477,7 +481,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
      * @param string|null $indexKey  作为索引值的列
      * @return array
      */
-    public function column(?string $columnKey, string $indexKey = null)
+    public function column( ? string $columnKey, string $indexKey = null)
     {
         return array_column($this->items, $columnKey, $indexKey);
     }
@@ -515,7 +519,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
             $fieldA = $a[$field] ?? null;
             $fieldB = $b[$field] ?? null;
 
-            return 'desc' == strtolower($order) ? $fieldB > $fieldA : $fieldA > $fieldB;
+            return 'desc' == strtolower($order) ? intval($fieldB > $fieldA) : intval($fieldA > $fieldB);
         });
     }
 
@@ -535,7 +539,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
     }
 
     /**
-     * 获取第一个单元数据
+     * 获取第一个单元数据
      *
      * @access public
      * @param callable|null $callback
@@ -623,7 +627,7 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria
      * @param integer $options json参数
      * @return string
      */
-    public function toJson(int $options = JSON_UNESCAPED_UNICODE): string
+    public function toJson(int $options = JSON_UNESCAPED_UNICODE) : string
     {
         return json_encode($this->toArray(), $options);
     }

+ 2 - 3
vendor/zoujingli/think-library/.gitignore

@@ -1,8 +1,7 @@
 .git
 .svn
 .idea
-!.gitignore
-!composer.json
 /composer.lock
 /vendor
-/test.php
+!.gitignore
+!composer.json

+ 6 - 5
vendor/zoujingli/think-library/src/Controller.php

@@ -32,6 +32,7 @@ use think\db\exception\DbException;
 use think\db\exception\ModelNotFoundException;
 use think\db\Query;
 use think\exception\HttpResponseException;
+use think\Model;
 use think\Request;
 
 /**
@@ -183,7 +184,7 @@ abstract class Controller extends stdClass
 
     /**
      * 快捷查询逻辑器
-     * @param string|Query $dbQuery
+     * @param Model|Query|string $dbQuery
      * @param array|string|null $input
      * @return QueryHelper
      */
@@ -194,7 +195,7 @@ abstract class Controller extends stdClass
 
     /**
      * 快捷分页逻辑器
-     * @param string|Query $dbQuery
+     * @param Model|Query|string $dbQuery
      * @param boolean $page 是否启用分页
      * @param boolean $display 是否渲染模板
      * @param boolean|integer $total 集合分页记录数
@@ -212,7 +213,7 @@ abstract class Controller extends stdClass
 
     /**
      * 快捷表单逻辑器
-     * @param string|Query $dbQuery
+     * @param Model|Query|string $dbQuery
      * @param string $template 模板名称
      * @param string $field 指定数据对象主键
      * @param array $where 额外更新条件
@@ -240,7 +241,7 @@ abstract class Controller extends stdClass
 
     /**
      * 快捷更新逻辑器
-     * @param string|Query $dbQuery
+     * @param Model|Query|string $dbQuery
      * @param array $data 表单扩展数据
      * @param string $field 数据对象主键
      * @param array $where 额外更新条件
@@ -254,7 +255,7 @@ abstract class Controller extends stdClass
 
     /**
      * 快捷删除逻辑器
-     * @param string|Query $dbQuery
+     * @param Model|Query|string $dbQuery
      * @param string $field 数据对象主键
      * @param array $where 额外更新条件
      * @return boolean|null

+ 8 - 8
vendor/zoujingli/think-library/src/Exception.php

@@ -43,21 +43,21 @@ class Exception extends \Exception
     }
 
     /**
-     * 设置异常停止数据
-     * @param mixed $data
+     * 获取异常停止数据
+     * @return mixed
      */
-    public function setData($data)
+    public function getData()
     {
-        $this->data = $data;
+        return $this->data;
     }
 
     /**
-     * 获取异常停止数据
-     * @return mixed
+     * 设置异常停止数据
+     * @param mixed $data
      */
-    public function getData()
+    public function setData($data)
     {
-        return $this->data;
+        $this->data = $data;
     }
 
 }

+ 20 - 6
vendor/zoujingli/think-library/src/Helper.php

@@ -19,8 +19,9 @@ namespace think\admin;
 
 use think\App;
 use think\Container;
-use think\Db;
+use think\db\BaseQuery;
 use think\db\Query;
+use think\Model;
 
 /**
  * 控制器挂件
@@ -36,8 +37,14 @@ abstract class Helper
     public $app;
 
     /**
-     * 数据库实例
-     * @var Db|Query
+     * 数据模型实例
+     * @var Model
+     */
+    public $model;
+
+    /**
+     * 数据查询实例
+     * @var Query
      */
     public $query;
 
@@ -60,12 +67,19 @@ abstract class Helper
 
     /**
      * 获取数据库对象
-     * @param string|Db|Query $dbQuery
-     * @return Db|Query
+     * @param Model|Query|string $dbQuery
+     * @return Query|mixed
      */
     protected function buildQuery($dbQuery)
     {
-        return is_string($dbQuery) ? $this->app->db->name($dbQuery) : $dbQuery;
+        if (is_string($dbQuery)) {
+            $this->query = $this->app->db->name($dbQuery);
+        } elseif ($dbQuery instanceof \think\Model) {
+            $this->query = $dbQuery->db();
+        } elseif ($dbQuery instanceof BaseQuery) {
+            $this->query = $dbQuery;
+        }
+        return $this->query;
     }
 
     /**

+ 1 - 3
vendor/zoujingli/think-library/src/Service.php

@@ -45,18 +45,16 @@ abstract class Service
 
     /**
      * 初始化服务
-     * @return static
      */
     protected function initialize()
     {
-        return $this;
     }
 
     /**
      * 静态实例对象
      * @param array $var 实例参数
      * @param boolean $new 创建新实例
-     * @return static
+     * @return static|mixed
      */
     public static function instance(array $var = [], bool $new = false)
     {

+ 2 - 1
vendor/zoujingli/think-library/src/common.php

@@ -23,6 +23,7 @@ use think\db\exception\DataNotFoundException;
 use think\db\exception\DbException;
 use think\db\exception\ModelNotFoundException;
 use think\db\Query;
+use think\Model;
 
 if (!function_exists('p')) {
     /**
@@ -264,7 +265,7 @@ if (!function_exists('http_post')) {
 if (!function_exists('data_save')) {
     /**
      * 数据增量保存
-     * @param Query|string $dbQuery
+     * @param Model|Query|string $dbQuery
      * @param array $data 需要保存或更新的数据
      * @param string $key 条件主键限制
      * @param array $where 其它的where条件

+ 1 - 1
vendor/zoujingli/think-library/src/extend/JsonRpcServer.php

@@ -73,7 +73,7 @@ class JsonRpcServer
                 $response = ['jsonrpc' => '2.0', 'id' => '0', 'result' => null, 'error' => $error];
             } elseif (!isset($request['id']) || !isset($request['method']) || !isset($request['params'])) {
                 $error = ['code' => '-32600', 'message' => '无效的请求', 'meaning' => '发送的JSON不是一个有效的请求对象'];
-                $response = ['jsonrpc' => '2.0', 'id' => $request['id'], 'result' => null, 'error' => $error];
+                $response = ['jsonrpc' => '2.0', 'id' => $request['id'] ?? '0', 'result' => null, 'error' => $error];
             } else try {
                 // Executes the task on local object
                 if (method_exists($object, $request['method'])) {

+ 3 - 3
vendor/zoujingli/think-library/src/helper/DeleteHelper.php

@@ -18,9 +18,9 @@ declare (strict_types=1);
 namespace think\admin\helper;
 
 use think\admin\Helper;
-use think\Db;
 use think\db\exception\DbException;
 use think\db\Query;
+use think\Model;
 
 /**
  * 通用删除管理器
@@ -31,7 +31,7 @@ class DeleteHelper extends Helper
 {
     /**
      * 逻辑器初始化
-     * @param string|Db|Query $dbQuery
+     * @param Model|Query|string $dbQuery
      * @param string $field 操作数据主键
      * @param array $where 额外更新条件
      * @return boolean|null
@@ -45,7 +45,7 @@ class DeleteHelper extends Helper
         // 查询限制处理
         if (!empty($where)) $query->where($where);
         if (!isset($where[$field]) && is_string($value)) {
-            $query->whereIn($field, explode(',', $value));
+            $query->whereIn($field, str2arr($value));
         }
         // 前置回调处理
         if (false === $this->class->callback('_delete_filter', $query, $where)) {

+ 3 - 3
vendor/zoujingli/think-library/src/helper/FormHelper.php

@@ -18,11 +18,11 @@ declare (strict_types=1);
 namespace think\admin\helper;
 
 use think\admin\Helper;
-use think\Db;
 use think\db\exception\DataNotFoundException;
 use think\db\exception\DbException;
 use think\db\exception\ModelNotFoundException;
 use think\db\Query;
+use think\Model;
 
 /**
  * 表单视图管理器
@@ -34,7 +34,7 @@ class FormHelper extends Helper
 
     /**
      * 逻辑器初始化
-     * @param string|Db|Query $dbQuery
+     * @param Model|Query|string $dbQuery
      * @param string $template 模板名称
      * @param string $field 指定数据主键
      * @param array $where 额外更新条件
@@ -48,7 +48,7 @@ class FormHelper extends Helper
     {
         $query = $this->buildQuery($dbQuery);
         $field = $field ?: ($query->getPk() ?: 'id');
-        $value = input($field, $data[$field] ?? null);
+        $value = $data[$field] ?? input($field);
         if ($this->app->request->isGet()) {
             if ($value !== null) {
                 $find = $query->where([$field => $value])->where($where)->find();

+ 14 - 40
vendor/zoujingli/think-library/src/helper/PageHelper.php

@@ -22,6 +22,7 @@ use think\db\exception\DataNotFoundException;
 use think\db\exception\DbException;
 use think\db\exception\ModelNotFoundException;
 use think\db\Query;
+use think\Model;
 
 /**
  * 列表处理管理器
@@ -33,7 +34,7 @@ class PageHelper extends Helper
 
     /**
      * 逻辑器初始化
-     * @param string|Query $dbQuery
+     * @param Model|Query|string $dbQuery
      * @param boolean $page 是否启用分页
      * @param boolean $display 是否渲染模板
      * @param boolean|integer $total 集合分页记录数
@@ -48,9 +49,18 @@ class PageHelper extends Helper
     {
         $this->query = $this->buildQuery($dbQuery);
         // 数据列表排序自动处理
-        if ($this->app->request->isPost()) $this->_sortAction();
-        // 列表设置默认排序处理
-        if (!$this->query->getOptions('order')) $this->_orderAction();
+        if ($this->app->request->isPost() && $this->app->request->post('action') === 'sort') {
+            if (in_array('sort', $this->query->getTableFields())) {
+                if ($this->app->request->has($pk = $this->query->getPk() ?: 'id', 'post')) {
+                    $map = [$pk => $this->app->request->post($pk, 0)];
+                    $data = ['sort' => intval($this->app->request->post('sort', 0))];
+                    if ($this->app->db->table($this->query->getTable())->where($map)->update($data) !== false) {
+                        $this->class->success(lang('think_library_sort_success'), '');
+                    }
+                }
+            }
+            $this->class->error(lang('think_library_sort_error'));
+        }
         // 列表分页及结果集处理
         if ($page) {
             if (empty($limit)) {
@@ -92,40 +102,4 @@ class PageHelper extends Helper
         }
         return $result;
     }
-
-    /**
-     * 执行列表排序操作
-     * POST 提交 {action:sort,PK:$PK,SORT:$SORT}
-     * @throws DbException
-     */
-    private function _sortAction()
-    {
-        if ($this->app->request->post('action') === 'sort') {
-            if (method_exists($this->query, 'getTableFields') && in_array('sort', $this->query->getTableFields())) {
-                $pk = $this->query->getPk() ?: 'id';
-                if ($this->app->request->has($pk, 'post')) {
-                    $map = [$pk => $this->app->request->post($pk, 0)];
-                    $data = ['sort' => intval($this->app->request->post('sort', 0))];
-                    if ($this->app->db->table($this->query->getTable())->where($map)->update($data) !== false) {
-                        $this->class->success(lang('think_library_sort_success'), '');
-                    }
-                }
-            }
-            $this->class->error(lang('think_library_sort_error'));
-        }
-    }
-
-    /**
-     * 列表默认排序处理
-     * 未配置排序规则时自动按SORT排序
-     */
-    private function _orderAction()
-    {
-        if (method_exists($this->query, 'getTableFields')) {
-            if (in_array('sort', $this->query->getTableFields())) {
-                $this->query->order('sort desc');
-            }
-        }
-    }
-
 }

+ 4 - 4
vendor/zoujingli/think-library/src/helper/QueryHelper.php

@@ -18,11 +18,11 @@ declare (strict_types=1);
 namespace think\admin\helper;
 
 use think\admin\Helper;
-use think\Db;
 use think\db\exception\DataNotFoundException;
 use think\db\exception\DbException;
 use think\db\exception\ModelNotFoundException;
 use think\db\Query;
+use think\Model;
 
 /**
  * 搜索条件处理器
@@ -41,16 +41,16 @@ class QueryHelper extends Helper
 
     /**
      * 获取当前Db操作对象
-     * @return Db|Query
+     * @return Query
      */
-    public function db()
+    public function db(): Query
     {
         return $this->query;
     }
 
     /**
      * 逻辑器初始化
-     * @param string|Query|Db $dbQuery
+     * @param Model|Query|string $dbQuery
      * @param array|string|null $input 输入数据
      * @return $this
      */

+ 2 - 1
vendor/zoujingli/think-library/src/helper/SaveHelper.php

@@ -20,6 +20,7 @@ namespace think\admin\helper;
 use think\admin\Helper;
 use think\db\exception\DbException;
 use think\db\Query;
+use think\Model;
 
 /**
  * 数据更新管理器
@@ -31,7 +32,7 @@ class SaveHelper extends Helper
 
     /**
      * 逻辑器初始化
-     * @param Query|string $dbQuery
+     * @param Model|Query|string $dbQuery
      * @param array $data 表单扩展数据
      * @param string $field 数据对象主键
      * @param array $where 额外更新条件

+ 1 - 1
vendor/zoujingli/think-library/src/service/MenuService.php

@@ -58,7 +58,7 @@ class MenuService extends Service
     public function getTree(): array
     {
         $query = $this->app->db->name('SystemMenu');
-        $query->where(['status' => '1'])->order('sort desc,id asc');
+        $query->where(['status' => 1])->order('sort desc,id asc');
         return $this->_buildData(DataExtend::arr2tree($query->select()->toArray()));
     }
 

+ 4 - 1
vendor/zoujingli/think-library/src/service/SystemService.php

@@ -25,6 +25,7 @@ use think\db\exception\DbException;
 use think\db\exception\ModelNotFoundException;
 use think\db\Query;
 use think\helper\Str;
+use think\Model;
 
 /**
  * 系统参数管理服务
@@ -106,7 +107,7 @@ class SystemService extends Service
 
     /**
      * 数据增量保存
-     * @param Query|string $query 数据查询对象
+     * @param Model|Query|string $query 数据查询对象
      * @param array $data 需要保存的数据
      * @param string $key 更新条件查询主键
      * @param array $map 额外更新查询条件
@@ -117,6 +118,7 @@ class SystemService extends Service
      */
     public function save($query, array $data, string $key = 'id', array $map = [])
     {
+        if ($query instanceof Model) $query = $query->db();
         if (is_string($query)) $query = $this->app->db->name($query);
         [$query, $value] = [$query->master()->strict(false)->where($map), $data[$key] ?? null];
         if (empty($map[$key])) if (is_string($value) && strpos($value, ',') !== false) {
@@ -125,6 +127,7 @@ class SystemService extends Service
             $query->where([$key => $value]);
         }
         if (($info = (clone $query)->find()) && !empty($info)) {
+            if ($info instanceof Model) $info = $info->toArray();
             $query->update($data);
             return $info[$key] ?? true;
         } else {