manage.ctrl.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. define('FRAME', 'system');
  8. load()->model('system');
  9. load()->model('miniapp');
  10. $dos = array('delete', 'display', 'edit_version', 'del_version', 'get_available_apps');
  11. $do = in_array($do, $dos) ? $do : 'display';
  12. $uniacid = intval($_GPC['uniacid']);
  13. $acid = intval($_GPC['acid']);
  14. if (empty($uniacid)) {
  15. itoast('请选择要编辑的小程序', referer(), 'error');
  16. }
  17. $state = permission_account_user_role($_W['uid'], $uniacid);
  18. $role_permission = in_array($state, array(ACCOUNT_MANAGE_NAME_OWNER, ACCOUNT_MANAGE_NAME_FOUNDER, ACCOUNT_MANAGE_NAME_MANAGER));
  19. if (!$role_permission) {
  20. itoast('无权限操作!', referer(), 'error');
  21. }
  22. if ($do == 'display') {
  23. $account = uni_fetch($uniacid);
  24. if (is_error($account)) {
  25. itoast($account['message'], url('account/manage', array('account_type' => ACCOUNT_TYPE_APP_NORMAL)), 'error');
  26. } else {
  27. $wxapp_info = pdo_get('account_wxapp', array('uniacid' => $account['uniacid']));
  28. $version_exist = miniapp_fetch($account['uniacid']);
  29. if (!empty($version_exist)) {
  30. $wxapp_version_lists = miniapp_version_all($account['uniacid']);
  31. if (!empty($wxapp_version_lists)) {
  32. foreach ($wxapp_version_lists as &$row) {
  33. if (!empty($row['modules'])) {
  34. $row['module'] = current($row['modules']);
  35. }
  36. if (!empty($row['last_modules'])) {
  37. $row['last_modules'] = current($row['last_modules']);
  38. $module = module_fetch($row['last_modules']['name']);
  39. if (!empty($module)) {
  40. $row['last_modules'] = array_merge($module, $row['last_modules']);
  41. }
  42. }
  43. if (empty($row['last_modules'])) {
  44. $row['last_modules'] = $row['module'];
  45. }
  46. }
  47. unset($row);
  48. }
  49. $wxapp_modules = miniapp_support_uniacid_modules($account['uniacid'], MODULE_SUPPORT_WXAPP_NAME);
  50. }
  51. }
  52. template('wxapp/manage');
  53. }
  54. if ($do == 'edit_version') {
  55. if (empty($_GPC['version_info']) || !is_array($_GPC['version_info'])) {
  56. iajax(1, '数据错误!');
  57. }
  58. if (empty($_GPC['version_info']['modules'])) {
  59. iajax(1, '应用模块不可为空!');
  60. }
  61. $versionid = intval($_GPC['version_info']['id']);
  62. $version_exist = miniapp_fetch($uniacid, $versionid);
  63. if(empty($version_exist)) {
  64. iajax(1, '版本不存在或已删除!');
  65. }
  66. $version_module = current((array)$version_exist['version']['modules']);
  67. $have_permission = false;
  68. $wxapp_modules = miniapp_support_wxapp_modules($uniacid);
  69. $supoort_modulenames = array_keys($wxapp_modules);
  70. $new_module_data = array();
  71. if (intval($_GPC['version_info']['design_method']) == WXAPP_TEMPLATE) {
  72. foreach ($_GPC['version_info']['modules'] as $module_val) {
  73. if (!in_array($module_val['name'], $supoort_modulenames)) {
  74. iajax(1, '没有模块:' . $module_val['name'] . '的权限!');
  75. } else {
  76. $new_module_data[] = array(
  77. 'name' => $module_val['name'],
  78. 'version' => $module_val['version']
  79. );
  80. }
  81. }
  82. }
  83. if (intval($_GPC['version_info']['design_method']) == WXAPP_MODULE) {
  84. $module = current((array)$_GPC['version_info']['modules']);
  85. $module_name = trim($module['name']);
  86. $module_version = trim($module['version']);
  87. $have_permission = in_array($module_name, $supoort_modulenames);
  88. if (!empty($version_module['name']) && $module_name == $version_module['name']) {
  89. iajax(0, '修改成功', referer());
  90. }
  91. if (!empty($have_permission)) {
  92. $new_module_data = array(
  93. $module_name => array(
  94. 'name' => $module_name,
  95. 'version' => $module_version
  96. )
  97. );
  98. } else {
  99. iajax(1, '没有此模块的权限!');
  100. }
  101. }
  102. if (empty($new_module_data)) {
  103. iajax(1, '应用模块不可为空!');
  104. }
  105. pdo_update('wxapp_versions', array('modules' => iserializer($new_module_data)), array('id' => $versionid));
  106. if (!empty($version_module['uniacid']) && !empty($version_module['name'])) {
  107. table('uni_link_uniacid')->searchWithUniacidModulenameVersionid($uniacid, $version_module['name'], $versionid)->delete();
  108. }
  109. cache_delete(cache_system_key('miniapp_version', array('version_id' => $versionid)));
  110. iajax(0, '修改成功!', referer());
  111. }
  112. if ($do == 'del_version') {
  113. $id = intval($_GPC['versionid']);
  114. if (empty($id)) {
  115. iajax(1, '参数错误!');
  116. }
  117. $version_exist = pdo_get('wxapp_versions', array('id' => $id, 'uniacid' => $uniacid));
  118. if (empty($version_exist)) {
  119. iajax(1, '模块版本不存在!');
  120. }
  121. $version_module = current((array)iunserializer($version_exist['modules']));
  122. if (!empty($version_module['uniacid']) && !empty($version_module['name'])) {
  123. table('uni_link_uniacid')->searchWithUniacidModulenameVersionid($uniacid, $version_module['name'], $id)->delete();
  124. }
  125. $result = pdo_delete('wxapp_versions', array('id' => $id, 'uniacid' => $uniacid));
  126. if (!empty($result)) {
  127. iajax(0, '删除成功!', referer());
  128. } else {
  129. iajax(1, '删除失败,请稍候重试!');
  130. }
  131. }