人人商城

post-user.ctrl.php 13KB

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