post.ctrl.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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/manage'), 'error');
  19. }
  20. $defaultaccount = uni_account_default($uniacid);
  21. if (!$defaultaccount) {
  22. itoast('无效的acid', url('account/manage'), '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/manage'), '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_load(array('oauth'), $uniacid);
  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_load(array('oauth'), $uniacid);
  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. case 'highest_visit':
  108. if (user_is_vice_founder() || empty($_W['isfounder'])) {
  109. iajax(1, '只有创始人可以修改!');
  110. }
  111. $statistics_setting = (array)uni_setting_load(array('statistics'), $uniacid);
  112. if (!empty($statistics_setting['statistics'])) {
  113. $highest_visit = $statistics_setting['statistics'];
  114. $highest_visit['founder'] = intval($_GPC['request_data']);
  115. } else {
  116. $highest_visit = array('founder' => intval($_GPC['request_data']));
  117. }
  118. $result = pdo_update('uni_settings', array('statistics' => iserializer($highest_visit)), array('uniacid' => $uniacid));
  119. break;
  120. case 'endtime':
  121. if ($_GPC['endtype'] == 1) {
  122. $result = pdo_update('account', array('endtime' => -1), array('uniacid' => $uniacid));
  123. } else {
  124. $endtime = strtotime($_GPC['endtime']);
  125. $user_endtime = pdo_getcolumn('users', array('uid' => $_W['uid']), 'endtime');
  126. if ($user_endtime < $endtime && !empty($user_endtime) && $state == 'owner') {
  127. iajax(1, '设置到期日期不能超过主管理员的到期日期');
  128. }
  129. $result = pdo_update('account', array('endtime' => $endtime), array('uniacid' => $uniacid));
  130. }
  131. }
  132. if(!in_array($type, array('qrcodeimgsrc', 'headimgsrc', 'name', 'endtime', 'jointype', 'highest_visit'))) {
  133. $result = pdo_update(uni_account_tablename(ACCOUNT_TYPE), $data, array('acid' => $acid, 'uniacid' => $uniacid));
  134. }
  135. if($result) {
  136. cache_delete("uniaccount:{$uniacid}");
  137. cache_delete("unisetting:{$uniacid}");
  138. cache_delete("accesstoken:{$acid}");
  139. cache_delete("jsticket:{$acid}");
  140. cache_delete("cardticket:{$acid}");
  141. $cachekey = cache_system_key("statistics:{$uniacid}");
  142. cache_delete($cachekey);
  143. iajax(0, '修改成功!', '');
  144. }else {
  145. iajax(1, '修改失败!', '');
  146. }
  147. }
  148. if ($_W['setting']['platform']['authstate']) {
  149. $account_platform = new WeiXinPlatform();
  150. $preauthcode = $account_platform->getPreauthCode();
  151. if (is_error($preauthcode)) {
  152. $authurl = array(
  153. 'errno' => 1,
  154. 'url' => "{$preauthcode['message']}"
  155. );
  156. } else {
  157. $authurl = array(
  158. 'errno' => 0,
  159. 'url' => sprintf(ACCOUNT_PLATFORM_API_LOGIN, $account_platform->appid, $preauthcode, urlencode($GLOBALS['_W']['siteroot'] . 'index.php?c=account&a=auth&do=forward'))
  160. );
  161. }
  162. }
  163. $account['end'] = $account['endtime'] == 0 ? '永久' : date('Y-m-d', $account['endtime']);
  164. $account['endtype'] = $account['endtime'] == 0 ? 1 : 2;
  165. $statistics_setting = (array)uni_setting_load(array('statistics'), $uniacid);
  166. $account['highest_visit'] = empty($statistics_setting['statistics']['founder']) ? 0 : $statistics_setting['statistics']['founder'];
  167. $uniaccount = array();
  168. $uniaccount = pdo_get('uni_account', array('uniacid' => $uniacid));
  169. $account_api = uni_site_store_buy_goods($uniacid, STORE_TYPE_API);
  170. template('account/manage-base' . ACCOUNT_TYPE_TEMPLATE);
  171. }
  172. if($do == 'sms') {
  173. if (!$role_permission) {
  174. itoast('无权限操作!', url('account/post/modules_tpl', array('uniacid' => $uniacid, 'acid' => $acid)), 'error');
  175. }
  176. $settings = uni_setting($uniacid, array('notify'));
  177. $notify = $settings['notify'] ? $settings['notify'] : array();
  178. $sms_info = cloud_sms_info();
  179. $max_num = empty($sms_info['sms_count']) ? 0 : $sms_info['sms_count'];
  180. $signatures = $sms_info['sms_sign'];
  181. if ($_W['isajax'] && $_W['ispost'] && $_GPC['type'] == 'balance') {
  182. if ($max_num == 0) {
  183. iajax(-1, '您现有短信数量为0,请联系服务商购买短信!', '');
  184. }
  185. $balance = intval($_GPC['balance']);
  186. $notify['sms']['balance'] = $balance;
  187. $notify['sms']['balance'] = min(max(0, $notify['sms']['balance']), $max_num);
  188. $count_num = $max_num - $notify['sms']['balance'];
  189. $num = $notify['sms']['balance'];
  190. $notify = iserializer($notify);
  191. $updatedata['notify'] = $notify;
  192. $result = pdo_update('uni_settings', $updatedata , array('uniacid' => $uniacid));
  193. if($result){
  194. iajax(0, array('count' => $count_num, 'num' => $num), '');
  195. }else {
  196. iajax(1, '修改失败!', '');
  197. }
  198. }
  199. if($_W['isajax'] && $_W['ispost'] && $_GPC['type'] == 'signature') {
  200. if (!empty($_GPC['signature'])) {
  201. $signature = trim($_GPC['signature']);
  202. $setting = pdo_get('uni_settings', array('uniacid' => $uniacid));
  203. $notify = iunserializer($setting['notify']);
  204. $notify['sms']['signature'] = $signature;
  205. $notify = serialize($notify);
  206. $result = pdo_update('uni_settings', array('notify' => $notify), array('uniacid' => $uniacid));
  207. if($result) {
  208. iajax(0, '修改成功!', '');
  209. }else {
  210. iajax(1, '修改失败!', '');
  211. }
  212. }else {
  213. iajax(40035, '参数错误!', '');
  214. }
  215. }
  216. template('account/manage-sms' . ACCOUNT_TYPE_TEMPLATE);
  217. }
  218. if($do == 'modules_tpl') {
  219. $unigroups = uni_groups(array(), true);
  220. $uni_groups = uni_groups();
  221. $owner = account_owner($uniacid);
  222. if($_W['isajax'] && $_W['ispost'] && ($role_permission)) {
  223. if($_GPC['type'] == 'group') {
  224. $groups = $_GPC['groupdata'];
  225. if(!empty($groups)) {
  226. pdo_delete('uni_account_group', array('uniacid' => $uniacid));
  227. $group = pdo_get('users_group', array('id' => $owner['groupid']));
  228. $group['package'] = (array)iunserializer($group['package']);
  229. $group['package'] = array_unique($group['package']);
  230. foreach ($groups as $packageid) {
  231. if (!empty($packageid) && !in_array($packageid, $group['package'])) {
  232. pdo_insert('uni_account_group', array(
  233. 'uniacid' => $uniacid,
  234. 'groupid' => $packageid,
  235. ));
  236. }
  237. }
  238. cache_build_account_modules($uniacid);
  239. cache_build_account($uniacid);
  240. iajax(0, '修改成功!', '');
  241. }else {
  242. pdo_delete('uni_account_group', array('uniacid' => $uniacid));
  243. cache_build_account_modules($uniacid);
  244. cache_build_account($uniacid);
  245. iajax(0, '修改成功!', '');
  246. }
  247. }
  248. if($_GPC['type'] == 'extend') {
  249. $module = $_GPC['module'];
  250. $tpl = $_GPC['tpl'];
  251. if (!empty($module) || !empty($tpl)) {
  252. $data = array(
  253. 'modules' => iserializer($module),
  254. 'templates' => iserializer($tpl),
  255. 'uniacid' => $uniacid,
  256. 'name' => '',
  257. );
  258. $id = pdo_fetchcolumn("SELECT id FROM ".tablename('uni_group')." WHERE uniacid = :uniacid", array(':uniacid' => $uniacid));
  259. if (empty($id)) {
  260. pdo_insert('uni_group', $data);
  261. } else {
  262. pdo_update('uni_group', $data, array('id' => $id));
  263. }
  264. } else {
  265. pdo_delete('uni_group', array('uniacid' => $uniacid));
  266. }
  267. cache_build_account_modules($uniacid);
  268. cache_build_account($uniacid);
  269. iajax(0, '修改成功!', '');
  270. }
  271. iajax(40035, '参数错误!', '');
  272. }
  273. $modules_tpl = $extend = array();
  274. $founders = explode(',', $_W['config']['setting']['founder']);
  275. if (in_array($owner['uid'], $founders)) {
  276. $modules_tpl[] = array(
  277. 'id' => -1,
  278. 'name' => '所有服务',
  279. 'modules' => array(array('name' => 'all', 'title' => '所有模块')),
  280. 'templates' => array(array('name' => 'all', 'title' => '所有模板')),
  281. 'type' => 'default'
  282. );
  283. } else {
  284. if ($owner['founder_groupid'] == ACCOUNT_MANAGE_GROUP_VICE_FOUNDER) {
  285. $owner['group'] = pdo_get('users_founder_group', array('id' => $owner['groupid']), array('id', 'name', 'package'));
  286. } else {
  287. $owner['group'] = pdo_get('users_group', array('id' => $owner['groupid']), array('id', 'name', 'package'));
  288. }
  289. $owner['group']['package'] = iunserializer($owner['group']['package']);
  290. if(!empty($owner['group']['package'])){
  291. foreach ($owner['group']['package'] as $package_value) {
  292. if($package_value == -1){
  293. $modules_tpl[] = array(
  294. 'id' => -1,
  295. 'name' => '所有服务',
  296. 'modules' => array(array('name' => 'all', 'title' => '所有模块')),
  297. 'templates' => array(array('name' => 'all', 'title' => '所有模板')),
  298. 'type' => 'default'
  299. );
  300. }elseif ($package_value == 0) {
  301. }else {
  302. $defaultmodule = $unigroups[$package_value];
  303. $defaultmodule['type'] = 'default';
  304. $modules_tpl[] = $defaultmodule;
  305. }
  306. }
  307. }
  308. $extendpackage = pdo_getall('uni_account_group', array('uniacid' => $uniacid), array(), 'groupid');
  309. if(!empty($extendpackage)) {
  310. foreach ($extendpackage as $extendpackage_val) {
  311. if($extendpackage_val['groupid'] == -1){
  312. $modules_tpl[] = array(
  313. 'id' => -1,
  314. 'name' => '所有服务',
  315. 'modules' => array(array('name' => 'all', 'title' => '所有模块')),
  316. 'templates' => array(array('name' => 'all', 'title' => '所有模板')),
  317. 'type' => 'extend' );
  318. }elseif ($extendpackage_val['groupid'] == 0) {
  319. }else {
  320. $ex_module = $unigroups[$extendpackage_val['groupid']];
  321. $ex_module['type'] = 'extend';
  322. $modules_tpl[] = $ex_module;
  323. }
  324. }
  325. }
  326. }
  327. $modules = user_modules($_W['uid']);
  328. $templates = pdo_getall('site_templates', array(), array('id', 'name', 'title'));
  329. $extend = pdo_get('uni_group', array('uniacid' => $uniacid));
  330. $extend['modules'] = $current_module_names = iunserializer($extend['modules']);
  331. $extend['templates'] = iunserializer($extend['templates']);
  332. $canmodify = false;
  333. if ($_W['role'] == ACCOUNT_MANAGE_NAME_FOUNDER && !in_array($owner['uid'], $founders) || $_W['role'] == ACCOUNT_MANAGE_NAME_VICE_FOUNDER && $owner['uid'] != $_W['uid']) {
  334. $canmodify = true;
  335. }
  336. if (!empty($extend['modules'])) {
  337. foreach ($extend['modules'] as $module_key => $module_val) {
  338. $extend['modules'][$module_key] = module_fetch($module_val);
  339. }
  340. }
  341. if (!empty($extend['templates'])) {
  342. $extend['templates'] = pdo_getall('site_templates', array('id' => $extend['templates']), array('id', 'name', 'title'));
  343. }
  344. $account_buy_modules = uni_site_store_buy_goods($uniacid);
  345. if (!empty($account_buy_modules) && is_array($account_buy_modules)) {
  346. foreach ($account_buy_modules as &$module) {
  347. $module = module_fetch($module);
  348. $module['goods_id'] = pdo_getcolumn('site_store_goods', array('module' => $module['name']), 'id');
  349. $module['expire_time'] = pdo_getcolumn('site_store_order', array('uniacid' => $uniacid, 'type' => STORE_ORDER_FINISH, 'goodsid' => $module['goods_id']), 'max(endtime)');
  350. }
  351. }
  352. unset($module);
  353. $store = table('store');
  354. $account_buy_group = uni_site_store_buy_goods($uniacid, STORE_TYPE_PACKAGE);
  355. $account_buy_package = array();
  356. if (is_array($account_buy_group) && !empty($account_buy_group)) {
  357. foreach ($account_buy_group as $group) {
  358. $account_buy_package[$group] = $uni_groups[$group];
  359. $account_buy_package[$group]['goods_id'] = pdo_getcolumn('site_store_goods', array('module_group' => $group), 'id');
  360. $account_buy_package[$group]['expire_time'] = pdo_getcolumn('site_store_order', array('uniacid' => $uniacid, 'type' => STORE_ORDER_FINISH, 'goodsid' => $account_buy_package[$group]['goods_id']), 'max(endtime)');
  361. if (TIMESTAMP > $account_buy_package[$group]['expire_time']) {
  362. $account_buy_package[$group]['expire'] = true;
  363. } else {
  364. $account_buy_package[$group]['expire'] = false;
  365. $account_buy_package[$group]['near_expire'] = strtotime('-1 week', $account_buy_package[$group]['expire_time']) < time() ? true : false;
  366. }
  367. $account_buy_package[$group]['expire_time'] = date('Y-m-d', $account_buy_package[$group]['expire_time']);
  368. }
  369. }
  370. unset($group);
  371. template('account/manage-modules-tpl' . ACCOUNT_TYPE_TEMPLATE);
  372. }