DisinfectionTodo.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. class DisinfectionTodo 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', 'sort', 'trim'); //排序列
  18. $sort = input('sord', 'asc', 'trim'); //排序方式
  19. $order = $sortRow . ' ' . $sort . ' ,id desc';
  20. $title = input('content', '', 'trim');
  21. if ($title) {
  22. $map[] = ['content', 'like', '%' . $title . '%'];
  23. }
  24. $enable = input('enable', '', 'trim');
  25. if ($enable != '') {
  26. $map[] = ['enable', '=', $enable];
  27. }
  28. $map[] = ['org_id', '=', $this->orgId];
  29. // $map[] = ['del', '=', 0];
  30. $map = empty($map) ? true : $map;
  31. //数据查询
  32. $lists = Db::name('disinfection_todo')
  33. ->where($map)->limit($start, $length)->order($order)->select();
  34. foreach ($lists as $k=>$v){
  35. $lists[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  36. }
  37. //数据返回
  38. $totalCount = Db::name('disinfection_todo')->where($map)->count();
  39. $totalPage = ceil($totalCount / $length);
  40. $result['page'] = $page;
  41. $result['total'] = $totalPage;
  42. $result['records'] = $totalCount;
  43. $result['rows'] = $lists;
  44. return json($result);
  45. }
  46. else {
  47. $this->assign('meta_title', '预警工单');
  48. // $this->assign('m_name', '工作项');
  49. return $this->fetch();
  50. }
  51. }
  52. /**
  53. * 新增/编辑
  54. */
  55. public function add($id = 0) {
  56. if (request()->isPost()) {
  57. $model = $this->model;
  58. $res = $model->updates();
  59. if ($res) {
  60. $this->success('操作成功', url('index'));
  61. }
  62. else {
  63. $this->error($model->getError());
  64. }
  65. }
  66. else {
  67. $meta_title = '新增';
  68. if ($id) {
  69. $info = Db::name('disinfection_todo')->where('id', $id)->find();
  70. $this->assign('info', $info);
  71. $meta_title = '编辑';
  72. }
  73. $this->assign('meta_title', $meta_title);
  74. return $this->fetch();
  75. }
  76. }
  77. /**
  78. * 删除记录
  79. * @param int $id
  80. */
  81. public function del($id = 0) {
  82. if (!$id) {
  83. $this->error('参数错误');
  84. }
  85. $res = Db::name('disinfection_todo')->delete($id);
  86. if ($res) {
  87. // model('ActionLog')->addlog(is_login(),27,'任务工作项:删除',['id' => $id],cur_org_id());
  88. $this->success('删除成功');
  89. }
  90. else {
  91. $this->error('删除失败');
  92. }
  93. }
  94. }