人人商城

user.mod.php 34KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  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. load()->model('message');
  9. if (empty($user) || !is_array($user)) {
  10. return 0;
  11. }
  12. if (isset($user['uid'])) {
  13. unset($user['uid']);
  14. }
  15. $check_pass = safe_check_password(safe_gpc_string($user['password']));
  16. if (is_error($check_pass)) {
  17. return $check_pass;
  18. }
  19. $user['salt'] = random(8);
  20. $user['password'] = user_hash($user['password'], $user['salt']);
  21. $user['joinip'] = CLIENT_IP;
  22. $user['joindate'] = TIMESTAMP;
  23. $user['lastip'] = CLIENT_IP;
  24. $user['lastvisit'] = TIMESTAMP;
  25. if (!empty($user['owner_uid'])) {
  26. $vice_founder_info = user_single($user['owner_uid']);
  27. if (empty($vice_founder_info) || !user_is_vice_founder($vice_founder_info['uid'])) {
  28. $user['owner_uid'] = 0;
  29. }
  30. }
  31. if (empty($user['status'])) {
  32. $user['status'] = 2;
  33. }
  34. if (empty($user['type'])) {
  35. $user['type'] = USER_TYPE_COMMON;
  36. }
  37. $result = pdo_insert('users', $user);
  38. if (!empty($result)) {
  39. $user['uid'] = pdo_insertid();
  40. }
  41. $content = $user['username'] . ' ' .date("Y-m-d H:i:s") . '注册成功--' . $source;
  42. $message = array(
  43. 'status' => $user['status']
  44. );
  45. message_notice_record($content, $user['uid'], $user['uid'], MESSAGE_REGISTER_TYPE, $message);
  46. return intval($user['uid']);
  47. }
  48. function user_check($user) {
  49. if (empty($user) || !is_array($user)) {
  50. return false;
  51. }
  52. $where = ' WHERE 1 ';
  53. $params = array();
  54. if (!empty($user['uid'])) {
  55. $where .= ' AND `uid`=:uid';
  56. $params[':uid'] = intval($user['uid']);
  57. }
  58. if (!empty($user['username'])) {
  59. $where .= ' AND `username`=:username';
  60. $params[':username'] = $user['username'];
  61. }
  62. if (!empty($user['status'])) {
  63. $where .= " AND `status`=:status";
  64. $params[':status'] = intval($user['status']);
  65. }
  66. if (empty($params)) {
  67. return false;
  68. }
  69. $sql = 'SELECT `password`,`salt` FROM ' . tablename('users') . "$where LIMIT 1";
  70. $record = pdo_fetch($sql, $params);
  71. if (empty($record) || empty($record['password']) || empty($record['salt'])) {
  72. return false;
  73. }
  74. if (!empty($user['password'])) {
  75. $password = user_hash($user['password'], $record['salt']);
  76. return $password == $record['password'];
  77. }
  78. return true;
  79. }
  80. function user_is_founder($uid, $only_main_founder = false) {
  81. global $_W;
  82. $founders = explode(',', $_W['config']['setting']['founder']);
  83. if (in_array($uid, $founders)) {
  84. return true;
  85. }
  86. if (empty($only_main_founder)) {
  87. $founder_groupid = pdo_getcolumn('users', array('uid' => $uid), 'founder_groupid');
  88. if ($founder_groupid == ACCOUNT_MANAGE_GROUP_VICE_FOUNDER) {
  89. return true;
  90. }
  91. }
  92. return false;
  93. }
  94. function user_is_vice_founder($uid = 0) {
  95. global $_W;
  96. $uid = intval($uid);
  97. if (empty($uid)) {
  98. $user_info = $_W['user'];
  99. } else {
  100. $user_info = user_single($uid);
  101. }
  102. if ($user_info['founder_groupid'] == ACCOUNT_MANAGE_GROUP_VICE_FOUNDER) {
  103. return true;
  104. }
  105. return false;
  106. }
  107. function user_delete($uid, $is_recycle = false) {
  108. load()->model('cache');
  109. $user_table = table('users');
  110. if (empty($is_recycle)) {
  111. $user_table->userAccountRole(ACCOUNT_MANAGE_NAME_OWNER);
  112. $user_accounts = $user_table->userOwnedAccount($uid);
  113. if (!empty($user_accounts)) {
  114. foreach ($user_accounts as $uniacid) {
  115. cache_build_account_modules($uniacid);
  116. }
  117. }
  118. }
  119. $user_table->userAccountDelete($uid, $is_recycle);
  120. return true;
  121. }
  122. function user_single($user_or_uid) {
  123. $user = $user_or_uid;
  124. if (empty($user)) {
  125. return false;
  126. }
  127. if (is_numeric($user)) {
  128. $user = array('uid' => $user);
  129. }
  130. if (!is_array($user)) {
  131. return false;
  132. }
  133. $where = ' WHERE 1 ';
  134. $params = array();
  135. if (!empty($user['uid'])) {
  136. $where .= ' AND u.`uid`=:uid';
  137. $params[':uid'] = intval($user['uid']);
  138. }
  139. if (!empty($user['username'])) {
  140. $where .= ' AND u.`username`=:username';
  141. $params[':username'] = $user['username'];
  142. $user_exists = user_check($user);
  143. $is_mobile = preg_match(REGULAR_MOBILE, $user['username']);
  144. if (!$user_exists && !empty($user['username']) && $is_mobile) {
  145. $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";
  146. $bind_info = pdo_fetch($sql, array('bind_sign' => $user['username']));
  147. if (!is_array($bind_info) || empty($bind_info) || empty($bind_info['username'])) {
  148. return false;
  149. }
  150. $params[':username'] = $bind_info['username'];
  151. }
  152. }
  153. if (!empty($user['email'])) {
  154. $where .= ' AND u.`email`=:email';
  155. $params[':email'] = $user['email'];
  156. }
  157. if (!empty($user['status'])) {
  158. $where .= " AND u.`status`=:status";
  159. $params[':status'] = intval($user['status']);
  160. }
  161. if (empty($params)) {
  162. return false;
  163. }
  164. $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';
  165. $record = pdo_fetch($sql, $params);
  166. if (empty($record)) {
  167. return false;
  168. }
  169. if (!empty($user['password'])) {
  170. $password = user_hash($user['password'], $record['salt']);
  171. if ($password != $record['password']) {
  172. return false;
  173. }
  174. }
  175. $record['hash'] = md5($record['password'] . $record['salt']);
  176. if (!empty($record['owner_uid'])) {
  177. $record['vice_founder_name'] = pdo_getcolumn('users', array('uid' => $record['owner_uid']), 'username');
  178. }
  179. if($record['type'] == ACCOUNT_OPERATE_CLERK) {
  180. $clerk = pdo_get('activity_clerks', array('uid' => $record['uid']));
  181. if(!empty($clerk)) {
  182. $record['name'] = $clerk['name'];
  183. $record['clerk_id'] = $clerk['id'];
  184. $record['store_id'] = $clerk['storeid'];
  185. $record['store_name'] = pdo_fetchcolumn('SELECT business_name FROM ' . tablename('activity_stores') . ' WHERE id = :id', array(':id' => $clerk['storeid']));
  186. $record['clerk_type'] = '3';
  187. $record['uniacid'] = $clerk['uniacid'];
  188. }
  189. } else {
  190. $record['name'] = $record['username'];
  191. $record['clerk_id'] = $user['uid'];
  192. $record['store_id'] = 0;
  193. $record['clerk_type'] = '2';
  194. }
  195. $third_info = pdo_getall('users_bind', array('uid' => $record['uid']), array(), 'third_type');
  196. if (!empty($third_info) && is_array($third_info)) {
  197. $record['qq_openid'] = $third_info[USER_REGISTER_TYPE_QQ]['bind_sign'];
  198. $record['wechat_openid'] = $third_info[USER_REGISTER_TYPE_WECHAT]['bind_sign'];
  199. $record['mobile'] = $third_info[USER_REGISTER_TYPE_MOBILE]['bind_sign'];
  200. }
  201. return $record;
  202. }
  203. function user_update($user) {
  204. if (empty($user['uid']) || !is_array($user)) {
  205. return false;
  206. }
  207. $record = array();
  208. if (!empty($user['username'])) {
  209. $record['username'] = $user['username'];
  210. }
  211. if (!empty($user['password'])) {
  212. $record['password'] = user_hash($user['password'], $user['salt']);
  213. }
  214. if (!empty($user['lastvisit'])) {
  215. $record['lastvisit'] = (strlen($user['lastvisit']) == 10) ? $user['lastvisit'] : strtotime($user['lastvisit']);
  216. }
  217. if (!empty($user['lastip'])) {
  218. $record['lastip'] = $user['lastip'];
  219. }
  220. if (isset($user['joinip'])) {
  221. $record['joinip'] = $user['joinip'];
  222. }
  223. if (isset($user['remark'])) {
  224. $record['remark'] = $user['remark'];
  225. }
  226. if (isset($user['type'])) {
  227. $record['type'] = $user['type'];
  228. }
  229. if (isset($user['status'])) {
  230. $status = intval($user['status']);
  231. if (!in_array($status, array(1, 2))) {
  232. $status = 2;
  233. }
  234. $record['status'] = $status;
  235. }
  236. if (isset($user['groupid'])) {
  237. $record['groupid'] = $user['groupid'];
  238. }
  239. if (isset($user['starttime'])) {
  240. $record['starttime'] = $user['starttime'];
  241. }
  242. if (isset($user['endtime'])) {
  243. $record['endtime'] = $user['endtime'];
  244. }
  245. if(isset($user['lastuniacid'])) {
  246. $record['lastuniacid'] = intval($user['lastuniacid']);
  247. }
  248. if (empty($record)) {
  249. return false;
  250. }
  251. return pdo_update('users', $record, array('uid' => intval($user['uid'])));
  252. }
  253. function user_hash($passwordinput, $salt) {
  254. global $_W;
  255. $passwordinput = "{$passwordinput}-{$salt}-{$_W['config']['setting']['authkey']}";
  256. return sha1($passwordinput);
  257. }
  258. function user_level() {
  259. static $level = array(
  260. '-3' => '锁定用户',
  261. '-2' => '禁止访问',
  262. '-1' => '禁止发言',
  263. '0' => '普通会员',
  264. '1' => '管理员',
  265. );
  266. return $level;
  267. }
  268. function user_group() {
  269. global $_W;
  270. if (user_is_vice_founder()) {
  271. $condition = array(
  272. 'owner_uid' => $_W['uid'],
  273. );
  274. }
  275. $groups = pdo_getall('users_group', $condition, array('id', 'name', 'package'), 'id', 'id ASC');
  276. return $groups;
  277. }
  278. function user_founder_group() {
  279. $groups = pdo_getall('users_founder_group', array(), array('id', 'name', 'package'), 'id', 'id ASC');
  280. return $groups;
  281. }
  282. function user_group_detail_info($groupid = 0) {
  283. $group_info = array();
  284. $groupid = is_array($groupid) ? 0 : intval($groupid);
  285. if(empty($groupid)) {
  286. return $group_info;
  287. }
  288. $group_info = pdo_get('users_group', array('id' => $groupid));
  289. if (empty($group_info)) {
  290. return $group_info;
  291. }
  292. $group_info['package'] = (array)iunserializer($group_info['package']);
  293. if (!empty($group_info['package'])) {
  294. $group_info['package_detail'] = uni_groups($group_info['package']);
  295. }
  296. return $group_info;
  297. }
  298. function user_founder_group_detail_info($groupid = 0) {
  299. $group_info = array();
  300. $groupid = is_array($groupid) ? 0 : intval($groupid);
  301. if(empty($groupid)) {
  302. return $group_info;
  303. }
  304. $group_info = pdo_get('users_founder_group', array('id' => $groupid));
  305. if (empty($group_info)) {
  306. return $group_info;
  307. }
  308. $group_info['package'] = (array)iunserializer($group_info['package']);
  309. if (!empty($group_info['package'])) {
  310. $group_info['package_detail'] = uni_groups($group_info['package']);
  311. }
  312. return $group_info;
  313. }
  314. function user_account_detail_info($uid) {
  315. $account_lists = $app_user_info = $wxapp_user_info = $webapp_user_info = $xzapp_user_info = array();
  316. $uid = intval($uid);
  317. if (empty($uid)) {
  318. return $account_lists;
  319. }
  320. $account_users_info = table('account')->userOwnedAccount($uid);
  321. if (!empty($account_users_info)) {
  322. foreach ($account_users_info as $uniacid => $account) {
  323. if ($account['type'] == ACCOUNT_TYPE_OFFCIAL_NORMAL || $account['type'] == ACCOUNT_TYPE_OFFCIAL_AUTH) {
  324. $app_user_info[$uniacid] = $account;
  325. } elseif ($account['type'] == ACCOUNT_TYPE_APP_NORMAL) {
  326. $wxapp_user_info[$uniacid] = $account;
  327. } elseif ($account['type'] == ACCOUNT_TYPE_WEBAPP_NORMAL) {
  328. $webapp_user_info[$uniacid] = $account;
  329. } elseif ($account['type'] == ACCOUNT_TYPE_PHONEAPP_NORMAL) {
  330. $phoneapp_user_info[$uniacid] = $account;
  331. } elseif ($account['type'] == ACCOUNT_TYPE_XZAPP_NORMAL) {
  332. $xzapp_user_info[$uniacid] = $account;
  333. }
  334. }
  335. }
  336. $wxapps = $wechats = $webapps = $pohoneapp = $xzapp = array();
  337. if (!empty($wxapp_user_info)) {
  338. $wxapps = table('account')->accountWxappInfo(array_keys($wxapp_user_info), $uid);
  339. }
  340. if (!empty($app_user_info)) {
  341. $wechats = table('account')->accountWechatsInfo(array_keys($app_user_info), $uid);
  342. }
  343. if (!empty($webapp_user_info)) {
  344. $webapps = table('account')->accountWebappInfo(array_keys($webapp_user_info), $uid);
  345. }
  346. if (!empty($webapp_user_info)) {
  347. $pohoneapp = table('account')->accountPhoneappInfo(array_keys($webapp_user_info), $uid);
  348. }
  349. if (!empty($xzapp_user_info)) {
  350. $xzapp = table('account')->accountXzappInfo(array_keys($xzapp_user_info), $uid);
  351. }
  352. $accounts = array_merge($wxapps, $wechats, $webapps, $pohoneapp, $xzapp);
  353. if (!empty($accounts)) {
  354. foreach ($accounts as &$account_val) {
  355. $account_val['thumb'] = tomedia('headimg_'.$account_val['default_acid']. '.jpg');
  356. foreach ($account_users_info as $uniacid => $user_info) {
  357. if ($account_val['uniacid'] == $uniacid) {
  358. $account_val['type'] = $user_info['type'];
  359. if ($user_info['type'] == ACCOUNT_TYPE_APP_NORMAL || $user_info['type'] == ACCOUNT_TYPE_APP_AUTH) {
  360. $account_lists['wxapp'][$uniacid] = $account_val;
  361. } elseif ($user_info['type'] == ACCOUNT_TYPE_OFFCIAL_NORMAL || $user_info['type'] == ACCOUNT_TYPE_OFFCIAL_AUTH) {
  362. $account_lists['wechat'][$uniacid] = $account_val;
  363. } elseif ($user_info['type'] == ACCOUNT_TYPE_WEBAPP_NORMAL) {
  364. $account_lists['webapp'][$uniacid] = $account_val;
  365. } elseif ($user_info['type'] == ACCOUNT_TYPE_PHONEAPP_NORMAL) {
  366. $account_lists['phoneapp'][$uniacid] = $account_val;
  367. } elseif ($user_info['type'] == ACCOUNT_TYPE_XZAPP_NORMAL) {
  368. $account_lists['xzapp'][$uniacid] = $account_val;
  369. }
  370. }
  371. }
  372. }
  373. unset($account_val);
  374. }
  375. return $account_lists;
  376. }
  377. function user_modules($uid = 0) {
  378. global $_W;
  379. if (empty($uid)) {
  380. $uid = $_W['uid'];
  381. }
  382. $modules = cache_load(cache_system_key('user_modules', array('uid' => $uid)));
  383. if (empty($modules)) {
  384. $user_info = user_single(array ('uid' => $uid));
  385. if (empty($uid) || user_is_founder($uid, true)) {
  386. $module_list = table('modules')->searchWithRecycle();
  387. $module_list = modules_support_all(array_keys($module_list));
  388. } elseif (!empty($user_info) && $user_info['type'] == ACCOUNT_OPERATE_CLERK) {
  389. $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));
  390. if (empty($clerk_module)) {
  391. return array();
  392. }
  393. $module_list = array($clerk_module['type'] => $clerk_module['type']);
  394. $module_list = modules_support_all(array_keys($module_list));
  395. } elseif (!empty($user_info) && empty($user_info['groupid'])) {
  396. $module_list = pdo_getall('modules', array('issystem' => 1), array('name'), 'name');;
  397. $module_list = modules_support_all(array_keys($module_list));
  398. } else {
  399. if ($user_info['founder_groupid'] == ACCOUNT_MANAGE_GROUP_VICE_FOUNDER) {
  400. $user_group_info = user_founder_group_detail_info($user_info['groupid']);
  401. } else {
  402. $user_group_info = user_group_detail_info($user_info['groupid']);
  403. }
  404. $packageids = $user_group_info['package'];
  405. if (!empty($packageids) && in_array('-1', $packageids)) {
  406. $module_list = table('modules')->searchWithRecycle();
  407. $module_list = modules_support_all(array_keys($module_list));
  408. } else {
  409. $module_list = array();
  410. $package_group = (array) pdo_getall('uni_group', array('id' => $packageids));
  411. $package_group[] = pdo_get('uni_group', array('uid' => $uid)); if (!empty($package_group)) {
  412. foreach ($package_group as $row) {
  413. if (empty($row)) {
  414. continue;
  415. }
  416. $row['modules'] = iunserializer($row['modules']);
  417. if (!empty($row['modules'])) {
  418. foreach ($row['modules'] as $type => $modulenames) {
  419. foreach ($modulenames as $name) {
  420. switch ($type) {
  421. case 'modules':
  422. $module_list[$name][] = MODULE_SUPPORT_ACCOUNT_NAME;
  423. break;
  424. case 'wxapp':
  425. $module_list[$name][] = MODULE_SUPPORT_WXAPP_NAME;
  426. break;
  427. case 'webapp':
  428. $module_list[$name][] = MODULE_SUPPORT_WEBAPP_NAME;
  429. break;
  430. case 'xzapp':
  431. $module_list[$name][] = MODULE_SUPPORT_XZAPP_NAME;
  432. break;
  433. case 'phoneapp':
  434. $module_list[$name][] = MODULE_SUPPORT_PHONEAPP_NAME;
  435. break;
  436. }
  437. }
  438. }
  439. }
  440. }
  441. }
  442. }
  443. }
  444. $modules = array();
  445. if (!empty($module_list)) {
  446. $have_plugin_module = array();
  447. if (pdo_tableexists('modules_plugin')) {
  448. $plugin_list = pdo_getall('modules_plugin', array('name' => array_keys($module_list)), array());
  449. if (!empty($plugin_list)) {
  450. foreach ($plugin_list as $plugin) {
  451. $have_plugin_module[$plugin['main_module']][$plugin['name']] = $module_list[$plugin['name']];
  452. unset($module_list[$plugin['name']]);
  453. }
  454. }
  455. }
  456. if (!empty($module_list)) {
  457. foreach ($module_list as $module => $support) {
  458. $modules[$module] = $support;
  459. if (!empty($have_plugin_module[$module])) {
  460. foreach ($have_plugin_module[$module] as $plugin => $plugin_support) {
  461. $modules[$plugin] = $plugin_support;
  462. }
  463. }
  464. }
  465. }
  466. }
  467. cache_write(cache_system_key('user_modules', array('uid' => $uid)), $modules);
  468. }
  469. $module_list = array();
  470. if (!empty($modules)) {
  471. foreach ($modules as $module => $support) {
  472. $module_info = module_fetch($module);
  473. if (!user_is_founder($_W['uid'], true) &&
  474. $module_info[MODULE_SUPPORT_SYSTEMWELCOME_NAME] == MODULE_SUPPORT_SYSTEMWELCOME &&
  475. $module_info[MODULE_SUPPORT_ACCOUNT_NAME] != MODULE_SUPPORT_ACCOUNT &&
  476. $module_info[MODULE_SUPPORT_WXAPP_NAME] != MODULE_SUPPORT_WXAPP &&
  477. $module_info[MODULE_SUPPORT_WEBAPP_NAME] != MODULE_SUPPORT_WEBAPP &&
  478. $module_info[MODULE_SUPPORT_PHONEAPP_NAME] != MODULE_SUPPORT_PHONEAPP) {
  479. continue;
  480. }
  481. if ($support !== 'all') {
  482. if ($module_info[MODULE_SUPPORT_ACCOUNT_NAME] == MODULE_SUPPORT_ACCOUNT && !in_array(MODULE_SUPPORT_ACCOUNT_NAME, $support)) {
  483. $module_info[MODULE_SUPPORT_ACCOUNT_NAME] = MODULE_NONSUPPORT_ACCOUNT;
  484. }
  485. if ($module_info[MODULE_SUPPORT_WXAPP_NAME] == MODULE_SUPPORT_WXAPP && !in_array(MODULE_SUPPORT_WXAPP_NAME, $support)) {
  486. $module_info[MODULE_SUPPORT_WXAPP_NAME] = MODULE_NONSUPPORT_WXAPP;
  487. }
  488. if ($module_info[MODULE_SUPPORT_WEBAPP_NAME] == MODULE_SUPPORT_WEBAPP && !in_array(MODULE_SUPPORT_WEBAPP_NAME, $support)) {
  489. $module_info[MODULE_SUPPORT_WEBAPP_NAME] = MODULE_NOSUPPORT_WEBAPP;
  490. }
  491. if ($module_info[MODULE_SUPPORT_XZAPP_NAME] == MODULE_SUPPORT_XZAPP && !in_array(MODULE_SUPPORT_XZAPP_NAME, $support)) {
  492. $module_info[MODULE_SUPPORT_XZAPP_NAME] = MODULE_NOSUPPORT_XZAPP;
  493. }
  494. if ($module_info[MODULE_SUPPORT_PHONEAPP_NAME] == MODULE_SUPPORT_PHONEAPP && !in_array(MODULE_SUPPORT_PHONEAPP_NAME, $support)) {
  495. $module_info[MODULE_SUPPORT_PHONEAPP_NAME] = MODULE_NOSUPPORT_PHONEAPP;
  496. }
  497. }
  498. $module_list[$module] = $module_info;
  499. }
  500. }
  501. return $module_list;
  502. }
  503. function modules_support_all($modulenames) {
  504. if (empty($modulenames)) {
  505. return array();
  506. }
  507. $data = array();
  508. foreach ($modulenames as $name) {
  509. $data[$name] = 'all';
  510. }
  511. return $data;
  512. }
  513. function user_login_forward($forward = '') {
  514. global $_W, $_GPC;
  515. load()->model('module');
  516. $login_forward = trim($forward);
  517. $login_location = array(
  518. 'account' => url('home/welcome'),
  519. 'wxapp' => url('wxapp/version/home'),
  520. 'module' => url('module/display'),
  521. 'webapp' => url('webapp/home'),
  522. 'phoneapp' => url('phoneapp/display/home'),
  523. );
  524. if (!empty($forward)) {
  525. return $login_forward;
  526. }
  527. if (empty($_W['isfounder']) || user_is_vice_founder()) {
  528. if (!empty($_W['user']['endtime']) && $_W['user']['endtime'] < TIMESTAMP) {
  529. return url('user/profile');
  530. }
  531. }
  532. if (user_is_founder($_W['uid']) && !user_is_vice_founder($_W['uid'])) {
  533. return url('home/welcome/system');
  534. }
  535. if (user_is_vice_founder()) {
  536. return url('account/manage', array('account_type' => 1));
  537. }
  538. if ($_W['user']['type'] == ACCOUNT_OPERATE_CLERK) {
  539. return url('module/display');
  540. }
  541. $url = user_after_login_link();
  542. if (!empty($url)) {
  543. return $url;
  544. }
  545. $login_forward = url('account/display');
  546. $visit_key = '__lastvisit_' . $_W['uid'];
  547. if (!empty($_GPC[$visit_key])) {
  548. $last_visit = explode(',', $_GPC[$visit_key]);
  549. $last_visit_uniacid = intval($last_visit[0]);
  550. $last_visit_url = url_params($last_visit[1]);
  551. if ($last_visit_url['c'] == 'site' && in_array($last_visit_url['a'], array('entry', 'nav')) ||
  552. $last_visit_url['c'] == 'platform' && in_array($last_visit_url['a'], array('cover', 'reply')) && !in_array($last_visit_url['m'], module_system()) ||
  553. $last_visit_url['c'] == 'module' && in_array($last_visit_url['a'], array('manage-account', 'permission', 'display'))) {
  554. return $login_location['module'];
  555. } else {
  556. if ($last_visit_url['c'] == 'wxapp') {
  557. return $last_visit_url['a'] == 'display' ? url('account/display', array('type' => WXAPP_TYPE_SIGN)) : $login_location['wxapp'];
  558. }
  559. $account_info = uni_fetch($last_visit_uniacid);
  560. if (empty($account_info) || $last_visit_url['c'] == 'account' && $last_visit_url['a'] == 'display') {
  561. return $login_forward;
  562. }
  563. if (in_array($account_info['type'], array(ACCOUNT_TYPE_OFFCIAL_NORMAL, ACCOUNT_TYPE_OFFCIAL_AUTH))) {
  564. return $login_location['account'];
  565. }
  566. if ($account_info['type'] == ACCOUNT_TYPE_APP_NORMAL) {
  567. return $login_location['wxapp'];
  568. }
  569. if ($account_info['type'] == ACCOUNT_TYPE_WEBAPP_NORMAL) {
  570. return $login_location['webapp'];
  571. }
  572. if ($account_info['type'] == ACCOUNT_TYPE_PHONEAPP_NORMAL) {
  573. return $login_location['phoneapp'];
  574. }
  575. }
  576. }
  577. if (!empty($_W['uniacid']) && !empty($_W['account'])) {
  578. $permission = permission_account_user_role($_W['uid'], $_W['uniacid']);
  579. if (empty($permission)) {
  580. return $login_forward;
  581. }
  582. if ($_W['account']['type'] == ACCOUNT_TYPE_OFFCIAL_NORMAL || $_W['account']['type'] == ACCOUNT_TYPE_OFFCIAL_AUTH) {
  583. $login_forward = url('home/welcome');
  584. } elseif ($_W['account']['type'] == ACCOUNT_TYPE_APP_NORMAL) {
  585. $login_forward = url('wxapp/display/home');
  586. } elseif ($_W['account']['type'] == ACCOUNT_TYPE_WEBAPP_NORMAL) {
  587. $login_forward = url('webapp/home/display');
  588. } elseif ($_W['account']['type'] == ACCOUNT_TYPE_PHONEAPP_NORMAL) {
  589. $login_forward = url('phoneapp/display/home');
  590. }
  591. }
  592. return $login_forward;
  593. }
  594. function user_invite_register_url($uid = 0) {
  595. global $_W;
  596. if (empty($uid)) {
  597. $uid = $_W['uid'];
  598. }
  599. return $_W['siteroot'] . 'web/index.php?c=user&a=register&owner_uid=' . $uid;
  600. }
  601. function user_save_group($group_info) {
  602. global $_W;
  603. $group_table = table('group');
  604. $name = trim($group_info['name']);
  605. if (empty($name)) {
  606. return error(-1, '用户权限组名不能为空');
  607. }
  608. $group_table->searchWithName($name);
  609. if (!empty($group_info['id'])) {
  610. $group_table->searchWithNoId($group_info['id']);
  611. }
  612. $name_exist = $group_table->searchGroup();
  613. if (!empty($name_exist)) {
  614. return error(-1, '用户权限组名已存在!');
  615. }
  616. if (user_is_vice_founder()) {
  617. $group_table->searchWithId($_W['user']['groupid']);
  618. $founder_info = $group_table->searchGroup(true);
  619. if ($group_info['maxaccount'] > $founder_info['maxaccount']) {
  620. return error(-1, '当前用户组的公众号个数不能超过' . $founder_info['maxaccount'] . '个!');
  621. }
  622. if ($group_info['maxwxapp'] > $founder_info['maxwxapp']) {
  623. return error(-1, '当前用户组的小程序个数不能超过' . $founder_info['maxwxapp'] . '个!');
  624. }
  625. if ($group_info['maxwebapp'] > $founder_info['maxwebapp']) {
  626. return error(-1, '当前用户组的PC个数不能超过' . $founder_info['maxwebapp'] . '个!');
  627. }
  628. if ($group_info['maxphoneapp'] > $founder_info['maxphoneapp']) {
  629. return error(-1, '当前用户组的APP个数不能超过' . $founder_info['maxphoneapp'] . '个!');
  630. }
  631. if ($group_info['maxxzapp'] > $founder_info['maxxzapp']) {
  632. return error(-1, '当前用户组的熊掌号个数不能超过' . $founder_info['maxxzapp'] . '个!');
  633. }
  634. if ($group_info['maxaliapp'] > $founder_info['maxaliapp']) {
  635. return error(-1, '当前用户组的支付宝小程序个数不能超过' . $founder_info['maxaliapp'] . '个!');
  636. }
  637. }
  638. if (!empty($group_info['package'])) {
  639. foreach ($group_info['package'] as $value) {
  640. $package[] = intval($value);
  641. }
  642. }
  643. $group_info['package'] = iserializer($package);
  644. if (user_is_vice_founder()) {
  645. $group_info['owner_uid'] = $_W['uid'];
  646. }
  647. if (empty($group_info['id'])) {
  648. pdo_insert('users_group', $group_info);
  649. } else {
  650. pdo_update('users_group', $group_info, array('id' => $group_info['id']));
  651. }
  652. return error(0, '添加成功');
  653. }
  654. function user_save_founder_group($group_info) {
  655. $name = trim($group_info['name']);
  656. if (empty($name)) {
  657. return error(-1, '用户权限组名不能为空');
  658. }
  659. if (!empty($group_info['id'])) {
  660. $name_exist = pdo_get('users_founder_group', array('id <>' => $group_info['id'], 'name' => $name));
  661. } else {
  662. $name_exist = pdo_get('users_founder_group', array('name' => $name));
  663. }
  664. if (!empty($name_exist)) {
  665. return error(-1, '用户权限组名已存在!');
  666. }
  667. if (!empty($group_info['package'])) {
  668. foreach ($group_info['package'] as $value) {
  669. $package[] = intval($value);
  670. }
  671. }
  672. $group_info['package'] = iserializer($package);
  673. if (empty($group_info['id'])) {
  674. pdo_insert('users_founder_group', $group_info);
  675. } else {
  676. pdo_update('users_founder_group', $group_info, array('id' => $group_info['id']));
  677. }
  678. return error(0, '添加成功');
  679. }
  680. function user_group_format($lists) {
  681. if (empty($lists)) {
  682. return $lists;
  683. }
  684. $all_package = array();
  685. foreach ($lists as $key => $group) {
  686. if (empty($group['package'])) {
  687. continue;
  688. }
  689. $package = iunserializer($group['package']);
  690. if (!is_array($package)) {
  691. continue;
  692. }
  693. $all_package = array_merge($all_package, $package);
  694. }
  695. $group_package = uni_groups($all_package);
  696. foreach ($lists as $key => $group) {
  697. $package = iunserializer($group['package']);
  698. $group['package'] = array();
  699. if (is_array($package)) {
  700. foreach ($package as $packageid) {
  701. $group['package'][$packageid] = $group_package[$packageid];
  702. }
  703. }
  704. if (empty($package)) {
  705. $lists[$key]['module_nums'] = 0;
  706. $lists[$key]['wxapp_nums'] = 0;
  707. $lists[$key]['webapp_nums'] = 0;
  708. $lists[$key]['phoneapp_nums'] = 0;
  709. $lists[$key]['xzapp_nums'] = 0;
  710. continue;
  711. }
  712. if (is_array($package) && in_array(-1, $package)) {
  713. $lists[$key]['module_nums'] = -1;
  714. $lists[$key]['wxapp_nums'] = -1;
  715. $lists[$key]['webapp_nums'] = -1;
  716. $lists[$key]['phoneapp_nums'] = -1;
  717. $lists[$key]['xzapp_nums'] = -1;
  718. continue;
  719. }
  720. $names = array();
  721. $modules = array(
  722. 'modules' => array(),
  723. 'wxapp' => array(),
  724. 'webapp' => array(),
  725. 'phoneapp' => array(),
  726. 'xzapp' => array()
  727. );
  728. if (!empty($group['package'])) {
  729. foreach ($group['package'] as $package) {
  730. $names[] = $package['name'];
  731. $package['modules'] = !empty($package['modules']) && is_array($package['modules']) ? array_keys($package['modules']) : array();
  732. $package['wxapp'] = !empty($package['wxapp']) && is_array($package['wxapp']) ? array_keys($package['wxapp']) : array();
  733. $package['webapp'] = !empty($package['webapp']) && is_array($package['webapp']) ? array_keys($package['webapp']) : array();
  734. $package['phoneapp'] = !empty($package['phoneapp']) && is_array($package['phoneapp']) ? array_keys($package['phoneapp']) : array();
  735. $package['xzapp'] = !empty($package['xzapp']) && is_array($package['xzapp']) ? array_keys($package['xzapp']) : array();
  736. $modules['modules'] = array_unique(array_merge($modules['modules'], $package['modules']));
  737. $modules['wxapp'] = array_unique(array_merge($modules['wxapp'], $package['wxapp']));
  738. $modules['webapp'] = array_unique(array_merge($modules['webapp'], $package['webapp']));
  739. $modules['phoneapp'] = array_unique(array_merge($modules['phoneapp'], $package['phoneapp']));
  740. $modules['xzapp'] = array_unique(array_merge($modules['xzapp'], $package['xzapp']));
  741. }
  742. $lists[$key]['module_nums'] = count($modules['modules']);
  743. $lists[$key]['wxapp_nums'] = count($modules['wxapp']);
  744. $lists[$key]['webapp_nums'] = count($modules['webapp']);
  745. $lists[$key]['phoneapp_nums'] = count($modules['phoneapp']);
  746. $lists[$key]['xzapp_nums'] = count($modules['xzapp']);
  747. }
  748. $lists[$key]['packages'] = implode(',', $names);
  749. }
  750. return $lists;
  751. }
  752. function user_list_format($users) {
  753. if (empty($users)) {
  754. return array();
  755. }
  756. $users_table = table('users');
  757. $groups = $users_table->usersGroup();
  758. $founder_groups = $users_table->usersFounderGroup();
  759. foreach ($users as &$user) {
  760. $user['avatar'] = !empty($user['avatar']) ? $user['avatar'] : './resource/images/nopic-user.png';
  761. $user['joindate'] = date('Y-m-d', $user['joindate']);
  762. if (empty($user['endtime'])) {
  763. $user['endtime'] = '永久有效';
  764. } else {
  765. $user['endtime'] = $user['endtime'] <= TIMESTAMP ? '服务已到期' : date('Y-m-d', $user['endtime']);
  766. }
  767. $user['module_num'] =array();
  768. if ($user['founder_groupid'] == ACCOUNT_MANAGE_GROUP_VICE_FOUNDER) {
  769. $group = $founder_groups[$user['groupid']];
  770. } else {
  771. $group = $groups[$user['groupid']];
  772. }
  773. $user['maxaccount'] = $user['founder_groupid'] == 1 ? '不限' : (empty($group) ? 0 : $group['maxaccount']);
  774. $user['maxwxapp'] = $user['founder_groupid'] == 1 ? '不限' : (empty($group) ? 0 : $group['maxwxapp']);
  775. $user['maxwebapp'] = $user['founder_groupid'] == 1 ? '不限' : (empty($group) ? 0 : $group['maxwebapp']);
  776. $user['maxphoneapp'] = $user['founder_groupid'] == 1 ? '不限' : (empty($group) ? 0 : $group['maxphoneapp']);
  777. $user['maxxzapp'] = $user['founder_groupid'] == 1 ? '不限' : (empty($group) ? 0 : $group['maxxzapp']);
  778. $user['groupname'] = $group['name'];
  779. unset($user);
  780. }
  781. return $users;
  782. }
  783. function user_info_save($user, $is_founder_group = false) {
  784. global $_W;
  785. if (!preg_match(REGULAR_USERNAME, $user['username'])) {
  786. return error(-1, '必须输入用户名,格式为 3-30 位字符,可以包括汉字、字母(不区分大小写)、数字、下划线和句点。');
  787. }
  788. if (user_check(array('username' => $user['username']))) {
  789. return error(-1, '非常抱歉,此用户名已经被注册,你需要更换注册名称!');
  790. }
  791. if (istrlen($user['password']) < 8) {
  792. return error(-1, '必须输入密码,且密码长度不得低于8位。');
  793. } else {
  794. $check_pass = safe_check_password(safe_gpc_string($user['password']));
  795. if (is_error($check_pass)) {
  796. return $check_pass;
  797. }
  798. }
  799. if (trim($user['password']) !== trim($user['repassword'])) {
  800. return error(-1, '两次密码不一致!');
  801. }
  802. if (intval($user['groupid'])) {
  803. if ($is_founder_group) {
  804. $group = user_founder_group_detail_info($user['groupid']);
  805. } else {
  806. $group = user_group_detail_info($user['groupid']);
  807. }
  808. if (empty($group)) {
  809. return error(-1, '会员组不存在');
  810. }
  811. $timelimit = intval($group['timelimit']);
  812. } else {
  813. $timelimit = 0;
  814. }
  815. $timeadd = 0;
  816. if ($timelimit > 0) {
  817. $timeadd = strtotime($timelimit . ' days');
  818. }
  819. if (user_is_vice_founder() && !empty($_W['user']['endtime'])) {
  820. $timeadd = !empty($timeadd) ? min($timeadd, $_W['user']['endtime']) : $_W['user']['endtime'];
  821. }
  822. if (empty($timeadd)) {
  823. $user['endtime'] = max(0, $user['endtime']);
  824. } else {
  825. $user['endtime'] = empty($user['endtime']) ? $timeadd : min($timeadd, $user['endtime']);
  826. }
  827. if (user_is_vice_founder()) {
  828. $user['owner_uid'] = $_W['uid'];
  829. }
  830. unset($user['vice_founder_name']);
  831. unset($user['repassword']);
  832. $user_add_id = user_register($user, 'admin');
  833. if (empty($user_add_id)) {
  834. return error(-1, '增加失败,请稍候重试或联系网站管理员解决!');
  835. }
  836. return array('uid' => $user_add_id);
  837. }
  838. function user_detail_formate($profile) {
  839. if (!empty($profile)) {
  840. $profile['reside'] = array(
  841. 'province' => $profile['resideprovince'],
  842. 'city' => $profile['residecity'],
  843. 'district' => $profile['residedist']
  844. );
  845. $profile['birth'] = array(
  846. 'year' => $profile['birthyear'],
  847. 'month' => $profile['birthmonth'],
  848. 'day' => $profile['birthday'],
  849. );
  850. $profile['avatar'] = tomedia($profile['avatar']);
  851. $profile['resides'] = $profile['resideprovince'] . $profile['residecity'] . $profile['residedist'] ;
  852. $profile['births'] =($profile['birthyear'] ? $profile['birthyear'] : '--') . '年' . ($profile['birthmonth'] ? $profile['birthmonth'] : '--') . '月' . ($profile['birthday'] ? $profile['birthday'] : '--') .'日';
  853. }
  854. return $profile;
  855. }
  856. function user_support_urls() {
  857. global $_W;
  858. load()->classs('oauth2/oauth2client');
  859. $types = OAuth2Client::supportLoginType();
  860. $login_urls = array();
  861. foreach ($types as $type) {
  862. if (!empty($_W['setting']['thirdlogin'][$type]['authstate'])) {
  863. $login_urls[$type] = OAuth2Client::create($type, $_W['setting']['thirdlogin'][$type]['appid'], $_W['setting']['thirdlogin'][$type]['appsecret'])->showLoginUrl();
  864. }
  865. }
  866. if (empty($login_urls)) {
  867. $login_urls['system'] = true;
  868. }
  869. return $login_urls;
  870. }
  871. function user_borrow_oauth_account_list() {
  872. global $_W;
  873. $user_have_accounts = uni_user_accounts($_W['uid']);
  874. $oauth_accounts = array();
  875. $jsoauth_accounts = array();
  876. if(!empty($user_have_accounts)) {
  877. foreach($user_have_accounts as $account) {
  878. if(!empty($account['key']) && !empty($account['secret'])) {
  879. if (in_array($account['level'], array(ACCOUNT_SERVICE_VERIFY))) {
  880. $oauth_accounts[$account['acid']] = $account['name'];
  881. }
  882. if (in_array($account['level'], array(ACCOUNT_SUBSCRIPTION_VERIFY, ACCOUNT_SERVICE_VERIFY))) {
  883. $jsoauth_accounts[$account['acid']] = $account['name'];
  884. }
  885. }
  886. }
  887. }
  888. return array(
  889. 'oauth_accounts' => $oauth_accounts,
  890. 'jsoauth_accounts' => $jsoauth_accounts
  891. );
  892. }
  893. function user_founder_templates($founder_groupid) {
  894. $group_detail_info = user_founder_group_detail_info($founder_groupid);
  895. if (empty($group_detail_info) || empty($group_detail_info['package'])) {
  896. return array();
  897. }
  898. if (in_array(-1, $group_detail_info['package'])) {
  899. $template_list = table('sitetemplates')->getAllTemplates();
  900. return $template_list;
  901. }
  902. $template_list = array();
  903. foreach ($group_detail_info['package'] as $uni_group) {
  904. if (!empty($group_detail_info['package_detail'][$uni_group]['templates'])) {
  905. $template_list = array_merge($template_list, $group_detail_info['package_detail'][$uni_group]['templates']);
  906. }
  907. }
  908. return $template_list;
  909. }
  910. function user_is_bind() {
  911. global $_W;
  912. if (!empty($_W['setting']['copyright']['bind'])) {
  913. $complete_info = false;
  914. switch($_W['setting']['copyright']['bind']) {
  915. case 'qq' :
  916. if (!empty($_W['user']['qq_openid'])) {
  917. $complete_info = true;
  918. }
  919. break;
  920. case 'mobile' :
  921. if (!empty($_W['user']['mobile'])) {
  922. $complete_info = true;
  923. }
  924. break;
  925. case 'wechat' :
  926. if (!empty($_W['user']['wechat_openid'])) {
  927. $complete_info = true;
  928. }
  929. break;
  930. }
  931. if (empty($_W['isfounder']) && !$complete_info) {
  932. return false;
  933. }
  934. }
  935. return true;
  936. }
  937. function user_check_mobile($mobile) {
  938. if (empty($mobile)) {
  939. return error(-1, '手机号不能为空');
  940. }
  941. if (!preg_match(REGULAR_MOBILE, $mobile)) {
  942. return error(-1, '手机号格式不正确');
  943. }
  944. $user_profile = table('users');
  945. $find_mobile = $user_profile->userProfileMobile($mobile);
  946. if (empty($find_mobile)) {
  947. return error(-1, '手机号不存在');
  948. }
  949. return error(0, '手机号正确');
  950. }
  951. function user_change_welcome_status($uid, $welcome_status) {
  952. if (empty($uid)) {
  953. return true;
  954. }
  955. $user_table = table('users');
  956. $user_table->fillWelcomeStatus($welcome_status)->whereUid($uid)->save();
  957. return true;
  958. }
  959. function user_after_login_link() {
  960. global $_W;
  961. if (!empty($_W['user']['welcome_link'])) {
  962. $type = $_W['user']['welcome_link'];
  963. } else {
  964. if (!empty($_W['setting']['copyright']['welcome_link'])) {
  965. $type = $_W['setting']['copyright']['welcome_link'];
  966. } else {
  967. $type = WELCOME_DISPLAY_TYPE;
  968. }
  969. }
  970. switch ($type) {
  971. case WELCOME_DISPLAY_TYPE:
  972. $url = url('home/welcome/system_home');
  973. break;
  974. case PLATFORM_DISPLAY_TYPE:
  975. $url = url('account/display/platform');
  976. break;
  977. case MODULE_DISPLAY_TYPE:
  978. $url = url('module/display');
  979. break;
  980. default:
  981. $url = '';
  982. break;
  983. }
  984. return $url;
  985. }