DisinfectionDevice.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. class DisinfectionDevice extends Auth {
  6. public function __construct(App $app = null) {
  7. parent::__construct($app);
  8. $this->model = new \app\common\model\DisinfectionDevice();
  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[] = ['title', 'like', '%' . $title . '%'];
  23. }
  24. $map[] = ['org_id', '=', $this->orgId];
  25. $map = empty($map) ? true : $map;
  26. //数据查询
  27. $lists = Db::name('disinfection_device')
  28. ->where($map)->limit($start, $length)->order($order)->select();
  29. //数据返回
  30. $totalCount = Db::name('disinfection_device')->where($map)->count();
  31. $totalPage = ceil($totalCount / $length);
  32. $result['page'] = $page;
  33. $result['total'] = $totalPage;
  34. $result['records'] = $totalCount;
  35. $result['rows'] = $lists;
  36. return json($result);
  37. }
  38. else {
  39. $this->assign('meta_title', '设备列表');
  40. return $this->fetch();
  41. }
  42. }
  43. /**
  44. * 新增/编辑
  45. */
  46. public function add($id = 0) {
  47. if (request()->isPost()) {
  48. $model = $this->model;
  49. $res = $model->updates();
  50. if ($res) {
  51. $this->success('操作成功', url('index'));
  52. }
  53. else {
  54. $this->error($model->getError());
  55. }
  56. }
  57. else {
  58. $meta_title = '新增设备';
  59. if ($id) {
  60. $info = Db::name('disinfection_device')->where('id', $id)->find();
  61. $this->assign('info', $info);
  62. $meta_title = '编辑设备';
  63. }
  64. $this->assign('meta_title', $meta_title);
  65. return $this->fetch();
  66. }
  67. }
  68. /**
  69. * 删除记录
  70. * @param int $id
  71. */
  72. public function del($id = 0) {
  73. if (!$id) {
  74. $this->error('参数错误');
  75. }
  76. $res = Db::name('disinfection_device')->delete($id);
  77. if ($res) {
  78. $this->success('删除成功');
  79. }
  80. else {
  81. $this->error('删除失败');
  82. }
  83. }
  84. }