manage.ctrl.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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('wxapp');
  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, ACCOUNT_MANAGE_NAME_VICE_FOUNDER));
  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 = wxapp_fetch($account['uniacid']);
  29. if (!empty($version_exist)) {
  30. $wxapp_version_lists = wxapp_version_all($account['uniacid']);
  31. $wxapp_modules = wxapp_support_uniacid_modules();
  32. }
  33. }
  34. template('wxapp/manage');
  35. }
  36. if ($do == 'edit_version') {
  37. if (empty($_GPC['version_info']) || !is_array($_GPC['version_info'])) {
  38. iajax(1, '数据错误!');
  39. }
  40. if (empty($_GPC['version_info']['modules'])) {
  41. iajax(1, '应用模块不可为空!');
  42. }
  43. $versionid = intval($_GPC['version_info']['id']);
  44. $version_exist = wxapp_fetch($uniacid, $versionid);
  45. if(empty($version_exist)) {
  46. iajax(1, '版本不存在或已删除!');
  47. }
  48. $have_permission = false;
  49. $wxapp_modules = wxapp_support_wxapp_modules();
  50. $supoort_modulenames = array_keys($wxapp_modules);
  51. $new_module_data = array();
  52. if (intval($_GPC['version_info']['design_method']) == WXAPP_TEMPLATE) {
  53. foreach ($_GPC['version_info']['modules'] as $module_val) {
  54. if (!in_array($module_val['name'], $supoort_modulenames)) {
  55. iajax(1, '没有模块:' . $module_val['name'] . '的权限!');
  56. } else {
  57. $new_module_data[] = array(
  58. 'name' => $module_val['name'],
  59. 'version' => $module_val['version']
  60. );
  61. }
  62. }
  63. }
  64. if (intval($_GPC['version_info']['design_method']) == WXAPP_MODULE) {
  65. $module_name = trim($_GPC['version_info']['modules'][0]['name']);
  66. $module_version = trim($_GPC['version_info']['modules'][0]['version']);
  67. $have_permission = in_array($module_name, $supoort_modulenames);
  68. if (!empty($have_permission)) {
  69. $new_module_data = array(
  70. $module_name => array(
  71. 'name' => $module_name,
  72. 'version' => $module_version
  73. )
  74. );
  75. } else {
  76. iajax(1, '没有此模块的权限!');
  77. }
  78. }
  79. if (empty($new_module_data)) {
  80. iajax(1, '应用模块不可为空!');
  81. }
  82. $data = array('modules' => iserializer($new_module_data), 'version' => trim($_GPC['version_info']['version']), 'description' => trim($_GPC['version_info']['description']));
  83. pdo_update('wxapp_versions', $data, array('id' => $versionid));
  84. iajax(0, '修改成功!', referer());
  85. }
  86. if ($do == 'del_version') {
  87. $id = intval($_GPC['versionid']);
  88. if (empty($id)) {
  89. iajax(1, '参数错误!');
  90. }
  91. $version_exist = pdo_get('wxapp_versions', array('id' => $id, 'uniacid' => $uniacid));
  92. if (empty($version_exist)) {
  93. iajax(1, '模块版本不存在!');
  94. }
  95. $result = pdo_delete('wxapp_versions', array('id' => $id, 'uniacid' => $uniacid));
  96. if (!empty($result)) {
  97. iajax(0, '删除成功!', referer());
  98. } else {
  99. iajax(1, '删除失败,请稍候重试!');
  100. }
  101. }
  102. if ($do == 'delete') {
  103. $id = intval($_GPC['id']);
  104. $version_info = pdo_get('wxapp_versions', array('id' => $id));
  105. if (!empty($version_info)) {
  106. $allversions = wxapp_version_all($uniacid);
  107. if (count($allversions) <= 1) {
  108. itoast('请至少保留一个版本!', referer(), 'error');
  109. }
  110. pdo_delete('wxapp_versions', array('id' => $id));
  111. } else {
  112. itoast('版本不存在', referer(), 'error');
  113. }
  114. itoast('删除成功', referer(), 'success');
  115. }