diff --git a/app/admin/traits/Curd.php b/app/admin/traits/Curd.php index 89bd1912..8a39cc67 100644 --- a/app/admin/traits/Curd.php +++ b/app/admin/traits/Curd.php @@ -77,9 +77,9 @@ public function add() /** * @NodeAnotation(title="编辑") */ - public function edit($id) + public function edit() { - $row = $this->model->find($id); + $row = $this->model->find($this->request->param($this->model->getPk())); empty($row) && $this->error('数据不存在'); if ($this->request->isAjax()) { $post = $this->request->post(); @@ -99,9 +99,9 @@ public function edit($id) /** * @NodeAnotation(title="删除") */ - public function delete($id) + public function delete() { - $row = $this->model->whereIn('id', $id)->select(); + $row = $this->model->whereIn($this->model->getPk(), $this->request->param($this->model->getPk()))->select(); $row->isEmpty() && $this->error('数据不存在'); try { $save = $row->delete(); @@ -131,7 +131,7 @@ public function export() $list = $this->model ->where($where) ->limit(100000) - ->order('id', 'desc') + ->order($this->model->getPk(), 'desc') ->select() ->toArray(); $fileName = time(); @@ -145,12 +145,12 @@ public function modify() { $post = $this->request->post(); $rule = [ - 'id|ID' => 'require', - 'field|字段' => 'require', - 'value|值' => 'require', + $this->model->getPk().'|主键' => 'require', + 'field|字段' => 'require', + 'value|值' => 'require', ]; $this->validate($post, $rule); - $row = $this->model->find($post['id']); + $row = $this->model->find($post[$this->model->getPk()]); if (!$row) { $this->error('数据不存在'); }