改进软删除操作

This commit is contained in:
thinkphp
2017-03-13 16:47:50 +08:00
parent 75beb3f424
commit a7cdc2b126
3 changed files with 27 additions and 7 deletions

View File

@@ -280,6 +280,13 @@ abstract class Builder
$whereStr .= empty($whereStr) ? substr(implode(' ', $str), strlen($key) + 1) : implode(' ', $str);
}
if (!empty($options['soft_delete'])) {
// 附加软删除条件
list($field, $condition) = $options['soft_delete'];
$whereStr = $whereStr ? '( ' . $whereStr . ' ) AND ' : '';
$whereStr = $whereStr . $this->parseWhereItem($field, $condition, '', $options, $binds);
}
return $whereStr;
}

View File

@@ -1120,6 +1120,20 @@ class Query
return $this;
}
/**
* 设置软删除字段及条件
* @access public
* @param false|string $field 查询字段
* @param mixed $condition 查询条件
* @return $this
*/
public function useSoftDelete($field, $condition = null)
{
if ($field) {
$this->options['soft_delete'] = [$field, $condition ?: ['null', '']];
}
}
/**
* 分析查询表达式
* @access public