|
|
@ -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; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |