DisinfectionAlarm.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. class DisinfectionAlarm extends Auth {
  6. public function __construct(App $app = null) {
  7. parent::__construct($app);
  8. $this->model = new \app\common\model\DailyForm();
  9. }
  10. public function index() {
  11. if (request()->isAjax()) {
  12. //分页参数
  13. $length = input('rows', 10, 'intval'); //每页条数
  14. $page = input('page', 1, 'intval'); //第几页
  15. $start = ($page - 1) * $length; //分页开始位置
  16. //排序
  17. $sortRow = input('sidx', 'id', 'trim'); //排序列
  18. $sort = input('sord', 'asc', 'trim'); //排序方式
  19. $order = $sortRow . ' ' . $sort . ' ,id desc';
  20. $title = input('title', '', 'trim');
  21. if ($title) {
  22. $map[] = ['b.title', 'like', '%' . $title . '%'];
  23. }
  24. $enable = input('enable', '', 'trim');
  25. if ($enable != '') {
  26. $map[] = ['a.enable', '=', $enable];
  27. }
  28. $map[] = ['a.org_id', '=', $this->orgId];
  29. // $map[] = ['del', '=', 0];
  30. $map = empty($map) ? true : $map;
  31. //数据查询
  32. $lists = Db::name('disinfection_alarm')
  33. ->alias('a')
  34. ->join('disinfection_device b','a.device_id = b.id')
  35. ->field('a.*,b.title,b.sn')
  36. ->where($map)->limit($start, $length)->order($order)->select();
  37. //数据返回
  38. $totalCount = Db::name('disinfection_alarm')
  39. ->alias('a')
  40. ->join('disinfection_device b','a.device_id = b.id')
  41. ->where($map)->count();
  42. $totalPage = ceil($totalCount / $length);
  43. $result['page'] = $page;
  44. $result['total'] = $totalPage;
  45. $result['records'] = $totalCount;
  46. $result['rows'] = $lists;
  47. return json($result);
  48. }
  49. else {
  50. $this->assign('meta_title', '预警记录');
  51. return $this->fetch();
  52. }
  53. }
  54. /**
  55. * 新增/编辑
  56. */
  57. public function add($id = 0) {
  58. if (request()->isPost()) {
  59. $model = $this->model;
  60. $res = $model->updates();
  61. if ($res) {
  62. $this->success('操作成功', url('index'));
  63. }
  64. else {
  65. $this->error($model->getError());
  66. }
  67. }
  68. else {
  69. $meta_title = '新增';
  70. if ($id) {
  71. $info = Db::name('disinfection_alarm')->where('id', $id)->find();
  72. $this->assign('info', $info);
  73. $meta_title = '编辑';
  74. }
  75. $this->assign('meta_title', $meta_title);
  76. return $this->fetch();
  77. }
  78. }
  79. /**
  80. * 删除记录
  81. * @param int $id
  82. */
  83. public function del($id = 0) {
  84. if (!$id) {
  85. $this->error('参数错误');
  86. }
  87. $res = Db::name('disinfection_alarm')->delete($id);
  88. if ($res) {
  89. // model('ActionLog')->addlog(is_login(),27,'任务工作项:删除',['id' => $id],cur_org_id());
  90. $this->success('删除成功');
  91. }
  92. else {
  93. $this->error('删除失败');
  94. }
  95. }
  96. }