mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
优化Builder类的parseWhere方法
This commit is contained in:
@@ -224,43 +224,34 @@ abstract class Builder
|
|||||||
}
|
}
|
||||||
|
|
||||||
$whereStr = '';
|
$whereStr = '';
|
||||||
// 获取字段信息
|
|
||||||
$fields = $this->query->getTableFields($options);
|
|
||||||
$binds = $this->query->getFieldsBind($options);
|
|
||||||
foreach ($where as $key => $val) {
|
foreach ($where as $key => $val) {
|
||||||
$str = [];
|
$str = [];
|
||||||
foreach ($val as $field => $value) {
|
foreach ($val as $field => $value) {
|
||||||
if ($fields && in_array($field, $fields, true) && is_scalar($value) && !$this->query->isBind($field)) {
|
|
||||||
$this->query->bind($field, $value, isset($binds[$field]) ? $binds[$field] : PDO::PARAM_STR);
|
|
||||||
$value = ':' . $field;
|
|
||||||
}
|
|
||||||
if ($value instanceof \Closure) {
|
if ($value instanceof \Closure) {
|
||||||
// 使用闭包查询
|
// 使用闭包查询
|
||||||
$query = new Query($this->connection);
|
$query = new Query($this->connection);
|
||||||
call_user_func_array($value, [ & $query]);
|
call_user_func_array($value, [ & $query]);
|
||||||
$str[] = ' ' . $key . ' ( ' . $this->buildWhere($query->getOptions('where'), $options) . ' )';
|
$str[] = ' ' . $key . ' ( ' . $this->buildWhere($query->getOptions('where'), $options) . ' )';
|
||||||
} else {
|
} elseif (strpos($field, '|')) {
|
||||||
if (strpos($field, '|')) {
|
// 不同字段使用相同查询条件(OR)
|
||||||
// 不同字段使用相同查询条件(OR)
|
$array = explode('|', $field);
|
||||||
$array = explode('|', $field);
|
$item = [];
|
||||||
$item = [];
|
foreach ($array as $k) {
|
||||||
foreach ($array as $k) {
|
$item[] = $this->parseWhereItem($k, $value, '', $options);
|
||||||
$item[] = $this->parseWhereItem($k, $value, '', $options);
|
|
||||||
}
|
|
||||||
$str[] = ' ' . $key . ' ( ' . implode(' OR ', $item) . ' )';
|
|
||||||
} elseif (strpos($field, '&')) {
|
|
||||||
// 不同字段使用相同查询条件(AND)
|
|
||||||
$array = explode('&', $field);
|
|
||||||
$item = [];
|
|
||||||
foreach ($array as $k) {
|
|
||||||
$item[] = $this->parseWhereItem($k, $value, '', $options);
|
|
||||||
}
|
|
||||||
$str[] = ' ' . $key . ' ( ' . implode(' AND ', $item) . ' )';
|
|
||||||
} else {
|
|
||||||
// 对字段使用表达式查询
|
|
||||||
$field = is_string($field) ? $field : '';
|
|
||||||
$str[] = ' ' . $key . ' ' . $this->parseWhereItem($field, $value, $key, $options);
|
|
||||||
}
|
}
|
||||||
|
$str[] = ' ' . $key . ' ( ' . implode(' OR ', $item) . ' )';
|
||||||
|
} elseif (strpos($field, '&')) {
|
||||||
|
// 不同字段使用相同查询条件(AND)
|
||||||
|
$array = explode('&', $field);
|
||||||
|
$item = [];
|
||||||
|
foreach ($array as $k) {
|
||||||
|
$item[] = $this->parseWhereItem($k, $value, '', $options);
|
||||||
|
}
|
||||||
|
$str[] = ' ' . $key . ' ( ' . implode(' AND ', $item) . ' )';
|
||||||
|
} else {
|
||||||
|
// 对字段使用表达式查询
|
||||||
|
$field = is_string($field) ? $field : '';
|
||||||
|
$str[] = ' ' . $key . ' ' . $this->parseWhereItem($field, $value, $key, $options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user