Think/Db/Driver.php
protected function parseWhereItem($key, $val)
    {
        $whereStr = '';
        if (is_array($val)) {
            if (is_string($val[0])) {
                $exp = strtolower($val[0]);
                // 比较运算
                if (preg_match('/^(eq|neq|gt|egt|lt|elt)$/', $exp)) {
                    $whereStr .= $key.' '.$this->exp[$exp].' '.$this->parseValue($val[1]);
                    // 模糊查找
                } elseif (preg_match('/^(notlike|like)$/', $exp)) {
                    if (is_array($val[1])) {
                        $likeLogic = isset($val[2]) ? strtoupper($val[2]) : 'OR';
                        if (in_array($likeLogic, ['AND', 'OR', 'XOR'])) {
                            $like = [];
                            foreach ($val[1] as $item) {
                                $like[] = $key.' '.$this->exp[$exp].' '.$this->parseValue($item);
                            }
                            $whereStr .= '('.implode(' '.$likeLogic.' ', $like).')';
                        }
                    } else {
                        $whereStr .= $key.' '.$this->exp[$exp].' '.$this->parseValue($val[1]);
                    }
                    // 使用表达式
                } elseif ('bind' == $exp) {
                    $whereStr .= $key.' = :'.$val[1];
                    // 使用表达式
                } elseif ('exp' == $exp) {
                    $whereStr .= $key.' '.$val[1];
                    // IN 运算
                } elseif (preg_match('/^(notin|not in|in)$/', $exp)) {
                    if (isset($val[2]) && 'exp' == $val[2]) {
                        $whereStr .= $key.' '.$this->exp[$exp].' '.$val[1];
                    } else {
                        if (is_string($val[1])) {
                            $val[1] = explode(',', $val[1]);
                        }
                        $zone = implode(',', $this->parseValue($val[1]));
                        $whereStr .= $key.' '.$this->exp[$exp].' ('.$zone.')';
                    }
                    // BETWEEN运算
                } elseif (preg_match('/^(notbetween|not between|between)$/', $exp)) {
                    $data = is_string($val[1]) ? explode(',', $val[1]) : $val[1];
                    $whereStr .= $key.' '.$this->exp[$exp].' '.$this->parseValue(
                            $data[0]
                        ).' AND '.$this->parseValue($data[1]);
                } else {
                    throw new BaseException(L('_EXPRESS_ERROR_').':'.$val[0]);
                }
            } else {
                $count = count($val);
                $rule = isset($val[$count - 1]) ? (is_array($val[$count - 1]) ? strtoupper(
                    $val[$count - 1][0]
                ) : strtoupper($val[$count - 1])) : '';
                if (in_array($rule, ['AND', 'OR', 'XOR'])) {
                    $count = $count - 1;
                } else {
                    $rule = 'AND';
                }
                for ($i = 0; $i < $count; $i++) {
                    $data = is_array($val[$i]) ? $val[$i][1] : $val[$i];
                    if ('exp' == strtolower($val[$i][0])) {
                        $whereStr .= $key.' '.$data.' '.$rule.' ';
                    } else {
                        $whereStr .= $this->parseWhereItem($key, $val[$i]).' '.$rule.' ';
                    }
                }
                $whereStr = '( '.substr($whereStr, 0, -4).' )';
            }
        } else {
            //对字符串类型字段采用模糊匹配
            $likeFields = $this->config['db_like_fields'];
            if ($likeFields && preg_match('/^('.$likeFields.')$/i', $key)) {
                $whereStr .= $key.' LIKE '.$this->parseValue('%'.$val.'%');
            } else {
                $whereStr .= $key.' = '.$this->parseValue($val);
            }
        }

        return $whereStr;
    }
protected function parseWhereItem($key, $val)
    {
        $whereStr = '';
        if (is_array($val)) {
            if (is_string($val[0])) {
                $exp = strtolower($val[0]);
                // 比较运算
                if (preg_match('/^(eq|neq|gt|egt|lt|elt)$/', $exp)) {
                    $whereStr .= $key.' '.$this->exp[$exp].' '.$this->parseValue($val[1]);
                    // 模糊查找
                } elseif (preg_match('/^(notlike|like)$/', $exp)) {
                    if (is_array($val[1])) {
                        $likeLogic = isset($val[2]) ? strtoupper($val[2]) : 'OR';
                        if (in_array($likeLogic, ['AND', 'OR', 'XOR'])) {
                            $like = [];
                            foreach ($val[1] as $item) {
                                $like[] = $key.' '.$this->exp[$exp].' '.$this->parseValue($item);
                            }
                            $whereStr .= '('.implode(' '.$likeLogic.' ', $like).')';
                        }
                    } else {
                        $whereStr .= $key.' '.$this->exp[$exp].' '.$this->parseValue($val[1]);
                    }
                    // 使用表达式
                } elseif ('bind' == $exp) {
                    $whereStr .= $key.' = :'.$val[1];
                    // 使用表达式
                } elseif ('exp' == $exp) {
                    $whereStr .= $key.' '.$val[1];
                    // IN 运算
                } elseif (preg_match('/^(notin|not in|in)$/', $exp)) {
                    if (isset($val[2]) && 'exp' == $val[2]) {
                        $whereStr .= $key.' '.$this->exp[$exp].' '.$val[1];
                    } else {
                        if (is_string($val[1])) {
                            $val[1] = explode(',', $val[1]);
                        }
                        $zone = implode(',', $this->parseValue($val[1]));
                        $whereStr .= $key.' '.$this->exp[$exp].' ('.$zone.')';
                    }
                    // BETWEEN运算
                } elseif (preg_match('/^(notbetween|not between|between)$/', $exp)) {
                    $data = is_string($val[1]) ? explode(',', $val[1]) : $val[1];
                    $whereStr .= $key.' '.$this->exp[$exp].' '.$this->parseValue(
                            $data[0]
                        ).' AND '.$this->parseValue($data[1]);
                } else {
                    throw new BaseException(L('_EXPRESS_ERROR_').':'.$val[0]);
                }
            } else {
                $count = count($val);
                $rule = isset($val[$count - 1]) ? (is_array($val[$count - 1]) ? strtoupper(
                    $val[$count - 1][0]
                ) : strtoupper($val[$count - 1])) : '';
                if (in_array($rule, ['AND', 'OR', 'XOR'])) {
                    $count = $count - 1;
                } else {
                    $rule = 'AND';
                }
                for ($i = 0; $i < $count; $i++) {
                    $data = is_array($val[$i]) ? $val[$i][1] : $val[$i];
                    if ('exp' == strtolower($val[$i][0])) {
                        $whereStr .= $key.' '.$data.' '.$rule.' ';
                    } else {
                        $whereStr .= $this->parseWhereItem($key, $val[$i]).' '.$rule.' ';
                    }
                }
                $whereStr = '( '.substr($whereStr, 0, -4).' )';
            }
        } else {
            //对字符串类型字段采用模糊匹配
            $likeFields = $this->config['db_like_fields'];
            if ($likeFields && preg_match('/^('.$likeFields.')$/i', $key)) {
                $whereStr .= $key.' LIKE '.$this->parseValue('%'.$val.'%');
            } else {
                $whereStr .= $key.' = '.$this->parseValue($val);
            }
        }

        return $whereStr;
    }
where子单元解析

@param $key
@param $val
@return string
@throws BaseException