|
@@ -74,7 +74,7 @@ class Base {
|
|
*
|
|
*
|
|
* @var null
|
|
* @var null
|
|
*/
|
|
*/
|
|
- private $tableName = null;
|
|
|
|
|
|
+ protected $tableName = null;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 错误信息
|
|
* 错误信息
|
|
@@ -109,13 +109,14 @@ class Base {
|
|
* 设置表名
|
|
* 设置表名
|
|
*
|
|
*
|
|
* @param $tableName
|
|
* @param $tableName
|
|
- * @return void
|
|
|
|
|
|
+ * @return $this
|
|
*/
|
|
*/
|
|
public function setTableName($tableName) {
|
|
public function setTableName($tableName) {
|
|
if(is_callable($tableName)) {
|
|
if(is_callable($tableName)) {
|
|
$this->tableName = $tableName();
|
|
$this->tableName = $tableName();
|
|
}
|
|
}
|
|
if($tableName) $this->tableName = $tableName;
|
|
if($tableName) $this->tableName = $tableName;
|
|
|
|
+ return $this;
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
* 返回 table 的名字,以便分库分表的时候指定使用
|
|
* 返回 table 的名字,以便分库分表的时候指定使用
|
|
@@ -641,13 +642,13 @@ class Base {
|
|
*
|
|
*
|
|
* @param array|string $fields 字段名称
|
|
* @param array|string $fields 字段名称
|
|
* @param $args
|
|
* @param $args
|
|
- * @return void
|
|
|
|
- * @throws \Exception
|
|
|
|
|
|
+ * @return $this
|
|
*/
|
|
*/
|
|
final public function field($fields, $args = null) {
|
|
final public function field($fields, $args = null) {
|
|
$this->setQueryFieldsHooker(function() use($fields){
|
|
$this->setQueryFieldsHooker(function() use($fields){
|
|
return $fields;
|
|
return $fields;
|
|
}, $args);
|
|
}, $args);
|
|
|
|
+ return $this;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -866,6 +867,10 @@ class Base {
|
|
$query->groupBy($this->getGroupBy());
|
|
$query->groupBy($this->getGroupBy());
|
|
return $query->selectOne($this->prepareTable());
|
|
return $query->selectOne($this->prepareTable());
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ final public function sum($field = []){
|
|
|
|
+
|
|
|
|
+ }
|
|
/**
|
|
/**
|
|
* 检查是否有对应的属性
|
|
* 检查是否有对应的属性
|
|
*
|
|
*
|
|
@@ -1664,6 +1669,21 @@ class Base {
|
|
$this->withList($lists);
|
|
$this->withList($lists);
|
|
return $lists;
|
|
return $lists;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取一行
|
|
|
|
+ *
|
|
|
|
+ * @return array|bool
|
|
|
|
+ * @throws \Exception
|
|
|
|
+ */
|
|
|
|
+ final public function row(){
|
|
|
|
+ $query = $this->createQuery();
|
|
|
|
+ $query = $query->groupBy($this->getGroupBy());
|
|
|
|
+ $query = $query->orderBy($this->getOrderBy());
|
|
|
|
+ $row = $query->selectRow($this->prepareTable());
|
|
|
|
+ $this->withRow($row);
|
|
|
|
+ return $row;
|
|
|
|
+ }
|
|
/**
|
|
/**
|
|
* listts
|
|
* listts
|
|
* @param int $page 页码
|
|
* @param int $page 页码
|