quguofeng il y a 1 an
Parent
commit
897a9b610a
1 fichiers modifiés avec 14 ajouts et 29 suppressions
  1. 14 29
      application/api/controller/Login.php

+ 14 - 29
application/api/controller/Login.php

@@ -47,50 +47,35 @@ class Login extends Base
                     );
                     Db::name('department')->insert($data);
                 }
+                //获取子部门信息
+                $dept_id_list = $this->get_son_department($value->dept_id);
+                var_dump($dept_id_list);exit();
             }
         }
     }
     //获取子部门列表
-    public function get_son_department(){
+    public function get_son_department($parent_id){
         $c = $this->get_obj()['obj'];
         $req = new \OapiV2DepartmentListsubRequest;
-        $req->setDeptId("537635111");
+        $req->setDeptId($parent_id);
         $resp = $c->execute($req, $this->get_obj()['access_token'], "https://oapi.dingtalk.com/topapi/v2/department/listsubid");
+        $dept_id_list = array();
         if(isset($resp->result) && $resp->result){
-            var_dump($resp->result);exit();
-            foreach ($resp->result as $value){
-                $id = Db::name('department')->where('dept_id',$value->dept_id)->value('id');
-                if(empty($id)){
-                    $data = array(
-                        'dept_id' => $value->dept_id,
-                        'name' => $value->name,
-                        'parent_id' => $value->parent_id,
-                    );
-                    Db::name('department')->insert($data);
-                }
-            }
+            $resp->result->dept_id_list;
         }
+        return $dept_id_list;
     }
-    //获取部门详情
-    public function get_department_detail(){
+    //获取部门名称
+    public function get_department_name($dept_id){
         $c = $this->get_obj()['obj'];
         $req = new \OapiV2DepartmentListsubRequest;
-        $req->setDeptId("891114410");
+        $req->setDeptId($dept_id);
         $resp = $c->execute($req, $this->get_obj()['access_token'], "https://oapi.dingtalk.com/topapi/v2/department/get");
+        $name = '';
         if(isset($resp->result) && $resp->result){
-            var_dump($resp->result);exit();
-            foreach ($resp->result as $value){
-                $id = Db::name('department')->where('dept_id',$value->dept_id)->value('id');
-                if(empty($id)){
-                    $data = array(
-                        'dept_id' => $value->dept_id,
-                        'name' => $value->name,
-                        'parent_id' => $value->parent_id,
-                    );
-                    Db::name('department')->insert($data);
-                }
-            }
+            $name = $resp->result->name;
         }
+        return $name;
     }
     //获取部门用户详情
     public function get_user_list(){