user.mod.php 42 KB

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