人人商城

module-link-uniacid.ctrl.php 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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_module_link_uniacid');
  11. $_W['page']['title'] = '数据同步 - 小程序 - 管理';
  12. $wxapp_info = miniapp_fetch($_W['uniacid']);
  13. if ($do == 'module_link_uniacid') {
  14. $module_name = trim($_GPC['module_name']);
  15. if (checksubmit('submit')) {
  16. $uniacid = intval($_GPC['uniacid']);
  17. if (empty($module_name) || empty($uniacid)) {
  18. iajax('1', '参数错误!');
  19. }
  20. $module = module_fetch($module_name);
  21. if (empty($module)) {
  22. iajax('1', '模块不存在!');
  23. }
  24. $module_update = array();
  25. $module_update[$module['name']] = array('name' => $module['name'], 'version' => $module['version'], 'uniacid' => $uniacid);
  26. pdo_update('wxapp_versions', array('modules' => iserializer($module_update)), array('id' => $version_id));
  27. uni_passive_link_uniacid($uniacid, $module_name);
  28. cache_delete(cache_system_key('miniapp_version', array('version_id' => $version_id)));
  29. iajax(0, '关联成功');
  30. }
  31. if (!empty($version_info['modules'])) {
  32. foreach ($version_info['modules'] as &$module_value) {
  33. $link_uniacid_info = module_link_uniacid_info($module_value['name']);
  34. if (!empty($link_uniacid_info)) {
  35. foreach ($link_uniacid_info as $info) {
  36. if ($info['settings']['link_uniacid'] == $_W['uniacid'] ||
  37. !empty($info['settings']['passive_link_uniacid']) && $info['uniacid'] == $_W['uniacid']) {
  38. $module_value['other_link'] = uni_fetch(current($info['settings']['passive_link_uniacid']));
  39. }
  40. }
  41. }
  42. }
  43. }
  44. template('wxapp/version-module-link-uniacid');
  45. }
  46. if ($do == 'module_unlink_uniacid') {
  47. if (empty($version_info)) {
  48. iajax(-1, '版本信息错误!');
  49. }
  50. $module = current($version_info['modules']);
  51. $version_modules = array(
  52. $module['name'] => array(
  53. 'name' => $module['name'],
  54. 'version' => $module['version']
  55. )
  56. );
  57. uni_unpassive_link_uniacid($module['account']['uniacid'], $module['name']);
  58. $version_modules = iserializer($version_modules);
  59. $result = pdo_update('wxapp_versions', array('modules' => $version_modules), array('id' => $version_info['id']));
  60. if ($result) {
  61. cache_delete(cache_system_key('miniapp_version', array('version_id' => $version_id)));
  62. iajax(0, '删除成功!', referer());
  63. } else {
  64. iajax(0, '删除失败!', referer());
  65. }
  66. }
  67. if ($do == 'search_link_account') {
  68. $module_name = trim($_GPC['module_name']);
  69. $account_type = intval($_GPC['type']);
  70. if (empty($module_name)) {
  71. iajax(0, array());
  72. }
  73. $module = module_fetch($module_name);
  74. if (empty($module)) {
  75. iajax(0, array());
  76. }
  77. if (!in_array($account_type, array(ACCOUNT_TYPE_WEBAPP_NORMAL, ACCOUNT_TYPE_OFFCIAL_NORMAL, ACCOUNT_TYPE_APP_NORMAL))) {
  78. iajax(0, array());
  79. }
  80. $have_link_uniacid = array();
  81. $link_uniacid_info = module_link_uniacid_info($module_name);
  82. if (!empty($link_uniacid_info)) {
  83. foreach ($link_uniacid_info as $info) {
  84. if (!empty($info['settings']['link_uniacid'])) {
  85. $have_link_uniacid[] = $info['uniacid'];
  86. }
  87. }
  88. }
  89. if ($account_type == ACCOUNT_TYPE_OFFCIAL_NORMAL) {
  90. $account_normal_list = uni_search_link_account($module_name, ACCOUNT_TYPE_OFFCIAL_NORMAL);
  91. $account_auth_list = uni_search_link_account($module_name, ACCOUNT_TYPE_OFFCIAL_AUTH);
  92. $account_list = array_merge($account_normal_list, $account_auth_list);
  93. } elseif ($account_type == ACCOUNT_TYPE_APP_NORMAL) {
  94. $account_normal_list = uni_search_link_account($module_name, ACCOUNT_TYPE_APP_NORMAL);
  95. $account_auth_list = uni_search_link_account($module_name, ACCOUNT_TYPE_APP_AUTH);
  96. $account_list = array_merge($account_normal_list, $account_auth_list);
  97. } else {
  98. $account_list = uni_search_link_account($module_name, $account_type);
  99. }
  100. if (!empty($account_list)) {
  101. foreach ($account_list as $key => $account) {
  102. if (in_array($account['uniacid'], $have_link_uniacid)) {
  103. unset($account_list[$key]);
  104. continue;
  105. }
  106. $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';
  107. }
  108. }
  109. iajax(0, $account_list);
  110. }