Monitor.php 3.3 KB

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