display.ctrl.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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('module');
  8. load()->model('switch');
  9. load()->model('miniapp');
  10. $dos = array('display', 'switch', 'have_permission_uniacids', 'accounts_dropdown_menu', 'rank', 'set_default_account', 'switch_last_module', 'init_uni_modules');
  11. $do = in_array($do, $dos) ? $do : 'display';
  12. if ($do == 'switch_last_module') {
  13. $last_module = switch_get_module_display();
  14. if (!empty($last_module)) {
  15. $account_info = uni_fetch($last_module['uniacid']);
  16. if (!is_error($account_info) && !($account_info['endtime'] > 0 && TIMESTAMP > $account_info['endtime'] && !user_is_founder($_W['uid'], true))) {
  17. itoast('', url('account/display/switch', array('module_name' => $last_module['modulename'], 'uniacid' => $last_module['uniacid'], 'switch_uniacid' => 1, 'tohome' => intval($_GPC['tohome']))));
  18. }
  19. }
  20. $do = 'display';
  21. }
  22. if ($do == 'display') {
  23. $pageindex = max(1, intval($_GPC['page']));
  24. $pagesize = 20;
  25. //RubySn0w 修复安装新模块后直接从应用入口进入不显示此模块问题
  26. cache_build_account_modules($_W['uid']);
  27. $uni_modules_table = table('uni_modules');
  28. $module_title = safe_gpc_string($_GPC['module_title']);
  29. $module_letter = safe_gpc_string($_GPC['letter']);
  30. $uni_modules_table->searchGroupbyModuleName();
  31. $own_account_modules = array();
  32. $own_account_modules = $uni_modules_table->getModulesByUid($_W['uid']);
  33. $user_lastuse_table = table('users_lastuse');
  34. $user_lastuse_table->searchWithoutType('account_display');
  35. $user_lastuse_table->searchWithoutType('module_display');
  36. $default_module_list = $user_lastuse_table->getDefaultModulesAccount($_W['uid']);
  37. $modules_rank_table = table('modules_rank');
  38. $modules_rank_list = $modules_rank_table->getAllByUid($_W['uid']);
  39. $module_support_types = module_support_type();
  40. foreach($own_account_modules['modules'] as $account_module_name => &$account_module_info) {
  41. if ($account_module_info['role'] == ACCOUNT_MANAGE_NAME_CLERK || $account_module_info['role'] == ACCOUNT_MANAGE_NAME_OPERATOR || $account_module_info['role'] == ACCOUNT_MANAGE_NAME_MANAGER) {
  42. $user_permission_table = table('users_permission');
  43. $operator_modules_permissions = $user_permission_table->getAllUserModulePermission($_W['uid'], $account_module_info['uniacid']);
  44. $user_module_permission_info = $user_permission_table->getUserPermissionByType($_W['uid'], $account_module_info['uniacid'], $account_module_info['module_name']);
  45. if (!$user_module_permission_info && !empty($operator_modules_permissions)) {
  46. unset($own_account_modules['modules'][$account_module_name]);
  47. }
  48. }
  49. if (in_array($account_module_info['module_name'], array_keys($modules_rank_list))) {
  50. $account_module_info['rank'] = $modules_rank_list[$account_module_info['module_name']]['rank'];
  51. }
  52. if (in_array($account_module_info['module_name'], array_keys($own_account_modules['modules']))) {
  53. $account_module_info['default_uniacid'] = $default_module_list[$account_module_info['module_name']]['default_uniacid'];
  54. }
  55. if ($_W['highest_role'] == ACCOUNT_MANAGE_NAME_CLERK) {
  56. $account_module_info['uniacid'] = $account_module_info['permission_uniacid'];
  57. $account_module_info['default_uniacid'] = $account_module_info['permission_uniacid'];
  58. }
  59. $uni_account_info = uni_fetch($account_module_info['uniacid']);
  60. $account_module_info['account_name'] = $uni_account_info['name'];
  61. $account_module_info['acid'] = $uni_account_info['acid'];
  62. $account_module_info['account_type'] = $uni_account_info['account_type'];
  63. $account_module_info['account_logo'] = $uni_account_info['logo'];
  64. $uni_module_info = module_fetch($account_module_info['module_name']);
  65. $account_module_info['logo'] = tomedia($uni_module_info['logo']);
  66. $account_module_info['title'] = $uni_module_info['title'];
  67. $account_module_info['title_initial'] = $uni_module_info['title_initial'];
  68. foreach ($module_support_types as $support_type => $support_info) {
  69. $account_module_info[$support_type] = $uni_module_info[$support_type];
  70. }
  71. if (!empty($account_module_info['default_uniacid'])) {
  72. $account_module_info['default_account_name'] = $default_module_list[$account_module_info['module_name']]['default_account_name'];
  73. $account_module_info['default_account_info'] = uni_fetch($account_module_info['default_uniacid']);
  74. $account_module_info['default_account_type'] = $account_module_info['default_account_info']['type'];
  75. $account_module_info['default_account_logo'] = $account_module_info['default_account_info']['logo'];
  76. }
  77. }
  78. unset($account_module_info);
  79. $sort_arr = array();
  80. foreach ($own_account_modules['modules'] as $sort_key => $sort_val) {
  81. $sort_arr[$sort_key] = $sort_val['rank'];
  82. }
  83. array_multisort($sort_arr,SORT_DESC,$own_account_modules['modules']);
  84. $own_account_modules['system_have_modules'] = table('modules')->where('issystem !=', 1)->get();
  85. template('module/display');
  86. }
  87. if ($do == 'rank') {
  88. $module_name = trim($_GPC['module_name']);
  89. $uniacid = intval($_GPC['uniacid']);
  90. $exist = module_fetch($module_name, $uniacid);
  91. if (empty($exist)) {
  92. iajax(1, '模块不存在', '');
  93. }
  94. module_rank_top($module_name, $uniacid);
  95. itoast('更新成功!', referer(), 'success');
  96. }
  97. if ($do == 'switch') {
  98. $module_name = trim($_GPC['module_name']);
  99. $module_info = module_fetch($module_name);
  100. $module_name = empty($module_info['main_module']) ? $module_name : $module_info['main_module'];
  101. $uniacid = intval($_GPC['uniacid']);
  102. $account_info = uni_fetch($uniacid);
  103. if (empty($module_info)) {
  104. itoast('模块不存在或已经删除!', referer(), 'error');
  105. }
  106. if ($account_info->supportVersion) {
  107. $miniapp_version_info = miniapp_fetch($uniacid);
  108. $version_id = $miniapp_version_info['version']['id'];
  109. }
  110. if (empty($uniacid) && empty($version_id)) {
  111. itoast('该模块暂无可用的公众号或小程序,请先给公众号或小程序分配该应用的使用权限', url('module/display'), 'info');
  112. }
  113. if (!empty($version_id)) {
  114. $version_info = miniapp_version($version_id);
  115. miniapp_update_last_use_version($version_info['uniacid'], $version_id);
  116. $url = url('account/display/switch', array('uniacid' => $uniacid, 'module_name' => $module_name, 'version_id' => $version_id, 'switch_uniacid' => true));
  117. } else {
  118. $url = url('account/display/switch', array('uniacid' => $uniacid, 'module_name' => $module_name, 'switch_uniacid' => true));
  119. }
  120. switch_save_module_display($uniacid, $module_name);
  121. itoast('', $url, 'success');
  122. }
  123. if ($do == 'have_permission_uniacids') {
  124. $module_name = trim($_GPC['module_name']);
  125. $accounts_list = module_link_uniacid_fetch($_W['uid'], $module_name);
  126. iajax(0, $accounts_list);
  127. }
  128. if ($do == 'accounts_dropdown_menu') {
  129. $module_name = trim($_GPC['module_name']);
  130. if (empty($module_name)) {
  131. exit();
  132. }
  133. $accounts_list = module_link_uniacid_fetch($_W['uid'], $module_name);
  134. if (empty($accounts_list)) {
  135. exit();
  136. }
  137. foreach ($accounts_list as $key => $account) {
  138. $url = url('module/display/switch', array('uniacid' => $account['uniacid'], 'module_name' => $module_name));
  139. if (!empty($account['version_id'])) {
  140. $url .= '&version_id=' . $account['version_id'];
  141. }
  142. $accounts_list[$key]['url'] = $url;
  143. }
  144. echo template('module/dropdown-menu');
  145. exit;
  146. }
  147. if ($do == 'set_default_account') {
  148. $uniacid = intval($_GPC['uniacid']);
  149. $module_name = safe_gpc_string($_GPC['module_name']);
  150. if (empty($uniacid) || empty($module_name)) {
  151. iajax(-1, '设置失败!');
  152. }
  153. $result = switch_save_module($uniacid, $module_name);
  154. if ($result) {
  155. iajax(0, '设置成功!');
  156. } else {
  157. iajax(-1, '设置失败!');
  158. }
  159. }
  160. if ($do == 'init_uni_modules') {
  161. $pageindex = max(1, intval($_GPC['pageindex']));
  162. $pagesize = 20;
  163. $total = table('account')->count();
  164. $total = ceil($total/$pagesize);
  165. $init_accounts = table('account')->searchWithPage($pageindex, $pagesize)->getUniAccountList();
  166. if (empty($init_accounts)) {
  167. iajax(1, 'finished');
  168. }
  169. foreach ($init_accounts as $account) {
  170. cache_build_account_modules($account['uniacid']);
  171. }
  172. $pageindex = $pageindex + 1;
  173. iajax(0, array('pageindex' => $pageindex, 'total' => $total));
  174. }