|
1
|
|
|
<?php |
|
2
|
|
|
// +---------------------------------------------------------------------- |
|
3
|
|
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ] |
|
4
|
|
|
// +---------------------------------------------------------------------- |
|
5
|
|
|
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved. |
|
6
|
|
|
// +---------------------------------------------------------------------- |
|
7
|
|
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) |
|
8
|
|
|
// +---------------------------------------------------------------------- |
|
9
|
|
|
// | Author: liu21st <[email protected]> |
|
10
|
|
|
// +---------------------------------------------------------------------- |
|
11
|
|
|
declare (strict_types = 1); |
|
12
|
|
|
|
|
13
|
|
|
namespace think\db\concern; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* 聚合查询 |
|
17
|
|
|
*/ |
|
18
|
|
|
trait AggregateQuery |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* 聚合查询 |
|
22
|
|
|
* @access protected |
|
23
|
|
|
* @param string $aggregate 聚合方法 |
|
24
|
|
|
* @param string|Raw $field 字段名 |
|
|
|
|
|
|
25
|
|
|
* @param bool $force 强制转为数字类型 |
|
26
|
|
|
* @return mixed |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function aggregate(string $aggregate, $field, bool $force = false) |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->connection->aggregate($this, $aggregate, $field, $force); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* COUNT查询 |
|
35
|
|
|
* @access public |
|
36
|
|
|
* @param string|Raw $field 字段名 |
|
37
|
|
|
* @return int |
|
38
|
|
|
*/ |
|
39
|
|
|
public function count(string $field = '*'): int |
|
40
|
|
|
{ |
|
41
|
|
|
if (!empty($this->options['group'])) { |
|
42
|
|
|
// 支持GROUP |
|
43
|
|
|
$options = $this->getOptions(); |
|
|
|
|
|
|
44
|
|
|
$subSql = $this->options($options) |
|
|
|
|
|
|
45
|
|
|
->field('count(' . $field . ') AS think_count') |
|
46
|
|
|
->bind($this->bind) |
|
47
|
|
|
->buildSql(); |
|
48
|
|
|
|
|
49
|
|
|
$query = $this->newQuery()->table([$subSql => '_group_count_']); |
|
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
$count = $query->aggregate('COUNT', '*'); |
|
52
|
|
|
} else { |
|
53
|
|
|
$count = $this->aggregate('COUNT', $field); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return (int) $count; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* SUM查询 |
|
61
|
|
|
* @access public |
|
62
|
|
|
* @param string|Raw $field 字段名 |
|
63
|
|
|
* @return float |
|
64
|
|
|
*/ |
|
65
|
|
|
public function sum($field): float |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->aggregate('SUM', $field, true); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* MIN查询 |
|
72
|
|
|
* @access public |
|
73
|
|
|
* @param string|Raw $field 字段名 |
|
74
|
|
|
* @param bool $force 强制转为数字类型 |
|
75
|
|
|
* @return mixed |
|
76
|
|
|
*/ |
|
77
|
|
|
public function min($field, bool $force = true) |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->aggregate('MIN', $field, $force); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* MAX查询 |
|
84
|
|
|
* @access public |
|
85
|
|
|
* @param string|Raw $field 字段名 |
|
86
|
|
|
* @param bool $force 强制转为数字类型 |
|
87
|
|
|
* @return mixed |
|
88
|
|
|
*/ |
|
89
|
|
|
public function max($field, bool $force = true) |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->aggregate('MAX', $field, $force); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* AVG查询 |
|
96
|
|
|
* @access public |
|
97
|
|
|
* @param string|Raw $field 字段名 |
|
98
|
|
|
* @return float |
|
99
|
|
|
*/ |
|
100
|
|
|
public function avg($field): float |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->aggregate('AVG', $field, true); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths