Articlecategory.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\shop\controller;
  11. use app\model\article\ArticleCategory as CategoryModel;
  12. /**
  13. * 文章分类
  14. */
  15. class Articlecategory extends BaseShop
  16. {
  17. /*
  18. * 文章分类列表
  19. */
  20. public function lists()
  21. {
  22. $model = new CategoryModel();
  23. $condition[] = ['site_id', '=', $this->site_id];
  24. if (request()->isAjax()) {
  25. $page = (int)input('page', 1);
  26. $page_size = input('page_size', PAGE_LIST_ROWS);
  27. //排序
  28. $order = input('order', 'sort');
  29. $sort = input('sort', 'desc');
  30. if($order == 'sort'){
  31. $order_by = $order . ' ' . $sort;
  32. }else{
  33. $order_by = $order . ' ' . $sort.',sort desc';
  34. }
  35. $list = $model->getArticleCategoryPageList($condition, $page, $page_size, $order_by);
  36. return $list;
  37. } else {
  38. $this->forthMenu();
  39. return $this->fetch('articlecategory/lists');
  40. }
  41. }
  42. /**
  43. * 添加分组
  44. */
  45. public function add()
  46. {
  47. if (request()->isAjax()) {
  48. $data = [
  49. 'site_id' => $this->site_id,
  50. 'category_name' => input('category_name', ''),
  51. 'sort' => input('sort'),
  52. ];
  53. $category_model = new CategoryModel();
  54. return $category_model->addArticleCategory($data);
  55. }
  56. }
  57. /**
  58. * 编辑分组
  59. */
  60. public function edit()
  61. {
  62. if (request()->isAjax()) {
  63. $data = [
  64. 'category_id' => input('category_id'),
  65. 'site_id' => $this->site_id,
  66. 'category_name' => input('category_name', ''),
  67. 'sort' => input('sort'),
  68. ];
  69. $category_model = new CategoryModel();
  70. return $category_model->editArticleCategory([['site_id', '=', $this->site_id], ['category_id', '=', $data['category_id']]], $data);
  71. }
  72. }
  73. /**
  74. * 编辑分组排序
  75. * @return array
  76. */
  77. public function modifySort()
  78. {
  79. if (request()->isAjax()) {
  80. $data = [
  81. 'category_id' => input('category_id'),
  82. 'site_id' => $this->site_id,
  83. 'sort' => input('sort'),
  84. ];
  85. $category_model = new CategoryModel();
  86. return $category_model->editArticleCategory([['site_id', '=', $this->site_id], ['category_id', '=', $data['category_id']]], $data);
  87. }
  88. }
  89. /*
  90. * 删除分组
  91. */
  92. public function delete()
  93. {
  94. $category_id = input('category_id', '');
  95. $site_id = $this->site_id;
  96. $category_model = new CategoryModel();
  97. return $category_model->deleteArticleCategory($category_id, $site_id);
  98. }
  99. }