人人商城

permission.mod.php 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  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. $we7_file_permission = $acl;
  10. $permission_frames = require IA_ROOT . '/web/common/frames.inc.php';
  11. if (!in_array($_W['role'], array(ACCOUNT_MANAGE_NAME_OPERATOR, ACCOUNT_MANAGE_NAME_MANAGER)) || empty($_W['uniacid'])) {
  12. return $we7_file_permission;
  13. }
  14. $cachekey = cache_system_key('permission', array('uniacid' => $_W['uniacid'], 'uid' => $_W['uid']));
  15. $cache = cache_load($cachekey);
  16. if (!empty($cache)) {
  17. return $cache;
  18. }
  19. $permission_exist = permission_account_user_permission_exist($_W['uid'], $_W['uniacid']);
  20. if (empty($permission_exist)) {
  21. $we7_file_permission['platform'][$_W['role']] = array('platform*');
  22. $we7_file_permission['site'][$_W['role']] = array('site*');
  23. $we7_file_permission['mc'][$_W['role']] = array('mc*');
  24. $we7_file_permission['profile'][$_W['role']] = array('profile*');
  25. $we7_file_permission['module'][$_W['role']] = array('manage-account', 'display');
  26. $we7_file_permission['wxapp'][$_W['role']] = array('display', 'payment', 'post', 'version');
  27. $we7_file_permission['webapp'][$_W['role']] = array('home', 'manage');
  28. $we7_file_permission['phoneapp'][$_W['role']] = array('display', 'manage', 'version');
  29. cache_write($cachekey, $we7_file_permission);
  30. return $we7_file_permission;
  31. }
  32. $user_account_permission = permission_account_user_menu($_W['uid'], $_W['uniacid'], PERMISSION_ACCOUNT);
  33. $user_wxapp_permission = permission_account_user_menu($_W['uid'], $_W['uniacid'], PERMISSION_WXAPP);
  34. $user_permission = array_merge($user_account_permission, $user_wxapp_permission);
  35. $permission_contain = array('account', 'wxapp', 'system', 'phoneapp');
  36. $section = array();
  37. $permission_result = array();
  38. foreach ($permission_frames as $key => $frames) {
  39. if (!in_array($key, $permission_contain) || empty($frames['section'])) {
  40. continue;
  41. }
  42. foreach ($frames['section'] as $frame_key => $frame) {
  43. if (empty($frame['menu'])) {
  44. continue;
  45. }
  46. $section[$key][$frame_key] = $frame['menu'];
  47. }
  48. }
  49. $account = permission_get_nameandurl($section[$permission_contain[0]]);
  50. $wxapp = permission_get_nameandurl($section[$permission_contain[1]]);
  51. $system = permission_get_nameandurl($section[$permission_contain[2]]);
  52. $permission_result = array_merge($account, $wxapp, $system);
  53. foreach ($permission_result as $permission_val) {
  54. if (in_array($permission_val['permission_name'], $user_permission)) {
  55. $we7_file_permission[$permission_val['controller']][$_W['role']][] = $permission_val['action'];
  56. }
  57. }
  58. cache_write($cachekey, $we7_file_permission);
  59. return $we7_file_permission;
  60. }
  61. function permission_get_nameandurl($permission) {
  62. $result = array();
  63. if (empty($permission)) {
  64. return $result;
  65. }
  66. foreach ($permission as $menu) {
  67. if (empty($menu)) {
  68. continue;
  69. }
  70. foreach ($menu as $permission_name) {
  71. $url_query_array = url_params($permission_name['url']);
  72. $result[] = array(
  73. 'url' => $permission_name['url'],
  74. 'controller' => $url_query_array['c'],
  75. 'action' => $url_query_array['a'],
  76. 'permission_name' => $permission_name['permission_name']
  77. );
  78. if (!empty($permission_name['sub_permission'])) {
  79. foreach ($permission_name['sub_permission'] as $key => $sub_permission_name) {
  80. $sub_url_query_array = url_params($sub_permission_name['url']);
  81. $result[] = array(
  82. 'url' => $sub_permission_name['url'],
  83. 'controller' => $sub_url_query_array['c'],
  84. 'action' => $sub_url_query_array['a'],
  85. 'permission_name' => $sub_permission_name['permission_name'],
  86. );
  87. }
  88. }
  89. }
  90. }
  91. return $result;
  92. }
  93. function permission_create_account($uid, $type = ACCOUNT_TYPE_OFFCIAL_NORMAL) {
  94. $uid = intval($uid);
  95. if (empty($uid)) {
  96. return error(-1, '用户数据错误!');
  97. }
  98. $user_table = table('users');
  99. $userinfo = $user_table->usersInfo($uid);
  100. if (user_is_vice_founder($uid)) {
  101. $groupdata = $user_table->userFounderGroupInfo($userinfo['groupid']);
  102. } else {
  103. $groupdata = $user_table->usersGroupInfo($userinfo['groupid']);
  104. }
  105. $list = table('account')->getOwnedAccountCount($uid);
  106. foreach ($list as $item) {
  107. if ($item['type'] == ACCOUNT_TYPE_APP_NORMAL) {
  108. $wxapp_num = $item['count'];
  109. } else {
  110. $account_num = $item['count'];
  111. }
  112. }
  113. if ($type == ACCOUNT_TYPE_OFFCIAL_NORMAL || $type == ACCOUNT_TYPE_OFFCIAL_AUTH) {
  114. if ($account_num >= $groupdata['maxaccount']) {
  115. return error('-1', '您所在的用户组最多只能创建' . $groupdata['maxaccount'] . '个主公众号');
  116. }
  117. } elseif ($type == ACCOUNT_TYPE_APP_NORMAL) {
  118. if ($wxapp_num >= $groupdata['maxwxapp']) {
  119. return error('-1', '您所在的用户组最多只能创建' . $groupdata['maxwxapp'] . '个小程序');
  120. }
  121. }
  122. return true;
  123. }
  124. function permission_account_user_role($uid = 0, $uniacid = 0) {
  125. global $_W;
  126. load()->model('user');
  127. $role = '';
  128. $uid = empty($uid) ? $_W['uid'] : intval($uid);
  129. if (user_is_founder($uid, true)) {
  130. return ACCOUNT_MANAGE_NAME_FOUNDER;
  131. } else {
  132. $user_table = table('users');
  133. $user_info = pdo_get('users', array('uid' => $uid));
  134. if (!empty($user_info['endtime']) && $user_info['endtime'] < TIMESTAMP) {
  135. return ACCOUNT_MANAGE_NAME_EXPIRED;
  136. }
  137. if (user_is_vice_founder($uid)) {
  138. return ACCOUNT_MANAGE_NAME_VICE_FOUNDER;
  139. }
  140. if (!user_is_bind()) {
  141. return ACCOUNT_MANAGE_NAME_UNBIND_USER;
  142. }
  143. }
  144. if (!empty($uniacid)) {
  145. $role = $user_table->userOwnedAccountRole($uid, $uniacid);
  146. if ($role == ACCOUNT_MANAGE_NAME_OWNER) {
  147. $role = ACCOUNT_MANAGE_NAME_OWNER;
  148. } elseif ($role == ACCOUNT_MANAGE_NAME_VICE_FOUNDER) {
  149. $role = ACCOUNT_MANAGE_NAME_VICE_FOUNDER;
  150. } elseif ($role == ACCOUNT_MANAGE_NAME_MANAGER) {
  151. $role = ACCOUNT_MANAGE_NAME_MANAGER;
  152. } elseif ($role == ACCOUNT_MANAGE_NAME_OPERATOR) {
  153. $role = ACCOUNT_MANAGE_NAME_OPERATOR;
  154. } elseif ($role == ACCOUNT_MANAGE_NAME_CLERK) {
  155. $role = ACCOUNT_MANAGE_NAME_CLERK;
  156. }
  157. return $role;
  158. } else {
  159. $roles = $user_table->userOwnedAccountRole($uid);
  160. if (in_array(ACCOUNT_MANAGE_NAME_VICE_FOUNDER, $roles)) {
  161. $role = ACCOUNT_MANAGE_NAME_VICE_FOUNDER;
  162. } elseif (in_array(ACCOUNT_MANAGE_NAME_OWNER, $roles)) {
  163. $role = ACCOUNT_MANAGE_NAME_OWNER;
  164. } elseif (in_array(ACCOUNT_MANAGE_NAME_MANAGER, $roles)) {
  165. $role = ACCOUNT_MANAGE_NAME_MANAGER;
  166. } elseif (in_array(ACCOUNT_MANAGE_NAME_OPERATOR, $roles)) {
  167. $role = ACCOUNT_MANAGE_NAME_OPERATOR;
  168. } elseif (in_array(ACCOUNT_MANAGE_NAME_CLERK, $roles)) {
  169. $role = ACCOUNT_MANAGE_NAME_CLERK;
  170. }
  171. }
  172. $role = empty($role) ? ACCOUNT_MANAGE_NAME_OPERATOR : $role;
  173. return $role;
  174. }
  175. function permission_account_user_permission_exist($uid = 0, $uniacid = 0) {
  176. global $_W;
  177. load()->model('user');
  178. $uid = intval($uid) > 0 ? $uid : $_W['uid'];
  179. $uniacid = intval($uniacid) > 0 ? $uniacid : $_W['uniacid'];
  180. if (user_is_founder($uid)) {
  181. return false;
  182. }
  183. if (defined('FRAME') && FRAME == 'system') {
  184. return true;
  185. }
  186. $is_exist = table('users_permission')->getUserPermissionByType($uid, $uniacid);
  187. if(empty($is_exist)) {
  188. return false;
  189. } else {
  190. return true;
  191. }
  192. }
  193. function permission_account_user($type = 'system') {
  194. global $_W;
  195. $user_permission = table('users_permission')->getUserPermissionByType($_W['uid'], $_W['uniacid'], $type);
  196. $user_permission = $user_permission['permission'];
  197. if (empty($user_permission)) {
  198. $user_permission = array('account*', 'wxapp*', 'phoneapp*');
  199. }
  200. $permission_append = frames_menu_append();
  201. if (!empty($permission_append[$_W['role']])) {
  202. $user_permission = array_merge($user_permission, $permission_append[$_W['role']]);
  203. }
  204. if (empty($_W['role']) && empty($_W['uniacid'])) {
  205. $user_permission = array_merge($user_permission, $permission_append['operator']);
  206. }
  207. return (array)$user_permission;
  208. }
  209. function permission_account_user_menu($uid, $uniacid, $type) {
  210. $user_menu_permission = array();
  211. $uid = intval($uid);
  212. $uniacid = intval($uniacid);
  213. $type = trim($type);
  214. if (empty($uid) || empty($uniacid) || empty($type)) {
  215. return error(-1, '参数错误!');
  216. }
  217. $permission_exist = permission_account_user_permission_exist($uid, $uniacid);
  218. if (empty($permission_exist)) {
  219. return array('all');
  220. }
  221. $user_permission_table = table('users_permission');
  222. if ($type == 'modules') {
  223. $user_menu_permission = $user_permission_table->getAllUserModulePermission($uid, $uniacid);
  224. } else {
  225. $module = uni_modules_by_uniacid($uniacid);
  226. $module = array_keys($module);
  227. if (in_array($type, $module) || in_array($type, array(PERMISSION_ACCOUNT, PERMISSION_WXAPP, PERMISSION_SYSTEM))) {
  228. $menu_permission = $user_permission_table->getUserPermissionByType($uid, $uniacid, $type);
  229. $user_menu_permission = !empty($menu_permission['permission']) ? $menu_permission['permission'] : array();
  230. }
  231. }
  232. return $user_menu_permission;
  233. }
  234. function permission_menu_name() {
  235. load()->model('system');
  236. $menu_permission = array();
  237. $menu_list = system_menu_permission_list();
  238. $middle_menu = array();
  239. $middle_sub_menu = array();
  240. if (!empty($menu_list)) {
  241. foreach ($menu_list as $nav_id => $section) {
  242. foreach ($section['section'] as $section_id => $section) {
  243. if (!empty($section['menu'])) {
  244. $middle_menu[] = $section['menu'];
  245. }
  246. }
  247. }
  248. }
  249. if (!empty($middle_menu)) {
  250. foreach ($middle_menu as $menu) {
  251. foreach ($menu as $menu_val) {
  252. $menu_permission[] = $menu_val['permission_name'];
  253. if (!empty($menu_val['sub_permission'])) {
  254. $middle_sub_menu[] = $menu_val['sub_permission'];
  255. }
  256. }
  257. }
  258. }
  259. if (!empty($middle_sub_menu)) {
  260. foreach ($middle_sub_menu as $sub_menu) {
  261. foreach ($sub_menu as $sub_menu_val) {
  262. $menu_permission[] = $sub_menu_val['permission_name'];
  263. }
  264. }
  265. }
  266. return $menu_permission;
  267. }
  268. function permission_update_account_user($uid, $uniacid, $data) {
  269. $uid = intval($uid);
  270. $uniacid = intval($uniacid);
  271. if (empty($uid) || empty($uniacid) || !in_array($data['type'], array(PERMISSION_ACCOUNT, PERMISSION_WXAPP, PERMISSION_SYSTEM))) {
  272. return error('-1', '参数错误!');
  273. }
  274. $user_menu_permission = permission_account_user_menu($uid, $uniacid, $data['type']);
  275. if (is_error($user_menu_permission)) {
  276. return error('-1', '参数错误!');
  277. }
  278. if (empty($user_menu_permission)) {
  279. $insert = array(
  280. 'uniacid' => $uniacid,
  281. 'uid' => $uid,
  282. 'type' => $data['type'],
  283. 'permission' => $data['permission'],
  284. );
  285. $result = table('users_permission')->fill($insert)->save();
  286. } else {
  287. $update = array(
  288. 'permission' => $data['permission'],
  289. );
  290. $result = table('users_permission')->fill($update)->whereUniacid($uniacid)->whereUid($uid)->whereType($data['type'])->save();
  291. }
  292. return $result;
  293. }
  294. function permission_check_account_user($permission_name, $show_message = true, $action = '') {
  295. global $_W, $_GPC, $acl;
  296. load()->model('module');
  297. $see_more_info = $acl['see_more_info'];
  298. if (strpos($permission_name, 'see_') === 0) {
  299. $can_see_more = false;
  300. if (defined('FRAME') && FRAME == 'system') {
  301. $can_see_more = in_array($permission_name, $see_more_info[$_W['highest_role']]) ? true : false;
  302. } else {
  303. if (is_array($see_more_info[$_W['role']]) && !empty($see_more_info[$_W['role']])) {
  304. $can_see_more = in_array($permission_name, $see_more_info[$_W['role']]) ? true : false;
  305. }
  306. }
  307. return $can_see_more;
  308. }
  309. $user_has_permission = permission_account_user_permission_exist();
  310. if (empty($user_has_permission)) {
  311. return true;
  312. }
  313. $modulename = trim($_GPC['m']);
  314. $do = trim($_GPC['do']);
  315. $entry_id = intval($_GPC['eid']);
  316. if ($action == 'reply') {
  317. $system_modules = module_system();
  318. if (!empty($modulename) && !in_array($modulename, $system_modules)) {
  319. $permission_name = $modulename . '_rule';
  320. $users_permission = permission_account_user($modulename);
  321. }
  322. } elseif ($action == 'cover' && $entry_id > 0) {
  323. load()->model('module');
  324. $entry = module_entry($entry_id);
  325. if (!empty($entry)) {
  326. $permission_name = $entry['module'] . '_cover_' . trim($entry['do']);
  327. $users_permission = permission_account_user($entry['module']);
  328. }
  329. } elseif ($action == 'nav') {
  330. if(!empty($modulename)) {
  331. $permission_name = "{$modulename}_{$do}";
  332. $users_permission = permission_account_user($modulename);
  333. } else {
  334. return true;
  335. }
  336. } elseif ($action == 'wxapp' || !empty($_W['account']) && $_W['account']['type_sign'] == WXAPP_TYPE_SIGN) {
  337. $users_permission = permission_account_user('wxapp');
  338. } else {
  339. $users_permission = permission_account_user('system');
  340. }
  341. if (!isset($users_permission)) {
  342. $users_permission = permission_account_user('system');
  343. }
  344. if ($users_permission[0] != 'all' && !in_array($permission_name, $users_permission)) {
  345. if (in_array($permission_name, permission_first_sub_permission()) && !empty($show_message)) {
  346. load()->model('system');
  347. $permission_string = explode('_', $permission_name);
  348. $goto_permission = permission_subpermission($permission_string[0] . '_' . $permission_string[1] . '_');
  349. $system_menu = system_menu_permission_list(ACCOUNT_MANAGE_NAME_OPERATOR);
  350. $goto_url = $system_menu[FRAME]['section'][$permission_string[0]]['menu'][$permission_string[0] . '_' . $permission_string[1]]['sub_permission'][$goto_permission]['url'];
  351. itoast('', $goto_url);
  352. }
  353. if ($show_message) {
  354. itoast('您没有进行该操作的权限', referer(), 'error');
  355. } else {
  356. return false;
  357. }
  358. }
  359. return true;
  360. }
  361. function permission_first_sub_permission() {
  362. return array(
  363. 'platform_reply_keyword',
  364. 'platform_menu_default',
  365. 'platform_qr_qr',
  366. 'platform_masstask_post',
  367. 'platform_material_news',
  368. 'platform_site_multi',
  369. 'mc_fans_display',
  370. 'mc_member_diaplsy',
  371. 'profile_setting_remote',
  372. 'profile_payment_pay',
  373. 'statistics_visit_app',
  374. 'wxapp_payment_pay',
  375. );
  376. }
  377. function permission_check_module_user($permission_name) {
  378. global $_W;
  379. if (empty($_W['current_module']) || empty($permission_name)) {
  380. return false;
  381. }
  382. $users_permission = permission_account_user($_W['current_module']['name']);
  383. if (!in_array($permission_name, $users_permission)) {
  384. return false;
  385. }
  386. return true;
  387. }
  388. function permission_check_account_user_module($action = '', $module_name = '') {
  389. global $_W, $_GPC;
  390. $status = permission_account_user_permission_exist();
  391. if(empty($status)) {
  392. return true;
  393. }
  394. $a = trim($_GPC['a']);
  395. $do = trim($_GPC['do']);
  396. $m = trim($_GPC['m']);
  397. if ($a == 'manage-account' && $do == 'setting' && !empty($m)) {
  398. $permission_name = $m . '_settings';
  399. $users_permission = permission_account_user($m);
  400. if ($users_permission[0] != 'all' && !in_array($permission_name, $users_permission)) {
  401. return false;
  402. }
  403. } elseif ($a == 'default-entry' && !empty($m)) {
  404. if (!($_W['isfounder'] || $_W['role'] == ACCOUNT_MANAGE_NAME_OWNER)) {
  405. return false;
  406. }
  407. } elseif (!empty($do) && !empty($m)) {
  408. $is_exist = table('modules_bindings')->isEntryExists($m, 'menu', $do);
  409. if(empty($is_exist)) {
  410. return true;
  411. }
  412. }
  413. if(empty($module_name)) {
  414. $module_name = IN_MODULE;
  415. }
  416. $permission = permission_account_user($module_name);
  417. if(empty($permission) || ($permission[0] != 'all' && !empty($action) && !in_array($action, $permission))) {
  418. return false;
  419. }
  420. return true;
  421. }
  422. function permission_user_account_num($uid = 0) {
  423. global $_W;
  424. $uid = intval($uid);
  425. if ($uid <= 0) {
  426. $user = $_W['user'];
  427. } else {
  428. load()->model('user');
  429. $user = user_single($uid);
  430. }
  431. $user_table = table('users');
  432. if (user_is_vice_founder($user['uid'])) {
  433. $role = ACCOUNT_MANAGE_NAME_VICE_FOUNDER;
  434. $group = $user_table->userFounderGroupInfo($user['groupid']);
  435. $group_num = uni_owner_account_nums($user['uid'], $role);
  436. } else {
  437. $role = ACCOUNT_MANAGE_NAME_OWNER;
  438. $group = $user_table->usersGroupInfo($user['groupid']);
  439. $group_num = uni_owner_account_nums($user['uid'], $role);
  440. if (empty($_W['isfounder'])) {
  441. if (!empty($user['owner_uid'])) {
  442. $vice_users = pdo_getall('users', array('owner_uid' => $user['owner_uid']), 'uid');
  443. $users_accounts = array(
  444. 'account_num' => 0,
  445. 'wxapp_num' => 0,
  446. 'webapp_num' => 0,
  447. 'phoneapp_num' => 0,
  448. 'xzapp_num' => 0,
  449. 'aliapp_num' => 0
  450. );
  451. foreach ($vice_users as $key => $vice_user) {
  452. $user_group_num = uni_owner_account_nums($vice_user['uid'], $role);
  453. $users_accounts['account_num'] += $user_group_num['account_num'];
  454. $users_accounts['wxapp_num'] += $user_group_num['wxapp_num'];
  455. $users_accounts['webapp_num'] += $user_group_num['webapp_num'];
  456. $users_accounts['phoneapp_num'] += $user_group_num['phoneapp_num'];
  457. $users_accounts['xzapp_num'] += $user_group_num['xzapp_num'];
  458. $users_accounts['aliapp_num'] += $user_group_num['aliapp_num'];
  459. }
  460. $owner_info = $user_table->usersInfo($user['owner_uid']);
  461. $group_vice = $user_table->userFounderGroupInfo($owner_info['groupid']);
  462. $founder_group_num = uni_owner_account_nums($owner_info['uid'], ACCOUNT_MANAGE_NAME_VICE_FOUNDER);
  463. $group['maxaccount'] = intval($group_vice['maxaccount']) - $users_accounts['account_num'];
  464. $group['maxwxapp'] = intval($group_vice['maxwxapp']) - $users_accounts['wxapp_num'];
  465. $group['maxwebapp'] = intval($group_vice['maxwebapp']) - $users_accounts['webapp_num'];
  466. $group['maxphoneapp'] = intval($group_vice['maxphoneapp']) - $users_accounts['phoneapp_num'];
  467. $group['maxxzapp'] = intval($group_vice['maxxzapp']) - $users_accounts['xzapp_num'];
  468. $group['maxaliapp'] = intval($group_vice['maxaliapp']) - $users_accounts['aliapp_num'];
  469. }
  470. }
  471. }
  472. $store_table = table('store');
  473. $create_buy_account_num = $store_table->searchUserCreateAccountNum($user['uid']);
  474. $create_buy_wxapp_num = $store_table->searchUserCreateWxappNum($user['uid']);
  475. $store_buy_account = $store_table->searchUserBuyAccount($user['uid']);
  476. $store_buy_wxapp = $store_table->searchUserBuyWxapp($user['uid']);
  477. $uniacid_limit = max((intval($group['maxaccount']) + intval($store_buy_account) - $group_num['account_num']), 0);
  478. $wxapp_limit = max((intval($group['maxwxapp']) + intval($store_buy_wxapp) - $group_num['wxapp_num']), 0);
  479. $webapp_limit = max(intval($group['maxwebapp']) - $group_num['webapp_num'], 0);
  480. $phoneapp_limit = max(intval($group['maxphoneapp']) - $group_num['phoneapp_num'], 0);
  481. $xzapp_limit = max(intval($group['maxxzapp']) - $group_num['xzapp_num'], 0);
  482. $aliapp_limit = max(intval($group['maxaliapp']) - $group_num['aliapp_num'], 0);
  483. $founder_uniacid_limit = max((intval($group_vice['maxaccount']) + intval($store_buy_account) - $founder_group_num['account_num']), 0);
  484. $founder_wxapp_limit = max((intval($group_vice['maxwxapp']) + intval($store_buy_wxapp) - $founder_group_num['wxapp_num']), 0);
  485. $founder_webapp_limit = max(intval($group_vice['maxwebapp']) - $founder_group_num['webapp_num'], 0);
  486. $founder_phoneapp_limit = max(intval($group_vice['maxphoneapp']) - $founder_group_num['phoneapp_num'], 0);
  487. $founder_xzapp_limit = max(intval($group_vice['xzapp']) - $founder_group_num['xzapp_num'], 0);
  488. $founder_aliapp_limit = max(intval($group_vice['aliapp']) - $founder_group_num['aliapp_num'], 0);
  489. $data = array(
  490. 'group_name' => $group['name'],
  491. 'vice_group_name' => $group_vice['name'],
  492. 'maxaccount' => $group['maxaccount'] + $store_buy_account,
  493. 'usergroup_account_limit' => max($group['maxaccount'] - $group_num['account_num'] - $create_buy_account_num, 0), 'usergroup_wxapp_limit' => max($group['maxwxapp'] - $group_num['wxapp_num'] - $create_buy_wxapp_num, 0), 'usergroup_webapp_limit' => max($group['maxwebapp'] - $group_num['webapp_num'], 0), 'usergroup_phoneapp_limit' => max($group['maxphoneapp'] - $group_num['phoneapp_num'], 0), 'usergroup_xzapp_limit' => max($group['maxxzapp'] - $group_num['xzapp_num'], 0), 'usergroup_aliapp_limit' => max($group['maxaliapp'] - $group_num['aliapp_num'], 0), 'uniacid_num' => $group_num['account_num'],
  494. 'uniacid_limit' => max($uniacid_limit, 0),
  495. 'founder_uniacid_limit' => max($founder_uniacid_limit, 0),
  496. 'maxwxapp' => $group['maxwxapp'] + $store_buy_wxapp,
  497. 'wxapp_num' => $group_num['wxapp_num'],
  498. 'wxapp_limit' => max($wxapp_limit, 0),
  499. 'founder_wxapp_limit' => max($founder_wxapp_limit, 0),
  500. 'maxwebapp'=>$group['maxwebapp'], 'webapp_limit' => $webapp_limit, 'founder_webapp_limit' => max($founder_webapp_limit, 0),
  501. 'webapp_num'=> $group_num['webapp_num'], 'maxphoneapp' => $group['maxphoneapp'],
  502. 'phoneapp_num' => $group_num['phoneapp_num'],
  503. 'phoneapp_limit' => $phoneapp_limit,
  504. 'founder_phoneapp_limit' => max($founder_phoneapp_limit, 0),
  505. 'maxxzapp' => $group['maxxzapp'],
  506. 'xzapp_num' => $group_num['xzapp_num'],
  507. 'xzapp_limit' => $xzapp_limit,
  508. 'founder_xzapp_limit' => max($founder_xzapp_limit, 0),
  509. 'maxaliapp' => $group['maxaliapp'],
  510. 'aliapp_num' => $group_num['aliapp_num'],
  511. 'aliapp_limit' => $aliapp_limit,
  512. 'founder_aliapp_limit' => max($founder_aliapp_limit, 0),
  513. );
  514. return $data;
  515. }
  516. function permission_subpermission($prefix, $module = '') {
  517. global $_W;
  518. $result = '';
  519. if (empty($prefix)) {
  520. return $result;
  521. }
  522. $type = !empty($module) ? safe_gpc_string($module) : ($_W['account']['type_sign'] == 'account' ? 'system' : $_W['account']['type_sign']);
  523. $account_premission = table('users_permission')->getUserPermissionByType($_W['uid'], $_W['uniacid'], $type);
  524. if (!empty($account_premission['permission'])) {
  525. foreach ($account_premission['permission'] as $permission) {
  526. $if_exist = strpos($permission, $prefix);
  527. $result = $if_exist !== false ? $permission : '';
  528. if (!empty($result)) break;
  529. }
  530. }
  531. return $result;
  532. }
  533. function permission_user_account_creatable($uid = 0, $type_sign = '') {
  534. global $_W;
  535. $uid = empty($uid) ? $_W['uid'] : $uid;
  536. $type_sign = empty($type_sign) ? 'account' : $type_sign;
  537. if(user_is_founder($uid) && !user_is_vice_founder()) {
  538. return true;
  539. }
  540. $key = $type_sign . '_limit';
  541. $data = permission_user_account_num($uid);
  542. return isset($data[$key]) && $data[$key] > 0;
  543. }