人人商城

user.ctrl.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. load()->model('module');
  8. load()->model('system');
  9. $dos = array('delete', 'edit', 'set_permission', 'set_manager', 'module');
  10. $do = in_array($do, $dos) ? $do : 'edit';
  11. $uniacid = intval($_GPC['uniacid']);
  12. $acid = intval($_GPC['acid']);
  13. $_W['page']['title'] = '管理设置 - 微信' . ACCOUNT_TYPE_NAME . '管理';
  14. if (empty($uniacid) || empty($acid)) {
  15. itoast('请选择要编辑的公众号', referer(), 'error');
  16. }
  17. $state = permission_account_user_role($_W['uid'], $uniacid);
  18. $role_permission = in_array($state, array(ACCOUNT_MANAGE_NAME_FOUNDER, ACCOUNT_MANAGE_NAME_OWNER, ACCOUNT_MANAGE_NAME_VICE_FOUNDER));
  19. if (!$role_permission) {
  20. itoast('无权限操作!', referer(), 'error');
  21. }
  22. $founders = explode(',', $_W['config']['setting']['founder']);
  23. $headimgsrc = tomedia('headimg_'.$acid.'.jpg');
  24. $account = account_fetch($acid);
  25. if (is_error($account)) {
  26. itoast($account['message']);
  27. }
  28. if ($do == 'edit') {
  29. $permissions = 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');
  30. $owner = pdo_get('uni_account_users', array('uniacid' => $uniacid, 'role' => 'owner'), array('uid', 'id'));
  31. if (!empty($permissions)) {
  32. $member = pdo_fetchall("SELECT username, uid FROM ".tablename('users')." WHERE uid IN (".implode(',', array_keys($permissions)).")", array(), 'uid');
  33. if (!empty($member)) {
  34. foreach ($permissions as $key => $per_val) {
  35. $permissions[$key]['isfounder'] = in_array($member[$key]['uid'], $founders) ? 1 : 0;
  36. $permissions[$key]['username'] = $member[$key]['username'] ? $member[$key]['username'] : '';
  37. }
  38. }
  39. }
  40. $uids = array();
  41. foreach ($permissions as $v) {
  42. $uids[] = $v['uid'];
  43. }
  44. template('account/manage-users');
  45. } elseif ($do == 'delete') {
  46. $uid = is_array($_GPC['uid']) ? 0 : intval($_GPC['uid']);
  47. if (empty($uid)) {
  48. itoast('请选择要删除的用户!', referer(), 'error');
  49. }
  50. $data = array(
  51. 'uniacid' => $uniacid,
  52. 'uid' => $uid,
  53. );
  54. $exists = pdo_get('uni_account_users', array('uniacid' => $uniacid, 'uid' => $uid));
  55. if (!empty($exists)) {
  56. if ($state == ACCOUNT_MANAGE_NAME_MANAGER && ($exists['role'] == ACCOUNT_MANAGE_NAME_OWNER || $exists['role'] == ACCOUNT_MANAGE_NAME_MANAGER)) {
  57. itoast('管理员不可操作其他管理员', referer(), 'error');
  58. }
  59. $result = pdo_delete('uni_account_users', $data);
  60. if ($result) {
  61. itoast('删除成功!', referer(), 'success');
  62. } else {
  63. itoast('删除失败,请重试!', referer(), 'error');
  64. }
  65. } else {
  66. itoast('该公众号下不存在该用户!', referer(), 'error');
  67. }
  68. } elseif ($do == 'set_manager') {
  69. $username = trim($_GPC['username']);
  70. $user = user_single(array('username' => $username));
  71. if (!empty($user)) {
  72. if ($user['status'] != 2) {
  73. iajax(3, '用户未通过审核或不存在!', '');
  74. }
  75. if (in_array($user['uid'], $founders)) {
  76. iajax(1, '不可操作网站创始人!', '');
  77. }
  78. $addtype = intval($_GPC['addtype']);
  79. if (is_error($permission = permission_create_account($user['uid'], ACCOUNT_TYPE)) && $addtype == ACCOUNT_MANAGE_TYPE_OWNER) {
  80. itoast(error(5, $permission['message']), '', 'error');
  81. }
  82. $data = array(
  83. 'uniacid' => $uniacid,
  84. 'uid' => $user['uid'],
  85. );
  86. $exists = pdo_get('uni_account_users', $data);
  87. $owner = pdo_get('uni_account_users', array('uniacid' => $uniacid, 'role' => 'owner'));
  88. if (empty($exists)) {
  89. if ($addtype == ACCOUNT_MANAGE_TYPE_VICE_FOUNDER) {
  90. if ($user['founder_groupid'] != ACCOUNT_MANAGE_GROUP_VICE_FOUNDER) {
  91. iajax(6, '副创始人不存在!', '');
  92. }
  93. pdo_delete('uni_account_users', array('uniacid' => $uniacid, 'role' => ACCOUNT_MANAGE_NAME_VICE_FOUNDER));
  94. $data['role'] = ACCOUNT_MANAGE_NAME_VICE_FOUNDER;
  95. } else if ($addtype == ACCOUNT_MANAGE_TYPE_OWNER) {
  96. if ($state == ACCOUNT_MANAGE_NAME_MANAGER) {
  97. iajax(4, '管理员不可操作主管理员', '');
  98. }
  99. if (empty($owner)) {
  100. $data['role'] = ACCOUNT_MANAGE_NAME_OWNER;
  101. } else {
  102. $result = pdo_update('uni_account_users', $data, array('id' => $owner['id']));
  103. if ($result) {
  104. pdo_delete('users_permission', array('uniacid' => $uniacid, 'uid' => $user['uid']));
  105. iajax(0, '修改成功!', '');
  106. } else {
  107. iajax(1, '修改失败!', '');
  108. }
  109. exit;
  110. }
  111. } else if ($addtype == ACCOUNT_MANAGE_TYPE_MANAGER) {
  112. if ($state == ACCOUNT_MANAGE_NAME_MANAGER) {
  113. iajax(4, '管理员不可操作管理员', '');
  114. }
  115. $data['role'] = ACCOUNT_MANAGE_NAME_MANAGER;
  116. } else {
  117. $data['role'] = ACCOUNT_MANAGE_NAME_OPERATOR;
  118. }
  119. pdo_delete('uni_account_users', array('uniacid' => $uniacid,'uid' => $user['uid']));
  120. $result = pdo_insert('uni_account_users', $data);
  121. if ($result) {
  122. if ($addtype == ACCOUNT_MANAGE_TYPE_OWNER) {
  123. pdo_delete('users_permission', array('uniacid' => $uniacid, 'uid' => $user['uid']));
  124. }
  125. iajax(0, '添加成功!', '');
  126. } else {
  127. iajax(1, '添加失败!', '');
  128. }
  129. } else {
  130. iajax(2, $username.'已经是该公众号的店员或操作员或管理员,请勿重复添加!', '');
  131. }
  132. } else {
  133. iajax(-1, '参数错误,请刷新重试!', '');
  134. }
  135. } elseif ($do == 'set_permission') {
  136. $uid = intval($_GPC['uid']);
  137. $user = user_single(array('uid' => $uid));
  138. if (empty($user)) {
  139. itoast('您操作的用户不存在或是已经被删除!', '', '');
  140. }
  141. $role = permission_account_user_role($_W['uid'], $uniacid);
  142. if (empty($role)) {
  143. itoast('此用户没有操作该统一公众号的权限,请选指派“管理员”或是“操作员”权限!', '', '');
  144. }
  145. if ($account['type'] == ACCOUNT_TYPE_OFFCIAL_NORMAL || $account['type'] == ACCOUNT_TYPE_OFFCIAL_AUTH) {
  146. $user_menu_permission_account = permission_account_user_menu($uid, $uniacid, PERMISSION_ACCOUNT);
  147. $module_permission = permission_account_user_menu($uid, $uniacid, 'modules');
  148. if (is_error($user_menu_permission_account) || is_error($module_permission)) {
  149. itoast('参数错误!');
  150. }
  151. $module_permission_keys = array_keys($module_permission);
  152. $module = uni_modules_by_uniacid($uniacid);
  153. } elseif ($account['type'] == ACCOUNT_TYPE_APP_NORMAL) {
  154. $user_menu_permission_wxapp = permission_account_user_menu($uid, $uniacid, PERMISSION_WXAPP);
  155. if (is_error($user_menu_permission_wxapp)) {
  156. itoast('参数错误!');
  157. }
  158. }
  159. $menus = system_menu_permission_list($role);
  160. if (checksubmit('submit')) {
  161. $all_menu_permission = permission_menu_name();
  162. $user_menu_permission_new = array();
  163. if ($account['type'] == ACCOUNT_TYPE_OFFCIAL_NORMAL || $account['type'] == ACCOUNT_TYPE_OFFCIAL_AUTH) {
  164. if (!empty($_GPC['system'])) {
  165. foreach ($_GPC['system'] as $permission_name) {
  166. if (in_array($permission_name, $all_menu_permission)) {
  167. $user_menu_permission_new[] = $permission_name;
  168. }
  169. }
  170. $data = array(
  171. 'type' => PERMISSION_ACCOUNT,
  172. 'permission' => implode('|', $user_menu_permission_new)
  173. );
  174. $result = permission_update_account_user($uid, $uniacid, $data);
  175. if (is_error($result)) {
  176. itoast($result['message']);
  177. }
  178. } else {
  179. pdo_delete('users_permission', array('uniacid' => $uniacid, 'uid' => $uid, 'type' => PERMISSION_ACCOUNT));
  180. }
  181. pdo_query("DELETE FROM " . tablename('users_permission') . " WHERE uniacid = :uniacid AND uid = :uid AND type != '" . PERMISSION_ACCOUNT . "' AND type != '" . PERMISSION_WXAPP . "'", array(':uniacid' => $uniacid, ':uid' => $uid));
  182. if(!empty($_GPC['module'])) {
  183. foreach($_GPC['module'] as $module_val) {
  184. $insert = array(
  185. 'uniacid' => $uniacid,
  186. 'uid' => $uid,
  187. 'type' => $module_val,
  188. );
  189. if(empty($_GPC['module_'. $module_val]) || $_GPC[$module_val . '_select'] == 1) {
  190. $insert['permission'] = 'all';
  191. pdo_insert('users_permission', $insert);
  192. continue;
  193. } else {
  194. $data = array();
  195. foreach($_GPC['module_'. $module_val] as $v) {
  196. $data[] = $v;
  197. }
  198. if(!empty($data)) {
  199. $insert['permission'] = implode('|', $data);
  200. pdo_insert('users_permission', $insert);
  201. }
  202. }
  203. }
  204. }
  205. } elseif ($account['type'] == ACCOUNT_TYPE_APP_NORMAL) {
  206. if (!empty($_GPC['wxapp'])) {
  207. foreach ($_GPC['wxapp'] as $permission_name) {
  208. if (in_array($permission_name, $all_menu_permission)) {
  209. $user_menu_permission_new[] = $permission_name;
  210. }
  211. }
  212. $data = array(
  213. 'type' => PERMISSION_WXAPP,
  214. 'permission' => implode('|', $user_menu_permission_new)
  215. );
  216. $result = permission_update_account_user($uid, $uniacid, $data);
  217. if (is_error($result)) {
  218. itoast($result['message']);
  219. }
  220. } else {
  221. pdo_delete('users_permission', array('uniacid' => $uniacid, 'uid' => $uid, 'type' => PERMISSION_WXAPP));
  222. }
  223. }
  224. $cachekey = cache_system_key("permission:{$uniacid}:{$uid}");
  225. cache_delete($cachekey);
  226. itoast('操作菜单权限成功!', referer(), 'success');
  227. }
  228. template('account/set-permission');
  229. } elseif($do == 'module' && $_W['isajax']) {
  230. $uid = intval($_GPC['uid']);
  231. $user = user_single($uid);
  232. if(empty($user)) {
  233. iajax(1, '访问错误, 未找到指定操作用户.', '');
  234. }
  235. $founders = explode(',', $_W['config']['setting']['founder']);
  236. $isfounder = in_array($user['uid'], $founders);
  237. if($isfounder) {
  238. iajax(2, '访问错误, 无法编辑站长.', '');
  239. }
  240. $module_name = trim($_GPC['m']);
  241. $uniacid = intval($_GPC['uniacid']);
  242. $uid = intval($_GPC['uid']);
  243. $module = pdo_fetch('SELECT * FROM ' . tablename('modules') . ' WHERE name = :m', array(':m' => $module_name));
  244. $purview = pdo_fetch('SELECT * FROM ' . tablename('users_permission') . ' WHERE uniacid = :aid AND uid = :uid AND type = :type', array(':aid' => $uniacid, ':uid' => $uid, ':type' => $module_name));
  245. if(!empty($purview['permission'])) {
  246. $purview['permission'] = explode('|', $purview['permission']);
  247. } else {
  248. $purview['permission'] = array();
  249. }
  250. $mineurl = array();
  251. $all = 0;
  252. if(!empty($mods)) {
  253. foreach($mods as $mod) {
  254. if($mod['url'] == 'all') {
  255. $all = 1;
  256. break;
  257. } else {
  258. $mineurl[] = $mod['url'];
  259. }
  260. }
  261. }
  262. $data = array();
  263. if($module['settings']) {
  264. $data[] = array('title' => '参数设置', 'permission' => $module_name.'_settings');
  265. }
  266. if($module['isrulefields']) {
  267. $data[] = array('title' => '回复规则列表', 'permission' => $module_name.'_rule');
  268. }
  269. $entries = module_entries($module_name);
  270. if(!empty($entries['home'])) {
  271. $data[] = array('title' => '微站首页导航', 'permission' => $module_name.'_home');
  272. }
  273. if(!empty($entries['profile'])) {
  274. $data[] = array('title' => '个人中心导航', 'permission' => $module_name.'_profile');
  275. }
  276. if(!empty($entries['shortcut'])) {
  277. $data[] = array('title' => '快捷菜单', 'permission' => $module_name.'_shortcut');
  278. }
  279. if(!empty($entries['cover'])) {
  280. foreach($entries['cover'] as $cover) {
  281. $data[] = array('title' => $cover['title'], 'permission' => $module_name.'_cover_'.$cover['do']);
  282. }
  283. }
  284. if(!empty($entries['menu'])) {
  285. foreach($entries['menu'] as $menu) {
  286. $data[] = array('title' => $menu['title'], 'permission' => $module_name.'_menu_'.$menu['do']);
  287. }
  288. }
  289. unset($entries);
  290. if(!empty($module['permissions'])) {
  291. $module['permissions'] = (array)iunserializer($module['permissions']);
  292. $data = array_merge($data, $module['permissions']);
  293. }
  294. foreach($data as &$data_val) {
  295. $data_val['checked'] = 0;
  296. if(in_array($data_val['permission'], $purview['permission']) || in_array('all', $purview['permission'])) {
  297. $data_val['checked'] = 1;
  298. }
  299. }
  300. unset($data_val);
  301. if (empty($data)) {
  302. iajax(3, '无子权限!', '');
  303. } else {
  304. iajax(0, $data, '');
  305. }
  306. }