module-link-uniacid.ctrl.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. $dos = array('module_link_uniacid', 'search_link_account', 'module_unlink_uniacid');
  9. $do = in_array($do, $dos) ? $do : 'module_link_uniacid';
  10. permission_check_account_user('wxapp_profile_module_link_uniacid');
  11. if ($do == 'module_link_uniacid') {
  12. if (checksubmit('submit')) {
  13. $uniacid = intval($_GPC['uniacid']);
  14. $module_name = safe_gpc_string(trim($_GPC['module_name']));
  15. if (empty($module_name) || empty($uniacid)) {
  16. iajax('1', '参数错误!');
  17. }
  18. $module = module_fetch($module_name);
  19. if (empty($module)) {
  20. iajax('1', '模块不存在!');
  21. }
  22. $module_version = array();
  23. foreach ($version_info['modules'] as $item) {
  24. if ($item['name'] == $module_name) {
  25. $module_version = $item;
  26. break;
  27. }
  28. }
  29. if (empty($module_version)) {
  30. iajax('1', '模块不存在!');
  31. }
  32. $link_uniacid_talbe = table('uni_link_uniacid');
  33. $sub_uniacids = $link_uniacid_talbe->getSubUniacids($_W['uniacid'], $module_name, $version_id);
  34. if (!empty($sub_uniacids)) {
  35. iajax('1', '模块已被其他账号关联!');
  36. }
  37. $link_uniacid_talbe->fill(array(
  38. 'uniacid' => $_W['uniacid'],
  39. 'link_uniacid' => $uniacid,
  40. 'version_id' => $version_id,
  41. 'module_name' => $module_name,
  42. ));
  43. $main_uniacid = $link_uniacid_talbe->getMainUniacid($_W['uniacid'], $module_name, $version_id);
  44. if (!empty($main_uniacid)) {
  45. $link_uniacid_talbe->searchWithUniacidModulenameVersionid($_W['uniacid'], $module_name, $version_id);
  46. }
  47. $link_uniacid_talbe->save();
  48. if (!empty($main_uniacid)) {
  49. cache_clean(cache_system_key('module_setting', array('module_name' => $module_name, 'uniacid' => $main_uniacid)));
  50. }
  51. cache_clean(cache_system_key('module_setting', array('module_name' => $module_name, 'uniacid' => $uniacid)));
  52. cache_delete(cache_system_key('miniapp_version', array('version_id' => $version_id)));
  53. iajax(0, '关联成功');
  54. }
  55. if (!empty($version_info['modules'])) {
  56. foreach ($version_info['modules'] as &$module_value) {
  57. $passive_link_info = table('uni_link_uniacid')->getSubUniacids($_W['uniacid'], $name, $version_id);
  58. if (!empty($passive_link_info)) {
  59. foreach ($passive_link_info as $passive_uniacid) {
  60. $account = uni_fetch($passive_uniacid);
  61. $passive_account = $account->account;
  62. $passive_account['type_name'] = $account->typeName;
  63. $module_value['passive_link_uniacid'][] = $passive_account;
  64. }
  65. }
  66. }
  67. }
  68. template('wxapp/version-module-link-uniacid');
  69. }
  70. if ($do == 'module_unlink_uniacid') {
  71. if (empty($version_info)) {
  72. iajax(-1, '版本信息错误!');
  73. }
  74. $module_name = safe_gpc_string(trim($_GPC['module_name']));
  75. if (empty($module_name)) {
  76. iajax('1', '参数错误!');
  77. }
  78. $module = module_fetch($module_name);
  79. if (empty($module)) {
  80. iajax('1', '模块不存在!');
  81. }
  82. $link_uniacid_table = table('uni_link_uniacid');
  83. $main_uniacid = $link_uniacid_table->getMainUniacid($_W['uniacid'], $module_name, $version_id);
  84. if (empty($main_uniacid)) {
  85. iajax(0, '删除失败!', referer());
  86. }
  87. $result = $link_uniacid_table->searchWithUniacidModulenameVersionid($_W['uniacid'], $module_name, $version_id)->delete();
  88. if ($result) {
  89. cache_delete(cache_system_key('module_setting', array('module_name' => $module_name, 'uniacid' => $main_uniacid)));
  90. cache_delete(cache_system_key('miniapp_version', array('version_id' => $version_id)));
  91. cache_build_module_info($module_name);
  92. iajax(0, '删除成功!', referer());
  93. } else {
  94. iajax(0, '删除失败!', referer());
  95. }
  96. }
  97. if ($do == 'search_link_account') {
  98. $module_name = safe_gpc_string($_GPC['module_name']);
  99. $account_type_sign = safe_gpc_string($_GPC['type_sign']);
  100. if (empty($module_name) || empty($account_type_sign)) {
  101. iajax(1, '参数不能为空');
  102. }
  103. $module = module_fetch($module_name);
  104. if (empty($module)) {
  105. iajax(1, '模块不存在或已删除');
  106. }
  107. $all_account_type_sign = uni_account_type_sign();
  108. if (!empty($_W['account']) && $_W['account']->typeSign != WXAPP_TYPE_SIGN) {
  109. unset($all_account_type_sign[$_W['account']->typeSign]); }
  110. if (!in_array($account_type_sign, array_keys($all_account_type_sign))) {
  111. iajax(1, '账号类型不存在');
  112. }
  113. $link_sub_uniacids = table('uni_link_uniacid')->getAllSubUniacidsByModuleName($module_name);
  114. $account_list = uni_search_link_account($module_name, $account_type_sign, $_W['uniacid']);
  115. if (!empty($account_list)) {
  116. foreach ($account_list as $key => $account) {
  117. if (in_array($account['uniacid'], $link_sub_uniacids)) {
  118. unset($account_list[$key]);
  119. continue;
  120. }
  121. $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';
  122. }
  123. }
  124. iajax(0, $account_list);
  125. }