From 73fde3ff2de93ec2f7b91e8625b313c4ec1e9488 Mon Sep 17 00:00:00 2001 From: Anyon Date: Wed, 25 Dec 2019 11:04:23 +0800 Subject: [PATCH] ComposerUpdate --- app/wechat/service/WechatService.php | 3 +- composer.lock | 8 +-- vendor/composer/installed.json | 8 +-- vendor/services.php | 2 +- .../think-library/src/helper/PageHelper.php | 68 +++++++++++++------ .../src/service/JsonRpcClientService.php | 12 ++-- 6 files changed, 64 insertions(+), 37 deletions(-) diff --git a/app/wechat/service/WechatService.php b/app/wechat/service/WechatService.php index a801c453d..792f28bd7 100644 --- a/app/wechat/service/WechatService.php +++ b/app/wechat/service/WechatService.php @@ -249,8 +249,9 @@ class WechatService extends Service } if ($redirect && !empty($result['url'])) { throw new HttpResponseException(redirect($result['url'], 301)); + } else { + throw new HttpResponseException(response("window.location.href='{$result['url']}'")); } - exit("window.location.href='{$result['url']}'"); } } diff --git a/composer.lock b/composer.lock index d1dce30f9..040a52c2e 100644 --- a/composer.lock +++ b/composer.lock @@ -909,12 +909,12 @@ "source": { "type": "git", "url": "https://github.com/zoujingli/ThinkLibrary.git", - "reference": "9952e50062d5d8f447680cea4a557155b7353158" + "reference": "d9b6c53ed98ef92d9d9560c38e7d9442350042f5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/9952e50062d5d8f447680cea4a557155b7353158", - "reference": "9952e50062d5d8f447680cea4a557155b7353158", + "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/d9b6c53ed98ef92d9d9560c38e7d9442350042f5", + "reference": "d9b6c53ed98ef92d9d9560c38e7d9442350042f5", "shasum": "", "mirrors": [ { @@ -958,7 +958,7 @@ ], "description": "ThinkPHP v6.0 Development Library", "homepage": "http://framework.thinkadmin.top", - "time": "2019-12-24T02:28:27+00:00" + "time": "2019-12-25T02:08:57+00:00" }, { "name": "zoujingli/wechat-developer", diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 3acdc3f34..4880165ad 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -935,12 +935,12 @@ "source": { "type": "git", "url": "https://github.com/zoujingli/ThinkLibrary.git", - "reference": "9952e50062d5d8f447680cea4a557155b7353158" + "reference": "d9b6c53ed98ef92d9d9560c38e7d9442350042f5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/9952e50062d5d8f447680cea4a557155b7353158", - "reference": "9952e50062d5d8f447680cea4a557155b7353158", + "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/d9b6c53ed98ef92d9d9560c38e7d9442350042f5", + "reference": "d9b6c53ed98ef92d9d9560c38e7d9442350042f5", "shasum": "", "mirrors": [ { @@ -956,7 +956,7 @@ "ext-json": "*", "topthink/framework": "^6.0" }, - "time": "2019-12-24T02:28:27+00:00", + "time": "2019-12-25T02:08:57+00:00", "type": "library", "extra": { "think": { diff --git a/vendor/services.php b/vendor/services.php index a427b9a0e..bad4a39d3 100644 --- a/vendor/services.php +++ b/vendor/services.php @@ -1,5 +1,5 @@ 'think\\app\\Service', diff --git a/vendor/zoujingli/think-library/src/helper/PageHelper.php b/vendor/zoujingli/think-library/src/helper/PageHelper.php index 8bd6acf95..42e38847c 100644 --- a/vendor/zoujingli/think-library/src/helper/PageHelper.php +++ b/vendor/zoujingli/think-library/src/helper/PageHelper.php @@ -62,39 +62,30 @@ class PageHelper extends Helper * @throws \think\db\exception\ModelNotFoundException */ public function init($dbQuery, $page = true, $display = true, $total = false, $limit = 0) - { $this->page = $page; $this->total = $total; $this->limit = $limit; $this->display = $display; $this->query = $this->buildQuery($dbQuery); - // 数据列表排序处理 + // 数据列表排序自动处理 if ($this->app->request->isPost()) { - $post = $this->app->request->post(); - $sort = intval(isset($post['sort']) ? $post['sort'] : 0); - unset($post['action'], $post['sort']); - if ($this->app->db->table($this->query->getTable())->where($post)->update(['sort' => $sort]) !== false) { - return $this->controller->success('列表排序修改成功!', ''); - } else { - return $this->controller->error('列表排序修改失败,请稍候再试!'); - } + $this->sortAction(); } - // 未配置 order 规则时自动按 sort 字段排序 - if (!$this->query->getOptions('order') && method_exists($this->query, 'getTableFields')) { - if (in_array('sort', $this->query->getTableFields())) $this->query->order('sort desc'); + // 列表设置默认排序处理 + if (!$this->query->getOptions('order')) { + $this->orderAction(); } // 列表分页及结果集处理 if ($this->page) { - // 分页每页显示记录数 if ($this->limit > 0) { $limit = intval($this->limit); } else { $limit = $this->app->request->get('limit', $this->app->cookie->get('limit')); $this->app->cookie->set('limit', $limit = intval($limit >= 10 ? $limit : 20)); } - list($select, $query) = ['', $this->app->request->get()]; - $paginate = $this->query->paginate(['list_rows' => $limit, 'query' => $query], $this->total); + list($options, $query) = ['', $this->app->request->get()]; + $pager = $this->query->paginate(['list_rows' => $limit, 'query' => $query], $this->total); foreach ([10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200] as $num) { list($query['limit'], $query['page'], $selected) = [$num, 1, $limit === $num ? 'selected' : '']; if (stripos($this->app->request->get('spm', '-'), 'm-') === 0) { @@ -102,15 +93,15 @@ class PageHelper extends Helper } else { $url = $this->app->request->baseUrl() . '?' . urldecode(http_build_query($query)); } - $select .= ""; + $options .= ""; } - $pagehtml = "
共 {$paginate->total()} 条记录,每页显示 条,共 {$paginate->lastPage()} 页当前显示第 {$paginate->currentPage()} 页。{$paginate->render()}
"; + $html = "
共 {$pager->total()} 条记录,每页显示 条,共 {$pager->lastPage()} 页当前显示第 {$pager->currentPage()} 页。{$pager->render()}
"; if (stripos($this->app->request->get('spm', '-'), 'm-') === 0) { - $this->controller->assign('pagehtml', preg_replace('|href="(.*?)"|', 'data-open="$1" onclick="return false" href="$1"', $pagehtml)); + $this->controller->assign('pagehtml', preg_replace('|href="(.*?)"|', 'data-open="$1" onclick="return false" href="$1"', $html)); } else { - $this->controller->assign('pagehtml', $pagehtml); + $this->controller->assign('pagehtml', $html); } - $result = ['page' => ['limit' => intval($limit), 'total' => intval($paginate->total()), 'pages' => intval($paginate->lastPage()), 'current' => intval($paginate->currentPage())], 'list' => $paginate->items()]; + $result = ['page' => ['limit' => intval($limit), 'total' => intval($pager->total()), 'pages' => intval($pager->lastPage()), 'current' => intval($pager->currentPage())], 'list' => $pager->items()]; } else { $result = ['list' => $this->query->select()->toArray()]; } @@ -121,4 +112,39 @@ class PageHelper extends Helper } } + /** + * 执行列表排序操作 + * POST 提交 {action:sort,PK:$PK,SORT:$SORT} + * @throws \think\db\exception\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(isset($map['sort']) ?? 0)]; + if ($this->app->db->table($this->query->getTable())->where($map)->update($data) !== false) { + $this->controller->success('列表排序修改成功!', ''); + } + } + } + $this->controller->error('列表排序修改失败,请稍候再试!'); + } + } + + /** + * 列表默认排序处理 + * 未配置排序规则时自动按SORT排序 + */ + private function orderAction() + { + if (method_exists($this->query, 'getTableFields')) { + if (in_array('sort', $this->query->getTableFields())) { + $this->query->order('sort desc'); + } + } + } + } diff --git a/vendor/zoujingli/think-library/src/service/JsonRpcClientService.php b/vendor/zoujingli/think-library/src/service/JsonRpcClientService.php index a661478f9..bd9c3679b 100644 --- a/vendor/zoujingli/think-library/src/service/JsonRpcClientService.php +++ b/vendor/zoujingli/think-library/src/service/JsonRpcClientService.php @@ -35,16 +35,16 @@ class JsonRpcClientService extends Service * 请求ID * @var integer */ - private $requestid; + private $id; /** * 创建连接对象 * @param string $proxy - * @return $this + * @return mixed */ public function create($proxy) { - $this->requestid = CodeExtend::uniqidNumber(); + $this->id = CodeExtend::uniqidNumber(); $this->proxy = $proxy; return $this; } @@ -64,7 +64,7 @@ class JsonRpcClientService extends Service 'method' => 'POST', 'header' => 'Content-type: application/json', 'content' => json_encode([ - 'jsonrpc' => '2.0', 'method' => $method, 'params' => $params, 'id' => $this->requestid, + 'jsonrpc' => '2.0', 'method' => $method, 'params' => $params, 'id' => $this->id, ], JSON_UNESCAPED_UNICODE), ], ]; @@ -77,8 +77,8 @@ class JsonRpcClientService extends Service throw new \think\Exception("无法连接到 {$this->proxy}"); } // Final checks and return - if ($response['id'] != $this->requestid) { - throw new \think\Exception("错误的响应标记 (请求标记: {$this->requestid}, 响应标记: {$response['id']})"); + if ($response['id'] != $this->id) { + throw new \think\Exception("错误的响应标记 (请求标记: {$this->id}, 响应标记: {$response['id']})"); } if (is_null($response['error'])) { return $response['result'];