mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
softDelete trait增加destroy方法 并增加第二个参数 用于真实删除数据
This commit is contained in:
@@ -52,6 +52,35 @@ trait SoftDelete
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
* @access public
|
||||
* @param mixed $data 主键列表 支持闭包查询条件
|
||||
* @param bool $force 是否强制删除
|
||||
* @return integer 成功删除的记录数
|
||||
*/
|
||||
public static function destroy($data, $force = false)
|
||||
{
|
||||
$model = new static();
|
||||
$query = $model->db();
|
||||
if (is_array($data) && key($data) !== 0) {
|
||||
$query->where($data);
|
||||
$data = null;
|
||||
} elseif ($data instanceof \Closure) {
|
||||
call_user_func_array($data, [ & $query]);
|
||||
$data = null;
|
||||
}
|
||||
$resultSet = $query->select($data);
|
||||
$count = 0;
|
||||
if ($resultSet) {
|
||||
foreach ($resultSet as $data) {
|
||||
$result = $data->delete($force);
|
||||
$count += $result;
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复被软删除的记录
|
||||
* @access public
|
||||
|
||||
Reference in New Issue
Block a user