Department.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php namespace App\Servers\WechatWork;
  2. /**
  3. * 通讯录 部门管理
  4. *
  5. */
  6. class Department extends Work
  7. {
  8. /**
  9. * 获取列表
  10. *
  11. * @param int|null $id 获取指定部门及其下的子部门,默认获取全量组织架构
  12. *
  13. */
  14. public function getList($id=null){
  15. // 获取部门列表
  16. $result = $this->work->department->list($id);
  17. // 返回列表
  18. if( $result['errcode'] == 0 ) return $result['department'];// [["id"=>2, "name"=>"研发部", "parentid"=>1, "order"=>100000000,"department_leader"=>["Evan","LiuLiJun"]]];
  19. // 如果请求失败,返回空数据
  20. return [];
  21. }
  22. /**
  23. * 获取部门详情
  24. *
  25. * @param int $id 部门ID
  26. *
  27. */
  28. public function getOne($id){
  29. // 获取部门列表
  30. $result = $this->work->department->get($id);
  31. // 返回列表
  32. if( $result['errcode'] == 0 ) return $result['department'];// ["id"=>2, "name"=>"研发部", "parentid"=>1, "order"=>100000000,"department_leader"=>["Evan","LiuLiJun"]]
  33. // 如果请求失败,返回空数据
  34. return [];
  35. }
  36. /**
  37. * 添加
  38. *
  39. * @param array $data 部门信息
  40. * name 部门名称 *
  41. * parentid 上级ID *
  42. * order order值大的排序靠前。有效的值范围是[0, 2^32)
  43. */
  44. public function add($data){
  45. // 获取部门列表
  46. $result = $this->work->department->create($data); // ["errcode"=>0,"errmsg=>"created","id"=>2]
  47. // 返回列表
  48. if( $result['errcode'] == 0 ) return $result['id'];
  49. // 如果请求失败,返回空数据
  50. return 0;
  51. }
  52. /**
  53. * 修改
  54. *
  55. * @param int $id 部门ID
  56. * @param array $data 部门信息
  57. * name 部门名称 *
  58. * parentid 上级ID *
  59. * order order值大的排序靠前。有效的值范围是[0, 2^32)
  60. *
  61. */
  62. public function edit($id,$data){
  63. // 获取部门列表
  64. $result = $this->work->department->update($id,$data); // ["errcode"=>0,"errmsg=>"updated"]
  65. // 返回列表
  66. if( $result['errcode'] == 0 ) return $id;
  67. // 如果请求失败,返回空数据
  68. return 0;
  69. }
  70. /**
  71. * 删除
  72. *
  73. * @param int $id 部门ID
  74. *
  75. */
  76. public function del($id){
  77. // 获取部门列表
  78. $result = $this->work->department->delete($id); // ["errcode"=>0,"errmsg=>"deleted"]
  79. // 返回列表
  80. if( $result['errcode'] == 0 ) return $id;
  81. // 如果请求失败,返回空数据
  82. return 0;
  83. }
  84. }