人人商城

manage.ctrl.php 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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, 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 = 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. $have_permission = false;
  67. $wxapp_modules = miniapp_support_wxapp_modules();
  68. $supoort_modulenames = array_keys($wxapp_modules);
  69. $new_module_data = array();
  70. if (intval($_GPC['version_info']['design_method']) == WXAPP_TEMPLATE) {
  71. foreach ($_GPC['version_info']['modules'] as $module_val) {
  72. if (!in_array($module_val['name'], $supoort_modulenames)) {
  73. iajax(1, '没有模块:' . $module_val['name'] . '的权限!');
  74. } else {
  75. $new_module_data[] = array(
  76. 'name' => $module_val['name'],
  77. 'version' => $module_val['version']
  78. );
  79. }
  80. }
  81. }
  82. if (intval($_GPC['version_info']['design_method']) == WXAPP_MODULE) {
  83. $module_name = trim($_GPC['version_info']['modules'][0]['name']);
  84. $module_version = trim($_GPC['version_info']['modules'][0]['version']);
  85. $have_permission = in_array($module_name, $supoort_modulenames);
  86. if (!empty($have_permission)) {
  87. $new_module_data = array(
  88. $module_name => array(
  89. 'name' => $module_name,
  90. 'version' => $module_version
  91. )
  92. );
  93. } else {
  94. iajax(1, '没有此模块的权限!');
  95. }
  96. }
  97. if (empty($new_module_data)) {
  98. iajax(1, '应用模块不可为空!');
  99. }
  100. pdo_update('wxapp_versions', array('modules' => iserializer($new_module_data)), array('id' => $versionid));
  101. cache_delete(cache_system_key('miniapp_version', array('version_id' => $versionid)));
  102. iajax(0, '修改成功!', referer());
  103. }
  104. if ($do == 'del_version') {
  105. $id = intval($_GPC['versionid']);
  106. if (empty($id)) {
  107. iajax(1, '参数错误!');
  108. }
  109. $version_exist = pdo_get('wxapp_versions', array('id' => $id, 'uniacid' => $uniacid));
  110. if (empty($version_exist)) {
  111. iajax(1, '模块版本不存在!');
  112. }
  113. $result = pdo_delete('wxapp_versions', array('id' => $id, 'uniacid' => $uniacid));
  114. if (!empty($result)) {
  115. iajax(0, '删除成功!', referer());
  116. } else {
  117. iajax(1, '删除失败,请稍候重试!');
  118. }
  119. }
  120. if ($do == 'delete') {
  121. $id = intval($_GPC['id']);
  122. $version_info = pdo_get('wxapp_versions', array('id' => $id));
  123. if (!empty($version_info)) {
  124. $allversions = miniapp_version_all($uniacid);
  125. if (count($allversions) <= 1) {
  126. itoast('请至少保留一个版本!', referer(), 'error');
  127. }
  128. pdo_delete('wxapp_versions', array('id' => $id));
  129. } else {
  130. itoast('版本不存在', referer(), 'error');
  131. }
  132. itoast('删除成功', referer(), 'success');
  133. }