public function conditionFactory($column, $value, $operator = '=')
{
if ($this->sql['where'] == '') {
$this->sql['where'] = 'WHERE ';
}
if ($this->whereNeedAddAndOrOr === 1) {
$this->sql['where'] .= ' AND ';
} else {
if ($this->whereNeedAddAndOrOr === 2) {
$this->sql['where'] .= ' OR ';
}
}
//下一次where操作默认加上AND
$this->whereNeedAddAndOrOr = 1;
if ($operator == 'IN' || $operator == 'NOT IN') {
empty($value) && ($value = [0]);
//这边可直接跳过不组装sql,但是为了给用户提示无条件 便于调试还是加上where field in(0)
$inValue = '(';
foreach ($value as $val) {
$inValue .= '%s ,';
$this->bindParams[] = $val;
}
$this->sql['where'] .= "{$column} {$operator} " . rtrim($inValue, ',') . ') ';
} elseif ($operator == 'BETWEEN' || $operator == 'NOT BETWEEN') {
$betweenValue = '%s AND %s ';
$this->bindParams[] = $value[0];
$this->bindParams[] = $value[1];
$this->sql['where'] .= "{$column} {$operator} {$betweenValue}";
} else {
if ($operator == 'IS NULL' || $operator == 'IS NOT NULL') {
$this->sql['where'] .= "{$column} {$operator}";
} else {
$this->bindParams[] = $value;
$value = '%s';
$this->sql['where'] .= "{$column} {$operator} {$value} ";
}
}
}