function _get_goods($gid) { $render = $this->app->render(); $objGoods = $this->app->model('goods'); $aGoods_list = $objGoods->getList("goods_id,name,bn,brief,brand_id,type_id,unit,params,p_1,p_2,p_3,p_4,p_5,p_6,p_7,p_8,p_9,p_10,p_11,p_12,p_13,p_14,p_15,p_16,p_17,p_18,p_19,p_20,p_21,p_22,p_23,p_24,p_25,p_26,p_27,p_28,p_29,p_30,p_31,p_32,p_33,p_34,p_35,p_36,p_37,p_38,p_39,p_40,p_41,p_42,p_43,p_44,p_45,p_46,p_47,p_48,p_49,p_50", array('goods_id' => $gid)); $aGoods['name'] = $aGoods_list[0]['name']; $aGoods['bn'] = $aGoods_list[0]['bn']; $aGoods['brief'] = $aGoods_list[0]['brief']; $aGoods['params'] = $aGoods_list[0]['params']; $goods_type = app::get("b2c")->model("goods_type"); cachemgr::co_start(); if (!cachemgr::get("goods_type_props_value_list2dump" . $aGoods_list[0]['type_id'], $goods_type_data)) { $goods_type_data = $goods_type->dump($aGoods_list[0]['type_id']); cachemgr::set("goods_type_props_value_list2dump" . $aGoods_list[0]['type_id'], $goods_type_data, cachemgr::co_end()); } $aGoods['type'] = $goods_type_data; $brand_row = $goods_type->db->selectrow("select brand_id,brand_name from sdb_b2c_brand where brand_id=" . intval($aGoods_list[0]['brand_id'])); $aGoods['brand'] = $brand_row; foreach ($aGoods_list[0] as $aGoods_k => $aGoods_v) { if (strpos($aGoods_k, "p_") === 0) { $aGoods['props'][$aGoods_k]['value'] = $aGoods_v; } } return $aGoods; }
function show($gid, &$aGoods = null) { $render = $this->app->render(); if (!$aGoods) { $o = kernel::single('b2c_goods_model'); $aGoods = $o->getGoods($gid); } if (!$aGoods['images']) { $render->pagedata['noimage'] = 'true'; $imageDefault = app::get('image')->getConf('image.set'); $aGoods['images'][]['image_id'] = $imageDefault['M']['default_image']; $aGoods['goods']['image_default_id'] = $imageDefault['M']['default_image']; } else { $oImage = app::get('image')->model('image'); $imageDefault = app::get('image')->getConf('image.set'); foreach ($aGoods['images'] as $k => $v) { //todo 暂时cache 处理,以后优化的时候在storager中判断 //判断是否对应的图片是否存在,不存在则用默认图片显示 if (!cachemgr::get('goods_image' . intval($v['image_id']), $image_id)) { cachemgr::co_start(); $image_id = $oImage->getList("image_id", array('image_id' => $v['image_id'])); cachemgr::set('goods_image' . intval($v['image_id']), $image_id, cachemgr::co_end()); } if (!$image_id) { if ($aGoods['image_default_id'] == $v['image_id']) { $aGoods['image_default_id'] = $imageDefault['M']['default_image']; } $aGoods['images'][$k]['image_id'] = $imageDefault['M']['default_image']; } } } $render->pagedata['goods'] = $aGoods; return $render->fetch('site/product/goodspic.html'); }
function display($tmpl_file, $app_id = null, $fetch = false, $is_theme = false) { array_unshift($this->_files, $tmpl_file); $this->_vars = $this->pagedata; if ($p = strpos($tmpl_file, ':')) { $object = kernel::service('tpl_source.' . substr($tmpl_file, 0, $p)); if ($object) { $tmpl_file_path = substr($tmpl_file, $p + 1); $last_modified = $object->last_modified($tmpl_file_path); } } else { if (defined('CUSTOM_CORE_DIR') && file_exists(CUSTOM_CORE_DIR . '/' . ($app_id ? $app_id : $this->app->app_id) . '/view/' . $tmpl_file)) { $tmpl_file = CUSTOM_CORE_DIR . '/' . ($app_id ? $app_id : $this->app->app_id) . '/view/' . $tmpl_file; } else { if (!$is_theme) { $tmpl_file = realpath(APP_DIR . '/' . ($app_id ? $app_id : $this->app->app_id) . '/view/' . $tmpl_file); } else { $tmpl_file = realpath(THEME_DIR . '/' . $tmpl_file); } } $last_modified = filemtime($tmpl_file); } if (!$last_modified) { //无文件 } $this->tmpl_cachekey('__temp_lang', kernel::get_lang()); //设置模版所属语言包 $this->tmpl_cachekey('__temp_app_id', $app_id ? $app_id : $this->app->app_id); $compile_id = $this->compile_id($tmpl_file); #if($this->force_compile || base_kvstore::instance('cache/template')->fetch($compile_id, $compile_code, $last_modified) === false){ if ($this->force_compile || !cachemgr::get($compile_id . $last_modified, $compile_code)) { if ($object) { $compile_code = $this->_compiler()->compile($object->get_file_contents($tmpl_file_path)); } else { $compile_code = $this->_compiler()->compile_file($tmpl_file); } if ($compile_code !== false) { #base_kvstore::instance('cache/template')->store($compile_id,$compile_code); cachemgr::co_start(); cachemgr::set($compile_id . $last_modified, $compile_code, cachemgr::co_end()); } } ob_start(); eval('?>' . $compile_code); $content = ob_get_contents(); ob_end_clean(); array_shift($this->_files); $this->pre_display($content); if ($fetch === true) { return $content; } else { echo $content; } }
public function getListAll() { if (!cachemgr::get('member_lv_info_all', $data)) { cachemgr::co_start(); $memberLvData = $this->getList('*'); foreach ($memberLvData as $row) { $data[$row['member_lv_id']] = $row; } cachemgr::set('member_lv_info_all', $data, cachemgr::co_end()); } return $data; }
public function display($tmpl_file, $app_id = null, $fetch = false, $is_theme = false) { array_unshift($this->_files, $tmpl_file); $this->_vars = $this->pagedata; if ($p = strpos($tmpl_file, ':')) { $object = vmc::service('tpl_source.' . substr($tmpl_file, 0, $p)); if ($object) { $tmpl_file_path = substr($tmpl_file, $p + 1); $last_modified = $object->last_modified($tmpl_file_path); } } else { if (defined('EXTENDS_DIR') && file_exists(EXTENDS_DIR . '/' . ($app_id ? $app_id : $this->app->app_id) . '/view/' . $tmpl_file)) { $tmpl_file = EXTENDS_DIR . '/' . ($app_id ? $app_id : $this->app->app_id) . '/view/' . $tmpl_file; } else { if (!$is_theme) { $tmpl_file = realpath(APP_DIR . '/' . ($app_id ? $app_id : $this->app->app_id) . '/view/' . $tmpl_file); } else { $tmpl_file = realpath(THEME_DIR . '/' . $tmpl_file); } } $last_modified = filemtime($tmpl_file); } if (!$last_modified) { trigger_error('未知VIEW', E_USER_ERROR); } $this->tmpl_cachekey('__temp_lang', vmc::get_lang()); //设置模版所属语言包 $this->tmpl_cachekey('__temp_app_id', $app_id ? $app_id : $this->app->app_id); $compile_id = $this->compile_id($tmpl_file); if ($this->force_compile || !cachemgr::get($compile_id . $last_modified, $compile_code)) { if ($object) { $compile_code = $this->_compiler()->compile($object->get_file_contents($tmpl_file_path)); } else { $compile_code = $this->_compiler()->compile_file($tmpl_file); } if ($compile_code !== false) { cachemgr::co_start(); cachemgr::set($compile_id . $last_modified, $compile_code, cachemgr::co_end()); } } ob_start(); eval('?>' . $compile_code); $content = ob_get_contents(); ob_end_clean(); array_shift($this->_files); $this->pre_display($content); if ($fetch === true) { return $content; } else { echo $content; } }
function show($gid, &$aGoods = null, $siteMember = null) { $render = $this->app->render(); if (!$aGoods) { $o = kernel::single('b2c_goods_model'); $aGoods = $o->getGoods($gid); } if ($aGoods['product']) { if (empty($siteMember)) { $siteMember = $this->app->model("members")->get_current_member(); } $priceArea = array(); if ($siteMember['member_lv']) { $mlv = $siteMember['member_lv']; } else { $level =& $this->app->model('member_lv'); $mlv = $level->get_default_lv(); } if ($mlv) { $aConfig = kernel::single('b2c_cart_prefilter_promotion_goods')->_init_rule_public(array($gid), array('member_lv' => 'false')); foreach ($aGoods['product'] as $gpk => &$gpv) { $promotion_price = kernel::single('b2c_goods_promotion_price')->process($gpv, $aConfig); $gpv['price']['price']['current_price'] = empty($promotion_price['price']) ? $gpv['price']['price']['current_price'] : $promotion_price['price']; $gpv['price']['price']['price'] = empty($promotion_price['price']) ? $gpv['price']['price']['price'] : $promotion_price['price']; if (is_array($gpv['price']['member_lv_price'])) { foreach ($gpv['price']['member_lv_price'] as $mk => &$mv) { $mv['price'] = empty($promotion_price['price']) ? $mv['price'] : $promotion_price['price']; } } } } } $oMlv = $this->app->model('member_lv'); if (!cachemgr::get('member_evel_list', $mLevelList)) { cachemgr::co_start(); $mLevelList = $oMlv->getList('*', '', 0, -1); cachemgr::set('member_evel_list', $mLevelList, cachemgr::co_end()); } $render->pagedata['mLevel'] = $mLevelList; $render->pagedata['goods'] = $aGoods; return $render->fetch('site/product/mlv_price.html'); }
/** * 商品列表. */ public function gallery($params = array()) { $default_params = array('page_size' => 20, 'page_index' => 1, 'orderby' => ''); if (!is_array($params)) { $params = array(); } $params = array_merge($default_params, $params, $this->req_params); if ($params['orderby']) { $params['orderby'] = str_replace('-', ' ', $params['orderby']); } $cache_key = utils::array_md5($params); //优先从缓存读取 if (cachemgr::get($cache_key, $gallery_data)) { $this->success($gallery_data); } cachemgr::co_start(); $filter = $params['filter']; if (!is_array($filter)) { $filter = array(); } $filter['marketable'] = 'true'; $obj_goods_stage = vmc::singleton('b2c_goods_stage'); //set_member if ($this->app->member_id = vmc::singleton('b2c_user_object')->get_member_id()) { $obj_goods_stage->set_member($this->app->member_id); } $mdl_goods = app::get('b2c')->model('goods'); $goods_cols = 'goods_id,gid,name,type_id,cat_id,brand_id,nostore_sell,brief,image_default_id,goods_setting'; $goods_list = $mdl_goods->getList($goods_cols, $filter, $params['page_size'] * ($params['page_index'] - 1), $params['page_size'], $params['orderby']); if (!$goods_list) { $this->failure(); } $total = $mdl_goods->count($filter); $obj_goods_stage->gallery($goods_list); //引用传递 $page_total = $total ? ceil($total / $the_params['page_size']) : 1; $gallery_data = array('page_total' => $page_total > 0 ? $page_total : 1, 'goods_list' => array_values($goods_list)); cachemgr::set($cache_key, $gallery_data, cachemgr::co_end()); $this->success($gallery_data); }
private function _list($filter, $page, $orderby) { $cache_key = utils::array_md5(func_get_args()); if (cachemgr::get($cache_key, $return)) { return $return; } cachemgr::co_start(); $goods_cols = '*'; $mdl_goods = $this->app->model('goods'); $goods_list = $mdl_goods->getList($goods_cols, $filter, $page['size'] * ($page['index'] - 1), $page['size'], $orderby); $obj_goods_stage = vmc::singleton('b2c_goods_stage'); //set_member if ($this->app->member_id = vmc::singleton('b2c_user_object')->get_member_id()) { $obj_goods_stage->set_member($this->app->member_id); } $obj_goods_stage->gallery($goods_list); //引用传递 $total = $mdl_goods->count($filter); $return = array('data' => $goods_list, 'count' => count($goods_list), 'all_count' => $total, 'page_info' => array('total' => $total ? ceil($total / $page['size']) : 1, 'current' => intval($page['index']))); cachemgr::set($cache_key, $return, cachemgr::co_end()); return $return; }
public function dispatch($query) { $this->check_blacklist(); //黑名单检测 $page_starttime = $this->microtime_float(); /** 影响性能暂时去掉 foreach(kernel::servicelist('site.router.predispatch') as $obj) { $query = $obj->router_predispatch($query); **/ $this->init_query_info($query); $this->init_request_info(); $this->check_https(); $this->check_expanded_name(); $router_cache_options = $this->check_router_cache(); $page_key = 'SITE_PAGE_CACHE:' . $this->_request->get_request_uri(); logger::debug('page: ' . $this->_request->get_request_uri()); if (!$this->is_need_cache() || $this->is_need_cache() && !cachemgr::get($page_key, $page, $router_cache_options['skipvary'])) { if (WITHOUT_CACHE !== true) { logger::info('page cache miss:' . $this->_request->get_request_uri()); } cachemgr::co_start(); $this->default_dispatch(); $page['html'] = join("\n", $this->_response->get_bodys()); $page['date'] = date("Y-m-d H:i:s"); $page['times'] = sprintf('%0.2f', $this->microtime_float() - $page_starttime); if ($this->is_need_cache() && $this->_response->get_http_response_code() == 200 && $this->has_page_cache_control() === true) { $page_cache = true; $this->_response->set_header('X-Cache', 'HIT from ecos-pagecache ' . $page['date']); //todo:记录x-cache $page['headers'] = $this->_response->get_headers(); $page['raw_headers'] = $this->_response->get_raw_headers(); $page['etag'] = md5($page['html']); $cache_options = cachemgr::co_end(); if ($router_cache_options['expires']) { $cache_options['expires'] = $cache_options['expires'] && $cache_options['expires'] < $router_cache_options['expires'] ? $cache_options['expires'] : $router_cache_options['expires']; } $cache_options['expires'] = $cache_options['expires'] > time() ? $cache_options['expires'] : 0; //$cache_options['skip_vary'] = $cache_expires; cachemgr::set($page_key, $page, $cache_options); } else { $page_cache = false; cachemgr::co_end(); } } else { $page_cache = true; $this->_response->clean_headers(); if (isset($page['headers'])) { foreach ($page['headers'] as $header) { $this->_response->set_header($header['name'], $header['value'], $header['replace']); } } if (isset($page['raw_headers'])) { foreach ($page['raw_headers'] as $raw_header) { $this->_response->set_raw_headers($raw_header); } } if (WITHOUT_CACHE !== true) { logger::info('page cache hit:' . $this->_request->get_request_uri()); } } if ($page_cache === true) { $etag = $page['etag'] ? $page['etag'] : md5($page['html']); //todo: 兼容 $this->_response->set_header('Etag', $etag); $matchs = explode(',', $_ENV['HTTP_IF_NONE_MATCH']); foreach ($matchs as $match) { if (trim($match) == $etag) { $this->_response->clean_headers(); $this->_response->set_header('Content-length', '0'); $this->_response->set_http_response_code(304)->send_headers(); exit; } } } $this->set_vary_cookie(); $this->_response->send_headers(); echo $page['html']; logger::debug('This page created by ' . $page['date']); logger::debug('Mysql queries count:' . base_db_connections::$mysql_query_executions); logger::debug('Kvstore queries count:' . base_kvstore::$__fetch_count); logger::debug('Page Times: ' . $page['times']); }
function goodsDetailIntro($gid) { $this->_response->set_header('Cache-Control', 'no-store, no-cache'); if (!cachemgr::get('ajax_product_wap_detail_intro' . $gid, $intro_html)) { cachemgr::co_start(); $objGoods = $this->app->model('goods'); $aGoods_list = $objGoods->getList("intro,wapintro", array('goods_id' => $gid)); $intro = !empty($aGoods_list[0]['wapintro']) ? $aGoods_list[0]['wapintro'] : $aGoods_list[0]['intro']; $this->pagedata['intro'] = $intro; $intro_html = $this->fetch('wap/product/tab/detail_intro.html'); cachemgr::set('ajax_product_wap_detail_intro' . $gid, $intro_html, cachemgr::co_end()); } echo $intro_html; }
public final function display_tmpl($tmpl, $fetch = false, $is_preview = false) { array_unshift($this->_files, $this->get_theme() . '/' . $tmpl); $this->_vars = $this->pagedata; $tmpl_file = realpath(WAP_THEME_DIR . '/' . $this->get_theme() . '/' . $tmpl); $this->tmpl_cachekey('__theme_app_id', $this->get_tmpl_main_app_id() ? $this->get_tmpl_main_app_id() : $this->app->app_id); $this->tmpl_cachekey('__theme_main_page', $this->pagedata['_MAIN_']); $compile_id = $this->compile_id($this->get_theme() . "/" . $tmpl); $last_modified = filemtime($tmpl_file); if (!$is_preview) { if ($this->force_compile || !cachemgr::get($compile_id . $last_modified, $compile_code)) { cachemgr::co_start(); $tmpl_content = kernel::single('wap_theme_file')->get_tmpl_content($this->get_theme(), $tmpl); $compile_code = $this->_compiler()->compile($tmpl_content); if ($compile_code !== false) { $compile_code = $this->fix_theme_media($compile_code); } cachemgr::set($compile_id . $last_modified, $compile_code, cachemgr::co_end()); } } else { $this->_compiler()->is_preview = $is_preview; $tmpl_content = kernel::single('wap_theme_file')->get_tmpl_content($this->get_theme(), $tmpl); $compile_code = $this->_compiler()->compile($tmpl_content); if ($compile_code !== false) { $compile_code = $this->fix_theme_media($compile_code); } } kernel::single('wap_theme_base')->get_theme_cache_version($this->get_theme()); /** 添加theme_url的值 **/ $theme_url = kernel::base_url(1) . '/wap_themes'; ob_start(); eval('?>' . $compile_code); $content = ob_get_contents(); ob_end_clean(); array_shift($this->_files); $this->pre_display($content); if ($fetch === true) { return $content; } else { echo $content; } }
public function index($cat_id = '', $urlFilter = null, $orderBy = 0, $tab = null, $page = 1, $cat_type = null, $view = null) { $tab = intval($tab); $urlFilter = $this->RemoveXSS($urlFilter); // 20130204 Andrew 俱乐部专区功能,俱乐部专区只能俱乐部访问 $goods_cat = $this->app->model('goods_cat')->dump($cat_id); if ($goods_cat['cat_name'] == '俱乐部专区') { $custom_user = kernel::single('custom_member')->get_custom_user(helper::current_account_id()); if ((!$custom_user['club'] || !$custom_user['vip']) && !$custom_user['leader']) { $back_url = $this->gen_url(array('app' => 'b2c', 'ctl' => 'site', 'act' => 'index')); $this->splash('failed', $back_url, app::get('b2c')->_('本页需要认证俱乐部才能进入')); } } // 20130204 End $urlFilter = htmlspecialchars(urldecode($urlFilter)); $_GET['scontent'] = htmlspecialchars($_GET['scontent']); if (!empty($urlFilter) && $urlFilter != $_GET['scontent']) { $urlFilter .= '_' . $_GET['scontent']; } else { $urlFilter = $_GET['scontent']; } $virCatObj =& $this->app->model('goods_virtual_cat'); if ($cat_type) { $vcatid = $cat_type; $oSearch =& $this->app->model('search'); /** 颗粒缓存商品虚拟分类 **/ if (!cachemgr::get('goods_virtual_cat_' . intval($vcatid), $vcat)) { cachemgr::co_start(); $vcat = $virCatObj->getList('cat_id,cat_path,virtual_cat_id,filter,virtual_cat_name as cat_name', array('virtual_cat_id' => intval($vcatid))); cachemgr::set('goods_virtual_cat_' . intval($vcatid), $vcat, cachemgr::co_end()); } $vcat = current($vcat); $vcatFilters = $virCatObj->_mkFilter($vcat['filter']); $vcatFilters = $virCatObj->getFilter($vcatFilters); $old_cat_id = $cat_id; $old_urlFilter = $urlFilter; $cat_id = $cat_id ? $cat_id . implode(",", $vcatFilters['cat_id']) : implode(",", $vcatFilters['cat_id']); $urlFilter = $urlFilter ? $urlFilter : $oSearch->encode($vcatFilters); } $page = $page > 1 ? intval($page) : 1; if ($cat_id == '_ANY_') { unset($cat_id); } if ($cat_id) { $cat_id = explode(",", $cat_id); foreach ($cat_id as $k => $v) { if ($v) { $cat_id[$k] = intval($v); } } $this->id = implode(",", $cat_id); } else { $cat_id = array(''); $this->id = ''; } $pageLimit = $this->app->getConf('gallery.display.listnum'); $pageLimit = $pageLimit ? $pageLimit : 20; $this->pagedata['pdtPic'] = array('width' => 100, 'heigth' => 100); $productCat =& $this->app->model('goods_cat'); $objGoods = $this->app->model('goods'); $global_runtime_path = ""; // ajx 这里添加对分类的判断,当分类不存在时不做缓存处理 if (!cachemgr::get('global_runtime_path' . $this->id, $global_runtime_path)) { cachemgr::co_start(); if ($cat_type) { $global_runtime_path = $virCatObj->getPath($cat_type, ''); } else { $global_runtime_path = $productCat->getPath($cat_id[0], ''); } cachemgr::set('global_runtime_path', $global_runtime_path, cachemgr::co_end()); } /****ajx 以下是为了当搜索条件存在时 面包屑中显示 搜索条件 ***/ if ($_GET['scontent'] && strlen($urlFilter) > 0) { $global_runtime_path = array(array('type' => 'goodsCat', 'title' => app::get('site')->_('首页'), 'link' => kernel::base_url(1))); $title_ = explode('_', $urlFilter); $title_arr = ""; foreach ($title_ as $val_xin) { $title_xin = explode(',', $val_xin); if (count($title_xin) > 2) { unset($title_xin[0]); foreach ($title_xin as $xin_val) { $title_arr[] = $xin_val; } } else { $title_arr[] = $title_xin[1]; } } $title = implode(',', $title_arr); array_push($global_runtime_path, array('type' => 'goodsCat', 'title' => app::get('site')->_($title), 'link' => kernel::base_url(1))); } // ajx 以下是为了当无分类和搜索条件时 显示所有商品 if (count($global_runtime_path) < 2) { $global_runtime_path = array(array('type' => 'goodsCat', 'title' => app::get('site')->_('首页'), 'link' => kernel::base_url(1)), array('type' => 'goodsCat', 'title' => app::get('site')->_('所有商品'), 'link' => kernel::base_url(1))); } $GLOBALS['runtime']['path'] = $global_runtime_path; if ($cat_id[0]) { if (!cachemgr::get('goods_cat_' . $cat_id[0], $this->cat_result)) { cachemgr::co_start(); $this->cat_result = $productCat->getList('cat_name,gallery_setting,type_id', array('cat_id|in' => $cat_id), 0, 1); cachemgr::set('goods_cat_' . $cat_id[0], $this->cat_result, cachemgr::co_end()); } $type_filter['type_id'] = $this->cat_result[0]['type_id']; } if (isset($this->cat_result[0]['gallery_setting']['gallery_template']) && $this->cat_result[0]['gallery_setting']['gallery_template']) { $this->set_tmpl_file($this->cat_result[0]['gallery_setting']['gallery_template']); //添加模板 } if (empty($view)) { $view = $this->app->getConf('gallery.default_view') ? $this->app->getConf('gallery.default_view') : 'index'; } if (!cachemgr::get('goods_cat_childnode_' . $cat_id[0], $this->pagedata['childnode'])) { cachemgr::co_start(); $this->pagedata['childnode'] = $productCat->getCatParentById($cat_id, $view); cachemgr::set('goods_cat_childnode_' . $cat_id[0], $this->pagedata['childnode'], cachemgr::co_end()); } $cat = kernel::service('b2c_site_goods_list_viewer_apps')->get_view($cat_id, $view, $type_filter['type_id'], $cat_type); $args = array($cat_type ? $old_cat_id : $this->id, $cat_type ? $old_urlFilter : urlencode($urlFilter), $orderBy, $tab, $page, $cat_type, $view); $this->pagedata['args'] = $args; $this->pagedata['args1'] = $args[1]; $args[1] = null; $this->pagedata['args2'] = $args; if ($this->app->getConf('system.seo.noindex_catalog')) { $this->header .= '<meta name="robots" content="noindex,noarchive,follow" />'; } $searchtools =& $this->app->model('search'); $path = array(); $propargs = $searchtools->decode($urlFilter, $path, $cat); if (is_array($propargs)) { foreach ($propargs as $rk => $rv) { $pos = strpos($rk, 'p_'); if ($pos === 0) { $propz[$rk] = $rv[0]; $rk = substr($rk, 2); $proparg[$rk] = $rv; $prot[] = $rk; } } } if (isset($propargs['name'])) { $GLOBALS['runtime']['search_key'] = $propargs['name'][0]; } $this->pagedata['prot'] = $prot; $filter = $propargs; if (is_array($filter)) { $filter = array_merge(array('cat_id' => $cat_id, 'marketable' => 'true'), $filter); if (($filter['cat_id'][0] === '' || $filter['cat_id'][0] === null) && !isset($filter['cat_id'][1])) { unset($filter['cat_id']); } if (($filter['brand_id'][0] === '' || $filter['brand_id'][0] === null) && !isset($filter['brand_id'][1])) { unset($filter['brand_id']); } } else { $filter = array('cat_id' => $cat_id, 'marketable' => 'true'); } //--------获取类型关联的规格 $type_id = $type_filter['type_id']; $gType =& $this->app->model('goods_type'); if (!cachemgr::get('goods_type_' . $type_id, $SpecList)) { cachemgr::co_start(); $SpecList = $gType->getSpec($type_id, 1); //获取关联的规格 cachemgr::set('goods_type_' . $type_id, $SpecList, cachemgr::co_end()); } if ($SpecList) { $this->spec_goods = $SpecList[1]; } $oGoodsTypeSpec = $this->app->model('goods_type_spec'); if (!cachemgr::get('goods_type_spec' . $type_id, $type_spec)) { cachemgr::co_start(); $type_spec = $oGoodsTypeSpec->get_type_spec($type_id); cachemgr::set('goods_type_spec' . $type_id, $type_spec, cachemgr::co_end()); } $filter['cat_id'] = $cat_id; $filter['goods_type'] = 'normal'; $filter['marketable'] = 'true'; //-----查找当前类别子类别的关联类型ID if ($urlFilter) { if ($vcat['type_id']) { //$filter['type_id']=$vcat['type_id']; $filter['type_id'] = null; } } //-------- foreach ($path as $p) { $arg = unserialize(serialize($this->pagedata['args'])); $arg[1] = $p['str']; $title = array(); if ($p['type'] == 'brand_id') { $brand = array(); foreach ($cat['brand'] as $b) { $brand[$b['brand_id']] = $b['brand_name']; } foreach ($p['data'] as $i) { $title[] = $brand[$i]; $tip = __("品牌"); } unset($brand); } elseif (substr($p['type'], 0, 2) == 's_') { $spec = array(); foreach ($p['data'] as $spk => $spv) { $tmp = explode(",", $spv); $tip = $SpecList[$tmp[0]]['name']; $title[] = $SpecList[$tmp[0]]['spec_value'][$tmp[1]]['spec_value']; $g['pdt_desc'] = $SpecList[$tmp[0]]['spec_value'][$tmp[1]]['spec_value']; /*前台搜索商品规格筛选,所要获取的pdt_desc*/ } } $curSpec[$tmp[0]] = $tmp[1]; } $this->pagedata['tabs'] = $cat['tabs']; $this->pagedata['cat_id'] = implode(",", $cat_id); $views = $cat['setting']['list_tpl']; foreach ($views as $key => $val) { $this->pagedata['views'][$key] = array($cat_type ? $old_cat_id : $this->id, '', $orderBy, $tab, $page, $cat_type, $val); } if ($cat['tabs'][$tab]) { parse_str($cat['tabs'][$tab]['filter'], $_filter); $filter = array_merge($filter, $_filter); } if (isset($this->pagedata['orderBy'][$orderBy])) { $orderby = $this->pagedata['orderBy'][$orderBy]['sql']; } $selector = array(); $search = array(); /***********************/ if ($SpecList) { if ($curSpec) { $curSpecKey = array_keys($curSpec); } foreach ($SpecList as $spk => $spv) { $selected = 0; if ($curSpecKey && in_array($spk, $curSpecKey)) { $spv['spec_value'][$curSpec[$spk]]['selected'] = true; $selected = 1; } if ($spv['spec_style'] == "select") { //下拉 $SpecSelList[$spk] = $spv; if ($selected) { $SpecSelList[$spk]['selected'] = true; } } elseif ($spv['spec_style'] == "flat") { $SpecFlatList[$spk] = $spv; if ($selected) { $SpecFlatList[$spk]['selected'] = true; } } } } $this->pagedata['SpecFlatList'] = $SpecFlatList; foreach ($SpecFlatList as $sk => $sv) { if (strpos($sv['name'], '颜色') !== false) { foreach ($sv['spec_value'] as $ssk => $ssv) { $this->pagedata['allcolor'] = $sk; } } } $this->pagedata['specimagewidth'] = $this->app->getConf('spec.image.width'); $this->pagedata['specimageheight'] = $this->app->getConf('spec.image.height'); $this->pagedata['orderBy'] = $objGoods->orderBy(); //排序方式 if (empty($orderBy)) { $orderBy = 1; } if (!isset($this->pagedata['orderBy'][$orderBy])) { $this->_response->set_http_response_code(404); } else { $orderby = $this->pagedata['orderBy'][$orderBy]['sql']; } $selector['ordernum'] = $cat['ordernum']; if (app::get('base')->getConf('server.search_server.search_goods')) { $searchApp = search_core::instance('search_goods'); $sfilter['filter'] = $filter; $sfilter['from'] = $pageLimit * ($page - 1); //分页 $sfilter['to'] = $pageLimit; $sfilter['order'] = $orderby; $sfilter['scount'] = count($cat['props']); } $res = false; //初始化 if (is_object($searchApp)) { $sphinxstart = true; $queryRes = $searchApp->query($sfilter); if ($queryRes) { $res = $searchApp->commit(); $nprop = $res['prop']; //属性搜索 $cbrand = $res['brand']; $rfilter['goods_id'] = $res['result']; if (is_array($res['result'])) { $count = $res['total']; $search_data = $objGoods->getList('*', $rfilter); foreach ($search_data as $tmp_data) { $tmp_search_data[$tmp_data['goods_id']] = $tmp_data; } foreach ($res['result'] as $v) { if (!isset($tmp_search_data[$v])) { continue; } $aProduct[] = $tmp_search_data[$v]; //产品 } unset($search_data); unset($tmp_search_data); } else { $count = 0; $aProduct = array(); } } } if ($res === false) { if (isset($filter['tag'][0]) && !$filter['tag'][0]) { unset($filter['tag']); } $tmp_filter['str_where'] = $objGoods->_filter($filter); $aProduct = $objGoods->getList('*', $tmp_filter, $pageLimit * ($page - 1), $pageLimit, $orderby); $count = $objGoods->count($tmp_filter); } /************************/ if (is_array($cat['brand'])) { if ($sphinxstart) { $bCount = $cbrand; } else { $bCount = $objGoods->countBrandGoods($tmp_filter, $cat['brand']); } foreach ($cat['brand'] as $bk => $bv) { if (is_array($filter['brand_id'])) { $bid = array_flip($filter['brand_id']); } $brand = array('name' => app::get('b2c')->_('品牌'), 'value' => $bid); $brandArray[$bv['brand_id']] = $bv['brand_name']; } foreach ((array) $bCount as $sk => $sv) { if (isset($brandArray[$bCount[$sk]['brand_id']])) { $tmpOp[$bCount[$sk]['brand_id']] = $brandArray[$bCount[$sk]['brand_id']] . "<span class='num'>(" . $bCount[$sk]['_count'] . ")</span>"; } } $brand['options'] = $tmpOp; $selector['brand_id'] = $brand; } $goods_relate = array(); if (!is_array($cat_id) && $cat_id || $cat_id[0] || $cat_type) { //$goods_relate = $aProduct; $goods_relate = $objGoods->getList("p_1,p_2,p_3,p_4,p_5,p_6,p_7,p_8,p_9,p_10,p_11,p_12,p_13,p_14,p_15,p_16,p_17,p_18,p_19,p_20", $filter, 0, 100); } foreach ((array) $cat['props'] as $prop_id => $prop) { if ($prop['search'] == 'select') { if (count($prop['options']) > 0) { $prop['value'] = $filter['p_' . $prop_id][0]; $searchSelect[$prop_id] = $prop; } } elseif ($prop['search'] == 'input') { $prop['value'] = $filter['p_' . $prop_id][0]; $searchInput[$prop_id] = $prop; } elseif ($prop['search'] == 'nav') { if (is_array($filter['brand_id']) && isset($filter['p_' . $prop_id])) { $prop['value'] = array_flip($filter['p_' . $prop_id]); } $plugadd = array(); if (is_array($goods_relate)) { foreach ($goods_relate as $k => $v) { if ($v["p_" . $prop_id] != null) { if ($plugadd[$v["p_" . $prop_id]]) { $plugadd[$v["p_" . $prop_id]] = $plugadd[$v["p_" . $prop_id]] + 1; } else { $plugadd[$v["p_" . $prop_id]] = 1; } } $aFilter['goods_id'][] = $v['goods_id']; //当前的商品结果集 } } $navselector = 0; if (is_array($prop['options'])) { foreach ($prop['options'] as $q => $e) { if ($plugadd[$q]) { $prop['options'][$q] = $prop['options'][$q] . "<span class='num'>(" . $plugadd[$q] . ")</span>"; if (!$navselector) { $navselector = 1; } } else { unset($prop['options'][$q]); } } } $selector[$prop_id] = $prop; } } if ($navselector) { $nsvcount = 0; $noshow = 0; foreach ($selector as $sk => $sv) { if ($sv['value']) { $nsvcount++; } if (is_numeric($sk) && !$sv['show']) { $noshow++; } } if ($nsvcount == intval(count($selector) - $noshow)) { $navselector = 0; } } foreach ((array) $cat['spec'] as $spec_id => $spec_name) { $sId['spec_id'][] = $spec_id; } $cat['ordernum'] = $cat['ordernum'] ? $cat['ordernum'] : array('' => 2); if ($cat['ordernum']) { if ($selector) { foreach ($selector as $key => $val) { if (!in_array($key, $cat['ordernum']) && $val) { $selectorExd[$key] = $val; } } } } if (is_array($aProduct)) { foreach ($aProduct as $apk => $apv) { $rfilter[] = $apv['goods_id']; } } if (is_object(kernel::service('propselect.prop_search'))) { $dprop = kernel::service('propselect.prop_search')->getProps($filter, $propz, $prot, $dprop, $searchSelect); } $this->pagedata['dprop'] = $dprop; $this->pagedata['nprop'] = $nprop; //对商品进行预处理 $this->pagedata['mask_webslice'] = $this->app->getConf('system.ui.webslice') ? ' hslice' : null; $this->pagedata['searchInput'] =& $searchInput; $this->pagedata['selectorExd'] = $selectorExd; $this->cat_id = $cat_id; $this->_plugins['function']['selector'] = array(&$this, '_selector'); $this->pagedata['pager'] = array('current' => $page, 'total' => ceil($count / $pageLimit), 'link' => $this->gen_url(array('app' => 'b2c', 'ctl' => 'site_gallery', 'full' => 1, 'act' => 'index', 'args' => array($cat_type ? $old_cat_id : implode(',', $cat_id), '', $orderBy, $tab, $tmp = time(), $cat_type, $view))) . '?scontent=' . urlencode($p['str']), 'token' => $tmp); if ($page != 1 && $page > $this->pagedata['pager']['total']) { $this->_response->set_http_response_code(404); } if (!$count) { $this->pagedata['emtpy_info'] = kernel::single('site_errorpage_get')->getConf('errorpage.search'); } $this->pagedata['searchtotal'] = $count; $aData = $this->get_current_member(); if (is_array($aProduct) && count($aProduct) > 0) { $objProduct = $this->app->model('products'); if ($this->app->getConf('site.show_mark_price') == 'true') { $setting['mktprice'] = $this->app->getConf('site.show_mark_price'); if (isset($aProduct)) { foreach ($aProduct as $pk => $pv) { if (empty($aProduct[$pk]['mktprice'])) { $aProduct[$pk]['mktprice'] = $objProduct->getRealMkt($pv['price']); } } } } else { $setting['mktprice'] = 0; } $setting['saveprice'] = $this->app->getConf('site.save_price'); $setting['buytarget'] = $this->app->getConf('site.buy.target'); $this->pagedata['setting'] = $setting; //spec_desc $this->site_member_lv_id = $aData['member_lv']; $oGoodsLv =& $this->app->model('goods_lv_price'); $oMlv =& $this->app->model('member_lv'); if ($this->site_member_lv_id) { $mlv = $oMlv->getList('dis_count', array('member_lv_id' => $this->site_member_lv_id)); } $tmpGoods = array(); $tmp_goods_ids = array_map('current', $aProduct); /** 获取所有商品对应的货品 **/ $tmp_products = $objProduct->getList('product_id, spec_info, price,mktprice, freez, store, marketable, goods_id', array('goods_id|in' => $tmp_goods_ids, 'marketable' => 'true')); $tmp_products = utils::array_change_key($tmp_products, 'goods_id', 1); /** 促销处理 **/ $aProduct['goods_ids'] = $tmp_goods_ids; $aPromotion_price = kernel::single('b2c_goods_promotion_price')->process($aProduct); unset($aProduct['goods_ids']); foreach ($aProduct as $key => &$val) { $db = kernel::database(); $tvPrice = array(); //$temp = $objProduct->getList('mktprice,product_id, spec_info, price, freez, store, marketable, goods_id',array('goods_id'=>$val['goods_id'],'marketable'=>'true')); $temp = $tmp_products[$val['goods_id']]; $priceArea = array(); $mktpriceArea = array(); foreach ($tmp_products[$val['goods_id']] as $tpv) { $tvPrice[] = $tpv['price']; $priceArea[] = $tpv['price']; //销售价区域 if ($tpv['mktprice'] == '' || $tpv['mktprice'] == null) { $mktpriceArea[] = $objProduct->getRealMkt($tpv['mktprice']); } else { $mktpriceArea[] = $tpv['mktprice']; } } if ($this->app->getConf('site.show_mark_price') == "true" && count($priceArea) > 1) { //列表页价格区间@lujy $minprice = min($priceArea); $maxprice = max($priceArea); if ($minprice != $maxprice) { $val['minprice'] = $minprice; $val['maxprice'] = $maxprice; } } if ($this->app->getConf('site.show_mark_price') == "true" && count($mktpriceArea) > 1) { //列表也市场价区间 $mktminprice = min($mktpriceArea); $mktmaxprice = max($mktpriceArea); if ($mktminprice != $mktmaxprice) { $val['minmktprice'] = $mktminprice; $val['maxmktprice'] = $mktmaxprice; } } $val['price'] = min($tvPrice); $val['mktprice'] = max($mktpriceArea); if ($mlv) { $tmpGoods = array(); foreach ($oGoodsLv->getList('product_id,price', array('goods_id' => $val['goods_id'], 'level_id' => $this->site_member_lv_id)) as $k => $v) { $tmpGoods[$v['product_id']] = $v['price']; } foreach ($temp as &$tv) { $tv['price'] = isset($tmpGoods[$tv['product_id']]) ? $tmpGoods[$tv['product_id']] : $mlv[0]['dis_count'] * $tv['price']; } $val['price'] = isset($tmpGoods[$tv['product_id']]) ? $tmpGoods[$tv['product_id']] : $mlv[0]['dis_count'] * $val['price']; } if ($aPromotion_price[$val['goods_id']]) { $promotion_price = $aPromotion_price[$val['goods_id']]; if ($promotion_price['price']) { $val['timebuyprice'] = $promotion_price['price']; } else { $val['timebuyprice'] = $val['price']; } $val['show_button'] = $promotion_price['show_button']; $val['timebuy_over'] = $promotion_price['timebuy_over']; } $val['spec_desc_info'] = $temp; $aProduct[$key]['product_id'] = $temp[0]['product_id']; } // add here by liuyong // show tag on goods image foreach (kernel::servicelist('tags_special.add') as $services) { if (is_object($services)) { if (method_exists($services, 'add')) { $services->add($rfilter, $aProduct); } } } // end of add // 获取商品评分和频率 $objPoint = $this->app->model('comment_goods_point'); $salesGoods = $this->app->model('goods_promotion_ref'); foreach ($aProduct as $k => $v) { $aProduct[$k]['goods_point'] = $objPoint->get_single_point($v['goods_id']); $aProduct[$k]['total_point_nums'] = $objPoint->get_point_nums($v['goods_id']); //获取促销商品折扣图片 $aProduct[$k]['salse_description'] = $db->select("SELECT gpr.`goods_id`,gpr.`description`,srg.`image` FROM `sdb_b2c_goods_promotion_ref` as gpr\n left join sdb_b2c_sales_rule_goods as srg on gpr.rule_id = srg.rule_id\n WHERE gpr.`goods_id`=" . $v['goods_id'] . ""); // $aProduct[$k]['salse_description'] = $salesGoods->getList('goods_id,description,image', array('goods_id' => $v['goods_id'])); } $this->pagedata['products'] =& $aProduct; } if (!$aData['member_id']) { $this->pagedata['login'] = '******'; } if ($SpecSelList) { $this->pagedata['SpecSelList'] = $SpecSelList; } if ($searchSelect) { $this->pagedata['searchSelect'] =& $searchSelect; } $this->pagedata['curView'] = $view; $this->pagedata['selector'] =& $selector; $this->pagedata['cat_type'] = $cat_type; if ($GLOBALS['search_array'] && is_array($GLOBALS['search_array'])) { $this->pagedata['search_array'] = implode("+", $GLOBALS['search_array']); } $this->pagedata['_PDT_LST_TPL'] = $cat['tpl']; $this->pagedata['filter'] = $filter; unset($filter['name']); $this->pagedata['bfilter'] = $filter; $this->set_tmpl('gallery'); $this->pagedata['gallery_display'] = $this->app->getConf('gallery.display.grid.colnum'); $this->pagedata['show_cat'] = $this->app->getConf('site.cat.select'); if ($count < $this->pagedata['gallery_display']) { $this->pagedata['gwidth'] = $count * (100 / $this->pagedata['gallery_display']); } else { $this->pagedata['gwidth'] = 100; } $this->pagedata['property_select'] = $this->app->getConf('site.property.select'); $imageDefault = app::get('image')->getConf('image.set'); $this->pagedata['image_set'] = $imageDefault; $this->pagedata['defaultImage'] = $imageDefault['S']['default_image']; $this->pagedata['proparg'] = $proparg; /** 获取商品表相关meta **/ if ($cat_id) { $obj_meta_register = app::get('dbeav')->model('meta_register'); $arr_meta_register = $obj_meta_register->getList('*', array('tbl_name' => $productCat->table_name(1), 'col_name' => 'seo_info')); if (!$arr_meta_register) { $productCat->cat_meta_register(); } $meta_desc = $arr_meta_register[0]['col_desc']; $col_type = $arr_meta_register[0]['col_type']; $obj_meta_value = app::get('dbeav')->model('meta_value_' . $col_type); $seo_info = $obj_meta_value->select($arr_meta_register[0]['mr_id'], $cat_id); if (is_array($seo_info) && count($seo_info) == 1) { $seo_info = $seo_info[$cat_id[0]]; } elseif (is_string($seo_info)) { $seo_info = unserialize($seo_info[$cat_id[0]]); } elseif (!$seo_info) { $seo_info = ""; } } if (!empty($seo_info['seo_info']['seo_title']) || !empty($seo_info['seo_info']['seo_keywords']) || !empty($seo_info['seo_info']['seo_description'])) { $this->title = $seo_info['seo_info']['seo_title']; $this->keywords = $seo_info['seo_info']['seo_keywords']; $this->description = $seo_info['seo_info']['seo_description']; } else { $this->setSeo('site_gallery', 'index', $this->prepareSeoData($this->pagedata)); } $this->page('site/gallery/index.html'); }
public function dispatch($query) { $this->check_blacklist(); //黑名单检测 $page_starttime = $this->microtime_float(); $this->init_query_info($query); $this->init_request_info(); $this->check_https(); $this->check_expanded_name(); $router_cache_options = $this->check_router_cache(); $page_key = 'SITE_PAGE_CACHE:' . $this->_request->get_request_uri(); if (!$this->is_need_cache() || $this->is_need_cache() && !cachemgr::get($page_key, $page, $router_cache_options['skipvary'])) { $cache_log = 'cache missed on ' . date('Y-m-d H:i:s'); logger::info($cache_log . ',URL:' . $this->_request->get_request_uri()); $this->_response->set_header('X-Page-Cache', $cache_log, true); cachemgr::co_start(); $this->default_dispatch(); //执行控制器 $page['html'] = implode("\n", $this->_response->get_bodys()); $page['date'] = date('Y-m-d H:i:s'); $page['times'] = sprintf('%0.2f', $this->microtime_float() - $page_starttime); if ($this->is_need_cache() && $this->_response->get_http_response_code() == 200 && $this->has_page_cache_control() === true) { $page_cache = true; $cache_log = 'cache refreshed on ' . $page['date'] . ',page speed:' . $page['times']; //logger::info($cache_log.',URL:'. $this->_request->get_request_uri()); $this->_response->set_header('X-Page-Cache', $cache_log, true); $page['headers'] = $this->_response->get_headers(); $page['raw_headers'] = $this->_response->get_raw_headers(); $page['etag'] = md5($page['html']); $cache_options = cachemgr::co_end(); if ($router_cache_options['expires']) { $cache_options['expires'] = $cache_options['expires'] && $cache_options['expires'] < $router_cache_options['expires'] ? $cache_options['expires'] : $router_cache_options['expires']; } $cache_options['expires'] = $cache_options['expires'] > time() ? $cache_options['expires'] : 0; cachemgr::set($page_key, $page, $cache_options); } else { $page_cache = false; cachemgr::co_end(); } } else { $page_cache = true; $this->_response->clean_headers(); if (isset($page['headers'])) { foreach ($page['headers'] as $header) { $this->_response->set_header($header['name'], $header['value'], $header['replace']); } } if (isset($page['raw_headers'])) { foreach ($page['raw_headers'] as $raw_header) { $this->_response->set_raw_headers($raw_header); } } $cache_log = 'cache hit on ' . $page['date'] . ',page speed:' . $page['times']; //logger::info($cache_log.',URL:'. $this->_request->get_request_uri()); $this->_response->set_header('X-Page-Cache', $cache_log, true); } if ($page_cache === true) { $etag = $page['etag'] ? $page['etag'] : md5($page['html']); //todo: 兼容 $this->_response->set_header('Etag', $etag); $matchs = explode(',', $_ENV['HTTP_IF_NONE_MATCH']); foreach ($matchs as $match) { if (trim($match) == $etag) { $this->_response->clean_headers(); $this->_response->set_header('Content-length', '0'); $this->_response->set_http_response_code(304)->send_headers(); exit; } } } $this->set_vary_cookie(); $this->_response->send_headers(); echo $page['html']; logger::debug('This page created by ' . $page['date']); logger::debug('Kvstore queries count:' . base_kvstore::$__fetch_count); logger::debug('Page speed: ' . $page['times']); }
public function get_goods_brand($goodsId, $goodsInfo = array()) { if (empty($goodsInfo)) { $goodsInfo = $this->goodsModel->getList('brand_id', array('goods_id' => $goodsId)); $goodsInfo = $goodsInfo[0]; } if (!empty($goodsInfo['brand_id'])) { cachemgr::co_start(); if (!cachemgr::get("goodsObjectBrand" . $goodsInfo['brand_id'], $goodsInfoBrand)) { $goodsInfoBrand = app::get("b2c")->model("brand")->getList('*', array('brand_id' => $goodsInfo['brand_id'])); $goodsInfoBrand = $goodsInfoBrand[0]; cachemgr::set("goodsObjectBrand" . $goodsInfo['brand_id'], $goodsInfoBrand, cachemgr::co_end()); } } return $goodsInfoBrand; }
function ajax_product_basic($product_id) { $sql = "select * from sdb_starbuy_special_goods WHERE product_id = '{$product_id}' AND status = 'true'"; $huodong = kernel::database()->select($sql); $gguo = ''; if ($huodong) { $gguo = $huodong[0]['limit']; } $this->pagedata['xiangou_one'] = $gguo; $this->_response->set_header('Cache-Control', 'no-store, no-cache'); if (!cachemgr::get('ajax_product_basic' . $product_id, $basic_html)) { cachemgr::co_start(); $product = app::get('b2c')->model('products')->getList('*', array('product_id' => $product_id)); if (!$product) { echo json_encode(array('error' => app::get('b2c')->_('商品不存在'))); return; } if ($object_price = kernel::service('special_goods')) { $app_name = $object_price->ifSpecial($product_id); $this->pagedata['app_name'] = $app_name ? $app_name : ""; } $aGoods = app::get('b2c')->model('goods')->getList('*', array('goods_id' => $product[0]['goods_id'])); $aGoods = $aGoods[0]; $aGoods['product'] = $product[0]; $userObject = kernel::single('b2c_user_object'); $siteMember = $userObject->get_current_member(); if (empty($siteMember['member_id'])) { $this->pagedata['login'] = '******'; $member_id = '-1'; } else { $member_id = $siteMember['member_id']; $member_lv = $siteMember['member_lv']; $this->pagedata['member_info'] = $siteMember; $this->pagedata['this_member_lv_id'] = $member_lv; } $goodsId = $aGoods['goods_id']; $setting = $this->_get_goods_setting($goodsId); $this->pagedata['setting'] = $setting; $productBasic = $this->_get_product_basic($product_id, $aGoods, $siteMember); $gfav = explode(',', $_COOKIE['S']['GFAV'][$siteMember['member_id']]); if (in_array($aGoods['goods_id'], $gfav)) { $productBasic['is_fav'] = true; } //btn $this->pagedata['btn_page_list'] = $this->_get_servicelist_by('b2c_products_index_btn'); $this->pagedata['page_product_basic'] = $productBasic; //社会化分享 $goodsshare = kernel::single('b2c_goods_share')->get_share($productBasic); $this->pagedata['goods_share'] = $goodsshare; /**** start 商品评分 ****/ $objPoint = $this->app->model('comment_goods_point'); $this->pagedata['goods_point'] = $objPoint->get_single_point($goodsId); $this->pagedata['total_point_nums'] = $objPoint->get_point_nums($goodsId); /**** end 商品评分 ****/ $basic_html = $this->fetch('site/product/basic.html'); cachemgr::set('ajax_product_basic' . $product_id, $basic_html, cachemgr::co_end()); } echo $basic_html; }
public function dispatch($query) { $page_starttime = $this->microtime_float(); $post = $this->_request->get_post(); //post值 foreach (kernel::servicelist('site.router.predispatch') as $obj) { $obj->router_predispatch(); } $config_page_cache = app::get('site')->getConf('base.site_page_cache'); $page_key = 'SITE_PAGE_CACHE:' . $this->_request->get_request_uri(); if (count($post) > 0 || $config_page_cache === 'false' || !cachemgr::get($page_key, $page) || isset($_COOKIE['site']['preview']) && $_COOKIE['site']['preview'] == 'true') { if (defined('PAGE_CACHE_LOG') && PAGE_CACHE_LOG) { kernel::log('page cache miss:' . $this->_request->get_request_uri()); } $query_info = $this->parse_query($query); //分析query $allow_name = $query_info['allow']; //许可名 if (!array_key_exists($allow_name, $this->sitemap)) { $this->http_status('404'); //404页面 } if (app::get('site')->getConf('base.check_uri_expanded_name') == 'true' && $this->get_uri_expended_name($allow_name) != $query_info['extension']) { $this->http_status('404'); //404页面 } $separator = $query_info['separator'] ? $query_info['separator'] : $this->get_separator(); //分隔符 $realquery = $query_info['query']; //真实链接 cachemgr::co_start(); $route_value = $this->sitemap[$allow_name]; $service = kernel::service('site_router.' . $route_value[0]); if (is_object($service) && $service->enable()) { $service->dispatch($realquery, $allow_name, $separator); } else { $this->default_dispatch($realquery, $allow_name, $separator); } $page['html'] = join("\n", $this->_response->get_bodys()); $page['date'] = date("Y-m-d H:i:s"); $page['queries'] = base_db_connections::$mysql_query_executions; $page['times'] = sprintf('%0.2f', $this->microtime_float() - $page_starttime); if (count($post) == 0 && $this->_response->get_http_response_code() == 200 && $this->has_page_cache_control() === true && $config_page_cache === 'true' && (!isset($_COOKIE['site']['preview']) || $_COOKIE['site']['preview'] == '')) { $page_cache = true; $this->_response->set_header('X-Cache', 'HIT from ecos-pagecache ' . $page['date']); //todo:记录x-cache $page['headers'] = $this->_response->get_headers(); $page['raw_headers'] = $this->_response->get_raw_headers(); $page['etag'] = md5($page['html']); $theme_last_modifty = kernel::single('site_theme_base')->get_last_modify(); //todo:记录theme最后更新时间,避免无模板情况cache问题 cachemgr::set($page_key, $page, cachemgr::co_end()); } else { $page_cache = false; cachemgr::co_end(); } } else { $page_cache = true; $this->_response->clean_headers(); if (isset($page['headers'])) { foreach ($page['headers'] as $header) { $this->_response->set_header($header['name'], $header['value'], $header['replace']); } } if (isset($page['raw_headers'])) { foreach ($page['raw_headers'] as $raw_header) { $this->_response->set_raw_headers($raw_header); } } if (defined('PAGE_CACHE_LOG') && PAGE_CACHE_LOG) { kernel::log('page cache hit:' . $this->_request->get_request_uri()); } } if ($page_cache === true) { $etag = $page['etag'] ? $page['etag'] : md5($page['html']); //todo: 兼容 $this->_response->set_header('Etag', $etag); $matchs = explode(',', $_ENV['HTTP_IF_NONE_MATCH']); foreach ($matchs as $match) { if (trim($match) == $etag) { $this->_response->clean_headers(); $this->_response->set_header('Content-length', '0'); $this->_response->set_http_response_code(304)->send_headers(); exit; } } } $this->set_vary_cookie(); $this->_response->send_headers(); echo $page['html']; //only test //echo "\n".'<!-- ' . (($page_cache==true)?'Cached':'No cache') . ' -->'; //echo "\n".'<!-- This page created by ' . $page['date'] . ' -->'; //echo "\n".'<!-- Queries:' . $page['queries'] . ' -->'; //echo "\n".'<!-- Times:' . $page['times'] . 's -->'; }
private function screen($cat_id, $filter) { if (empty($cat_id)) { $screen = array(); } $screen['cat_id'] = $cat_id; $cat_id = $cat_id ? $cat_id : $this->pagedata['show_cat_id']; //搜索时的分类 if (!$screen['cat_id'] && count($this->pagedata['catArr']) > 1) { $searchCat = app::get('b2c')->model('goods_cat')->getList('cat_id,cat_name', array('cat_id' => $this->pagedata['catArr'])); $i = 0; foreach ($this->catCount as $catid => $num) { $sort[$catid] = $i; if ($i == 9) { break; } $i++; } foreach ($searchCat as $row) { $screen['search_cat'][$sort[$row['cat_id']]] = $row; } ksort($screen['search_cat']); } //商品子分类 /* $show_cat = $this->app->getConf('site.cat.select'); if($show_cat == 'true'){ $sCatData = app::get('b2c')->model('goods_cat')->getList('cat_id,cat_name',array('parent_id'=>$cat_id)); $screen['cat'] = $sCatData; } */ cachemgr::co_start(); if (!cachemgr::get("goodsObjectCat" . $cat_id, $catInfo)) { $goodsInfoCat = app::get("b2c")->model("goods_cat")->getList('*', array('cat_id' => $cat_id)); $catInfo = $goodsInfoCat[0]; cachemgr::set("goodsObjectCat" . $cat_id, $catInfo, cachemgr::co_end()); } $this->goods_cat = $catInfo['cat_name']; //seo cachemgr::co_start(); if (!cachemgr::get("goodsObjectType" . $catInfo['type_id'], $typeInfo)) { $typeInfo = app::get("b2c")->model("goods_type")->dump2(array('type_id' => $catInfo['type_id'])); cachemgr::set("goodsObjectType" . $catInfo['type_id'], $typeInfo, cachemgr::co_end()); } $this->goods_type = $typeInfo['name']; //seo if ($typeInfo['price'] && $filter['price'][0]) { $active_filter['price']['title'] = $this->app->_('价格'); $active_filter['price']['label'] = 'price'; $active_filter['price']['options'][0]['data'] = $filter['price'][0]; foreach ($typeInfo['price'] as $key => $price) { $price_filter = implode('~', $price); if ($filter['price'][0] == $price_filter) { $typeInfo['price'][$key]['active'] = 'active'; $active_arr['price'] = 'active'; } $active_filter['price']['options'][0]['name'] = $filter['price'][0]; } } $screen['price'] = $typeInfo['price']; if ($typeInfo['setting']['use_brand']) { $type_brand = app::get('b2c')->model('type_brand')->getList('brand_id', array('type_id' => $catInfo['type_id'])); if ($type_brand) { foreach ($type_brand as $brand_k => $brand_row) { $brand_ids[$brand_k] = $brand_row['brand_id']; } } $brands = app::get('b2c')->model('brand')->getList('brand_id,brand_name', array('brand_id' => $brand_ids, 'disabled' => 'false')); //是否已选择 foreach ($brands as $b_k => $row) { if (@in_array($row['brand_id'], $filter['brand_id'])) { $brands[$b_k]['active'] = 'active'; $active_arr['brand'] = 'active'; $active_filter['brand']['title'] = $this->app->_('品牌'); $active_filter['brand']['label'] = 'brand_id'; $active_filter['brand']['options'][$row['brand_id']]['data'] = $row['brand_id']; $active_filter['brand']['options'][$row['brand_id']]['name'] = $row['brand_name']; } } $screen['brand'] = $brands; } //扩展属性 if ($typeInfo['setting']['use_props'] && $typeInfo['props']) { foreach ($typeInfo['props'] as $p_k => $p_v) { if ($p_v['search'] != 'disabled') { $props[$p_k]['name'] = $p_v['name']; $props[$p_k]['goods_p'] = $p_v['goods_p']; $props[$p_k]['type'] = $p_v['type']; $props[$p_k]['search'] = $p_v['search']; $props[$p_k]['show'] = $p_v['show']; $propsActive = array(); if ($p_v['options']) { foreach ($p_v['options'] as $propItemKey => $propItemValue) { $activeKey = 'p_' . $p_v['goods_p']; if ($filter[$activeKey] && in_array($propItemKey, $filter[$activeKey])) { $active_filter[$activeKey]['title'] = $p_v['name']; $active_filter[$activeKey]['label'] = $activeKey; $active_filter[$activeKey]['options'][$propItemKey]['data'] = $propItemKey; $active_filter[$activeKey]['options'][$propItemKey]['name'] = $propItemValue; $propsActive[$propItemKey] = 'active'; } } } $props[$p_k]['options'] = $p_v['options']; $props[$p_k]['active'] = $propsActive; } } $screen['props'] = $props; } //规格 $gType =& $this->app->model('goods_type'); $SpecList = $gType->getSpec($catInfo['type_id'], 1); //获取关联的规格 if ($SpecList) { foreach ($SpecList as $speck => $spec_value) { if ($spec_value['spec_value']) { foreach ($spec_value['spec_value'] as $specKey => $SpecValue) { if ($spec_value['spec_type'] == "image") { $SpecList[$speck]['spec_value'][$specKey]['spec_image'] = base_storager::image_path($SpecList[$speck]['spec_image'][$specKey]['spec_image'], 's'); } $activeKey = 's_' . $speck; if ($filter[$activeKey] && in_array($specKey, $filter[$activeKey])) { $active_filter[$activeKey]['title'] = $spec_value['name']; $active_filter[$activeKey]['label'] = $activeKey; $active_filter[$activeKey]['options'][$specKey]['data'] = $specKey; $active_filter[$activeKey]['options'][$specKey]['name'] = $SpecValue['spec_value']; $specActive[$specKey] = 'active'; } } } $SpecList[$speck]['active'] = $specActive; } } $screen['spec'] = $SpecList; //排序 $orderBy = $this->app->model('goods')->orderBy(); $screen['orderBy'] = $orderBy; //标签 $tagFilter['app_id'][] = 'b2c'; $giftAppActive = app::get('gift')->is_actived(); if ($giftAppActive) { $tagFilter['app_id'][] = 'gift'; } $progetcouponAppActive = app::get('progetcoupon')->is_actived(); if ($progetcouponAppActive) { //$progetcouponAppActive['app_id'][] = 'progetcoupon'; } $tags = app::get('desktop')->model('tag')->getList('*', $tagFilter); if ($filter['pTag']) { $active_arr['pTags'] = 'active'; } foreach ($tags as $tag_key => $tag_row) { if ($tag_row['tag_type'] == 'goods') { //商品标签 if (@in_array($tag_row['tag_id'], $filter['gTag'])) { $screen['tags']['goods'][$tag_key]['active'] = 'checked'; } $screen['tags']['goods'][$tag_key]['tag_id'] = $tag_row['tag_id']; $screen['tags']['goods'][$tag_key]['tag_name'] = $tag_row['tag_name']; } elseif ($tag_row['tag_type'] == 'promotion') { //促销标签 if (@in_array($tag_row['tag_id'], $filter['pTag'])) { $screen['tags']['promotion'][$tag_key]['active'] = 'active'; $active_filter['pTag']['title'] = $this->app->_('促销商品'); $active_filter['pTag']['label'] = 'pTag'; $active_filter['pTag']['options'][$tag_row['tag_id']]['data'] = $tag_row['tag_id']; $active_filter['pTag']['options'][$tag_row['tag_id']]['name'] = $tag_row['tag_name']; } $screen['tags']['promotion'][$tag_key]['tag_id'] = $tag_row['tag_id']; $screen['tags']['promotion'][$tag_key]['tag_name'] = $tag_row['tag_name']; } } $this->pagedata['active_arr'] = $active_arr; $return['screen'] = $screen; $return['active_filter'] = $active_filter; $return['seo_info'] = $catInfo['seo_info']; return $return; }
public final function display_tmpl($tmpl, $fetch = false, $is_preview = false) { array_unshift($this->_files, $this->get_theme() . '/' . $tmpl); $this->_vars = $this->pagedata; $tmpl_file = realpath(THEME_DIR . '/' . $this->get_theme() . '/' . $tmpl); $this->tmpl_cachekey('__theme_app_id', $this->get_tmpl_main_app_id() ? $this->get_tmpl_main_app_id() : $this->app->app_id); $this->tmpl_cachekey('__theme_main_page', $this->pagedata['_MAIN_']); $compile_id = $this->compile_id($this->get_theme() . "/" . $tmpl); $last_modified = filemtime($tmpl_file); #if($this->force_compile || base_kvstore::instance('cache/theme')->fetch($compile_id, $compile_code, filemtime($tmpl_file))===false){ if (!$is_preview) { if ($this->force_compile || !cachemgr::get($compile_id . $last_modified, $compile_code)) { cachemgr::co_start(); $tmpl_content = kernel::single('site_theme_file')->get_tmpl_content($this->get_theme(), $tmpl); $compile_code = $this->_compiler()->compile($tmpl_content); if ($compile_code !== false) { $compile_code = $this->fix_theme_media($compile_code); #base_kvstore::instance('cache/theme')->store($compile_id, $compile_code); } cachemgr::set($compile_id . $last_modified, $compile_code, cachemgr::co_end()); } } else { $this->_compiler()->is_preview = $is_preview; $tmpl_content = kernel::single('site_theme_file')->get_tmpl_content($this->get_theme(), $tmpl); $compile_code = $this->_compiler()->compile($tmpl_content); if ($compile_code !== false) { $compile_code = $this->fix_theme_media($compile_code); } } kernel::single('site_theme_base')->get_theme_cache_version($this->get_theme()); /** 添加theme_url的值 **/ $theme_url = kernel::get_themes_host_url(); ob_start(); eval('?>' . $compile_code); $content = ob_get_contents(); ob_end_clean(); array_shift($this->_files); $this->pre_display($content); #图片地址替换 by michael if (defined('IMG_SERVER')) { $img_array = unserialize(constant('IMG_SERVER')); if ($img_array) { foreach ($img_array as $key => $value) { $content = str_replace($key, $value, $content); } } } if ($fetch === true) { return $content; } else { echo $content; } }
function get_goods($listgoods = null, $member_lv_id = -1) { if (empty($listgoods)) { return false; } $aGoods['goods_id'] = $listgoods['goods_id']; $aGoods['bn'] = $listgoods['bn']; $aGoods['name'] = $listgoods['name']; $goods_type = app::get("b2c")->model("goods_type"); if (!cachemgr::get("goods_type_props_value_list2dump" . $listgoods['type_id'], $goods_type_data)) { cachemgr::co_start(); $goods_type_data = $goods_type->dump($listgoods['type_id']); cachemgr::set("goods_type_props_value_list2dump" . $listgoods['type_id'], $goods_type_data, cachemgr::co_end()); } $aGoods['type'] = $goods_type_data; $cat['cat_id'] = $listgoods['cat_id']; $aGoods['category'] = $cat; $brand_row = $goods_type->db->selectrow("select brand_id,brand_name from sdb_b2c_brand where brand_id=" . intval($listgoods['brand_id'])); $aGoods['brand'] = $brand_row; $aGoods['status'] = $listgoods['status']; $aGoods['marketable'] = $listgoods['marketable']; $aGoods['store'] = $listgoods['store']; $aGoods['notify_num'] = $listgoods['notify_num']; $aGoods['gain_score'] = $listgoods['gain_score']; $aGoods['unit'] = $listgoods['unit']; $aGoods['brief'] = $listgoods['brief']; $aGoods['image_default_id'] = $listgoods['image_default_id']; $aGoods['udfimg'] = $listgoods['udfimg']; $aGoods['thumbnail_pic'] = $listgoods['thumbnail_pic']; $aGoods['small_pic'] = $listgoods['small_pic']; $aGoods['big_pic'] = $listgoods['big_pic']; $aGoods['min_buy'] = $listgoods['min_buy']; $aGoods['package_scale'] = $listgoods['package_scale']; $aGoods['package_unit'] = $listgoods['package_unit']; $aGoods['package_use'] = $listgoods['package_use']; $aGoods['score_setting'] = $listgoods['score_setting']; $aGoods['nostore_sell'] = $listgoods['nostore_sell']; $aGoods['goods_setting'] = $listgoods['goods_setting']; $aGoods['disabled'] = $listgoods['disabled']; $aGoods['adjunct'] = $listgoods['adjunct']; //meta数据 $aGoods['seo_info'] = $listgoods['seo_info']; $aGoods['price'] = $listgoods['price']; $aGoods['cost'] = $listgoods['cost']; $products = $this->app->model("products"); //市场价 if ($listgoods['mktprice'] == '' || $listgoods['mktprice'] == null) { $aGoods['mktprice'] = $products->getRealMkt($aGoods['price']); } else { $aGoods['mktprice'] = $listgoods['mktprice']; } $aGoods['weight'] = $listgoods['weight']; $member_lv = $this->app->model("member_lv"); $memLv = $member_lv->getList("member_lv_id,name,dis_count"); foreach ($memLv as $memLv_k => $memLv_v) { $memLvaData[$memLv_v['member_lv_id']] = $memLv_v; } $sql = "SELECT p.*,l.level_id,l.price as lv_price FROM `sdb_b2c_products` AS p LEFT JOIN `sdb_b2c_goods_lv_price` AS l ON p.product_id = l.product_id "; $sql .= " WHERE p.goods_id =" . intval($aGoods['goods_id']); $sql .= " AND p.marketable='true' "; if (!$aGoods['nostore_sell']) { $sql .= " AND p.store>0 "; } $products_row = $products->db->select($sql); foreach ($products_row as $pro_k => $pro_v) { $price = $pro_v['price']; unset($pro_v['price']); $pro_v['spec_desc'] = unserialize($pro_v['spec_desc']); $productAmp[$pro_v['product_id']] = $pro_v; $productAmp[$pro_v['product_id']]['price']['price']['price'] = $price; $productAmp[$pro_v['product_id']]['price']['cost']['price'] = $pro_v['cost']; $productAmp[$pro_v['product_id']]['price']['mktprice']['price'] = $pro_v['mktprice']; if ($pro_v['level_id']) { $product_lv_price[$pro_v['product_id']][$pro_v['level_id']] = $pro_v['lv_price']; } $product_id_filter[$pro_v['product_id']] = $pro_v['product_id']; } foreach ($product_id_filter as $pid) { $price = $productAmp[$pid]['price']['price']['price']; foreach ($memLvaData as $memLv_k => $memLv_v) { $rs = array('level_id' => $memLv_v['member_lv_id'], 'price' => $memLv_v['dis_count'] > 0 ? $memLv_v['dis_count'] * $price : $price, 'title' => $memLv_v['name'], 'custom' => 'false'); if ($product_lv_price[$pid][$memLv_v['member_lv_id']]) { $rs['price'] = $product_lv_price[$pid][$memLv_v['member_lv_id']]; } $productAmp[$pid]['price']['member_lv_price'][$memLv_v['member_lv_id']] = $rs; } if (isset($productAmp[$pid]['price']) && $productAmp[$pid]['price'] && is_array($productAmp[$pid]['price']) && isset($productAmp[$pid]['price']['member_lv_price']) && $productAmp[$pid]['price']['member_lv_price'] && is_array($productAmp[$pid]['price']['member_lv_price'])) { if (array_key_exists('member_lv_price', $productAmp[$pid]['price']) && array_key_exists($member_lv_id, $productAmp[$pid]['price']['member_lv_price'])) { $productAmp[$pid]['price']['price']['current_price'] = $productAmp[$pid]['price']['member_lv_price'][$member_lv_id]['price']; } else { $productAmp[$pid]['price']['price']['current_price'] = $productAmp[$pid]['price']['price']['price']; } } } $aGoods['product'] = $productAmp; $image = app::get("image")->model("image_attach"); $image_data = $image->getList("attach_id,image_id", array("target_id" => intval($aGoods['goods_id']), 'target_type' => 'goods')); foreach ($image_data as $img_k => $img_v) { $aGoods['images'][$img_v['attach_id']] = $img_v; } //$aGoods['spec'] = 下面 $oSpec = $this->app->model('specification'); if ($listgoods['spec_desc'] && is_array($listgoods['spec_desc'])) { foreach ($listgoods['spec_desc'] as $specId => $spec) { $aRow = $oSpec->getList("*", array('spec_id' => $specId)); $aGoods['spec'][$specId] = $aRow[0]; foreach ($spec as $pSpecId => $specValue) { $aGoods['spec'][$specId]['option'][$pSpecId] = array_merge(array('private_spec_value_id' => $pSpecId), $specValue); } } } unset($aGoods['spec_desc']); if ($aGoods['product']) { $aProduct = current($aGoods['product']); if (isset($aProduct['price']['price']['current_price'])) { $aGoods['current_price'] = $aProduct['price']['price']['current_price']; } } else { if ($aGoods['price']) { $aGoods['current_price'] = $aGoods['price']; } } foreach ($listgoods as $aGoods_k => $aGoods_v) { if (strpos($aGoods_k, "p_") === 0) { $aGoods['props'][$aGoods_k]['value'] = $aGoods_v; } } $aGoods['description'] = $listgoods['intro']; return $aGoods; }
/** * 根据条件获取商品信息 * @param array $filter (所有条件都可选) * array( 'goodsId' => array(1,2)/1, //商品ID 'priceFrom' => 5, //价格区间(低) 'priceTo' => 100, //价格区间(高) 'typeId' => 2, //商品类型ID 'catId' => array(1,2)/1, //商品分类ID 'brandId' => array(1,2)/1, //商品品牌ID 'goodsOrderBy' => 1, //商品排序 'goodsNum' => 12, //总商品数(xo最多20) ), */ public function getGoodsList($filter, $platform = 'site') { if (isset($_COOKIE['MLV'])) { if (!cachemgr::get('member_lv_disCount' . $_COOKIE['MLV'], $dis_count)) { cachemgr::co_start(); $member_level = $_COOKIE['MLV']; (array) ($arr = $this->app->model('member_lv')->getList('dis_count', array('member_lv_id' => $member_level))); $dis_count = $arr[0]['dis_count']; cachemgr::set('member_lv_disCount' . $_COOKIE['MLV'], $dis_count, cachemgr::co_end()); } } $objLvprice = $this->app->model('goods_lv_price'); $goods = $this->app->model('goods'); $objProduct = $this->app->model('products'); $objgoodscat = $this->app->model('goods_cat'); $config = $this->app->getConf('site.save_price'); $imageDefault = app::get('image')->getConf('image.set'); $search = $this->app->model('search'); $orderBy = $filter['goodsOrderBy'] ? $filter['goodsOrderBy'] : 0; $order = $filter['goodsOrderBy'] ? $this->_getOrderBy($filter['goodsOrderBy'], false) : null; $limit = intval($filter['goodsNum']) > 0 ? intval($filter['goodsNum']) : 6; //$limit = ($limit > 20) ? 20 : $limit; $result = array(); unset($filter['goodsOrderBy']); unset($filter['goodsNum']); $_filter = $this->_getFilter($filter); $result['goodsMoreLink'] = kernel::router()->gen_url(array('app' => 'b2c', 'ctl' => 'site_gallery', 'act' => 'index', 'args' => array(implode(",", (array) $filter['catId']), $search->encode($filter), $orderBy))); $goodsList = $goods->getList('*', $_filter, 0, $limit, $order['sql']); if (!empty($_filter['goods_id'])) { $goods_temp = array(); foreach ($_filter['goods_id'] as $k => $v) { foreach ($goodsList as $row) { if ($v == $row['goods_id']) { $goods_temp[$k] = $row; } } } unset($goodsList); $goodsList = $goods_temp; unset($goods_temp); } if (is_array($goodsList) && $goodsList) { foreach ($goodsList as $key => $value) { $gids[] = $value['goods_id']; $catIds[] = intval($value['cat_id']); } } if ($gids) { if ($catIds) { $catsData = $objgoodscat->getList('cat_id,cat_name', array('cat_id' => $catIds)); foreach ($catsData as $row) { $goodsCats[$row['cat_id']] = $row['cat_name']; } } if ($member_level) { $lv_price_data = $objLvprice->getList('goods_id,price', array('goods_id' => $gids, 'level_id' => $member_level)); foreach ($lv_price_data as $row) { $goodsLvPrice[$row['goods_id']] = $row['price']; } } } if (is_array($goodsList) && $goodsList) { foreach ($goodsList as $pk => $pv) { if (empty($pv['mktprice']) || $pv['mktprice'] == '0') { $pv['mktprice'] = $objProduct->getRealMkt($pv['price']); } $pv['cat_name'] = $goodsCats[$pv['cat_id']]; // add for member price #$lv_price = $objLvprice->getList('price',array('goods_id'=>$pv['goods_id'],'level_id'=>$member_level)); $lv_price[0] = $goodsLvPrice[$pv['goods_id']]; if (isset($dis_count)) { if (is_array($lv_price) && count($lv_price) > 0) { $lv_price = end($lv_price); $pv['memprice'] = $lv_price['price']; } else { $pv['memprice'] = $pv['price'] * $dis_count; } if (intval($pv['price']) != 0) { $pv['dis_count'] = (1 - $pv['memprice'] / $pv['price']) * 100; } else { $pv['dis_count'] = 0; } } else { $pv['dis_count'] = 0; $pv['memprice'] = false; } if (empty($pv['image_default_id'])) { $pv['l_pic'] = base_storager::modifier($imageDefault['L']['default_image']); $pv['m_pic'] = base_storager::modifier($imageDefault['M']['default_image']); $pv['s_pic'] = base_storager::modifier($imageDefault['S']['default_image']); } else { $pv['l_pic'] = base_storager::modifier($pv['image_default_id'], 'l'); $pv['m_pic'] = base_storager::modifier($pv['image_default_id'], 'm'); $pv['s_pic'] = base_storager::modifier($pv['image_default_id'], 's'); } $result['goodsRows'][$pv['goods_id']] = $this->_getOutData($pv); } } if ($gids) { $productData = $objProduct->getList('goods_id,product_id,marketable', array('goods_id' => $gids, 'is_default' => 'true')); foreach ($productData as $k => $val) { $_return['goodsRows'][$val['goods_id']]['products'][] = $val; $result['goodsRows'][$val['goods_id']]['goodsLink'] = $this->getGoodsLink($val['product_id'], $platform); } } return $result; }
function fororder() { $this->_response->set_header('Cache-Control', 'no-store, no-cache'); $fororder_setting = app::get('b2c')->getConf('cart_fororder_setting'); //每个TAB的商品数量 $limit = $fororder_setting['fororder']['nums']; //价格区间 TAB $fororder_filter = $fororder_setting['fororder']['filter']; foreach ($fororder_filter as $tab_key => $tab_value) { if (empty($tab_value['price_min']) || !$tab_value['price_min']) { $new_fororder_tab[$tab_key]['tab_name'] = $tab_value['price_max'] . '元以下'; } elseif (empty($tab_value['price_max']) || $tab_value['price_max'] == 999999) { $new_fororder_tab[$tab_key]['tab_name'] = $tab_value['price_min'] . '元以上'; } else { $new_fororder_tab[$tab_key]['tab_name'] = $tab_value['price_min'] . '-' . $tab_value['price_max'] . '元'; } $new_fororder_tab[$tab_key]['tab_filter'] = $tab_value['price_min'] . '-' . $tab_value['price_max']; } $this->pagedata['fororder_tab'] = $new_fororder_tab; if (isset($_POST['tab_name'])) { $tab_name = $_POST['tab_name']; $view = 'wap/cart/cart_fororder_item.html'; } else { $new_tab_name = current($new_fororder_tab); $tab_name = $new_tab_name['tab_filter']; $view = 'wap/cart/cart_fororder.html'; } //获取商品 if (!cachemgr::get('fororder_goods_data' . $tab_name, $list)) { cachemgr::co_start(); $filter = $this->fororder_filter($tab_name); $goods_model = app::get('b2c')->model('goods'); $aGoods_list = $goods_model->getList("store,spec_desc,goods_id,name,image_default_id,price,nostore_sell", $filter, 0, $limit, 'price asc,last_modify desc'); foreach ($aGoods_list as $goods_key => $goods) { $goodsids[] = $goods['goods_id']; $list[$goods['goods_id']] = $goods; } $products = app::get('b2c')->model('products')->getList('goods_id,product_id,store,freez', array('goods_id' => $goodsids, 'marketable' => 'true', 'is_default' => 'true'), 0, -1, 'price asc'); foreach ((array) $products as $pk => $row) { $goods = $list[$row['goods_id']]; if (($goods['store'] === null || $row['store'] - $row['freez']) > 0 || $goods['nostore_sell']) { $list[$row['goods_id']]['product_id'] = $row['product_id']; } else { unset($list[$row['goods_id']]); } } cachemgr::set('fororder_goods_data' . $tab_name, $list, cachemgr::co_end()); } $i = 1; foreach ($list as $goods_item) { if ($i <= 4) { $aGoods_list_before[] = $goods_item; $i++; } else { $aGoods_list_last[] = $goods_item; $i++; if ($i == 9) { $i = 1; } } } $aGoods_list['before'] = $aGoods_list_before; $aGoods_list['last'] = $aGoods_list_last; $imageDefault = app::get('image')->getConf('image.set'); $this->pagedata['defaultImage'] = $imageDefault['S']['default_image']; $this->pagedata['goods_list'] = $aGoods_list; echo $this->fetch($view); }
function get_goods_cat($result) { $pcat = $this->app->model('goods_cat'); $cat_id = $result['goods']['category']['cat_id']; if (!cachemgr::get('goods_cat' . intval($cat_id), $row)) { cachemgr::co_start(); $row = $pcat->getList("cat_name", array('cat_id' => $result['goods']['category']['cat_id'])); cachemgr::set('goods_cat' . intval($cat_id), $row, cachemgr::co_end()); } return $row[0]['cat_name']; }
private function _merge_vcat_filter($virtual_cat_id, $filter) { $virCatObj = $this->app->model('goods_virtual_cat'); /** 颗粒缓存商品虚拟分类 **/ if (!cachemgr::get('goods_virtual_cat_' . intval($virtual_cat_id), $vcat)) { cachemgr::co_start(); $vcat = $virCatObj->getList('cat_id,cat_path,virtual_cat_id,filter,virtual_cat_name as cat_name', array('virtual_cat_id' => intval($virtual_cat_id))); cachemgr::set('goods_virtual_cat_' . intval($virtual_cat_id), $vcat, cachemgr::co_end()); } $vcat = current($vcat); parse_str($vcat['filter'], $vcatFilters); if ($filter['cat_id'] && $vcatFilters['cat_id']) { unset($vcatFilters['cat_id']); } $filter = array_merge_recursive($filter, $vcatFilters); return $filter; }
public function dispatch($query) { $page_starttime = $this->microtime_float(); $post = $this->_request->get_post(); //post值 $get = $this->_request->get_get(); //get值 $query_info = $this->parse_query($query); //分析query $allow_name = $query_info['allow']; //许可名 $separator = $query_info['separator'] ? $query_info['separator'] : $this->get_separator(); //分隔符 $realquery = $query_info['query']; //真实链接 $page_key = md5($realquery . serialize(ksort($get))); if (!array_key_exists($allow_name, $this->sitemap)) { $this->http_status(404); //404页面 } if (count($post) > 0 || !cachemgr::get($page_key, $page)) { cachemgr::co_start(); $route_value = $this->sitemap[$allow_name]; $service = kernel::service('site_router.' . $route_value[0]); if (is_object($service) && $service->enable()) { $service->dispatch($realquery, $allow_name, $separator); } else { $this->default_dispatch($realquery, $allow_name, $separator); } $page['html'] = join("\n", $this->_response->get_bodys()); if (count($post) == 0 && $this->_response->get_http_response_code() == 200 && $this->has_page_cache_control() === true) { $page_cache = true; $page['raw_headers'] = $this->_response->get_raw_headers(); $page['date'] = date("Y-m-d H:i:s"); $page['queries'] = base_db_connections::$mysql_query_executions; $page['times'] = sprintf('%0.2f', $this->microtime_float() - $page_starttime); $page['etag'] = md5($page['html']); cachemgr::set($page_key, $page, cachemgr::co_end()); } else { $page_cache = false; $page['date'] = date("Y-m-d H:i:s"); $page['queries'] = base_db_connections::$mysql_query_executions; $page['times'] = sprintf('%0.2f', $this->microtime_float() - $page_starttime); } } else { $page_cache = true; $this->_response->clean_headers(); if (isset($page['raw_headers'])) { foreach ($page['raw_headers'] as $raw_header) { $this->_response->set_raw_headers($raw_header); } } } if ($page_cache === true) { $etag = $page['etag'] ? $page['etag'] : md5($page['html']); $this->_response->set_header('Etag', $etag); $matchs = explode(',', $_ENV['HTTP_IF_NONE_MATCH']); foreach ($matchs as $match) { if (trim($match) == $etag) { $this->_response->clean_headers(); $this->_response->set_header('Content-length', '0'); $this->_response->set_http_response_code(304)->send_headers(); exit; } } } $this->_response->send_headers(); echo $page['html']; //only test //echo "\n".'<!-- ' . (($page_cache==true)?'Cached':'No cache') . ' -->'; //echo "\n".'<!-- This page created by ' . $page['date'] . ' -->'; //echo "\n".'<!-- Queries:' . $page['queries'] . ' -->'; //echo "\n".'<!-- Times:' . $page['times'] . 's -->'; }