人人商城

module-group.ctrl.php 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. load()->model('user');
  9. $dos = array('display', 'delete', 'post', 'save');
  10. $do = !empty($_GPC['do']) ? $_GPC['do'] : 'display';
  11. if ($_W['role'] != ACCOUNT_MANAGE_NAME_OWNER && $_W['role'] != ACCOUNT_MANAGE_NAME_MANAGER && $_W['role'] != ACCOUNT_MANAGE_NAME_FOUNDER) {
  12. itoast('无权限操作!', referer(), 'error');
  13. }
  14. if ($do != 'display' && $_W['role'] != ACCOUNT_MANAGE_NAME_FOUNDER) {
  15. itoast('您只有查看权限!', url('system/module-group'), 'error');
  16. }
  17. if ($do == 'save') {
  18. $modules = empty($_GPC['modules']) ? array() : (array)$_GPC['modules'];
  19. $wxapp = empty($_GPC['wxapp']) ? array() : (array)array_keys($_GPC['wxapp']);
  20. $package_info = array(
  21. 'id' => intval($_GPC['id']),
  22. 'name' => $_GPC['name'],
  23. 'modules' => array_merge($modules, $wxapp),
  24. 'templates' => $_GPC['templates'],
  25. );
  26. if (empty($package_info['name'])) {
  27. iajax(1, '请输入套餐名');
  28. }
  29. if (!empty($package_info['modules'])) {
  30. $package_info['modules'] = iserializer($package_info['modules']);
  31. }
  32. if (!empty($package_info['templates'])) {
  33. $templates = array();
  34. foreach ($package_info['templates'] as $template) {
  35. $templates[] = $template['id'];
  36. }
  37. $package_info['templates'] = iserializer($templates);
  38. }
  39. if (!empty($package_info['id'])) {
  40. $name_exist = pdo_get('uni_group', array('uniacid' => 0, 'id <>' => $package_info['id'], 'name' => $package_info['name']));
  41. if (!empty($name_exist)) {
  42. iajax(1, '套餐名已存在');
  43. }
  44. $packageid = $package_info['id'];
  45. unset($package_info['id']);
  46. pdo_update('uni_group', $package_info, array('id' => $packageid));
  47. cache_build_uni_group();
  48. cache_build_account_modules();
  49. module_build_privileges();
  50. iajax(0, '', url('system/module-group'));
  51. } else {
  52. $name_exist = pdo_get('uni_group', array('uniacid' => 0, 'name' => $package_info['name']));
  53. if (!empty($name_exist)) {
  54. iajax(1, '套餐名已存在', '');
  55. }
  56. pdo_insert('uni_group', $package_info);
  57. cache_build_uni_group();
  58. module_build_privileges();
  59. iajax(0, '', url('system/module-group'));
  60. }
  61. }
  62. if ($do == 'display') {
  63. $_W['page']['title'] = '应用套餐列表';
  64. $param = array('uniacid' => 0);
  65. if (!empty($_GPC['name'])) {
  66. $param['name like'] = "%". trim($_GPC['name']) ."%";
  67. }
  68. $modules = user_modules($_W['uid']);
  69. $modules_group_list = uni_groups();
  70. if (!empty($modules_group_list)) {
  71. foreach ($modules_group_list as &$group) {
  72. if (empty($group['modules'])) {
  73. $group['modules'] = array();
  74. }
  75. if (!empty($group['wxapp'])) {
  76. $wxapp = $group['wxapp'];
  77. if (is_array($wxapp) && !empty($wxapp)) {
  78. if (!empty($group['wxapp'])) {
  79. foreach ($group['wxapp'] as &$wxapp) {
  80. if (file_exists(IA_ROOT.'/addons/'.$wxapp['name'].'/icon-custom.jpg')) {
  81. $wxapp['logo'] = tomedia(IA_ROOT.'/addons/'.$wxapp['name'].'/icon-custom.jpg');
  82. } else {
  83. $wxapp['logo'] = tomedia(IA_ROOT.'/addons/'.$wxapp['name'].'/icon.jpg');
  84. }
  85. }
  86. unset($wxapp);
  87. }
  88. } else {
  89. $group['wxapp'] = array();
  90. }
  91. }
  92. $group['templates'] = !empty($group['templates']) ? $group['templates'] : array();
  93. }
  94. unset($group);
  95. }
  96. }
  97. if ($do == 'delete') {
  98. $id = intval($_GPC['id']);
  99. if (!empty($id)) {
  100. pdo_delete('uni_group', array('id' => $id));
  101. cache_build_uni_group();
  102. cache_build_account_modules();
  103. }
  104. itoast('删除成功!', referer(), 'success');
  105. }
  106. if ($do == 'post') {
  107. $group_id = intval($_GPC['id']);
  108. $_W['page']['title'] = $group_id ? '编辑应用套餐' : '添加应用套餐';
  109. $group_have_module_app = array();
  110. $group_have_module_wxapp = array();
  111. $group_have_template = array();
  112. if (!empty($group_id)) {
  113. $uni_groups = uni_groups();
  114. $module_group = $uni_groups[$group_id];
  115. $group_have_module_app = empty($module_group['modules']) ? array() : $module_group['modules'];
  116. $group_have_module_wxapp = empty($module_group['wxapp']) ? array() : $module_group['wxapp'];
  117. $group_have_template = empty($module_group['templates']) ? array() : $module_group['templates'];
  118. }
  119. $module_list = pdo_getall('modules', array('issystem' => 0), array(), 'name', 'mid DESC');
  120. $group_not_have_module_app = array();
  121. $group_not_have_module_wxapp = array();
  122. if (!empty($module_list)) {
  123. foreach ($module_list as $name => $module_info) {
  124. $module_info = module_fetch($name);
  125. if ($module_info['app_support'] == 2 && !in_array($name, array_keys($group_have_module_app))) {
  126. if (!empty($module_info['main_module'])) {
  127. if (in_array($module_info['main_module'], array_keys($group_have_module_app))) {
  128. $group_not_have_module_app[$name] = $module_info;
  129. }
  130. } elseif (!empty($module_info['plugin'])) {
  131. $group_not_have_module_app[$name] = $module_info;
  132. if (!empty($module_info['plugin'])) {
  133. foreach ($module_info['plugin'] as $plugin) {
  134. if (!in_array($plugin, array_keys($group_have_module_app))) {
  135. $plugin = module_fetch($plugin);
  136. if (!empty($plugin)) {
  137. $group_not_have_module_app[$plugin['name']] = $plugin;
  138. }
  139. }
  140. }
  141. }
  142. } else {
  143. $group_not_have_module_app[$name] = $module_info;
  144. }
  145. }
  146. if ($module_info['wxapp_support'] == 2 && !in_array($name, array_keys($group_have_module_wxapp))) {
  147. $group_not_have_module_wxapp[$name] = $module_info;
  148. }
  149. }
  150. }
  151. $template_list = pdo_getall('site_templates', array(), array(), 'name');
  152. $group_not_have_template = array(); if (!empty($template_list)) {
  153. foreach ($template_list as $template) {
  154. if (!in_array($template['name'], array_keys($group_have_template))) {
  155. $group_not_have_template[$template['name']] = $template;
  156. }
  157. }
  158. }
  159. }
  160. template('system/module-group');