zengyyh 4 months ago
parent d3a92a6ee0
commit 322245bc92
  1. 5
      app/store/controller/Recovery.php
  2. 35
      app/store/model/server/ServerRecovery.php

@ -175,10 +175,9 @@ class Recovery extends Controller
* @return Json * @return Json
* @author: wanghousheng * @author: wanghousheng
*/ */
public function deleteRecovery(array $recoveryId): Json public function deleteRecovery(array $serverId): Json
{ {
$model = new ServerRecovery; if(ServerRecovery::deleteRecoveryId($serverId)){
if ($model->remove($recoveryId)) {
return $this->renderSuccess('删除成功'); return $this->renderSuccess('删除成功');
} }
return $this->renderError('删除失败'); return $this->renderError('删除失败');

@ -59,4 +59,39 @@ class ServerRecovery extends BaseServerRecovery
{ {
return static::detail($recoveryId, ['image', 'category']); return static::detail($recoveryId, ['image', 'category']);
} }
public static function deleteRecoveryId($data, bool $force = false)
{
// 传入空值(包括空字符串和空数组)的时候不会做任何的数据删除操作,但传入0则是有效的
if (empty($data) && 0 !== $data) {
return false;
}
$model = (new static());
$query = $model->db(false);
// 仅当强制删除时包含软删除数据
if ($force) {
$query->removeOption('soft_delete');
}
if (is_array($data) && key($data) !== 0) {
$query->where($data);
$data = null;
} elseif ($data instanceof \Closure) {
call_user_func_array($data, [&$query]);
$data = null;
} elseif (is_null($data)) {
return false;
}
$resultSet = $query->select($data);
foreach ($resultSet as $result) {
/** @var Model $result */
$result->force($force)->delete();
}
return true;
}
} }
Loading…
Cancel
Save