manage.ctrl.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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('display', 'edit_version', 'del_version');
  11. $do = in_array($do, $dos) ? $do : 'display';
  12. $uniacid = intval($_GPC['uniacid']);
  13. if (empty($uniacid)) {
  14. itoast('请选择要编辑的小程序', referer(), 'error');
  15. }
  16. $state = permission_account_user_role($_W['uid'], $uniacid);
  17. $role_permission = in_array($state, array(ACCOUNT_MANAGE_NAME_OWNER, ACCOUNT_MANAGE_NAME_FOUNDER, ACCOUNT_MANAGE_NAME_MANAGER, ACCOUNT_MANAGE_NAME_VICE_FOUNDER));
  18. if (!$role_permission) {
  19. itoast('无权限操作!', referer(), 'error');
  20. }
  21. $account = uni_fetch($uniacid);
  22. if (is_error($account) || empty($account['type'])) {
  23. itoast($account['message'], url('account/manage'), 'error');
  24. }
  25. if ($do == 'display') {
  26. $miniapp_info = pdo_get($account_all_type[$account['type']]['table_name'], array('uniacid' => $account['uniacid']));
  27. $version_exist = miniapp_fetch($account['uniacid']);
  28. if (!empty($version_exist)) {
  29. $version_lists = miniapp_version_all($uniacid);
  30. if (!empty($version_lists)) {
  31. foreach ($version_lists as &$row) {
  32. if (!empty($row['modules'])) {
  33. $row['module']['module_info'] = current($row['modules']);
  34. }
  35. if (!empty($row['last_modules'])) {
  36. $row['last_modules'] = current($row['last_modules']);
  37. $module = module_fetch($row['last_modules']['name']);
  38. if (!empty($module)) {
  39. $row['last_modules'] = array_merge($module, $row['last_modules']);
  40. }
  41. }
  42. if (empty($row['last_modules'])) {
  43. $row['last_modules'] = $row['module'];
  44. }
  45. }
  46. unset($row);
  47. }
  48. $miniapp_modules = miniapp_support_uniacid_modules($uniacid);
  49. }
  50. template('miniapp/manage');
  51. }
  52. if ($do == 'edit_version') {
  53. $versionid = intval($_GPC['version_id']);
  54. $module_name = safe_gpc_string($_GPC['name']);
  55. if (empty($module_name)) {
  56. iajax(1, '模块名不可为空!');
  57. }
  58. if (empty($versionid)) {
  59. iajax(1, '版本号不可为空!');
  60. }
  61. $module_info = module_fetch($module_name);
  62. if (empty($module_info)) {
  63. iajax(1, '模块不存在!');
  64. }
  65. $version_exist = miniapp_fetch($uniacid, $versionid);
  66. if(empty($version_exist)) {
  67. iajax(1, '版本不存在或已删除!');
  68. }
  69. $miniapp_modules = miniapp_support_uniacid_modules($uniacid);
  70. $supoort_modulenames = array_keys($miniapp_modules);
  71. if (!in_array($module_name, $supoort_modulenames)) {
  72. iajax(1, '没有模块:' . $module_info['title'] . '的权限!');
  73. }
  74. $new_module_data = array();
  75. $new_module_data[$module_name] = array(
  76. 'name' => $module_name,
  77. 'version' => $module_info['version']
  78. );
  79. pdo_update($account_all_type[$account['type']]['version_tablename'], array('modules' => iserializer($new_module_data)), array('id' => $versionid, 'uniacid' => $uniacid));
  80. $version_module = current($version_exist['version']['modules']);
  81. if (!empty($version_module['uniacid']) && !empty($version_module['name'])) {
  82. table('uni_link_uniacid')->searchWithUniacidModulenameVersionid($uniacid, $version_module['name'], $versionid)->delete();
  83. }
  84. cache_delete(cache_system_key('miniapp_version', array('version_id' => $versionid)));
  85. iajax(0, '修改成功!', referer());
  86. }
  87. if ($do == 'del_version') {
  88. $versionid = intval($_GPC['versionid']);
  89. if (empty($versionid)) {
  90. iajax(1, '参数错误!');
  91. }
  92. $version_exist = miniapp_fetch($uniacid, $versionid);
  93. if (empty($version_exist)) {
  94. iajax(1, '模块版本不存在!');
  95. }
  96. $version_module = current($version_exist['version']['modules']);
  97. if (!empty($version_module['name'])) {
  98. table('uni_link_uniacid')->searchWithUniacidModulenameVersionid($uniacid, $version_module['name'], $versionid)->delete();
  99. }
  100. $result = pdo_delete($account_all_type[$account['type']]['version_tablename'], array('id' => $versionid, 'uniacid' => $uniacid));
  101. if (!empty($result)) {
  102. iajax(0, '删除成功!', referer());
  103. } else {
  104. iajax(1, '删除失败,请稍候重试!');
  105. }
  106. }