人人商城

post.ctrl.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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('cloud');
  9. load()->model('cache');
  10. load()->model('user');
  11. load()->classs('weixin.platform');
  12. load()->model('wxapp');
  13. load()->model('utility');
  14. load()->func('file');
  15. $uniacid = intval($_GPC['uniacid']);
  16. $acid = intval($_GPC['acid']);
  17. if (empty($uniacid) || empty($acid)) {
  18. itoast('请选择要编辑的公众号', url('account/manager'), 'error');
  19. }
  20. $defaultaccount = uni_account_default($uniacid);
  21. if (!$defaultaccount) {
  22. itoast('无效的acid', url('account/manager'), 'error');
  23. }
  24. $acid = $defaultaccount['acid'];
  25. $state = permission_account_user_role($_W['uid'], $uniacid);
  26. $dos = array('base', 'sms', 'modules_tpl');
  27. $role_permission = in_array($state, array(ACCOUNT_MANAGE_NAME_FOUNDER, ACCOUNT_MANAGE_NAME_OWNER, ACCOUNT_MANAGE_NAME_VICE_FOUNDER));
  28. if ($role_permission) {
  29. $do = in_array($do, $dos) ? $do : 'base';
  30. } elseif ($state == ACCOUNT_MANAGE_NAME_MANAGER) {
  31. if (ACCOUNT_TYPE == ACCOUNT_TYPE_APP_NORMAL) {
  32. header('Location: ' . url('wxapp/manage/display', array('uniacid' => $uniacid, 'acid' => $acid)));
  33. exit;
  34. } else {
  35. $do = in_array($do, $dos) ? $do : 'modules_tpl';
  36. }
  37. } else {
  38. itoast('您是该公众号的操作员,无权限操作!', url('account/manager'), 'error');
  39. }
  40. $_W['page']['title'] = '管理设置 - 微信' . ACCOUNT_TYPE_NAME . '管理';
  41. $headimgsrc = tomedia('headimg_'.$acid.'.jpg');
  42. $qrcodeimgsrc = tomedia('qrcode_'.$acid.'.jpg');
  43. $account = account_fetch($acid);
  44. if($do == 'base') {
  45. if (!$role_permission) {
  46. itoast('无权限操作!', url('account/post/modules_tpl', array('uniacid' => $uniacid, 'acid' => $acid)), 'error');
  47. }
  48. if($_W['ispost'] && $_W['isajax']) {
  49. if(!empty($_GPC['type'])) {
  50. $type = trim($_GPC['type']);
  51. }else {
  52. iajax(40035, '参数错误!', '');
  53. }
  54. switch ($type) {
  55. case 'qrcodeimgsrc':
  56. case 'headimgsrc':
  57. $image_type = array(
  58. 'qrcodeimgsrc' => ATTACHMENT_ROOT . 'qrcode_' . $acid . '.jpg',
  59. 'headimgsrc' => ATTACHMENT_ROOT . 'headimg_' . $acid . '.jpg'
  60. );
  61. $imgsrc = $_GPC['imgsrc'];
  62. if(!file_is_image($imgsrc)){
  63. $result = '';
  64. }
  65. $result = utility_image_rename($imgsrc, $image_type[$type]);
  66. break;
  67. case 'name':
  68. $uni_account = pdo_update('uni_account', array('name' => trim($_GPC['request_data'])), array('uniacid' => $uniacid));
  69. $account_wechats = pdo_update(uni_account_tablename(ACCOUNT_TYPE), array('name' => trim($_GPC['request_data'])), array('acid' => $acid, 'uniacid' => $uniacid));
  70. $result = ($uni_account && $account_wechats) ? true : false;
  71. break;
  72. case 'account' :
  73. $data = array('account' => trim($_GPC['request_data']));break;
  74. case 'original':
  75. $data = array('original' => trim($_GPC['request_data']));break;
  76. case 'level':
  77. $data = array('level' => intval($_GPC['request_data']));break;
  78. case 'key':
  79. $data = array('key' => trim($_GPC['request_data']));break;
  80. case 'secret':
  81. $data = array('secret' => trim($_GPC['request_data']));break;
  82. case 'token':
  83. $oauth = (array)uni_setting($uniacid, array('oauth'));
  84. if($oauth['oauth'] == $acid && $account['level'] != 4) {
  85. $acid = pdo_fetchcolumn("SELECT acid FROM " . tablename('account_wechats') . " WHERE uniacid = :uniacid AND level = 4 AND secret != '' AND `key` != ''", array(':uniacid' => $uniacid));
  86. pdo_update('uni_settings', array('oauth' => iserializer(array('account' => $acid, 'host' => $oauth['oauth']['host']))), array('uniacid' => $uniacid));
  87. }
  88. $data = array('token' => trim($_GPC['request_data']));
  89. break;
  90. case 'encodingaeskey':
  91. $oauth = (array)uni_setting($uniacid, array('oauth'));
  92. if($oauth['oauth'] == $acid && $account['level'] != 4) {
  93. $acid = pdo_fetchcolumn("SELECT acid FROM " . tablename('account_wechats') . " WHERE uniacid = :uniacid AND level = 4 AND secret != '' AND `key` != ''", array(':uniacid' => $uniacid));
  94. pdo_update('uni_settings', array('oauth' => iserializer(array('account' => $acid, 'host' => $oauth['oauth']['host']))), array('uniacid' => $uniacid));
  95. }
  96. $data = array('encodingaeskey' => trim($_GPC['request_data']));
  97. break;
  98. case 'jointype':
  99. $original_type = pdo_get('account', array('uniacid' => $uniacid), 'type');
  100. if ($original_type['type'] == ACCOUNT_NORMAL_LOGIN) {
  101. $result = true;
  102. } else {
  103. $update_type = pdo_update('account', array('type' => ACCOUNT_NORMAL_LOGIN), array('uniacid' => $uniacid));
  104. $result = $update_type ? true : false;
  105. }
  106. break;
  107. }
  108. if(!in_array($type, array('qrcodeimgsrc', 'headimgsrc', 'name', 'endtime', 'jointype'))) {
  109. $result = pdo_update(uni_account_tablename(ACCOUNT_TYPE), $data, array('acid' => $acid, 'uniacid' => $uniacid));
  110. }
  111. if($result) {
  112. cache_delete("uniaccount:{$uniacid}");
  113. cache_delete("unisetting:{$uniacid}");
  114. cache_delete("accesstoken:{$acid}");
  115. cache_delete("jsticket:{$acid}");
  116. cache_delete("cardticket:{$acid}");
  117. iajax(0, '修改成功!', '');
  118. }else {
  119. iajax(1, '修改失败!', '');
  120. }
  121. }
  122. if ($_W['setting']['platform']['authstate']) {
  123. $account_platform = new WeiXinPlatform();
  124. $preauthcode = $account_platform->getPreauthCode();
  125. if (is_error($preauthcode)) {
  126. $authurl = array(
  127. 'errno' => 1,
  128. 'url' => "{$preauthcode['message']}"
  129. );
  130. } else {
  131. $authurl = array(
  132. 'errno' => 0,
  133. 'url' => sprintf(ACCOUNT_PLATFORM_API_LOGIN, $account_platform->appid, $preauthcode, urlencode(urlencode($GLOBALS['_W']['siteroot'] . 'index.php?c=account&a=auth&do=forward')))
  134. );
  135. }
  136. }
  137. $account['end'] = $account['endtime'] == 0 ? '永久' : date('Y-m-d', $account['endtime']);
  138. $account['endtype'] = $account['endtime'] == 0 ? 1 : 2;
  139. $uniaccount = array();
  140. $uniaccount = pdo_get('uni_account', array('uniacid' => $uniacid));
  141. template('account/manage-base' . ACCOUNT_TYPE_TEMPLATE);
  142. }
  143. if($do == 'sms') {
  144. if (!$role_permission) {
  145. itoast('无权限操作!', url('account/post/modules_tpl', array('uniacid' => $uniacid, 'acid' => $acid)), 'error');
  146. }
  147. $settings = uni_setting($uniacid, array('notify'));
  148. $notify = $settings['notify'] ? $settings['notify'] : array();
  149. $sms_info = cloud_sms_info();
  150. $max_num = empty($sms_info['sms_count']) ? 0 : $sms_info['sms_count'];
  151. $signatures = $sms_info['sms_sign'];
  152. if ($_W['isajax'] && $_W['ispost'] && $_GPC['type'] == 'balance') {
  153. if ($max_num == 0) {
  154. iajax(-1, '您现有短信数量为0,请联系服务商购买短信!', '');
  155. }
  156. $balance = intval($_GPC['balance']);
  157. $notify['sms']['balance'] = $balance;
  158. $notify['sms']['balance'] = min(max(0, $notify['sms']['balance']), $max_num);
  159. $count_num = $max_num - $notify['sms']['balance'];
  160. $num = $notify['sms']['balance'];
  161. $notify = iserializer($notify);
  162. $updatedata['notify'] = $notify;
  163. $result = pdo_update('uni_settings', $updatedata , array('uniacid' => $uniacid));
  164. if($result){
  165. iajax(0, array('count' => $count_num, 'num' => $num), '');
  166. }else {
  167. iajax(1, '修改失败!', '');
  168. }
  169. }
  170. if($_W['isajax'] && $_W['ispost'] && $_GPC['type'] == 'signature') {
  171. if (!empty($_GPC['signature'])) {
  172. $signature = trim($_GPC['signature']);
  173. $setting = pdo_get('uni_settings', array('uniacid' => $uniacid));
  174. $notify = iunserializer($setting['notify']);
  175. $notify['sms']['signature'] = $signature;
  176. $notify = serialize($notify);
  177. $result = pdo_update('uni_settings', array('notify' => $notify), array('uniacid' => $uniacid));
  178. if($result) {
  179. iajax(0, '修改成功!', '');
  180. }else {
  181. iajax(1, '修改失败!', '');
  182. }
  183. }else {
  184. iajax(40035, '参数错误!', '');
  185. }
  186. }
  187. template('account/manage-sms' . ACCOUNT_TYPE_TEMPLATE);
  188. }
  189. if($do == 'modules_tpl') {
  190. $unigroups = uni_groups(array(), true);
  191. $uni_groups = uni_groups();
  192. $owner = account_owner($uniacid);
  193. if($_W['isajax'] && $_W['ispost'] && ($role_permission)) {
  194. if($_GPC['type'] == 'group') {
  195. $groups = $_GPC['groupdata'];
  196. if(!empty($groups)) {
  197. pdo_delete('uni_account_group', array('uniacid' => $uniacid));
  198. $group = pdo_get('users_group', array('id' => $owner['groupid']));
  199. $group['package'] = (array)iunserializer($group['package']);
  200. $group['package'] = array_unique($group['package']);
  201. foreach ($groups as $packageid) {
  202. if (!empty($packageid) && !in_array($packageid, $group['package'])) {
  203. pdo_insert('uni_account_group', array(
  204. 'uniacid' => $uniacid,
  205. 'groupid' => $packageid,
  206. ));
  207. }
  208. }
  209. cache_build_account_modules($uniacid);
  210. cache_build_account($uniacid);
  211. iajax(0, '修改成功!', '');
  212. }else {
  213. pdo_delete('uni_account_group', array('uniacid' => $uniacid));
  214. cache_build_account_modules($uniacid);
  215. cache_build_account($uniacid);
  216. iajax(0, '修改成功!', '');
  217. }
  218. }
  219. if($_GPC['type'] == 'extend') {
  220. $module = $_GPC['module'];
  221. $tpl = $_GPC['tpl'];
  222. if (!empty($module) || !empty($tpl)) {
  223. $data = array(
  224. 'modules' => iserializer($module),
  225. 'templates' => iserializer($tpl),
  226. 'uniacid' => $uniacid,
  227. 'name' => '',
  228. );
  229. $id = pdo_fetchcolumn("SELECT id FROM ".tablename('uni_group')." WHERE uniacid = :uniacid", array(':uniacid' => $uniacid));
  230. if (empty($id)) {
  231. pdo_insert('uni_group', $data);
  232. } else {
  233. pdo_update('uni_group', $data, array('id' => $id));
  234. }
  235. } else {
  236. pdo_delete('uni_group', array('uniacid' => $uniacid));
  237. }
  238. cache_build_account_modules($uniacid);
  239. cache_build_account($uniacid);
  240. iajax(0, '修改成功!', '');
  241. }
  242. iajax(40035, '参数错误!', '');
  243. }
  244. $modules_tpl = $extend = array();
  245. $founders = explode(',', $_W['config']['setting']['founder']);
  246. if (in_array($owner['uid'], $founders)) {
  247. $modules_tpl[] = array(
  248. 'id' => -1,
  249. 'name' => '所有服务',
  250. 'modules' => array(array('name' => 'all', 'title' => '所有模块')),
  251. 'templates' => array(array('name' => 'all', 'title' => '所有模板')),
  252. 'type' => 'default'
  253. );
  254. } else {
  255. if ($owner['founder_groupid'] == ACCOUNT_MANAGE_GROUP_VICE_FOUNDER) {
  256. $owner['group'] = pdo_get('users_founder_group', array('id' => $owner['groupid']), array('id', 'name', 'package'));
  257. } else {
  258. $owner['group'] = pdo_get('users_group', array('id' => $owner['groupid']), array('id', 'name', 'package'));
  259. }
  260. $owner['group']['package'] = iunserializer($owner['group']['package']);
  261. if(!empty($owner['group']['package'])){
  262. foreach ($owner['group']['package'] as $package_value) {
  263. if($package_value == -1){
  264. $modules_tpl[] = array(
  265. 'id' => -1,
  266. 'name' => '所有服务',
  267. 'modules' => array(array('name' => 'all', 'title' => '所有模块')),
  268. 'templates' => array(array('name' => 'all', 'title' => '所有模板')),
  269. 'type' => 'default'
  270. );
  271. }elseif ($package_value == 0) {
  272. }else {
  273. $defaultmodule = $unigroups[$package_value];
  274. $defaultmodule['type'] = 'default';
  275. $modules_tpl[] = $defaultmodule;
  276. }
  277. }
  278. }
  279. $extendpackage = pdo_getall('uni_account_group', array('uniacid' => $uniacid), array(), 'groupid');
  280. if(!empty($extendpackage)) {
  281. foreach ($extendpackage as $extendpackage_val) {
  282. if($extendpackage_val['groupid'] == -1){
  283. $modules_tpl[] = array(
  284. 'id' => -1,
  285. 'name' => '所有服务',
  286. 'modules' => array(array('name' => 'all', 'title' => '所有模块')),
  287. 'templates' => array(array('name' => 'all', 'title' => '所有模板')),
  288. 'type' => 'extend' );
  289. }elseif ($extendpackage_val['groupid'] == 0) {
  290. }else {
  291. $ex_module = $unigroups[$extendpackage_val['groupid']];
  292. $ex_module['type'] = 'extend';
  293. $modules_tpl[] = $ex_module;
  294. }
  295. }
  296. }
  297. }
  298. $modules = user_modules($_W['uid']);
  299. $templates = pdo_getall('site_templates', array(), array('id', 'name', 'title'));
  300. $extend = pdo_get('uni_group', array('uniacid' => $uniacid));
  301. $extend['modules'] = $current_module_names = iunserializer($extend['modules']);
  302. $extend['templates'] = iunserializer($extend['templates']);
  303. $canmodify = false;
  304. if ($_W['role'] == ACCOUNT_MANAGE_NAME_FOUNDER && !in_array($owner['uid'], $founders) || $_W['role'] == ACCOUNT_MANAGE_NAME_VICE_FOUNDER && $owner['uid'] != $_W['uid']) {
  305. $canmodify = true;
  306. }
  307. if (!empty($extend['modules'])) {
  308. foreach ($extend['modules'] as $module_key => $module_val) {
  309. $extend['modules'][$module_key] = module_fetch($module_val);
  310. }
  311. }
  312. if (!empty($extend['templates'])) {
  313. $extend['templates'] = pdo_getall('site_templates', array('id' => $extend['templates']), array('id', 'name', 'title'));
  314. }
  315. template('account/manage-modules-tpl' . ACCOUNT_TYPE_TEMPLATE);
  316. }