user.mod.php 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  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 user_register($user, $source) {
  8. global $_W;
  9. load()->model('message');
  10. if (empty($user) || !is_array($user)) {
  11. return 0;
  12. }
  13. if (isset($user['uid'])) {
  14. unset($user['uid']);
  15. }
  16. load()->classs('oauth2/oauth2client');
  17. $support_login_types = Oauth2CLient::supportThirdLoginType();
  18. if (!in_array($source, $support_login_types)) {
  19. $check_pass = safe_check_password($user['password']);
  20. if (is_error($check_pass)) {
  21. return $check_pass;
  22. }
  23. }
  24. $user['salt'] = random(8);
  25. $user['password'] = user_hash($user['password'], $user['salt']);
  26. $user['joinip'] = $_W['clientip'];
  27. $user['joindate'] = TIMESTAMP;
  28. $user['lastip'] = '';
  29. $user['lastvisit'] = '';
  30. $user['groupid'] = intval($_W['setting']['register']['groupid']);
  31. if (!empty($user['owner_uid'])) {
  32. $vice_founder_info = user_single($user['owner_uid']);
  33. if (empty($vice_founder_info) || !user_is_vice_founder($vice_founder_info['uid'])) {
  34. $user['owner_uid'] = 0;
  35. }
  36. }
  37. if (empty($user['status'])) {
  38. $user['status'] = 2;
  39. }
  40. if (empty($user['type'])) {
  41. $user['type'] = USER_TYPE_COMMON;
  42. }
  43. $result = pdo_insert('users', $user);
  44. if (!empty($result)) {
  45. $user['uid'] = pdo_insertid();
  46. }
  47. if (!empty($user['uid']) && !empty($user['owner_uid'])) {
  48. $founder_user_add = table('users_founder_own_users')->addOwnUser($user['uid'], $user['owner_uid']);
  49. }
  50. message_notice_record($_W['config']['setting']['founder'], MESSAGE_REGISTER_TYPE, array(
  51. 'uid' => $user['uid'],
  52. 'username' => $user['username'],
  53. 'status' => $user['status'],
  54. 'source' => $source,
  55. 'type_name' => $user['type'] == USER_TYPE_COMMON ? '普通用户' : '应用操作员',
  56. ));
  57. return intval($user['uid']);
  58. }
  59. function user_check($user) {
  60. if (empty($user) || !is_array($user)) {
  61. return 0;
  62. }
  63. $where = ' WHERE 1 ';
  64. $params = array();
  65. if (!empty($user['uid'])) {
  66. $where .= ' AND `uid`=:uid';
  67. $params[':uid'] = intval($user['uid']);
  68. }
  69. if (!empty($user['username'])) {
  70. $where .= ' AND `username`=:username';
  71. $params[':username'] = $user['username'];
  72. }
  73. if (!empty($user['status'])) {
  74. $where .= " AND `status`=:status";
  75. $params[':status'] = intval($user['status']);
  76. }
  77. if (empty($params)) {
  78. return 0;
  79. }
  80. $sql = 'SELECT `uid`,`password`,`salt` FROM ' . tablename('users') . "$where LIMIT 1";
  81. $record = pdo_fetch($sql, $params);
  82. if (empty($record) || empty($record['password']) || empty($record['salt'])) {
  83. return 0;
  84. }
  85. if (!empty($user['password'])) {
  86. $password = user_hash($user['password'], $record['salt']);
  87. return $password == $record['password'] ? $record['uid'] : 0;
  88. }
  89. return $record['uid'];
  90. }
  91. function user_is_founder($uid, $only_main_founder = false) {
  92. global $_W;
  93. $founders = explode(',', $_W['config']['setting']['founder']);
  94. if (in_array($uid, $founders)) {
  95. return true;
  96. }
  97. if (empty($only_main_founder)) {
  98. $founder_groupid = pdo_getcolumn('users', array('uid' => $uid), 'founder_groupid');
  99. if ($founder_groupid == ACCOUNT_MANAGE_GROUP_VICE_FOUNDER) {
  100. return true;
  101. }
  102. }
  103. return false;
  104. }
  105. function user_is_vice_founder($uid = 0) {
  106. global $_W;
  107. $uid = intval($uid);
  108. if (empty($uid)) {
  109. $user_info = $_W['user'];
  110. } else {
  111. $user_info = table('users')->getById($uid);
  112. }
  113. if ($user_info['founder_groupid'] == ACCOUNT_MANAGE_GROUP_VICE_FOUNDER) {
  114. return true;
  115. }
  116. return false;
  117. }
  118. function user_delete($uid, $is_recycle = false) {
  119. load()->model('cache');
  120. if (!empty($is_recycle)) {
  121. pdo_update('users', array('status' => USER_STATUS_BAN), array('uid' => $uid));
  122. return true;
  123. }
  124. $user_accounts = table('uni_account_users')->getOwnedAccountsByUid($uid);
  125. if (!empty($user_accounts)) {
  126. foreach ($user_accounts as $uniacid => $account) {
  127. cache_build_account_modules($uniacid);
  128. }
  129. }
  130. $user_info = table('users')->getById($uid);
  131. if ($user_info['founder_groupid'] == ACCOUNT_MANAGE_GROUP_VICE_FOUNDER) {
  132. pdo_update('users', array('owner_uid' => ACCOUNT_NO_OWNER_UID), array('owner_uid' => $uid));
  133. pdo_update('users_group', array('owner_uid' => ACCOUNT_NO_OWNER_UID), array('owner_uid' => $uid));
  134. pdo_update('uni_group', array('owner_uid' => ACCOUNT_NO_OWNER_UID), array('owner_uid' => $uid));
  135. pdo_delete('users_founder_own_users', array('founder_uid' => $uid));
  136. pdo_delete('users_founder_own_users_groups', array('founder_uid' => $uid));
  137. pdo_delete('users_founder_own_uni_groups', array('founder_uid' => $uid));
  138. pdo_delete('users_founder_own_create_groups', array('founder_uid' => $uid));
  139. }
  140. pdo_delete('users', array('uid' => $uid));
  141. pdo_delete('uni_account_users', array('uid' => $uid));
  142. pdo_delete('users_profile', array('uid' => $uid));
  143. pdo_delete('users_bind', array('uid' => $uid));
  144. pdo_delete('users_extra_group', array('uid' => $uid));
  145. pdo_delete('users_extra_limit', array('uid' => $uid));
  146. pdo_delete('users_extra_modules', array('uid' => $uid));
  147. pdo_delete('users_extra_templates', array('uid' => $uid));
  148. pdo_delete('users_founder_own_users', array('uid' => $uid));
  149. return true;
  150. }
  151. function user_single($user_or_uid) {
  152. $user = $user_or_uid;
  153. if (empty($user)) {
  154. return false;
  155. }
  156. if (is_numeric($user)) {
  157. $user = array('uid' => $user);
  158. }
  159. if (!is_array($user)) {
  160. return false;
  161. }
  162. $where = ' WHERE 1 ';
  163. $params = array();
  164. if (!empty($user['uid'])) {
  165. $where .= ' AND u.`uid`=:uid';
  166. $params[':uid'] = intval($user['uid']);
  167. }
  168. if (!empty($user['username'])) {
  169. $where .= ' AND u.`username`=:username';
  170. $params[':username'] = $user['username'];
  171. $user_exists = user_check($user);
  172. $is_mobile = preg_match(REGULAR_MOBILE, $user['username']);
  173. if (!$user_exists && !empty($user['username']) && $is_mobile) {
  174. $sql = "select b.uid, u.username FROM " . tablename('users_bind') . " AS b LEFT JOIN " . tablename('users') . " AS u ON b.uid = u.uid WHERE b.bind_sign = :bind_sign";
  175. $bind_info = pdo_fetch($sql, array('bind_sign' => $user['username']));
  176. if (!is_array($bind_info) || empty($bind_info) || empty($bind_info['username'])) {
  177. return false;
  178. }
  179. $params[':username'] = $bind_info['username'];
  180. }
  181. }
  182. if (!empty($user['email'])) {
  183. $where .= ' AND u.`email`=:email';
  184. $params[':email'] = $user['email'];
  185. }
  186. if (!empty($user['status'])) {
  187. $where .= " AND u.`status`=:status";
  188. $params[':status'] = intval($user['status']);
  189. }
  190. if (empty($params)) {
  191. return false;
  192. }
  193. $sql = 'SELECT u.*, p.avatar FROM ' . tablename('users') . ' AS u LEFT JOIN ' . tablename('users_profile') . ' AS p ON u.uid = p.uid ' . $where . ' LIMIT 1';
  194. $record = pdo_fetch($sql, $params);
  195. if (empty($record)) {
  196. return false;
  197. }
  198. if (!empty($user['password'])) {
  199. $password = user_hash($user['password'], $record['salt']);
  200. if ($password != $record['password']) {
  201. return false;
  202. }
  203. }
  204. $record['hash'] = md5($record['password'] . $record['salt']);
  205. unset($record['password'], $record['salt']);
  206. $founder_own_user_info = empty($user['uid']) ? array() : table('users_founder_own_users')->getFounderByUid($user['uid']);
  207. if (!empty($founder_own_user_info) && !empty($founder_own_user_info['founder_uid'])) {
  208. $vice_founder_info = pdo_getcolumn('users', array('uid' => $founder_own_user_info['founder_uid']), 'username');
  209. if (!empty($vice_founder_info)) {
  210. $record['vice_founder_name'] = $vice_founder_info;
  211. } else {
  212. pdo_delete('users_founder_own_users', array('founder_uid' => $founder_own_user_info['founder_uid'], 'uid' => $founder_own_user_info['uid']));
  213. }
  214. }
  215. if ($record['type'] == ACCOUNT_OPERATE_CLERK) {
  216. $clerk = pdo_get('activity_clerks', array('uid' => $record['uid']));
  217. if (!empty($clerk)) {
  218. $record['name'] = $clerk['name'];
  219. $record['clerk_id'] = $clerk['id'];
  220. $record['store_id'] = $clerk['storeid'];
  221. $record['store_name'] = pdo_fetchcolumn('SELECT business_name FROM ' . tablename('activity_stores') . ' WHERE id = :id', array(':id' => $clerk['storeid']));
  222. $record['clerk_type'] = '3';
  223. $record['uniacid'] = $clerk['uniacid'];
  224. }
  225. } else {
  226. $record['name'] = $record['username'];
  227. $record['clerk_id'] = empty($user['uid']) ? 0 : $user['uid'];
  228. $record['store_id'] = 0;
  229. $record['clerk_type'] = '2';
  230. }
  231. $third_info = pdo_getall('users_bind', array('uid' => $record['uid']), array(), 'third_type');
  232. if (!empty($third_info) && is_array($third_info)) {
  233. $record['qq_openid'] = empty($third_info[USER_REGISTER_TYPE_QQ]['bind_sign']) ? '' : $third_info[USER_REGISTER_TYPE_QQ]['bind_sign'];
  234. $record['wechat_openid'] = empty($third_info[USER_REGISTER_TYPE_WECHAT]['bind_sign']) ? '' : $third_info[USER_REGISTER_TYPE_WECHAT]['bind_sign'];
  235. $record['mobile'] = empty($third_info[USER_REGISTER_TYPE_MOBILE]['bind_sign']) ? '' : $third_info[USER_REGISTER_TYPE_MOBILE]['bind_sign'];
  236. $record['console'] = empty($third_info[USER_REGISTER_TYPE_CONSOLE]) ? '' : $third_info[USER_REGISTER_TYPE_CONSOLE]['bind_sign'];
  237. }
  238. $record['notice_setting'] = iunserializer($record['notice_setting']);
  239. $record['is_expired'] = STATUS_OFF;
  240. if (!empty($record['endtime']) && !in_array($record['endtime'], array(USER_ENDTIME_GROUP_EMPTY_TYPE, USER_ENDTIME_GROUP_UNLIMIT_TYPE)) && $record['endtime'] < TIMESTAMP) {
  241. $record['is_expired'] = STATUS_ON;
  242. }
  243. return $record;
  244. }
  245. function user_related_update($uid, $user) {
  246. $uid = intval($uid);
  247. if (empty($uid) || !is_array($user)) {
  248. return false;
  249. }
  250. if (isset($user['groupid'])) {
  251. $record['groupid'] = $user['groupid'];
  252. $user_info = table('users')->getById($uid);
  253. if ($user_info['founder_groupid'] == ACCOUNT_MANAGE_GROUP_VICE_FOUNDER || $user['founder_groupid'] == ACCOUNT_MANAGE_GROUP_VICE_FOUNDER) {
  254. $group_info = user_founder_group_detail_info($user['groupid']);
  255. } else {
  256. $group_info = user_group_detail_info($user['groupid']);
  257. }
  258. if (!empty($group_info)) {
  259. $group_info['timelimit'] = intval($group_info['timelimit']);
  260. if ($group_info['timelimit'] > 0) {
  261. $extra_limit_table = table('users_extra_limit');
  262. $extraLimit = $extra_limit_table->getExtraLimitByUid($user_info['uid']);
  263. $time_limit = $group_info['timelimit'] + $extraLimit['timelimit'];
  264. $user_end_time = strtotime($time_limit . ' days', max($user_info['endtime'], time()));
  265. if (user_is_vice_founder() && !empty($user_info['endtime'])) {
  266. $user_end_time = min($user_end_time, $user_info['endtime']);
  267. }
  268. } else {
  269. $user_end_time = USER_ENDTIME_GROUP_UNLIMIT_TYPE;
  270. }
  271. $change_status = $user_end_time;
  272. pdo_update('users', array('endtime' => $user_end_time), array('uid' => $uid));
  273. }
  274. }
  275. if (isset($user['endtime']) || !empty($change_status)) {
  276. $expire_notice = setting_load('user_expire');
  277. if (!empty($expire_notice['user_expire']['status'])) {
  278. $user_info = empty($user_info) ? table('users')->getById($user['uid']) : $user_info;
  279. if ($user_info['endtime'] != $record['endtime']) {
  280. pdo_update('users_profile', array('send_expire_status' => 0), array('uid' => intval($user_info['uid'])));
  281. }
  282. }
  283. }
  284. return true;
  285. }
  286. function user_hash($passwordinput, $salt) {
  287. global $_W;
  288. $passwordinput = "{$passwordinput}-{$salt}-{$_W['config']['setting']['authkey']}";
  289. return sha1($passwordinput);
  290. }
  291. function user_password_hash($password, $uid) {
  292. if (empty($password) || intval($uid) <= 0) {
  293. return '';
  294. }
  295. $user_info = table('users')->getById($uid);
  296. if (empty($user_info)) {
  297. return '';
  298. }
  299. return md5($password . $user_info['salt']);
  300. }
  301. function user_password($passwordinput, $uid) {
  302. if (empty($passwordinput) || intval($uid) <= 0) {
  303. return '';
  304. }
  305. $user_info = table('users')->getById($uid);
  306. if (empty($user_info)) {
  307. return '';
  308. }
  309. return user_hash($passwordinput, $user_info['salt']);
  310. }
  311. function user_level() {
  312. static $level = array(
  313. '-3' => '锁定用户',
  314. '-2' => '禁止访问',
  315. '-1' => '禁止发言',
  316. '0' => '普通会员',
  317. '1' => '管理员',
  318. );
  319. return $level;
  320. }
  321. function user_group() {
  322. global $_W;
  323. $users_group_table = table('users_group');
  324. if (user_is_vice_founder()) {
  325. $users_group_table->getOwnUsersGroupsList($_W['uid']);
  326. }
  327. return $users_group_table->getUsersGroupList();
  328. }
  329. function user_founder_group() {
  330. $groups = pdo_getall('users_founder_group', array(), '*', 'id', 'id ASC');
  331. return $groups;
  332. }
  333. function user_group_detail_info($groupid = 0) {
  334. $group_info = array();
  335. $groupid = is_array($groupid) ? 0 : intval($groupid);
  336. if (empty($groupid)) {
  337. return $group_info;
  338. }
  339. $group_info = pdo_get('users_group', array('id' => $groupid));
  340. if (empty($group_info)) {
  341. return $group_info;
  342. }
  343. $group_info['package'] = (array)iunserializer($group_info['package']);
  344. if (!empty($group_info['package']) && !in_array(-1, $group_info['package'])) {
  345. $group_info['package_detail'] = uni_groups($group_info['package']);
  346. $group_info['user_group_modules_all'] = array();
  347. if (!empty($group_info['package_detail'])) {
  348. foreach ($group_info['package_detail'] as $package_detail) {
  349. if (!empty($package_detail['modules_all'])) {
  350. foreach ($package_detail['modules_all'] as $mdoule_key => $module_val) {
  351. $group_info['user_group_modules_all'][$mdoule_key] = $module_val;
  352. }
  353. }
  354. }
  355. }
  356. } else {
  357. $group_info['modules'] = empty($group_info['package']) ? '' : 'all';
  358. $group_info['templates'] = empty($group_info['package']) ? '' : 'all';
  359. }
  360. return $group_info;
  361. }
  362. function user_founder_group_detail_info($groupid = 0) {
  363. $group_info = array();
  364. $groupid = is_array($groupid) ? 0 : intval($groupid);
  365. if (empty($groupid)) {
  366. return $group_info;
  367. }
  368. $group_info = pdo_get('users_founder_group', array('id' => $groupid));
  369. if (empty($group_info)) {
  370. return $group_info;
  371. }
  372. $group_info['package'] = (array)iunserializer($group_info['package']);
  373. if (!empty($group_info['package'])) {
  374. $group_info['package_detail'] = uni_groups($group_info['package']);
  375. }
  376. return $group_info;
  377. }
  378. function user_account_detail_info($uid) {
  379. $account_lists = $app_user_info = $wxapp_user_info = $webapp_user_info = array();
  380. $uid = intval($uid);
  381. if (empty($uid)) {
  382. return $account_lists;
  383. }
  384. $account_users_info = table('account')->userOwnedAccount($uid);
  385. $account_type_signs = uni_account_type();
  386. $accounts = array();
  387. if (!empty($account_users_info)) {
  388. foreach ($account_users_info as $uniacid => $account) {
  389. $type_sign = $account_type_signs[$account['type']]['type_sign'];
  390. if (empty($type_sign)) {
  391. continue;
  392. }
  393. $account_info = uni_fetch($uniacid);
  394. $account_info['role'] = permission_account_user_role($uid, $uniacid);
  395. $accounts[$type_sign][$uniacid] = $account_info;
  396. }
  397. }
  398. return $accounts;
  399. }
  400. function user_modules($uid = 0) {
  401. global $_W;
  402. load()->model('module');
  403. if (empty($uid)) {
  404. $uid = $_W['uid'];
  405. }
  406. $support_type = module_support_type();
  407. $modules = cache_load(cache_system_key('user_modules', array('uid' => $uid)));
  408. if (empty($modules)) {
  409. $user_info = user_single(array('uid' => $uid));
  410. $extra_modules = table('users_extra_modules')->getExtraModulesByUid($uid);
  411. $users_extra_group_table = table('users_extra_group');
  412. $extra_groups = $users_extra_group_table->getUniGroupsByUid($uid);
  413. if (empty($uid) || user_is_founder($uid, true)) {
  414. $module_list = table('modules')->getNonRecycleModules();
  415. $module_list = modules_support_all(array_keys($module_list));
  416. } elseif (!empty($user_info) && $user_info['type'] == ACCOUNT_OPERATE_CLERK && $user_info['founder_groupid'] != ACCOUNT_MANAGE_GROUP_VICE_FOUNDER) {
  417. $clerk_module = pdo_fetchall("SELECT p.type FROM " . tablename('users_permission') . " p LEFT JOIN " . tablename('uni_account_users') . " u ON p.uid = u.uid AND p.uniacid = u.uniacid WHERE u.role = :role AND p.uid = :uid", array(':role' => ACCOUNT_MANAGE_NAME_CLERK, ':uid' => $uid));
  418. if (empty($clerk_module)) {
  419. return array();
  420. }
  421. $module_list = modules_support_all(array_column($clerk_module, 'type'));
  422. } elseif (!empty($user_info) && empty($user_info['groupid']) && empty($extra_modules) && empty($extra_groups)) {
  423. $module_list = pdo_getall('modules', array('issystem' => 1), array('name'), 'name');
  424. $module_list = modules_support_all(array_keys($module_list));
  425. } else {
  426. if ($user_info['founder_groupid'] == ACCOUNT_MANAGE_GROUP_VICE_FOUNDER) {
  427. $user_group_info = user_founder_group_detail_info($user_info['groupid']);
  428. } else {
  429. $user_group_info = user_group_detail_info($user_info['groupid']);
  430. }
  431. $packageids = $user_group_info['package'];
  432. if (!empty($packageids) && in_array('-1', $packageids)) {
  433. $module_list = table('modules')->getNonRecycleModules();
  434. $module_list = modules_support_all(array_keys($module_list));
  435. } else {
  436. $module_list = array();
  437. $package_group = (array) pdo_getall('uni_group', array('id' => $packageids));
  438. $uni_group_add = pdo_get('uni_group', array('uid' => $uid));
  439. if (!empty($uni_group_add)) {
  440. $package_group[] = $uni_group_add;
  441. }
  442. $users_extra_group_table = table('users_extra_group');
  443. $extra_groups = $users_extra_group_table->getUniGroupsByUid($uid);
  444. $extra_uni_groups = pdo_getall('uni_group', array('id' => array_keys($extra_groups)));
  445. $package_group = array_merge($package_group, $extra_uni_groups);
  446. if (!empty($package_group)) {
  447. foreach ($package_group as $row) {
  448. $row['modules'] = iunserializer($row['modules']);
  449. if (empty($row) || empty($row['modules'])) {
  450. continue;
  451. }
  452. foreach ($row['modules'] as $type => $modulenames) {
  453. if (!is_array($modulenames) || empty($modulenames)) {
  454. continue;
  455. }
  456. foreach ($modulenames as $name) {
  457. switch ($type) {
  458. case 'modules':
  459. $module_list[$name][] = MODULE_SUPPORT_ACCOUNT_NAME;
  460. break;
  461. case 'account':
  462. $module_list[$name][] = MODULE_SUPPORT_ACCOUNT_NAME;
  463. break;
  464. case 'wxapp':
  465. $module_list[$name][] = MODULE_SUPPORT_WXAPP_NAME;
  466. break;
  467. case 'webapp':
  468. $module_list[$name][] = MODULE_SUPPORT_WEBAPP_NAME;
  469. break;
  470. case 'phoneapp':
  471. $module_list[$name][] = MODULE_SUPPORT_PHONEAPP_NAME;
  472. break;
  473. case 'aliapp':
  474. $module_list[$name][] = MODULE_SUPPORT_ALIAPP_NAME;
  475. break;
  476. case 'baiduapp':
  477. $module_list[$name][] = MODULE_SUPPORT_BAIDUAPP_NAME;
  478. break;
  479. case 'toutiaoapp':
  480. $module_list[$name][] = MODULE_SUPPORT_TOUTIAOAPP_NAME;
  481. break;
  482. case 'welcome':
  483. $module_list[$name][] = MODULE_SUPPORT_SYSTEMWELCOME_NAME;
  484. break;
  485. }
  486. }
  487. }
  488. }
  489. }
  490. }
  491. }
  492. if (!empty($extra_modules)) {
  493. foreach ($extra_modules as $extra_module_key => $extra_module_val) {
  494. if (!empty($module_list[$extra_module_val['module_name']]) && $module_list[$extra_module_val['module_name']] == 'all') {
  495. continue;
  496. }
  497. $module_list[$extra_module_val['module_name']][] = $extra_module_val['support'];
  498. }
  499. }
  500. $modules = array();
  501. if (!empty($module_list)) {
  502. $have_plugin_module = array();
  503. $plugin_list = pdo_getall('modules_plugin', array('name' => array_keys($module_list)), array());
  504. if (!empty($plugin_list)) {
  505. foreach ($plugin_list as $plugin) {
  506. $have_plugin_module[$plugin['main_module']][$plugin['name']] = empty($module_list[$plugin['name']]) ? '' : $module_list[$plugin['name']];
  507. unset($module_list[$plugin['name']]);
  508. }
  509. }
  510. if (!empty($module_list)) {
  511. foreach ($module_list as $module => $support) {
  512. $modules[$module] = $support;
  513. if (!empty($have_plugin_module[$module])) {
  514. foreach ($have_plugin_module[$module] as $plugin => $plugin_support) {
  515. $modules[$plugin] = $plugin_support;
  516. }
  517. }
  518. }
  519. }
  520. }
  521. cache_write(cache_system_key('user_modules', array('uid' => $uid)), $modules);
  522. }
  523. $module_list = array();
  524. if (!empty($modules)) {
  525. $modulenames = array_keys($modules);
  526. $all_modules = table('modules')->searchWithName($modulenames)->getAll('name');
  527. $plugin_data = table('modules_plugin')->getAllByNameOrMainModule($modulenames);
  528. $all_recycle_info = table('modules_recycle')->searchWithNameType($modulenames, MODULE_RECYCLE_INSTALL_DISABLED)->getall('name');
  529. foreach ($all_modules as $k => $value) {
  530. $all_modules[$k]['logo'] = tomedia($all_modules[$k]['logo']);
  531. $all_modules[$k]['subscribes'] = (array)iunserializer($all_modules[$k]['subscribes']);
  532. $all_modules[$k]['handles'] = (array)iunserializer($all_modules[$k]['handles']);
  533. $all_modules[$k]['isdisplay'] = 1;
  534. $all_modules[$k]['main_module'] = '';
  535. $all_modules[$k]['main_module_logo'] = '';
  536. $all_modules[$k]['main_module_title'] = '';
  537. $all_modules[$k]['plugin_list'] = array();
  538. }
  539. foreach ($plugin_data as $value) {
  540. $all_modules[$value['main_module']]['plugin_list'][] = $value['name'];
  541. $all_modules[$value['name']]['main_module'] = $value['main_module'];
  542. $main_module_info = $all_modules[$value['main_module']];
  543. if (empty($main_module_info)) {
  544. $main_module_info = pdo_get('modules_cloud', array('name' => $value['main_module']));
  545. }
  546. $all_modules[$value['name']]['main_module_logo'] = $main_module_info['logo'];
  547. $all_modules[$value['name']]['main_module_title'] = $main_module_info['title'];
  548. }
  549. foreach ($modules as $modulename => $support) {
  550. if (empty($all_modules[$modulename]) || (!empty($_W['account']) && is_array($support) && !in_array($_W['account']->typeSign . '_support', $support))) {
  551. continue;
  552. }
  553. $module_info = $all_modules[$modulename];
  554. foreach ($support_type as $support_name => $value) {
  555. if (!empty($all_recycle_info[$modulename])) {
  556. if ($all_recycle_info[$modulename][$support_name] > 0 && $module_info[$support_name] == $value['support']) {
  557. $module_info[$support_name] = $value['not_support'];
  558. }
  559. }
  560. if ($support !== 'all' && !empty($support)) {
  561. if ($module_info[$support_name] == $value['support'] && !in_array($support_name, $support)) {
  562. $module_info[$support_name] = $value['not_support'];
  563. }
  564. }
  565. }
  566. $is_continue = true;
  567. foreach ($support_type as $support_name => $value) {
  568. if ($module_info[$support_name] == $value['support']) {
  569. $is_continue = false;
  570. }
  571. }
  572. if ($is_continue) {
  573. continue;
  574. }
  575. $module_list[$modulename] = $module_info;
  576. }
  577. }
  578. return $module_list;
  579. }
  580. function modules_support_all($modulenames) {
  581. if (empty($modulenames)) {
  582. return array();
  583. }
  584. $data = array();
  585. foreach ($modulenames as $name) {
  586. $data[$name] = 'all';
  587. }
  588. return $data;
  589. }
  590. function user_login_forward($forward = '') {
  591. global $_W;
  592. load()->model('module');
  593. $login_forward = trim($forward);
  594. if (!empty($forward)) {
  595. return $login_forward;
  596. }
  597. if ($_W['isadmin']) {
  598. return './home.php';
  599. } else {
  600. $user_end_time = user_end_time($_W['uid']);
  601. if (!empty($user_end_time) && strtotime($user_end_time) < TIMESTAMP) {
  602. return url('user/profile');
  603. }
  604. }
  605. $login_forward = user_after_login_link();
  606. return $login_forward;
  607. }
  608. function user_invite_register_url($uid = 0) {
  609. global $_W;
  610. if (empty($uid)) {
  611. $uid = $_W['uid'];
  612. }
  613. return $_W['siteroot'] . 'web/index.php?c=user&a=register&do=register_url&owner_uid=' . $uid;
  614. }
  615. function user_save_create_group($account_group_info) {
  616. global $_W;
  617. $account_group_table = table('users_create_group');
  618. $group_name = trim($account_group_info['group_name']);
  619. $id = $account_group_info['id'];
  620. if (empty($group_name)) {
  621. return error(-1, '账户权限组不能为空');
  622. }
  623. $account_group_table->searchWithGroupName($group_name);
  624. if (!empty($id)) {
  625. $account_group_table->searchWithoutId($id);
  626. }
  627. $account_group_exist = $account_group_table->getCreateGroupInfo();
  628. if (!empty($account_group_exist)) {
  629. return error(-1, '账户权限组已经存在!');
  630. }
  631. if (user_is_vice_founder()) {
  632. $premission_check_result = permission_check_vice_founder_limit($account_group_info);
  633. if (is_error($premission_check_result)) {
  634. return $premission_check_result;
  635. }
  636. }
  637. if (empty($id)) {
  638. pdo_insert('users_create_group', $account_group_info);
  639. $create_group_id = pdo_insertid();
  640. if (user_is_vice_founder()) {
  641. $own_create_group_table = table('users_founder_own_create_groups');
  642. $own_create_group_table->addOwnCreateGroup($_W['uid'], $create_group_id);
  643. }
  644. } else {
  645. pdo_update('users_create_group', $account_group_info, array('id' => $account_group_info['id']));
  646. }
  647. return error(0, '添加成功!');
  648. }
  649. function user_save_group($group_info) {
  650. global $_W;
  651. $group_table = table('users_group');
  652. $name = trim($group_info['name']);
  653. if (empty($name)) {
  654. return error(-1, '用户权限组名不能为空');
  655. }
  656. if (10000 < $group_info['timelimit']) {
  657. return error(-1, '有效期上限为 10000 天');
  658. }
  659. $group_table->searchWithName($name);
  660. if (!empty($group_info['id'])) {
  661. $group_table->searchWithNoId($group_info['id']);
  662. }
  663. $name_exist = $group_table->getUsersGroupList();
  664. if (!empty($name_exist)) {
  665. return error(-1, '用户权限组名已存在!');
  666. }
  667. if (user_is_vice_founder()) {
  668. $permission_check_result = permission_check_vice_founder_limit($group_info);
  669. if (is_error($permission_check_result)) {
  670. return $permission_check_result;
  671. }
  672. }
  673. if (!empty($group_info['package'])) {
  674. foreach ($group_info['package'] as $value) {
  675. $package[] = intval($value);
  676. }
  677. }
  678. $group_info['package'] = empty($package) ? '' : iserializer($package);
  679. if (empty($group_info['id'])) {
  680. pdo_insert('users_group', $group_info);
  681. $users_group_id = pdo_insertid();
  682. if (user_is_vice_founder()) {
  683. $table = table('users_founder_own_users_groups');
  684. $table->addOwnUsersGroup($_W['uid'], $users_group_id);
  685. }
  686. } else {
  687. $old_group = $group_table->getById($group_info['id']);
  688. if (empty($old_group)) {
  689. return error(-1, '参数有误');
  690. }
  691. $result = pdo_update('users_group', $group_info, array('id' => $group_info['id']));
  692. if (!empty($result) && $old_group['timelimit'] != $group_info['timelimit']) {
  693. $all_group_users = table('users')
  694. ->where('founder_groupid', ACCOUNT_MANAGE_GROUP_GENERAL)
  695. ->where('groupid', $old_group['id'])
  696. ->getall();
  697. if (!empty($all_group_users)) {
  698. foreach ($all_group_users as $user) {
  699. if ($group_info['timelimit'] > 0) {
  700. $endtime = strtotime($group_info['timelimit'] . ' days', max($user['joindate'], $user['starttime']));
  701. if (user_is_vice_founder() && !empty($_W['user']['endtime'])) {
  702. $endtime = min($endtime, $_W['user']['endtime']);
  703. }
  704. } else {
  705. $endtime = 0;
  706. }
  707. $data['endtime'] = $endtime;
  708. pdo_update('users', $data, array('uid' => $user['uid']));
  709. user_related_update($user['uid'], $data);
  710. }
  711. }
  712. }
  713. }
  714. return error(0, '添加成功');
  715. }
  716. function user_save_founder_group($group_info) {
  717. $name = trim($group_info['name']);
  718. if (empty($name)) {
  719. return error(-1, '用户权限组名不能为空');
  720. }
  721. if (10000 < $group_info['timelimit']) {
  722. return error(-1, '有效期上限为 10000 天');
  723. }
  724. if (!empty($group_info['id'])) {
  725. $name_exist = pdo_get('users_founder_group', array('id <>' => $group_info['id'], 'name' => $name));
  726. } else {
  727. $name_exist = pdo_get('users_founder_group', array('name' => $name));
  728. }
  729. if (!empty($name_exist)) {
  730. return error(-1, '用户权限组名已存在!');
  731. }
  732. if (!empty($group_info['package'])) {
  733. foreach ($group_info['package'] as $value) {
  734. $package[] = intval($value);
  735. }
  736. }
  737. $group_info['package'] = empty($package) ? '' : iserializer($package);
  738. if (empty($group_info['id'])) {
  739. pdo_insert('users_founder_group', $group_info);
  740. } else {
  741. $old_group = table('users_founder_group')->getById($group_info['id']);
  742. if (empty($old_group)) {
  743. return error(-1, '参数有误');
  744. }
  745. $result = pdo_update('users_founder_group', $group_info, array('id' => $group_info['id']));
  746. if (!empty($result) && $old_group['timelimit'] != $group_info['timelimit']) {
  747. $all_group_users = table('users')
  748. ->where('founder_groupid', ACCOUNT_MANAGE_GROUP_VICE_FOUNDER)
  749. ->where('groupid', $old_group['id'])
  750. ->getall();
  751. if (!empty($all_group_users)) {
  752. foreach ($all_group_users as $user) {
  753. if ($group_info['timelimit'] > 0) {
  754. $endtime = strtotime($group_info['timelimit'] . ' days', max($user['joindate'], $user['starttime']));
  755. } else {
  756. $endtime = 0;
  757. }
  758. $data['endtime'] = $endtime;
  759. pdo_update('users', $data, array('uid' => $user['uid']));
  760. user_related_update($user['uid'], $data);
  761. }
  762. }
  763. }
  764. }
  765. return error(0, '添加成功');
  766. }
  767. function user_group_format($lists) {
  768. if (empty($lists)) {
  769. return $lists;
  770. }
  771. $all_package = array();
  772. foreach ($lists as $key => $group) {
  773. if (empty($group['package'])) {
  774. continue;
  775. }
  776. $package = iunserializer($group['package']);
  777. if (!is_array($package)) {
  778. continue;
  779. }
  780. $all_package = array_merge($all_package, $package);
  781. }
  782. $group_package = uni_groups($all_package);
  783. foreach ($lists as $key => $group) {
  784. $package = iunserializer($group['package']);
  785. $lists[$key]['package'] = $package;
  786. $group['package'] = array();
  787. if (is_array($package)) {
  788. foreach ($package as $packageid) {
  789. $group['package'][$packageid] = $group_package[$packageid];
  790. }
  791. }
  792. if (empty($package)) {
  793. $lists[$key]['module_nums'] = 0;
  794. $lists[$key]['wxapp_nums'] = 0;
  795. $lists[$key]['webapp_nums'] = 0;
  796. $lists[$key]['phoneapp_nums'] = 0;
  797. continue;
  798. }
  799. if (is_array($package) && in_array(-1, $package)) {
  800. $lists[$key]['module_nums'] = -1;
  801. $lists[$key]['wxapp_nums'] = -1;
  802. $lists[$key]['webapp_nums'] = -1;
  803. $lists[$key]['phoneapp_nums'] = -1;
  804. continue;
  805. }
  806. $names = array();
  807. $modules = array(
  808. 'modules' => array(),
  809. 'wxapp' => array(),
  810. 'webapp' => array(),
  811. 'phoneapp' => array(),
  812. );
  813. if (!empty($group['package'])) {
  814. foreach ($group['package'] as $package) {
  815. $names[] = $package['name'];
  816. $package['modules'] = !empty($package['modules']) && is_array($package['modules']) ? array_keys($package['modules']) : array();
  817. $package['wxapp'] = !empty($package['wxapp']) && is_array($package['wxapp']) ? array_keys($package['wxapp']) : array();
  818. $package['webapp'] = !empty($package['webapp']) && is_array($package['webapp']) ? array_keys($package['webapp']) : array();
  819. $package['phoneapp'] = !empty($package['phoneapp']) && is_array($package['phoneapp']) ? array_keys($package['phoneapp']) : array();
  820. $modules['modules'] = array_unique(array_merge($modules['modules'], $package['modules']));
  821. $modules['wxapp'] = array_unique(array_merge($modules['wxapp'], $package['wxapp']));
  822. $modules['webapp'] = array_unique(array_merge($modules['webapp'], $package['webapp']));
  823. $modules['phoneapp'] = array_unique(array_merge($modules['phoneapp'], $package['phoneapp']));
  824. }
  825. $lists[$key]['module_nums'] = count($modules['modules']);
  826. $lists[$key]['wxapp_nums'] = count($modules['wxapp']);
  827. $lists[$key]['webapp_nums'] = count($modules['webapp']);
  828. $lists[$key]['phoneapp_nums'] = count($modules['phoneapp']);
  829. }
  830. $lists[$key]['packages'] = implode(',', $names);
  831. }
  832. return $lists;
  833. }
  834. function user_end_time($uid) {
  835. $user = table('users')->getById($uid);
  836. if (user_is_vice_founder($uid)) {
  837. $group_info = table('users_founder_group')->getById($user['groupid']);
  838. } else {
  839. $group_info = table('users_group')->getById($user['groupid']);
  840. }
  841. $extra_limit_table = table('users_extra_limit');
  842. $extra_limit_info = $extra_limit_table->getExtraLimitByUid($uid);
  843. $group_info['timelimit'] = empty($group_info['timelimit']) ? 0 : $group_info['timelimit'];
  844. $extra_limit_info['timelimit'] = empty($extra_limit_info['timelimit']) ? 0 : $extra_limit_info['timelimit'];
  845. $total_timelimit = $group_info['timelimit'] + $extra_limit_info['timelimit'];
  846. if ($user['endtime'] == USER_ENDTIME_GROUP_EMPTY_TYPE || $user['endtime'] == USER_ENDTIME_GROUP_UNLIMIT_TYPE) {
  847. $user['end'] = 0;
  848. } elseif ($user['endtime'] == USER_ENDTIME_GROUP_DELETE_TYPE && $total_timelimit == 0) {
  849. $user['end'] = date('Y-m-d', $user['joindate']);
  850. } else {
  851. $user['end'] = date('Y-m-d', $user['endtime']);
  852. }
  853. return $user['end'];
  854. }
  855. function user_list_format($users, $founder_list = true) {
  856. if (empty($users)) {
  857. return array();
  858. }
  859. $groups = table('users_group')->getall('id');
  860. $founder_groups = table('users_founder_group')->getall('id');
  861. foreach ($users as &$user) {
  862. $user['avatar'] = !empty($user['avatar']) ? $user['avatar'] : './resource/images/nopic-user.png';
  863. $user['joindate'] = date('Y-m-d', $user['joindate']);
  864. if ($user['endtime'] == USER_ENDTIME_GROUP_EMPTY_TYPE || $user['endtime'] == USER_ENDTIME_GROUP_UNLIMIT_TYPE) {
  865. $user['endtime'] = '永久有效';
  866. } else {
  867. $user['endtime'] = $user['endtime'] <= TIMESTAMP ? '服务已到期' : date('Y-m-d', intval($user['endtime']));
  868. }
  869. $user['module_num'] = array();
  870. if ($user['founder_groupid'] == ACCOUNT_MANAGE_GROUP_VICE_FOUNDER) {
  871. $group = empty($founder_groups[$user['groupid']]) ? array() : $founder_groups[$user['groupid']];
  872. } else {
  873. $group = empty($groups[$user['groupid']]) ? array() : $groups[$user['groupid']];
  874. }
  875. if ($founder_list) {
  876. $user['account_nums'] = permission_user_account_num($user['uid']);
  877. }
  878. if (empty($user['bind_console_name'])) {
  879. $user['bind_console_name'] = '--';
  880. }
  881. $user['groupname'] = empty($group['name']) ? '' : $group['name'];
  882. unset($user);
  883. unset($group);
  884. }
  885. unset($groups);
  886. unset($founder_groups);
  887. return $users;
  888. }
  889. function user_info_check($user) {
  890. if (!empty($user['username'])) {
  891. if (!safe_gpc_string($user['username'])) {
  892. return error(-1, '必须输入用户名,格式为 3-30 位字符,可以包括汉字、字母(不区分大小写)、数字、下划线和句点。');
  893. }
  894. if (user_check(array('username' => $user['username']))) {
  895. return error(-2, '非常抱歉,此用户名已经被注册,你需要更换注册名称!');
  896. }
  897. }
  898. if (!empty($user['password']) && !empty($user['repassword'])) {
  899. $check_pass = safe_check_password(safe_gpc_string($user['password']));
  900. if (is_error($check_pass)) {
  901. return $check_pass;
  902. }
  903. if (trim($user['password']) !== trim($user['repassword'])) {
  904. return error(-4, '两次密码不一致!');
  905. }
  906. }
  907. return error(0, '');
  908. }
  909. function user_info_save($user, $is_founder_group = false) {
  910. global $_W;
  911. $check_result = user_info_check($user);
  912. if (is_error($check_result)) {
  913. return $check_result;
  914. }
  915. if (intval($user['groupid'])) {
  916. if ($is_founder_group) {
  917. $group = user_founder_group_detail_info($user['groupid']);
  918. } else {
  919. $group = user_group_detail_info($user['groupid']);
  920. }
  921. if (empty($group)) {
  922. $timelimit = 0;
  923. } else {
  924. $timelimit = intval($group['timelimit']);
  925. }
  926. } else {
  927. $timelimit = 0;
  928. }
  929. $timeadd = 0;
  930. if ($timelimit > 0) {
  931. $timeadd = strtotime($timelimit . ' days');
  932. }
  933. if (user_is_vice_founder() && !empty($_W['user']['endtime']) && $_W['user']['endtime'] > time()) {
  934. $timeadd = !empty($timeadd) ? min($timeadd, $_W['user']['endtime']) : $_W['user']['endtime'];
  935. }
  936. if (empty($timeadd)) {
  937. $user['endtime'] = max(0, $user['endtime']);
  938. } else {
  939. $user['endtime'] = empty($user['endtime']) ? $timeadd : min($timeadd, $user['endtime']);
  940. }
  941. unset($user['vice_founder_name']);
  942. unset($user['repassword']);
  943. $user_add_id = user_register($user, 'admin');
  944. if (empty($user_add_id)) {
  945. return error(-1, '增加失败,请稍候重试或联系网站管理员解决!');
  946. }
  947. return array('uid' => $user_add_id);
  948. }
  949. function user_detail_formate($profile) {
  950. if (!empty($profile)) {
  951. $profile['reside'] = array(
  952. 'province' => $profile['resideprovince'],
  953. 'city' => $profile['residecity'],
  954. 'district' => $profile['residedist']
  955. );
  956. $profile['birth'] = array(
  957. 'year' => $profile['birthyear'],
  958. 'month' => $profile['birthmonth'],
  959. 'day' => $profile['birthday'],
  960. );
  961. $profile['avatar'] = tomedia($profile['avatar']);
  962. $profile['resides'] = $profile['resideprovince'] . $profile['residecity'] . $profile['residedist'] ;
  963. $profile['births'] = ($profile['birthyear'] ? $profile['birthyear'] : '--') . '年' . ($profile['birthmonth'] ? $profile['birthmonth'] : '--') . '月' . ($profile['birthday'] ? $profile['birthday'] : '--') . '日';
  964. }
  965. return $profile;
  966. }
  967. function user_support_urls() {
  968. global $_W;
  969. load()->classs('oauth2/oauth2client');
  970. $types = OAuth2Client::supportLoginType();
  971. $login_urls = array();
  972. foreach ($types as $type) {
  973. if (!empty($_W['setting']['thirdlogin'][$type]['authstate'])) {
  974. $login_urls[$type] = OAuth2Client::create($type, $_W['setting']['thirdlogin'][$type]['appid'], $_W['setting']['thirdlogin'][$type]['appsecret'])->showLoginUrl();
  975. }
  976. }
  977. if (empty($login_urls)) {
  978. $login_urls['system'] = true;
  979. }
  980. return $login_urls;
  981. }
  982. function user_borrow_oauth_account_list() {
  983. global $_W;
  984. $user_have_accounts = uni_user_accounts($_W['uid']);
  985. $oauth_accounts = array();
  986. $jsoauth_accounts = array();
  987. if (!empty($user_have_accounts)) {
  988. foreach ($user_have_accounts as $account) {
  989. if (!empty($account['key']) && (!empty($account['secret']) || $account['type'] == ACCOUNT_TYPE_OFFCIAL_AUTH)) {
  990. if (in_array($account['level'], array(ACCOUNT_SERVICE_VERIFY))) {
  991. $oauth_accounts[$account['acid']] = $account['name'];
  992. }
  993. if (in_array($account['level'], array(ACCOUNT_SUBSCRIPTION_VERIFY, ACCOUNT_SERVICE_VERIFY))) {
  994. $jsoauth_accounts[$account['acid']] = $account['name'];
  995. }
  996. }
  997. }
  998. }
  999. return array(
  1000. 'oauth_accounts' => $oauth_accounts,
  1001. 'jsoauth_accounts' => $jsoauth_accounts
  1002. );
  1003. }
  1004. function user_founder_templates($founder_groupid) {
  1005. $group_detail_info = user_founder_group_detail_info($founder_groupid);
  1006. if (empty($group_detail_info) || empty($group_detail_info['package'])) {
  1007. return array();
  1008. }
  1009. if (in_array(-1, $group_detail_info['package'])) {
  1010. $template_list = table('modules')->getAllTemplates();
  1011. return $template_list;
  1012. }
  1013. $template_list = array();
  1014. foreach ($group_detail_info['package'] as $uni_group) {
  1015. if (!empty($group_detail_info['package_detail'][$uni_group]['templates'])) {
  1016. $template_list = array_merge($template_list, $group_detail_info['package_detail'][$uni_group]['templates']);
  1017. }
  1018. }
  1019. return $template_list;
  1020. }
  1021. function user_is_bind() {
  1022. global $_W;
  1023. if (!empty($_W['isw7_request']) || !empty($_W['isadmin'])) {
  1024. return true;
  1025. }
  1026. load()->classs('oauth2/oauth2client');
  1027. return OAuth2Client::create('console')->isbind();
  1028. }
  1029. function user_check_mobile($mobile) {
  1030. if (empty($mobile)) {
  1031. return error(-1, '手机号不能为空');
  1032. }
  1033. if (!preg_match(REGULAR_MOBILE, $mobile)) {
  1034. return error(-1, '手机号格式不正确');
  1035. }
  1036. $find_mobile = table('users_profile')->getByMobile($mobile);
  1037. if (empty($find_mobile)) {
  1038. return error(-1, '系统内无此手机号');
  1039. }
  1040. return $find_mobile;
  1041. }
  1042. function user_change_welcome_status($uid, $welcome_status) {
  1043. if (empty($uid)) {
  1044. return true;
  1045. }
  1046. $user_table = table('users');
  1047. $user_table->fillWelcomeStatus($welcome_status)->whereUid($uid)->save();
  1048. return true;
  1049. }
  1050. function user_after_login_link() {
  1051. global $_W;
  1052. $url = '';
  1053. $type = WELCOME_DISPLAY_TYPE;
  1054. if (!empty($_W['user']['welcome_link'])) {
  1055. $type = $_W['user']['welcome_link'];
  1056. }
  1057. switch ($type) {
  1058. case WELCOME_DISPLAY_TYPE:
  1059. $url = './home.php';
  1060. break;
  1061. case PLATFORM_DISPLAY_TYPE:
  1062. case MODULE_DISPLAY_TYPE:
  1063. default:
  1064. $last_operate = table('users_operate_history')->where('uid', $_W['uid'])->orderby('createtime', 'DESC')->get();
  1065. if (USERS_OPERATE_TYPE_ACCOUNT == $last_operate['type']) {
  1066. $url = url('account/display/platform');
  1067. } elseif (USERS_OPERATE_TYPE_MODULE == $last_operate['type']) {
  1068. $url = url('account/display/switch', array('module_name' => $last_operate['module_name'], 'uniacid' => $last_operate['uniacid'], 'switch_uniacid' => 1));
  1069. }
  1070. break;
  1071. }
  1072. if (empty($url)) {
  1073. $url = './home.php';
  1074. }
  1075. return $url;
  1076. }
  1077. function user_available_extra_fields() {
  1078. $default_field = array('realname', 'births', 'qq', 'mobile', 'address', 'resides');
  1079. $fields = table('core_profile_fields')->getall();
  1080. $extra_fields = array();
  1081. if (!empty($fields) && is_array($fields)) {
  1082. foreach ($fields as $field_info) {
  1083. if ($field_info['available'] == 1 && $field_info['showinregister'] == 1 && !in_array($field_info['field'], $default_field)) {
  1084. $extra_fields[] = $field_info;
  1085. }
  1086. }
  1087. }
  1088. return $extra_fields;
  1089. }
  1090. function user_lastuse_module_default_account() {
  1091. return table('users_lastuse')->getDefaultModulesAccount();
  1092. }
  1093. function user_role_title($role = '') {
  1094. $data = array(
  1095. ACCOUNT_MANAGE_NAME_FOUNDER => '创始人',
  1096. ACCOUNT_MANAGE_NAME_VICE_FOUNDER => '副创始人',
  1097. ACCOUNT_MANAGE_NAME_OWNER => '主管理员',
  1098. ACCOUNT_MANAGE_NAME_MANAGER => '管理员',
  1099. ACCOUNT_MANAGE_NAME_OPERATOR => '操作员',
  1100. ACCOUNT_MANAGE_NAME_CLERK => '店员',
  1101. );
  1102. if (!empty($role)) {
  1103. return empty($data[$role]) ? '' : $data[$role];
  1104. }
  1105. return $data;
  1106. }
  1107. function user_save_operate_history($type, $value) {
  1108. global $_W;
  1109. $vaild_type = array(USERS_OPERATE_TYPE_ACCOUNT, USERS_OPERATE_TYPE_MODULE);
  1110. if (!in_array($type, $vaild_type)) {
  1111. return false;
  1112. }
  1113. $data = array('uid' => $_W['uid'], 'type' => $type);
  1114. if (USERS_OPERATE_TYPE_ACCOUNT == $type) {
  1115. $data['uniacid'] = $value;
  1116. } elseif (USERS_OPERATE_TYPE_MODULE == $type) {
  1117. $data['module_name'] = $value;
  1118. $data['uniacid'] = $_W['uniacid'];
  1119. }
  1120. table('users_operate_history')->deleteByUidTypeOperate($data);
  1121. $data['createtime'] = TIMESTAMP;
  1122. $result = table('users_operate_history')->fill($data)->save();
  1123. if ($result) {
  1124. return true;
  1125. } else {
  1126. return false;
  1127. }
  1128. }
  1129. function user_save_operate_star($type, $uniacid, $module_name) {
  1130. global $_W;
  1131. if (!in_array($type, array(USERS_OPERATE_TYPE_ACCOUNT, USERS_OPERATE_TYPE_MODULE)) || empty($uniacid)) {
  1132. return error(-1, '参数不合法!');
  1133. }
  1134. if (USERS_OPERATE_TYPE_MODULE == $type) {
  1135. if (!empty($module_name) && !module_exist_in_account($module_name, $uniacid)) {
  1136. return error(-1, '平台账号无该模块权限,请更新缓存后重试!');
  1137. }
  1138. }
  1139. $data = array('uid' => $_W['uid'], 'uniacid' => $uniacid, 'module_name' => $module_name, 'type' => $type);
  1140. if (USERS_OPERATE_TYPE_ACCOUNT == $type) {
  1141. unset($data['module_name']);
  1142. }
  1143. $if_exists = table('users_operate_star')->where($data)->get();
  1144. if ($if_exists) {
  1145. $result = table('users_operate_star')->where($data)->delete();
  1146. } else {
  1147. $data['createtime'] = TIMESTAMP;
  1148. $maxrank = table('users_operate_star')->getMaxRank();
  1149. $data['rank'] = intval($maxrank) + 1;
  1150. $result = table('users_operate_star')->fill($data)->save();
  1151. }
  1152. if ($result) {
  1153. return error(0, '');
  1154. } else {
  1155. return error(-1, '设置失败!');
  1156. }
  1157. }
  1158. function user_account_delete($uniacid) {
  1159. if (empty($uniacid)) {
  1160. return false;
  1161. }
  1162. $mc_oauth_fans = pdo_getall('mc_oauth_fans', array('uniacid' => $uniacid), array('id', 'oauth_openid'));
  1163. if (!empty($mc_oauth_fans)) {
  1164. $ids = $openids = $uids = array();
  1165. foreach ($mc_oauth_fans as $key => $oauth_openid) {
  1166. $ids[] = $oauth_openid['id'];
  1167. if (empty($oauth_openid['oauth_openid'])) {
  1168. continue;
  1169. }
  1170. $openids[] = $oauth_openid['oauth_openid'];
  1171. }
  1172. if (!empty($ids)) {
  1173. pdo_delete('mc_oauth_fans', array('id' => $ids, 'uniacid' => $uniacid));
  1174. }
  1175. if (!empty($openids)) {
  1176. $mapping_fans = pdo_getall('mc_mapping_fans', array('uniacid' => $uniacid, 'openid' => $openids), array('uid'));
  1177. $uids = array_filter(array_column($mapping_fans, 'uid'));
  1178. pdo_delete('mc_mapping_fans', array('uniacid' => $uniacid, 'openid' => $openids));
  1179. }
  1180. if (!empty($uids)) {
  1181. pdo_delete('mc_members', array('uniacid' => $uniacid, 'uid' => $uids));
  1182. }
  1183. }
  1184. return true;
  1185. }