Articleclass.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Articleclass extends AdminControl {
  17. public function initialize() {
  18. parent::initialize();
  19. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/articleclass.lang.php');
  20. }
  21. /**
  22. * 文章管理
  23. */
  24. public function index() {
  25. $articleclass_model = model('articleclass');
  26. /**
  27. * 父ID
  28. */
  29. $parent_id = input('param.ac_parent_id') ? intval(input('param.ac_parent_id')) : 0;
  30. /**
  31. * 列表
  32. */
  33. $tmp_list = $articleclass_model->getTreeClassList(2);
  34. $class_list = array();
  35. if (is_array($tmp_list)) {
  36. foreach ($tmp_list as $k => $v) {
  37. if ($v['ac_parent_id'] == $parent_id) {
  38. /**
  39. * 判断是否有子类
  40. */
  41. $v['have_child'] = 0;
  42. if (isset($tmp_list[$k + 1]['deep']) && $tmp_list[$k + 1]['deep'] > $v['deep']) {
  43. $v['have_child'] = 1;
  44. }
  45. $class_list[] = $v;
  46. }
  47. }
  48. }
  49. if (input('param.ajax') == '1') {
  50. /**
  51. * 转码
  52. */
  53. $output = json_encode($class_list);
  54. print_r($output);
  55. exit;
  56. } else {
  57. View::assign('class_list', $class_list);
  58. $this->setAdminCurItem('index');
  59. return View::fetch('article_class_index');
  60. }
  61. }
  62. /**
  63. * 文章分类 新增
  64. */
  65. public function article_class_add() {
  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. $articleclass_model = model('articleclass');
  111. $ac_id = intval(input('param.ac_id'));
  112. if (request()->isPost()) {
  113. /**
  114. * 验证
  115. */
  116. $data = [
  117. 'ac_name' => input('param.ac_name'),
  118. 'ac_sort' => input('param.ac_sort')
  119. ];
  120. $article_validate = ds_validate('article');
  121. if (!$article_validate->scene('article_class_edit')->check($data)) {
  122. $this->error($article_validate->getError());
  123. } else {
  124. $update_array = array();
  125. $update_array['ac_name'] = trim(input('post.ac_name'));
  126. $update_array['ac_sort'] = trim(input('post.ac_sort'));
  127. $result = $articleclass_model->editArticleclass($update_array,$ac_id);
  128. if ($result>=0) {
  129. $this->log(lang('ds_edit') . lang('article_class_index_class') . '[' . input('post.ac_name') . ']', 1);
  130. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  131. } else {
  132. $this->error(lang('ds_common_op_fail'));
  133. }
  134. }
  135. } else {
  136. $class_array = $articleclass_model->getOneArticleclass($ac_id);
  137. if (empty($class_array)) {
  138. $this->error(lang('param_error'));
  139. }
  140. View::assign('class_array', $class_array);
  141. return View::fetch('article_class_edit');
  142. }
  143. }
  144. /**
  145. * 删除分类
  146. */
  147. public function article_class_del() {
  148. $articleclass_model = model('articleclass');
  149. $ac_id = input('param.ac_id');
  150. $ac_id_array = ds_delete_param($ac_id);
  151. if ($ac_id_array === FALSE) {
  152. ds_json_encode('10001', lang('param_error'));
  153. }
  154. $del_array = $articleclass_model->getChildClass($ac_id_array);
  155. if (is_array($del_array)) {
  156. foreach ($del_array as $k => $v) {
  157. $articleclass_model->delArticleclass($v['ac_id']);
  158. }
  159. }
  160. $this->log(lang('ds_add') . lang('article_class_index_class') . '[ID:' . $ac_id . ']', 1);
  161. ds_json_encode(10000, lang('ds_common_del_succ'));
  162. }
  163. /**
  164. * ajax操作
  165. */
  166. public function ajax() {
  167. switch (input('param.branch')) {
  168. /**
  169. * 分类:验证是否有重复的名称
  170. */
  171. case 'article_class_name':
  172. $articleclass_model = model('articleclass');
  173. $class_array = $articleclass_model->getOneArticleclass(intval(input('param.id')));
  174. $condition[]=array('ac_name','=',trim(input('param.value')));
  175. $condition[]=array('ac_parent_id','=',$class_array['ac_parent_id']);
  176. $condition[]=array('ac_id','<>',intval(input('param.id')));
  177. $class_list = $articleclass_model->getArticleclassList($condition);
  178. if (empty($class_list)) {
  179. $update_array = array();
  180. $update_array['ac_name'] = trim(input('param.value'));
  181. $articleclass_model->editArticleclass($update_array,input('param.id'));
  182. echo 'true';
  183. exit;
  184. } else {
  185. echo 'false';
  186. exit;
  187. }
  188. break;
  189. /**
  190. * 分类: 排序 显示 设置
  191. */
  192. case 'article_class_sort':
  193. $articleclass_model = model('articleclass');
  194. $update_array = array();
  195. $update_array[input('param.column')] = trim(input('param.value'));
  196. $result = $articleclass_model->editArticleclass($update_array,intval(input('param.id')));
  197. echo 'true';
  198. exit;
  199. break;
  200. /**
  201. * 分类:添加、修改操作中 检测类别名称是否有重复
  202. */
  203. case 'check_class_name':
  204. $articleclass_model = model('articleclass');
  205. $condition[]=array('ac_name','=',trim(input('param.ac_name')));
  206. // $condition[] = array('ac_parent_id','=',intval(input('param.ac_parent_id')));
  207. $condition[]=array('ac_id','<>',intval(input('param.ac_id')));
  208. $class_list = $articleclass_model->getArticleclassList($condition);
  209. if (empty($class_list)) {
  210. echo 'true';
  211. exit;
  212. } else {
  213. echo 'false';
  214. exit;
  215. }
  216. break;
  217. }
  218. }
  219. protected function getAdminItemList() {
  220. $menu_array = array(
  221. array(
  222. 'name' => 'index',
  223. 'text' =>lang('ds_manage'),
  224. 'url' => (string)url('Articleclass/index')
  225. ),
  226. array(
  227. 'name' => 'add',
  228. 'text' => lang('ds_new'),
  229. 'url' =>"javascript:dsLayerOpen('".(string)url('Articleclass/article_class_add')."','".lang('article_class_add')."')",
  230. )
  231. );
  232. return $menu_array;
  233. }
  234. }