Apply.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace app\admin\controller\ddrive;
  3. use app\common\controller\Backend;
  4. use Exception;
  5. use think\Db;
  6. use think\exception\PDOException;
  7. use think\exception\ValidateException;
  8. /**
  9. *
  10. *
  11. * @icon fa fa-circle-o
  12. */
  13. class Apply extends Backend
  14. {
  15. /**
  16. * Apply模型对象
  17. * @var \addons\ddrive\model\Apply
  18. */
  19. protected $model = null;
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = new \addons\ddrive\model\Apply;
  24. $this->view->assign("statusList", $this->model->getStatusList());
  25. }
  26. /**
  27. * 查看
  28. */
  29. public function index()
  30. {
  31. //当前是否为关联查询
  32. $this->relationSearch = true;
  33. //设置过滤方法
  34. $this->request->filter(['strip_tags', 'trim']);
  35. if ($this->request->isAjax()) {
  36. //如果发送的来源是Selectpage,则转发到Selectpage
  37. if ($this->request->request('keyField')) {
  38. return $this->selectpage();
  39. }
  40. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  41. $total = $this->model
  42. ->with(['user'])
  43. ->where($where)
  44. ->order($sort, $order)
  45. ->count();
  46. $list = $this->model
  47. ->with(['user'])
  48. ->where($where)
  49. ->order($sort, $order)
  50. ->limit($offset, $limit)
  51. ->select();
  52. foreach ($list as $row) {
  53. }
  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 edit($ids = null)
  64. {
  65. $row = $this->model->get($ids);
  66. if (!$row) {
  67. $this->error(__('No Results were found'));
  68. }
  69. $adminIds = $this->getDataLimitAdminIds();
  70. if (is_array($adminIds)) {
  71. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  72. $this->error(__('You have no permission'));
  73. }
  74. }
  75. if ($this->request->isPost()) {
  76. $params = $this->request->post("row/a");
  77. if ($params) {
  78. $params = $this->preExcludeFields($params);
  79. $result = false;
  80. Db::startTrans();
  81. try {
  82. //是否采用模型验证
  83. if ($this->modelValidate) {
  84. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  85. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  86. $row->validateFailException(true)->validate($validate);
  87. }
  88. $result = $row->allowField(true)->save($params);
  89. Db::commit();
  90. } catch (ValidateException $e) {
  91. Db::rollback();
  92. $this->error($e->getMessage());
  93. } catch (PDOException $e) {
  94. Db::rollback();
  95. $this->error($e->getMessage());
  96. } catch (Exception $e) {
  97. Db::rollback();
  98. $this->error($e->getMessage());
  99. }
  100. if ($result !== false) {
  101. $this->success();
  102. } else {
  103. $this->error(__('No rows were updated'));
  104. }
  105. }
  106. $this->error(__('Parameter %s can not be empty', ''));
  107. }
  108. $this->view->assign("row", $row);
  109. return $this->view->fetch();
  110. }
  111. }