Articleclass.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class Articleclass extends AdminControl
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/articleclass.lang.php');
  18. }
  19. /**
  20. * 文章管理
  21. */
  22. public function index()
  23. {
  24. $articleclass_model = model('articleclass');
  25. /**
  26. * 父ID
  27. */
  28. $parent_id = input('param.ac_parent_id') ? intval(input('param.ac_parent_id')) : 0;
  29. /**
  30. * 列表
  31. */
  32. $tmp_list = $articleclass_model->getTreeClassList(2);
  33. $class_list = array();
  34. if (is_array($tmp_list)) {
  35. foreach ($tmp_list as $k => $v) {
  36. if ($v['ac_parent_id'] == $parent_id) {
  37. /**
  38. * 判断是否有子类
  39. */
  40. $v['have_child'] = 0;
  41. if (isset($tmp_list[$k + 1]['deep']) && $tmp_list[$k + 1]['deep'] > $v['deep']) {
  42. $v['have_child'] = 1;
  43. }
  44. $class_list[] = $v;
  45. }
  46. }
  47. }
  48. if (input('param.ajax') == '1') {
  49. /**
  50. * 转码
  51. */
  52. $output = json_encode($class_list);
  53. print_r($output);
  54. exit;
  55. } else {
  56. View::assign('class_list', $class_list);
  57. $this->setAdminCurItem('index');
  58. return View::fetch('article_class_index');
  59. }
  60. }
  61. /**
  62. * 文章分类 新增
  63. */
  64. public function article_class_add()
  65. {
  66. $articleclass_model = model('articleclass');
  67. if (request()->isPost()) {
  68. /**
  69. * 验证
  70. */
  71. $data = [
  72. 'ac_name' => input('param.ac_name'),
  73. 'ac_sort' => input('param.ac_sort')
  74. ];
  75. $article_validate = ds_validate('article');
  76. if (!$article_validate->scene('article_class_add')->check($data)) {
  77. $this->error($article_validate->getError());
  78. } else {
  79. $insert_array = array();
  80. $insert_array['ac_name'] = trim(input('param.ac_name'));
  81. $insert_array['ac_parent_id'] = intval(input('param.ac_parent_id'));
  82. $insert_array['ac_sort'] = trim(input('param.ac_sort'));
  83. $result = $articleclass_model->addArticleclass($insert_array);
  84. if ($result) {
  85. $this->log(lang('ds_add') . lang('article_class_index_class') . '[' . input('ac_name') . ']', 1);
  86. dsLayerOpenSuccess(lang('article_class_add_succ'));
  87. } else {
  88. $this->error(lang('article_class_add_fail'));
  89. }
  90. }
  91. } else {
  92. /**
  93. * 父类列表,只取到第三级
  94. */
  95. $parent_list = $articleclass_model->getTreeClassList(1);
  96. if (is_array($parent_list)) {
  97. foreach ($parent_list as $k => $v) {
  98. $parent_list[$k]['ac_name'] = str_repeat("&nbsp;", $v['deep'] * 2) . $v['ac_name'];
  99. }
  100. }
  101. View::assign('ac_parent_id', intval(input('param.ac_parent_id')));
  102. View::assign('parent_list', $parent_list);
  103. return View::fetch('article_class_edit');
  104. }
  105. }
  106. /**
  107. * 文章分类编辑
  108. */
  109. public function article_class_edit()
  110. {
  111. $articleclass_model = model('articleclass');
  112. $ac_id = intval(input('param.ac_id'));
  113. if (request()->isPost()) {
  114. /**
  115. * 验证
  116. */
  117. $data = [
  118. 'ac_name' => input('param.ac_name'),
  119. 'ac_sort' => input('param.ac_sort')
  120. ];
  121. $article_validate = ds_validate('article');
  122. if (!$article_validate->scene('article_class_edit')->check($data)) {
  123. $this->error($article_validate->getError());
  124. } else {
  125. $update_array = array();
  126. $update_array['ac_name'] = trim(input('post.ac_name'));
  127. $update_array['ac_sort'] = trim(input('post.ac_sort'));
  128. $result = $articleclass_model->editArticleclass($update_array, $ac_id);
  129. if ($result >= 0) {
  130. $this->log(lang('ds_edit') . lang('article_class_index_class') . '[' . input('post.ac_name') . ']', 1);
  131. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  132. } else {
  133. $this->error(lang('ds_common_op_fail'));
  134. }
  135. }
  136. } else {
  137. $class_array = $articleclass_model->getOneArticleclass($ac_id);
  138. if (empty($class_array)) {
  139. $this->error(lang('param_error'));
  140. }
  141. View::assign('class_array', $class_array);
  142. return View::fetch('article_class_edit');
  143. }
  144. }
  145. /**
  146. * 删除分类
  147. */
  148. public function article_class_del()
  149. {
  150. $articleclass_model = model('articleclass');
  151. $ac_id = input('param.ac_id');
  152. $ac_id_array = ds_delete_param($ac_id);
  153. if ($ac_id_array === FALSE) {
  154. ds_json_encode('10001', lang('param_error'));
  155. }
  156. $del_array = $articleclass_model->getChildClass($ac_id_array);
  157. if (is_array($del_array)) {
  158. foreach ($del_array as $k => $v) {
  159. $articleclass_model->delArticleclass($v['ac_id']);
  160. }
  161. }
  162. $this->log(lang('ds_add') . lang('article_class_index_class') . '[ID:' . $ac_id . ']', 1);
  163. ds_json_encode(10000, lang('ds_common_del_succ'));
  164. }
  165. /**
  166. * ajax操作
  167. */
  168. public function ajax()
  169. {
  170. switch (input('param.branch')) {
  171. /**
  172. * 分类:验证是否有重复的名称
  173. */
  174. case 'article_class_name':
  175. $articleclass_model = model('articleclass');
  176. $class_array = $articleclass_model->getOneArticleclass(intval(input('param.id')));
  177. $condition[] = array('ac_name', '=', trim(input('param.value')));
  178. $condition[] = array('ac_parent_id', '=', $class_array['ac_parent_id']);
  179. $condition[] = array('ac_id', '<>', intval(input('param.id')));
  180. $class_list = $articleclass_model->getArticleclassList($condition);
  181. if (empty($class_list)) {
  182. $update_array = array();
  183. $update_array['ac_name'] = trim(input('param.value'));
  184. $articleclass_model->editArticleclass($update_array, input('param.id'));
  185. echo 'true';
  186. exit;
  187. } else {
  188. echo 'false';
  189. exit;
  190. }
  191. break;
  192. /**
  193. * 分类: 排序 显示 设置
  194. */
  195. case 'article_class_sort':
  196. $articleclass_model = model('articleclass');
  197. $update_array = array();
  198. $update_array[input('param.column')] = trim(input('param.value'));
  199. $result = $articleclass_model->editArticleclass($update_array, intval(input('param.id')));
  200. echo 'true';
  201. exit;
  202. break;
  203. /**
  204. * 分类:添加、修改操作中 检测类别名称是否有重复
  205. */
  206. case 'check_class_name':
  207. $articleclass_model = model('articleclass');
  208. $condition[] = array('ac_name', '=', trim(input('param.ac_name')));
  209. // $condition[] = array('ac_parent_id','=',intval(input('param.ac_parent_id')));
  210. $condition[] = array('ac_id', '<>', intval(input('param.ac_id')));
  211. $class_list = $articleclass_model->getArticleclassList($condition);
  212. if (empty($class_list)) {
  213. echo 'true';
  214. exit;
  215. } else {
  216. echo 'false';
  217. exit;
  218. }
  219. break;
  220. }
  221. }
  222. protected function getAdminItemList()
  223. {
  224. $menu_array = array(
  225. array(
  226. 'name' => 'index',
  227. 'text' => lang('ds_manage'),
  228. 'url' => (string)url('Articleclass/index')
  229. ),
  230. array(
  231. 'name' => 'add',
  232. 'text' => lang('ds_new'),
  233. 'url' => "javascript:dsLayerOpen('" . (string)url('Articleclass/article_class_add') . "','" . lang('article_class_add') . "')",
  234. )
  235. );
  236. return $menu_array;
  237. }
  238. }