0
0

HouseFee.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. class HouseFee extends Auth
  6. {
  7. public function __construct(App $app = null) {
  8. parent::__construct($app);
  9. $this->model= new \app\common\model\HouseFee();
  10. $this->table=$this->model->table;
  11. }
  12. /**
  13. * 科室管理页
  14. */
  15. public function index(){
  16. $list = $this->model->getTree(cur_org_id());
  17. $this->assign('tree',$list);
  18. return $this->fetch();
  19. }
  20. /**
  21. * 新增/编辑
  22. */
  23. public function add($id=0,$pid=0){
  24. if(request()->isPost()){
  25. $res = $this->model->updates();
  26. if($res){
  27. $this->success('操作成功',url('index'));
  28. }else{
  29. $this->error($this->model->getError());
  30. }
  31. }else{
  32. if($id){
  33. $info =db($this->table)->where('id',$id)->find();
  34. $this->assign('info',$info);
  35. }
  36. $this->assign('type',[
  37. [
  38. 'id'=>1,
  39. 'title'=>'房屋'
  40. ],
  41. [
  42. 'id'=>2,
  43. 'title'=>'储藏室'
  44. ],[
  45. 'id'=>3,
  46. 'title'=>'停车位'
  47. ]
  48. ]);
  49. $pInfo = [];
  50. if($pid >0){
  51. $pInfo = Db::name('house_fee')
  52. ->where('id',$pid)
  53. ->find();
  54. }
  55. $this->assign('pid',$pid);
  56. $this->assign('pInfo',$pInfo);
  57. return $this->fetch();
  58. }
  59. }
  60. /**
  61. * 删除记录
  62. * @param int $id
  63. */
  64. public function del($id=0){
  65. if(!$id){
  66. $this->error('参数错误');
  67. }
  68. $info = db($this->table)->where('id',$id)->where('del',0)->find();
  69. if(!$info) $this->error('科目不存在');
  70. if($info['parent_id']==0){
  71. $child = db($this->table)->where('parent_id',$id)
  72. ->where('del',0)->find();
  73. if($child) $this->error('请先删除子科目');
  74. }
  75. $res = db($this->table)->where('id',$id)->setField('del',1);
  76. if($res){
  77. $this->success('删除成功');
  78. }else{
  79. $this->error('删除失败');
  80. }
  81. }
  82. /**
  83. * 改变字段值
  84. * @param int $fv
  85. * @param string $fn
  86. * @param int $fv
  87. */
  88. public function changeField($id=0,$fn='',$fv=0){
  89. if(!$fn||!$id){
  90. $this->error('参数错误');
  91. }
  92. $res = db($this->table)->where('id',$id)->setField($fn,$fv);
  93. if($res){
  94. $this->success('操作成功');
  95. }else{
  96. $this->error('操作失败');
  97. }
  98. }
  99. }