post.ctrl.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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()->classs('weixin.platform');
  11. load()->model('utility');
  12. load()->func('file');
  13. $uniacid = intval($_GPC['uniacid']);
  14. if (empty($uniacid)) {
  15. $url = url('account/manage', array('account_type' => ACCOUNT_TYPE));
  16. itoast('请选择要编辑的' . ACCOUNT_TYPE_NAME, $url, 'error');
  17. }
  18. $defaultaccount = uni_account_default($uniacid);
  19. if (!$defaultaccount) {
  20. itoast('无效的acid', url('account/manage'), 'error');
  21. }
  22. $acid = $defaultaccount['acid'];
  23. $state = permission_account_user_role($_W['uid'], $uniacid);
  24. $dos = array('base', 'sms', 'modules_tpl');
  25. $role_permission = in_array($state, array(ACCOUNT_MANAGE_NAME_FOUNDER, ACCOUNT_MANAGE_NAME_OWNER, ACCOUNT_MANAGE_NAME_VICE_FOUNDER));
  26. if ($role_permission) {
  27. $do = in_array($do, $dos) ? $do : 'base';
  28. } elseif ($state == ACCOUNT_MANAGE_NAME_MANAGER) {
  29. if (ACCOUNT_TYPE == ACCOUNT_TYPE_APP_NORMAL || ACCOUNT_TYPE == ACCOUNT_TYPE_APP_AUTH) {
  30. header('Location: ' . url('wxapp/manage/display', array('uniacid' => $uniacid, 'acid' => $acid)));
  31. exit;
  32. } else {
  33. $do = in_array($do, $dos) ? $do : 'modules_tpl';
  34. }
  35. } else {
  36. itoast('您是该公众号的操作员,无权限操作!', url('account/manage'), 'error');
  37. }
  38. $headimgsrc = tomedia('headimg_'.$acid.'.jpg');
  39. $qrcodeimgsrc = tomedia('qrcode_'.$acid.'.jpg');
  40. $account = account_fetch($acid);
  41. if($do == 'base') {
  42. if (!$role_permission) {
  43. itoast('无权限操作!', url('account/post/modules_tpl', array('uniacid' => $uniacid, 'acid' => $acid)), 'error');
  44. }
  45. if($_W['ispost'] && $_W['isajax']) {
  46. if(!empty($_GPC['type'])) {
  47. $type = trim($_GPC['type']);
  48. } else {
  49. iajax(40035, '参数错误!', '');
  50. }
  51. $request_data = safe_gpc_string(trim($_GPC['request_data']));
  52. switch ($type) {
  53. case 'qrcodeimgsrc':
  54. case 'headimgsrc':
  55. $image_type = array(
  56. 'qrcodeimgsrc' => ATTACHMENT_ROOT . 'qrcode_' . $acid . '.jpg',
  57. 'headimgsrc' => ATTACHMENT_ROOT . 'headimg_' . $acid . '.jpg'
  58. );
  59. $imgsrc = safe_gpc_path($_GPC['imgsrc']);
  60. if(file_is_image($imgsrc)){
  61. $result = utility_image_rename($imgsrc, $image_type[$type]);
  62. } else {
  63. $result = '';
  64. }
  65. break;
  66. case 'name':
  67. $uni_account = pdo_update('uni_account', array('name' => $request_data), array('uniacid' => $uniacid));
  68. $account_wechats = pdo_update($account->tablename, array('name' => $request_data), array('acid' => $acid, 'uniacid' => $uniacid));
  69. $result = ($uni_account && $account_wechats) ? true : false;
  70. break;
  71. case 'account' :
  72. $data = array('account' => $request_data);break;
  73. case 'original':
  74. $data = array('original' => $request_data);break;
  75. case 'level':
  76. $data = array('level' => intval($_GPC['request_data']));break;
  77. case 'appid':
  78. $data = array('appid' => $request_data);break;
  79. case 'key':
  80. if ($account['key'] == $request_data) {
  81. iajax(0, '修改成功!');
  82. }
  83. $data = array('key' => $request_data);break;
  84. case 'secret':
  85. if ($account['secret'] == $request_data) {
  86. iajax(0, '修改成功!');
  87. }
  88. $data = array('secret' => $request_data);break;
  89. case 'token':
  90. $oauth = (array)uni_setting_load(array('oauth'), $uniacid);
  91. if($oauth['oauth'] == $acid && $account['level'] != 4) {
  92. $acid = pdo_fetchcolumn("SELECT acid FROM " . tablename('account_wechats') . " WHERE uniacid = :uniacid AND level = 4 AND secret != '' AND `key` != ''", array(':uniacid' => $uniacid));
  93. pdo_update('uni_settings', array('oauth' => iserializer(array('account' => $acid, 'host' => $oauth['oauth']['host']))), array('uniacid' => $uniacid));
  94. }
  95. $data = array('token' => $request_data);
  96. break;
  97. case 'encodingaeskey':
  98. $oauth = (array)uni_setting_load(array('oauth'), $uniacid);
  99. if($oauth['oauth'] == $acid && $account['level'] != 4) {
  100. $acid = pdo_fetchcolumn("SELECT acid FROM " . tablename('account_wechats') . " WHERE uniacid = :uniacid AND level = 4 AND secret != '' AND `key` != ''", array(':uniacid' => $uniacid));
  101. pdo_update('uni_settings', array('oauth' => iserializer(array('account' => $acid, 'host' => $oauth['oauth']['host']))), array('uniacid' => $uniacid));
  102. }
  103. $data = array('encodingaeskey' => $request_data);
  104. break;
  105. case 'jointype':
  106. if (in_array($account['type'], array(ACCOUNT_TYPE_OFFCIAL_NORMAL, ACCOUNT_TYPE_APP_NORMAL))) {
  107. $result = true;
  108. } else {
  109. $change_type = array(
  110. 'type' => $account->typeSign == 'account' ? ACCOUNT_TYPE_OFFCIAL_NORMAL : ACCOUNT_TYPE_APP_NORMAL
  111. );
  112. $update_type = pdo_update('account', $change_type, array('uniacid' => $uniacid));
  113. $result = $update_type ? true : false;
  114. }
  115. break;
  116. case 'highest_visit':
  117. if (user_is_vice_founder() || empty($_W['isfounder'])) {
  118. iajax(1, '只有创始人可以修改!');
  119. }
  120. $statistics_setting = (array)uni_setting_load(array('statistics'), $uniacid);
  121. if (!empty($statistics_setting['statistics'])) {
  122. $highest_visit = $statistics_setting['statistics'];
  123. $highest_visit['founder'] = intval($_GPC['request_data']);
  124. } else {
  125. $highest_visit = array('founder' => intval($_GPC['request_data']));
  126. }
  127. $result = pdo_update('uni_settings', array('statistics' => iserializer($highest_visit)), array('uniacid' => $uniacid));
  128. break;
  129. case 'endtime':
  130. $endtime = strtotime($_GPC['endtime']);
  131. if ($endtime <= 0) {
  132. iajax(1, '参数错误!');
  133. }
  134. $store_create_account_info = table('store')->StoreCreateAccountInfo($uniacid);
  135. if (user_is_founder($_W['uid'], true)) {
  136. if (!empty($store_create_account_info)) {
  137. pdo_update('site_store_create_account', array('endtime' => $endtime), array('uniacid' => $uniacid));
  138. }
  139. } else {
  140. $owner_id = pdo_getcolumn('uni_account_users', array('uniacid' => $uniacid, 'role' => 'owner'), 'uid');
  141. $user_endtime = pdo_getcolumn('users', array('uid' => $owner_id), 'endtime');
  142. if (!empty($store_create_account_info)) {
  143. $user_endtime = max($user_endtime, $store_create_account_info['endtime']);
  144. }
  145. if ($user_endtime < $endtime && !empty($user_endtime)) {
  146. iajax(1, '设置到期日期不能超过' . date('Y-m-d', $user_endtime));
  147. }
  148. }
  149. $result = pdo_update('account', array('endtime' => $endtime), array('uniacid' => $uniacid));
  150. break;
  151. case 'attachment_limit':
  152. if (user_is_vice_founder() || empty($_W['isfounder'])) {
  153. iajax(1, '只有创始人可以修改!');
  154. }
  155. $has_uniacid = pdo_getcolumn('uni_settings', array('uniacid' => $uniacid), 'uniacid');
  156. if ($_GPC['request_data'] < 0) {
  157. $attachment_limit = -1;
  158. } else {
  159. $attachment_limit = intval($_GPC['request_data']);
  160. }
  161. if (empty($has_uniacid)) {
  162. $result = pdo_insert('uni_settings', array('attachment_limit' => $attachment_limit, 'uniacid' => $uniacid));
  163. } else {
  164. $result = pdo_update('uni_settings', array('attachment_limit' => $attachment_limit), array('uniacid' => $uniacid));
  165. }
  166. break;
  167. }
  168. if(!in_array($type, array('qrcodeimgsrc', 'headimgsrc', 'name', 'endtime', 'jointype', 'highest_visit', 'attachment_limit'))) {
  169. $result = pdo_update($account->tablename, $data, array('acid' => $acid, 'uniacid' => $uniacid));
  170. }
  171. if($result) {
  172. cache_delete(cache_system_key('uniaccount', array('uniacid' => $uniacid)));
  173. cache_delete(cache_system_key('accesstoken', array('uniacid' => $uniacid)));
  174. cache_delete(cache_system_key('statistics', array('uniacid' => $uniacid)));
  175. iajax(0, '修改成功!', '');
  176. } else {
  177. iajax(1, '修改失败!', '');
  178. }
  179. }
  180. if ($_W['setting']['platform']['authstate']) {
  181. $account_platform = new WeixinPlatform();
  182. $preauthcode = $account_platform->getPreauthCode();
  183. if (is_error($preauthcode)) {
  184. if ($preauthcode['errno'] == 40013) {
  185. $url = "微信开放平台 appid 链接不成功,请检查修改后再试" . "<a href='" . url('system/platform') . "' style='color:#3296fa'>去设置</a>";
  186. } else {
  187. $url = "{$preauthcode['message']}";
  188. }
  189. $authurl = array(
  190. 'errno' => 1,
  191. 'url' => $url,
  192. );
  193. } else {
  194. $authurl = array(
  195. 'errno' => 0,
  196. 'url' => sprintf(ACCOUNT_PLATFORM_API_LOGIN, $account_platform->appid, $preauthcode, urlencode($GLOBALS['_W']['siteroot'] . 'index.php?c=account&a=auth&do=forward'), ACCOUNT_PLATFORM_API_LOGIN_ACCOUNT)
  197. );
  198. }
  199. }
  200. $account['start'] = date('Y-m-d', $account['starttime']);
  201. $account['end'] = in_array($account['endtime'], array(USER_ENDTIME_GROUP_EMPTY_TYPE, USER_ENDTIME_GROUP_UNLIMIT_TYPE)) ? '永久' : date('Y-m-d', $account['endtime']);
  202. $account['endtype'] = $account['endtime'] == 0 ? 1 : 2;
  203. $uni_setting = (array)uni_setting_load(array('statistics', 'attachment_limit', 'attachment_size'), $uniacid);
  204. $account['highest_visit'] = empty($uni_setting['statistics']['founder']) ? 0 : $uni_setting['statistics']['founder'];
  205. $account['attachment_size'] = round($uni_setting['attachment_size'] / 1024, 2);
  206. $attachment_limit = intval($uni_setting['attachment_limit']);
  207. if ($attachment_limit == 0) {
  208. $upload = setting_load('upload');
  209. $attachment_limit = empty($upload['upload']['attachment_limit']) ? 0 : intval($upload['upload']['attachment_limit']);
  210. }
  211. if ($attachment_limit <= 0) {
  212. $attachment_limit = -1;
  213. }
  214. $account['attachment_limit'] = intval($attachment_limit);
  215. $uniaccount = array();
  216. $uniaccount = pdo_get('uni_account', array('uniacid' => $uniacid));
  217. $account_api = uni_site_store_buy_goods($uniacid, STORE_TYPE_API);
  218. template('account/manage-base' . ACCOUNT_TYPE_TEMPLATE);
  219. }
  220. if($do == 'sms') {
  221. if (!$role_permission) {
  222. itoast('无权限操作!', url('account/post/modules_tpl', array('uniacid' => $uniacid, 'acid' => $acid)), 'error');
  223. }
  224. $settings = uni_setting($uniacid, array('notify'));
  225. $notify = $settings['notify'] ? $settings['notify'] : array();
  226. $sms_info = cloud_sms_info();
  227. $max_num = empty($sms_info['sms_count']) ? 0 : $sms_info['sms_count'];
  228. $signatures = $sms_info['sms_sign'];
  229. if ($_W['isajax'] && $_W['ispost'] && $_GPC['type'] == 'balance') {
  230. if ($max_num == 0) {
  231. iajax(-1, '您现有短信数量为0,请联系服务商购买短信!', '');
  232. }
  233. $balance = intval($_GPC['balance']);
  234. $notify['sms']['balance'] = $balance;
  235. $notify['sms']['balance'] = min(max(0, $notify['sms']['balance']), $max_num);
  236. $count_num = $max_num - $notify['sms']['balance'];
  237. $num = $notify['sms']['balance'];
  238. $notify = iserializer($notify);
  239. $updatedata['notify'] = $notify;
  240. $result = pdo_update('uni_settings', $updatedata , array('uniacid' => $uniacid));
  241. cache_delete(cache_system_key('uniaccount', array('uniacid' => $uniacid)));
  242. if($result){
  243. iajax(0, array('count' => $count_num, 'num' => $num), '');
  244. }else {
  245. iajax(1, '修改失败!', '');
  246. }
  247. }
  248. if($_W['isajax'] && $_W['ispost'] && $_GPC['type'] == 'signature') {
  249. if (!empty($_GPC['signature'])) {
  250. $signature = trim($_GPC['signature']);
  251. $setting = pdo_get('uni_settings', array('uniacid' => $uniacid));
  252. $notify = iunserializer($setting['notify']);
  253. $notify['sms']['signature'] = $signature;
  254. $notify = serialize($notify);
  255. $result = pdo_update('uni_settings', array('notify' => $notify), array('uniacid' => $uniacid));
  256. if($result) {
  257. iajax(0, '修改成功!', '');
  258. }else {
  259. iajax(1, '修改失败!', '');
  260. }
  261. }else {
  262. iajax(40035, '参数错误!', '');
  263. }
  264. }
  265. template('account/manage-sms' . ACCOUNT_TYPE_TEMPLATE);
  266. }
  267. if($do == 'modules_tpl') {
  268. $owner = $account->owner;
  269. if($_W['isajax'] && $_W['ispost'] && ($role_permission)) {
  270. if($_GPC['type'] == 'group') {
  271. $groups = $_GPC['groupdata'];
  272. if(!empty($groups)) {
  273. pdo_delete('uni_account_group', array('uniacid' => $uniacid));
  274. $group = pdo_get('users_group', array('id' => $owner['groupid']));
  275. $group['package'] = (array)iunserializer($group['package']);
  276. $group['package'] = array_unique($group['package']);
  277. foreach ($groups as $packageid) {
  278. if (!empty($packageid) && !in_array($packageid, $group['package'])) {
  279. pdo_insert('uni_account_group', array(
  280. 'uniacid' => $uniacid,
  281. 'groupid' => $packageid,
  282. ));
  283. }
  284. }
  285. cache_build_account_modules($uniacid);
  286. cache_build_account($uniacid);
  287. iajax(0, '修改成功!', '');
  288. }else {
  289. pdo_delete('uni_account_group', array('uniacid' => $uniacid));
  290. cache_build_account_modules($uniacid);
  291. cache_build_account($uniacid);
  292. iajax(0, '修改成功!', '');
  293. }
  294. }
  295. if($_GPC['type'] == 'extend') {
  296. $module = safe_gpc_array($_GPC['module']);
  297. $tpl = safe_gpc_array($_GPC['tpl']);
  298. if (!empty($module) || !empty($tpl)) {
  299. $data = array(
  300. 'modules' => array('modules' => array(), 'wxapp' => array(), 'webapp' => array(), 'xzapp' => array(), 'phoneapp' => array()),
  301. 'templates' => empty($tpl) ? '' : iserializer($tpl),
  302. 'uniacid' => $uniacid,
  303. 'name' => '',
  304. );
  305. switch ($defaultaccount['type']) {
  306. case ACCOUNT_TYPE_OFFCIAL_NORMAL:
  307. case ACCOUNT_TYPE_OFFCIAL_AUTH:
  308. $data['modules']['modules'] = $module;
  309. break;
  310. case ACCOUNT_TYPE_APP_NORMAL:
  311. case ACCOUNT_TYPE_APP_AUTH:
  312. case ACCOUNT_TYPE_WXAPP_WORK:
  313. $data['modules']['wxapp'] = $module;
  314. break;
  315. case ACCOUNT_TYPE_WEBAPP_NORMAL:
  316. $data['modules']['webapp'] = $module;
  317. break;
  318. case ACCOUNT_TYPE_XZAPP_NORMAL:
  319. case ACCOUNT_TYPE_XZAPP_AUTH:
  320. $data['modules']['xzapp'] = $module;
  321. break;
  322. case ACCOUNT_TYPE_PHONEAPP_NORMAL:
  323. $data['modules']['phoneapp'] = $module;
  324. break;
  325. case ACCOUNT_TYPE_ALIAPP_NORMAL:
  326. $data['modules']['aliapp'] = $module;
  327. break;
  328. }
  329. $data['modules'] = iserializer($data['modules']);
  330. $uni_groups_modules_old = array_keys(uni_modules_by_uniacid($uniacid));
  331. $id = pdo_fetchcolumn("SELECT id FROM ".tablename('uni_group')." WHERE uniacid = :uniacid", array(':uniacid' => $uniacid));
  332. if (empty($id)) {
  333. pdo_insert('uni_group', $data);
  334. } else {
  335. pdo_update('uni_group', $data, array('id' => $id));
  336. }
  337. } else {
  338. $uni_groups_modules_old = array_keys(uni_modules_by_uniacid($uniacid));
  339. pdo_delete('uni_group', array('uniacid' => $uniacid));
  340. }
  341. cache_build_account_modules($uniacid);
  342. cache_build_account($uniacid);
  343. iajax(0, '修改成功!', '');
  344. }
  345. if ($_GPC['type'] == 'store_endtime' && user_is_founder($_W['uid']) && !user_is_vice_founder()) {
  346. $order_id = intval($_GPC['order_id']);
  347. $new_endtime = safe_gpc_string($_GPC['new_time']);
  348. if (empty($order_id)) {
  349. iajax(-1, '参数错误!');
  350. }
  351. $condition = array('uniacid' => $uniacid, 'type' => STORE_ORDER_FINISH, 'id' => $order_id);
  352. $order_exist = pdo_get('site_store_order', $condition);
  353. if (!empty($order_exist)) {
  354. pdo_update('site_store_order', array('endtime' => strtotime($new_endtime)), $condition);
  355. } else {
  356. iajax(-1, '您未购买该权限组!');
  357. }
  358. iajax(0, '修改成功!', referer());
  359. }
  360. iajax(40035, '参数错误!', '');
  361. }
  362. $founders = explode(',', $_W['config']['setting']['founder']);
  363. if (in_array($_W['uid'], $founders)) {
  364. $uni_groups = uni_groups();
  365. }
  366. $modules = user_modules($_W['uid']);
  367. $templates = pdo_getall('site_templates', array(), array('id', 'name', 'title'));
  368. $modules_tpl = array();
  369. if (in_array($owner['uid'], $founders)) {
  370. $modules_tpl[] = array(
  371. 'id' => -1,
  372. 'name' => '所有服务',
  373. 'modules' => array(array('name' => 'all', 'title' => '所有模块')),
  374. 'templates' => array(array('name' => 'all', 'title' => '所有模板')),
  375. 'type' => 'default'
  376. );
  377. } else {
  378. if ($owner['founder_groupid'] == ACCOUNT_MANAGE_GROUP_VICE_FOUNDER) {
  379. $owner['group'] = pdo_get('users_founder_group', array('id' => $owner['groupid']), array('id', 'name', 'package'));
  380. } else {
  381. $owner['group'] = pdo_get('users_group', array('id' => $owner['groupid']), array('id', 'name', 'package'));
  382. }
  383. $owner['group']['package'] = (array)iunserializer($owner['group']['package']);
  384. if(!empty($owner['group']['package'])){
  385. foreach ($owner['group']['package'] as $package_value) {
  386. if($package_value == -1){
  387. $modules_tpl[] = array(
  388. 'id' => -1,
  389. 'name' => '所有服务',
  390. 'modules' => array(array('name' => 'all', 'title' => '所有模块')),
  391. 'templates' => array(array('name' => 'all', 'title' => '所有模板')),
  392. 'type' => 'default'
  393. );
  394. }elseif ($package_value == 0) {
  395. }else {
  396. $defaultmodule = current(uni_groups(array($package_value)));
  397. $defaultmodule['type'] = 'default';
  398. $modules_tpl[] = $defaultmodule;
  399. }
  400. }
  401. }
  402. $users_extra_group_table = table('users_extra_group');
  403. $extra_groups = $users_extra_group_table->getUniGroupsByUid($owner['uid']);
  404. if (!empty($extra_groups)) {
  405. $extra_uni_groups = uni_groups(array_keys($extra_groups));
  406. foreach ($extra_uni_groups as $extra_group_val) {
  407. $extra_group_val['type'] = 'extend';
  408. $modules_tpl[] = $extra_group_val;
  409. }
  410. }
  411. $user_extend_modules_talbe = table('users_extra_modules');
  412. $user_extend_modules_talbe->searchByUid($owner['uid']);
  413. $user_extend_modules_talbe->searchBySupport($account->typeSign . '_support');
  414. $user_extend_modules = $user_extend_modules_talbe->getall();
  415. if (!empty($user_extend_modules)) {
  416. foreach($user_extend_modules as $k => $info) {
  417. $module_info = module_fetch($info['module_name']);
  418. if (!empty($module_info)) {
  419. $user_extend_modules[$k] = $module_info;
  420. } else {
  421. unset($user_extend_modules[$k]);
  422. }
  423. }
  424. }
  425. }
  426. $extend = array(
  427. 'groups' => array(),
  428. 'modules' => array(),
  429. 'templates' => array()
  430. );
  431. $extendpackage = pdo_getall('uni_account_group', array('uniacid' => $uniacid), array(), 'groupid');
  432. if(!empty($extendpackage)) {
  433. foreach ($extendpackage as $extendpackage_val) {
  434. if($extendpackage_val['groupid'] == -1){
  435. $extend['groups'] = array(array(
  436. 'id' => -1,
  437. 'name' => '所有服务',
  438. 'modules' => array(array('name' => 'all', 'title' => '所有模块')),
  439. 'templates' => array(array('name' => 'all', 'title' => '所有模板')),
  440. 'type' => 'extend' ));
  441. break;
  442. } elseif ($extendpackage_val['groupid'] != 0) {
  443. $ex_module = current(uni_groups(array($extendpackage_val['groupid'])));
  444. if (!empty($ex_module)) {
  445. $extend['groups'][] = $ex_module;
  446. }
  447. }
  448. }
  449. }
  450. $extend_uni_group = pdo_get('uni_group', array('uniacid' => $uniacid));
  451. if (!empty($extend_uni_group)) {
  452. $extend_uni_group['modules'] = iunserializer($extend_uni_group['modules']);
  453. if (is_array($extend_uni_group['modules'])) {
  454. $current_module_names = array();
  455. foreach ($extend_uni_group['modules'] as $modulenames) {
  456. if (!is_array($modulenames)) {
  457. continue;
  458. }
  459. $current_module_names = array_merge($current_module_names, $modulenames);
  460. }
  461. $current_module_names = array_unique($current_module_names);
  462. if (!empty($current_module_names)) {
  463. foreach ($current_module_names as $name) {
  464. $fetch_module = module_fetch($name);
  465. if (!empty($fetch_module)) {
  466. $extend['modules'][$name] = $fetch_module;
  467. }
  468. }
  469. }
  470. }
  471. $extend_uni_group['templates'] = iunserializer($extend_uni_group['templates']);
  472. if (!empty($extend_uni_group['templates'])) {
  473. $extend['templates'] = pdo_getall('site_templates', array('id' => $extend_uni_group['templates']), array('id', 'name', 'title'));
  474. }
  475. }
  476. $canmodify = false;
  477. if ($_W['role'] == ACCOUNT_MANAGE_NAME_FOUNDER && !in_array($owner['uid'], $founders) || $_W['role'] == ACCOUNT_MANAGE_NAME_VICE_FOUNDER && $owner['uid'] != $_W['uid']) {
  478. $canmodify = true;
  479. }
  480. $account_buy_modules = uni_site_store_buy_goods($uniacid,$_GPC['account_type']);
  481. if (!empty($account_buy_modules) && is_array($account_buy_modules)) {
  482. foreach ($account_buy_modules as &$module) {
  483. $module = module_fetch($module);
  484. $module['goods_id'] = pdo_getcolumn('site_store_goods', array('module' => $module['name'], 'status' => 1), 'id');
  485. $order_info = pdo_get('site_store_order', array('uniacid' => $uniacid, 'type' => STORE_ORDER_FINISH, 'goodsid' => $module['goods_id']), array('id', 'max(endtime) as endtime'));
  486. $module['order_id'] = $order_info['id'];
  487. $module['expire_time'] = $order_info['endtime'];
  488. }
  489. }
  490. unset($module);
  491. $account_buy_package = array();
  492. $account_buy_group = uni_site_store_buy_goods($uniacid, STORE_TYPE_PACKAGE);
  493. if (is_array($account_buy_group) && !empty($account_buy_group)) {
  494. foreach ($account_buy_group as $group) {
  495. $account_buy_package[$group] = current(uni_groups(array($group)));
  496. $account_buy_package[$group]['goods_id'] = pdo_getcolumn('site_store_goods', array('module_group' => $group), 'id');
  497. $order_info = pdo_fetch(
  498. 'SELECT id, endtime from ' . tablename('site_store_order') . ' WHERE (uniacid = :uniacid OR wxapp = :wxapp) AND `type` = :status AND goodsid = :goodsid ORDER BY endtime DESC LIMIT 1'
  499. , array(':uniacid' => $uniacid, ':wxapp' => $uniacid, ':status' => STORE_ORDER_FINISH, ':goodsid' => $account_buy_package[$group]['goods_id'])
  500. );
  501. $account_buy_package[$group]['order_id'] = $order_info['id'];
  502. $account_buy_package[$group]['expire_time'] = $order_info['endtime'];
  503. if (TIMESTAMP > $account_buy_package[$group]['expire_time']) {
  504. $account_buy_package[$group]['expire'] = true;
  505. } else {
  506. $account_buy_package[$group]['expire'] = false;
  507. $account_buy_package[$group]['near_expire'] = strtotime('-1 week', $account_buy_package[$group]['expire_time']) < time() ? true : false;
  508. }
  509. $account_buy_package[$group]['expire_time'] = date('Y-m-d', $account_buy_package[$group]['expire_time']);
  510. }
  511. }
  512. unset($group);
  513. template('account/manage-modules-tpl');
  514. }