mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-05 22:52:49 +08:00
改进Query类的聚合查询
This commit is contained in:
@@ -373,9 +373,10 @@ class Query
|
|||||||
* @access public
|
* @access public
|
||||||
* @param string $field 字段名
|
* @param string $field 字段名
|
||||||
* @param mixed $default 默认值
|
* @param mixed $default 默认值
|
||||||
|
* @param bool $force 强制转为数字类型
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function value($field, $default = null)
|
public function value($field, $default = null, $force = false)
|
||||||
{
|
{
|
||||||
$result = false;
|
$result = false;
|
||||||
if (empty($options['fetch_sql']) && !empty($this->options['cache'])) {
|
if (empty($options['fetch_sql']) && !empty($this->options['cache'])) {
|
||||||
@@ -397,6 +398,9 @@ class Query
|
|||||||
return $pdo;
|
return $pdo;
|
||||||
}
|
}
|
||||||
$result = $pdo->fetchColumn();
|
$result = $pdo->fetchColumn();
|
||||||
|
if ($force) {
|
||||||
|
$result = is_numeric($result) ? $result + 0 : $result;
|
||||||
|
}
|
||||||
if (isset($cache)) {
|
if (isset($cache)) {
|
||||||
// 缓存数据
|
// 缓存数据
|
||||||
if (isset($cache['tag'])) {
|
if (isset($cache['tag'])) {
|
||||||
@@ -489,8 +493,7 @@ class Query
|
|||||||
*/
|
*/
|
||||||
public function count($field = '*')
|
public function count($field = '*')
|
||||||
{
|
{
|
||||||
$value = $this->value('COUNT(' . $field . ') AS tp_count', 0);
|
return $this->value('COUNT(' . $field . ') AS tp_count', 0, true);
|
||||||
return is_numeric($value) ? (int) $value : $value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -501,8 +504,7 @@ class Query
|
|||||||
*/
|
*/
|
||||||
public function sum($field = '*')
|
public function sum($field = '*')
|
||||||
{
|
{
|
||||||
$value = $this->value('SUM(' . $field . ') AS tp_sum', 0);
|
return $this->value('SUM(' . $field . ') AS tp_sum', 0, true);
|
||||||
return is_numeric($value) ? $value + 0 : $value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -513,8 +515,7 @@ class Query
|
|||||||
*/
|
*/
|
||||||
public function min($field = '*')
|
public function min($field = '*')
|
||||||
{
|
{
|
||||||
$value = $this->value('MIN(' . $field . ') AS tp_min', 0);
|
return $this->value('MIN(' . $field . ') AS tp_min', 0, true);
|
||||||
return is_numeric($value) ? $value + 0 : $value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -525,8 +526,7 @@ class Query
|
|||||||
*/
|
*/
|
||||||
public function max($field = '*')
|
public function max($field = '*')
|
||||||
{
|
{
|
||||||
$value = $this->value('MAX(' . $field . ') AS tp_max', 0);
|
return $this->value('MAX(' . $field . ') AS tp_max', 0, true);
|
||||||
return is_numeric($value) ? $value + 0 : $value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -537,8 +537,7 @@ class Query
|
|||||||
*/
|
*/
|
||||||
public function avg($field = '*')
|
public function avg($field = '*')
|
||||||
{
|
{
|
||||||
$value = $this->value('AVG(' . $field . ') AS tp_avg', 0);
|
return $this->value('AVG(' . $field . ') AS tp_avg', 0, true);
|
||||||
return is_numeric($value) ? $value + 0 : $value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user