permission.mod.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  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. function permission_build() {
  8. global $_W, $acl;
  9. load()->model('system');
  10. $we7_file_permission = $acl;
  11. $permission_frames = system_menu();
  12. if (!in_array($_W['role'], array(ACCOUNT_MANAGE_NAME_OPERATOR, ACCOUNT_MANAGE_NAME_MANAGER)) || empty($_W['uniacid'])) {
  13. return $we7_file_permission;
  14. }
  15. $cachekey = cache_system_key('permission', array('uniacid' => $_W['uniacid'], 'uid' => $_W['uid']));
  16. $cache = cache_load($cachekey);
  17. if (!empty($cache)) {
  18. return $cache;
  19. }
  20. $permission_exist = permission_account_user_permission_exist($_W['uid'], $_W['uniacid']);
  21. if (empty($permission_exist)) {
  22. cache_write($cachekey, $we7_file_permission);
  23. return $we7_file_permission;
  24. }
  25. $user_account_permission = permission_account_user_menu($_W['uid'], $_W['uniacid'], PERMISSION_ACCOUNT);
  26. $user_wxapp_permission = permission_account_user_menu($_W['uid'], $_W['uniacid'], PERMISSION_WXAPP);
  27. $account_info = uni_fetch($_W['uniacid']);
  28. $user_other_permission = permission_account_user_menu($_W['uid'], $_W['uniacid'], $account_info->typeSign);
  29. $user_permission = array_merge($user_account_permission, $user_wxapp_permission, $user_other_permission);
  30. $permission_contain = array('account', 'wxapp', 'system', 'phoneapp');
  31. $section = array();
  32. $permission_result = array();
  33. foreach ($permission_frames as $key => $frames) {
  34. if (!in_array($key, $permission_contain) || empty($frames['section'])) {
  35. continue;
  36. }
  37. foreach ($frames['section'] as $frame_key => $frame) {
  38. if (empty($frame['menu'])) {
  39. continue;
  40. }
  41. $section[$key][$frame_key] = $frame['menu'];
  42. }
  43. }
  44. $account = permission_get_nameandurl($section[$permission_contain[0]]);
  45. $wxapp = permission_get_nameandurl($section[$permission_contain[1]]);
  46. $system = permission_get_nameandurl($section[$permission_contain[2]]);
  47. $permission_result = array_merge($account, $wxapp, $system);
  48. foreach ($permission_result as $permission_val) {
  49. if (in_array($permission_val['permission_name'], $user_permission)) {
  50. $we7_file_permission[$permission_val['controller']][$_W['role']][] = $permission_val['action'];
  51. }
  52. }
  53. cache_write($cachekey, $we7_file_permission);
  54. return $we7_file_permission;
  55. }
  56. function permission_get_nameandurl($permission) {
  57. $result = array();
  58. if (empty($permission)) {
  59. return $result;
  60. }
  61. foreach ($permission as $menu) {
  62. if (empty($menu)) {
  63. continue;
  64. }
  65. foreach ($menu as $permission_name) {
  66. $url_query_array = url_params($permission_name['url']);
  67. $result[] = array(
  68. 'url' => $permission_name['url'],
  69. 'controller' => $url_query_array['c'],
  70. 'action' => $url_query_array['a'],
  71. 'permission_name' => $permission_name['permission_name']
  72. );
  73. if (!empty($permission_name['sub_permission'])) {
  74. foreach ($permission_name['sub_permission'] as $key => $sub_permission_name) {
  75. $sub_url_query_array = url_params($sub_permission_name['url']);
  76. $result[] = array(
  77. 'url' => $sub_permission_name['url'],
  78. 'controller' => $sub_url_query_array['c'],
  79. 'action' => $sub_url_query_array['a'],
  80. 'permission_name' => $sub_permission_name['permission_name'],
  81. );
  82. }
  83. }
  84. }
  85. }
  86. return $result;
  87. }
  88. function permission_account_user_role($uid = 0, $uniacid = 0) {
  89. global $_W;
  90. load()->model('user');
  91. $role = '';
  92. $uid = empty($uid) ? $_W['uid'] : intval($uid);
  93. if (user_is_founder($uid, true)) {
  94. return ACCOUNT_MANAGE_NAME_FOUNDER;
  95. } else {
  96. $user_info = pdo_get('users', array('uid' => $uid));
  97. if (!empty($user_info['endtime']) && $user_info['endtime'] != USER_ENDTIME_GROUP_EMPTY_TYPE && $user_info['endtime'] != USER_ENDTIME_GROUP_UNLIMIT_TYPE && $user_info['endtime'] < TIMESTAMP) {
  98. return ACCOUNT_MANAGE_NAME_EXPIRED;
  99. }
  100. if (user_is_vice_founder($uid)) {
  101. return ACCOUNT_MANAGE_NAME_VICE_FOUNDER;
  102. }
  103. if (!user_is_bind()) {
  104. return ACCOUNT_MANAGE_NAME_UNBIND_USER;
  105. }
  106. if ($user_info['type'] == ACCOUNT_OPERATE_CLERK) {
  107. return ACCOUNT_MANAGE_NAME_CLERK;
  108. }
  109. }
  110. if (!empty($uniacid)) {
  111. $role = table('uni_account_users')->getUserRoleByUniacid($uid, $uniacid);
  112. if ($role == ACCOUNT_MANAGE_NAME_OWNER) {
  113. $role = ACCOUNT_MANAGE_NAME_OWNER;
  114. } elseif ($role == ACCOUNT_MANAGE_NAME_VICE_FOUNDER) {
  115. $role = ACCOUNT_MANAGE_NAME_VICE_FOUNDER;
  116. } elseif ($role == ACCOUNT_MANAGE_NAME_MANAGER) {
  117. $role = ACCOUNT_MANAGE_NAME_MANAGER;
  118. } elseif ($role == ACCOUNT_MANAGE_NAME_OPERATOR) {
  119. $role = ACCOUNT_MANAGE_NAME_OPERATOR;
  120. } elseif ($role == ACCOUNT_MANAGE_NAME_CLERK) {
  121. $role = ACCOUNT_MANAGE_NAME_CLERK;
  122. }
  123. return $role;
  124. } else {
  125. $roles = table('uni_account_users')->getAllUserRole($uid);
  126. $roles = array_keys($roles);
  127. if (in_array(ACCOUNT_MANAGE_NAME_VICE_FOUNDER, $roles)) {
  128. $role = ACCOUNT_MANAGE_NAME_VICE_FOUNDER;
  129. } elseif (in_array(ACCOUNT_MANAGE_NAME_OWNER, $roles)) {
  130. $role = ACCOUNT_MANAGE_NAME_OWNER;
  131. } elseif (in_array(ACCOUNT_MANAGE_NAME_MANAGER, $roles)) {
  132. $role = ACCOUNT_MANAGE_NAME_MANAGER;
  133. } elseif (in_array(ACCOUNT_MANAGE_NAME_OPERATOR, $roles)) {
  134. $role = ACCOUNT_MANAGE_NAME_OPERATOR;
  135. }
  136. }
  137. $role = empty($role) ? ACCOUNT_MANAGE_NAME_OPERATOR : $role;
  138. return $role;
  139. }
  140. function permission_account_user_permission_exist($uid = 0, $uniacid = 0) {
  141. global $_W;
  142. load()->model('user');
  143. $uid = intval($uid) > 0 ? $uid : $_W['uid'];
  144. $uniacid = intval($uniacid) > 0 ? $uniacid : $_W['uniacid'];
  145. if (user_is_founder($uid)) {
  146. return false;
  147. }
  148. if (defined('FRAME') && FRAME == 'system') {
  149. return true;
  150. }
  151. $is_exist = table('users_permission')->getUserPermissionByType($uid, $uniacid);
  152. if(empty($is_exist)) {
  153. return false;
  154. } else {
  155. return true;
  156. }
  157. }
  158. function permission_account_user($type = 'system') {
  159. global $_W;
  160. $user_permission = table('users_permission')->getUserPermissionByType($_W['uid'], $_W['uniacid'], $type);
  161. $user_permission = $user_permission['permission'];
  162. if (empty($user_permission)) {
  163. $user_permission = array('account*', 'wxapp*', 'phoneapp*');
  164. }
  165. $permission_append = frames_menu_append();
  166. if (!empty($permission_append[$_W['role']])) {
  167. $user_permission = array_merge($user_permission, $permission_append[$_W['role']]);
  168. }
  169. if (empty($_W['role']) && empty($_W['uniacid'])) {
  170. $user_permission = array_merge($user_permission, $permission_append['operator']);
  171. }
  172. return (array)$user_permission;
  173. }
  174. function permission_account_user_menu($uid, $uniacid, $type) {
  175. $user_menu_permission = array();
  176. $uid = intval($uid);
  177. $uniacid = intval($uniacid);
  178. $type = trim($type);
  179. if (empty($uid) || empty($uniacid) || empty($type)) {
  180. return error(-1, '参数错误!');
  181. }
  182. $permission_exist = permission_account_user_permission_exist($uid, $uniacid);
  183. if (empty($permission_exist)) {
  184. return array('all');
  185. }
  186. $user_permission_table = table('users_permission');
  187. if ($type == 'modules') {
  188. $user_menu_permission = $user_permission_table->getAllUserModulePermission($uid, $uniacid);
  189. if ($user_menu_permission['modules'] && $user_menu_permission['modules']['permission'] == 'all') {
  190. return array('all');
  191. }
  192. } else {
  193. $module = uni_modules_by_uniacid($uniacid);
  194. $module = array_keys($module);
  195. if (in_array($type, $module) || in_array($type, array(PERMISSION_ACCOUNT, PERMISSION_WXAPP, PERMISSION_WEBAPP, PERMISSION_PHONEAPP, PERMISSION_XZAPP, PERMISSION_ALIAPP, PERMISSION_BAIDUAPP, PERMISSION_TOUTIAOAPP, PERMISSION_SYSTEM))) {
  196. $menu_permission = $user_permission_table->getUserPermissionByType($uid, $uniacid, $type);
  197. $user_menu_permission = !empty($menu_permission['permission']) ? $menu_permission['permission'] : array();
  198. }
  199. }
  200. return $user_menu_permission;
  201. }
  202. function permission_menu_name() {
  203. load()->model('system');
  204. $menu_permission = array();
  205. $menu_list = system_menu_permission_list();
  206. $middle_menu = array();
  207. $middle_sub_menu = array();
  208. if (!empty($menu_list)) {
  209. foreach ($menu_list as $nav_id => $section) {
  210. foreach ($section['section'] as $section_id => $section) {
  211. if (!empty($section['menu'])) {
  212. $middle_menu[] = $section['menu'];
  213. }
  214. }
  215. }
  216. }
  217. if (!empty($middle_menu)) {
  218. foreach ($middle_menu as $menu) {
  219. foreach ($menu as $menu_val) {
  220. $menu_permission[] = $menu_val['permission_name'];
  221. if (!empty($menu_val['sub_permission'])) {
  222. $middle_sub_menu[] = $menu_val['sub_permission'];
  223. }
  224. }
  225. }
  226. }
  227. if (!empty($middle_sub_menu)) {
  228. foreach ($middle_sub_menu as $sub_menu) {
  229. foreach ($sub_menu as $sub_menu_val) {
  230. $menu_permission[] = $sub_menu_val['permission_name'];
  231. }
  232. }
  233. }
  234. return $menu_permission;
  235. }
  236. function permission_update_account_user($uid, $uniacid, $data) {
  237. $uid = intval($uid);
  238. $uniacid = intval($uniacid);
  239. if (empty($uid) || empty($uniacid) || !in_array($data['type'], array(PERMISSION_ACCOUNT, PERMISSION_WXAPP, PERMISSION_WEBAPP, PERMISSION_PHONEAPP, PERMISSION_XZAPP, PERMISSION_ALIAPP, PERMISSION_BAIDUAPP, PERMISSION_TOUTIAOAPP, PERMISSION_SYSTEM))) {
  240. return error('-1', '参数错误!');
  241. }
  242. $user_menu_permission = permission_account_user_menu($uid, $uniacid, $data['type']);
  243. if (is_error($user_menu_permission)) {
  244. return error('-1', '参数错误!');
  245. }
  246. $permission = table('users_permission')->getUserPermissionByType($uid, $uniacid, $data['type']);
  247. if (empty($permission)) {
  248. $result = table('users_permission')->fill(array(
  249. 'uniacid' => $uniacid,
  250. 'uid' => $uid,
  251. 'type' => $data['type'],
  252. 'permission' => $data['permission'],
  253. ))->save();
  254. } else {
  255. $result = table('users_permission')->fill(array('permission' => $data['permission']))->whereId($permission['id'])->save();
  256. }
  257. return $result;
  258. }
  259. function permission_check_account_user($permission_name, $show_message = true, $action = '') {
  260. global $_W, $_GPC, $acl;
  261. load()->model('module');
  262. $see_more_info = $acl['see_more_info'];
  263. if (strpos($permission_name, 'see_') === 0) {
  264. $can_see_more = false;
  265. if (in_array(FRAME, array('system', 'site', 'account_manage', 'myself'))) {
  266. $can_see_more = in_array($permission_name, $see_more_info[$_W['highest_role']]) ? true : false;
  267. } else {
  268. if (is_array($see_more_info[$_W['role']]) && !empty($see_more_info[$_W['role']])) {
  269. $can_see_more = in_array($permission_name, $see_more_info[$_W['role']]) ? true : false;
  270. }
  271. }
  272. return $can_see_more;
  273. }
  274. $user_has_permission = permission_account_user_permission_exist();
  275. if (empty($user_has_permission)) {
  276. return true;
  277. }
  278. $modulename = trim($_GPC['m']);
  279. $do = trim($_GPC['do']);
  280. $entry_id = intval($_GPC['eid']);
  281. if ($action == 'reply') {
  282. $system_modules = module_system();
  283. if (!empty($modulename) && !in_array($modulename, $system_modules)) {
  284. $permission_name = $modulename . '_rule';
  285. $users_permission = permission_account_user($modulename);
  286. }
  287. } elseif ($action == 'cover' && $entry_id > 0) {
  288. load()->model('module');
  289. $entry = module_entry($entry_id);
  290. if (!empty($entry)) {
  291. $permission_name = $entry['module'] . '_cover_' . trim($entry['do']);
  292. $users_permission = permission_account_user($entry['module']);
  293. }
  294. } elseif ($action == 'nav') {
  295. if(!empty($modulename)) {
  296. $permission_name = "{$modulename}_{$do}";
  297. $users_permission = permission_account_user($modulename);
  298. } else {
  299. return true;
  300. }
  301. } elseif ($action == 'wxapp' || !empty($_W['account']) && $_W['account']['type_sign'] == WXAPP_TYPE_SIGN) {
  302. $users_permission = permission_account_user('wxapp');
  303. } else {
  304. $users_permission = permission_account_user('system');
  305. }
  306. if (!isset($users_permission)) {
  307. $users_permission = permission_account_user('system');
  308. }
  309. if ($users_permission[0] != 'all' && !in_array($permission_name, $users_permission) && !in_array(FRAME . '*', $users_permission)) {
  310. if (in_array($permission_name, permission_first_sub_permission()) && !empty($show_message)) {
  311. load()->model('system');
  312. $permission_string = explode('_', $permission_name);
  313. $goto_permission = permission_subpermission($permission_string[0] . '_' . $permission_string[1] . '_');
  314. $system_menu = system_menu_permission_list(ACCOUNT_MANAGE_NAME_OPERATOR);
  315. $goto_url = $system_menu[FRAME]['section'][$permission_string[0]]['menu'][$permission_string[0] . '_' . $permission_string[1]]['sub_permission'][$goto_permission]['url'];
  316. itoast('', $goto_url);
  317. }
  318. if ($show_message) {
  319. itoast('您没有进行该操作的权限', referer(), 'error');
  320. } else {
  321. return false;
  322. }
  323. }
  324. return true;
  325. }
  326. function permission_first_sub_permission() {
  327. return array(
  328. 'platform_reply_keyword',
  329. 'platform_menu_default',
  330. 'platform_qr_qr',
  331. 'platform_masstask_post',
  332. 'platform_material_news',
  333. 'platform_site_multi',
  334. 'mc_fans_display',
  335. 'mc_member_diaplsy',
  336. 'profile_setting_remote',
  337. 'profile_payment_pay',
  338. 'statistics_visit_app',
  339. 'wxapp_payment_pay',
  340. );
  341. }
  342. function permission_check_module_user($permission_name) {
  343. global $_W;
  344. if (empty($_W['current_module']) || empty($permission_name)) {
  345. return false;
  346. }
  347. $users_permission = permission_account_user($_W['current_module']['name']);
  348. if (!in_array($permission_name, $users_permission)) {
  349. return false;
  350. }
  351. return true;
  352. }
  353. function permission_check_account_user_module($action = '', $module_name = '') {
  354. global $_W, $_GPC;
  355. $status = permission_account_user_permission_exist();
  356. if(empty($status)) {
  357. return true;
  358. }
  359. $a = trim($_GPC['a']);
  360. $do = trim($_GPC['do']);
  361. $m = trim($_GPC['m']);
  362. if ($a == 'manage-account' && $do == 'setting' && !empty($m)) {
  363. $permission_name = $m . '_settings';
  364. $users_permission = permission_account_user($m);
  365. if ($users_permission[0] != 'all' && !in_array($permission_name, $users_permission)) {
  366. return false;
  367. }
  368. } elseif (!empty($do) && !empty($m)) {
  369. $is_exist = table('modules_bindings')->isEntryExists($m, 'menu', $do);
  370. if(empty($is_exist)) {
  371. return true;
  372. }
  373. }
  374. if(empty($module_name)) {
  375. $module_name = IN_MODULE;
  376. }
  377. $permission = permission_account_user($module_name);
  378. if(empty($permission) || ($permission[0] != 'all' && !empty($action) && !in_array($action, $permission))) {
  379. return false;
  380. }
  381. return true;
  382. }
  383. function permission_user_account_num($uid = 0) {
  384. global $_W;
  385. $uid = intval($uid);
  386. $user = $uid > 0 ? user_single($uid) : $_W['user'];
  387. if (empty($user)) {
  388. return array();
  389. }
  390. $user_founder_info = table('users_founder_own_users')->getFounderByUid($user['uid']);
  391. $account_all_type = uni_account_type();
  392. $account_all_type_sign = array_keys(uni_account_type_sign());
  393. $extra_group_table = table('users_extra_group');
  394. $extra_limit_table = table('users_extra_limit');
  395. if (user_is_vice_founder($user['uid']) || !empty($user_founder_info['founder_uid'])) {
  396. if (!empty($user_founder_info['founder_uid'])) {
  397. $role = ACCOUNT_MANAGE_NAME_OWNER;
  398. $group = table('users_group')->getById($user['groupid']);
  399. $user_uid = $user_founder_info['founder_uid'];
  400. } else {
  401. $role = ACCOUNT_MANAGE_NAME_VICE_FOUNDER;
  402. $group = table('users_founder_group')->getById($user['groupid']);
  403. $user_uid = $user['uid'];
  404. }
  405. foreach ($account_all_type_sign as $type_info) {
  406. $key_name = $type_info . '_num';
  407. $group_num[$key_name] = 0;
  408. }
  409. $fouder_own_users_owner_account = table('account')->searchAccountList(false, 1, $fields = 'a.uniacid, b.type');
  410. $current_vice_founder_user_group_nums = 0;
  411. if (!empty($fouder_own_users_owner_account)) {
  412. foreach ($fouder_own_users_owner_account as $account) {
  413. foreach ($account_all_type as $type_key => $type_info) {
  414. if ($type_key == $account['type']) {
  415. $key_name = $type_info['type_sign'] . '_num';
  416. $group_num[$key_name] += 1;
  417. $current_vice_founder_user_group_nums += 1;
  418. continue;
  419. }
  420. }
  421. }
  422. }
  423. } else {
  424. $role = ACCOUNT_MANAGE_NAME_OWNER;
  425. $group = table('users_group')->getById($user['groupid']);
  426. $group_num = uni_owner_account_nums($user['uid'], $role);
  427. if (empty($_W['isfounder'])) {
  428. if (!empty($user['owner_uid'])) {
  429. $owner_info = table('users')->getById($user['owner_uid']);
  430. $group_vice = table('users_founder_group')->getById($owner_info['groupid']);
  431. $founder_group_num = uni_owner_account_nums($owner_info['uid'], ACCOUNT_MANAGE_NAME_VICE_FOUNDER);
  432. foreach ($account_all_type_sign as $sign) {
  433. $maxsign = 'max' . $sign;
  434. $group[$maxsign] = min(intval($group[$maxsign]), intval($group_vice[$maxsign]));
  435. }
  436. }
  437. }
  438. }
  439. if (!empty($user_founder_info['founder_uid'])) {
  440. $owner_info = table('users')->getById($user_founder_info['founder_uid']);
  441. $group_vice = table('users_founder_group')->getById($owner_info['groupid']);
  442. $founder_group_num = uni_owner_account_nums($owner_info['uid'], ACCOUNT_MANAGE_NAME_VICE_FOUNDER);
  443. }
  444. $store_table = table('store');
  445. $create_buy_num['account'] = $store_table->searchUserCreateAccountNum($user['uid']);
  446. $create_buy_num['wxapp'] = $store_table->searchUserCreateWxappNum($user['uid']);
  447. $store_buy['account'] = $store_table->searchUserBuyAccount($user['uid']);
  448. $store_buy['wxapp'] = $store_table->searchUserBuyWxapp($user['uid']);
  449. $store_buy['account'] = $store_buy['account'] < 0 ? 0 : $store_buy['account'];
  450. $store_buy['wxapp'] = $store_buy['wxapp'] < 0 ? 0 : $store_buy['wxapp'];
  451. $extra_create_group_info = array_keys($extra_group_table->getCreateGroupsByUid($user['uid']));
  452. $extra_limits_info = $extra_limit_table->getExtraLimitByUid($user['uid']);
  453. $create_group_info_all = array();
  454. if (!empty($extra_create_group_info)) {
  455. $create_group_table = table('users_create_group');
  456. $create_groups = array();
  457. foreach($extra_create_group_info as $create_group_id) {
  458. $create_group_info = $create_group_table->getById($create_group_id);
  459. $create_groups[] = $create_group_info;
  460. foreach ($account_all_type_sign as $sign) {
  461. $maxsign = 'max' . $sign;
  462. $create_group_info_all[$maxsign] += $create_group_info[$maxsign];
  463. }
  464. }
  465. }
  466. $extra = $limit = $founder_limit = array();
  467. foreach ($account_all_type_sign as $sign) {
  468. $maxsign = 'max' . $sign;
  469. $extra[$sign] = $create_group_info_all[$maxsign] + $extra_limits_info[$maxsign];
  470. $sign_num = $sign . '_num';
  471. $limit[$sign] = max((intval($group[$maxsign]) + $extra[$sign] + intval($store_buy[$sign]) - $group_num[$sign_num]), 0);
  472. $founder_limit[$sign] = max((intval($group_vice[$maxsign]) + intval($store_buy[$sign]) - $founder_group_num[$sign_num]), 0);
  473. if (!empty($vice_founder_own_users_create_nums)) {
  474. foreach ($vice_founder_own_users_create_nums as $own_user_uid => $own_user_info) {
  475. $founder_limit[$sign] -= $own_user_info[$sign_num];
  476. }
  477. }
  478. }
  479. $data = array(
  480. 'group_name' => $group['name'],
  481. 'vice_group_name' => $group_vice['name'],
  482. 'create_groups' => $create_groups,
  483. 'store_buy_account' => $store_buy['account'],
  484. 'store_buy_wxapp' => $store_buy['wxapp'],
  485. );
  486. $data['max_total'] = 0;
  487. $data['created_total'] = 0;
  488. $data['limit_total'] = $data['store_buy_account'] + $data['store_buy_wxapp'];
  489. foreach ($account_all_type_sign as $sign) {
  490. $maxsign = 'max' . $sign;
  491. $sign_num = $sign . '_num';
  492. $data['user_group_max' . $sign] = $group[$maxsign];
  493. $data['usergroup_' . $sign . '_limit'] = max($group[$maxsign] - $group_num[$sign_num] - intval($create_buy_num[$sign]), 0);
  494. $data[$maxsign] = $group[$maxsign] + intval($store_buy[$sign]) + $extra[$sign];
  495. $data[$sign_num] = $group_num[$sign_num];
  496. $data[$sign . '_limit'] = max($limit[$sign], 0);
  497. $data['extra_' . $sign] = $extra_limits_info[$maxsign];
  498. $data['founder_' . $sign . '_limit'] = max($founder_limit[$sign], 0);
  499. $data['max_total'] = $data[$maxsign] + $data['max_total'];
  500. $data['created_total'] = $data[$sign_num] + $data['created_total'];
  501. $data['limit_total'] = $data[$sign . '_limit'] + $data['limit_total'];
  502. $data['current_vice_founder_user_created_total'] = !empty($current_vice_founder_user_group_nums) ? $current_vice_founder_user_group_nums : 0;
  503. if (!empty($vice_founder_own_users_create_nums)) {
  504. foreach ($vice_founder_own_users_create_nums as $own_user_uid => $account_num_info) {
  505. $data['vice_founder_own_users_' . $sign_num] += $account_num_info[$sign_num]; $data['vice_founder_own_users_created_total'] += $account_num_info[$sign_num]; }
  506. }
  507. }
  508. if (user_is_vice_founder()) {
  509. $data['created_total'] += intval($data['vice_founder_own_users_created_total']);
  510. $data['limit_total'] = $data['max_total'] - $data['created_total'];
  511. }
  512. ksort($data);
  513. return $data;
  514. }
  515. function permission_subpermission($prefix, $module = '') {
  516. global $_W;
  517. $result = '';
  518. if (empty($prefix)) {
  519. return $result;
  520. }
  521. $type = !empty($module) ? safe_gpc_string($module) : ($_W['account']['type_sign'] == 'account' ? 'system' : $_W['account']['type_sign']);
  522. $account_premission = table('users_permission')->getUserPermissionByType($_W['uid'], $_W['uniacid'], $type);
  523. if (!empty($account_premission['permission'])) {
  524. foreach ($account_premission['permission'] as $permission) {
  525. $if_exist = strpos($permission, $prefix);
  526. $result = $if_exist !== false ? $permission : '';
  527. if (!empty($result)) break;
  528. }
  529. }
  530. return $result;
  531. }
  532. function permission_user_account_creatable($uid = 0, $type_sign = '') {
  533. global $_W;
  534. $uid = empty($uid) ? $_W['uid'] : $uid;
  535. $type_sign = empty($type_sign) ? 'account' : $type_sign;
  536. if(user_is_founder($uid) && !user_is_vice_founder()) {
  537. return true;
  538. }
  539. $key = $type_sign . '_limit';
  540. $data = permission_user_account_num($uid);
  541. return isset($data[$key]) && $data[$key] > 0;
  542. }
  543. function permission_user_timelimits($uid = 0) {
  544. global $_W;
  545. $uid = empty($uid) ? $_W['uid'] : $uid;
  546. $user = user_single($uid);
  547. if (user_is_founder($uid) && !user_is_vice_founder()) {
  548. return 0;
  549. }
  550. if (user_is_vice_founder($uid)) {
  551. $group_info = user_founder_group_detail_info($user['groupid']);
  552. } else {
  553. $group_info = user_group_detail_info($user['groupid']);
  554. }
  555. $users_extra_limit_table = table('users_extra_limit');
  556. $extra_limit_info = $users_extra_limit_table->getExtraLimitByUid($uid);
  557. $limits = array();
  558. $limits['user_group'] = $group_info['timelimit'];
  559. $limits['user_extra'] = $extra_limit_info['timelimit'];
  560. $limits['total'] = $group_info['timelimit'] + $extra_limit_info['timelimit'];
  561. return $limits;
  562. }
  563. function permission_check_vice_founder_limit($group_info) {
  564. global $_W;
  565. $timelimits = permission_user_timelimits();
  566. $user_end_time = user_end_time($_W['uid']);
  567. if ($group_info['timelimit'] > $timelimits['total'] && !empty($user_end_time)) {
  568. return error(-1, '当前用户组的有效期不能超过' . $timelimits['total'] . '天!');
  569. }
  570. $account_nums = permission_user_account_num();
  571. $account_all_type_sign = uni_account_type_sign();
  572. foreach ($account_all_type_sign as $account_type_key => $account_type_info) {
  573. $maxtype = 'max' . $account_type_key;
  574. if ($group_info[$maxtype] > $account_nums[$maxtype]) {
  575. return error(-1, "当前用户组的" . $account_type_info['title'] . "个数不能超过" . $account_nums[$maxtype] . '个!');
  576. }
  577. }
  578. return true;
  579. }
  580. function permission_account_user_init($uid, $uniacid) {
  581. $uid = intval($uid);
  582. $uniacid = intval($uniacid);
  583. if (empty($uid) || empty($uniacid)) {
  584. return error(-1, '参数错误');
  585. }
  586. $account = uni_fetch($uniacid);
  587. $account_all_type_sign = uni_account_type_sign();
  588. foreach ($account_all_type_sign as $account_type_sign => $account_type_info) {
  589. if (in_array($account['type'], $account_type_info['contain_type'])) {
  590. $account_type = $account_type_sign == 'account' ? 'system' : $account_type_sign;
  591. }
  592. }
  593. $user_own_menu_permission = table('users_permission')->getUserPermissionByType($uid, $uniacid, $account_type);
  594. $user_own_module_permission = table('users_permission')->getAllUserModulePermission($uid, $uniacid);
  595. if (empty($user_own_menu_permission)) {
  596. $all_menu_permission = permission_menu_name();
  597. $user_menu_permission_data = array(
  598. 'type' => $account_type,
  599. 'permission' => implode('|', $all_menu_permission),
  600. );
  601. permission_update_account_user($uid, $uniacid, $user_menu_permission_data);
  602. }
  603. if (empty($user_own_module_permission)) {
  604. $insert = array(
  605. 'uniacid' => $uniacid,
  606. 'uid' => $uid,
  607. 'type' => 'modules',
  608. 'permission' => 'all',
  609. );
  610. pdo_insert('users_permission', $insert);
  611. }
  612. return true;
  613. }