DepartmentController.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * 企业号部门管理控制器
  4. * @author zhouxcuchen 2015-11-30
  5. */
  6. class DepartmentController extends AdminController {
  7. /**
  8. * 后台管理部门列表首页
  9. */
  10. public function actionIndex() {
  11. }
  12. /**
  13. * 后台Ajax请求获取部门列表
  14. */
  15. public function actionGetDepartmentList() {
  16. $option = WechatConfig::getIns()->getLinkOption();
  17. $secret = WechatConfig::getIns()->getSecret('admin_dev');
  18. $wechat = new QyWechat($option);
  19. if ($wechat->checkAuth($option['appid'], $secret)) {
  20. $result = $wechat->getDepartment();
  21. if ($result['errmsg'] == 'ok') {
  22. $department = $result['department'];
  23. $departmentList = array();
  24. foreach ($department as $key => $row) {
  25. $departmentList[$row['id']] = array(
  26. 'name' => $row['name'],
  27. 'id' => $row['id'],
  28. 'parentid' => $row['parentid'],
  29. );
  30. }
  31. $data = array(
  32. 'code' => 0,
  33. 'msg' => 'success',
  34. 'content' => $departmentList
  35. );
  36. } else {
  37. $data = array(
  38. 'code' => 1,
  39. 'msg' => $result['errmsg'],
  40. 'content' => array(),
  41. );
  42. }
  43. } else {
  44. $data = array(
  45. 'code' => 1,
  46. 'msg' => '微信验证失败',
  47. 'content' => array(),
  48. );
  49. }
  50. echo json_encode($data);
  51. }
  52. }