module-link-uniacid.ctrl.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. $dos = array('module_link_uniacid', 'search_link_account', 'module_unlink_uniacid');
  8. $do = in_array($do, $dos) ? $do : 'module_link_uniacid';
  9. if ($do == 'module_link_uniacid') {
  10. if (checksubmit('submit')) {
  11. $module_name = trim($_GPC['module_name']);
  12. $uniacid = intval($_GPC['uniacid']);
  13. if (empty($module_name) || empty($uniacid)) {
  14. iajax('1', '参数错误!');
  15. }
  16. $module = module_fetch($module_name);
  17. if (empty($module)) {
  18. iajax('1', '模块不存在!');
  19. }
  20. $link_uniacid_table = table('uni_link_uniacid');
  21. $sub_uniacids = $link_uniacid_table->getSubUniacids($_W['uniacid'], $module_name);
  22. if (!empty($sub_uniacids)) {
  23. iajax('1', '模块已被其他账号关联!');
  24. }
  25. $link_uniacid_table->fill(array(
  26. 'uniacid' => $_W['uniacid'],
  27. 'link_uniacid' => $uniacid,
  28. 'module_name' => $module_name,
  29. ));
  30. $main_uniacid = $link_uniacid_table->getMainUniacid($_W['uniacid'], $module_name);
  31. if (!empty($main_uniacid)) {
  32. $link_uniacid_table->searchWithUniacidModulenameVersionid($_W['uniacid'], $module_name);
  33. }
  34. $link_uniacid_table->save();
  35. if (!empty($main_uniacid)) {
  36. cache_clean(cache_system_key('module_setting', array('module_name' => $module_name, 'uniacid' => $main_uniacid)));
  37. }
  38. cache_clean(cache_system_key('module_setting', array('module_name' => $module_name, 'uniacid' => $uniacid)));
  39. cache_build_module_info($module_name);
  40. iajax(0, '关联成功');
  41. }
  42. $modules = uni_modules();
  43. $link_uniacid_table = table('uni_link_uniacid');
  44. foreach ($modules as $key => $value) {
  45. if (!empty($value['issystem'])) {
  46. unset($modules[$key]);
  47. continue;
  48. }
  49. $has_non_other_support = true;
  50. foreach (module_support_type() as $support => $item) {
  51. if ($item['type'] == $_W['account']['type_sign'] || $item['type'] == 'welcome') {
  52. continue;
  53. }
  54. if ($value[$support] == $item['support']) {
  55. $has_non_other_support = false;
  56. break;
  57. }
  58. }
  59. if ($has_non_other_support) {
  60. unset($modules[$key]);
  61. continue;
  62. }
  63. $link_uniacid = $link_uniacid_table->getMainUniacid($_W['uniacid'], $value['name']);
  64. if (!empty($link_uniacid)) {
  65. $account = uni_fetch($link_uniacid);
  66. $modules[$key]['link_uniacid_info'] = $account->account;
  67. $modules[$key]['link_uniacid_info']['logo'] = $account->logo;
  68. continue;
  69. }
  70. $passive_link_uniacid = $link_uniacid_table->getSubUniacids($_W['uniacid'], $value['name']);
  71. if (!empty($passive_link_uniacid)) {
  72. foreach ($passive_link_uniacid as $passive_uniacid) {
  73. $modules[$key]['other_link'][] = uni_fetch($passive_uniacid);
  74. }
  75. }
  76. }
  77. template('profile/module-link-uniacid');
  78. }
  79. if ($do == 'module_unlink_uniacid') {
  80. $module_name = safe_gpc_string(trim($_GPC['module_name']));
  81. if (empty($module_name)) {
  82. iajax(-1, '参数错误!');
  83. }
  84. $module = module_fetch($module_name);
  85. if (empty($module)) {
  86. iajax(-1, '模块不存在!');
  87. }
  88. $link_uniacid_table = table('uni_link_uniacid');
  89. $main_uniacid = $link_uniacid_table->getMainUniacid($_W['uniacid'], $module_name);
  90. if (empty($main_uniacid)) {
  91. iajax(0, '删除失败!', referer());
  92. }
  93. $result = $link_uniacid_table->searchWithUniacidModulenameVersionid($_W['uniacid'], $module_name)->delete();
  94. if ($result) {
  95. cache_delete(cache_system_key('module_setting', array('module_name' => $module_name, 'uniacid' => $main_uniacid)));
  96. cache_clean(cache_system_key('module_setting', array('module_name' => $module_name, 'uniacid' => $_W['uniacid'])));
  97. cache_build_module_info($module_name);
  98. iajax(0, '删除成功!', referer());
  99. } else {
  100. iajax(0, '删除失败!', referer());
  101. }
  102. }
  103. if ($do == 'search_link_account') {
  104. $module_name = safe_gpc_string($_GPC['module_name']);
  105. $account_type_sign = safe_gpc_string($_GPC['type_sign']);
  106. if (empty($module_name) || empty($account_type_sign)) {
  107. iajax(1, '参数不能为空');
  108. }
  109. $module = module_fetch($module_name);
  110. if (empty($module)) {
  111. iajax(1, '模块不存在或已删除');
  112. }
  113. $all_account_type_sign = uni_account_type_sign();
  114. if (!empty($_W['account']) && $_W['account']->typeSign != WXAPP_TYPE_SIGN) {
  115. unset($all_account_type_sign[$_W['account']->typeSign]); }
  116. if (!in_array($account_type_sign, array_keys($all_account_type_sign))) {
  117. iajax(1, '账号类型不存在');
  118. }
  119. $link_sub_uniacids = table('uni_link_uniacid')->getAllSubUniacidsByModuleName($module_name);
  120. $account_list = uni_search_link_account($module_name, $account_type_sign, $_W['uniacid']);
  121. $account_type_info = uni_account_type();
  122. if (!empty($account_list)) {
  123. foreach ($account_list as $key => $account) {
  124. if (in_array($account['uniacid'], $link_sub_uniacids)) {
  125. unset($account_list[$key]);
  126. continue;
  127. }
  128. $account_list[$key]['type_sign'] = $account_type_info[$account['type']]['type_sign'];
  129. $account_list[$key]['type_title'] = $account_type_info[$account['type']]['title'];
  130. $account_list[$key]['logo'] = is_file(IA_ROOT . '/attachment/headimg_' . $account['acid'] . '.jpg') ? tomedia('headimg_'.$account['acid']. '.jpg').'?time='.time() : './resource/images/nopic-107.png';
  131. $account_list[$key]['module_name'] = $module_name;
  132. }
  133. }
  134. iajax(0, $account_list);
  135. }