Maintenance.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace app\admin\controller\equipment;
  3. use app\admin\model\equipment\Staff;
  4. use app\common\controller\Backend;
  5. /**
  6. * 保养计划
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Maintenance extends Backend
  11. {
  12. /**
  13. * Plan模型对象
  14. * @var \app\admin\model\equipment\Plan
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\equipment\Plan;
  21. $this->view->assign("statusList", $this->model->getStatusList());
  22. }
  23. /**
  24. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  25. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  26. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  27. */
  28. /**
  29. * 查看
  30. */
  31. public function index()
  32. {
  33. $this->relationSearch = true;
  34. //设置过滤方法
  35. $this->request->filter(['strip_tags', 'trim']);
  36. if ($this->request->isAjax()) {
  37. //如果发送的来源是Selectpage,则转发到Selectpage
  38. if ($this->request->request('keyField')) {
  39. return $this->selectpage();
  40. }
  41. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  42. $list = $this->model
  43. ->with(['planArchives', 'planFields', 'planUsers'])
  44. ->where($where)
  45. ->where('type', 'maintenance')
  46. ->order($sort, $order)
  47. ->paginate($limit);
  48. $result = array("total" => $list->total(), "rows" => $list->items());
  49. return json($result);
  50. }
  51. return $this->view->fetch();
  52. }
  53. /**
  54. * 已停用计划
  55. */
  56. public function deactivated()
  57. {
  58. $this->relationSearch = true;
  59. //设置过滤方法
  60. $this->request->filter(['strip_tags', 'trim']);
  61. if ($this->request->isAjax()) {
  62. //如果发送的来源是Selectpage,则转发到Selectpage
  63. if ($this->request->request('keyField')) {
  64. return $this->selectpage();
  65. }
  66. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  67. $list = $this->model
  68. ->onlyTrashed()
  69. ->with(['planArchives', 'planFields', 'planUsers'])
  70. ->where($where)
  71. ->where('type', 'maintenance')
  72. ->order($sort, $order)
  73. ->paginate($limit);
  74. $result = array("total" => $list->total(), "rows" => $list->items());
  75. return json($result);
  76. }
  77. return $this->view->fetch();
  78. }
  79. /**
  80. * 添加
  81. */
  82. public function add()
  83. {
  84. if ($this->request->isPost()) {
  85. $params = $this->request->post("row/a");
  86. if ($params) {
  87. $result = $this->model->addPlan('maintenance', $params);
  88. if ($result === true) {
  89. $this->success();
  90. } else {
  91. $this->error($result);
  92. }
  93. }
  94. $this->error(__('Parameter %s can not be empty', ''));
  95. }
  96. return parent::add();
  97. }
  98. }