|
@@ -259,6 +259,14 @@ class Base {
|
|
public function getWhereHooker() {
|
|
public function getWhereHooker() {
|
|
$where = $this->properties();
|
|
$where = $this->properties();
|
|
if(!isset($this->hooker['where']) || !is_array($this->hooker['where'])) {
|
|
if(!isset($this->hooker['where']) || !is_array($this->hooker['where'])) {
|
|
|
|
+ if($this->alias != "" && is_array($where)) {
|
|
|
|
+ foreach ($where as $key => $value) {
|
|
|
|
+ if(!preg_match("/^[a-zA-Z_]\./", $key)) {
|
|
|
|
+ $where[$this->alias . '.' . $key] = $value;
|
|
|
|
+ unset($where[$key]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return $where;
|
|
return $where;
|
|
}
|
|
}
|
|
// 遍历
|
|
// 遍历
|
|
@@ -266,10 +274,29 @@ class Base {
|
|
if(is_callable($item['func'])) {
|
|
if(is_callable($item['func'])) {
|
|
$subWhere = call_user_func($item['func'], $where, $item['args']);
|
|
$subWhere = call_user_func($item['func'], $where, $item['args']);
|
|
foreach ($subWhere as $key => $value) {
|
|
foreach ($subWhere as $key => $value) {
|
|
|
|
+ if(is_array($value)) {
|
|
|
|
+ foreach ($value as $k => $v) {
|
|
|
|
+ if($this->alias != "") {
|
|
|
|
+ if(!preg_match("/^[a-zA-Z_]\./", $k)) {
|
|
|
|
+ $where[$this->alias . '.' . $k] = $v;
|
|
|
|
+ unset($where[$k]);
|
|
|
|
+ }else{
|
|
|
|
+ $where[$k] = $v;
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ $where[$key] = $v;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ unset($subWhere[$key]);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
if($this->alias != "") {
|
|
if($this->alias != "") {
|
|
- if(!preg_match("/{$this->alias}\.{$key}/", $key)) {
|
|
|
|
|
|
+ if(!preg_match("/^[a-zA-Z_]\./", $key)) {
|
|
$where[$this->alias . '.' . $key] = $value;
|
|
$where[$this->alias . '.' . $key] = $value;
|
|
unset($subWhere[$key]);
|
|
unset($subWhere[$key]);
|
|
|
|
+ unset($where[$key]);
|
|
|
|
+ }else{
|
|
|
|
+ $where[$key] = $value;
|
|
}
|
|
}
|
|
}else{
|
|
}else{
|
|
$where[$key] = $value;
|
|
$where[$key] = $value;
|
|
@@ -281,7 +308,7 @@ class Base {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * join 条件
|
|
|
|
|
|
+ * join 条件 [table, on, join type]
|
|
* @param mixed $join 条件
|
|
* @param mixed $join 条件
|
|
* @param mixed $args 参数
|
|
* @param mixed $args 参数
|
|
* @return $this
|
|
* @return $this
|
|
@@ -977,7 +1004,19 @@ class Base {
|
|
*/
|
|
*/
|
|
public function info() {
|
|
public function info() {
|
|
try{
|
|
try{
|
|
|
|
+ $limit = $this->getLimitHooker();
|
|
|
|
+ $page = null;
|
|
|
|
+ $pageSize = null;
|
|
|
|
+ if(count($limit) > 0) {
|
|
|
|
+ $page = $limit[0];
|
|
|
|
+ $pageSize = isset($limit[1]) ? $limit[1] : null;
|
|
|
|
+ }
|
|
$query = $this->createQuery();
|
|
$query = $this->createQuery();
|
|
|
|
+ $query = $query->groupBy($this->getGroupBy());
|
|
|
|
+ $query = $query->orderBy($this->getOrderBy());
|
|
|
|
+ if($page !== null) {
|
|
|
|
+ $query = $query->limit($page, $pageSize);
|
|
|
|
+ }
|
|
$info = $query->selectRow($this->prepareTable());
|
|
$info = $query->selectRow($this->prepareTable());
|
|
$this->calledSQL = $query->executeSQL;
|
|
$this->calledSQL = $query->executeSQL;
|
|
if($info) $this->withRow($info);
|
|
if($info) $this->withRow($info);
|
|
@@ -1453,10 +1492,35 @@ class Base {
|
|
}
|
|
}
|
|
$join = $this->getJoinHooker();
|
|
$join = $this->getJoinHooker();
|
|
foreach ($join as $j) {
|
|
foreach ($join as $j) {
|
|
- $query = $query->join($j);
|
|
|
|
|
|
+ if(count($j) != count($j, 1)) {
|
|
|
|
+ foreach ($j as $v) {
|
|
|
|
+ $v = $this->formatJoin($v);
|
|
|
|
+ $query = $query->join($v[0], $v[1], $v[2]);
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ $j = $this->formatJoin($j);
|
|
|
|
+ $query = $query->join($j[0], $j[1], $j[2]);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return $query;
|
|
return $query;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 格式化 join 参数
|
|
|
|
+ * @param $v
|
|
|
|
+ * @return array
|
|
|
|
+ * @throws InvalidParams
|
|
|
|
+ */
|
|
|
|
+ protected function formatJoin($v){
|
|
|
|
+ if(!is_array($v) || count($v) < 2) {
|
|
|
|
+ throw new InvalidParams('jon 参数不正确 [table, on, join type]');
|
|
|
|
+ }
|
|
|
|
+ if(count($v) < 3) {
|
|
|
|
+ $v[2] = null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $v;
|
|
|
|
+ }
|
|
/**
|
|
/**
|
|
* 获取第一条数据
|
|
* 获取第一条数据
|
|
*
|
|
*
|
|
@@ -1692,6 +1756,10 @@ class Base {
|
|
if(count($this->getFields()) > 0 && !in_array($relKey, $this->getFields())) {
|
|
if(count($this->getFields()) > 0 && !in_array($relKey, $this->getFields())) {
|
|
$fields[] = $relKey;
|
|
$fields[] = $relKey;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if(array_search('*', $fields) !== false) {
|
|
|
|
+ $fields = ['*'];
|
|
|
|
+ }
|
|
$fields = array_unique($fields);
|
|
$fields = array_unique($fields);
|
|
$query = $this->createQuery($fields);
|
|
$query = $this->createQuery($fields);
|
|
$res = $query->where($args[1])->rs($this->prepareTable());
|
|
$res = $query->where($args[1])->rs($this->prepareTable());
|