人人商城

post-step.ctrl.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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()->func('file');
  8. load()->model('module');
  9. load()->model('user');
  10. $_W['page']['title'] = '添加/编辑熊掌号 - 熊掌号管理';
  11. $uniacid = intval($_GPC['uniacid']);
  12. $step = intval($_GPC['step']) ? intval($_GPC['step']) : 1;
  13. $user_create_account_info = permission_user_account_num();
  14. if ($step == 1) {
  15. if ($user_create_account_info['xzapp_limit'] <= 0 && !$_W['isfounder']) {
  16. $authurl = "javascript:alert('创建熊掌号已达上限');";
  17. }
  18. if (empty($authurl) && !empty($_W['setting']['platform']['authstate'])) {
  19. $authurl = "javascript:alert('暂不支持授权接入');";
  20. }
  21. }
  22. if ($step == 2) {
  23. if (checksubmit('submit')) {
  24. if ($user_create_account_info['xzapp_limit'] <= 0 && !$_W['isfounder']) {
  25. itoast('创建熊掌号已达上限!');
  26. }
  27. $update = array();
  28. $update['name'] = trim($_GPC['cname']);
  29. if (empty($update['name'])) {
  30. itoast('熊掌号名称必须填写', '', '');
  31. }
  32. if (empty($uniacid)) {
  33. $name = trim($_GPC['cname']);
  34. $description = trim($_GPC['description']);
  35. $data = array(
  36. 'name' => $name,
  37. 'description' => $description,
  38. 'title_initial' => get_first_pinyin($name),
  39. 'groupid' => 0,
  40. );
  41. $account_table = table('account');
  42. $account_table->searchWithTitle($name);
  43. $account_table->searchWithType(ACCOUNT_TYPE_XZAPP_NORMAL);
  44. $check_uniacname = $account_table->searchAccountList();
  45. if (!empty($check_uniacname)) {
  46. itoast('该熊掌号名称已经存在', '', '');
  47. }
  48. if (!pdo_insert('uni_account', $data)) {
  49. itoast('添加熊掌号失败', '', '');
  50. }
  51. $uniacid = pdo_insertid();
  52. $template = pdo_fetch('SELECT id,title FROM ' . tablename('site_templates') . " WHERE name = 'default'");
  53. $styles['uniacid'] = $uniacid;
  54. $styles['templateid'] = $template['id'];
  55. $styles['name'] = $template['title'] . '_' . random(4);
  56. pdo_insert('site_styles', $styles);
  57. $styleid = pdo_insertid();
  58. $multi['uniacid'] = $uniacid;
  59. $multi['title'] = $data['name'];
  60. $multi['styleid'] = $styleid;
  61. pdo_insert('site_multi', $multi);
  62. $multi_id = pdo_insertid();
  63. $unisettings['creditnames'] = array('credit1' => array('title' => '积分', 'enabled' => 1), 'credit2' => array('title' => '余额', 'enabled' => 1));
  64. $unisettings['creditnames'] = iserializer($unisettings['creditnames']);
  65. $unisettings['creditbehaviors'] = array('activity' => 'credit1', 'currency' => 'credit2');
  66. $unisettings['creditbehaviors'] = iserializer($unisettings['creditbehaviors']);
  67. $unisettings['uniacid'] = $uniacid;
  68. $unisettings['default_site'] = $multi_id;
  69. $unisettings['sync'] = iserializer(array('switch' => 0, 'acid' => ''));
  70. pdo_insert('uni_settings', $unisettings);
  71. pdo_insert('mc_groups', array('uniacid' => $uniacid, 'title' => '默认会员组', 'isdefault' => 1));
  72. $fields = pdo_getall('profile_fields');
  73. foreach($fields as $field) {
  74. $data = array(
  75. 'uniacid' => $uniacid,
  76. 'fieldid' => $field['id'],
  77. 'title' => $field['title'],
  78. 'available' => $field['available'],
  79. 'displayorder' => $field['displayorder'],
  80. );
  81. pdo_insert('mc_member_fields', $data);
  82. }
  83. }
  84. $update['original'] = trim($_GPC['original']);
  85. $update['level'] = intval($_GPC['level']);
  86. $update['key'] = trim($_GPC['key']);
  87. $update['secret'] = trim($_GPC['secret']);
  88. $update['type'] = ACCOUNT_TYPE_XZAPP_NORMAL;
  89. $update['encodingaeskey'] = trim($_GPC['encodingaeskey']);
  90. if (user_is_vice_founder()) {
  91. uni_user_account_role($uniacid, $_W['uid'], ACCOUNT_MANAGE_NAME_VICE_FOUNDER);
  92. }
  93. if (empty($acid)) {
  94. $acid = account_create($uniacid, $update);
  95. if (is_error($acid)) {
  96. itoast('添加熊掌号信息失败', url('xzapp/post-step/', array('uniacid' => $uniacid, 'step' => 2)), 'error');
  97. }
  98. pdo_update('uni_account', array('default_acid' => $acid), array('uniacid' => $uniacid));
  99. if (empty($_W['isfounder'])) {
  100. uni_user_account_role($uniacid, $_W['uid'], ACCOUNT_MANAGE_NAME_OWNER);
  101. }
  102. if (!empty($_W['user']['owner_uid'])) {
  103. uni_user_account_role($uniacid, $_W['user']['owner_uid'], ACCOUNT_MANAGE_NAME_VICE_FOUNDER);
  104. }
  105. } else {
  106. pdo_update('account', array('type' => ACCOUNT_TYPE_XZAPP_NORMAL, 'hash' => ''), array('acid' => $acid, 'uniacid' => $uniacid));
  107. unset($update['type']);
  108. }
  109. if(parse_path($_GPC['headimg']) && in_array(pathinfo($_GPC['qrcode'], PATHINFO_EXTENSION), $_W['config']['upload']['image']['extentions'])) {
  110. copy($_GPC['headimg'], IA_ROOT . '/attachment/headimg_'.$acid.'.jpg');
  111. }
  112. if (!empty($_GPC['uniacid']) || empty($_W['isfounder'])) {
  113. header("Location: ".url('xzapp/post-step/', array('uniacid' => $uniacid, 'acid' => $acid, 'step' => 4)));
  114. } else {
  115. header("Location: ".url('xzapp/post-step/', array('uniacid' => $uniacid, 'acid' => $acid, 'step' => 3)));
  116. }
  117. exit;
  118. }
  119. }
  120. if ($step == 3) {
  121. $acid = intval($_GPC['acid']);
  122. $uniacid = intval($_GPC['uniacid']);
  123. if (empty($_W['isfounder'])) {
  124. itoast('您无权进行该操作!', '', '');
  125. }
  126. if ($_GPC['get_type'] == 'userinfo' && $_W['ispost']) {
  127. $result = array();
  128. $uid = intval($_GPC['uid'][0]);
  129. $user = user_single(array('uid' => $uid));
  130. if (empty($user)) {
  131. iajax(-1, '用户不存在或是已经被删除', '');
  132. }
  133. $result['username'] = $user['username'];
  134. $result['uid'] = $user['uid'];
  135. $result['group'] = user_group_detail_info($user['groupid']);
  136. $result['package'] = iunserializer($result['group']['package']);
  137. iajax(0, $result, '');
  138. exit;
  139. }
  140. if (checksubmit('submit')) {
  141. $uid = intval($_GPC['uid']);
  142. $groupid = intval($_GPC['groupid']);
  143. if (!empty($uid)) {
  144. $create_account_info = permission_user_account_num($uid);
  145. if ($create_account_info['uniacid_limit'] <= 0 && (!user_is_founder($_W['uid']) || user_is_vice_founder())) {
  146. itoast("您所设置的主管理员所在的用户组可添加的公众号数量已达上限,请选择其他人做主管理员!", referer(), 'error');
  147. }
  148. pdo_delete('uni_account_users', array('uniacid' => $uniacid, 'uid' => $uid));
  149. $owner = pdo_get('uni_account_users', array('uniacid' => $uniacid, 'role' => 'owner'));
  150. if (!empty($owner)) {
  151. pdo_update('uni_account_users', array('uid' => $uid), array('uniacid' => $uniacid, 'role' => 'owner'));
  152. } else {
  153. uni_user_account_role($uniacid, $uid, ACCOUNT_MANAGE_NAME_OWNER);
  154. }
  155. $user_vice_id = pdo_getcolumn('users', array('uid' => $uid), 'owner_uid');
  156. if ($_W['user']['founder_groupid'] != ACCOUNT_MANAGE_GROUP_VICE_FOUNDER && !empty($user_vice_id)) {
  157. uni_user_account_role($uniacid, $user_vice_id, ACCOUNT_MANAGE_NAME_VICE_FOUNDER);
  158. }
  159. }
  160. $user = array(
  161. 'uid' => $uid,
  162. 'groupid' => $groupid,
  163. );
  164. if ($_GPC['is-set-endtime'] == 1 && !empty($_GPC['endtime'])) {
  165. $user['endtime'] = strtotime($_GPC['endtime']);
  166. } else {
  167. $user['endtime'] = 0;
  168. }
  169. if (!empty($user)) {
  170. user_update($user);
  171. }
  172. pdo_delete('uni_account_group', array('uniacid' => $uniacid));
  173. if (!empty($_GPC['package'])) {
  174. $group = pdo_get('users_group', array('id' => $groupid));
  175. $group['package'] = iunserializer($group['package']);
  176. if (!is_array($group['package']) || !in_array('-1', $group['package'])) {
  177. foreach ($_GPC['package'] as $packageid) {
  178. if (!empty($packageid)) {
  179. pdo_insert('uni_account_group', array(
  180. 'uniacid' => $uniacid,
  181. 'groupid' => $packageid,
  182. ));
  183. }
  184. }
  185. }
  186. }
  187. if (!empty($_GPC['extra']['modules']) || !empty($_GPC['extra']['templates'])) {
  188. $data = array(
  189. 'modules' => array('modules' => array(), 'wxapp' => array(), 'webapp' => array(), 'xzapp' => array(), 'phoneapp' => array()),
  190. 'templates' => iserializer($_GPC['extra']['templates']),
  191. 'uniacid' => $uniacid,
  192. 'name' => '',
  193. );
  194. $account = pdo_get('account', array('uniacid' => $uniacid));
  195. if (empty($account)) {
  196. itoast('无效的 uniacid', '', '');
  197. }
  198. switch ($account['type']) {
  199. case ACCOUNT_TYPE_OFFCIAL_NORMAL:
  200. case ACCOUNT_TYPE_OFFCIAL_AUTH:
  201. $data['modules']['modules'] = $_GPC['extra']['modules'];
  202. break;
  203. case ACCOUNT_TYPE_APP_NORMAL:
  204. case ACCOUNT_TYPE_APP_AUTH:
  205. case ACCOUNT_TYPE_WXAPP_WORK:
  206. $data['modules']['wxapp'] = $_GPC['extra']['modules'];
  207. break;
  208. case ACCOUNT_TYPE_WEBAPP_NORMAL:
  209. $data['modules']['webapp'] = $_GPC['extra']['modules'];
  210. break;
  211. case ACCOUNT_TYPE_XZAPP_NORMAL:
  212. case ACCOUNT_TYPE_XZAPP_AUTH:
  213. $data['modules']['xzapp'] = $_GPC['extra']['modules'];
  214. break;
  215. case ACCOUNT_TYPE_PHONEAPP_NORMAL:
  216. $data['modules']['phoneapp'] = $_GPC['extra']['modules'];
  217. break;
  218. }
  219. $data['modules'] = iserializer($data['modules']);
  220. $id = pdo_fetchcolumn("SELECT id FROM ".tablename('uni_group')." WHERE uniacid = :uniacid", array(':uniacid' => $uniacid));
  221. if (empty($id)) {
  222. pdo_insert('uni_group', $data);
  223. } else {
  224. pdo_update('uni_group', $data, array('id' => $id));
  225. }
  226. } else {
  227. pdo_delete('uni_group', array('uniacid' => $uniacid));
  228. }
  229. cache_delete(cache_system_key('uniaccount', array('uniacid' => $uniacid)));
  230. cache_delete(cache_system_key('unimodules', array('uniacid' => $uniacid, 'enabled' => 1)));
  231. cache_delete(cache_system_key('unimodules', array('uniacid' => $uniacid, 'enabled' => '')));
  232. cache_clean(cache_system_key('user_accounts'));
  233. if (!empty($_GPC['from'])) {
  234. itoast('熊掌号权限修改成功', url('xzapp/post-step/', array('uniacid' => $uniacid, 'step' => 3, 'from' => 'list')), 'success');
  235. } else {
  236. header("Location: ".url('xzapp/post-step/', array('uniacid' => $uniacid, 'acid' => $acid, 'step' => 4)));
  237. exit;
  238. }
  239. }
  240. $unigroups = uni_groups();
  241. if(!empty($unigroups['modules'])) {
  242. foreach ($unigroups['modules'] as $module_key => $module_val) {
  243. if(file_exists(IA_ROOT.'/addons/'.$module_val['name'].'/icon-custom.jpg')) {
  244. $unigroups['modules'][$module_key]['logo'] = tomedia(IA_ROOT.'/addons/'.$module_val['name'].'/icon-custom.jpg');
  245. }else {
  246. $unigroups['modules'][$module_key]['logo'] = tomedia(IA_ROOT.'/addons/'.$module_val['name'].'/icon.jpg');
  247. }
  248. }
  249. }
  250. $settings = uni_setting($uniacid, array('notify'));
  251. $notify = $settings['notify'] ? $settings['notify'] : array();
  252. $ownerid = pdo_fetchcolumn("SELECT uid FROM ".tablename('uni_account_users')." WHERE uniacid = :uniacid AND role = 'owner'", array(':uniacid' => $uniacid));
  253. if (!empty($ownerid)) {
  254. $owner = user_single(array('uid' => $ownerid));
  255. $owner['group'] = pdo_fetch("SELECT id, name, package FROM ".tablename('users_group')." WHERE id = :id", array(':id' => $owner['groupid']));
  256. $owner['group']['package'] = iunserializer($owner['group']['package']);
  257. }
  258. $extend = pdo_fetch("SELECT * FROM ".tablename('uni_group')." WHERE uniacid = :uniacid", array(':uniacid' => $uniacid));
  259. $extend['templates'] = iunserializer($extend['templates']);
  260. $extend['modules'] = iunserializer($extend['modules']);
  261. if (!empty($extend['modules'])) {
  262. $extend_modules = $extend['modules'];
  263. $extend['modules'] = array();
  264. foreach ($extend_modules as $modulenames) {
  265. if (!empty($modulenames)) {
  266. $extend['modules'] = array_merge($extend['modules'], $modulenames);
  267. }
  268. }
  269. $owner['extend']['modules'] = pdo_getall('modules', array('name' => $extend['modules']));
  270. if (!empty($owner['extend']['modules'])) {
  271. foreach ($owner['extend']['modules'] as &$extend_module) {
  272. if (file_exists(IA_ROOT.'/addons/'.$extend_module['name'].'/icon-custom.jpg')) {
  273. $extend_module['logo'] = tomedia(IA_ROOT.'/addons/'.$extend_module['name'].'/icon-custom.jpg');
  274. } else {
  275. $extend_module['logo'] = tomedia(IA_ROOT.'/addons/'.$extend_module['name'].'/icon.jpg');
  276. }
  277. }
  278. unset($extend_module);
  279. }
  280. }
  281. if (!empty($extend['templates'])) {
  282. $owner['extend']['templates'] = pdo_getall('site_templates', array('id' => $extend['templates']));
  283. }
  284. $groups = user_group();
  285. $modules = user_modules($_W['uid']);
  286. $modules = array_filter($modules, function($module) {
  287. return empty($module['issystem']);
  288. });
  289. $templates = pdo_fetchall("SELECT * FROM ".tablename('site_templates'));
  290. }
  291. if ($step == 4) {
  292. $uniacid = intval($_GPC['uniacid']);
  293. $acid = intval($_GPC['acid']);
  294. $uni_account = pdo_get('uni_account', array('uniacid' => $uniacid));
  295. if (empty($uni_account)) {
  296. itoast('非法访问', '', '');
  297. }
  298. $account = account_fetch($uni_account['default_acid']);
  299. }
  300. template('xzapp/post-step');