人人商城

step.ctrl.php 13KB

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