acl.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace WY\app\controller\derpay;
  3. use WY\app\libs\Controller;
  4. if (!defined('WY_ROOT')) {
  5. exit;
  6. }
  7. class acl extends CheckAdmin
  8. {
  9. public function index()
  10. {
  11. $data = array('title' => '接入网关');
  12. $acpcode = $this->req->get('acpcode');
  13. $acwid = $this->req->get('acwid');
  14. $gateway = $this->req->get('gateway');
  15. $cons = '';
  16. $consArr = array();
  17. if ($acpcode) {
  18. $cons .= $cons ? ' and ' : '';
  19. $cons .= 'a.acpcode=?';
  20. $consArr[] = $acpcode;
  21. }
  22. if ($acwid) {
  23. $cons .= $cons ? ' and ' : '';
  24. $cons .= 'a.acwid=?';
  25. $consArr[] = $acwid;
  26. }
  27. if ($gateway) {
  28. $cons .= $cons ? ' and ' : '';
  29. $cons .= 'a.gateway=?';
  30. $consArr[] = $gateway;
  31. }
  32. $acw = $this->model()->select()->from('acw')->fetchAll();
  33. $acp = $this->model()->select()->from('acp')->fetchAll();
  34. $page = $this->req->get('p');
  35. $page = $page ? $page : 1;
  36. $pagesize = 20;
  37. $lists = array();
  38. $where = array('fields' => $cons, 'values' => $consArr);
  39. $totalsize = $this->model()->select()->from('acl a')->where($where)->count();
  40. if ($totalsize) {
  41. $totalpage = ceil($totalsize / $pagesize);
  42. $page = $page > $totalpage ? $totalpage : $page;
  43. $offset = ($page - 1) * $pagesize;
  44. $lists = $this->model()->select('a.*,b.name')->left('acw b')->on('a.acwid=b.id')->join()->limit($pagesize)->offset($offset)->from('acl a')->where($where)->orderby('id desc')->fetchAll();
  45. }
  46. $pagelist = $this->page->put(array('page' => $page, 'pagesize' => $pagesize, 'totalsize' => $totalsize, 'url' => '?acpcode=' . $acpcode . '&acwid=' . $acwid . '&gateway=' . $gateway . '&p='));
  47. $data += array('lists' => $lists, 'acw' => $acw, 'acp' => $acp, 'search' => array('acpcode' => $acpcode, 'acwid' => $acwid, 'gateway' => $gateway), 'pagelist' => $pagelist);
  48. $this->put('acl.php', $data);
  49. }
  50. public function save()
  51. {
  52. $acpcode = $this->req->post('acpcode');
  53. $acwid = $this->req->post('acwid');
  54. $gateway = $this->req->post('gateway');
  55. if ($acpcode == '' || $acwid == '' || $gateway == '') {
  56. echo json_encode(array('status' => 0, 'msg' => '选项填写不完整'));
  57. exit;
  58. }
  59. if ($this->model()->select()->from('acl')->where(array('fields' => 'acpcode=? and gateway=?', 'values' => array($acpcode, $gateway)))->count()) {
  60. echo json_encode(array('status' => 0, 'msg' => '此接入商下的网关已存在'));
  61. exit;
  62. }
  63. $data = array('acpcode' => $acpcode, 'acwid' => $acwid, 'gateway' => $gateway);
  64. if ($this->model()->from('acl')->insertData($data)->insert()) {
  65. echo json_encode(array('status' => 1, 'msg' => '设置保存成功', 'url' => $this->dir . 'acl'));
  66. exit;
  67. }
  68. echo json_encode(array('status' => 0, 'msg' => '设置保存失败'));
  69. exit;
  70. }
  71. public function edit()
  72. {
  73. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  74. $acw = $this->model()->select()->from('acw')->fetchAll();
  75. $acp = $this->model()->select()->from('acp')->fetchAll();
  76. $acl = $this->model()->select()->from('acl')->where(array('fields' => 'id=?', 'values' => array($id)))->fetchRow();
  77. $data = array('title' => '编辑接入网关', 'data' => $acl, 'acw' => $acw, 'acp' => $acp);
  78. $this->put('acledit.php', $data);
  79. }
  80. public function editsave()
  81. {
  82. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  83. $acpcode = $this->req->post('acpcode');
  84. $acwid = $this->req->post('acwid');
  85. $gateway = $this->req->post('gateway');
  86. if ($acpcode == '' || $acwid == '' || $gateway == '') {
  87. echo json_encode(array('status' => 0, 'msg' => '选项填写不完整'));
  88. exit;
  89. }
  90. $data = array('acpcode' => $acpcode, 'acwid' => $acwid, 'gateway' => $gateway);
  91. if ($this->model()->from('acl')->updateSet($data)->where(array('fields' => 'id=?', 'values' => array($id)))->update()) {
  92. echo json_encode(array('status' => 1, 'msg' => '设置保存成功', 'url' => $this->dir . 'acl'));
  93. exit;
  94. }
  95. echo json_encode(array('status' => 0, 'msg' => '设置保存失败'));
  96. exit;
  97. }
  98. public function del()
  99. {
  100. $id = $this->req->get('id');
  101. if ($id) {
  102. if ($this->model()->from('acl')->where(array('fields' => 'id=?', 'values' => array($id)))->delete()) {
  103. echo json_encode(array('status' => 1));
  104. exit;
  105. }
  106. }
  107. echo json_encode(array('status' => 0));
  108. exit;
  109. }
  110. }