AdmintermController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2014 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: Tuolaji <479923197@qq.com>
  8. // +----------------------------------------------------------------------
  9. namespace app\admin\controller;
  10. use cmf\controller\AdminBaseController;
  11. use think\Db;
  12. use think\db\Query;
  13. class AdminTermController extends AdminBaseController{
  14. // 后台文章分类列表
  15. public function index(){
  16. $list=Db::name('terms')
  17. ->where('parentid=0')
  18. ->order("listorder ASC,id DESC")
  19. ->paginate(10);
  20. $page = $list->render();
  21. $this->assign('list', $list);
  22. $this->assign('page', $page);
  23. // 渲染模板输出
  24. return $this->fetch();
  25. }
  26. //文章分类添加
  27. public function add(){
  28. $parentid = input('id');
  29. if(!$parentid){
  30. $parentid=0;
  31. }
  32. $this->assign('parentid', $parentid);
  33. return $this->fetch();
  34. }
  35. public function add_post(){
  36. $data = input('post.');
  37. if($data['name']==''){
  38. $this->error('分类名称不能为空!');
  39. }
  40. $add=Db::name('terms')->insertGetId($data);
  41. if($add){
  42. $this->success('添加成功!');
  43. }else{
  44. $this->error('添加失败!');
  45. }
  46. }
  47. //文章分类编辑
  48. public function edit(){
  49. $id = input('param.id');
  50. if($id){
  51. $info=Db::name('terms')->where('id',$id)->find();
  52. $this->assign('info',$info);
  53. }else{
  54. $this->error('数据传入失败!');
  55. }
  56. return $this->fetch();
  57. }
  58. public function edit_post(){
  59. $data = input('post.');
  60. if($data['name']==''){
  61. $this->error('分类名称不能为空!');
  62. }
  63. $save=Db::name('terms')->where('id',$data['id'])->update($data);
  64. if($save!==false){
  65. $this->success('保存成功!');
  66. }else{
  67. $this->error('保存失败!');
  68. }
  69. }
  70. // 文章分类删除
  71. public function del(){
  72. $id = input('param.id');
  73. if($id){
  74. $result=Db::name('terms')->delete($id);
  75. if($result){
  76. //删除分类下的文章
  77. //Db::name('posts')->where('id',$id)->delete();
  78. $this->success('删除成功');
  79. }else{
  80. $this->error('删除失败');
  81. }
  82. }else{
  83. $this->error('数据传入失败!');
  84. }
  85. }
  86. // 文章分类排序
  87. public function listorder(){
  88. $listorders = input('listorders');
  89. foreach ($listorders as $key => $r) {
  90. $data=array();
  91. $data['listorder'] = $r;
  92. Db::name('terms')->where(['id'=>$key])->update($data);
  93. }
  94. $status = true;
  95. if ($status) {
  96. $this->success("排序更新成功!");
  97. } else {
  98. $this->error("排序更新失败!");
  99. }
  100. }
  101. }