wangsaitao 10 meses atrás
pai
commit
8a5a46eff3
1 arquivos alterados com 24 adições e 12 exclusões
  1. 24 12
      application/api/controller/screen/User.php

+ 24 - 12
application/api/controller/screen/User.php

@@ -74,19 +74,31 @@ class User extends Index
     }
 
     public function userDep(){
-        $depList = Db::name('dep')->where('enable',1)->where('org_id',$this->orgId)->where('del',0)->limit(6)->order('id desc')->select();
+       // $depList = Db::name('dep')->where('enable',1)->where('org_id',$this->orgId)->where('del',0)->limit(6)->order('id desc')->select();
         $data = [];
-        foreach ($depList as $v){
-            $data[] = [
-                'name' => $v['title'],
-                'value' => Db::name('user_dep')
-                    ->alias('ud')
-                    ->join('user u','u.id=ud.user_id')
-                    ->where('ud.dep_id',$v['id'])
-                    ->where('u.del',0)
-                    ->count(),
-            ];
-        }
+        $data =  Db::name('user_dep')
+            ->alias('ud')
+            ->join('user u','u.id=ud.user_id')
+            ->join('dep dp','ud.dep_id=dp.id')
+            ->where('u.del',0)
+            ->field('count(ud.user_id) as value,dp.title as name')
+            ->group('ud.dep_id')
+            ->order('value','desc')
+            ->limit(6)
+            ->select();
+
+//        foreach ($depList as $v){
+//            $data[] = [
+//                'name' => $v['title'],
+//                'value' => Db::name('user_dep')
+//                    ->alias('ud')
+//                    ->join('user u','u.id=ud.user_id')
+//                    ->where('ud.dep_id',$v['id'])
+//                    ->where('u.del',0)
+//                    ->count(),
+//            ];
+//        }
+
         HelpHander::success($data);
 
     }