人人商城

module-link-uniacid.ctrl.php 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. $_W['page']['title'] = '数据同步 - PC - 管理';
  10. if ($do == 'module_link_uniacid') {
  11. if (checksubmit('submit')) {
  12. $module_name = trim($_GPC['module_name']);
  13. $uniacid = intval($_GPC['uniacid']);
  14. if (empty($module_name) || empty($uniacid)) {
  15. iajax('1', '参数错误!');
  16. }
  17. $module = module_fetch($module_name);
  18. if (empty($module)) {
  19. iajax('1', '模块不存在!');
  20. }
  21. $account_module = pdo_get('uni_account_modules', array('module' => $module_name, 'uniacid' => $_W['uniacid']), array('id', 'settings'));
  22. if (!empty($account_module)) {
  23. $settings = (array)iunserializer($account_module['settings']);
  24. $settings['link_uniacid'] = $uniacid;
  25. pdo_update('uni_account_modules', array('settings' => iserializer($settings)), array('id' => $account_module['id']));
  26. } else {
  27. $settings = array('link_uniacid' => $uniacid);
  28. $data = array(
  29. 'settings' => iserializer($settings),
  30. 'uniacid' => $_W['uniacid'],
  31. 'module' => $module_name,
  32. 'enabled' => STATUS_ON,
  33. );
  34. pdo_insert('uni_account_modules', $data);
  35. }
  36. uni_passive_link_uniacid($uniacid, $module_name);
  37. cache_build_module_info($module_name);
  38. iajax(0, '关联成功');
  39. }
  40. $modules = uni_modules();
  41. foreach ($modules as $key => $value) {
  42. if ($value[MODULE_SUPPORT_WXAPP_NAME] == MODULE_NONSUPPORT_WXAPP && $value[MODULE_SUPPORT_ACCOUNT_NAME] == MODULE_NONSUPPORT_ACCOUNT || !empty($value['issystem'])) {
  43. unset($modules[$key]);
  44. continue;
  45. }
  46. if (!empty($value['config']) && !empty($value['config']['link_uniacid'])) {
  47. $modules[$key]['link_uniacid_info'] = uni_fetch($value['config']['link_uniacid']);
  48. continue;
  49. }
  50. if (!empty($value['config']['passive_link_uniacid'])) {
  51. $modules[$key]['other_link'] = uni_fetch($value['config']['passive_link_uniacid']);
  52. }
  53. }
  54. template('webapp/module-link-uniacid');
  55. }
  56. if ($do == 'module_unlink_uniacid') {
  57. $module_name = trim($_GPC['module_name']);
  58. if (empty($module_name)) {
  59. iajax(-1, '参数错误!');
  60. }
  61. $module = module_fetch($module_name);
  62. if (empty($module)) {
  63. iajax(-1, '模块不存在!');
  64. }
  65. $account_module = pdo_get('uni_account_modules', array('module' => $module_name, 'uniacid' => $_W['uniacid']), array('id', 'settings'));
  66. if (!empty($account_module)) {
  67. $settings = iunserializer($account_module['settings']);
  68. if (empty($settings['link_uniacid'])) {
  69. $result = true;
  70. } else {
  71. unset($settings['link_uniacid']);
  72. $data = empty($settings) ? '' : iserializer($settings);
  73. $result = pdo_update('uni_account_modules', array('settings' => $data), array('id' => $account_module['id']));
  74. }
  75. }
  76. if ($result) {
  77. cache_build_module_info($module_name);
  78. iajax(0, '删除成功!', referer());
  79. } else {
  80. iajax(0, '删除失败!', referer());
  81. }
  82. }
  83. if ($do == 'search_link_account') {
  84. $module_name = trim($_GPC['module_name']);
  85. $account_type = intval($_GPC['type']);
  86. if (empty($module_name)) {
  87. iajax(0, array());
  88. }
  89. $module = module_fetch($module_name);
  90. if (empty($module)) {
  91. iajax(0, array());
  92. }
  93. if (!in_array($account_type, array(ACCOUNT_TYPE_APP_NORMAL, ACCOUNT_TYPE_OFFCIAL_NORMAL))) {
  94. iajax(0, array());
  95. }
  96. $have_link_uniacid = array();
  97. $link_uniacid_info = module_link_uniacid_info($module_name);
  98. if (!empty($link_uniacid_info)) {
  99. foreach ($link_uniacid_info as $info) {
  100. if (!empty($info['settings']['link_uniacid'])) {
  101. $have_link_uniacid[] = $info['uniacid'];
  102. }
  103. }
  104. }
  105. if ($account_type == ACCOUNT_TYPE_OFFCIAL_NORMAL) {
  106. $account_normal_list = uni_search_link_account($module_name, ACCOUNT_TYPE_OFFCIAL_NORMAL);
  107. $account_auth_list = uni_search_link_account($module_name, ACCOUNT_TYPE_OFFCIAL_AUTH);
  108. $account_list = array_merge($account_normal_list, $account_auth_list);
  109. } else {
  110. $account_list = uni_search_link_account($module_name, $account_type);
  111. }
  112. if (!empty($account_list)) {
  113. foreach ($account_list as $key => $account) {
  114. if (in_array($account['uniacid'], $have_link_uniacid)) {
  115. unset($account_list[$key]);
  116. continue;
  117. }
  118. $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';
  119. }
  120. }
  121. iajax(0, $account_list);
  122. }