正在显示
29 个修改的文件
包含
4773 行增加
和
0 行删除
.gitignore
0 → 100644
CONTRIBUTING.md
0 → 100644
LICENSE.txt
0 → 100644
1 | +ThinkCMF遵循Apache2开源协议发布,并提供免费使用。 | ||
2 | +版权所有Copyright © 2013-2018 by ThinkCMF (https://www.thinkcmf.com) | ||
3 | +All rights reserved。 | ||
4 | + | ||
5 | +Apache Licence是著名的非盈利开源组织Apache采用的协议。 | ||
6 | +该协议和BSD类似,鼓励代码共享和尊重原作者的著作权, | ||
7 | +允许代码修改,再作为开源或商业软件发布。需要满足 | ||
8 | +的条件: | ||
9 | +1. 需要给代码的用户一份Apache Licence ; | ||
10 | +2. 如果你修改了代码,需要在被修改的文件中说明; | ||
11 | +3. 在延伸的代码中(修改和有源代码衍生的代码中)需要 | ||
12 | +带有原来代码中的协议,商标,专利声明和其他原来作者规 | ||
13 | +定需要包含的说明; | ||
14 | +4. 如果再发布的产品中包含一个Notice文件,则在Notice文 | ||
15 | +件中需要带有本协议内容。你可以在Notice中增加自己的 | ||
16 | +许可,但不可以表现为对Apache Licence构成更改。 | ||
17 | +具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0 | ||
18 | + | ||
19 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
20 | +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
21 | +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
22 | +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
23 | +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
24 | +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
25 | +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
26 | +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
27 | +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
28 | +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
29 | +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
30 | +POSSIBILITY OF SUCH DAMAGE. |
README.md
0 → 100644
1 | +ThinkCMF 5.0.180525 正式版 | ||
2 | +=============== | ||
3 | + | ||
4 | +### 系列讲座 | ||
5 | +https://www.thinkcmf.com/college.html | ||
6 | + | ||
7 | +### ThinkCMF5主要特性 | ||
8 | +* 基于全新 ThinkPHP5.0开发 | ||
9 | +* 更规范的代码,遵循PSR-2命名规范和PSR-4自动加载规范 | ||
10 | +* 更规范的数据库设计 | ||
11 | +* 前后台完全基于bootstrap3 | ||
12 | +* 增加 api 模块(需单独下载) | ||
13 | +* 支持 composer 管理第三方库 | ||
14 | +* 核心化:独立核心代码包 | ||
15 | +* 应用化:开发者以应用的形式增加项目模模块 | ||
16 | +* 插件化:更强的插件机制,开发者以插件形式扩展功能 | ||
17 | +* 模板化:模板完全傻瓜式,用户无须改动任何代码即可在后台完成模板设计和配置 | ||
18 | +* 增加 URL美化功能,支持别名设置,更简单 | ||
19 | +* 独立的回收站功能,可以管理所有应用临时删除的数据 | ||
20 | +* 统一的资源管理,相同文件只保存一份 | ||
21 | +* 注解式的后台菜单管理功能,方便开发者代码管理后台菜单 | ||
22 | +* 文件存储插件化,默认支持七牛文件存储插件 | ||
23 | +* 模板制作标签化,内置多个cmf标签,方便小白用户 | ||
24 | +* 更人性化的导航标签,可以随意定制 html 结构 | ||
25 | +* 后台首页插件化,用户可以定制的网站后台首页 | ||
26 | + | ||
27 | +### 环境推荐 | ||
28 | +> php5.5+ | ||
29 | + | ||
30 | +> mysql 5.6+ | ||
31 | + | ||
32 | +> 打开rewrite | ||
33 | + | ||
34 | + | ||
35 | +### 最低环境要求 | ||
36 | +> php5.4+ | ||
37 | + | ||
38 | +> mysql 5.5+ (mysql5.1安装时选择utf8编码,不支持表情符) | ||
39 | + | ||
40 | +> 打开rewrite | ||
41 | + | ||
42 | + | ||
43 | +### 运行环境配置教程 | ||
44 | +https://www.thinkcmf.com/topic/1502.html | ||
45 | + | ||
46 | + | ||
47 | +### 自动安装 | ||
48 | +> 之前安装过 cmf5的同学,请手动创建`data/install.lock`文件 | ||
49 | + | ||
50 | +代码已经加入自动安装程序,如果你在安装中有任何问题请提交 issue! | ||
51 | + | ||
52 | +1. public目录做为网站根目录,入口文件在 public/index.php | ||
53 | +2. 配置好网站,请访问http://你的域名 | ||
54 | + | ||
55 | +enjoy your cmf~! | ||
56 | + | ||
57 | +### 系统更新 | ||
58 | +如果您是已经安装过 cmf5的用户,请查看 update 目录下的 sql 升级文件,根据自己的下载的程序版本进行更新 | ||
59 | + | ||
60 | +### API开发 (支持app,小程序,web) | ||
61 | +如果你需要 `api` 开发请下载: | ||
62 | +ThinkCMF5 API :https://github.com/thinkcmf/thinkcmfapi | ||
63 | + | ||
64 | +### 完整版目录结构 | ||
65 | +``` | ||
66 | +thinkcmf 根目录 | ||
67 | +├─api api目录(核心版不带) | ||
68 | +├─app 应用目录 | ||
69 | +│ ├─portal 门户应用目录 | ||
70 | +│ │ ├─config.php 应用配置文件 | ||
71 | +│ │ ├─common.php 模块函数文件 | ||
72 | +│ │ ├─controller 控制器目录 | ||
73 | +│ │ ├─model 模型目录 | ||
74 | +│ │ └─ ... 更多类库目录 | ||
75 | +│ ├─ ... 更多应用 | ||
76 | +│ ├─command.php 命令行工具配置文件 | ||
77 | +│ ├─common.php 应用公共(函数)文件 | ||
78 | +│ ├─config.php 应用(公共)配置文件 | ||
79 | +│ ├─database.php 数据库配置文件 | ||
80 | +│ ├─tags.php 应用行为扩展定义文件 | ||
81 | +│ └─route.php 路由配置文件 | ||
82 | +├─data 数据目录 | ||
83 | +│ ├─conf 动态配置目录 | ||
84 | +│ ├─runtime 应用的运行时目录(可写) | ||
85 | +│ └─ ... 更多 | ||
86 | +├─public WEB 部署目录(对外访问目录) | ||
87 | +│ ├─api api入口目录(核心版不带) | ||
88 | +│ ├─plugins 插件目录 | ||
89 | +│ ├─static 静态资源存放目录(css,js,image) | ||
90 | +│ ├─themes 前后台主题目录 | ||
91 | +│ │ ├─admin_simpleboot3 后台默认主题 | ||
92 | +│ │ └─simpleboot3 前台默认主题 | ||
93 | +│ ├─upload 文件上传目录 | ||
94 | +│ ├─index.php 入口文件 | ||
95 | +│ ├─robots.txt 爬虫协议文件 | ||
96 | +│ ├─router.php 快速测试文件 | ||
97 | +│ └─.htaccess apache重写文件 | ||
98 | +├─simplewind | ||
99 | +│ ├─cmf CMF核心库目录 | ||
100 | +│ ├─extend 扩展类库目录 | ||
101 | +│ ├─thinkphp thinkphp目录 | ||
102 | +│ └─vendor 第三方类库目录(Composer) | ||
103 | +├─composer.json composer 定义文件 | ||
104 | +├─LICENSE.txt 授权说明文件 | ||
105 | +├─README.md README 文件 | ||
106 | +├─think 命令行入口文件 | ||
107 | +``` | ||
108 | + | ||
109 | +### 开发手册 | ||
110 | +http://www.kancloud.cn/thinkcmf/doc | ||
111 | + | ||
112 | +### QQ群: | ||
113 | +`ThinkCMF 官方交流群`:316669417 | ||
114 | + | ||
115 | +`ThinkCMF 高级交流群`:100828313 (付费) | ||
116 | +高级群专属权益: | ||
117 | +第一波:两个后台风格(ThinkCMF官网风格后台主题,蓝色风格后台主题) | ||
118 | +第二波:ThinkCMF5完全开发手册离线版(PDF,EPUB,MOBI格式) | ||
119 | +更多专属权益正在路上... | ||
120 | + | ||
121 | +`ThinkCMF 铲屎官交流群`:415136742 (生活娱乐,为有喵的猿人准备) | ||
122 | + | ||
123 | +### 话题专区 | ||
124 | +http://www.thinkcmf.com/topic/index/index/cat/11.html | ||
125 | + | ||
126 | +### 反馈问题 | ||
127 | +https://github.com/thinkcmf/thinkcmf/issues | ||
128 | + | ||
129 | +### 更新日志 | ||
130 | +#### 5.0.180525 | ||
131 | +* 修复ajax请求普通页面时返回格式为json | ||
132 | +* 优化图片链接生成 | ||
133 | +* 修复插件模板常量地址问题 | ||
134 | +* 修复后台用户注册验证开关错误 #481 | ||
135 | +* 增加后台刷新后保持当前页面的功能 #475 | ||
136 | +* 取消用户名注册和绑定功能 | ||
137 | +* 优化无限滚动jquery插件 | ||
138 | + | ||
139 | +#### 5.0.180508 | ||
140 | +* 修复用户注册问题 | ||
141 | +* 优化缓存清理,防止删除日志文件 | ||
142 | + | ||
143 | +#### 5.0.180501 | ||
144 | +[核心] | ||
145 | +* 升级TP到5.0.19,增强安全性 | ||
146 | +* 修复模板设计数组编辑验证规则不生效 #440 | ||
147 | +* 修复后台登录失效后iframe里加载首页 | ||
148 | +* 修复七牛插件上传云存储文件没有后缀名问题#437 | ||
149 | +* 修复删除评论时的错误文案提示 #443 | ||
150 | +* 修复ueditor漏洞#431 | ||
151 | +* 修复PHP7.2下后台清除报错 | ||
152 | +* 修复前台账号绑定无法获取mobile、email验证码 #418 | ||
153 | +* 修复百度编辑器大附件上传问题 | ||
154 | +* 修复百度编辑器大视频文件上传问题 | ||
155 | +* 升级font awesome到4.7.0 | ||
156 | + | ||
157 | +[门户应用] | ||
158 | +* 修复文章分类修改层级后子分类层级不更新问题 | ||
159 | +* 优化 portal:articles 标签field,order 属性支持 php 变量 | ||
160 | +* 修复文章分类别名设置为纯数字,路由生成错误,无法访问。 #438 | ||
161 | +* 增加页面相册和附件功能 #449 | ||
162 | + | ||
163 | +#### 5.0.180123 | ||
164 | +[核心] | ||
165 | +* 增加小程序管理插件 | ||
166 | +* 增加插件后台首页左侧菜单显示 | ||
167 | +* 增加 themes 根命名空间 | ||
168 | +* 增加模板设计图片模板变量取消功能 | ||
169 | +* 增加插件自定义处理配置功能 | ||
170 | +* 增加插件后台权限管理功能 | ||
171 | +* 增加后台模板切换 | ||
172 | +* 增加直传云存储功能 | ||
173 | +* 增强导航和子导航标签,自定义更随意 | ||
174 | +* 增加before_content,fetch_upload_view,log_write_done,switch_admin_theme钩子 | ||
175 | +* 增加PluginAdminBaseController基类 | ||
176 | +* 增加系统钩子同步 | ||
177 | +* 增加插件中可使用$site_info变量 | ||
178 | +* 增加 xml 生成函数 | ||
179 | +* 增加插件设置上传文件组件 | ||
180 | +* 优化数字验证码日志写入增加过期时间配置 | ||
181 | +* 优化数字验证码逻辑,增加数字验证码发送图片验证码,【升级时注意界面逻辑】 | ||
182 | +* 优化验证码生成功能,可增加验证码插件管理验证码生成 | ||
183 | +* 优化钩子插件管理 | ||
184 | +* 优化插件注册机制 | ||
185 | +* 优化后台首页菜单加载 | ||
186 | +* 修复模板管理变量数据为array时删除出错 #392 | ||
187 | +* 修复后台管理搜索翻页时条件丢失问题 #366 | ||
188 | +* 修复删除第三方用户时报错 #368 | ||
189 | +* 修复在使用cdn加速js时后台文章编辑器时无法加载编辑器配置 | ||
190 | +* 修复模板设计模板变量file类型不支持上传 #136 | ||
191 | +* 修复用户行为周期设置无效 #382 | ||
192 | +* 修复个人信息编辑签名验证问题 | ||
193 | +* 修复用户生日早于1970年报错 | ||
194 | +* 修复地址坐标选择搜索后无法确定坐标问题 | ||
195 | +* 优化IE8,9下的兼容问题 | ||
196 | +* 优化前台未登录时跳转方式 | ||
197 | + | ||
198 | +[安装程序] | ||
199 | +* 增加安装时管理员密码长度限制 #334 | ||
200 | +* 增加安装时检查 rewrite设置 | ||
201 | +* 增加安装时 innodb 检测 | ||
202 | +* 更正PHP版本要求 | ||
203 | + | ||
204 | +[门户应用] | ||
205 | +* 优化portal:articles标签可在模板里设置分页参数和样式 | ||
206 | +* 优化portal:articles标签所有属性都支持PHP变量 | ||
207 | +* 优化标签控制器支持标签名 | ||
208 | +* 增加portal:tagArticles标签 | ||
209 | +* 取消文章列表用户关联查询 | ||
210 | +* 修复文章多分类进文章列表文章重复问题 | ||
211 | + | ||
212 | + | ||
213 | +#### 5.0.170927 | ||
214 | +[核心] | ||
215 | +* 增加是否开放注册设置 | ||
216 | +* 增加已经安装模板文件检测是否已经删除功能 | ||
217 | +* 增加模板卸载风险提示 | ||
218 | +* 增加钩子同步功能 | ||
219 | +* 增加用户操作同步功能 #291 | ||
220 | +* 增加网站信息【$site_info】变量,可以在插件中使用 #310 | ||
221 | +* 修复添加管理员不能登录 #110 | ||
222 | +* 优化 admin.js | ||
223 | +* 优化后台模板设计排版 | ||
224 | +* 优化后台加密码设置 | ||
225 | +* 返回按钮统一优化 | ||
226 | +* 优化 url 美化时规划选择 | ||
227 | +* 修复`api`模块缺少函数报错 | ||
228 | +* 修复回收站还原提示错误 #111 | ||
229 | +* 修复原始网址和显示网址同时有参数的情况下,两个参数值相同的时候不能解析URL | ||
230 | +* 修复模板设计数组编辑功能缺失 | ||
231 | +* 修复后台登录在双核浏览器下会使用 IE 内核问题#168 | ||
232 | +* 修复模板widget只有数组时,后台设计保存时报错 | ||
233 | +* 修复日期选择在windows firefox下报错 | ||
234 | +* 修复模板设计数据源页面清空链接错误 | ||
235 | +* 修复后台模板设计,json文件中的数组数据,不能正常显示 #222 | ||
236 | +* 修复`cmf\lib\Auth\check`方法逻辑问题 #252 | ||
237 | +* 修复后台用户登录自动退出后iframe页跳转到首页的问题 | ||
238 | +* 修复用户个人资料修改问题 | ||
239 | +* 修复绑定手机号和绑定邮箱号惟一性提示信息错 | ||
240 | + | ||
241 | +[安装程序] | ||
242 | +* 更改安装时数据库默认为127.0.0.1 | ||
243 | +* 优化安装时链接生成 | ||
244 | + | ||
245 | +[门户应用] | ||
246 | +* 增加前台文章控制器默认分类指定 | ||
247 | +* 增加后台文章列表所在分类列 | ||
248 | +* 增加后台文章分类必须指定分类验证 | ||
249 | +* 增加 portal:articles 标签 limit可以设置变量 | ||
250 | +* 增加模板设计页面数据源 | ||
251 | +* 完善 ApiService获取指定分类下的所有子分类方法 | ||
252 | +* 增加portal:categories,portal:subCategories,portal:allSubCategories标签 | ||
253 | +* 增加文章、页面、分类模板选择时模板文件名称查看 | ||
254 | +* 增加文章保存钩子 | ||
255 | +* 优化指定分类下所有子分类获取方法 | ||
256 | +* 修复文章分类管理中不保存选择的模板 #107 | ||
257 | +* 修复面包屑标签 self属性无法识别 false | ||
258 | +* 修复后台编辑文件会覆盖原作者ID #175 | ||
259 | +* 修复后台文章保存后排序变化问题 | ||
260 | +* 修复添加文章分类时 path 没数据问题 | ||
261 | + | ||
262 | +[升级指导] | ||
263 | +https://www.kancloud.cn/thinkcmf/doc/327443 | ||
264 | + | ||
265 | +#### 5.0.170607 | ||
266 | +[核心] | ||
267 | +* 删除 app/common.php | ||
268 | +* 规范 admin.js frontend.js函数名 | ||
269 | +* 更改后台模板设计的模板文件列表排序规则为从小到大排序 | ||
270 | +* 增加模板切换钩子,方便开发者实现复杂的模板切换功能 | ||
271 | +* 增加插件作者和演示信息 | ||
272 | +* 增加数字验证码模板编辑功能 | ||
273 | +* 增加模板变量编辑控件color | ||
274 | +* 增加插件配置组件时间,图片,地理位置,颜色 | ||
275 | +* 优化模板配置更新 | ||
276 | +* 优化文件上传,检查已经上传文件是否存在,不存在重新上传 | ||
277 | +* 修复插件增加新配置时报错 | ||
278 | +* 修复模板变量 rule 规则存在,但没有规则时模板设计保存会报错 | ||
279 | +* 修复后台清除缓存后url生成不美化 | ||
280 | +* 修复模板设计一个页面有多个数组编辑问题 | ||
281 | +* 修复cdn设置不生效 | ||
282 | +* 修复后台菜单添加子菜单不选择上级问题 | ||
283 | +* 修复后台可能多个滚动条 | ||
284 | +* 修复后台添加、编辑角色一处文字错误 | ||
285 | +* 修复插件更新时不更新新增的钩子 | ||
286 | + | ||
287 | +[门户应用] | ||
288 | +* 完善前台模板钩子 | ||
289 | +* 完善文章标签功能 | ||
290 | +* 增加前台模板手机注册关闭开关 | ||
291 | +* 优化文章后台文章分类链接生成 | ||
292 | +* 修复ff下文章相册图片替换和删除问题 | ||
293 | +* 修复文章分类排序功能 | ||
294 | + | ||
295 | +#### 5.0.170520 | ||
296 | +[核心] | ||
297 | +* 完善插件后台管理 | ||
298 | +* 后台登录插件化 | ||
299 | +* 后台首页插件化 | ||
300 | +* 文件存储插件化 | ||
301 | +* 增加 URL 美化功能 | ||
302 | +* 增加后台加密码功能 | ||
303 | +* 增加用户修改头像 | ||
304 | +* 增加插件设置表单验证 | ||
305 | +* 增加前台后台通用语言包 | ||
306 | +* 增加编辑器里上传文件链接替换 | ||
307 | +* 增加应用 command.php 配置文件 | ||
308 | +* 增加后台管理员添加编辑用户名,邮箱惟一性验证 | ||
309 | +* 优化安装程序 | ||
310 | +* 优化上传文件 | ||
311 | +* 优化后台首页 | ||
312 | +* 优化回收站 | ||
313 | +* 优化插件启用禁用 | ||
314 | +* 优化小屏下后台首页不兼容问题 | ||
315 | +* 优化后台图片查看 | ||
316 | +* 修复后台菜单编辑不生效 | ||
317 | +* 修复幻灯片添加不显示问题 | ||
318 | +* 修复导航数据源数据返回为空时报错 | ||
319 | +* 修复 pathinfo 模式下后台本站用户默认头像不显示问题 | ||
320 | +* 修复后台 cdn 不能设置 | ||
321 | +* 合并asset应用到 user | ||
322 | + | ||
323 | +[门户应用] | ||
324 | +* 增加文章收藏功能 | ||
325 | +* 增加文章点赞限制,一个用户只能点赞一次 | ||
326 | +* 增加文章分类缩略图 | ||
327 | +* 优化文章分类管理删除 | ||
328 | +* 优化文章页和页面页内容图片样式问题 | ||
329 | +* 修复文章添加编辑默认图片错误 | ||
330 | +* 修复分类下没有文章时报错 | ||
331 | +* 修复页面模板设置无效 | ||
332 | +* 修复页面删除后仍可以访问 | ||
333 | + | ||
334 | +#### 5.0.170505 | ||
335 | +[核心] | ||
336 | +* 完善用户注册流程 | ||
337 | +* 完善插件功能 | ||
338 | +* 增加手机验证码发送钩子 | ||
339 | +* 增加手机验证码发送演示插件 | ||
340 | +* 增加用户邮箱绑定 | ||
341 | +* 增加用户手机绑定 | ||
342 | +* 增加常用模板钩子 | ||
343 | +* 增加模板设计图片上传 | ||
344 | +* 增加用户密码修改 | ||
345 | +* 增加用户收藏功能 | ||
346 | +* 增加导航标签,子导航标签增加 `max-level` 设置 | ||
347 | +* 修复邮箱验证码发送 | ||
348 | +* 修复windows下获取模板数据时模板文件路径问题 | ||
349 | +* 修复单文件,多文件上传 | ||
350 | +* 修复后台首页用户昵称一直显示admin | ||
351 | +* 修复 `navigation`,`subNavigation` 标签两个以上不能同时使用问题 | ||
352 | +* 修复 console 模式报错 | ||
353 | +* 取消前台有错误时界面刷新 | ||
354 | + | ||
355 | +[门户应用] | ||
356 | +* 增加文章附件功能 | ||
357 | +* 优化文章相册 | ||
358 | + | ||
359 | +#### 5.0.170422 | ||
360 | +[核心] | ||
361 | +* 完善幻灯片 | ||
362 | +* 完善后台控制器方法注释 | ||
363 | +* 增加调试模式下实时更新模板配置 | ||
364 | +* 增加友情链接图片上传 | ||
365 | +* 增加应用公共语言包功能 | ||
366 | +* 增加资源管理 | ||
367 | +* 增加模板设计数据源层级关系 | ||
368 | +* 更新jQuery Form版本 | ||
369 | +* 增加后台菜单类型是否有界面区分 | ||
370 | +* 增加权限验证时权限规则里没有的规则不用验证 | ||
371 | +* 增加前台网站信息获取 | ||
372 | +* 优化后台菜单导入 | ||
373 | +* 统一排序规则,按从小到大排序 | ||
374 | +* 修复后台模板管理点更新提示卸载 | ||
375 | +* 修复标签`NavigationMenu` | ||
376 | +* 修复菜单导入时未添加权限规则 | ||
377 | +* 修复`navigationFolder`设置多个子菜单后会多循环数据 | ||
378 | +* 修复部分代码php5.4下不兼容 | ||
379 | +* 修复后台菜单不能添加编辑 | ||
380 | + | ||
381 | +[门户应用] | ||
382 | +* 完全独立门户应用 | ||
383 | +* 完善后台页面管理 | ||
384 | +* 完善面包屑标签`breadcrumb` | ||
385 | +* 完善文章分类管理 | ||
386 | +* 完善文章管理 | ||
387 | +* 修复文章分类`path`更新 | ||
388 | +* 优化文章列表标签`articles` | ||
389 | +* 优化后台文章分类选择 | ||
390 | +* 增加前台文章点赞功能 | ||
391 | +* 增加前台文章搜索功能 | ||
392 | +* 增加文章列表分页总数获取 | ||
393 | + | ||
394 | +#### 5.0.170401 | ||
395 | +* 完善文件上传 | ||
396 | +* 增加回收站功能 | ||
397 | +* 完善友情链接 | ||
398 | +* 优化网站设置 | ||
399 | +* 增加后台登陆验证码 | ||
400 | +* 修复后台用户密码修改 | ||
401 | +* 修复用户管理-本站用户头像不显示 | ||
402 | +* 完善前台用户登录注册 | ||
403 | +* 增加后台菜单导入 | ||
404 | +* 修复后台菜单列表排序 | ||
405 | +* 完善导航 | ||
406 | +* 增加插件钩子管理 | ||
407 | +* 完善前台模板 | ||
408 | + | ||
409 | + |
_config.yml
0 → 100644
1 | +theme: jekyll-theme-cayman |
app/admin/annotation/AdminMenuAnnotation.php
0 → 100644
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: 老猫 <zxxjjforever@163.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\annotation; | ||
12 | + | ||
13 | +use mindplay\annotations\Annotation; | ||
14 | + | ||
15 | +/** | ||
16 | + * Specifies validation of a string, requiring a minimum and/or maximum length. | ||
17 | + * | ||
18 | + * @usage('method'=>true, 'inherited'=>true, 'multiple'=>false) | ||
19 | + */ | ||
20 | +class AdminMenuAnnotation extends Annotation | ||
21 | +{ | ||
22 | + public $remark = ''; | ||
23 | + | ||
24 | + public $icon = ''; | ||
25 | + | ||
26 | + public $name = ''; | ||
27 | + | ||
28 | + public $param = ''; | ||
29 | + | ||
30 | + public $parent = ''; | ||
31 | + | ||
32 | + public $display = false; | ||
33 | + | ||
34 | + public $order = 10000; | ||
35 | + | ||
36 | + public $hasView = true; | ||
37 | + | ||
38 | + /** | ||
39 | + * Initialize the annotation. | ||
40 | + * @param array $properties | ||
41 | + */ | ||
42 | + public function initAnnotation(array $properties) | ||
43 | + { | ||
44 | + parent::initAnnotation($properties); | ||
45 | + } | ||
46 | +} |
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: 老猫 <zxxjjforever@163.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\annotation; | ||
12 | + | ||
13 | +use mindplay\annotations\AnnotationException; | ||
14 | +use mindplay\annotations\Annotation; | ||
15 | + | ||
16 | +/** | ||
17 | + * Specifies validation of a string, requiring a minimum and/or maximum length. | ||
18 | + * | ||
19 | + * @usage('class'=>true, 'inherited'=>true, 'multiple'=>true) | ||
20 | + */ | ||
21 | +class AdminMenuRootAnnotation extends Annotation | ||
22 | +{ | ||
23 | + /** | ||
24 | + * @var int|null Minimum string length (or null, if no minimum) | ||
25 | + */ | ||
26 | + public $remark = ''; | ||
27 | + | ||
28 | + /** | ||
29 | + * @var int|null Maximum string length (or null, if no maximum) | ||
30 | + */ | ||
31 | + public $icon = ''; | ||
32 | + | ||
33 | + /** | ||
34 | + * @var int|null Minimum string length (or null, if no minimum) | ||
35 | + */ | ||
36 | + public $name = ''; | ||
37 | + | ||
38 | + public $action = ''; | ||
39 | + | ||
40 | + public $param = ''; | ||
41 | + | ||
42 | + public $parent = ''; | ||
43 | + | ||
44 | + public $display = false; | ||
45 | + | ||
46 | + public $order = 10000; | ||
47 | + | ||
48 | + /** | ||
49 | + * Initialize the annotation. | ||
50 | + * @param array $properties | ||
51 | + */ | ||
52 | + public function initAnnotation(array $properties) | ||
53 | + { | ||
54 | + parent::initAnnotation($properties); | ||
55 | + } | ||
56 | +} |
app/admin/api/NavApi.php
0 → 100644
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: 老猫 <thinkcmf@126.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\api; | ||
12 | + | ||
13 | +use app\admin\model\NavModel; | ||
14 | + | ||
15 | +class NavApi | ||
16 | +{ | ||
17 | + // 导航模板数据源 用于模板设计 | ||
18 | + public function index($param = []) | ||
19 | + { | ||
20 | + $navModel = new NavModel(); | ||
21 | + | ||
22 | + $where = []; | ||
23 | + | ||
24 | + if (!empty($param['keyword'])) { | ||
25 | + $where['name'] = ['like', "%{$param['keyword']}%"]; | ||
26 | + } | ||
27 | + | ||
28 | + return $navModel->where($where)->select(); | ||
29 | + } | ||
30 | + | ||
31 | +} |
app/admin/api/NavMenuApi.php
0 → 100644
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: 老猫 <thinkcmf@126.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\api; | ||
12 | + | ||
13 | +use app\admin\model\NavMenuModel; | ||
14 | + | ||
15 | +class NavMenuApi | ||
16 | +{ | ||
17 | + // 导航菜单模板数据源 用于模板设计 | ||
18 | + public function index($param = []) | ||
19 | + { | ||
20 | + $navMenuModel = new NavMenuModel(); | ||
21 | + | ||
22 | + $where = []; | ||
23 | + | ||
24 | + if (!empty($param['keyword'])) { | ||
25 | + $where['name'] = ['like', "%{$param['keyword']}%"]; | ||
26 | + } | ||
27 | + if (!empty($param['id'])) { | ||
28 | + $where['nav_id'] = $param['id']; | ||
29 | + } | ||
30 | + | ||
31 | + return $navMenuModel->where($where)->select(); | ||
32 | + } | ||
33 | + | ||
34 | +} |
app/admin/api/SlideApi.php
0 → 100644
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: 老猫 <thinkcmf@126.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\api; | ||
12 | + | ||
13 | +use app\admin\model\SlideModel; | ||
14 | + | ||
15 | +class SlideApi | ||
16 | +{ | ||
17 | + /** | ||
18 | + * 幻灯片模板数据源 用于模板设计 | ||
19 | + * @param array $param | ||
20 | + * @return false|\PDOStatement|string|\think\Collection | ||
21 | + */ | ||
22 | + public function index($param = []) | ||
23 | + { | ||
24 | + $slideModel = new SlideModel(); | ||
25 | + | ||
26 | + $where = []; | ||
27 | + | ||
28 | + if (!empty($param['keyword'])) { | ||
29 | + $where['name'] = ['like', "%{$param['keyword']}%"]; | ||
30 | + } | ||
31 | + | ||
32 | + //返回的数据必须是数据集或数组,item里必须包括id,name,如果想表示层级关系请加上 parent_id | ||
33 | + return $slideModel->where($where)->select(); | ||
34 | + } | ||
35 | + | ||
36 | +} |
app/admin/controller/DialogController.php
0 → 100644
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: 老猫 <zxxjjforever@163.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\controller; | ||
12 | + | ||
13 | +use cmf\controller\AdminBaseController; | ||
14 | + | ||
15 | +class DialogController extends AdminBaseController | ||
16 | +{ | ||
17 | + public function _initialize() | ||
18 | + { | ||
19 | + | ||
20 | + } | ||
21 | + | ||
22 | + public function map() | ||
23 | + { | ||
24 | + $location = $this->request->param('location'); | ||
25 | + $location = explode(',', $location); | ||
26 | + $lng = empty($location[0]) ? 116.424966 : $location[0]; | ||
27 | + $lat = empty($location[1]) ? 39.907851 : $location[1]; | ||
28 | + | ||
29 | + $this->assign(['lng' => $lng, 'lat' => $lat]); | ||
30 | + return $this->fetch(); | ||
31 | + } | ||
32 | + | ||
33 | +} |
app/admin/controller/GetPrizeController.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Administrator | ||
5 | + * Date: 2018/6/9 | ||
6 | + * Time: 16:05 | ||
7 | + */ | ||
8 | +namespace app\admin\controller; | ||
9 | +use api\common\model\CommonModel; | ||
10 | +use app\admin\model\GetPrizeModel; | ||
11 | +use cmf\controller\AdminBaseController; | ||
12 | +use Think\Db; | ||
13 | +use Think\Model; | ||
14 | + | ||
15 | + | ||
16 | + | ||
17 | + | ||
18 | +class GetPrizeController extends AdminBaseController{ | ||
19 | + //index方法 | ||
20 | + public function index() | ||
21 | + { | ||
22 | + $param = $this->request->param(); | ||
23 | + | ||
24 | + $getprizeModel=new GetPrizeModel(); | ||
25 | + $lists=$getprizeModel->GetPrize($param); | ||
26 | + | ||
27 | + $this->assign('start_time', isset($param['start_time']) ? $param['start_time'] : ''); | ||
28 | + $this->assign('end_time', isset($param['end_time']) ? $param['end_time'] : ''); | ||
29 | + $this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : ''); | ||
30 | + $this->assign('list',$lists); | ||
31 | + return $this->fetch(); | ||
32 | + } | ||
33 | + //核销 | ||
34 | + public function hexiao() | ||
35 | + { | ||
36 | + $id = $this->request->param('id', 0, 'intval'); | ||
37 | + $status=1; | ||
38 | + $create_time=time(); | ||
39 | + $getprizeModel=new GetPrizeModel(); | ||
40 | + $post=$getprizeModel->hexiao($id,$status,$create_time); | ||
41 | + if ($post){ | ||
42 | + $this->success('核销成功','index'); | ||
43 | + } | ||
44 | + } | ||
45 | + //获奖信息删除 | ||
46 | + public function deleteGetPrize() | ||
47 | + { | ||
48 | + $id = $this->request->param('id', 0, 'intval'); | ||
49 | + $getprizeModel=new GetPrizeModel(); | ||
50 | + $result=$getprizeModel->deleteGetPrize($id); | ||
51 | + if ($result){ | ||
52 | + return $this->success('删除成功'); | ||
53 | + } | ||
54 | + } | ||
55 | +} |
app/admin/controller/HookController.php
0 → 100644
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: 老猫 <zxxjjforever@163.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\controller; | ||
12 | + | ||
13 | +use cmf\controller\AdminBaseController; | ||
14 | +use app\admin\model\HookModel; | ||
15 | +use app\admin\model\PluginModel; | ||
16 | +use app\admin\model\HookPluginModel; | ||
17 | +use think\Db; | ||
18 | + | ||
19 | +/** | ||
20 | + * Class HookController 钩子管理控制器 | ||
21 | + * @package app\admin\controller | ||
22 | + */ | ||
23 | +class HookController extends AdminBaseController | ||
24 | +{ | ||
25 | + /** | ||
26 | + * 钩子管理 | ||
27 | + * @adminMenu( | ||
28 | + * 'name' => '钩子管理', | ||
29 | + * 'parent' => 'admin/Plugin/default', | ||
30 | + * 'display'=> true, | ||
31 | + * 'hasView'=> true, | ||
32 | + * 'order' => 10000, | ||
33 | + * 'icon' => '', | ||
34 | + * 'remark' => '钩子管理', | ||
35 | + * 'param' => '' | ||
36 | + * ) | ||
37 | + */ | ||
38 | + public function index() | ||
39 | + { | ||
40 | + $hookModel = new HookModel(); | ||
41 | + $hooks = $hookModel->select(); | ||
42 | + $this->assign('hooks', $hooks); | ||
43 | + return $this->fetch(); | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * 钩子插件管理 | ||
48 | + * @adminMenu( | ||
49 | + * 'name' => '钩子插件管理', | ||
50 | + * 'parent' => 'index', | ||
51 | + * 'display'=> false, | ||
52 | + * 'hasView'=> true, | ||
53 | + * 'order' => 10000, | ||
54 | + * 'icon' => '', | ||
55 | + * 'remark' => '钩子插件管理', | ||
56 | + * 'param' => '' | ||
57 | + * ) | ||
58 | + */ | ||
59 | + public function plugins() | ||
60 | + { | ||
61 | + $hook = $this->request->param('hook'); | ||
62 | + $pluginModel = new PluginModel(); | ||
63 | + $plugins = $pluginModel->field('a.*,b.hook,b.plugin,b.list_order,b.status as hook_plugin_status,b.id as hook_plugin_id') | ||
64 | + ->alias('a')->join('__HOOK_PLUGIN__ b', 'a.name = b.plugin') | ||
65 | + ->where('b.hook', $hook) | ||
66 | + ->order('b.list_order asc') | ||
67 | + ->select(); | ||
68 | + $this->assign('plugins', $plugins); | ||
69 | + return $this->fetch(); | ||
70 | + } | ||
71 | + | ||
72 | + /** | ||
73 | + * 钩子插件排序 | ||
74 | + * @adminMenu( | ||
75 | + * 'name' => '钩子插件排序', | ||
76 | + * 'parent' => 'index', | ||
77 | + * 'display'=> false, | ||
78 | + * 'hasView'=> false, | ||
79 | + * 'order' => 10000, | ||
80 | + * 'icon' => '', | ||
81 | + * 'remark' => '钩子插件排序', | ||
82 | + * 'param' => '' | ||
83 | + * ) | ||
84 | + */ | ||
85 | + public function pluginListOrder() | ||
86 | + { | ||
87 | + $hookPluginModel = new HookPluginModel(); | ||
88 | + parent::listOrders($hookPluginModel); | ||
89 | + | ||
90 | + $this->success("排序更新成功!"); | ||
91 | + } | ||
92 | + | ||
93 | + /** | ||
94 | + * 同步钩子 | ||
95 | + * @adminMenu( | ||
96 | + * 'name' => '同步钩子', | ||
97 | + * 'parent' => 'index', | ||
98 | + * 'display'=> false, | ||
99 | + * 'hasView'=> true, | ||
100 | + * 'order' => 10000, | ||
101 | + * 'icon' => '', | ||
102 | + * 'remark' => '同步钩子', | ||
103 | + * 'param' => '' | ||
104 | + * ) | ||
105 | + */ | ||
106 | + public function sync() | ||
107 | + { | ||
108 | + | ||
109 | + $apps = cmf_scan_dir(APP_PATH . '*', GLOB_ONLYDIR); | ||
110 | + | ||
111 | + array_push($apps, 'cmf'); | ||
112 | + | ||
113 | + foreach ($apps as $app) { | ||
114 | + if ($app == 'cmf') { | ||
115 | + $hookConfigFile = CMF_PATH . '/hooks.php'; | ||
116 | + } else { | ||
117 | + $hookConfigFile = APP_PATH . $app . '/hooks.php'; | ||
118 | + } | ||
119 | + | ||
120 | + if (file_exists($hookConfigFile)) { | ||
121 | + $hooksInFile = include $hookConfigFile; | ||
122 | + | ||
123 | + foreach ($hooksInFile as $hookName => $hook) { | ||
124 | + | ||
125 | + $hook['type'] = empty($hook['type']) ? 2 : $hook['type']; | ||
126 | + | ||
127 | + if (!in_array($hook['type'], [2, 3, 4]) && $app != 'cmf') { | ||
128 | + $hook['type'] = 2; | ||
129 | + } | ||
130 | + | ||
131 | + $findHook = Db::name('hook')->where(['hook' => $hookName])->count(); | ||
132 | + | ||
133 | + $hook['app'] = $app; | ||
134 | + | ||
135 | + if ($findHook > 0) { | ||
136 | + Db::name('hook')->where(['hook' => $hookName])->strict(false)->field(true)->update($hook); | ||
137 | + } else { | ||
138 | + $hook['hook'] = $hookName; | ||
139 | + Db::name('hook')->insert($hook); | ||
140 | + } | ||
141 | + } | ||
142 | + } | ||
143 | + } | ||
144 | + | ||
145 | + return $this->fetch(); | ||
146 | + } | ||
147 | + | ||
148 | + | ||
149 | +} |
app/admin/controller/IndexController.php
0 → 100644
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: 小夏 < 449134904@qq.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\controller; | ||
12 | + | ||
13 | +use cmf\controller\AdminBaseController; | ||
14 | +use think\Db; | ||
15 | +use app\admin\model\AdminMenuModel; | ||
16 | + | ||
17 | +class IndexController extends AdminBaseController | ||
18 | +{ | ||
19 | + | ||
20 | + public function _initialize() | ||
21 | + { | ||
22 | + $adminSettings = cmf_get_option('admin_settings'); | ||
23 | + if (empty($adminSettings['admin_password']) || $this->request->path() == $adminSettings['admin_password']) { | ||
24 | + $adminId = cmf_get_current_admin_id(); | ||
25 | + if (empty($adminId)) { | ||
26 | + session("__LOGIN_BY_CMF_ADMIN_PW__", 1);//设置后台登录加密码 | ||
27 | + } | ||
28 | + } | ||
29 | + | ||
30 | + parent::_initialize(); | ||
31 | + } | ||
32 | + | ||
33 | + /** | ||
34 | + * 后台首页 | ||
35 | + */ | ||
36 | + public function index() | ||
37 | + { | ||
38 | + $adminMenuModel = new AdminMenuModel(); | ||
39 | + $menus = cache('admin_menus_' . cmf_get_current_admin_id(), '', null, 'admin_menus'); | ||
40 | + | ||
41 | + if (empty($menus)) { | ||
42 | + $menus = $adminMenuModel->menuTree(); | ||
43 | + cache('admin_menus_' . cmf_get_current_admin_id(), $menus, null, 'admin_menus'); | ||
44 | + } | ||
45 | + | ||
46 | + $this->assign("menus", $menus); | ||
47 | + | ||
48 | + | ||
49 | + $result = Db::name('AdminMenu')->order(["app" => "ASC", "controller" => "ASC", "action" => "ASC"])->select(); | ||
50 | + $menusTmp = array(); | ||
51 | + foreach ($result as $item){ | ||
52 | + //去掉/ _ 全部小写。作为索引。 | ||
53 | + $indexTmp = $item['app'].$item['controller'].$item['action']; | ||
54 | + $indexTmp = preg_replace("/[\\/|_]/","",$indexTmp); | ||
55 | + $indexTmp = strtolower($indexTmp); | ||
56 | + $menusTmp[$indexTmp] = $item; | ||
57 | + } | ||
58 | + $this->assign("menus_js_var",json_encode($menusTmp)); | ||
59 | + | ||
60 | + //$admin = Db::name("user")->where('id', cmf_get_current_admin_id())->find(); | ||
61 | + //$this->assign('admin', $admin); | ||
62 | + return $this->fetch(); | ||
63 | + } | ||
64 | +} |
app/admin/controller/LinkController.php
0 → 100644
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: 小夏 < 449134904@qq.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\controller; | ||
12 | + | ||
13 | +use cmf\controller\AdminBaseController; | ||
14 | +use app\admin\model\LinkModel; | ||
15 | + | ||
16 | +class LinkController extends AdminBaseController | ||
17 | +{ | ||
18 | + protected $targets = ["_blank" => "新标签页打开", "_self" => "本窗口打开"]; | ||
19 | + | ||
20 | + /** | ||
21 | + * 友情链接管理 | ||
22 | + * @adminMenu( | ||
23 | + * 'name' => '友情链接', | ||
24 | + * 'parent' => 'admin/Setting/default', | ||
25 | + * 'display'=> true, | ||
26 | + * 'hasView'=> true, | ||
27 | + * 'order' => 50, | ||
28 | + * 'icon' => '', | ||
29 | + * 'remark' => '友情链接管理', | ||
30 | + * 'param' => '' | ||
31 | + * ) | ||
32 | + */ | ||
33 | + public function index() | ||
34 | + { | ||
35 | + $linkModel = new LinkModel(); | ||
36 | + $links = $linkModel->select(); | ||
37 | + $this->assign('links', $links); | ||
38 | + | ||
39 | + return $this->fetch(); | ||
40 | + } | ||
41 | + | ||
42 | + /** | ||
43 | + * 添加友情链接 | ||
44 | + * @adminMenu( | ||
45 | + * 'name' => '添加友情链接', | ||
46 | + * 'parent' => 'index', | ||
47 | + * 'display'=> false, | ||
48 | + * 'hasView'=> true, | ||
49 | + * 'order' => 10000, | ||
50 | + * 'icon' => '', | ||
51 | + * 'remark' => '添加友情链接', | ||
52 | + * 'param' => '' | ||
53 | + * ) | ||
54 | + */ | ||
55 | + public function add() | ||
56 | + { | ||
57 | + $this->assign('targets', $this->targets); | ||
58 | + return $this->fetch(); | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * 添加友情链接提交保存 | ||
63 | + * @adminMenu( | ||
64 | + * 'name' => '添加友情链接提交保存', | ||
65 | + * 'parent' => 'index', | ||
66 | + * 'display'=> false, | ||
67 | + * 'hasView'=> false, | ||
68 | + * 'order' => 10000, | ||
69 | + * 'icon' => '', | ||
70 | + * 'remark' => '添加友情链接提交保存', | ||
71 | + * 'param' => '' | ||
72 | + * ) | ||
73 | + */ | ||
74 | + public function addPost() | ||
75 | + { | ||
76 | + $data = $this->request->param(); | ||
77 | + $linkModel = new LinkModel(); | ||
78 | + $result = $linkModel->validate(true)->allowField(true)->save($data); | ||
79 | + if ($result === false) { | ||
80 | + $this->error($linkModel->getError()); | ||
81 | + } | ||
82 | + | ||
83 | + $this->success("添加成功!", url("link/index")); | ||
84 | + } | ||
85 | + | ||
86 | + /** | ||
87 | + * 编辑友情链接 | ||
88 | + * @adminMenu( | ||
89 | + * 'name' => '编辑友情链接', | ||
90 | + * 'parent' => 'index', | ||
91 | + * 'display'=> false, | ||
92 | + * 'hasView'=> true, | ||
93 | + * 'order' => 10000, | ||
94 | + * 'icon' => '', | ||
95 | + * 'remark' => '编辑友情链接', | ||
96 | + * 'param' => '' | ||
97 | + * ) | ||
98 | + */ | ||
99 | + public function edit() | ||
100 | + { | ||
101 | + $id = $this->request->param('id', 0, 'intval'); | ||
102 | + $linkModel = LinkModel::get($id); | ||
103 | + $this->assign('targets', $this->targets); | ||
104 | + $this->assign('link', $linkModel); | ||
105 | + return $this->fetch(); | ||
106 | + } | ||
107 | + | ||
108 | + /** | ||
109 | + * 编辑友情链接提交保存 | ||
110 | + * @adminMenu( | ||
111 | + * 'name' => '编辑友情链接提交保存', | ||
112 | + * 'parent' => 'index', | ||
113 | + * 'display'=> false, | ||
114 | + * 'hasView'=> false, | ||
115 | + * 'order' => 10000, | ||
116 | + * 'icon' => '', | ||
117 | + * 'remark' => '编辑友情链接提交保存', | ||
118 | + * 'param' => '' | ||
119 | + * ) | ||
120 | + */ | ||
121 | + public function editPost() | ||
122 | + { | ||
123 | + $data = $this->request->param(); | ||
124 | + $linkModel = new LinkModel(); | ||
125 | + $result = $linkModel->validate(true)->allowField(true)->isUpdate(true)->save($data); | ||
126 | + if ($result === false) { | ||
127 | + $this->error($linkModel->getError()); | ||
128 | + } | ||
129 | + | ||
130 | + $this->success("保存成功!", url("link/index")); | ||
131 | + } | ||
132 | + | ||
133 | + /** | ||
134 | + * 删除友情链接 | ||
135 | + * @adminMenu( | ||
136 | + * 'name' => '删除友情链接', | ||
137 | + * 'parent' => 'index', | ||
138 | + * 'display'=> false, | ||
139 | + * 'hasView'=> false, | ||
140 | + * 'order' => 10000, | ||
141 | + * 'icon' => '', | ||
142 | + * 'remark' => '删除友情链接', | ||
143 | + * 'param' => '' | ||
144 | + * ) | ||
145 | + */ | ||
146 | + public function delete() | ||
147 | + { | ||
148 | + $id = $this->request->param('id', 0, 'intval'); | ||
149 | + LinkModel::destroy($id); | ||
150 | + | ||
151 | + $this->success("删除成功!", url("link/index")); | ||
152 | + } | ||
153 | + | ||
154 | + /** | ||
155 | + * 友情链接排序 | ||
156 | + * @adminMenu( | ||
157 | + * 'name' => '友情链接排序', | ||
158 | + * 'parent' => 'index', | ||
159 | + * 'display'=> false, | ||
160 | + * 'hasView'=> false, | ||
161 | + * 'order' => 10000, | ||
162 | + * 'icon' => '', | ||
163 | + * 'remark' => '友情链接排序', | ||
164 | + * 'param' => '' | ||
165 | + * ) | ||
166 | + */ | ||
167 | + public function listOrder() | ||
168 | + { | ||
169 | + $linkModel = new LinkModel(); | ||
170 | + parent::listOrders($linkModel); | ||
171 | + $this->success("排序更新成功!"); | ||
172 | + } | ||
173 | + | ||
174 | + /** | ||
175 | + * 友情链接显示隐藏 | ||
176 | + * @adminMenu( | ||
177 | + * 'name' => '友情链接显示隐藏', | ||
178 | + * 'parent' => 'index', | ||
179 | + * 'display'=> false, | ||
180 | + * 'hasView'=> false, | ||
181 | + * 'order' => 10000, | ||
182 | + * 'icon' => '', | ||
183 | + * 'remark' => '友情链接显示隐藏', | ||
184 | + * 'param' => '' | ||
185 | + * ) | ||
186 | + */ | ||
187 | + public function toggle() | ||
188 | + { | ||
189 | + $data = $this->request->param(); | ||
190 | + $linkModel = new LinkModel(); | ||
191 | + | ||
192 | + if (isset($data['ids']) && !empty($data["display"])) { | ||
193 | + $ids = $this->request->param('ids/a'); | ||
194 | + $linkModel->where(['id' => ['in', $ids]])->update(['status' => 1]); | ||
195 | + $this->success("更新成功!"); | ||
196 | + } | ||
197 | + | ||
198 | + if (isset($data['ids']) && !empty($data["hide"])) { | ||
199 | + $ids = $this->request->param('ids/a'); | ||
200 | + $linkModel->where(['id' => ['in', $ids]])->update(['status' => 0]); | ||
201 | + $this->success("更新成功!"); | ||
202 | + } | ||
203 | + | ||
204 | + | ||
205 | + } | ||
206 | + | ||
207 | +} |
app/admin/controller/MailerController.php
0 → 100644
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: 小夏 < 449134904@qq.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\controller; | ||
12 | + | ||
13 | +use cmf\controller\AdminBaseController; | ||
14 | +use think\Validate; | ||
15 | + | ||
16 | +class MailerController extends AdminBaseController | ||
17 | +{ | ||
18 | + | ||
19 | + /** | ||
20 | + * 邮箱配置 | ||
21 | + * @adminMenu( | ||
22 | + * 'name' => '邮箱配置', | ||
23 | + * 'parent' => 'admin/Setting/default', | ||
24 | + * 'display'=> true, | ||
25 | + * 'hasView'=> true, | ||
26 | + * 'order' => 10, | ||
27 | + * 'icon' => '', | ||
28 | + * 'remark' => '邮箱配置', | ||
29 | + * 'param' => '' | ||
30 | + * ) | ||
31 | + */ | ||
32 | + public function index() | ||
33 | + { | ||
34 | + $emailSetting = cmf_get_option('smtp_setting'); | ||
35 | + $this->assign($emailSetting); | ||
36 | + return $this->fetch(); | ||
37 | + } | ||
38 | + | ||
39 | + /** | ||
40 | + * 邮箱配置 | ||
41 | + * @adminMenu( | ||
42 | + * 'name' => '邮箱配置提交保存', | ||
43 | + * 'parent' => 'index', | ||
44 | + * 'display'=> false, | ||
45 | + * 'hasView'=> false, | ||
46 | + * 'order' => 10000, | ||
47 | + * 'icon' => '', | ||
48 | + * 'remark' => '邮箱配置提交保存', | ||
49 | + * 'param' => '' | ||
50 | + * ) | ||
51 | + */ | ||
52 | + public function indexPost() | ||
53 | + { | ||
54 | + $post = array_map('trim', $this->request->param()); | ||
55 | + | ||
56 | + if (in_array('', $post) && !empty($post['smtpsecure'])) { | ||
57 | + $this->error("不能留空!"); | ||
58 | + } | ||
59 | + | ||
60 | + cmf_set_option('smtp_setting', $post); | ||
61 | + | ||
62 | + $this->success("保存成功!"); | ||
63 | + } | ||
64 | + | ||
65 | + /** | ||
66 | + * 邮件模板 | ||
67 | + * @adminMenu( | ||
68 | + * 'name' => '邮件模板', | ||
69 | + * 'parent' => 'index', | ||
70 | + * 'display'=> false, | ||
71 | + * 'hasView'=> true, | ||
72 | + * 'order' => 10000, | ||
73 | + * 'icon' => '', | ||
74 | + * 'remark' => '邮件模板', | ||
75 | + * 'param' => '' | ||
76 | + * ) | ||
77 | + */ | ||
78 | + public function template() | ||
79 | + { | ||
80 | + $allowedTemplateKeys = ['verification_code']; | ||
81 | + $templateKey = $this->request->param('template_key'); | ||
82 | + | ||
83 | + if (empty($templateKey) || !in_array($templateKey, $allowedTemplateKeys)) { | ||
84 | + $this->error('非法请求!'); | ||
85 | + } | ||
86 | + | ||
87 | + $template = cmf_get_option('email_template_' . $templateKey); | ||
88 | + $this->assign($template); | ||
89 | + return $this->fetch('template_verification_code'); | ||
90 | + } | ||
91 | + | ||
92 | + /** | ||
93 | + * 邮件模板提交 | ||
94 | + * @adminMenu( | ||
95 | + * 'name' => '邮件模板提交', | ||
96 | + * 'parent' => 'index', | ||
97 | + * 'display'=> false, | ||
98 | + * 'hasView'=> false, | ||
99 | + * 'order' => 10000, | ||
100 | + * 'icon' => '', | ||
101 | + * 'remark' => '邮件模板提交', | ||
102 | + * 'param' => '' | ||
103 | + * ) | ||
104 | + */ | ||
105 | + public function templatePost() | ||
106 | + { | ||
107 | + $allowedTemplateKeys = ['verification_code']; | ||
108 | + $templateKey = $this->request->param('template_key'); | ||
109 | + | ||
110 | + if (empty($templateKey) || !in_array($templateKey, $allowedTemplateKeys)) { | ||
111 | + $this->error('非法请求!'); | ||
112 | + } | ||
113 | + | ||
114 | + $data = $this->request->param(); | ||
115 | + | ||
116 | + unset($data['template_key']); | ||
117 | + | ||
118 | + cmf_set_option('email_template_' . $templateKey, $data); | ||
119 | + | ||
120 | + $this->success("保存成功!"); | ||
121 | + } | ||
122 | + | ||
123 | + /** | ||
124 | + * 邮件发送测试 | ||
125 | + * @adminMenu( | ||
126 | + * 'name' => '邮件发送测试', | ||
127 | + * 'parent' => 'index', | ||
128 | + * 'display'=> false, | ||
129 | + * 'hasView'=> true, | ||
130 | + * 'order' => 10000, | ||
131 | + * 'icon' => '', | ||
132 | + * 'remark' => '邮件发送测试', | ||
133 | + * 'param' => '' | ||
134 | + * ) | ||
135 | + */ | ||
136 | + public function test() | ||
137 | + { | ||
138 | + if ($this->request->isPost()) { | ||
139 | + | ||
140 | + $validate = new Validate([ | ||
141 | + 'to' => 'require|email', | ||
142 | + 'subject' => 'require', | ||
143 | + 'content' => 'require', | ||
144 | + ]); | ||
145 | + $validate->message([ | ||
146 | + 'to.require' => '收件箱不能为空!', | ||
147 | + 'to.email' => '收件箱格式不正确!', | ||
148 | + 'subject.require' => '标题不能为空!', | ||
149 | + 'content.require' => '内容不能为空!', | ||
150 | + ]); | ||
151 | + | ||
152 | + $data = $this->request->param(); | ||
153 | + if (!$validate->check($data)) { | ||
154 | + $this->error($validate->getError()); | ||
155 | + } | ||
156 | + | ||
157 | + $result = cmf_send_email($data['to'], $data['subject'], $data['content']); | ||
158 | + if ($result && empty($result['error'])) { | ||
159 | + $this->success('发送成功!'); | ||
160 | + } else { | ||
161 | + $this->error('发送失败:' . $result['message']); | ||
162 | + } | ||
163 | + | ||
164 | + } else { | ||
165 | + return $this->fetch(); | ||
166 | + } | ||
167 | + | ||
168 | + } | ||
169 | + | ||
170 | + | ||
171 | +} | ||
172 | + |
app/admin/controller/MainController.php
0 → 100644
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: 小夏 < 449134904@qq.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\controller; | ||
12 | + | ||
13 | +use cmf\controller\AdminBaseController; | ||
14 | +use think\Db; | ||
15 | +use app\admin\model\Menu; | ||
16 | + | ||
17 | +class MainController extends AdminBaseController | ||
18 | +{ | ||
19 | + | ||
20 | + public function _initialize() | ||
21 | + { | ||
22 | + parent::_initialize(); | ||
23 | + } | ||
24 | + | ||
25 | + /** | ||
26 | + * 后台欢迎页 | ||
27 | + */ | ||
28 | + public function index() | ||
29 | + { | ||
30 | + $dashboardWidgets = []; | ||
31 | + $widgets = cmf_get_option('admin_dashboard_widgets'); | ||
32 | + | ||
33 | + $defaultDashboardWidgets = [ | ||
34 | + '_SystemCmfHub' => ['name' => 'CmfHub', 'is_system' => 1], | ||
35 | + '_SystemCmfDocuments' => ['name' => 'CmfDocuments', 'is_system' => 1], | ||
36 | + '_SystemMainContributors' => ['name' => 'MainContributors', 'is_system' => 1], | ||
37 | + '_SystemContributors' => ['name' => 'Contributors', 'is_system' => 1], | ||
38 | + '_SystemCustom1' => ['name' => 'Custom1', 'is_system' => 1], | ||
39 | + '_SystemCustom2' => ['name' => 'Custom2', 'is_system' => 1], | ||
40 | + '_SystemCustom3' => ['name' => 'Custom3', 'is_system' => 1], | ||
41 | + '_SystemCustom4' => ['name' => 'Custom4', 'is_system' => 1], | ||
42 | + '_SystemCustom5' => ['name' => 'Custom5', 'is_system' => 1], | ||
43 | + ]; | ||
44 | + | ||
45 | + if (empty($widgets)) { | ||
46 | + $dashboardWidgets = $defaultDashboardWidgets; | ||
47 | + } else { | ||
48 | + foreach ($widgets as $widget) { | ||
49 | + if ($widget['is_system']) { | ||
50 | + $dashboardWidgets['_System' . $widget['name']] = ['name' => $widget['name'], 'is_system' => 1]; | ||
51 | + } else { | ||
52 | + $dashboardWidgets[$widget['name']] = ['name' => $widget['name'], 'is_system' => 0]; | ||
53 | + } | ||
54 | + } | ||
55 | + | ||
56 | + foreach ($defaultDashboardWidgets as $widgetName => $widget) { | ||
57 | + $dashboardWidgets[$widgetName] = $widget; | ||
58 | + } | ||
59 | + | ||
60 | + | ||
61 | + } | ||
62 | + | ||
63 | + $dashboardWidgetPlugins = []; | ||
64 | + | ||
65 | + $hookResults = hook('admin_dashboard'); | ||
66 | + | ||
67 | + if (!empty($hookResults)) { | ||
68 | + foreach ($hookResults as $hookResult) { | ||
69 | + if (isset($hookResult['width']) && isset($hookResult['view']) && isset($hookResult['plugin'])) { //验证插件返回合法性 | ||
70 | + $dashboardWidgetPlugins[$hookResult['plugin']] = $hookResult; | ||
71 | + if (!isset($dashboardWidgets[$hookResult['plugin']])) { | ||
72 | + $dashboardWidgets[$hookResult['plugin']] = ['name' => $hookResult['plugin'], 'is_system' => 0]; | ||
73 | + } | ||
74 | + } | ||
75 | + } | ||
76 | + } | ||
77 | + | ||
78 | + $smtpSetting = cmf_get_option('smtp_setting'); | ||
79 | + | ||
80 | + $this->assign('dashboard_widgets', $dashboardWidgets); | ||
81 | + $this->assign('dashboard_widget_plugins', $dashboardWidgetPlugins); | ||
82 | + $this->assign('has_smtp_setting', empty($smtpSetting) ? false : true); | ||
83 | + | ||
84 | + return $this->fetch(); | ||
85 | + } | ||
86 | + | ||
87 | + public function dashboardWidget() | ||
88 | + { | ||
89 | + $dashboardWidgets = []; | ||
90 | + $widgets = $this->request->param('widgets/a'); | ||
91 | + if (!empty($widgets)) { | ||
92 | + foreach ($widgets as $widget) { | ||
93 | + if ($widget['is_system']) { | ||
94 | + array_push($dashboardWidgets, ['name' => $widget['name'], 'is_system' => 1]); | ||
95 | + } else { | ||
96 | + array_push($dashboardWidgets, ['name' => $widget['name'], 'is_system' => 0]); | ||
97 | + } | ||
98 | + } | ||
99 | + } | ||
100 | + | ||
101 | + cmf_set_option('admin_dashboard_widgets', $dashboardWidgets, true); | ||
102 | + | ||
103 | + $this->success('更新成功!'); | ||
104 | + | ||
105 | + } | ||
106 | + | ||
107 | +} |
app/admin/controller/MenuController.php
0 → 100644
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: 小夏 < 449134904@qq.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\controller; | ||
12 | + | ||
13 | +use app\admin\model\AdminMenuModel; | ||
14 | +use cmf\controller\AdminBaseController; | ||
15 | +use think\Db; | ||
16 | +use tree\Tree; | ||
17 | +use mindplay\annotations\Annotations; | ||
18 | + | ||
19 | +class MenuController extends AdminBaseController | ||
20 | +{ | ||
21 | + /** | ||
22 | + * 后台菜单管理 | ||
23 | + * @adminMenu( | ||
24 | + * 'name' => '后台菜单', | ||
25 | + * 'parent' => 'admin/Setting/default', | ||
26 | + * 'display'=> false, | ||
27 | + * 'hasView'=> true, | ||
28 | + * 'order' => 10000, | ||
29 | + * 'icon' => '', | ||
30 | + * 'remark' => '后台菜单管理', | ||
31 | + * 'param' => '' | ||
32 | + * ) | ||
33 | + */ | ||
34 | + public function index() | ||
35 | + { | ||
36 | + session('admin_menu_index', 'Menu/index'); | ||
37 | + $result = Db::name('AdminMenu')->order(["list_order" => "ASC"])->select()->toArray(); | ||
38 | + $tree = new Tree(); | ||
39 | + $tree->icon = [' │ ', ' ├─ ', ' └─ ']; | ||
40 | + $tree->nbsp = ' '; | ||
41 | + | ||
42 | + $newMenus = []; | ||
43 | + foreach ($result as $m) { | ||
44 | + $newMenus[$m['id']] = $m; | ||
45 | + } | ||
46 | + foreach ($result as $key => $value) { | ||
47 | + | ||
48 | + $result[$key]['parent_id_node'] = ($value['parent_id']) ? ' class="child-of-node-' . $value['parent_id'] . '"' : ''; | ||
49 | + $result[$key]['style'] = empty($value['parent_id']) ? '' : 'display:none;'; | ||
50 | + $result[$key]['str_manage'] = '<a href="' . url("Menu/add", ["parent_id" => $value['id'], "menu_id" => $this->request->param("menu_id")]) | ||
51 | + . '">' . lang('ADD_SUB_MENU') . '</a> <a href="' . url("Menu/edit", ["id" => $value['id'], "menu_id" => $this->request->param("menu_id")]) | ||
52 | + . '">' . lang('EDIT') . '</a> <a class="js-ajax-delete" href="' . url("Menu/delete", ["id" => $value['id'], "menu_id" => $this->request->param("menu_id")]) . '">' . lang('DELETE') . '</a> '; | ||
53 | + $result[$key]['status'] = $value['status'] ? lang('DISPLAY') : lang('HIDDEN'); | ||
54 | + if (APP_DEBUG) { | ||
55 | + $result[$key]['app'] = $value['app'] . "/" . $value['controller'] . "/" . $value['action']; | ||
56 | + } | ||
57 | + } | ||
58 | + | ||
59 | + $tree->init($result); | ||
60 | + $str = "<tr id='node-\$id' \$parent_id_node style='\$style'> | ||
61 | + <td style='padding-left:20px;'><input name='list_orders[\$id]' type='text' size='3' value='\$list_order' class='input input-order'></td> | ||
62 | + <td>\$id</td> | ||
63 | + <td>\$spacer\$name</td> | ||
64 | + <td>\$app</td> | ||
65 | + <td>\$status</td> | ||
66 | + <td>\$str_manage</td> | ||
67 | + </tr>"; | ||
68 | + $category = $tree->getTree(0, $str); | ||
69 | + $this->assign("category", $category); | ||
70 | + return $this->fetch(); | ||
71 | + } | ||
72 | + | ||
73 | + /** | ||
74 | + * 后台所有菜单列表 | ||
75 | + * @adminMenu( | ||
76 | + * 'name' => '所有菜单', | ||
77 | + * 'parent' => 'index', | ||
78 | + * 'display'=> false, | ||
79 | + * 'hasView'=> true, | ||
80 | + * 'order' => 10000, | ||
81 | + * 'icon' => '', | ||
82 | + * 'remark' => '后台所有菜单列表', | ||
83 | + * 'param' => '' | ||
84 | + * ) | ||
85 | + */ | ||
86 | + public function lists() | ||
87 | + { | ||
88 | + session('admin_menu_index', 'Menu/lists'); | ||
89 | + $result = Db::name('AdminMenu')->order(["app" => "ASC", "controller" => "ASC", "action" => "ASC"])->select(); | ||
90 | + $this->assign("menus", $result); | ||
91 | + return $this->fetch(); | ||
92 | + } | ||
93 | + | ||
94 | + /** | ||
95 | + * 后台菜单添加 | ||
96 | + * @adminMenu( | ||
97 | + * 'name' => '后台菜单添加', | ||
98 | + * 'parent' => 'index', | ||
99 | + * 'display'=> false, | ||
100 | + * 'hasView'=> true, | ||
101 | + * 'order' => 10000, | ||
102 | + * 'icon' => '', | ||
103 | + * 'remark' => '后台菜单添加', | ||
104 | + * 'param' => '' | ||
105 | + * ) | ||
106 | + */ | ||
107 | + public function add() | ||
108 | + { | ||
109 | + $tree = new Tree(); | ||
110 | + $parentId = $this->request->param("parent_id", 0, 'intval'); | ||
111 | + $result = Db::name('AdminMenu')->order(["list_order" => "ASC"])->select(); | ||
112 | + $array = []; | ||
113 | + foreach ($result as $r) { | ||
114 | + $r['selected'] = $r['id'] == $parentId ? 'selected' : ''; | ||
115 | + $array[] = $r; | ||
116 | + } | ||
117 | + $str = "<option value='\$id' \$selected>\$spacer \$name</option>"; | ||
118 | + $tree->init($array); | ||
119 | + $selectCategory = $tree->getTree(0, $str); | ||
120 | + $this->assign("select_category", $selectCategory); | ||
121 | + return $this->fetch(); | ||
122 | + } | ||
123 | + | ||
124 | + /** | ||
125 | + * 后台菜单添加提交保存 | ||
126 | + * @adminMenu( | ||
127 | + * 'name' => '后台菜单添加提交保存', | ||
128 | + * 'parent' => 'index', | ||
129 | + * 'display'=> false, | ||
130 | + * 'hasView'=> false, | ||
131 | + * 'order' => 10000, | ||
132 | + * 'icon' => '', | ||
133 | + * 'remark' => '后台菜单添加提交保存', | ||
134 | + * 'param' => '' | ||
135 | + * ) | ||
136 | + */ | ||
137 | + public function addPost() | ||
138 | + { | ||
139 | + if ($this->request->isPost()) { | ||
140 | + $result = $this->validate($this->request->param(), 'AdminMenu'); | ||
141 | + if ($result !== true) { | ||
142 | + $this->error($result); | ||
143 | + } else { | ||
144 | + $data = $this->request->param(); | ||
145 | + Db::name('AdminMenu')->strict(false)->field(true)->insert($data); | ||
146 | + | ||
147 | + $app = $this->request->param("app"); | ||
148 | + $controller = $this->request->param("controller"); | ||
149 | + $action = $this->request->param("action"); | ||
150 | + $param = $this->request->param("param"); | ||
151 | + $authRuleName = "$app/$controller/$action"; | ||
152 | + $menuName = $this->request->param("name"); | ||
153 | + | ||
154 | + $findAuthRuleCount = Db::name('auth_rule')->where([ | ||
155 | + 'app' => $app, | ||
156 | + 'name' => $authRuleName, | ||
157 | + 'type' => 'admin_url' | ||
158 | + ])->count(); | ||
159 | + if (empty($findAuthRuleCount)) { | ||
160 | + Db::name('AuthRule')->insert([ | ||
161 | + "name" => $authRuleName, | ||
162 | + "app" => $app, | ||
163 | + "type" => "admin_url", //type 1-admin rule;2-user rule | ||
164 | + "title" => $menuName, | ||
165 | + 'param' => $param, | ||
166 | + ]); | ||
167 | + } | ||
168 | + $sessionAdminMenuIndex = session('admin_menu_index'); | ||
169 | + $to = empty($sessionAdminMenuIndex) ? "Menu/index" : $sessionAdminMenuIndex; | ||
170 | + $this->_exportAppMenuDefaultLang(); | ||
171 | + cache(null, 'admin_menus');// 删除后台菜单缓存 | ||
172 | + $this->success("添加成功!", url($to)); | ||
173 | + } | ||
174 | + } | ||
175 | + } | ||
176 | + | ||
177 | + /** | ||
178 | + * 后台菜单编辑 | ||
179 | + * @adminMenu( | ||
180 | + * 'name' => '后台菜单编辑', | ||
181 | + * 'parent' => 'index', | ||
182 | + * 'display'=> false, | ||
183 | + * 'hasView'=> true, | ||
184 | + * 'order' => 10000, | ||
185 | + * 'icon' => '', | ||
186 | + * 'remark' => '后台菜单编辑', | ||
187 | + * 'param' => '' | ||
188 | + * ) | ||
189 | + */ | ||
190 | + public function edit() | ||
191 | + { | ||
192 | + $tree = new Tree(); | ||
193 | + $id = $this->request->param("id", 0, 'intval'); | ||
194 | + $rs = Db::name('AdminMenu')->where(["id" => $id])->find(); | ||
195 | + $result = Db::name('AdminMenu')->order(["list_order" => "ASC"])->select(); | ||
196 | + $array = []; | ||
197 | + foreach ($result as $r) { | ||
198 | + $r['selected'] = $r['id'] == $rs['parent_id'] ? 'selected' : ''; | ||
199 | + $array[] = $r; | ||
200 | + } | ||
201 | + $str = "<option value='\$id' \$selected>\$spacer \$name</option>"; | ||
202 | + $tree->init($array); | ||
203 | + $selectCategory = $tree->getTree(0, $str); | ||
204 | + $this->assign("data", $rs); | ||
205 | + $this->assign("select_category", $selectCategory); | ||
206 | + return $this->fetch(); | ||
207 | + } | ||
208 | + | ||
209 | + /** | ||
210 | + * 后台菜单编辑提交保存 | ||
211 | + * @adminMenu( | ||
212 | + * 'name' => '后台菜单编辑提交保存', | ||
213 | + * 'parent' => 'index', | ||
214 | + * 'display'=> false, | ||
215 | + * 'hasView'=> false, | ||
216 | + * 'order' => 10000, | ||
217 | + * 'icon' => '', | ||
218 | + * 'remark' => '后台菜单编辑提交保存', | ||
219 | + * 'param' => '' | ||
220 | + * ) | ||
221 | + */ | ||
222 | + public function editPost() | ||
223 | + { | ||
224 | + if ($this->request->isPost()) { | ||
225 | + $id = $this->request->param('id', 0, 'intval'); | ||
226 | + $oldMenu = Db::name('AdminMenu')->where(['id' => $id])->find(); | ||
227 | + | ||
228 | + $result = $this->validate($this->request->param(), 'AdminMenu.edit'); | ||
229 | + | ||
230 | + if ($result !== true) { | ||
231 | + $this->error($result); | ||
232 | + } else { | ||
233 | + Db::name('AdminMenu')->strict(false)->field(true)->update($this->request->param()); | ||
234 | + $app = $this->request->param("app"); | ||
235 | + $controller = $this->request->param("controller"); | ||
236 | + $action = $this->request->param("action"); | ||
237 | + $param = $this->request->param("param"); | ||
238 | + $authRuleName = "$app/$controller/$action"; | ||
239 | + $menuName = $this->request->param("name"); | ||
240 | + | ||
241 | + $findAuthRuleCount = Db::name('auth_rule')->where([ | ||
242 | + 'app' => $app, | ||
243 | + 'name' => $authRuleName, | ||
244 | + 'type' => 'admin_url' | ||
245 | + ])->count(); | ||
246 | + if (empty($findAuthRuleCount)) { | ||
247 | + $oldApp = $oldMenu['app']; | ||
248 | + $oldController = $oldMenu['controller']; | ||
249 | + $oldAction = $oldMenu['action']; | ||
250 | + $oldName = "$oldApp/$oldController/$oldAction"; | ||
251 | + $findOldRuleId = Db::name('AuthRule')->where(["name" => $oldName])->value('id'); | ||
252 | + if (empty($findOldRuleId)) { | ||
253 | + Db::name('AuthRule')->insert([ | ||
254 | + "name" => $authRuleName, | ||
255 | + "app" => $app, | ||
256 | + "type" => "admin_url", | ||
257 | + "title" => $menuName, | ||
258 | + "param" => $param | ||
259 | + ]);//type 1-admin rule;2-user rule | ||
260 | + } else { | ||
261 | + Db::name('AuthRule')->where(['id' => $findOldRuleId])->update([ | ||
262 | + "name" => $authRuleName, | ||
263 | + "app" => $app, | ||
264 | + "type" => "admin_url", | ||
265 | + "title" => $menuName, | ||
266 | + "param" => $param]);//type 1-admin rule;2-user rule | ||
267 | + } | ||
268 | + } else { | ||
269 | + Db::name('AuthRule')->where([ | ||
270 | + 'app' => $app, | ||
271 | + 'name' => $authRuleName, | ||
272 | + 'type' => 'admin_url' | ||
273 | + ])->update(["title" => $menuName, 'param' => $param]);//type 1-admin rule;2-user rule | ||
274 | + } | ||
275 | + $this->_exportAppMenuDefaultLang(); | ||
276 | + cache(null, 'admin_menus');// 删除后台菜单缓存 | ||
277 | + $this->success("保存成功!"); | ||
278 | + } | ||
279 | + } | ||
280 | + } | ||
281 | + | ||
282 | + /** | ||
283 | + * 后台菜单删除 | ||
284 | + * @adminMenu( | ||
285 | + * 'name' => '后台菜单删除', | ||
286 | + * 'parent' => 'index', | ||
287 | + * 'display'=> false, | ||
288 | + * 'hasView'=> false, | ||
289 | + * 'order' => 10000, | ||
290 | + * 'icon' => '', | ||
291 | + * 'remark' => '后台菜单删除', | ||
292 | + * 'param' => '' | ||
293 | + * ) | ||
294 | + */ | ||
295 | + public function delete() | ||
296 | + { | ||
297 | + $id = $this->request->param("id", 0, 'intval'); | ||
298 | + $count = Db::name('AdminMenu')->where(["parent_id" => $id])->count(); | ||
299 | + if ($count > 0) { | ||
300 | + $this->error("该菜单下还有子菜单,无法删除!"); | ||
301 | + } | ||
302 | + if (Db::name('AdminMenu')->delete($id) !== false) { | ||
303 | + $this->success("删除菜单成功!"); | ||
304 | + } else { | ||
305 | + $this->error("删除失败!"); | ||
306 | + } | ||
307 | + } | ||
308 | + | ||
309 | + /** | ||
310 | + * 后台菜单排序 | ||
311 | + * @adminMenu( | ||
312 | + * 'name' => '后台菜单排序', | ||
313 | + * 'parent' => 'index', | ||
314 | + * 'display'=> false, | ||
315 | + * 'hasView'=> false, | ||
316 | + * 'order' => 10000, | ||
317 | + * 'icon' => '', | ||
318 | + * 'remark' => '后台菜单排序', | ||
319 | + * 'param' => '' | ||
320 | + * ) | ||
321 | + */ | ||
322 | + public function listOrder() | ||
323 | + { | ||
324 | + $adminMenuModel = new AdminMenuModel(); | ||
325 | + parent::listOrders($adminMenuModel); | ||
326 | + $this->success("排序更新成功!"); | ||
327 | + } | ||
328 | + | ||
329 | + /** | ||
330 | + * 导入新后台菜单 | ||
331 | + * @adminMenu( | ||
332 | + * 'name' => '导入新后台菜单', | ||
333 | + * 'parent' => 'index', | ||
334 | + * 'display'=> false, | ||
335 | + * 'hasView'=> true, | ||
336 | + * 'order' => 10000, | ||
337 | + * 'icon' => '', | ||
338 | + * 'remark' => '导入新后台菜单', | ||
339 | + * 'param' => '' | ||
340 | + * ) | ||
341 | + */ | ||
342 | + public function getActions() | ||
343 | + { | ||
344 | + Annotations::$config['cache'] = false; | ||
345 | + $annotationManager = Annotations::getManager(); | ||
346 | + $annotationManager->registry['adminMenu'] = 'app\admin\annotation\AdminMenuAnnotation'; | ||
347 | + $annotationManager->registry['adminMenuRoot'] = 'app\admin\annotation\AdminMenuRootAnnotation'; | ||
348 | + $newMenus = []; | ||
349 | + | ||
350 | + $apps = cmf_scan_dir(APP_PATH . '*', GLOB_ONLYDIR); | ||
351 | + | ||
352 | + $app = $this->request->param('app', ''); | ||
353 | + if (empty($app)) { | ||
354 | + $app = $apps[0]; | ||
355 | + } | ||
356 | + | ||
357 | + if (!in_array($app, $apps)) { | ||
358 | + $this->error('应用' . $app . '不存在!'); | ||
359 | + } | ||
360 | + | ||
361 | + if ($app == 'admin') { | ||
362 | + $filePatten = APP_PATH . $app . '/controller/*Controller.php'; | ||
363 | + } else { | ||
364 | + $filePatten = APP_PATH . $app . '/controller/Admin*Controller.php'; | ||
365 | + } | ||
366 | + | ||
367 | + $controllers = cmf_scan_dir($filePatten); | ||
368 | + | ||
369 | + if (!empty($controllers)) { | ||
370 | + foreach ($controllers as $controller) { | ||
371 | + $controller = preg_replace('/\.php$/', '', $controller); | ||
372 | + $controllerName = preg_replace('/\Controller$/', '', $controller); | ||
373 | + $controllerClass = "app\\$app\\controller\\$controller"; | ||
374 | + | ||
375 | + $menuAnnotations = Annotations::ofClass($controllerClass, '@adminMenuRoot'); | ||
376 | + | ||
377 | + if (!empty($menuAnnotations)) { | ||
378 | + foreach ($menuAnnotations as $menuAnnotation) { | ||
379 | + | ||
380 | + $name = $menuAnnotation->name; | ||
381 | + $icon = $menuAnnotation->icon; | ||
382 | + $type = 0;//1:有界面可访问菜单,2:无界面可访问菜单,0:只作为菜单 | ||
383 | + $action = $menuAnnotation->action; | ||
384 | + $status = empty($menuAnnotation->display) ? 0 : 1; | ||
385 | + $listOrder = floatval($menuAnnotation->order); | ||
386 | + $param = $menuAnnotation->param; | ||
387 | + $remark = $menuAnnotation->remark; | ||
388 | + | ||
389 | + if (empty($menuAnnotation->parent)) { | ||
390 | + $parentId = 0; | ||
391 | + } else { | ||
392 | + | ||
393 | + $parent = explode('/', $menuAnnotation->parent); | ||
394 | + $countParent = count($parent); | ||
395 | + if ($countParent > 3) { | ||
396 | + throw new \Exception($controllerClass . ':' . $action . ' @adminMenuRoot parent格式不正确!'); | ||
397 | + } | ||
398 | + | ||
399 | + $parentApp = $app; | ||
400 | + $parentController = $controllerName; | ||
401 | + $parentAction = ''; | ||
402 | + | ||
403 | + switch ($countParent) { | ||
404 | + case 1: | ||
405 | + $parentAction = $parent[0]; | ||
406 | + break; | ||
407 | + case 2: | ||
408 | + $parentController = $parent[0]; | ||
409 | + $parentAction = $parent[1]; | ||
410 | + break; | ||
411 | + case 3: | ||
412 | + $parentApp = $parent[0]; | ||
413 | + $parentController = $parent[1]; | ||
414 | + $parentAction = $parent[2]; | ||
415 | + break; | ||
416 | + } | ||
417 | + | ||
418 | + $findParentAdminMenu = Db::name('admin_menu')->where([ | ||
419 | + 'app' => $parentApp, | ||
420 | + 'controller' => $parentController, | ||
421 | + 'action' => $parentAction | ||
422 | + ])->find(); | ||
423 | + | ||
424 | + if (empty($findParentAdminMenu)) { | ||
425 | + $parentId = Db::name('admin_menu')->insertGetId([ | ||
426 | + 'app' => $parentApp, | ||
427 | + 'controller' => $parentController, | ||
428 | + 'action' => $parentAction, | ||
429 | + 'name' => '--new--' | ||
430 | + ]); | ||
431 | + } else { | ||
432 | + $parentId = $findParentAdminMenu['id']; | ||
433 | + } | ||
434 | + } | ||
435 | + | ||
436 | + $findAdminMenu = Db::name('admin_menu')->where([ | ||
437 | + 'app' => $app, | ||
438 | + 'controller' => $controllerName, | ||
439 | + 'action' => $action | ||
440 | + ])->find(); | ||
441 | + | ||
442 | + if (empty($findAdminMenu)) { | ||
443 | + | ||
444 | + Db::name('admin_menu')->insert([ | ||
445 | + 'parent_id' => $parentId, | ||
446 | + 'type' => $type, | ||
447 | + 'status' => $status, | ||
448 | + 'list_order' => $listOrder, | ||
449 | + 'app' => $app, | ||
450 | + 'controller' => $controllerName, | ||
451 | + 'action' => $action, | ||
452 | + 'param' => $param, | ||
453 | + 'name' => $name, | ||
454 | + 'icon' => $icon, | ||
455 | + 'remark' => $remark | ||
456 | + ]); | ||
457 | + | ||
458 | + $menuName = $name; | ||
459 | + | ||
460 | + array_push($newMenus, "$app/$controllerName/$action 已导入"); | ||
461 | + | ||
462 | + } else { | ||
463 | + | ||
464 | + if ($findAdminMenu['name'] == '--new--') { | ||
465 | + Db::name('admin_menu')->where([ | ||
466 | + 'app' => $app, | ||
467 | + 'controller' => $controllerName, | ||
468 | + 'action' => $action | ||
469 | + ])->update([ | ||
470 | + 'parent_id' => $parentId, | ||
471 | + 'type' => $type, | ||
472 | + 'status' => $status, | ||
473 | + 'list_order' => $listOrder, | ||
474 | + 'param' => $param, | ||
475 | + 'name' => $name, | ||
476 | + 'icon' => $icon, | ||
477 | + 'remark' => $remark | ||
478 | + ]); | ||
479 | + $menuName = $name; | ||
480 | + } else { | ||
481 | + // 只关注菜单层级关系,是否有视图 | ||
482 | + Db::name('admin_menu')->where([ | ||
483 | + 'app' => $app, | ||
484 | + 'controller' => $controllerName, | ||
485 | + 'action' => $action | ||
486 | + ])->update([ | ||
487 | + //'parent_id' => $parentId, | ||
488 | + 'type' => $type, | ||
489 | + ]); | ||
490 | + $menuName = $findAdminMenu['name']; | ||
491 | + } | ||
492 | + | ||
493 | + array_push($newMenus, "$app/$controllerName/$action 层级关系已更新"); | ||
494 | + } | ||
495 | + | ||
496 | + $authRuleName = "{$app}/{$controllerName}/{$action}"; | ||
497 | + $findAuthRuleCount = Db::name('auth_rule')->where([ | ||
498 | + 'app' => $app, | ||
499 | + 'name' => $authRuleName, | ||
500 | + 'type' => 'admin_url' | ||
501 | + ])->count(); | ||
502 | + | ||
503 | + if ($findAuthRuleCount == 0) { | ||
504 | + Db::name('auth_rule')->insert([ | ||
505 | + 'app' => $app, | ||
506 | + 'name' => $authRuleName, | ||
507 | + 'type' => 'admin_url', | ||
508 | + 'param' => $param, | ||
509 | + 'title' => $menuName | ||
510 | + ]); | ||
511 | + } else { | ||
512 | + Db::name('auth_rule')->where([ | ||
513 | + 'app' => $app, | ||
514 | + 'name' => $authRuleName, | ||
515 | + 'type' => 'admin_url', | ||
516 | + ])->update([ | ||
517 | + 'param' => $param, | ||
518 | + 'title' => $menuName | ||
519 | + ]); | ||
520 | + } | ||
521 | + | ||
522 | + } | ||
523 | + } | ||
524 | + | ||
525 | + $reflect = new \ReflectionClass($controllerClass); | ||
526 | + $methods = $reflect->getMethods(\ReflectionMethod::IS_PUBLIC); | ||
527 | + | ||
528 | + if (!empty($methods)) { | ||
529 | + foreach ($methods as $method) { | ||
530 | + | ||
531 | + if ($method->class == $controllerClass && strpos($method->name, '_') !== 0) { | ||
532 | + $menuAnnotations = Annotations::ofMethod($controllerClass, $method->name, '@adminMenu'); | ||
533 | + | ||
534 | + if (!empty($menuAnnotations)) { | ||
535 | + | ||
536 | + $menuAnnotation = $menuAnnotations[0]; | ||
537 | + | ||
538 | + $name = $menuAnnotation->name; | ||
539 | + $icon = $menuAnnotation->icon; | ||
540 | + $type = $menuAnnotation->hasView ? 1 : 2;//1:有界面可访问菜单,2:无界面可访问菜单,0:只作为菜单 | ||
541 | + $action = $method->name; | ||
542 | + $status = empty($menuAnnotation->display) ? 0 : 1; | ||
543 | + $listOrder = floatval($menuAnnotation->order); | ||
544 | + $param = $menuAnnotation->param; | ||
545 | + $remark = $menuAnnotation->remark; | ||
546 | + | ||
547 | + if (empty($menuAnnotation->parent)) { | ||
548 | + $parentId = 0; | ||
549 | + } else { | ||
550 | + $parent = explode('/', $menuAnnotation->parent); | ||
551 | + $countParent = count($parent); | ||
552 | + if ($countParent > 3) { | ||
553 | + throw new \Exception($controllerClass . ':' . $action . ' @menuRoot parent格式不正确!'); | ||
554 | + } | ||
555 | + | ||
556 | + $parentApp = $app; | ||
557 | + $parentController = $controllerName; | ||
558 | + $parentAction = ''; | ||
559 | + | ||
560 | + switch ($countParent) { | ||
561 | + case 1: | ||
562 | + $parentAction = $parent[0]; | ||
563 | + break; | ||
564 | + case 2: | ||
565 | + $parentController = $parent[0]; | ||
566 | + $parentAction = $parent[1]; | ||
567 | + break; | ||
568 | + case 3: | ||
569 | + $parentApp = $parent[0]; | ||
570 | + $parentController = $parent[1]; | ||
571 | + $parentAction = $parent[2]; | ||
572 | + break; | ||
573 | + } | ||
574 | + | ||
575 | + $findParentAdminMenu = Db::name('admin_menu')->where([ | ||
576 | + 'app' => $parentApp, | ||
577 | + 'controller' => $parentController, | ||
578 | + 'action' => $parentAction | ||
579 | + ])->find(); | ||
580 | + | ||
581 | + if (empty($findParentAdminMenu)) { | ||
582 | + $parentId = Db::name('admin_menu')->insertGetId([ | ||
583 | + 'app' => $parentApp, | ||
584 | + 'controller' => $parentController, | ||
585 | + 'action' => $parentAction, | ||
586 | + 'name' => '--new--' | ||
587 | + ]); | ||
588 | + } else { | ||
589 | + $parentId = $findParentAdminMenu['id']; | ||
590 | + } | ||
591 | + } | ||
592 | + | ||
593 | + $findAdminMenu = Db::name('admin_menu')->where([ | ||
594 | + 'app' => $app, | ||
595 | + 'controller' => $controllerName, | ||
596 | + 'action' => $action | ||
597 | + ])->find(); | ||
598 | + | ||
599 | + if (empty($findAdminMenu)) { | ||
600 | + | ||
601 | + Db::name('admin_menu')->insert([ | ||
602 | + 'parent_id' => $parentId, | ||
603 | + 'type' => $type, | ||
604 | + 'status' => $status, | ||
605 | + 'list_order' => $listOrder, | ||
606 | + 'app' => $app, | ||
607 | + 'controller' => $controllerName, | ||
608 | + 'action' => $action, | ||
609 | + 'param' => $param, | ||
610 | + 'name' => $name, | ||
611 | + 'icon' => $icon, | ||
612 | + 'remark' => $remark | ||
613 | + ]); | ||
614 | + | ||
615 | + $menuName = $name; | ||
616 | + | ||
617 | + array_push($newMenus, "$app/$controllerName/$action 已导入"); | ||
618 | + | ||
619 | + } else { | ||
620 | + if ($findAdminMenu['name'] == '--new--') { | ||
621 | + Db::name('admin_menu')->where([ | ||
622 | + 'app' => $app, | ||
623 | + 'controller' => $controllerName, | ||
624 | + 'action' => $action | ||
625 | + ])->update([ | ||
626 | + 'parent_id' => $parentId, | ||
627 | + 'type' => $type, | ||
628 | + 'status' => $status, | ||
629 | + 'list_order' => $listOrder, | ||
630 | + 'param' => $param, | ||
631 | + 'name' => $name, | ||
632 | + 'icon' => $icon, | ||
633 | + 'remark' => $remark | ||
634 | + ]); | ||
635 | + $menuName = $name; | ||
636 | + } else { | ||
637 | + // 只关注菜单层级关系,是否有视图 | ||
638 | + Db::name('admin_menu')->where([ | ||
639 | + 'app' => $app, | ||
640 | + 'controller' => $controllerName, | ||
641 | + 'action' => $action | ||
642 | + ])->update([ | ||
643 | + //'parent_id' => $parentId, | ||
644 | + 'type' => $type, | ||
645 | + ]); | ||
646 | + $menuName = $findAdminMenu['name']; | ||
647 | + } | ||
648 | + | ||
649 | + | ||
650 | + array_push($newMenus, "$app/$controllerName/$action 已更新"); | ||
651 | + } | ||
652 | + | ||
653 | + $authRuleName = "{$app}/{$controllerName}/{$action}"; | ||
654 | + $findAuthRuleCount = Db::name('auth_rule')->where([ | ||
655 | + 'app' => $app, | ||
656 | + 'name' => $authRuleName, | ||
657 | + 'type' => 'admin_url' | ||
658 | + ])->count(); | ||
659 | + | ||
660 | + if ($findAuthRuleCount == 0) { | ||
661 | + Db::name('auth_rule')->insert([ | ||
662 | + 'app' => $app, | ||
663 | + 'name' => $authRuleName, | ||
664 | + 'type' => 'admin_url', | ||
665 | + 'param' => $param, | ||
666 | + 'title' => $menuName | ||
667 | + ]); | ||
668 | + } else { | ||
669 | + Db::name('auth_rule')->where([ | ||
670 | + 'app' => $app, | ||
671 | + 'name' => $authRuleName, | ||
672 | + 'type' => 'admin_url', | ||
673 | + ])->update([ | ||
674 | + 'param' => $param, | ||
675 | + 'title' => $menuName | ||
676 | + ]); | ||
677 | + } | ||
678 | + } | ||
679 | + | ||
680 | + } | ||
681 | + } | ||
682 | + } | ||
683 | + | ||
684 | + } | ||
685 | + } | ||
686 | + | ||
687 | + $index = array_search($app, $apps); | ||
688 | + $nextIndex = $index + 1; | ||
689 | + $nextIndex = $nextIndex >= count($apps) ? 0 : $nextIndex; | ||
690 | + if ($nextIndex) { | ||
691 | + $this->assign("next_app", $apps[$nextIndex]); | ||
692 | + } | ||
693 | + $this->assign("app", $app); | ||
694 | + $this->assign("new_menus", $newMenus); | ||
695 | + | ||
696 | + cache(null, 'admin_menus');// 删除后台菜单缓存 | ||
697 | + | ||
698 | + return $this->fetch(); | ||
699 | + | ||
700 | + } | ||
701 | + | ||
702 | + /** | ||
703 | + * 导出后台菜单语言包 | ||
704 | + */ | ||
705 | + private function _exportAppMenuDefaultLang() | ||
706 | + { | ||
707 | + $menus = Db::name('AdminMenu')->order(["app" => "ASC", "controller" => "ASC", "action" => "ASC"])->select(); | ||
708 | + $langDir = config('DEFAULT_LANG'); | ||
709 | + $adminMenuLang = CMF_ROOT . "data/lang/" . $langDir . "/admin_menu.php"; | ||
710 | + | ||
711 | + if (!empty($adminMenuLang) && !file_exists_case($adminMenuLang)) { | ||
712 | + mkdir(dirname($adminMenuLang), 0777, true); | ||
713 | + } | ||
714 | + | ||
715 | + $lang = []; | ||
716 | + | ||
717 | + foreach ($menus as $menu) { | ||
718 | + $lang_key = strtoupper($menu['app'] . '_' . $menu['controller'] . '_' . $menu['action']); | ||
719 | + $lang[$lang_key] = $menu['name']; | ||
720 | + } | ||
721 | + | ||
722 | + $langStr = var_export($lang, true); | ||
723 | + $langStr = preg_replace("/\s+\d+\s=>\s(\n|\r)/", "\n", $langStr); | ||
724 | + | ||
725 | + if (!empty($adminMenuLang)) { | ||
726 | + file_put_contents($adminMenuLang, "<?php\nreturn $langStr;"); | ||
727 | + } | ||
728 | + } | ||
729 | +} |
app/admin/controller/NavController.php
0 → 100644
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: kane <chengjin005@163.com> 小夏 < 449134904@qq.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\controller; | ||
12 | + | ||
13 | +use cmf\controller\AdminBaseController; | ||
14 | +use app\admin\model\NavModel; | ||
15 | +use think\Db; | ||
16 | + | ||
17 | +/** | ||
18 | + * Class NavController 导航类别管理控制器 | ||
19 | + * @package app\admin\controller | ||
20 | + */ | ||
21 | +class NavController extends AdminBaseController | ||
22 | +{ | ||
23 | + /** | ||
24 | + * 导航管理 | ||
25 | + * @adminMenu( | ||
26 | + * 'name' => '导航管理', | ||
27 | + * 'parent' => 'admin/Setting/default', | ||
28 | + * 'display'=> true, | ||
29 | + * 'hasView'=> true, | ||
30 | + * 'order' => 30, | ||
31 | + * 'icon' => '', | ||
32 | + * 'remark' => '导航管理', | ||
33 | + * 'param' => '' | ||
34 | + * ) | ||
35 | + */ | ||
36 | + public function index() | ||
37 | + { | ||
38 | + $navModel = new NavModel(); | ||
39 | + | ||
40 | + $navs = $navModel->select(); | ||
41 | + $this->assign('navs', $navs); | ||
42 | + | ||
43 | + return $this->fetch(); | ||
44 | + | ||
45 | + } | ||
46 | + | ||
47 | + /** | ||
48 | + * 添加导航 | ||
49 | + * @adminMenu( | ||
50 | + * 'name' => '添加导航', | ||
51 | + * 'parent' => 'index', | ||
52 | + * 'display'=> false, | ||
53 | + * 'hasView'=> true, | ||
54 | + * 'order' => 10000, | ||
55 | + * 'icon' => '', | ||
56 | + * 'remark' => '添加导航', | ||
57 | + * 'param' => '' | ||
58 | + * ) | ||
59 | + */ | ||
60 | + public function add() | ||
61 | + { | ||
62 | + return $this->fetch(); | ||
63 | + } | ||
64 | + | ||
65 | + /** | ||
66 | + * 添加导航提交保存 | ||
67 | + * @adminMenu( | ||
68 | + * 'name' => '添加导航提交保存', | ||
69 | + * 'parent' => 'index', | ||
70 | + * 'display'=> false, | ||
71 | + * 'hasView'=> false, | ||
72 | + * 'order' => 10000, | ||
73 | + * 'icon' => '', | ||
74 | + * 'remark' => '添加导航提交保存', | ||
75 | + * 'param' => '' | ||
76 | + * ) | ||
77 | + */ | ||
78 | + public function addPost() | ||
79 | + { | ||
80 | + | ||
81 | + $navModel = new NavModel(); | ||
82 | + $arrData = $this->request->post(); | ||
83 | + | ||
84 | + if (empty($arrData["is_main"])) { | ||
85 | + $arrData["is_main"] = 0; | ||
86 | + } else { | ||
87 | + $navModel->where("is_main", 1)->update(["is_main" => 0]); | ||
88 | + } | ||
89 | + | ||
90 | + $navModel->allowField(true)->insert($arrData); | ||
91 | + $this->success(lang("EDIT_SUCCESS"), url("nav/index")); | ||
92 | + | ||
93 | + } | ||
94 | + | ||
95 | + /** | ||
96 | + * 编辑导航 | ||
97 | + * @adminMenu( | ||
98 | + * 'name' => '编辑导航', | ||
99 | + * 'parent' => 'index', | ||
100 | + * 'display'=> false, | ||
101 | + * 'hasView'=> true, | ||
102 | + * 'order' => 10000, | ||
103 | + * 'icon' => '', | ||
104 | + * 'remark' => '编辑导航', | ||
105 | + * 'param' => '' | ||
106 | + * ) | ||
107 | + */ | ||
108 | + public function edit() | ||
109 | + { | ||
110 | + $navModel = new NavModel(); | ||
111 | + $intId = $this->request->param("id", 0, 'intval'); | ||
112 | + | ||
113 | + $objNavCat = $navModel->where(["id" => $intId])->find(); | ||
114 | + $arrNavCat = $objNavCat ? $objNavCat->toArray() : []; | ||
115 | + | ||
116 | + $this->assign($arrNavCat); | ||
117 | + return $this->fetch(); | ||
118 | + } | ||
119 | + | ||
120 | + | ||
121 | + /** | ||
122 | + * 编辑导航提交保存 | ||
123 | + * @adminMenu( | ||
124 | + * 'name' => '编辑导航提交保存', | ||
125 | + * 'parent' => 'index', | ||
126 | + * 'display'=> false, | ||
127 | + * 'hasView'=> false, | ||
128 | + * 'order' => 10000, | ||
129 | + * 'icon' => '', | ||
130 | + * 'remark' => '编辑导航提交保存', | ||
131 | + * 'param' => '' | ||
132 | + * ) | ||
133 | + */ | ||
134 | + public function editPost() | ||
135 | + { | ||
136 | + | ||
137 | + $navModel = new NavModel(); | ||
138 | + $arrData = $this->request->post(); | ||
139 | + | ||
140 | + if (empty($arrData["is_main"])) { | ||
141 | + $arrData["is_main"] = 0; | ||
142 | + } else { | ||
143 | + $navModel->where("is_main", 1)->update(["is_main" => 0]); | ||
144 | + } | ||
145 | + | ||
146 | + $navModel->allowField(true)->where(["id" => $arrData["id"]])->update($arrData); | ||
147 | + $this->success(lang("EDIT_SUCCESS"), url("nav/index")); | ||
148 | + | ||
149 | + } | ||
150 | + | ||
151 | + /** | ||
152 | + * 删除导航 | ||
153 | + * @adminMenu( | ||
154 | + * 'name' => '删除导航', | ||
155 | + * 'parent' => 'index', | ||
156 | + * 'display'=> false, | ||
157 | + * 'hasView'=> false, | ||
158 | + * 'order' => 10000, | ||
159 | + * 'icon' => '', | ||
160 | + * 'remark' => '删除导航', | ||
161 | + * 'param' => '' | ||
162 | + * ) | ||
163 | + */ | ||
164 | + public function delete() | ||
165 | + { | ||
166 | + $navModel = new NavModel(); | ||
167 | + $intId = $this->request->param("id", 0, "intval"); | ||
168 | + | ||
169 | + if (empty($intId)) { | ||
170 | + $this->error(lang("NO_ID")); | ||
171 | + } | ||
172 | + | ||
173 | + $navModel->where(["id" => $intId])->delete(); | ||
174 | + $this->success(lang("DELETE_SUCCESS"), url("nav/index")); | ||
175 | + | ||
176 | + } | ||
177 | + | ||
178 | + | ||
179 | +} |
app/admin/controller/NavMenuController.php
0 → 100644
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: kane <chengjin005@163.com> 小夏 < 449134904@qq.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\controller; | ||
12 | + | ||
13 | +use app\admin\model\NavMenuModel; | ||
14 | +use cmf\controller\AdminBaseController; | ||
15 | +use tree\Tree; | ||
16 | + | ||
17 | +/** | ||
18 | + * Class NavMenuController 前台菜单管理控制器 | ||
19 | + * @package app\admin\controller | ||
20 | + */ | ||
21 | +class NavMenuController extends AdminBaseController | ||
22 | +{ | ||
23 | + /** | ||
24 | + * 导航菜单 | ||
25 | + * @adminMenu( | ||
26 | + * 'name' => '导航菜单', | ||
27 | + * 'parent' => 'admin/Nav/index', | ||
28 | + * 'display'=> false, | ||
29 | + * 'hasView'=> true, | ||
30 | + * 'order' => 10000, | ||
31 | + * 'icon' => '', | ||
32 | + * 'remark' => '导航菜单', | ||
33 | + * 'param' => '' | ||
34 | + * ) | ||
35 | + */ | ||
36 | + public function index() | ||
37 | + { | ||
38 | + $intNavId = $this->request->param("nav_id"); | ||
39 | + $navMenuModel = new NavMenuModel(); | ||
40 | + | ||
41 | + if (empty($intNavId)) { | ||
42 | + $this->error("请指定导航!"); | ||
43 | + } | ||
44 | + | ||
45 | + $objResult = $navMenuModel->where("nav_id", $intNavId)->order(["list_order" => "ASC"])->select(); | ||
46 | + $arrResult = $objResult ? $objResult->toArray() : []; | ||
47 | + | ||
48 | + $tree = new Tree(); | ||
49 | + $tree->icon = [' │ ', ' ├─ ', ' └─ ']; | ||
50 | + $tree->nbsp = ' '; | ||
51 | + | ||
52 | + $array = []; | ||
53 | + foreach ($arrResult as $r) { | ||
54 | + $r['str_manage'] = '<a href="' . url("NavMenu/add", ["parent_id" => $r['id'], "nav_id" => $r['nav_id']]) . '">添加子菜单</a> <a href="' | ||
55 | + . url("NavMenu/edit", ["id" => $r['id'], "parent_id" => $r['parent_id'], "nav_id" => $r['nav_id']]) . '">编辑</a> <a class="js-ajax-delete" href="' . url("NavMenu/delete", ["id" => $r['id'], 'nav_id' => $r['nav_id']]) . '">删除</a> '; | ||
56 | + $r['status'] = $r['status'] ? "显示" : "隐藏"; | ||
57 | + $array[] = $r; | ||
58 | + } | ||
59 | + | ||
60 | + $tree->init($array); | ||
61 | + $str = "<tr> | ||
62 | + <td><input name='list_orders[\$id]' type='text' size='3' value='\$list_order' class='input input-order'></td> | ||
63 | + <td>\$id</td> | ||
64 | + <td >\$spacer\$name</td> | ||
65 | + <td>\$status</td> | ||
66 | + <td>\$str_manage</td> | ||
67 | + </tr>"; | ||
68 | + | ||
69 | + $categories = $tree->getTree(0, $str); | ||
70 | + | ||
71 | + $this->assign("categories", $categories); | ||
72 | + $this->assign('nav_id', $intNavId); | ||
73 | + | ||
74 | + return $this->fetch(); | ||
75 | + } | ||
76 | + | ||
77 | + /** | ||
78 | + * 添加导航菜单 | ||
79 | + * @adminMenu( | ||
80 | + * 'name' => '添加导航菜单', | ||
81 | + * 'parent' => 'index', | ||
82 | + * 'display'=> false, | ||
83 | + * 'order' => 10000, | ||
84 | + * 'hasView'=> true, | ||
85 | + * 'icon' => '', | ||
86 | + * 'remark' => '添加导航菜单', | ||
87 | + * 'param' => '' | ||
88 | + * ) | ||
89 | + */ | ||
90 | + public function add() | ||
91 | + { | ||
92 | + $navMenuModel = new NavMenuModel(); | ||
93 | + $intNavId = $this->request->param("nav_id"); | ||
94 | + $intParentId = $this->request->param("parent_id"); | ||
95 | + $objResult = $navMenuModel->where("nav_id", $intNavId)->order(["list_order" => "ASC"])->select(); | ||
96 | + $arrResult = $objResult ? $objResult->toArray() : []; | ||
97 | + | ||
98 | + $tree = new Tree(); | ||
99 | + $tree->icon = [' │ ', ' ├─ ', ' └─ ']; | ||
100 | + $tree->nbsp = ' '; | ||
101 | + $array = []; | ||
102 | + | ||
103 | + foreach ($arrResult as $r) { | ||
104 | + $r['str_manage'] = '<a href="' . url("NavMenu/add", ["parent_id" => $r['id']]) . '">添加子菜单</a> | <a href="' | ||
105 | + . url("NavMenu/edit", ["id" => $r['id']]) . '">编辑</a> | <a class="J_ajax_del" href="' | ||
106 | + . url("NavMenu/delete", ["id" => $r['id']]) . '">删除</a> '; | ||
107 | + $r['status'] = $r['status'] ? "显示" : "隐藏"; | ||
108 | + $r['selected'] = $r['id'] == $intParentId ? "selected" : ""; | ||
109 | + $array[] = $r; | ||
110 | + } | ||
111 | + | ||
112 | + $tree->init($array); | ||
113 | + $str = "<option value='\$id' \$selected>\$spacer\$name</option>"; | ||
114 | + $navTrees = $tree->getTree(0, $str); | ||
115 | + $this->assign("nav_trees", $navTrees); | ||
116 | + | ||
117 | + $navs = $navMenuModel->selectNavs(); | ||
118 | + $this->assign('navs', $navs); | ||
119 | + | ||
120 | + $this->assign("nav_id", $intNavId); | ||
121 | + return $this->fetch(); | ||
122 | + } | ||
123 | + | ||
124 | + /** | ||
125 | + * 添加导航菜单提交保存 | ||
126 | + * @adminMenu( | ||
127 | + * 'name' => '添加导航菜单提交保存', | ||
128 | + * 'parent' => 'index', | ||
129 | + * 'display'=> false, | ||
130 | + * 'hasView'=> false, | ||
131 | + * 'order' => 10000, | ||
132 | + * 'icon' => '', | ||
133 | + * 'remark' => '添加导航菜单提交保存', | ||
134 | + * 'param' => '' | ||
135 | + * ) | ||
136 | + */ | ||
137 | + public function addPost() | ||
138 | + { | ||
139 | + $navMenuModel = new NavMenuModel(); | ||
140 | + $arrData = $this->request->post(); | ||
141 | + | ||
142 | + if (isset($arrData['external_href'])) { | ||
143 | + $arrData['href'] = htmlspecialchars_decode($arrData['external_href']); | ||
144 | + } else { | ||
145 | + $arrData['href'] = htmlspecialchars_decode($arrData['href']); | ||
146 | + $arrData['href'] = base64_decode($arrData['href']); | ||
147 | + } | ||
148 | + | ||
149 | + $navMenuModel->allowField(true)->isUpdate(false)->save($arrData); | ||
150 | + | ||
151 | + $this->success(lang("EDIT_SUCCESS"), url("NavMenu/index", ['nav_id' => $arrData['nav_id']])); | ||
152 | + | ||
153 | + } | ||
154 | + | ||
155 | + /** | ||
156 | + * 编辑导航菜单 | ||
157 | + * @adminMenu( | ||
158 | + * 'name' => '编辑导航菜单', | ||
159 | + * 'parent' => 'index', | ||
160 | + * 'display'=> false, | ||
161 | + * 'hasView'=> true, | ||
162 | + * 'order' => 10000, | ||
163 | + * 'icon' => '', | ||
164 | + * 'remark' => '编辑导航菜单', | ||
165 | + * 'param' => '' | ||
166 | + * ) | ||
167 | + */ | ||
168 | + public function edit() | ||
169 | + { | ||
170 | + $navMenuModel = new NavMenuModel(); | ||
171 | + $intNavId = $this->request->param("nav_id"); | ||
172 | + $intId = $this->request->param("id"); | ||
173 | + $intParentId = $this->request->param("parent_id"); | ||
174 | + $objResult = $navMenuModel->where(["nav_id" => $intNavId, "id" => ["neq", $intId]])->order(["list_order" => "ASC"])->select(); | ||
175 | + $arrResult = $objResult ? $objResult->toArray() : []; | ||
176 | + | ||
177 | + $tree = new Tree(); | ||
178 | + $tree->icon = [' │ ', ' ├─ ', ' └─ ']; | ||
179 | + $tree->nbsp = ' '; | ||
180 | + $array = []; | ||
181 | + foreach ($arrResult as $r) { | ||
182 | + $r['str_manage'] = '<a href="' . url("NavMenu/add", ["parent_id" => $r['id'], "nav_id" => $intNavId]) . '">添加子菜单</a> | <a href="' | ||
183 | + . url("NavMenu/edit", ["id" => $r['id'], "nav_id" => $intNavId]) . '">编辑</a> | <a class="js-ajax-delete" href="' | ||
184 | + . url("NavMenu/delete", ["id" => $r['id'], "nav_id" => $intNavId]) . '">删除</a> '; | ||
185 | + $r['status'] = $r['status'] ? "显示" : "隐藏"; | ||
186 | + $r['selected'] = $r['id'] == $intParentId ? "selected" : ""; | ||
187 | + $array[] = $r; | ||
188 | + } | ||
189 | + | ||
190 | + $tree->init($array); | ||
191 | + $str = "<option value='\$id' \$selected>\$spacer\$name</option>"; | ||
192 | + $nav_trees = $tree->getTree(0, $str); | ||
193 | + $this->assign("nav_trees", $nav_trees); | ||
194 | + | ||
195 | + $objNav = $navMenuModel->where("id", $intId)->find(); | ||
196 | + $arrNav = $objNav ? $objNav->toArray() : []; | ||
197 | + | ||
198 | + $arrNav['href_old'] = $arrNav['href']; | ||
199 | + | ||
200 | + if (strpos($arrNav['href'], "{") === 0 || $arrNav['href'] == 'home') { | ||
201 | + $arrNav['href'] = base64_encode($arrNav['href']); | ||
202 | + } | ||
203 | + | ||
204 | + $this->assign($arrNav); | ||
205 | + | ||
206 | + $navs = $navMenuModel->selectNavs(); | ||
207 | + $this->assign('navs', $navs); | ||
208 | + | ||
209 | + $this->assign("nav_id", $intNavId); | ||
210 | + $this->assign("parent_id", $intParentId); | ||
211 | + | ||
212 | + return $this->fetch(); | ||
213 | + } | ||
214 | + | ||
215 | + /** | ||
216 | + * 编辑导航菜单提交保存 | ||
217 | + * @adminMenu( | ||
218 | + * 'name' => '编辑导航菜单提交保存', | ||
219 | + * 'parent' => 'index', | ||
220 | + * 'display'=> false, | ||
221 | + * 'hasView'=> false, | ||
222 | + * 'order' => 10000, | ||
223 | + * 'icon' => '', | ||
224 | + * 'remark' => '编辑导航菜单提交保存', | ||
225 | + * 'param' => '' | ||
226 | + * ) | ||
227 | + */ | ||
228 | + public function editPost() | ||
229 | + { | ||
230 | + $navMenuModel = new NavMenuModel(); | ||
231 | + $intId = $this->request->param('id', 0, 'intval'); | ||
232 | + $arrData = $this->request->post(); | ||
233 | + | ||
234 | + if (isset($arrData['external_href'])) { | ||
235 | + $arrData['href'] = htmlspecialchars_decode($arrData['external_href']); | ||
236 | + } else { | ||
237 | + $arrData['href'] = htmlspecialchars_decode($arrData['href']); | ||
238 | + $arrData['href'] = base64_decode($arrData['href']); | ||
239 | + } | ||
240 | + | ||
241 | + $navMenuModel->update($arrData, ["id" => $intId], true); | ||
242 | + | ||
243 | + $this->success(lang("EDIT_SUCCESS"), url("NavMenu/index", ['nav_id' => $arrData['nav_id']])); | ||
244 | + | ||
245 | + } | ||
246 | + | ||
247 | + /** | ||
248 | + * 删除导航菜单 | ||
249 | + * @adminMenu( | ||
250 | + * 'name' => '删除导航菜单', | ||
251 | + * 'parent' => 'index', | ||
252 | + * 'display'=> false, | ||
253 | + * 'hasView'=> false, | ||
254 | + * 'order' => 10000, | ||
255 | + * 'icon' => '', | ||
256 | + * 'remark' => '删除导航菜单', | ||
257 | + * 'param' => '' | ||
258 | + * ) | ||
259 | + */ | ||
260 | + public function delete() | ||
261 | + { | ||
262 | + $navMenuModel = new NavMenuModel(); | ||
263 | + | ||
264 | + $intId = $this->request->param("id", 0, "intval"); | ||
265 | + $intNavId = $this->request->param("nav_id", 0, "intval"); | ||
266 | + | ||
267 | + if (empty($intId)) { | ||
268 | + $this->error(lang("NO_ID")); | ||
269 | + } | ||
270 | + | ||
271 | + $count = $navMenuModel->where(["parent_id" => $intId])->count(); | ||
272 | + if ($count > 0) { | ||
273 | + $this->error("该菜单下还有子菜单,无法删除!"); | ||
274 | + } | ||
275 | + | ||
276 | + $navMenuModel->where(["id" => $intId])->delete(); | ||
277 | + $this->success(lang("DELETE_SUCCESS"), url("NavMenu/index", ['nav_id' => $intNavId])); | ||
278 | + | ||
279 | + } | ||
280 | + | ||
281 | + /** | ||
282 | + * 导航菜单排序 | ||
283 | + * @adminMenu( | ||
284 | + * 'name' => '导航菜单排序', | ||
285 | + * 'parent' => 'index', | ||
286 | + * 'display'=> false, | ||
287 | + * 'hasView'=> false, | ||
288 | + * 'order' => 10000, | ||
289 | + * 'icon' => '', | ||
290 | + * 'remark' => '导航菜单排序', | ||
291 | + * 'param' => '' | ||
292 | + * ) | ||
293 | + */ | ||
294 | + public function listOrder() | ||
295 | + { | ||
296 | + $navMenuModel = new NavMenuModel(); | ||
297 | + $status = parent::listOrders($navMenuModel); | ||
298 | + if ($status) { | ||
299 | + $this->success("排序更新成功!"); | ||
300 | + } else { | ||
301 | + $this->error("排序更新失败!"); | ||
302 | + } | ||
303 | + } | ||
304 | + | ||
305 | + | ||
306 | +} |
app/admin/controller/PlayRuleController.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Administrator | ||
5 | + * Date: 2018/6/9 | ||
6 | + * Time: 16:05 | ||
7 | + */ | ||
8 | +namespace app\admin\controller; | ||
9 | +use api\common\model\CommonModel; | ||
10 | +use app\admin\model\PlayRuleModel; | ||
11 | +use cmf\controller\AdminBaseController; | ||
12 | +use Think\Model; | ||
13 | + | ||
14 | + | ||
15 | + | ||
16 | + | ||
17 | +class PlayRuleController extends AdminBaseController{ | ||
18 | + //index方法 | ||
19 | + public function index() | ||
20 | + { | ||
21 | + $playruleModel=new PlayRuleModel(); | ||
22 | + $lists=$playruleModel->getPlayRule(); | ||
23 | + $this->assign('list',$lists); | ||
24 | + return $this->fetch(); | ||
25 | + } | ||
26 | + //编辑规则 | ||
27 | + public function edit() | ||
28 | + { | ||
29 | + $id = $this->request->param('id', 0, 'intval'); | ||
30 | + $playruleModel=new PlayRuleModel(); | ||
31 | + $post=$playruleModel->edit($id); | ||
32 | + $this->assign('post',$post); | ||
33 | + return $this->fetch(); | ||
34 | + | ||
35 | + } | ||
36 | + //编辑规则提交 | ||
37 | + public function editPost() | ||
38 | + { | ||
39 | + $data = $this->request->param(); | ||
40 | + | ||
41 | + $playruleModel=new PlayRuleModel(); | ||
42 | +// $result=$this->allowField(true)->isUpdate(true)->data($data, true)->save(); | ||
43 | + $result=$playruleModel->editPost($data['post']['id'],$data['post']['name'],htmlspecialchars_decode($data['post']['content'])); | ||
44 | + if ($result) { | ||
45 | + return $this->success('编辑成功'); | ||
46 | + } | ||
47 | + } | ||
48 | + //规则添加 | ||
49 | + public function add() | ||
50 | + { | ||
51 | + return $this->fetch(); | ||
52 | + } | ||
53 | + //规则添加提交 | ||
54 | + public function addPost() | ||
55 | + { | ||
56 | + $data=$this->request->param(); | ||
57 | + $data['post']['create_time']=time(); | ||
58 | + | ||
59 | + $playruleModel=new PlayRuleModel(); | ||
60 | + $result=$playruleModel->addPost( $data['post']['name'],htmlspecialchars_decode($data['post']['content']),$data['post']['create_time']); | ||
61 | + if ($result){ | ||
62 | + return $this->success('添加成功','index'); | ||
63 | + } | ||
64 | + } | ||
65 | + //规则删除 | ||
66 | + public function deletePlayRule() | ||
67 | + { | ||
68 | + $id = $this->request->param('id', 0, 'intval'); | ||
69 | + $playruleModel=new PlayRuleModel(); | ||
70 | + $result=$playruleModel->deletePlayRule($id); | ||
71 | + if ($result){ | ||
72 | + return $this->success('删除成功'); | ||
73 | + } | ||
74 | + } | ||
75 | +} |
app/admin/controller/PluginController.php
0 → 100644
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: 老猫 <zxxjjforever@163.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\controller; | ||
12 | + | ||
13 | +use cmf\controller\AdminBaseController; | ||
14 | +use app\admin\model\PluginModel; | ||
15 | +use app\admin\model\HookPluginModel; | ||
16 | +use mindplay\annotations\Annotations; | ||
17 | +use think\Db; | ||
18 | +use think\Validate; | ||
19 | + | ||
20 | +/** | ||
21 | + * Class PluginController | ||
22 | + * @package app\admin\controller | ||
23 | + * @adminMenuRoot( | ||
24 | + * 'name' =>'插件中心', | ||
25 | + * 'action' =>'default', | ||
26 | + * 'parent' =>'', | ||
27 | + * 'display'=> true, | ||
28 | + * 'order' => 20, | ||
29 | + * 'icon' =>'cloud', | ||
30 | + * 'remark' =>'插件中心' | ||
31 | + * ) | ||
32 | + */ | ||
33 | +class PluginController extends AdminBaseController | ||
34 | +{ | ||
35 | + | ||
36 | + protected $pluginModel; | ||
37 | + | ||
38 | + public function _initialize() | ||
39 | + { | ||
40 | + parent::_initialize(); | ||
41 | + } | ||
42 | + | ||
43 | + /** | ||
44 | + * 插件列表 | ||
45 | + * @adminMenu( | ||
46 | + * 'name' => '插件列表', | ||
47 | + * 'parent' => 'admin/Plugin/default', | ||
48 | + * 'display'=> true, | ||
49 | + * 'hasView'=> true, | ||
50 | + * 'order' => 10000, | ||
51 | + * 'icon' => '', | ||
52 | + * 'remark' => '插件列表', | ||
53 | + * 'param' => '' | ||
54 | + * ) | ||
55 | + */ | ||
56 | + public function index() | ||
57 | + { | ||
58 | + $pluginModel = new PluginModel(); | ||
59 | + $plugins = $pluginModel->getList(); | ||
60 | + $this->assign("plugins", $plugins); | ||
61 | + return $this->fetch(); | ||
62 | + } | ||
63 | + | ||
64 | + /** | ||
65 | + * 插件启用/禁用 | ||
66 | + * @adminMenu( | ||
67 | + * 'name' => '插件启用禁用', | ||
68 | + * 'parent' => 'index', | ||
69 | + * 'display'=> false, | ||
70 | + * 'hasView'=> false, | ||
71 | + * 'order' => 10000, | ||
72 | + * 'icon' => '', | ||
73 | + * 'remark' => '插件启用禁用', | ||
74 | + * 'param' => '' | ||
75 | + * ) | ||
76 | + */ | ||
77 | + public function toggle() | ||
78 | + { | ||
79 | + $id = $this->request->param('id', 0, 'intval'); | ||
80 | + | ||
81 | + $pluginModel = PluginModel::get($id); | ||
82 | + | ||
83 | + if (empty($pluginModel)) { | ||
84 | + $this->error('插件不存在!'); | ||
85 | + } | ||
86 | + | ||
87 | + $status = 1; | ||
88 | + $successMessage = "启用成功!"; | ||
89 | + | ||
90 | + if ($this->request->param('disable')) { | ||
91 | + $status = 0; | ||
92 | + $successMessage = "禁用成功!"; | ||
93 | + } | ||
94 | + | ||
95 | + $pluginModel->startTrans(); | ||
96 | + | ||
97 | + try { | ||
98 | + $pluginModel->save(['status' => $status], ['id' => $id]); | ||
99 | + | ||
100 | + $hookPluginModel = new HookPluginModel(); | ||
101 | + | ||
102 | + $hookPluginModel->save(['status' => $status], ['plugin' => $pluginModel->name]); | ||
103 | + | ||
104 | + $pluginModel->commit(); | ||
105 | + | ||
106 | + } catch (\Exception $e) { | ||
107 | + | ||
108 | + $pluginModel->rollback(); | ||
109 | + | ||
110 | + $this->error('操作失败!'); | ||
111 | + | ||
112 | + } | ||
113 | + | ||
114 | + cache('init_hook_plugins', null); | ||
115 | + | ||
116 | + $this->success($successMessage); | ||
117 | + } | ||
118 | + | ||
119 | + /** | ||
120 | + * 插件设置 | ||
121 | + * @adminMenu( | ||
122 | + * 'name' => '插件设置', | ||
123 | + * 'parent' => 'index', | ||
124 | + * 'display'=> false, | ||
125 | + * 'hasView'=> true, | ||
126 | + * 'order' => 10000, | ||
127 | + * 'icon' => '', | ||
128 | + * 'remark' => '插件设置', | ||
129 | + * 'param' => '' | ||
130 | + * ) | ||
131 | + */ | ||
132 | + public function setting() | ||
133 | + { | ||
134 | + $id = $this->request->param('id', 0, 'intval'); | ||
135 | + | ||
136 | + $pluginModel = new PluginModel(); | ||
137 | + $plugin = $pluginModel->find($id); | ||
138 | + | ||
139 | + if (empty($plugin)) { | ||
140 | + $this->error('插件未安装!'); | ||
141 | + } | ||
142 | + | ||
143 | + $plugin = $plugin->toArray(); | ||
144 | + | ||
145 | + $pluginClass = cmf_get_plugin_class($plugin['name']); | ||
146 | + if (!class_exists($pluginClass)) { | ||
147 | + $this->error('插件不存在!'); | ||
148 | + } | ||
149 | + | ||
150 | + $pluginObj = new $pluginClass; | ||
151 | + //$plugin['plugin_path'] = $pluginObj->plugin_path; | ||
152 | + //$plugin['custom_config'] = $pluginObj->custom_config; | ||
153 | + $pluginConfigInDb = $plugin['config']; | ||
154 | + $plugin['config'] = include $pluginObj->getConfigFilePath(); | ||
155 | + | ||
156 | + if ($pluginConfigInDb) { | ||
157 | + $pluginConfigInDb = json_decode($pluginConfigInDb, true); | ||
158 | + foreach ($plugin['config'] as $key => $value) { | ||
159 | + if ($value['type'] != 'group') { | ||
160 | + if (isset($pluginConfigInDb[$key])) { | ||
161 | + $plugin['config'][$key]['value'] = $pluginConfigInDb[$key]; | ||
162 | + } | ||
163 | + } else { | ||
164 | + foreach ($value['options'] as $group => $options) { | ||
165 | + foreach ($options['options'] as $gkey => $value) { | ||
166 | + if (isset($pluginConfigInDb[$gkey])) { | ||
167 | + $plugin['config'][$key]['options'][$group]['options'][$gkey]['value'] = $pluginConfigInDb[$gkey]; | ||
168 | + } | ||
169 | + } | ||
170 | + } | ||
171 | + } | ||
172 | + } | ||
173 | + } | ||
174 | + | ||
175 | + $this->assign('data', $plugin); | ||
176 | +// if ($plugin['custom_config']) { | ||
177 | +// $this->assign('custom_config', $this->fetch($plugin['plugin_path'] . $plugin['custom_config'])); | ||
178 | +// } | ||
179 | + | ||
180 | + $this->assign('id', $id); | ||
181 | + return $this->fetch(); | ||
182 | + | ||
183 | + } | ||
184 | + | ||
185 | + /** | ||
186 | + * 插件设置提交 | ||
187 | + * @adminMenu( | ||
188 | + * 'name' => '插件设置提交', | ||
189 | + * 'parent' => 'index', | ||
190 | + * 'display'=> false, | ||
191 | + * 'hasView'=> false, | ||
192 | + * 'order' => 10000, | ||
193 | + * 'icon' => '', | ||
194 | + * 'remark' => '插件设置提交', | ||
195 | + * 'param' => '' | ||
196 | + * ) | ||
197 | + */ | ||
198 | + public function settingPost() | ||
199 | + { | ||
200 | + if ($this->request->isPost()) { | ||
201 | + $id = $this->request->param('id', 0, 'intval'); | ||
202 | + | ||
203 | + $pluginModel = new PluginModel(); | ||
204 | + $plugin = $pluginModel->find($id)->toArray(); | ||
205 | + | ||
206 | + if (!$plugin) { | ||
207 | + $this->error('插件未安装!'); | ||
208 | + } | ||
209 | + | ||
210 | + $pluginClass = cmf_get_plugin_class($plugin['name']); | ||
211 | + if (!class_exists($pluginClass)) { | ||
212 | + $this->error('插件不存在!'); | ||
213 | + } | ||
214 | + | ||
215 | + $pluginObj = new $pluginClass; | ||
216 | + //$plugin['plugin_path'] = $pluginObj->plugin_path; | ||
217 | + //$plugin['custom_config'] = $pluginObj->custom_config; | ||
218 | + $pluginConfigInDb = $plugin['config']; | ||
219 | + $plugin['config'] = include $pluginObj->getConfigFilePath(); | ||
220 | + | ||
221 | + $rules = []; | ||
222 | + $messages = []; | ||
223 | + | ||
224 | + foreach ($plugin['config'] as $key => $value) { | ||
225 | + if ($value['type'] != 'group') { | ||
226 | + if (isset($value['rule'])) { | ||
227 | + $rules[$key] = $this->_parseRules($value['rule']); | ||
228 | + } | ||
229 | + | ||
230 | + if (isset($value['message'])) { | ||
231 | + foreach ($value['message'] as $rule => $msg) { | ||
232 | + $messages[$key . '.' . $rule] = $msg; | ||
233 | + } | ||
234 | + } | ||
235 | + | ||
236 | + } else { | ||
237 | + foreach ($value['options'] as $group => $options) { | ||
238 | + foreach ($options['options'] as $gkey => $value) { | ||
239 | + if (isset($value['rule'])) { | ||
240 | + $rules[$gkey] = $this->_parseRules($value['rule']); | ||
241 | + } | ||
242 | + | ||
243 | + if (isset($value['message'])) { | ||
244 | + foreach ($value['message'] as $rule => $msg) { | ||
245 | + $messages[$gkey . '.' . $rule] = $msg; | ||
246 | + } | ||
247 | + } | ||
248 | + } | ||
249 | + } | ||
250 | + } | ||
251 | + } | ||
252 | + | ||
253 | + $config = $this->request->param('config/a'); | ||
254 | + | ||
255 | + $validate = new Validate($rules, $messages); | ||
256 | + $result = $validate->check($config); | ||
257 | + if ($result !== true) { | ||
258 | + $this->error($validate->getError()); | ||
259 | + } | ||
260 | + | ||
261 | + $pluginModel = new PluginModel(); | ||
262 | + $pluginModel->save(['config' => json_encode($config)], ['id' => $id]); | ||
263 | + $this->success('保存成功', ''); | ||
264 | + } | ||
265 | + } | ||
266 | + | ||
267 | + /** | ||
268 | + * 解析插件配置验证规则 | ||
269 | + * @param $rules | ||
270 | + * @return array | ||
271 | + */ | ||
272 | + private function _parseRules($rules) | ||
273 | + { | ||
274 | + $newRules = []; | ||
275 | + | ||
276 | + $simpleRules = [ | ||
277 | + 'require', 'number', | ||
278 | + 'integer', 'float', 'boolean', 'email', | ||
279 | + 'array', 'accepted', 'date', 'alpha', | ||
280 | + 'alphaNum', 'alphaDash', 'activeUrl', | ||
281 | + 'url', 'ip']; | ||
282 | + foreach ($rules as $key => $rule) { | ||
283 | + if (in_array($key, $simpleRules) && $rule) { | ||
284 | + array_push($newRules, $key); | ||
285 | + } | ||
286 | + } | ||
287 | + | ||
288 | + return $newRules; | ||
289 | + } | ||
290 | + | ||
291 | + /** | ||
292 | + * 插件安装 | ||
293 | + * @adminMenu( | ||
294 | + * 'name' => '插件安装', | ||
295 | + * 'parent' => 'index', | ||
296 | + * 'display'=> false, | ||
297 | + * 'hasView'=> false, | ||
298 | + * 'order' => 10000, | ||
299 | + * 'icon' => '', | ||
300 | + * 'remark' => '插件安装', | ||
301 | + * 'param' => '' | ||
302 | + * ) | ||
303 | + */ | ||
304 | + public function install() | ||
305 | + { | ||
306 | + $pluginName = $this->request->param('name', '', 'trim'); | ||
307 | + $class = cmf_get_plugin_class($pluginName); | ||
308 | + if (!class_exists($class)) { | ||
309 | + $this->error('插件不存在!'); | ||
310 | + } | ||
311 | + | ||
312 | + $pluginModel = new PluginModel(); | ||
313 | + $pluginCount = $pluginModel->where('name', $pluginName)->count(); | ||
314 | + | ||
315 | + if ($pluginCount > 0) { | ||
316 | + $this->error('插件已安装!'); | ||
317 | + } | ||
318 | + | ||
319 | + $plugin = new $class; | ||
320 | + $info = $plugin->info; | ||
321 | + if (!$info || !$plugin->checkInfo()) {//检测信息的正确性 | ||
322 | + $this->error('插件信息缺失!'); | ||
323 | + } | ||
324 | + | ||
325 | + $installSuccess = $plugin->install(); | ||
326 | + if (!$installSuccess) { | ||
327 | + $this->error('插件预安装失败!'); | ||
328 | + } | ||
329 | + | ||
330 | + $methods = get_class_methods($plugin); | ||
331 | + | ||
332 | + foreach ($methods as $methodKey => $method) { | ||
333 | + $methods[$methodKey] = cmf_parse_name($method); | ||
334 | + } | ||
335 | + | ||
336 | + $systemHooks = $pluginModel->getHooks(true); | ||
337 | + | ||
338 | + $pluginHooks = array_intersect($systemHooks, $methods); | ||
339 | + | ||
340 | + //$info['hooks'] = implode(",", $pluginHooks); | ||
341 | + | ||
342 | + if (!empty($plugin->hasAdmin)) { | ||
343 | + $info['has_admin'] = 1; | ||
344 | + } else { | ||
345 | + $info['has_admin'] = 0; | ||
346 | + } | ||
347 | + | ||
348 | + $info['config'] = json_encode($plugin->getConfig()); | ||
349 | + | ||
350 | + $pluginModel->data($info)->allowField(true)->save(); | ||
351 | + | ||
352 | + $hookPluginModel = new HookPluginModel(); | ||
353 | + foreach ($pluginHooks as $pluginHook) { | ||
354 | + $hookPluginModel->data(['hook' => $pluginHook, 'plugin' => $pluginName, 'status' => 1])->isUpdate(false)->save(); | ||
355 | + } | ||
356 | + | ||
357 | + $this->_getActions($pluginName); | ||
358 | + | ||
359 | + cache('init_hook_plugins', null); | ||
360 | + cache(null, 'admin_menus');// 删除后台菜单缓存 | ||
361 | + | ||
362 | + $this->success('安装成功!'); | ||
363 | + } | ||
364 | + | ||
365 | + /** | ||
366 | + * 插件更新 | ||
367 | + * @adminMenu( | ||
368 | + * 'name' => '插件更新', | ||
369 | + * 'parent' => 'index', | ||
370 | + * 'display'=> false, | ||
371 | + * 'hasView'=> false, | ||
372 | + * 'order' => 10000, | ||
373 | + * 'icon' => '', | ||
374 | + * 'remark' => '插件更新', | ||
375 | + * 'param' => '' | ||
376 | + * ) | ||
377 | + */ | ||
378 | + public function update() | ||
379 | + { | ||
380 | + $pluginName = $this->request->param('name', '', 'trim'); | ||
381 | + $class = cmf_get_plugin_class($pluginName); | ||
382 | + if (!class_exists($class)) { | ||
383 | + $this->error('插件不存在!'); | ||
384 | + } | ||
385 | + | ||
386 | + $plugin = new $class; | ||
387 | + $info = $plugin->info; | ||
388 | + if (!$info || !$plugin->checkInfo()) {//检测信息的正确性 | ||
389 | + $this->error('插件信息缺失!'); | ||
390 | + } | ||
391 | + | ||
392 | + $methods = get_class_methods($plugin); | ||
393 | + | ||
394 | + foreach ($methods as $methodKey => $method) { | ||
395 | + $methods[$methodKey] = cmf_parse_name($method); | ||
396 | + } | ||
397 | + | ||
398 | + $pluginModel = new PluginModel(); | ||
399 | + $systemHooks = $pluginModel->getHooks(true); | ||
400 | + | ||
401 | + $pluginHooks = array_intersect($systemHooks, $methods); | ||
402 | + | ||
403 | + if (!empty($plugin->hasAdmin)) { | ||
404 | + $info['has_admin'] = 1; | ||
405 | + } else { | ||
406 | + $info['has_admin'] = 0; | ||
407 | + } | ||
408 | + | ||
409 | + $config = $plugin->getConfig(); | ||
410 | + | ||
411 | + $defaultConfig = $plugin->getDefaultConfig(); | ||
412 | + | ||
413 | + $pluginModel = new PluginModel(); | ||
414 | + | ||
415 | + $config = array_merge($defaultConfig, $config); | ||
416 | + | ||
417 | + $info['config'] = json_encode($config); | ||
418 | + | ||
419 | + $pluginModel->allowField(true)->save($info, ['name' => $pluginName]); | ||
420 | + | ||
421 | + $hookPluginModel = new HookPluginModel(); | ||
422 | + | ||
423 | + $pluginHooksInDb = $hookPluginModel->where('plugin', $pluginName)->column('hook'); | ||
424 | + | ||
425 | + $samePluginHooks = array_intersect($pluginHooks, $pluginHooksInDb); | ||
426 | + | ||
427 | + $shouldDeleteHooks = array_diff($samePluginHooks, $pluginHooksInDb); | ||
428 | + | ||
429 | + $newHooks = array_diff($pluginHooks, $samePluginHooks); | ||
430 | + | ||
431 | + if (count($shouldDeleteHooks) > 0) { | ||
432 | + $hookPluginModel->where('hook', 'in', $shouldDeleteHooks)->delete(); | ||
433 | + } | ||
434 | + | ||
435 | + foreach ($newHooks as $pluginHook) { | ||
436 | + $hookPluginModel->data(['hook' => $pluginHook, 'plugin' => $pluginName])->isUpdate(false)->save(); | ||
437 | + } | ||
438 | + | ||
439 | + $this->_getActions($pluginName); | ||
440 | + | ||
441 | + cache('init_hook_plugins', null); | ||
442 | + cache(null, 'admin_menus');// 删除后台菜单缓存 | ||
443 | + | ||
444 | + $this->success('更新成功!'); | ||
445 | + } | ||
446 | + | ||
447 | + private function _getActions($pluginName) | ||
448 | + { | ||
449 | + Annotations::$config['cache'] = false; | ||
450 | + $annotationManager = Annotations::getManager(); | ||
451 | + $annotationManager->registry['adminMenu'] = 'app\admin\annotation\AdminMenuAnnotation'; | ||
452 | + $newMenus = []; | ||
453 | + | ||
454 | + $pluginDir = cmf_parse_name($pluginName); | ||
455 | + | ||
456 | + $filePatten = PLUGINS_PATH . $pluginDir . '/controller/Admin*Controller.php'; | ||
457 | + | ||
458 | + $controllers = cmf_scan_dir($filePatten); | ||
459 | + | ||
460 | + if (!empty($controllers)) { | ||
461 | + foreach ($controllers as $controller) { | ||
462 | + $controller = preg_replace('/\.php$/', '', $controller); | ||
463 | + $controllerName = preg_replace('/\Controller$/', '', $controller); | ||
464 | + $controllerClass = "plugins\\$pluginDir\\controller\\$controller"; | ||
465 | + | ||
466 | + $reflect = new \ReflectionClass($controllerClass); | ||
467 | + $methods = $reflect->getMethods(\ReflectionMethod::IS_PUBLIC); | ||
468 | + | ||
469 | + if (!empty($methods)) { | ||
470 | + foreach ($methods as $method) { | ||
471 | + | ||
472 | + if ($method->class == $controllerClass && strpos($method->name, '_') !== 0) { | ||
473 | + $menuAnnotations = Annotations::ofMethod($controllerClass, $method->name, '@adminMenu'); | ||
474 | + | ||
475 | + if (!empty($menuAnnotations)) { | ||
476 | + | ||
477 | + $menuAnnotation = $menuAnnotations[0]; | ||
478 | + | ||
479 | + $name = $menuAnnotation->name; | ||
480 | + $icon = $menuAnnotation->icon; | ||
481 | + $type = $menuAnnotation->hasView ? 1 : 2;//1:有界面可访问菜单,2:无界面可访问菜单,0:只作为菜单 | ||
482 | + $action = $method->name; | ||
483 | + $status = empty($menuAnnotation->display) ? 0 : 1; | ||
484 | + $listOrder = floatval($menuAnnotation->order); | ||
485 | + $param = $menuAnnotation->param; | ||
486 | + $remark = $menuAnnotation->remark; | ||
487 | + | ||
488 | + if (empty($menuAnnotation->parent)) { | ||
489 | + $parentId = 0; | ||
490 | + } else { | ||
491 | + $parent = explode('/', $menuAnnotation->parent); | ||
492 | + $countParent = count($parent); | ||
493 | + if ($countParent > 3) { | ||
494 | + throw new \Exception($controllerClass . ':' . $action . ' @menuRoot parent格式不正确!'); | ||
495 | + } | ||
496 | + | ||
497 | + $parentApp = 'plugin/' . $pluginName; | ||
498 | + $parentController = $controllerName; | ||
499 | + $parentAction = ''; | ||
500 | + | ||
501 | + switch ($countParent) { | ||
502 | + case 1: | ||
503 | + $parentAction = $parent[0]; | ||
504 | + break; | ||
505 | + case 2: | ||
506 | + $parentController = $parent[0]; | ||
507 | + $parentAction = $parent[1]; | ||
508 | + break; | ||
509 | + case 3: | ||
510 | + $parentApp = $parent[0]; | ||
511 | + $parentController = $parent[1]; | ||
512 | + $parentAction = $parent[2]; | ||
513 | + break; | ||
514 | + } | ||
515 | + | ||
516 | + $findParentAdminMenu = Db::name('admin_menu')->where([ | ||
517 | + 'app' => $parentApp, | ||
518 | + 'controller' => $parentController, | ||
519 | + 'action' => $parentAction | ||
520 | + ])->find(); | ||
521 | + | ||
522 | + if (empty($findParentAdminMenu)) { | ||
523 | + $parentId = Db::name('admin_menu')->insertGetId([ | ||
524 | + 'app' => $parentApp, | ||
525 | + 'controller' => $parentController, | ||
526 | + 'action' => $parentAction, | ||
527 | + 'name' => '--new--' | ||
528 | + ]); | ||
529 | + } else { | ||
530 | + $parentId = $findParentAdminMenu['id']; | ||
531 | + } | ||
532 | + } | ||
533 | + | ||
534 | + $findAdminMenu = Db::name('admin_menu')->where([ | ||
535 | + 'app' => 'plugin/' . $pluginName, | ||
536 | + 'controller' => $controllerName, | ||
537 | + 'action' => $action | ||
538 | + ])->find(); | ||
539 | + | ||
540 | + if (empty($findAdminMenu)) { | ||
541 | + | ||
542 | + Db::name('admin_menu')->insert([ | ||
543 | + 'parent_id' => $parentId, | ||
544 | + 'type' => $type, | ||
545 | + 'status' => $status, | ||
546 | + 'list_order' => $listOrder, | ||
547 | + 'app' => 'plugin/' . $pluginName, | ||
548 | + 'controller' => $controllerName, | ||
549 | + 'action' => $action, | ||
550 | + 'param' => $param, | ||
551 | + 'name' => $name, | ||
552 | + 'icon' => $icon, | ||
553 | + 'remark' => $remark | ||
554 | + ]); | ||
555 | + | ||
556 | + $menuName = $name; | ||
557 | + | ||
558 | + //array_push($newMenus, "$app/$controllerName/$action 已导入"); | ||
559 | + | ||
560 | + } else { | ||
561 | + if ($findAdminMenu['name'] == '--new--') { | ||
562 | + Db::name('admin_menu')->where([ | ||
563 | + 'app' => 'plugin/' . $pluginName, | ||
564 | + 'controller' => $controllerName, | ||
565 | + 'action' => $action | ||
566 | + ])->update([ | ||
567 | + 'parent_id' => $parentId, | ||
568 | + 'type' => $type, | ||
569 | + 'status' => $status, | ||
570 | + 'list_order' => $listOrder, | ||
571 | + 'param' => $param, | ||
572 | + 'name' => $name, | ||
573 | + 'icon' => $icon, | ||
574 | + 'remark' => $remark | ||
575 | + ]); | ||
576 | + $menuName = $name; | ||
577 | + } else { | ||
578 | + // 只关注是否有视图 | ||
579 | + Db::name('admin_menu')->where([ | ||
580 | + 'app' => 'plugin/' . $pluginName, | ||
581 | + 'controller' => $controllerName, | ||
582 | + 'action' => $action | ||
583 | + ])->update([ | ||
584 | + //'parent_id' => $parentId, | ||
585 | + 'type' => $type, | ||
586 | + ]); | ||
587 | + $menuName = $findAdminMenu['name']; | ||
588 | + } | ||
589 | + | ||
590 | + | ||
591 | +// array_push($newMenus, "$app/$controllerName/$action 已更新"); | ||
592 | + } | ||
593 | + | ||
594 | + $authRuleName = "plugin/{$pluginName}/{$controllerName}/{$action}"; | ||
595 | + $findAuthRuleCount = Db::name('auth_rule')->where([ | ||
596 | + 'app' => 'plugin/' . $pluginName, | ||
597 | + 'name' => $authRuleName, | ||
598 | + 'type' => 'plugin_url' | ||
599 | + ])->count(); | ||
600 | + | ||
601 | + if ($findAuthRuleCount == 0) { | ||
602 | + Db::name('auth_rule')->insert([ | ||
603 | + 'app' => 'plugin/' . $pluginName, | ||
604 | + 'name' => $authRuleName, | ||
605 | + 'type' => 'plugin_url', | ||
606 | + 'param' => $param, | ||
607 | + 'title' => $menuName | ||
608 | + ]); | ||
609 | + } else { | ||
610 | + Db::name('auth_rule')->where([ | ||
611 | + 'app' => 'plugin/' . $pluginName, | ||
612 | + 'name' => $authRuleName, | ||
613 | + 'type' => 'plugin_url', | ||
614 | + ])->update([ | ||
615 | + 'param' => $param, | ||
616 | + 'title' => $menuName | ||
617 | + ]); | ||
618 | + } | ||
619 | + } | ||
620 | + | ||
621 | + } | ||
622 | + } | ||
623 | + } | ||
624 | + | ||
625 | + } | ||
626 | + } | ||
627 | + | ||
628 | + } | ||
629 | + | ||
630 | + /** | ||
631 | + * 卸载插件 | ||
632 | + * @adminMenu( | ||
633 | + * 'name' => '卸载插件', | ||
634 | + * 'parent' => 'index', | ||
635 | + * 'display'=> false, | ||
636 | + * 'hasView'=> false, | ||
637 | + * 'order' => 10000, | ||
638 | + * 'icon' => '', | ||
639 | + * 'remark' => '卸载插件', | ||
640 | + * 'param' => '' | ||
641 | + * ) | ||
642 | + */ | ||
643 | + public function uninstall() | ||
644 | + { | ||
645 | + $pluginModel = new PluginModel(); | ||
646 | + $id = $this->request->param('id', 0, 'intval'); | ||
647 | + | ||
648 | + $result = $pluginModel->uninstall($id); | ||
649 | + | ||
650 | + if ($result !== true) { | ||
651 | + $this->error('卸载失败!'); | ||
652 | + } | ||
653 | + | ||
654 | + cache('init_hook_plugins', null); | ||
655 | + cache(null, 'admin_menus');// 删除后台菜单缓存 | ||
656 | + | ||
657 | + $this->success('卸载成功!'); | ||
658 | + } | ||
659 | + | ||
660 | + | ||
661 | +} |
app/admin/controller/PrizeController.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Administrator | ||
5 | + * Date: 2018/6/9 | ||
6 | + * Time: 16:05 | ||
7 | + */ | ||
8 | +namespace app\admin\controller; | ||
9 | +use api\common\model\CommonModel; | ||
10 | +use app\admin\model\PrizeModel; | ||
11 | +use cmf\controller\AdminBaseController; | ||
12 | +use Think\Model; | ||
13 | + | ||
14 | + | ||
15 | + | ||
16 | + | ||
17 | +class PrizeController extends AdminBaseController{ | ||
18 | + //index方法 | ||
19 | + public function index() | ||
20 | + { | ||
21 | + echo time(); | ||
22 | + echo date('Y-m-d H:i',time()); | ||
23 | + $prizeModel=new PrizeModel(); | ||
24 | + $lists=$prizeModel->getPrize(); | ||
25 | + $this->assign('list',$lists); | ||
26 | + return $this->fetch(); | ||
27 | + } | ||
28 | + //编辑奖品 | ||
29 | + public function edit() | ||
30 | + { | ||
31 | + $id = $this->request->param('id', 0, 'intval'); | ||
32 | + $prizeModel=new PrizeModel(); | ||
33 | + $post=$prizeModel->edit($id); | ||
34 | + $this->assign('post',$post); | ||
35 | + return $this->fetch(); | ||
36 | + | ||
37 | + } | ||
38 | + //编辑奖品提交 | ||
39 | + public function editPost() | ||
40 | + { | ||
41 | + $data = $this->request->param(); | ||
42 | + | ||
43 | + $prizeModel=new PrizeModel(); | ||
44 | + $result=$prizeModel->editPost($data['post']['id'],$data['post']['name'],$data['post']['place'],$data['post']['status']); | ||
45 | + if ($result) { | ||
46 | + return $this->success('编辑成功'); | ||
47 | + } | ||
48 | + } | ||
49 | + //奖品添加 | ||
50 | + public function add() | ||
51 | + { | ||
52 | + return $this->fetch(); | ||
53 | + } | ||
54 | + //奖品添加提交 | ||
55 | + public function addPost() | ||
56 | + { | ||
57 | + $data=$this->request->param(); | ||
58 | + $data['post']['status']=0; | ||
59 | + $data['post']['create_time']=time(); | ||
60 | + | ||
61 | + $prizeModel=new PrizeModel(); | ||
62 | + $result=$prizeModel->addPost( $data['post']['name'],$data['post']['place'],$data['post']['status'],$data['post']['create_time']); | ||
63 | + if ($result){ | ||
64 | + return $this->success('添加成功'); | ||
65 | + } | ||
66 | + } | ||
67 | + //奖品删除 | ||
68 | + public function deletePrize() | ||
69 | + { | ||
70 | + $id = $this->request->param('id', 0, 'intval'); | ||
71 | + $prizeModel=new PrizeModel(); | ||
72 | + $result=$prizeModel->deletePrize($id); | ||
73 | + if ($result){ | ||
74 | + return $this->success('删除成功'); | ||
75 | + } | ||
76 | + } | ||
77 | +} |
app/admin/controller/PublicController.php
0 → 100644
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: 小夏 < 449134904@qq.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\controller; | ||
12 | + | ||
13 | +use cmf\controller\AdminBaseController; | ||
14 | +use think\Db; | ||
15 | + | ||
16 | +class PublicController extends AdminBaseController | ||
17 | +{ | ||
18 | + public function _initialize() | ||
19 | + { | ||
20 | + } | ||
21 | + | ||
22 | + /** | ||
23 | + * 后台登陆界面 | ||
24 | + */ | ||
25 | + public function login() | ||
26 | + { | ||
27 | + $loginAllowed = session("__LOGIN_BY_CMF_ADMIN_PW__"); | ||
28 | + if (empty($loginAllowed)) { | ||
29 | + //$this->error('非法登录!', cmf_get_root() . '/'); | ||
30 | + return redirect(cmf_get_root() . "/"); | ||
31 | + } | ||
32 | + | ||
33 | + $admin_id = session('ADMIN_ID'); | ||
34 | + if (!empty($admin_id)) {//已经登录 | ||
35 | + return redirect(url("admin/Index/index")); | ||
36 | + } else { | ||
37 | + $site_admin_url_password = config("cmf_SITE_ADMIN_URL_PASSWORD"); | ||
38 | + $upw = session("__CMF_UPW__"); | ||
39 | + if (!empty($site_admin_url_password) && $upw != $site_admin_url_password) { | ||
40 | + return redirect(cmf_get_root() . "/"); | ||
41 | + } else { | ||
42 | + session("__SP_ADMIN_LOGIN_PAGE_SHOWED_SUCCESS__", true); | ||
43 | + $result = hook_one('admin_login'); | ||
44 | + if (!empty($result)) { | ||
45 | + return $result; | ||
46 | + } | ||
47 | + return $this->fetch(":login"); | ||
48 | + } | ||
49 | + } | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
53 | + * 登录验证 | ||
54 | + */ | ||
55 | + public function doLogin() | ||
56 | + { | ||
57 | + $loginAllowed = session("__LOGIN_BY_CMF_ADMIN_PW__"); | ||
58 | + if (empty($loginAllowed)) { | ||
59 | + $this->error('非法登录!', cmf_get_root() . '/'); | ||
60 | + } | ||
61 | + | ||
62 | + $captcha = $this->request->param('captcha'); | ||
63 | + if (empty($captcha)) { | ||
64 | + $this->error(lang('CAPTCHA_REQUIRED')); | ||
65 | + } | ||
66 | + //验证码 | ||
67 | + if (!cmf_captcha_check($captcha)) { | ||
68 | + $this->error(lang('CAPTCHA_NOT_RIGHT')); | ||
69 | + } | ||
70 | + | ||
71 | + $name = $this->request->param("username"); | ||
72 | + if (empty($name)) { | ||
73 | + $this->error(lang('USERNAME_OR_EMAIL_EMPTY')); | ||
74 | + } | ||
75 | + $pass = $this->request->param("password"); | ||
76 | + if (empty($pass)) { | ||
77 | + $this->error(lang('PASSWORD_REQUIRED')); | ||
78 | + } | ||
79 | + if (strpos($name, "@") > 0) {//邮箱登陆 | ||
80 | + $where['user_email'] = $name; | ||
81 | + } else { | ||
82 | + $where['user_login'] = $name; | ||
83 | + } | ||
84 | + | ||
85 | + $result = Db::name('user')->where($where)->find(); | ||
86 | + | ||
87 | + if (!empty($result) && $result['user_type'] == 1) { | ||
88 | + if (cmf_compare_password($pass, $result['user_pass'])) { | ||
89 | + $groups = Db::name('RoleUser') | ||
90 | + ->alias("a") | ||
91 | + ->join('__ROLE__ b', 'a.role_id =b.id') | ||
92 | + ->where(["user_id" => $result["id"], "status" => 1]) | ||
93 | + ->value("role_id"); | ||
94 | + if ($result["id"] != 1 && (empty($groups) || empty($result['user_status']))) { | ||
95 | + $this->error(lang('USE_DISABLED')); | ||
96 | + } | ||
97 | + //登入成功页面跳转 | ||
98 | + session('ADMIN_ID', $result["id"]); | ||
99 | + session('name', $result["user_login"]); | ||
100 | + $result['last_login_ip'] = get_client_ip(0, true); | ||
101 | + $result['last_login_time'] = time(); | ||
102 | + $token = cmf_generate_user_token($result["id"], 'web'); | ||
103 | + if (!empty($token)) { | ||
104 | + session('token', $token); | ||
105 | + } | ||
106 | + Db::name('user')->update($result); | ||
107 | + cookie("admin_username", $name, 3600 * 24 * 30); | ||
108 | + session("__LOGIN_BY_CMF_ADMIN_PW__", null); | ||
109 | + $this->success(lang('LOGIN_SUCCESS'), url("admin/Index/index")); | ||
110 | + } else { | ||
111 | + $this->error(lang('PASSWORD_NOT_RIGHT')); | ||
112 | + } | ||
113 | + } else { | ||
114 | + $this->error(lang('USERNAME_NOT_EXIST')); | ||
115 | + } | ||
116 | + } | ||
117 | + | ||
118 | + /** | ||
119 | + * 后台管理员退出 | ||
120 | + */ | ||
121 | + public function logout() | ||
122 | + { | ||
123 | + session('ADMIN_ID', null); | ||
124 | + return redirect(url('/', [], false, true)); | ||
125 | + } | ||
126 | +} |
app/admin/controller/RbacController.php
0 → 100644
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: 小夏 < 449134904@qq.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\controller; | ||
12 | + | ||
13 | +use cmf\controller\AdminBaseController; | ||
14 | +use think\Db; | ||
15 | +use tree\Tree; | ||
16 | +use app\admin\model\AdminMenuModel; | ||
17 | + | ||
18 | +class RbacController extends AdminBaseController | ||
19 | +{ | ||
20 | + | ||
21 | + /** | ||
22 | + * 角色管理列表 | ||
23 | + * @adminMenu( | ||
24 | + * 'name' => '角色管理', | ||
25 | + * 'parent' => 'admin/User/default', | ||
26 | + * 'display'=> true, | ||
27 | + * 'hasView'=> true, | ||
28 | + * 'order' => 10000, | ||
29 | + * 'icon' => '', | ||
30 | + * 'remark' => '角色管理', | ||
31 | + * 'param' => '' | ||
32 | + * ) | ||
33 | + */ | ||
34 | + public function index() | ||
35 | + { | ||
36 | + $data = Db::name('role')->order(["list_order" => "ASC", "id" => "DESC"])->select(); | ||
37 | + $this->assign("roles", $data); | ||
38 | + return $this->fetch(); | ||
39 | + } | ||
40 | + | ||
41 | + /** | ||
42 | + * 添加角色 | ||
43 | + * @adminMenu( | ||
44 | + * 'name' => '添加角色', | ||
45 | + * 'parent' => 'index', | ||
46 | + * 'display'=> false, | ||
47 | + * 'hasView'=> true, | ||
48 | + * 'order' => 10000, | ||
49 | + * 'icon' => '', | ||
50 | + * 'remark' => '添加角色', | ||
51 | + * 'param' => '' | ||
52 | + * ) | ||
53 | + */ | ||
54 | + public function roleAdd() | ||
55 | + { | ||
56 | + return $this->fetch(); | ||
57 | + } | ||
58 | + | ||
59 | + /** | ||
60 | + * 添加角色提交 | ||
61 | + * @adminMenu( | ||
62 | + * 'name' => '添加角色提交', | ||
63 | + * 'parent' => 'index', | ||
64 | + * 'display'=> false, | ||
65 | + * 'hasView'=> false, | ||
66 | + * 'order' => 10000, | ||
67 | + * 'icon' => '', | ||
68 | + * 'remark' => '添加角色提交', | ||
69 | + * 'param' => '' | ||
70 | + * ) | ||
71 | + */ | ||
72 | + public function roleAddPost() | ||
73 | + { | ||
74 | + if ($this->request->isPost()) { | ||
75 | + $data = $this->request->param(); | ||
76 | + $result = $this->validate($data, 'role'); | ||
77 | + if ($result !== true) { | ||
78 | + // 验证失败 输出错误信息 | ||
79 | + $this->error($result); | ||
80 | + } else { | ||
81 | + $result = Db::name('role')->insert($data); | ||
82 | + if ($result) { | ||
83 | + $this->success("添加角色成功", url("rbac/index")); | ||
84 | + } else { | ||
85 | + $this->error("添加角色失败"); | ||
86 | + } | ||
87 | + | ||
88 | + } | ||
89 | + } | ||
90 | + } | ||
91 | + | ||
92 | + /** | ||
93 | + * 编辑角色 | ||
94 | + * @adminMenu( | ||
95 | + * 'name' => '编辑角色', | ||
96 | + * 'parent' => 'index', | ||
97 | + * 'display'=> false, | ||
98 | + * 'hasView'=> true, | ||
99 | + * 'order' => 10000, | ||
100 | + * 'icon' => '', | ||
101 | + * 'remark' => '编辑角色', | ||
102 | + * 'param' => '' | ||
103 | + * ) | ||
104 | + */ | ||
105 | + public function roleEdit() | ||
106 | + { | ||
107 | + $id = $this->request->param("id", 0, 'intval'); | ||
108 | + if ($id == 1) { | ||
109 | + $this->error("超级管理员角色不能被修改!"); | ||
110 | + } | ||
111 | + $data = Db::name('role')->where(["id" => $id])->find(); | ||
112 | + if (!$data) { | ||
113 | + $this->error("该角色不存在!"); | ||
114 | + } | ||
115 | + $this->assign("data", $data); | ||
116 | + return $this->fetch(); | ||
117 | + } | ||
118 | + | ||
119 | + /** | ||
120 | + * 编辑角色提交 | ||
121 | + * @adminMenu( | ||
122 | + * 'name' => '编辑角色提交', | ||
123 | + * 'parent' => 'index', | ||
124 | + * 'display'=> false, | ||
125 | + * 'hasView'=> false, | ||
126 | + * 'order' => 10000, | ||
127 | + * 'icon' => '', | ||
128 | + * 'remark' => '编辑角色提交', | ||
129 | + * 'param' => '' | ||
130 | + * ) | ||
131 | + */ | ||
132 | + public function roleEditPost() | ||
133 | + { | ||
134 | + $id = $this->request->param("id", 0, 'intval'); | ||
135 | + if ($id == 1) { | ||
136 | + $this->error("超级管理员角色不能被修改!"); | ||
137 | + } | ||
138 | + if ($this->request->isPost()) { | ||
139 | + $data = $this->request->param(); | ||
140 | + $result = $this->validate($data, 'role'); | ||
141 | + if ($result !== true) { | ||
142 | + // 验证失败 输出错误信息 | ||
143 | + $this->error($result); | ||
144 | + | ||
145 | + } else { | ||
146 | + if (Db::name('role')->update($data) !== false) { | ||
147 | + $this->success("保存成功!", url('rbac/index')); | ||
148 | + } else { | ||
149 | + $this->error("保存失败!"); | ||
150 | + } | ||
151 | + } | ||
152 | + } | ||
153 | + } | ||
154 | + | ||
155 | + /** | ||
156 | + * 删除角色 | ||
157 | + * @adminMenu( | ||
158 | + * 'name' => '删除角色', | ||
159 | + * 'parent' => 'index', | ||
160 | + * 'display'=> false, | ||
161 | + * 'hasView'=> false, | ||
162 | + * 'order' => 10000, | ||
163 | + * 'icon' => '', | ||
164 | + * 'remark' => '删除角色', | ||
165 | + * 'param' => '' | ||
166 | + * ) | ||
167 | + */ | ||
168 | + public function roleDelete() | ||
169 | + { | ||
170 | + $id = $this->request->param("id", 0, 'intval'); | ||
171 | + if ($id == 1) { | ||
172 | + $this->error("超级管理员角色不能被删除!"); | ||
173 | + } | ||
174 | + $count = Db::name('RoleUser')->where(['role_id' => $id])->count(); | ||
175 | + if ($count > 0) { | ||
176 | + $this->error("该角色已经有用户!"); | ||
177 | + } else { | ||
178 | + $status = Db::name('role')->delete($id); | ||
179 | + if (!empty($status)) { | ||
180 | + $this->success("删除成功!", url('rbac/index')); | ||
181 | + } else { | ||
182 | + $this->error("删除失败!"); | ||
183 | + } | ||
184 | + } | ||
185 | + } | ||
186 | + | ||
187 | + /** | ||
188 | + * 设置角色权限 | ||
189 | + * @adminMenu( | ||
190 | + * 'name' => '设置角色权限', | ||
191 | + * 'parent' => 'index', | ||
192 | + * 'display'=> false, | ||
193 | + * 'hasView'=> true, | ||
194 | + * 'order' => 10000, | ||
195 | + * 'icon' => '', | ||
196 | + * 'remark' => '设置角色权限', | ||
197 | + * 'param' => '' | ||
198 | + * ) | ||
199 | + */ | ||
200 | + public function authorize() | ||
201 | + { | ||
202 | + $AuthAccess = Db::name("AuthAccess"); | ||
203 | + $adminMenuModel = new AdminMenuModel(); | ||
204 | + //角色ID | ||
205 | + $roleId = $this->request->param("id", 0, 'intval'); | ||
206 | + if (empty($roleId)) { | ||
207 | + $this->error("参数错误!"); | ||
208 | + } | ||
209 | + | ||
210 | + $tree = new Tree(); | ||
211 | + $tree->icon = ['│ ', '├─ ', '└─ ']; | ||
212 | + $tree->nbsp = ' '; | ||
213 | + | ||
214 | + $result = $adminMenuModel->menuCache(); | ||
215 | + | ||
216 | + $newMenus = []; | ||
217 | + $privilegeData = $AuthAccess->where(["role_id" => $roleId])->column("rule_name");//获取权限表数据 | ||
218 | + | ||
219 | + foreach ($result as $m) { | ||
220 | + $newMenus[$m['id']] = $m; | ||
221 | + } | ||
222 | + | ||
223 | + foreach ($result as $n => $t) { | ||
224 | + $result[$n]['checked'] = ($this->_isChecked($t, $privilegeData)) ? ' checked' : ''; | ||
225 | + $result[$n]['level'] = $this->_getLevel($t['id'], $newMenus); | ||
226 | + $result[$n]['style'] = empty($t['parent_id']) ? '' : 'display:none;'; | ||
227 | + $result[$n]['parentIdNode'] = ($t['parent_id']) ? ' class="child-of-node-' . $t['parent_id'] . '"' : ''; | ||
228 | + } | ||
229 | + | ||
230 | + $str = "<tr id='node-\$id'\$parentIdNode style='\$style'> | ||
231 | + <td style='padding-left:30px;'>\$spacer<input type='checkbox' name='menuId[]' value='\$id' level='\$level' \$checked onclick='javascript:checknode(this);'> \$name</td> | ||
232 | + </tr>"; | ||
233 | + $tree->init($result); | ||
234 | + | ||
235 | + $category = $tree->getTree(0, $str); | ||
236 | + | ||
237 | + $this->assign("category", $category); | ||
238 | + $this->assign("roleId", $roleId); | ||
239 | + return $this->fetch(); | ||
240 | + } | ||
241 | + | ||
242 | + /** | ||
243 | + * 角色授权提交 | ||
244 | + * @adminMenu( | ||
245 | + * 'name' => '角色授权提交', | ||
246 | + * 'parent' => 'index', | ||
247 | + * 'display'=> false, | ||
248 | + * 'hasView'=> false, | ||
249 | + * 'order' => 10000, | ||
250 | + * 'icon' => '', | ||
251 | + * 'remark' => '角色授权提交', | ||
252 | + * 'param' => '' | ||
253 | + * ) | ||
254 | + */ | ||
255 | + public function authorizePost() | ||
256 | + { | ||
257 | + if ($this->request->isPost()) { | ||
258 | + $roleId = $this->request->param("roleId", 0, 'intval'); | ||
259 | + if (!$roleId) { | ||
260 | + $this->error("需要授权的角色不存在!"); | ||
261 | + } | ||
262 | + if (is_array($this->request->param('menuId/a')) && count($this->request->param('menuId/a')) > 0) { | ||
263 | + | ||
264 | + Db::name("authAccess")->where(["role_id" => $roleId, 'type' => 'admin_url'])->delete(); | ||
265 | + foreach ($_POST['menuId'] as $menuId) { | ||
266 | + $menu = Db::name("adminMenu")->where(["id" => $menuId])->field("app,controller,action")->find(); | ||
267 | + if ($menu) { | ||
268 | + $app = $menu['app']; | ||
269 | + $model = $menu['controller']; | ||
270 | + $action = $menu['action']; | ||
271 | + $name = strtolower("$app/$model/$action"); | ||
272 | + Db::name("authAccess")->insert(["role_id" => $roleId, "rule_name" => $name, 'type' => 'admin_url']); | ||
273 | + } | ||
274 | + } | ||
275 | + | ||
276 | + cache(null, 'admin_menus');// 删除后台菜单缓存 | ||
277 | + | ||
278 | + $this->success("授权成功!"); | ||
279 | + } else { | ||
280 | + //当没有数据时,清除当前角色授权 | ||
281 | + Db::name("authAccess")->where(["role_id" => $roleId])->delete(); | ||
282 | + $this->error("没有接收到数据,执行清除授权成功!"); | ||
283 | + } | ||
284 | + } | ||
285 | + } | ||
286 | + | ||
287 | + /** | ||
288 | + * 检查指定菜单是否有权限 | ||
289 | + * @param array $menu menu表中数组 | ||
290 | + * @param $privData | ||
291 | + * @return bool | ||
292 | + */ | ||
293 | + private function _isChecked($menu, $privData) | ||
294 | + { | ||
295 | + $app = $menu['app']; | ||
296 | + $model = $menu['controller']; | ||
297 | + $action = $menu['action']; | ||
298 | + $name = strtolower("$app/$model/$action"); | ||
299 | + if ($privData) { | ||
300 | + if (in_array($name, $privData)) { | ||
301 | + return true; | ||
302 | + } else { | ||
303 | + return false; | ||
304 | + } | ||
305 | + } else { | ||
306 | + return false; | ||
307 | + } | ||
308 | + | ||
309 | + } | ||
310 | + | ||
311 | + /** | ||
312 | + * 获取菜单深度 | ||
313 | + * @param $id | ||
314 | + * @param array $array | ||
315 | + * @param int $i | ||
316 | + * @return int | ||
317 | + */ | ||
318 | + protected function _getLevel($id, $array = [], $i = 0) | ||
319 | + { | ||
320 | + if ($array[$id]['parent_id'] == 0 || empty($array[$array[$id]['parent_id']]) || $array[$id]['parent_id'] == $id) { | ||
321 | + return $i; | ||
322 | + } else { | ||
323 | + $i++; | ||
324 | + return $this->_getLevel($array[$id]['parent_id'], $array, $i); | ||
325 | + } | ||
326 | + } | ||
327 | + | ||
328 | + //角色成员管理 | ||
329 | + public function member() | ||
330 | + { | ||
331 | + //TODO 添加角色成员管理 | ||
332 | + | ||
333 | + } | ||
334 | + | ||
335 | +} | ||
336 | + |
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: 小夏 < 449134904@qq.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\controller; | ||
12 | + | ||
13 | +use app\admin\model\RecycleBinModel; | ||
14 | +use app\admin\model\RouteModel; | ||
15 | +use cmf\controller\AdminBaseController; | ||
16 | +use think\Db; | ||
17 | + | ||
18 | +class RecycleBinController extends AdminBaseController | ||
19 | +{ | ||
20 | + /** | ||
21 | + * 回收站 | ||
22 | + * @adminMenu( | ||
23 | + * 'name' => '回收站', | ||
24 | + * 'parent' => '', | ||
25 | + * 'display'=> false, | ||
26 | + * 'hasView'=> true, | ||
27 | + * 'order' => 10000, | ||
28 | + * 'icon' => '', | ||
29 | + * 'remark' => '回收站', | ||
30 | + * 'param' => '' | ||
31 | + * ) | ||
32 | + */ | ||
33 | + function index() | ||
34 | + { | ||
35 | + $recycleBinModel = new RecycleBinModel(); | ||
36 | + $list = $recycleBinModel->order('create_time desc')->paginate(10); | ||
37 | + // 获取分页显示 | ||
38 | + $page = $list->render(); | ||
39 | + $this->assign('page', $page); | ||
40 | + $this->assign('list', $list); | ||
41 | + return $this->fetch(); | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * 回收站还原 | ||
46 | + * @adminMenu( | ||
47 | + * 'name' => '回收站还原', | ||
48 | + * 'parent' => 'index', | ||
49 | + * 'display'=> false, | ||
50 | + * 'hasView'=> false, | ||
51 | + * 'order' => 10000, | ||
52 | + * 'icon' => '', | ||
53 | + * 'remark' => '回收站还原', | ||
54 | + * 'param' => '' | ||
55 | + * ) | ||
56 | + */ | ||
57 | + function restore() | ||
58 | + { | ||
59 | + | ||
60 | + $id = $this->request->param('id'); | ||
61 | + $result = Db::name('recycleBin')->where(['id' => $id])->find(); | ||
62 | + | ||
63 | + $tableName = explode('#', $result['table_name']); | ||
64 | + $tableName = $tableName[0]; | ||
65 | + //还原资源 | ||
66 | + if ($result) { | ||
67 | + $res = Db::name($tableName) | ||
68 | + ->where(['id' => $result['object_id']]) | ||
69 | + ->update(['delete_time' => '0']); | ||
70 | + if ($tableName =='portal_post'){ | ||
71 | + Db::name('portal_category_post')->where('post_id',$result['object_id'])->update(['status'=>1]); | ||
72 | + Db::name('portal_tag_post')->where('post_id',$result['object_id'])->update(['status'=>1]); | ||
73 | + } | ||
74 | + | ||
75 | + if ($res) { | ||
76 | + $re = Db::name('recycleBin')->where('id', $id)->delete(); | ||
77 | + if ($re) { | ||
78 | + $this->success("还原成功!"); | ||
79 | + } | ||
80 | + } | ||
81 | + } | ||
82 | + } | ||
83 | + | ||
84 | + /** | ||
85 | + * 回收站彻底删除 | ||
86 | + * @adminMenu( | ||
87 | + * 'name' => '回收站彻底删除', | ||
88 | + * 'parent' => 'index', | ||
89 | + * 'display'=> false, | ||
90 | + * 'hasView'=> false, | ||
91 | + * 'order' => 10000, | ||
92 | + * 'icon' => '', | ||
93 | + * 'remark' => '回收站彻底删除', | ||
94 | + * 'param' => '' | ||
95 | + * ) | ||
96 | + */ | ||
97 | + function delete() | ||
98 | + { | ||
99 | + $id = $this->request->param('id'); | ||
100 | + $result = Db::name('recycleBin')->where(['id' => $id])->find(); | ||
101 | + //删除资源 | ||
102 | + if ($result) { | ||
103 | + | ||
104 | + //页面没有单独的表. | ||
105 | + if($result['table_name'] === 'portal_post#page'){ | ||
106 | + $re = Db::name('portal_post')->where('id', $result['object_id'])->delete(); | ||
107 | + //消除路由 | ||
108 | + $routeModel = new RouteModel(); | ||
109 | + $routeModel->setRoute('', 'portal/Page/index', ['id' => $result['object_id']], 2, 5000); | ||
110 | + $routeModel->getRoutes(true); | ||
111 | + }else{ | ||
112 | + $re = Db::name($result['table_name'])->where('id', $result['object_id'])->delete(); | ||
113 | + } | ||
114 | + | ||
115 | + if ($re) { | ||
116 | + $res = Db::name('recycleBin')->where('id', $id)->delete(); | ||
117 | + if($result['table_name'] === 'portal_post'){ | ||
118 | + Db::name('portal_category_post')->where('post_id',$result['object_id'])->delete(); | ||
119 | + Db::name('portal_tag_post')->where('post_id',$result['object_id'])->delete(); | ||
120 | + } | ||
121 | + if ($res) { | ||
122 | + $this->success("删除成功!"); | ||
123 | + } | ||
124 | + | ||
125 | + } | ||
126 | + } | ||
127 | + } | ||
128 | +} |
app/admin/controller/RouteController.php
0 → 100644
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: 老猫 <thinkcmf@126.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\controller; | ||
12 | + | ||
13 | +use app\admin\model\RouteModel; | ||
14 | +use cmf\controller\AdminBaseController; | ||
15 | +use think\Db; | ||
16 | + | ||
17 | +class RouteController extends AdminBaseController | ||
18 | +{ | ||
19 | + | ||
20 | + public function _initialize() | ||
21 | + { | ||
22 | + parent::_initialize(); | ||
23 | + } | ||
24 | + | ||
25 | + /** | ||
26 | + * 路由规则列表 | ||
27 | + * @adminMenu( | ||
28 | + * 'name' => 'URL美化', | ||
29 | + * 'parent' => 'admin/Setting/default', | ||
30 | + * 'display'=> true, | ||
31 | + * 'hasView'=> true, | ||
32 | + * 'order' => 10000, | ||
33 | + * 'icon' => '', | ||
34 | + * 'remark' => 'URL规则管理', | ||
35 | + * 'param' => '' | ||
36 | + * ) | ||
37 | + */ | ||
38 | + public function index() | ||
39 | + { | ||
40 | + $routeModel = new RouteModel(); | ||
41 | + $routes = Db::name('route')->order("list_order asc")->select(); | ||
42 | + $routeModel->getRoutes(true); | ||
43 | + $this->assign("routes", $routes); | ||
44 | + return $this->fetch(); | ||
45 | + } | ||
46 | + | ||
47 | + /** | ||
48 | + * 添加路由规则 | ||
49 | + * @adminMenu( | ||
50 | + * 'name' => '添加路由规则', | ||
51 | + * 'parent' => 'index', | ||
52 | + * 'display'=> false, | ||
53 | + * 'hasView'=> true, | ||
54 | + * 'order' => 10000, | ||
55 | + * 'icon' => '', | ||
56 | + * 'remark' => '添加路由规则', | ||
57 | + * 'param' => '' | ||
58 | + * ) | ||
59 | + */ | ||
60 | + public function add() | ||
61 | + { | ||
62 | + return $this->fetch(); | ||
63 | + } | ||
64 | + | ||
65 | + /** | ||
66 | + * 添加路由规则提交 | ||
67 | + * @adminMenu( | ||
68 | + * 'name' => '添加路由规则提交', | ||
69 | + * 'parent' => 'index', | ||
70 | + * 'display'=> false, | ||
71 | + * 'hasView'=> false, | ||
72 | + * 'order' => 10000, | ||
73 | + * 'icon' => '', | ||
74 | + * 'remark' => '添加路由规则提交', | ||
75 | + * 'param' => '' | ||
76 | + * ) | ||
77 | + */ | ||
78 | + public function addPost() | ||
79 | + { | ||
80 | + $data = $this->request->param(); | ||
81 | + $routeModel = new RouteModel(); | ||
82 | + $result = $routeModel->validate(true)->allowField(true)->save($data); | ||
83 | + if ($result === false) { | ||
84 | + $this->error($routeModel->getError()); | ||
85 | + } | ||
86 | + | ||
87 | + $this->success("添加成功!", url("Route/index", ['id' => $routeModel->id])); | ||
88 | + } | ||
89 | + | ||
90 | + /** | ||
91 | + * 路由规则编辑 | ||
92 | + * @adminMenu( | ||
93 | + * 'name' => '路由规则编辑', | ||
94 | + * 'parent' => 'index', | ||
95 | + * 'display'=> false, | ||
96 | + * 'hasView'=> true, | ||
97 | + * 'order' => 10000, | ||
98 | + * 'icon' => '', | ||
99 | + * 'remark' => '路由规则编辑', | ||
100 | + * 'param' => '' | ||
101 | + * ) | ||
102 | + */ | ||
103 | + public function edit() | ||
104 | + { | ||
105 | + $id = $this->request->param("id", 0, 'intval'); | ||
106 | + $route = Db::name('route')->where(['id' => $id])->find(); | ||
107 | + $this->assign($route); | ||
108 | + return $this->fetch(); | ||
109 | + } | ||
110 | + | ||
111 | + /** | ||
112 | + * 路由规则编辑提交 | ||
113 | + * @adminMenu( | ||
114 | + * 'name' => '路由规则编辑提交', | ||
115 | + * 'parent' => 'index', | ||
116 | + * 'display'=> false, | ||
117 | + * 'hasView'=> false, | ||
118 | + * 'order' => 10000, | ||
119 | + * 'icon' => '', | ||
120 | + * 'remark' => '路由规则编辑提交', | ||
121 | + * 'param' => '' | ||
122 | + * ) | ||
123 | + */ | ||
124 | + public function editPost() | ||
125 | + { | ||
126 | + $data = $this->request->param(); | ||
127 | + $routeModel = new RouteModel(); | ||
128 | + $result = $routeModel->validate(true)->allowField(true)->isUpdate(true)->save($data); | ||
129 | + if ($result === false) { | ||
130 | + $this->error($routeModel->getError()); | ||
131 | + } | ||
132 | + | ||
133 | + $this->success("保存成功!", url("Route/index")); | ||
134 | + } | ||
135 | + | ||
136 | + /** | ||
137 | + * 路由规则删除 | ||
138 | + * @adminMenu( | ||
139 | + * 'name' => '路由规则删除', | ||
140 | + * 'parent' => 'index', | ||
141 | + * 'display'=> false, | ||
142 | + * 'hasView'=> false, | ||
143 | + * 'order' => 10000, | ||
144 | + * 'icon' => '', | ||
145 | + * 'remark' => '路由规则删除', | ||
146 | + * 'param' => '' | ||
147 | + * ) | ||
148 | + */ | ||
149 | + public function delete() | ||
150 | + { | ||
151 | + $id = $this->request->param('id', 0, 'intval'); | ||
152 | + RouteModel::destroy($id); | ||
153 | + | ||
154 | + $this->success("删除成功!"); | ||
155 | + } | ||
156 | + | ||
157 | + /** | ||
158 | + * 路由规则禁用 | ||
159 | + * @adminMenu( | ||
160 | + * 'name' => '路由规则禁用', | ||
161 | + * 'parent' => 'index', | ||
162 | + * 'display'=> false, | ||
163 | + * 'hasView'=> false, | ||
164 | + * 'order' => 10000, | ||
165 | + * 'icon' => '', | ||
166 | + * 'remark' => '路由规则禁用', | ||
167 | + * 'param' => '' | ||
168 | + * ) | ||
169 | + */ | ||
170 | + public function ban() | ||
171 | + { | ||
172 | + $id = $this->request->param("id", 0, 'intval'); | ||
173 | + $data = []; | ||
174 | + $data['status'] = 0; | ||
175 | + $data['id'] = $id; | ||
176 | + $routeModel = new RouteModel(); | ||
177 | + | ||
178 | + $routeModel->isUpdate(true)->save($data); | ||
179 | + $this->success("禁用成功!"); | ||
180 | + } | ||
181 | + | ||
182 | + /** | ||
183 | + * 路由规则启用 | ||
184 | + * @adminMenu( | ||
185 | + * 'name' => '路由规则启用', | ||
186 | + * 'parent' => 'index', | ||
187 | + * 'display'=> false, | ||
188 | + * 'hasView'=> false, | ||
189 | + * 'order' => 10000, | ||
190 | + * 'icon' => '', | ||
191 | + * 'remark' => '路由规则启用', | ||
192 | + * 'param' => '' | ||
193 | + * ) | ||
194 | + */ | ||
195 | + public function open() | ||
196 | + { | ||
197 | + $id = $this->request->param("id", 0, 'intval'); | ||
198 | + $data = []; | ||
199 | + $data['status'] = 1; | ||
200 | + $data['id'] = $id; | ||
201 | + $routeModel = new RouteModel(); | ||
202 | + | ||
203 | + $routeModel->isUpdate(true)->save($data); | ||
204 | + $this->success("启用成功!"); | ||
205 | + } | ||
206 | + | ||
207 | + /** | ||
208 | + * 路由规则排序 | ||
209 | + * @adminMenu( | ||
210 | + * 'name' => '路由规则排序', | ||
211 | + * 'parent' => 'index', | ||
212 | + * 'display'=> false, | ||
213 | + * 'hasView'=> false, | ||
214 | + * 'order' => 10000, | ||
215 | + * 'icon' => '', | ||
216 | + * 'remark' => '路由规则排序', | ||
217 | + * 'param' => '' | ||
218 | + * ) | ||
219 | + */ | ||
220 | + public function listOrder() | ||
221 | + { | ||
222 | + $routeModel = new RouteModel(); | ||
223 | + parent::listOrders($routeModel); | ||
224 | + $this->success("排序更新成功!"); | ||
225 | + } | ||
226 | + | ||
227 | + /** | ||
228 | + * 选择 URL | ||
229 | + * @adminMenu( | ||
230 | + * 'name' => '选择URL', | ||
231 | + * 'parent' => 'index', | ||
232 | + * 'display'=> false, | ||
233 | + * 'hasView'=> true, | ||
234 | + * 'order' => 10000, | ||
235 | + * 'icon' => '', | ||
236 | + * 'remark' => '选择URL', | ||
237 | + * 'param' => '' | ||
238 | + * ) | ||
239 | + */ | ||
240 | + public function select() | ||
241 | + { | ||
242 | + $routeModel = new RouteModel(); | ||
243 | + $urls = $routeModel->getAppUrls(); | ||
244 | + | ||
245 | + $this->assign('urls', $urls); | ||
246 | + return $this->fetch(); | ||
247 | + } | ||
248 | + | ||
249 | + function _suggest_url($action, $url) | ||
250 | + { | ||
251 | + $actionArr = explode('/', $action); | ||
252 | + | ||
253 | + $params = array_keys($url['vars']); | ||
254 | + | ||
255 | + $urlDepr1Params = []; | ||
256 | + | ||
257 | + $urlDepr2Params = []; | ||
258 | + | ||
259 | + if (!empty($params)) { | ||
260 | + | ||
261 | + foreach ($params as $param) { | ||
262 | + if(empty($url['vars'][$param]['require'])){ | ||
263 | + array_push($urlDepr1Params, "[:$param]"); | ||
264 | + }else{ | ||
265 | + array_push($urlDepr1Params, ":$param"); | ||
266 | + } | ||
267 | + | ||
268 | + array_push($urlDepr2Params, htmlspecialchars('<') . $param . htmlspecialchars('>')); | ||
269 | + } | ||
270 | + | ||
271 | + } | ||
272 | + | ||
273 | + if ($actionArr[2] == 'index') { | ||
274 | + $actionArr[1] = cmf_parse_name($actionArr[1]); | ||
275 | + return empty($params) ? $actionArr[1].'$' : ($actionArr[1] . '/' . implode('/', $urlDepr1Params) /*. '或' . $actionArr[1] . '-' . implode('-', $urlDepr2Params)*/); | ||
276 | + } else { | ||
277 | + $actionArr[2] = cmf_parse_name($actionArr[2]); | ||
278 | + return empty($params) ? $actionArr[2].'$' : ($actionArr[2] . '/' . implode('/', $urlDepr1Params) /*. '或' . $actionArr[2] . '-' . implode('-', $urlDepr2Params)*/); | ||
279 | + } | ||
280 | + | ||
281 | + } | ||
282 | + | ||
283 | + function _url_vars($url) | ||
284 | + { | ||
285 | + if (!empty($url['vars'])) { | ||
286 | + return implode(',', array_keys($url['vars'])); | ||
287 | + } | ||
288 | + | ||
289 | + return ''; | ||
290 | + } | ||
291 | + | ||
292 | +} |
app/admin/controller/SettingController.php
0 → 100644
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: 小夏 < 449134904@qq.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\controller; | ||
12 | + | ||
13 | +use app\admin\model\RouteModel; | ||
14 | +use cmf\controller\AdminBaseController; | ||
15 | + | ||
16 | +use think\Db; | ||
17 | + | ||
18 | +/** | ||
19 | + * Class SettingController | ||
20 | + * @package app\admin\controller | ||
21 | + * @adminMenuRoot( | ||
22 | + * 'name' =>'设置', | ||
23 | + * 'action' =>'default', | ||
24 | + * 'parent' =>'', | ||
25 | + * 'display'=> true, | ||
26 | + * 'order' => 0, | ||
27 | + * 'icon' =>'cogs', | ||
28 | + * 'remark' =>'系统设置入口' | ||
29 | + * ) | ||
30 | + */ | ||
31 | +class SettingController extends AdminBaseController | ||
32 | +{ | ||
33 | + | ||
34 | + /** | ||
35 | + * 网站信息 | ||
36 | + * @adminMenu( | ||
37 | + * 'name' => '网站信息', | ||
38 | + * 'parent' => 'default', | ||
39 | + * 'display'=> true, | ||
40 | + * 'hasView'=> true, | ||
41 | + * 'order' => 0, | ||
42 | + * 'icon' => '', | ||
43 | + * 'remark' => '网站信息', | ||
44 | + * 'param' => '' | ||
45 | + * ) | ||
46 | + */ | ||
47 | + public function site() | ||
48 | + { | ||
49 | + $noNeedDirs = [".", "..", ".svn", 'fonts']; | ||
50 | + $adminThemesDir = config('cmf_admin_theme_path') . config('cmf_admin_default_theme') . '/public/assets/themes/'; | ||
51 | + $adminStyles = cmf_scan_dir($adminThemesDir . '*', GLOB_ONLYDIR); | ||
52 | + $adminStyles = array_diff($adminStyles, $noNeedDirs); | ||
53 | + $cdnSettings = cmf_get_option('cdn_settings'); | ||
54 | + $cmfSettings = cmf_get_option('cmf_settings'); | ||
55 | + $adminSettings = cmf_get_option('admin_settings'); | ||
56 | + | ||
57 | + $this->assign('site_info', cmf_get_option('site_info')); | ||
58 | + $this->assign("admin_styles", $adminStyles); | ||
59 | + $this->assign("templates", []); | ||
60 | + $this->assign("cdn_settings", $cdnSettings); | ||
61 | + $this->assign("admin_settings", $adminSettings); | ||
62 | + $this->assign("cmf_settings", $cmfSettings); | ||
63 | + | ||
64 | + return $this->fetch(); | ||
65 | + } | ||
66 | + | ||
67 | + /** | ||
68 | + * 网站信息设置提交 | ||
69 | + * @adminMenu( | ||
70 | + * 'name' => '网站信息设置提交', | ||
71 | + * 'parent' => 'site', | ||
72 | + * 'display'=> false, | ||
73 | + * 'hasView'=> false, | ||
74 | + * 'order' => 10000, | ||
75 | + * 'icon' => '', | ||
76 | + * 'remark' => '网站信息设置提交', | ||
77 | + * 'param' => '' | ||
78 | + * ) | ||
79 | + */ | ||
80 | + public function sitePost() | ||
81 | + { | ||
82 | + if ($this->request->isPost()) { | ||
83 | + $result = $this->validate($this->request->param(), 'SettingSite'); | ||
84 | + if ($result !== true) { | ||
85 | + $this->error($result); | ||
86 | + } | ||
87 | + | ||
88 | + $options = $this->request->param('options/a'); | ||
89 | + cmf_set_option('site_info', $options); | ||
90 | + | ||
91 | + $cmfSettings = $this->request->param('cmf_settings/a'); | ||
92 | + | ||
93 | + $bannedUsernames = preg_replace("/[^0-9A-Za-z_\\x{4e00}-\\x{9fa5}-]/u", ",", $cmfSettings['banned_usernames']); | ||
94 | + $cmfSettings['banned_usernames'] = $bannedUsernames; | ||
95 | + cmf_set_option('cmf_settings', $cmfSettings); | ||
96 | + | ||
97 | + $cdnSettings = $this->request->param('cdn_settings/a'); | ||
98 | + cmf_set_option('cdn_settings', $cdnSettings); | ||
99 | + | ||
100 | + $adminSettings = $this->request->param('admin_settings/a'); | ||
101 | + | ||
102 | + $routeModel = new RouteModel(); | ||
103 | + if (!empty($adminSettings['admin_password'])) { | ||
104 | + $routeModel->setRoute($adminSettings['admin_password'] . '$', 'admin/Index/index', [], 2, 5000); | ||
105 | + } else { | ||
106 | + $routeModel->deleteRoute('admin/Index/index', []); | ||
107 | + } | ||
108 | + | ||
109 | + $routeModel->getRoutes(true); | ||
110 | + | ||
111 | + cmf_set_option('admin_settings', $adminSettings); | ||
112 | + | ||
113 | + $this->success("保存成功!", ''); | ||
114 | + | ||
115 | + } | ||
116 | + } | ||
117 | + | ||
118 | + /** | ||
119 | + * 密码修改 | ||
120 | + * @adminMenu( | ||
121 | + * 'name' => '密码修改', | ||
122 | + * 'parent' => 'default', | ||
123 | + * 'display'=> false, | ||
124 | + * 'hasView'=> true, | ||
125 | + * 'order' => 10000, | ||
126 | + * 'icon' => '', | ||
127 | + * 'remark' => '密码修改', | ||
128 | + * 'param' => '' | ||
129 | + * ) | ||
130 | + */ | ||
131 | + public function password() | ||
132 | + { | ||
133 | + return $this->fetch(); | ||
134 | + } | ||
135 | + | ||
136 | + /** | ||
137 | + * 密码修改提交 | ||
138 | + * @adminMenu( | ||
139 | + * 'name' => '密码修改提交', | ||
140 | + * 'parent' => 'password', | ||
141 | + * 'display'=> false, | ||
142 | + * 'hasView'=> false, | ||
143 | + * 'order' => 10000, | ||
144 | + * 'icon' => '', | ||
145 | + * 'remark' => '密码修改提交', | ||
146 | + * 'param' => '' | ||
147 | + * ) | ||
148 | + */ | ||
149 | + public function passwordPost() | ||
150 | + { | ||
151 | + if ($this->request->isPost()) { | ||
152 | + | ||
153 | + $data = $this->request->param(); | ||
154 | + if (empty($data['old_password'])) { | ||
155 | + $this->error("原始密码不能为空!"); | ||
156 | + } | ||
157 | + if (empty($data['password'])) { | ||
158 | + $this->error("新密码不能为空!"); | ||
159 | + } | ||
160 | + | ||
161 | + $userId = cmf_get_current_admin_id(); | ||
162 | + | ||
163 | + $admin = Db::name('user')->where(["id" => $userId])->find(); | ||
164 | + | ||
165 | + $oldPassword = $data['old_password']; | ||
166 | + $password = $data['password']; | ||
167 | + $rePassword = $data['re_password']; | ||
168 | + | ||
169 | + if (cmf_compare_password($oldPassword, $admin['user_pass'])) { | ||
170 | + if ($password == $rePassword) { | ||
171 | + | ||
172 | + if (cmf_compare_password($password, $admin['user_pass'])) { | ||
173 | + $this->error("新密码不能和原始密码相同!"); | ||
174 | + } else { | ||
175 | + Db::name('user')->where('id', $userId)->update(['user_pass' => cmf_password($password)]); | ||
176 | + $this->success("密码修改成功!"); | ||
177 | + } | ||
178 | + } else { | ||
179 | + $this->error("密码输入不一致!"); | ||
180 | + } | ||
181 | + | ||
182 | + } else { | ||
183 | + $this->error("原始密码不正确!"); | ||
184 | + } | ||
185 | + } | ||
186 | + } | ||
187 | + | ||
188 | + /** | ||
189 | + * 上传限制设置界面 | ||
190 | + * @adminMenu( | ||
191 | + * 'name' => '上传设置', | ||
192 | + * 'parent' => 'default', | ||
193 | + * 'display'=> true, | ||
194 | + * 'hasView'=> true, | ||
195 | + * 'order' => 10000, | ||
196 | + * 'icon' => '', | ||
197 | + * 'remark' => '上传设置', | ||
198 | + * 'param' => '' | ||
199 | + * ) | ||
200 | + */ | ||
201 | + public function upload() | ||
202 | + { | ||
203 | + $uploadSetting = cmf_get_upload_setting(); | ||
204 | + $this->assign('upload_setting',$uploadSetting); | ||
205 | + return $this->fetch(); | ||
206 | + } | ||
207 | + | ||
208 | + /** | ||
209 | + * 上传限制设置界面提交 | ||
210 | + * @adminMenu( | ||
211 | + * 'name' => '上传设置提交', | ||
212 | + * 'parent' => 'upload', | ||
213 | + * 'display'=> false, | ||
214 | + * 'hasView'=> false, | ||
215 | + * 'order' => 10000, | ||
216 | + * 'icon' => '', | ||
217 | + * 'remark' => '上传设置提交', | ||
218 | + * 'param' => '' | ||
219 | + * ) | ||
220 | + */ | ||
221 | + public function uploadPost() | ||
222 | + { | ||
223 | + if ($this->request->isPost()) { | ||
224 | + //TODO 非空验证 | ||
225 | + $uploadSetting = $this->request->post(); | ||
226 | + | ||
227 | + cmf_set_option('upload_setting', $uploadSetting); | ||
228 | + $this->success('保存成功!'); | ||
229 | + } | ||
230 | + | ||
231 | + } | ||
232 | + | ||
233 | + /** | ||
234 | + * 清除缓存 | ||
235 | + * @adminMenu( | ||
236 | + * 'name' => '清除缓存', | ||
237 | + * 'parent' => 'default', | ||
238 | + * 'display'=> false, | ||
239 | + * 'hasView'=> true, | ||
240 | + * 'order' => 10000, | ||
241 | + * 'icon' => '', | ||
242 | + * 'remark' => '清除缓存', | ||
243 | + * 'param' => '' | ||
244 | + * ) | ||
245 | + */ | ||
246 | + public function clearCache() | ||
247 | + { | ||
248 | + cmf_clear_cache(); | ||
249 | + return $this->fetch(); | ||
250 | + } | ||
251 | + | ||
252 | + | ||
253 | +} |
app/admin/controller/SlideController.php
0 → 100644
1 | +<?php | ||
2 | +// +---------------------------------------------------------------------- | ||
3 | +// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] | ||
4 | +// +---------------------------------------------------------------------- | ||
5 | +// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. | ||
6 | +// +---------------------------------------------------------------------- | ||
7 | +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) | ||
8 | +// +---------------------------------------------------------------------- | ||
9 | +// | Author: 小夏 < 449134904@qq.com> | ||
10 | +// +---------------------------------------------------------------------- | ||
11 | +namespace app\admin\controller; | ||
12 | + | ||
13 | +use app\admin\model\SlideModel; | ||
14 | +use cmf\controller\AdminBaseController; | ||
15 | +use think\Db; | ||
16 | + | ||
17 | +class SlideController extends AdminBaseController | ||
18 | +{ | ||
19 | + | ||
20 | + /** | ||
21 | + * 幻灯片列表 | ||
22 | + * @adminMenu( | ||
23 | + * 'name' => '幻灯片管理', | ||
24 | + * 'parent' => 'admin/Setting/default', | ||
25 | + * 'display'=> true, | ||
26 | + * 'hasView'=> true, | ||
27 | + * 'order' => 40, | ||
28 | + * 'icon' => '', | ||
29 | + * 'remark' => '幻灯片管理', | ||
30 | + * 'param' => '' | ||
31 | + * ) | ||
32 | + */ | ||
33 | + public function index() | ||
34 | + { | ||
35 | + $slidePostModel = new SlideModel(); | ||
36 | + $slides = $slidePostModel->where(['delete_time' => ['eq', 0]])->select(); | ||
37 | + $this->assign('slides', $slides); | ||
38 | + return $this->fetch(); | ||
39 | + } | ||
40 | + | ||
41 | + /** | ||
42 | + * 添加幻灯片 | ||
43 | + * @adminMenu( | ||
44 | + * 'name' => '添加幻灯片', | ||
45 | + * 'parent' => 'index', | ||
46 | + * 'display'=> false, | ||
47 | + * 'hasView'=> true, | ||
48 | + * 'order' => 10000, | ||
49 | + * 'icon' => '', | ||
50 | + * 'remark' => '添加幻灯片', | ||
51 | + * 'param' => '' | ||
52 | + * ) | ||
53 | + */ | ||
54 | + public function add() | ||
55 | + { | ||
56 | + return $this->fetch(); | ||
57 | + } | ||
58 | + | ||
59 | + /** | ||
60 | + * 添加幻灯片提交 | ||
61 | + * @adminMenu( | ||
62 | + * 'name' => '添加幻灯片提交', | ||
63 | + * 'parent' => 'index', | ||
64 | + * 'display'=> false, | ||
65 | + * 'hasView'=> false, | ||
66 | + * 'order' => 10000, | ||
67 | + * 'icon' => '', | ||
68 | + * 'remark' => '添加幻灯片提交', | ||
69 | + * 'param' => '' | ||
70 | + * ) | ||
71 | + */ | ||
72 | + public function addPost() | ||
73 | + { | ||
74 | + $data = $this->request->param(); | ||
75 | + $slidePostModel = new SlideModel(); | ||
76 | + $result = $slidePostModel->validate(true)->save($data); | ||
77 | + if ($result === false) { | ||
78 | + $this->error($slidePostModel->getError()); | ||
79 | + } | ||
80 | + $this->success("添加成功!", url("slide/index")); | ||
81 | + } | ||
82 | + | ||
83 | + /** | ||
84 | + * 编辑幻灯片 | ||
85 | + * @adminMenu( | ||
86 | + * 'name' => '编辑幻灯片', | ||
87 | + * 'parent' => 'index', | ||
88 | + * 'display'=> false, | ||
89 | + * 'hasView'=> true, | ||
90 | + * 'order' => 10000, | ||
91 | + * 'icon' => '', | ||
92 | + * 'remark' => '编辑幻灯片', | ||
93 | + * 'param' => '' | ||
94 | + * ) | ||
95 | + */ | ||
96 | + public function edit() | ||
97 | + { | ||
98 | + $id = $this->request->param('id'); | ||
99 | + $slidePostModel = new SlideModel(); | ||
100 | + $result = $slidePostModel->where('id', $id)->find(); | ||
101 | + $this->assign('result', $result); | ||
102 | + return $this->fetch(); | ||
103 | + } | ||
104 | + | ||
105 | + /** | ||
106 | + * 编辑幻灯片提交 | ||
107 | + * @adminMenu( | ||
108 | + * 'name' => '编辑幻灯片提交', | ||
109 | + * 'parent' => 'index', | ||
110 | + * 'display'=> false, | ||
111 | + * 'hasView'=> false, | ||
112 | + * 'order' => 10000, | ||
113 | + * 'icon' => '', | ||
114 | + * 'remark' => '编辑幻灯片提交', | ||
115 | + * 'param' => '' | ||
116 | + * ) | ||
117 | + */ | ||
118 | + public function editPost() | ||
119 | + { | ||
120 | + $data = $this->request->param(); | ||
121 | + $slidePostModel = new SlideModel(); | ||
122 | + $result = $slidePostModel->validate(true)->save($data, ['id' => $data['id']]); | ||
123 | + if ($result === false) { | ||
124 | + $this->error($slidePostModel->getError()); | ||
125 | + } | ||
126 | + $this->success("保存成功!", url("slide/index")); | ||
127 | + } | ||
128 | + | ||
129 | + /** | ||
130 | + * 删除幻灯片 | ||
131 | + * @adminMenu( | ||
132 | + * 'name' => '删除幻灯片', | ||
133 | + * 'parent' => 'index', | ||
134 | + * 'display'=> false, | ||
135 | + * 'hasView'=> false, | ||
136 | + * 'order' => 10000, | ||
137 | + * 'icon' => '', | ||
138 | + * 'remark' => '删除幻灯片', | ||
139 | + * 'param' => '' | ||
140 | + * ) | ||
141 | + */ | ||
142 | + public function delete() | ||
143 | + { | ||
144 | + $id = $this->request->param('id', 0, 'intval'); | ||
145 | + $slidePostModel = new SlideModel(); | ||
146 | + $result = $slidePostModel->where(['id' => $id])->find(); | ||
147 | + if (empty($result)){ | ||
148 | + $this->error('幻灯片不存在!'); | ||
149 | + } | ||
150 | + | ||
151 | + //如果存在页面。则不能删除。 | ||
152 | + $slidePostCount = Db::name('slide_item')->where('slide_id', $id)->count(); | ||
153 | + if ($slidePostCount > 0) { | ||
154 | + $this->error('此幻灯片有页面无法删除!'); | ||
155 | + } | ||
156 | + | ||
157 | + $data = [ | ||
158 | + 'object_id' => $id, | ||
159 | + 'create_time' => time(), | ||
160 | + 'table_name' => 'slide', | ||
161 | + 'name' => $result['name'] | ||
162 | + ]; | ||
163 | + | ||
164 | + $resultSlide = $slidePostModel->save(['delete_time' => time()], ['id' => $id]); | ||
165 | + if ($resultSlide) { | ||
166 | + Db::name('recycleBin')->insert($data); | ||
167 | + } | ||
168 | + $this->success("删除成功!", url("slide/index")); | ||
169 | + } | ||
170 | +} |
-
请 注册 或 登录 后发表评论