人人商城

display.ctrl.php 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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('miniapp');
  9. load()->model('account');
  10. $dos = array('display', 'switch', 'getall_last_switch', 'have_permission_uniacids', 'accounts_dropdown_menu', 'rank');
  11. $do = in_array($do, $dos) ? $do : 'display';
  12. if ($do == 'display') {
  13. $user_module = array();
  14. if (!$_W['isfounder'] || user_is_vice_founder()) {
  15. $account_table = table('account');
  16. $userspermission_table = table('users_permission');
  17. $user_owned_account = $account_table->userOwnedAccount($_W['uid']);
  18. if (!empty($user_owned_account) && is_array($user_owned_account)) {
  19. foreach ($user_owned_account as $uniacid => $account) {
  20. $account_module = uni_modules_list($uniacid, $account['type']);
  21. $account_user_module = $userspermission_table->getAllUserPermission($_W['uid'], $uniacid);
  22. if ($account['type'] == ACCOUNT_TYPE_APP_NORMAL || $account['type'] == ACCOUNT_TYPE_APP_AUTH) {
  23. $wxapp_versions = pdo_getall('wxapp_versions', array('uniacid' => $uniacid), '');
  24. if (is_array($wxapp_versions) && !empty($wxapp_versions)) {
  25. $versions = array();
  26. foreach($wxapp_versions as $version) {
  27. $version_module = (array)iunserializer($version['modules']);
  28. $version_module = array_keys($version_module);
  29. $versions[] = $version_module[0];
  30. }
  31. $diffs = array_diff(array_keys($account_module), $versions);
  32. foreach($diffs as $diff) {
  33. unset($account_module[$diff]);
  34. }
  35. } else {
  36. $account_module = array();
  37. }
  38. }
  39. if (!empty($account_user_module) && is_array($account_user_module)) {
  40. $account_module = array_intersect_key($account_module, $account_user_module);
  41. }
  42. $user_module = array_merge($user_module, $account_module);
  43. }
  44. }
  45. } else {
  46. $user_module = user_modules($_W['uid']);
  47. $user_owned_account = pdo_getall('account', array('isdeleted' => 0), array(), 'uniacid');
  48. foreach($user_owned_account as $account_key => $account) {
  49. if (in_array($account['type'], array(ACCOUNT_TYPE_APP_NORMAL, ACCOUNT_TYPE_APP_AUTH, ACCOUNT_TYPE_WXAPP_WORK))) {
  50. $versions = miniapp_version_all($account['uniacid']);
  51. if (empty($versions)) {
  52. $user_owned_account[$account_key]['premission_modules'][] = '';
  53. continue;
  54. }
  55. foreach($versions as $version) {
  56. if (empty($version['modules'])) {
  57. $user_owned_account[$account_key]['premission_modules'][] = '';
  58. continue;
  59. }
  60. $module_info = current($version['modules']);
  61. $user_owned_account[$account_key]['premission_modules'][] = $module_info['name'];
  62. }
  63. $user_owned_account[$account_key]['premission_modules'] = array_unique($user_owned_account[$account_key]['premission_modules']);
  64. } else {
  65. $account_modules = uni_modules_list($account['uniacid'], $account['type']);
  66. $user_owned_account[$account_key]['premission_modules'] = array_keys($account_modules);
  67. }
  68. }
  69. foreach($user_module as $key => $module) {
  70. $show_module = false;
  71. foreach($user_owned_account as $account) {
  72. if (in_array($module['name'], $account['premission_modules'])) {
  73. $show_module = true;
  74. break;
  75. }
  76. }
  77. if ($show_module == false) {
  78. unset($user_module[$key]);
  79. }
  80. }
  81. }
  82. $module_rank = table('modules_rank')->getByModuleNameList(array_keys($user_module));
  83. $rank = array();
  84. foreach ($user_module as $module_name => $module_info) {
  85. if (!empty($module_info['issystem']) || ($module_info[MODULE_SUPPORT_SYSTEMWELCOME_NAME] == MODULE_SUPPORT_SYSTEMWELCOME && $module_info[MODULE_SUPPORT_ACCOUNT_NAME] != MODULE_SUPPORT_ACCOUNT && $module_info[MODULE_SUPPORT_WXAPP_NAME] != MODULE_SUPPORT_WXAPP && $module_info[MODULE_SUPPORT_WEBAPP_NAME] != MODULE_SUPPORT_WEBAPP && $module_info[MODULE_SUPPORT_PHONEAPP_NAME] != MODULE_SUPPORT_PHONEAPP && $module_info[MODULE_SUPPORT_XZAPP_NAME] != MODULE_SUPPORT_XZAPP)) {
  86. unset($user_module[$module_name]);
  87. } else {
  88. $rank[] = !empty($module_rank[$module_name]['rank']) ? $module_rank[$module_name]['rank'] : 0;
  89. }
  90. }
  91. array_multisort($rank, SORT_DESC, $user_module);
  92. template('module/display');
  93. }
  94. if ($do == 'rank') {
  95. $module_name = trim($_GPC['module_name']);
  96. $exist = module_fetch($module_name);
  97. if (empty($exist)) {
  98. iajax(1, '模块不存在', '');
  99. }
  100. module_rank_top($module_name);
  101. itoast('更新成功!', referer(), 'success');
  102. }
  103. if ($do == 'switch') {
  104. $module_name = trim($_GPC['module_name']);
  105. $module_info = module_fetch($module_name);
  106. $uniacid = intval($_GPC['uniacid']);
  107. $version_id = intval($_GPC['version_id']);
  108. if (empty($module_name) || empty($module_info)) {
  109. itoast('模块不存在或已经删除!', referer(), 'error');
  110. }
  111. if (empty($uniacid) && empty($version_id)) {
  112. $last_module_info = module_last_switch($module_name);
  113. if (empty($last_module_info)) {
  114. $accounts_list = module_link_uniacid_fetch($_W['uid'], $module_name);
  115. $current_account = current($accounts_list);
  116. $uniacid = $current_account['uniacid'];
  117. $version_id = $current_account['version_id'];
  118. } else {
  119. $uniacid = $last_module_info['uniacid'];
  120. $version_id = $last_module_info['version_id'];
  121. }
  122. }
  123. if (empty($uniacid) && empty($version_id)) {
  124. itoast('该模块暂无可用的公众号或小程序,请先给公众号或小程序分配该应用的使用权限', url('module/display'), 'info');
  125. }
  126. module_save_switch($module_name, $uniacid, $version_id);
  127. if (!empty($version_id)) {
  128. $version_info = miniapp_version($version_id);
  129. }
  130. if (empty($uniacid) && !empty($version_id)) {
  131. uni_account_save_switch($version_info['uniacid'], WXAPP_TYPE_SIGN);
  132. miniapp_update_last_use_version($version_info['uniacid'], $version_id);
  133. itoast('', url('account/display/switch', array('uniacid' => $uniacid, 'module' => $module_name, 'version_id' => $version_id, 'type' => ACCOUNT_TYPE_APP_NORMAL)), 'success');
  134. }
  135. if (!empty($uniacid)) {
  136. if (empty($version_id)) {
  137. itoast('', url('account/display/switch', array('uniacid' => $uniacid, 'module_name' => $module_name, 'type' => ACCOUNT_TYPE_OFFCIAL_NORMAL)), 'success');
  138. }
  139. if ($version_info['uniacid'] != $uniacid) {
  140. itoast('', url('account/display/switch', array('uniacid' => $uniacid, 'module_name' => $module_name, 'version_id' => $version_id, 'type' => ACCOUNT_TYPE_OFFCIAL_NORMAL)), 'success');
  141. } else {
  142. uni_account_save_switch($version_info['uniacid'], WXAPP_TYPE_SIGN);
  143. miniapp_update_last_use_version($version_info['uniacid'], $version_id);
  144. itoast('', url('account/display/switch', array('uniacid' => $uniacid, 'module' => $module_name, 'version_id' => $version_id, 'type' => ACCOUNT_TYPE_APP_NORMAL)), 'success');
  145. }
  146. }
  147. }
  148. if ($do == 'getall_last_switch') {
  149. set_time_limit(0);
  150. $user_module = user_modules($_W['uid']);
  151. $result = array();
  152. foreach ($user_module as $module_value) {
  153. $last_module_info = module_last_switch($module_value['name']);
  154. if (empty($last_module_info)) {
  155. $accounts_list = module_link_uniacid_fetch($_W['uid'], $module_value['name']);
  156. $current_account = current($accounts_list);
  157. $result[$module_value['name']] = array(
  158. 'app_name' => $current_account['app_name'],
  159. 'wxapp_name' => $current_account['wxapp_name'],
  160. );
  161. continue;
  162. }
  163. $account_info = uni_fetch($last_module_info['uniacid']);
  164. if ($account_info['type'] == ACCOUNT_TYPE_APP_NORMAL) {
  165. $result[$module_value['name']] = array(
  166. 'app_name' => '',
  167. 'wxapp_name' => $account_info['name']
  168. );
  169. continue;
  170. }
  171. if (!empty($last_module_info['version_id'])) {
  172. $version_info = miniapp_version($last_module_info['version_id']);
  173. $account_wxapp_info = miniapp_fetch($version_info['uniacid']);
  174. $result[$module_value['name']] = array(
  175. 'app_name' => $account_info['name'],
  176. 'wxapp_name' => $account_wxapp_info['name']
  177. );
  178. } else {
  179. $result[$module_value['name']] = array(
  180. 'app_name' => $account_info['name'],
  181. 'wxapp_name' => ''
  182. );
  183. }
  184. }
  185. iajax(0, $result);
  186. }
  187. if ($do == 'have_permission_uniacids') {
  188. $module_name = trim($_GPC['module_name']);
  189. $accounts_list = module_link_uniacid_fetch($_W['uid'], $module_name);
  190. iajax(0, $accounts_list);
  191. }
  192. if ($do == 'accounts_dropdown_menu') {
  193. $module_name = trim($_GPC['module_name']);
  194. if (empty($module_name)) {
  195. exit();
  196. }
  197. $accounts_list = module_link_uniacid_fetch($_W['uid'], $module_name);
  198. if (empty($accounts_list)) {
  199. exit();
  200. }
  201. $selected_account = array();
  202. foreach ($accounts_list as $account) {
  203. if (empty($account['uniacid']) || $account['uniacid'] != $_W['uniacid']) {
  204. continue;
  205. }
  206. if (in_array($_W['account']['type'], array(ACCOUNT_TYPE_OFFCIAL_NORMAL, ACCOUNT_TYPE_OFFCIAL_AUTH))) {
  207. if (!empty($account['version_id'])) {
  208. $version_info = miniapp_version($account['version_id']);
  209. $account['version_info'] = $version_info;
  210. }
  211. $selected_account = $account;
  212. break;
  213. } elseif (in_array($_W['account']['type'], array(ACCOUNT_TYPE_APP_NORMAL, ACCOUNT_TYPE_ALIAPP_NORMAL))) {
  214. $version_info = miniapp_version($account['version_id']);
  215. $account['version_info'] = $version_info;
  216. $selected_account = $account;
  217. break;
  218. }
  219. }
  220. foreach ($accounts_list as $key => $account) {
  221. $url = url('module/display/switch', array('uniacid' => $account['uniacid'], 'module_name' => $module_name));
  222. if (!empty($account['version_id'])) {
  223. $url .= '&version_id=' . $account['version_id'];
  224. }
  225. $accounts_list[$key]['url'] = $url;
  226. }
  227. echo template('module/dropdown-menu');
  228. exit;
  229. }