Group2depart.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\admin\controller\csmadmin;
  3. use addons\csmadmin\library\CsmBackend;
  4. use addons\csmadmin\library\CsmUtils;
  5. use addons\csmadmin\library\CsmadminUtils;
  6. /**
  7. * 角色组授权部门
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Group2depart extends CsmBackend
  12. {
  13. /**
  14. * Group2depart模型对象
  15. * @var \app\admin\model\csmadmin\Group2depart
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\csmadmin\Group2depart;
  22. }
  23. public function index()
  24. {
  25. // 当前页面必须从活动页面跳转过来
  26. $parentid = $this->csmreq("parentid", true);
  27. $parent = $this->csmGetDbRowByReqest(new \app\admin\model\AuthGroup(), "parentid");
  28. $this->assign('parent', $parent);
  29. // 设置过滤方法
  30. $this->request->filter([
  31. 'strip_tags'
  32. ]);
  33. if ($this->request->isAjax()) {
  34. // 如果发送的来源是Selectpage,则转发到Selectpage
  35. if ($this->request->request('keyField')) {
  36. return $this->selectpage();
  37. }
  38. list ($where, $sort, $order, $offset, $limit) = $this->buildparams();
  39. $total = $this->model->where($where)
  40. ->where("auth_group_id", "=", $parentid)
  41. ->order($sort, $order)
  42. ->count();
  43. $list = $this->model->where($where)
  44. ->where("auth_group_id", "=", $parentid)
  45. ->order($sort, $order)
  46. ->limit($offset, $limit)
  47. ->select();
  48. CsmUtils::convertListColumn($list, "auth_group_id", new \app\admin\model\AuthGroup(),'name');
  49. $ids = [];
  50. foreach($list as $item){
  51. $ids[] = $item['csmadmin_depart_id'];
  52. }
  53. $ll = CsmadminUtils::getDepartWithParentname($ids);
  54. foreach($list as &$item){
  55. if(isset($ll['ID#'.$item->csmadmin_depart_id])){
  56. $item['departname'] = $ll['ID#'.$item->csmadmin_depart_id];
  57. }
  58. }
  59. $list = collection($list)->toArray();
  60. $result = array(
  61. "total" => $total,
  62. "rows" => $list
  63. );
  64. return json($result);
  65. }
  66. return $this->view->fetch();
  67. }
  68. }