人人商城

permission.ctrl.php 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. $do = $_GPC['do'];
  8. $dos = array('deny', 'delete', 'auth', 'revo', 'revos', 'select', 'role', 'user');
  9. $do = in_array($do, $dos) ? $do: 'edit';
  10. $uniacid = intval($_GPC['uniacid']);
  11. $state = uni_permission($_W['uid'], $uniacid);
  12. if($state != 'founder' && $state != 'manager') {
  13. message('没有该公众号操作权限!', url('accound/display'), 'error');
  14. }
  15. if($do == 'edit') {
  16. $_W['page']['title'] = '账号操作员列表';
  17. $account = pdo_fetch("SELECT * FROM ".tablename('uni_account')." WHERE uniacid = :uniacid", array(':uniacid' => $uniacid));
  18. if (empty($account)) {
  19. message('抱歉,您操作的公众号不存在或是已经被删除!');
  20. }
  21. $permission = pdo_fetchall("SELECT id, uid, role FROM ".tablename('uni_account_users')." WHERE uniacid = '$uniacid' and role != :role ORDER BY uid ASC, role DESC", array(':role' => 'clerk'), 'uid');
  22. if (!empty($permission)) {
  23. $member = pdo_fetchall("SELECT username, uid FROM ".tablename('users')." WHERE uid IN (".implode(',', array_keys($permission)).")", array(), 'uid');
  24. }
  25. $uids = array();
  26. foreach ($permission as $v) {
  27. $uids[] = $v['uid'];
  28. }
  29. $founders = explode(',', $_W['config']['setting']['founder']);
  30. template('account/permission');
  31. }
  32. if ($do == 'auth') {
  33. if(!$_W['isfounder']) {
  34. exit('您没有进行该操作的权限');
  35. }
  36. $uids = $_GPC['uid'];
  37. if(empty($uids) || !is_array($uids) || empty($uniacid)) {
  38. exit('error');
  39. }
  40. foreach($uids as $v) {
  41. $tmpuid = intval($v);
  42. $data = array(
  43. 'uniacid' => $uniacid,
  44. 'uid' => $tmpuid,
  45. );
  46. $exists = pdo_fetch("SELECT * FROM ".tablename('uni_account_users')." WHERE uid = :uid AND uniacid = :uniacid", array(':uniacid' => $uniacid, ':uid' => $tmpuid));
  47. if(empty($exists)) {
  48. $data['role'] = 'operator';
  49. pdo_insert('uni_account_users', $data);
  50. }
  51. }
  52. exit('success');
  53. }
  54. if ($do == 'revo') {
  55. $uid = intval($_GPC['uid']);
  56. if(empty($uid) || empty($uniacid)) {
  57. exit('error');
  58. }
  59. $data = array(
  60. 'uniacid' => $uniacid,
  61. 'uid' => $uid,
  62. );
  63. $exists = pdo_fetch("SELECT * FROM ".tablename('uni_account_users')." WHERE uid = :uid AND uniacid = :uniacid", array(':uniacid' => $uniacid, ':uid' => $uid));
  64. if(!empty($exists)) {
  65. pdo_delete('uni_account_users', $data);
  66. }
  67. exit('success');
  68. }
  69. if ($do == 'revos') {
  70. $ids = $_GPC['ids'];
  71. $ms = array();
  72. foreach($ids as $v) {
  73. $id = intval($v);
  74. if($id) {
  75. array_push($ms, $id);
  76. }
  77. }
  78. if(!empty($ms)){
  79. $sql = 'DELETE FROM ' . tablename('uni_account_users') . " WHERE `id` IN (".implode(',', $ms).")";
  80. pdo_query($sql);
  81. }
  82. exit('success');
  83. }
  84. if ($do == 'select') {
  85. $condition = '';
  86. $params = array();
  87. if(!empty($_GPC['keyword'])) {
  88. $condition = '`username` LIKE :username';
  89. $params[':username'] = "%{$_GPC['keyword']}%";
  90. }
  91. $pindex = max(1, intval($_GPC['page']));
  92. $psize = 10;
  93. $total = 0;
  94. $list = pdo_fetchall("SELECT * FROM ".tablename('users')." WHERE status = '0' ".(!empty($_W['config']['setting']['founder']) ? " AND uid NOT IN ({$_W['config']['setting']['founder']})" : '')." LIMIT ".(($pindex - 1) * $psize).",{$psize}");
  95. $total = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('users')." WHERE status = '0' ".(!empty($_W['config']['setting']['founder']) ? " AND uid NOT IN ({$_W['config']['setting']['founder']})" : '')."");
  96. $pager = pagination($total, $pindex, $psize, '', array('ajaxcallback'=>'null'));
  97. $permission = pdo_fetchall("SELECT uid FROM ".tablename('uni_account_users')." WHERE uniacid = '$uniacid'", array(), 'uid');
  98. template('account/select');
  99. exit;
  100. }
  101. if ($do == 'role') {
  102. $uid = intval($_GPC['uid']);
  103. $uniacid = intval($_GPC['uniacid']);
  104. $role = !empty($_GPC['role']) && in_array($_GPC['role'], array('operator', 'manager')) ? $_GPC['role'] : 'operator';
  105. $state = pdo_update('uni_account_users', array('role' => $role), array('uid' => $uid, 'uniacid' => $uniacid));
  106. if($state === false) exit('error'); else exit('success');
  107. }
  108. if($do == 'user') {
  109. load()->model('user');
  110. $post = array();
  111. $post['username'] = trim($_GPC['username']);
  112. $user = user_single($post);
  113. if(!empty($user)) {
  114. $data = array(
  115. 'uniacid' => $uniacid,
  116. 'uid' => $user['uid'],
  117. );
  118. $exists = pdo_fetch("SELECT * FROM ".tablename('uni_account_users')." WHERE uid = :uid AND uniacid = :uniacid", array(':uniacid' => $uniacid, ':uid' => $user['uid']));
  119. if(empty($exists)) {
  120. $data['role'] = 'operator';
  121. pdo_insert('uni_account_users', $data);
  122. } else {
  123. exit("{$post['username']} 已经是该公众号的操作员或管理员,请勿重复添加");
  124. }
  125. exit('success');
  126. }
  127. exit('用户不存在或已被删除!');
  128. }