diff --git a/application/admin/library/traits/Backend.php b/application/admin/library/traits/Backend.php index 89b73ac09af8f3da4a6a2ffd5a589a0594da6a2b..f5a5589300c1326dd4aaf5e85f56021eb6005785 100755 --- a/application/admin/library/traits/Backend.php +++ b/application/admin/library/traits/Backend.php @@ -1,6 +1,7 @@ modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; $this->model->validate($validate); } - $result = $this->model->allowField(true)->save($params); + if (Hook::get('common_model_add')) { + $model = $this->model; + $result = Hook::listen("common_model_add", $model, $params); + } else { + $result = $this->model->allowField(true)->save($params); + } if ($result !== false) { $this->success(); } else { @@ -125,7 +131,11 @@ trait Backend $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; $row->validate($validate); } - $result = $row->allowField(true)->save($params); + if (Hook::get('common_model_edit')) { + $result = Hook::listen("common_model_edit", $row, $params); + } else { + $result = $row->allowField(true)->save($params); + } if ($result !== false) { $this->success(); } else { @@ -154,10 +164,15 @@ trait Backend if (is_array($adminIds)) { $count = $this->model->where($this->dataLimitField, 'in', $adminIds); } - $list = $this->model->where($pk, 'in', $ids)->select(); - $count = 0; - foreach ($list as $k => $v) { - $count += $v->delete(); + if (Hook::get('common_model_del')) { + $model = $this->model; + $count = Hook::listen("common_model_del", $model, [$pk,$ids]); + } else { + $list = $this->model->where($pk, 'in', $ids)->select(); + $count = 0; + foreach ($list as $k => $v) { + $count += $v->delete(); + } } if ($count) { $this->success(); @@ -178,13 +193,18 @@ trait Backend if (is_array($adminIds)) { $count = $this->model->where($this->dataLimitField, 'in', $adminIds); } - if ($ids) { - $this->model->where($pk, 'in', $ids); - } - $count = 0; - $list = $this->model->onlyTrashed()->select(); - foreach ($list as $k => $v) { - $count += $v->delete(true); + if (Hook::get('common_model_destroy')) { + $model = $this->model; + $count = Hook::listen("common_model_destroy", $model, [$pk,$ids]); + } else { + if ($ids) { + $this->model->where($pk, 'in', $ids); + } + $count = 0; + $list = $this->model->onlyTrashed()->select(); + foreach ($list as $k => $v) { + $count += $v->delete(true); + } } if ($count) { $this->success(); @@ -204,13 +224,18 @@ trait Backend if (is_array($adminIds)) { $this->model->where($this->dataLimitField, 'in', $adminIds); } - if ($ids) { - $this->model->where($pk, 'in', $ids); - } - $count = 0; - $list = $this->model->onlyTrashed()->select(); - foreach ($list as $index => $item) { - $count += $item->restore(); + if (Hook::get('common_model_restore')) { + $model = $this->model; + $count = Hook::listen("common_model_restore", $model, [$pk,$ids]); + } else { + if ($ids) { + $this->model->where($pk, 'in', $ids); + } + $count = 0; + $list = $this->model->onlyTrashed()->select(); + foreach ($list as $index => $item) { + $count += $item->restore(); + } } if ($count) { $this->success(); @@ -224,6 +249,7 @@ trait Backend public function multi($ids = "") { $ids = $ids ? $ids : $this->request->param("ids"); + $pk = $this->model->getPk(); if ($ids) { if ($this->request->has('params')) { parse_str($this->request->post("params"), $values); @@ -233,10 +259,15 @@ trait Backend if (is_array($adminIds)) { $this->model->where($this->dataLimitField, 'in', $adminIds); } - $count = 0; - $list = $this->model->where($this->model->getPk(), 'in', $ids)->select(); - foreach ($list as $index => $item) { - $count += $item->allowField(true)->isUpdate(true)->save($values); + if (Hook::get('common_model_multi')) { + $model = $this->model; + $count = Hook::listen("common_model_multi", $model, [$pk,$ids,$values]); + } else { + $count = 0; + $list = $this->model->where($pk, 'in', $ids)->select(); + foreach ($list as $index => $item) { + $count += $item->allowField(true)->isUpdate(true)->save($values); + } } if ($count) { $this->success();