人人商城

group.ctrl.php 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. load()->model('module');
  10. $dos = array('display', 'delete', 'post', 'save');
  11. $do = !empty($_GPC['do']) ? $_GPC['do'] : 'display';
  12. if (!in_array($_W['role'], array(ACCOUNT_MANAGE_NAME_OWNER, ACCOUNT_MANAGE_NAME_MANAGER, ACCOUNT_MANAGE_NAME_FOUNDER, ACCOUNT_MANAGE_NAME_VICE_FOUNDER))){
  13. itoast('无权限操作!', referer(), 'error');
  14. }
  15. if ($do != 'display' && !in_array($_W['role'], array(ACCOUNT_MANAGE_NAME_FOUNDER, ACCOUNT_MANAGE_NAME_VICE_FOUNDER))) {
  16. itoast('您只有查看权限!', url('module/group'), 'error');
  17. }
  18. if ($do == 'save') {
  19. $package_info = array(
  20. 'id' => intval($_GPC['id']),
  21. 'name' => $_GPC['name'],
  22. 'modules' => array(
  23. 'modules' => (array) $_GPC['modules'],
  24. 'wxapp' => (array) $_GPC['wxapp'],
  25. 'webapp' => empty($_GPC['webapp']) ? array() : (array) array_keys($_GPC['webapp']),
  26. 'xzapp' => empty($_GPC['xzapp']) ? array() : (array) array_keys($_GPC['xzapp']),
  27. 'phoneapp' => empty($_GPC['phoneapp']) ? array() : (array) array_keys($_GPC['phoneapp']),
  28. 'aliapp' => empty($_GPC['aliapp']) ? array() : (array) array_keys($_GPC['aliapp'])
  29. ),
  30. 'templates' => $_GPC['templates'],
  31. );
  32. $package_info = module_save_group_package($package_info);
  33. if (is_error($package_info)) {
  34. iajax(1, $package_info['message'], '');
  35. }
  36. iajax(0, '', url('module/group'));
  37. }
  38. if ($do == 'display') {
  39. $_W['page']['title'] = '应用套餐列表';
  40. $pageindex = max(1, intval($_GPC['page']));
  41. $pagesize = 10;
  42. $condition = 'WHERE uniacid = 0 AND uid = 0';
  43. $params = array();
  44. $name = safe_gpc_string($_GPC['name']);
  45. if (!empty($name)) {
  46. $condition .= " AND name LIKE :name";
  47. $params[':name'] = "%{$name}%";
  48. }
  49. if (user_is_vice_founder()) {
  50. $condition .= " AND owner_uid = :owner_uid";
  51. $params[':owner_uid'] = $_W['uid'];
  52. }
  53. $modules_group_list = pdo_fetchall("SELECT * FROM " . tablename('uni_group') . $condition . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize, $params);
  54. $total = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename('uni_group') . $condition, $params);
  55. $pager = pagination($total, $pageindex, $pagesize);
  56. if (!empty($modules_group_list)) {
  57. foreach ($modules_group_list as $key => $value) {
  58. $modules = (array)iunserializer($value['modules']);
  59. if (!empty($modules)) {
  60. foreach ($modules as $type => $modulenames) {
  61. if (empty($modulenames) || !is_array($modulenames)) {
  62. continue;
  63. }
  64. foreach ($modulenames as $name) {
  65. $module = module_fetch($name);
  66. if (empty($module)) {
  67. continue;
  68. }
  69. switch ($type) {
  70. case 'modules':
  71. if ($module[MODULE_SUPPORT_ACCOUNT_NAME] == MODULE_SUPPORT_ACCOUNT) {
  72. $modules_group_list[$key]['account_num'] += 1;
  73. $modules_group_list[$key]['account_modules'][] = $module;
  74. }
  75. break;
  76. case 'wxapp':
  77. if ($module[MODULE_SUPPORT_WXAPP_NAME] == MODULE_SUPPORT_WXAPP) {
  78. $modules_group_list[$key]['wxapp_num'] += 1;
  79. $modules_group_list[$key]['wxapp_modules'][] = $module;
  80. }
  81. break;
  82. case 'webapp':
  83. if ($module[MODULE_SUPPORT_WEBAPP_NAME] == MODULE_SUPPORT_WEBAPP) {
  84. $modules_group_list[$key]['webapp_num'] += 1;
  85. $modules_group_list[$key]['webapp_modules'][] = $module;
  86. }
  87. break;
  88. case 'xzapp':
  89. if ($module[MODULE_SUPPORT_XZAPP_NAME] == MODULE_SUPPORT_XZAPP) {
  90. $modules_group_list[$key]['xzapp_num'] += 1;
  91. $modules_group_list[$key]['xzapp_modules'][] = $module;
  92. }
  93. break;
  94. case 'phoneapp':
  95. if ($module[MODULE_SUPPORT_PHONEAPP_NAME] == MODULE_SUPPORT_PHONEAPP) {
  96. $modules_group_list[$key]['phoneapp_num'] += 1;
  97. $modules_group_list[$key]['phoneapp_modules'][] = $module;
  98. }
  99. break;
  100. case 'aliapp':
  101. if ($module[MODULE_SUPPORT_ALIAPP_NAME] == MODULE_SUPPORT_ALIAPP) {
  102. $modules_group_list[$key]['aliapp_num'] += 1;
  103. $modules_group_list[$key]['aliapp_modules'][] = $module;
  104. }
  105. break;
  106. }
  107. }
  108. }
  109. }
  110. $templates = (array)iunserializer($value['templates']);
  111. $modules_group_list[$key]['template_num'] = !empty($templates) ? count($templates) : 0;
  112. $modules_group_list[$key]['templates'] = pdo_getall('site_templates', array('id' => $templates), array('id', 'name', 'title'), 'name');
  113. }
  114. }
  115. $modules = user_modules($_W['uid']);
  116. }
  117. if ($do == 'delete') {
  118. $id = intval($_GPC['id']);
  119. if (!empty($id)) {
  120. pdo_delete('uni_group', array('id' => $id));
  121. cache_build_uni_group();
  122. cache_build_account_modules();
  123. }
  124. itoast('删除成功!', referer(), 'success');
  125. }
  126. if ($do == 'post') {
  127. $group_id = intval($_GPC['id']);
  128. $_W['page']['title'] = $group_id ? '编辑应用套餐' : '添加应用套餐';
  129. $group_have_module_app = array();
  130. $group_have_module_wxapp = array();
  131. $group_have_module_webapp = array();
  132. $group_have_module_phoneapp = array();
  133. $group_have_module_xzapp = array();
  134. $group_have_module_aliapp = array();
  135. $group_have_template = array();
  136. if (!empty($group_id)) {
  137. $module_group = current(uni_groups(array($group_id)));
  138. $group_have_module_app = empty($module_group['modules']) ? array() : array_filter($module_group['modules']);
  139. $group_have_module_wxapp = empty($module_group['wxapp']) ? array() : array_filter($module_group['wxapp']);
  140. $group_have_template = empty($module_group['templates']) ? array() : array_filter($module_group['templates']);
  141. $group_have_module_webapp = empty($module_group['webapp']) ? array() : array_filter($module_group['webapp']);
  142. $group_have_module_phoneapp = empty($module_group['phoneapp']) ? array() : array_filter($module_group['phoneapp']);
  143. $group_have_module_xzapp = empty($module_group['xzapp']) ? array() : array_filter($module_group['xzapp']);
  144. $group_have_module_aliapp = empty($module_group['aliapp']) ? array() : array_filter($module_group['aliapp']);
  145. }
  146. $module_list = user_modules($_W['uid']);
  147. foreach($module_list as $key => $val) {
  148. if (!empty($val['issystem'])) {
  149. unset($module_list[$key]);
  150. }
  151. }
  152. $group_not_have_module_app = array();
  153. $group_not_have_module_wxapp = array();
  154. $group_not_have_module_webapp = array();
  155. $group_not_have_module_phoneapp = array();
  156. $group_not_have_module_xzapp = array();
  157. $group_not_have_module_aliapp = array();
  158. if (!empty($module_list)) {
  159. foreach ($module_list as $name => $module_info) {
  160. if ($module_info[MODULE_SUPPORT_ACCOUNT_NAME] == MODULE_SUPPORT_WXAPP && !in_array($name, array_keys($group_have_module_app))) {
  161. if (!empty($module_info['main_module'])) {
  162. if (!in_array($module_info['name'], array_keys($group_have_module_app))) {
  163. $group_not_have_module_app[$name] = $module_info;
  164. }
  165. } elseif (is_array($module_info['plugin_list']) && !empty($module_info['plugin_list'])) {
  166. $group_not_have_module_app[$name] = $module_info;
  167. foreach ($module_info['plugin_list'] as $plugin) {
  168. if (!in_array($plugin, array_keys($group_have_module_app))) {
  169. $plugin = module_fetch($plugin);
  170. if (!empty($plugin)) {
  171. $group_not_have_module_app[$plugin['name']] = $plugin;
  172. }
  173. }
  174. }
  175. } else {
  176. $group_not_have_module_app[$name] = $module_info;
  177. }
  178. }
  179. if ($module_info['wxapp_support'] == MODULE_SUPPORT_WXAPP && !in_array($name, array_keys($group_have_module_wxapp))) {
  180. $group_not_have_module_wxapp[$name] = $module_info;
  181. }
  182. if ($module_info['webapp_support'] == MODULE_SUPPORT_WEBAPP && !in_array($name, array_keys($group_have_module_webapp))) {
  183. $group_not_have_module_webapp[$name] = $module_info;
  184. }
  185. if ($module_info['phoneapp_support'] == MODULE_SUPPORT_PHONEAPP && !in_array($name, array_keys($group_have_module_phoneapp))) {
  186. $group_not_have_module_phoneapp[$name] = $module_info;
  187. }
  188. if ($module_info['xzapp_support'] == MODULE_SUPPORT_XZAPP && !in_array($name, array_keys($group_have_module_xzapp))) {
  189. $group_not_have_module_xzapp[$name] = $module_info;
  190. }
  191. if ($module_info['aliapp_support'] == MODULE_SUPPORT_ALIAPP && !in_array($name, array_keys($group_have_module_aliapp))) {
  192. $group_not_have_module_aliapp[$name] = $module_info;
  193. }
  194. }
  195. }
  196. if (user_is_vice_founder($_W['uid'])) {
  197. $template_list = user_founder_templates($_W['user']['groupid']);
  198. } else {
  199. $template_list = pdo_getall('site_templates', array(), array(), 'name');
  200. }
  201. $group_not_have_template = array(); if (!empty($template_list)) {
  202. foreach ($template_list as $template) {
  203. if (!in_array($template['name'], array_keys($group_have_template))) {
  204. $group_not_have_template[$template['name']] = $template;
  205. }
  206. }
  207. }
  208. }
  209. template('module/group');