12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php namespace App\Servers\WechatWork;
- use Illuminate\Support\Carbon;
- /**
- * 通讯录 成员管理
- *
- */
- class User extends Work
- {
- /**
- * 获取列表
- *
- * @param int $departId 指定部门ID
- * @param bool $fetchChild 递归获取子部门下面的成员
- *
- */
- public function getList($departId,$fetchChild=false){
- try {
- // 获取部门列表
- $result = $this->work->user->getDetailedDepartmentUsers($departId,$fetchChild);
- // 返回列表
- if( $result['errcode'] == 0 ) return $result['userlist'];// [["userid"=>"zhangsan", "name"=>"张三", "open_userid"=>"","department"=>[1,2]]];
- // 如果请求失败,返回空数据
- return [];
- } catch (\Throwable $th) {
- return [];
- }
- }
- /**
- * 获取所有部门的成员列表
- *
- */
- public function getListDepart(){
- try {
- // 获取缓存数据
- $departList = cache('work:department:user:list',[]);
- // 有数据的返回
- if( $departList ) return $departList;
- // 获取部门数据
- $departList = $this->work->department->list();
- // 返回列表
- $departList = $departList['errcode'] == 0 ? $departList['department'] : [];
- // 循环部门
- foreach ($departList as $key => $value) {
- // 获取每个部门的成员
- $value['user_list'] = $this->getList($value['id']);
- // 重组
- $departList[$key] = $value;
- }
- // 时间处理
- cache(['work:department:user:list'=>$departList],Carbon::now()->addMinutes(30));
- // 返回结果
- return $departList;
- } catch (\Throwable $th) {
- return [];
- }
- }
- /**
- * 获取成员详情
- *
- * @param string $userid 成员ID
- *
- */
- public function getOne($userid){
- // 获取部门列表
- $result = $this->work->user->get($userid);
- // 返回列表
- if( $result['errcode'] == 0 ) return $result['department'];// ["userid"=>"zhangsan", "name"=>"张三", "open_userid"=>"","department"=>[1,2]]
- // 如果请求失败,返回空数据
- return [];
- }
- }
|