welcome.ctrl.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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. load()->model('extension');//qwj
  8. load()->model('welcome');
  9. load()->model('module');
  10. load()->model('system');
  11. load()->model('miniapp');
  12. load()->model('message');
  13. load()->model('visit');
  14. load()->model('cloud');
  15. load()->model('cache');//qwj
  16. $dos = array('platform', 'system', 'ext', 'account_ext', 'get_fans_kpi', 'get_system_upgrade', 'get_upgrade_modules', 'get_module_statistics', 'get_ads', 'get_not_installed_modules', 'system_home', 'set_top', 'set_default', 'add_welcome', 'ignore_update_module', 'get_workerorder', 'add_welcome_shortcut', 'remove_welcome_shortcut', 'build_account_modules');
  17. $do = in_array($do, $dos) ? $do : 'platform';
  18. if ($_W['highest_role'] == ACCOUNT_MANAGE_NAME_CLERK && in_array($do, array('platform', 'system_home', 'system'))) {
  19. itoast('', url('module/display'));
  20. }
  21. if ($_W['highest_role'] == ACCOUNT_MANAGE_NAME_EXPIRED && in_array($do, array('system_home'))) {
  22. cache_updatecache();
  23. itoast('', url('user/profile'));
  24. }
  25. if ($do == 'get_not_installed_modules') {
  26. cache_build_uninstalled_module();//qwj
  27. $not_installed_modules = module_uninstall_list();
  28. iajax(0, $not_installed_modules);
  29. }
  30. if ($do == 'ext' && $_GPC['m'] != 'store' && !$_GPC['system_welcome']) {
  31. if (!empty($_GPC['version_id'])) {
  32. $version_info = miniapp_version($_GPC['version_id']);
  33. }
  34. $account_api = WeAccount::createByUniacid();
  35. if (is_error($account_api)) {
  36. message($account_api['message'], url('account/display'));
  37. }
  38. $check_manange = $account_api->checkIntoManage();
  39. if (is_error($check_manange)) {
  40. itoast('', $account_api->displayUrl);
  41. }
  42. }
  43. if ($do == 'platform') {
  44. if (empty($_W['account'])) {
  45. itoast('账号信息有误!', url('account/manage'), 'info');
  46. }
  47. if (!empty($_W['account']['endtime']) && $_W['account']['endtime'] != USER_ENDTIME_GROUP_EMPTY_TYPE && $_W['account']['endtime'] != USER_ENDTIME_GROUP_UNLIMIT_TYPE && $_W['account']['endtime'] < time() && !user_is_founder($_W['uid'], true)) {
  48. itoast('平台账号已到服务期限,请联系管理员并续费', url('account/manage'), 'info');
  49. }
  50. $notices = welcome_notices_get();
  51. template('home/welcome');
  52. }
  53. if ($do == 'system') {
  54. if(!$_W['isfounder'] || user_is_vice_founder()){
  55. header('Location: ' . url('home/welcome/system_home'));
  56. exit;
  57. }
  58. $reductions = system_database_backup();
  59. if (!empty($reductions)) {
  60. $last_backup = array_shift($reductions);
  61. $last_backup_time = $last_backup['time'];
  62. $backup_days = welcome_database_backup_days($last_backup_time);
  63. } else {
  64. $backup_days = 0;
  65. }
  66. $today_start = strtotime(date('Y-m-d',time()));
  67. $yestoday_start = strtotime(date('Y-m-d',strtotime("-1 days")));
  68. $statistics_order['today'] = table('store')->getStatisticsOrderInfoByDate($today_start, $today_start + 86400);
  69. $statistics_order['yestoday'] = table('store')->getStatisticsOrderInfoByDate($yestoday_start, $yestoday_start + 86400);
  70. $system_check = cache_load(cache_system_key('system_check'));
  71. template('home/welcome-system');
  72. }
  73. if ($do =='get_module_statistics') {
  74. $install_modules = module_installed_list();
  75. $module_statistics = array(
  76. 'account' => array(
  77. 'total' => array(
  78. 'uninstall' => module_uninstall_total('account'),
  79. 'upgrade' => module_upgrade_total('account'),
  80. 'all' => 0
  81. ),
  82. ),
  83. 'wxapp' => array(
  84. 'total' => array(
  85. 'uninstall' => module_uninstall_total('wxapp'),
  86. 'upgrade' => module_upgrade_total('wxapp'),
  87. 'all' => 0,
  88. )
  89. ),
  90. );
  91. $module_statistics['account']['total']['all'] = $module_statistics['account']['total']['uninstall'] + count((array)$install_modules['account']);
  92. $module_statistics['wxapp']['total']['all'] = $module_statistics['wxapp']['total']['uninstall'] + count((array)$install_modules['wxapp']);
  93. iajax(0, $module_statistics, '');
  94. }
  95. if ($do == 'ext') {
  96. $uniacid = intval($_GPC['uniacid']);
  97. $modulename = $_GPC['m'];
  98. if (!empty($modulename)) {
  99. $_W['current_module'] = module_fetch($modulename);
  100. }
  101. define('IN_MODULE', $modulename);
  102. if ($_GPC['system_welcome'] && $_W['isfounder']) {
  103. define('SYSTEM_WELCOME_MODULE', true);
  104. $frames = buildframes('system_welcome');
  105. } else {
  106. if ($modulename != 'store' && empty($_W['current_module']['main_module']) && module_get_direct_enter_status($modulename) != STATUS_ON || $_GPC['tohome'] == STATUS_ON) {
  107. itoast('', url('module/welcome', array('m' => $modulename, 'uniacid' => $uniacid)));
  108. }
  109. $site = WeUtility::createModule($modulename);
  110. if (!is_error($site)) {
  111. $method = 'welcomeDisplay';
  112. if(method_exists($site, $method)){
  113. define('FRAME', 'module_welcome');
  114. $entries = module_entries($modulename, array('menu', 'home', 'profile', 'shortcut', 'cover', 'mine'));
  115. $site->$method($entries);
  116. exit;
  117. }
  118. }
  119. $frames = buildframes('account');
  120. }
  121. foreach ($frames['section'] as $secion) {
  122. foreach ($secion['menu'] as $menu) {
  123. if (!empty($menu['url'])) {
  124. if ($menu['module_welcome_display'] && !empty($_W['current_module']['main_module'])) {
  125. continue;
  126. }
  127. header('Location: ' . $_W['siteroot'] . 'web/' . $menu['url']);
  128. exit;
  129. }
  130. }
  131. }
  132. template('home/welcome-ext');
  133. }
  134. if ($do == 'account_ext') {
  135. $modulename = $_GPC['m'];
  136. if (!empty($modulename)) {
  137. $module_info = module_fetch($modulename);
  138. }
  139. if (empty($module_info)) {
  140. itoast('抱歉,你操作的模块不能被访问!');
  141. }
  142. $link_uniacid = table('uni_link_uniacid')->getMainUniacid($_W['uniacid'], $modulename, intval($_GPC['version_id']));
  143. $redirect_uniacid = empty($link_uniacid) ? $_W['uniacid'] : $link_uniacid;
  144. switch_save_account_display($redirect_uniacid);
  145. template('home/welcome-ext');
  146. }
  147. if ($do == 'get_fans_kpi') {
  148. uni_update_week_stat();
  149. $yesterday = date('Ymd', strtotime('-1 days'));
  150. $yesterday_stat = pdo_get('stat_fans', array('date' => $yesterday, 'uniacid' => $_W['uniacid']));
  151. $yesterday_stat['new'] = intval($yesterday_stat['new']);
  152. $yesterday_stat['cancel'] = intval($yesterday_stat['cancel']);
  153. $yesterday_stat['jing_num'] = intval($yesterday_stat['new']) - intval($yesterday_stat['cancel']);
  154. $yesterday_stat['cumulate'] = intval($yesterday_stat['cumulate']);
  155. $today_stat = pdo_get('stat_fans', array('date' => date('Ymd'), 'uniacid' => $_W['uniacid']));
  156. $today_stat['new'] = intval($today_stat['new']);
  157. $today_stat['cancel'] = intval($today_stat['cancel']);
  158. $today_stat['jing_num'] = $today_stat['new'] - $today_stat['cancel'];
  159. $today_stat['cumulate'] = intval($today_stat['jing_num']) + $yesterday_stat['cumulate'];
  160. $today_stat['cumulate'] = max(0, $today_stat['cumulate']);
  161. iajax(0, array('yesterday' => $yesterday_stat, 'today' => $today_stat, 'all' => $today_stat['cumulate']), '');
  162. }
  163. if ($do == 'get_system_upgrade') {
  164. $upgrade = welcome_get_cloud_upgrade();
  165. iajax(0, $upgrade, '');
  166. }
  167. if ($do == 'get_upgrade_modules') {
  168. $module_support_types = module_support_type();
  169. module_upgrade_info();
  170. $upgrade_modules = module_upgrade_list();
  171. if (!empty($_GPC['unstall'])) {
  172. $module_cloud_table = table('modules_cloud');
  173. $module_cloud_table->where('install_status', array(MODULE_LOCAL_UNINSTALL, MODULE_CLOUD_UNINSTALL));
  174. $module_cloud_table->orderby('buytime', 'desc');
  175. $module_cloud_table->orderby('lastupdatetime', 'asc');
  176. $unstall_moudle_list = $module_cloud_table->getall('name');
  177. if (!empty($unstall_moudle_list)) {
  178. foreach ($unstall_moudle_list as $module_key => &$module_val) {
  179. $module_val['unstall'] = 1;
  180. }
  181. }
  182. $upgrade_modules = array_merge($upgrade_modules, $unstall_moudle_list);
  183. }
  184. if (!empty($upgrade_modules)) {
  185. $modulenames = array();
  186. foreach ($upgrade_modules as $module) {
  187. if (!empty($module['name']) && !in_array($module['name'], $modulenames)) {
  188. $modulenames[] = $module['name'];
  189. }
  190. }
  191. $module_recycle_support = array();
  192. if ($modulenames) {
  193. $modules_recycle = table('modules_recycle')->getByName($modulenames, '');
  194. if (!empty($modules_recycle)) {
  195. foreach ($modules_recycle as $info) {
  196. foreach ($module_support_types as $support => $value) {
  197. if (empty($module_recycle_support[$info['name']][$support])) {
  198. $module_recycle_support[$info['name']][$support] = $info[$support];
  199. }
  200. }
  201. }
  202. }
  203. }
  204. foreach ($upgrade_modules as $key => $module) {
  205. $is_unset = true;
  206. foreach ($module_support_types as $support => $value) {
  207. if (!empty($module_recycle_support[$module['name']][$support])) {
  208. $module[$support] = $value['not_support'];
  209. }
  210. if ($module[$support] == $value['support']) {
  211. $is_unset = false;
  212. }
  213. }
  214. if ($is_unset) {
  215. unset($upgrade_modules[$key]);
  216. }
  217. }
  218. }
  219. iajax(0, $upgrade_modules, '');
  220. }
  221. if ($do == 'get_ads') {
  222. $ads = welcome_get_ads();
  223. if (is_error($ads)) {
  224. iajax(1, $ads['message']);
  225. } else {
  226. iajax(0, $ads);
  227. }
  228. }
  229. if ($do == 'system_home') {
  230. $user_info = user_single($_W['uid']);
  231. $account_num = permission_user_account_num($_W['uid']);
  232. $redirect_urls = array(
  233. array('id' => WELCOME_DISPLAY_TYPE, 'name' => '用户欢迎页'),
  234. array('id' => PLATFORM_DISPLAY_TYPE, 'name' => '平台入口'),
  235. array('id' => MODULE_DISPLAY_TYPE, 'name' => '应用入口'),
  236. );
  237. $user_founder_info = table('users_founder_own_users')->getFounderByUid($user_info['uid']);
  238. $uni_modules_table = table('uni_modules');
  239. $uni_modules_table->searchGroupbyModuleName();
  240. $own_account_modules_all = $uni_modules_table->getModulesByUid($_W['uid']);
  241. if (!empty($own_account_modules_all)) {
  242. foreach($own_account_modules_all['modules'] as $key => &$value) {
  243. $module_info = module_fetch($value['module_name']);
  244. $value['title'] = $module_info['title'];
  245. $value['logo'] = tomedia($module_info['logo']);
  246. $value['checked'] = 0;
  247. $own_account_modules_all['modules'][$key] = $value;
  248. if ($value['role'] == ACCOUNT_MANAGE_NAME_CLERK || $value['role'] == ACCOUNT_MANAGE_NAME_OPERATOR) {
  249. $user_permission_table = table('users_permission');
  250. $operator_modules_permissions = $user_permission_table->getAllUserModulePermission($_W['uid'], $value['uniacid']);
  251. $user_module_permission_info = $user_permission_table->getUserPermissionByType($_W['uid'], $value['uniacid'], $value['module_name']);
  252. if (!$user_module_permission_info && !empty($operator_modules_permissions)) {
  253. unset($own_account_modules_all['modules'][$key]);
  254. }
  255. }
  256. unset($value);
  257. }
  258. }
  259. $core_menu_shortcut_table = table('core_menu_shortcut');
  260. $user_welcome_modules = $core_menu_shortcut_table->getUserWelcomeShortcutList($_W['uid']);
  261. $last_accounts = array();
  262. $last_modules = array();
  263. if (!empty($user_welcome_modules)) {
  264. foreach ($user_welcome_modules as $info) {
  265. if (empty($info['uniacid'])) {
  266. continue;
  267. }
  268. if (!in_array($info['modulename'], array_column($own_account_modules_all['modules'], 'module_name'))) {
  269. continue;
  270. }
  271. $last_modules_account_info = uni_fetch($info['uniacid']);
  272. if (is_error($last_modules_account_info) || $last_modules_account_info['isdeleted'] == 1) {
  273. continue;
  274. }
  275. if (!empty($info['modulename'])) {
  276. $info['module'] = module_fetch($info['modulename']);
  277. $info['module']['switchurl'] = url('module/display/switch', array('module_name' => $info['modulename']));
  278. $info['account'] = $last_modules_account_info;
  279. $last_modules[$info['modulename']] = $info;
  280. }else {
  281. $info['account'] = $last_modules_account_info;
  282. $last_accounts[$info['uniacid']] = $info;
  283. }
  284. }
  285. }
  286. if (empty($last_accounts)) {
  287. $is_empty_accounts = 1;
  288. $uni_account_users_table = table('uni_account_users');
  289. $uni_account_users_table->searchWithPage(1, 5);
  290. $uni_account_users_table->searchWithUserRole(ACCOUNT_MANAGE_NAME_OWNER);
  291. $user_accounts = $uni_account_users_table->getUsableAccountsByUid($_W['uid']);
  292. if (!empty($user_accounts)) {
  293. foreach ($user_accounts as $user_account_info) {
  294. $account_info['account'] = uni_fetch($user_account_info['uniacid']);
  295. if ($account_info['account']->typeSign == WXAPP_TYPE_SIGN) {
  296. $version_info = miniapp_version_all($user_account_info['uniacid']);
  297. if (empty($version_info)) {
  298. continue;
  299. }
  300. foreach ($version_info as $version_key => $version_val) {
  301. $last_version_modules = $version_val['last_modules'] ? current($version_val['last_modules']) : array();
  302. }
  303. $modules = current($version_info[0]['modules']);
  304. $account_info['account']['need_upload'] = $last_version_modules['version'] < $modules['version'] ? 1 : 0;
  305. }
  306. if ($account_info['account']['isdeleted']) {
  307. continue;
  308. }
  309. $core_menu_shortcut_table->saveUserWelcomeShortcut($_W['uid'], $user_account_info['uniacid'], '');
  310. $last_accounts[] = $account_info;
  311. }
  312. }
  313. } else {
  314. $is_empty_accounts = 0;
  315. }
  316. if (empty($last_modules) && !empty($own_account_modules_all['modules'])) {
  317. $is_empty_modules = 1;
  318. $i = 0;
  319. foreach ($own_account_modules_all['modules'] as $m_key => $m_val) {
  320. if ($i >= 5) {
  321. break;
  322. }
  323. $core_menu_shortcut_table->saveUserWelcomeShortcut($_W['uid'], $m_val['uniacid'], $m_val['module_name']);
  324. $module_info['module'] = module_fetch($m_val['module_name']);
  325. $module_info['module']['switchurl'] = url('module/display/switch', array('module_name' => $m_val['module_name']));
  326. $module_info['account'] = uni_fetch($m_val['uniacid']);
  327. $last_modules[$m_val['module_name']] = $module_info;
  328. $i++;
  329. }
  330. } else {
  331. $is_empty_modules = 0;
  332. }
  333. $default_module_list = user_lastuse_module_default_account();
  334. if (!empty($last_modules) && !empty($default_module_list)) {
  335. foreach ($last_modules as $last_module_key => &$last_module_val) {
  336. if (in_array($last_module_key, array_keys($default_module_list))) {
  337. $last_module_val['default_uniacid'] = $default_module_list[$last_module_key]['default_uniacid'];
  338. $last_module_val['default_account_name'] = $default_module_list[$last_module_key]['default_account_name'];
  339. $last_module_val['default_account_info'] = uni_fetch($last_module_val['default_uniacid']);
  340. }
  341. }
  342. }
  343. $types = array(MESSAGE_ACCOUNT_EXPIRE_TYPE, MESSAGE_WECHAT_EXPIRE_TYPE, MESSAGE_WEBAPP_EXPIRE_TYPE, MESSAGE_USER_EXPIRE_TYPE, MESSAGE_WXAPP_MODULE_UPGRADE);
  344. $messages = pdo_getall('message_notice_log', array('uid' => $_W['uid'], 'type' => $types, 'is_read' => MESSAGE_NOREAD), array(), '', array('id desc'), 10);
  345. $messages = message_list_detail($messages);
  346. $notices = welcome_notices_get();
  347. template('home/welcome-system-home');
  348. }
  349. if ($do == 'set_top') {
  350. $id = intval($_GPC['id']);
  351. $displayorder = pdo_get('core_menu_shortcut', array('position' => 'home_welcome_system_common'), 'MAX(displayorder)');
  352. $displayorder = current($displayorder);
  353. $update_data['displayorder'] = ++$displayorder;
  354. $update_data['updatetime'] = TIMESTAMP;
  355. pdo_update('core_menu_shortcut', $update_data, array('id' => $id));
  356. iajax(0, '', referer());
  357. }
  358. if ($do == 'add_welcome_shortcut') {
  359. $core_menu_shortcut_table = table('core_menu_shortcut');
  360. $shortcuts = safe_gpc_array($_GPC['shortcuts']);
  361. if (!empty($shortcuts)) {
  362. foreach ($shortcuts as $shortcut_info) {
  363. $modulename = empty($shortcut_info['module_name']) ? '' : $shortcut_info['module_name'];
  364. $core_menu_shortcut_table->saveUserWelcomeShortcut($_W['uid'], $shortcut_info['uniacid'], $modulename);
  365. }
  366. }
  367. }
  368. if ($do == 'remove_welcome_shortcut') {
  369. $core_menu_shortcut_table = table('core_menu_shortcut');
  370. $uniacid = intval($_GPC['uniacid']);
  371. $module_name = safe_gpc_string($_GPC['module_name']);
  372. $module_name = empty($module_name) ? '' : $module_name;
  373. pdo_delete('core_menu_shortcut', array('uid' => $_W['uid'], 'uniacid' => $uniacid, 'modulename' => $module_name, 'position' => 'home_welcome_system_common'));
  374. }
  375. if ($do == 'set_default') {
  376. $uniacid = intval($_GPC['uniacid']);
  377. $module_name = safe_gpc_string($_GPC['module_name']);
  378. switch_save_module($uniacid, $module_name);
  379. iajax(0, '', '');
  380. }
  381. if ($do == 'ignore_update_module') {
  382. if (empty($_GPC['name'])) {
  383. iajax(1, '参数错误');
  384. }
  385. $module_info = module_fetch($_GPC['name']);
  386. if (empty($module_info)) {
  387. iajax(1, '参数错误');
  388. }
  389. $upgrade_version = table('modules_cloud')->getByName($module_info['name']);
  390. table('modules_ignore')->add($module_info['name'], $upgrade_version['version']);
  391. iajax(0, '');
  392. }
  393. if ($do == 'get_workerorder') {
  394. //$workorder_info = cloud_workorder();
  395. $workorder_info = '';
  396. iajax(0, $workorder_info, '');
  397. }
  398. if ($do == 'build_account_modules') {
  399. cache_build_account_modules($_W['uniacid']);
  400. iajax(0, '');
  401. }