user.mod.php 44 KB

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