控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Cms.php 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Yzncms [ 御宅男工作室 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018 http://yzncms.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 御宅男 <530765310@qq.com>
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 内容管理插件
  13. // +----------------------------------------------------------------------
  14. namespace addons\cms;
  15. use addons\cms\library\FulltextSearch;
  16. use app\common\library\Menu;
  17. use think\Addons;
  18. use think\Db;
  19. use think\facade\Config;
  20. use think\facade\Route;
  21. class Cms extends Addons
  22. {
  23. protected $ext_table = '_data';
  24. //后台菜单
  25. protected $menu = [
  26. [
  27. "name" => "cms",
  28. "title" => "cms内容管理",
  29. "icon" => "iconfont icon-draft-line",
  30. "sublist" => [
  31. [
  32. "name" => "addons/config/name/cms",
  33. "title" => "站点配置",
  34. "icon" => "iconfont icon-setup",
  35. 'ismenu' => 1,
  36. "listorder" => 10,
  37. ],
  38. [
  39. "name" => "cms.cms",
  40. "title" => "管理内容",
  41. "icon" => "iconfont icon-draft-line",
  42. "listorder" => 9,
  43. "sublist" => [
  44. ["name" => "cms.cms/index", "title" => "查看"],
  45. ["name" => "cms.cms/add", "title" => "新增"],
  46. ["name" => "cms.cms/edit", "title" => "编辑"],
  47. ["name" => "cms.cms/del", "title" => "删除"],
  48. ["name" => "cms.cms/listorder", "title" => "排序"],
  49. ["name" => "cms.cms/remove", "title" => "批量移动"],
  50. ["name" => "cms.cms/setstate", "title" => "状态"],
  51. ["name" => "cms.cms/recycle", "title" => "回收站"],
  52. ["name" => "cms.cms/destroy", "title" => "清空回收站"],
  53. ["name" => "cms.cms/restore", "title" => "还原回收站"],
  54. ],
  55. ],
  56. [
  57. "name" => "cms.publish",
  58. "title" => "稿件管理",
  59. "icon" => "iconfont icon-draft-line",
  60. "listorder" => 8,
  61. "sublist" => [
  62. ["name" => "cms.publish/index", "title" => "查看"],
  63. ["name" => "cms.publish/del", "title" => "删除"],
  64. ["name" => "cms.publish/pass", "title" => "通过"],
  65. ["name" => "cms.publish/reject", "title" => "退稿"],
  66. ],
  67. ],
  68. [
  69. "name" => "cms.order",
  70. "title" => "订单管理",
  71. "icon" => "iconfont icon-file-list-3-line",
  72. "listorder" => 7,
  73. "sublist" => [
  74. ["name" => "cms.order/index", "title" => "查看"],
  75. ["name" => "cms.order/del", "title" => "删除"],
  76. ],
  77. ],
  78. [
  79. "name" => "cms.tags",
  80. "title" => "Tags管理",
  81. "icon" => "iconfont icon-label",
  82. "listorder" => 6,
  83. "sublist" => [
  84. ["name" => "cms.tags/index", "title" => "查看"],
  85. ["name" => "cms.tags/add", "title" => "新增"],
  86. ["name" => "cms.tags/edit", "title" => "编辑"],
  87. ["name" => "cms.tags/del", "title" => "删除"],
  88. ["name" => "cms.tags/create", "title" => "数据重建"],
  89. ["name" => "cms.tags/multi", "title" => "批量更新"],
  90. ],
  91. ],
  92. [
  93. "name" => "cms.category",
  94. "title" => "栏目列表",
  95. "icon" => "iconfont icon-other",
  96. "listorder" => 5,
  97. "sublist" => [
  98. ["name" => "cms.category/index", "title" => "查看"],
  99. ["name" => "cms.category/add", "title" => "新增"],
  100. ["name" => "cms.category/cat_priv", "title" => "栏目授权"],
  101. ["name" => "cms.category/edit", "title" => "编辑"],
  102. ["name" => "cms.category/del", "title" => "删除"],
  103. ["name" => "cms.category/multi", "title" => "批量更新"],
  104. ],
  105. ],
  106. [
  107. "name" => "cms.models",
  108. "title" => "模型管理",
  109. "icon" => "iconfont icon-apartment",
  110. "listorder" => 4,
  111. "sublist" => [
  112. ["name" => "cms.models/index", "title" => "查看"],
  113. ["name" => "cms.models/add", "title" => "新增"],
  114. ["name" => "cms.models/edit", "title" => "编辑"],
  115. ["name" => "cms.models/del", "title" => "删除"],
  116. ["name" => "cms.models/multi", "title" => "批量更新"],
  117. ],
  118. ],
  119. [
  120. "name" => "cms.field",
  121. "title" => "字段管理",
  122. "ismenu" => 0,
  123. "sublist" => [
  124. ["name" => "cms.field/index", "title" => "查看"],
  125. ["name" => "cms.field/add", "title" => "新增"],
  126. ["name" => "cms.field/edit", "title" => "编辑"],
  127. ["name" => "cms.field/del", "title" => "删除"],
  128. ["name" => "cms.field/listorder", "title" => "排序"],
  129. ["name" => "cms.field/setstate", "title" => "状态"],
  130. ["name" => "cms.field/setsearch", "title" => "状态-搜索"],
  131. ["name" => "cms.field/setvisible", "title" => "状态-隐藏"],
  132. ["name" => "cms.field/setrequire", "title" => "状态-必须"],
  133. ],
  134. ],
  135. ],
  136. ],
  137. ];
  138. public $cache_list = [
  139. 'Category' => [
  140. 'name' => '栏目索引',
  141. 'model' => 'Category',
  142. 'action' => 'category_cache',
  143. ],
  144. ];
  145. //安装
  146. public function install()
  147. {
  148. $info = get_addon_info('member');
  149. if (!$info || $info['status'] != 1) {
  150. throw new \think\Exception("请在后台插件管理中安装《会员插件》并启用后再尝试");
  151. }
  152. Menu::create($this->menu);
  153. return true;
  154. }
  155. //卸载
  156. public function uninstall()
  157. {
  158. $droptables = request()->param("droptables");
  159. $auth = \app\admin\service\User::instance();
  160. //只有开启调试且为超级管理员才允许删除相关数据库
  161. if ($droptables && Config::get("app_debug") && $auth->isAdministrator()) {
  162. // 删除模型中建的表
  163. $table_list = Db::name('model')->where('module', 'cms')->field('tablename,type,id')->select();
  164. if ($table_list) {
  165. foreach ($table_list as $val) {
  166. $tablename = Config::get('database.prefix') . $val['tablename'];
  167. Db::execute("DROP TABLE IF EXISTS `{$tablename}`;");
  168. if ($val['type'] == 2) {
  169. Db::execute("DROP TABLE IF EXISTS `{$tablename}{$this->ext_table}`;");
  170. }
  171. Db::name('model_field')->where('modelid', $val['id'])->delete();
  172. }
  173. }
  174. //删除模型中的表
  175. Db::name('model')->where(['module' => 'cms'])->delete();
  176. }
  177. Menu::delete("cms");
  178. return true;
  179. }
  180. /**
  181. * 插件启用方法
  182. * @return bool
  183. */
  184. public function enable()
  185. {
  186. Menu::enable("cms");
  187. return true;
  188. }
  189. /**
  190. * 插件禁用方法
  191. * @return bool
  192. */
  193. public function disable()
  194. {
  195. Menu::disable("cms");
  196. return true;
  197. }
  198. //或者run方法
  199. public function userSidenavAfter($content)
  200. {
  201. return $this->fetch('userSidenavAfter');
  202. }
  203. public function xunsearchIndexReset($project)
  204. {
  205. if ($project['name'] == 'cms') {
  206. return FulltextSearch::reset();
  207. }
  208. }
  209. /**
  210. * 插件升级方法
  211. */
  212. public function upgrade()
  213. {
  214. Menu::upgrade('cms', $this->menu);
  215. return true;
  216. }
  217. public function appInit()
  218. {
  219. $config = get_addon_config('cms');
  220. //TODO 暂时这么排除后台使用此路由
  221. //if (strpos(request()->url(), '/admin') === false) {
  222. Route::rule('', 'cms/index/index');
  223. Route::rule('index', 'cms/index/index');
  224. Route::rule('lists/:catid', 'cms/index/lists')->pattern(['catid' => '\d+']);
  225. Route::rule('shows/:catid/:id', 'cms/index/shows')->pattern(['catid' => '\d+', 'id' => '\d+']);
  226. Route::rule('tag/[:tag]', 'cms/index/tags');
  227. Route::rule('search', 'cms/search/index');
  228. if ($config['site_url_mode'] == 2) {
  229. Route::rule('d/:catdir/:id', 'cms/index/shows')->pattern(['catdir' => '[A-Za-z0-9\-\_]+', 'id' => '\d+']);
  230. Route::rule('c/:catdir/[:condition]', 'cms/index/lists')->pattern(['catdir' => '[A-Za-z0-9\-\_]+', 'condition' => '[0-9_&=a-zA-Z]+']);
  231. }
  232. //}
  233. //此函数需要全局调用
  234. if (is_file(ADDON_PATH . 'cms' . DS . 'function.php')) {
  235. include_once ADDON_PATH . 'cms' . DS . 'function.php';
  236. }
  237. }
  238. public function contentDeleteEnd($params)
  239. {
  240. //参数是审核文章的数据
  241. if (!empty($params) && isset($params['sysadd']) && $params['sysadd'] == 0) {
  242. //删除对应的会员投稿记录信息
  243. db("cms_content")->where(["content_id" => $params['id'], "catid" => $params['catid']])->delete();
  244. }
  245. }
  246. public function contentEditEnd($params)
  247. {
  248. //参数是审核文章的数据
  249. if (!empty($params)) {
  250. //标识审核状态
  251. db("cms_content")->where(["content_id" => $params['id'], "catid" => $params['catid']])->setField('status', $params['status']);
  252. }
  253. }
  254. }