commit
d6a27ceb7c
969 changed files with 235966 additions and 0 deletions
@ -0,0 +1,11 @@ |
|||||
|
{ |
||||
|
"directory": "public/assets/libs", |
||||
|
"ignoredDependencies": [ |
||||
|
"es6-promise", |
||||
|
"file-saver", |
||||
|
"html2canvas", |
||||
|
"jspdf", |
||||
|
"jspdf-autotable", |
||||
|
"pdfmake" |
||||
|
] |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
[app] |
||||
|
debug = true |
||||
|
trace = true |
||||
|
|
||||
|
[database] |
||||
|
hostname = 127.0.0.1 |
||||
|
database = fastadmin |
||||
|
username = root |
||||
|
password = root |
||||
|
hostport = 3306 |
||||
|
prefix = fa_ |
||||
@ -0,0 +1,18 @@ |
|||||
|
/nbproject/ |
||||
|
/thinkphp/ |
||||
|
/vendor/ |
||||
|
/runtime/* |
||||
|
/addons/* |
||||
|
/public/assets/libs/ |
||||
|
/public/assets/addons/* |
||||
|
/public/uploads/* |
||||
|
.idea |
||||
|
composer.lock |
||||
|
*.log |
||||
|
*.css.map |
||||
|
!.gitkeep |
||||
|
.env |
||||
|
.svn |
||||
|
.vscode |
||||
|
node_modules |
||||
|
.user.ini |
||||
@ -0,0 +1,191 @@ |
|||||
|
Apache License |
||||
|
Version 2.0, January 2004 |
||||
|
http://www.apache.org/licenses/ |
||||
|
|
||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION |
||||
|
|
||||
|
1. Definitions. |
||||
|
|
||||
|
"License" shall mean the terms and conditions for use, reproduction, and |
||||
|
distribution as defined by Sections 1 through 9 of this document. |
||||
|
|
||||
|
"Licensor" shall mean the copyright owner or entity authorized by the copyright |
||||
|
owner that is granting the License. |
||||
|
|
||||
|
"Legal Entity" shall mean the union of the acting entity and all other entities |
||||
|
that control, are controlled by, or are under common control with that entity. |
||||
|
For the purposes of this definition, "control" means (i) the power, direct or |
||||
|
indirect, to cause the direction or management of such entity, whether by |
||||
|
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the |
||||
|
outstanding shares, or (iii) beneficial ownership of such entity. |
||||
|
|
||||
|
"You" (or "Your") shall mean an individual or Legal Entity exercising |
||||
|
permissions granted by this License. |
||||
|
|
||||
|
"Source" form shall mean the preferred form for making modifications, including |
||||
|
but not limited to software source code, documentation source, and configuration |
||||
|
files. |
||||
|
|
||||
|
"Object" form shall mean any form resulting from mechanical transformation or |
||||
|
translation of a Source form, including but not limited to compiled object code, |
||||
|
generated documentation, and conversions to other media types. |
||||
|
|
||||
|
"Work" shall mean the work of authorship, whether in Source or Object form, made |
||||
|
available under the License, as indicated by a copyright notice that is included |
||||
|
in or attached to the work (an example is provided in the Appendix below). |
||||
|
|
||||
|
"Derivative Works" shall mean any work, whether in Source or Object form, that |
||||
|
is based on (or derived from) the Work and for which the editorial revisions, |
||||
|
annotations, elaborations, or other modifications represent, as a whole, an |
||||
|
original work of authorship. For the purposes of this License, Derivative Works |
||||
|
shall not include works that remain separable from, or merely link (or bind by |
||||
|
name) to the interfaces of, the Work and Derivative Works thereof. |
||||
|
|
||||
|
"Contribution" shall mean any work of authorship, including the original version |
||||
|
of the Work and any modifications or additions to that Work or Derivative Works |
||||
|
thereof, that is intentionally submitted to Licensor for inclusion in the Work |
||||
|
by the copyright owner or by an individual or Legal Entity authorized to submit |
||||
|
on behalf of the copyright owner. For the purposes of this definition, |
||||
|
"submitted" means any form of electronic, verbal, or written communication sent |
||||
|
to the Licensor or its representatives, including but not limited to |
||||
|
communication on electronic mailing lists, source code control systems, and |
||||
|
issue tracking systems that are managed by, or on behalf of, the Licensor for |
||||
|
the purpose of discussing and improving the Work, but excluding communication |
||||
|
that is conspicuously marked or otherwise designated in writing by the copyright |
||||
|
owner as "Not a Contribution." |
||||
|
|
||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf |
||||
|
of whom a Contribution has been received by Licensor and subsequently |
||||
|
incorporated within the Work. |
||||
|
|
||||
|
2. Grant of Copyright License. |
||||
|
|
||||
|
Subject to the terms and conditions of this License, each Contributor hereby |
||||
|
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, |
||||
|
irrevocable copyright license to reproduce, prepare Derivative Works of, |
||||
|
publicly display, publicly perform, sublicense, and distribute the Work and such |
||||
|
Derivative Works in Source or Object form. |
||||
|
|
||||
|
3. Grant of Patent License. |
||||
|
|
||||
|
Subject to the terms and conditions of this License, each Contributor hereby |
||||
|
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, |
||||
|
irrevocable (except as stated in this section) patent license to make, have |
||||
|
made, use, offer to sell, sell, import, and otherwise transfer the Work, where |
||||
|
such license applies only to those patent claims licensable by such Contributor |
||||
|
that are necessarily infringed by their Contribution(s) alone or by combination |
||||
|
of their Contribution(s) with the Work to which such Contribution(s) was |
||||
|
submitted. If You institute patent litigation against any entity (including a |
||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work or a |
||||
|
Contribution incorporated within the Work constitutes direct or contributory |
||||
|
patent infringement, then any patent licenses granted to You under this License |
||||
|
for that Work shall terminate as of the date such litigation is filed. |
||||
|
|
||||
|
4. Redistribution. |
||||
|
|
||||
|
You may reproduce and distribute copies of the Work or Derivative Works thereof |
||||
|
in any medium, with or without modifications, and in Source or Object form, |
||||
|
provided that You meet the following conditions: |
||||
|
|
||||
|
You must give any other recipients of the Work or Derivative Works a copy of |
||||
|
this License; and |
||||
|
You must cause any modified files to carry prominent notices stating that You |
||||
|
changed the files; and |
||||
|
You must retain, in the Source form of any Derivative Works that You distribute, |
||||
|
all copyright, patent, trademark, and attribution notices from the Source form |
||||
|
of the Work, excluding those notices that do not pertain to any part of the |
||||
|
Derivative Works; and |
||||
|
If the Work includes a "NOTICE" text file as part of its distribution, then any |
||||
|
Derivative Works that You distribute must include a readable copy of the |
||||
|
attribution notices contained within such NOTICE file, excluding those notices |
||||
|
that do not pertain to any part of the Derivative Works, in at least one of the |
||||
|
following places: within a NOTICE text file distributed as part of the |
||||
|
Derivative Works; within the Source form or documentation, if provided along |
||||
|
with the Derivative Works; or, within a display generated by the Derivative |
||||
|
Works, if and wherever such third-party notices normally appear. The contents of |
||||
|
the NOTICE file are for informational purposes only and do not modify the |
||||
|
License. You may add Your own attribution notices within Derivative Works that |
||||
|
You distribute, alongside or as an addendum to the NOTICE text from the Work, |
||||
|
provided that such additional attribution notices cannot be construed as |
||||
|
modifying the License. |
||||
|
You may add Your own copyright statement to Your modifications and may provide |
||||
|
additional or different license terms and conditions for use, reproduction, or |
||||
|
distribution of Your modifications, or for any such Derivative Works as a whole, |
||||
|
provided Your use, reproduction, and distribution of the Work otherwise complies |
||||
|
with the conditions stated in this License. |
||||
|
|
||||
|
5. Submission of Contributions. |
||||
|
|
||||
|
Unless You explicitly state otherwise, any Contribution intentionally submitted |
||||
|
for inclusion in the Work by You to the Licensor shall be under the terms and |
||||
|
conditions of this License, without any additional terms or conditions. |
||||
|
Notwithstanding the above, nothing herein shall supersede or modify the terms of |
||||
|
any separate license agreement you may have executed with Licensor regarding |
||||
|
such Contributions. |
||||
|
|
||||
|
6. Trademarks. |
||||
|
|
||||
|
This License does not grant permission to use the trade names, trademarks, |
||||
|
service marks, or product names of the Licensor, except as required for |
||||
|
reasonable and customary use in describing the origin of the Work and |
||||
|
reproducing the content of the NOTICE file. |
||||
|
|
||||
|
7. Disclaimer of Warranty. |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, Licensor provides the |
||||
|
Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, |
||||
|
including, without limitation, any warranties or conditions of TITLE, |
||||
|
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are |
||||
|
solely responsible for determining the appropriateness of using or |
||||
|
redistributing the Work and assume any risks associated with Your exercise of |
||||
|
permissions under this License. |
||||
|
|
||||
|
8. Limitation of Liability. |
||||
|
|
||||
|
In no event and under no legal theory, whether in tort (including negligence), |
||||
|
contract, or otherwise, unless required by applicable law (such as deliberate |
||||
|
and grossly negligent acts) or agreed to in writing, shall any Contributor be |
||||
|
liable to You for damages, including any direct, indirect, special, incidental, |
||||
|
or consequential damages of any character arising as a result of this License or |
||||
|
out of the use or inability to use the Work (including but not limited to |
||||
|
damages for loss of goodwill, work stoppage, computer failure or malfunction, or |
||||
|
any and all other commercial damages or losses), even if such Contributor has |
||||
|
been advised of the possibility of such damages. |
||||
|
|
||||
|
9. Accepting Warranty or Additional Liability. |
||||
|
|
||||
|
While redistributing the Work or Derivative Works thereof, You may choose to |
||||
|
offer, and charge a fee for, acceptance of support, warranty, indemnity, or |
||||
|
other liability obligations and/or rights consistent with this License. However, |
||||
|
in accepting such obligations, You may act only on Your own behalf and on Your |
||||
|
sole responsibility, not on behalf of any other Contributor, and only if You |
||||
|
agree to indemnify, defend, and hold each Contributor harmless for any liability |
||||
|
incurred by, or claims asserted against, such Contributor by reason of your |
||||
|
accepting any such warranty or additional liability. |
||||
|
|
||||
|
END OF TERMS AND CONDITIONS |
||||
|
|
||||
|
APPENDIX: How to apply the Apache License to your work |
||||
|
|
||||
|
To apply the Apache License to your work, attach the following boilerplate |
||||
|
notice, with the fields enclosed by brackets "{}" replaced with your own |
||||
|
identifying information. (Don't include the brackets!) The text should be |
||||
|
enclosed in the appropriate comment syntax for the file format. We also |
||||
|
recommend that a file or class name and description of purpose be included on |
||||
|
the same "printed page" as the copyright notice for easier identification within |
||||
|
third-party archives. |
||||
|
|
||||
|
Copyright 2017 Karson |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
||||
@ -0,0 +1,97 @@ |
|||||
|
FastAdmin是一款基于ThinkPHP+Bootstrap的极速后台开发框架。 |
||||
|
|
||||
|
|
||||
|
## 主要特性 |
||||
|
|
||||
|
* 基于`Auth`验证的权限管理系统 |
||||
|
* 支持无限级父子级权限继承,父级的管理员可任意增删改子级管理员及权限设置 |
||||
|
* 支持单管理员多角色 |
||||
|
* 支持管理子级数据或个人数据 |
||||
|
* 强大的一键生成功能 |
||||
|
* 一键生成CRUD,包括控制器、模型、视图、JS、语言包、菜单、回收站等 |
||||
|
* 一键压缩打包JS和CSS文件,一键CDN静态资源部署 |
||||
|
* 一键生成控制器菜单和规则 |
||||
|
* 一键生成API接口文档 |
||||
|
* 完善的前端功能组件开发 |
||||
|
* 基于`AdminLTE`二次开发 |
||||
|
* 基于`Bootstrap`开发,自适应手机、平板、PC |
||||
|
* 基于`RequireJS`进行JS模块管理,按需加载 |
||||
|
* 基于`Less`进行样式开发 |
||||
|
* 强大的插件扩展功能,在线安装卸载升级插件 |
||||
|
* 通用的会员模块和API模块 |
||||
|
* 共用同一账号体系的Web端会员中心权限验证和API接口会员权限验证 |
||||
|
* 二级域名部署支持,同时域名支持绑定到应用插件 |
||||
|
* 多语言支持,服务端及客户端支持 |
||||
|
* 支持大文件分片上传、剪切板粘贴上传、拖拽上传,进度条显示,图片上传前压缩 |
||||
|
* 支持表格固定列、固定表头、跨页选择、Excel导出、模板渲染等功能 |
||||
|
* 强大的第三方应用模块支持([CMS](https://www.fastadmin.net/store/cms.html)、[博客](https://www.fastadmin.net/store/blog.html)、[知识付费问答](https://www.fastadmin.net/store/ask.html)、[在线投票系统](https://www.fastadmin.net/store/vote.html)、[B2C商城](https://www.fastadmin.net/store/shopro.html)、[B2B2C商城](https://www.fastadmin.net/store/wanlshop.html)) |
||||
|
* 支持CMS、博客、知识付费问答无缝整合[Xunsearch全文搜索](https://www.fastadmin.net/store/xunsearch.html) |
||||
|
* 第三方小程序支持([CMS小程序](https://www.fastadmin.net/store/cms.html)、[预订小程序](https://www.fastadmin.net/store/ball.html)、[问答小程序](https://www.fastadmin.net/store/ask.html)、[点餐小程序](https://www.fastadmin.net/store/unidrink.html)、[B2C小程序](https://www.fastadmin.net/store/shopro.html)、[B2B2C小程序](https://www.fastadmin.net/store/wanlshop.html)、[博客小程序](https://www.fastadmin.net/store/blog.html)) |
||||
|
* 整合第三方短信接口(阿里云、腾讯云短信) |
||||
|
* 无缝整合第三方云存储(七牛云、阿里云OSS、又拍云)功能,支持云储存分片上传 |
||||
|
* 第三方富文本编辑器支持(Summernote、Kindeditor、百度编辑器) |
||||
|
* 第三方登录(QQ、微信、微博)整合 |
||||
|
* 第三方支付(微信、支付宝)无缝整合,微信支持PC端扫码支付 |
||||
|
* 丰富的插件应用市场 |
||||
|
|
||||
|
## 安装使用 |
||||
|
|
||||
|
https://doc.fastadmin.net |
||||
|
|
||||
|
## 在线演示 |
||||
|
|
||||
|
https://demo.fastadmin.net |
||||
|
|
||||
|
用户名:admin |
||||
|
|
||||
|
密 码:123456 |
||||
|
|
||||
|
提 示:演示站数据无法进行修改,请下载源码安装体验全部功能 |
||||
|
|
||||
|
## 界面截图 |
||||
|
 |
||||
|
|
||||
|
## 问题反馈 |
||||
|
|
||||
|
在使用中有任何问题,请使用以下联系方式联系我们 |
||||
|
|
||||
|
交流社区: https://ask.fastadmin.net |
||||
|
|
||||
|
QQ 1 群(满)、QQ 2 群(满)、QQ 3 群(满)、QQ 4 群(满)、QQ 5 群(满)、QQ 6 群(满)、[QQ 7 群](https://www.fastadmin.net/goto/qun)。 |
||||
|
|
||||
|
Github: https://github.com/karsonzhang/fastadmin |
||||
|
|
||||
|
Gitee: https://gitee.com/karson/fastadmin |
||||
|
|
||||
|
## 特别鸣谢 |
||||
|
|
||||
|
感谢以下的项目,排名不分先后 |
||||
|
|
||||
|
ThinkPHP:http://www.thinkphp.cn |
||||
|
|
||||
|
AdminLTE:https://adminlte.io |
||||
|
|
||||
|
Bootstrap:http://getbootstrap.com |
||||
|
|
||||
|
jQuery:http://jquery.com |
||||
|
|
||||
|
Bootstrap-table:https://github.com/wenzhixin/bootstrap-table |
||||
|
|
||||
|
Nice-validator: https://validator.niceue.com |
||||
|
|
||||
|
SelectPage: https://github.com/TerryZ/SelectPage |
||||
|
|
||||
|
Layer: https://layuion.com/layer/ |
||||
|
|
||||
|
DropzoneJS: https://www.dropzonejs.com |
||||
|
|
||||
|
|
||||
|
## 版权信息 |
||||
|
|
||||
|
FastAdmin遵循Apache2开源协议发布,并提供免费使用。 |
||||
|
|
||||
|
本项目包含的第三方源码和二进制文件之版权信息另行标注。 |
||||
|
|
||||
|
版权所有Copyright © 2017-2022 by FastAdmin (https://www.fastadmin.net) |
||||
|
|
||||
|
All rights reserved。 |
||||
@ -0,0 +1 @@ |
|||||
|
|
||||
@ -0,0 +1 @@ |
|||||
|
deny from all |
||||
@ -0,0 +1,14 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\behavior; |
||||
|
|
||||
|
class AdminLog |
||||
|
{ |
||||
|
public function run(&$params) |
||||
|
{ |
||||
|
//只记录POST请求的日志 |
||||
|
if (request()->isPost() && config('fastadmin.auto_record_log')) { |
||||
|
\app\admin\model\AdminLog::record(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,344 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\command; |
||||
|
|
||||
|
use think\addons\AddonException; |
||||
|
use think\addons\Service; |
||||
|
use think\Config; |
||||
|
use think\console\Command; |
||||
|
use think\console\Input; |
||||
|
use think\console\input\Option; |
||||
|
use think\console\Output; |
||||
|
use think\Db; |
||||
|
use think\Exception; |
||||
|
use think\exception\PDOException; |
||||
|
|
||||
|
class Addon extends Command |
||||
|
{ |
||||
|
|
||||
|
protected function configure() |
||||
|
{ |
||||
|
$this |
||||
|
->setName('addon') |
||||
|
->addOption('name', 'a', Option::VALUE_REQUIRED, 'addon name', null) |
||||
|
->addOption('action', 'c', Option::VALUE_REQUIRED, 'action(create/enable/disable/uninstall/refresh/package/move)', 'create') |
||||
|
->addOption('force', 'f', Option::VALUE_OPTIONAL, 'force override', null) |
||||
|
->addOption('release', 'r', Option::VALUE_OPTIONAL, 'addon release version', null) |
||||
|
->addOption('uid', 'u', Option::VALUE_OPTIONAL, 'fastadmin uid', null) |
||||
|
->addOption('token', 't', Option::VALUE_OPTIONAL, 'fastadmin token', null) |
||||
|
->addOption('domain', 'd', Option::VALUE_OPTIONAL, 'domain', null) |
||||
|
->addOption('local', 'l', Option::VALUE_OPTIONAL, 'local package', null) |
||||
|
->setDescription('Addon manager'); |
||||
|
} |
||||
|
|
||||
|
protected function execute(Input $input, Output $output) |
||||
|
{ |
||||
|
$name = $input->getOption('name') ?: ''; |
||||
|
$action = $input->getOption('action') ?: ''; |
||||
|
if (stripos($name, 'addons' . DS) !== false) { |
||||
|
$name = explode(DS, $name)[1]; |
||||
|
} |
||||
|
//强制覆盖 |
||||
|
$force = $input->getOption('force'); |
||||
|
//版本 |
||||
|
$release = $input->getOption('release') ?: ''; |
||||
|
//uid |
||||
|
$uid = $input->getOption('uid') ?: ''; |
||||
|
//token |
||||
|
$token = $input->getOption('token') ?: ''; |
||||
|
|
||||
|
include dirname(__DIR__) . DS . 'common.php'; |
||||
|
|
||||
|
if (!$name && !in_array($action, ['refresh'])) { |
||||
|
throw new Exception('Addon name could not be empty'); |
||||
|
} |
||||
|
if (!$action || !in_array($action, ['create', 'disable', 'enable', 'install', 'uninstall', 'refresh', 'upgrade', 'package', 'move'])) { |
||||
|
throw new Exception('Please input correct action name'); |
||||
|
} |
||||
|
|
||||
|
// 查询一次SQL,判断连接是否正常 |
||||
|
Db::execute("SELECT 1"); |
||||
|
|
||||
|
$addonDir = ADDON_PATH . $name . DS; |
||||
|
switch ($action) { |
||||
|
case 'create': |
||||
|
//非覆盖模式时如果存在则报错 |
||||
|
if (is_dir($addonDir) && !$force) { |
||||
|
throw new Exception("addon already exists!\nIf you need to create again, use the parameter --force=true "); |
||||
|
} |
||||
|
//如果存在先移除 |
||||
|
if (is_dir($addonDir)) { |
||||
|
rmdirs($addonDir); |
||||
|
} |
||||
|
mkdir($addonDir, 0755, true); |
||||
|
mkdir($addonDir . DS . 'controller', 0755, true); |
||||
|
$menuList = \app\common\library\Menu::export($name); |
||||
|
$createMenu = $this->getCreateMenu($menuList); |
||||
|
$prefix = Config::get('database.prefix'); |
||||
|
$createTableSql = ''; |
||||
|
try { |
||||
|
$result = Db::query("SHOW CREATE TABLE `" . $prefix . $name . "`;"); |
||||
|
if (isset($result[0]) && isset($result[0]['Create Table'])) { |
||||
|
$createTableSql = $result[0]['Create Table']; |
||||
|
} |
||||
|
} catch (PDOException $e) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
$data = [ |
||||
|
'name' => $name, |
||||
|
'addon' => $name, |
||||
|
'addonClassName' => ucfirst($name), |
||||
|
'addonInstallMenu' => $createMenu ? "\$menu = " . var_export_short($createMenu) . ";\n\tMenu::create(\$menu);" : '', |
||||
|
'addonUninstallMenu' => $menuList ? 'Menu::delete("' . $name . '");' : '', |
||||
|
'addonEnableMenu' => $menuList ? 'Menu::enable("' . $name . '");' : '', |
||||
|
'addonDisableMenu' => $menuList ? 'Menu::disable("' . $name . '");' : '', |
||||
|
]; |
||||
|
$this->writeToFile("addon", $data, $addonDir . ucfirst($name) . '.php'); |
||||
|
$this->writeToFile("config", $data, $addonDir . 'config.php'); |
||||
|
$this->writeToFile("info", $data, $addonDir . 'info.ini'); |
||||
|
$this->writeToFile("controller", $data, $addonDir . 'controller' . DS . 'Index.php'); |
||||
|
if ($createTableSql) { |
||||
|
$createTableSql = str_replace("`" . $prefix, '`__PREFIX__', $createTableSql); |
||||
|
file_put_contents($addonDir . 'install.sql', $createTableSql); |
||||
|
} |
||||
|
|
||||
|
$output->info("Create Successed!"); |
||||
|
break; |
||||
|
case 'disable': |
||||
|
case 'enable': |
||||
|
try { |
||||
|
//调用启用、禁用的方法 |
||||
|
Service::$action($name, 0); |
||||
|
} catch (AddonException $e) { |
||||
|
if ($e->getCode() != -3) { |
||||
|
throw new Exception($e->getMessage()); |
||||
|
} |
||||
|
if (!$force) { |
||||
|
//如果有冲突文件则提醒 |
||||
|
$data = $e->getData(); |
||||
|
foreach ($data['conflictlist'] as $k => $v) { |
||||
|
$output->warning($v); |
||||
|
} |
||||
|
$output->info("Are you sure you want to " . ($action == 'enable' ? 'override' : 'delete') . " all those files? Type 'yes' to continue: "); |
||||
|
$line = fgets(defined('STDIN') ? STDIN : fopen('php://stdin', 'r')); |
||||
|
if (trim($line) != 'yes') { |
||||
|
throw new Exception("Operation is aborted!"); |
||||
|
} |
||||
|
} |
||||
|
//调用启用、禁用的方法 |
||||
|
Service::$action($name, 1); |
||||
|
} catch (Exception $e) { |
||||
|
throw new Exception($e->getMessage()); |
||||
|
} |
||||
|
$output->info(ucfirst($action) . " Successed!"); |
||||
|
break; |
||||
|
case 'uninstall': |
||||
|
//非覆盖模式时如果存在则报错 |
||||
|
if (!$force) { |
||||
|
throw new Exception("If you need to uninstall addon, use the parameter --force=true "); |
||||
|
} |
||||
|
try { |
||||
|
Service::uninstall($name, 0); |
||||
|
} catch (AddonException $e) { |
||||
|
if ($e->getCode() != -3) { |
||||
|
throw new Exception($e->getMessage()); |
||||
|
} |
||||
|
if (!$force) { |
||||
|
//如果有冲突文件则提醒 |
||||
|
$data = $e->getData(); |
||||
|
foreach ($data['conflictlist'] as $k => $v) { |
||||
|
$output->warning($v); |
||||
|
} |
||||
|
$output->info("Are you sure you want to delete all those files? Type 'yes' to continue: "); |
||||
|
$line = fgets(defined('STDIN') ? STDIN : fopen('php://stdin', 'r')); |
||||
|
if (trim($line) != 'yes') { |
||||
|
throw new Exception("Operation is aborted!"); |
||||
|
} |
||||
|
} |
||||
|
Service::uninstall($name, 1); |
||||
|
} catch (Exception $e) { |
||||
|
throw new Exception($e->getMessage()); |
||||
|
} |
||||
|
|
||||
|
$output->info("Uninstall Successed!"); |
||||
|
break; |
||||
|
case 'refresh': |
||||
|
Service::refresh(); |
||||
|
$output->info("Refresh Successed!"); |
||||
|
break; |
||||
|
case 'package': |
||||
|
$infoFile = $addonDir . 'info.ini'; |
||||
|
if (!is_file($infoFile)) { |
||||
|
throw new Exception(__('Addon info file was not found')); |
||||
|
} |
||||
|
|
||||
|
$info = get_addon_info($name); |
||||
|
if (!$info) { |
||||
|
throw new Exception(__('Addon info file data incorrect')); |
||||
|
} |
||||
|
$infoname = isset($info['name']) ? $info['name'] : ''; |
||||
|
if (!$infoname || !preg_match("/^[a-z]+$/i", $infoname) || $infoname != $name) { |
||||
|
throw new Exception(__('Addon info name incorrect')); |
||||
|
} |
||||
|
|
||||
|
$infoversion = isset($info['version']) ? $info['version'] : ''; |
||||
|
if (!$infoversion || !preg_match("/^\d+\.\d+\.\d+$/i", $infoversion)) { |
||||
|
throw new Exception(__('Addon info version incorrect')); |
||||
|
} |
||||
|
|
||||
|
$addonTmpDir = RUNTIME_PATH . 'addons' . DS; |
||||
|
if (!is_dir($addonTmpDir)) { |
||||
|
@mkdir($addonTmpDir, 0755, true); |
||||
|
} |
||||
|
$addonFile = $addonTmpDir . $infoname . '-' . $infoversion . '.zip'; |
||||
|
if (!class_exists('ZipArchive')) { |
||||
|
throw new Exception(__('ZinArchive not install')); |
||||
|
} |
||||
|
$zip = new \ZipArchive; |
||||
|
$zip->open($addonFile, \ZipArchive::CREATE | \ZipArchive::OVERWRITE); |
||||
|
|
||||
|
$files = new \RecursiveIteratorIterator( |
||||
|
new \RecursiveDirectoryIterator($addonDir), \RecursiveIteratorIterator::LEAVES_ONLY |
||||
|
); |
||||
|
|
||||
|
foreach ($files as $name => $file) { |
||||
|
if (!$file->isDir()) { |
||||
|
$filePath = $file->getRealPath(); |
||||
|
$relativePath = str_replace(DS, '/', substr($filePath, strlen($addonDir))); |
||||
|
if (!in_array($file->getFilename(), ['.git', '.DS_Store', 'Thumbs.db'])) { |
||||
|
$zip->addFile($filePath, $relativePath); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$zip->close(); |
||||
|
$output->info("Package Successed!"); |
||||
|
break; |
||||
|
case 'move': |
||||
|
$movePath = [ |
||||
|
'adminOnlySelfDir' => ['admin/behavior', 'admin/controller', 'admin/library', 'admin/model', 'admin/validate', 'admin/view'], |
||||
|
'adminAllSubDir' => ['admin/lang'], |
||||
|
'publicDir' => ['public/assets/addons', 'public/assets/js/backend'] |
||||
|
]; |
||||
|
$paths = []; |
||||
|
$appPath = str_replace('/', DS, APP_PATH); |
||||
|
$rootPath = str_replace('/', DS, ROOT_PATH); |
||||
|
foreach ($movePath as $k => $items) { |
||||
|
switch ($k) { |
||||
|
case 'adminOnlySelfDir': |
||||
|
foreach ($items as $v) { |
||||
|
$v = str_replace('/', DS, $v); |
||||
|
$oldPath = $appPath . $v . DS . $name; |
||||
|
$newPath = $rootPath . "addons" . DS . $name . DS . "application" . DS . $v . DS . $name; |
||||
|
$paths[$oldPath] = $newPath; |
||||
|
} |
||||
|
break; |
||||
|
case 'adminAllSubDir': |
||||
|
foreach ($items as $v) { |
||||
|
$v = str_replace('/', DS, $v); |
||||
|
$vPath = $appPath . $v; |
||||
|
$list = scandir($vPath); |
||||
|
foreach ($list as $_v) { |
||||
|
if (!in_array($_v, ['.', '..']) && is_dir($vPath . DS . $_v)) { |
||||
|
$oldPath = $appPath . $v . DS . $_v . DS . $name; |
||||
|
$newPath = $rootPath . "addons" . DS . $name . DS . "application" . DS . $v . DS . $_v . DS . $name; |
||||
|
$paths[$oldPath] = $newPath; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
break; |
||||
|
case 'publicDir': |
||||
|
foreach ($items as $v) { |
||||
|
$v = str_replace('/', DS, $v); |
||||
|
$oldPath = $rootPath . $v . DS . $name; |
||||
|
$newPath = $rootPath . 'addons' . DS . $name . DS . $v . DS . $name; |
||||
|
$paths[$oldPath] = $newPath; |
||||
|
} |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
foreach ($paths as $oldPath => $newPath) { |
||||
|
if (is_dir($oldPath)) { |
||||
|
if ($force) { |
||||
|
if (is_dir($newPath)) { |
||||
|
$list = scandir($newPath); |
||||
|
foreach ($list as $_v) { |
||||
|
if (!in_array($_v, ['.', '..'])) { |
||||
|
$file = $newPath . DS . $_v; |
||||
|
@chmod($file, 0777); |
||||
|
@unlink($file); |
||||
|
} |
||||
|
} |
||||
|
@rmdir($newPath); |
||||
|
} |
||||
|
} |
||||
|
copydirs($oldPath, $newPath); |
||||
|
} |
||||
|
} |
||||
|
break; |
||||
|
default: |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取创建菜单的数组 |
||||
|
* @param array $menu |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function getCreateMenu($menu) |
||||
|
{ |
||||
|
$result = []; |
||||
|
foreach ($menu as $k => & $v) { |
||||
|
$arr = [ |
||||
|
'name' => $v['name'], |
||||
|
'title' => $v['title'], |
||||
|
]; |
||||
|
if ($v['icon'] != 'fa fa-circle-o') { |
||||
|
$arr['icon'] = $v['icon']; |
||||
|
} |
||||
|
if ($v['ismenu']) { |
||||
|
$arr['ismenu'] = $v['ismenu']; |
||||
|
} |
||||
|
if (isset($v['childlist']) && $v['childlist']) { |
||||
|
$arr['sublist'] = $this->getCreateMenu($v['childlist']); |
||||
|
} |
||||
|
$result[] = $arr; |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 写入到文件 |
||||
|
* @param string $name |
||||
|
* @param array $data |
||||
|
* @param string $pathname |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
protected function writeToFile($name, $data, $pathname) |
||||
|
{ |
||||
|
$search = $replace = []; |
||||
|
foreach ($data as $k => $v) { |
||||
|
$search[] = "{%{$k}%}"; |
||||
|
$replace[] = $v; |
||||
|
} |
||||
|
$stub = file_get_contents($this->getStub($name)); |
||||
|
$content = str_replace($search, $replace, $stub); |
||||
|
|
||||
|
if (!is_dir(dirname($pathname))) { |
||||
|
mkdir(strtolower(dirname($pathname)), 0755, true); |
||||
|
} |
||||
|
return file_put_contents($pathname, $content); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取基础模板 |
||||
|
* @param string $name |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected function getStub($name) |
||||
|
{ |
||||
|
return __DIR__ . '/Addon/stubs/' . $name . '.stub'; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,54 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace addons\{%name%}; |
||||
|
|
||||
|
use app\common\library\Menu; |
||||
|
use think\Addons; |
||||
|
|
||||
|
/** |
||||
|
* 插件 |
||||
|
*/ |
||||
|
class {%addonClassName%} extends Addons |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* 插件安装方法 |
||||
|
* @return bool |
||||
|
*/ |
||||
|
public function install() |
||||
|
{ |
||||
|
{%addonInstallMenu%} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 插件卸载方法 |
||||
|
* @return bool |
||||
|
*/ |
||||
|
public function uninstall() |
||||
|
{ |
||||
|
{%addonUninstallMenu%} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 插件启用方法 |
||||
|
* @return bool |
||||
|
*/ |
||||
|
public function enable() |
||||
|
{ |
||||
|
{%addonEnableMenu%} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 插件禁用方法 |
||||
|
* @return bool |
||||
|
*/ |
||||
|
public function disable() |
||||
|
{ |
||||
|
{%addonDisableMenu%} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,44 @@ |
|||||
|
<?php |
||||
|
|
||||
|
return [ |
||||
|
[ |
||||
|
//配置唯一标识 |
||||
|
'name' => 'usernmae', |
||||
|
//显示的标题 |
||||
|
'title' => '用户名', |
||||
|
//类型 |
||||
|
'type' => 'string', |
||||
|
//分组 |
||||
|
'group' => '', |
||||
|
//动态显示 |
||||
|
'visible' => '', |
||||
|
//数据字典 |
||||
|
'content' => [ |
||||
|
], |
||||
|
//值 |
||||
|
'value' => '', |
||||
|
//验证规则 |
||||
|
'rule' => 'required', |
||||
|
//错误消息 |
||||
|
'msg' => '', |
||||
|
//提示消息 |
||||
|
'tip' => '', |
||||
|
//成功消息 |
||||
|
'ok' => '', |
||||
|
//扩展信息 |
||||
|
'extend' => '' |
||||
|
], |
||||
|
[ |
||||
|
'name' => 'password', |
||||
|
'title' => '密码', |
||||
|
'type' => 'string', |
||||
|
'content' => [ |
||||
|
], |
||||
|
'value' => '', |
||||
|
'rule' => 'required', |
||||
|
'msg' => '', |
||||
|
'tip' => '', |
||||
|
'ok' => '', |
||||
|
'extend' => '' |
||||
|
], |
||||
|
]; |
||||
@ -0,0 +1,15 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace addons\{%addon%}\controller; |
||||
|
|
||||
|
use think\addons\Controller; |
||||
|
|
||||
|
class Index extends Controller |
||||
|
{ |
||||
|
|
||||
|
public function index() |
||||
|
{ |
||||
|
$this->error("当前插件暂无前台页面"); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
name = {%name%} |
||||
|
title = 插件名称{%name%} |
||||
|
intro = 插件介绍 |
||||
|
author = yourname |
||||
|
website = https://www.fastadmin.net |
||||
|
version = 1.0.0 |
||||
|
state = 1 |
||||
@ -0,0 +1,195 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\command; |
||||
|
|
||||
|
use app\admin\command\Api\library\Builder; |
||||
|
use think\Config; |
||||
|
use think\console\Command; |
||||
|
use think\console\Input; |
||||
|
use think\console\input\Option; |
||||
|
use think\console\Output; |
||||
|
use think\Exception; |
||||
|
|
||||
|
class Api extends Command |
||||
|
{ |
||||
|
protected function configure() |
||||
|
{ |
||||
|
$site = Config::get('site'); |
||||
|
$this |
||||
|
->setName('api') |
||||
|
->addOption('url', 'u', Option::VALUE_OPTIONAL, 'default api url', '') |
||||
|
->addOption('module', 'm', Option::VALUE_OPTIONAL, 'module name(admin/index/api)', 'api') |
||||
|
->addOption('output', 'o', Option::VALUE_OPTIONAL, 'output index file name', 'api.html') |
||||
|
->addOption('template', 'e', Option::VALUE_OPTIONAL, '', 'index.html') |
||||
|
->addOption('force', 'f', Option::VALUE_OPTIONAL, 'force override general file', false) |
||||
|
->addOption('title', 't', Option::VALUE_OPTIONAL, 'document title', $site['name'] ?? '') |
||||
|
->addOption('class', 'c', Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'extend class', null) |
||||
|
->addOption('language', 'l', Option::VALUE_OPTIONAL, 'language', 'zh-cn') |
||||
|
->addOption('addon', 'a', Option::VALUE_OPTIONAL, 'addon name', null) |
||||
|
->addOption('controller', 'r', Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, 'controller name', null) |
||||
|
->setDescription('Build Api document from controller'); |
||||
|
} |
||||
|
|
||||
|
protected function execute(Input $input, Output $output) |
||||
|
{ |
||||
|
$apiDir = __DIR__ . DS . 'Api' . DS; |
||||
|
|
||||
|
$force = $input->getOption('force'); |
||||
|
$url = $input->getOption('url'); |
||||
|
$language = $input->getOption('language'); |
||||
|
$template = $input->getOption('template'); |
||||
|
if (!preg_match("/^([a-z0-9]+)\.html\$/i", $template)) { |
||||
|
throw new Exception('template file not correct'); |
||||
|
} |
||||
|
$language = $language ? $language : 'zh-cn'; |
||||
|
$langFile = $apiDir . 'lang' . DS . $language . '.php'; |
||||
|
if (!is_file($langFile)) { |
||||
|
throw new Exception('language file not found'); |
||||
|
} |
||||
|
$lang = include_once $langFile; |
||||
|
// 目标目录 |
||||
|
$output_dir = ROOT_PATH . 'public' . DS; |
||||
|
$output_file = $output_dir . $input->getOption('output'); |
||||
|
if (is_file($output_file) && !$force) { |
||||
|
throw new Exception("api index file already exists!\nIf you need to rebuild again, use the parameter --force=true "); |
||||
|
} |
||||
|
// 模板文件 |
||||
|
$template_dir = $apiDir . 'template' . DS; |
||||
|
$template_file = $template_dir . $template; |
||||
|
if (!is_file($template_file)) { |
||||
|
throw new Exception('template file not found'); |
||||
|
} |
||||
|
// 额外的类 |
||||
|
$classes = $input->getOption('class'); |
||||
|
// 标题 |
||||
|
$title = $input->getOption('title'); |
||||
|
// 模块 |
||||
|
$module = $input->getOption('module'); |
||||
|
// 插件 |
||||
|
$addon = $input->getOption('addon'); |
||||
|
|
||||
|
$moduleDir = $addonDir = ''; |
||||
|
if ($addon) { |
||||
|
$addonInfo = get_addon_info($addon); |
||||
|
if (!$addonInfo) { |
||||
|
throw new Exception('addon not found'); |
||||
|
} |
||||
|
$moduleDir = ADDON_PATH . $addon . DS; |
||||
|
} else { |
||||
|
$moduleDir = APP_PATH . $module . DS; |
||||
|
} |
||||
|
if (!is_dir($moduleDir)) { |
||||
|
throw new Exception('module not found'); |
||||
|
} |
||||
|
|
||||
|
if (version_compare(PHP_VERSION, '7.0.0', '<')) { |
||||
|
throw new Exception("Requires PHP version 7.0 or newer"); |
||||
|
} |
||||
|
|
||||
|
//控制器名 |
||||
|
$controller = $input->getOption('controller') ?: []; |
||||
|
if (!$controller) { |
||||
|
$controllerDir = $moduleDir . Config::get('url_controller_layer') . DS; |
||||
|
$files = new \RecursiveIteratorIterator( |
||||
|
new \RecursiveDirectoryIterator($controllerDir), |
||||
|
\RecursiveIteratorIterator::LEAVES_ONLY |
||||
|
); |
||||
|
|
||||
|
foreach ($files as $name => $file) { |
||||
|
if (!$file->isDir() && $file->getExtension() == 'php') { |
||||
|
$filePath = $file->getRealPath(); |
||||
|
$classes[] = $this->get_class_from_file($filePath); |
||||
|
} |
||||
|
} |
||||
|
} else { |
||||
|
foreach ($controller as $index => $item) { |
||||
|
$filePath = $moduleDir . Config::get('url_controller_layer') . DS . $item . '.php'; |
||||
|
$classes[] = $this->get_class_from_file($filePath); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$classes = array_unique(array_filter($classes)); |
||||
|
|
||||
|
$config = [ |
||||
|
'sitename' => config('site.name'), |
||||
|
'title' => $title, |
||||
|
'author' => config('site.name'), |
||||
|
'description' => '', |
||||
|
'apiurl' => $url, |
||||
|
'language' => $language, |
||||
|
]; |
||||
|
|
||||
|
$builder = new Builder($classes); |
||||
|
$content = $builder->render($template_file, ['config' => $config, 'lang' => $lang]); |
||||
|
|
||||
|
if (!file_put_contents($output_file, $content)) { |
||||
|
throw new Exception('Cannot save the content to ' . $output_file); |
||||
|
} |
||||
|
$output->info("Build Successed!"); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* get full qualified class name |
||||
|
* |
||||
|
* @param string $path_to_file |
||||
|
* @return string |
||||
|
* @author JBYRNE http://jarretbyrne.com/2015/06/197/ |
||||
|
*/ |
||||
|
protected function get_class_from_file($path_to_file) |
||||
|
{ |
||||
|
//Grab the contents of the file |
||||
|
$contents = file_get_contents($path_to_file); |
||||
|
|
||||
|
//Start with a blank namespace and class |
||||
|
$namespace = $class = ""; |
||||
|
|
||||
|
//Set helper values to know that we have found the namespace/class token and need to collect the string values after them |
||||
|
$getting_namespace = $getting_class = false; |
||||
|
|
||||
|
//Go through each token and evaluate it as necessary |
||||
|
foreach (token_get_all($contents) as $token) { |
||||
|
|
||||
|
//If this token is the namespace declaring, then flag that the next tokens will be the namespace name |
||||
|
if (is_array($token) && $token[0] == T_NAMESPACE) { |
||||
|
$getting_namespace = true; |
||||
|
} |
||||
|
|
||||
|
//If this token is the class declaring, then flag that the next tokens will be the class name |
||||
|
if (is_array($token) && $token[0] == T_CLASS) { |
||||
|
$getting_class = true; |
||||
|
} |
||||
|
|
||||
|
//While we're grabbing the namespace name... |
||||
|
if ($getting_namespace === true) { |
||||
|
|
||||
|
//If the token is a string or the namespace separator... |
||||
|
if (is_array($token) && in_array($token[0], [T_STRING, T_NS_SEPARATOR])) { |
||||
|
|
||||
|
//Append the token's value to the name of the namespace |
||||
|
$namespace .= $token[1]; |
||||
|
} elseif ($token === ';') { |
||||
|
|
||||
|
//If the token is the semicolon, then we're done with the namespace declaration |
||||
|
$getting_namespace = false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//While we're grabbing the class name... |
||||
|
if ($getting_class === true) { |
||||
|
|
||||
|
//If the token is a string, it's the name of the class |
||||
|
if (is_array($token) && $token[0] == T_STRING) { |
||||
|
|
||||
|
//Store the token's value as the class name |
||||
|
$class = $token[1]; |
||||
|
|
||||
|
//Got what we need, stope here |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//Build the fully-qualified class name and return it |
||||
|
return $namespace ? $namespace . '\\' . $class : $class; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
<?php |
||||
|
|
||||
|
return [ |
||||
|
'Info' => '基础信息', |
||||
|
'Sandbox' => '在线测试', |
||||
|
'Sampleoutput' => '返回示例', |
||||
|
'Headers' => 'Headers', |
||||
|
'Parameters' => '参数', |
||||
|
'Body' => '正文', |
||||
|
'Name' => '名称', |
||||
|
'Type' => '类型', |
||||
|
'Required' => '必选', |
||||
|
'Description' => '描述', |
||||
|
'Send' => '提交', |
||||
|
'Reset' => '重置', |
||||
|
'Tokentips' => 'Token在会员注册或登录后都会返回,WEB端同时存在于Cookie中', |
||||
|
'Apiurltips' => 'API接口URL', |
||||
|
'Savetips' => '点击保存后Token和Api url都将保存在本地Localstorage中', |
||||
|
'Authorization' => '权限', |
||||
|
'NeedLogin' => '登录', |
||||
|
'NeedRight' => '鉴权', |
||||
|
'ReturnHeaders' => '响应头', |
||||
|
'ReturnParameters' => '返回参数', |
||||
|
'Response' => '响应输出', |
||||
|
]; |
||||
@ -0,0 +1,253 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\command\Api\library; |
||||
|
|
||||
|
use think\Config; |
||||
|
|
||||
|
/** |
||||
|
* @website https://github.com/calinrada/php-apidoc |
||||
|
* @author Calin Rada <rada.calin@gmail.com> |
||||
|
* @author Karson <karson@fastadmin.net> |
||||
|
*/ |
||||
|
class Builder |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @var \think\View |
||||
|
*/ |
||||
|
public $view = null; |
||||
|
|
||||
|
/** |
||||
|
* parse classes |
||||
|
* @var array |
||||
|
*/ |
||||
|
protected $classes = []; |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @param array $classes |
||||
|
*/ |
||||
|
public function __construct($classes = []) |
||||
|
{ |
||||
|
$this->classes = array_merge($this->classes, $classes); |
||||
|
$this->view = new \think\View(Config::get('template'), Config::get('view_replace_str')); |
||||
|
} |
||||
|
|
||||
|
protected function extractAnnotations() |
||||
|
{ |
||||
|
foreach ($this->classes as $class) { |
||||
|
$classAnnotation = Extractor::getClassAnnotations($class); |
||||
|
// 如果忽略 |
||||
|
if (isset($classAnnotation['ApiInternal'])) { |
||||
|
continue; |
||||
|
} |
||||
|
Extractor::getClassMethodAnnotations($class); |
||||
|
//Extractor::getClassPropertyValues($class); |
||||
|
} |
||||
|
$allClassAnnotation = Extractor::getAllClassAnnotations(); |
||||
|
$allClassMethodAnnotation = Extractor::getAllClassMethodAnnotations(); |
||||
|
//$allClassPropertyValue = Extractor::getAllClassPropertyValues(); |
||||
|
|
||||
|
// foreach ($allClassMethodAnnotation as $className => &$methods) { |
||||
|
// foreach ($methods as &$method) { |
||||
|
// //权重判断 |
||||
|
// if ($method && !isset($method['ApiWeigh']) && isset($allClassAnnotation[$className]['ApiWeigh'])) { |
||||
|
// $method['ApiWeigh'] = $allClassAnnotation[$className]['ApiWeigh']; |
||||
|
// } |
||||
|
// } |
||||
|
// } |
||||
|
// unset($methods); |
||||
|
return [$allClassAnnotation, $allClassMethodAnnotation]; |
||||
|
} |
||||
|
|
||||
|
protected function generateHeadersTemplate($docs) |
||||
|
{ |
||||
|
if (!isset($docs['ApiHeaders'])) { |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
$headerslist = array(); |
||||
|
foreach ($docs['ApiHeaders'] as $params) { |
||||
|
$tr = array( |
||||
|
'name' => $params['name'] ?? '', |
||||
|
'type' => $params['type'] ?? 'string', |
||||
|
'sample' => $params['sample'] ?? '', |
||||
|
'required' => $params['required'] ?? false, |
||||
|
'description' => $params['description'] ?? '', |
||||
|
); |
||||
|
$headerslist[] = $tr; |
||||
|
} |
||||
|
|
||||
|
return $headerslist; |
||||
|
} |
||||
|
|
||||
|
protected function generateParamsTemplate($docs) |
||||
|
{ |
||||
|
if (!isset($docs['ApiParams'])) { |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
$paramslist = array(); |
||||
|
foreach ($docs['ApiParams'] as $params) { |
||||
|
$tr = array( |
||||
|
'name' => $params['name'], |
||||
|
'type' => $params['type'] ?? 'string', |
||||
|
'sample' => $params['sample'] ?? '', |
||||
|
'required' => $params['required'] ?? true, |
||||
|
'description' => $params['description'] ?? '', |
||||
|
); |
||||
|
$paramslist[] = $tr; |
||||
|
} |
||||
|
|
||||
|
return $paramslist; |
||||
|
} |
||||
|
|
||||
|
protected function generateReturnHeadersTemplate($docs) |
||||
|
{ |
||||
|
if (!isset($docs['ApiReturnHeaders'])) { |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
$headerslist = array(); |
||||
|
foreach ($docs['ApiReturnHeaders'] as $params) { |
||||
|
$tr = array( |
||||
|
'name' => $params['name'] ?? '', |
||||
|
'type' => 'string', |
||||
|
'sample' => $params['sample'] ?? '', |
||||
|
'required' => isset($params['required']) && $params['required'] ? 'Yes' : 'No', |
||||
|
'description' => $params['description'] ?? '', |
||||
|
); |
||||
|
$headerslist[] = $tr; |
||||
|
} |
||||
|
|
||||
|
return $headerslist; |
||||
|
} |
||||
|
|
||||
|
protected function generateReturnParamsTemplate($st_params) |
||||
|
{ |
||||
|
if (!isset($st_params['ApiReturnParams'])) { |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
$paramslist = array(); |
||||
|
foreach ($st_params['ApiReturnParams'] as $params) { |
||||
|
$tr = array( |
||||
|
'name' => $params['name'] ?? '', |
||||
|
'type' => $params['type'] ?? 'string', |
||||
|
'sample' => $params['sample'] ?? '', |
||||
|
'description' => $params['description'] ?? '', |
||||
|
); |
||||
|
$paramslist[] = $tr; |
||||
|
} |
||||
|
|
||||
|
return $paramslist; |
||||
|
} |
||||
|
|
||||
|
protected function generateBadgeForMethod($data) |
||||
|
{ |
||||
|
$method = strtoupper(is_array($data['ApiMethod'][0]) ? $data['ApiMethod'][0]['data'] : $data['ApiMethod'][0]); |
||||
|
$labes = array( |
||||
|
'POST' => 'label-primary', |
||||
|
'GET' => 'label-success', |
||||
|
'PUT' => 'label-warning', |
||||
|
'DELETE' => 'label-danger', |
||||
|
'PATCH' => 'label-default', |
||||
|
'OPTIONS' => 'label-info' |
||||
|
); |
||||
|
|
||||
|
return isset($labes[$method]) ? $labes[$method] : $labes['GET']; |
||||
|
} |
||||
|
|
||||
|
public function parse() |
||||
|
{ |
||||
|
list($allClassAnnotations, $allClassMethodAnnotations) = $this->extractAnnotations(); |
||||
|
|
||||
|
$sectorArr = []; |
||||
|
foreach ($allClassAnnotations as $index => &$allClassAnnotation) { |
||||
|
// 如果设置隐藏,则不显示在文档 |
||||
|
if (isset($allClassAnnotation['ApiInternal'])) { |
||||
|
continue; |
||||
|
} |
||||
|
$sector = isset($allClassAnnotation['ApiSector']) ? $allClassAnnotation['ApiSector'][0] : $allClassAnnotation['ApiTitle'][0]; |
||||
|
$sectorArr[$sector] = isset($allClassAnnotation['ApiWeigh']) ? $allClassAnnotation['ApiWeigh'][0] : 0; |
||||
|
} |
||||
|
unset($allClassAnnotation); |
||||
|
|
||||
|
arsort($sectorArr); |
||||
|
$routes = include_once CONF_PATH . 'route.php'; |
||||
|
$subdomain = false; |
||||
|
if (config('url_domain_deploy') && isset($routes['__domain__']) && isset($routes['__domain__']['api']) && $routes['__domain__']['api']) { |
||||
|
$subdomain = true; |
||||
|
} |
||||
|
$counter = 0; |
||||
|
$section = null; |
||||
|
$weigh = 0; |
||||
|
$docsList = []; |
||||
|
foreach ($allClassMethodAnnotations as $class => $methods) { |
||||
|
foreach ($methods as $name => $docs) { |
||||
|
if (isset($docs['ApiSector'][0])) { |
||||
|
$section = is_array($docs['ApiSector'][0]) ? $docs['ApiSector'][0]['data'] : $docs['ApiSector'][0]; |
||||
|
} else { |
||||
|
$section = $class; |
||||
|
} |
||||
|
if (0 === count($docs)) { |
||||
|
continue; |
||||
|
} |
||||
|
$route = is_array($docs['ApiRoute'][0]) ? $docs['ApiRoute'][0]['data'] : $docs['ApiRoute'][0]; |
||||
|
if ($subdomain) { |
||||
|
$route = substr($route, 4); |
||||
|
} |
||||
|
$docsList[$section][$name] = [ |
||||
|
'id' => $counter, |
||||
|
'method' => is_array($docs['ApiMethod'][0]) ? $docs['ApiMethod'][0]['data'] : $docs['ApiMethod'][0], |
||||
|
'methodLabel' => $this->generateBadgeForMethod($docs), |
||||
|
'section' => $section, |
||||
|
'route' => $route, |
||||
|
'title' => is_array($docs['ApiTitle'][0]) ? $docs['ApiTitle'][0]['data'] : $docs['ApiTitle'][0], |
||||
|
'summary' => is_array($docs['ApiSummary'][0]) ? $docs['ApiSummary'][0]['data'] : $docs['ApiSummary'][0], |
||||
|
'body' => isset($docs['ApiBody'][0]) ? (is_array($docs['ApiBody'][0]) ? $docs['ApiBody'][0]['data'] : $docs['ApiBody'][0]) : '', |
||||
|
'headersList' => $this->generateHeadersTemplate($docs), |
||||
|
'paramsList' => $this->generateParamsTemplate($docs), |
||||
|
'returnHeadersList' => $this->generateReturnHeadersTemplate($docs), |
||||
|
'returnParamsList' => $this->generateReturnParamsTemplate($docs), |
||||
|
'weigh' => is_array($docs['ApiWeigh'][0]) ? $docs['ApiWeigh'][0]['data'] : $docs['ApiWeigh'][0], |
||||
|
'return' => isset($docs['ApiReturn']) ? (is_array($docs['ApiReturn'][0]) ? $docs['ApiReturn'][0]['data'] : $docs['ApiReturn'][0]) : '', |
||||
|
'needLogin' => $docs['ApiPermissionLogin'][0], |
||||
|
'needRight' => $docs['ApiPermissionRight'][0], |
||||
|
]; |
||||
|
$counter++; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//重建排序 |
||||
|
foreach ($docsList as $index => &$methods) { |
||||
|
$methodSectorArr = []; |
||||
|
foreach ($methods as $name => $method) { |
||||
|
$methodSectorArr[$name] = isset($method['weigh']) ? $method['weigh'] : 0; |
||||
|
} |
||||
|
arsort($methodSectorArr); |
||||
|
$methods = array_merge(array_flip(array_keys($methodSectorArr)), $methods); |
||||
|
} |
||||
|
$docsList = array_merge(array_flip(array_keys($sectorArr)), $docsList); |
||||
|
return $docsList; |
||||
|
} |
||||
|
|
||||
|
public function getView() |
||||
|
{ |
||||
|
return $this->view; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 渲染 |
||||
|
* @param string $template |
||||
|
* @param array $vars |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function render($template, $vars = []) |
||||
|
{ |
||||
|
$docsList = $this->parse(); |
||||
|
|
||||
|
return $this->view->display(file_get_contents($template), array_merge($vars, ['docsList' => $docsList])); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,544 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\command\Api\library; |
||||
|
|
||||
|
use Exception; |
||||
|
|
||||
|
/** |
||||
|
* Class imported from https://github.com/eriknyk/Annotations |
||||
|
* @author Erik Amaru Ortiz https://github.com/eriknyk |
||||
|
* |
||||
|
* @license http://opensource.org/licenses/bsd-license.php The BSD License |
||||
|
* @author Calin Rada <rada.calin@gmail.com> |
||||
|
*/ |
||||
|
class Extractor |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* Static array to store already parsed annotations |
||||
|
* @var array |
||||
|
*/ |
||||
|
private static $annotationCache; |
||||
|
|
||||
|
private static $classAnnotationCache; |
||||
|
|
||||
|
private static $classMethodAnnotationCache; |
||||
|
|
||||
|
private static $classPropertyValueCache; |
||||
|
|
||||
|
/** |
||||
|
* Indicates that annotations should has strict behavior, 'false' by default |
||||
|
* @var boolean |
||||
|
*/ |
||||
|
private $strict = false; |
||||
|
|
||||
|
/** |
||||
|
* Stores the default namespace for Objects instance, usually used on methods like getMethodAnnotationsObjects() |
||||
|
* @var string |
||||
|
*/ |
||||
|
public $defaultNamespace = ''; |
||||
|
|
||||
|
/** |
||||
|
* Sets strict variable to true/false |
||||
|
* @param bool $value boolean value to indicate that annotations to has strict behavior |
||||
|
*/ |
||||
|
public function setStrict($value) |
||||
|
{ |
||||
|
$this->strict = (bool)$value; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Sets default namespace to use in object instantiation |
||||
|
* @param string $namespace default namespace |
||||
|
*/ |
||||
|
public function setDefaultNamespace($namespace) |
||||
|
{ |
||||
|
$this->defaultNamespace = $namespace; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Gets default namespace used in object instantiation |
||||
|
* @return string $namespace default namespace |
||||
|
*/ |
||||
|
public function getDefaultAnnotationNamespace() |
||||
|
{ |
||||
|
return $this->defaultNamespace; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Gets all anotations with pattern @SomeAnnotation() from a given class |
||||
|
* |
||||
|
* @param string $className class name to get annotations |
||||
|
* @return array self::$classAnnotationCache all annotated elements |
||||
|
*/ |
||||
|
public static function getClassAnnotations($className) |
||||
|
{ |
||||
|
if (!isset(self::$classAnnotationCache[$className])) { |
||||
|
$class = new \ReflectionClass($className); |
||||
|
$annotationArr = self::parseAnnotations($class->getDocComment()); |
||||
|
$annotationArr['ApiTitle'] = !isset($annotationArr['ApiTitle'][0]) || !trim($annotationArr['ApiTitle'][0]) ? [$class->getShortName()] : $annotationArr['ApiTitle']; |
||||
|
self::$classAnnotationCache[$className] = $annotationArr; |
||||
|
} |
||||
|
|
||||
|
return self::$classAnnotationCache[$className]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取类所有方法的属性配置 |
||||
|
* @param $className |
||||
|
* @return mixed |
||||
|
* @throws \ReflectionException |
||||
|
*/ |
||||
|
public static function getClassMethodAnnotations($className) |
||||
|
{ |
||||
|
$class = new \ReflectionClass($className); |
||||
|
|
||||
|
foreach ($class->getMethods() as $object) { |
||||
|
self::$classMethodAnnotationCache[$className][$object->name] = self::getMethodAnnotations($className, $object->name); |
||||
|
} |
||||
|
|
||||
|
return self::$classMethodAnnotationCache[$className]; |
||||
|
} |
||||
|
|
||||
|
public static function getClassPropertyValues($className) |
||||
|
{ |
||||
|
$class = new \ReflectionClass($className); |
||||
|
|
||||
|
foreach ($class->getProperties() as $object) { |
||||
|
self::$classPropertyValueCache[$className][$object->name] = self::getClassPropertyValue($className, $object->name); |
||||
|
} |
||||
|
|
||||
|
return self::$classMethodAnnotationCache[$className]; |
||||
|
} |
||||
|
|
||||
|
public static function getAllClassAnnotations() |
||||
|
{ |
||||
|
return self::$classAnnotationCache; |
||||
|
} |
||||
|
|
||||
|
public static function getAllClassMethodAnnotations() |
||||
|
{ |
||||
|
return self::$classMethodAnnotationCache; |
||||
|
} |
||||
|
|
||||
|
public static function getAllClassPropertyValues() |
||||
|
{ |
||||
|
return self::$classPropertyValueCache; |
||||
|
} |
||||
|
|
||||
|
public static function getClassPropertyValue($className, $property) |
||||
|
{ |
||||
|
$_SERVER['REQUEST_METHOD'] = 'GET'; |
||||
|
$reflectionClass = new \ReflectionClass($className); |
||||
|
$reflectionProperty = $reflectionClass->getProperty($property); |
||||
|
$reflectionProperty->setAccessible(true); |
||||
|
return $reflectionProperty->getValue($reflectionClass->newInstanceWithoutConstructor()); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Gets all anotations with pattern @SomeAnnotation() from a determinated method of a given class |
||||
|
* |
||||
|
* @param string $className class name |
||||
|
* @param string $methodName method name to get annotations |
||||
|
* @return array self::$annotationCache all annotated elements of a method given |
||||
|
*/ |
||||
|
public static function getMethodAnnotations($className, $methodName) |
||||
|
{ |
||||
|
if (!isset(self::$annotationCache[$className . '::' . $methodName])) { |
||||
|
try { |
||||
|
$method = new \ReflectionMethod($className, $methodName); |
||||
|
$class = new \ReflectionClass($className); |
||||
|
if (!$method->isPublic() || $method->isConstructor()) { |
||||
|
$annotations = array(); |
||||
|
} else { |
||||
|
$annotations = self::consolidateAnnotations($method, $class); |
||||
|
} |
||||
|
} catch (\ReflectionException $e) { |
||||
|
$annotations = array(); |
||||
|
} |
||||
|
|
||||
|
self::$annotationCache[$className . '::' . $methodName] = $annotations; |
||||
|
} |
||||
|
|
||||
|
return self::$annotationCache[$className . '::' . $methodName]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Gets all anotations with pattern @SomeAnnotation() from a determinated method of a given class |
||||
|
* and instance its abcAnnotation class |
||||
|
* |
||||
|
* @param string $className class name |
||||
|
* @param string $methodName method name to get annotations |
||||
|
* @return array self::$annotationCache all annotated objects of a method given |
||||
|
*/ |
||||
|
public function getMethodAnnotationsObjects($className, $methodName) |
||||
|
{ |
||||
|
$annotations = $this->getMethodAnnotations($className, $methodName); |
||||
|
$objects = array(); |
||||
|
|
||||
|
$i = 0; |
||||
|
|
||||
|
foreach ($annotations as $annotationClass => $listParams) { |
||||
|
$annotationClass = ucfirst($annotationClass); |
||||
|
$class = $this->defaultNamespace . $annotationClass . 'Annotation'; |
||||
|
|
||||
|
// verify is the annotation class exists, depending if Annotations::strict is true |
||||
|
// if not, just skip the annotation instance creation. |
||||
|
if (!class_exists($class)) { |
||||
|
if ($this->strict) { |
||||
|
throw new Exception(sprintf('Runtime Error: Annotation Class Not Found: %s', $class)); |
||||
|
} else { |
||||
|
// silent skip & continue |
||||
|
continue; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (empty($objects[$annotationClass])) { |
||||
|
$objects[$annotationClass] = new $class(); |
||||
|
} |
||||
|
|
||||
|
foreach ($listParams as $params) { |
||||
|
if (is_array($params)) { |
||||
|
foreach ($params as $key => $value) { |
||||
|
$objects[$annotationClass]->set($key, $value); |
||||
|
} |
||||
|
} else { |
||||
|
$objects[$annotationClass]->set($i++, $params); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $objects; |
||||
|
} |
||||
|
|
||||
|
private static function consolidateAnnotations($method, $class) |
||||
|
{ |
||||
|
$dockblockClass = $class->getDocComment(); |
||||
|
$docblockMethod = $method->getDocComment(); |
||||
|
$methodName = $method->getName(); |
||||
|
|
||||
|
$methodAnnotations = self::parseAnnotations($docblockMethod); |
||||
|
$methodAnnotations['ApiTitle'] = !isset($methodAnnotations['ApiTitle'][0]) || !trim($methodAnnotations['ApiTitle'][0]) ? [$method->getName()] : $methodAnnotations['ApiTitle']; |
||||
|
|
||||
|
$classAnnotations = self::parseAnnotations($dockblockClass); |
||||
|
$classAnnotations['ApiTitle'] = !isset($classAnnotations['ApiTitle'][0]) || !trim($classAnnotations['ApiTitle'][0]) ? [$class->getShortName()] : $classAnnotations['ApiTitle']; |
||||
|
|
||||
|
if (isset($methodAnnotations['ApiInternal']) || $methodName == '_initialize' || $methodName == '_empty') { |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
$properties = $class->getDefaultProperties(); |
||||
|
$noNeedLogin = isset($properties['noNeedLogin']) ? (is_array($properties['noNeedLogin']) ? $properties['noNeedLogin'] : [$properties['noNeedLogin']]) : []; |
||||
|
$noNeedRight = isset($properties['noNeedRight']) ? (is_array($properties['noNeedRight']) ? $properties['noNeedRight'] : [$properties['noNeedRight']]) : []; |
||||
|
|
||||
|
preg_match_all("/\*[\s]+(.*)(\\r\\n|\\r|\\n)/U", str_replace('/**', '', $docblockMethod), $methodArr); |
||||
|
preg_match_all("/\*[\s]+(.*)(\\r\\n|\\r|\\n)/U", str_replace('/**', '', $dockblockClass), $classArr); |
||||
|
|
||||
|
if (!isset($methodAnnotations['ApiMethod'])) { |
||||
|
$methodAnnotations['ApiMethod'] = ['get']; |
||||
|
} |
||||
|
if (!isset($methodAnnotations['ApiWeigh'])) { |
||||
|
$methodAnnotations['ApiWeigh'] = [0]; |
||||
|
} |
||||
|
if (!isset($methodAnnotations['ApiSummary'])) { |
||||
|
$methodAnnotations['ApiSummary'] = $methodAnnotations['ApiTitle']; |
||||
|
} |
||||
|
|
||||
|
if ($methodAnnotations) { |
||||
|
foreach ($classAnnotations as $name => $valueClass) { |
||||
|
if (count($valueClass) !== 1) { |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if ($name === 'ApiRoute') { |
||||
|
if (isset($methodAnnotations[$name])) { |
||||
|
$methodAnnotations[$name] = [rtrim($valueClass[0], '/') . $methodAnnotations[$name][0]]; |
||||
|
} else { |
||||
|
$methodAnnotations[$name] = [rtrim($valueClass[0], '/') . '/' . $method->getName()]; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if ($name === 'ApiSector') { |
||||
|
$methodAnnotations[$name] = $valueClass; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
if (!isset($methodAnnotations['ApiRoute'])) { |
||||
|
$urlArr = []; |
||||
|
$className = $class->getName(); |
||||
|
|
||||
|
list($prefix, $suffix) = explode('\\' . \think\Config::get('url_controller_layer') . '\\', $className); |
||||
|
$prefixArr = explode('\\', $prefix); |
||||
|
$suffixArr = explode('\\', $suffix); |
||||
|
if ($prefixArr[0] == \think\Config::get('app_namespace')) { |
||||
|
$prefixArr[0] = ''; |
||||
|
} |
||||
|
$urlArr = array_merge($urlArr, $prefixArr); |
||||
|
$urlArr[] = implode('.', array_map(function ($item) { |
||||
|
return \think\Loader::parseName($item); |
||||
|
}, $suffixArr)); |
||||
|
$urlArr[] = $method->getName(); |
||||
|
|
||||
|
$methodAnnotations['ApiRoute'] = [implode('/', $urlArr)]; |
||||
|
} |
||||
|
if (!isset($methodAnnotations['ApiSector'])) { |
||||
|
$methodAnnotations['ApiSector'] = isset($classAnnotations['ApiSector']) ? $classAnnotations['ApiSector'] : $classAnnotations['ApiTitle']; |
||||
|
} |
||||
|
if (!isset($methodAnnotations['ApiParams'])) { |
||||
|
$params = self::parseCustomAnnotations($docblockMethod, 'param'); |
||||
|
foreach ($params as $k => $v) { |
||||
|
$arr = explode(' ', preg_replace("/[\s]+/", " ", $v)); |
||||
|
$methodAnnotations['ApiParams'][] = [ |
||||
|
'name' => isset($arr[1]) ? str_replace('$', '', $arr[1]) : '', |
||||
|
'nullable' => false, |
||||
|
'type' => isset($arr[0]) ? $arr[0] : 'string', |
||||
|
'description' => isset($arr[2]) ? $arr[2] : '' |
||||
|
]; |
||||
|
} |
||||
|
} |
||||
|
$methodAnnotations['ApiPermissionLogin'] = [!in_array('*', $noNeedLogin) && !in_array($methodName, $noNeedLogin)]; |
||||
|
$methodAnnotations['ApiPermissionRight'] = !$methodAnnotations['ApiPermissionLogin'][0] ? [false] : [!in_array('*', $noNeedRight) && !in_array($methodName, $noNeedRight)]; |
||||
|
return $methodAnnotations; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Parse annotations |
||||
|
* |
||||
|
* @param string $docblock |
||||
|
* @param string $name |
||||
|
* @return array parsed annotations params |
||||
|
*/ |
||||
|
private static function parseCustomAnnotations($docblock, $name = 'param') |
||||
|
{ |
||||
|
$annotations = array(); |
||||
|
|
||||
|
$docblock = substr($docblock, 3, -2); |
||||
|
if (preg_match_all('/@' . $name . '(?:\s*(?:\(\s*)?(.*?)(?:\s*\))?)??\s*(?:\n|\*\/)/', $docblock, $matches)) { |
||||
|
foreach ($matches[1] as $k => $v) { |
||||
|
$annotations[] = $v; |
||||
|
} |
||||
|
} |
||||
|
return $annotations; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Parse annotations |
||||
|
* |
||||
|
* @param string $docblock |
||||
|
* @return array parsed annotations params |
||||
|
*/ |
||||
|
private static function parseAnnotations($docblock) |
||||
|
{ |
||||
|
$annotations = array(); |
||||
|
|
||||
|
// Strip away the docblock header and footer to ease parsing of one line annotations |
||||
|
$docblock = substr($docblock, 3, -2); |
||||
|
if (preg_match_all('/@(?<name>[A-Za-z_-]+)[\s\t]*\((?<args>(?:(?!\)).)*)\)\r?/s', $docblock, $matches)) { |
||||
|
$numMatches = count($matches[0]); |
||||
|
for ($i = 0; $i < $numMatches; ++$i) { |
||||
|
$name = $matches['name'][$i]; |
||||
|
$value = ''; |
||||
|
// annotations has arguments |
||||
|
if (isset($matches['args'][$i])) { |
||||
|
$argsParts = trim($matches['args'][$i]); |
||||
|
if ($name == 'ApiReturn') { |
||||
|
$value = $argsParts; |
||||
|
} elseif ($matches['args'][$i] != '') { |
||||
|
$argsParts = preg_replace("/\{(\w+)\}/", '#$1#', $argsParts); |
||||
|
$value = self::parseArgs($argsParts); |
||||
|
if (is_string($value)) { |
||||
|
$value = preg_replace("/\#(\w+)\#/", '{$1}', $argsParts); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$annotations[$name][] = $value; |
||||
|
} |
||||
|
} |
||||
|
if (stripos($docblock, '@ApiInternal') !== false) { |
||||
|
$annotations['ApiInternal'] = [true]; |
||||
|
} |
||||
|
if (!isset($annotations['ApiTitle'])) { |
||||
|
preg_match_all("/\*[\s]+(.*)(\\r\\n|\\r|\\n)/U", str_replace('/**', '', $docblock), $matchArr); |
||||
|
$title = isset($matchArr[1]) && isset($matchArr[1][0]) ? $matchArr[1][0] : ''; |
||||
|
$annotations['ApiTitle'] = [$title]; |
||||
|
} |
||||
|
|
||||
|
return $annotations; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Parse individual annotation arguments |
||||
|
* |
||||
|
* @param string $content arguments string |
||||
|
* @return array annotated arguments |
||||
|
*/ |
||||
|
private static function parseArgs($content) |
||||
|
{ |
||||
|
// Replace initial stars |
||||
|
$content = preg_replace('/^\s*\*/m', '', $content); |
||||
|
|
||||
|
$data = array(); |
||||
|
$len = strlen($content); |
||||
|
$i = 0; |
||||
|
$var = ''; |
||||
|
$val = ''; |
||||
|
$level = 1; |
||||
|
|
||||
|
$prevDelimiter = ''; |
||||
|
$nextDelimiter = ''; |
||||
|
$nextToken = ''; |
||||
|
$composing = false; |
||||
|
$type = 'plain'; |
||||
|
$delimiter = null; |
||||
|
$quoted = false; |
||||
|
$tokens = array('"', '"', '{', '}', ',', '='); |
||||
|
|
||||
|
while ($i <= $len) { |
||||
|
$prev_c = substr($content, $i - 1, 1); |
||||
|
$c = substr($content, $i++, 1); |
||||
|
|
||||
|
if ($c === '"' && $prev_c !== "\\") { |
||||
|
$delimiter = $c; |
||||
|
//open delimiter |
||||
|
if (!$composing && empty($prevDelimiter) && empty($nextDelimiter)) { |
||||
|
$prevDelimiter = $nextDelimiter = $delimiter; |
||||
|
$val = ''; |
||||
|
$composing = true; |
||||
|
$quoted = true; |
||||
|
} else { |
||||
|
// close delimiter |
||||
|
if ($c !== $nextDelimiter) { |
||||
|
throw new Exception(sprintf( |
||||
|
"Parse Error: enclosing error -> expected: [%s], given: [%s]", |
||||
|
$nextDelimiter, |
||||
|
$c |
||||
|
)); |
||||
|
} |
||||
|
|
||||
|
// validating syntax |
||||
|
if ($i < $len) { |
||||
|
if (',' !== substr($content, $i, 1) && '\\' !== $prev_c) { |
||||
|
throw new Exception(sprintf( |
||||
|
"Parse Error: missing comma separator near: ...%s<--", |
||||
|
substr($content, ($i - 10), $i) |
||||
|
)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$prevDelimiter = $nextDelimiter = ''; |
||||
|
$composing = false; |
||||
|
$delimiter = null; |
||||
|
} |
||||
|
} elseif (!$composing && in_array($c, $tokens)) { |
||||
|
switch ($c) { |
||||
|
case '=': |
||||
|
$prevDelimiter = $nextDelimiter = ''; |
||||
|
$level = 2; |
||||
|
$composing = false; |
||||
|
$type = 'assoc'; |
||||
|
$quoted = false; |
||||
|
break; |
||||
|
case ',': |
||||
|
$level = 3; |
||||
|
|
||||
|
// If composing flag is true yet, |
||||
|
// it means that the string was not enclosed, so it is parsing error. |
||||
|
if ($composing === true && !empty($prevDelimiter) && !empty($nextDelimiter)) { |
||||
|
throw new Exception(sprintf( |
||||
|
"Parse Error: enclosing error -> expected: [%s], given: [%s]", |
||||
|
$nextDelimiter, |
||||
|
$c |
||||
|
)); |
||||
|
} |
||||
|
|
||||
|
$prevDelimiter = $nextDelimiter = ''; |
||||
|
break; |
||||
|
case '{': |
||||
|
$subc = ''; |
||||
|
$subComposing = true; |
||||
|
|
||||
|
while ($i <= $len) { |
||||
|
$c = substr($content, $i++, 1); |
||||
|
|
||||
|
if (isset($delimiter) && $c === $delimiter) { |
||||
|
throw new Exception(sprintf( |
||||
|
"Parse Error: Composite variable is not enclosed correctly." |
||||
|
)); |
||||
|
} |
||||
|
|
||||
|
if ($c === '}') { |
||||
|
$subComposing = false; |
||||
|
break; |
||||
|
} |
||||
|
$subc .= $c; |
||||
|
} |
||||
|
|
||||
|
// if the string is composing yet means that the structure of var. never was enclosed with '}' |
||||
|
if ($subComposing) { |
||||
|
throw new Exception(sprintf( |
||||
|
"Parse Error: Composite variable is not enclosed correctly. near: ...%s'", |
||||
|
$subc |
||||
|
)); |
||||
|
} |
||||
|
|
||||
|
$val = self::parseArgs($subc); |
||||
|
break; |
||||
|
} |
||||
|
} else { |
||||
|
if ($level == 1) { |
||||
|
$var .= $c; |
||||
|
} elseif ($level == 2) { |
||||
|
$val .= $c; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if ($level === 3 || $i === $len) { |
||||
|
if ($type == 'plain' && $i === $len) { |
||||
|
$data = self::castValue($var); |
||||
|
} else { |
||||
|
$data[trim($var)] = self::castValue($val, !$quoted); |
||||
|
} |
||||
|
|
||||
|
$level = 1; |
||||
|
$var = $val = ''; |
||||
|
$composing = false; |
||||
|
$quoted = false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $data; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Try determinate the original type variable of a string |
||||
|
* |
||||
|
* @param string $val string containing possibles variables that can be cast to bool or int |
||||
|
* @param boolean $trim indicate if the value passed should be trimmed after to try cast |
||||
|
* @return mixed returns the value converted to original type if was possible |
||||
|
*/ |
||||
|
private static function castValue($val, $trim = false) |
||||
|
{ |
||||
|
if (is_array($val)) { |
||||
|
foreach ($val as $key => $value) { |
||||
|
$val[$key] = self::castValue($value); |
||||
|
} |
||||
|
} elseif (is_string($val)) { |
||||
|
if ($trim) { |
||||
|
$val = trim($val); |
||||
|
} |
||||
|
$val = stripslashes($val); |
||||
|
$tmp = strtolower($val); |
||||
|
|
||||
|
if ($tmp === 'false' || $tmp === 'true') { |
||||
|
$val = $tmp === 'true'; |
||||
|
} elseif (is_numeric($val)) { |
||||
|
return $val + 0; |
||||
|
} |
||||
|
|
||||
|
unset($tmp); |
||||
|
} |
||||
|
|
||||
|
return $val; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,654 @@ |
|||||
|
<!DOCTYPE html> |
||||
|
<html> |
||||
|
<head> |
||||
|
<meta charset="utf-8"> |
||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||
|
<meta name="description" content=""> |
||||
|
<title>{$config.title}</title> |
||||
|
|
||||
|
<!-- Bootstrap Core CSS --> |
||||
|
<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> |
||||
|
|
||||
|
<!-- Plugin CSS --> |
||||
|
<link href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> |
||||
|
|
||||
|
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> |
||||
|
<!--[if lt IE 9]> |
||||
|
<script src="https://cdn.staticfile.org/html5shiv/3.7.3/html5shiv.min.js"></script> |
||||
|
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script> |
||||
|
<![endif]--> |
||||
|
|
||||
|
<style type="text/css"> |
||||
|
body { |
||||
|
padding-top: 70px; margin-bottom: 15px; |
||||
|
-webkit-font-smoothing: antialiased; |
||||
|
-moz-osx-font-smoothing: grayscale; |
||||
|
font-family: "Roboto", "SF Pro SC", "SF Pro Display", "SF Pro Icons", "PingFang SC", BlinkMacSystemFont, -apple-system, "Segoe UI", "Microsoft Yahei", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", "Helvetica", "Arial", sans-serif; |
||||
|
font-weight: 400; |
||||
|
} |
||||
|
h2 { font-size: 1.2em; } |
||||
|
hr { margin-top: 10px; } |
||||
|
.tab-pane { padding-top: 10px; } |
||||
|
.mt0 { margin-top: 0px; } |
||||
|
.footer { font-size: 12px; color: #666; } |
||||
|
.docs-list .label { display: inline-block; min-width: 65px; padding: 0.3em 0.6em 0.3em; } |
||||
|
.string { color: green; } |
||||
|
.number { color: darkorange; } |
||||
|
.boolean { color: blue; } |
||||
|
.null { color: magenta; } |
||||
|
.key { color: red; } |
||||
|
.popover { max-width: 400px; max-height: 400px; overflow-y: auto;} |
||||
|
.list-group.panel > .list-group-item { |
||||
|
} |
||||
|
.list-group-item:last-child { |
||||
|
border-radius:0; |
||||
|
} |
||||
|
h4.panel-title a { |
||||
|
font-weight:normal; |
||||
|
font-size:14px; |
||||
|
} |
||||
|
h4.panel-title a .text-muted { |
||||
|
font-size:12px; |
||||
|
font-weight:normal; |
||||
|
font-family: 'Verdana'; |
||||
|
} |
||||
|
#sidebar { |
||||
|
width: 220px; |
||||
|
position: fixed; |
||||
|
margin-left: -240px; |
||||
|
overflow-y:auto; |
||||
|
} |
||||
|
#sidebar > .list-group { |
||||
|
margin-bottom:0; |
||||
|
} |
||||
|
#sidebar > .list-group > a{ |
||||
|
text-indent:0; |
||||
|
} |
||||
|
#sidebar .child > a .tag{ |
||||
|
position: absolute; |
||||
|
right: 10px; |
||||
|
top: 11px; |
||||
|
} |
||||
|
#sidebar .child > a .pull-right{ |
||||
|
margin-left:3px; |
||||
|
} |
||||
|
#sidebar .child { |
||||
|
border:1px solid #ddd; |
||||
|
border-bottom:none; |
||||
|
} |
||||
|
#sidebar .child:last-child { |
||||
|
border-bottom:1px solid #ddd; |
||||
|
} |
||||
|
#sidebar .child > a { |
||||
|
border:0; |
||||
|
min-height: 40px; |
||||
|
} |
||||
|
#sidebar .list-group a.current { |
||||
|
background:#f5f5f5; |
||||
|
} |
||||
|
@media (max-width: 1620px){ |
||||
|
#sidebar { |
||||
|
margin:0; |
||||
|
} |
||||
|
#accordion { |
||||
|
padding-left:235px; |
||||
|
} |
||||
|
} |
||||
|
@media (max-width: 768px){ |
||||
|
#sidebar { |
||||
|
display: none; |
||||
|
} |
||||
|
#accordion { |
||||
|
padding-left:0px; |
||||
|
} |
||||
|
} |
||||
|
.label-primary { |
||||
|
background-color: #248aff; |
||||
|
} |
||||
|
.docs-list .panel .panel-body .table { |
||||
|
margin-bottom: 0; |
||||
|
} |
||||
|
|
||||
|
</style> |
||||
|
</head> |
||||
|
<body> |
||||
|
<!-- Fixed navbar --> |
||||
|
<div class="navbar navbar-default navbar-fixed-top" role="navigation"> |
||||
|
<div class="container"> |
||||
|
<div class="navbar-header"> |
||||
|
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> |
||||
|
<span class="sr-only">Toggle navigation</span> |
||||
|
<span class="icon-bar"></span> |
||||
|
<span class="icon-bar"></span> |
||||
|
<span class="icon-bar"></span> |
||||
|
</button> |
||||
|
<a class="navbar-brand" href="./" target="_blank">{$config.title}</a> |
||||
|
</div> |
||||
|
<div class="navbar-collapse collapse"> |
||||
|
<form class="navbar-form navbar-right"> |
||||
|
<div class="form-group"> |
||||
|
Token: |
||||
|
</div> |
||||
|
<div class="form-group"> |
||||
|
<input type="text" class="form-control input-sm" data-toggle="tooltip" title="{$lang.Tokentips}" placeholder="token" id="token" /> |
||||
|
</div> |
||||
|
<div class="form-group"> |
||||
|
Apiurl: |
||||
|
</div> |
||||
|
<div class="form-group"> |
||||
|
<input id="apiUrl" type="text" class="form-control input-sm" data-toggle="tooltip" title="{$lang.Apiurltips}" placeholder="https://api.mydomain.com" value="{$config.apiurl}" /> |
||||
|
</div> |
||||
|
<div class="form-group"> |
||||
|
<button type="button" class="btn btn-success btn-sm" data-toggle="tooltip" title="{$lang.Savetips}" id="save_data"> |
||||
|
<span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span> |
||||
|
</button> |
||||
|
</div> |
||||
|
</form> |
||||
|
</div><!--/.nav-collapse --> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
<div class="container"> |
||||
|
<!-- menu --> |
||||
|
<div id="sidebar"> |
||||
|
<div class="list-group panel"> |
||||
|
{foreach name="docsList" id="docs"} |
||||
|
<a href="#{$key}" class="list-group-item" data-toggle="collapse" data-parent="#sidebar">{$key} <i class="fa fa-caret-down"></i></a> |
||||
|
<div class="child collapse" id="{$key}"> |
||||
|
{foreach name="docs" id="api" } |
||||
|
<a href="javascript:;" data-id="{$api.id}" class="list-group-item">{$api.title} |
||||
|
<span class="tag"> |
||||
|
{if $api.needRight} |
||||
|
<span class="label label-danger pull-right">鉴</span> |
||||
|
{/if} |
||||
|
{if $api.needLogin} |
||||
|
<span class="label label-success pull-right noneedlogin">登</span> |
||||
|
{/if} |
||||
|
</span> |
||||
|
</a> |
||||
|
{/foreach} |
||||
|
</div> |
||||
|
{/foreach} |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="panel-group docs-list" id="accordion"> |
||||
|
{foreach name="docsList" id="docs"} |
||||
|
<h2>{$key}</h2> |
||||
|
<hr> |
||||
|
{foreach name="docs" id="api" } |
||||
|
<div class="panel panel-default"> |
||||
|
<div class="panel-heading" id="heading-{$api.id}"> |
||||
|
<h4 class="panel-title"> |
||||
|
<span class="label {$api.methodLabel}">{$api.method|strtoupper}</span> |
||||
|
<a data-toggle="collapse" data-parent="#accordion{$api.id}" href="#collapseOne{$api.id}"> {$api.title} <span class="text-muted">{$api.route}</span></a> |
||||
|
</h4> |
||||
|
</div> |
||||
|
<div id="collapseOne{$api.id}" class="panel-collapse collapse"> |
||||
|
<div class="panel-body"> |
||||
|
|
||||
|
<!-- Nav tabs --> |
||||
|
<ul class="nav nav-tabs" id="doctab{$api.id}"> |
||||
|
<li class="active"><a href="#info{$api.id}" data-toggle="tab">{$lang.Info}</a></li> |
||||
|
<li><a href="#sandbox{$api.id}" data-toggle="tab">{$lang.Sandbox}</a></li> |
||||
|
<li><a href="#sample{$api.id}" data-toggle="tab">{$lang.Sampleoutput}</a></li> |
||||
|
</ul> |
||||
|
|
||||
|
<!-- Tab panes --> |
||||
|
<div class="tab-content"> |
||||
|
|
||||
|
<div class="tab-pane active" id="info{$api.id}"> |
||||
|
<div class="well"> |
||||
|
{$api.summary} |
||||
|
</div> |
||||
|
<div class="panel panel-default"> |
||||
|
<div class="panel-heading"><strong>{$lang.Authorization}</strong></div> |
||||
|
<div class="panel-body"> |
||||
|
<table class="table table-hover"> |
||||
|
<tbody> |
||||
|
<tr> |
||||
|
<td>{$lang.NeedLogin}</td> |
||||
|
<td>{$api.needLogin?'是':'否'}</td> |
||||
|
</tr> |
||||
|
<tr> |
||||
|
<td>{$lang.NeedRight}</td> |
||||
|
<td>{$api.needRight?'是':'否'}</td> |
||||
|
</tr> |
||||
|
</tbody> |
||||
|
</table> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="panel panel-default"> |
||||
|
<div class="panel-heading"><strong>{$lang.Headers}</strong></div> |
||||
|
<div class="panel-body"> |
||||
|
{if $api.headersList} |
||||
|
<table class="table table-hover"> |
||||
|
<thead> |
||||
|
<tr> |
||||
|
<th>{$lang.Name}</th> |
||||
|
<th>{$lang.Type}</th> |
||||
|
<th>{$lang.Required}</th> |
||||
|
<th>{$lang.Description}</th> |
||||
|
</tr> |
||||
|
</thead> |
||||
|
<tbody> |
||||
|
{foreach name="api['headersList']" id="header"} |
||||
|
<tr> |
||||
|
<td>{$header.name}</td> |
||||
|
<td>{$header.type}</td> |
||||
|
<td>{$header.required?'是':'否'}</td> |
||||
|
<td>{$header.description}</td> |
||||
|
</tr> |
||||
|
{/foreach} |
||||
|
</tbody> |
||||
|
</table> |
||||
|
{else /} |
||||
|
无 |
||||
|
{/if} |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="panel panel-default"> |
||||
|
<div class="panel-heading"><strong>{$lang.Parameters}</strong></div> |
||||
|
<div class="panel-body"> |
||||
|
{if $api.paramsList} |
||||
|
<table class="table table-hover"> |
||||
|
<thead> |
||||
|
<tr> |
||||
|
<th>{$lang.Name}</th> |
||||
|
<th>{$lang.Type}</th> |
||||
|
<th>{$lang.Required}</th> |
||||
|
<th>{$lang.Description}</th> |
||||
|
</tr> |
||||
|
</thead> |
||||
|
<tbody> |
||||
|
{foreach name="api['paramsList']" id="param"} |
||||
|
<tr> |
||||
|
<td>{$param.name}</td> |
||||
|
<td>{$param.type}</td> |
||||
|
<td>{:$param.required?'是':'否'}</td> |
||||
|
<td>{$param.description}</td> |
||||
|
</tr> |
||||
|
{/foreach} |
||||
|
</tbody> |
||||
|
</table> |
||||
|
{else /} |
||||
|
无 |
||||
|
{/if} |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="panel panel-default"> |
||||
|
<div class="panel-heading"><strong>{$lang.Body}</strong></div> |
||||
|
<div class="panel-body"> |
||||
|
{$api.body|default='无'} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div><!-- #info --> |
||||
|
|
||||
|
<div class="tab-pane" id="sandbox{$api.id}"> |
||||
|
<div class="row"> |
||||
|
<div class="col-md-12"> |
||||
|
{if $api.headersList} |
||||
|
<div class="panel panel-default"> |
||||
|
<div class="panel-heading"><strong>{$lang.Headers}</strong></div> |
||||
|
<div class="panel-body"> |
||||
|
<div class="headers"> |
||||
|
{foreach name="api['headersList']" id="param"} |
||||
|
<div class="form-group"> |
||||
|
<label class="control-label" for="{$param.name}">{$param.name}</label> |
||||
|
<input type="{$param.type}" class="form-control input-sm" id="{$param.name}" {if $param.required}required{/if} placeholder="{$param.description} - Ex: {$param.sample}" name="{$param.name}"> |
||||
|
</div> |
||||
|
{/foreach} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
{/if} |
||||
|
<div class="panel panel-default"> |
||||
|
<div class="panel-heading"><strong>{$lang.Parameters}</strong> |
||||
|
<div class="pull-right"> |
||||
|
<a href="javascript:" class="btn btn-xs btn-info btn-append">追加</a> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="panel-body"> |
||||
|
<form enctype="application/x-www-form-urlencoded" role="form" action="{$api.route}" method="{$api.method}" name="form{$api.id}" id="form{$api.id}"> |
||||
|
{if $api.paramsList} |
||||
|
{foreach name="api['paramsList']" id="param"} |
||||
|
<div class="form-group"> |
||||
|
<label class="control-label" for="{$param.name}">{$param.name}</label> |
||||
|
<input type="{$param.type}" class="form-control input-sm" id="{$param.name}" {if $param.required}required{/if} placeholder="{$param.description}{if $param.sample} - 例: {$param.sample}{/if}" name="{$param.name}"> |
||||
|
</div> |
||||
|
{/foreach} |
||||
|
{else /} |
||||
|
<div class="form-group"> |
||||
|
无 |
||||
|
</div> |
||||
|
{/if} |
||||
|
<div class="form-group form-group-submit"> |
||||
|
<button type="submit" class="btn btn-success send" rel="{$api.id}">{$lang.Send}</button> |
||||
|
<button type="reset" class="btn btn-info" rel="{$api.id}">{$lang.Reset}</button> |
||||
|
</div> |
||||
|
</form> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="panel panel-default"> |
||||
|
<div class="panel-heading"><strong>{$lang.Response}</strong></div> |
||||
|
<div class="panel-body"> |
||||
|
<div class="row"> |
||||
|
<div class="col-md-12" style="overflow-x:auto"> |
||||
|
<pre id="response_headers{$api.id}"></pre> |
||||
|
<pre id="response{$api.id}"></pre> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="panel panel-default"> |
||||
|
<div class="panel-heading"><strong>{$lang.ReturnParameters}</strong></div> |
||||
|
<div class="panel-body"> |
||||
|
{if $api.returnParamsList} |
||||
|
<table class="table table-hover"> |
||||
|
<thead> |
||||
|
<tr> |
||||
|
<th>{$lang.Name}</th> |
||||
|
<th>{$lang.Type}</th> |
||||
|
<th>{$lang.Description}</th> |
||||
|
</tr> |
||||
|
</thead> |
||||
|
<tbody> |
||||
|
{foreach name="api['returnParamsList']" id="param"} |
||||
|
<tr> |
||||
|
<td>{$param.name}</td> |
||||
|
<td>{$param.type}</td> |
||||
|
<td>{$param.description}</td> |
||||
|
</tr> |
||||
|
{/foreach} |
||||
|
</tbody> |
||||
|
</table> |
||||
|
{else /} |
||||
|
无 |
||||
|
{/if} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div><!-- #sandbox --> |
||||
|
|
||||
|
<div class="tab-pane" id="sample{$api.id}"> |
||||
|
<div class="row"> |
||||
|
<div class="col-md-12"> |
||||
|
<pre id="sample_response{$api.id}">{$api.return|default='无'}</pre> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div><!-- #sample --> |
||||
|
|
||||
|
</div><!-- .tab-content --> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
{/foreach} |
||||
|
{/foreach} |
||||
|
</div> |
||||
|
|
||||
|
<hr> |
||||
|
|
||||
|
<div class="row mt0 footer"> |
||||
|
<div class="col-md-6" align="left"> |
||||
|
|
||||
|
</div> |
||||
|
<div class="col-md-6" align="right"> |
||||
|
Generated on {:date('Y-m-d H:i:s')} <a href="./" target="_blank">{$config.sitename}</a> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
</div> <!-- /container --> |
||||
|
|
||||
|
<!-- jQuery --> |
||||
|
<script src="https://cdn.staticfile.org/jquery/2.1.4/jquery.min.js"></script> |
||||
|
|
||||
|
<!-- Bootstrap Core JavaScript --> |
||||
|
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script> |
||||
|
|
||||
|
<script type="text/javascript"> |
||||
|
function syntaxHighlight(json) { |
||||
|
if (typeof json != 'string') { |
||||
|
json = JSON.stringify(json, undefined, 2); |
||||
|
} |
||||
|
json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); |
||||
|
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) { |
||||
|
var cls = 'number'; |
||||
|
if (/^"/.test(match)) { |
||||
|
if (/:$/.test(match)) { |
||||
|
cls = 'key'; |
||||
|
} else { |
||||
|
cls = 'string'; |
||||
|
} |
||||
|
} else if (/true|false/.test(match)) { |
||||
|
cls = 'boolean'; |
||||
|
} else if (/null/.test(match)) { |
||||
|
cls = 'null'; |
||||
|
} |
||||
|
return '<span class="' + cls + '">' + match + '</span>'; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
function prepareStr(str) { |
||||
|
try { |
||||
|
return syntaxHighlight(JSON.stringify(JSON.parse(str.replace(/'/g, '"')), null, 2)); |
||||
|
} catch (e) { |
||||
|
return str; |
||||
|
} |
||||
|
} |
||||
|
var storage = (function () { |
||||
|
var uid = new Date; |
||||
|
var storage; |
||||
|
var result; |
||||
|
try { |
||||
|
(storage = window.localStorage).setItem(uid, uid); |
||||
|
result = storage.getItem(uid) == uid; |
||||
|
storage.removeItem(uid); |
||||
|
return result && storage; |
||||
|
} catch (exception) { |
||||
|
} |
||||
|
}()); |
||||
|
|
||||
|
$.fn.serializeObject = function () |
||||
|
{ |
||||
|
var o = {}; |
||||
|
var a = this.serializeArray(); |
||||
|
$.each(a, function () { |
||||
|
if (!this.value) { |
||||
|
return; |
||||
|
} |
||||
|
if (o[this.name] !== undefined) { |
||||
|
if (!o[this.name].push) { |
||||
|
o[this.name] = [o[this.name]]; |
||||
|
} |
||||
|
o[this.name].push(this.value || ''); |
||||
|
} else { |
||||
|
o[this.name] = this.value || ''; |
||||
|
} |
||||
|
}); |
||||
|
return o; |
||||
|
}; |
||||
|
|
||||
|
$(document).ready(function () { |
||||
|
|
||||
|
if (storage) { |
||||
|
storage.getItem('token') && $('#token').val(storage.getItem('token')); |
||||
|
storage.getItem('apiUrl') && $('#apiUrl').val(storage.getItem('apiUrl')); |
||||
|
} |
||||
|
|
||||
|
$('[data-toggle="tooltip"]').tooltip({ |
||||
|
placement: 'bottom' |
||||
|
}); |
||||
|
|
||||
|
$(window).on("resize", function(){ |
||||
|
$("#sidebar").css("max-height", $(window).height()-80); |
||||
|
}); |
||||
|
|
||||
|
$(window).trigger("resize"); |
||||
|
|
||||
|
$(document).on("click", "#sidebar .list-group > .list-group-item", function(){ |
||||
|
$("#sidebar .list-group > .list-group-item").removeClass("current"); |
||||
|
$(this).addClass("current"); |
||||
|
}); |
||||
|
$(document).on("click", "#sidebar .child a", function(){ |
||||
|
var heading = $("#heading-"+$(this).data("id")); |
||||
|
if(!heading.next().hasClass("in")){ |
||||
|
$("a", heading).trigger("click"); |
||||
|
} |
||||
|
$("html,body").animate({scrollTop:heading.offset().top-70}); |
||||
|
}); |
||||
|
|
||||
|
$('code[id^=response]').hide(); |
||||
|
|
||||
|
$.each($('pre[id^=sample_response],pre[id^=sample_post_body]'), function () { |
||||
|
if ($(this).html() == 'NA') { |
||||
|
return; |
||||
|
} |
||||
|
var str = prepareStr($(this).html()); |
||||
|
$(this).html(str); |
||||
|
}); |
||||
|
|
||||
|
$("[data-toggle=popover]").popover({placement: 'right'}); |
||||
|
|
||||
|
$('[data-toggle=popover]').on('shown.bs.popover', function () { |
||||
|
var $sample = $(this).parent().find(".popover-content"), |
||||
|
str = $(this).data('content'); |
||||
|
if (typeof str == "undefined" || str === "") { |
||||
|
return; |
||||
|
} |
||||
|
var str = prepareStr(str); |
||||
|
$sample.html('<pre>' + str + '</pre>'); |
||||
|
}); |
||||
|
|
||||
|
$(document).on('click', '#save_data', function (e) { |
||||
|
if (storage) { |
||||
|
storage.setItem('token', $('#token').val()); |
||||
|
storage.setItem('apiUrl', $('#apiUrl').val()); |
||||
|
} else { |
||||
|
alert('Your browser does not support local storage'); |
||||
|
} |
||||
|
}); |
||||
|
$(document).on('click', '.btn-append', function (e) { |
||||
|
$($("#appendtpl").html()).insertBefore($(this).closest(".panel").find(".form-group-submit")); |
||||
|
return false; |
||||
|
}); |
||||
|
$(document).on('click', '.btn-remove', function (e) { |
||||
|
$(this).closest(".form-group").remove(); |
||||
|
return false; |
||||
|
}); |
||||
|
$(document).on('keyup', '.input-custom-name', function (e) { |
||||
|
$(this).closest(".row").find(".input-custom-value").attr("name", $(this).val()); |
||||
|
return false; |
||||
|
}); |
||||
|
|
||||
|
$(document).on('click', '.send', function (e) { |
||||
|
e.preventDefault(); |
||||
|
var form = $(this).closest('form'); |
||||
|
//added /g to get all the matched params instead of only first |
||||
|
var matchedParamsInRoute = $(form).attr('action').match(/[^{]+(?=\})/g); |
||||
|
var theId = $(this).attr('rel'); |
||||
|
//keep a copy of action attribute in order to modify the copy |
||||
|
//instead of the initial attribute |
||||
|
var url = $(form).attr('action'); |
||||
|
var method = $(form).prop('method').toLowerCase() || 'get'; |
||||
|
|
||||
|
var formData = new FormData(); |
||||
|
|
||||
|
$(form).find('input').each(function (i, input) { |
||||
|
if ($(input).attr('type').toLowerCase() == 'file') { |
||||
|
formData.append($(input).attr('name'), $(input)[0].files[0]); |
||||
|
method = 'post'; |
||||
|
} else { |
||||
|
formData.append($(input).attr('name'), $(input).val()) |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
var index, key, value; |
||||
|
|
||||
|
if (matchedParamsInRoute) { |
||||
|
var params = {}; |
||||
|
formData.forEach(function(value, key){ |
||||
|
params[key] = value; |
||||
|
}); |
||||
|
for (index = 0; index < matchedParamsInRoute.length; ++index) { |
||||
|
try { |
||||
|
key = matchedParamsInRoute[index]; |
||||
|
value = params[key]; |
||||
|
if (typeof value == "undefined") |
||||
|
value = ""; |
||||
|
url = url.replace("\{" + key + "\}", value); |
||||
|
formData.delete(key); |
||||
|
} catch (err) { |
||||
|
console.log(err); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
var headers = {}; |
||||
|
|
||||
|
var token = $('#token').val(); |
||||
|
if (token.length > 0) { |
||||
|
headers['token'] = token; |
||||
|
} |
||||
|
|
||||
|
$("#sandbox" + theId + " .headers input[type=text]").each(function () { |
||||
|
val = $(this).val(); |
||||
|
if (val.length > 0) { |
||||
|
headers[$(this).prop('name')] = val; |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
$.ajax({ |
||||
|
url: $('#apiUrl').val() + url, |
||||
|
data: method == 'get' ? $(form).serialize() : formData, |
||||
|
type: method, |
||||
|
dataType: 'json', |
||||
|
contentType: false, |
||||
|
processData: false, |
||||
|
headers: headers, |
||||
|
xhrFields: { |
||||
|
withCredentials: true |
||||
|
}, |
||||
|
success: function (data, textStatus, xhr) { |
||||
|
if (typeof data === 'object') { |
||||
|
var str = JSON.stringify(data, null, 2); |
||||
|
$('#response' + theId).html(syntaxHighlight(str)); |
||||
|
} else { |
||||
|
$('#response' + theId).html(data || ''); |
||||
|
} |
||||
|
$('#response_headers' + theId).html('HTTP ' + xhr.status + ' ' + xhr.statusText + '<br/><br/>' + xhr.getAllResponseHeaders()); |
||||
|
$('#response' + theId).show(); |
||||
|
}, |
||||
|
error: function (xhr, textStatus, error) { |
||||
|
try { |
||||
|
var str = JSON.stringify($.parseJSON(xhr.responseText), null, 2); |
||||
|
} catch (e) { |
||||
|
var str = xhr.responseText; |
||||
|
} |
||||
|
$('#response_headers' + theId).html('HTTP ' + xhr.status + ' ' + xhr.statusText + '<br/><br/>' + xhr.getAllResponseHeaders()); |
||||
|
$('#response' + theId).html(syntaxHighlight(str)); |
||||
|
$('#response' + theId).show(); |
||||
|
} |
||||
|
}); |
||||
|
return false; |
||||
|
}); |
||||
|
}); |
||||
|
</script> |
||||
|
<script type="text/html" id="appendtpl"> |
||||
|
<div class="form-group"> |
||||
|
<label class="control-label">自定义</label> |
||||
|
<div class="row"> |
||||
|
<div class="col-xs-4"> |
||||
|
<input type="text" class="form-control input-sm input-custom-name" placeholder="名称"> |
||||
|
</div> |
||||
|
<div class="col-xs-6"> |
||||
|
<input type="text" class="form-control input-sm input-custom-value" placeholder="值"> |
||||
|
</div> |
||||
|
<div class="col-xs-2 text-center"> |
||||
|
<a href="javascript:" class="btn btn-sm btn-danger btn-remove">删除</a> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</script> |
||||
|
</body> |
||||
|
</html> |
||||
File diff suppressed because it is too large
@ -0,0 +1,11 @@ |
|||||
|
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action=""> |
||||
|
|
||||
|
{%addList%} |
||||
|
<div class="form-group layer-footer"> |
||||
|
<label class="control-label col-xs-12 col-sm-2"></label> |
||||
|
<div class="col-xs-12 col-sm-8"> |
||||
|
<button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button> |
||||
|
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button> |
||||
|
</div> |
||||
|
</div> |
||||
|
</form> |
||||
@ -0,0 +1,37 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace {%controllerNamespace%}; |
||||
|
|
||||
|
use app\common\controller\Backend; |
||||
|
|
||||
|
/** |
||||
|
* {%tableComment%} |
||||
|
* |
||||
|
* @icon {%iconName%} |
||||
|
*/ |
||||
|
class {%controllerName%} extends Backend |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* {%modelName%}模型对象 |
||||
|
* @var \{%modelNamespace%}\{%modelName%} |
||||
|
*/ |
||||
|
protected $model = null; |
||||
|
|
||||
|
public function _initialize() |
||||
|
{ |
||||
|
parent::_initialize(); |
||||
|
$this->model = new \{%modelNamespace%}\{%modelName%}; |
||||
|
{%controllerAssignList%} |
||||
|
} |
||||
|
|
||||
|
{%controllerImport%} |
||||
|
|
||||
|
/** |
||||
|
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 |
||||
|
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 |
||||
|
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 |
||||
|
*/ |
||||
|
|
||||
|
{%controllerIndex%} |
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
|
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() |
||||
|
{ |
||||
|
//当前是否为关联查询 |
||||
|
$this->relationSearch = {%relationSearch%}; |
||||
|
//设置过滤方法 |
||||
|
$this->request->filter(['strip_tags', 'trim']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
//如果发送的来源是Selectpage,则转发到Selectpage |
||||
|
if ($this->request->request('keyField')) { |
||||
|
return $this->selectpage(); |
||||
|
} |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
|
||||
|
$list = $this->model |
||||
|
{%relationWithList%} |
||||
|
->where($where) |
||||
|
->order($sort, $order) |
||||
|
->paginate($limit); |
||||
|
|
||||
|
foreach ($list as $row) { |
||||
|
{%visibleFieldList%} |
||||
|
{%relationVisibleFieldList%} |
||||
|
} |
||||
|
|
||||
|
$result = array("total" => $list->total(), "rows" => $list->items()); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action=""> |
||||
|
|
||||
|
{%editList%} |
||||
|
<div class="form-group layer-footer"> |
||||
|
<label class="control-label col-xs-12 col-sm-2"></label> |
||||
|
<div class="col-xs-12 col-sm-8"> |
||||
|
<button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button> |
||||
|
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button> |
||||
|
</div> |
||||
|
</div> |
||||
|
</form> |
||||
@ -0,0 +1,6 @@ |
|||||
|
|
||||
|
<div class="checkbox"> |
||||
|
{foreach name="{%fieldList%}" item="vo"} |
||||
|
<label for="{%fieldName%}-{$key}"><input id="{%fieldName%}-{$key}" name="{%fieldName%}" type="checkbox" value="{$key}" {in name="key" value="{%selectedValue%}"}checked{/in} /> {$vo}</label> |
||||
|
{/foreach} |
||||
|
</div> |
||||
@ -0,0 +1,20 @@ |
|||||
|
|
||||
|
<table class="table fieldlist" data-name="{%fieldName%}" data-template="{%fieldName%}tpl"> |
||||
|
<tr> |
||||
|
{%theadList%} |
||||
|
<td width="90">{:__('Operate')}</td> |
||||
|
</tr> |
||||
|
<tr><td colspan="{%colspan%}"> |
||||
|
<a href="javascript:;" class="btn btn-sm btn-success btn-append"><i class="fa fa-plus"></i> {:__('Append')}</a> |
||||
|
<textarea name="{%fieldName%}" class="form-control hide" cols="30" rows="5">{%fieldValue%}</textarea> |
||||
|
</td></tr> |
||||
|
</table> |
||||
|
<script type="text/html" id="{%fieldName%}tpl"> |
||||
|
<tr> |
||||
|
{%tbodyList%} |
||||
|
<td width="90"> |
||||
|
<span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span> |
||||
|
<span class="btn btn-sm btn-primary btn-dragsort"><i class="fa fa-arrows"></i></span> |
||||
|
</td> |
||||
|
</tr> |
||||
|
</script> |
||||
@ -0,0 +1,10 @@ |
|||||
|
|
||||
|
<dl class="fieldlist" data-name="{%fieldName%}"> |
||||
|
<dd> |
||||
|
<ins>{:__('{%itemKey%}')}</ins> |
||||
|
<ins>{:__('{%itemValue%}')}</ins> |
||||
|
</dd> |
||||
|
<dd><a href="javascript:;" class="btn btn-sm btn-success btn-append"><i class="fa fa-plus"></i> {:__('Append')}</a></dd> |
||||
|
<textarea name="{%fieldName%}" class="form-control hide" cols="30" rows="5">{%fieldValue%}</textarea> |
||||
|
</dl> |
||||
|
|
||||
@ -0,0 +1,10 @@ |
|||||
|
|
||||
|
<div class="panel-heading"> |
||||
|
{:build_heading(null,FALSE)} |
||||
|
<ul class="nav nav-tabs" data-field="{%field%}"> |
||||
|
<li class="{:$Think.get.{%field%} === null ? 'active' : ''}"><a href="#t-all" data-value="" data-toggle="tab">{:__('All')}</a></li> |
||||
|
{foreach name="{%fieldName%}List" item="vo"} |
||||
|
<li class="{:$Think.get.{%field%} === (string)$key ? 'active' : ''}"><a href="#t-{$key}" data-value="{$key}" data-toggle="tab">{$vo}</a></li> |
||||
|
{/foreach} |
||||
|
</ul> |
||||
|
</div> |
||||
@ -0,0 +1,6 @@ |
|||||
|
|
||||
|
<div class="radio"> |
||||
|
{foreach name="{%fieldList%}" item="vo"} |
||||
|
<label for="{%fieldName%}-{$key}"><input id="{%fieldName%}-{$key}" name="{%fieldName%}" type="radio" value="{$key}" {in name="key" value="{%selectedValue%}"}checked{/in} /> {$vo}</label> |
||||
|
{/foreach} |
||||
|
</div> |
||||
@ -0,0 +1 @@ |
|||||
|
<a class="btn btn-success btn-recyclebin btn-dialog {:$auth->check('{%controllerUrl%}/recyclebin')?'':'hide'}" href="{%controllerUrl%}/recyclebin" title="{:__('Recycle bin')}"><i class="fa fa-recycle"></i> {:__('Recycle bin')}</a> |
||||
@ -0,0 +1,6 @@ |
|||||
|
|
||||
|
<select {%attrStr%}> |
||||
|
{foreach name="{%fieldList%}" item="vo"} |
||||
|
<option value="{$key}" {in name="key" value="{%selectedValue%}"}selected{/in}>{$vo}</option> |
||||
|
{/foreach} |
||||
|
</select> |
||||
@ -0,0 +1,5 @@ |
|||||
|
|
||||
|
<input {%attrStr%} name="{%fieldName%}" type="hidden" value="{%fieldValue%}"> |
||||
|
<a href="javascript:;" data-toggle="switcher" class="btn-switcher" data-input-id="c-{%field%}" data-yes="{%fieldYes%}" data-no="{%fieldNo%}" > |
||||
|
<i class="fa fa-toggle-on text-success {%fieldSwitchClass%} fa-2x"></i> |
||||
|
</a> |
||||
@ -0,0 +1,35 @@ |
|||||
|
<div class="panel panel-default panel-intro"> |
||||
|
{%headingHtml%} |
||||
|
|
||||
|
<div class="panel-body"> |
||||
|
<div id="myTabContent" class="tab-content"> |
||||
|
<div class="tab-pane fade active in" id="one"> |
||||
|
<div class="widget-body no-padding"> |
||||
|
<div id="toolbar" class="toolbar"> |
||||
|
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a> |
||||
|
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('{%controllerUrl%}/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a> |
||||
|
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('{%controllerUrl%}/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a> |
||||
|
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('{%controllerUrl%}/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a> |
||||
|
{%importHtml%} |
||||
|
|
||||
|
<div class="dropdown btn-group {:$auth->check('{%controllerUrl%}/multi')?'':'hide'}"> |
||||
|
<a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a> |
||||
|
<ul class="dropdown-menu text-left" role="menu"> |
||||
|
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li> |
||||
|
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li> |
||||
|
</ul> |
||||
|
</div> |
||||
|
|
||||
|
{%recyclebinHtml%} |
||||
|
</div> |
||||
|
<table id="table" class="table table-striped table-bordered table-hover table-nowrap" |
||||
|
data-operate-edit="{:$auth->check('{%controllerUrl%}/edit')}" |
||||
|
data-operate-del="{:$auth->check('{%controllerUrl%}/del')}" |
||||
|
width="100%"> |
||||
|
</table> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
@ -0,0 +1,48 @@ |
|||||
|
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { |
||||
|
|
||||
|
var Controller = { |
||||
|
index: function () { |
||||
|
// 初始化表格参数配置 |
||||
|
Table.api.init({ |
||||
|
extend: { |
||||
|
index_url: '{%controllerUrl%}/index' + location.search, |
||||
|
add_url: '{%controllerUrl%}/add', |
||||
|
edit_url: '{%controllerUrl%}/edit', |
||||
|
del_url: '{%controllerUrl%}/del', |
||||
|
multi_url: '{%controllerUrl%}/multi', |
||||
|
import_url: '{%controllerUrl%}/import', |
||||
|
table: '{%table%}', |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
var table = $("#table"); |
||||
|
|
||||
|
// 初始化表格 |
||||
|
table.bootstrapTable({ |
||||
|
url: $.fn.bootstrapTable.defaults.extend.index_url, |
||||
|
pk: '{%pk%}', |
||||
|
sortName: '{%order%}',{%fixedColumnsJs%} |
||||
|
columns: [ |
||||
|
[ |
||||
|
{%javascriptList%} |
||||
|
] |
||||
|
] |
||||
|
}); |
||||
|
|
||||
|
// 为表格绑定事件 |
||||
|
Table.api.bindevent(table); |
||||
|
},{%recyclebinJs%} |
||||
|
add: function () { |
||||
|
Controller.api.bindevent(); |
||||
|
}, |
||||
|
edit: function () { |
||||
|
Controller.api.bindevent(); |
||||
|
}, |
||||
|
api: { |
||||
|
bindevent: function () { |
||||
|
Form.api.bindevent($("form[role=form]")); |
||||
|
} |
||||
|
} |
||||
|
}; |
||||
|
return Controller; |
||||
|
}); |
||||
@ -0,0 +1,5 @@ |
|||||
|
<?php |
||||
|
|
||||
|
return [ |
||||
|
{%langList%} |
||||
|
]; |
||||
@ -0,0 +1,8 @@ |
|||||
|
|
||||
|
public function {%methodName%}($value, $data) |
||||
|
{ |
||||
|
$value = $value ? $value : (isset($data['{%field%}']) ? $data['{%field%}'] : ''); |
||||
|
$valueArr = explode(',', $value); |
||||
|
$list = $this->{%listMethodName%}(); |
||||
|
return implode(',', array_intersect_key($list, array_flip($valueArr))); |
||||
|
} |
||||
@ -0,0 +1,6 @@ |
|||||
|
|
||||
|
public function {%methodName%}($value, $data) |
||||
|
{ |
||||
|
$value = $value ? $value : (isset($data['{%field%}']) ? $data['{%field%}'] : ''); |
||||
|
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; |
||||
|
} |
||||
@ -0,0 +1 @@ |
|||||
|
|
||||
@ -0,0 +1,4 @@ |
|||||
|
public function import() |
||||
|
{ |
||||
|
parent::import(); |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
|
||||
|
protected static function init() |
||||
|
{ |
||||
|
self::afterInsert(function ($row) { |
||||
|
$pk = $row->getPk(); |
||||
|
$row->getQuery()->where($pk, $row[$pk])->update(['{%order%}' => $row[$pk]]); |
||||
|
}); |
||||
|
} |
||||
@ -0,0 +1,5 @@ |
|||||
|
|
||||
|
public function {%relationMethod%}s() |
||||
|
{ |
||||
|
return $this->{%relationMode%}('{%relationClassName%}', '{%relationForeignKey%}', '{%relationPrimaryKey%}'); |
||||
|
} |
||||
@ -0,0 +1,5 @@ |
|||||
|
|
||||
|
public function {%relationMethod%}() |
||||
|
{ |
||||
|
return $this->{%relationMode%}('{%relationClassName%}', '{%relationForeignKey%}', '{%relationPrimaryKey%}', [], 'LEFT')->setEagerlyType(0); |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
|
||||
|
public function {%methodName%}($value, $data) |
||||
|
{ |
||||
|
$value = $value ? $value : (isset($data['{%field%}']) ? $data['{%field%}'] : ''); |
||||
|
$valueArr = explode(',', $value); |
||||
|
$list = $this->{%listMethodName%}(); |
||||
|
return implode(',', array_intersect_key($list, array_flip($valueArr))); |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
|
||||
|
public function {%methodName%}($value, $data) |
||||
|
{ |
||||
|
$value = $value ? $value : (isset($data['{%field%}']) ? $data['{%field%}'] : ''); |
||||
|
$list = $this->{%listMethodName%}(); |
||||
|
return isset($list[$value]) ? $list[$value] : ''; |
||||
|
} |
||||
@ -0,0 +1,60 @@ |
|||||
|
|
||||
|
recyclebin: function () { |
||||
|
// 初始化表格参数配置 |
||||
|
Table.api.init({ |
||||
|
extend: { |
||||
|
'dragsort_url': '' |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
var table = $("#table"); |
||||
|
|
||||
|
// 初始化表格 |
||||
|
table.bootstrapTable({ |
||||
|
url: '{%controllerUrl%}/recyclebin' + location.search, |
||||
|
pk: 'id', |
||||
|
sortName: 'id', |
||||
|
columns: [ |
||||
|
[ |
||||
|
{checkbox: true}, |
||||
|
{field: 'id', title: __('Id')},{%recyclebinTitleJs%} |
||||
|
{ |
||||
|
field: '{%deleteTimeField%}', |
||||
|
title: __('Deletetime'), |
||||
|
operate: 'RANGE', |
||||
|
addclass: 'datetimerange', |
||||
|
formatter: Table.api.formatter.datetime |
||||
|
}, |
||||
|
{ |
||||
|
field: 'operate', |
||||
|
width: '140px', |
||||
|
title: __('Operate'), |
||||
|
table: table, |
||||
|
events: Table.api.events.operate, |
||||
|
buttons: [ |
||||
|
{ |
||||
|
name: 'Restore', |
||||
|
text: __('Restore'), |
||||
|
classname: 'btn btn-xs btn-info btn-ajax btn-restoreit', |
||||
|
icon: 'fa fa-rotate-left', |
||||
|
url: '{%controllerUrl%}/restore', |
||||
|
refresh: true |
||||
|
}, |
||||
|
{ |
||||
|
name: 'Destroy', |
||||
|
text: __('Destroy'), |
||||
|
classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit', |
||||
|
icon: 'fa fa-times', |
||||
|
url: '{%controllerUrl%}/destroy', |
||||
|
refresh: true |
||||
|
} |
||||
|
], |
||||
|
formatter: Table.api.formatter.operate |
||||
|
} |
||||
|
] |
||||
|
] |
||||
|
}); |
||||
|
|
||||
|
// 为表格绑定事件 |
||||
|
Table.api.bindevent(table); |
||||
|
}, |
||||
@ -0,0 +1,7 @@ |
|||||
|
|
||||
|
public function {%methodName%}($value, $data) |
||||
|
{ |
||||
|
$value = $value ? $value : (isset($data['{%field%}']) ? $data['{%field%}'] : ''); |
||||
|
$list = $this->{%listMethodName%}(); |
||||
|
return isset($list[$value]) ? $list[$value] : ''; |
||||
|
} |
||||
@ -0,0 +1,40 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace {%modelNamespace%}; |
||||
|
|
||||
|
use think\Model; |
||||
|
{%softDeleteClassPath%} |
||||
|
|
||||
|
class {%modelName%} extends Model |
||||
|
{ |
||||
|
|
||||
|
{%softDelete%} |
||||
|
|
||||
|
{%modelConnection%} |
||||
|
|
||||
|
// 表名 |
||||
|
protected ${%modelTableType%} = '{%modelTableTypeName%}'; |
||||
|
|
||||
|
// 自动写入时间戳字段 |
||||
|
protected $autoWriteTimestamp = {%modelAutoWriteTimestamp%}; |
||||
|
|
||||
|
// 定义时间戳字段名 |
||||
|
protected $createTime = {%createTime%}; |
||||
|
protected $updateTime = {%updateTime%}; |
||||
|
protected $deleteTime = {%deleteTime%}; |
||||
|
|
||||
|
// 追加属性 |
||||
|
protected $append = [ |
||||
|
{%appendAttrList%} |
||||
|
]; |
||||
|
|
||||
|
{%modelInit%} |
||||
|
|
||||
|
{%getEnumList%} |
||||
|
|
||||
|
{%getAttrList%} |
||||
|
|
||||
|
{%setAttrList%} |
||||
|
|
||||
|
{%relationMethodList%} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
<div class="panel panel-default panel-intro"> |
||||
|
{:build_heading()} |
||||
|
|
||||
|
<div class="panel-body"> |
||||
|
<div id="myTabContent" class="tab-content"> |
||||
|
<div class="tab-pane fade active in" id="one"> |
||||
|
<div class="widget-body no-padding"> |
||||
|
<div id="toolbar" class="toolbar"> |
||||
|
{:build_toolbar('refresh')} |
||||
|
<a class="btn btn-info btn-multi btn-disabled disabled {:$auth->check('{%controllerUrl%}/restore')?'':'hide'}" href="javascript:;" data-url="{%controllerUrl%}/restore" data-action="restore"><i class="fa fa-rotate-left"></i> {:__('Restore')}</a> |
||||
|
<a class="btn btn-danger btn-multi btn-disabled disabled {:$auth->check('{%controllerUrl%}/destroy')?'':'hide'}" href="javascript:;" data-url="{%controllerUrl%}/destroy" data-action="destroy"><i class="fa fa-times"></i> {:__('Destroy')}</a> |
||||
|
<a class="btn btn-success btn-restoreall {:$auth->check('{%controllerUrl%}/restore')?'':'hide'}" href="javascript:;" data-url="{%controllerUrl%}/restore" title="{:__('Restore all')}"><i class="fa fa-rotate-left"></i> {:__('Restore all')}</a> |
||||
|
<a class="btn btn-danger btn-destroyall {:$auth->check('{%controllerUrl%}/destroy')?'':'hide'}" href="javascript:;" data-url="{%controllerUrl%}/destroy" title="{:__('Destroy all')}"><i class="fa fa-times"></i> {:__('Destroy all')}</a> |
||||
|
</div> |
||||
|
<table id="table" class="table table-striped table-bordered table-hover" |
||||
|
data-operate-restore="{:$auth->check('{%controllerUrl%}/restore')}" |
||||
|
data-operate-destroy="{:$auth->check('{%controllerUrl%}/destroy')}" |
||||
|
width="100%"> |
||||
|
</table> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
@ -0,0 +1,12 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace {%modelNamespace%}; |
||||
|
|
||||
|
use think\Model; |
||||
|
|
||||
|
class {%relationName%} extends Model |
||||
|
{ |
||||
|
// 表名 |
||||
|
protected ${%relationTableType%} = '{%relationTableTypeName%}'; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace {%validateNamespace%}; |
||||
|
|
||||
|
use think\Validate; |
||||
|
|
||||
|
class {%validateName%} extends Validate |
||||
|
{ |
||||
|
/** |
||||
|
* 验证规则 |
||||
|
*/ |
||||
|
protected $rule = [ |
||||
|
]; |
||||
|
/** |
||||
|
* 提示消息 |
||||
|
*/ |
||||
|
protected $message = [ |
||||
|
]; |
||||
|
/** |
||||
|
* 验证场景 |
||||
|
*/ |
||||
|
protected $scene = [ |
||||
|
'add' => [], |
||||
|
'edit' => [], |
||||
|
]; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,329 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\command; |
||||
|
|
||||
|
use fast\Random; |
||||
|
use PDO; |
||||
|
use think\Config; |
||||
|
use think\console\Command; |
||||
|
use think\console\Input; |
||||
|
use think\console\input\Option; |
||||
|
use think\console\Output; |
||||
|
use think\Db; |
||||
|
use think\Exception; |
||||
|
use think\Lang; |
||||
|
use think\Request; |
||||
|
use think\View; |
||||
|
|
||||
|
class Install extends Command |
||||
|
{ |
||||
|
protected $model = null; |
||||
|
/** |
||||
|
* @var \think\View 视图类实例 |
||||
|
*/ |
||||
|
protected $view; |
||||
|
|
||||
|
/** |
||||
|
* @var \think\Request Request 实例 |
||||
|
*/ |
||||
|
protected $request; |
||||
|
|
||||
|
protected function configure() |
||||
|
{ |
||||
|
$config = Config::get('database'); |
||||
|
$this |
||||
|
->setName('install') |
||||
|
->addOption('hostname', 'a', Option::VALUE_OPTIONAL, 'mysql hostname', $config['hostname']) |
||||
|
->addOption('hostport', 'o', Option::VALUE_OPTIONAL, 'mysql hostport', $config['hostport']) |
||||
|
->addOption('database', 'd', Option::VALUE_OPTIONAL, 'mysql database', $config['database']) |
||||
|
->addOption('prefix', 'r', Option::VALUE_OPTIONAL, 'table prefix', $config['prefix']) |
||||
|
->addOption('username', 'u', Option::VALUE_OPTIONAL, 'mysql username', $config['username']) |
||||
|
->addOption('password', 'p', Option::VALUE_OPTIONAL, 'mysql password', $config['password']) |
||||
|
->addOption('force', 'f', Option::VALUE_OPTIONAL, 'force override', false) |
||||
|
->setDescription('New installation of FastAdmin'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 命令行安装 |
||||
|
*/ |
||||
|
protected function execute(Input $input, Output $output) |
||||
|
{ |
||||
|
define('INSTALL_PATH', APP_PATH . 'admin' . DS . 'command' . DS . 'Install' . DS); |
||||
|
// 覆盖安装 |
||||
|
$force = $input->getOption('force'); |
||||
|
$hostname = $input->getOption('hostname'); |
||||
|
$hostport = $input->getOption('hostport'); |
||||
|
$database = $input->getOption('database'); |
||||
|
$prefix = $input->getOption('prefix'); |
||||
|
$username = $input->getOption('username'); |
||||
|
$password = $input->getOption('password'); |
||||
|
|
||||
|
$installLockFile = INSTALL_PATH . "install.lock"; |
||||
|
if (is_file($installLockFile) && !$force) { |
||||
|
throw new Exception("\nFastAdmin already installed!\nIf you need to reinstall again, use the parameter --force=true "); |
||||
|
} |
||||
|
|
||||
|
$adminUsername = 'admin'; |
||||
|
$adminPassword = Random::alnum(10); |
||||
|
$adminEmail = 'admin@admin.com'; |
||||
|
$siteName = __('My Website'); |
||||
|
|
||||
|
$adminName = $this->installation($hostname, $hostport, $database, $username, $password, $prefix, $adminUsername, $adminPassword, $adminEmail, $siteName); |
||||
|
if ($adminName) { |
||||
|
$output->highlight("Admin url:http://www.yoursite.com/{$adminName}"); |
||||
|
} |
||||
|
|
||||
|
$output->highlight("Admin username:{$adminUsername}"); |
||||
|
$output->highlight("Admin password:{$adminPassword}"); |
||||
|
|
||||
|
\think\Cache::rm('__menu__'); |
||||
|
|
||||
|
$output->info("Install Successed!"); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* PC端安装 |
||||
|
*/ |
||||
|
public function index() |
||||
|
{ |
||||
|
$this->view = View::instance(Config::get('template'), Config::get('view_replace_str')); |
||||
|
$this->request = Request::instance(); |
||||
|
|
||||
|
define('INSTALL_PATH', APP_PATH . 'admin' . DS . 'command' . DS . 'Install' . DS); |
||||
|
|
||||
|
$lang = $this->request->langset(); |
||||
|
$lang = preg_match("/^([a-zA-Z\-_]{2,10})\$/i", $lang) ? $lang : 'zh-cn'; |
||||
|
|
||||
|
if (!$lang || in_array($lang, ['zh-cn', 'zh-hans-cn'])) { |
||||
|
Lang::load(INSTALL_PATH . 'zh-cn.php'); |
||||
|
} |
||||
|
|
||||
|
$installLockFile = INSTALL_PATH . "install.lock"; |
||||
|
|
||||
|
if (is_file($installLockFile)) { |
||||
|
echo __('The system has been installed. If you need to reinstall, please remove %s first', 'install.lock'); |
||||
|
exit; |
||||
|
} |
||||
|
$output = function ($code, $msg, $url = null, $data = null) { |
||||
|
return json(['code' => $code, 'msg' => $msg, 'url' => $url, 'data' => $data]); |
||||
|
}; |
||||
|
|
||||
|
if ($this->request->isPost()) { |
||||
|
$mysqlHostname = $this->request->post('mysqlHostname', '127.0.0.1'); |
||||
|
$mysqlHostport = $this->request->post('mysqlHostport', '3306'); |
||||
|
$hostArr = explode(':', $mysqlHostname); |
||||
|
if (count($hostArr) > 1) { |
||||
|
$mysqlHostname = $hostArr[0]; |
||||
|
$mysqlHostport = $hostArr[1]; |
||||
|
} |
||||
|
$mysqlUsername = $this->request->post('mysqlUsername', 'root'); |
||||
|
$mysqlPassword = $this->request->post('mysqlPassword', ''); |
||||
|
$mysqlDatabase = $this->request->post('mysqlDatabase', ''); |
||||
|
$mysqlPrefix = $this->request->post('mysqlPrefix', 'fa_'); |
||||
|
$adminUsername = $this->request->post('adminUsername', 'admin'); |
||||
|
$adminPassword = $this->request->post('adminPassword', ''); |
||||
|
$adminPasswordConfirmation = $this->request->post('adminPasswordConfirmation', ''); |
||||
|
$adminEmail = $this->request->post('adminEmail', 'admin@admin.com'); |
||||
|
$siteName = $this->request->post('siteName', __('My Website')); |
||||
|
|
||||
|
if ($adminPassword !== $adminPasswordConfirmation) { |
||||
|
return $output(0, __('The two passwords you entered did not match')); |
||||
|
} |
||||
|
|
||||
|
$adminName = ''; |
||||
|
try { |
||||
|
$adminName = $this->installation($mysqlHostname, $mysqlHostport, $mysqlDatabase, $mysqlUsername, $mysqlPassword, $mysqlPrefix, $adminUsername, $adminPassword, $adminEmail, $siteName); |
||||
|
} catch (\PDOException $e) { |
||||
|
throw new Exception($e->getMessage()); |
||||
|
} catch (\Exception $e) { |
||||
|
return $output(0, $e->getMessage()); |
||||
|
} |
||||
|
return $output(1, __('Install Successed'), null, ['adminName' => $adminName]); |
||||
|
} |
||||
|
$errInfo = ''; |
||||
|
try { |
||||
|
$this->checkenv(); |
||||
|
} catch (\Exception $e) { |
||||
|
$errInfo = $e->getMessage(); |
||||
|
} |
||||
|
return $this->view->fetch(INSTALL_PATH . "install.html", ['errInfo' => $errInfo]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 执行安装 |
||||
|
*/ |
||||
|
protected function installation($mysqlHostname, $mysqlHostport, $mysqlDatabase, $mysqlUsername, $mysqlPassword, $mysqlPrefix, $adminUsername, $adminPassword, $adminEmail = null, $siteName = null) |
||||
|
{ |
||||
|
$this->checkenv(); |
||||
|
|
||||
|
if ($mysqlDatabase == '') { |
||||
|
throw new Exception(__('Please input correct database')); |
||||
|
} |
||||
|
if (!preg_match("/^\w{3,12}$/", $adminUsername)) { |
||||
|
throw new Exception(__('Please input correct username')); |
||||
|
} |
||||
|
if (!preg_match("/^[\S]{6,16}$/", $adminPassword)) { |
||||
|
throw new Exception(__('Please input correct password')); |
||||
|
} |
||||
|
$weakPasswordArr = ['123456', '12345678', '123456789', '654321', '111111', '000000', 'password', 'qwerty', 'abc123', '1qaz2wsx']; |
||||
|
if (in_array($adminPassword, $weakPasswordArr)) { |
||||
|
throw new Exception(__('Password is too weak')); |
||||
|
} |
||||
|
if ($siteName == '' || preg_match("/fast" . "admin/i", $siteName)) { |
||||
|
throw new Exception(__('Please input correct website')); |
||||
|
} |
||||
|
|
||||
|
$sql = file_get_contents(INSTALL_PATH . 'fastadmin.sql'); |
||||
|
|
||||
|
$sql = str_replace("`fa_", "`{$mysqlPrefix}", $sql); |
||||
|
|
||||
|
// 先尝试能否自动创建数据库 |
||||
|
$config = Config::get('database'); |
||||
|
try { |
||||
|
$pdo = new PDO("{$config['type']}:host={$mysqlHostname}" . ($mysqlHostport ? ";port={$mysqlHostport}" : ''), $mysqlUsername, $mysqlPassword); |
||||
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
||||
|
$pdo->query("CREATE DATABASE IF NOT EXISTS `{$mysqlDatabase}` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"); |
||||
|
|
||||
|
// 连接install命令中指定的数据库 |
||||
|
$instance = Db::connect([ |
||||
|
'type' => "{$config['type']}", |
||||
|
'hostname' => "{$mysqlHostname}", |
||||
|
'hostport' => "{$mysqlHostport}", |
||||
|
'database' => "{$mysqlDatabase}", |
||||
|
'username' => "{$mysqlUsername}", |
||||
|
'password' => "{$mysqlPassword}", |
||||
|
'prefix' => "{$mysqlPrefix}", |
||||
|
]); |
||||
|
|
||||
|
// 查询一次SQL,判断连接是否正常 |
||||
|
$instance->execute("SELECT 1"); |
||||
|
|
||||
|
// 调用原生PDO对象进行批量查询 |
||||
|
$instance->getPdo()->exec($sql); |
||||
|
} catch (\PDOException $e) { |
||||
|
throw new Exception($e->getMessage()); |
||||
|
} |
||||
|
// 后台入口文件 |
||||
|
$adminFile = ROOT_PATH . 'public' . DS . 'admin.php'; |
||||
|
|
||||
|
// 数据库配置文件 |
||||
|
$dbConfigFile = APP_PATH . 'database.php'; |
||||
|
$dbConfigText = @file_get_contents($dbConfigFile); |
||||
|
$callback = function ($matches) use ($mysqlHostname, $mysqlHostport, $mysqlUsername, $mysqlPassword, $mysqlDatabase, $mysqlPrefix) { |
||||
|
$field = "mysql" . ucfirst($matches[1]); |
||||
|
$replace = $$field; |
||||
|
if ($matches[1] == 'hostport' && $mysqlHostport == 3306) { |
||||
|
$replace = ''; |
||||
|
} |
||||
|
return "'{$matches[1]}'{$matches[2]}=>{$matches[3]}Env::get('database.{$matches[1]}', '{$replace}'),"; |
||||
|
}; |
||||
|
$dbConfigText = preg_replace_callback("/'(hostname|database|username|password|hostport|prefix)'(\s+)=>(\s+)Env::get\((.*)\)\,/", $callback, $dbConfigText); |
||||
|
|
||||
|
// 检测能否成功写入数据库配置 |
||||
|
$result = @file_put_contents($dbConfigFile, $dbConfigText); |
||||
|
if (!$result) { |
||||
|
throw new Exception(__('The current permissions are insufficient to write the file %s', 'application/database.php')); |
||||
|
} |
||||
|
|
||||
|
// 设置新的Token随机密钥key |
||||
|
$oldTokenKey = config('token.key'); |
||||
|
$newTokenKey = \fast\Random::alnum(32); |
||||
|
$coreConfigFile = CONF_PATH . 'config.php'; |
||||
|
$coreConfigText = @file_get_contents($coreConfigFile); |
||||
|
$coreConfigText = preg_replace("/'key'(\s+)=>(\s+)'{$oldTokenKey}'/", "'key'\$1=>\$2'{$newTokenKey}'", $coreConfigText); |
||||
|
|
||||
|
$result = @file_put_contents($coreConfigFile, $coreConfigText); |
||||
|
if (!$result) { |
||||
|
throw new Exception(__('The current permissions are insufficient to write the file %s', 'application/config.php')); |
||||
|
} |
||||
|
|
||||
|
$avatar = request()->domain() . '/assets/img/avatar.png'; |
||||
|
// 变更默认管理员密码 |
||||
|
$adminPassword = $adminPassword ? $adminPassword : Random::alnum(8); |
||||
|
$adminEmail = $adminEmail ? $adminEmail : "admin@admin.com"; |
||||
|
$newSalt = substr(md5(uniqid(true)), 0, 6); |
||||
|
$newPassword = md5(md5($adminPassword) . $newSalt); |
||||
|
$data = ['username' => $adminUsername, 'email' => $adminEmail, 'avatar' => $avatar, 'password' => $newPassword, 'salt' => $newSalt]; |
||||
|
$instance->name('admin')->where('username', 'admin')->update($data); |
||||
|
|
||||
|
// 变更前台默认用户的密码,随机生成 |
||||
|
$newSalt = substr(md5(uniqid(true)), 0, 6); |
||||
|
$newPassword = md5(md5(Random::alnum(8)) . $newSalt); |
||||
|
$instance->name('user')->where('username', 'admin')->update(['avatar' => $avatar, 'password' => $newPassword, 'salt' => $newSalt]); |
||||
|
|
||||
|
// 修改后台入口 |
||||
|
$adminName = ''; |
||||
|
if (is_file($adminFile)) { |
||||
|
$adminName = Random::alpha(10) . '.php'; |
||||
|
rename($adminFile, ROOT_PATH . 'public' . DS . $adminName); |
||||
|
} |
||||
|
|
||||
|
//修改站点名称 |
||||
|
if ($siteName != config('site.name')) { |
||||
|
$instance->name('config')->where('name', 'name')->update(['value' => $siteName]); |
||||
|
$siteConfigFile = CONF_PATH . 'extra' . DS . 'site.php'; |
||||
|
$siteConfig = include $siteConfigFile; |
||||
|
$configList = $instance->name("config")->select(); |
||||
|
foreach ($configList as $k => $value) { |
||||
|
if (in_array($value['type'], ['selects', 'checkbox', 'images', 'files'])) { |
||||
|
$value['value'] = is_array($value['value']) ? $value['value'] : explode(',', $value['value']); |
||||
|
} |
||||
|
if ($value['type'] == 'array') { |
||||
|
$value['value'] = (array)json_decode($value['value'], true); |
||||
|
} |
||||
|
$siteConfig[$value['name']] = $value['value']; |
||||
|
} |
||||
|
$siteConfig['name'] = $siteName; |
||||
|
file_put_contents($siteConfigFile, '<?php' . "\n\nreturn " . var_export_short($siteConfig) . ";\n"); |
||||
|
} |
||||
|
|
||||
|
$installLockFile = INSTALL_PATH . "install.lock"; |
||||
|
//检测能否成功写入lock文件 |
||||
|
$result = @file_put_contents($installLockFile, 1); |
||||
|
if (!$result) { |
||||
|
throw new Exception(__('The current permissions are insufficient to write the file %s', 'application/admin/command/Install/install.lock')); |
||||
|
} |
||||
|
|
||||
|
try { |
||||
|
//删除安装脚本 |
||||
|
@unlink(ROOT_PATH . 'public' . DS . 'install.php'); |
||||
|
} catch (\Exception $e) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
return $adminName; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 检测环境 |
||||
|
*/ |
||||
|
protected function checkenv() |
||||
|
{ |
||||
|
// 检测目录是否存在 |
||||
|
$checkDirs = [ |
||||
|
'thinkphp', |
||||
|
'vendor', |
||||
|
'public' . DS . 'assets' . DS . 'libs' |
||||
|
]; |
||||
|
|
||||
|
//数据库配置文件 |
||||
|
$dbConfigFile = APP_PATH . 'database.php'; |
||||
|
|
||||
|
if (version_compare(PHP_VERSION, '7.2.0', '<')) { |
||||
|
throw new Exception(__("The current version %s is too low, please use PHP 7.2 or higher", PHP_VERSION)); |
||||
|
} |
||||
|
if (!extension_loaded("PDO")) { |
||||
|
throw new Exception(__("PDO is not currently installed and cannot be installed")); |
||||
|
} |
||||
|
if (!is_really_writable($dbConfigFile)) { |
||||
|
throw new Exception(__('The current permissions are insufficient to write the configuration file application/database.php')); |
||||
|
} |
||||
|
foreach ($checkDirs as $k => $v) { |
||||
|
if (!is_dir(ROOT_PATH . $v)) { |
||||
|
throw new Exception(__('Please go to the official website to download the full package or resource package and try to install')); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,605 @@ |
|||||
|
/* |
||||
|
FastAdmin Install SQL |
||||
|
Date: 2020-06-11 22:11:09 |
||||
|
*/ |
||||
|
|
||||
|
SET FOREIGN_KEY_CHECKS = 0; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Table structure for fa_admin |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `fa_admin`; |
||||
|
CREATE TABLE `fa_admin` ( |
||||
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', |
||||
|
`username` varchar(20) DEFAULT '' COMMENT '用户名', |
||||
|
`nickname` varchar(50) DEFAULT '' COMMENT '昵称', |
||||
|
`password` varchar(32) DEFAULT '' COMMENT '密码', |
||||
|
`salt` varchar(30) DEFAULT '' COMMENT '密码盐', |
||||
|
`avatar` varchar(255) DEFAULT '' COMMENT '头像', |
||||
|
`email` varchar(100) DEFAULT '' COMMENT '电子邮箱', |
||||
|
`mobile` varchar(11) DEFAULT '' COMMENT '手机号码', |
||||
|
`loginfailure` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '失败次数', |
||||
|
`logintime` bigint(16) DEFAULT NULL COMMENT '登录时间', |
||||
|
`loginip` varchar(50) DEFAULT NULL COMMENT '登录IP', |
||||
|
`createtime` bigint(16) DEFAULT NULL COMMENT '创建时间', |
||||
|
`updatetime` bigint(16) DEFAULT NULL COMMENT '更新时间', |
||||
|
`token` varchar(59) DEFAULT '' COMMENT 'Session标识', |
||||
|
`status` varchar(30) NOT NULL DEFAULT 'normal' COMMENT '状态', |
||||
|
PRIMARY KEY (`id`), |
||||
|
UNIQUE KEY `username` (`username`) USING BTREE |
||||
|
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT='管理员表'; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Records of fa_admin |
||||
|
-- ---------------------------- |
||||
|
BEGIN; |
||||
|
INSERT INTO `fa_admin` VALUES (1, 'admin', 'Admin', '', '', '/assets/img/avatar.png', 'admin@admin.com', '', 0, 1491635035, '127.0.0.1',1491635035, 1491635035, '', 'normal'); |
||||
|
COMMIT; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Table structure for fa_admin_log |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `fa_admin_log`; |
||||
|
CREATE TABLE `fa_admin_log` ( |
||||
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', |
||||
|
`admin_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '管理员ID', |
||||
|
`username` varchar(30) DEFAULT '' COMMENT '管理员名字', |
||||
|
`url` varchar(1500) DEFAULT '' COMMENT '操作页面', |
||||
|
`title` varchar(100) DEFAULT '' COMMENT '日志标题', |
||||
|
`content` longtext NOT NULL COMMENT '内容', |
||||
|
`ip` varchar(50) DEFAULT '' COMMENT 'IP', |
||||
|
`useragent` varchar(255) DEFAULT '' COMMENT 'User-Agent', |
||||
|
`createtime` bigint(16) DEFAULT NULL COMMENT '操作时间', |
||||
|
PRIMARY KEY (`id`), |
||||
|
KEY `name` (`username`) |
||||
|
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT='管理员日志表'; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Table structure for fa_area |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `fa_area`; |
||||
|
CREATE TABLE `fa_area` ( |
||||
|
`id` int(10) NOT NULL AUTO_INCREMENT COMMENT 'ID', |
||||
|
`pid` int(10) DEFAULT NULL COMMENT '父id', |
||||
|
`shortname` varchar(100) DEFAULT NULL COMMENT '简称', |
||||
|
`name` varchar(100) DEFAULT NULL COMMENT '名称', |
||||
|
`mergename` varchar(255) DEFAULT NULL COMMENT '全称', |
||||
|
`level` tinyint(4) DEFAULT NULL COMMENT '层级:1=省,2=市,3=区/县', |
||||
|
`pinyin` varchar(100) DEFAULT NULL COMMENT '拼音', |
||||
|
`code` varchar(100) DEFAULT NULL COMMENT '长途区号', |
||||
|
`zip` varchar(100) DEFAULT NULL COMMENT '邮编', |
||||
|
`first` varchar(50) DEFAULT NULL COMMENT '首字母', |
||||
|
`lng` varchar(100) DEFAULT NULL COMMENT '经度', |
||||
|
`lat` varchar(100) DEFAULT NULL COMMENT '纬度', |
||||
|
PRIMARY KEY (`id`), |
||||
|
KEY `pid` (`pid`) |
||||
|
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT='地区表'; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Table structure for fa_attachment |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `fa_attachment`; |
||||
|
CREATE TABLE `fa_attachment` ( |
||||
|
`id` int(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', |
||||
|
`category` varchar(50) DEFAULT '' COMMENT '类别', |
||||
|
`admin_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '管理员ID', |
||||
|
`user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '会员ID', |
||||
|
`url` varchar(255) DEFAULT '' COMMENT '物理路径', |
||||
|
`imagewidth` varchar(30) DEFAULT '' COMMENT '宽度', |
||||
|
`imageheight` varchar(30) DEFAULT '' COMMENT '高度', |
||||
|
`imagetype` varchar(30) DEFAULT '' COMMENT '图片类型', |
||||
|
`imageframes` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '图片帧数', |
||||
|
`filename` varchar(100) DEFAULT '' COMMENT '文件名称', |
||||
|
`filesize` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '文件大小', |
||||
|
`mimetype` varchar(100) DEFAULT '' COMMENT 'mime类型', |
||||
|
`extparam` varchar(255) DEFAULT '' COMMENT '透传数据', |
||||
|
`createtime` bigint(16) DEFAULT NULL COMMENT '创建日期', |
||||
|
`updatetime` bigint(16) DEFAULT NULL COMMENT '更新时间', |
||||
|
`uploadtime` bigint(16) DEFAULT NULL COMMENT '上传时间', |
||||
|
`storage` varchar(100) NOT NULL DEFAULT 'local' COMMENT '存储位置', |
||||
|
`sha1` varchar(40) DEFAULT '' COMMENT '文件 sha1编码', |
||||
|
PRIMARY KEY (`id`) |
||||
|
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT='附件表'; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Records of fa_attachment |
||||
|
-- ---------------------------- |
||||
|
BEGIN; |
||||
|
INSERT INTO `fa_attachment` VALUES (1, '', 1, 0, '/assets/img/qrcode.png', '150', '150', 'png', 0, 'qrcode.png', 21859, 'image/png', '', 1491635035, 1491635035, 1491635035, 'local', '17163603d0263e4838b9387ff2cd4877e8b018f6'); |
||||
|
COMMIT; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Table structure for fa_auth_group |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `fa_auth_group`; |
||||
|
CREATE TABLE `fa_auth_group` ( |
||||
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, |
||||
|
`pid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '父组别', |
||||
|
`name` varchar(100) DEFAULT '' COMMENT '组名', |
||||
|
`rules` text NOT NULL COMMENT '规则ID', |
||||
|
`createtime` bigint(16) DEFAULT NULL COMMENT '创建时间', |
||||
|
`updatetime` bigint(16) DEFAULT NULL COMMENT '更新时间', |
||||
|
`status` varchar(30) DEFAULT '' COMMENT '状态', |
||||
|
PRIMARY KEY (`id`) |
||||
|
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT='分组表'; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Records of fa_auth_group |
||||
|
-- ---------------------------- |
||||
|
BEGIN; |
||||
|
INSERT INTO `fa_auth_group` VALUES (1, 0, 'Admin group', '*', 1491635035, 1491635035, 'normal'); |
||||
|
INSERT INTO `fa_auth_group` VALUES (2, 1, 'Second group', '13,14,16,15,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,40,41,42,43,44,45,46,47,48,49,50,55,56,57,58,59,60,61,62,63,64,65,1,9,10,11,7,6,8,2,4,5', 1491635035, 1491635035, 'normal'); |
||||
|
INSERT INTO `fa_auth_group` VALUES (3, 2, 'Third group', '1,4,9,10,11,13,14,15,16,17,40,41,42,43,44,45,46,47,48,49,50,55,56,57,58,59,60,61,62,63,64,65,5', 1491635035, 1491635035, 'normal'); |
||||
|
INSERT INTO `fa_auth_group` VALUES (4, 1, 'Second group 2', '1,4,13,14,15,16,17,55,56,57,58,59,60,61,62,63,64,65', 1491635035, 1491635035, 'normal'); |
||||
|
INSERT INTO `fa_auth_group` VALUES (5, 2, 'Third group 2', '1,2,6,7,8,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34', 1491635035, 1491635035, 'normal'); |
||||
|
COMMIT; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Table structure for fa_auth_group_access |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `fa_auth_group_access`; |
||||
|
CREATE TABLE `fa_auth_group_access` ( |
||||
|
`uid` int(10) unsigned NOT NULL COMMENT '会员ID', |
||||
|
`group_id` int(10) unsigned NOT NULL COMMENT '级别ID', |
||||
|
UNIQUE KEY `uid_group_id` (`uid`,`group_id`), |
||||
|
KEY `uid` (`uid`), |
||||
|
KEY `group_id` (`group_id`) |
||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT='权限分组表'; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Records of fa_auth_group_access |
||||
|
-- ---------------------------- |
||||
|
BEGIN; |
||||
|
INSERT INTO `fa_auth_group_access` VALUES (1, 1); |
||||
|
COMMIT; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Table structure for fa_auth_rule |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `fa_auth_rule`; |
||||
|
CREATE TABLE `fa_auth_rule` ( |
||||
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, |
||||
|
`type` enum('menu','file') NOT NULL DEFAULT 'file' COMMENT 'menu为菜单,file为权限节点', |
||||
|
`pid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '父ID', |
||||
|
`name` varchar(100) DEFAULT '' COMMENT '规则名称', |
||||
|
`title` varchar(50) DEFAULT '' COMMENT '规则名称', |
||||
|
`icon` varchar(50) DEFAULT '' COMMENT '图标', |
||||
|
`url` varchar(255) DEFAULT '' COMMENT '规则URL', |
||||
|
`condition` varchar(255) DEFAULT '' COMMENT '条件', |
||||
|
`remark` varchar(255) DEFAULT '' COMMENT '备注', |
||||
|
`ismenu` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '是否为菜单', |
||||
|
`menutype` enum('addtabs','blank','dialog','ajax') DEFAULT NULL COMMENT '菜单类型', |
||||
|
`extend` varchar(255) DEFAULT '' COMMENT '扩展属性', |
||||
|
`py` varchar(30) DEFAULT '' COMMENT '拼音首字母', |
||||
|
`pinyin` varchar(100) DEFAULT '' COMMENT '拼音', |
||||
|
`createtime` bigint(16) DEFAULT NULL COMMENT '创建时间', |
||||
|
`updatetime` bigint(16) DEFAULT NULL COMMENT '更新时间', |
||||
|
`weigh` int(10) NOT NULL DEFAULT '0' COMMENT '权重', |
||||
|
`status` varchar(30) DEFAULT '' COMMENT '状态', |
||||
|
PRIMARY KEY (`id`), |
||||
|
UNIQUE KEY `name` (`name`) USING BTREE, |
||||
|
KEY `pid` (`pid`), |
||||
|
KEY `weigh` (`weigh`) |
||||
|
) ENGINE=InnoDB AUTO_INCREMENT=66 DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT='节点表'; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Records of fa_auth_rule |
||||
|
-- ---------------------------- |
||||
|
BEGIN; |
||||
|
INSERT INTO `fa_auth_rule` VALUES (1, 'file', 0, 'dashboard', 'Dashboard', 'fa fa-dashboard', '', '', 'Dashboard tips', 1, NULL, '', 'kzt', 'kongzhitai', 1491635035, 1491635035, 143, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (2, 'file', 0, 'general', 'General', 'fa fa-cogs', '', '', '', 1, NULL, '', 'cggl', 'changguiguanli', 1491635035, 1491635035, 137, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (3, 'file', 0, 'category', 'Category', 'fa fa-leaf', '', '', 'Category tips', 0, NULL, '', 'flgl', 'fenleiguanli', 1491635035, 1491635035, 119, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (4, 'file', 0, 'addon', 'Addon', 'fa fa-rocket', '', '', 'Addon tips', 1, NULL, '', 'cjgl', 'chajianguanli', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (5, 'file', 0, 'auth', 'Auth', 'fa fa-group', '', '', '', 1, NULL, '', 'qxgl', 'quanxianguanli', 1491635035, 1491635035, 99, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (6, 'file', 2, 'general/config', 'Config', 'fa fa-cog', '', '', 'Config tips', 1, NULL, '', 'xtpz', 'xitongpeizhi', 1491635035, 1491635035, 60, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (7, 'file', 2, 'general/attachment', 'Attachment', 'fa fa-file-image-o', '', '', 'Attachment tips', 1, NULL, '', 'fjgl', 'fujianguanli', 1491635035, 1491635035, 53, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (8, 'file', 2, 'general/profile', 'Profile', 'fa fa-user', '', '', '', 1, NULL, '', 'grzl', 'gerenziliao', 1491635035, 1491635035, 34, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (9, 'file', 5, 'auth/admin', 'Admin', 'fa fa-user', '', '', 'Admin tips', 1, NULL, '', 'glygl', 'guanliyuanguanli', 1491635035, 1491635035, 118, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (10, 'file', 5, 'auth/adminlog', 'Admin log', 'fa fa-list-alt', '', '', 'Admin log tips', 1, NULL, '', 'glyrz', 'guanliyuanrizhi', 1491635035, 1491635035, 113, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (11, 'file', 5, 'auth/group', 'Group', 'fa fa-group', '', '', 'Group tips', 1, NULL, '', 'jsz', 'juesezu', 1491635035, 1491635035, 109, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (12, 'file', 5, 'auth/rule', 'Rule', 'fa fa-bars', '', '', 'Rule tips', 1, NULL, '', 'cdgz', 'caidanguize', 1491635035, 1491635035, 104, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (13, 'file', 1, 'dashboard/index', 'View', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 136, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (14, 'file', 1, 'dashboard/add', 'Add', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 135, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (15, 'file', 1, 'dashboard/del', 'Delete', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 133, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (16, 'file', 1, 'dashboard/edit', 'Edit', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 134, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (17, 'file', 1, 'dashboard/multi', 'Multi', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 132, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (18, 'file', 6, 'general/config/index', 'View', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 52, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (19, 'file', 6, 'general/config/add', 'Add', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 51, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (20, 'file', 6, 'general/config/edit', 'Edit', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 50, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (21, 'file', 6, 'general/config/del', 'Delete', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 49, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (22, 'file', 6, 'general/config/multi', 'Multi', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 48, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (23, 'file', 7, 'general/attachment/index', 'View', 'fa fa-circle-o', '', '', 'Attachment tips', 0, NULL, '', '', '', 1491635035, 1491635035, 59, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (24, 'file', 7, 'general/attachment/select', 'Select attachment', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 58, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (25, 'file', 7, 'general/attachment/add', 'Add', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 57, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (26, 'file', 7, 'general/attachment/edit', 'Edit', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 56, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (27, 'file', 7, 'general/attachment/del', 'Delete', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 55, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (28, 'file', 7, 'general/attachment/multi', 'Multi', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 54, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (29, 'file', 8, 'general/profile/index', 'View', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 33, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (30, 'file', 8, 'general/profile/update', 'Update profile', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 32, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (31, 'file', 8, 'general/profile/add', 'Add', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 31, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (32, 'file', 8, 'general/profile/edit', 'Edit', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 30, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (33, 'file', 8, 'general/profile/del', 'Delete', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 29, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (34, 'file', 8, 'general/profile/multi', 'Multi', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 28, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (35, 'file', 3, 'category/index', 'View', 'fa fa-circle-o', '', '', 'Category tips', 0, NULL, '', '', '', 1491635035, 1491635035, 142, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (36, 'file', 3, 'category/add', 'Add', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 141, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (37, 'file', 3, 'category/edit', 'Edit', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 140, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (38, 'file', 3, 'category/del', 'Delete', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 139, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (39, 'file', 3, 'category/multi', 'Multi', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 138, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (40, 'file', 9, 'auth/admin/index', 'View', 'fa fa-circle-o', '', '', 'Admin tips', 0, NULL, '', '', '', 1491635035, 1491635035, 117, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (41, 'file', 9, 'auth/admin/add', 'Add', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 116, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (42, 'file', 9, 'auth/admin/edit', 'Edit', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 115, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (43, 'file', 9, 'auth/admin/del', 'Delete', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 114, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (44, 'file', 10, 'auth/adminlog/index', 'View', 'fa fa-circle-o', '', '', 'Admin log tips', 0, NULL, '', '', '', 1491635035, 1491635035, 112, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (45, 'file', 10, 'auth/adminlog/detail', 'Detail', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 111, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (46, 'file', 10, 'auth/adminlog/del', 'Delete', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 110, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (47, 'file', 11, 'auth/group/index', 'View', 'fa fa-circle-o', '', '', 'Group tips', 0, NULL, '', '', '', 1491635035, 1491635035, 108, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (48, 'file', 11, 'auth/group/add', 'Add', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 107, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (49, 'file', 11, 'auth/group/edit', 'Edit', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 106, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (50, 'file', 11, 'auth/group/del', 'Delete', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 105, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (51, 'file', 12, 'auth/rule/index', 'View', 'fa fa-circle-o', '', '', 'Rule tips', 0, NULL, '', '', '', 1491635035, 1491635035, 103, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (52, 'file', 12, 'auth/rule/add', 'Add', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 102, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (53, 'file', 12, 'auth/rule/edit', 'Edit', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 101, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (54, 'file', 12, 'auth/rule/del', 'Delete', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 100, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (55, 'file', 4, 'addon/index', 'View', 'fa fa-circle-o', '', '', 'Addon tips', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (56, 'file', 4, 'addon/add', 'Add', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (57, 'file', 4, 'addon/edit', 'Edit', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (58, 'file', 4, 'addon/del', 'Delete', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (59, 'file', 4, 'addon/downloaded', 'Local addon', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (60, 'file', 4, 'addon/state', 'Update state', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (63, 'file', 4, 'addon/config', 'Setting', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (64, 'file', 4, 'addon/refresh', 'Refresh', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (65, 'file', 4, 'addon/multi', 'Multi', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (66, 'file', 0, 'user', 'User', 'fa fa-user-circle', '', '', '', 1, NULL, '', 'hygl', 'huiyuanguanli', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (67, 'file', 66, 'user/user', 'User', 'fa fa-user', '', '', '', 1, NULL, '', 'hygl', 'huiyuanguanli', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (68, 'file', 67, 'user/user/index', 'View', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (69, 'file', 67, 'user/user/edit', 'Edit', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (70, 'file', 67, 'user/user/add', 'Add', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (71, 'file', 67, 'user/user/del', 'Del', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (72, 'file', 67, 'user/user/multi', 'Multi', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (73, 'file', 66, 'user/group', 'User group', 'fa fa-users', '', '', '', 1, NULL, '', 'hyfz', 'huiyuanfenzu', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (74, 'file', 73, 'user/group/add', 'Add', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (75, 'file', 73, 'user/group/edit', 'Edit', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (76, 'file', 73, 'user/group/index', 'View', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (77, 'file', 73, 'user/group/del', 'Del', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (78, 'file', 73, 'user/group/multi', 'Multi', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (79, 'file', 66, 'user/rule', 'User rule', 'fa fa-circle-o', '', '', '', 1, NULL, '', 'hygz', 'huiyuanguize', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (80, 'file', 79, 'user/rule/index', 'View', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (81, 'file', 79, 'user/rule/del', 'Del', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (82, 'file', 79, 'user/rule/add', 'Add', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (83, 'file', 79, 'user/rule/edit', 'Edit', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
INSERT INTO `fa_auth_rule` VALUES (84, 'file', 79, 'user/rule/multi', 'Multi', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', 1491635035, 1491635035, 0, 'normal'); |
||||
|
COMMIT; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Table structure for fa_category |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `fa_category`; |
||||
|
CREATE TABLE `fa_category` ( |
||||
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, |
||||
|
`pid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '父ID', |
||||
|
`type` varchar(30) DEFAULT '' COMMENT '栏目类型', |
||||
|
`name` varchar(30) DEFAULT '', |
||||
|
`nickname` varchar(50) DEFAULT '', |
||||
|
`flag` set('hot','index','recommend') DEFAULT '', |
||||
|
`image` varchar(100) DEFAULT '' COMMENT '图片', |
||||
|
`keywords` varchar(255) DEFAULT '' COMMENT '关键字', |
||||
|
`description` varchar(255) DEFAULT '' COMMENT '描述', |
||||
|
`diyname` varchar(30) DEFAULT '' COMMENT '自定义名称', |
||||
|
`createtime` bigint(16) DEFAULT NULL COMMENT '创建时间', |
||||
|
`updatetime` bigint(16) DEFAULT NULL COMMENT '更新时间', |
||||
|
`weigh` int(10) NOT NULL DEFAULT '0' COMMENT '权重', |
||||
|
`status` varchar(30) DEFAULT '' COMMENT '状态', |
||||
|
PRIMARY KEY (`id`), |
||||
|
KEY `weigh` (`weigh`,`id`), |
||||
|
KEY `pid` (`pid`) |
||||
|
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT='分类表'; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Records of fa_category |
||||
|
-- ---------------------------- |
||||
|
BEGIN; |
||||
|
INSERT INTO `fa_category` VALUES (1, 0, 'page', '官方新闻', 'news', 'recommend', '/assets/img/qrcode.png', '', '', 'news', 1491635035, 1491635035, 1, 'normal'); |
||||
|
INSERT INTO `fa_category` VALUES (2, 0, 'page', '移动应用', 'mobileapp', 'hot', '/assets/img/qrcode.png', '', '', 'mobileapp', 1491635035, 1491635035, 2, 'normal'); |
||||
|
INSERT INTO `fa_category` VALUES (3, 2, 'page', '微信公众号', 'wechatpublic', 'index', '/assets/img/qrcode.png', '', '', 'wechatpublic', 1491635035, 1491635035, 3, 'normal'); |
||||
|
INSERT INTO `fa_category` VALUES (4, 2, 'page', 'Android开发', 'android', 'recommend', '/assets/img/qrcode.png', '', '', 'android', 1491635035, 1491635035, 4, 'normal'); |
||||
|
INSERT INTO `fa_category` VALUES (5, 0, 'page', '软件产品', 'software', 'recommend', '/assets/img/qrcode.png', '', '', 'software', 1491635035, 1491635035, 5, 'normal'); |
||||
|
INSERT INTO `fa_category` VALUES (6, 5, 'page', '网站建站', 'website', 'recommend', '/assets/img/qrcode.png', '', '', 'website', 1491635035, 1491635035, 6, 'normal'); |
||||
|
INSERT INTO `fa_category` VALUES (7, 5, 'page', '企业管理软件', 'company', 'index', '/assets/img/qrcode.png', '', '', 'company', 1491635035, 1491635035, 7, 'normal'); |
||||
|
INSERT INTO `fa_category` VALUES (8, 6, 'page', 'PC端', 'website-pc', 'recommend', '/assets/img/qrcode.png', '', '', 'website-pc', 1491635035, 1491635035, 8, 'normal'); |
||||
|
INSERT INTO `fa_category` VALUES (9, 6, 'page', '移动端', 'website-mobile', 'recommend', '/assets/img/qrcode.png', '', '', 'website-mobile', 1491635035, 1491635035, 9, 'normal'); |
||||
|
INSERT INTO `fa_category` VALUES (10, 7, 'page', 'CRM系统 ', 'company-crm', 'recommend', '/assets/img/qrcode.png', '', '', 'company-crm', 1491635035, 1491635035, 10, 'normal'); |
||||
|
INSERT INTO `fa_category` VALUES (11, 7, 'page', 'SASS平台软件', 'company-sass', 'recommend', '/assets/img/qrcode.png', '', '', 'company-sass', 1491635035, 1491635035, 11, 'normal'); |
||||
|
INSERT INTO `fa_category` VALUES (12, 0, 'test', '测试1', 'test1', 'recommend', '/assets/img/qrcode.png', '', '', 'test1', 1491635035, 1491635035, 12, 'normal'); |
||||
|
INSERT INTO `fa_category` VALUES (13, 0, 'test', '测试2', 'test2', 'recommend', '/assets/img/qrcode.png', '', '', 'test2', 1491635035, 1491635035, 13, 'normal'); |
||||
|
COMMIT; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Table structure for fa_config |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `fa_config`; |
||||
|
CREATE TABLE `fa_config` ( |
||||
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, |
||||
|
`name` varchar(30) DEFAULT '' COMMENT '变量名', |
||||
|
`group` varchar(30) DEFAULT '' COMMENT '分组', |
||||
|
`title` varchar(100) DEFAULT '' COMMENT '变量标题', |
||||
|
`tip` varchar(100) DEFAULT '' COMMENT '变量描述', |
||||
|
`type` varchar(30) DEFAULT '' COMMENT '类型:string,text,int,bool,array,datetime,date,file', |
||||
|
`visible` varchar(255) DEFAULT '' COMMENT '可见条件', |
||||
|
`value` text COMMENT '变量值', |
||||
|
`content` text COMMENT '变量字典数据', |
||||
|
`rule` varchar(100) DEFAULT '' COMMENT '验证规则', |
||||
|
`extend` varchar(255) DEFAULT '' COMMENT '扩展属性', |
||||
|
`setting` varchar(255) DEFAULT '' COMMENT '配置', |
||||
|
PRIMARY KEY (`id`), |
||||
|
UNIQUE KEY `name` (`name`) |
||||
|
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT='系统配置'; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Records of fa_config |
||||
|
-- ---------------------------- |
||||
|
BEGIN; |
||||
|
INSERT INTO `fa_config` VALUES (1, 'name', 'basic', 'Site name', '请填写站点名称', 'string', '', '我的网站', '', 'required', '', ''); |
||||
|
INSERT INTO `fa_config` VALUES (2, 'beian', 'basic', 'Beian', '粤ICP备15000000号-1', 'string', '', '', '', '', '', ''); |
||||
|
INSERT INTO `fa_config` VALUES (3, 'cdnurl', 'basic', 'Cdn url', '如果全站静态资源使用第三方云储存请配置该值', 'string', '', '', '', '', '', ''); |
||||
|
INSERT INTO `fa_config` VALUES (4, 'version', 'basic', 'Version', '如果静态资源有变动请重新配置该值', 'string', '', '1.0.1', '', 'required', '', ''); |
||||
|
INSERT INTO `fa_config` VALUES (5, 'timezone', 'basic', 'Timezone', '', 'string', '', 'Asia/Shanghai', '', 'required', '', ''); |
||||
|
INSERT INTO `fa_config` VALUES (6, 'forbiddenip', 'basic', 'Forbidden ip', '一行一条记录', 'text', '', '', '', '', '', ''); |
||||
|
INSERT INTO `fa_config` VALUES (7, 'languages', 'basic', 'Languages', '', 'array', '', '{\"backend\":\"zh-cn\",\"frontend\":\"zh-cn\"}', '', 'required', '', ''); |
||||
|
INSERT INTO `fa_config` VALUES (8, 'fixedpage', 'basic', 'Fixed page', '请尽量输入左侧菜单栏存在的链接', 'string', '', 'dashboard', '', 'required', '', ''); |
||||
|
INSERT INTO `fa_config` VALUES (9, 'categorytype', 'dictionary', 'Category type', '', 'array', '', '{\"default\":\"Default\",\"page\":\"Page\",\"article\":\"Article\",\"test\":\"Test\"}', '', '', '', ''); |
||||
|
INSERT INTO `fa_config` VALUES (10, 'configgroup', 'dictionary', 'Config group', '', 'array', '', '{\"basic\":\"Basic\",\"email\":\"Email\",\"dictionary\":\"Dictionary\",\"user\":\"User\",\"example\":\"Example\"}', '', '', '', ''); |
||||
|
INSERT INTO `fa_config` VALUES (11, 'mail_type', 'email', 'Mail type', '选择邮件发送方式', 'select', '', '1', '[\"请选择\",\"SMTP\"]', '', '', ''); |
||||
|
INSERT INTO `fa_config` VALUES (12, 'mail_smtp_host', 'email', 'Mail smtp host', '错误的配置发送邮件会导致服务器超时', 'string', '', 'smtp.qq.com', '', '', '', ''); |
||||
|
INSERT INTO `fa_config` VALUES (13, 'mail_smtp_port', 'email', 'Mail smtp port', '(不加密默认25,SSL默认465,TLS默认587)', 'string', '', '465', '', '', '', ''); |
||||
|
INSERT INTO `fa_config` VALUES (14, 'mail_smtp_user', 'email', 'Mail smtp user', '(填写完整用户名)', 'string', '', '10000', '', '', '', ''); |
||||
|
INSERT INTO `fa_config` VALUES (15, 'mail_smtp_pass', 'email', 'Mail smtp password', '(填写您的密码或授权码)', 'string', '', 'password', '', '', '', ''); |
||||
|
INSERT INTO `fa_config` VALUES (16, 'mail_verify_type', 'email', 'Mail vertify type', '(SMTP验证方式[推荐SSL])', 'select', '', '2', '[\"无\",\"TLS\",\"SSL\"]', '', '', ''); |
||||
|
INSERT INTO `fa_config` VALUES (17, 'mail_from', 'email', 'Mail from', '', 'string', '', '10000@qq.com', '', '', '', ''); |
||||
|
INSERT INTO `fa_config` VALUES (18, 'attachmentcategory', 'dictionary', 'Attachment category', '', 'array', '', '{\"category1\":\"Category1\",\"category2\":\"Category2\",\"custom\":\"Custom\"}', '', '', '', ''); |
||||
|
COMMIT; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Table structure for fa_ems |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `fa_ems`; |
||||
|
CREATE TABLE `fa_ems` ( |
||||
|
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID', |
||||
|
`event` varchar(30) DEFAULT '' COMMENT '事件', |
||||
|
`email` varchar(100) DEFAULT '' COMMENT '邮箱', |
||||
|
`code` varchar(10) DEFAULT '' COMMENT '验证码', |
||||
|
`times` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '验证次数', |
||||
|
`ip` varchar(30) DEFAULT '' COMMENT 'IP', |
||||
|
`createtime` bigint(16) DEFAULT NULL COMMENT '创建时间', |
||||
|
PRIMARY KEY (`id`) USING BTREE |
||||
|
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT='邮箱验证码表'; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Table structure for fa_sms |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `fa_sms`; |
||||
|
CREATE TABLE `fa_sms` ( |
||||
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', |
||||
|
`event` varchar(30) DEFAULT '' COMMENT '事件', |
||||
|
`mobile` varchar(20) DEFAULT '' COMMENT '手机号', |
||||
|
`code` varchar(10) DEFAULT '' COMMENT '验证码', |
||||
|
`times` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '验证次数', |
||||
|
`ip` varchar(30) DEFAULT '' COMMENT 'IP', |
||||
|
`createtime` bigint(16) unsigned DEFAULT '0' COMMENT '创建时间', |
||||
|
PRIMARY KEY (`id`) |
||||
|
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT='短信验证码表'; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Table structure for fa_test |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `fa_test`; |
||||
|
CREATE TABLE `fa_test` ( |
||||
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', |
||||
|
`user_id` int(10) DEFAULT '0' COMMENT '会员ID', |
||||
|
`admin_id` int(10) DEFAULT '0' COMMENT '管理员ID', |
||||
|
`category_id` int(10) unsigned DEFAULT '0' COMMENT '分类ID(单选)', |
||||
|
`category_ids` varchar(100) COMMENT '分类ID(多选)', |
||||
|
`tags` varchar(255) DEFAULT '' COMMENT '标签', |
||||
|
`week` enum('monday','tuesday','wednesday') COMMENT '星期(单选):monday=星期一,tuesday=星期二,wednesday=星期三', |
||||
|
`flag` set('hot','index','recommend') DEFAULT '' COMMENT '标志(多选):hot=热门,index=首页,recommend=推荐', |
||||
|
`genderdata` enum('male','female') DEFAULT 'male' COMMENT '性别(单选):male=男,female=女', |
||||
|
`hobbydata` set('music','reading','swimming') COMMENT '爱好(多选):music=音乐,reading=读书,swimming=游泳', |
||||
|
`title` varchar(100) DEFAULT '' COMMENT '标题', |
||||
|
`content` text COMMENT '内容', |
||||
|
`image` varchar(100) DEFAULT '' COMMENT '图片', |
||||
|
`images` varchar(1500) DEFAULT '' COMMENT '图片组', |
||||
|
`attachfile` varchar(100) DEFAULT '' COMMENT '附件', |
||||
|
`keywords` varchar(255) DEFAULT '' COMMENT '关键字', |
||||
|
`description` varchar(255) DEFAULT '' COMMENT '描述', |
||||
|
`city` varchar(100) DEFAULT '' COMMENT '省市', |
||||
|
`json` varchar(255) DEFAULT NULL COMMENT '配置:key=名称,value=值', |
||||
|
`multiplejson` varchar(1500) DEFAULT '' COMMENT '二维数组:title=标题,intro=介绍,author=作者,age=年龄', |
||||
|
`price` decimal(10,2) unsigned DEFAULT '0.00' COMMENT '价格', |
||||
|
`views` int(10) unsigned DEFAULT '0' COMMENT '点击', |
||||
|
`workrange` varchar(100) DEFAULT '' COMMENT '时间区间', |
||||
|
`startdate` date DEFAULT NULL COMMENT '开始日期', |
||||
|
`activitytime` datetime DEFAULT NULL COMMENT '活动时间(datetime)', |
||||
|
`year` year(4) DEFAULT NULL COMMENT '年', |
||||
|
`times` time DEFAULT NULL COMMENT '时间', |
||||
|
`refreshtime` bigint(16) DEFAULT NULL COMMENT '刷新时间', |
||||
|
`createtime` bigint(16) DEFAULT NULL COMMENT '创建时间', |
||||
|
`updatetime` bigint(16) DEFAULT NULL COMMENT '更新时间', |
||||
|
`deletetime` bigint(16) DEFAULT NULL COMMENT '删除时间', |
||||
|
`weigh` int(10) DEFAULT '0' COMMENT '权重', |
||||
|
`switch` tinyint(1) DEFAULT '0' COMMENT '开关', |
||||
|
`status` enum('normal','hidden') DEFAULT 'normal' COMMENT '状态', |
||||
|
`state` enum('0','1','2') DEFAULT '1' COMMENT '状态值:0=禁用,1=正常,2=推荐', |
||||
|
PRIMARY KEY (`id`) |
||||
|
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT='测试表'; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Records of fa_test |
||||
|
-- ---------------------------- |
||||
|
BEGIN; |
||||
|
INSERT INTO `fa_test` VALUES (1, 1, 1, 12, '12,13', '互联网,计算机', 'monday', 'hot,index', 'male', 'music,reading', '我是一篇测试文章', '<p>我是测试内容</p>', '/assets/img/avatar.png', '/assets/img/avatar.png,/assets/img/qrcode.png', '/assets/img/avatar.png', '关键字', '描述', '广西壮族自治区/百色市/平果县', '{\"a\":\"1\",\"b\":\"2\"}', '[{\"title\":\"标题一\",\"intro\":\"介绍一\",\"author\":\"小明\",\"age\":\"21\"}]', 0.00, 0, '2020-10-01 00:00:00 - 2021-10-31 23:59:59', '2017-07-10', '2017-07-10 18:24:45', 2017, '18:24:45', 1491635035, 1491635035, 1491635035, NULL, 0, 1, 'normal', '1'); |
||||
|
COMMIT; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Table structure for fa_user |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `fa_user`; |
||||
|
CREATE TABLE `fa_user` ( |
||||
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', |
||||
|
`group_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '组别ID', |
||||
|
`username` varchar(32) DEFAULT '' COMMENT '用户名', |
||||
|
`nickname` varchar(50) DEFAULT '' COMMENT '昵称', |
||||
|
`password` varchar(32) DEFAULT '' COMMENT '密码', |
||||
|
`salt` varchar(30) DEFAULT '' COMMENT '密码盐', |
||||
|
`email` varchar(100) DEFAULT '' COMMENT '电子邮箱', |
||||
|
`mobile` varchar(11) DEFAULT '' COMMENT '手机号', |
||||
|
`avatar` varchar(255) DEFAULT '' COMMENT '头像', |
||||
|
`level` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '等级', |
||||
|
`gender` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '性别', |
||||
|
`birthday` date DEFAULT NULL COMMENT '生日', |
||||
|
`bio` varchar(100) DEFAULT '' COMMENT '格言', |
||||
|
`money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '余额', |
||||
|
`score` int(10) NOT NULL DEFAULT '0' COMMENT '积分', |
||||
|
`successions` int(10) unsigned NOT NULL DEFAULT '1' COMMENT '连续登录天数', |
||||
|
`maxsuccessions` int(10) unsigned NOT NULL DEFAULT '1' COMMENT '最大连续登录天数', |
||||
|
`prevtime` bigint(16) DEFAULT NULL COMMENT '上次登录时间', |
||||
|
`logintime` bigint(16) DEFAULT NULL COMMENT '登录时间', |
||||
|
`loginip` varchar(50) DEFAULT '' COMMENT '登录IP', |
||||
|
`loginfailure` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '失败次数', |
||||
|
`joinip` varchar(50) DEFAULT '' COMMENT '加入IP', |
||||
|
`jointime` bigint(16) DEFAULT NULL COMMENT '加入时间', |
||||
|
`createtime` bigint(16) DEFAULT NULL COMMENT '创建时间', |
||||
|
`updatetime` bigint(16) DEFAULT NULL COMMENT '更新时间', |
||||
|
`token` varchar(50) DEFAULT '' COMMENT 'Token', |
||||
|
`status` varchar(30) DEFAULT '' COMMENT '状态', |
||||
|
`verification` varchar(255) DEFAULT '' COMMENT '验证', |
||||
|
PRIMARY KEY (`id`), |
||||
|
KEY `username` (`username`), |
||||
|
KEY `email` (`email`), |
||||
|
KEY `mobile` (`mobile`) |
||||
|
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT='会员表'; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Records of fa_user |
||||
|
-- ---------------------------- |
||||
|
BEGIN; |
||||
|
INSERT INTO `fa_user` VALUES (1, 1, 'admin', 'admin', '', '', 'admin@163.com', '13888888888', '', 0, 0, '2017-04-08', '', 0, 0, 1, 1, 1491635035, 1491635035, '127.0.0.1', 0, '127.0.0.1', 1491635035, 0, 1491635035, '', 'normal',''); |
||||
|
COMMIT; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Table structure for fa_user_group |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `fa_user_group`; |
||||
|
CREATE TABLE `fa_user_group` ( |
||||
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, |
||||
|
`name` varchar(50) DEFAULT '' COMMENT '组名', |
||||
|
`rules` text COMMENT '权限节点', |
||||
|
`createtime` bigint(16) DEFAULT NULL COMMENT '添加时间', |
||||
|
`updatetime` bigint(16) DEFAULT NULL COMMENT '更新时间', |
||||
|
`status` enum('normal','hidden') DEFAULT NULL COMMENT '状态', |
||||
|
PRIMARY KEY (`id`) |
||||
|
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT='会员组表'; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Records of fa_user_group |
||||
|
-- ---------------------------- |
||||
|
BEGIN; |
||||
|
INSERT INTO `fa_user_group` VALUES (1, '默认组', '1,2,3,4,5,6,7,8,9,10,11,12', 1491635035, 1491635035, 'normal'); |
||||
|
COMMIT; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Table structure for fa_user_money_log |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `fa_user_money_log`; |
||||
|
CREATE TABLE `fa_user_money_log` ( |
||||
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, |
||||
|
`user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '会员ID', |
||||
|
`money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '变更余额', |
||||
|
`before` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '变更前余额', |
||||
|
`after` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '变更后余额', |
||||
|
`memo` varchar(255) DEFAULT '' COMMENT '备注', |
||||
|
`createtime` bigint(16) DEFAULT NULL COMMENT '创建时间', |
||||
|
PRIMARY KEY (`id`) |
||||
|
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT='会员余额变动表'; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Table structure for fa_user_rule |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `fa_user_rule`; |
||||
|
CREATE TABLE `fa_user_rule` ( |
||||
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, |
||||
|
`pid` int(10) DEFAULT NULL COMMENT '父ID', |
||||
|
`name` varchar(50) DEFAULT NULL COMMENT '名称', |
||||
|
`title` varchar(50) DEFAULT '' COMMENT '标题', |
||||
|
`remark` varchar(100) DEFAULT NULL COMMENT '备注', |
||||
|
`ismenu` tinyint(1) DEFAULT NULL COMMENT '是否菜单', |
||||
|
`createtime` bigint(16) DEFAULT NULL COMMENT '创建时间', |
||||
|
`updatetime` bigint(16) DEFAULT NULL COMMENT '更新时间', |
||||
|
`weigh` int(10) DEFAULT '0' COMMENT '权重', |
||||
|
`status` enum('normal','hidden') DEFAULT NULL COMMENT '状态', |
||||
|
PRIMARY KEY (`id`) |
||||
|
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT='会员规则表'; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Records of fa_user_rule |
||||
|
-- ---------------------------- |
||||
|
BEGIN; |
||||
|
INSERT INTO `fa_user_rule` VALUES (1, 0, 'index', 'Frontend', '', 1, 1491635035, 1491635035, 1, 'normal'); |
||||
|
INSERT INTO `fa_user_rule` VALUES (2, 0, 'api', 'API Interface', '', 1, 1491635035, 1491635035, 2, 'normal'); |
||||
|
INSERT INTO `fa_user_rule` VALUES (3, 1, 'user', 'User Module', '', 1, 1491635035, 1491635035, 12, 'normal'); |
||||
|
INSERT INTO `fa_user_rule` VALUES (4, 2, 'user', 'User Module', '', 1, 1491635035, 1491635035, 11, 'normal'); |
||||
|
INSERT INTO `fa_user_rule` VALUES (5, 3, 'index/user/login', 'Login', '', 0, 1491635035, 1491635035, 5, 'normal'); |
||||
|
INSERT INTO `fa_user_rule` VALUES (6, 3, 'index/user/register', 'Register', '', 0, 1491635035, 1491635035, 7, 'normal'); |
||||
|
INSERT INTO `fa_user_rule` VALUES (7, 3, 'index/user/index', 'User Center', '', 0, 1491635035, 1491635035, 9, 'normal'); |
||||
|
INSERT INTO `fa_user_rule` VALUES (8, 3, 'index/user/profile', 'Profile', '', 0, 1491635035, 1491635035, 4, 'normal'); |
||||
|
INSERT INTO `fa_user_rule` VALUES (9, 4, 'api/user/login', 'Login', '', 0, 1491635035, 1491635035, 6, 'normal'); |
||||
|
INSERT INTO `fa_user_rule` VALUES (10, 4, 'api/user/register', 'Register', '', 0, 1491635035, 1491635035, 8, 'normal'); |
||||
|
INSERT INTO `fa_user_rule` VALUES (11, 4, 'api/user/index', 'User Center', '', 0, 1491635035, 1491635035, 10, 'normal'); |
||||
|
INSERT INTO `fa_user_rule` VALUES (12, 4, 'api/user/profile', 'Profile', '', 0, 1491635035, 1491635035, 3, 'normal'); |
||||
|
COMMIT; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Table structure for fa_user_score_log |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `fa_user_score_log`; |
||||
|
CREATE TABLE `fa_user_score_log` ( |
||||
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, |
||||
|
`user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '会员ID', |
||||
|
`score` int(10) NOT NULL DEFAULT '0' COMMENT '变更积分', |
||||
|
`before` int(10) NOT NULL DEFAULT '0' COMMENT '变更前积分', |
||||
|
`after` int(10) NOT NULL DEFAULT '0' COMMENT '变更后积分', |
||||
|
`memo` varchar(255) DEFAULT '' COMMENT '备注', |
||||
|
`createtime` bigint(16) DEFAULT NULL COMMENT '创建时间', |
||||
|
PRIMARY KEY (`id`) |
||||
|
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT='会员积分变动表'; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Table structure for fa_user_token |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `fa_user_token`; |
||||
|
CREATE TABLE `fa_user_token` ( |
||||
|
`token` varchar(50) NOT NULL COMMENT 'Token', |
||||
|
`user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '会员ID', |
||||
|
`createtime` bigint(16) DEFAULT NULL COMMENT '创建时间', |
||||
|
`expiretime` bigint(16) DEFAULT NULL COMMENT '过期时间', |
||||
|
PRIMARY KEY (`token`) |
||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT='会员Token表'; |
||||
|
|
||||
|
-- ---------------------------- |
||||
|
-- Table structure for fa_version |
||||
|
-- ---------------------------- |
||||
|
DROP TABLE IF EXISTS `fa_version`; |
||||
|
CREATE TABLE `fa_version` ( |
||||
|
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID', |
||||
|
`oldversion` varchar(30) DEFAULT '' COMMENT '旧版本号', |
||||
|
`newversion` varchar(30) DEFAULT '' COMMENT '新版本号', |
||||
|
`packagesize` varchar(30) DEFAULT '' COMMENT '包大小', |
||||
|
`content` varchar(500) DEFAULT '' COMMENT '升级内容', |
||||
|
`downloadurl` varchar(255) DEFAULT '' COMMENT '下载地址', |
||||
|
`enforce` tinyint(1) UNSIGNED NOT NULL DEFAULT 0 COMMENT '强制更新', |
||||
|
`createtime` bigint(16) DEFAULT NULL COMMENT '创建时间', |
||||
|
`updatetime` bigint(16) DEFAULT NULL COMMENT '更新时间', |
||||
|
`weigh` int(10) NOT NULL DEFAULT 0 COMMENT '权重', |
||||
|
`status` varchar(30) DEFAULT '' COMMENT '状态', |
||||
|
PRIMARY KEY (`id`) USING BTREE |
||||
|
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT='版本表'; |
||||
|
|
||||
|
SET FOREIGN_KEY_CHECKS = 1; |
||||
@ -0,0 +1,316 @@ |
|||||
|
<!doctype html> |
||||
|
<html> |
||||
|
<head> |
||||
|
<meta charset="utf-8"> |
||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
||||
|
<title>{:__('Installing FastAdmin')}</title> |
||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1"> |
||||
|
<meta name="renderer" content="webkit"> |
||||
|
|
||||
|
<style> |
||||
|
body { |
||||
|
background: #f1f6fd; |
||||
|
margin: 0; |
||||
|
padding: 0; |
||||
|
line-height: 1.5; |
||||
|
-webkit-font-smoothing: antialiased; |
||||
|
-moz-osx-font-smoothing: grayscale; |
||||
|
} |
||||
|
|
||||
|
body, input, button { |
||||
|
font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, 'Microsoft Yahei', Arial, sans-serif; |
||||
|
font-size: 14px; |
||||
|
color: #7E96B3; |
||||
|
} |
||||
|
|
||||
|
.container { |
||||
|
max-width: 480px; |
||||
|
margin: 0 auto; |
||||
|
padding: 20px; |
||||
|
text-align: center; |
||||
|
} |
||||
|
|
||||
|
a { |
||||
|
color: #4e73df; |
||||
|
text-decoration: none; |
||||
|
} |
||||
|
|
||||
|
a:hover { |
||||
|
text-decoration: underline; |
||||
|
} |
||||
|
|
||||
|
h1 { |
||||
|
margin-top: 0; |
||||
|
margin-bottom: 10px; |
||||
|
} |
||||
|
|
||||
|
h2 { |
||||
|
font-size: 28px; |
||||
|
font-weight: normal; |
||||
|
color: #3C5675; |
||||
|
margin-bottom: 0; |
||||
|
margin-top: 0; |
||||
|
} |
||||
|
|
||||
|
form { |
||||
|
margin-top: 40px; |
||||
|
} |
||||
|
|
||||
|
.form-group { |
||||
|
margin-bottom: 20px; |
||||
|
} |
||||
|
|
||||
|
.form-group .form-field:first-child input { |
||||
|
border-top-left-radius: 4px; |
||||
|
border-top-right-radius: 4px; |
||||
|
} |
||||
|
|
||||
|
.form-group .form-field:last-child input { |
||||
|
border-bottom-left-radius: 4px; |
||||
|
border-bottom-right-radius: 4px; |
||||
|
} |
||||
|
|
||||
|
.form-field input { |
||||
|
background: #fff; |
||||
|
margin: 0 0 2px; |
||||
|
border: 2px solid transparent; |
||||
|
transition: background 0.2s, border-color 0.2s, color 0.2s; |
||||
|
width: 100%; |
||||
|
padding: 15px 15px 15px 180px; |
||||
|
box-sizing: border-box; |
||||
|
} |
||||
|
|
||||
|
.form-field input:focus { |
||||
|
border-color: #4e73df; |
||||
|
background: #fff; |
||||
|
color: #444; |
||||
|
outline: none; |
||||
|
} |
||||
|
|
||||
|
.form-field label { |
||||
|
float: left; |
||||
|
width: 160px; |
||||
|
text-align: right; |
||||
|
margin-right: -160px; |
||||
|
position: relative; |
||||
|
margin-top: 15px; |
||||
|
font-size: 14px; |
||||
|
pointer-events: none; |
||||
|
opacity: 0.7; |
||||
|
} |
||||
|
|
||||
|
button, .btn { |
||||
|
background: #3C5675; |
||||
|
color: #fff; |
||||
|
border: 0; |
||||
|
font-weight: bold; |
||||
|
border-radius: 4px; |
||||
|
cursor: pointer; |
||||
|
padding: 15px 30px; |
||||
|
-webkit-appearance: none; |
||||
|
} |
||||
|
|
||||
|
button[disabled] { |
||||
|
opacity: 0.5; |
||||
|
} |
||||
|
|
||||
|
.form-buttons { |
||||
|
height: 52px; |
||||
|
line-height: 52px; |
||||
|
} |
||||
|
|
||||
|
.form-buttons .btn { |
||||
|
margin-right: 5px; |
||||
|
} |
||||
|
|
||||
|
#error, .error, #success, .success, #warmtips, .warmtips { |
||||
|
background: #D83E3E; |
||||
|
color: #fff; |
||||
|
padding: 15px 20px; |
||||
|
border-radius: 4px; |
||||
|
margin-bottom: 20px; |
||||
|
} |
||||
|
|
||||
|
#success { |
||||
|
background: #3C5675; |
||||
|
} |
||||
|
|
||||
|
#error a, .error a { |
||||
|
color: white; |
||||
|
text-decoration: underline; |
||||
|
} |
||||
|
|
||||
|
#warmtips { |
||||
|
background: #ffcdcd; |
||||
|
font-size: 14px; |
||||
|
color: #e74c3c; |
||||
|
} |
||||
|
|
||||
|
#warmtips a { |
||||
|
background: #ffffff7a; |
||||
|
display: block; |
||||
|
height: 30px; |
||||
|
line-height: 30px; |
||||
|
margin-top: 10px; |
||||
|
color: #e21a1a; |
||||
|
border-radius: 3px; |
||||
|
} |
||||
|
</style> |
||||
|
</head> |
||||
|
|
||||
|
<body> |
||||
|
<div class="container"> |
||||
|
<h1> |
||||
|
<svg width="80px" height="96px" viewBox="0 0 768 830" version="1.1" xmlns="http://www.w3.org/2000/svg" |
||||
|
xmlns:xlink="http://www.w3.org/1999/xlink"> |
||||
|
<g id="logo" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> |
||||
|
<path d="M64.433651,605.899968 C20.067302,536.265612 0,469.698785 0,389.731348 C0,174.488668 171.922656,0 384,0 C596.077344,0 768,174.488668 768,389.731348 C768,469.698785 747.932698,536.265612 703.566349,605.899968 C614.4,753.480595 441.6,870.4 384,870.4 C326.4,870.4 153.6,753.480595 64.433651,605.899968 L64.433651,605.899968 Z" |
||||
|
id="body" fill="#4e73df"></path> |
||||
|
<path d="M429.648991,190.816 L430.160991,190.816 L429.648991,190.816 L429.648991,190.816 Z M429.648991,156 L427.088991,156 C419.408991,157.024 411.728991,160.608 404.560991,168.8 L403.024991,170.848 L206.928991,429.92 C198.736991,441.184 197.712991,453.984 204.368991,466.784 C210.512991,478.048 222.288991,485.728 235.600991,485.728 L336.464991,486.24 L304.208991,673.632 C301.648991,689.504 310.352991,705.376 325.200991,712.032 C329.808991,714.08 334.416991,714.592 339.536991,714.592 C349.776991,714.592 358.992991,709.472 366.160991,700.256 L561.744991,419.168 C569.936991,407.904 570.960991,395.104 564.304991,382.304 C557.648991,369.504 547.408991,363.36 533.072991,363.36 L432.208991,363.36 L463.952991,199.008 C464.464991,196.448 464.976991,193.376 464.976991,190.816 C464.976991,171.872 449.104991,156 431.184991,156 L429.648991,156 L429.648991,156 Z" |
||||
|
id="flash" fill="#FFFFFF"></path> |
||||
|
</g> |
||||
|
</svg> |
||||
|
</h1> |
||||
|
<h2>{:__('Installing FastAdmin')}</h2> |
||||
|
<div> |
||||
|
|
||||
|
<form method="post"> |
||||
|
{if $errInfo} |
||||
|
<div class="error"> |
||||
|
{$errInfo} |
||||
|
</div> |
||||
|
{/if} |
||||
|
<div id="error" style="display:none"></div> |
||||
|
<div id="success" style="display:none"></div> |
||||
|
<div id="warmtips" style="display:none"></div> |
||||
|
|
||||
|
<div class="form-group"> |
||||
|
<div class="form-field"> |
||||
|
<label>{:__('Mysql Hostname')}</label> |
||||
|
<input type="text" name="mysqlHostname" value="127.0.0.1" required=""> |
||||
|
</div> |
||||
|
|
||||
|
<div class="form-field"> |
||||
|
<label>{:__('Mysql Database')}</label> |
||||
|
<input type="text" name="mysqlDatabase" value="" required=""> |
||||
|
</div> |
||||
|
|
||||
|
<div class="form-field"> |
||||
|
<label>{:__('Mysql Username')}</label> |
||||
|
<input type="text" name="mysqlUsername" value="root" required=""> |
||||
|
</div> |
||||
|
|
||||
|
<div class="form-field"> |
||||
|
<label>{:__('Mysql Password')}</label> |
||||
|
<input type="password" name="mysqlPassword"> |
||||
|
</div> |
||||
|
|
||||
|
<div class="form-field"> |
||||
|
<label>{:__('Mysql Prefix')}</label> |
||||
|
<input type="text" name="mysqlPrefix" value="fa_"> |
||||
|
</div> |
||||
|
|
||||
|
<div class="form-field"> |
||||
|
<label>{:__('Mysql Hostport')}</label> |
||||
|
<input type="number" name="mysqlHostport" value="3306"> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
<div class="form-group"> |
||||
|
<div class="form-field"> |
||||
|
<label>{:__('Admin Username')}</label> |
||||
|
<input name="adminUsername" value="admin" required=""/> |
||||
|
</div> |
||||
|
|
||||
|
<div class="form-field"> |
||||
|
<label>{:__('Admin Email')}</label> |
||||
|
<input name="adminEmail" value="admin@admin.com" required=""> |
||||
|
</div> |
||||
|
|
||||
|
<div class="form-field"> |
||||
|
<label>{:__('Admin Password')}</label> |
||||
|
<input type="password" name="adminPassword" required=""> |
||||
|
</div> |
||||
|
|
||||
|
<div class="form-field"> |
||||
|
<label>{:__('Repeat Password')}</label> |
||||
|
<input type="password" name="adminPasswordConfirmation" required=""> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
<div class="form-group"> |
||||
|
<div class="form-field"> |
||||
|
<label>{:__('Website')}</label> |
||||
|
<input type="text" name="siteName" value="{:__('My Website')}" required=""/> |
||||
|
</div> |
||||
|
|
||||
|
</div> |
||||
|
|
||||
|
<div class="form-buttons"> |
||||
|
<!--@formatter:off--> |
||||
|
<button type="submit" {:$errInfo?'disabled':''}>{:__('Install now')}</button> |
||||
|
<!--@formatter:on--> |
||||
|
</div> |
||||
|
</form> |
||||
|
|
||||
|
<!-- jQuery --> |
||||
|
<script src="https://cdn.staticfile.org/jquery/2.1.4/jquery.min.js"></script> |
||||
|
|
||||
|
<script> |
||||
|
$(function () { |
||||
|
$('form :input:first').select(); |
||||
|
|
||||
|
$('form').on('submit', function (e) { |
||||
|
e.preventDefault(); |
||||
|
var form = this; |
||||
|
var $error = $("#error"); |
||||
|
var $success = $("#success"); |
||||
|
var $button = $(this).find('button') |
||||
|
.text("{:__('Installing')}") |
||||
|
.prop('disabled', true); |
||||
|
$.ajax({ |
||||
|
url: "", |
||||
|
type: "POST", |
||||
|
dataType: "json", |
||||
|
data: $(this).serialize(), |
||||
|
success: function (ret) { |
||||
|
if (ret.code == 1) { |
||||
|
var data = ret.data; |
||||
|
$error.hide(); |
||||
|
$(".form-group", form).remove(); |
||||
|
$button.remove(); |
||||
|
$("#success").text(ret.msg).show(); |
||||
|
|
||||
|
$buttons = $(".form-buttons", form); |
||||
|
$("<a class='btn' href='./'>{:__('Home')}</a>").appendTo($buttons); |
||||
|
|
||||
|
if (typeof data.adminName !== 'undefined') { |
||||
|
var url = location.href.replace(/install\.php/, data.adminName); |
||||
|
$("#warmtips").html("{:__('Security tips')}" + '<a href="' + url + '">' + url + '</a>').show(); |
||||
|
$('<a class="btn" href="' + url + '" id="btn-admin" style="background:#4e73df">' + "{:__('Dashboard')}" + '</a>').appendTo($buttons); |
||||
|
} |
||||
|
localStorage.setItem("fastep", "installed"); |
||||
|
} else { |
||||
|
$error.show().text(ret.msg); |
||||
|
$button.prop('disabled', false).text("{:__('Install now')}"); |
||||
|
$("html,body").animate({ |
||||
|
scrollTop: 0 |
||||
|
}, 500); |
||||
|
} |
||||
|
}, |
||||
|
error: function (xhr) { |
||||
|
$error.show().text(xhr.responseText); |
||||
|
$button.prop('disabled', false).text("{:__('Install now')}"); |
||||
|
$("html,body").animate({ |
||||
|
scrollTop: 0 |
||||
|
}, 500); |
||||
|
} |
||||
|
}); |
||||
|
return false; |
||||
|
}); |
||||
|
}); |
||||
|
</script> |
||||
|
</div> |
||||
|
</div> |
||||
|
</body> |
||||
|
</html> |
||||
@ -0,0 +1 @@ |
|||||
|
1 |
||||
@ -0,0 +1,35 @@ |
|||||
|
<?php |
||||
|
return [ |
||||
|
'Warning' => '温馨提示', |
||||
|
'Installing FastAdmin' => '安装FastAdmin', |
||||
|
'Mysql Hostname' => 'MySQL 数据库地址', |
||||
|
'Mysql Database' => 'MySQL 数据库名', |
||||
|
'Mysql Username' => 'MySQL 用户名', |
||||
|
'Mysql Password' => 'MySQL 密码', |
||||
|
'Mysql Prefix' => 'MySQL 数据表前缀', |
||||
|
'Mysql Hostport' => 'MySQL 端口号', |
||||
|
'Admin Username' => '管理员用户名', |
||||
|
'Admin Email' => '管理员Email', |
||||
|
'Admin Password' => '管理员密码', |
||||
|
'Repeat Password' => '重复管理员密码', |
||||
|
'Website' => '网站名称', |
||||
|
'My Website' => '我的网站', |
||||
|
'Install now' => '点击安装', |
||||
|
'Installing' => '安装中...', |
||||
|
'Home' => '访问首页', |
||||
|
'Dashboard' => '进入后台', |
||||
|
'Go back' => '返回上一页', |
||||
|
'Install Successed' => '安装成功!', |
||||
|
'Security tips' => '温馨提示:请将以下后台登录入口添加到你的收藏夹,为了你的安全,不要泄漏或发送给他人!如有泄漏请及时修改!', |
||||
|
'Please input correct database' => '请输入正确的数据库名', |
||||
|
'Please input correct username' => '用户名只能由3-30位数字、字母、下划线组合', |
||||
|
'Please input correct password' => '密码长度必须在6-30位之间,不能包含空格', |
||||
|
'Password is too weak' => '密码太简单,请重新输入', |
||||
|
'The two passwords you entered did not match' => '两次输入的密码不一致', |
||||
|
'Please input correct website' => '网站名称输入不正确', |
||||
|
'The current version %s is too low, please use PHP 7.1 or higher' => '当前版本%s过低,请使用PHP7.1以上版本', |
||||
|
'PDO is not currently installed and cannot be installed' => '当前未开启PDO,无法进行安装', |
||||
|
'The current permissions are insufficient to write the file %s' => '当前权限不足,无法写入文件%s', |
||||
|
'Please go to the official website to download the full package or resource package and try to install' => '当前代码仅包含核心代码,请前往官网下载完整包或资源包覆盖后再尝试安装', |
||||
|
'The system has been installed. If you need to reinstall, please remove %s first' => '当前已经安装成功,如果需要重新安装,请手动移除%s文件', |
||||
|
]; |
||||
@ -0,0 +1,327 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\command; |
||||
|
|
||||
|
use app\admin\model\AuthRule; |
||||
|
use ReflectionClass; |
||||
|
use ReflectionMethod; |
||||
|
use think\Cache; |
||||
|
use think\Config; |
||||
|
use think\console\Command; |
||||
|
use think\console\Input; |
||||
|
use think\console\input\Option; |
||||
|
use think\console\Output; |
||||
|
use think\Exception; |
||||
|
use think\Loader; |
||||
|
|
||||
|
class Menu extends Command |
||||
|
{ |
||||
|
protected $model = null; |
||||
|
|
||||
|
protected function configure() |
||||
|
{ |
||||
|
$this |
||||
|
->setName('menu') |
||||
|
->addOption('controller', 'c', Option::VALUE_REQUIRED | Option::VALUE_IS_ARRAY, 'controller name,use \'all-controller\' when build all menu', null) |
||||
|
->addOption('delete', 'd', Option::VALUE_OPTIONAL, 'delete the specified menu', '') |
||||
|
->addOption('force', 'f', Option::VALUE_OPTIONAL, 'force delete menu,without tips', null) |
||||
|
->addOption('equal', 'e', Option::VALUE_OPTIONAL, 'the controller must be equal', null) |
||||
|
->setDescription('Build auth menu from controller'); |
||||
|
//要执行的controller必须一样,不适用模糊查询 |
||||
|
} |
||||
|
|
||||
|
protected function execute(Input $input, Output $output) |
||||
|
{ |
||||
|
$this->model = new AuthRule(); |
||||
|
$adminPath = dirname(__DIR__) . DS; |
||||
|
//控制器名 |
||||
|
$controller = $input->getOption('controller') ?: ''; |
||||
|
if (!$controller) { |
||||
|
throw new Exception("please input controller name"); |
||||
|
} |
||||
|
$force = $input->getOption('force'); |
||||
|
//是否为删除模式 |
||||
|
$delete = $input->getOption('delete'); |
||||
|
//是否控制器完全匹配 |
||||
|
$equal = $input->getOption('equal'); |
||||
|
|
||||
|
|
||||
|
if ($delete) { |
||||
|
if (in_array('all-controller', $controller)) { |
||||
|
throw new Exception("could not delete all menu"); |
||||
|
} |
||||
|
$ids = []; |
||||
|
$list = $this->model->where(function ($query) use ($controller, $equal) { |
||||
|
foreach ($controller as $index => $item) { |
||||
|
if (stripos($item, '_') !== false) { |
||||
|
$item = Loader::parseName($item, 1); |
||||
|
} |
||||
|
if (stripos($item, '/') !== false) { |
||||
|
$controllerArr = explode('/', $item); |
||||
|
end($controllerArr); |
||||
|
$key = key($controllerArr); |
||||
|
$controllerArr[$key] = Loader::parseName($controllerArr[$key]); |
||||
|
} else { |
||||
|
$controllerArr = [Loader::parseName($item)]; |
||||
|
} |
||||
|
$item = str_replace('_', '\_', implode('/', $controllerArr)); |
||||
|
if ($equal) { |
||||
|
$query->whereOr('name', 'eq', $item); |
||||
|
} else { |
||||
|
$query->whereOr('name', 'like', strtolower($item) . "%"); |
||||
|
} |
||||
|
} |
||||
|
})->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
$output->warning($v->name); |
||||
|
$ids[] = $v->id; |
||||
|
} |
||||
|
if (!$ids) { |
||||
|
throw new Exception("There is no menu to delete"); |
||||
|
} |
||||
|
if (!$force) { |
||||
|
$output->info("Are you sure you want to delete all those menu? Type 'yes' to continue: "); |
||||
|
$line = fgets(defined('STDIN') ? STDIN : fopen('php://stdin', 'r')); |
||||
|
if (trim($line) != 'yes') { |
||||
|
throw new Exception("Operation is aborted!"); |
||||
|
} |
||||
|
} |
||||
|
AuthRule::destroy($ids); |
||||
|
|
||||
|
Cache::rm("__menu__"); |
||||
|
$output->info("Delete Successed"); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
if (!in_array('all-controller', $controller)) { |
||||
|
foreach ($controller as $index => $item) { |
||||
|
if (stripos($item, '_') !== false) { |
||||
|
$item = Loader::parseName($item, 1); |
||||
|
} |
||||
|
if (stripos($item, '/') !== false) { |
||||
|
$controllerArr = explode('/', $item); |
||||
|
end($controllerArr); |
||||
|
$key = key($controllerArr); |
||||
|
$controllerArr[$key] = ucfirst($controllerArr[$key]); |
||||
|
} else { |
||||
|
$controllerArr = [ucfirst($item)]; |
||||
|
} |
||||
|
$adminPath = dirname(__DIR__) . DS . 'controller' . DS . implode(DS, $controllerArr) . '.php'; |
||||
|
if (!is_file($adminPath)) { |
||||
|
$output->error("controller not found"); |
||||
|
return; |
||||
|
} |
||||
|
$this->importRule($item); |
||||
|
} |
||||
|
} else { |
||||
|
$authRuleList = AuthRule::select(); |
||||
|
//生成权限规则备份文件 |
||||
|
file_put_contents(RUNTIME_PATH . 'authrule.json', json_encode(collection($authRuleList)->toArray())); |
||||
|
|
||||
|
$this->model->where('id', '>', 0)->delete(); |
||||
|
$controllerDir = $adminPath . 'controller' . DS; |
||||
|
// 扫描新的节点信息并导入 |
||||
|
$treelist = $this->import($this->scandir($controllerDir)); |
||||
|
} |
||||
|
Cache::rm("__menu__"); |
||||
|
$output->info("Build Successed!"); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 递归扫描文件夹 |
||||
|
* @param string $dir |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function scandir($dir) |
||||
|
{ |
||||
|
$result = []; |
||||
|
$cdir = scandir($dir); |
||||
|
foreach ($cdir as $value) { |
||||
|
if (!in_array($value, array(".", ".."))) { |
||||
|
if (is_dir($dir . DS . $value)) { |
||||
|
$result[$value] = $this->scandir($dir . DS . $value); |
||||
|
} else { |
||||
|
$result[] = $value; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 导入规则节点 |
||||
|
* @param array $dirarr |
||||
|
* @param array $parentdir |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function import($dirarr, $parentdir = []) |
||||
|
{ |
||||
|
$menuarr = []; |
||||
|
foreach ($dirarr as $k => $v) { |
||||
|
if (is_array($v)) { |
||||
|
//当前是文件夹 |
||||
|
$nowparentdir = array_merge($parentdir, [$k]); |
||||
|
$this->import($v, $nowparentdir); |
||||
|
} else { |
||||
|
//只匹配PHP文件 |
||||
|
if (!preg_match('/^(\w+)\.php$/', $v, $matchone)) { |
||||
|
continue; |
||||
|
} |
||||
|
//导入文件 |
||||
|
$controller = ($parentdir ? implode('/', $parentdir) . '/' : '') . $matchone[1]; |
||||
|
$this->importRule($controller); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $menuarr; |
||||
|
} |
||||
|
|
||||
|
protected function importRule($controller) |
||||
|
{ |
||||
|
$controller = str_replace('\\', '/', $controller); |
||||
|
if (stripos($controller, '/') !== false) { |
||||
|
$controllerArr = explode('/', $controller); |
||||
|
end($controllerArr); |
||||
|
$key = key($controllerArr); |
||||
|
$controllerArr[$key] = ucfirst($controllerArr[$key]); |
||||
|
} else { |
||||
|
$key = 0; |
||||
|
$controllerArr = [ucfirst($controller)]; |
||||
|
} |
||||
|
$classSuffix = Config::get('controller_suffix') ? ucfirst(Config::get('url_controller_layer')) : ''; |
||||
|
$className = "\\app\\admin\\controller\\" . implode("\\", $controllerArr) . $classSuffix; |
||||
|
|
||||
|
$pathArr = $controllerArr; |
||||
|
array_unshift($pathArr, '', 'application', 'admin', 'controller'); |
||||
|
$classFile = ROOT_PATH . implode(DS, $pathArr) . $classSuffix . ".php"; |
||||
|
$classContent = file_get_contents($classFile); |
||||
|
$uniqueName = uniqid("FastAdmin") . $classSuffix; |
||||
|
$classContent = str_replace("class " . $controllerArr[$key] . $classSuffix . " ", 'class ' . $uniqueName . ' ', $classContent); |
||||
|
$classContent = preg_replace("/namespace\s(.*);/", 'namespace ' . __NAMESPACE__ . ";", $classContent); |
||||
|
|
||||
|
//临时的类文件 |
||||
|
$tempClassFile = __DIR__ . DS . $uniqueName . ".php"; |
||||
|
file_put_contents($tempClassFile, $classContent); |
||||
|
$className = "\\app\\admin\\command\\" . $uniqueName; |
||||
|
|
||||
|
//删除临时文件 |
||||
|
register_shutdown_function(function () use ($tempClassFile) { |
||||
|
if ($tempClassFile) { |
||||
|
//删除临时文件 |
||||
|
@unlink($tempClassFile); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
//反射机制调用类的注释和方法名 |
||||
|
$reflector = new ReflectionClass($className); |
||||
|
|
||||
|
//只匹配公共的方法 |
||||
|
$methods = $reflector->getMethods(ReflectionMethod::IS_PUBLIC); |
||||
|
$classComment = $reflector->getDocComment(); |
||||
|
//判断是否有启用软删除 |
||||
|
$softDeleteMethods = ['destroy', 'restore', 'recyclebin']; |
||||
|
$withSofeDelete = false; |
||||
|
$modelRegexArr = ["/\\\$this\->model\s*=\s*model\(['|\"](\w+)['|\"]\);/", "/\\\$this\->model\s*=\s*new\s+([a-zA-Z\\\]+);/"]; |
||||
|
$modelRegex = preg_match($modelRegexArr[0], $classContent) ? $modelRegexArr[0] : $modelRegexArr[1]; |
||||
|
preg_match_all($modelRegex, $classContent, $matches); |
||||
|
if (isset($matches[1]) && isset($matches[1][0]) && $matches[1][0]) { |
||||
|
\think\Request::instance()->module('admin'); |
||||
|
$model = model($matches[1][0]); |
||||
|
if (in_array('trashed', get_class_methods($model))) { |
||||
|
$withSofeDelete = true; |
||||
|
} |
||||
|
} |
||||
|
//忽略的类 |
||||
|
if (stripos($classComment, "@internal") !== false) { |
||||
|
return; |
||||
|
} |
||||
|
preg_match_all('#(@.*?)\n#s', $classComment, $annotations); |
||||
|
$controllerIcon = 'fa fa-circle-o'; |
||||
|
$controllerRemark = ''; |
||||
|
//判断注释中是否设置了icon值 |
||||
|
if (isset($annotations[1])) { |
||||
|
foreach ($annotations[1] as $tag) { |
||||
|
if (stripos($tag, '@icon') !== false) { |
||||
|
$controllerIcon = substr($tag, stripos($tag, ' ') + 1); |
||||
|
} |
||||
|
if (stripos($tag, '@remark') !== false) { |
||||
|
$controllerRemark = substr($tag, stripos($tag, ' ') + 1); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
//过滤掉其它字符 |
||||
|
$controllerTitle = trim(preg_replace(array('/^\/\*\*(.*)[\n\r\t]/u', '/[\s]+\*\//u', '/\*\s@(.*)/u', '/[\s|\*]+/u'), '', $classComment)); |
||||
|
|
||||
|
//导入中文语言包 |
||||
|
\think\Lang::load(dirname(__DIR__) . DS . 'lang/zh-cn.php'); |
||||
|
|
||||
|
//先导入菜单的数据 |
||||
|
$pid = 0; |
||||
|
foreach ($controllerArr as $k => $v) { |
||||
|
$key = $k + 1; |
||||
|
//驼峰转下划线 |
||||
|
$controllerNameArr = array_slice($controllerArr, 0, $key); |
||||
|
foreach ($controllerNameArr as &$val) { |
||||
|
$val = strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $val), "_")); |
||||
|
} |
||||
|
unset($val); |
||||
|
$name = implode('/', $controllerNameArr); |
||||
|
$title = (!isset($controllerArr[$key]) ? $controllerTitle : ''); |
||||
|
$icon = (!isset($controllerArr[$key]) ? $controllerIcon : 'fa fa-list'); |
||||
|
$remark = (!isset($controllerArr[$key]) ? $controllerRemark : ''); |
||||
|
$title = $title ? $title : $v; |
||||
|
$rulemodel = $this->model->get(['name' => $name]); |
||||
|
if (!$rulemodel) { |
||||
|
$this->model |
||||
|
->data(['pid' => $pid, 'name' => $name, 'title' => $title, 'icon' => $icon, 'remark' => $remark, 'ismenu' => 1, 'status' => 'normal']) |
||||
|
->isUpdate(false) |
||||
|
->save(); |
||||
|
$pid = $this->model->id; |
||||
|
} else { |
||||
|
$pid = $rulemodel->id; |
||||
|
} |
||||
|
} |
||||
|
$ruleArr = []; |
||||
|
foreach ($methods as $m => $n) { |
||||
|
//过滤特殊的类 |
||||
|
if (substr($n->name, 0, 2) == '__' || $n->name == '_initialize') { |
||||
|
continue; |
||||
|
} |
||||
|
//未启用软删除时过滤相关方法 |
||||
|
if (!$withSofeDelete && in_array($n->name, $softDeleteMethods)) { |
||||
|
continue; |
||||
|
} |
||||
|
//只匹配符合的方法 |
||||
|
if (!preg_match('/^(\w+)' . Config::get('action_suffix') . '/', $n->name, $matchtwo)) { |
||||
|
unset($methods[$m]); |
||||
|
continue; |
||||
|
} |
||||
|
$comment = $reflector->getMethod($n->name)->getDocComment(); |
||||
|
//忽略的方法 |
||||
|
if (stripos($comment, "@internal") !== false) { |
||||
|
continue; |
||||
|
} |
||||
|
//过滤掉其它字符 |
||||
|
$comment = preg_replace(array('/^\/\*\*(.*)[\n\r\t]/u', '/[\s]+\*\//u', '/\*\s@(.*)/u', '/[\s|\*]+/u'), '', $comment); |
||||
|
|
||||
|
$title = $comment ? $comment : ucfirst($n->name); |
||||
|
|
||||
|
//获取主键,作为AuthRule更新依据 |
||||
|
$id = $this->getAuthRulePK($name . "/" . strtolower($n->name)); |
||||
|
|
||||
|
$ruleArr[] = array('id' => $id, 'pid' => $pid, 'name' => $name . "/" . strtolower($n->name), 'icon' => 'fa fa-circle-o', 'title' => $title, 'ismenu' => 0, 'status' => 'normal'); |
||||
|
} |
||||
|
$this->model->isUpdate(false)->saveAll($ruleArr); |
||||
|
} |
||||
|
|
||||
|
//获取主键 |
||||
|
protected function getAuthRulePK($name) |
||||
|
{ |
||||
|
if (!empty($name)) { |
||||
|
$id = $this->model |
||||
|
->where('name', $name) |
||||
|
->value('id'); |
||||
|
return $id ? $id : null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,162 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\command; |
||||
|
|
||||
|
use think\console\Command; |
||||
|
use think\console\Input; |
||||
|
use think\console\input\Option; |
||||
|
use think\console\Output; |
||||
|
use think\Exception; |
||||
|
|
||||
|
class Min extends Command |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* 路径和文件名配置 |
||||
|
*/ |
||||
|
protected $options = [ |
||||
|
'cssBaseUrl' => 'public/assets/css/', |
||||
|
'cssBaseName' => '{module}', |
||||
|
'jsBaseUrl' => 'public/assets/js/', |
||||
|
'jsBaseName' => 'require-{module}', |
||||
|
]; |
||||
|
|
||||
|
protected function configure() |
||||
|
{ |
||||
|
$this |
||||
|
->setName('min') |
||||
|
->addOption('module', 'm', Option::VALUE_REQUIRED, 'module name(frontend or backend),use \'all\' when build all modules', null) |
||||
|
->addOption('resource', 'r', Option::VALUE_REQUIRED, 'resource name(js or css),use \'all\' when build all resources', null) |
||||
|
->addOption('optimize', 'o', Option::VALUE_OPTIONAL, 'optimize type(uglify|closure|none)', 'none') |
||||
|
->setDescription('Compress js and css file'); |
||||
|
} |
||||
|
|
||||
|
protected function execute(Input $input, Output $output) |
||||
|
{ |
||||
|
$module = $input->getOption('module') ?: ''; |
||||
|
$resource = $input->getOption('resource') ?: ''; |
||||
|
$optimize = $input->getOption('optimize') ?: 'none'; |
||||
|
|
||||
|
if (!$module || !in_array($module, ['frontend', 'backend', 'all'])) { |
||||
|
throw new Exception('Please input correct module name'); |
||||
|
} |
||||
|
if (!$resource || !in_array($resource, ['js', 'css', 'all'])) { |
||||
|
throw new Exception('Please input correct resource name'); |
||||
|
} |
||||
|
|
||||
|
$moduleArr = $module == 'all' ? ['frontend', 'backend'] : [$module]; |
||||
|
$resourceArr = $resource == 'all' ? ['js', 'css'] : [$resource]; |
||||
|
|
||||
|
$minPath = __DIR__ . DS . 'Min' . DS; |
||||
|
$publicPath = ROOT_PATH . 'public' . DS; |
||||
|
$tempFile = $minPath . 'temp.js'; |
||||
|
|
||||
|
$nodeExec = ''; |
||||
|
|
||||
|
if (!$nodeExec) { |
||||
|
if (IS_WIN) { |
||||
|
// Winsows下请手动配置配置该值,一般将该值配置为 '"C:\Program Files\nodejs\node.exe"',除非你的Node安装路径有变更 |
||||
|
$nodeExec = 'C:\Program Files\nodejs\node.exe'; |
||||
|
if (file_exists($nodeExec)) { |
||||
|
$nodeExec = '"' . $nodeExec . '"'; |
||||
|
} else { |
||||
|
// 如果 '"C:\Program Files\nodejs\node.exe"' 不存在,可能是node安装路径有变更 |
||||
|
// 但安装node会自动配置环境变量,直接执行 '"node.exe"' 提高第一次使用压缩打包的成功率 |
||||
|
$nodeExec = '"node.exe"'; |
||||
|
} |
||||
|
} else { |
||||
|
try { |
||||
|
$nodeExec = exec("which node"); |
||||
|
if (!$nodeExec) { |
||||
|
throw new Exception("node environment not found!please install node first!"); |
||||
|
} |
||||
|
} catch (Exception $e) { |
||||
|
throw new Exception($e->getMessage()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
foreach ($moduleArr as $mod) { |
||||
|
foreach ($resourceArr as $res) { |
||||
|
$data = [ |
||||
|
'publicPath' => $publicPath, |
||||
|
'jsBaseName' => str_replace('{module}', $mod, $this->options['jsBaseName']), |
||||
|
'jsBaseUrl' => $this->options['jsBaseUrl'], |
||||
|
'cssBaseName' => str_replace('{module}', $mod, $this->options['cssBaseName']), |
||||
|
'cssBaseUrl' => $this->options['cssBaseUrl'], |
||||
|
'jsBasePath' => str_replace(DS, '/', ROOT_PATH . $this->options['jsBaseUrl']), |
||||
|
'cssBasePath' => str_replace(DS, '/', ROOT_PATH . $this->options['cssBaseUrl']), |
||||
|
'optimize' => $optimize, |
||||
|
'ds' => DS, |
||||
|
]; |
||||
|
|
||||
|
//源文件 |
||||
|
$from = $data["{$res}BasePath"] . $data["{$res}BaseName"] . '.' . $res; |
||||
|
if (!is_file($from)) { |
||||
|
$output->error("{$res} source file not found!file:{$from}"); |
||||
|
continue; |
||||
|
} |
||||
|
if ($res == "js") { |
||||
|
$content = file_get_contents($from); |
||||
|
preg_match("/require\.config\(\{[\r\n]?[\n]?+(.*?)[\r\n]?[\n]?}\);/is", $content, $matches); |
||||
|
if (!isset($matches[1])) { |
||||
|
$output->error("js config not found!"); |
||||
|
continue; |
||||
|
} |
||||
|
$config = preg_replace("/(urlArgs|baseUrl):(.*)\n/", '', $matches[1]); |
||||
|
$data['config'] = $config; |
||||
|
} |
||||
|
// 生成压缩文件 |
||||
|
$this->writeToFile($res, $data, $tempFile); |
||||
|
|
||||
|
$output->info("Compress " . $data["{$res}BaseName"] . ".{$res}"); |
||||
|
|
||||
|
// 执行压缩 |
||||
|
$command = "{$nodeExec} \"{$minPath}r.js\" -o \"{$tempFile}\" >> \"{$minPath}node.log\""; |
||||
|
if ($output->isDebug()) { |
||||
|
$output->warning($command); |
||||
|
} |
||||
|
echo exec($command); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (!$output->isDebug()) { |
||||
|
@unlink($tempFile); |
||||
|
} |
||||
|
|
||||
|
$output->info("Build Successed!"); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 写入到文件 |
||||
|
* @param string $name |
||||
|
* @param array $data |
||||
|
* @param string $pathname |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
protected function writeToFile($name, $data, $pathname) |
||||
|
{ |
||||
|
$search = $replace = []; |
||||
|
foreach ($data as $k => $v) { |
||||
|
$search[] = "{%{$k}%}"; |
||||
|
$replace[] = $v; |
||||
|
} |
||||
|
$stub = file_get_contents($this->getStub($name)); |
||||
|
$content = str_replace($search, $replace, $stub); |
||||
|
|
||||
|
if (!is_dir(dirname($pathname))) { |
||||
|
mkdir(strtolower(dirname($pathname)), 0755, true); |
||||
|
} |
||||
|
return file_put_contents($pathname, $content); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取基础模板 |
||||
|
* @param string $name |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected function getStub($name) |
||||
|
{ |
||||
|
return __DIR__ . DS . 'Min' . DS . 'stubs' . DS . $name . '.stub'; |
||||
|
} |
||||
|
} |
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,6 @@ |
|||||
|
({ |
||||
|
cssIn: "{%cssBasePath%}{%cssBaseName%}.css", |
||||
|
out: "{%cssBasePath%}{%cssBaseName%}.min.css", |
||||
|
optimizeCss: "default", |
||||
|
optimize: "{%optimize%}" |
||||
|
}) |
||||
@ -0,0 +1,11 @@ |
|||||
|
({ |
||||
|
{%config%} |
||||
|
, |
||||
|
optimizeCss: "standard", |
||||
|
optimize: "{%optimize%}", //可使用uglify|closure|none |
||||
|
preserveLicenseComments: false, |
||||
|
removeCombined: false, |
||||
|
baseUrl: "{%jsBasePath%}", //JS文件所在的基础目录 |
||||
|
name: "{%jsBaseName%}", //来源文件,不包含后缀 |
||||
|
out: "{%jsBasePath%}{%jsBaseName%}.min.js" //目标文件 |
||||
|
}); |
||||
@ -0,0 +1,197 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use app\common\model\Category; |
||||
|
use fast\Form; |
||||
|
use fast\Tree; |
||||
|
use think\Db; |
||||
|
use think\Loader; |
||||
|
|
||||
|
if (!function_exists('build_select')) { |
||||
|
|
||||
|
/** |
||||
|
* 生成下拉列表 |
||||
|
* @param string $name |
||||
|
* @param mixed $options |
||||
|
* @param mixed $selected |
||||
|
* @param mixed $attr |
||||
|
* @return string |
||||
|
*/ |
||||
|
function build_select($name, $options, $selected = [], $attr = []) |
||||
|
{ |
||||
|
$options = is_array($options) ? $options : explode(',', $options); |
||||
|
$selected = is_array($selected) ? $selected : explode(',', $selected); |
||||
|
return Form::select($name, $options, $selected, $attr); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (!function_exists('build_radios')) { |
||||
|
|
||||
|
/** |
||||
|
* 生成单选按钮组 |
||||
|
* @param string $name |
||||
|
* @param array $list |
||||
|
* @param mixed $selected |
||||
|
* @return string |
||||
|
*/ |
||||
|
function build_radios($name, $list = [], $selected = null) |
||||
|
{ |
||||
|
$html = []; |
||||
|
$selected = is_null($selected) ? key($list) : $selected; |
||||
|
$selected = is_array($selected) ? $selected : explode(',', $selected); |
||||
|
foreach ($list as $k => $v) { |
||||
|
$html[] = sprintf(Form::label("{$name}-{$k}", "%s {$v}"), Form::radio($name, $k, in_array($k, $selected), ['id' => "{$name}-{$k}"])); |
||||
|
} |
||||
|
return '<div class="radio">' . implode(' ', $html) . '</div>'; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (!function_exists('build_checkboxs')) { |
||||
|
|
||||
|
/** |
||||
|
* 生成复选按钮组 |
||||
|
* @param string $name |
||||
|
* @param array $list |
||||
|
* @param mixed $selected |
||||
|
* @return string |
||||
|
*/ |
||||
|
function build_checkboxs($name, $list = [], $selected = null) |
||||
|
{ |
||||
|
$html = []; |
||||
|
$selected = is_null($selected) ? [] : $selected; |
||||
|
$selected = is_array($selected) ? $selected : explode(',', $selected); |
||||
|
foreach ($list as $k => $v) { |
||||
|
$html[] = sprintf(Form::label("{$name}-{$k}", "%s {$v}"), Form::checkbox($name, $k, in_array($k, $selected), ['id' => "{$name}-{$k}"])); |
||||
|
} |
||||
|
return '<div class="checkbox">' . implode(' ', $html) . '</div>'; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
if (!function_exists('build_category_select')) { |
||||
|
|
||||
|
/** |
||||
|
* 生成分类下拉列表框 |
||||
|
* @param string $name |
||||
|
* @param string $type |
||||
|
* @param mixed $selected |
||||
|
* @param array $attr |
||||
|
* @param array $header |
||||
|
* @return string |
||||
|
*/ |
||||
|
function build_category_select($name, $type, $selected = null, $attr = [], $header = []) |
||||
|
{ |
||||
|
$tree = Tree::instance(); |
||||
|
$tree->init(Category::getCategoryArray($type), 'pid'); |
||||
|
$categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name'); |
||||
|
$categorydata = $header ? $header : []; |
||||
|
foreach ($categorylist as $k => $v) { |
||||
|
$categorydata[$v['id']] = $v['name']; |
||||
|
} |
||||
|
$attr = array_merge(['id' => "c-{$name}", 'class' => 'form-control selectpicker'], $attr); |
||||
|
return build_select($name, $categorydata, $selected, $attr); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (!function_exists('build_toolbar')) { |
||||
|
|
||||
|
/** |
||||
|
* 生成表格操作按钮栏 |
||||
|
* @param array $btns 按钮组 |
||||
|
* @param array $attr 按钮属性值 |
||||
|
* @return string |
||||
|
*/ |
||||
|
function build_toolbar($btns = null, $attr = []) |
||||
|
{ |
||||
|
$auth = \app\admin\library\Auth::instance(); |
||||
|
$controller = str_replace('.', '/', Loader::parseName(request()->controller())); |
||||
|
$btns = $btns ? $btns : ['refresh', 'add', 'edit', 'del', 'import']; |
||||
|
$btns = is_array($btns) ? $btns : explode(',', $btns); |
||||
|
$index = array_search('delete', $btns); |
||||
|
if ($index !== false) { |
||||
|
$btns[$index] = 'del'; |
||||
|
} |
||||
|
$btnAttr = [ |
||||
|
'refresh' => ['javascript:;', 'btn btn-primary btn-refresh', 'fa fa-refresh', '', __('Refresh')], |
||||
|
'add' => ['javascript:;', 'btn btn-success btn-add', 'fa fa-plus', __('Add'), __('Add')], |
||||
|
'edit' => ['javascript:;', 'btn btn-success btn-edit btn-disabled disabled', 'fa fa-pencil', __('Edit'), __('Edit')], |
||||
|
'del' => ['javascript:;', 'btn btn-danger btn-del btn-disabled disabled', 'fa fa-trash', __('Delete'), __('Delete')], |
||||
|
'import' => ['javascript:;', 'btn btn-info btn-import', 'fa fa-upload', __('Import'), __('Import')], |
||||
|
]; |
||||
|
$btnAttr = array_merge($btnAttr, $attr); |
||||
|
$html = []; |
||||
|
foreach ($btns as $k => $v) { |
||||
|
//如果未定义或没有权限 |
||||
|
if (!isset($btnAttr[$v]) || ($v !== 'refresh' && !$auth->check("{$controller}/{$v}"))) { |
||||
|
continue; |
||||
|
} |
||||
|
list($href, $class, $icon, $text, $title) = $btnAttr[$v]; |
||||
|
//$extend = $v == 'import' ? 'id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"' : ''; |
||||
|
//$html[] = '<a href="' . $href . '" class="' . $class . '" title="' . $title . '" ' . $extend . '><i class="' . $icon . '"></i> ' . $text . '</a>'; |
||||
|
if ($v == 'import') { |
||||
|
$template = str_replace('/', '_', $controller); |
||||
|
$download = ''; |
||||
|
if (file_exists("./template/{$template}.xlsx")) { |
||||
|
$download .= "<li><a href=\"/template/{$template}.xlsx\" target=\"_blank\">XLSX模版</a></li>"; |
||||
|
} |
||||
|
if (file_exists("./template/{$template}.xls")) { |
||||
|
$download .= "<li><a href=\"/template/{$template}.xls\" target=\"_blank\">XLS模版</a></li>"; |
||||
|
} |
||||
|
if (file_exists("./template/{$template}.csv")) { |
||||
|
$download .= empty($download) ? '' : "<li class=\"divider\"></li>"; |
||||
|
$download .= "<li><a href=\"/template/{$template}.csv\" target=\"_blank\">CSV模版</a></li>"; |
||||
|
} |
||||
|
$download .= empty($download) ? '' : "\n "; |
||||
|
if (!empty($download)) { |
||||
|
$html[] = <<<EOT |
||||
|
<div class="btn-group"> |
||||
|
<button type="button" href="{$href}" class="btn btn-info btn-import" title="{$title}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="{$icon}"></i> {$text}</button> |
||||
|
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" title="下载批量导入模版"> |
||||
|
<span class="caret"></span> |
||||
|
<span class="sr-only">Toggle Dropdown</span> |
||||
|
</button> |
||||
|
<ul class="dropdown-menu" role="menu">{$download}</ul> |
||||
|
</div> |
||||
|
EOT; |
||||
|
} else { |
||||
|
$html[] = '<a href="' . $href . '" class="' . $class . '" title="' . $title . '" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="' . $icon . '"></i> ' . $text . '</a>'; |
||||
|
} |
||||
|
} else { |
||||
|
$html[] = '<a href="' . $href . '" class="' . $class . '" title="' . $title . '"><i class="' . $icon . '"></i> ' . $text . '</a>'; |
||||
|
} |
||||
|
} |
||||
|
return implode(' ', $html); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (!function_exists('build_heading')) { |
||||
|
|
||||
|
/** |
||||
|
* 生成页面Heading |
||||
|
* |
||||
|
* @param string $path 指定的path |
||||
|
* @return string |
||||
|
*/ |
||||
|
function build_heading($path = null, $container = true) |
||||
|
{ |
||||
|
$title = $content = ''; |
||||
|
if (is_null($path)) { |
||||
|
$action = request()->action(); |
||||
|
$controller = str_replace('.', '/', Loader::parseName(request()->controller())); |
||||
|
$path = strtolower($controller . ($action && $action != 'index' ? '/' . $action : '')); |
||||
|
} |
||||
|
// 根据当前的URI自动匹配父节点的标题和备注 |
||||
|
$data = Db::name('auth_rule')->where('name', $path)->field('title,remark')->find(); |
||||
|
if ($data) { |
||||
|
$title = __($data['title']); |
||||
|
$content = __($data['remark']); |
||||
|
} |
||||
|
if (!$content) { |
||||
|
return ''; |
||||
|
} |
||||
|
$result = '<div class="panel-lead"><em>' . $title . '</em>' . $content . '</div>'; |
||||
|
if ($container) { |
||||
|
$result = '<div class="panel-heading">' . $result . '</div>'; |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
<?php |
||||
|
|
||||
|
//配置文件 |
||||
|
return [ |
||||
|
'url_common_param' => true, |
||||
|
'url_html_suffix' => '', |
||||
|
'controller_auto_search' => true, |
||||
|
]; |
||||
@ -0,0 +1,136 @@ |
|||||
|
<!DOCTYPE html> |
||||
|
<html> |
||||
|
<head> |
||||
|
<meta charset="UTF-8"/> |
||||
|
<title>短信模板列表</title> |
||||
|
<link rel="stylesheet" href="/sms/static/layui/css/layui.css?_v=20230419123656"> |
||||
|
<link rel="stylesheet" href="/sms/static/css/font-awesome.min.css?_v=20230419123656"> |
||||
|
<link rel="stylesheet" href="/sms/static/css/sms-style.css?_v=20230419123656"> |
||||
|
<style>.layui-table-cell { |
||||
|
height: auto; |
||||
|
overflow: visible; |
||||
|
text-overflow: inherit; |
||||
|
white-space: normal |
||||
|
} |
||||
|
|
||||
|
.sms-tpl-preview { |
||||
|
word-break: break-all; |
||||
|
padding: 10px; |
||||
|
max-height: 180px; |
||||
|
overflow-y: auto; |
||||
|
border: 1px solid #efefef; |
||||
|
min-height: 18px |
||||
|
}</style> |
||||
|
</head> |
||||
|
<body> |
||||
|
<div class="main"> |
||||
|
<div class="sms-tabmenu"><a href="#" class="current">短信模板列表</a></div> |
||||
|
<div class="main_wrap"> |
||||
|
<div> |
||||
|
<div class="sms-param-item"> |
||||
|
<button class="sms-btn-action sms-btn-disable" id="btnSelectAll"><i class="fa fa-calendar-check-o"></i>查询全选 |
||||
|
</button> |
||||
|
</div> |
||||
|
<div class="sms-param-item"> |
||||
|
<button class="sms-btn-action" id="btnBatchExport"><i class="fa fa-external-link"></i>导出模板</button> |
||||
|
</div> |
||||
|
<div class="sms-param-item" style="border-right: 1px solid #d6d6d6; padding-right: 10px;"> |
||||
|
<button class="sms-btn-action" id="btnBatchDelete"><i class="fa fa-times-circle-o"></i>批量删除</button> |
||||
|
</div> |
||||
|
<div class="sms-param-item"><a class="sms-btn-action" id="btnAddTpl"><i class="fa fa-plus"></i>新增短信模板</a> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="layui-form" lay-filter="gridParamForm" data-submitor="#searchBtn"> |
||||
|
<div class="sms-param-item sms-param-lg"><input type="text" name="userName" class="layui-input" |
||||
|
placeholder="账号"/></div> |
||||
|
<div class="sms-param-item sms-param-lg"><input type="text" name="content" class="layui-input" |
||||
|
placeholder="内容"/></div> |
||||
|
<div class="sms-param-item sms-param-lg"><select name="approveStep"> |
||||
|
<option value="" selected="selected">模板状态</option> |
||||
|
<option value="2">正常</option> |
||||
|
<option value="1">审核中</option> |
||||
|
<option value="3">审核拒绝</option> |
||||
|
<option value="4">已过期</option> |
||||
|
</select></div> |
||||
|
<div class="sms-param-item sms-param-lg"> |
||||
|
<button id="searchBtn" class="layui-btn layui-btn-normal sms-btn"><i class="fa fa-search"></i>查询 |
||||
|
</button> |
||||
|
</div> |
||||
|
</div> |
||||
|
<table id="templateGrid" lay-filter="templateGrid"></table> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div id="templateDialog" class="sms-dialog" style="width: 620px;"> |
||||
|
<div class="layui-form" lay-filter="templateForm"><input type="hidden" name="id"/> |
||||
|
<div class="layui-form-item layui-form-text" style="margin-bottom: 6px;"><label |
||||
|
class="layui-form-label sms-require">模板类型</label> |
||||
|
<div class="layui-input-block"><input type="radio" name="type" value="1" lay-filter="tplTypeChanged" |
||||
|
title="精确模板"><input type="radio" name="type" value="2" |
||||
|
lay-filter="tplTypeChanged" |
||||
|
title="相似度模板"></div> |
||||
|
</div> |
||||
|
<div class="layui-form-item layui-form-text biz-tpl-exact"><label class="layui-form-label">预览</label> |
||||
|
<div class="layui-input-block"> |
||||
|
<div id="tpl_preview" class="sms-tpl-preview"></div> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="layui-form-item layui-form-text biz-tpl-like hidden"><label |
||||
|
class="layui-form-label">匹配相似度</label> |
||||
|
<div class="layui-input-block" style="padding-top: 10px; min-height: 0;"> |
||||
|
<div style="display: inline-block; width: 50%; height: 4px; background-color: #1E9FFF; margin-right: -10px;"></div> |
||||
|
<div id="tpl_slodePercent" style="display: inline-block; width: 46%;"></div> |
||||
|
<span id="tpl_slodePercentTip">%</span></div> |
||||
|
</div> |
||||
|
<div class="layui-form-item layui-form-text"><label class="layui-form-label sms-require">模板内容</label> |
||||
|
<div class="layui-input-block"><textarea id="tpl_content" name="content" class="layui-textarea" rows="6" |
||||
|
placeholder="请输入模板内容"></textarea> |
||||
|
<button id="tpl_insertVar" type="button" class="layui-btn layui-btn-sm biz-tpl-exact" |
||||
|
style="float: right; margin-top: 6px;">插入变量 |
||||
|
</button> |
||||
|
<div class="sms-line-tips"><span class="fa fa-exclamation-circle"></span> 已输入 <span |
||||
|
id="tpl_wordLenth" class="c-blue-deep">0</span> 个字符,实际计费字数以发送内容为准。 |
||||
|
</div> |
||||
|
<div class="sms-line-tips biz-tpl-exact"><span class="fa fa-exclamation-circle"></span> “<span |
||||
|
class="c-blue">{%</span>”和“<span class="c-blue">%}</span>”包裹字符表示模板变量,例如:<span |
||||
|
class="c-blue">{%变量%}</span>。 |
||||
|
</div> |
||||
|
<div class="sms-line-tips biz-tpl-like hidden"><span class="fa fa-exclamation-circle"></span> |
||||
|
模板将与实际发送内容计算相似度,达到指定百分比以上则为匹配。 |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="layui-form-item layui-form-text"><label class="layui-form-label">有效期至</label> |
||||
|
<div class="layui-input-block"><input type="text" id="expiryDateStr" name="expiryDateStr" |
||||
|
class="layui-input" style="width: 220px" placeholder="不限制" |
||||
|
autocomplete="off"/></div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div id="templateTestDialog" class="sms-dialog"> |
||||
|
<div class="layui-form" lay-filter="templateTestForm"><input type="hidden" name="id"/> |
||||
|
<div class="layui-form-item layui-form-text"><label class="layui-form-label">模板内容</label> |
||||
|
<div class="layui-input-block"> |
||||
|
<div id="test_templateCnt" class="sms-tpl-preview c-blue"></div> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="layui-form-item layui-form-text"><label class="layui-form-label sms-require">短信内容</label> |
||||
|
<div class="layui-input-block"><textarea name="content" class="layui-textarea" rows="6" |
||||
|
placeholder="请输入短信内容"></textarea></div> |
||||
|
</div> |
||||
|
<div id="test_result" class="layui-form-item layui-form-text hidden"><label |
||||
|
class="layui-form-label">测试结果</label> |
||||
|
<div class="layui-input-block" style="line-height: 38px;"><span id="test_success" |
||||
|
class="c-green">模板匹配成功</span><span |
||||
|
id="test_failure" class="c-red">模板不匹配</span> |
||||
|
<div id="test_matchRate" style="line-height: 20px;">匹配度:<span></span></div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
<input type="hidden" id="myRoleCode" value="GROUP"/><input type="hidden" id="leftVarChar" value="{%"/><input |
||||
|
type="hidden" id="rightVarChar" value="%}"/> |
||||
|
<script src="/sms/static/layui/layui.js?_v=20230419123656"></script> |
||||
|
<script src="/sms/static/js/sms-common.js?_v=20230419123656"></script> |
||||
|
<script src="/sms/static/js/sms/message/memberTemplateList.js?_v=20230419123656"></script> |
||||
|
</body> |
||||
|
</html> |
||||
@ -0,0 +1,454 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller; |
||||
|
|
||||
|
use app\common\controller\Backend; |
||||
|
use fast\Http; |
||||
|
use think\addons\AddonException; |
||||
|
use think\addons\Service; |
||||
|
use think\Cache; |
||||
|
use think\Config; |
||||
|
use think\Db; |
||||
|
use think\Exception; |
||||
|
|
||||
|
/** |
||||
|
* 插件管理 |
||||
|
* |
||||
|
* @icon fa fa-cube |
||||
|
* @remark 可在线安装、卸载、禁用、启用、配置、升级插件,插件升级前请做好备份。 |
||||
|
*/ |
||||
|
class Addon extends Backend |
||||
|
{ |
||||
|
protected $model = null; |
||||
|
protected $noNeedRight = ['get_table_list']; |
||||
|
|
||||
|
public function _initialize() |
||||
|
{ |
||||
|
parent::_initialize(); |
||||
|
if (!$this->auth->isSuperAdmin() && in_array($this->request->action(), ['install', 'uninstall', 'local', 'upgrade', 'authorization', 'testdata'])) { |
||||
|
$this->error(__('Access is allowed only to the super management group')); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 插件列表 |
||||
|
*/ |
||||
|
public function index() |
||||
|
{ |
||||
|
$addons = get_addon_list(); |
||||
|
foreach ($addons as $k => &$v) { |
||||
|
$config = get_addon_config($v['name']); |
||||
|
$v['config'] = $config ? 1 : 0; |
||||
|
$v['url'] = str_replace($this->request->server('SCRIPT_NAME'), '', $v['url']); |
||||
|
} |
||||
|
$this->assignconfig(['addons' => $addons, 'api_url' => config('fastadmin.api_url'), 'faversion' => config('fastadmin.version'), 'domain' => request()->host(true)]); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 配置 |
||||
|
*/ |
||||
|
public function config($name = null) |
||||
|
{ |
||||
|
$name = $name ? $name : $this->request->get("name"); |
||||
|
if (!$name) { |
||||
|
$this->error(__('Parameter %s can not be empty', 'name')); |
||||
|
} |
||||
|
if (!preg_match("/^[a-zA-Z0-9]+$/", $name)) { |
||||
|
$this->error(__('Addon name incorrect')); |
||||
|
} |
||||
|
$info = get_addon_info($name); |
||||
|
$config = get_addon_fullconfig($name); |
||||
|
if (!$info) { |
||||
|
$this->error(__('Addon not exists')); |
||||
|
} |
||||
|
if ($this->request->isPost()) { |
||||
|
$params = $this->request->post("row/a", [], 'trim'); |
||||
|
if ($params) { |
||||
|
foreach ($config as $k => &$v) { |
||||
|
if (isset($params[$v['name']])) { |
||||
|
if ($v['type'] == 'array') { |
||||
|
$params[$v['name']] = is_array($params[$v['name']]) ? $params[$v['name']] : (array)json_decode($params[$v['name']], true); |
||||
|
$value = $params[$v['name']]; |
||||
|
} else { |
||||
|
$value = is_array($params[$v['name']]) ? implode(',', $params[$v['name']]) : $params[$v['name']]; |
||||
|
} |
||||
|
$v['value'] = $value; |
||||
|
} |
||||
|
} |
||||
|
try { |
||||
|
$addon = get_addon_instance($name); |
||||
|
//插件自定义配置实现逻辑 |
||||
|
if (method_exists($addon, 'config')) { |
||||
|
$addon->config($name, $config); |
||||
|
} else { |
||||
|
//更新配置文件 |
||||
|
set_addon_fullconfig($name, $config); |
||||
|
Service::refresh(); |
||||
|
} |
||||
|
} catch (Exception $e) { |
||||
|
$this->error(__($e->getMessage())); |
||||
|
} |
||||
|
$this->success(); |
||||
|
} |
||||
|
$this->error(__('Parameter %s can not be empty', '')); |
||||
|
} |
||||
|
$tips = []; |
||||
|
$groupList = []; |
||||
|
foreach ($config as $index => &$item) { |
||||
|
//如果有设置分组 |
||||
|
if (isset($item['group']) && $item['group']) { |
||||
|
if (!in_array($item['group'], $groupList)) { |
||||
|
$groupList["custom" . (count($groupList) + 1)] = $item['group']; |
||||
|
} |
||||
|
} |
||||
|
if ($item['name'] == '__tips__') { |
||||
|
$tips = $item; |
||||
|
unset($config[$index]); |
||||
|
} |
||||
|
} |
||||
|
$groupList['other'] = '其它'; |
||||
|
$this->view->assign("groupList", $groupList); |
||||
|
$this->view->assign("addon", ['info' => $info, 'config' => $config, 'tips' => $tips]); |
||||
|
$configFile = ADDON_PATH . $name . DS . 'config.html'; |
||||
|
$viewFile = is_file($configFile) ? $configFile : ''; |
||||
|
return $this->view->fetch($viewFile); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 安装 |
||||
|
*/ |
||||
|
public function install() |
||||
|
{ |
||||
|
$name = $this->request->post("name"); |
||||
|
$force = (int)$this->request->post("force"); |
||||
|
if (!$name) { |
||||
|
$this->error(__('Parameter %s can not be empty', 'name')); |
||||
|
} |
||||
|
if (!preg_match("/^[a-zA-Z0-9]+$/", $name)) { |
||||
|
$this->error(__('Addon name incorrect')); |
||||
|
} |
||||
|
|
||||
|
$info = []; |
||||
|
try { |
||||
|
$uid = $this->request->post("uid"); |
||||
|
$token = $this->request->post("token"); |
||||
|
$version = $this->request->post("version"); |
||||
|
$faversion = $this->request->post("faversion"); |
||||
|
$extend = [ |
||||
|
'uid' => $uid, |
||||
|
'token' => $token, |
||||
|
'version' => $version, |
||||
|
'faversion' => $faversion |
||||
|
]; |
||||
|
$info = Service::install($name, $force, $extend); |
||||
|
} catch (AddonException $e) { |
||||
|
$this->result($e->getData(), $e->getCode(), __($e->getMessage())); |
||||
|
} catch (Exception $e) { |
||||
|
$this->error(__($e->getMessage()), $e->getCode()); |
||||
|
} |
||||
|
$this->success(__('Install successful'), '', ['addon' => $info]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 卸载 |
||||
|
*/ |
||||
|
public function uninstall() |
||||
|
{ |
||||
|
$name = $this->request->post("name"); |
||||
|
$force = (int)$this->request->post("force"); |
||||
|
$droptables = (int)$this->request->post("droptables"); |
||||
|
if (!$name) { |
||||
|
$this->error(__('Parameter %s can not be empty', 'name')); |
||||
|
} |
||||
|
if (!preg_match("/^[a-zA-Z0-9]+$/", $name)) { |
||||
|
$this->error(__('Addon name incorrect')); |
||||
|
} |
||||
|
//只有开启调试且为超级管理员才允许删除相关数据库 |
||||
|
$tables = []; |
||||
|
if ($droptables && Config::get("app_debug") && $this->auth->isSuperAdmin()) { |
||||
|
$tables = get_addon_tables($name); |
||||
|
} |
||||
|
try { |
||||
|
Service::uninstall($name, $force); |
||||
|
if ($tables) { |
||||
|
$prefix = Config::get('database.prefix'); |
||||
|
//删除插件关联表 |
||||
|
foreach ($tables as $index => $table) { |
||||
|
//忽略非插件标识的表名 |
||||
|
if (!preg_match("/^{$prefix}{$name}/", $table)) { |
||||
|
continue; |
||||
|
} |
||||
|
Db::execute("DROP TABLE IF EXISTS `{$table}`"); |
||||
|
} |
||||
|
} |
||||
|
} catch (AddonException $e) { |
||||
|
$this->result($e->getData(), $e->getCode(), __($e->getMessage())); |
||||
|
} catch (Exception $e) { |
||||
|
$this->error(__($e->getMessage())); |
||||
|
} |
||||
|
$this->success(__('Uninstall successful')); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 禁用启用 |
||||
|
*/ |
||||
|
public function state() |
||||
|
{ |
||||
|
$name = $this->request->post("name"); |
||||
|
$action = $this->request->post("action"); |
||||
|
$force = (int)$this->request->post("force"); |
||||
|
if (!$name) { |
||||
|
$this->error(__('Parameter %s can not be empty', 'name')); |
||||
|
} |
||||
|
if (!preg_match("/^[a-zA-Z0-9]+$/", $name)) { |
||||
|
$this->error(__('Addon name incorrect')); |
||||
|
} |
||||
|
try { |
||||
|
$action = $action == 'enable' ? $action : 'disable'; |
||||
|
//调用启用、禁用的方法 |
||||
|
Service::$action($name, $force); |
||||
|
Cache::rm('__menu__'); |
||||
|
} catch (AddonException $e) { |
||||
|
$this->result($e->getData(), $e->getCode(), __($e->getMessage())); |
||||
|
} catch (Exception $e) { |
||||
|
$this->error(__($e->getMessage())); |
||||
|
} |
||||
|
$this->success(__('Operate successful')); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 本地上传 |
||||
|
*/ |
||||
|
public function local() |
||||
|
{ |
||||
|
Config::set('default_return_type', 'json'); |
||||
|
|
||||
|
$info = []; |
||||
|
$file = $this->request->file('file'); |
||||
|
try { |
||||
|
$uid = $this->request->post("uid"); |
||||
|
$token = $this->request->post("token"); |
||||
|
$faversion = $this->request->post("faversion"); |
||||
|
if (!$uid || !$token) { |
||||
|
throw new Exception(__('Please login and try to install')); |
||||
|
} |
||||
|
$extend = [ |
||||
|
'uid' => $uid, |
||||
|
'token' => $token, |
||||
|
'faversion' => $faversion |
||||
|
]; |
||||
|
$info = Service::local($file, $extend); |
||||
|
} catch (AddonException $e) { |
||||
|
$this->result($e->getData(), $e->getCode(), __($e->getMessage())); |
||||
|
} catch (Exception $e) { |
||||
|
$this->error(__($e->getMessage())); |
||||
|
} |
||||
|
$this->success(__('Offline installed tips'), '', ['addon' => $info]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 更新插件 |
||||
|
*/ |
||||
|
public function upgrade() |
||||
|
{ |
||||
|
$name = $this->request->post("name"); |
||||
|
$addonTmpDir = RUNTIME_PATH . 'addons' . DS; |
||||
|
if (!$name) { |
||||
|
$this->error(__('Parameter %s can not be empty', 'name')); |
||||
|
} |
||||
|
if (!preg_match("/^[a-zA-Z0-9]+$/", $name)) { |
||||
|
$this->error(__('Addon name incorrect')); |
||||
|
} |
||||
|
if (!is_dir($addonTmpDir)) { |
||||
|
@mkdir($addonTmpDir, 0755, true); |
||||
|
} |
||||
|
|
||||
|
$info = []; |
||||
|
try { |
||||
|
$info = get_addon_info($name); |
||||
|
$uid = $this->request->post("uid"); |
||||
|
$token = $this->request->post("token"); |
||||
|
$version = $this->request->post("version"); |
||||
|
$faversion = $this->request->post("faversion"); |
||||
|
$extend = [ |
||||
|
'uid' => $uid, |
||||
|
'token' => $token, |
||||
|
'version' => $version, |
||||
|
'oldversion' => $info['version'] ?? '', |
||||
|
'faversion' => $faversion |
||||
|
]; |
||||
|
//调用更新的方法 |
||||
|
$info = Service::upgrade($name, $extend); |
||||
|
Cache::rm('__menu__'); |
||||
|
} catch (AddonException $e) { |
||||
|
$this->result($e->getData(), $e->getCode(), __($e->getMessage())); |
||||
|
} catch (Exception $e) { |
||||
|
$this->error(__($e->getMessage())); |
||||
|
} |
||||
|
$this->success(__('Operate successful'), '', ['addon' => $info]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 测试数据 |
||||
|
*/ |
||||
|
public function testdata() |
||||
|
{ |
||||
|
$name = $this->request->post("name"); |
||||
|
if (!$name) { |
||||
|
$this->error(__('Parameter %s can not be empty', 'name')); |
||||
|
} |
||||
|
if (!preg_match("/^[a-zA-Z0-9]+$/", $name)) { |
||||
|
$this->error(__('Addon name incorrect')); |
||||
|
} |
||||
|
|
||||
|
try { |
||||
|
Service::importsql($name, 'testdata.sql'); |
||||
|
} catch (AddonException $e) { |
||||
|
$this->result($e->getData(), $e->getCode(), __($e->getMessage())); |
||||
|
} catch (Exception $e) { |
||||
|
$this->error(__($e->getMessage()), $e->getCode()); |
||||
|
} |
||||
|
$this->success(__('Import successful'), ''); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 已装插件 |
||||
|
*/ |
||||
|
public function downloaded() |
||||
|
{ |
||||
|
$offset = (int)$this->request->get("offset"); |
||||
|
$limit = (int)$this->request->get("limit"); |
||||
|
$filter = $this->request->get("filter"); |
||||
|
$search = $this->request->get("search"); |
||||
|
$search = htmlspecialchars(strip_tags($search)); |
||||
|
$onlineaddons = $this->getAddonList(); |
||||
|
$filter = (array)json_decode($filter, true); |
||||
|
$addons = get_addon_list(); |
||||
|
$list = []; |
||||
|
foreach ($addons as $k => $v) { |
||||
|
if ($search && stripos($v['name'], $search) === false && stripos($v['title'], $search) === false && stripos($v['intro'], $search) === false) { |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if (isset($onlineaddons[$v['name']])) { |
||||
|
$v = array_merge($v, $onlineaddons[$v['name']]); |
||||
|
$v['price'] = '-'; |
||||
|
} else { |
||||
|
$v['category_id'] = 0; |
||||
|
$v['flag'] = ''; |
||||
|
$v['banner'] = ''; |
||||
|
$v['image'] = ''; |
||||
|
$v['demourl'] = ''; |
||||
|
$v['price'] = __('None'); |
||||
|
$v['screenshots'] = []; |
||||
|
$v['releaselist'] = []; |
||||
|
$v['url'] = addon_url($v['name']); |
||||
|
$v['url'] = str_replace($this->request->server('SCRIPT_NAME'), '', $v['url']); |
||||
|
} |
||||
|
$v['createtime'] = filemtime(ADDON_PATH . $v['name']); |
||||
|
if ($filter && isset($filter['category_id']) && is_numeric($filter['category_id']) && $filter['category_id'] != $v['category_id']) { |
||||
|
continue; |
||||
|
} |
||||
|
$list[] = $v; |
||||
|
} |
||||
|
$total = count($list); |
||||
|
if ($limit) { |
||||
|
$list = array_slice($list, $offset, $limit); |
||||
|
} |
||||
|
$result = array("total" => $total, "rows" => $list); |
||||
|
|
||||
|
$callback = $this->request->get('callback') ? "jsonp" : "json"; |
||||
|
return $callback($result); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 检测 |
||||
|
*/ |
||||
|
public function isbuy() |
||||
|
{ |
||||
|
$name = $this->request->post("name"); |
||||
|
$uid = $this->request->post("uid"); |
||||
|
$token = $this->request->post("token"); |
||||
|
$version = $this->request->post("version"); |
||||
|
$faversion = $this->request->post("faversion"); |
||||
|
$extend = [ |
||||
|
'uid' => $uid, |
||||
|
'token' => $token, |
||||
|
'version' => $version, |
||||
|
'faversion' => $faversion |
||||
|
]; |
||||
|
try { |
||||
|
$result = Service::isBuy($name, $extend); |
||||
|
} catch (Exception $e) { |
||||
|
$this->error(__($e->getMessage())); |
||||
|
} |
||||
|
return json($result); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 刷新授权 |
||||
|
*/ |
||||
|
public function authorization() |
||||
|
{ |
||||
|
$params = [ |
||||
|
'uid' => $this->request->post('uid'), |
||||
|
'token' => $this->request->post('token'), |
||||
|
'faversion' => $this->request->post('faversion'), |
||||
|
]; |
||||
|
try { |
||||
|
Service::authorization($params); |
||||
|
} catch (Exception $e) { |
||||
|
$this->error(__($e->getMessage())); |
||||
|
} |
||||
|
$this->success(__('Operate successful')); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取插件相关表 |
||||
|
*/ |
||||
|
public function get_table_list() |
||||
|
{ |
||||
|
$name = $this->request->post("name"); |
||||
|
if (!preg_match("/^[a-zA-Z0-9]+$/", $name)) { |
||||
|
$this->error(__('Addon name incorrect')); |
||||
|
} |
||||
|
$tables = get_addon_tables($name); |
||||
|
$prefix = Config::get('database.prefix'); |
||||
|
foreach ($tables as $index => $table) { |
||||
|
//忽略非插件标识的表名 |
||||
|
if (!preg_match("/^{$prefix}{$name}/", $table)) { |
||||
|
unset($tables[$index]); |
||||
|
} |
||||
|
} |
||||
|
$tables = array_values($tables); |
||||
|
$this->success('', null, ['tables' => $tables]); |
||||
|
} |
||||
|
|
||||
|
protected function getAddonList() |
||||
|
{ |
||||
|
$onlineaddons = Cache::get("onlineaddons"); |
||||
|
if (!is_array($onlineaddons) && config('fastadmin.api_url')) { |
||||
|
$onlineaddons = []; |
||||
|
$params = [ |
||||
|
'uid' => $this->request->post('uid'), |
||||
|
'token' => $this->request->post('token'), |
||||
|
'version' => config('fastadmin.version'), |
||||
|
'faversion' => config('fastadmin.version'), |
||||
|
]; |
||||
|
$json = []; |
||||
|
try { |
||||
|
$json = Service::addons($params); |
||||
|
} catch (\Exception $e) { |
||||
|
|
||||
|
} |
||||
|
$rows = isset($json['rows']) ? $json['rows'] : []; |
||||
|
foreach ($rows as $index => $row) { |
||||
|
$onlineaddons[$row['name']] = $row; |
||||
|
} |
||||
|
Cache::set("onlineaddons", $onlineaddons, 600); |
||||
|
} |
||||
|
return $onlineaddons; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,313 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller; |
||||
|
|
||||
|
use app\common\controller\Backend; |
||||
|
use app\common\exception\UploadException; |
||||
|
use app\common\library\Upload; |
||||
|
use fast\Random; |
||||
|
use think\addons\Service; |
||||
|
use think\Cache; |
||||
|
use think\Config; |
||||
|
use think\Db; |
||||
|
use think\Lang; |
||||
|
use think\Response; |
||||
|
use think\Validate; |
||||
|
|
||||
|
/** |
||||
|
* Ajax异步请求接口 |
||||
|
* @internal |
||||
|
*/ |
||||
|
class Ajax extends Backend |
||||
|
{ |
||||
|
|
||||
|
protected $noNeedLogin = ['lang']; |
||||
|
protected $noNeedRight = ['*']; |
||||
|
protected $layout = ''; |
||||
|
|
||||
|
public function _initialize() |
||||
|
{ |
||||
|
parent::_initialize(); |
||||
|
|
||||
|
//设置过滤方法 |
||||
|
$this->request->filter(['trim', 'strip_tags', 'htmlspecialchars']); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 加载语言包 |
||||
|
*/ |
||||
|
public function lang() |
||||
|
{ |
||||
|
$this->request->get(['callback' => 'define']); |
||||
|
$header = ['Content-Type' => 'application/javascript']; |
||||
|
if (!config('app_debug')) { |
||||
|
$offset = 30 * 60 * 60 * 24; // 缓存一个月 |
||||
|
$header['Cache-Control'] = 'public'; |
||||
|
$header['Pragma'] = 'cache'; |
||||
|
$header['Expires'] = gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"; |
||||
|
} |
||||
|
|
||||
|
$controllername = input("controllername"); |
||||
|
//默认只加载了控制器对应的语言名,你还根据控制器名来加载额外的语言包 |
||||
|
$this->loadlang($controllername); |
||||
|
return jsonp(Lang::get(), 200, $header, ['json_encode_param' => JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 上传文件 |
||||
|
*/ |
||||
|
public function upload() |
||||
|
{ |
||||
|
Config::set('default_return_type', 'json'); |
||||
|
//必须设定cdnurl为空,否则cdnurl函数计算错误 |
||||
|
Config::set('upload.cdnurl', ''); |
||||
|
$chunkid = $this->request->post("chunkid"); |
||||
|
if ($chunkid) { |
||||
|
if (!Config::get('upload.chunking')) { |
||||
|
$this->error(__('Chunk file disabled')); |
||||
|
} |
||||
|
$action = $this->request->post("action"); |
||||
|
$chunkindex = $this->request->post("chunkindex/d"); |
||||
|
$chunkcount = $this->request->post("chunkcount/d"); |
||||
|
$filename = $this->request->post("filename"); |
||||
|
$method = $this->request->method(true); |
||||
|
if ($action == 'merge') { |
||||
|
$attachment = null; |
||||
|
//合并分片文件 |
||||
|
try { |
||||
|
$upload = new Upload(); |
||||
|
$attachment = $upload->merge($chunkid, $chunkcount, $filename); |
||||
|
} catch (UploadException $e) { |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
$this->success(__('Uploaded successful'), '', ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]); |
||||
|
} elseif ($method == 'clean') { |
||||
|
//删除冗余的分片文件 |
||||
|
try { |
||||
|
$upload = new Upload(); |
||||
|
$upload->clean($chunkid); |
||||
|
} catch (UploadException $e) { |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
$this->success(); |
||||
|
} else { |
||||
|
//上传分片文件 |
||||
|
//默认普通上传文件 |
||||
|
$file = $this->request->file('file'); |
||||
|
try { |
||||
|
$upload = new Upload($file); |
||||
|
$upload->chunk($chunkid, $chunkindex, $chunkcount); |
||||
|
} catch (UploadException $e) { |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
$this->success(); |
||||
|
} |
||||
|
} else { |
||||
|
$attachment = null; |
||||
|
//默认普通上传文件 |
||||
|
$file = $this->request->file('file'); |
||||
|
try { |
||||
|
$upload = new Upload($file); |
||||
|
$attachment = $upload->upload(); |
||||
|
} catch (UploadException $e) { |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
|
||||
|
$this->success(__('Uploaded successful'), '', ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 通用排序 |
||||
|
*/ |
||||
|
public function weigh() |
||||
|
{ |
||||
|
//排序的数组 |
||||
|
$ids = $this->request->post("ids"); |
||||
|
//拖动的记录ID |
||||
|
$changeid = $this->request->post("changeid"); |
||||
|
//操作字段 |
||||
|
$field = $this->request->post("field"); |
||||
|
//操作的数据表 |
||||
|
$table = $this->request->post("table"); |
||||
|
if (!Validate::is($table, "alphaDash")) { |
||||
|
$this->error(); |
||||
|
} |
||||
|
//主键 |
||||
|
$pk = $this->request->post("pk"); |
||||
|
//排序的方式 |
||||
|
$orderway = strtolower($this->request->post("orderway", "")); |
||||
|
$orderway = $orderway == 'asc' ? 'ASC' : 'DESC'; |
||||
|
$sour = $weighdata = []; |
||||
|
$ids = explode(',', $ids); |
||||
|
$prikey = $pk && preg_match("/^[a-z0-9\-_]+$/i", $pk) ? $pk : (Db::name($table)->getPk() ?: 'id'); |
||||
|
$pid = $this->request->post("pid", ""); |
||||
|
//限制更新的字段 |
||||
|
$field = in_array($field, ['weigh']) ? $field : 'weigh'; |
||||
|
|
||||
|
// 如果设定了pid的值,此时只匹配满足条件的ID,其它忽略 |
||||
|
if ($pid !== '') { |
||||
|
$hasids = []; |
||||
|
$list = Db::name($table)->where($prikey, 'in', $ids)->where('pid', 'in', $pid)->field("{$prikey},pid")->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
$hasids[] = $v[$prikey]; |
||||
|
} |
||||
|
$ids = array_values(array_intersect($ids, $hasids)); |
||||
|
} |
||||
|
|
||||
|
$list = Db::name($table)->field("$prikey,$field")->where($prikey, 'in', $ids)->order($field, $orderway)->select(); |
||||
|
foreach ($list as $k => $v) { |
||||
|
$sour[] = $v[$prikey]; |
||||
|
$weighdata[$v[$prikey]] = $v[$field]; |
||||
|
} |
||||
|
$position = array_search($changeid, $ids); |
||||
|
$desc_id = isset($sour[$position]) ? $sour[$position] : end($sour); //移动到目标的ID值,取出所处改变前位置的值 |
||||
|
$sour_id = $changeid; |
||||
|
$weighids = array(); |
||||
|
$temp = array_values(array_diff_assoc($ids, $sour)); |
||||
|
foreach ($temp as $m => $n) { |
||||
|
if ($n == $sour_id) { |
||||
|
$offset = $desc_id; |
||||
|
} else { |
||||
|
if ($sour_id == $temp[0]) { |
||||
|
$offset = isset($temp[$m + 1]) ? $temp[$m + 1] : $sour_id; |
||||
|
} else { |
||||
|
$offset = isset($temp[$m - 1]) ? $temp[$m - 1] : $sour_id; |
||||
|
} |
||||
|
} |
||||
|
if (!isset($weighdata[$offset])) { |
||||
|
continue; |
||||
|
} |
||||
|
$weighids[$n] = $weighdata[$offset]; |
||||
|
Db::name($table)->where($prikey, $n)->update([$field => $weighdata[$offset]]); |
||||
|
} |
||||
|
$this->success(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 清空系统缓存 |
||||
|
*/ |
||||
|
public function wipecache() |
||||
|
{ |
||||
|
try { |
||||
|
$type = $this->request->request("type"); |
||||
|
switch ($type) { |
||||
|
case 'all': |
||||
|
// no break |
||||
|
case 'content': |
||||
|
//内容缓存 |
||||
|
rmdirs(CACHE_PATH, false); |
||||
|
Cache::clear(); |
||||
|
if ($type == 'content') { |
||||
|
break; |
||||
|
} |
||||
|
case 'template': |
||||
|
// 模板缓存 |
||||
|
rmdirs(TEMP_PATH, false); |
||||
|
if ($type == 'template') { |
||||
|
break; |
||||
|
} |
||||
|
case 'addons': |
||||
|
// 插件缓存 |
||||
|
Service::refresh(); |
||||
|
if ($type == 'addons') { |
||||
|
break; |
||||
|
} |
||||
|
case 'browser': |
||||
|
// 浏览器缓存 |
||||
|
// 只有生产环境下才修改 |
||||
|
if (!config('app_debug')) { |
||||
|
$version = config('site.version'); |
||||
|
$newversion = preg_replace_callback("/(.*)\.([0-9]+)\$/", function ($match) { |
||||
|
return $match[1] . '.' . ($match[2] + 1); |
||||
|
}, $version); |
||||
|
if ($newversion && $newversion != $version) { |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
\app\common\model\Config::where('name', 'version')->update(['value' => $newversion]); |
||||
|
\app\common\model\Config::refreshFile(); |
||||
|
Db::commit(); |
||||
|
} catch (\Exception $e) { |
||||
|
Db::rollback(); |
||||
|
exception($e->getMessage()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
if ($type == 'browser') { |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} catch (\Exception $e) { |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
|
||||
|
\think\Hook::listen("wipecache_after"); |
||||
|
$this->success(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 读取分类数据,联动列表 |
||||
|
*/ |
||||
|
public function category() |
||||
|
{ |
||||
|
$type = $this->request->get('type', ''); |
||||
|
$pid = $this->request->get('pid', ''); |
||||
|
$where = ['status' => 'normal']; |
||||
|
$categorylist = null; |
||||
|
if ($pid || $pid === '0') { |
||||
|
$where['pid'] = $pid; |
||||
|
} |
||||
|
if ($type) { |
||||
|
$where['type'] = $type; |
||||
|
} |
||||
|
|
||||
|
$categorylist = Db::name('category')->where($where)->field('id as value,name')->order('weigh desc,id desc')->select(); |
||||
|
|
||||
|
$this->success('', '', $categorylist); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 读取省市区数据,联动列表 |
||||
|
*/ |
||||
|
public function area() |
||||
|
{ |
||||
|
$params = $this->request->get("row/a"); |
||||
|
if (!empty($params)) { |
||||
|
$province = isset($params['province']) ? $params['province'] : null; |
||||
|
$city = isset($params['city']) ? $params['city'] : null; |
||||
|
} else { |
||||
|
$province = $this->request->get('province'); |
||||
|
$city = $this->request->get('city'); |
||||
|
} |
||||
|
$where = ['pid' => 0, 'level' => 1]; |
||||
|
$provincelist = null; |
||||
|
if ($province !== null) { |
||||
|
$where['pid'] = $province; |
||||
|
$where['level'] = 2; |
||||
|
if ($city !== null) { |
||||
|
$where['pid'] = $city; |
||||
|
$where['level'] = 3; |
||||
|
} |
||||
|
} |
||||
|
$provincelist = Db::name('area')->where($where)->field('id as value,name')->select(); |
||||
|
$this->success('', '', $provincelist); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 生成后缀图标 |
||||
|
*/ |
||||
|
public function icon() |
||||
|
{ |
||||
|
$suffix = $this->request->request("suffix"); |
||||
|
$suffix = $suffix ? $suffix : "FILE"; |
||||
|
$data = build_suffix_image($suffix); |
||||
|
$header = ['Content-Type' => 'image/svg+xml']; |
||||
|
$offset = 30 * 60 * 60 * 24; // 缓存一个月 |
||||
|
$header['Cache-Control'] = 'public'; |
||||
|
$header['Pragma'] = 'cache'; |
||||
|
$header['Expires'] = gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"; |
||||
|
$response = Response::create($data, '', 200, $header); |
||||
|
return $response; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,158 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller; |
||||
|
|
||||
|
use app\common\controller\Backend; |
||||
|
use app\common\model\Category as CategoryModel; |
||||
|
use fast\Tree; |
||||
|
|
||||
|
/** |
||||
|
* 分类管理 |
||||
|
* |
||||
|
* @icon fa fa-list |
||||
|
* @remark 用于管理网站的所有分类,分类可进行无限级分类,分类类型请在常规管理->系统配置->字典配置中添加 |
||||
|
*/ |
||||
|
class Category extends Backend |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* @var \app\common\model\Category |
||||
|
*/ |
||||
|
protected $model = null; |
||||
|
protected $categorylist = []; |
||||
|
protected $noNeedRight = ['selectpage']; |
||||
|
|
||||
|
public function _initialize() |
||||
|
{ |
||||
|
parent::_initialize(); |
||||
|
$this->model = model('app\common\model\Category'); |
||||
|
|
||||
|
$tree = Tree::instance(); |
||||
|
$tree->init(collection($this->model->order('weigh desc,id desc')->select())->toArray(), 'pid'); |
||||
|
$this->categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name'); |
||||
|
$categorydata = [0 => ['type' => 'all', 'name' => __('None')]]; |
||||
|
foreach ($this->categorylist as $k => $v) { |
||||
|
$categorydata[$v['id']] = $v; |
||||
|
} |
||||
|
$typeList = CategoryModel::getTypeList(); |
||||
|
$this->view->assign("flagList", $this->model->getFlagList()); |
||||
|
$this->view->assign("typeList", $typeList); |
||||
|
$this->view->assign("parentList", $categorydata); |
||||
|
$this->assignconfig('typeList', $typeList); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() |
||||
|
{ |
||||
|
//设置过滤方法 |
||||
|
$this->request->filter(['strip_tags']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
$search = $this->request->request("search"); |
||||
|
$type = $this->request->request("type"); |
||||
|
|
||||
|
//构造父类select列表选项数据 |
||||
|
$list = []; |
||||
|
|
||||
|
foreach ($this->categorylist as $k => $v) { |
||||
|
if ($search) { |
||||
|
if ($v['type'] == $type && stripos($v['name'], $search) !== false || stripos($v['nickname'], $search) !== false) { |
||||
|
if ($type == "all" || $type == null) { |
||||
|
$list = $this->categorylist; |
||||
|
} else { |
||||
|
$list[] = $v; |
||||
|
} |
||||
|
} |
||||
|
} else { |
||||
|
if ($type == "all" || $type == null) { |
||||
|
$list = $this->categorylist; |
||||
|
} elseif ($v['type'] == $type) { |
||||
|
$list[] = $v; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$total = count($list); |
||||
|
$result = array("total" => $total, "rows" => $list); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加 |
||||
|
*/ |
||||
|
public function add() |
||||
|
{ |
||||
|
if ($this->request->isPost()) { |
||||
|
$this->token(); |
||||
|
} |
||||
|
return parent::add(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 编辑 |
||||
|
*/ |
||||
|
public function edit($ids = null) |
||||
|
{ |
||||
|
$row = $this->model->get($ids); |
||||
|
if (!$row) { |
||||
|
$this->error(__('No Results were found')); |
||||
|
} |
||||
|
$adminIds = $this->getDataLimitAdminIds(); |
||||
|
if (is_array($adminIds)) { |
||||
|
if (!in_array($row[$this->dataLimitField], $adminIds)) { |
||||
|
$this->error(__('You have no permission')); |
||||
|
} |
||||
|
} |
||||
|
if ($this->request->isPost()) { |
||||
|
$this->token(); |
||||
|
$params = $this->request->post("row/a"); |
||||
|
if ($params) { |
||||
|
$params = $this->preExcludeFields($params); |
||||
|
|
||||
|
if ($params['pid'] != $row['pid']) { |
||||
|
$childrenIds = Tree::instance()->init(collection(\app\common\model\Category::select())->toArray())->getChildrenIds($row['id'], true); |
||||
|
if (in_array($params['pid'], $childrenIds)) { |
||||
|
$this->error(__('Can not change the parent to child or itself')); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
try { |
||||
|
//是否采用模型验证 |
||||
|
if ($this->modelValidate) { |
||||
|
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); |
||||
|
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; |
||||
|
$row->validate($validate); |
||||
|
} |
||||
|
$result = $row->allowField(true)->save($params); |
||||
|
if ($result !== false) { |
||||
|
$this->success(); |
||||
|
} else { |
||||
|
$this->error($row->getError()); |
||||
|
} |
||||
|
} catch (\think\exception\PDOException $e) { |
||||
|
$this->error($e->getMessage()); |
||||
|
} catch (\think\Exception $e) { |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
} |
||||
|
$this->error(__('Parameter %s can not be empty', '')); |
||||
|
} |
||||
|
$this->view->assign("row", $row); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Selectpage搜索 |
||||
|
* |
||||
|
* @internal |
||||
|
*/ |
||||
|
public function selectpage() |
||||
|
{ |
||||
|
return parent::selectpage(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,85 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller; |
||||
|
|
||||
|
use app\admin\model\Admin; |
||||
|
use app\admin\model\User; |
||||
|
use app\common\controller\Backend; |
||||
|
use app\common\model\Attachment; |
||||
|
use fast\Date; |
||||
|
use think\Db; |
||||
|
|
||||
|
/** |
||||
|
* 控制台 |
||||
|
* |
||||
|
* @icon fa fa-dashboard |
||||
|
* @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据 |
||||
|
*/ |
||||
|
class Dashboard extends Backend |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() |
||||
|
{ |
||||
|
try { |
||||
|
\think\Db::execute("SET @@sql_mode='';"); |
||||
|
} catch (\Exception $e) { |
||||
|
|
||||
|
} |
||||
|
$column = []; |
||||
|
$starttime = Date::unixtime('day', -6); |
||||
|
$endtime = Date::unixtime('day', 0, 'end'); |
||||
|
$joinlist = Db("user")->where('jointime', 'between time', [$starttime, $endtime]) |
||||
|
->where('cid',CID) |
||||
|
->field('jointime, status, COUNT(*) AS nums, DATE_FORMAT(FROM_UNIXTIME(jointime), "%Y-%m-%d") AS join_date') |
||||
|
->group('join_date') |
||||
|
->select(); |
||||
|
for ($time = $starttime; $time <= $endtime;) { |
||||
|
$column[] = date("Y-m-d", $time); |
||||
|
$time += 86400; |
||||
|
} |
||||
|
$userlist = array_fill_keys($column, 0); |
||||
|
foreach ($joinlist as $k => $v) { |
||||
|
$userlist[$v['join_date']] = $v['nums']; |
||||
|
} |
||||
|
|
||||
|
$dbTableList = Db::query("SHOW TABLE STATUS"); |
||||
|
$addonList = get_addon_list(); |
||||
|
$totalworkingaddon = 0; |
||||
|
$totaladdon = count($addonList); |
||||
|
foreach ($addonList as $index => $item) { |
||||
|
if ($item['state']) { |
||||
|
$totalworkingaddon += 1; |
||||
|
} |
||||
|
} |
||||
|
$this->view->assign([ |
||||
|
'totaluser' => User::count(), |
||||
|
'totaladdon' => $totaladdon, |
||||
|
'totaladmin' => Admin::count(), |
||||
|
'totalcategory' => \app\common\model\Category::count(), |
||||
|
'todayusersignup' => User::whereTime('jointime', 'today')->count(), |
||||
|
'todayuserlogin' => User::whereTime('logintime', 'today')->count(), |
||||
|
'sevendau' => User::whereTime('jointime|logintime|prevtime', '-7 days')->count(), |
||||
|
'thirtydau' => User::whereTime('jointime|logintime|prevtime', '-30 days')->count(), |
||||
|
'threednu' => User::whereTime('jointime', '-3 days')->count(), |
||||
|
'sevendnu' => User::whereTime('jointime', '-7 days')->count(), |
||||
|
'dbtablenums' => count($dbTableList), |
||||
|
'dbsize' => array_sum(array_map(function ($item) { |
||||
|
return $item['Data_length'] + $item['Index_length']; |
||||
|
}, $dbTableList)), |
||||
|
'totalworkingaddon' => $totalworkingaddon, |
||||
|
'attachmentnums' => Attachment::count(), |
||||
|
'attachmentsize' => Attachment::sum('filesize'), |
||||
|
'picturenums' => Attachment::where('mimetype', 'like', 'image/%')->count(), |
||||
|
'picturesize' => Attachment::where('mimetype', 'like', 'image/%')->sum('filesize'), |
||||
|
]); |
||||
|
|
||||
|
$this->assignconfig('column', array_keys($userlist)); |
||||
|
$this->assignconfig('userdata', array_values($userlist)); |
||||
|
|
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,320 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller; |
||||
|
|
||||
|
use addons\qingdong\model\Staff; |
||||
|
use addons\qingdong\model\StaffDepartment; |
||||
|
use addons\qingdong\model\StaffRole; |
||||
|
use app\admin\model\AdminLog; |
||||
|
use app\admin\model\AuthGroup; |
||||
|
use app\admin\model\Company; |
||||
|
use app\admin\model\Member; |
||||
|
use app\admin\model\MemberCompany; |
||||
|
use app\admin\model\MemberGroup; |
||||
|
use app\admin\model\MemberGroupAccess; |
||||
|
use app\admin\model\User; |
||||
|
use app\common\controller\Backend; |
||||
|
use fast\Random; |
||||
|
use think\Cache; |
||||
|
use think\Config; |
||||
|
use think\Db; |
||||
|
use think\Exception; |
||||
|
use think\Hook; |
||||
|
use think\Session; |
||||
|
use think\Validate; |
||||
|
|
||||
|
/** |
||||
|
* 后台首页 |
||||
|
* @internal |
||||
|
*/ |
||||
|
class Index extends Backend |
||||
|
{ |
||||
|
|
||||
|
protected $noNeedLogin = ['login','register','sendSms']; |
||||
|
protected $noNeedRight = ['index', 'logout']; |
||||
|
protected $layout = ''; |
||||
|
|
||||
|
public function _initialize() |
||||
|
{ |
||||
|
parent::_initialize(); |
||||
|
//移除HTML标签 |
||||
|
$this->request->filter('trim,strip_tags,htmlspecialchars'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 后台首页 |
||||
|
*/ |
||||
|
public function index() |
||||
|
{ |
||||
|
$cookieArr = ['adminskin' => "/^skin\-([a-z\-]+)\$/i", 'multiplenav' => "/^(0|1)\$/", 'multipletab' => "/^(0|1)\$/", 'show_submenu' => "/^(0|1)\$/"]; |
||||
|
foreach ($cookieArr as $key => $regex) { |
||||
|
$cookieValue = $this->request->cookie($key); |
||||
|
if (!is_null($cookieValue) && preg_match($regex, $cookieValue)) { |
||||
|
config('fastadmin.' . $key, $cookieValue); |
||||
|
} |
||||
|
} |
||||
|
//左侧菜单 |
||||
|
list($menulist, $navlist, $fixedmenu, $referermenu) = $this->auth->getSidebar([ |
||||
|
'dashboard' => 'hot', |
||||
|
'addon' => ['new', 'red', 'badge'], |
||||
|
'auth/rule' => __('Menu'), |
||||
|
'general' => ['new', 'purple'], |
||||
|
], $this->view->site['fixedpage']); |
||||
|
|
||||
|
//获取公司信息 |
||||
|
$admin = Session::get('admin')?Session::get('admin'):Session::get('member'); |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
$action = $this->request->request('action'); |
||||
|
if ($this->request->isPost()) { |
||||
|
if ($action == 'refreshmenu') { |
||||
|
$this->success('', null, ['menulist' => $menulist, 'navlist' => $navlist]); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
$companys = Db::name("member_company")->where('uid','=',$admin['id'])->select(); |
||||
|
|
||||
|
$cids = array_column($companys,'cid',NULL); |
||||
|
$nowCompany = new Company(); |
||||
|
$scompany = Db::name("company")->where("id",'in',$cids)->select(); |
||||
|
|
||||
|
foreach ($scompany as $v){ |
||||
|
if($v['id'] == CID){ |
||||
|
$nowCompany = $v; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$this->assignconfig('cookie', ['prefix' => config('cookie.prefix')]); |
||||
|
$this->view->assign('companyList', $scompany); |
||||
|
$this->view->assign('nowCompany', $nowCompany); |
||||
|
$this->view->assign('menulist', $menulist); |
||||
|
$this->view->assign('navlist', $navlist); |
||||
|
$this->view->assign('fixedmenu', $fixedmenu); |
||||
|
$this->view->assign('referermenu', $referermenu); |
||||
|
$this->view->assign('title', __('Home')); |
||||
|
|
||||
|
// |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 管理员登录 |
||||
|
*/ |
||||
|
public function login() |
||||
|
{ |
||||
|
$url = $this->request->get('url', 'index/index'); |
||||
|
if ($this->auth->isLogin()) { |
||||
|
$this->success(__("You've logged in, do not login again"), $url); |
||||
|
} |
||||
|
if ($this->request->isPost()) { |
||||
|
$username = $this->request->post('username'); |
||||
|
$password = $this->request->post('password'); |
||||
|
$keeplogin = $this->request->post('keeplogin'); |
||||
|
$token = $this->request->post('__token__'); |
||||
|
$rule = [ |
||||
|
'username' => 'require|length:3,30', |
||||
|
'password' => 'require|length:3,30', |
||||
|
'__token__' => 'require|token', |
||||
|
]; |
||||
|
$data = [ |
||||
|
'username' => $username, |
||||
|
'password' => $password, |
||||
|
'__token__' => $token, |
||||
|
]; |
||||
|
if (Config::get('fastadmin.login_captcha')) { |
||||
|
$rule['captcha'] = 'require|captcha'; |
||||
|
$data['captcha'] = $this->request->post('captcha'); |
||||
|
} |
||||
|
$validate = new Validate($rule, [], ['username' => __('Username'), 'password' => __('Password'), 'captcha' => __('Captcha')]); |
||||
|
$result = $validate->check($data); |
||||
|
if (!$result) { |
||||
|
$this->error($validate->getError(), $url, ['token' => $this->request->token()]); |
||||
|
} |
||||
|
AdminLog::setTitle(__('Login')); |
||||
|
$result = $this->auth->login($username, $password, $keeplogin ? 86400 : 0); |
||||
|
if ($result === true) { |
||||
|
Hook::listen("admin_login_after", $this->request); |
||||
|
$this->success(__('Login successful'), $url, ['url' => $url, 'id' => $this->auth->id, 'username' => $username, 'avatar' => $this->auth->avatar]); |
||||
|
} else { |
||||
|
$msg = $this->auth->getError(); |
||||
|
$msg = $msg ? $msg : __('Username or password is incorrect'); |
||||
|
$this->error($msg, $url, ['token' => $this->request->token()]); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 根据客户端的cookie,判断是否可以自动登录 |
||||
|
if ($this->auth->autologin()) { |
||||
|
Session::delete("referer"); |
||||
|
$this->redirect($url); |
||||
|
} |
||||
|
$background = Config::get('fastadmin.login_background'); |
||||
|
$background = $background ? (stripos($background, 'http') === 0 ? $background : config('site.cdnurl') . $background) : ''; |
||||
|
$this->view->assign('background', $background); |
||||
|
$this->view->assign('title', __('Login')); |
||||
|
Hook::listen("admin_login_init", $this->request); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 退出登录 |
||||
|
*/ |
||||
|
public function logout() |
||||
|
{ |
||||
|
if ($this->request->isPost()) { |
||||
|
$this->auth->logout(); |
||||
|
Hook::listen("admin_logout_after", $this->request); |
||||
|
$this->success(__('Logout successful'), 'index/register'); |
||||
|
} |
||||
|
$html = "<form id='logout_submit' name='logout_submit' action='' method='post'>" . token() . "<input type='submit' value='ok' style='display:none;'></form>"; |
||||
|
$html .= "<script>document.forms['logout_submit'].submit();</script>"; |
||||
|
|
||||
|
return $html; |
||||
|
} |
||||
|
/** |
||||
|
* 获取验证码 |
||||
|
*/ |
||||
|
public function sendSms() |
||||
|
{ |
||||
|
$mobile = $this->request->get('mobile', ''); |
||||
|
if(!$mobile){ |
||||
|
$this->error("请输入手机号"); |
||||
|
} |
||||
|
//生成验证码 |
||||
|
$random = 8888; |
||||
|
// rand(1000,9999) |
||||
|
//发送验证码 |
||||
|
$flag = 1; |
||||
|
if(!$flag){ |
||||
|
$this->error("验证码发送失败,请稍后重试!"); |
||||
|
} |
||||
|
|
||||
|
Cache::set("yzm_".$mobile,$random,600); |
||||
|
|
||||
|
$this->success("发送成功"); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 用户登录/注册 |
||||
|
*/ |
||||
|
public function register() |
||||
|
{ |
||||
|
$url = $this->request->get('url', 'index/index'); |
||||
|
if ($this->auth->isLogin()) { |
||||
|
$this->success(__("You've logged in, do not login again"), $url); |
||||
|
} |
||||
|
|
||||
|
if ($this->request->isPost()) { |
||||
|
|
||||
|
$mobile = $this->request->post('mobile', ''); |
||||
|
$code = $this->request->post('code', ''); |
||||
|
|
||||
|
if(!$mobile){ |
||||
|
$this->error("请输入手机号"); |
||||
|
} |
||||
|
if(!$code){ |
||||
|
$this->error("请输入验证码"); |
||||
|
} |
||||
|
|
||||
|
//先判断验证码是否正确 |
||||
|
$codes = Cache::get("yzm_".$mobile); |
||||
|
if($code != $codes){ |
||||
|
$this->error("验证码不正确,请重新获取!"); |
||||
|
} |
||||
|
|
||||
|
AdminLog::setTitle(__('Login')); |
||||
|
|
||||
|
//先判断是是否有用户 没有新建 |
||||
|
$suerModel = new Staff(); |
||||
|
$user = $suerModel->where("mobile",$mobile)->find(); |
||||
|
if($user && $user['status']!=1){ |
||||
|
$this->error("账号异常,请联系管理员!"); |
||||
|
} |
||||
|
if(!$user){ |
||||
|
//建立我的团队 |
||||
|
$company['name'] = "我的团队"; |
||||
|
$companyModel = new Company(); |
||||
|
//先保存企业默认数据 |
||||
|
$companyModel->save($company); |
||||
|
$result2 = $companyModel->getLastInsID(); |
||||
|
|
||||
|
|
||||
|
//建立用户组 |
||||
|
$memberGroup['name'] = "我的团队"; |
||||
|
$memberGroup['pid'] = 0; |
||||
|
$memberGroup['rules'] = "*"; |
||||
|
$memberGroup['cid'] = $result2; |
||||
|
$memberGroup['status'] = "normal"; |
||||
|
$memberGroupModel = new MemberGroup(); |
||||
|
$memberGroupModel->save($memberGroup); |
||||
|
$result4 = $memberGroupModel->getLastInsID(); |
||||
|
|
||||
|
//建立角色 |
||||
|
$roleModel = new StaffRole(); |
||||
|
$role['name'] = "主管"; |
||||
|
$role['cid'] = $result2; |
||||
|
$roleModel->save($role); |
||||
|
$result5 = $roleModel->getLastInsID(); |
||||
|
|
||||
|
// $data['username'] = $mobile; |
||||
|
$data['group_ids'] = $result4; |
||||
|
$data['department_id'] = $result5; |
||||
|
$data['role'] = $result5; |
||||
|
|
||||
|
$data['post'] = "负责人"; |
||||
|
$data['mobile'] = $mobile; |
||||
|
$data['name'] = "用户".rand(100000,999999); |
||||
|
$data['password'] = '123456'; |
||||
|
$data['email'] = ''; |
||||
|
$newSalt = substr(md5(uniqid(true)), 0, 6); |
||||
|
$newPassword = md5(md5($data['password']) . $newSalt); |
||||
|
$data['salt'] = $newSalt; |
||||
|
$data['password'] = $newPassword; |
||||
|
$data['status'] = 1; |
||||
|
$data['cid'] = $result2; |
||||
|
$data['img'] = '/assets/img/avatar.png'; //设置新管理员默认头像。 |
||||
|
$data['num'] = "01"; |
||||
|
//先保存数据 |
||||
|
$res = $suerModel->save($data); |
||||
|
if(!$res){ |
||||
|
$this->error("保存信息错误,请重试!"); |
||||
|
} |
||||
|
$result = $suerModel->getLastInsID(); |
||||
|
|
||||
|
//建立企业与个人绑定关系 |
||||
|
$userCompany['cid'] =$result2; |
||||
|
$userCompany['uid'] =$result; |
||||
|
$usercompanyModel = new MemberCompany(); |
||||
|
$usercompanyModel->save($userCompany); |
||||
|
|
||||
|
$memberGroupAccess['uid'] = $result; |
||||
|
$memberGroupAccess['cid'] = $result2; |
||||
|
$memberGroupAccess['group_id'] = $result4; |
||||
|
$memberGroupAccessModel = new MemberGroupAccess(); |
||||
|
$memberGroupAccessModel->save($memberGroupAccess); |
||||
|
} |
||||
|
|
||||
|
$result = $this->auth->loginByNoPass($mobile); |
||||
|
|
||||
|
if ($result === true) { |
||||
|
Hook::listen("admin_login_after", $this->request); |
||||
|
$this->success(__('Login successful'), $url, ['url' => $url, 'id' => $this->auth->id, 'username' => $mobile, 'avatar' => $this->auth->avatar]); |
||||
|
} else { |
||||
|
$msg = $this->auth->getError(); |
||||
|
$msg = $msg ? $msg : "登录失败"; |
||||
|
$this->error($msg, $url, ['token' => $this->request->token()]); |
||||
|
} |
||||
|
} |
||||
|
$background = Config::get('fastadmin.login_background'); |
||||
|
$background = $background ? (stripos($background, 'http') === 0 ? $background : config('site.cdnurl') . $background) : ''; |
||||
|
$this->view->assign('background', $background); |
||||
|
$this->view->assign('title', __('Login')); |
||||
|
Hook::listen("admin_login_init", $this->request); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,297 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\auth; |
||||
|
|
||||
|
use app\admin\model\AuthGroup; |
||||
|
use app\admin\model\AuthGroupAccess; |
||||
|
use app\common\controller\Backend; |
||||
|
use fast\Random; |
||||
|
use fast\Tree; |
||||
|
use think\Db; |
||||
|
use think\Validate; |
||||
|
|
||||
|
/** |
||||
|
* 管理员管理 |
||||
|
* |
||||
|
* @icon fa fa-users |
||||
|
* @remark 一个管理员可以有多个角色组,左侧的菜单根据管理员所拥有的权限进行生成 |
||||
|
*/ |
||||
|
class Admin extends Backend |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* @var \app\admin\model\Admin |
||||
|
*/ |
||||
|
protected $model = null; |
||||
|
protected $selectpageFields = 'id,username,nickname,avatar'; |
||||
|
protected $searchFields = 'id,username,nickname'; |
||||
|
protected $childrenGroupIds = []; |
||||
|
protected $childrenAdminIds = []; |
||||
|
|
||||
|
public function _initialize() |
||||
|
{ |
||||
|
parent::_initialize(); |
||||
|
$this->model = model('Admin'); |
||||
|
|
||||
|
$this->childrenAdminIds = $this->auth->getChildrenAdminIds($this->auth->isSuperAdmin()); |
||||
|
$this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin()); |
||||
|
|
||||
|
$groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray(); |
||||
|
|
||||
|
Tree::instance()->init($groupList); |
||||
|
$groupdata = []; |
||||
|
if ($this->auth->isSuperAdmin()) { |
||||
|
$result = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0)); |
||||
|
foreach ($result as $k => $v) { |
||||
|
$groupdata[$v['id']] = $v['name']; |
||||
|
} |
||||
|
} else { |
||||
|
$result = []; |
||||
|
$groups = $this->auth->getGroups(); |
||||
|
foreach ($groups as $m => $n) { |
||||
|
$childlist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['id'])); |
||||
|
$temp = []; |
||||
|
foreach ($childlist as $k => $v) { |
||||
|
$temp[$v['id']] = $v['name']; |
||||
|
} |
||||
|
$result[__($n['name'])] = $temp; |
||||
|
} |
||||
|
$groupdata = $result; |
||||
|
} |
||||
|
|
||||
|
$this->view->assign('groupdata', $groupdata); |
||||
|
$this->assignconfig("admin", ['id' => $this->auth->id]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() |
||||
|
{ |
||||
|
//设置过滤方法 |
||||
|
$this->request->filter(['strip_tags', 'trim']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
//如果发送的来源是Selectpage,则转发到Selectpage |
||||
|
if ($this->request->request('keyField')) { |
||||
|
return $this->selectpage(); |
||||
|
} |
||||
|
$childrenGroupIds = $this->childrenGroupIds; |
||||
|
$groupName = AuthGroup::where('id', 'in', $childrenGroupIds) |
||||
|
->column('id,name'); |
||||
|
$authGroupList = AuthGroupAccess::where('group_id', 'in', $childrenGroupIds) |
||||
|
->field('uid,group_id') |
||||
|
->select(); |
||||
|
|
||||
|
$adminGroupName = []; |
||||
|
foreach ($authGroupList as $k => $v) { |
||||
|
if (isset($groupName[$v['group_id']])) { |
||||
|
$adminGroupName[$v['uid']][$v['group_id']] = $groupName[$v['group_id']]; |
||||
|
} |
||||
|
} |
||||
|
$groups = $this->auth->getGroups(); |
||||
|
foreach ($groups as $m => $n) { |
||||
|
$adminGroupName[$this->auth->id][$n['id']] = $n['name']; |
||||
|
} |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
|
||||
|
$list = $this->model |
||||
|
->where($where) |
||||
|
->where('id', 'in', $this->childrenAdminIds) |
||||
|
->field(['password', 'salt', 'token'], true) |
||||
|
->order($sort, $order) |
||||
|
->paginate($limit); |
||||
|
|
||||
|
foreach ($list as $k => &$v) { |
||||
|
$groups = isset($adminGroupName[$v['id']]) ? $adminGroupName[$v['id']] : []; |
||||
|
$v['groups'] = implode(',', array_keys($groups)); |
||||
|
$v['groups_text'] = implode(',', array_values($groups)); |
||||
|
} |
||||
|
unset($v); |
||||
|
$result = array("total" => $list->total(), "rows" => $list->items()); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加 |
||||
|
*/ |
||||
|
public function add() |
||||
|
{ |
||||
|
if ($this->request->isPost()) { |
||||
|
$this->token(); |
||||
|
$params = $this->request->post("row/a"); |
||||
|
if ($params) { |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
if (!Validate::is($params['password'], '\S{6,30}')) { |
||||
|
exception(__("Please input correct password")); |
||||
|
} |
||||
|
$params['salt'] = Random::alnum(); |
||||
|
$params['password'] = md5(md5($params['password']) . $params['salt']); |
||||
|
$params['avatar'] = '/assets/img/avatar.png'; //设置新管理员默认头像。 |
||||
|
$result = $this->model->validate('Admin.add')->save($params); |
||||
|
if ($result === false) { |
||||
|
exception($this->model->getError()); |
||||
|
} |
||||
|
$group = $this->request->post("group/a"); |
||||
|
|
||||
|
//过滤不允许的组别,避免越权 |
||||
|
$group = array_intersect($this->childrenGroupIds, $group); |
||||
|
if (!$group) { |
||||
|
exception(__('The parent group exceeds permission limit')); |
||||
|
} |
||||
|
|
||||
|
$dataset = []; |
||||
|
foreach ($group as $value) { |
||||
|
$dataset[] = ['uid' => $this->model->id, 'group_id' => $value]; |
||||
|
} |
||||
|
model('AuthGroupAccess')->saveAll($dataset); |
||||
|
Db::commit(); |
||||
|
} catch (\Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
$this->success(); |
||||
|
} |
||||
|
$this->error(__('Parameter %s can not be empty', '')); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 编辑 |
||||
|
*/ |
||||
|
public function edit($ids = null) |
||||
|
{ |
||||
|
$row = $this->model->get(['id' => $ids]); |
||||
|
if (!$row) { |
||||
|
$this->error(__('No Results were found')); |
||||
|
} |
||||
|
if (!in_array($row->id, $this->childrenAdminIds)) { |
||||
|
$this->error(__('You have no permission')); |
||||
|
} |
||||
|
if ($this->request->isPost()) { |
||||
|
$this->token(); |
||||
|
$params = $this->request->post("row/a"); |
||||
|
if ($params) { |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
if ($params['password']) { |
||||
|
if (!Validate::is($params['password'], '\S{6,30}')) { |
||||
|
exception(__("Please input correct password")); |
||||
|
} |
||||
|
$params['salt'] = Random::alnum(); |
||||
|
$params['password'] = md5(md5($params['password']) . $params['salt']); |
||||
|
} else { |
||||
|
unset($params['password'], $params['salt']); |
||||
|
} |
||||
|
//这里需要针对username和email做唯一验证 |
||||
|
$adminValidate = \think\Loader::validate('Admin'); |
||||
|
$adminValidate->rule([ |
||||
|
'username' => 'require|regex:\w{3,30}|unique:admin,username,' . $row->id, |
||||
|
'email' => 'require|email|unique:admin,email,' . $row->id, |
||||
|
'mobile' => 'regex:1[3-9]\d{9}|unique:admin,mobile,' . $row->id, |
||||
|
'password' => 'regex:\S{32}', |
||||
|
]); |
||||
|
$result = $row->validate('Admin.edit')->save($params); |
||||
|
if ($result === false) { |
||||
|
exception($row->getError()); |
||||
|
} |
||||
|
|
||||
|
// 先移除所有权限 |
||||
|
model('AuthGroupAccess')->where('uid', $row->id)->delete(); |
||||
|
|
||||
|
$group = $this->request->post("group/a"); |
||||
|
|
||||
|
// 过滤不允许的组别,避免越权 |
||||
|
$group = array_intersect($this->childrenGroupIds, $group); |
||||
|
if (!$group) { |
||||
|
exception(__('The parent group exceeds permission limit')); |
||||
|
} |
||||
|
|
||||
|
$dataset = []; |
||||
|
foreach ($group as $value) { |
||||
|
$dataset[] = ['uid' => $row->id, 'group_id' => $value]; |
||||
|
} |
||||
|
model('AuthGroupAccess')->saveAll($dataset); |
||||
|
Db::commit(); |
||||
|
} catch (\Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
$this->success(); |
||||
|
} |
||||
|
$this->error(__('Parameter %s can not be empty', '')); |
||||
|
} |
||||
|
$grouplist = $this->auth->getGroups($row['id']); |
||||
|
$groupids = []; |
||||
|
foreach ($grouplist as $k => $v) { |
||||
|
$groupids[] = $v['id']; |
||||
|
} |
||||
|
$this->view->assign("row", $row); |
||||
|
$this->view->assign("groupids", $groupids); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
*/ |
||||
|
public function del($ids = "") |
||||
|
{ |
||||
|
if (!$this->request->isPost()) { |
||||
|
$this->error(__("Invalid parameters")); |
||||
|
} |
||||
|
$ids = $ids ? $ids : $this->request->post("ids"); |
||||
|
if ($ids) { |
||||
|
$ids = array_intersect($this->childrenAdminIds, array_filter(explode(',', $ids))); |
||||
|
// 避免越权删除管理员 |
||||
|
$childrenGroupIds = $this->childrenGroupIds; |
||||
|
$adminList = $this->model->where('id', 'in', $ids)->where('id', 'in', function ($query) use ($childrenGroupIds) { |
||||
|
$query->name('auth_group_access')->where('group_id', 'in', $childrenGroupIds)->field('uid'); |
||||
|
})->select(); |
||||
|
if ($adminList) { |
||||
|
$deleteIds = []; |
||||
|
foreach ($adminList as $k => $v) { |
||||
|
$deleteIds[] = $v->id; |
||||
|
} |
||||
|
$deleteIds = array_values(array_diff($deleteIds, [$this->auth->id])); |
||||
|
if ($deleteIds) { |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
$this->model->destroy($deleteIds); |
||||
|
model('AuthGroupAccess')->where('uid', 'in', $deleteIds)->delete(); |
||||
|
Db::commit(); |
||||
|
} catch (\Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
$this->success(); |
||||
|
} |
||||
|
$this->error(__('No rows were deleted')); |
||||
|
} |
||||
|
} |
||||
|
$this->error(__('You have no permission')); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 批量更新 |
||||
|
* @internal |
||||
|
*/ |
||||
|
public function multi($ids = "") |
||||
|
{ |
||||
|
// 管理员禁止批量操作 |
||||
|
$this->error(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 下拉搜索 |
||||
|
*/ |
||||
|
public function selectpage() |
||||
|
{ |
||||
|
$this->dataLimit = 'auth'; |
||||
|
$this->dataLimitField = 'id'; |
||||
|
return parent::selectpage(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,133 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\auth; |
||||
|
|
||||
|
use app\admin\model\AuthGroup; |
||||
|
use app\common\controller\Backend; |
||||
|
|
||||
|
/** |
||||
|
* 管理员日志 |
||||
|
* |
||||
|
* @icon fa fa-users |
||||
|
* @remark 管理员可以查看自己所拥有的权限的管理员日志 |
||||
|
*/ |
||||
|
class Adminlog extends Backend |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* @var \app\admin\model\AdminLog |
||||
|
*/ |
||||
|
protected $model = null; |
||||
|
protected $childrenGroupIds = []; |
||||
|
protected $childrenAdminIds = []; |
||||
|
|
||||
|
public function _initialize() |
||||
|
{ |
||||
|
parent::_initialize(); |
||||
|
$this->model = model('AdminLog'); |
||||
|
|
||||
|
$this->childrenAdminIds = $this->auth->getChildrenAdminIds(true); |
||||
|
$this->childrenGroupIds = $this->auth->getChildrenGroupIds(true); |
||||
|
|
||||
|
$groupName = AuthGroup::where('id', 'in', $this->childrenGroupIds) |
||||
|
->column('id,name'); |
||||
|
|
||||
|
$this->view->assign('groupdata', $groupName); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() |
||||
|
{ |
||||
|
//设置过滤方法 |
||||
|
$this->request->filter(['strip_tags', 'trim']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
$list = $this->model |
||||
|
->where($where) |
||||
|
->where('admin_id', 'in', $this->childrenAdminIds) |
||||
|
->order($sort, $order) |
||||
|
->paginate($limit); |
||||
|
|
||||
|
$result = array("total" => $list->total(), "rows" => $list->items()); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 详情 |
||||
|
*/ |
||||
|
public function detail($ids) |
||||
|
{ |
||||
|
$row = $this->model->get(['id' => $ids]); |
||||
|
if (!$row) { |
||||
|
$this->error(__('No Results were found')); |
||||
|
} |
||||
|
if (!$row['admin_id'] || !in_array($row['admin_id'], $this->childrenAdminIds)) { |
||||
|
$this->error(__('You have no permission')); |
||||
|
} |
||||
|
$this->view->assign("row", $row->toArray()); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加 |
||||
|
* @internal |
||||
|
*/ |
||||
|
public function add() |
||||
|
{ |
||||
|
$this->error(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 编辑 |
||||
|
* @internal |
||||
|
*/ |
||||
|
public function edit($ids = null) |
||||
|
{ |
||||
|
$this->error(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
*/ |
||||
|
public function del($ids = "") |
||||
|
{ |
||||
|
if (!$this->request->isPost()) { |
||||
|
$this->error(__("Invalid parameters")); |
||||
|
} |
||||
|
$ids = $ids ? $ids : $this->request->post("ids"); |
||||
|
if ($ids) { |
||||
|
$adminList = $this->model->where('id', 'in', $ids)->where('admin_id', 'in', $this->childrenAdminIds)->select(); |
||||
|
if ($adminList) { |
||||
|
$deleteIds = []; |
||||
|
foreach ($adminList as $k => $v) { |
||||
|
$deleteIds[] = $v->id; |
||||
|
} |
||||
|
if ($deleteIds) { |
||||
|
$this->model->destroy($deleteIds); |
||||
|
$this->success(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$this->error(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 批量更新 |
||||
|
* @internal |
||||
|
*/ |
||||
|
public function multi($ids = "") |
||||
|
{ |
||||
|
// 管理员禁止批量操作 |
||||
|
$this->error(); |
||||
|
} |
||||
|
|
||||
|
public function selectpage() |
||||
|
{ |
||||
|
return parent::selectpage(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,317 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\auth; |
||||
|
|
||||
|
use app\admin\model\AuthGroup; |
||||
|
use app\common\controller\Backend; |
||||
|
use fast\Tree; |
||||
|
use think\Db; |
||||
|
use think\Exception; |
||||
|
|
||||
|
/** |
||||
|
* 角色组 |
||||
|
* |
||||
|
* @icon fa fa-group |
||||
|
* @remark 角色组可以有多个,角色有上下级层级关系,如果子角色有角色组和管理员的权限则可以派生属于自己组别下级的角色组或管理员 |
||||
|
*/ |
||||
|
class Group extends Backend |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* @var \app\admin\model\AuthGroup |
||||
|
*/ |
||||
|
protected $model = null; |
||||
|
//当前登录管理员所有子组别 |
||||
|
protected $childrenGroupIds = []; |
||||
|
//当前组别列表数据 |
||||
|
protected $grouplist = []; |
||||
|
protected $groupdata = []; |
||||
|
//无需要权限判断的方法 |
||||
|
protected $noNeedRight = ['roletree']; |
||||
|
|
||||
|
public function _initialize() |
||||
|
{ |
||||
|
parent::_initialize(); |
||||
|
$this->model = model('AuthGroup'); |
||||
|
|
||||
|
$this->childrenGroupIds = $this->auth->getChildrenGroupIds(true); |
||||
|
|
||||
|
$groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray(); |
||||
|
|
||||
|
Tree::instance()->init($groupList); |
||||
|
$groupList = []; |
||||
|
if ($this->auth->isSuperAdmin()) { |
||||
|
$groupList = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0)); |
||||
|
} else { |
||||
|
$groups = $this->auth->getGroups(); |
||||
|
$groupIds = []; |
||||
|
foreach ($groups as $m => $n) { |
||||
|
if (in_array($n['id'], $groupIds) || in_array($n['pid'], $groupIds)) { |
||||
|
continue; |
||||
|
} |
||||
|
$groupList = array_merge($groupList, Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['pid']))); |
||||
|
foreach ($groupList as $index => $item) { |
||||
|
$groupIds[] = $item['id']; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$groupName = []; |
||||
|
foreach ($groupList as $k => $v) { |
||||
|
$groupName[$v['id']] = $v['name']; |
||||
|
} |
||||
|
|
||||
|
$this->grouplist = $groupList; |
||||
|
$this->groupdata = $groupName; |
||||
|
$this->assignconfig("admin", ['id' => $this->auth->id, 'group_ids' => $this->auth->getGroupIds()]); |
||||
|
|
||||
|
$this->view->assign('groupdata', $this->groupdata); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() |
||||
|
{ |
||||
|
if ($this->request->isAjax()) { |
||||
|
$list = $this->grouplist; |
||||
|
$total = count($list); |
||||
|
$result = array("total" => $total, "rows" => $list); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加 |
||||
|
*/ |
||||
|
public function add() |
||||
|
{ |
||||
|
if ($this->request->isPost()) { |
||||
|
$this->token(); |
||||
|
$params = $this->request->post("row/a", [], 'strip_tags'); |
||||
|
$params['rules'] = explode(',', $params['rules']); |
||||
|
if (!in_array($params['pid'], $this->childrenGroupIds)) { |
||||
|
$this->error(__('The parent group exceeds permission limit')); |
||||
|
} |
||||
|
$parentmodel = model("AuthGroup")->get($params['pid']); |
||||
|
if (!$parentmodel) { |
||||
|
$this->error(__('The parent group can not found')); |
||||
|
} |
||||
|
// 父级别的规则节点 |
||||
|
$parentrules = explode(',', $parentmodel->rules); |
||||
|
// 当前组别的规则节点 |
||||
|
$currentrules = $this->auth->getRuleIds(); |
||||
|
$rules = $params['rules']; |
||||
|
// 如果父组不是超级管理员则需要过滤规则节点,不能超过父组别的权限 |
||||
|
$rules = in_array('*', $parentrules) ? $rules : array_intersect($parentrules, $rules); |
||||
|
// 如果当前组别不是超级管理员则需要过滤规则节点,不能超当前组别的权限 |
||||
|
$rules = in_array('*', $currentrules) ? $rules : array_intersect($currentrules, $rules); |
||||
|
$params['rules'] = implode(',', $rules); |
||||
|
if ($params) { |
||||
|
$this->model->create($params); |
||||
|
$this->success(); |
||||
|
} |
||||
|
$this->error(); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 编辑 |
||||
|
*/ |
||||
|
public function edit($ids = null) |
||||
|
{ |
||||
|
if (!in_array($ids, $this->childrenGroupIds)) { |
||||
|
$this->error(__('You have no permission')); |
||||
|
} |
||||
|
$row = $this->model->get(['id' => $ids]); |
||||
|
if (!$row) { |
||||
|
$this->error(__('No Results were found')); |
||||
|
} |
||||
|
if ($this->request->isPost()) { |
||||
|
$this->token(); |
||||
|
$params = $this->request->post("row/a", [], 'strip_tags'); |
||||
|
//父节点不能是非权限内节点 |
||||
|
if (!in_array($params['pid'], $this->childrenGroupIds)) { |
||||
|
$this->error(__('The parent group exceeds permission limit')); |
||||
|
} |
||||
|
// 父节点不能是它自身的子节点或自己本身 |
||||
|
if (in_array($params['pid'], Tree::instance()->getChildrenIds($row->id, true))) { |
||||
|
$this->error(__('The parent group can not be its own child or itself')); |
||||
|
} |
||||
|
$params['rules'] = explode(',', $params['rules']); |
||||
|
|
||||
|
$parentmodel = model("AuthGroup")->get($params['pid']); |
||||
|
if (!$parentmodel) { |
||||
|
$this->error(__('The parent group can not found')); |
||||
|
} |
||||
|
// 父级别的规则节点 |
||||
|
$parentrules = explode(',', $parentmodel->rules); |
||||
|
// 当前组别的规则节点 |
||||
|
$currentrules = $this->auth->getRuleIds(); |
||||
|
$rules = $params['rules']; |
||||
|
// 如果父组不是超级管理员则需要过滤规则节点,不能超过父组别的权限 |
||||
|
$rules = in_array('*', $parentrules) ? $rules : array_intersect($parentrules, $rules); |
||||
|
// 如果当前组别不是超级管理员则需要过滤规则节点,不能超当前组别的权限 |
||||
|
$rules = in_array('*', $currentrules) ? $rules : array_intersect($currentrules, $rules); |
||||
|
$params['rules'] = implode(',', $rules); |
||||
|
if ($params) { |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
$row->save($params); |
||||
|
$children_auth_groups = model("AuthGroup")->all(['id' => ['in', implode(',', (Tree::instance()->getChildrenIds($row->id)))]]); |
||||
|
$childparams = []; |
||||
|
foreach ($children_auth_groups as $key => $children_auth_group) { |
||||
|
$childparams[$key]['id'] = $children_auth_group->id; |
||||
|
$childparams[$key]['rules'] = implode(',', array_intersect(explode(',', $children_auth_group->rules), $rules)); |
||||
|
} |
||||
|
model("AuthGroup")->saveAll($childparams); |
||||
|
Db::commit(); |
||||
|
$this->success(); |
||||
|
} catch (Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
} |
||||
|
$this->error(); |
||||
|
return; |
||||
|
} |
||||
|
$this->view->assign("row", $row); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
*/ |
||||
|
public function del($ids = "") |
||||
|
{ |
||||
|
if (!$this->request->isPost()) { |
||||
|
$this->error(__("Invalid parameters")); |
||||
|
} |
||||
|
$ids = $ids ? $ids : $this->request->post("ids"); |
||||
|
if ($ids) { |
||||
|
$ids = explode(',', $ids); |
||||
|
$grouplist = $this->auth->getGroups(); |
||||
|
$group_ids = array_map(function ($group) { |
||||
|
return $group['id']; |
||||
|
}, $grouplist); |
||||
|
// 移除掉当前管理员所在组别 |
||||
|
$ids = array_diff($ids, $group_ids); |
||||
|
|
||||
|
// 循环判断每一个组别是否可删除 |
||||
|
$grouplist = $this->model->where('id', 'in', $ids)->select(); |
||||
|
$groupaccessmodel = model('AuthGroupAccess'); |
||||
|
foreach ($grouplist as $k => $v) { |
||||
|
// 当前组别下有管理员 |
||||
|
$groupone = $groupaccessmodel->get(['group_id' => $v['id']]); |
||||
|
if ($groupone) { |
||||
|
$ids = array_diff($ids, [$v['id']]); |
||||
|
continue; |
||||
|
} |
||||
|
// 当前组别下有子组别 |
||||
|
$groupone = $this->model->get(['pid' => $v['id']]); |
||||
|
if ($groupone) { |
||||
|
$ids = array_diff($ids, [$v['id']]); |
||||
|
continue; |
||||
|
} |
||||
|
} |
||||
|
if (!$ids) { |
||||
|
$this->error(__('You can not delete group that contain child group and administrators')); |
||||
|
} |
||||
|
$count = $this->model->where('id', 'in', $ids)->delete(); |
||||
|
if ($count) { |
||||
|
$this->success(); |
||||
|
} |
||||
|
} |
||||
|
$this->error(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 批量更新 |
||||
|
* @internal |
||||
|
*/ |
||||
|
public function multi($ids = "") |
||||
|
{ |
||||
|
// 组别禁止批量操作 |
||||
|
$this->error(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 读取角色权限树 |
||||
|
* |
||||
|
* @internal |
||||
|
*/ |
||||
|
public function roletree() |
||||
|
{ |
||||
|
$this->loadlang('auth/group'); |
||||
|
|
||||
|
$model = model('AuthGroup'); |
||||
|
$id = $this->request->post("id"); |
||||
|
$pid = $this->request->post("pid"); |
||||
|
$parentGroupModel = $model->get($pid); |
||||
|
$currentGroupModel = null; |
||||
|
if ($id) { |
||||
|
$currentGroupModel = $model->get($id); |
||||
|
} |
||||
|
if (($pid || $parentGroupModel) && (!$id || $currentGroupModel)) { |
||||
|
$id = $id ? $id : null; |
||||
|
$ruleList = collection(model('AuthRule')->order('weigh', 'desc')->order('id', 'asc')->select())->toArray(); |
||||
|
//读取父类角色所有节点列表 |
||||
|
$parentRuleList = []; |
||||
|
if (in_array('*', explode(',', $parentGroupModel->rules))) { |
||||
|
$parentRuleList = $ruleList; |
||||
|
} else { |
||||
|
$parentRuleIds = explode(',', $parentGroupModel->rules); |
||||
|
foreach ($ruleList as $k => $v) { |
||||
|
if (in_array($v['id'], $parentRuleIds)) { |
||||
|
$parentRuleList[] = $v; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$ruleTree = new Tree(); |
||||
|
$groupTree = new Tree(); |
||||
|
//当前所有正常规则列表 |
||||
|
$ruleTree->init($parentRuleList); |
||||
|
//角色组列表 |
||||
|
$groupTree->init(collection(model('AuthGroup')->where('id', 'in', $this->childrenGroupIds)->select())->toArray()); |
||||
|
|
||||
|
//读取当前角色下规则ID集合 |
||||
|
$adminRuleIds = $this->auth->getRuleIds(); |
||||
|
//是否是超级管理员 |
||||
|
$superadmin = $this->auth->isSuperAdmin(); |
||||
|
//当前拥有的规则ID集合 |
||||
|
$currentRuleIds = $id ? explode(',', $currentGroupModel->rules) : []; |
||||
|
|
||||
|
if (!$id || !in_array($pid, $this->childrenGroupIds) || !in_array($pid, $groupTree->getChildrenIds($id, true))) { |
||||
|
$parentRuleList = $ruleTree->getTreeList($ruleTree->getTreeArray(0), 'name'); |
||||
|
$hasChildrens = []; |
||||
|
foreach ($parentRuleList as $k => $v) { |
||||
|
if ($v['haschild']) { |
||||
|
$hasChildrens[] = $v['id']; |
||||
|
} |
||||
|
} |
||||
|
$parentRuleIds = array_map(function ($item) { |
||||
|
return $item['id']; |
||||
|
}, $parentRuleList); |
||||
|
$nodeList = []; |
||||
|
foreach ($parentRuleList as $k => $v) { |
||||
|
if (!$superadmin && !in_array($v['id'], $adminRuleIds)) { |
||||
|
continue; |
||||
|
} |
||||
|
if ($v['pid'] && !in_array($v['pid'], $parentRuleIds)) { |
||||
|
continue; |
||||
|
} |
||||
|
$state = array('selected' => in_array($v['id'], $currentRuleIds) && !in_array($v['id'], $hasChildrens)); |
||||
|
$nodeList[] = array('id' => $v['id'], 'parent' => $v['pid'] ? $v['pid'] : '#', 'text' => __($v['title']), 'type' => 'menu', 'state' => $state); |
||||
|
} |
||||
|
$this->success('', null, $nodeList); |
||||
|
} else { |
||||
|
$this->error(__('Can not change the parent to child')); |
||||
|
} |
||||
|
} else { |
||||
|
$this->error(__('Group not found')); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,159 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\auth; |
||||
|
|
||||
|
use app\admin\model\AuthRule; |
||||
|
use app\common\controller\Backend; |
||||
|
use fast\Tree; |
||||
|
use think\Cache; |
||||
|
|
||||
|
/** |
||||
|
* 规则管理 |
||||
|
* |
||||
|
* @icon fa fa-list |
||||
|
* @remark 规则通常对应一个控制器的方法,同时左侧的菜单栏数据也从规则中体现,通常建议通过控制台进行生成规则节点 |
||||
|
*/ |
||||
|
class Rule extends Backend |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* @var \app\admin\model\AuthRule |
||||
|
*/ |
||||
|
protected $model = null; |
||||
|
protected $rulelist = []; |
||||
|
protected $multiFields = 'ismenu,status'; |
||||
|
|
||||
|
public function _initialize() |
||||
|
{ |
||||
|
parent::_initialize(); |
||||
|
if (!$this->auth->isSuperAdmin()) { |
||||
|
$this->error(__('Access is allowed only to the super management group')); |
||||
|
} |
||||
|
$this->model = model('AuthRule'); |
||||
|
// 必须将结果集转换为数组 |
||||
|
$ruleList = \think\Db::name("auth_rule")->field('type,condition,remark,createtime,updatetime', true)->order('weigh DESC,id ASC')->select(); |
||||
|
foreach ($ruleList as $k => &$v) { |
||||
|
$v['title'] = __($v['title']); |
||||
|
} |
||||
|
unset($v); |
||||
|
Tree::instance()->init($ruleList); |
||||
|
$this->rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title'); |
||||
|
$ruledata = [0 => __('None')]; |
||||
|
foreach ($this->rulelist as $k => &$v) { |
||||
|
if (!$v['ismenu']) { |
||||
|
continue; |
||||
|
} |
||||
|
$ruledata[$v['id']] = $v['title']; |
||||
|
unset($v['spacer']); |
||||
|
} |
||||
|
unset($v); |
||||
|
$this->view->assign('ruledata', $ruledata); |
||||
|
$this->view->assign("menutypeList", $this->model->getMenutypeList()); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() |
||||
|
{ |
||||
|
if ($this->request->isAjax()) { |
||||
|
$list = $this->rulelist; |
||||
|
$total = count($this->rulelist); |
||||
|
$result = array("total" => $total, "rows" => $list); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加 |
||||
|
*/ |
||||
|
public function add() |
||||
|
{ |
||||
|
if ($this->request->isPost()) { |
||||
|
$this->token(); |
||||
|
$params = $this->request->post("row/a", [], 'strip_tags'); |
||||
|
if ($params) { |
||||
|
if (!$params['ismenu'] && !$params['pid']) { |
||||
|
$this->error(__('The non-menu rule must have parent')); |
||||
|
} |
||||
|
$result = $this->model->validate()->save($params); |
||||
|
if ($result === false) { |
||||
|
$this->error($this->model->getError()); |
||||
|
} |
||||
|
Cache::rm('__menu__'); |
||||
|
$this->success(); |
||||
|
} |
||||
|
$this->error(); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 编辑 |
||||
|
*/ |
||||
|
public function edit($ids = null) |
||||
|
{ |
||||
|
$row = $this->model->get(['id' => $ids]); |
||||
|
if (!$row) { |
||||
|
$this->error(__('No Results were found')); |
||||
|
} |
||||
|
if ($this->request->isPost()) { |
||||
|
$this->token(); |
||||
|
$params = $this->request->post("row/a", [], 'strip_tags'); |
||||
|
if ($params) { |
||||
|
if (!$params['ismenu'] && !$params['pid']) { |
||||
|
$this->error(__('The non-menu rule must have parent')); |
||||
|
} |
||||
|
if ($params['pid'] == $row['id']) { |
||||
|
$this->error(__('Can not change the parent to self')); |
||||
|
} |
||||
|
if ($params['pid'] != $row['pid']) { |
||||
|
$childrenIds = Tree::instance()->init(collection(AuthRule::select())->toArray())->getChildrenIds($row['id']); |
||||
|
if (in_array($params['pid'], $childrenIds)) { |
||||
|
$this->error(__('Can not change the parent to child')); |
||||
|
} |
||||
|
} |
||||
|
//这里需要针对name做唯一验证 |
||||
|
$ruleValidate = \think\Loader::validate('AuthRule'); |
||||
|
$ruleValidate->rule([ |
||||
|
'name' => 'require|unique:AuthRule,name,' . $row->id, |
||||
|
]); |
||||
|
$result = $row->validate()->save($params); |
||||
|
if ($result === false) { |
||||
|
$this->error($row->getError()); |
||||
|
} |
||||
|
Cache::rm('__menu__'); |
||||
|
$this->success(); |
||||
|
} |
||||
|
$this->error(); |
||||
|
} |
||||
|
$this->view->assign("row", $row); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
*/ |
||||
|
public function del($ids = "") |
||||
|
{ |
||||
|
if (!$this->request->isPost()) { |
||||
|
$this->error(__("Invalid parameters")); |
||||
|
} |
||||
|
$ids = $ids ? $ids : $this->request->post("ids"); |
||||
|
if ($ids) { |
||||
|
$delIds = []; |
||||
|
foreach (explode(',', $ids) as $k => $v) { |
||||
|
$delIds = array_merge($delIds, Tree::instance()->getChildrenIds($v, true)); |
||||
|
} |
||||
|
$delIds = array_unique($delIds); |
||||
|
$count = $this->model->where('id', 'in', $delIds)->delete(); |
||||
|
if ($count) { |
||||
|
Cache::rm('__menu__'); |
||||
|
$this->success(); |
||||
|
} |
||||
|
} |
||||
|
$this->error(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,160 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\general; |
||||
|
|
||||
|
use app\common\controller\Backend; |
||||
|
|
||||
|
/** |
||||
|
* 附件管理 |
||||
|
* |
||||
|
* @icon fa fa-circle-o |
||||
|
* @remark 主要用于管理上传到服务器或第三方存储的数据 |
||||
|
*/ |
||||
|
class Attachment extends Backend |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* @var \app\common\model\Attachment |
||||
|
*/ |
||||
|
protected $model = null; |
||||
|
|
||||
|
protected $searchFields = 'id,filename,url'; |
||||
|
protected $noNeedRight = ['classify']; |
||||
|
|
||||
|
public function _initialize() |
||||
|
{ |
||||
|
parent::_initialize(); |
||||
|
$this->model = model('Attachment'); |
||||
|
$this->view->assign("mimetypeList", \app\common\model\Attachment::getMimetypeList()); |
||||
|
$this->view->assign("categoryList", \app\common\model\Attachment::getCategoryList()); |
||||
|
$this->assignconfig("categoryList", \app\common\model\Attachment::getCategoryList()); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() |
||||
|
{ |
||||
|
//设置过滤方法 |
||||
|
$this->request->filter(['strip_tags', 'trim']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
$mimetypeQuery = []; |
||||
|
$filter = $this->request->request('filter'); |
||||
|
$filterArr = (array)json_decode($filter, true); |
||||
|
if (isset($filterArr['category']) && $filterArr['category'] == 'unclassed') { |
||||
|
$filterArr['category'] = ',unclassed'; |
||||
|
$this->request->get(['filter' => json_encode(array_diff_key($filterArr, ['category' => '']))]); |
||||
|
} |
||||
|
if (isset($filterArr['mimetype']) && preg_match("/(\/|\,|\*)/", $filterArr['mimetype'])) { |
||||
|
$mimetype = $filterArr['mimetype']; |
||||
|
$filterArr = array_diff_key($filterArr, ['mimetype' => '']); |
||||
|
$mimetypeQuery = function ($query) use ($mimetype) { |
||||
|
$mimetypeArr = array_filter(explode(',', $mimetype)); |
||||
|
foreach ($mimetypeArr as $index => $item) { |
||||
|
$query->whereOr('mimetype', 'like', '%' . str_replace("/*", "/", $item) . '%'); |
||||
|
} |
||||
|
}; |
||||
|
} |
||||
|
$this->request->get(['filter' => json_encode($filterArr)]); |
||||
|
|
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
|
||||
|
$list = $this->model |
||||
|
->where($mimetypeQuery) |
||||
|
->where($where) |
||||
|
->order($sort, $order) |
||||
|
->paginate($limit); |
||||
|
|
||||
|
$cdnurl = preg_replace("/\/(\w+)\.php$/i", '', $this->request->root()); |
||||
|
foreach ($list as $k => &$v) { |
||||
|
$v['fullurl'] = ($v['storage'] == 'local' ? $cdnurl : $this->view->config['upload']['cdnurl']) . $v['url']; |
||||
|
} |
||||
|
unset($v); |
||||
|
$result = array("total" => $list->total(), "rows" => $list->items()); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 选择附件 |
||||
|
*/ |
||||
|
public function select() |
||||
|
{ |
||||
|
if ($this->request->isAjax()) { |
||||
|
return $this->index(); |
||||
|
} |
||||
|
$mimetype = $this->request->get('mimetype', ''); |
||||
|
$mimetype = substr($mimetype, -1) === '/' ? $mimetype . '*' : $mimetype; |
||||
|
$this->view->assign('mimetype', $mimetype); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加 |
||||
|
*/ |
||||
|
public function add() |
||||
|
{ |
||||
|
if ($this->request->isAjax()) { |
||||
|
$this->error(); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除附件 |
||||
|
* @param array $ids |
||||
|
*/ |
||||
|
public function del($ids = "") |
||||
|
{ |
||||
|
if (!$this->request->isPost()) { |
||||
|
$this->error(__("Invalid parameters")); |
||||
|
} |
||||
|
$ids = $ids ? $ids : $this->request->post("ids"); |
||||
|
if ($ids) { |
||||
|
\think\Hook::add('upload_delete', function ($params) { |
||||
|
if ($params['storage'] == 'local') { |
||||
|
$attachmentFile = ROOT_PATH . '/public' . $params['url']; |
||||
|
if (is_file($attachmentFile)) { |
||||
|
@unlink($attachmentFile); |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
$attachmentlist = $this->model->where('id', 'in', $ids)->select(); |
||||
|
foreach ($attachmentlist as $attachment) { |
||||
|
\think\Hook::listen("upload_delete", $attachment); |
||||
|
$attachment->delete(); |
||||
|
} |
||||
|
$this->success(); |
||||
|
} |
||||
|
$this->error(__('Parameter %s can not be empty', 'ids')); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 归类 |
||||
|
*/ |
||||
|
public function classify() |
||||
|
{ |
||||
|
if (!$this->auth->check('general/attachment/edit')) { |
||||
|
\think\Hook::listen('admin_nopermission', $this); |
||||
|
$this->error(__('You have no permission'), ''); |
||||
|
} |
||||
|
if (!$this->request->isPost()) { |
||||
|
$this->error(__("Invalid parameters")); |
||||
|
} |
||||
|
$category = $this->request->post('category', ''); |
||||
|
$ids = $this->request->post('ids'); |
||||
|
if (!$ids) { |
||||
|
$this->error(__('Parameter %s can not be empty', 'ids')); |
||||
|
} |
||||
|
$categoryList = \app\common\model\Attachment::getCategoryList(); |
||||
|
if ($category && !isset($categoryList[$category])) { |
||||
|
$this->error(__('Category not found')); |
||||
|
} |
||||
|
$category = $category == 'unclassed' ? '' : $category; |
||||
|
\app\common\model\Attachment::where('id', 'in', $ids)->update(['category' => $category]); |
||||
|
$this->success(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,311 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\general; |
||||
|
|
||||
|
use app\common\controller\Backend; |
||||
|
use app\common\library\Email; |
||||
|
use app\common\model\Config as ConfigModel; |
||||
|
use think\Cache; |
||||
|
use think\Db; |
||||
|
use think\Exception; |
||||
|
use think\Validate; |
||||
|
|
||||
|
/** |
||||
|
* 系统配置 |
||||
|
* |
||||
|
* @icon fa fa-cogs |
||||
|
* @remark 可以在此增改系统的变量和分组,也可以自定义分组和变量,如果需要删除请从数据库中删除 |
||||
|
*/ |
||||
|
class Config extends Backend |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* @var \app\common\model\Config |
||||
|
*/ |
||||
|
protected $model = null; |
||||
|
protected $noNeedRight = ['check', 'rulelist', 'selectpage', 'get_fields_list']; |
||||
|
|
||||
|
public function _initialize() |
||||
|
{ |
||||
|
parent::_initialize(); |
||||
|
// $this->model = model('Config'); |
||||
|
$this->model = new ConfigModel; |
||||
|
ConfigModel::event('before_write', function ($row) { |
||||
|
if (isset($row['name']) && $row['name'] == 'name' && preg_match("/fast" . "admin/i", $row['value'])) { |
||||
|
throw new Exception(__("Site name incorrect")); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() |
||||
|
{ |
||||
|
$siteList = []; |
||||
|
$groupList = ConfigModel::getGroupList(); |
||||
|
foreach ($groupList as $k => $v) { |
||||
|
$siteList[$k]['name'] = $k; |
||||
|
$siteList[$k]['title'] = $v; |
||||
|
$siteList[$k]['list'] = []; |
||||
|
} |
||||
|
|
||||
|
foreach ($this->model->all() as $k => $v) { |
||||
|
if (!isset($siteList[$v['group']])) { |
||||
|
continue; |
||||
|
} |
||||
|
$value = $v->toArray(); |
||||
|
$value['title'] = __($value['title']); |
||||
|
if (in_array($value['type'], ['select', 'selects', 'checkbox', 'radio'])) { |
||||
|
$value['value'] = explode(',', $value['value']); |
||||
|
} |
||||
|
$value['content'] = json_decode($value['content'], true); |
||||
|
if (in_array($value['name'], ['categorytype', 'configgroup', 'attachmentcategory'])) { |
||||
|
$dictValue = (array)json_decode($value['value'], true); |
||||
|
foreach ($dictValue as $index => &$item) { |
||||
|
$item = __($item); |
||||
|
} |
||||
|
unset($item); |
||||
|
$value['value'] = json_encode($dictValue, JSON_UNESCAPED_UNICODE); |
||||
|
} |
||||
|
$value['tip'] = htmlspecialchars($value['tip']); |
||||
|
if ($value['name'] == 'cdnurl') { |
||||
|
//cdnurl不支持在线修改 |
||||
|
continue; |
||||
|
} |
||||
|
$siteList[$v['group']]['list'][] = $value; |
||||
|
} |
||||
|
$index = 0; |
||||
|
foreach ($siteList as $k => &$v) { |
||||
|
$v['active'] = !$index ? true : false; |
||||
|
$index++; |
||||
|
} |
||||
|
$this->view->assign('siteList', $siteList); |
||||
|
$this->view->assign('typeList', ConfigModel::getTypeList()); |
||||
|
$this->view->assign('ruleList', ConfigModel::getRegexList()); |
||||
|
$this->view->assign('groupList', ConfigModel::getGroupList()); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加 |
||||
|
*/ |
||||
|
public function add() |
||||
|
{ |
||||
|
if (!config('app_debug')) { |
||||
|
$this->error(__('Only work at development environment')); |
||||
|
} |
||||
|
if ($this->request->isPost()) { |
||||
|
$this->token(); |
||||
|
$params = $this->request->post("row/a", [], 'trim'); |
||||
|
if ($params) { |
||||
|
foreach ($params as $k => &$v) { |
||||
|
$v = is_array($v) && $k !== 'setting' ? implode(',', $v) : $v; |
||||
|
} |
||||
|
if (in_array($params['type'], ['select', 'selects', 'checkbox', 'radio', 'array'])) { |
||||
|
$params['content'] = json_encode(ConfigModel::decode($params['content']), JSON_UNESCAPED_UNICODE); |
||||
|
} else { |
||||
|
$params['content'] = ''; |
||||
|
} |
||||
|
try { |
||||
|
$result = $this->model->create($params); |
||||
|
} catch (Exception $e) { |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
if ($result !== false) { |
||||
|
try { |
||||
|
ConfigModel::refreshFile(); |
||||
|
} catch (Exception $e) { |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
$this->success(); |
||||
|
} else { |
||||
|
$this->error($this->model->getError()); |
||||
|
} |
||||
|
} |
||||
|
$this->error(__('Parameter %s can not be empty', '')); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 编辑 |
||||
|
* @param null $ids |
||||
|
*/ |
||||
|
public function edit($ids = null) |
||||
|
{ |
||||
|
if ($this->request->isPost()) { |
||||
|
$this->token(); |
||||
|
$row = $this->request->post("row/a", [], 'trim'); |
||||
|
if ($row) { |
||||
|
$configList = []; |
||||
|
foreach ($this->model->all() as $v) { |
||||
|
if (isset($row[$v['name']])) { |
||||
|
$value = $row[$v['name']]; |
||||
|
if (is_array($value) && isset($value['field'])) { |
||||
|
$value = json_encode(ConfigModel::getArrayData($value), JSON_UNESCAPED_UNICODE); |
||||
|
} else { |
||||
|
$value = is_array($value) ? implode(',', $value) : $value; |
||||
|
} |
||||
|
$v['value'] = $value; |
||||
|
$configList[] = $v->toArray(); |
||||
|
} |
||||
|
} |
||||
|
try { |
||||
|
$this->model->allowField(true)->saveAll($configList); |
||||
|
} catch (Exception $e) { |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
try { |
||||
|
ConfigModel::refreshFile(); |
||||
|
} catch (Exception $e) { |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
$this->success(); |
||||
|
} |
||||
|
$this->error(__('Parameter %s can not be empty', '')); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
* @param string $ids |
||||
|
*/ |
||||
|
public function del($ids = "") |
||||
|
{ |
||||
|
if (!config('app_debug')) { |
||||
|
$this->error(__('Only work at development environment')); |
||||
|
} |
||||
|
$name = $this->request->post('name'); |
||||
|
$config = ConfigModel::getByName($name); |
||||
|
if ($name && $config) { |
||||
|
try { |
||||
|
$config->delete(); |
||||
|
ConfigModel::refreshFile(); |
||||
|
} catch (Exception $e) { |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
$this->success(); |
||||
|
} else { |
||||
|
$this->error(__('Invalid parameters')); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 检测配置项是否存在 |
||||
|
* @internal |
||||
|
*/ |
||||
|
public function check() |
||||
|
{ |
||||
|
$params = $this->request->post("row/a"); |
||||
|
if ($params) { |
||||
|
$config = $this->model->get($params); |
||||
|
if (!$config) { |
||||
|
$this->success(); |
||||
|
} else { |
||||
|
$this->error(__('Name already exist')); |
||||
|
} |
||||
|
} else { |
||||
|
$this->error(__('Invalid parameters')); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 规则列表 |
||||
|
* @internal |
||||
|
*/ |
||||
|
public function rulelist() |
||||
|
{ |
||||
|
//主键 |
||||
|
$primarykey = $this->request->request("keyField"); |
||||
|
//主键值 |
||||
|
$keyValue = $this->request->request("keyValue", ""); |
||||
|
|
||||
|
$keyValueArr = array_filter(explode(',', $keyValue)); |
||||
|
$regexList = \app\common\model\Config::getRegexList(); |
||||
|
$list = []; |
||||
|
foreach ($regexList as $k => $v) { |
||||
|
if ($keyValueArr) { |
||||
|
if (in_array($k, $keyValueArr)) { |
||||
|
$list[] = ['id' => $k, 'name' => $v]; |
||||
|
} |
||||
|
} else { |
||||
|
$list[] = ['id' => $k, 'name' => $v]; |
||||
|
} |
||||
|
} |
||||
|
return json(['list' => $list]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 发送测试邮件 |
||||
|
* @internal |
||||
|
*/ |
||||
|
public function emailtest() |
||||
|
{ |
||||
|
$row = $this->request->post('row/a'); |
||||
|
$receiver = $this->request->post("receiver"); |
||||
|
if ($receiver) { |
||||
|
if (!Validate::is($receiver, "email")) { |
||||
|
$this->error(__('Please input correct email')); |
||||
|
} |
||||
|
\think\Config::set('site', array_merge(\think\Config::get('site'), $row)); |
||||
|
$email = new Email; |
||||
|
$result = $email |
||||
|
->to($receiver) |
||||
|
->subject(__("This is a test mail", config('site.name'))) |
||||
|
->message('<div style="min-height:550px; padding: 100px 55px 200px;">' . __('This is a test mail content', config('site.name')) . '</div>') |
||||
|
->send(); |
||||
|
if ($result) { |
||||
|
$this->success(); |
||||
|
} else { |
||||
|
$this->error($email->getError()); |
||||
|
} |
||||
|
} else { |
||||
|
$this->error(__('Invalid parameters')); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public function selectpage() |
||||
|
{ |
||||
|
$id = $this->request->get("id/d"); |
||||
|
$config = \app\common\model\Config::get($id); |
||||
|
if (!$config) { |
||||
|
$this->error(__('Invalid parameters')); |
||||
|
} |
||||
|
$setting = $config['setting']; |
||||
|
//自定义条件 |
||||
|
$custom = isset($setting['conditions']) ? (array)json_decode($setting['conditions'], true) : []; |
||||
|
$custom = array_filter($custom); |
||||
|
|
||||
|
$this->request->request(['showField' => $setting['field'], 'keyField' => $setting['primarykey'], 'custom' => $custom, 'searchField' => [$setting['field'], $setting['primarykey']]]); |
||||
|
$this->model = \think\Db::connect()->setTable($setting['table']); |
||||
|
return parent::selectpage(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取表列表 |
||||
|
* @internal |
||||
|
*/ |
||||
|
public function get_table_list() |
||||
|
{ |
||||
|
$tableList = []; |
||||
|
$dbname = \think\Config::get('database.database'); |
||||
|
$tableList = \think\Db::query("SELECT `TABLE_NAME` AS `name`,`TABLE_COMMENT` AS `title` FROM `information_schema`.`TABLES` where `TABLE_SCHEMA` = '{$dbname}';"); |
||||
|
$this->success('', null, ['tableList' => $tableList]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取表字段列表 |
||||
|
* @internal |
||||
|
*/ |
||||
|
public function get_fields_list() |
||||
|
{ |
||||
|
$table = $this->request->request('table'); |
||||
|
$dbname = \think\Config::get('database.database'); |
||||
|
//从数据库中获取表字段信息 |
||||
|
$sql = "SELECT `COLUMN_NAME` AS `name`,`COLUMN_COMMENT` AS `title`,`DATA_TYPE` AS `type` FROM `information_schema`.`columns` WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? ORDER BY ORDINAL_POSITION"; |
||||
|
//加载主表的列 |
||||
|
$fieldList = Db::query($sql, [$dbname, $table]); |
||||
|
$this->success("", null, ['fieldList' => $fieldList]); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,83 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\general; |
||||
|
|
||||
|
use app\admin\model\Admin; |
||||
|
use app\common\controller\Backend; |
||||
|
use fast\Random; |
||||
|
use think\Session; |
||||
|
use think\Validate; |
||||
|
|
||||
|
/** |
||||
|
* 个人配置 |
||||
|
* |
||||
|
* @icon fa fa-user |
||||
|
*/ |
||||
|
class Profile extends Backend |
||||
|
{ |
||||
|
|
||||
|
protected $searchFields = 'id,title'; |
||||
|
|
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() |
||||
|
{ |
||||
|
//设置过滤方法 |
||||
|
$this->request->filter(['strip_tags', 'trim']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
$this->model = model('AdminLog'); |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
|
||||
|
$list = $this->model |
||||
|
->where($where) |
||||
|
->where('admin_id', $this->auth->id) |
||||
|
->order($sort, $order) |
||||
|
->paginate($limit); |
||||
|
|
||||
|
$result = array("total" => $list->total(), "rows" => $list->items()); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 更新个人信息 |
||||
|
*/ |
||||
|
public function update() |
||||
|
{ |
||||
|
if ($this->request->isPost()) { |
||||
|
$this->token(); |
||||
|
$params = $this->request->post("row/a"); |
||||
|
$params = array_filter(array_intersect_key( |
||||
|
$params, |
||||
|
array_flip(array('email', 'nickname', 'password', 'avatar')) |
||||
|
)); |
||||
|
unset($v); |
||||
|
if (!Validate::is($params['email'], "email")) { |
||||
|
$this->error(__("Please input correct email")); |
||||
|
} |
||||
|
if (isset($params['password'])) { |
||||
|
if (!Validate::is($params['password'], "/^[\S]{6,30}$/")) { |
||||
|
$this->error(__("Please input correct password")); |
||||
|
} |
||||
|
$params['salt'] = Random::alnum(); |
||||
|
$params['password'] = md5(md5($params['password']) . $params['salt']); |
||||
|
} |
||||
|
$exist = Admin::where('email', $params['email'])->where('id', '<>', $this->auth->id)->find(); |
||||
|
if ($exist) { |
||||
|
$this->error(__("Email already exists")); |
||||
|
} |
||||
|
if ($params) { |
||||
|
$admin = Admin::get($this->auth->id); |
||||
|
$admin->save($params); |
||||
|
//因为个人资料面板读取的Session显示,修改自己资料后同时更新Session |
||||
|
Session::set("admin", $admin->toArray()); |
||||
|
$this->success(); |
||||
|
} |
||||
|
$this->error(); |
||||
|
} |
||||
|
return; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,297 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\member; |
||||
|
|
||||
|
use app\admin\model\AuthGroup; |
||||
|
use app\admin\model\AuthGroupAccess; |
||||
|
use app\common\controller\Backend; |
||||
|
use fast\Random; |
||||
|
use fast\Tree; |
||||
|
use think\Db; |
||||
|
use think\Validate; |
||||
|
|
||||
|
/** |
||||
|
* 管理员管理 |
||||
|
* |
||||
|
* @icon fa fa-users |
||||
|
* @remark 一个管理员可以有多个角色组,左侧的菜单根据管理员所拥有的权限进行生成 |
||||
|
*/ |
||||
|
class Admin extends Backend |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* @var \app\admin\model\Admin |
||||
|
*/ |
||||
|
protected $model = null; |
||||
|
protected $selectpageFields = 'id,username,nickname,avatar'; |
||||
|
protected $searchFields = 'id,username,nickname'; |
||||
|
protected $childrenGroupIds = []; |
||||
|
protected $childrenAdminIds = []; |
||||
|
|
||||
|
public function _initialize() |
||||
|
{ |
||||
|
parent::_initialize(); |
||||
|
$this->model = model('Admin'); |
||||
|
|
||||
|
$this->childrenAdminIds = $this->auth->getChildrenAdminIds($this->auth->isSuperAdmin()); |
||||
|
$this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin()); |
||||
|
|
||||
|
$groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray(); |
||||
|
|
||||
|
Tree::instance()->init($groupList); |
||||
|
$groupdata = []; |
||||
|
if ($this->auth->isSuperAdmin()) { |
||||
|
$result = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0)); |
||||
|
foreach ($result as $k => $v) { |
||||
|
$groupdata[$v['id']] = $v['name']; |
||||
|
} |
||||
|
} else { |
||||
|
$result = []; |
||||
|
$groups = $this->auth->getGroups(); |
||||
|
foreach ($groups as $m => $n) { |
||||
|
$childlist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['id'])); |
||||
|
$temp = []; |
||||
|
foreach ($childlist as $k => $v) { |
||||
|
$temp[$v['id']] = $v['name']; |
||||
|
} |
||||
|
$result[__($n['name'])] = $temp; |
||||
|
} |
||||
|
$groupdata = $result; |
||||
|
} |
||||
|
|
||||
|
$this->view->assign('groupdata', $groupdata); |
||||
|
$this->assignconfig("admin", ['id' => $this->auth->id]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() |
||||
|
{ |
||||
|
//设置过滤方法 |
||||
|
$this->request->filter(['strip_tags', 'trim']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
//如果发送的来源是Selectpage,则转发到Selectpage |
||||
|
if ($this->request->request('keyField')) { |
||||
|
return $this->selectpage(); |
||||
|
} |
||||
|
$childrenGroupIds = $this->childrenGroupIds; |
||||
|
$groupName = AuthGroup::where('id', 'in', $childrenGroupIds) |
||||
|
->column('id,name'); |
||||
|
$authGroupList = AuthGroupAccess::where('group_id', 'in', $childrenGroupIds) |
||||
|
->field('uid,group_id') |
||||
|
->select(); |
||||
|
|
||||
|
$adminGroupName = []; |
||||
|
foreach ($authGroupList as $k => $v) { |
||||
|
if (isset($groupName[$v['group_id']])) { |
||||
|
$adminGroupName[$v['uid']][$v['group_id']] = $groupName[$v['group_id']]; |
||||
|
} |
||||
|
} |
||||
|
$groups = $this->auth->getGroups(); |
||||
|
foreach ($groups as $m => $n) { |
||||
|
$adminGroupName[$this->auth->id][$n['id']] = $n['name']; |
||||
|
} |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
|
||||
|
$list = $this->model |
||||
|
->where($where) |
||||
|
->where('id', 'in', $this->childrenAdminIds) |
||||
|
->field(['password', 'salt', 'token'], true) |
||||
|
->order($sort, $order) |
||||
|
->paginate($limit); |
||||
|
|
||||
|
foreach ($list as $k => &$v) { |
||||
|
$groups = isset($adminGroupName[$v['id']]) ? $adminGroupName[$v['id']] : []; |
||||
|
$v['groups'] = implode(',', array_keys($groups)); |
||||
|
$v['groups_text'] = implode(',', array_values($groups)); |
||||
|
} |
||||
|
unset($v); |
||||
|
$result = array("total" => $list->total(), "rows" => $list->items()); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加 |
||||
|
*/ |
||||
|
public function add() |
||||
|
{ |
||||
|
if ($this->request->isPost()) { |
||||
|
$this->token(); |
||||
|
$params = $this->request->post("row/a"); |
||||
|
if ($params) { |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
if (!Validate::is($params['password'], '\S{6,30}')) { |
||||
|
exception(__("Please input correct password")); |
||||
|
} |
||||
|
$params['salt'] = Random::alnum(); |
||||
|
$params['password'] = md5(md5($params['password']) . $params['salt']); |
||||
|
$params['avatar'] = '/assets/img/avatar.png'; //设置新管理员默认头像。 |
||||
|
$result = $this->model->validate('Admin.add')->save($params); |
||||
|
if ($result === false) { |
||||
|
exception($this->model->getError()); |
||||
|
} |
||||
|
$group = $this->request->post("group/a"); |
||||
|
|
||||
|
//过滤不允许的组别,避免越权 |
||||
|
$group = array_intersect($this->childrenGroupIds, $group); |
||||
|
if (!$group) { |
||||
|
exception(__('The parent group exceeds permission limit')); |
||||
|
} |
||||
|
|
||||
|
$dataset = []; |
||||
|
foreach ($group as $value) { |
||||
|
$dataset[] = ['uid' => $this->model->id, 'group_id' => $value]; |
||||
|
} |
||||
|
model('AuthGroupAccess')->saveAll($dataset); |
||||
|
Db::commit(); |
||||
|
} catch (\Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
$this->success(); |
||||
|
} |
||||
|
$this->error(__('Parameter %s can not be empty', '')); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 编辑 |
||||
|
*/ |
||||
|
public function edit($ids = null) |
||||
|
{ |
||||
|
$row = $this->model->get(['id' => $ids]); |
||||
|
if (!$row) { |
||||
|
$this->error(__('No Results were found')); |
||||
|
} |
||||
|
if (!in_array($row->id, $this->childrenAdminIds)) { |
||||
|
$this->error(__('You have no permission')); |
||||
|
} |
||||
|
if ($this->request->isPost()) { |
||||
|
$this->token(); |
||||
|
$params = $this->request->post("row/a"); |
||||
|
if ($params) { |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
if ($params['password']) { |
||||
|
if (!Validate::is($params['password'], '\S{6,30}')) { |
||||
|
exception(__("Please input correct password")); |
||||
|
} |
||||
|
$params['salt'] = Random::alnum(); |
||||
|
$params['password'] = md5(md5($params['password']) . $params['salt']); |
||||
|
} else { |
||||
|
unset($params['password'], $params['salt']); |
||||
|
} |
||||
|
//这里需要针对username和email做唯一验证 |
||||
|
$adminValidate = \think\Loader::validate('Admin'); |
||||
|
$adminValidate->rule([ |
||||
|
'username' => 'require|regex:\w{3,30}|unique:admin,username,' . $row->id, |
||||
|
'email' => 'require|email|unique:admin,email,' . $row->id, |
||||
|
'mobile' => 'regex:1[3-9]\d{9}|unique:admin,mobile,' . $row->id, |
||||
|
'password' => 'regex:\S{32}', |
||||
|
]); |
||||
|
$result = $row->validate('Admin.edit')->save($params); |
||||
|
if ($result === false) { |
||||
|
exception($row->getError()); |
||||
|
} |
||||
|
|
||||
|
// 先移除所有权限 |
||||
|
model('AuthGroupAccess')->where('uid', $row->id)->delete(); |
||||
|
|
||||
|
$group = $this->request->post("group/a"); |
||||
|
|
||||
|
// 过滤不允许的组别,避免越权 |
||||
|
$group = array_intersect($this->childrenGroupIds, $group); |
||||
|
if (!$group) { |
||||
|
exception(__('The parent group exceeds permission limit')); |
||||
|
} |
||||
|
|
||||
|
$dataset = []; |
||||
|
foreach ($group as $value) { |
||||
|
$dataset[] = ['uid' => $row->id, 'group_id' => $value]; |
||||
|
} |
||||
|
model('AuthGroupAccess')->saveAll($dataset); |
||||
|
Db::commit(); |
||||
|
} catch (\Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
$this->success(); |
||||
|
} |
||||
|
$this->error(__('Parameter %s can not be empty', '')); |
||||
|
} |
||||
|
$grouplist = $this->auth->getGroups($row['id']); |
||||
|
$groupids = []; |
||||
|
foreach ($grouplist as $k => $v) { |
||||
|
$groupids[] = $v['id']; |
||||
|
} |
||||
|
$this->view->assign("row", $row); |
||||
|
$this->view->assign("groupids", $groupids); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
*/ |
||||
|
public function del($ids = "") |
||||
|
{ |
||||
|
if (!$this->request->isPost()) { |
||||
|
$this->error(__("Invalid parameters")); |
||||
|
} |
||||
|
$ids = $ids ? $ids : $this->request->post("ids"); |
||||
|
if ($ids) { |
||||
|
$ids = array_intersect($this->childrenAdminIds, array_filter(explode(',', $ids))); |
||||
|
// 避免越权删除管理员 |
||||
|
$childrenGroupIds = $this->childrenGroupIds; |
||||
|
$adminList = $this->model->where('id', 'in', $ids)->where('id', 'in', function ($query) use ($childrenGroupIds) { |
||||
|
$query->name('auth_group_access')->where('group_id', 'in', $childrenGroupIds)->field('uid'); |
||||
|
})->select(); |
||||
|
if ($adminList) { |
||||
|
$deleteIds = []; |
||||
|
foreach ($adminList as $k => $v) { |
||||
|
$deleteIds[] = $v->id; |
||||
|
} |
||||
|
$deleteIds = array_values(array_diff($deleteIds, [$this->auth->id])); |
||||
|
if ($deleteIds) { |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
$this->model->destroy($deleteIds); |
||||
|
model('AuthGroupAccess')->where('uid', 'in', $deleteIds)->delete(); |
||||
|
Db::commit(); |
||||
|
} catch (\Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
$this->success(); |
||||
|
} |
||||
|
$this->error(__('No rows were deleted')); |
||||
|
} |
||||
|
} |
||||
|
$this->error(__('You have no permission')); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 批量更新 |
||||
|
* @internal |
||||
|
*/ |
||||
|
public function multi($ids = "") |
||||
|
{ |
||||
|
// 管理员禁止批量操作 |
||||
|
$this->error(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 下拉搜索 |
||||
|
*/ |
||||
|
public function selectpage() |
||||
|
{ |
||||
|
$this->dataLimit = 'auth'; |
||||
|
$this->dataLimitField = 'id'; |
||||
|
return parent::selectpage(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,133 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\member; |
||||
|
|
||||
|
use app\admin\model\AuthGroup; |
||||
|
use app\common\controller\Backend; |
||||
|
|
||||
|
/** |
||||
|
* 管理员日志 |
||||
|
* |
||||
|
* @icon fa fa-users |
||||
|
* @remark 管理员可以查看自己所拥有的权限的管理员日志 |
||||
|
*/ |
||||
|
class Adminlog extends Backend |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* @var \app\admin\model\AdminLog |
||||
|
*/ |
||||
|
protected $model = null; |
||||
|
protected $childrenGroupIds = []; |
||||
|
protected $childrenAdminIds = []; |
||||
|
|
||||
|
public function _initialize() |
||||
|
{ |
||||
|
parent::_initialize(); |
||||
|
$this->model = model('AdminLog'); |
||||
|
|
||||
|
$this->childrenAdminIds = $this->auth->getChildrenAdminIds(true); |
||||
|
$this->childrenGroupIds = $this->auth->getChildrenGroupIds(true); |
||||
|
|
||||
|
$groupName = AuthGroup::where('id', 'in', $this->childrenGroupIds) |
||||
|
->column('id,name'); |
||||
|
|
||||
|
$this->view->assign('groupdata', $groupName); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() |
||||
|
{ |
||||
|
//设置过滤方法 |
||||
|
$this->request->filter(['strip_tags', 'trim']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
$list = $this->model |
||||
|
->where($where) |
||||
|
->where('admin_id', 'in', $this->childrenAdminIds) |
||||
|
->order($sort, $order) |
||||
|
->paginate($limit); |
||||
|
|
||||
|
$result = array("total" => $list->total(), "rows" => $list->items()); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 详情 |
||||
|
*/ |
||||
|
public function detail($ids) |
||||
|
{ |
||||
|
$row = $this->model->get(['id' => $ids]); |
||||
|
if (!$row) { |
||||
|
$this->error(__('No Results were found')); |
||||
|
} |
||||
|
if (!$row['admin_id'] || !in_array($row['admin_id'], $this->childrenAdminIds)) { |
||||
|
$this->error(__('You have no permission')); |
||||
|
} |
||||
|
$this->view->assign("row", $row->toArray()); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加 |
||||
|
* @internal |
||||
|
*/ |
||||
|
public function add() |
||||
|
{ |
||||
|
$this->error(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 编辑 |
||||
|
* @internal |
||||
|
*/ |
||||
|
public function edit($ids = null) |
||||
|
{ |
||||
|
$this->error(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
*/ |
||||
|
public function del($ids = "") |
||||
|
{ |
||||
|
if (!$this->request->isPost()) { |
||||
|
$this->error(__("Invalid parameters")); |
||||
|
} |
||||
|
$ids = $ids ? $ids : $this->request->post("ids"); |
||||
|
if ($ids) { |
||||
|
$adminList = $this->model->where('id', 'in', $ids)->where('admin_id', 'in', $this->childrenAdminIds)->select(); |
||||
|
if ($adminList) { |
||||
|
$deleteIds = []; |
||||
|
foreach ($adminList as $k => $v) { |
||||
|
$deleteIds[] = $v->id; |
||||
|
} |
||||
|
if ($deleteIds) { |
||||
|
$this->model->destroy($deleteIds); |
||||
|
$this->success(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$this->error(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 批量更新 |
||||
|
* @internal |
||||
|
*/ |
||||
|
public function multi($ids = "") |
||||
|
{ |
||||
|
// 管理员禁止批量操作 |
||||
|
$this->error(); |
||||
|
} |
||||
|
|
||||
|
public function selectpage() |
||||
|
{ |
||||
|
return parent::selectpage(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,334 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\member; |
||||
|
|
||||
|
use app\admin\model\AuthGroup; |
||||
|
use app\admin\model\MemberGroup; |
||||
|
use app\common\controller\Backend; |
||||
|
use fast\Tree; |
||||
|
use think\Db; |
||||
|
use think\Exception; |
||||
|
|
||||
|
/** |
||||
|
* 角色组 |
||||
|
* |
||||
|
* @icon fa fa-group |
||||
|
* @remark 角色组可以有多个,角色有上下级层级关系,如果子角色有角色组和管理员的权限则可以派生属于自己组别下级的角色组或管理员 |
||||
|
*/ |
||||
|
class Group extends Backend |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* @var \app\admin\model\AuthGroup |
||||
|
*/ |
||||
|
protected $model = null; |
||||
|
//当前登录管理员所有子组别 |
||||
|
protected $childrenGroupIds = []; |
||||
|
//当前组别列表数据 |
||||
|
protected $grouplist = []; |
||||
|
protected $groupdata = []; |
||||
|
//无需要权限判断的方法 |
||||
|
protected $noNeedRight = ['roletree']; |
||||
|
|
||||
|
public function _initialize() |
||||
|
{ |
||||
|
parent::_initialize(); |
||||
|
$this->model = model('MemberGroup'); |
||||
|
|
||||
|
$this->childrenGroupIds = $this->auth->getChildrenGroupIds(true); |
||||
|
|
||||
|
$groupList = collection(MemberGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray(); |
||||
|
|
||||
|
Tree::instance()->init($groupList); |
||||
|
$groupList = []; |
||||
|
if ($this->auth->isSuperAdmin()) { |
||||
|
$groupList = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0)); |
||||
|
} else { |
||||
|
$groups = $this->auth->getGroups(); |
||||
|
$groupIds = []; |
||||
|
foreach ($groups as $m => $n) { |
||||
|
if (in_array($n['id'], $groupIds) || in_array($n['pid'], $groupIds)) { |
||||
|
continue; |
||||
|
} |
||||
|
$groupList = array_merge($groupList, Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['pid']))); |
||||
|
foreach ($groupList as $index => $item) { |
||||
|
$groupIds[] = $item['id']; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$groupName = []; |
||||
|
foreach ($groupList as $k => $v) { |
||||
|
$groupName[$v['id']] = $v['name']; |
||||
|
} |
||||
|
|
||||
|
$this->grouplist = $groupList; |
||||
|
$this->groupdata = $groupName; |
||||
|
$this->assignconfig("admin", ['id' => $this->auth->id, 'group_ids' => $this->auth->getGroupIds()]); |
||||
|
|
||||
|
$this->view->assign('groupdata', $this->groupdata); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() |
||||
|
{ |
||||
|
if ($this->request->isAjax()) { |
||||
|
$list = $this->grouplist; |
||||
|
$total = count($list); |
||||
|
$result = array("total" => $total, "rows" => $list); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加 |
||||
|
*/ |
||||
|
public function add() |
||||
|
{ |
||||
|
if ($this->request->isPost()) { |
||||
|
$this->token(); |
||||
|
$params = $this->request->post("row/a", [], 'strip_tags'); |
||||
|
$params['rules'] = explode(',', $params['rules']); |
||||
|
if (!in_array($params['pid'], $this->childrenGroupIds)) { |
||||
|
$this->error(__('The parent group exceeds permission limit')); |
||||
|
} |
||||
|
$parentmodel = model("MemberGroup")->get($params['pid']); |
||||
|
|
||||
|
if (!$parentmodel) { |
||||
|
$this->error(__('The parent group can not found')); |
||||
|
} |
||||
|
// 父级别的规则节点 |
||||
|
$parentrules = explode(',', $parentmodel->rules); |
||||
|
// 当前组别的规则节点 |
||||
|
$currentrules = $this->auth->getRuleIds(); |
||||
|
$rules = $params['rules']; |
||||
|
// 如果父组不是超级管理员则需要过滤规则节点,不能超过父组别的权限 |
||||
|
$rules = in_array('*', $parentrules) ? $rules : array_intersect($parentrules, $rules); |
||||
|
// 如果当前组别不是超级管理员则需要过滤规则节点,不能超当前组别的权限 |
||||
|
$rules = in_array('*', $currentrules) ? $rules : array_intersect($currentrules, $rules); |
||||
|
$params['rules'] = implode(',', $rules); |
||||
|
if ($params) { |
||||
|
$this->model->create($params); |
||||
|
$this->success(); |
||||
|
} |
||||
|
$this->error(); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 编辑 |
||||
|
*/ |
||||
|
public function edit($ids = null) |
||||
|
{ |
||||
|
if (!in_array($ids, $this->childrenGroupIds)) { |
||||
|
$this->error(__('You have no permission')); |
||||
|
} |
||||
|
$row = $this->model->get(['id' => $ids]); |
||||
|
if (!$row) { |
||||
|
$this->error(__('No Results were found')); |
||||
|
} |
||||
|
if ($this->request->isPost()) { |
||||
|
$this->token(); |
||||
|
$params = $this->request->post("row/a", [], 'strip_tags'); |
||||
|
//父节点不能是非权限内节点 |
||||
|
if (!in_array($params['pid'], $this->childrenGroupIds)) { |
||||
|
$this->error(__('The parent group exceeds permission limit')); |
||||
|
} |
||||
|
// 父节点不能是它自身的子节点或自己本身 |
||||
|
if (in_array($params['pid'], Tree::instance()->getChildrenIds($row->id, true))) { |
||||
|
$this->error(__('The parent group can not be its own child or itself')); |
||||
|
} |
||||
|
$params['rules'] = explode(',', $params['rules']); |
||||
|
|
||||
|
$parentmodel = model("MemberGroup")->get($params['pid']); |
||||
|
if (!$parentmodel) { |
||||
|
$this->error(__('The parent group can not found')); |
||||
|
} |
||||
|
// 父级别的规则节点 |
||||
|
$parentrules = explode(',', $parentmodel->rules); |
||||
|
// 当前组别的规则节点 |
||||
|
$currentrules = $this->auth->getRuleIds(); |
||||
|
$rules = $params['rules']; |
||||
|
// 如果父组不是超级管理员则需要过滤规则节点,不能超过父组别的权限 |
||||
|
$rules = in_array('*', $parentrules) ? $rules : array_intersect($parentrules, $rules); |
||||
|
// 如果当前组别不是超级管理员则需要过滤规则节点,不能超当前组别的权限 |
||||
|
$rules = in_array('*', $currentrules) ? $rules : array_intersect($currentrules, $rules); |
||||
|
$params['rules'] = implode(',', $rules); |
||||
|
if ($params) { |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
$row->save($params); |
||||
|
$children_auth_groups = model("MemberGroup")->all(['id' => ['in', implode(',', (Tree::instance()->getChildrenIds($row->id)))]]); |
||||
|
$childparams = []; |
||||
|
foreach ($children_auth_groups as $key => $children_auth_group) { |
||||
|
$childparams[$key]['id'] = $children_auth_group->id; |
||||
|
$childparams[$key]['rules'] = implode(',', array_intersect(explode(',', $children_auth_group->rules), $rules)); |
||||
|
} |
||||
|
model("AuthGroup")->saveAll($childparams); |
||||
|
Db::commit(); |
||||
|
$this->success(); |
||||
|
} catch (Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
} |
||||
|
$this->error(); |
||||
|
return; |
||||
|
} |
||||
|
$this->view->assign("row", $row); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
*/ |
||||
|
public function del($ids = "") |
||||
|
{ |
||||
|
if (!$this->request->isPost()) { |
||||
|
$this->error(__("Invalid parameters")); |
||||
|
} |
||||
|
$ids = $ids ? $ids : $this->request->post("ids"); |
||||
|
if ($ids) { |
||||
|
$ids = explode(',', $ids); |
||||
|
$grouplist = $this->auth->getGroups(); |
||||
|
$group_ids = array_map(function ($group) { |
||||
|
return $group['id']; |
||||
|
}, $grouplist); |
||||
|
// 移除掉当前管理员所在组别 |
||||
|
$ids = array_diff($ids, $group_ids); |
||||
|
|
||||
|
// 循环判断每一个组别是否可删除 |
||||
|
$grouplist = $this->model->where('id', 'in', $ids)->select(); |
||||
|
$groupaccessmodel = model('MemberGroupAccess'); |
||||
|
foreach ($grouplist as $k => $v) { |
||||
|
// 当前组别下有管理员 |
||||
|
$groupone = $groupaccessmodel->get(['group_id' => $v['id']]); |
||||
|
if ($groupone) { |
||||
|
$ids = array_diff($ids, [$v['id']]); |
||||
|
continue; |
||||
|
} |
||||
|
// 当前组别下有子组别 |
||||
|
$groupone = $this->model->get(['pid' => $v['id']]); |
||||
|
if ($groupone) { |
||||
|
$ids = array_diff($ids, [$v['id']]); |
||||
|
continue; |
||||
|
} |
||||
|
} |
||||
|
if (!$ids) { |
||||
|
$this->error(__('You can not delete group that contain child group and administrators')); |
||||
|
} |
||||
|
$count = $this->model->where('id', 'in', $ids)->delete(); |
||||
|
if ($count) { |
||||
|
$this->success(); |
||||
|
} |
||||
|
} |
||||
|
$this->error(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 批量更新 |
||||
|
* @internal |
||||
|
*/ |
||||
|
public function multi($ids = "") |
||||
|
{ |
||||
|
// 组别禁止批量操作 |
||||
|
$this->error(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 读取角色权限树 |
||||
|
* |
||||
|
* @internal |
||||
|
*/ |
||||
|
public function roletree() |
||||
|
{ |
||||
|
$this->loadlang('auth/group'); |
||||
|
|
||||
|
$model = model('MemberGroup'); |
||||
|
$id = $this->request->post("id"); |
||||
|
$pid = $this->request->post("pid"); |
||||
|
$parentGroupModel = $model->get($pid); |
||||
|
|
||||
|
$currentGroupModel = null; |
||||
|
if ($id) { |
||||
|
$currentGroupModel = $model->get($id); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
if (($pid || $parentGroupModel) && (!$id || $currentGroupModel)) { |
||||
|
|
||||
|
if (in_array('*', explode(',', $parentGroupModel->rules))) { |
||||
|
//获取该企业拥有的子菜单 |
||||
|
$company = Db::name('company')->where('id',CID)->find(); |
||||
|
$group = Db::name('auth_group')->where('id',$company['group_id'])->find(); |
||||
|
$parentGroupModel->rules = $group['rules']; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
$id = $id ? $id : null; |
||||
|
$ruleList = collection(model('AuthRule')->order('weigh', 'desc')->order('id', 'asc')->select())->toArray(); |
||||
|
|
||||
|
//读取父类角色所有节点列表 |
||||
|
$parentRuleList = []; |
||||
|
if (in_array('*', explode(',', $parentGroupModel->rules))) { |
||||
|
$parentRuleList = $ruleList; |
||||
|
} else { |
||||
|
$parentRuleIds = explode(',', $parentGroupModel->rules); |
||||
|
foreach ($ruleList as $k => $v) { |
||||
|
if (in_array($v['id'], $parentRuleIds)) { |
||||
|
$parentRuleList[] = $v; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$ruleTree = new Tree(); |
||||
|
$groupTree = new Tree(); |
||||
|
//当前所有正常规则列表 |
||||
|
$ruleTree->init($parentRuleList); |
||||
|
|
||||
|
//角色组列表 |
||||
|
$groupTree->init(collection(model('MemberGroup')->where('id', 'in', $this->childrenGroupIds)->select())->toArray()); |
||||
|
|
||||
|
//读取当前角色下规则ID集合 |
||||
|
$adminRuleIds = $this->auth->getRuleIds(); |
||||
|
//是否是超级管理员 |
||||
|
$superadmin = $this->auth->isSuperAdmin(); |
||||
|
//当前拥有的规则ID集合 |
||||
|
$currentRuleIds = $id ? explode(',', $currentGroupModel->rules) : []; |
||||
|
|
||||
|
if (!$id || !in_array($pid, $this->childrenGroupIds) || !in_array($pid, $groupTree->getChildrenIds($id, true))) { |
||||
|
$parentRuleList = $ruleTree->getTreeList($ruleTree->getTreeArray(0), 'name'); |
||||
|
$hasChildrens = []; |
||||
|
foreach ($parentRuleList as $k => $v) { |
||||
|
if ($v['haschild']) { |
||||
|
$hasChildrens[] = $v['id']; |
||||
|
} |
||||
|
} |
||||
|
$parentRuleIds = array_map(function ($item) { |
||||
|
return $item['id']; |
||||
|
}, $parentRuleList); |
||||
|
$nodeList = []; |
||||
|
foreach ($parentRuleList as $k => $v) { |
||||
|
if (!$superadmin && !in_array($v['id'], $adminRuleIds)) { |
||||
|
continue; |
||||
|
} |
||||
|
if ($v['pid'] && !in_array($v['pid'], $parentRuleIds)) { |
||||
|
continue; |
||||
|
} |
||||
|
$state = array('selected' => in_array($v['id'], $currentRuleIds) && !in_array($v['id'], $hasChildrens)); |
||||
|
$nodeList[] = array('id' => $v['id'], 'parent' => $v['pid'] ? $v['pid'] : '#', 'text' => __($v['title']), 'type' => 'menu', 'state' => $state); |
||||
|
} |
||||
|
$this->success('', null, $nodeList); |
||||
|
} |
||||
|
else { |
||||
|
$this->error(__('Can not change the parent to child')); |
||||
|
} |
||||
|
} else { |
||||
|
$this->error(__('Group not found')); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,159 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\member; |
||||
|
|
||||
|
use app\admin\model\AuthRule; |
||||
|
use app\common\controller\Backend; |
||||
|
use fast\Tree; |
||||
|
use think\Cache; |
||||
|
|
||||
|
/** |
||||
|
* 规则管理 |
||||
|
* |
||||
|
* @icon fa fa-list |
||||
|
* @remark 规则通常对应一个控制器的方法,同时左侧的菜单栏数据也从规则中体现,通常建议通过控制台进行生成规则节点 |
||||
|
*/ |
||||
|
class Rule extends Backend |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* @var \app\admin\model\AuthRule |
||||
|
*/ |
||||
|
protected $model = null; |
||||
|
protected $rulelist = []; |
||||
|
protected $multiFields = 'ismenu,status'; |
||||
|
|
||||
|
public function _initialize() |
||||
|
{ |
||||
|
parent::_initialize(); |
||||
|
if (!$this->auth->isSuperAdmin()) { |
||||
|
$this->error(__('Access is allowed only to the super management group')); |
||||
|
} |
||||
|
$this->model = model('AuthRule'); |
||||
|
// 必须将结果集转换为数组 |
||||
|
$ruleList = \think\Db::name("auth_rule")->field('type,condition,remark,createtime,updatetime', true)->order('weigh DESC,id ASC')->select(); |
||||
|
foreach ($ruleList as $k => &$v) { |
||||
|
$v['title'] = __($v['title']); |
||||
|
} |
||||
|
unset($v); |
||||
|
Tree::instance()->init($ruleList); |
||||
|
$this->rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title'); |
||||
|
$ruledata = [0 => __('None')]; |
||||
|
foreach ($this->rulelist as $k => &$v) { |
||||
|
if (!$v['ismenu']) { |
||||
|
continue; |
||||
|
} |
||||
|
$ruledata[$v['id']] = $v['title']; |
||||
|
unset($v['spacer']); |
||||
|
} |
||||
|
unset($v); |
||||
|
$this->view->assign('ruledata', $ruledata); |
||||
|
$this->view->assign("menutypeList", $this->model->getMenutypeList()); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() |
||||
|
{ |
||||
|
if ($this->request->isAjax()) { |
||||
|
$list = $this->rulelist; |
||||
|
$total = count($this->rulelist); |
||||
|
$result = array("total" => $total, "rows" => $list); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加 |
||||
|
*/ |
||||
|
public function add() |
||||
|
{ |
||||
|
if ($this->request->isPost()) { |
||||
|
$this->token(); |
||||
|
$params = $this->request->post("row/a", [], 'strip_tags'); |
||||
|
if ($params) { |
||||
|
if (!$params['ismenu'] && !$params['pid']) { |
||||
|
$this->error(__('The non-menu rule must have parent')); |
||||
|
} |
||||
|
$result = $this->model->validate()->save($params); |
||||
|
if ($result === false) { |
||||
|
$this->error($this->model->getError()); |
||||
|
} |
||||
|
Cache::rm('__menu__'); |
||||
|
$this->success(); |
||||
|
} |
||||
|
$this->error(); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 编辑 |
||||
|
*/ |
||||
|
public function edit($ids = null) |
||||
|
{ |
||||
|
$row = $this->model->get(['id' => $ids]); |
||||
|
if (!$row) { |
||||
|
$this->error(__('No Results were found')); |
||||
|
} |
||||
|
if ($this->request->isPost()) { |
||||
|
$this->token(); |
||||
|
$params = $this->request->post("row/a", [], 'strip_tags'); |
||||
|
if ($params) { |
||||
|
if (!$params['ismenu'] && !$params['pid']) { |
||||
|
$this->error(__('The non-menu rule must have parent')); |
||||
|
} |
||||
|
if ($params['pid'] == $row['id']) { |
||||
|
$this->error(__('Can not change the parent to self')); |
||||
|
} |
||||
|
if ($params['pid'] != $row['pid']) { |
||||
|
$childrenIds = Tree::instance()->init(collection(AuthRule::select())->toArray())->getChildrenIds($row['id']); |
||||
|
if (in_array($params['pid'], $childrenIds)) { |
||||
|
$this->error(__('Can not change the parent to child')); |
||||
|
} |
||||
|
} |
||||
|
//这里需要针对name做唯一验证 |
||||
|
$ruleValidate = \think\Loader::validate('AuthRule'); |
||||
|
$ruleValidate->rule([ |
||||
|
'name' => 'require|unique:AuthRule,name,' . $row->id, |
||||
|
]); |
||||
|
$result = $row->validate()->save($params); |
||||
|
if ($result === false) { |
||||
|
$this->error($row->getError()); |
||||
|
} |
||||
|
Cache::rm('__menu__'); |
||||
|
$this->success(); |
||||
|
} |
||||
|
$this->error(); |
||||
|
} |
||||
|
$this->view->assign("row", $row); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
*/ |
||||
|
public function del($ids = "") |
||||
|
{ |
||||
|
if (!$this->request->isPost()) { |
||||
|
$this->error(__("Invalid parameters")); |
||||
|
} |
||||
|
$ids = $ids ? $ids : $this->request->post("ids"); |
||||
|
if ($ids) { |
||||
|
$delIds = []; |
||||
|
foreach (explode(',', $ids) as $k => $v) { |
||||
|
$delIds = array_merge($delIds, Tree::instance()->getChildrenIds($v, true)); |
||||
|
} |
||||
|
$delIds = array_unique($delIds); |
||||
|
$count = $this->model->where('id', 'in', $delIds)->delete(); |
||||
|
if ($count) { |
||||
|
Cache::rm('__menu__'); |
||||
|
$this->success(); |
||||
|
} |
||||
|
} |
||||
|
$this->error(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,104 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\qingdong; |
||||
|
|
||||
|
use addons\qingdong\controller\File; |
||||
|
use addons\qingdong\model\Staff; |
||||
|
use app\common\controller\Backend; |
||||
|
use app\common\exception\UploadException; |
||||
|
use app\common\library\Upload; |
||||
|
|
||||
|
/** |
||||
|
* qingdong 基础控制器 |
||||
|
* |
||||
|
* @icon fa fa-circle-o |
||||
|
*/ |
||||
|
class Base extends Backend |
||||
|
{ |
||||
|
|
||||
|
protected $noNeedRight = []; |
||||
|
protected $_staff = null; |
||||
|
|
||||
|
public function _initialize() |
||||
|
{ |
||||
|
parent::_initialize(); |
||||
|
$staff = Staff::where(['admin_id' => $this->auth->id])->find(); |
||||
|
if (!empty($staff)) { |
||||
|
$this->_staff = $staff; |
||||
|
}else{ |
||||
|
$data = [ |
||||
|
'admin_id' => $this->auth->id, |
||||
|
'group_ids' => implode(',', $this->auth->getGroupIds()), |
||||
|
'name' => $this->auth->nickname, |
||||
|
'num'=>'01', |
||||
|
'mobile' => $this->auth->username, |
||||
|
'salt' => $this->auth->salt, |
||||
|
'password' => $this->auth->password, |
||||
|
'img' => '/assets/addons/qingdong/mini/avatar.png', |
||||
|
'email' => $this->auth->email, |
||||
|
'sex' => 1, |
||||
|
'status' => 1, |
||||
|
'createtime' => $this->auth->createtime, |
||||
|
'updatetime' => $this->auth->updatetime |
||||
|
]; |
||||
|
$staffModel = new Staff(); |
||||
|
$result = $staffModel->save($data); |
||||
|
if ($result) { |
||||
|
$staff = Staff::where(['admin_id' => $this->auth->id])->find(); |
||||
|
$this->_staff = $staff; |
||||
|
} else { |
||||
|
$this->error('当前账号未绑定员工,要使用插件功能,请在员工列表添加账号', 'qingdong/department/staff'); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public function getStaff() |
||||
|
{ |
||||
|
return $this->_staff; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
protected function qingdongValidate($params, $class, $scene, $rules = []) { |
||||
|
$validate = validate('addons\qingdong\validate\\'.$class); |
||||
|
if (!$validate->check($params, $rules, $scene)) { |
||||
|
return $validate->getError(); |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 上传文件 |
||||
|
* @ApiMethod (POST) |
||||
|
* @param File $file 文件流 |
||||
|
*/ |
||||
|
public function upload() { |
||||
|
|
||||
|
$attachment = null; |
||||
|
//默认普通上传文件 |
||||
|
$file = $this->request->file('file'); |
||||
|
try { |
||||
|
$upload = new Upload($file); |
||||
|
$attachment = $upload->upload(); |
||||
|
$info = $attachment->toArray(); |
||||
|
$file = new \addons\qingdong\model\File(); |
||||
|
$params = [ |
||||
|
'name' => $info['filename'], |
||||
|
'save_name' => $info['url'], |
||||
|
'size' => isset($info['filesize'])?$info['filesize']:0, |
||||
|
'types' => $info['mimetype'], |
||||
|
'file_path' => $info['url'], |
||||
|
'create_staff_id' => empty($staff)?0:$staff->id, |
||||
|
]; |
||||
|
$file->data(array_filter($params)); |
||||
|
$file->save(); |
||||
|
$fileId = $file->id; |
||||
|
|
||||
|
} catch (UploadException $e) { |
||||
|
return json_encode(['code' => 0, 'msg' => $e->getMessage()]); |
||||
|
} |
||||
|
$this->success(__('Uploaded successful'),'', [ |
||||
|
'id' => $fileId, |
||||
|
'url' =>$params['file_path'] |
||||
|
]); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,184 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\qingdong; |
||||
|
|
||||
|
|
||||
|
use addons\qingdong\model\Staff; |
||||
|
use app\admin\controller\qingdong\Base; |
||||
|
use addons\qingdong\model\Contract; |
||||
|
use addons\qingdong\model\Customer; |
||||
|
use addons\qingdong\model\Field; |
||||
|
use addons\qingdong\model\Receivables; |
||||
|
use addons\qingdong\model\Record; |
||||
|
use addons\qingdong\model\Leads; |
||||
|
use addons\qingdong\model\ExamineRecord; |
||||
|
|
||||
|
use think\Config; |
||||
|
|
||||
|
/** |
||||
|
* 控制台 |
||||
|
* @icon fa fa-dashboard |
||||
|
* @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据 |
||||
|
*/ |
||||
|
class Dashboard extends Base { |
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() { |
||||
|
|
||||
|
//团队统计 |
||||
|
$time = strtotime(date('Y-m', strtotime('-1 year'))); |
||||
|
$auth = Staff::getMyStaffIds(); |
||||
|
$staff_id = implode(',',$auth); //权限 |
||||
|
$sources = Field::getField('客户来源'); |
||||
|
$customers = Customer::where([ |
||||
|
'owner_staff_id'=>['in',$staff_id], |
||||
|
'createtime' => [ |
||||
|
'egt', |
||||
|
$time |
||||
|
] |
||||
|
])->field("FROM_UNIXTIME(createtime,'%Y-%m') as ctime,source,count(*) as c")->group('source,ctime')->select(); |
||||
|
$select = []; |
||||
|
foreach ($customers as $v) { |
||||
|
$select[$v['source']][$v['ctime']] = $v['c']; |
||||
|
} |
||||
|
$toMonthTime = strtotime(date('Y-m')); |
||||
|
$sourcedata = ['客户来源' => ['客户来源']]; |
||||
|
for ($time; $time <= $toMonthTime; $time = strtotime('+1 month', $time)) { |
||||
|
$sourcedata['客户来源'][] = date('Y-m', $time); |
||||
|
foreach ($sources as $v) { |
||||
|
if (empty($sourcedata[$v])) { |
||||
|
$sourcedata[$v][] = $v; |
||||
|
} |
||||
|
$sourcedata[$v][] = intval($select[$v][date('Y-m', $time)] ?? 0); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//合同金额统计 |
||||
|
$time = strtotime(date('Y-m', strtotime('-1 year'))); |
||||
|
|
||||
|
$contractNums=Contract::where(['cid'=>CID,'order_staff_id'=>['in',$staff_id],'check_status' => 2,'createtime' => ['egt',$time]])->field("FROM_UNIXTIME(createtime,'%Y-%m') as ctime,count(*) as c")->group('ctime')->select(); |
||||
|
$contractNums=modify_array($contractNums,'ctime','c'); |
||||
|
$contract=Contract::where(['cid'=>CID,'order_staff_id'=>['in',$staff_id],'check_status' => 2,'createtime' => ['egt',$time]])->field("FROM_UNIXTIME(createtime,'%Y-%m') as ctime,sum(money) as s")->group('ctime')->select(); |
||||
|
$contract=modify_array($contract,'ctime','s'); |
||||
|
//回款 |
||||
|
$receivables=Receivables::where(['cid'=>CID,'owner_staff_id'=>['in',$staff_id],'check_status'=>2,'createtime' => ['egt',$time]])->field("FROM_UNIXTIME(createtime,'%Y-%m') as ctime,sum(money) as s")->group("ctime")->select(); |
||||
|
$receivables=modify_array($receivables,'ctime','s'); |
||||
|
$contactdata=[]; |
||||
|
for ($time; $time <= $toMonthTime; $time = strtotime('+1 month', $time)) { |
||||
|
$contactdata['date'][] = date('Y-m', $time); |
||||
|
$contactdata['num'][] = $contractNums[date('Y-m', $time)]??0; |
||||
|
$contactdata['contract'][] = $contract[date('Y-m', $time)]??0; |
||||
|
$contactdata['receivables'][] = $receivables[date('Y-m', $time)]??0; |
||||
|
} |
||||
|
|
||||
|
$where1['owner_staff_id'] =array('in',$staff_id); |
||||
|
$start = strtotime(date('Y-m-d 00:00:00')); |
||||
|
$end = strtotime(date('Y-m-d 23:59:59')); |
||||
|
$where2['createtime']= array(array('egt',$start),array('elt',$end)); |
||||
|
//今日新增客户 |
||||
|
$todaycontomer = Customer::where(['owner_staff_id'=>['in',$staff_id]])->where($where2)->count(); |
||||
|
//今日跟进记录 |
||||
|
$todayrecord=Record::where(['create_staff_id'=>$where1['owner_staff_id']])->where($where2)->count(); |
||||
|
//今日新增线索 |
||||
|
$todaylead = Leads::where($where1)->where($where2)->count(); |
||||
|
//今日新增公海 |
||||
|
$todaysea = Customer::where('owner_staff_id is null or owner_staff_id =0')->where($where2)->count(); |
||||
|
//今日新增合同 |
||||
|
$todaycontract = Contract::where($where1)->where($where2)->count(); |
||||
|
//今日新增回款 |
||||
|
$todayreceivables = Receivables::where($where1)->where($where2)->sum('money'); |
||||
|
//今日已审批 |
||||
|
$todayexamine = ExamineRecord::where(array('check_staff_id'=>['in',$staff_id],'status'=>1))->where($where2)->count(); |
||||
|
//今日待审批 |
||||
|
$todaywork =ExamineRecord::where(array('check_staff_id'=>['in',$staff_id],'status'=>0))->where($where2)->count(); |
||||
|
|
||||
|
|
||||
|
//个人统计 |
||||
|
$Persontime = strtotime(date('Y-m', strtotime('-1 year'))); |
||||
|
$Personauth = Staff::info(); |
||||
|
$Personstaff_id = $Personauth->id; //权限 |
||||
|
$Personcustomers = Customer::where(['cid'=>CID, |
||||
|
'owner_staff_id'=>$Personstaff_id, |
||||
|
'createtime' => [ |
||||
|
'egt', |
||||
|
$Persontime |
||||
|
] |
||||
|
])->field("FROM_UNIXTIME(createtime,'%Y-%m') as ctime,source,count(*) as c")->group('source,ctime')->select(); |
||||
|
$Personselect = []; |
||||
|
foreach ($Personcustomers as $v) { |
||||
|
$Personselect[$v['source']][$v['ctime']] = $v['c']; |
||||
|
} |
||||
|
$PersontoMonthTime = strtotime(date('Y-m')); |
||||
|
$Personsourcedata = ['客户来源' => ['客户来源']]; |
||||
|
for ($Persontime; $Persontime <= $PersontoMonthTime; $Persontime = strtotime('+1 month', $Persontime)) { |
||||
|
$Personsourcedata['客户来源'][] = date('Y-m', $Persontime); |
||||
|
foreach ($sources as $v) { |
||||
|
if (empty($Personsourcedata[$v])) { |
||||
|
$Personsourcedata[$v][] = $v; |
||||
|
} |
||||
|
$Personsourcedata[$v][] = intval($Personselect[$v][date('Y-m', $Persontime)] ?? 0); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//合同金额统计 |
||||
|
$Persontime = strtotime(date('Y-m', strtotime('-1 year'))); |
||||
|
$PersoncontractNums=Contract::where(['cid'=>CID,'order_staff_id'=>$Personstaff_id,'check_status' => 2,'createtime' => ['egt',$Persontime]])->field("FROM_UNIXTIME(createtime,'%Y-%m') as ctime,count(*) as c")->group('ctime')->select(); |
||||
|
$PersoncontractNums=modify_array($PersoncontractNums,'ctime','c'); |
||||
|
$Personcontract=Contract::where(['cid'=>CID,'order_staff_id'=>$Personstaff_id,'check_status' => 2,'createtime' => ['egt',$Persontime]])->field("FROM_UNIXTIME(createtime,'%Y-%m') as ctime,sum(money) as s")->group('ctime')->select(); |
||||
|
$Personcontract=modify_array($Personcontract,'ctime','s'); |
||||
|
//回款 |
||||
|
$Personreceivables=Receivables::where(['cid'=>CID,'owner_staff_id'=>$Personstaff_id,'check_status'=>2,'createtime' => ['egt',$Persontime]])->field("FROM_UNIXTIME(createtime,'%Y-%m') as ctime,sum(money) as s")->group("ctime")->select(); |
||||
|
$Personreceivables=modify_array($Personreceivables,'ctime','s'); |
||||
|
$Personcontactdata=[]; |
||||
|
for ($Persontime; $Persontime <= $PersontoMonthTime; $Persontime = strtotime('+1 month', $Persontime)) { |
||||
|
$Personcontactdata['date'][] = date('Y-m', $Persontime); |
||||
|
$Personcontactdata['num'][] = $PersoncontractNums[date('Y-m', $Persontime)]??0; |
||||
|
$Personcontactdata['contract'][] = $Personcontract[date('Y-m', $Persontime)]??0; |
||||
|
$Personcontactdata['receivables'][] = $Personreceivables[date('Y-m', $Persontime)]??0; |
||||
|
} |
||||
|
$Personwhere1['owner_staff_id'] =$Personstaff_id; |
||||
|
$Personwhere2['createtime']= array(array('egt',$start),array('elt',$end)); |
||||
|
//今日新增客户 |
||||
|
$Persontodaycontomer = Customer::where(['owner_staff_id'=>$Personstaff_id])->where($Personwhere2)->count(); |
||||
|
//今日跟进记录 |
||||
|
$Persontodayrecord=Record::where(['create_staff_id'=>$Personstaff_id])->where($Personwhere2)->count(); |
||||
|
//今日新增线索 |
||||
|
$Persontodaylead = Leads::where($Personwhere1)->where($Personwhere2)->count(); |
||||
|
//今日新增公海 |
||||
|
$Persontodaysea = Customer::where('owner_staff_id is null or owner_staff_id =0')->where($Personwhere2)->count(); |
||||
|
//今日新增合同 |
||||
|
$Persontodaycontract = Contract::where($Personwhere1)->where($Personwhere2)->count(); |
||||
|
//今日新增回款 |
||||
|
$Persontodayreceivables = Receivables::where($Personwhere1)->where($Personwhere2)->sum('money'); |
||||
|
//今日已审批 |
||||
|
$Persontodayexamine = ExamineRecord::where(array('check_staff_id'=>$Personstaff_id,'status'=>1))->where($Personwhere2)->count(); |
||||
|
//今日待审批 |
||||
|
$Persontodaywork =ExamineRecord::where(array('check_staff_id'=>$Personstaff_id,'status'=>0))->where($Personwhere2)->count(); |
||||
|
|
||||
|
$this->view->assign([ |
||||
|
'sourcedata' => array_values($sourcedata), |
||||
|
'contactdata' => $contactdata, |
||||
|
'todaycontomer' =>$todaycontomer, |
||||
|
'todayrecord' =>$todayrecord, |
||||
|
'todaylead' =>$todaylead, |
||||
|
'todaysea' =>$todaysea, |
||||
|
'todaycontract' =>$todaycontract, |
||||
|
'todayreceivables' =>$todayreceivables, |
||||
|
'todayexamine' =>$todayexamine, |
||||
|
'todaywork' =>$todaywork, |
||||
|
'Personsourcedata' => array_values($Personsourcedata), |
||||
|
'Personcontactdata' => $Personcontactdata, |
||||
|
'Persontodaycontomer' =>$Persontodaycontomer, |
||||
|
'Persontodayrecord' =>$Persontodayrecord, |
||||
|
'Persontodaylead' =>$Persontodaylead, |
||||
|
'Persontodaysea' =>$Persontodaysea, |
||||
|
'Persontodaycontract' =>$Persontodaycontract, |
||||
|
'Persontodayreceivables' =>$Persontodayreceivables, |
||||
|
'Persontodayexamine' =>$Persontodayexamine, |
||||
|
'Persontodaywork' =>$Persontodaywork, |
||||
|
]); |
||||
|
|
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,54 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\qingdong\attendance; |
||||
|
|
||||
|
|
||||
|
use addons\qingdong\model\Attendance as AttendanceModel; |
||||
|
use addons\qingdong\model\Staff; |
||||
|
use app\common\controller\Backend; |
||||
|
|
||||
|
/** |
||||
|
* 打卡记录 |
||||
|
*/ |
||||
|
class Attendance extends Backend { |
||||
|
public function _initialize() { |
||||
|
parent::_initialize(); |
||||
|
$this->model = new AttendanceModel(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 打卡记录列表 |
||||
|
*/ |
||||
|
public function index() { |
||||
|
$this->request->filter(['strip_tags']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
//0:全部 1:我的 2:下属的 |
||||
|
$type = input('type',0); |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
switch($type){ |
||||
|
case 1: |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 2: |
||||
|
$wheres['staff_id'] = array('in',Staff::getLowerStaffId()); |
||||
|
break; |
||||
|
default: |
||||
|
$wheres['staff_id'] = array('in',Staff::getMyStaffIds()); |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
$wheres['type'] = 0;//上下班打卡 |
||||
|
$list = $this->model->where($where)->where($wheres)->with(['staff'])->order($sort, $order)->paginate($limit); |
||||
|
$row = $list->items(); |
||||
|
$result = array("total" => $list->total(), "rows" => $row); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,53 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\qingdong\attendance; |
||||
|
|
||||
|
use addons\qingdong\model\AttendanceCard; |
||||
|
use addons\qingdong\model\Staff; |
||||
|
use app\common\controller\Backend; |
||||
|
|
||||
|
/** |
||||
|
* 补卡记录 |
||||
|
*/ |
||||
|
class Card extends Backend { |
||||
|
public function _initialize() { |
||||
|
parent::_initialize(); |
||||
|
$this->model = new AttendanceCard(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 补卡记录 |
||||
|
*/ |
||||
|
public function index() { |
||||
|
$this->request->filter(['strip_tags']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
//0:全部 1:我的 2:下属的 |
||||
|
$type = input('type',0); |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
switch($type){ |
||||
|
case 1: |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['create_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 2: |
||||
|
$wheres['create_staff_id'] = array('in',Staff::getLowerStaffId()); |
||||
|
break; |
||||
|
default: |
||||
|
$wheres['create_staff_id'] = array('in',Staff::getMyStaffIds()); |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
$wheres['type'] = 0;//上下班打卡 |
||||
|
$list = $this->model->where($where)->where($wheres)->with(['createStaff'])->order($sort, $order)->paginate($limit); |
||||
|
$row = $list->items(); |
||||
|
$result = array("total" => $list->total(), "rows" => $row); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,52 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\qingdong\attendance; |
||||
|
|
||||
|
use addons\qingdong\model\Staff; |
||||
|
use app\common\controller\Backend; |
||||
|
use addons\qingdong\model\Leave as leaveModel; |
||||
|
/** |
||||
|
* 请假记录 |
||||
|
*/ |
||||
|
class Leave extends Backend { |
||||
|
public function _initialize() { |
||||
|
parent::_initialize(); |
||||
|
$this->model = new leaveModel(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 请假记录 |
||||
|
*/ |
||||
|
public function index() { |
||||
|
|
||||
|
$this->request->filter(['strip_tags']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
//0:全部 1:我的 2:下属的 |
||||
|
$type = input('type',0); |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
switch($type){ |
||||
|
case 1: |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['create_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 2: |
||||
|
$wheres['create_staff_id'] = array('in',Staff::getLowerStaffId()); |
||||
|
break; |
||||
|
default: |
||||
|
$wheres['create_staff_id'] = array('in',Staff::getMyStaffIds()); |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
$list = $this->model->where($where)->where($wheres)->with(['createStaff'])->order($sort, $order)->paginate($limit); |
||||
|
$row = $list->items(); |
||||
|
$result = array("total" => $list->total(), "rows" => $row); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,54 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\qingdong\attendance; |
||||
|
|
||||
|
|
||||
|
use addons\qingdong\model\Attendance as AttendanceModel; |
||||
|
use addons\qingdong\model\Staff; |
||||
|
use app\common\controller\Backend; |
||||
|
|
||||
|
/** |
||||
|
* 外勤打卡记录 |
||||
|
*/ |
||||
|
class Out extends Backend { |
||||
|
public function _initialize() { |
||||
|
parent::_initialize(); |
||||
|
$this->model = new AttendanceModel(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 外勤打卡记录 |
||||
|
*/ |
||||
|
public function index() { |
||||
|
$this->request->filter(['strip_tags']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
//0:全部 1:我的 2:下属的 |
||||
|
$type = input('type',0); |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
switch($type){ |
||||
|
case 1: |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 2: |
||||
|
$wheres['staff_id'] = array('in',Staff::getLowerStaffId()); |
||||
|
break; |
||||
|
default: |
||||
|
$wheres['staff_id'] = array('in',Staff::getMyStaffIds()); |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
$wheres['type'] = 1;//外勤 |
||||
|
$list = $this->model->where($where)->where($wheres)->with(['staff'])->order($sort, $order)->paginate($limit); |
||||
|
$row = $list->items(); |
||||
|
$result = array("total" => $list->total(), "rows" => $row); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,152 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\qingdong\attendance; |
||||
|
|
||||
|
use addons\qingdong\model\AttendanceStatisc; |
||||
|
use addons\qingdong\model\Staff; |
||||
|
use app\common\controller\Backend; |
||||
|
use addons\qingdong\model\Attendance; |
||||
|
|
||||
|
/** |
||||
|
* 考勤统计 |
||||
|
*/ |
||||
|
class Statisc extends Backend { |
||||
|
public function _initialize() { |
||||
|
parent::_initialize(); |
||||
|
$this->model = new AttendanceStatisc(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 考勤统计 |
||||
|
*/ |
||||
|
public function index() { |
||||
|
$this->request->filter(['strip_tags']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
//0:全部 1:我的 2:下属的 |
||||
|
$type = input('type',0); |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
$wheres=[]; |
||||
|
switch($type){ |
||||
|
case 1: |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 2: |
||||
|
$wheres['staff_id'] = array('in',Staff::getLowerStaffId()); |
||||
|
break; |
||||
|
default: |
||||
|
$wheres['staff_id'] = array('in',Staff::getMyStaffIds()); |
||||
|
break; |
||||
|
} |
||||
|
$statisc = AttendanceStatisc::where($wheres)->where($where)->select(); |
||||
|
$data = []; |
||||
|
foreach ($statisc as $v) { |
||||
|
$data[$v['staff_id']][$v['time']][] = [ |
||||
|
'clock_in' => $v['clock_in'],//上班打卡 |
||||
|
'leaver_time' => $v['leaver_time'], |
||||
|
'clock_out' => $v['clock_out'], |
||||
|
'late_time' => $v['late_time'],//迟到时间 |
||||
|
'start_time' => $v['start_time'], |
||||
|
'end_time' => $v['end_time'], |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
$staffs = Staff::where(['id' =>$wheres['staff_id']])->column('name', 'id'); |
||||
|
$result=[]; |
||||
|
foreach ($data as $staff_id => $d) { |
||||
|
$leave = 0;//早退 |
||||
|
$leave_time = 0;//早退时间 |
||||
|
$late = 0;//迟到 |
||||
|
$late_time = 0;//迟到时间 |
||||
|
$work = 0;//旷工 |
||||
|
$work_time = 0;//旷工时间 |
||||
|
$card = 0;//缺卡 |
||||
|
$normal = 0;//正常 |
||||
|
$error = 0;//异常 |
||||
|
$overtime=0;//加班 |
||||
|
|
||||
|
foreach ($d as $day => $time) { |
||||
|
$is_normal = 1;//正常 |
||||
|
$is_error = 0;//异常 |
||||
|
foreach ($time as $t) { |
||||
|
if (empty($t['clock_in']) && !empty($t['clock_out'])) {//缺卡 |
||||
|
$card += 1; |
||||
|
} |
||||
|
if (empty($t['clock_out']) && !empty($t['clock_in'])) {//缺卡 |
||||
|
$card += 1; |
||||
|
} |
||||
|
if (empty($t['clock_in']) && empty($t['clock_out'])) { |
||||
|
$work += 1; |
||||
|
$end_time = strtotime(date('Y-m-d ') . $v['end_time']); |
||||
|
$start_time = strtotime(date('Y-m-d ') . $v['start_time']); |
||||
|
$end_time = $end_time > $start_time ? $end_time : $end_time + 86400; |
||||
|
//旷工时长 |
||||
|
$wtime = intval(($end_time - $start_time) / 60); |
||||
|
$work_time += $wtime; |
||||
|
} |
||||
|
if ($t['leaver_time'] > 0) {//早退 |
||||
|
$leave += 1; |
||||
|
$leave_time += $t['leaver_time']; |
||||
|
} |
||||
|
if ($t['late_time'] > 0) {//迟到 |
||||
|
$late += 1; |
||||
|
$late_time += $t['late_time']; |
||||
|
} |
||||
|
|
||||
|
if (empty($t['clock_in']) || empty($t['clock_out']) |
||||
|
|| $t['late_time'] != 0 || $t['leaver_time'] != 0) {//不正常卡 |
||||
|
$is_normal = 0; |
||||
|
$is_error = 1; |
||||
|
} |
||||
|
|
||||
|
//工作日加班 |
||||
|
if ($t['clock_out'] && $leave_time == 0) { |
||||
|
$clock_out = strtotime($t['clock_out']); |
||||
|
$date = date('Y-m-d ', $clock_out); |
||||
|
$end_time = $date . $t['end_time']; |
||||
|
$end_time = strtotime($end_time); |
||||
|
if ($end_time < $clock_out) { |
||||
|
$end_time = $end_time + 86400; |
||||
|
} |
||||
|
$overtime += intval(($end_time - $clock_out) / 60); |
||||
|
} |
||||
|
} |
||||
|
if ($is_normal == 1) { |
||||
|
$normal += 1; |
||||
|
} |
||||
|
if ($is_error == 1) { |
||||
|
$error += 1; |
||||
|
} |
||||
|
} |
||||
|
//外勤 |
||||
|
$month=date('Y-m',strtotime($day)); |
||||
|
$other = Attendance::where(['type' => 1,'staff_id'=>$staff_id, 'time' => ['like', "{$month}%"]])->count(); |
||||
|
|
||||
|
$result[] = [ |
||||
|
'staff'=>$staffs[$staff_id], |
||||
|
'month'=>$month, |
||||
|
'leave' => $leave, |
||||
|
'leave_time' => $leave_time, |
||||
|
'late' => $late, |
||||
|
'late_time' => $late_time, |
||||
|
'work' => $work, |
||||
|
'work_time' => $work_time, |
||||
|
'card' => $card, |
||||
|
'normal' => $normal, |
||||
|
'error' => $error, |
||||
|
'other' => $other, |
||||
|
'overtime' => $overtime]; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
$result = array("total" => count($result), "rows" => $result); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,154 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\qingdong\canlendar; |
||||
|
use addons\qingdong\model\Staff; |
||||
|
use app\admin\controller\qingdong\Base; |
||||
|
use addons\qingdong\model\Event; |
||||
|
use addons\qingdong\model\Customer; |
||||
|
use addons\qingdong\model\Contacts; |
||||
|
use addons\qingdong\model\Contract; |
||||
|
use addons\qingdong\model\Leads; |
||||
|
use think\DB; |
||||
|
use fast\Tree; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 日程 |
||||
|
*/ |
||||
|
class Canlendar extends Base { |
||||
|
public function _initialize() { |
||||
|
parent::_initialize(); |
||||
|
$this->model = new Event(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 日程列表 |
||||
|
*/ |
||||
|
public function index() { |
||||
|
|
||||
|
$this->request->filter(['strip_tags']); |
||||
|
$need = input('need',''); |
||||
|
if ($this->request->isAjax()) { |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
$wheres['type'] =1; |
||||
|
$wheres['staff_id'] = ['in',Staff::getMyStaffIds()]; |
||||
|
if(isset($need) && $need == 'canlendar'){ |
||||
|
$wheres['staff_id'] = $this->_staff->id; |
||||
|
$wheres['status'] = array('in','0,1'); |
||||
|
} |
||||
|
if(isset($need) && $need == 'task'){ |
||||
|
$wheres['staff_id'] = $this->_staff->id; |
||||
|
$wheres['status'] = array('in','0,1'); |
||||
|
$wheres['start_time'] = ['lt', date('Y-m-d', strtotime('+1 day'))]; |
||||
|
} |
||||
|
|
||||
|
$list = $this->model->where($where)->where($wheres)->order($sort, $order)->paginate($limit); |
||||
|
$row = $list->items(); |
||||
|
$result = array("total" => $list->total(), "rows" => $row); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
|
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 添加日程 |
||||
|
*/ |
||||
|
public function add() { |
||||
|
if ($this->request->isAjax()) { |
||||
|
$data = $this->request->post('row/a'); |
||||
|
$staff = Staff::info(); |
||||
|
$data['staff_id'] = $staff->id; |
||||
|
$result = $this->model->save($data); |
||||
|
if (!$result) { |
||||
|
$this->error('提交失败'); |
||||
|
} |
||||
|
$this->success('提交成功'); |
||||
|
} |
||||
|
$customer = Customer::where(['cid'=>CID,'owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select(); |
||||
|
$this->view->assign("customer", $customer); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 修改日程 |
||||
|
*/ |
||||
|
public function edit($ids = null) { |
||||
|
$map['id'] = $ids; |
||||
|
if ($this->request->isAjax()) { |
||||
|
$data = $this->request->post('row/a'); |
||||
|
$result = $this->model->save($data, $map); |
||||
|
|
||||
|
if (!$result) { |
||||
|
$this->error('修改失败'); |
||||
|
} |
||||
|
$this->success('修改成功'); |
||||
|
} |
||||
|
|
||||
|
$data = $this->model->where($map)->find(); |
||||
|
if($data['relation_type'] == 1){ |
||||
|
$customer = Customer::where(['cid'=>CID,'owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select(); |
||||
|
}elseif($data['relation_type'] == 2){ |
||||
|
$customer = Contacts::where(['cid'=>CID,'owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select(); |
||||
|
}elseif($data['relation_type'] == 3){ |
||||
|
$customer = Contract::where(['cid'=>CID,'owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select(); |
||||
|
}elseif($data['relation_type'] == 4){ |
||||
|
$customer = Leads::where(['cid'=>CID,'owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select(); |
||||
|
}else{ |
||||
|
$customer = Customer::where(['cid'=>CID,'owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select(); |
||||
|
} |
||||
|
$this->view->assign("customer", $customer); |
||||
|
$this->view->assign("row", $data); |
||||
|
|
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除日程 |
||||
|
*/ |
||||
|
public function del($ids = null) { |
||||
|
if ($this->request->isAjax()) { |
||||
|
$map['id'] = array('in', $ids); |
||||
|
$result = $this->model->destroy($map); |
||||
|
if (!$result) { |
||||
|
$this->error('删除失败'); |
||||
|
} |
||||
|
$this->success('删除成功'); |
||||
|
} |
||||
|
|
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取客户列表 |
||||
|
*/ |
||||
|
public function customer(){ |
||||
|
$list = Customer::where(['cid'=>CID,'owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select(); |
||||
|
$this->success('','',$list); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取联系人列表 |
||||
|
*/ |
||||
|
public function contacts(){ |
||||
|
$list = Contacts::where(['cid'=>CID,'owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select(); |
||||
|
$this->success('','',$list); |
||||
|
} |
||||
|
/** |
||||
|
* 获取合同列表 |
||||
|
*/ |
||||
|
public function contract(){ |
||||
|
$list = Contract::where(['cid'=>CID,'owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select(); |
||||
|
$this->success('','',$list); |
||||
|
} |
||||
|
/** |
||||
|
* 获取线索列表 |
||||
|
*/ |
||||
|
public function leads(){ |
||||
|
$list = Leads::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select(); |
||||
|
$this->success('','',$list); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,58 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\qingdong\contract; |
||||
|
use addons\qingdong\model\Staff; |
||||
|
use app\admin\controller\qingdong\Base; |
||||
|
use addons\qingdong\model\Comment as CommentModel; |
||||
|
use think\DB; |
||||
|
|
||||
|
/** |
||||
|
* 评论列表 |
||||
|
* 操作文档:https://doc.fastadmin.net/qingdong |
||||
|
* 软件介绍:https://www.fastadmin.net/store/qingdong.html |
||||
|
* 售后微信:qingdong_crm |
||||
|
*/ |
||||
|
class Comment extends Base { |
||||
|
public function _initialize() { |
||||
|
parent::_initialize(); |
||||
|
$this->model = new CommentModel(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 评论列表 |
||||
|
* @return string|\think\response\Json |
||||
|
*/ |
||||
|
public function index() { |
||||
|
$this->request->filter(['strip_tags']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
//0:全部 1:我负责的 2:下属负责的 |
||||
|
$type = input('type',0); |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
switch($type){ |
||||
|
case 1: |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 2: |
||||
|
$wheres['staff_id'] = array('in',Staff::getLowerStaffId()); |
||||
|
break; |
||||
|
default: |
||||
|
$wheres['staff_id'] = array('in',Staff::getMyStaffIds()); |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
$wheres['relation_type'] = 3; |
||||
|
$list = $this->model->where($where)->where($wheres)->with(['staff','record'])->order($sort, $order)->paginate($limit); |
||||
|
$row = $list->items(); |
||||
|
$result = array("total" => $list->total(), "rows" => $row); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
|
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,155 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\qingdong\contract; |
||||
|
use addons\qingdong\model\Contract; |
||||
|
use addons\qingdong\model\Field; |
||||
|
use addons\qingdong\model\File; |
||||
|
use addons\qingdong\model\Staff; |
||||
|
use app\admin\controller\qingdong\Base; |
||||
|
use addons\qingdong\model\Record as RecordModel; |
||||
|
use think\DB; |
||||
|
use think\Exception; |
||||
|
|
||||
|
/** |
||||
|
* 跟进记录 |
||||
|
* 操作文档:https://doc.fastadmin.net/qingdong |
||||
|
* 软件介绍:https://www.fastadmin.net/store/qingdong.html |
||||
|
* 售后微信:qingdong_crm |
||||
|
*/ |
||||
|
class Record extends Base { |
||||
|
public function _initialize() { |
||||
|
parent::_initialize(); |
||||
|
$this->model = new RecordModel(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 跟进列表 |
||||
|
*/ |
||||
|
public function index() { |
||||
|
$this->request->filter(['strip_tags']); |
||||
|
$need = input('need',''); |
||||
|
if ($this->request->isAjax()) { |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
//0:全部 1:我负责的 2:下属负责的 3:今日待跟进 4:今日已跟进 |
||||
|
$type = input('type',0); |
||||
|
switch($type){ |
||||
|
case 1: |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['create_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 2: |
||||
|
$wheres['create_staff_id'] = array('in',Staff::getLowerStaffId()); |
||||
|
break; |
||||
|
case 3: |
||||
|
$start = date('Y-m-d 00:00:00'); |
||||
|
$end = date('Y-m-d 23:59:59'); |
||||
|
$record = collection(RecordModel::where(array('cid'=>CID,'relation_type'=>3,'next_time'=>array(array('egt',$start),array('elt',$end))))->field("id,relation_id")->select())->toArray(); |
||||
|
$relationId = []; |
||||
|
foreach($record as $k=>$v){ |
||||
|
$whereRe['id'] = array('gt',$v['id']); |
||||
|
$whereRe['relation_id'] = $v['relation_id']; |
||||
|
$recordData = RecordModel::where($whereRe)->count(); |
||||
|
if($recordData == 0){ |
||||
|
$relationId[] = $v['id']; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
$wheres['id'] = array('in',$relationId); |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['create_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 4: |
||||
|
$start = date('Y-m-d 00:00:00'); |
||||
|
$end = date('Y-m-d 23:59:59'); |
||||
|
$record = collection(RecordModel::where(array('cid'=>CID,'relation_type'=>3,'next_time'=>array(array('egt',$start),array('elt',$end))))->field("id,relation_id")->select())->toArray(); |
||||
|
$relationId = []; |
||||
|
foreach($record as $k=>$v){ |
||||
|
$whereRe['id'] = array('gt',$v['id']); |
||||
|
$whereRe['relation_id'] = $v['relation_id']; |
||||
|
$recordData = RecordModel::where($whereRe)->count(); |
||||
|
if($recordData >=1){ |
||||
|
$relationId[] = $v['id']; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
$wheres['id'] = array('in',$relationId); |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['create_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
default: |
||||
|
$wheres['create_staff_id'] = array('in',Staff::getMyStaffIds()); |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
$wheres['relation_type'] = 3; |
||||
|
if(isset($need) && $need =='contract'){ |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['create_staff_id'] = $staff->id; |
||||
|
$wheres['status'] = 0; |
||||
|
$wheres['follow_type'] = ['neq', '其它']; |
||||
|
$wheres['next_time'] = array(array('egt',date('Y-m-d 00:00:00')),array('lt',date('Y-m-d 23:59:59'))); |
||||
|
$infolist = $this->model->where($wheres)->column('relation_id'); |
||||
|
if($infolist){ |
||||
|
$whereExit['relation_id'] = array('in',$infolist); |
||||
|
$whereExit['next_time'] = array('gt',date('Y-m-d 23:59:59')); |
||||
|
$recordIds = $this->model->where($whereExit)->column('id'); |
||||
|
if($recordIds){ |
||||
|
$wheres['id'] = array('in',$recordIds); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$list = $this->model->where($where)->where($wheres)->with(['staff','contract'])->order($sort, $order)->paginate($limit); |
||||
|
$row = $list->items(); |
||||
|
$result = array("total" => $list->total(), "rows" => $row); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
|
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加跟进 |
||||
|
*/ |
||||
|
public function add($ids = null) { |
||||
|
$relation_type=input('relation_type',3); |
||||
|
if ($this->request->isPost()) { |
||||
|
$params = $this->request->post('row/a'); |
||||
|
// 表单验证 |
||||
|
if (($result = $this->qingdongValidate($params, 'Record', 'create')) !== true) { |
||||
|
$this->error($result); |
||||
|
} |
||||
|
if(!empty($params['files'])){ |
||||
|
$params['files']=File::getId($params['files']); |
||||
|
} |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
$result = $this->model::createRecord($params); |
||||
|
Db::commit(); |
||||
|
} catch (Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
if ($result) { |
||||
|
$this->success('创建跟进记录成功'); |
||||
|
} |
||||
|
$this->error('创建失败'); |
||||
|
} |
||||
|
|
||||
|
$staff=Staff::where([])->column('name','id'); |
||||
|
if($ids){ |
||||
|
$contracts=Contract::where(['id'=>$ids])->column('id,name'); |
||||
|
}else{ |
||||
|
$contracts=Contract::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->column('id,name'); |
||||
|
} |
||||
|
$follow= Field::getField('客户状态'); |
||||
|
$this->assign('ids', $ids); |
||||
|
$this->assign('relation_type', $relation_type); |
||||
|
$this->assign('contracts', $contracts); |
||||
|
$this->assign('staff', $staff); |
||||
|
$this->assign('follow', $follow); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
File diff suppressed because it is too large
@ -0,0 +1,303 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\qingdong\customer; |
||||
|
|
||||
|
use addons\qingdong\model\ContactsFile; |
||||
|
use addons\qingdong\model\ReceivablesPlan; |
||||
|
use app\admin\controller\qingdong\Base; |
||||
|
use addons\qingdong\model\Staff; |
||||
|
use think\Db; |
||||
|
use think\Exception; |
||||
|
use addons\qingdong\model\Customer; |
||||
|
use addons\qingdong\model\Contacts; |
||||
|
use addons\qingdong\model\Form; |
||||
|
use addons\qingdong\model\CustomerOther; |
||||
|
use addons\qingdong\model\Receivables; |
||||
|
use addons\qingdong\model\Record; |
||||
|
use addons\qingdong\model\Contract; |
||||
|
use addons\qingdong\model\Comment; |
||||
|
use addons\qingdong\model\Consume; |
||||
|
/** |
||||
|
* 客户查重管理 |
||||
|
* 操作文档:https://doc.fastadmin.net/qingdong |
||||
|
* 软件介绍:https://www.fastadmin.net/store/qingdong.html |
||||
|
* 售后微信:qingdong_crm |
||||
|
*/ |
||||
|
class Cnki extends Base |
||||
|
{ |
||||
|
protected $relationSearch = true; |
||||
|
/** |
||||
|
* @var \addons\qingdong\model\Customer |
||||
|
*/ |
||||
|
protected $model = null; |
||||
|
|
||||
|
|
||||
|
public function _initialize() |
||||
|
{ |
||||
|
parent::_initialize(); |
||||
|
$this->model = new \addons\qingdong\model\Customer; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() |
||||
|
{ |
||||
|
//设置过滤方法 |
||||
|
$this->request->filter(['strip_tags', 'trim']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
if ($this->request->request('keyField')) { |
||||
|
return $this->selectpage(); |
||||
|
} |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
$customer_ids_name=Customer::where('cid='.CID.' and name in '.Customer::where(['cid'=>CID])->having('count(*) > 1')->group('name')->field('name')->buildSql(true))->column('id'); |
||||
|
$customer_ids_mobile= Contacts::where('cid='.CID.' and mobile in '. Contacts::where(['cid'=>CID])->having('count(*) > 1')->group('mobile')->where(['mobile'=>['neq','']])->field('mobile')->buildSql(true))->column('customer_id'); |
||||
|
$customer_ids_email = Contacts::where('cid='.CID.' and email in '.Contacts::where(['cid'=>CID])->having('count(*) > 1')->group('email,customer_id')->where(['email'=>['neq','']])->field('email')->buildSql(true))->column('customer_id'); |
||||
|
|
||||
|
$customer_ids=array_merge($customer_ids_name?:[],$customer_ids_mobile?:[],$customer_ids_email?:[]); |
||||
|
$customer_ids=array_values(array_unique($customer_ids)); |
||||
|
$list = $this->model->where($where) |
||||
|
->where(['id'=>['in',$customer_ids]]) |
||||
|
->order($sort, $order)->paginate($limit); |
||||
|
|
||||
|
$rows = $list->items(); |
||||
|
foreach($rows as $k=>$v){ |
||||
|
$contacts = Contacts::where(array('cid'=>CID,'customer_id'=>$v['id']))->select(); |
||||
|
foreach($contacts as $ks=>$vs){ |
||||
|
$emailinfo=''; |
||||
|
$mobileinfo =''; |
||||
|
if($vs['mobile']){ |
||||
|
$mobileinfo = Contacts::where(array('id'=>['neq',$vs['id']],'customer_id'=>$v['id'],'mobile'=>$vs['mobile']))->value('id'); |
||||
|
} |
||||
|
if($vs['email']){ |
||||
|
$emailinfo = Contacts::where(array('id'=>['neq',$vs['id']],'customer_id'=>$v['id'],'email'=>$vs['email']))->value('id'); |
||||
|
} |
||||
|
if($mobileinfo || $emailinfo){ |
||||
|
unset($rows[$k]); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
$result = array("total" => $list->total(), "rows" => array_values($rows)); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
|
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 合并客户 |
||||
|
*/ |
||||
|
public function edit($ids=null) |
||||
|
{ |
||||
|
if ($this->request->isPost()) { |
||||
|
$params = $this->request->post("row/a"); |
||||
|
if ($params) { |
||||
|
|
||||
|
$check = isset($params['check']) ? $params['check'] : ''; |
||||
|
$ids = $params['id']; |
||||
|
$customer_ids = $params['customer_ids']; |
||||
|
unset($params['check']); |
||||
|
unset($params['customer_ids']); |
||||
|
$params = $this->preExcludeFields($params); |
||||
|
$result = false; |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
$params['id'] = $ids; |
||||
|
$result = $this->model::updateCustomer($params); |
||||
|
//合并后删除被合并客户 |
||||
|
$rescustomer = true; |
||||
|
$rescontacts = true; |
||||
|
$resrecord = true; |
||||
|
$rescontract = true; |
||||
|
$resconsume = true; |
||||
|
$resreceivables = true; |
||||
|
$resreceivables_plan = true; |
||||
|
$rescomment = true; |
||||
|
if($check == 1){ |
||||
|
//客户 |
||||
|
$hecustomer = $this->model->where(array('id'=>$customer_ids))->find(); |
||||
|
if($hecustomer){ |
||||
|
$rescustomer = $this->model->where(array('id'=>$customer_ids))->update(array('deletetime'=>time())); |
||||
|
} |
||||
|
//联系人 |
||||
|
$hecontacts =Contacts::where(array('customer_id'=>$customer_ids))->find(); |
||||
|
if($hecontacts){ |
||||
|
$rescontacts = Contacts::where(array('customer_id'=>$customer_ids))->update(array('customer_id'=>$ids,'updatetime'=>time())); |
||||
|
} |
||||
|
//跟进记录 |
||||
|
$herecord = Record::where(array('relation_type'=>1,'relation_id'=>$customer_ids))->find(); |
||||
|
if($herecord){ |
||||
|
$resrecord = Record::where(array('relation_type'=>1,'relation_id'=>$customer_ids))->update(array('relation_id'=>$ids,'updatetime'=>time())); |
||||
|
} |
||||
|
//合同 |
||||
|
$hecontract=Contract::where(array('customer_id'=>$customer_ids))->find(); |
||||
|
if($hecontract){ |
||||
|
$rescontract=Contract::where(array('customer_id'=>$customer_ids))->update(array('customer_id'=>$ids,'updatetime'=>time())); |
||||
|
} |
||||
|
//费用 |
||||
|
$heconsume = Consume::where(array('customer_id'=>$customer_ids))->find(); |
||||
|
if($heconsume){ |
||||
|
$resconsume = Consume::where(array('customer_id'=>$customer_ids))->update(array('customer_id'=>$ids,'updatetime'=>time())); |
||||
|
} |
||||
|
//回款 |
||||
|
$hereceivables = Receivables::where(array('customer_id'=>$customer_ids))->find(); |
||||
|
if($hereceivables){ |
||||
|
$resreceivables = Receivables::where(array('customer_id'=>$customer_ids))->update(array('customer_id'=>$ids,'updatetime'=>time())); |
||||
|
} |
||||
|
//回款计划 |
||||
|
$hereceivables_plan = ReceivablesPlan::where(array('customer_id'=>$customer_ids))->find(); |
||||
|
if($hereceivables_plan){ |
||||
|
$resreceivables_plan = ReceivablesPlan::where(array('customer_id'=>$customer_ids))->update(array('customer_id'=>$ids,'updatetime'=>time())); |
||||
|
} |
||||
|
//评论 |
||||
|
$hecomment = Comment::where(array('relation_type'=>1,'relation_id'=>$customer_ids))->find(); |
||||
|
if($hecomment){ |
||||
|
$rescomment = Comment::where(array('relation_type'=>1,'relation_id'=>$customer_ids))->update(array('relation_id'=>$ids,'updatetime'=>time())); |
||||
|
|
||||
|
} |
||||
|
if(!$rescustomer || !$rescontacts || !$resrecord || !$rescontract || !$resconsume || !$resreceivables || !$resreceivables_plan || !$rescomment){ |
||||
|
$result = false; |
||||
|
throw new Exception('合并失败'); |
||||
|
} |
||||
|
}else{ |
||||
|
//联系人 |
||||
|
$hecontacts = collection(Contacts::where(array('cid'=>CID,'customer_id'=>$customer_ids))->select())->toArray(); |
||||
|
foreach($hecontacts as $k=>$v){ |
||||
|
unset($v['id']); |
||||
|
$mobileinfo = Contacts::where(array('customer_id'=>$customer_ids,'mobile'=>$v['mobile']))->value('id'); |
||||
|
$emailinfo = Contacts::where(array('customer_id'=>$customer_ids,'email'=>$v['email']))->value('id'); |
||||
|
if($emailinfo){ |
||||
|
$v['email'] = ''; |
||||
|
} |
||||
|
if(($mobileinfo && $emailinfo) || $mobileinfo){ |
||||
|
continue; |
||||
|
} |
||||
|
$v['customer_id'] = $ids; |
||||
|
$rescontacts = Contacts::create($v); |
||||
|
} |
||||
|
|
||||
|
//跟进记录 |
||||
|
$herecords = collection(Record::where(array('relation_type'=>1,'relation_id'=>$customer_ids))->select())->toArray(); |
||||
|
foreach($herecords as $k=>$vs){ |
||||
|
unset($vs['id']); |
||||
|
$vs['relation_id'] = $ids; |
||||
|
$resrecord = Record::create($vs); |
||||
|
} |
||||
|
//合同 |
||||
|
$hecontract=collection(Contract::where(array('customer_id'=>$customer_ids))->select())->toArray(); |
||||
|
foreach($hecontract as $k=>$v){ |
||||
|
unset($v['id']); |
||||
|
$v['customer_id'] = $ids; |
||||
|
$rescontract = Contract::create($v); |
||||
|
} |
||||
|
//费用 |
||||
|
$heconsume = collection(Consume::where(array('customer_id'=>$customer_ids))->select())->toArray(); |
||||
|
foreach($heconsume as $k=>$v){ |
||||
|
unset($v['id']); |
||||
|
$v['customer_id'] = $ids; |
||||
|
$resconsume = Consume::create($v); |
||||
|
} |
||||
|
//回款 |
||||
|
$hereceivables = collection(Receivables::where(array('customer_id'=>$customer_ids))->select())->toArray(); |
||||
|
foreach($hereceivables as $k=>$v){ |
||||
|
unset($v['id']); |
||||
|
$v['customer_id'] = $ids; |
||||
|
$resreceivables = Receivables::create($v); |
||||
|
} |
||||
|
//回款计划 |
||||
|
$hereceivables_plan = collection(ReceivablesPlan::where(array('customer_id'=>$customer_ids))->select())->toArray(); |
||||
|
foreach($hereceivables_plan as $k=>$v){ |
||||
|
unset($v['id']); |
||||
|
$v['customer_id'] = $ids; |
||||
|
$resreceivables_plan = ReceivablesPlan::create($v); |
||||
|
} |
||||
|
//评论 |
||||
|
$hecomment = collection(Comment::where(array('relation_type'=>1,'relation_id'=>$customer_ids))->select())->toArray(); |
||||
|
foreach($hecomment as $k=>$v){ |
||||
|
unset($v['id']); |
||||
|
$v['relation_id'] = $ids; |
||||
|
$rescomment = Comment::create($v); |
||||
|
} |
||||
|
|
||||
|
if(!$rescontacts || !$resrecord || !$rescontract || !$resconsume || !$resreceivables || !$resreceivables_plan || !$rescomment){ |
||||
|
$result = false; |
||||
|
throw new Exception('合并失败'); |
||||
|
} |
||||
|
} |
||||
|
Db::commit(); |
||||
|
} catch (Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
if ($result !== false) { |
||||
|
$this->success(); |
||||
|
} else { |
||||
|
$this->error('合并失败'); |
||||
|
} |
||||
|
} |
||||
|
$this->error('参数不能为空'); |
||||
|
} |
||||
|
//客户 |
||||
|
$row = Customer::where(array('id'=>$ids))->find(); |
||||
|
if(!$row){ |
||||
|
$this->error('客户不存在'); |
||||
|
} |
||||
|
$row=$row->toArray(); |
||||
|
$row = CustomerOther::getOther($row); |
||||
|
$fieldlist = Form::getDataValue('customer'); |
||||
|
|
||||
|
//被合并客户信息 |
||||
|
$customer_ids = Customer::where(array('name'=>$row['name'],'id'=>['neq',$ids]))->value('id'); |
||||
|
if(!$customer_ids){ |
||||
|
//手机号 |
||||
|
$wheres['customer_id'] = array('neq',$ids); |
||||
|
$customer_ids_mobile = Contacts::where(array('customer_id'=>$ids))->field('mobile')->group('mobile')->column('mobile'); |
||||
|
if($customer_ids_mobile){ |
||||
|
$customer_ids_mobile = Contacts::where($wheres)->where('mobile', 'in', $customer_ids_mobile)->value('customer_id'); |
||||
|
if($customer_ids_mobile){ |
||||
|
$customer_ids = $customer_ids_mobile; |
||||
|
} |
||||
|
} |
||||
|
$customer_ids_email = Contacts::where(array('customer_id'=>$ids))->field('email')->group('email')->column('email'); |
||||
|
if($customer_ids_email){ |
||||
|
$customer_ids_email = Contacts::where($wheres)->where('email', 'in', $customer_ids_mobile)->value('customer_id'); |
||||
|
if($customer_ids_email){ |
||||
|
$customer_ids = $customer_ids_email; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
if(!$customer_ids){ |
||||
|
$this->error('被合并客户不存在'); |
||||
|
} |
||||
|
$rowinfo = Customer::where(array('id' => $customer_ids))->find(); |
||||
|
$rowinfo = $rowinfo->toArray(); |
||||
|
$rowinfo = CustomerOther::getOther($rowinfo); |
||||
|
$hecustomer = $fieldlist; |
||||
|
$hecustomerInfo = []; |
||||
|
foreach($hecustomer as $k=>$v){ |
||||
|
$hecustomerInfo[$v['id']] = $v; |
||||
|
$hecustomerInfo[$v['id']]['value']= $rowinfo[$v['id']]??''; |
||||
|
} |
||||
|
|
||||
|
$zucustomer = $fieldlist; |
||||
|
//主客户信息 |
||||
|
foreach($zucustomer as $k=>$v){ |
||||
|
$zucustomer[$k]['value']= $row[$v['id']]??''; |
||||
|
|
||||
|
if(key_exists($v['id'],$hecustomerInfo)){ |
||||
|
$zucustomer[$k]['chilend'] = $hecustomerInfo[$v['id']];; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$check = array('1'=>'合并后删除被合并客户'); |
||||
|
$this->assign('check',$check); |
||||
|
$this->assign('form_data', $zucustomer); |
||||
|
$this->assign('ids',$ids); |
||||
|
$this->assign('customer_ids',$customer_ids); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,98 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\qingdong\customer; |
||||
|
use addons\qingdong\model\Staff; |
||||
|
use app\admin\controller\qingdong\Base; |
||||
|
use addons\qingdong\model\Comment as CommentModel; |
||||
|
use addons\qingdong\model\Record; |
||||
|
use addons\qingdong\model\Message; |
||||
|
use think\DB; |
||||
|
use function EasyWeChat\Kernel\Support\get_client_ip; |
||||
|
/** |
||||
|
* 客户评论 |
||||
|
*/ |
||||
|
class Comment extends Base { |
||||
|
public function _initialize() { |
||||
|
parent::_initialize(); |
||||
|
$this->model = new CommentModel(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 评论列表 |
||||
|
*/ |
||||
|
public function index() { |
||||
|
$this->request->filter(['strip_tags']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
//0:全部 1:我负责的 2:下属负责的 |
||||
|
$type = input('type',0); |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
switch($type){ |
||||
|
case 1: |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 2: |
||||
|
$wheres['staff_id'] = array('in',Staff::getLowerStaffId()); |
||||
|
break; |
||||
|
default: |
||||
|
$wheres['staff_id'] = array('in',Staff::getMyStaffIds()); |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
$wheres['relation_type'] = 1; |
||||
|
$list = $this->model->where($where)->where($wheres)->with(['staff','record'])->order($sort, $order)->paginate($limit); |
||||
|
$row = $list->items(); |
||||
|
$result = array("total" => $list->total(), "rows" => $row); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
|
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加评论 |
||||
|
* @param null $ids |
||||
|
* @return string |
||||
|
* @throws \think\Exception |
||||
|
* @throws \think\exception\DbException |
||||
|
*/ |
||||
|
public function add($ids=null) { |
||||
|
if ($this->request->isPost()) { |
||||
|
$content = input('content'); |
||||
|
if (empty($content)) { |
||||
|
$this->error('评论内容不能为空'); |
||||
|
} |
||||
|
$record = Record::get($ids); |
||||
|
$data = [ |
||||
|
'relation_type' => $record['relation_type'], |
||||
|
'relation_id' => $ids, |
||||
|
'staff_id' => $this->_staff->id, |
||||
|
'content' => $content, |
||||
|
'status' => 1, |
||||
|
'ip' => get_client_ip(), |
||||
|
]; |
||||
|
|
||||
|
|
||||
|
$commentModel = new CommentModel(); |
||||
|
$commentModel->save($data); |
||||
|
|
||||
|
|
||||
|
Message::addMessage(Message::COMMENT_TYPE, $ids, $record['create_staff_id'], $this->_staff->id); |
||||
|
|
||||
|
$staff_ids = $commentModel->where(['relation_type' => $record['relation_type'], 'relation_id' => $ids])->group('staff_id')->column('staff_id'); |
||||
|
foreach ($staff_ids as $staff_id) { |
||||
|
//发送通知 |
||||
|
if ($staff_id != $this->_staff->id) { |
||||
|
Message::addMessage(Message::COMMENT_TYPE, $ids, $staff_id, $this->_staff->id); |
||||
|
} |
||||
|
} |
||||
|
$this->success('评论成功'); |
||||
|
} |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,220 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\qingdong\customer; |
||||
|
|
||||
|
use addons\qingdong\model\ExamineRecord; |
||||
|
use addons\qingdong\model\File; |
||||
|
use addons\qingdong\model\Flow; |
||||
|
use addons\qingdong\model\Message; |
||||
|
use addons\qingdong\model\Staff; |
||||
|
use app\admin\controller\qingdong\Base; |
||||
|
use addons\qingdong\model\ContractOther; |
||||
|
use addons\qingdong\model\Form; |
||||
|
use addons\qingdong\model\Contacts; |
||||
|
use addons\qingdong\model\Customer; |
||||
|
use addons\qingdong\model\OperationLog; |
||||
|
use addons\qingdong\model\Record; |
||||
|
use addons\qingdong\model\ContractFile; |
||||
|
use think\Db; |
||||
|
use think\Exception; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 费用管理 |
||||
|
* 操作文档:https://doc.fastadmin.net/qingdong |
||||
|
* 软件介绍:https://www.fastadmin.net/store/qingdong.html |
||||
|
* 售后微信:qingdong_crm |
||||
|
*/ |
||||
|
class Consume extends Base { |
||||
|
protected $relationSearch = true; |
||||
|
/** |
||||
|
* @var \addons\qingdong\model\Consume |
||||
|
*/ |
||||
|
protected $model = null; |
||||
|
|
||||
|
|
||||
|
public function _initialize() { |
||||
|
parent::_initialize(); |
||||
|
$this->model = new \addons\qingdong\model\Consume; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() { |
||||
|
//设置过滤方法 |
||||
|
$this->request->filter(['strip_tags', 'trim']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
if ($this->request->request('keyField')) { |
||||
|
return $this->selectpage(); |
||||
|
} |
||||
|
//0:全部 1:我负责的 2:下属负责的 |
||||
|
$type = input('type',0); |
||||
|
switch($type){ |
||||
|
case 1: |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 2: |
||||
|
$wheres['staff_id'] = array('in',Staff::getLowerStaffId()); |
||||
|
break; |
||||
|
default: |
||||
|
$wheres['staff_id'] = array('in',Staff::getMyStaffIds()); |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
|
||||
|
$list = $this->model->where($where)->where($wheres)->with(['customer','staff'])->order($sort, $order)->paginate($limit); |
||||
|
|
||||
|
$result = array("total" => $list->total(), "rows" => $list->items()); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
|
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 添加 |
||||
|
*/ |
||||
|
public function add() |
||||
|
{ |
||||
|
if ($this->request->isPost()) { |
||||
|
$params = $this->request->post("row/a"); |
||||
|
if ($params) { |
||||
|
$params = $this->preExcludeFields($params); |
||||
|
// 表单验证 |
||||
|
if (($result = $this->qingdongValidate($params, 'Consume', 'create')) !== true) { |
||||
|
$this->error($result); |
||||
|
} |
||||
|
$result = false; |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
if(!empty($params['file_ids'])){ |
||||
|
$params['file_ids']=File::getId($params['file_ids']); |
||||
|
} |
||||
|
$result = $this->model::createConsume($params); |
||||
|
Db::commit(); |
||||
|
} catch (Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
if ($result !== false) { |
||||
|
$this->success('添加成功'); |
||||
|
} else { |
||||
|
$this->error(__('No rows were inserted')); |
||||
|
} |
||||
|
} |
||||
|
$this->error(__('Parameter %s can not be empty', '')); |
||||
|
} |
||||
|
$flow= Flow::getsteplist(Flow::CONSUME_STATUS); |
||||
|
if (empty($flow)) { |
||||
|
$this->error('无可用审批流,请联系管理员','qingdong/work/flow'); |
||||
|
} |
||||
|
$customer_id=input('customer_id',null); |
||||
|
|
||||
|
$this->assign('customer_id',$customer_id); |
||||
|
$this->assign('customer',Customer::get($customer_id)); |
||||
|
$this->assign('flow',$flow); |
||||
|
$this->assign('staff', Staff::getStaff()); |
||||
|
|
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 修改费用 |
||||
|
*/ |
||||
|
public function edit($ids = null) { |
||||
|
$map['id'] = $ids; |
||||
|
if ($this->request->isAjax()) { |
||||
|
$params = $this->request->post('row/a'); |
||||
|
$params = $this->preExcludeFields($params); |
||||
|
$row = $this->model::where(['id' => $ids, 'check_status' => ['in', [0,1,3, 4,5]]])->find(); |
||||
|
if (empty($row)) { |
||||
|
$this->error('审核通过的费用不可编辑'); |
||||
|
} |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
$params['id'] = $ids; |
||||
|
if(!empty($params['file_ids'])){ |
||||
|
$params['file_ids']=File::getId($params['file_ids']); |
||||
|
} |
||||
|
$result = $this->model::updateConsume($params); |
||||
|
Db::commit(); |
||||
|
} catch (Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
if ($result !== false) { |
||||
|
$this->success('修改成功'); |
||||
|
} else { |
||||
|
$this->error('修改失败'); |
||||
|
} |
||||
|
} |
||||
|
$row = $this->model->where($map)->with(['customer'])->find(); |
||||
|
$customers=Customer::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->column('name','id'); |
||||
|
if($row['file_ids']){ |
||||
|
$wheres['id']=array('in',$row['file_ids']); |
||||
|
$file = File::where($wheres)->column('file_path'); |
||||
|
$row['file_ids'] = implode(',',$file); |
||||
|
} |
||||
|
$flow= Flow::getsteplist(Flow::CONSUME_STATUS); |
||||
|
if (empty($flow)) { |
||||
|
$this->error('无可用审批流,请联系管理员','qingdong/work/flow'); |
||||
|
} |
||||
|
$this->assign('flow',$flow); |
||||
|
|
||||
|
$this->view->assign("row", $row); |
||||
|
$this->assign('customer', $customers); |
||||
|
$this->assign('staff', Staff::getStaff()); |
||||
|
$this->assign('form_data', Form::getDataValue('contract')); |
||||
|
|
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 费用详情 |
||||
|
*/ |
||||
|
public function detail($ids = null) |
||||
|
{ |
||||
|
$row = $this->model->with(['staff','customer', 'followStaff'])->where([ |
||||
|
'id' => $ids, |
||||
|
])->find(); |
||||
|
if (empty($row)) { |
||||
|
$this->error(__('No Results were found')); |
||||
|
} |
||||
|
|
||||
|
$this->assign('flow',Flow::getstepdetail(Flow::CONSUME_STATUS,$ids)); |
||||
|
//标记通知已读 |
||||
|
Message::setRead(Message::CONSUME_TYPE, $ids, $this->_staff->id); |
||||
|
//审批记录 |
||||
|
$this->assign('examine_record', ExamineRecord::getList(ExamineRecord::CONSUME_TYPE,$ids)); |
||||
|
$this->assign('row', $row); |
||||
|
$this->assign('ids', $ids); |
||||
|
|
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
/** |
||||
|
* 删除 |
||||
|
*/ |
||||
|
public function del($ids = "") { |
||||
|
if (!$this->request->isPost()) { |
||||
|
$this->error(__("Invalid parameters")); |
||||
|
} |
||||
|
$ids = $ids ? $ids : $this->request->post("ids"); |
||||
|
$row = $this->model::where(['id' => $ids, 'check_status' => ['in', [0,1,3, 4,5]]])->find(); |
||||
|
if (empty($row)) { |
||||
|
$this->error('审核通过的费用不可删除'); |
||||
|
} |
||||
|
$row = $this->model->get($ids); |
||||
|
$this->modelValidate = true; |
||||
|
if (!$row) { |
||||
|
$this->error(__('No Results were found')); |
||||
|
} |
||||
|
$row->delete(); |
||||
|
$this->success(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,640 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\qingdong\customer; |
||||
|
|
||||
|
use addons\qingdong\model\AdminConfig; |
||||
|
use addons\qingdong\model\File; |
||||
|
use addons\qingdong\model\FormField; |
||||
|
use addons\qingdong\model\Staff; |
||||
|
use app\admin\controller\qingdong\Base; |
||||
|
use addons\qingdong\model\ContactsOther; |
||||
|
use addons\qingdong\model\Form; |
||||
|
use addons\qingdong\model\OperationLog; |
||||
|
use addons\qingdong\model\Record; |
||||
|
use addons\qingdong\model\Customer; |
||||
|
use PhpOffice\PhpSpreadsheet\Cell\Coordinate; |
||||
|
use PhpOffice\PhpSpreadsheet\Reader\Csv; |
||||
|
use PhpOffice\PhpSpreadsheet\Reader\Xls; |
||||
|
use PhpOffice\PhpSpreadsheet\Reader\Xlsx; |
||||
|
use PhpOffice\PhpSpreadsheet\RichText\RichText; |
||||
|
use think\Db; |
||||
|
use think\Exception; |
||||
|
use app\admin\controller\qingdong\synchronizate\Ku; |
||||
|
|
||||
|
/** |
||||
|
* 联系人管理 |
||||
|
* 操作文档:https://doc.fastadmin.net/qingdong |
||||
|
* 软件介绍:https://www.fastadmin.net/store/qingdong.html |
||||
|
* 售后微信:qingdong_crm |
||||
|
*/ |
||||
|
class Contacts extends Base { |
||||
|
protected $relationSearch = true; |
||||
|
protected $searchFields = 'id,username,nickname'; |
||||
|
/** |
||||
|
* @var \addons\qingdong\model\Contacts |
||||
|
*/ |
||||
|
protected $model = null; |
||||
|
|
||||
|
|
||||
|
public function _initialize() { |
||||
|
parent::_initialize(); |
||||
|
$this->model = new \addons\qingdong\model\Contacts; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() { |
||||
|
//设置过滤方法 |
||||
|
$this->request->filter(['strip_tags', 'trim']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
//如果发送的来源是Selectpage,则转发到Selectpage |
||||
|
if ($this->request->request('keyField')) { |
||||
|
return $this->selectpage(); |
||||
|
} |
||||
|
//0:全部 1:我负责的 2:下属负责的 3:今日待跟进 4:今日已跟进 5:从未跟进的 |
||||
|
$type = input('type',0); |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
switch($type){ |
||||
|
case 1: |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['owner_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 2: |
||||
|
$wheres['owner_staff_id'] = array('in',Staff::getLowerStaffId()); |
||||
|
break; |
||||
|
case 3: |
||||
|
$start = date('Y-m-d 00:00:00'); |
||||
|
$end = date('Y-m-d 23:59:59'); |
||||
|
$record = collection(Record::where(array('relation_type'=>2,'next_time'=>array(array('egt',$start),array('elt',$end))))->field("id,relation_id")->select())->toArray(); |
||||
|
$relationId = []; |
||||
|
foreach($record as $k=>$v){ |
||||
|
$whereRe['id'] = array('gt',$v['id']); |
||||
|
$whereRe['relation_id'] = $v['relation_id']; |
||||
|
$recordData = Record::where($whereRe)->count(); |
||||
|
if($recordData == 0){ |
||||
|
$relationId[] = $v['relation_id']; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
$wheres['id'] = array('in',$relationId); |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['owner_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 4: |
||||
|
$start = date('Y-m-d 00:00:00'); |
||||
|
$end = date('Y-m-d 23:59:59'); |
||||
|
$record = collection(Record::where(array('relation_type'=>2,'next_time'=>array(array('egt',$start),array('elt',$end))))->field("id,relation_id")->select())->toArray(); |
||||
|
$relationId = []; |
||||
|
foreach($record as $k=>$v){ |
||||
|
$whereRe['id'] = array('gt',$v['id']); |
||||
|
$whereRe['relation_id'] = $v['relation_id']; |
||||
|
$recordData = Record::where($whereRe)->count(); |
||||
|
if($recordData >=1){ |
||||
|
$relationId[] = $v['relation_id']; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
$wheres['id'] = array('in',$relationId); |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['owner_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 5: |
||||
|
$record = collection(Record::where(array('relation_type'=>2,'next_time'=>array('neq','')))->column('relation_id'))->toArray(); |
||||
|
$wheres['id'] = array('not in',$record); |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['owner_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
default: |
||||
|
$wheres['owner_staff_id'] = array('in',Staff::getMyStaffIds()); |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
$list = $this->model->with(['ownerStaff']) |
||||
|
->where($wheres) |
||||
|
->where($where)->with(['customer'])->order($sort, $order)->paginate($limit); |
||||
|
|
||||
|
$result = array("total" => $list->total(), "rows" => $list->items()); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
|
||||
|
$field = FormField::getFields(FormField::CONTACTS_TYPE); |
||||
|
$this->assignconfig('fields', $field); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 添加 |
||||
|
*/ |
||||
|
public function add() { |
||||
|
if ($this->request->isPost()) { |
||||
|
$params = $this->request->post("row/a"); |
||||
|
if ($params) { |
||||
|
$params = $this->preExcludeFields($params); |
||||
|
// 表单验证 |
||||
|
if (($result = $this->qingdongValidate($params, 'Contacts', 'create')) !== true) { |
||||
|
$this->error($result); |
||||
|
} |
||||
|
|
||||
|
$result = FormField::checkFields(FormField::CONTACTS_TYPE, $params); |
||||
|
if ($result !== true) { |
||||
|
$this->error($result); |
||||
|
} |
||||
|
$result = false; |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
$is_linkman=AdminConfig::getConfigValue('is_linkman',AdminConfig::TYPE_SEAS); |
||||
|
//联系人手机号是否允许重复 |
||||
|
if($is_linkman == 1){//不同客户的联系人是否允许重复 |
||||
|
$contactsFind = $this->model->where(array('customer_id'=>$params['customer_id'],'mobile'=>$params['mobile']))->find(); |
||||
|
if($contactsFind){ |
||||
|
throw new Exception('手机号已存在'); |
||||
|
} |
||||
|
}else{ |
||||
|
$contactsFind = $this->model->where(array('mobile'=>$params['mobile']))->find(); |
||||
|
if($contactsFind){ |
||||
|
throw new Exception('手机号已存在'); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if(isset($params['email'])){ |
||||
|
$contactsFind = $this->model->where(array('customer_id'=>$params['customer_id'],'email'=>$params['email']))->find(); |
||||
|
if($contactsFind){ |
||||
|
throw new Exception('邮箱已存在'); |
||||
|
} |
||||
|
} |
||||
|
$params = Form::updateFormParams(Form::CONTACTS_TYPE, $params); |
||||
|
|
||||
|
$result = $this->model::createContacts($params); |
||||
|
Db::commit(); |
||||
|
} catch (Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
if ($result !== false) { |
||||
|
$this->success(); |
||||
|
} else { |
||||
|
$this->error(__('No rows were inserted')); |
||||
|
} |
||||
|
} |
||||
|
$this->error(__('Parameter %s can not be empty', '')); |
||||
|
} |
||||
|
$staffs = Customer::getList(); |
||||
|
$customer_id=input('customer_id'); |
||||
|
$customer= Customer::get($customer_id); |
||||
|
|
||||
|
$this->assign('staffs', $staffs); |
||||
|
$this->assign('customer_id', input('customer_id')); |
||||
|
$this->assign('customer', $customer); |
||||
|
$this->assign('form_data', Form::getDataValue(Form::CONTACTS_TYPE)); |
||||
|
|
||||
|
|
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 修改 |
||||
|
*/ |
||||
|
public function edit($ids = null) { |
||||
|
$row = $this->model->get($ids); |
||||
|
if ($this->request->isPost()) { |
||||
|
$params = $this->request->post("row/a"); |
||||
|
if ($params) { |
||||
|
$params = $this->preExcludeFields($params); |
||||
|
// 表单验证 |
||||
|
if (($result = $this->qingdongValidate($params, 'Contacts', 'create')) !== true) { |
||||
|
$this->error($result); |
||||
|
} |
||||
|
$result = FormField::checkFields(FormField::CONTACTS_TYPE, $params,$ids); |
||||
|
if ($result !== true) { |
||||
|
$this->error($result); |
||||
|
} |
||||
|
$result = false; |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
$is_linkman=AdminConfig::getConfigValue('is_linkman',AdminConfig::TYPE_SEAS); |
||||
|
if($is_linkman == 1){//不同客户的联系人是否允许重复 |
||||
|
$contactsFind = $this->model->where(array('id'=>['neq',$row['id']],'customer_id'=>$row['customer_id'],'mobile'=>$params['mobile']))->find(); |
||||
|
if($contactsFind){ |
||||
|
throw new Exception('手机号已存在'); |
||||
|
} |
||||
|
}else{ |
||||
|
$contactsFind = $this->model->where(array('id'=>['neq',$row['id']],'mobile'=>$params['mobile']))->find(); |
||||
|
if($contactsFind){ |
||||
|
throw new Exception('手机号已存在'); |
||||
|
} |
||||
|
} |
||||
|
if(isset($params['email'])){ |
||||
|
$contactsFind = $this->model->where(array('id'=>['neq',$row['id']],'customer_id'=>$row['customer_id'],'email'=>$params['email']))->find(); |
||||
|
if($contactsFind){ |
||||
|
throw new Exception('邮箱已存在'); |
||||
|
} |
||||
|
} |
||||
|
$params = Form::updateFormParams(Form::CONTACTS_TYPE, $params); |
||||
|
|
||||
|
$params['id']=$ids; |
||||
|
$result = $row::updateContacts($params); |
||||
|
Db::commit(); |
||||
|
} catch (Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
if ($result !== false) { |
||||
|
$this->success(); |
||||
|
} else { |
||||
|
$this->error(__('No rows were inserted')); |
||||
|
} |
||||
|
} |
||||
|
$this->error(__('Parameter %s can not be empty', '')); |
||||
|
} |
||||
|
$staffs = \addons\qingdong\model\Customer::getList(); |
||||
|
$this->assign('staffs', $staffs); |
||||
|
|
||||
|
$row=$row->toArray(); |
||||
|
$row=ContactsOther::getOther($row); |
||||
|
$this->assign('form_data', Form::getDataValue(Form::CONTACTS_TYPE,$row)); |
||||
|
$this->assign('row', $row); |
||||
|
|
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 联系人详情 |
||||
|
*/ |
||||
|
public function detail($ids = null) { |
||||
|
$row = $this->model->with(['customer'])->where(['id' => $ids])->find(); |
||||
|
if(empty($row)){ |
||||
|
$this->error('信息不存在'); |
||||
|
} |
||||
|
//跟进记录 |
||||
|
$this->assign('records', Record::getList(Record::CONTACTS_TYPE, $ids)); |
||||
|
//操作记录 |
||||
|
$this->assign('operation_log', OperationLog::getList(OperationLog::CONTACTS_TYPE, $ids)); |
||||
|
$row=$row->toArray(); |
||||
|
$row=ContactsOther::getOther($row); |
||||
|
|
||||
|
$this->assign('form_data', Form::getDataValue(Form::CONTACTS_TYPE,$row)); |
||||
|
$this->assign('row', $row); |
||||
|
$this->assign('ids', $ids); |
||||
|
$this->assignconfig("idinfo", ['id' => $ids]); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 获取附件记录 |
||||
|
*/ |
||||
|
public function get_file($ids = null) { |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
$list = \addons\qingdong\model\ContactsFile::where(['contacts_id' => $ids])->with(['file'])->field('file_id')->paginate($limit); |
||||
|
|
||||
|
$result = array("total" => $list->total(), "rows" => $list->items()); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
*/ |
||||
|
public function del($ids = "") { |
||||
|
if (!$this->request->isPost()) { |
||||
|
$this->error(__("Invalid parameters")); |
||||
|
} |
||||
|
$ids = $ids ? $ids : $this->request->post("ids"); |
||||
|
$row = $this->model->get($ids); |
||||
|
$this->modelValidate = true; |
||||
|
if (!$row) { |
||||
|
$this->error(__('No Results were found')); |
||||
|
} |
||||
|
$map['id'] = $ids; |
||||
|
$result = $this->model->destroy($map); |
||||
|
if (!$result) { |
||||
|
$this->error('删除失败'); |
||||
|
} |
||||
|
$this->success(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 导入客户 |
||||
|
* @return string|void |
||||
|
*/ |
||||
|
public function import() |
||||
|
{ |
||||
|
set_time_limit(0); |
||||
|
if ($this->request->isPost()) { |
||||
|
|
||||
|
$file = $this->request->request('file'); |
||||
|
if (!$file) { |
||||
|
$this->error(__('Parameter %s can not be empty', 'file')); |
||||
|
} |
||||
|
$filePath = ROOT_PATH . 'public' . $file; |
||||
|
if (!is_file($filePath)) { |
||||
|
$this->error(__('No results were found')); |
||||
|
} |
||||
|
//实例化reader |
||||
|
$ext = pathinfo($filePath, PATHINFO_EXTENSION); |
||||
|
if (!in_array($ext, ['csv', 'xls', 'xlsx'])) { |
||||
|
$this->error(__('Unknown data format')); |
||||
|
} |
||||
|
if ($ext === 'csv') { |
||||
|
$file = fopen($filePath, 'r'); |
||||
|
$filePath = tempnam(sys_get_temp_dir(), 'import_csv'); |
||||
|
$fp = fopen($filePath, "w"); |
||||
|
$n = 0; |
||||
|
while ($line = fgets($file)) { |
||||
|
$line = rtrim($line, "\n\r\0"); |
||||
|
$encoding = mb_detect_encoding($line, ['utf-8', 'gbk', 'latin1', 'big5']); |
||||
|
if ($encoding != 'utf-8') { |
||||
|
$line = mb_convert_encoding($line, 'utf-8', $encoding); |
||||
|
} |
||||
|
if ($n == 0 || preg_match('/^".*"$/', $line)) { |
||||
|
fwrite($fp, $line . "\n"); |
||||
|
} else { |
||||
|
fwrite($fp, '"' . str_replace(['"', ','], ['""', '","'], $line) . "\"\n"); |
||||
|
} |
||||
|
$n++; |
||||
|
} |
||||
|
fclose($file) || fclose($fp); |
||||
|
|
||||
|
$reader = new Csv(); |
||||
|
} elseif ($ext === 'xls') { |
||||
|
$reader = new Xls(); |
||||
|
} else { |
||||
|
$reader = new Xlsx(); |
||||
|
} |
||||
|
if (!$PHPExcel = $reader->load($filePath)) { |
||||
|
$this->error(__('Unknown data format')); |
||||
|
} |
||||
|
$currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表 |
||||
|
|
||||
|
$allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号 |
||||
|
$allRow = $currentSheet->getHighestRow(); //取得一共有多少行 |
||||
|
|
||||
|
$maxColumnNumber = Coordinate::columnIndexFromString($allColumn); |
||||
|
//开始读取数据 |
||||
|
$fields = []; |
||||
|
for ($currentRow = 1; $currentRow <= 1; $currentRow++) { |
||||
|
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) { |
||||
|
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue(); |
||||
|
$fields[$currentRow][] = $val; |
||||
|
if ($val instanceof RichText) {//富文本转换字符串 |
||||
|
$val = $val->__toString(); |
||||
|
} |
||||
|
$values[] = is_null($val) ? '' : trim($val); |
||||
|
} |
||||
|
} |
||||
|
if (!isset($fields[1])) { |
||||
|
$this->error('导入文件第一行没有数据'); |
||||
|
} |
||||
|
$lastid = $this->model->withTrashed()->order('id desc')->value('id'); |
||||
|
|
||||
|
$lastid = $lastid + 5;//防止重复 |
||||
|
|
||||
|
$contactsRow = []; |
||||
|
$errorInfo = []; |
||||
|
|
||||
|
$fieldnames = FormField::where(['types' => FormField::CONTACTS_TYPE])->column('field', 'name'); |
||||
|
if(!$fieldnames){ |
||||
|
$this->error('请在系统管理->字段管理中保存联系人管理表单生成联系人导入字段'); |
||||
|
} |
||||
|
$customerNames=Customer::where([])->column('id,owner_staff_id','name'); |
||||
|
$fn = []; |
||||
|
for ($currentRow = 1; $currentRow <= 1; $currentRow++) { |
||||
|
$values = []; |
||||
|
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) { |
||||
|
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue(); |
||||
|
$values[] = is_null($val) ? NULL : $val; |
||||
|
} |
||||
|
foreach ($values as $l) { |
||||
|
|
||||
|
$fn[] = $fieldnames[$l] ?? ''; |
||||
|
} |
||||
|
} |
||||
|
for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) { |
||||
|
$values = []; |
||||
|
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) { |
||||
|
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue(); |
||||
|
if ($val instanceof RichText) {//富文本转换字符串 |
||||
|
$val = $val->__toString(); |
||||
|
} |
||||
|
$values[] = is_null($val) ? NULL : trim($val); |
||||
|
} |
||||
|
$lastid++; |
||||
|
$addContacts = ['id' => $lastid]; |
||||
|
$customer=isset($customerNames[$values[0]])?$customerNames[$values[0]]:0; |
||||
|
if(empty($customer)){ |
||||
|
$errorInfo[] = "第{$currentRow}行,客户名称不存在;"; |
||||
|
continue; |
||||
|
} |
||||
|
$addContacts['customer_id']=$customer['id']; |
||||
|
$addContacts['owner_staff_id']=$customer['owner_staff_id']; |
||||
|
$addContacts['create_staff_id']=$customer['owner_staff_id']; |
||||
|
foreach ($values as $kv => $value) { |
||||
|
if (!isset($fn[$kv]) || empty($fn[$kv])) { |
||||
|
continue; |
||||
|
} |
||||
|
$addContacts[$fn[$kv]] = $value; |
||||
|
} |
||||
|
if (empty($addContacts['name'])) { |
||||
|
$errorInfo[] = "第{$currentRow}行,联系人名称不能为空;"; |
||||
|
continue; |
||||
|
} |
||||
|
if (empty($addContacts['mobile'])) { |
||||
|
$errorInfo[] = "第{$currentRow}行,联系人手机号不能为空;"; |
||||
|
continue; |
||||
|
} |
||||
|
$contactsRow[] = $addContacts; |
||||
|
} |
||||
|
if (!empty($errorInfo)) { |
||||
|
$this->error(implode(',', $errorInfo)); |
||||
|
} |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
$this->model::importContacts($contactsRow); |
||||
|
Db::commit(); |
||||
|
} catch (Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
$this->success('导入成功'); |
||||
|
} |
||||
|
$this->assign('staffs', Staff::getList()); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 模板 |
||||
|
*/ |
||||
|
public function template() |
||||
|
{ |
||||
|
$title = [ |
||||
|
'客户名称' |
||||
|
]; |
||||
|
$contractData = Form::getDataValue(Form::CONTACTS_TYPE); |
||||
|
|
||||
|
foreach ($contractData as $val) { |
||||
|
$title[] = $val['config']['label']; |
||||
|
} |
||||
|
|
||||
|
$file = export_excel($title, [], '联系人'); |
||||
|
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); |
||||
|
header('Content-Disposition: attachment;filename=' . $file['fileName']); |
||||
|
header('Cache-Control: max-age=0'); |
||||
|
|
||||
|
$obj = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); |
||||
|
// 以下内容是excel文件的信息描述信息 |
||||
|
$obj->getProperties()->setTitle('导出文件'); //设置标题 |
||||
|
$obj->setActiveSheetIndex(0); |
||||
|
$obj->getActiveSheet()->setTitle('导出文件'); |
||||
|
/* 循环读取每个单元格的数据 */ |
||||
|
$a = 'A'; |
||||
|
$currentSheet = $obj->getActiveSheet(); |
||||
|
foreach ($title as $key => $value) { |
||||
|
//读取工作表1 |
||||
|
// 设置第一行加粗 |
||||
|
$obj->getActiveSheet()->getStyle($a . '1')->getFont()->setBold(true); |
||||
|
//这里是设置单元格的内容 |
||||
|
$currentSheet->getCell($a . '1')->setValue($value); |
||||
|
$a++; |
||||
|
} |
||||
|
|
||||
|
$PHPWriter = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($obj); |
||||
|
|
||||
|
$PHPWriter->save('php://output'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 导出信息 |
||||
|
*/ |
||||
|
public function export() |
||||
|
{ |
||||
|
$this->request->filter(['strip_tags', 'trim']); |
||||
|
$ids = input('ids'); |
||||
|
$isall = input('isall'); |
||||
|
$wheres = array(); |
||||
|
//导出其中几条 |
||||
|
if (isset($ids)) { |
||||
|
$wheres['id'] = array('in', $ids); |
||||
|
} |
||||
|
//导出全部 |
||||
|
if (isset($isall)) { |
||||
|
if ($isall == 3) { |
||||
|
unset($wheres['id']); |
||||
|
} |
||||
|
} |
||||
|
//0:全部 1:我负责的 2:下属负责的 3:今日待跟进 4:今日已跟进 5:从未跟进的 |
||||
|
$type = input('type',0); |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
switch($type){ |
||||
|
case 1: |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['owner_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 2: |
||||
|
$wheres['owner_staff_id'] = array('in',Staff::getLowerStaffId()); |
||||
|
break; |
||||
|
case 3: |
||||
|
$start = date('Y-m-d 00:00:00'); |
||||
|
$end = date('Y-m-d 23:59:59'); |
||||
|
$record = collection(Record::where(array('relation_type'=>2,'next_time'=>array(array('egt',$start),array('elt',$end))))->field("id,relation_id")->select())->toArray(); |
||||
|
$relationId = []; |
||||
|
foreach($record as $k=>$v){ |
||||
|
$whereRe['id'] = array('gt',$v['id']); |
||||
|
$whereRe['relation_id'] = $v['relation_id']; |
||||
|
$recordData = Record::where($whereRe)->count(); |
||||
|
if($recordData == 0){ |
||||
|
$relationId[] = $v['relation_id']; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
$wheres['id'] = array('in',$relationId); |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['owner_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 4: |
||||
|
$start = date('Y-m-d 00:00:00'); |
||||
|
$end = date('Y-m-d 23:59:59'); |
||||
|
$record = collection(Record::where(array('relation_type'=>2,'next_time'=>array(array('egt',$start),array('elt',$end))))->field("id,relation_id")->select())->toArray(); |
||||
|
$relationId = []; |
||||
|
foreach($record as $k=>$v){ |
||||
|
$whereRe['id'] = array('gt',$v['id']); |
||||
|
$whereRe['relation_id'] = $v['relation_id']; |
||||
|
$recordData = Record::where($whereRe)->count(); |
||||
|
if($recordData >=1){ |
||||
|
$relationId[] = $v['relation_id']; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
$wheres['id'] = array('in',$relationId); |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['owner_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 5: |
||||
|
$record = collection(Record::where(array('relation_type'=>2,'next_time'=>array('neq','')))->column('relation_id'))->toArray(); |
||||
|
$wheres['id'] = array('not in',$record); |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['owner_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
default: |
||||
|
$wheres['owner_staff_id'] = array('in',Staff::getMyStaffIds()); |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
$list = $this->model->with([ |
||||
|
'ownerStaff','contactsOther','customer' |
||||
|
])->where($where)->where($wheres)->order($sort, $order)->select(); |
||||
|
$list = collection($list)->toArray(); |
||||
|
|
||||
|
if (!$list) { |
||||
|
$this->error('无导出数据'); |
||||
|
} |
||||
|
$title = [ |
||||
|
'序号', |
||||
|
'客户名称', |
||||
|
'归属人', |
||||
|
'创建时间', |
||||
|
'下次联系时间', |
||||
|
]; |
||||
|
|
||||
|
$dataValue = Form::getDataValue(Form::CONTACTS_TYPE); |
||||
|
|
||||
|
foreach ($dataValue as $val) { |
||||
|
$title[] = $val['config']['label']; |
||||
|
} |
||||
|
foreach ($list as $k => $v) { |
||||
|
if($v['contacts_other']){//其他客户 |
||||
|
$other=$v['contacts_other']['otherdata']; |
||||
|
$other=json_decode($other,true); |
||||
|
$v = array_merge($v, $other); |
||||
|
} |
||||
|
$field = array( |
||||
|
$v['id'], |
||||
|
$v['customer']['name'], |
||||
|
|
||||
|
$v['owner_staff']['name'], |
||||
|
date('Y-m-d H:i:s',$v['createtime']), |
||||
|
$v['next_time'] |
||||
|
); |
||||
|
foreach ($dataValue as $val) { |
||||
|
if ($val['component'] == 'uploadImage' || $val['component'] == 'uploadFile') { |
||||
|
$field[] = $v[$val['id'] . '_str'] ?? ''; |
||||
|
} else { |
||||
|
$field[] = ($v[$val['id']] ?? ''); |
||||
|
} |
||||
|
} |
||||
|
$data[] = $field; |
||||
|
} |
||||
|
$file = export_excel($title, $data, '联系人'); |
||||
|
if ($file['filePath']) { |
||||
|
$this->success('导出成功', '', $file); |
||||
|
} |
||||
|
$this->error('导出失败'); |
||||
|
} |
||||
|
} |
||||
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,684 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\qingdong\customer; |
||||
|
|
||||
|
use addons\qingdong\model\File; |
||||
|
use addons\qingdong\model\FormField; |
||||
|
use addons\qingdong\model\Staff; |
||||
|
use app\admin\controller\qingdong\Base; |
||||
|
use addons\qingdong\model\Form; |
||||
|
use addons\qingdong\model\LeadsOther; |
||||
|
use addons\qingdong\model\OperationLog; |
||||
|
use addons\qingdong\model\Record; |
||||
|
use addons\qingdong\model\Customer; |
||||
|
use addons\qingdong\model\Contacts; |
||||
|
use addons\qingdong\model\LeadsFile; |
||||
|
use PhpOffice\PhpSpreadsheet\Cell\Coordinate; |
||||
|
use PhpOffice\PhpSpreadsheet\IOFactory; |
||||
|
use PhpOffice\PhpSpreadsheet\Reader\Csv; |
||||
|
use PhpOffice\PhpSpreadsheet\Reader\Xls; |
||||
|
use PhpOffice\PhpSpreadsheet\Reader\Xlsx; |
||||
|
use PhpOffice\PhpSpreadsheet\RichText\RichText; |
||||
|
use think\Db; |
||||
|
use think\Exception; |
||||
|
|
||||
|
/** |
||||
|
* 线索 |
||||
|
* 操作文档:https://doc.fastadmin.net/qingdong |
||||
|
* 软件介绍:https://www.fastadmin.net/store/qingdong.html |
||||
|
* 售后微信:qingdong_crm |
||||
|
*/ |
||||
|
class Leads extends Base |
||||
|
{ |
||||
|
protected $relationSearch = true; |
||||
|
protected $searchFields = 'id,name'; |
||||
|
/** |
||||
|
* @var \addons\qingdong\model\Leads |
||||
|
*/ |
||||
|
protected $model = null; |
||||
|
|
||||
|
|
||||
|
public function _initialize() |
||||
|
{ |
||||
|
parent::_initialize(); |
||||
|
$this->model = new \addons\qingdong\model\Leads; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() |
||||
|
{ |
||||
|
$this->request->filter(['strip_tags', 'trim']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
//0:全部 1:我负责的 2:下属负责的 3:今日待跟进 4:今日已跟进 5:从未跟进的 |
||||
|
$type = input('type', 0); |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
|
||||
|
switch ($type) { |
||||
|
case 1: |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['owner_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 2: |
||||
|
$wheres['owner_staff_id'] = array('in', Staff::getLowerStaffId()); |
||||
|
break; |
||||
|
case 3: |
||||
|
$start = date('Y-m-d 00:00:00'); |
||||
|
$end = date('Y-m-d 23:59:59'); |
||||
|
$record = collection(Record::where(array('cid'=>CID,'relation_type' => 1, 'next_time' => array(array('egt', $start), array('elt', $end))))->field("id,relation_id")->select())->toArray(); |
||||
|
$relationId = []; |
||||
|
foreach ($record as $k => $v) { |
||||
|
$whereRe['id'] = array('gt', $v['id']); |
||||
|
$whereRe['relation_id'] = $v['relation_id']; |
||||
|
$recordData = Record::where($whereRe)->count(); |
||||
|
if ($recordData == 0) { |
||||
|
$relationId[] = $v['relation_id']; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
$wheres['id'] = array('in', $relationId); |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['owner_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 4: |
||||
|
$start = date('Y-m-d 00:00:00'); |
||||
|
$end = date('Y-m-d 23:59:59'); |
||||
|
$record = collection(Record::where(array('cid'=>CID,'relation_type' => 1, 'next_time' => array(array('egt', $start), array('elt', $end))))->field("id,relation_id")->select())->toArray(); |
||||
|
$relationId = []; |
||||
|
foreach ($record as $k => $v) { |
||||
|
$whereRe['id'] = array('gt', $v['id']); |
||||
|
$whereRe['relation_id'] = $v['relation_id']; |
||||
|
$recordData = Record::where($whereRe)->count(); |
||||
|
if ($recordData >= 1) { |
||||
|
$relationId[] = $v['relation_id']; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
$wheres['id'] = array('in', $relationId); |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['owner_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 5: |
||||
|
$record = collection(Record::where(array('relation_type' => 4))->column('relation_id'))->toArray(); |
||||
|
$wheres['id'] = array('not in', $record); |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['owner_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
default: |
||||
|
$wheres['owner_staff_id'] = array('in', Staff::getMyStaffIds()); |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
$wheres['is_transform'] = 0; |
||||
|
$list = $this->model->where($where)->where($wheres)->order($sort, $order)->with(['ownerStaff'])->paginate($limit); |
||||
|
|
||||
|
$result = array("total" => $list->total(), "rows" => $list->items()); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
|
||||
|
$field = FormField::getFields(FormField::LEADS_TYPE); |
||||
|
$this->assignconfig('fields', $field); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 添加 |
||||
|
*/ |
||||
|
public function add() |
||||
|
{ |
||||
|
if ($this->request->isPost()) { |
||||
|
$params = $this->request->post("row/a"); |
||||
|
if ($params) { |
||||
|
$params = $this->preExcludeFields($params); |
||||
|
// 表单验证 |
||||
|
if (($result = $this->qingdongValidate($params, 'Leads', 'create')) !== true) { |
||||
|
$this->error($result); |
||||
|
} |
||||
|
|
||||
|
$result = FormField::checkFields('leads', $params); |
||||
|
if ($result !== true) { |
||||
|
$this->error($result); |
||||
|
} |
||||
|
$result = false; |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
$params = Form::updateFormParams('leads', $params); |
||||
|
|
||||
|
$result = $this->model::createLeads($params); |
||||
|
Db::commit(); |
||||
|
} catch (Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
if ($result !== false) { |
||||
|
$this->success(); |
||||
|
} else { |
||||
|
$this->error(__('No rows were inserted')); |
||||
|
} |
||||
|
} |
||||
|
$this->error(__('Parameter %s can not be empty', '')); |
||||
|
} |
||||
|
$staffs = Staff::getList($this->_staff->id); |
||||
|
|
||||
|
$this->assign('staffs', $staffs); |
||||
|
$this->view->assign('form_data', Form::getDataValue('leads')); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 修改 |
||||
|
*/ |
||||
|
public function edit($ids = null) |
||||
|
{ |
||||
|
$row = $this->model->get($ids); |
||||
|
if ($this->request->isPost()) { |
||||
|
$params = $this->request->post("row/a"); |
||||
|
if ($params) { |
||||
|
$params = $this->preExcludeFields($params); |
||||
|
// 表单验证 |
||||
|
if (($result = $this->qingdongValidate($params, 'Leads', 'create')) !== true) { |
||||
|
$this->error($result); |
||||
|
} |
||||
|
$result = FormField::checkFields('leads', $params, $ids); |
||||
|
if ($result !== true) { |
||||
|
$this->error($result); |
||||
|
} |
||||
|
$result = false; |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
$params = Form::updateFormParams('leads', $params); |
||||
|
$params['id'] = $ids; |
||||
|
$result = $this->model::updateLeads($params); |
||||
|
Db::commit(); |
||||
|
} catch (Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
if ($result !== false) { |
||||
|
$this->success(); |
||||
|
} else { |
||||
|
$this->error(__('No rows were inserted')); |
||||
|
} |
||||
|
} |
||||
|
$this->error(__('Parameter %s can not be empty', '')); |
||||
|
} |
||||
|
$row = $row->toArray(); |
||||
|
$row = LeadsOther::getOther($row); |
||||
|
$this->assign('row', $row); |
||||
|
|
||||
|
$this->view->assign('form_data', Form::getDataValue('leads', $row)); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 线索详情 |
||||
|
*/ |
||||
|
public function detail($ids = null) |
||||
|
{ |
||||
|
$row = $this->model->with(['create_staff', 'owner_staff'])->where(['id' => $ids])->find(); |
||||
|
|
||||
|
//跟进记录 |
||||
|
$this->assign('records', Record::getList(Record::LEADS_TYPE, $ids)); |
||||
|
//操作记录 |
||||
|
$this->assign('operation_log', OperationLog::getList(OperationLog::LEADS_TYPE, $ids)); |
||||
|
|
||||
|
|
||||
|
$row = $row->toArray(); |
||||
|
$row = LeadsOther::getOther($row); |
||||
|
$this->view->assign('form_data', Form::getDataValue('leads', $row)); |
||||
|
$this->assign('row', $row); |
||||
|
$this->assign('ids', $ids); |
||||
|
$this->assignconfig("idinfo", ['id' => $ids]); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 转为客户 |
||||
|
*/ |
||||
|
public function convert_customer($ids = null) |
||||
|
{ |
||||
|
$row = $this->model->get($ids); |
||||
|
if (empty($row)) { |
||||
|
$this->error('线索不存在'); |
||||
|
} |
||||
|
try { |
||||
|
$customer = [ |
||||
|
'leads_id' => $row['id'], |
||||
|
'name' => $row['name'], |
||||
|
'level' => $row['level'], |
||||
|
'industry' => $row['industry'], |
||||
|
'remarks' => $row['remarks'], |
||||
|
'source' => $row['source'], |
||||
|
'follow' => $row['follow'], |
||||
|
'address' => $row['address'], |
||||
|
'address_detail' => $row['address_detail'], |
||||
|
'create_staff_id' => $row['owner_staff_id'], |
||||
|
'owner_staff_id' => $row['owner_staff_id'], |
||||
|
]; |
||||
|
//线索转化 |
||||
|
$leads_id = ''; |
||||
|
if (isset($customer['leads_id'])) { |
||||
|
$leads_id = $customer['leads_id']; |
||||
|
} |
||||
|
$customer_id = Customer::createCustomer($customer, $leads_id); |
||||
|
$contracts = [ |
||||
|
'customer_id' => $customer_id, |
||||
|
'is_major' => 1, |
||||
|
'name' => $row['name'], |
||||
|
'mobile' => $row['mobile'], |
||||
|
'remarks' => $row['remarks'], |
||||
|
'create_staff_id' => $row['owner_staff_id'], |
||||
|
'owner_staff_id' => $row['owner_staff_id'], |
||||
|
]; |
||||
|
$contacts_id = Contacts::createContacts($contracts); |
||||
|
} catch (Exception $e) { |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
$this->success('转变成功'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取附件记录 |
||||
|
*/ |
||||
|
public function get_file($ids = null) |
||||
|
{ |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
$list = LeadsFile::where(['leads_id' => $ids])->with(['file'])->field('file_id')->paginate($limit); |
||||
|
|
||||
|
$result = array("total" => $list->total(), "rows" => $list->items()); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 转移线索 |
||||
|
*/ |
||||
|
public function transfer($ids = null) |
||||
|
{ |
||||
|
$row = $this->model::where(['id' => $ids])->find(); |
||||
|
if (empty($row)) { |
||||
|
$this->error('线索不存在'); |
||||
|
} |
||||
|
if ($this->request->isPost()) { |
||||
|
$staff_id = input('staff_id'); |
||||
|
if (empty($staff_id)) { |
||||
|
$this->error('参数错误'); |
||||
|
} |
||||
|
$staff = Staff::get($staff_id); |
||||
|
if (empty($staff)) { |
||||
|
$this->error('接收对象不存在'); |
||||
|
} |
||||
|
try { |
||||
|
$this->model::transfer($ids, $staff_id); |
||||
|
} catch (Exception $e) { |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
$this->success('转变成功'); |
||||
|
} |
||||
|
$staffs = Staff::getList(); |
||||
|
|
||||
|
$this->assign('staffs', $staffs); |
||||
|
$this->assign('row', $row); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
*/ |
||||
|
public function del($ids = "") |
||||
|
{ |
||||
|
if (!$this->request->isPost()) { |
||||
|
$this->error(__("Invalid parameters")); |
||||
|
} |
||||
|
$ids = $ids ? $ids : $this->request->post("ids"); |
||||
|
$row = $this->model->get($ids); |
||||
|
$this->modelValidate = true; |
||||
|
if (!$row) { |
||||
|
$this->error(__('No Results were found')); |
||||
|
} |
||||
|
$row->delete(); |
||||
|
$this->success(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 导入 |
||||
|
*/ |
||||
|
public function import() |
||||
|
{ |
||||
|
set_time_limit(0); |
||||
|
if ($this->request->isPost()) { |
||||
|
|
||||
|
$file = $this->request->request('file'); |
||||
|
$staff_id = $this->request->request('staff_id', 0); |
||||
|
if (!$file) { |
||||
|
$this->error(__('Parameter %s can not be empty', 'file')); |
||||
|
} |
||||
|
$filePath = ROOT_PATH . 'public' . $file; |
||||
|
if (!is_file($filePath)) { |
||||
|
$this->error(__('No results were found')); |
||||
|
} |
||||
|
//实例化reader |
||||
|
$ext = pathinfo($filePath, PATHINFO_EXTENSION); |
||||
|
if (!in_array($ext, ['csv', 'xls', 'xlsx'])) { |
||||
|
$this->error(__('Unknown data format')); |
||||
|
} |
||||
|
if ($ext === 'csv') { |
||||
|
$file = fopen($filePath, 'r'); |
||||
|
$filePath = tempnam(sys_get_temp_dir(), 'import_csv'); |
||||
|
$fp = fopen($filePath, "w"); |
||||
|
$n = 0; |
||||
|
while ($line = fgets($file)) { |
||||
|
$line = rtrim($line, "\n\r\0"); |
||||
|
$encoding = mb_detect_encoding($line, ['utf-8', 'gbk', 'latin1', 'big5']); |
||||
|
if ($encoding != 'utf-8') { |
||||
|
$line = mb_convert_encoding($line, 'utf-8', $encoding); |
||||
|
} |
||||
|
if ($n == 0 || preg_match('/^".*"$/', $line)) { |
||||
|
fwrite($fp, $line . "\n"); |
||||
|
} else { |
||||
|
fwrite($fp, '"' . str_replace(['"', ','], ['""', '","'], $line) . "\"\n"); |
||||
|
} |
||||
|
$n++; |
||||
|
} |
||||
|
fclose($file) || fclose($fp); |
||||
|
|
||||
|
$reader = new Csv(); |
||||
|
} elseif ($ext === 'xls') { |
||||
|
$reader = new Xls(); |
||||
|
} else { |
||||
|
$reader = new Xlsx(); |
||||
|
} |
||||
|
if (!$PHPExcel = $reader->load($filePath)) { |
||||
|
$this->error(__('Unknown data format')); |
||||
|
} |
||||
|
$currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表 |
||||
|
|
||||
|
$allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号 |
||||
|
$allRow = $currentSheet->getHighestRow(); //取得一共有多少行 |
||||
|
|
||||
|
$maxColumnNumber = Coordinate::columnIndexFromString($allColumn); |
||||
|
//开始读取数据 |
||||
|
$fields = []; |
||||
|
for ($currentRow = 1; $currentRow <= 1; $currentRow++) { |
||||
|
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) { |
||||
|
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue(); |
||||
|
$fields[$currentRow][] = $val; |
||||
|
} |
||||
|
} |
||||
|
if (!isset($fields[1])) { |
||||
|
$this->error('导入文件第一行没有数据'); |
||||
|
} |
||||
|
$lastid = $this->model->withTrashed()->order('id desc')->value('id'); |
||||
|
$contacts_lastid = (new Contacts())->withTrashed()->order('id desc')->value('id'); |
||||
|
|
||||
|
$lastid = $lastid + 5;//防止重复 |
||||
|
$contacts_lastid = $contacts_lastid + 5;//防止重复 |
||||
|
|
||||
|
$leadRow = []; |
||||
|
$errorInfo = []; |
||||
|
$formrow = []; |
||||
|
$names = $this->model->where([])->column('name'); |
||||
|
$fieldnames = FormField::where(['types' => FormField::LEADS_TYPE])->column('field', 'name'); |
||||
|
if(!$fieldnames){ |
||||
|
$this->error('请在系统管理->字段管理中保存线索管理表单生成线索导入字段'); |
||||
|
} |
||||
|
$forms = Form::getDataValue('leads'); |
||||
|
foreach($forms as $k=>$v){ |
||||
|
$formrow[$v['id']] = $v['name']; |
||||
|
} |
||||
|
|
||||
|
$fn = []; |
||||
|
for ($currentRow = 1; $currentRow <= 1; $currentRow++) { |
||||
|
$values = []; |
||||
|
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) { |
||||
|
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue(); |
||||
|
$values[] = is_null($val) ? '' : $val; |
||||
|
} |
||||
|
foreach ($values as $l) { |
||||
|
$fn[] = $fieldnames[$l] ?? ''; |
||||
|
} |
||||
|
} |
||||
|
for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) { |
||||
|
$values = []; |
||||
|
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) { |
||||
|
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue(); |
||||
|
if ($val instanceof RichText) {//富文本转换字符串 |
||||
|
$val = $val->__toString(); |
||||
|
} |
||||
|
$values[] = is_null($val) ? NULL : $val; |
||||
|
} |
||||
|
|
||||
|
$lastid++; |
||||
|
$contacts_lastid++; |
||||
|
$addLeads = ['id' => $lastid, 'owner_staff_id' => $staff_id, 'create_staff_id' => $staff_id]; |
||||
|
foreach ($values as $kv => $value) { |
||||
|
if (!isset($fn[$kv]) || empty($fn[$kv])) { |
||||
|
continue; |
||||
|
} |
||||
|
$addLeads[$fn[$kv]] = $value; |
||||
|
} |
||||
|
|
||||
|
//日期处理 |
||||
|
foreach($formrow as $k=>$v){ |
||||
|
if($v=='日期选择框'){ |
||||
|
if(isset($addLeads[$k]) && $addLeads[$k]){ |
||||
|
$addLeads[$k] =date("Y-m-d", ($addLeads[$k] - 25569) * 24 * 3600); |
||||
|
} |
||||
|
} |
||||
|
if($v=='时间选择框'){ |
||||
|
if(isset($addLeads[$k]) && $addLeads[$k]){ |
||||
|
$addLeads[$k] =date("Y-m-d H:i:s", ($addLeads[$k] - 25569) * 24 * 3600); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
if (!isset($addLeads['name']) || empty($addLeads['name'])) { |
||||
|
$errorInfo[] = "第{$currentRow}行,线索名称不能为空;"; |
||||
|
continue; |
||||
|
} |
||||
|
if (in_array($addLeads['name'], $names)) { |
||||
|
$errorInfo[] = "第{$currentRow}行,线索名称`{$addLeads['name']}`已存在;"; |
||||
|
continue; |
||||
|
} |
||||
|
$leadRow[] = $addLeads; |
||||
|
} |
||||
|
if (!empty($errorInfo)) { |
||||
|
$this->error(implode(',', $errorInfo)); |
||||
|
} |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
$this->model::importleads($leadRow); |
||||
|
|
||||
|
Db::commit(); |
||||
|
} catch (Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
$this->success('导入成功'); |
||||
|
} |
||||
|
$this->assign('staffs', Staff::getList()); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 模板 |
||||
|
*/ |
||||
|
public function template() |
||||
|
{ |
||||
|
$title = []; |
||||
|
$contractData = Form::getDataValue('leads'); |
||||
|
|
||||
|
foreach ($contractData as $val) { |
||||
|
$title[] = $val['config']['label']; |
||||
|
} |
||||
|
|
||||
|
$file = export_excel($title, [], '线索'); |
||||
|
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); |
||||
|
header('Content-Disposition: attachment;filename=' . $file['fileName']); |
||||
|
header('Cache-Control: max-age=0'); |
||||
|
|
||||
|
$obj = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); |
||||
|
// 以下内容是excel文件的信息描述信息 |
||||
|
$obj->getProperties()->setTitle('导出文件'); //设置标题 |
||||
|
$obj->setActiveSheetIndex(0); |
||||
|
$obj->getActiveSheet()->setTitle('导出文件'); |
||||
|
/* 循环读取每个单元格的数据 */ |
||||
|
$a = 'A'; |
||||
|
$currentSheet = $obj->getActiveSheet(); |
||||
|
foreach ($title as $key => $value) { |
||||
|
//读取工作表1 |
||||
|
// 设置第一行加粗 |
||||
|
$obj->getActiveSheet()->getStyle($a . '1')->getFont()->setBold(true); |
||||
|
//这里是设置单元格的内容 |
||||
|
$currentSheet->getCell($a . '1')->setValue($value); |
||||
|
$a++; |
||||
|
} |
||||
|
|
||||
|
$PHPWriter = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($obj); |
||||
|
|
||||
|
$PHPWriter->save('php://output'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 导出信息 |
||||
|
*/ |
||||
|
public function export() |
||||
|
{ |
||||
|
$this->request->filter(['strip_tags', 'trim']); |
||||
|
$ids = input('ids'); |
||||
|
$isall = input('isall'); |
||||
|
$wheres = array(); |
||||
|
//导出其中几条 |
||||
|
if (isset($ids)) { |
||||
|
$wheres['id'] = array('in', $ids); |
||||
|
} |
||||
|
//导出全部 |
||||
|
if (isset($isall)) { |
||||
|
if ($isall == 3) { |
||||
|
unset($wheres['id']); |
||||
|
} |
||||
|
} |
||||
|
$type = input('type', 0); |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
|
||||
|
switch ($type) { |
||||
|
case 1: |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['owner_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 2: |
||||
|
$wheres['owner_staff_id'] = array('in', Staff::getLowerStaffId()); |
||||
|
break; |
||||
|
case 3: |
||||
|
$start = date('Y-m-d 00:00:00'); |
||||
|
$end = date('Y-m-d 23:59:59'); |
||||
|
$record = collection(Record::where(array('relation_type' => 1, 'next_time' => array(array('egt', $start), array('elt', $end))))->field("id,relation_id")->select())->toArray(); |
||||
|
$relationId = []; |
||||
|
foreach ($record as $k => $v) { |
||||
|
$whereRe['id'] = array('gt', $v['id']); |
||||
|
$whereRe['relation_id'] = $v['relation_id']; |
||||
|
$recordData = Record::where($whereRe)->count(); |
||||
|
if ($recordData == 0) { |
||||
|
$relationId[] = $v['relation_id']; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
$wheres['id'] = array('in', $relationId); |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['owner_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 4: |
||||
|
$start = date('Y-m-d 00:00:00'); |
||||
|
$end = date('Y-m-d 23:59:59'); |
||||
|
$record = collection(Record::where(array('relation_type' => 1, 'next_time' => array(array('egt', $start), array('elt', $end))))->field("id,relation_id")->select())->toArray(); |
||||
|
$relationId = []; |
||||
|
foreach ($record as $k => $v) { |
||||
|
$whereRe['id'] = array('gt', $v['id']); |
||||
|
$whereRe['relation_id'] = $v['relation_id']; |
||||
|
$recordData = Record::where($whereRe)->count(); |
||||
|
if ($recordData >= 1) { |
||||
|
$relationId[] = $v['relation_id']; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
$wheres['id'] = array('in', $relationId); |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['owner_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 5: |
||||
|
$record = collection(Record::where(array('relation_type' => 4))->column('relation_id'))->toArray(); |
||||
|
$wheres['id'] = array('not in', $record); |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['owner_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
default: |
||||
|
$wheres['owner_staff_id'] = array('in', Staff::getMyStaffIds()); |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
$wheres['is_transform'] = 0; |
||||
|
$list = $this->model->with([ |
||||
|
'ownerStaff','leadsOther' |
||||
|
])->where($where)->where($wheres)->order($sort, $order)->select(); |
||||
|
$list = collection($list)->toArray(); |
||||
|
|
||||
|
if (!$list) { |
||||
|
$this->error('无导出数据'); |
||||
|
} |
||||
|
$title = [ |
||||
|
'序号', |
||||
|
'归属人', |
||||
|
'创建时间', |
||||
|
]; |
||||
|
|
||||
|
$contractData = Form::getDataValue('leads'); |
||||
|
|
||||
|
foreach ($contractData as $val) { |
||||
|
$title[] = $val['config']['label']; |
||||
|
} |
||||
|
foreach ($list as $k => $v) { |
||||
|
if($v['leads_other']){//其他线索 |
||||
|
$other=$v['leads_other']['otherdata']; |
||||
|
$other=json_decode($other,true); |
||||
|
$v = array_merge($v, $other); |
||||
|
} |
||||
|
$field = array( |
||||
|
$k + 1, |
||||
|
|
||||
|
$v['owner_staff']['name'], |
||||
|
$v['createtime'] |
||||
|
); |
||||
|
foreach ($contractData as $val) { |
||||
|
if ($val['component'] == 'uploadImage' || $val['component'] == 'uploadFile') { |
||||
|
$field[] = $v[$val['id'] . '_str'] ?? ''; |
||||
|
} else { |
||||
|
$field[] = ($v[$val['id']] ?? ''); |
||||
|
} |
||||
|
} |
||||
|
$data[] = $field; |
||||
|
} |
||||
|
$file = export_excel($title, $data, '线索'); |
||||
|
if ($file['filePath']) { |
||||
|
$this->success('导出成功', '', $file); |
||||
|
} |
||||
|
$this->error('导出失败'); |
||||
|
} |
||||
|
/** |
||||
|
* 移入线索池 |
||||
|
*/ |
||||
|
public function movepool() |
||||
|
{ |
||||
|
$ids = input('ids'); |
||||
|
$reuslt= $this->model->where(['id' => $ids])->update(['owner_staff_id' => 0,'updatetime'=>time()]); |
||||
|
if(!$reuslt){ |
||||
|
$this->error('放入失败'); |
||||
|
} |
||||
|
$this->success('放入成功'); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,390 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\qingdong\customer; |
||||
|
|
||||
|
use addons\qingdong\model\File; |
||||
|
use addons\qingdong\model\Staff; |
||||
|
use app\admin\controller\qingdong\Base; |
||||
|
use addons\qingdong\model\Form; |
||||
|
use addons\qingdong\model\LeadsOther; |
||||
|
use addons\qingdong\model\OperationLog; |
||||
|
use addons\qingdong\model\Record; |
||||
|
use addons\qingdong\model\Customer; |
||||
|
use addons\qingdong\model\Contacts; |
||||
|
use addons\qingdong\model\LeadsFile; |
||||
|
use PhpOffice\PhpSpreadsheet\Cell\Coordinate; |
||||
|
use PhpOffice\PhpSpreadsheet\Reader\Csv; |
||||
|
use PhpOffice\PhpSpreadsheet\Reader\Xls; |
||||
|
use PhpOffice\PhpSpreadsheet\Reader\Xlsx; |
||||
|
use think\Db; |
||||
|
use think\Exception; |
||||
|
|
||||
|
/** |
||||
|
* 线索池 |
||||
|
* 操作文档:https://doc.fastadmin.net/qingdong |
||||
|
* 软件介绍:https://www.fastadmin.net/store/qingdong.html |
||||
|
* 售后微信:qingdong_crm |
||||
|
*/ |
||||
|
class Leadspool extends Base { |
||||
|
protected $relationSearch = true; |
||||
|
protected $searchFields = 'id,name'; |
||||
|
/** |
||||
|
* @var \addons\qingdong\model\Leads |
||||
|
*/ |
||||
|
protected $model = null; |
||||
|
|
||||
|
|
||||
|
public function _initialize() { |
||||
|
parent::_initialize(); |
||||
|
$this->model = new \addons\qingdong\model\Leads; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() { |
||||
|
$this->request->filter(['strip_tags', 'trim']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
$list = $this->model->where($where)->where('owner_staff_id is null or owner_staff_id = 0')->order($sort, $order)->with(['createStaff'])->paginate($limit); |
||||
|
$result = array("total" => $list->total(), "rows" => $list->items()); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
|
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 添加 |
||||
|
*/ |
||||
|
public function add() { |
||||
|
if ($this->request->isPost()) { |
||||
|
$params = $this->request->post("row/a"); |
||||
|
if ($params) { |
||||
|
$params = $this->preExcludeFields($params); |
||||
|
$result = false; |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
$form = Form::getDataValue('leads'); |
||||
|
foreach($form as $k=>$v){ |
||||
|
if($v['component'] == 'uploadImage' || $v['component'] == 'uploadFile'){ |
||||
|
if(key_exists($v['id'],$params)){ |
||||
|
if($params[$v['id']]){ |
||||
|
$filearr = explode(',',$params[$v['id']]); |
||||
|
$files =''; |
||||
|
if($filearr){ |
||||
|
foreach($filearr as $ks=>$vs){ |
||||
|
$files = File::where(array('file_path'=>$vs))->order('id desc')->value('id').','.$files; |
||||
|
} |
||||
|
$params[$v['id']] = rtrim($files,','); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
}elseif($v['component'] == 'select'){ |
||||
|
if(isset($v['config']['multiple']) && $v['config']['multiple'] == true){ |
||||
|
if(key_exists($v['id'],$params)){ |
||||
|
if($params[$v['id']]){ |
||||
|
$params[$v['id']] = implode(',',$params[$v['id']]); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$result =$this->model::createLeads($params,1); |
||||
|
Db::commit(); |
||||
|
} catch (Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
if ($result !== false) { |
||||
|
$this->success(); |
||||
|
} else { |
||||
|
$this->error(__('No rows were inserted')); |
||||
|
} |
||||
|
} |
||||
|
$this->error(__('Parameter %s can not be empty', '')); |
||||
|
} |
||||
|
$staffs = Staff::getList($this->_staff->id); |
||||
|
|
||||
|
$this->assign('staffs', $staffs); |
||||
|
$this->view->assign('form_data', Form::getDataValue('leads')); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 修改 |
||||
|
*/ |
||||
|
public function edit($ids = null) { |
||||
|
$row = $this->model->get($ids); |
||||
|
if ($this->request->isPost()) { |
||||
|
$params = $this->request->post("row/a"); |
||||
|
if ($params) { |
||||
|
$form = Form::getDataValue('leads'); |
||||
|
foreach($form as $k=>$v){ |
||||
|
if($v['component'] == 'uploadImage' || $v['component'] == 'uploadFile'){ |
||||
|
if(key_exists($v['id'],$params)){ |
||||
|
if($params[$v['id']]){ |
||||
|
$filearr = explode(',',$params[$v['id']]); |
||||
|
$files =''; |
||||
|
if($filearr){ |
||||
|
foreach($filearr as $ks=>$vs){ |
||||
|
$files = File::where(array('file_path'=>$vs))->order('id desc')->value('id').','.$files; |
||||
|
} |
||||
|
$params[$v['id']] = rtrim($files,','); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
}elseif($v['component'] == 'select'){ |
||||
|
if(isset($v['config']['multiple']) && $v['config']['multiple'] == true){ |
||||
|
if(key_exists($v['id'],$params)){ |
||||
|
if($params[$v['id']]){ |
||||
|
$params[$v['id']] = implode(',',$params[$v['id']]); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$params = $this->preExcludeFields($params); |
||||
|
|
||||
|
$result = false; |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
$params['id']=$ids; |
||||
|
$result=$this->model::updateLeads($params); |
||||
|
Db::commit(); |
||||
|
} catch (Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
if ($result !== false) { |
||||
|
$this->success(); |
||||
|
} else { |
||||
|
$this->error(__('No rows were inserted')); |
||||
|
} |
||||
|
} |
||||
|
$this->error(__('Parameter %s can not be empty', '')); |
||||
|
} |
||||
|
$row=$row->toArray(); |
||||
|
$row=LeadsOther::getOther($row); |
||||
|
$this->assign('row', $row); |
||||
|
|
||||
|
$this->view->assign('form_data', Form::getDataValue('leads',$row)); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 线索详情 |
||||
|
*/ |
||||
|
public function detail($ids = null) { |
||||
|
$row = $this->model->with(['create_staff', 'owner_staff'])->where(['id' => $ids])->find(); |
||||
|
|
||||
|
//跟进记录 |
||||
|
$this->assign('records', Record::getList(Record::LEADS_TYPE, $ids)); |
||||
|
//操作记录 |
||||
|
$this->assign('operation_log', OperationLog::getList(OperationLog::LEADS_TYPE, $ids)); |
||||
|
|
||||
|
|
||||
|
$row=$row->toArray(); |
||||
|
$row=LeadsOther::getOther($row); |
||||
|
$this->view->assign('form_data', Form::getDataValue('leads',$row)); |
||||
|
$this->assign('row', $row); |
||||
|
$this->assign('ids', $ids); |
||||
|
$this->assignconfig("idinfo", ['id' => $ids]); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 获取附件记录 |
||||
|
*/ |
||||
|
public function get_file($ids = null) { |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
$list = LeadsFile::where(['leads_id' => $ids])->with(['file'])->field('file_id')->paginate($limit); |
||||
|
|
||||
|
$result = array("total" => $list->total(), "rows" => $list->items()); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 分配线索 |
||||
|
*/ |
||||
|
public function transfer($ids=null){ |
||||
|
|
||||
|
if ($this->request->isPost()) { |
||||
|
$leadId = input('ids'); |
||||
|
$staff_id = input('staff_id'); |
||||
|
if (!$staff_id || !$leadId) { |
||||
|
$this->error('参数错误'); |
||||
|
} |
||||
|
$staff = Staff::get($staff_id); |
||||
|
if (empty($staff)) { |
||||
|
$this->error('接收对象不存在'); |
||||
|
} |
||||
|
try { |
||||
|
$ids = explode(',',$ids); |
||||
|
$this->model::transfer($ids, $staff_id); |
||||
|
} catch (Exception $e) { |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
$this->success('分配成功'); |
||||
|
} |
||||
|
$ids = json_decode($ids, true); |
||||
|
$row = $this->model::where(['id' => ['in',$ids]])->find(); |
||||
|
if (empty($row)) { |
||||
|
$this->error('线索不存在'); |
||||
|
} |
||||
|
$staffs = Staff::getList(); |
||||
|
|
||||
|
$this->assign('staffs', $staffs); |
||||
|
$this->assign('row', $row); |
||||
|
$this->assign('ids', implode(',',$ids)); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
*/ |
||||
|
public function del($ids = "") { |
||||
|
if (!$this->request->isPost()) { |
||||
|
$this->error(__("Invalid parameters")); |
||||
|
} |
||||
|
$ids = $ids ? $ids : $this->request->post("ids"); |
||||
|
$row = $this->model->get($ids); |
||||
|
$this->modelValidate = true; |
||||
|
if (!$row) { |
||||
|
$this->error(__('No Results were found')); |
||||
|
} |
||||
|
$row->delete(); |
||||
|
$this->success(); |
||||
|
} |
||||
|
/** |
||||
|
* 导入 |
||||
|
*/ |
||||
|
public function import() |
||||
|
{ |
||||
|
set_time_limit(0); |
||||
|
if ($this->request->isPost()) { |
||||
|
|
||||
|
$file = $this->request->request('file'); |
||||
|
if (!$file) { |
||||
|
$this->error(__('Parameter %s can not be empty', 'file')); |
||||
|
} |
||||
|
$filePath = ROOT_PATH . 'public' . $file; |
||||
|
if (!is_file($filePath)) { |
||||
|
$this->error(__('No results were found')); |
||||
|
} |
||||
|
//实例化reader |
||||
|
$ext = pathinfo($filePath, PATHINFO_EXTENSION); |
||||
|
if (!in_array($ext, ['csv', 'xls', 'xlsx'])) { |
||||
|
$this->error(__('Unknown data format')); |
||||
|
} |
||||
|
$staff = Staff::info(); |
||||
|
if ($ext === 'csv') { |
||||
|
$file = fopen($filePath, 'r'); |
||||
|
$filePath = tempnam(sys_get_temp_dir(), 'import_csv'); |
||||
|
$fp = fopen($filePath, "w"); |
||||
|
$n = 0; |
||||
|
while ($line = fgets($file)) { |
||||
|
$line = rtrim($line, "\n\r\0"); |
||||
|
$encoding = mb_detect_encoding($line, ['utf-8', 'gbk', 'latin1', 'big5']); |
||||
|
if ($encoding != 'utf-8') { |
||||
|
$line = mb_convert_encoding($line, 'utf-8', $encoding); |
||||
|
} |
||||
|
if ($n == 0 || preg_match('/^".*"$/', $line)) { |
||||
|
fwrite($fp, $line . "\n"); |
||||
|
} else { |
||||
|
fwrite($fp, '"' . str_replace(['"', ','], ['""', '","'], $line) . "\"\n"); |
||||
|
} |
||||
|
$n++; |
||||
|
} |
||||
|
fclose($file) || fclose($fp); |
||||
|
|
||||
|
$reader = new Csv(); |
||||
|
} elseif ($ext === 'xls') { |
||||
|
$reader = new Xls(); |
||||
|
} else { |
||||
|
$reader = new Xlsx(); |
||||
|
} |
||||
|
if (!$PHPExcel = $reader->load($filePath)) { |
||||
|
$this->error(__('Unknown data format')); |
||||
|
} |
||||
|
$currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表 |
||||
|
|
||||
|
$allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号 |
||||
|
$allRow = $currentSheet->getHighestRow(); //取得一共有多少行 |
||||
|
|
||||
|
$maxColumnNumber = Coordinate::columnIndexFromString($allColumn); |
||||
|
//开始读取数据 |
||||
|
$fields = []; |
||||
|
for ($currentRow = 1; $currentRow <= 1; $currentRow++) { |
||||
|
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) { |
||||
|
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue(); |
||||
|
$fields[$currentRow][] = $val; |
||||
|
} |
||||
|
} |
||||
|
if (!isset($fields[1])) { |
||||
|
$this->error('导入文件第一行没有数据'); |
||||
|
} |
||||
|
$lastid = $this->model->withTrashed()->order('id desc')->value('id'); |
||||
|
|
||||
|
$lastid = $lastid + 5;//防止重复 |
||||
|
|
||||
|
$customerRow = []; |
||||
|
$errorInfo = []; |
||||
|
$names = $this->model->where([])->column('name'); |
||||
|
|
||||
|
for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) { |
||||
|
$values = []; |
||||
|
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) { |
||||
|
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue(); |
||||
|
$values[] = is_null($val) ? '' : $val; |
||||
|
} |
||||
|
|
||||
|
$lastid++; |
||||
|
|
||||
|
$addCustomers = ['id' => $lastid, 'owner_staff_id' => 0, 'create_staff_id' => $staff->id]; |
||||
|
|
||||
|
$addCustomers['name'] = $values[0]; |
||||
|
$addCustomers['source'] = $values[1]; |
||||
|
$addCustomers['mobile'] = $values[2]; |
||||
|
$addCustomers['address_detail'] = $values[3]; |
||||
|
|
||||
|
$addCustomers['telephone'] = $values[4]; |
||||
|
$addCustomers['sex'] = $values[5]; |
||||
|
$addCustomers['industry'] = $values[6]; |
||||
|
$addCustomers['remarks'] = $values[7]; |
||||
|
|
||||
|
if (empty($addCustomers['name'])) { |
||||
|
$errorInfo[] = "第{$currentRow}行,线索名称不能为空;"; |
||||
|
continue; |
||||
|
} |
||||
|
if (in_array($addCustomers['name'], $names)) { |
||||
|
$errorInfo[] = "第{$currentRow}行,线索名称`{$addCustomers['name']}`已存在;"; |
||||
|
continue; |
||||
|
} |
||||
|
$customerRow[] = $addCustomers; |
||||
|
} |
||||
|
if (!empty($errorInfo)) { |
||||
|
$this->error(implode(',', $errorInfo)); |
||||
|
} |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
$this->model::importleads($customerRow); |
||||
|
|
||||
|
Db::commit(); |
||||
|
} catch (Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
$this->success('导入成功'); |
||||
|
} |
||||
|
$this->assign('staffs', Staff::getList()); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,70 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\qingdong\customer; |
||||
|
|
||||
|
use app\admin\controller\qingdong\Base; |
||||
|
use addons\qingdong\model\OperationLog; |
||||
|
use think\Db; |
||||
|
use think\Exception; |
||||
|
|
||||
|
/** |
||||
|
* 操作文档:https://doc.fastadmin.net/qingdong |
||||
|
* 软件介绍:https://www.fastadmin.net/store/qingdong.html |
||||
|
* 售后微信:qingdong_crm |
||||
|
* 日志管理 |
||||
|
*/ |
||||
|
class Log extends Base |
||||
|
{ |
||||
|
protected $model = null; |
||||
|
public function _initialize() |
||||
|
{ |
||||
|
parent::_initialize(); |
||||
|
$this->model = new \addons\qingdong\model\OperationLog; |
||||
|
} |
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() |
||||
|
{ |
||||
|
//设置过滤方法 |
||||
|
$this->request->filter(['strip_tags', 'trim']); |
||||
|
$customer_id = input('customer_id','','trim'); |
||||
|
$contacts_id = input('contacts_id','','trim'); |
||||
|
$leads_id = input('leads_id','','trim'); |
||||
|
$contract_id = input('contract_id','','trim'); |
||||
|
if ($this->request->isAjax()) { |
||||
|
if ($this->request->request('keyField')) { |
||||
|
return $this->selectpage(); |
||||
|
} |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
$wheres = []; |
||||
|
if(isset($customer_id) && $customer_id){ |
||||
|
$wheres['relation_type'] = 1; |
||||
|
$wheres['relation_id'] = $customer_id; |
||||
|
} |
||||
|
if(isset($contacts_id) && $contacts_id){ |
||||
|
$wheres['relation_type'] = 2; |
||||
|
$wheres['relation_id'] = $contacts_id; |
||||
|
} |
||||
|
if(isset($leads_id) && $leads_id){ |
||||
|
$wheres['relation_type'] = 4; |
||||
|
$wheres['relation_id'] = $leads_id; |
||||
|
} |
||||
|
if(isset($contract_id) && $contract_id){ |
||||
|
$wheres['relation_type'] = 3; |
||||
|
$wheres['relation_id'] = $contract_id; |
||||
|
} |
||||
|
$list = $this->model->with('staff')->where($where)->where($wheres) |
||||
|
->order($sort, $order)->paginate($limit); |
||||
|
|
||||
|
$rows = $list->items(); |
||||
|
|
||||
|
|
||||
|
$result = array("total" => $list->total(), "rows" => $list->items()); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
|
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,245 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\qingdong\customer; |
||||
|
|
||||
|
use addons\qingdong\model\ReceivablesPlan; |
||||
|
use app\admin\controller\qingdong\Base; |
||||
|
use addons\qingdong\model\Staff; |
||||
|
use think\Db; |
||||
|
use think\Exception; |
||||
|
use addons\qingdong\model\Event; |
||||
|
use addons\qingdong\model\ExamineRecord; |
||||
|
|
||||
|
use addons\qingdong\model\Record; |
||||
|
|
||||
|
/** |
||||
|
* 待办管理 |
||||
|
* 操作文档:https://doc.fastadmin.net/qingdong |
||||
|
* 软件介绍:https://www.fastadmin.net/store/qingdong.html |
||||
|
* 售后微信:qingdong_crm |
||||
|
*/ |
||||
|
class Need extends Base |
||||
|
{ |
||||
|
protected $relationSearch = true; |
||||
|
|
||||
|
protected $model = null; |
||||
|
|
||||
|
|
||||
|
public function _initialize() |
||||
|
{ |
||||
|
parent::_initialize(); |
||||
|
|
||||
|
} |
||||
|
/** |
||||
|
* 待办列表 |
||||
|
*/ |
||||
|
public function index(){ |
||||
|
$where['create_staff_id'] = $this->_staff->id; |
||||
|
$where['next_time'] = array(array('egt',date('Y-m-d 00:00:00')),array('lt',date('Y-m-d 23:59:59'))); |
||||
|
$where['follow_type'] = ['neq', '其它']; |
||||
|
$where['status'] = 0; |
||||
|
// 待跟进客户 |
||||
|
$where1['relation_type'] = 1; |
||||
|
$customerlist = Record::where($where)->where($where1)->column('relation_id'); |
||||
|
$customerlist1 = 0; |
||||
|
if($customerlist){ |
||||
|
$whereExit['relation_id'] = array('in',$customerlist); |
||||
|
$whereExit['next_time'] = array('gt',date('Y-m-d 23:59:59')); |
||||
|
$customerlist1 = Record::where($whereExit)->count(); |
||||
|
} |
||||
|
$customer = count($customerlist) - $customerlist1; |
||||
|
if($customer <=0){ |
||||
|
$customer =0; |
||||
|
} |
||||
|
//待跟进合同 |
||||
|
$where2['relation_type'] = 3; |
||||
|
$contractlist = Record::where($where)->where($where2)->column('relation_id'); |
||||
|
$contractlist1 = 0; |
||||
|
if($contractlist){ |
||||
|
$whereExitC['relation_id'] = array('in',$contractlist); |
||||
|
$whereExitC['next_time'] = array('gt',date('Y-m-d 23:59:59')); |
||||
|
$contractlist1 = Record::where($whereExitC)->count(); |
||||
|
} |
||||
|
$contract = count($contractlist)-$contractlist1; |
||||
|
if($contract <=0){ |
||||
|
$contract =0; |
||||
|
} |
||||
|
//待跟进线索 |
||||
|
$where3['relation_type'] = 4; |
||||
|
$leadlist = Record::where($where)->where($where3)->column('relation_id'); |
||||
|
$leadlist1 = 0; |
||||
|
if($leadlist){ |
||||
|
$whereExitL['relation_id'] = array('in',$leadlist); |
||||
|
$whereExitL['next_time'] = array('gt',date('Y-m-d 23:59:59')); |
||||
|
$leadlist1 = Record::where($whereExitL)->count(); |
||||
|
} |
||||
|
$lead = count($leadlist)-$leadlist1; |
||||
|
if($lead <=0){ |
||||
|
$lead =0; |
||||
|
} |
||||
|
//费用审核 |
||||
|
$consume = ExamineRecord::where([ |
||||
|
'relation_type' => ExamineRecord::CONSUME_TYPE, |
||||
|
'status' => 0, |
||||
|
'check_staff_id' => $this->_staff->id |
||||
|
])->count(); |
||||
|
//待处理日程 |
||||
|
$eventOne = Event::where([ |
||||
|
'type' => 1, |
||||
|
'status' => ['in', [0, 1]], |
||||
|
'staff_id' => $this->_staff->id, |
||||
|
])->count(); |
||||
|
//待审核合同 |
||||
|
$examine = ExamineRecord::where([ |
||||
|
'relation_type' => ExamineRecord::CONTRACT_TYPE, |
||||
|
'status' => 0, |
||||
|
'check_staff_id' => $this->_staff->id |
||||
|
])->count(); |
||||
|
//待审核回款 |
||||
|
$receivables = ExamineRecord::where([ |
||||
|
'relation_type' => ExamineRecord::RECEIVABLES_TYPE, |
||||
|
'status' => 0, |
||||
|
'check_staff_id' => $this->_staff->id, |
||||
|
])->count(); |
||||
|
//待审批办公 |
||||
|
$approval = ExamineRecord::where([ |
||||
|
'relation_type' => ExamineRecord::APPROVAL_TYPE, |
||||
|
'status' => 0, |
||||
|
'check_staff_id' => $this->_staff->id, |
||||
|
])->count(); |
||||
|
//超时任务 |
||||
|
$eventtask = Event::where([ |
||||
|
'type' => 1, |
||||
|
'status' => ['in', [0, 1]], |
||||
|
'start_time' => ['lt', date('Y-m-d', strtotime('+1 day'))], |
||||
|
'staff_id' => $this->_staff->id, |
||||
|
])->count(); |
||||
|
//业绩审核 |
||||
|
$achievement = ExamineRecord::where([ |
||||
|
'relation_type' => ExamineRecord::ACHIEVEMENT_TYPE, |
||||
|
'status' => 0, |
||||
|
'check_staff_id' => $this->_staff->id |
||||
|
])->count(); |
||||
|
$info = array( |
||||
|
'customer'=>$customer, |
||||
|
'contract'=>$contract, |
||||
|
'lead'=>$lead, |
||||
|
'consume'=>$consume, |
||||
|
'eventOne'=>$eventOne, |
||||
|
'examine'=>$examine, |
||||
|
'receivables'=>$receivables, |
||||
|
'approval'=>$approval, |
||||
|
'eventtask'=>$eventtask, |
||||
|
'achievement'=>$achievement, |
||||
|
); |
||||
|
$this->view->assign('row',$info); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
/** |
||||
|
* 获取通知数量 |
||||
|
*/ |
||||
|
public function get_need_number(){ |
||||
|
$where['create_staff_id'] = $this->_staff->id; |
||||
|
$where['next_time'] = array(array('egt',date('Y-m-d 00:00:00')),array('lt',date('Y-m-d 23:59:59'))); |
||||
|
$where['follow_type'] = ['neq', '其它']; |
||||
|
$where['status'] = 0; |
||||
|
// 待跟进客户 |
||||
|
$where1['relation_type'] = 1; |
||||
|
$customerlist = Record::where($where)->where($where1)->column('relation_id'); |
||||
|
$customerlist1 = 0; |
||||
|
if($customerlist){ |
||||
|
$whereExit['relation_id'] = array('in',$customerlist); |
||||
|
$whereExit['next_time'] = array('gt',date('Y-m-d 23:59:59')); |
||||
|
$customerlist1 = Record::where($whereExit)->count(); |
||||
|
} |
||||
|
$customer = count($customerlist) - $customerlist1; |
||||
|
if($customer <=0){ |
||||
|
$customer =0; |
||||
|
} |
||||
|
//待跟进合同 |
||||
|
$where2['relation_type'] = 3; |
||||
|
$contractlist = Record::where($where)->where($where2)->column('relation_id'); |
||||
|
$contractlist1 = 0; |
||||
|
if($contractlist){ |
||||
|
$whereExitC['relation_id'] = array('in',$contractlist); |
||||
|
$whereExitC['next_time'] = array('gt',date('Y-m-d 23:59:59')); |
||||
|
$contractlist1 = Record::where($whereExitC)->count(); |
||||
|
} |
||||
|
$contract = count($contractlist)-$contractlist1; |
||||
|
if($contract <=0){ |
||||
|
$contract =0; |
||||
|
} |
||||
|
//待跟进线索 |
||||
|
$where3['relation_type'] = 4; |
||||
|
$leadlist = Record::where($where)->where($where3)->column('relation_id'); |
||||
|
$leadlist1 = 0; |
||||
|
if($leadlist){ |
||||
|
$whereExitL['relation_id'] = array('in',$leadlist); |
||||
|
$whereExitL['next_time'] = array('gt',date('Y-m-d 23:59:59')); |
||||
|
$leadlist1 = Record::where($whereExitL)->count(); |
||||
|
} |
||||
|
$lead = count($leadlist)-$leadlist1; |
||||
|
if($lead <=0){ |
||||
|
$lead =0; |
||||
|
} |
||||
|
//费用审核 |
||||
|
$consume = ExamineRecord::where([ |
||||
|
'relation_type' => ExamineRecord::CONSUME_TYPE, |
||||
|
'status' => 0, |
||||
|
'check_staff_id' => $this->_staff->id |
||||
|
])->count(); |
||||
|
|
||||
|
//待处理日程 |
||||
|
$eventOne = Event::where([ |
||||
|
'type' => 1, |
||||
|
'status' => ['in', [0, 1]], |
||||
|
'staff_id' => ['in',$this->_staff->id], |
||||
|
])->count(); |
||||
|
//待审核合同 |
||||
|
$examine = ExamineRecord::where([ |
||||
|
'relation_type' => ExamineRecord::CONTRACT_TYPE, |
||||
|
'status' => 0, |
||||
|
'check_staff_id' => $this->_staff->id |
||||
|
])->count(); |
||||
|
//待审核回款 |
||||
|
$receivables = ExamineRecord::where([ |
||||
|
'relation_type' => ExamineRecord::RECEIVABLES_TYPE, |
||||
|
'status' => 0, |
||||
|
'check_staff_id' => $this->_staff->id |
||||
|
])->count(); |
||||
|
//待审批办公 |
||||
|
$approval = ExamineRecord::where([ |
||||
|
'relation_type' => ExamineRecord::APPROVAL_TYPE, |
||||
|
'status' => 0, |
||||
|
'check_staff_id' => $this->_staff->id |
||||
|
])->count(); |
||||
|
//超时任务 |
||||
|
$eventtask = Event::where([ |
||||
|
'type' => 1, |
||||
|
'status' => ['in', [0, 1]], |
||||
|
'start_time' => ['lt', date('Y-m-d', strtotime('+1 day'))], |
||||
|
'staff_id' => $this->_staff->id |
||||
|
])->count(); |
||||
|
//业绩审核 |
||||
|
$achievement = ExamineRecord::where([ |
||||
|
'relation_type' => ExamineRecord::ACHIEVEMENT_TYPE, |
||||
|
'status' => 0, |
||||
|
'check_staff_id' => $this->_staff->id |
||||
|
])->count(); |
||||
|
$info = array( |
||||
|
'customer'=>$customer, |
||||
|
'contract'=>$contract, |
||||
|
'lead'=>$lead, |
||||
|
'consume'=>$consume, |
||||
|
'eventOne'=>$eventOne, |
||||
|
'examine'=>$examine, |
||||
|
'receivables'=>$receivables, |
||||
|
'approval'=>$approval, |
||||
|
'eventtask'=>$eventtask, |
||||
|
'achievement'=>$achievement, |
||||
|
); |
||||
|
$number=array_sum(array_values($info)); |
||||
|
$info['number']=$number; |
||||
|
$this->success('请求成功','',$info); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,560 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\admin\controller\qingdong\customer; |
||||
|
|
||||
|
use addons\qingdong\model\Flow; |
||||
|
use addons\qingdong\model\FormField; |
||||
|
use addons\qingdong\model\Staff; |
||||
|
use app\admin\controller\qingdong\Base; |
||||
|
use app\common\library\Auth; |
||||
|
use addons\qingdong\model\ExamineRecord; |
||||
|
use addons\qingdong\model\Customer; |
||||
|
use addons\qingdong\model\Form; |
||||
|
use addons\qingdong\model\Contract; |
||||
|
use addons\qingdong\model\ReceivablesOther; |
||||
|
use PhpOffice\PhpSpreadsheet\Cell\Coordinate; |
||||
|
use PhpOffice\PhpSpreadsheet\Reader\Csv; |
||||
|
use PhpOffice\PhpSpreadsheet\Reader\Xls; |
||||
|
use PhpOffice\PhpSpreadsheet\Reader\Xlsx; |
||||
|
use PhpOffice\PhpSpreadsheet\RichText\RichText; |
||||
|
use think\Db; |
||||
|
use think\Exception; |
||||
|
|
||||
|
/** |
||||
|
* 回款管理 |
||||
|
* 操作文档:https://doc.fastadmin.net/qingdong |
||||
|
* 软件介绍:https://www.fastadmin.net/store/qingdong.html |
||||
|
* 售后微信:qingdong_crm |
||||
|
*/ |
||||
|
class Receivables extends Base { |
||||
|
protected $relationSearch = true; |
||||
|
protected $searchFields = 'id'; |
||||
|
/** |
||||
|
* @var \addons\qingdong\model\Receivables |
||||
|
*/ |
||||
|
protected $model = null; |
||||
|
|
||||
|
|
||||
|
public function _initialize() { |
||||
|
parent::_initialize(); |
||||
|
$this->model = new \addons\qingdong\model\Receivables; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 查看 |
||||
|
*/ |
||||
|
public function index() { |
||||
|
$this->request->filter(['strip_tags', 'trim']); |
||||
|
if ($this->request->isAjax()) { |
||||
|
|
||||
|
//0:全部 1:我负责的 2:下属负责的 |
||||
|
$type = input('type',0); |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
switch($type){ |
||||
|
case 1: |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['owner_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 2: |
||||
|
$wheres['owner_staff_id'] = array('in',Staff::getLowerStaffId()); |
||||
|
break; |
||||
|
default: |
||||
|
$wheres['owner_staff_id'] = array('in',Staff::getMyStaffIds()); |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
$ids=[]; |
||||
|
$group_id=input('group_id'); |
||||
|
$staff_id=input('staff_id'); |
||||
|
if ($group_id) {//角色组 |
||||
|
$ids = Staff::getGroupStaffIds($group_id); |
||||
|
} |
||||
|
if ($staff_id) { |
||||
|
$ids = $staff_id; |
||||
|
} |
||||
|
if ($group_id || $staff_id) { |
||||
|
$wheres['owner_staff_id'] = ['in', $ids]; |
||||
|
} |
||||
|
$list = $this->model->where($where) |
||||
|
->where($wheres)->with(['customer', 'contract','ownerStaff'])->order($sort, $order)->paginate($limit); |
||||
|
|
||||
|
$result = array("total" => $list->total(), "rows" => $list->items()); |
||||
|
|
||||
|
return json($result); |
||||
|
} |
||||
|
|
||||
|
$field = FormField::getFields(FormField::RECEIVABLES_TYPE); |
||||
|
$this->assignconfig('fields', $field); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 添加 |
||||
|
*/ |
||||
|
public function add($ids=null) { |
||||
|
if ($this->request->isPost()) { |
||||
|
$params = $this->request->post("row/a"); |
||||
|
if ($params) { |
||||
|
$params = $this->preExcludeFields($params); |
||||
|
// 表单验证 |
||||
|
if (($result = $this->qingdongValidate($params, 'Receivables', 'create')) !== true) { |
||||
|
$this->error($result); |
||||
|
} |
||||
|
$result = FormField::checkFields(FormField::RECEIVABLES_TYPE, $params); |
||||
|
if ($result !== true) { |
||||
|
$this->error($result); |
||||
|
} |
||||
|
|
||||
|
if ($this->model->where(['number' => $params['number'], 'contract_id' => $params['contract_id']])->find()) { |
||||
|
$this->error('回款编号已存在'); |
||||
|
} |
||||
|
$contract=Contract::where(['id'=>$params['contract_id']])->find(); |
||||
|
if(empty($contract)){ |
||||
|
$this->error('合同不存在'); |
||||
|
} |
||||
|
if($contract['check_status'] != 2){ |
||||
|
$this->error('当前合同未审核通过'); |
||||
|
} |
||||
|
$result = false; |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
$params = Form::updateFormParams('examine', $params); |
||||
|
|
||||
|
$params['owner_staff_id'] = $contract['owner_staff_id']; |
||||
|
$result=$this->model::createReceivables($params); |
||||
|
Db::commit(); |
||||
|
} catch (Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
if ($result !== false) { |
||||
|
$this->success(); |
||||
|
} else { |
||||
|
$this->error(__('No rows were inserted')); |
||||
|
} |
||||
|
} |
||||
|
$this->error(__('Parameter %s can not be empty', '')); |
||||
|
} |
||||
|
$staff=Staff::where([])->column('name','id'); |
||||
|
$this->assign('staff', $staff); |
||||
|
|
||||
|
$flow= Flow::getsteplist(Flow::RECEIVABLES_STATUS); |
||||
|
if (empty($flow)) { |
||||
|
$this->error('无可用审批流,请联系管理员','qingdong/work/flow'); |
||||
|
} |
||||
|
$customer_id = input('customer_id'); |
||||
|
$contract_id = input('contract_id'); |
||||
|
$this->assign('contract_id', $contract_id); |
||||
|
$this->assign('customer_id', $customer_id); |
||||
|
$this->assign('customer', Customer::get($customer_id)); |
||||
|
$this->assign('contract', Contract::get($contract_id)); |
||||
|
$this->assign('flow',$flow); |
||||
|
$this->view->assign('ids',$ids); |
||||
|
$this->view->assign('form_data', Form::getDataValue('examine')); |
||||
|
$this->assign('createNum', get_num('receivables')); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 回款详情 |
||||
|
*/ |
||||
|
public function detail($ids = null) { |
||||
|
$row = $this->model->where(['id' => $ids])->with(['customer', 'contract','plan','ownerStaff'])->find(); |
||||
|
|
||||
|
$status = [0 => '待审核', 1 => '审核中', 2 => '审核通过', 3 => '审核未通过', 4 => '撤销', 5 => '未提交']; |
||||
|
|
||||
|
|
||||
|
$this->assign('status', $status); |
||||
|
$row = $row->toArray(); |
||||
|
$row = ReceivablesOther::getOther($row); |
||||
|
|
||||
|
$this->assign('examine_record',ExamineRecord::getList(ExamineRecord::RECEIVABLES_TYPE,$ids)); |
||||
|
|
||||
|
$this->assign('flow',Flow::getstepdetail(Flow::RECEIVABLES_STATUS, $ids)); |
||||
|
$this->assign('row', $row); |
||||
|
$this->assign('form_data', Form::getDataValue('examine',$row)); |
||||
|
$this->assign('ids', $ids); |
||||
|
$this->assignconfig("idinfo", ['id' => $ids]); |
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
*/ |
||||
|
public function del($ids = "") { |
||||
|
if (!$this->request->isPost()) { |
||||
|
$this->error(__("Invalid parameters")); |
||||
|
} |
||||
|
$ids = $ids ? $ids : $this->request->post("ids"); |
||||
|
$row = $this->model->get($ids); |
||||
|
$this->modelValidate = true; |
||||
|
if (!$row) { |
||||
|
$this->error(__('No Results were found')); |
||||
|
} |
||||
|
Auth::instance()->delete($row['id']); |
||||
|
$this->success(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取客户列表 |
||||
|
*/ |
||||
|
public function getcustomer() |
||||
|
{ |
||||
|
$pageSize = input('pageSize'); |
||||
|
$pageNumber = input('pageNumber'); |
||||
|
$where = []; |
||||
|
if ($keyValue = $this->request->request("keyValue")) { |
||||
|
$where['id'] = $keyValue; |
||||
|
} |
||||
|
$name = input('name'); |
||||
|
if (!empty($name)) { |
||||
|
$where['name'] = ['like', '%' . $name . '%']; |
||||
|
} |
||||
|
$staff = Staff::info(); |
||||
|
$staff_id = $staff->id; |
||||
|
$whereStaff = function ($query) use ($staff_id) { |
||||
|
$query->where(['ro_staff_id' => ['like', "%,{$staff_id},%"]]) |
||||
|
->whereOr('rw_staff_id', 'like', "%,{$staff_id},%") |
||||
|
->whereOr(['owner_staff_id' => ['in', Staff::getMyStaffIds()]]); |
||||
|
}; |
||||
|
$customer = Customer::where($whereStaff)->where($where)->field('id,name')->order('id desc')->paginate($pageSize, false, ['page' => $pageNumber]); |
||||
|
return json(['list' => $customer->items(), 'total' => $customer->total()]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取合同列表 |
||||
|
*/ |
||||
|
public function getcontract() |
||||
|
{ |
||||
|
$pageSize = input('pageSize'); |
||||
|
$pageNumber = input('pageNumber'); |
||||
|
$customer_id = input('customer_id', 0); |
||||
|
$where = []; |
||||
|
if ($keyValue = $this->request->request("keyValue")) { |
||||
|
$where['id'] = $keyValue; |
||||
|
} |
||||
|
$name = input('name'); |
||||
|
if(!empty($name)){ |
||||
|
$where['name'] = ['like','%'.$name.'%']; |
||||
|
} |
||||
|
$where['check_status'] = 2; |
||||
|
$where['customer_id'] = $customer_id; |
||||
|
$contacts = Contract::where($where)->field('id,name,num')->order('id desc')->paginate($pageSize, false, ['page' => $pageNumber]); |
||||
|
$data = []; |
||||
|
$item=$contacts->items(); |
||||
|
foreach ($item as $v) { |
||||
|
$v->name=$v['num'] . "({$v['name']})"; |
||||
|
} |
||||
|
return json(['list' => $item, 'total' =>$contacts->total()]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取审批人列表 |
||||
|
*/ |
||||
|
public function getstaff(){ |
||||
|
$pageSize = input('pageSize'); |
||||
|
$pageNumber = input('pageNumber'); |
||||
|
$where = []; |
||||
|
if ($keyValue = $this->request->request("keyValue")) { |
||||
|
$where['id'] = ['in',$keyValue]; |
||||
|
} |
||||
|
$name = input('name'); |
||||
|
if(!empty($name)){ |
||||
|
$where['name'] = ['like','%'.$name.'%']; |
||||
|
} |
||||
|
$staff = Staff::where($where)->where(['id'=>['neq',$this->_staff->id]])->field('id,name')->order('id desc')->paginate($pageSize, false, ['page' => $pageNumber]); |
||||
|
return json(['list' => $staff->items(), 'total' => $staff->total()]); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 导入回款信息 |
||||
|
* @return string|void |
||||
|
*/ |
||||
|
public function import() |
||||
|
{ |
||||
|
set_time_limit(0); |
||||
|
if ($this->request->isPost()) { |
||||
|
|
||||
|
$file = $this->request->request('file'); |
||||
|
if (!$file) { |
||||
|
$this->error(__('Parameter %s can not be empty', 'file')); |
||||
|
} |
||||
|
$filePath = ROOT_PATH . 'public' . $file; |
||||
|
if (!is_file($filePath)) { |
||||
|
$this->error(__('No results were found')); |
||||
|
} |
||||
|
//实例化reader |
||||
|
$ext = pathinfo($filePath, PATHINFO_EXTENSION); |
||||
|
if (!in_array($ext, ['csv', 'xls', 'xlsx'])) { |
||||
|
$this->error(__('Unknown data format')); |
||||
|
} |
||||
|
if ($ext === 'csv') { |
||||
|
$file = fopen($filePath, 'r'); |
||||
|
$filePath = tempnam(sys_get_temp_dir(), 'import_csv'); |
||||
|
$fp = fopen($filePath, "w"); |
||||
|
$n = 0; |
||||
|
while ($line = fgets($file)) { |
||||
|
$line = rtrim($line, "\n\r\0"); |
||||
|
$encoding = mb_detect_encoding($line, ['utf-8', 'gbk', 'latin1', 'big5']); |
||||
|
if ($encoding != 'utf-8') { |
||||
|
$line = mb_convert_encoding($line, 'utf-8', $encoding); |
||||
|
} |
||||
|
if ($n == 0 || preg_match('/^".*"$/', $line)) { |
||||
|
fwrite($fp, $line . "\n"); |
||||
|
} else { |
||||
|
fwrite($fp, '"' . str_replace(['"', ','], ['""', '","'], $line) . "\"\n"); |
||||
|
} |
||||
|
$n++; |
||||
|
} |
||||
|
fclose($file) || fclose($fp); |
||||
|
|
||||
|
$reader = new Csv(); |
||||
|
} elseif ($ext === 'xls') { |
||||
|
$reader = new Xls(); |
||||
|
} else { |
||||
|
$reader = new Xlsx(); |
||||
|
} |
||||
|
if (!$PHPExcel = $reader->load($filePath)) { |
||||
|
$this->error(__('Unknown data format')); |
||||
|
} |
||||
|
$currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表 |
||||
|
|
||||
|
$allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号 |
||||
|
$allRow = $currentSheet->getHighestRow(); //取得一共有多少行 |
||||
|
|
||||
|
$maxColumnNumber = Coordinate::columnIndexFromString($allColumn); |
||||
|
//开始读取数据 |
||||
|
$fields = []; |
||||
|
for ($currentRow = 1; $currentRow <= 1; $currentRow++) { |
||||
|
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) { |
||||
|
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue(); |
||||
|
$fields[$currentRow][] = $val; |
||||
|
if ($val instanceof RichText) {//富文本转换字符串 |
||||
|
$val = $val->__toString(); |
||||
|
} |
||||
|
$values[] = is_null($val) ? NULL : trim($val); |
||||
|
} |
||||
|
} |
||||
|
if (!isset($fields[1])) { |
||||
|
$this->error('导入文件第一行没有数据'); |
||||
|
} |
||||
|
$lastid = $this->model->withTrashed()->order('id desc')->value('id'); |
||||
|
|
||||
|
$lastid = $lastid + 5;//防止重复 |
||||
|
|
||||
|
$contractRow = []; |
||||
|
$errorInfo = []; |
||||
|
|
||||
|
$fieldnames = FormField::where(['types' => FormField::RECEIVABLES_TYPE])->column('field', 'name'); |
||||
|
if(!$fieldnames){ |
||||
|
$this->error('请在系统管理->字段管理中保存回款管理表单生成回款导入字段'); |
||||
|
} |
||||
|
$customerNames=Customer::where([])->column('id,owner_staff_id','name'); |
||||
|
$contractNames=Contract::where([])->column('id,name,num','num'); |
||||
|
|
||||
|
$fn = []; |
||||
|
$nums=$this->model->where([])->column('number'); |
||||
|
for ($currentRow = 1; $currentRow <= 1; $currentRow++) { |
||||
|
$values = []; |
||||
|
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) { |
||||
|
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue(); |
||||
|
$values[] = is_null($val) ? '' : $val; |
||||
|
} |
||||
|
foreach ($values as $l) { |
||||
|
|
||||
|
$fn[] = $fieldnames[$l] ?? ''; |
||||
|
} |
||||
|
} |
||||
|
for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) { |
||||
|
$values = []; |
||||
|
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) { |
||||
|
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue(); |
||||
|
if ($val instanceof RichText) {//富文本转换字符串 |
||||
|
$val = $val->__toString(); |
||||
|
} |
||||
|
$values[] = is_null($val) ? NULL : trim($val); |
||||
|
} |
||||
|
$lastid++; |
||||
|
$addReceivables = ['id' => $lastid]; |
||||
|
$customer=isset($customerNames[$values[0]])?$customerNames[$values[0]]:0; |
||||
|
if(empty($customer)){ |
||||
|
$errorInfo[] = "第{$currentRow}行,客户名称不存在;"; |
||||
|
continue; |
||||
|
} |
||||
|
$contract=isset($contractNames[$values[1]])?$contractNames[$values[1]]:0; |
||||
|
if(empty($contract)){ |
||||
|
$errorInfo[] = "第{$currentRow}行,合同编号不存在;"; |
||||
|
continue; |
||||
|
} |
||||
|
$addReceivables['contract_id']=$contract['id']; |
||||
|
$addReceivables['customer_id']=$customer['id']; |
||||
|
$addReceivables['owner_staff_id']=$customer['owner_staff_id']; |
||||
|
$addReceivables['create_staff_id']=$customer['owner_staff_id']; |
||||
|
|
||||
|
foreach ($values as $kv => $value) { |
||||
|
if (!isset($fn[$kv]) || empty($fn[$kv])) { |
||||
|
continue; |
||||
|
} |
||||
|
$addReceivables[$fn[$kv]] = $value; |
||||
|
} |
||||
|
if (empty($addReceivables['number'])) { |
||||
|
$errorInfo[] = "第{$currentRow}行,回款编号不能为空;"; |
||||
|
continue; |
||||
|
} |
||||
|
if (in_array($addReceivables['number'], $nums)) { |
||||
|
$errorInfo[] = "第{$currentRow}行,回款编号`{$addReceivables['number']}`已存在;"; |
||||
|
continue; |
||||
|
} |
||||
|
$contractRow[] = $addReceivables; |
||||
|
} |
||||
|
if (!empty($errorInfo)) { |
||||
|
$this->error(implode(',', $errorInfo)); |
||||
|
} |
||||
|
Db::startTrans(); |
||||
|
try { |
||||
|
$this->model::importReceivables($contractRow); |
||||
|
Db::commit(); |
||||
|
} catch (Exception $e) { |
||||
|
Db::rollback(); |
||||
|
$this->error($e->getMessage()); |
||||
|
} |
||||
|
$this->success('导入成功'); |
||||
|
} |
||||
|
|
||||
|
return $this->view->fetch(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 模板 |
||||
|
*/ |
||||
|
public function template() |
||||
|
{ |
||||
|
$title = [ |
||||
|
'客户名称', |
||||
|
'合同编号', |
||||
|
|
||||
|
]; |
||||
|
$contractData = Form::getDataValue(Form::RECEIVABLES_TYPE); |
||||
|
|
||||
|
foreach ($contractData as $val) { |
||||
|
$title[] = $val['config']['label']; |
||||
|
} |
||||
|
|
||||
|
$file = export_excel($title, [], '回款'); |
||||
|
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); |
||||
|
header('Content-Disposition: attachment;filename=' . $file['fileName']); |
||||
|
header('Cache-Control: max-age=0'); |
||||
|
|
||||
|
$obj = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); |
||||
|
// 以下内容是excel文件的信息描述信息 |
||||
|
$obj->getProperties()->setTitle('导出文件'); //设置标题 |
||||
|
$obj->setActiveSheetIndex(0); |
||||
|
$obj->getActiveSheet()->setTitle('导出文件'); |
||||
|
/* 循环读取每个单元格的数据 */ |
||||
|
$a = 'A'; |
||||
|
$currentSheet = $obj->getActiveSheet(); |
||||
|
foreach ($title as $key => $value) { |
||||
|
//读取工作表1 |
||||
|
// 设置第一行加粗 |
||||
|
$obj->getActiveSheet()->getStyle($a . '1')->getFont()->setBold(true); |
||||
|
//这里是设置单元格的内容 |
||||
|
$currentSheet->getCell($a . '1')->setValue($value); |
||||
|
$a++; |
||||
|
} |
||||
|
|
||||
|
$PHPWriter = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($obj); |
||||
|
|
||||
|
$PHPWriter->save('php://output'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 导出信息 |
||||
|
*/ |
||||
|
public function export() |
||||
|
{ |
||||
|
$this->request->filter(['strip_tags', 'trim']); |
||||
|
$ids = input('ids'); |
||||
|
$isall = input('isall',0); |
||||
|
$wheres = array(); |
||||
|
//导出其中几条 |
||||
|
if (isset($ids)) { |
||||
|
$wheres['id'] = array('in', $ids); |
||||
|
} |
||||
|
//导出全部 |
||||
|
if ($isall == 3) { |
||||
|
unset($wheres['id']); |
||||
|
} |
||||
|
//0:全部 1:我负责的 2:下属负责的 |
||||
|
$type = input('type',0); |
||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); |
||||
|
switch($type){ |
||||
|
case 1: |
||||
|
$staff = Staff::info(); |
||||
|
$wheres['owner_staff_id'] = $staff->id; |
||||
|
break; |
||||
|
case 2: |
||||
|
$wheres['owner_staff_id'] = array('in',Staff::getLowerStaffId()); |
||||
|
break; |
||||
|
default: |
||||
|
$wheres['owner_staff_id'] = array('in',Staff::getMyStaffIds()); |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
$list = $this->model->with(['customer', 'contract','ownerStaff','receivablesOther'])->where($where)->where($wheres)->order($sort, $order)->select(); |
||||
|
$list = collection($list)->toArray(); |
||||
|
|
||||
|
if (!$list) { |
||||
|
$this->error('无导出数据'); |
||||
|
} |
||||
|
$title = [ |
||||
|
'序号', |
||||
|
'客户名称', |
||||
|
'合同名称', |
||||
|
'合同编号', |
||||
|
|
||||
|
'负责人', |
||||
|
'创建时间', |
||||
|
]; |
||||
|
|
||||
|
$dataValue = Form::getDataValue(Form::RECEIVABLES_TYPE); |
||||
|
|
||||
|
foreach ($dataValue as $val) { |
||||
|
$title[] = $val['config']['label']; |
||||
|
} |
||||
|
foreach ($list as $k => $v) { |
||||
|
if($v['receivables_other']){//其他客户 |
||||
|
$other=$v['receivables_other']['otherdata']; |
||||
|
$other=json_decode($other,true); |
||||
|
$v = array_merge($v, $other); |
||||
|
} |
||||
|
$field = array( |
||||
|
$v['id'], |
||||
|
$v['customer']['name'] ?? '', |
||||
|
$v['contract']['name'] ?? '', |
||||
|
$v['contract']['num'] ?? '', |
||||
|
$v['owner_staff']['name'] ?? '', |
||||
|
$v['createtime'], |
||||
|
); |
||||
|
foreach ($dataValue as $val) { |
||||
|
if ($val['component'] == 'uploadImage' || $val['component'] == 'uploadFile') { |
||||
|
$field[] = $v[$val['id'] . '_str'] ?? ''; |
||||
|
} else { |
||||
|
$field[] = ($v[$val['id']] ?? ''); |
||||
|
} |
||||
|
} |
||||
|
$data[] = $field; |
||||
|
} |
||||
|
$file = export_excel($title, $data, '回款'); |
||||
|
if ($file['filePath']) { |
||||
|
$this->success('导出成功', '', $file); |
||||
|
} |
||||
|
$this->error('导出失败'); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue