static function share() { if (!self::$_instance instanceof self) { $plat = getC("SERVER_PLAT"); if ($plat == "SAE") { self::$_instance = new SAE_Memcache(); } else { if ($plat == "BAE") { self::$_instance = new BAE_Memcache(); } else { self::$_instance = new My_Memcache(); } } } return self::$_instance; }
function MC() { return MyCache::share(); }
public function index() { $parent_id = 0; if (isset($this->request->get['parent_id'])) { $parent_id = $this->request->get['parent_id']; } $category_id = 0; if (isset($this->request->get['category_id'])) { $category_id = $this->request->get['category_id']; } if (isset($this->request->get['page'])) { $page = $this->request->get['page']; } else { $page = 1; } $url = ""; if (isset($this->request->get['keyword'])) { $keyword = $this->request->get['keyword']; $url .= '&keyword=' . urlencode(html_entity_decode($this->request->get['keyword'], ENT_QUOTES, 'UTF-8')); } else { $keyword = ''; } $banner_url = ""; $banner_color = ""; switch ($parent_id) { case 201: $banner_url = "images/site/mall/banner_hometown.jpg"; $banner_color = "#ffc593"; break; case 212: $banner_url = "images/site/mall/banner_fengshui.jpg"; $banner_color = "#ffef94"; break; case 222: $banner_url = "images/site/mall/banner_lipin.jpg"; $banner_color = "#ff6969"; break; case 193: $banner_url = "images/site/mall/banner_qingqu.jpg"; $banner_color = "#d094ff"; break; case 63: $banner_url = "images/site/mall/banner_shenghuo.jpg"; $banner_color = "#ceff94"; break; default: $banner_url = "images/site/mall/banner_hometown.jpg"; $banner_color = "#ffc593"; break; } $this->data['banner_url'] = $banner_url; $this->data['banner_color'] = $banner_color; $this->load->model('catalog/category'); $this->data['category'] = $this->model_catalog_category->getCategories($parent_id); $this->data['parent_id'] = $parent_id; $this->data['category_id'] = $category_id; $this->data['keyword'] = $keyword; //dump($this->data['category']); $search_category_id = 0; if ($category_id <= 0) { $search_category_id = $parent_id; } else { $search_category_id = $category_id; } $data = array(); $data['filter_category_id'] = $search_category_id; $data['filter_name'] = $keyword; $data['limit'] = 10; $data['start'] = ($page - 1) * $data['limit']; require_once DIR_SYSTEM . '/cache.class.php'; $pcache = new MyCache(); $products_categoryid_info = $pcache->file2array('pc', $search_category_id); // if (null == $products_categoryid_info) { // echo('11111111111'); $this->load->model('catalog/product'); // $results = $this->model_catalog_category->getCategories(); $products_categoryid_info = $this->model_catalog_product->getProducts($data); $products_total = $this->model_catalog_product->getTotalProducts($data); $pcache->array2file($products_categoryid_info, 'pc', $search_category_id); //} //dump($products_categoryid_info); foreach ($products_categoryid_info as $product_categoryid_info) { if ($product_categoryid_info) { if ($product_categoryid_info['image']) { $image = substr("cache/" . $product_categoryid_info['image'], 0, -4) . "-222x222.jpg"; } else { $image = ''; } if ($product_categoryid_info['price']) { $price = $product_categoryid_info['price']; } else { $price = ''; } $this->data['products_categoryid_info'][] = array('category_product_id' => $search_category_id, 'product_id' => $product_categoryid_info['product_id'], 'thumb' => $image, 'name' => $product_categoryid_info['name'], 'price' => $price, 'href' => $product_categoryid_info['product_id'] . ".html"); } } // dump($this->data['products_categoryid_info']); $pagination = new Pagination(); $pagination->total = $products_total; $pagination->page = $page; $pagination->limit = 10; $pagination->text = $this->language->get('text_pagination'); $pagination->url = $this->url->link("product/sort&parent_id={$parent_id}&category_id={$category_id}{$url}&page={page}"); $this->data['pagination'] = $pagination->render(); //头部 title,keyword description $category_info = $this->model_catalog_category->getCategory($search_category_id); if (!empty($category_info)) { $this->document->setTitle($category_info['name'] . "-CNstorm"); $this->document->setDescription($category_info['meta_description']); $this->document->setKeywords($category_info['meta_keyword']); } else { $this->document->setTitle($keyword . "- CNstorm商品搜索"); $this->document->setDescription($keyword . "- CNstorm商品搜索"); $this->document->setKeywords($keyword . "- CNstorm商品搜索"); } //以下代码定义模版文件路径 if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/sort.tpl')) { $this->template = $this->config->get('config_template') . '/template/product/sort.tpl'; } else { $this->template = 'default/template/product/sort.tpl'; } //以下代码定义头尾文件路径 $this->children = array('common/header_mall', 'common/footer'); $this->response->setOutput($this->render()); }
public function index() { $categoryName = isset($_GET['categoryName']) ? $_GET['categoryName'] : ''; $s_categoryName = isset($_GET['s_categoryName']) ? $_GET['s_categoryName'] : ''; $this->data['categoryName'] = $categoryName; $this->data['s_categoryName'] = $s_categoryName; $this->data['home'] = $this->url->link('common/home'); $this->load->model('catalog/product'); $this->load->model('catalog/category'); $this->load->model('tool/image'); $this->data['products'] = array(); // add by weikun 从数据表中获取所有分类的数据 $this->data['products_categoryid_info'] = array(); $this->data['categoryids'] = array(); $this->data['s_categoryids'] = array(); $results = $this->model_catalog_category->getCategories(); $categoryid_all = array(); foreach ($results as $result) { if ($result) { $categoryid_all[] = $result['category_id']; $s_results = $this->model_catalog_category->getCategories($result['category_id']); if ($s_results) { foreach ($s_results as $s_result) { $this->data['s_categoryids'][] = array('s_category_id' => $s_result['category_id'], 'name' => $s_result['name'], 's_parent_category_id' => $result['category_id'], 'href' => $result['category_id'] . "_" . $s_result['category_id'] . ".html"); } } $this->data['categoryids'][] = array('category_id' => $result['category_id'], 'name' => $result['name']); } } if (isset($this->request->get['filter'])) { $filter = $this->request->get['filter']; } else { $filter = ''; } if (isset($this->request->get['sort'])) { $sort = $this->request->get['sort']; } else { $sort = 'p.sort_order'; } if (isset($this->request->get['order'])) { $order = $this->request->get['order']; } else { $order = 'ASC'; } if (isset($this->request->get['page'])) { $page = $this->request->get['page']; } else { $page = 1; } if (isset($this->request->get['limit'])) { $limit = $this->request->get['limit']; } else { $limit = $this->config->get('config_catalog_limit'); } $category_id = 0; if (isset($this->request->get['path'])) { $url = ''; if (isset($this->request->get['sort'])) { $url .= '&sort=' . $this->request->get['sort']; } if (isset($this->request->get['order'])) { $url .= '&order=' . $this->request->get['order']; } if (isset($this->request->get['limit'])) { $url .= '&limit=' . $this->request->get['limit']; } if (isset($this->request->get['page'])) { $page = $this->request->get['page']; } else { $page = 1; } $path = ''; if (!empty($this->request->get['path'])) { $parts = explode('_', (string) $this->request->get['path']); $small_id = $parts[1]; $category_id = (int) array_pop($parts); $big_id = $parts[0]; $this->data['categoryName'] = $this->model_catalog_category->getSingalBigCategory($big_id); $this->data['s_categoryName'] = $this->model_catalog_category->getSingalSmallCategory($small_id); $this->data['path'] = $big_id . '_' . $big_id; foreach ($parts as $path_id) { if (!$path) { $path = (int) $path_id; } else { $path .= '_' . (int) $path_id; } } } } $category_info = $this->model_catalog_category->getCategory($category_id); // var_dump($category_info); if ($category_info) { $this->document->addScript('catalog/view/javascript/jquery/jquery.total-storage.min.js'); $url = ''; if (isset($this->request->get['sort'])) { $url .= '&sort=' . $this->request->get['sort']; } if (isset($this->request->get['order'])) { $url .= '&order=' . $this->request->get['order']; } if (isset($this->request->get['page'])) { $url .= '&page=' . $this->request->get['page']; } if (isset($this->request->get['limit'])) { $url .= '&limit=' . $this->request->get['limit']; } if ($category_info['image']) { $this->data['thumb'] = $this->model_tool_image->resize($category_info['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height')); } else { $this->data['thumb'] = ''; } $this->data['description'] = html_entity_decode($category_info['description'], ENT_QUOTES, 'UTF-8'); $this->data['compare'] = $this->url->link('product/compare'); $url = ''; if (isset($this->request->get['filter'])) { $url .= '&filter=' . $this->request->get['filter']; } if (isset($this->request->get['sort'])) { $url .= '&sort=' . $this->request->get['sort']; } if (isset($this->request->get['order'])) { $url .= '&order=' . $this->request->get['order']; } if (isset($this->request->get['limit'])) { $url .= '&limit=' . $this->request->get['limit']; } $this->data['categories'] = array(); $results = $this->model_catalog_category->getCategories($category_id); // var_dump($results); foreach ($results as $result) { $data = array('filter_category_id' => $result['category_id'], 'filter_sub_category' => true); // var_dump($data); $product_total = $this->model_catalog_product->getTotalProducts($data); // var_dump($product_total); // var_dump($this->config->get('config_product_count')); // var_dump($this->data['categories']); $this->data['categories'][] = array('name' => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''), 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)); } $this->data['products'] = array(); $sort = isset($_GET['sort']) ? $_GET['sort'] : ''; if ($sort == 'viewed') { $sort = 'p.viewed'; $this->data['sort_id'] = isset($_GET['sort_id']) ? $_GET['sort_id'] : ''; $this->data['sort_id'] = $this->data['sort_id'] == 'ASC' ? 'DESC' : 'ASC'; $order = $this->data['sort_id']; $this->data['sort_name'] = 1; $this->data['sort_age'] = 1; } if ($sort == 'date_modified') { $sort = 'p.date_modified'; $this->data['sort_name'] = isset($_GET['sort_name']) ? $_GET['sort_name'] : ''; $this->data['sort_name'] = $this->data['sort_name'] == 'ASC' ? 'DESC' : 'ASC'; $order = $this->data['sort_name']; $this->data['sort_id'] = 1; $this->data['sort_age'] = 1; } if ($sort == 'price') { $sort = 'p.price'; $this->data['sort_age'] = isset($_GET['sort_age']) ? $_GET['sort_age'] : ''; $this->data['sort_age'] = $this->data['sort_age'] == 'ASC' ? 'DESC' : 'ASC'; $order = $this->data['sort_age']; $this->data['sort_id'] = 1; $this->data['sort_name'] = 1; } if ($sort == '') { $sort = 'p.sort_order'; $order = null; $this->data['sort_id'] = 1; $this->data['sort_name'] = 1; $this->data['sort_age'] = 1; } $data = array('filter_category_id' => $category_id, 'sort' => $sort, 'order' => $order, 'start' => ($page - 1) * $limit, 'limit' => $limit); //将查询结果集放到文件中,失效时间未过时从文件中读取 //add by fc $fn = ''; $f = isset($this->request->get['path']) ? $this->request->get['path'] : '0_0'; $b = isset($this->request->get['page']) ? $this->request->get['page'] : '1'; $fn = $f . '_' . $b; require_once DIR_SYSTEM . '/cache.class.php'; $cache = new MyCache(); $results = $cache->file2array('productcache', $fn); if (null == $results) { // echo('11111111111'); $results = $this->model_catalog_product->getProducts($data); $cache->array2file($results, 'productcache', $fn); } $product_total = $this->model_catalog_product->getTotalProducts($data); // var_dump($product_total); $this->data['product_total'] = $product_total; // var_dump($results); if ($results) { foreach ($results as $result) { // var_dump($result);exit(); if ($result['image']) { $image = "image/" . $result['image']; } else { $image = false; } if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) { // $price = $this->currency->format($result['price']); $price = $result['price']; } else { $price = false; } $this->data['products'][] = array('viewed' => $result['viewed'], 'date_added' => $result['date_added'], 'product_id' => $result['product_id'], 'thumb' => $image, 'name' => $result['name'], 'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..', 'price' => $price, 'href' => $this->request->get['path'] . ".html&product_id=" . $result['product_id'] . $url); } /* * $sort= isset ( $_GET ['sort'] ) ? $_GET ['sort'] : ''; if ($sort== 'id') { $this->data['sort_id'] = isset ( $_GET ['sort_id'] ) ? $_GET ['sort_id'] : ''; $this->data['sort_id'] = $this->data['sort_id'] == SORT_ASC ? SORT_DESC : SORT_ASC; $sort_id = $this->data['sort_id']; $this->data['sort_name'] = 1; $this->data['sort_age'] = 1; $this->data['products'] = $this->multi_array_sort ( $this->data['products'], 'viewed', $sort_id ); } if ($sort== 'name') { $this->data['sort_name'] = isset ( $_GET ['sort_name'] ) ? $_GET ['sort_name'] : ''; $this->data['sort_name'] = $this->data['sort_name'] == SORT_ASC ? SORT_DESC : SORT_ASC; $sort_name = $this->data['sort_name']; $this->data['sort_id'] = 1; $this->data['sort_age'] = 1; $this->data['products'] = $this->multi_array_sort ( $this->data['products'], 'date_added', $sort_name ); } if ($sort== 'age') { $this->data['sort_age'] = isset ( $_GET ['sort_age'] ) ? $_GET ['sort_age'] : ''; $this->data['sort_age'] = $this->data['sort_age'] == SORT_ASC ? SORT_DESC : SORT_ASC; $sort_age = $this->data['sort_age']; $this->data['sort_id'] = 1; $this->data['sort_name'] = 1; $this->data['products'] = $this->multi_array_sort ( $this->data['products'], 'price', $sort_age ); } if ($sort== '') { $this->data['sort_id'] = 1; $this->data['sort_name'] = 1; $this->data['sort_age'] = 1; } */ $pagination = new Pagination(); $pagination->total = $product_total; $pagination->page = $page; $pagination->limit = $limit; $pagination->text = $this->language->get('text_pagination'); // $pagination->url = $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&page={page}'); $pagination->url = $this->request->get['path'] . '.html&page={page}' . $url; $this->data['urlNew'] = $this->request->get['path'] . ".html"; $this->data['pagination'] = $pagination->render(); // var_dump($pagination); $this->data['url'] = $pagination->url; $this->data['page'] = $page; $total = $pagination->total; $limit = $pagination->limit; if ($total % $limit) { $pagenum = $total % $limit + 1; } else { $pagenum = $total / $limit; } $this->data['pagenum'] = $pagenum; if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/types.tpl')) { $this->template = $this->config->get('config_template') . '/template/product/types.tpl'; } else { $this->template = 'default/template/product/types.tpl'; } $this->children = array('common/footer', 'common/header'); $this->response->setOutput($this->render()); } else { $this->data['name'] = $category_info['name']; $this->response->addHeader($this->request->server['SERVER_PROTOCOL'] . '/1.1 404 Not Found'); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/search_no_results.tpl')) { $this->template = $this->config->get('config_template') . '/template/error/search_no_results.tpl'; } else { $this->template = 'default/template/error/search_no_results.tpl'; } $this->children = array('common/footer', 'common/header'); $this->response->setOutput($this->render()); } } else { $this->session->data['redirect'] = $this->url->link('product/favorite', '', 'SSL'); $this->redirect($this->url->link('product/favorite', '', 'SSL')); } }
public function index() { $this->data['login'] = $this->url->link('account/login'); $this->data['home'] = $this->url->link('common/home'); $this->load->model('catalog/product'); //轮播图 $this->data['lunbopics'] = $this->model_catalog_product->getLunboPics(); //小C推荐 $this->data['xiaoc'] = $this->model_catalog_product->getLunboPics(2); //大家最爱 $this->data['zuiai'] = $this->model_catalog_product->getLunboPics(2, 0); $this->load->model('catalog/category'); $this->load->model('tool/image'); $this->data['products'] = array(); //add by weikun 从数据表中获取所有分类的数据 $this->data['products_categoryid_info'] = array(); $this->data['categoryids'] = array(); $this->data['s_categoryids'] = array(); $results = $this->model_catalog_category->getCategories(); $categoryid_all = array(); foreach ($results as $result) { if ($result) { $categoryid_all[] = $result['category_id']; $s_results = $this->model_catalog_category->getCategories($result['category_id']); if ($s_results) { foreach ($s_results as $s_result) { $this->data['s_categoryids'][] = array('s_category_id' => $s_result['category_id'], 'name' => $s_result['name'], 's_parent_category_id' => $result['category_id'], 'href' => $result['category_id'] . "_" . $s_result['category_id'] . ".html"); } } $this->data['categoryids'][] = array('category_id' => $result['category_id'], 'name' => $result['name']); } } //var_dump($this->data['s_categoryids']); //var_dump($this->data['categoryids']); //add by weikun 以商品分类ID从数据库中获取相应的6条数据显示 foreach ($categoryid_all as $categoryid_all_info) { $data = array(); $data['filter_category_id'] = $categoryid_all_info; $data['start'] = 0; $data['limit'] = 10; require_once DIR_SYSTEM . '/cache.class.php'; $pcache = new MyCache(); $products_categoryid_info = $pcache->file2array('pc', $categoryid_all_info); if (null == $products_categoryid_info) { // echo('11111111111'); // $results = $this->model_catalog_category->getCategories(); $products_categoryid_info = $this->model_catalog_product->getProducts($data); $pcache->array2file($products_categoryid_info, 'pc', $categoryid_all_info); } //var_dump($products_categoryid_info); foreach ($products_categoryid_info as $product_categoryid_info) { if ($product_categoryid_info) { if ($product_categoryid_info['image']) { $image = $product_categoryid_info['image']; } else { $image = ''; } if ($product_categoryid_info['price']) { $price = $product_categoryid_info['price']; } else { $price = ''; } $this->data['products_categoryid_info'][] = array('category_product_id' => $categoryid_all_info, 'product_id' => $product_categoryid_info['product_id'], 'thumb' => $image, 'name' => $product_categoryid_info['name'], 'price' => $price, 'href' => $product_categoryid_info['product_id'] . ".html"); } } } if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/favorite.tpl')) { $this->template = $this->config->get('config_template') . '/template/product/favorite.tpl'; } else { $this->template = 'default/template/product/favorite.tpl'; } $this->children = array('common/footer', 'common/header'); $this->response->setOutput($this->render()); }