AssetCate.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class AssetCate extends Auth
  5. {
  6. public function index(){
  7. $tree = model('AssetCate')->showAllTree();
  8. $this->assign('tree',$tree);
  9. return $this->fetch();
  10. }
  11. /**
  12. * 新增
  13. */
  14. public function add($pid=0){
  15. if(request()->isPost()){
  16. $res = model('AssetCate')->addSave();
  17. if($res){
  18. $this->success('操作成功',url('index'));
  19. }else{
  20. $this->error(model('AssetCate')->getError());
  21. }
  22. }else{
  23. $this->assign('pid',$pid);
  24. return $this->fetch();
  25. }
  26. }
  27. /**
  28. * 编辑
  29. */
  30. public function edit($id=0){
  31. if(request()->isPost()){
  32. $res = model('AssetCate')->editSave();
  33. if($res){
  34. $this->success('操作成功',url('index'));
  35. }else{
  36. $this->error(model('AssetCate')->getError());
  37. }
  38. }else{
  39. $info = db('asset_cate')->where('id',$id)->find();
  40. $this->assign('info',$info);
  41. return $this->fetch();
  42. }
  43. }
  44. /**
  45. * 删除记录
  46. * @param int $id
  47. */
  48. public function del($id=0){
  49. if(!$id){
  50. $this->error('参数错误');
  51. }
  52. // 检查是否有子级
  53. $ret = Db::name('asset_cate')->where('parent_id',$id)->find();
  54. if($ret){
  55. $this->error('有子级不能删除');
  56. }
  57. $res = Db::name('asset_cate')->where('id',$id)->delete();
  58. if($res){
  59. $this->success('删除成功');
  60. }else{
  61. $this->error('删除失败');
  62. }
  63. }
  64. }