|
@@ -250,6 +250,7 @@ final class EasyORM {
|
|
|
$this->_easyORM->exclude = array();
|
|
|
$this->_easyORM->orderBy = array();
|
|
|
$this->_easyORM->queryFields = '*';
|
|
|
+ $this->_easyORM->groupBy = array();
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
@@ -266,6 +267,7 @@ final class EasyORM {
|
|
|
$this->cleanExcluded();
|
|
|
$this->cleanQueryFields();
|
|
|
$this->cleanOrderBy();
|
|
|
+ $this->cleanGroupBy();
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
@@ -466,10 +468,17 @@ final class EasyORM {
|
|
|
foreach ($value as $key => $val) {
|
|
|
$query[$key] = $val;
|
|
|
}
|
|
|
- $result = $this->_easyORM->db->fields(' count(1) as count')->limit(1)
|
|
|
+ $countFields = ' COUNT(1) as count';
|
|
|
+ if($this->_easyORM->queryFields != "*") {
|
|
|
+ $countFields = $this->_easyORM->queryFields;
|
|
|
+ }
|
|
|
+ $result = $this->_easyORM->db
|
|
|
+ ->fields($countFields)
|
|
|
+ ->limit(1)
|
|
|
->where($query)
|
|
|
->like($this->_easyORM->like)
|
|
|
->exclude($this->_easyORM->exclude)
|
|
|
+ ->groupBy($this->_easyORM->groupBy)
|
|
|
->selectOne($this->_easyORM->rules->getTable());
|
|
|
if ($this->_easyORM->db->isError()) {
|
|
|
return $this->_easyORM->db->getResponse();
|
|
@@ -597,6 +606,7 @@ final class EasyORM {
|
|
|
->where($fieldsAndValues)
|
|
|
->like($this->_easyORM->like)
|
|
|
->exclude($this->_easyORM->exclude)
|
|
|
+ ->groupBy($this->_easyORM->groupBy)
|
|
|
->orderBy($this->_easyORM->orderBy)
|
|
|
->selectRows($this->getTable());
|
|
|
if ($this->_easyORM->db->isError()) {
|
|
@@ -627,8 +637,30 @@ final class EasyORM {
|
|
|
*
|
|
|
* @return EasyORM
|
|
|
*/
|
|
|
- public function cleanOrderBy() {
|
|
|
- $this->_easyORM->orderBy = [];
|
|
|
+ final public function cleanOrderBy() {
|
|
|
+ $this->_easyORM->orderBy = array();
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置group by 条件
|
|
|
+ * @param $groupBy
|
|
|
+ * @return $this
|
|
|
+ */
|
|
|
+ final public function setGroupBy($groupBy = array()) {
|
|
|
+ if(!$groupBy) {
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+ $this->_easyORM->groupBy = $groupBy;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 清除 gorup 条件
|
|
|
+ * @return $this
|
|
|
+ */
|
|
|
+ public function cleanGroupBy() {
|
|
|
+ $this->_easyORM->groupBy = array();
|
|
|
return $this;
|
|
|
}
|
|
|
/**
|