@@ -104,20 +104,22 @@ function makeToken(string $username, string $pwd , string $ip): string
104
104
* @param string $pid_field 父级字段名
105
105
* @param string $search_field 过滤字段名
106
106
* @param string $order_field 排序字段名
107
+ * @param int $total 总条数
107
108
* @return array
108
109
*/
109
- function getTreeList ($ model , int $ pid , string $ keywords , string $ pid_field = 'pid ' , string $ search_field = 'title ' , string $ order_field = 'sort_num ' ): array
110
+ function getTreeList ($ model , int $ pid , string $ keywords , string $ pid_field = 'pid ' , string $ search_field = 'title ' , string $ order_field = 'sort_num ' , int & $ total = 0 ): array
110
111
{
111
112
$ query = $ model ->where ($ pid_field , $ pid );
112
113
!empty ($ keywords ) && $ query ->whereLike ($ search_field , '% ' .$ keywords .'% ' );
113
114
!empty ($ order_field ) && $ query ->order ($ order_field );
114
115
$ res = $ query ->select ()->toArray ();
116
+ $ total += count ($ res );
115
117
foreach ($ res as &$ val ){
116
- $ child = getTreeList ($ model ,$ val ['id ' ], $ keywords , $ pid_field , $ search_field , $ order_field );
118
+ $ child = getTreeList ($ model , $ val ['id ' ], $ keywords , $ pid_field , $ search_field , $ order_field, $ total );
117
119
$ val [$ pid_field ] == 0 && $ val [$ pid_field ] = '' ;
118
- !empty ($ child ) && $ val ['children ' ] = $ child ;
120
+ !empty ($ child[ ' data ' ] ) && $ val ['children ' ] = $ child[ ' data ' ] ;
119
121
}
120
- return $ res ;
122
+ return [ ' data ' => $ res, ' total ' => $ total ] ;
121
123
}
122
124
123
125
@@ -191,4 +193,3 @@ function getTreeIdPath(string &$id_path, $model, int $pid = 0, string $pid_field
191
193
192
194
return $ id_path ;
193
195
}
194
-
0 commit comments