人人商城

post.ctrl.php 20KB

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