Report.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace app\admin\controller\quality;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. use think\Exception;
  6. use think\exception\PDOException;
  7. use think\exception\ValidateException;
  8. /**
  9. * 质量因子
  10. *
  11. * @icon fa fa-circle-o
  12. */
  13. class Report extends Backend
  14. {
  15. /**
  16. * Report模型对象
  17. * @var \app\admin\model\quality\Report
  18. */
  19. protected $model = null;
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = new \app\admin\model\quality\Report;
  24. }
  25. /**
  26. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  27. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  28. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  29. */
  30. /**
  31. * 查看
  32. */
  33. public function index()
  34. {
  35. //设置过滤方法
  36. $this->request->filter(['strip_tags']);
  37. if ($this->request->isAjax()) {
  38. //如果发送的来源是Selectpage,则转发到Selectpage
  39. if ($this->request->request('keyField')) {
  40. return $this->selectpage();
  41. }
  42. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  43. $total = $this->model
  44. ->where($where)
  45. ->where('type',2)
  46. ->order($sort, $order)
  47. ->count();
  48. $list = $this->model
  49. ->where($where)
  50. ->where('type',2)
  51. ->order($sort, $order)
  52. ->limit($offset, $limit)
  53. ->select();
  54. $list = collection($list)->toArray();
  55. $result = array("total" => $total, "rows" => $list);
  56. return json($result);
  57. }
  58. return $this->view->fetch();
  59. }
  60. /**
  61. * 添加
  62. */
  63. public function add()
  64. {
  65. if ($this->request->isPost()) {
  66. $params = $this->request->post("row/a");
  67. if ($params) {
  68. $params = $this->preExcludeFields($params);
  69. if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  70. $params[$this->dataLimitField] = $this->auth->id;
  71. }
  72. $result = false;
  73. Db::startTrans();
  74. try {
  75. //是否采用模型验证
  76. if ($this->modelValidate) {
  77. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  78. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  79. $this->model->validateFailException(true)->validate($validate);
  80. }
  81. $params['type'] = 2;
  82. $result = $this->model->allowField(true)->save($params);
  83. Db::commit();
  84. } catch (ValidateException $e) {
  85. Db::rollback();
  86. $this->error($e->getMessage());
  87. } catch (PDOException $e) {
  88. Db::rollback();
  89. $this->error($e->getMessage());
  90. } catch (Exception $e) {
  91. Db::rollback();
  92. $this->error($e->getMessage());
  93. }
  94. if ($result !== false) {
  95. $this->success();
  96. } else {
  97. $this->error(__('No rows were inserted'));
  98. }
  99. }
  100. $this->error(__('Parameter %s can not be empty', ''));
  101. }
  102. return $this->view->fetch();
  103. }
  104. }