人人商城

cache.mod.php 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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. function cache_build_template() {
  7. load()->func('file');
  8. rmdirs(IA_ROOT . '/data/tpl', true);
  9. }
  10. function cache_build_setting() {
  11. $sql = "SELECT * FROM " . tablename('core_settings');
  12. $setting = pdo_fetchall($sql, array(), 'key');
  13. if (is_array($setting)) {
  14. foreach ($setting as $k => $v) {
  15. $setting[$v['key']] = iunserializer($v['value']);
  16. }
  17. cache_write(cache_system_key('setting'), $setting);
  18. }
  19. }
  20. function cache_build_account_modules($uniacid = 0, $uid = 0) {
  21. $uniacid = intval($uniacid);
  22. if (empty($uniacid)) {
  23. cache_clean(cache_system_key('unimodules'));
  24. if (!empty($uid)) {
  25. cache_delete(cache_system_key('user_modules', array('uid' => $uid)));
  26. } else {
  27. cache_clean(cache_system_key('user_modules'));
  28. }
  29. } else {
  30. cache_delete(cache_system_key('unimodules', array('uniacid' => $uniacid, 'enabled' => 1)));
  31. cache_delete(cache_system_key('unimodules', array('uniacid' => $uniacid, 'enabled' => '')));
  32. if (empty($uid)) {
  33. $uid = table('account')->searchWithUniacid($uniacid)->searchWithRole('owner')->getOwnerUid();
  34. }
  35. cache_delete(cache_system_key('user_modules', array('uid' => $uid)));
  36. }
  37. }
  38. function cache_build_account($uniacid = 0) {
  39. global $_W;
  40. $uniacid = intval($uniacid);
  41. if (empty($uniacid)) {
  42. $uniacid_arr = pdo_fetchall("SELECT uniacid FROM " . tablename('uni_account'));
  43. foreach($uniacid_arr as $account){
  44. cache_delete(cache_system_key('uniaccount', array('uniacid' => $account['uniacid'])));
  45. cache_delete(cache_system_key('defaultgroupid', array('uniacid' => $account['uniacid'])));
  46. }
  47. } else {
  48. cache_delete(cache_system_key('uniaccount', array('uniacid' => $uniacid)));
  49. cache_delete(cache_system_key('defaultgroupid', array('uniacid' => $uniacid)));
  50. }
  51. }
  52. function cache_build_memberinfo($uid) {
  53. $uid = intval($uid);
  54. cache_delete(cache_system_key('memberinfo', array('uid' => $uid)));
  55. return true;
  56. }
  57. function cache_build_users_struct() {
  58. $base_fields = array(
  59. 'uniacid' => '同一公众号id',
  60. 'groupid' => '分组id',
  61. 'credit1' => '积分',
  62. 'credit2' => '余额',
  63. 'credit3' => '预留积分类型3',
  64. 'credit4' => '预留积分类型4',
  65. 'credit5' => '预留积分类型5',
  66. 'credit6' => '预留积分类型6',
  67. 'createtime' => '加入时间',
  68. 'mobile' => '手机号码',
  69. 'email' => '电子邮箱',
  70. 'realname' => '真实姓名',
  71. 'nickname' => '昵称',
  72. 'avatar' => '头像',
  73. 'qq' => 'QQ号',
  74. 'gender' => '性别',
  75. 'birth' => '生日',
  76. 'constellation' => '星座',
  77. 'zodiac' => '生肖',
  78. 'telephone' => '固定电话',
  79. 'idcard' => '证件号码',
  80. 'studentid' => '学号',
  81. 'grade' => '班级',
  82. 'address' => '地址',
  83. 'zipcode' => '邮编',
  84. 'nationality' => '国籍',
  85. 'reside' => '居住地',
  86. 'graduateschool' => '毕业学校',
  87. 'company' => '公司',
  88. 'education' => '学历',
  89. 'occupation' => '职业',
  90. 'position' => '职位',
  91. 'revenue' => '年收入',
  92. 'affectivestatus' => '情感状态',
  93. 'lookingfor' => ' 交友目的',
  94. 'bloodtype' => '血型',
  95. 'height' => '身高',
  96. 'weight' => '体重',
  97. 'alipay' => '支付宝帐号',
  98. 'msn' => 'MSN',
  99. 'taobao' => '阿里旺旺',
  100. 'site' => '主页',
  101. 'bio' => '自我介绍',
  102. 'interest' => '兴趣爱好',
  103. 'password' => '密码',
  104. 'pay_password' => '支付密码',
  105. );
  106. cache_write(cache_system_key('userbasefields'), $base_fields);
  107. $fields = table('core_profile_fields')->getProfileFields();
  108. if (!empty($fields)) {
  109. foreach ($fields as &$field) {
  110. $field = $field['title'];
  111. }
  112. $fields['uniacid'] = '同一公众号id';
  113. $fields['groupid'] = '分组id';
  114. $fields['credit1'] ='积分';
  115. $fields['credit2'] = '余额';
  116. $fields['credit3'] = '预留积分类型3';
  117. $fields['credit4'] = '预留积分类型4';
  118. $fields['credit5'] = '预留积分类型5';
  119. $fields['credit6'] = '预留积分类型6';
  120. $fields['createtime'] = '加入时间';
  121. $fields['password'] = '用户密码';
  122. $fields['pay_password'] = '支付密码';
  123. cache_write(cache_system_key('usersfields'), $fields);
  124. } else {
  125. cache_write(cache_system_key('usersfields'), $base_fields);
  126. }
  127. }
  128. function cache_build_frame_menu() {
  129. global $_W;
  130. $system_menu_db = pdo_getall('core_menu', array('permission_name !=' => ''), array(), 'permission_name');
  131. $account = pdo_get('account', array('uniacid' => $_W['uniacid']));
  132. $system_menu = require IA_ROOT . '/web/common/frames.inc.php';
  133. if (!empty($system_menu) && is_array($system_menu)) {
  134. $system_displayoder = 1;
  135. foreach ($system_menu as $menu_name => $menu) {
  136. $system_menu[$menu_name]['is_system'] = true;
  137. $system_menu[$menu_name]['is_display'] = !empty($system_menu_db[$menu_name]['is_display']) ? true : ((isset($system_menu[$menu_name]['is_display']) && empty($system_menu[$menu_name]['is_display']) || !empty($system_menu_db[$menu_name])) ? false : true);
  138. $system_menu[$menu_name]['displayorder'] = !empty($system_menu_db[$menu_name]) ? intval($system_menu_db[$menu_name]['displayorder']) : ++$system_displayoder;
  139. if ($_W['role'] == ACCOUNT_MANAGE_NAME_EXPIRED && $menu_name != 'store' && $menu_name != 'system') {
  140. $system_menu[$menu_name]['is_display'] = false;
  141. }
  142. if ($menu_name == 'appmarket') {
  143. $system_menu[$menu_name]['is_display'] = true;
  144. }
  145. foreach ($menu['section'] as $section_name => $section) {
  146. $displayorder = max(count($section['menu']), 1);
  147. if (empty($section['menu'])) {
  148. $section['menu'] = array();
  149. }
  150. $add_menu = pdo_getall('core_menu', array('group_name' => $section_name), array(
  151. 'id', 'title', 'url', 'is_display', 'is_system', 'permission_name', 'displayorder', 'icon',
  152. ), 'permission_name', 'displayorder DESC');
  153. if (!empty($add_menu)) {
  154. foreach ($add_menu as $permission_name => $menu) {
  155. $menu['icon'] = !empty($menu['icon']) ? $menu['icon'] : 'wi wi-appsetting';
  156. $section['menu'][$permission_name] = $menu;
  157. }
  158. }
  159. $section_hidden_menu_count = 0;
  160. foreach ($section['menu'] as $permission_name => $sub_menu) {
  161. $sub_menu_db = $system_menu_db[$sub_menu['permission_name']];
  162. $system_menu[$menu_name]['section'][$section_name]['menu'][$permission_name] = array(
  163. 'is_system' => isset($sub_menu['is_system']) ? $sub_menu['is_system'] : 1,
  164. 'permission_display' => $sub_menu['is_display'],
  165. 'is_display' => isset($sub_menu_db['is_display']) ? $sub_menu_db['is_display'] : ((isset($sub_menu['is_display']) && (empty($sub_menu['is_display']) || (is_array($sub_menu['is_display']) && !in_array($account['type'], $sub_menu['is_display'])))) ? 0 : 1),
  166. 'title' => !empty($sub_menu_db['title']) ? $sub_menu_db['title'] : $sub_menu['title'],
  167. 'url' => $sub_menu['url'],
  168. 'permission_name' => $sub_menu['permission_name'],
  169. 'icon' => $sub_menu['icon'],
  170. 'displayorder' => !empty($sub_menu_db['displayorder']) ? $sub_menu_db['displayorder'] : $displayorder,
  171. 'id' => $sub_menu['id'],
  172. 'sub_permission' => $sub_menu['sub_permission'],
  173. );
  174. $displayorder--;
  175. $displayorder = max($displayorder, 0);
  176. if (empty($system_menu[$menu_name]['section'][$section_name]['menu'][$permission_name]['is_display'])) {
  177. $section_hidden_menu_count++;
  178. }
  179. }
  180. if (empty($section['is_display']) && $section_hidden_menu_count == count($section['menu']) && $section_name != 'platform_module') {
  181. $system_menu[$menu_name]['section'][$section_name]['is_display'] = 0;
  182. }
  183. $system_menu[$menu_name]['section'][$section_name]['menu'] = iarray_sort($system_menu[$menu_name]['section'][$section_name]['menu'], 'displayorder', 'desc');
  184. }
  185. }
  186. $add_top_nav = pdo_getall('core_menu', array('group_name' => 'frame', 'is_system <>' => 1), array('title', 'url', 'permission_name', 'displayorder', 'icon', 'is_display'));
  187. if (!empty($add_top_nav)) {
  188. foreach ($add_top_nav as $menu) {
  189. $menu['url'] = strexists($menu['url'], 'http') ? $menu['url'] : $_W['siteroot'] . $menu['url'];
  190. $menu['blank'] = true;
  191. $menu['is_display'] = $menu['is_display'] == 0 ? false : true;;
  192. $system_menu[$menu['permission_name']] = $menu;
  193. }
  194. }
  195. $system_menu = iarray_sort($system_menu, 'displayorder', 'asc');
  196. cache_delete(cache_system_key('system_frame', array('uniacid' => $_W['uniacid'])));
  197. cache_write(cache_system_key('system_frame', array('uniacid' => $_W['uniacid'])), $system_menu);
  198. return $system_menu;
  199. }
  200. }
  201. function cache_build_module_subscribe_type() {
  202. global $_W;
  203. $modules = table('modules')->getByHasSubscribes();
  204. if (empty($modules)) {
  205. return array();
  206. }
  207. $subscribe = array();
  208. foreach ($modules as $module) {
  209. $module['subscribes'] = iunserializer($module['subscribes']);
  210. if (!empty($module['subscribes'])) {
  211. foreach ($module['subscribes'] as $event) {
  212. if ($event == 'text') {
  213. continue;
  214. }
  215. $subscribe[$event][] = $module['name'];
  216. }
  217. }
  218. }
  219. $module_ban = $_W['setting']['module_receive_ban'];
  220. foreach ($subscribe as $event => $module_group) {
  221. if (!empty($module_group)) {
  222. foreach ($module_group as $index => $module) {
  223. if (!empty($module_ban[$module])) {
  224. unset($subscribe[$event][$index]);
  225. }
  226. }
  227. }
  228. }
  229. cache_write(cache_system_key('module_receive_enable'), $subscribe);
  230. return $subscribe;
  231. }
  232. function cache_build_cloud_ad() {
  233. global $_W;
  234. $uniacid_arr = pdo_fetchall("SELECT uniacid FROM " . tablename('uni_account'));
  235. foreach($uniacid_arr as $account){
  236. cache_delete(cache_system_key('stat_todaylock', array('uniacid' => $account['uniacid'])));
  237. cache_delete(cache_system_key('cloud_ad_uniaccount', array('uniacid' => $account['uniacid'])));
  238. cache_delete(cache_system_key('cloud_ad_app_list', array('uniacid' => $account['uniacid'])));
  239. }
  240. cache_delete(cache_system_key('cloud_flow_master'));
  241. cache_delete(cache_system_key('cloud_ad_uniaccount_list'));
  242. cache_delete(cache_system_key('cloud_ad_tags'));
  243. cache_delete(cache_system_key('cloud_ad_type_list'));
  244. cache_delete(cache_system_key('cloud_ad_app_support_list'));
  245. cache_delete(cache_system_key('cloud_ad_site_finance'));
  246. }
  247. function cache_build_uninstalled_module() {
  248. $modulelist = table('modules')->getall('name');
  249. $module_root = IA_ROOT . '/addons/';
  250. $module_path_list = glob($module_root . '/*');
  251. if (empty($module_path_list)) {
  252. return true;
  253. }
  254. foreach ($module_path_list as $path) {
  255. $modulename = pathinfo($path, PATHINFO_BASENAME);
  256. if (!empty($modulelist[$modulename])) {
  257. $module_cloud_upgrade = table('modules_cloud')->getByName($modulename);
  258. if (!empty($module_cloud_upgrade)) {
  259. $has_new_support = false;
  260. $new_support = array();
  261. $all_support = array('account_support', 'wxapp_support', 'webapp_support', 'phoneapp_support', 'welcome_support', 'xzapp_support', 'aliapp_support');
  262. foreach ($all_support as $support) {
  263. if ($module_cloud_upgrade[$support] == MODULE_SUPPORT_ACCOUNT && $modulelist[$modulename][$support] == MODULE_NONSUPPORT_ACCOUNT) {
  264. $new_support[$support] = MODULE_SUPPORT_ACCOUNT;
  265. $has_new_support = true;
  266. } else {
  267. $new_support[$support] = MODULE_NONSUPPORT_ACCOUNT;
  268. }
  269. }
  270. if ($has_new_support) {
  271. $new_support['install_status'] = MODULE_CLOUD_UNINSTALL;
  272. table('modules_cloud')->fill($new_support)->where('name', $modulename)->save();
  273. } else {
  274. table('modules_cloud')->deleteByName($modulename);
  275. }
  276. continue;
  277. }
  278. }
  279. if (!is_dir($path) || !file_exists($path . '/manifest.xml')) {
  280. continue;
  281. }
  282. $manifest = ext_module_manifest($modulename);
  283. $module_upgrade_data = array(
  284. 'name' => $modulename,
  285. 'has_new_version' => 0,
  286. 'has_new_branch' => 0,
  287. 'install_status' => MODULE_LOCAL_UNINSTALL,
  288. 'logo' => $manifest['application']['logo'],
  289. 'version' => $manifest['application']['version'],
  290. 'title' => $manifest['application']['name'],
  291. 'title_initial' => get_first_pinyin($manifest['application']['name']),
  292. );
  293. if (!empty($manifest['platform']['supports'])) {
  294. foreach (array('app', 'wxapp', 'webapp', 'phoneapp', 'system_welcome', 'xzapp', 'aliapp') as $support) {
  295. if (in_array($support, $manifest['platform']['supports'])) {
  296. if ($support == 'app') {
  297. $support = 'account';
  298. }
  299. $module_upgrade_data["{$support}_support"] = MODULE_SUPPORT_ACCOUNT;
  300. }
  301. }
  302. }
  303. if (!empty($modulelist[$modulename])) {
  304. $new_support = module_check_notinstalled_support($modulelist[$modulename], $manifest['platform']['supports']);
  305. if (!empty($new_support)) {
  306. $module_upgrade_data = array_merge($module_upgrade_data, $new_support);
  307. } else {
  308. table('modules_cloud')->deleteByName($modulename);
  309. continue;
  310. }
  311. }
  312. $module_cloud_upgrade = table('modules_cloud')->getByName($modulename);
  313. if (empty($module_cloud_upgrade)) {
  314. table('modules_cloud')->fill($module_upgrade_data)->save();
  315. } else {
  316. table('modules_cloud')->fill($module_upgrade_data)->where('name', $modulename)->save();
  317. }
  318. }
  319. return true;
  320. }
  321. function cache_build_proxy_wechatpay_account() {
  322. global $_W;
  323. load()->model('account');
  324. if(empty($_W['isfounder'])) {
  325. $where = " WHERE `uniacid` IN (SELECT `uniacid` FROM " . tablename('uni_account_users') . " WHERE `uid`=:uid)";
  326. $params[':uid'] = $_W['uid'];
  327. }
  328. $sql = "SELECT * FROM " . tablename('uni_account') . $where;
  329. $uniaccounts = pdo_fetchall($sql, $params);
  330. $service = array();
  331. $borrow = array();
  332. if (!empty($uniaccounts)) {
  333. foreach ($uniaccounts as $uniaccount) {
  334. $account = account_fetch($uniaccount['default_acid']);
  335. $account_setting = pdo_get('uni_settings', array ('uniacid' => $account['uniacid']));
  336. $payment = iunserializer($account_setting['payment']);
  337. if (is_array($account) && !empty($account['key']) && !empty($account['secret']) && in_array($account['level'], array (4)) &&
  338. is_array($payment) && !empty($payment) && intval($payment['wechat']['switch']) == 1) {
  339. if ((!is_bool ($payment['wechat']['switch']) && $payment['wechat']['switch'] != 4) || (is_bool ($payment['wechat']['switch']) && !empty($payment['wechat']['switch']))) {
  340. $borrow[$account['uniacid']] = $account['name'];
  341. }
  342. }
  343. if (!empty($payment['wechat_facilitator']['switch'])) {
  344. $service[$account['uniacid']] = $account['name'];
  345. }
  346. }
  347. }
  348. $cache = array(
  349. 'service' => $service,
  350. 'borrow' => $borrow
  351. );
  352. cache_write(cache_system_key('proxy_wechatpay_account'), $cache);
  353. return $cache;
  354. }
  355. function cache_build_module_info($module_name) {
  356. global $_W;
  357. table('modules_cloud')->deleteByName($module_name);
  358. cache_delete(cache_system_key('module_info', array('module_name' => $module_name)));
  359. }
  360. function cache_build_uni_group() {
  361. cache_delete(cache_system_key('uni_groups'));
  362. }