PatrolCate.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. class PatrolCate extends Auth
  6. {
  7. public function __construct(App $app = null) {
  8. parent::__construct($app);
  9. $this->model= new \app\common\model\PatrolCate();
  10. $this->table= $this->model->table;
  11. }
  12. public function index($mode=1){
  13. if(request()->isAjax()){
  14. //分页参数
  15. $length = input('rows',10,'intval'); //每页条数
  16. $page = input('page',1,'intval'); //第几页
  17. $start = ($page - 1) * $length; //分页开始位置
  18. //排序
  19. $sortRow = input('sidx','id','trim'); //排序列
  20. $sort = input('sord','desc','trim'); //排序方式
  21. $order = $sortRow.' '.$sort;
  22. $title = input('title','','trim');
  23. if($title){
  24. $map[] = ['title','like','%'.$title.'%'];
  25. }
  26. $enable = input('enable','','trim');
  27. if($enable != ''){
  28. $map[] = ['enable','=',$enable];
  29. }
  30. $map[] = ['del','=',0];
  31. $map[] = ['patrol_mode','=',$mode];
  32. $map[] = ['org_id','=',$this->orgId];
  33. $map= empty($map) ? true: $map;
  34. //数据查询
  35. $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
  36. //数据返回
  37. $totalCount = db($this->table)->where($map)->count();
  38. $totalPage = ceil($totalCount/$length);
  39. $result['page'] = $page;
  40. $result['total'] = $totalPage;
  41. $result['records'] = $totalCount;
  42. $result['rows'] = $lists;
  43. return json($result);
  44. }else{
  45. $this->assign('m_name','检查项分类');
  46. $this->assign('mode',$mode);
  47. return $this->fetch();
  48. }
  49. }
  50. /**
  51. * 新增/编辑
  52. */
  53. public function add($id=0){
  54. $mode =input('mode',1,'trim');
  55. if(request()->isPost()){
  56. $res = $this->model->updates();
  57. if($res){
  58. $this->success('操作成功',url('index',['mode'=>$mode]));
  59. }else{
  60. $this->error($this->model->getError());
  61. }
  62. }else{
  63. if($id){
  64. $info =db($this->table)->where('id',$id)->find();
  65. $this->assign('info',$info);
  66. }
  67. $this->assign('mode',$mode);
  68. return $this->fetch();
  69. }
  70. }
  71. /**
  72. * 删除记录
  73. * @param int $id
  74. */
  75. public function del($id=0){
  76. if(!$id){
  77. $this->error('参数错误');
  78. }
  79. $r = Db::name('patrol_form')
  80. ->where('cate_id',$id)
  81. ->where('del',0)
  82. ->find();
  83. if($r){
  84. $this->error('当前分类有检查项绑定,暂不能删除');
  85. }
  86. $res = db($this->table)->where('id',$id)->setField('del',1);
  87. if($res){
  88. $this->success('删除成功');
  89. }else{
  90. $this->error('删除失败');
  91. }
  92. }
  93. /**
  94. * 改变字段值
  95. * @param int $fv
  96. * @param string $fn
  97. * @param int $fv
  98. */
  99. public function changeField($id=0,$fn='',$fv=0){
  100. if(!$fn||!$id){
  101. $this->error('参数错误');
  102. }
  103. $res = db($this->table)->where('id',$id)->setField($fn,$fv);
  104. if($res){
  105. $this->success('操作成功');
  106. }else{
  107. $this->error('操作失败');
  108. }
  109. }
  110. }