public function get($f3) { global $smarty; // 首先做参数合法性验证 $validator = new Validator($f3->get('GET')); $goods_id = $validator->required('商品id不能为空')->digits('商品id非法')->min(1, true, '商品id非法')->validate('goods_id'); if (!$this->validate($validator)) { goto out_fail; } // 生成 smarty 的缓存 id $smartyCacheId = 'Goods|' . $goods_id . '|View'; // 开启并设置 smarty 缓存时间 enableSmartyCache(true, MobileThemePlugin::getOptionValue('smarty_cache_time_goods_view')); // 缓存页面 if ($smarty->isCached('goods_view.tpl', $smartyCacheId)) { goto out_display; } // 查询商品信息 $goodsBasicService = new GoodsBasicService(); $goodsInfo = $goodsBasicService->loadGoodsById($goods_id); // 商品不存在,退出 if ($goodsInfo->isEmpty() || !Utils::isTagExist(PluginHelper::SYSTEM_MOBILE, $goodsInfo['system_tag_list'])) { $this->addFlashMessage('商品 [' . $goods_id . '] 不存在'); goto out_fail; } // 取商品推广信息设置 $goodsPromote = $goodsBasicService->loadGoodsPromoteByGoodsId($goods_id); // 取商品图片集 $goodsGalleryArray = GoodsGalleryCache::getGoodsGallery($goods_id); foreach ($goodsGalleryArray as &$galleryItem) { $galleryItem['img_url'] = RouteHelper::makeImageUrl($galleryItem['img_url']); $galleryItem['thumb_url'] = RouteHelper::makeImageUrl($galleryItem['thumb_url']); } unset($galleryItem); // 设置商品页面的 SEO 信息 $smarty->assign('seo_title', $goodsInfo['seo_title'] . ',' . $f3->get('sysConfig[site_name]')); $smarty->assign('seo_description', $goodsInfo['seo_description']); $smarty->assign('seo_keywords', $goodsInfo['seo_keyword']); // 给模板赋值 $smarty->assign('goodsInfo', $goodsInfo); $smarty->assign('goodsPromote', $goodsPromote); if (!Utils::isEmpty($goodsGalleryArray)) { $smarty->assign('goodsGalleryArray', $goodsGalleryArray); } // 设置商品规格 if (!empty($goodsInfo['goods_spec'])) { $goodsSpecService = new GoodsSpecService(); $goodsSpecService->initWithJson($goodsInfo['goods_spec']); $smarty->assign('goodsSpec', $goodsSpecService->getGoodsSpecDataArray()); } out_display: $smarty->display('goods_view.tpl', $smartyCacheId); return; out_fail: // 失败从这里返回 RouteHelper::reRoute($this, '/'); // 返回首页 }
public function get($f3) { global $smarty; $smartyCacheId = 'EtaoFeed|' . md5(__NAMESPACE__ . '\\' . __CLASS__ . '_\\' . __METHOD__); // 判断是否有缓存 enableSmartyCache(true, 1200); // 缓存 20 分钟 if ($smarty->isCached('empty.tpl', $smartyCacheId)) { goto out_display; } $currentStamp = Time::localTimeStr(); $sellerId = EtaoFeedPlugin::getOptionValue('etaofeed_seller_id'); $categoryUrl = RouteHelper::makeUrl('/Thirdpart/EtaoFeed/Category', null, false, true); $itemDir = RouteHelper::makeUrl('/Thirdpart/EtaoFeed/Item', null, false, true); $itemIdXmlList = ''; // 处理 delete 的商品 $currentThemeInstance = ThemeHelper::getCurrentSystemThemeInstance(); $totalGoodsCount = SearchHelper::count(SearchHelper::Module_Goods, array(array('is_on_sale = 0'), array('update_time', '>=', EtaoFeedPlugin::getOptionValue('etaofeed_query_timestamp')), array(QueryBuilder::buildGoodsFilterForSystem($currentThemeInstance->getGoodsFilterSystemArray())))); if ($totalGoodsCount <= 0) { goto query_update_goods; } $totalPageCount = ceil($totalGoodsCount / Item::$pageSize); for ($index = 0; $index < $totalPageCount; $index++) { $itemIdXmlList .= '<outer_id action="delete">1' . $index . '</outer_id>'; } query_update_goods: // 处理修改过的商品 $totalGoodsCount = SearchHelper::count(SearchHelper::Module_Goods, array(array('is_on_sale = 1'), array('update_time', '>=', EtaoFeedPlugin::getOptionValue('etaofeed_query_timestamp')), array(QueryBuilder::buildGoodsFilterForSystem($currentThemeInstance->getGoodsFilterSystemArray())))); if ($totalGoodsCount <= 0) { goto out_output; } $totalPageCount = ceil($totalGoodsCount / Item::$pageSize); for ($index = 0; $index < $totalPageCount; $index++) { $itemIdXmlList .= '<outer_id action="upload">2' . $index . '</outer_id>'; } out_output: $apiXml = <<<XML <?xml version="1.0" encoding="utf-8" ?> <root> <version>1.0</version> <modified>{$currentStamp}</modified> <seller_id>{$sellerId}</seller_id> <cat_url>{$categoryUrl}</cat_url> <dir>{$itemDir}/</dir> <item_ids>{$itemIdXmlList}</item_ids> </root> XML; $smarty->assign('outputContent', $apiXml); // 更新查询时间 //EtaoFeedPlugin::saveOptionValue('etaofeed_query_timestamp', Time::gmTime()); out_display: header('Content-Type:text/xml;charset=utf-8'); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 //查询信息 $smarty->display('empty.tpl', $smartyCacheId); }
public function get($f3) { global $smarty; // 生成 smarty 的缓存 id $smartyCacheId = 'My|Account|get'; enableSmartyCache(true, 3600); // 缓存 1 小时 if ($smarty->isCached('my_account.tpl', $smartyCacheId)) { goto out_display; } out_display: $smarty->display('my_account.tpl', $smartyCacheId); }
public function get($f3) { global $smarty; // 生成 smarty 的缓存 id $smartyCacheId = 'Cache|Page'; enableSmartyCache(true, MobileThemePlugin::getOptionValue('smarty_cache_time_cache_page')); // 缓存页面 if ($smarty->isCached('cache_page.tpl', $smartyCacheId)) { goto out_display; } out_display: $smarty->display('cache_page.tpl', $smartyCacheId); }
public function get($f3) { global $smarty; // 生成 smarty 的缓存 id $smartyCacheId = 'User|Login|get'; enableSmartyCache(true, 3600); // 缓存 1 小时 if ($smarty->isCached('user_login.tpl', $smartyCacheId)) { goto out_display; } out_display: $smarty->display('user_login.tpl', $smartyCacheId); }
public function get($f3) { global $smarty; // 生成 smarty 的缓存 id $smartyCacheId = 'User|Login|get'; enableSmartyCache(true, 3600); // 缓存 1 小时 if ($smarty->isCached('user_login.tpl', $smartyCacheId)) { goto out_display; } out_display: $smarty->assign('captchaUrl', RouteHelper::makeUrl('/Image/Captcha', array('hash' => time(), session_name() => session_id()))); $smarty->display('user_login.tpl', $smartyCacheId); }
public function get($f3) { global $smarty; // 解析传入的 fileName, 文件名的格式应该是 /1.xml,最后的数字为页号 $fileName = $f3->get('PARAMS.fileName'); $smartyCacheId = 'EtaoFeed|' . md5(__NAMESPACE__ . '\\' . __CLASS__ . '_\\' . __METHOD__ . '\\' . $fileName); // 判断是否有缓存 enableSmartyCache(true, 1200); // 缓存 20 分钟 if ($smarty->isCached('empty.tpl', $smartyCacheId)) { goto out_display; } // 文件一般为 00.xml 10.xml 20.xml // 第一个数字 0: upload, 1: delete , 2: update //去掉文件扩展名 $extPos = strrpos($fileName, '.'); if ($extPos) { $fileName = substr($fileName, 0, $extPos); } // 解析文件名 $itemType = intval($fileName[0]); $pageNo = intval(substr($fileName, 1)); // 根据调用类型查询商品 $goodsArray = array(); switch ($itemType) { case 0: $goodsArray = $this->queryUploadGoods($pageNo); break; case 1: $goodsArray = $this->queryDeleteGoods($pageNo); break; case 2: $goodsArray = $this->queryUpdateGoods($pageNo); break; default: break; } $apiXml = $this->getGoodsArrayXml($goodsArray); $smarty->assign('outputContent', $apiXml); out_display: header('Content-Type:text/xml;charset=utf-8'); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 //查询信息 $smarty->display('empty.tpl', $smartyCacheId); }
public function get($f3) { global $smarty; // 生成 smarty 的缓存 id $smartyCacheId = 'Ajax|Category'; // 开启并设置 smarty 缓存时间 enableSmartyCache(true, bzf_get_option_value('smarty_cache_time_ajax_category')); if ($smarty->isCached('ajax_category.tpl', $smartyCacheId)) { goto out_display; } // 取得商品分类树形结构 $goodsCategoryService = new GoodsCategoryService(); $goodsCategoryTreeArray = $goodsCategoryService->fetchCategoryTreeArray(0); $smarty->assign('goodsCategoryTreeArray', $goodsCategoryTreeArray); out_display: $f3->expire(600); // 让客户端缓存 10 分钟 $smarty->display('ajax_category.tpl', $smartyCacheId); }
/** * 列出在线客服 * * @param $f3 */ public function ListKefuIdName($f3) { global $smarty; // 检查缓存 $smartyCacheId = 'Ajax|' . md5(__NAMESPACE__ . '\\' . __CLASS__ . '\\' . __METHOD__); enableSmartyCache(true, 600); // 缓存 10 分钟 // 判断是否有缓存 if ($smarty->isCached('empty.tpl', $smartyCacheId)) { goto out_display; } $baseService = new BaseService(); $adminArray = $baseService->_fetchArray('admin_user', 'user_id,user_name', array(array('disable = 0'), array('is_kefu = 1')), array('order' => 'user_id desc'), 0, 0, 0); $smarty->assign('outputContent', Ajax::buildResult(null, null, $adminArray)); out_display: $f3->expire(600); // 客户端缓存 10 分钟 Ajax::header(); $smarty->display('empty.tpl', $smartyCacheId); }
public function get($f3) { global $smarty; $cacheTime = 300; // 缓存5分钟 enableSmartyCache(true, $cacheTime); $smartyCacheId = 'Api|' . md5(__NAMESPACE__ . '\\' . __CLASS__ . '\\' . __METHOD__); // 判断是否有缓存 if ($smarty->isCached('empty.tpl', $smartyCacheId)) { goto out_display; } // 查询商品 $currentThemeInstance = ThemeHelper::getCurrentSystemThemeInstance(); $condArray = array(array(QueryBuilder::buildGoodsFilterForSystem($currentThemeInstance->getGoodsFilterSystemArray()))); $apiGoodsService = new ApiGoodsService(); $goodsGalleryPromoteArray = $apiGoodsService->fetchGoodsGalleryPromote($condArray, 'aimeidaren_sort_order desc, sort_order desc, goods_id desc', 0, 0, $cacheTime); // 商品和图片 $goodsArray = $goodsGalleryPromoteArray['goods']; $goodsIdToGalleryArray = $goodsGalleryPromoteArray['goodsIdToGalleryArray']; $xmlItems = ''; $goodsArrayCount = count($goodsArray); for ($index = 0; $index < $goodsArrayCount; $index++) { $xmlItems .= $this->getGoodsItemXml($index + 1, $goodsArray[$index], $goodsIdToGalleryArray); } $apiXml = <<<XML <?xml version="1.0" encoding="utf-8" ?> <urlset> \t{$xmlItems} </urlset> XML; unset($xmlItems); $smarty->assign('outputContent', $apiXml); out_display: header('Content-Type:text/xml;charset=utf-8'); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 //查询信息 $smarty->display('empty.tpl', $smartyCacheId); }
public function get($f3) { global $smarty; // 生成 smarty 的缓存 id $smartyCacheId = 'Shop|Index'; // 开启并设置 smarty 缓存时间 enableSmartyCache(true, bzf_get_option_value('smarty_cache_time_shop_index')); if ($smarty->isCached('shop_index.tpl', $smartyCacheId)) { goto out_display; } // 滑动图片广告 $shop_index_adv_slider = json_decode(bzf_get_option_value('shop_index_adv_slider'), true); if (!empty($shop_index_adv_slider)) { $smarty->assign('shop_index_adv_slider', $shop_index_adv_slider); } // 今日新品 $recommandGoodsArray = SearchHelper::search(SearchHelper::Module_Goods, $this->searchFieldSelector, $this->searchExtraCondArray, array(array('goods_id', 'desc')), 0, 40); if (!empty($recommandGoodsArray)) { $smarty->assign('recommandGoodsArray', $recommandGoodsArray); } // 广告 advBlock $shop_index_advblock_json_data = json_decode(bzf_get_option_value('shop_index_advblock_json_data'), true); if (!empty($shop_index_advblock_json_data)) { // 生成随机的 id 号给 html 使用 foreach ($shop_index_advblock_json_data as &$advBlockObject) { $advBlockObject['id'] = Utils::generateRandomHtmlId(); foreach ($advBlockObject['advBlockImageArray'] as &$advBlockImage) { $advBlockImage['id'] = Utils::generateRandomHtmlId(); } } $smarty->assign('shop_index_advblock_json_data', $shop_index_advblock_json_data); } // 移动端对应的 URL,用于百度页面适配 $smarty->assign('currentPageMobileUrl', RouteHelper::makeShopSystemUrl(PluginHelper::SYSTEM_MOBILE, '/')); out_display: $smarty->assign('seo_title', $smarty->getTemplateVars('seo_title') . ',' . $f3->get('HOST')); $smarty->display('shop_index.tpl', $smartyCacheId); }
public function get($f3) { global $smarty; // 首先做参数合法性验证 $validator = new Validator($f3->get('GET')); $article_id = $validator->required('文章id不能为空')->digits('文章id非法')->min(1, true, '文章id非法')->validate('article_id'); if (!$this->validate($validator)) { goto out_fail; } // 生成 smarty 的缓存 id $smartyCacheId = 'Article|' . $article_id . '|View'; // 开启并设置 smarty 缓存时间 enableSmartyCache(true, bzf_get_option_value('smarty_cache_time_article_view')); if ($smarty->isCached('article_view.tpl', $smartyCacheId)) { goto out_display; } // 查询文章信息 $articleService = new ArticleBasicService(); $articleInfo = $articleService->loadArticleById($article_id); // 文章不存在,退出 if ($articleInfo->isEmpty() || !$articleInfo->is_open) { $this->addFlashMessage('文章 [' . $article_id . '] 不存在'); goto out_fail; } // 设置文章页面的 SEO 信息 $smarty->assign('seo_title', $articleInfo['title'] . ',' . $f3->get('sysConfig[site_name]')); $smarty->assign('seo_description', $articleInfo['description']); $smarty->assign('seo_keywords', $articleInfo['seo_keyword']); // 给模板赋值 $smarty->assign('articleInfo', $articleInfo); out_display: $smarty->display('article_view.tpl', $smartyCacheId); return; out_fail: // 失败从这里返回 RouteHelper::reRoute($this, '/'); // 返回首页 }
public function get($f3) { global $smarty; $smartyCacheId = 'EtaoFeed|' . md5(__NAMESPACE__ . '\\' . __CLASS__ . '_\\' . __METHOD__); // 判断是否有缓存 enableSmartyCache(true, 1800); // 缓存 30 分钟 if ($smarty->isCached('empty.tpl', $smartyCacheId)) { goto out_display; } // 取得商品分类树形结构 $goodsCategoryService = new GoodsCategoryService(); $goodsCategoryTreeArray = $goodsCategoryService->fetchCategoryTreeArray(0); $currentStamp = Time::localTimeStr(); $sellerId = EtaoFeedPlugin::getOptionValue('etaofeed_seller_id'); // 生成商品分类 XML $categoryXmlList = ''; foreach ($goodsCategoryTreeArray as $goodsCategoryItem) { $categoryXmlList .= $this->getGoodsCategoryXml($goodsCategoryItem); } $apiXml = <<<XML <?xml version="1.0" encoding="utf-8" ?> <root> <version>1.0</version> <modified>{$currentStamp}</modified> <seller_id>{$sellerId}</seller_id> <seller_cats>{$categoryXmlList}</seller_cats> </root> XML; $smarty->assign('outputContent', $apiXml); out_display: header('Content-Type:text/xml;charset=utf-8'); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 //查询信息 $smarty->display('empty.tpl', $smartyCacheId); }
public function get($f3) { global $smarty; // 参数验证 $validator = new Validator($_GET); $cid = $validator->required()->validate('cid'); $queryCreateDate = $validator->digits()->validate('d'); $queryUpdateDate = $validator->digits()->validate('ud'); // 参数有错误 if (!$this->validate($validator)) { goto out_fail; } // 不能同时为空 if (empty($queryCreateDate) && empty($queryUpdateDate)) { goto out_fail; } if (!empty($queryCreateDate)) { // 参数检查,格式只能为 20120304 或者 2012030410 $dateStrLen = strlen($queryCreateDate); if (8 != $dateStrLen && 10 != $dateStrLen) { goto out_fail; } } if (!empty($queryUpdateDate)) { // 参数检查,格式只能为 20120304 或者 2012030410 $dateStrLen = strlen($queryUpdateDate); if (8 != $dateStrLen && 10 != $dateStrLen) { goto out_fail; } } enableSmartyCache(true, 60); //缓存1分钟,防止访问很频繁从而变成对网站的攻击 $smartyCacheId = 'YiqifaCps|' . md5(json_encode(QueryOrder::$extraQueryCond) . '_' . $cid . '_' . $queryCreateDate . '_' . $queryUpdateDate); // 判断是否有缓存 if ($smarty->isCached('yiqifacps_empty.tpl', $smartyCacheId)) { goto out_display; } $txtOutput = ''; // 构造查询条件 $condArray = array(); $condArray[] = array('orf.utm_source = ? or (orf.login_type = ? and orf.utm_source is null)', 'YIQIFACPS', 'qqlogin'); // add_time 查询 if (!empty($queryCreateDate)) { $startTime = 0; $endTime = 0; if (strlen($queryCreateDate) == 8) { $startTime = strtotime($queryCreateDate); $endTime = $startTime + 24 * 60 * 60; } if (strlen($queryCreateDate) == 10) { $datePart = substr($queryCreateDate, 0, 8); $hourPart = substr($queryCreateDate, 8, 2); $startTime = strtotime($datePart . " " . $hourPart . ":00:00"); $endTime = $startTime + 60 * 60; } $condArray[] = array('oi.add_time >= ? and oi.add_time < ?', $startTime, $endTime); } // update_time 查询 if (!empty($queryUpdateDate)) { $startTime = 0; $endTime = 0; if (strlen($queryUpdateDate) == 8) { $startTime = strtotime($queryUpdateDate); $endTime = $startTime + 24 * 60 * 60; } if (strlen($queryUpdateDate) == 10) { $datePart = substr($queryUpdateDate, 0, 8); $hourPart = substr($queryUpdateDate, 8, 2); $startTime = strtotime($datePart . " " . $hourPart . ":00:00"); $endTime = $startTime + 60 * 60; } $condArray[] = array('oi.update_time >= ? and oi.update_time < ?', $startTime, $endTime); } /** * 加入额外的查询条件 */ if (!empty(QueryOrder::$extraQueryCond)) { $condArray[] = QueryOrder::$extraQueryCond; } // 查询订单,每次最多 2000 条数据,防止拖死系统 $orderReferService = new OrderReferService(); $orderReferInfoArray = $orderReferService->fetchOrderReferInfo($condArray, array('order' => 'oi.order_id asc'), 0, 2000); // 过滤 cid,只留下需要查询的 cid 数据,同时收集 order_id 用于查询 order_goods 信息 $cidOrderReferInfoArray = array(); $orderIdArray = array(); foreach ($orderReferInfoArray as $orderReferInfoItem) { $referParamArray = json_decode($orderReferInfoItem['refer_param'], true); if (!empty($referParamArray['cid']) && $referParamArray['cid'] != $cid) { //不是要查询的订单,跳过 continue; // ==== 为了测试临时注释的代码 } $cidOrderReferInfoArray[] = $orderReferInfoItem; $orderIdArray[] = $orderReferInfoItem['order_id']; } unset($orderReferInfoArray); //清除旧数据 $orderReferInfoArray = $cidOrderReferInfoArray; unset($cidOrderReferInfoArray); //清除临时数据 if (empty($orderReferInfoArray)) { // 没有数据,跳出 goto out; } $orderGoodsArray = $orderReferService->_fetchArray('order_goods', '*', array(array(QueryBuilder::buildInCondition('order_id', $orderIdArray))), array('order' => 'order_id asc, rec_id asc'), 0, 10000); //最多查询 10000 条记录,防止拖死系统 // 建立 order_id --> array( order_goods ) 的反查表 $orderIdToOrderGoodsArray = array(); foreach ($orderGoodsArray as $orderGoodsItem) { if (!isset($orderIdToOrderGoodsArray[$orderGoodsItem['order_id']])) { $orderIdToOrderGoodsArray[$orderGoodsItem['order_id']] = array(); } $orderIdToOrderGoodsArray[$orderGoodsItem['order_id']][] = $orderGoodsItem; } // 根据订单构建 CPS 返回记录 foreach ($orderReferInfoArray as $orderReferItem) { if (isset($orderIdToOrderGoodsArray[$orderReferItem['order_id']])) { $txtOutput .= $this->getOrderTxt($orderReferItem, $orderIdToOrderGoodsArray[$orderReferItem['order_id']]); } } out: $smarty->assign('outputContent', $txtOutput); out_display: //成功从这里返回 header('Content-Type:text/plain;charset=utf-8'); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 //查询信息 $smarty->display('yiqifacps_empty.tpl', $smartyCacheId); return; out_fail: // 失败从这里返回 echo "paramters error"; }
public function get($f3) { global $smarty; // 首先做参数合法性验证 $validator = new Validator($f3->get('GET')); $goods_id = $validator->required('商品id不能为空')->digits('商品id非法')->min(1, true, '商品id非法')->validate('goods_id'); if (!$this->validate($validator)) { goto out_fail; } // 生成 smarty 的缓存 id $smartyCacheId = 'Goods|' . $goods_id . '|View'; // 开启并设置 smarty 缓存时间 enableSmartyCache(true, bzf_get_option_value('smarty_cache_time_goods_view')); if ($smarty->isCached('goods_view.tpl', $smartyCacheId)) { goto out_display; } // 查询商品信息 $goodsBasicService = new GoodsBasicService(); $goodsInfo = $goodsBasicService->loadGoodsById($goods_id); // 商品不存在,退出 if ($goodsInfo->isEmpty() || !Utils::isTagExist(PluginHelper::SYSTEM_SHOP, $goodsInfo['system_tag_list'])) { $this->addFlashMessage('商品 [' . $goods_id . '] 不存在'); goto out_fail; } // 取得商品的分类层级 $goodsCategoryLevelArray = array(); $goodsCategoryService = new GoodsCategoryService(); $categoryLevel = 5; // 最多取 5 层分类 $currentCategoryId = $goodsInfo['cat_id']; for (; $categoryLevel > 0; $categoryLevel--) { $category = $goodsCategoryService->loadCategoryById($currentCategoryId, 1800); if ($category->isEmpty()) { break; } array_unshift($goodsCategoryLevelArray, $category); if ($category['parent_meta_id'] <= 0) { break; } $currentCategoryId = $category['parent_meta_id']; } // 取商品推广信息设置 $goodsPromote = $goodsBasicService->loadGoodsPromoteByGoodsId($goods_id); // 取商品图片集 $goodsGalleryArray = GoodsGalleryCache::getGoodsGallery($goods_id); foreach ($goodsGalleryArray as &$galleryItem) { $galleryItem['img_original'] = RouteHelper::makeImageUrl($galleryItem['img_original']); $galleryItem['img_url'] = RouteHelper::makeImageUrl($galleryItem['img_url']); $galleryItem['thumb_url'] = RouteHelper::makeImageUrl($galleryItem['thumb_url']); } unset($galleryItem); // 取相互关联的商品 $linkGoodsArray = $goodsBasicService->fetchLinkGoodsArray($goods_id); // 相同供货商的商品,一起购买只收一份邮费 $goodsSupplierService = new GoodsSupplierService(); // 取得供货商下面的商品总数,总数只缓存 10 分钟 $supplierTotalGoodsCount = $goodsSupplierService->countSupplierGoodsArray($goodsInfo['suppliers_id'], 600); // 随机挑选 10 个商品 $supplierGoodsSize = 10; $supplierGoodsOffset = $supplierTotalGoodsCount <= $supplierGoodsSize ? 0 : mt_rand(0, $supplierTotalGoodsCount - $supplierGoodsSize); $supplierGoodsArray = $goodsSupplierService->fetchSupplierGoodsArray($goodsInfo['suppliers_id'], $supplierGoodsOffset, $supplierGoodsSize); // 把自己去除掉 $supplierGoodsKeyExcludeArray = array(); foreach ($supplierGoodsArray as $supplierGoodsKey => $supplierGoodsItem) { if ($supplierGoodsItem['goods_id'] == $goods_id) { $supplierGoodsKeyExcludeArray[] = $supplierGoodsKey; } } foreach ($supplierGoodsKeyExcludeArray as $supplierGoodsKey) { unset($supplierGoodsArray[$supplierGoodsKey]); } // 设置商品页面的 SEO 信息 $smarty->assign('seo_title', $goodsInfo['seo_title'] . ',' . $f3->get('sysConfig[site_name]')); $smarty->assign('seo_description', $goodsInfo['seo_description']); $smarty->assign('seo_keywords', $goodsInfo['seo_keyword']); // 给模板赋值 $smarty->assign('goodsInfo', $goodsInfo); $smarty->assign('goodsPromote', $goodsPromote); // 商品购买选择的规格 if (!empty($goodsInfo['goods_spec'])) { $goodsSpecService = new GoodsSpecService(); $goodsSpecService->initWithJson($goodsInfo['goods_spec']); // 只显示有库存的商品规格 $goodsSpecData = $goodsSpecService->getBuyableData(); $smarty->assign($goodsSpecData); $smarty->assign('goodsSpecJson', json_encode($goodsSpecData)); } // 商品的类型属性 if ($goodsInfo['type_id'] > 0) { $goodsTypeService = new GoodsTypeService(); $goodsAttrTreeTable = $goodsTypeService->fetchGoodsAttrItemValueTreeTable($goodsInfo['goods_id'], $goodsInfo['type_id']); $smarty->assign('goodsAttrTreeTable', $goodsAttrTreeTable); } if (!empty($goodsCategoryLevelArray)) { $smarty->assign('goodsCategoryLevelArray', $goodsCategoryLevelArray); } if (!Utils::isEmpty($goodsGalleryArray)) { $smarty->assign('goodsGalleryArray', $goodsGalleryArray); } if (!Utils::isEmpty($linkGoodsArray)) { $smarty->assign('linkGoodsArray', $linkGoodsArray); } if (!Utils::isEmpty($supplierGoodsArray)) { $smarty->assign('supplierGoodsArray', $supplierGoodsArray); } // 滑动图片广告 $goods_view_adv_slider = json_decode(bzf_get_option_value('goods_view_adv_slider'), true); if (!empty($goods_view_adv_slider)) { $smarty->assign('goods_view_adv_slider', $goods_view_adv_slider); } // 移动端对应的 URL,用于百度页面适配 $smarty->assign('currentPageMobileUrl', RouteHelper::makeShopSystemUrl(PluginHelper::SYSTEM_MOBILE, '/Goods/View', array('goods_id' => $goods_id))); out_display: $smarty->display('goods_view.tpl', $smartyCacheId); return; out_fail: // 失败从这里返回 RouteHelper::reRoute($this, '/'); // 返回首页 }
public function get($f3) { global $smarty; // 首先做参数合法性验证 $validator = new Validator($f3->get('GET')); $pageNo = $validator->digits('pageNo 参数非法')->min(0, true, 'pageNo 参数非法')->validate('pageNo'); // 搜索参数数组 $searchFormQuery = array(); $searchFormQuery['g.category_id'] = $validator->required('商品分类不能为空')->digits('分类id非法')->min(1, true, '分类id非法')->filter('ValidatorIntValue')->validate('category_id'); // 这里支持多品牌查询 $searchFormQuery['g.brand_id'] = array('=', $validator->validate('brand_id')); // 价格区间查询 $shopPriceMin = $validator->filter('ValidatorFloatValue')->validate('shop_price_min'); $shopPriceMin = null == $shopPriceMin ? null : Money::toStorage($shopPriceMin); $shopPriceMax = $validator->filter('ValidatorFloatValue')->validate('shop_price_max'); $shopPriceMax = null == $shopPriceMax ? null : Money::toStorage($shopPriceMax); $searchFormQuery['g.shop_price'] = array($shopPriceMin, $shopPriceMax); // 属性过滤 $filter = $validator->validate('filter'); // 排序 $orderBy = $validator->oneOf(array('', 'total_buy_number', 'shop_price', 'add_time'))->validate('orderBy'); $orderDir = $validator->oneOf(array('', 'asc', 'desc'))->validate('orderDir'); $orderByParam = array(); if (!empty($orderBy)) { $orderByParam = array(array($orderBy, $orderDir)); } //增加一些我们的缺省排序 $orderByParam[] = array('g.sort_order', 'desc'); $orderByParam[] = array('g.goods_id', 'desc'); // 参数验证 if (!$this->validate($validator) || empty($searchFormQuery)) { goto out_fail; } $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0; $pageSize = 45; // 每页固定显示 45 个商品 // 生成 smarty 的缓存 id $smartyCacheId = 'Goods|Category|' . md5(json_encode($searchFormQuery) . json_encode($orderByParam) . '_' . $filter . '_' . $pageNo . '_' . $pageSize); // 开启并设置 smarty 缓存时间 enableSmartyCache(true, bzf_get_option_value('smarty_cache_time_goods_search')); if ($smarty->isCached('goods_category.tpl', $smartyCacheId)) { goto out_display; } $goodsCategoryService = new GoodsCategoryService(); $category = $goodsCategoryService->loadCategoryById($searchFormQuery['g.category_id'], 1800); if ($category->isEmpty()) { $this->addFlashMessage('分类[' . $searchFormQuery['category_id'] . ']不存在'); goto out_fail; } $smarty->assign('category', $category); $metaData = json_decode($category['meta_data'], true); $metaFilterArray = @$metaData['filterArray']; // 1. 我们需要在左侧显示分类层级结构 $goodsCategoryTreeArray = $goodsCategoryService->fetchCategoryTreeArray($category['parent_meta_id'], false, 1800); $smarty->assign('goodsCategoryTreeArray', $goodsCategoryTreeArray); /** * 构造 Filter 数组,结构如下 * * array( * '商品品牌' => array( * filterKey => 'brand_id' * filterValueArray => array( array(value=>'13', text=>'品牌1'), ...) * ), * '颜色' => array( * filterKey => 'filter', * filterValueArray => array( array(value=>'13', text=>'品牌1'), ...) * ) * ) * */ $goodsFilterArray = array(); // filter 查询在这个条件下进行 $goodsFilterQueryCond = array_merge($this->searchExtraCondArray, array(array('g.category_id', '=', $searchFormQuery['g.category_id']))); // 2. 商品品牌查询 $goodsBrandIdArray = SearchHelper::search(SearchHelper::Module_Goods, 'distinct(g.brand_id)', array_merge($goodsFilterQueryCond, array(array('g.brand_id > 0'))), null, 0, 0); $brandIdArray = array_map(function ($elem) { return $elem['brand_id']; }, $goodsBrandIdArray); if (!empty($brandIdArray)) { $goodsBrandService = new GoodsBrandService(); $goodsBrandArray = $goodsBrandService->fetchBrandArrayByIdArray(array_unique(array_values($brandIdArray))); $filterBrandArray = array(); foreach ($goodsBrandArray as $brand) { $filterBrandArray[] = array('value' => $brand['brand_id'], 'text' => $brand['brand_name']); } if (!empty($filterBrandArray)) { $goodsFilterArray['品牌'] = array('filterKey' => 'brand_id', 'filterValueArray' => $filterBrandArray); } } // 3. 查询属性过滤 if (!empty($metaFilterArray)) { $goodsTypeService = new GoodsTypeService(); foreach ($metaFilterArray as $filterItem) { $goodsTypeAttrItem = $goodsTypeService->loadGoodsTypeAttrItemById($filterItem['attrItemId']); if ($goodsTypeAttrItem->isEmpty()) { continue; } // 取得商品属性值列表 $goodsAttrItemValueArray = SearchHelper::search(SearchHelper::Module_GoodsAttrGoods, 'min(ga.goods_attr_id) as goods_attr_id, ga.attr_item_value', array_merge($goodsFilterQueryCond, array(array('ga.attr_item_id', '=', $filterItem['attrItemId']))), null, 0, 0, 'ga.attr_item_value'); if (!empty($goodsAttrItemValueArray)) { $filterValueArray = array(); foreach ($goodsAttrItemValueArray as $itemValue) { $filterValueArray[] = array('value' => $itemValue['goods_attr_id'], 'text' => $itemValue['attr_item_value']); } $goodsFilterArray[$goodsTypeAttrItem['meta_name']] = array('filterKey' => 'filter', 'filterValueArray' => $filterValueArray); } else { // 如果这个属性完全没有值(没有一个商品设过任何值),我们弄一个空的 $goodsFilterArray[$goodsTypeAttrItem['meta_name']] = array('filterKey' => 'filter', 'filterValueArray' => array()); } } } // 赋值给模板 if (!empty($goodsFilterArray)) { $smarty->assign('goodsFilterArray', $goodsFilterArray); } // 4. 商品查询 if (!empty($metaFilterArray)) { // 构造 attrItemId $metaFilterTypeIdArray = array(); foreach ($metaFilterArray as $metaFilterItem) { $metaFilterTypeIdArray[] = $metaFilterItem['attrItemId']; } // 构造 filter 参数,注意 filter 参数在 GoodsGoodsAttr 中具体解析 // 合并查询参数 $searchParamArray = array_merge(QueryBuilder::buildSearchParamArray($searchFormQuery), $this->searchExtraCondArray, array(array('ga.filter', implode('.', $metaFilterTypeIdArray), $filter))); } else { // 合并查询参数 $searchParamArray = array_merge(QueryBuilder::buildSearchParamArray($searchFormQuery), $this->searchExtraCondArray); } $totalCount = SearchHelper::count(SearchHelper::Module_GoodsGoodsAttr, $searchParamArray); if ($totalCount <= 0) { goto out_display; // 没有商品,直接显示 } // 页号可能是用户乱输入的,我们需要检查 if ($pageNo * $pageSize >= $totalCount) { goto out_fail; // 返回首页 } $goodsArray = SearchHelper::search(SearchHelper::Module_GoodsGoodsAttr, 'g.goods_id, g.cat_id, g.goods_sn, g.goods_name, g.brand_id, g.goods_number, g.market_price' . ', g.shop_price, g.suppliers_id, g.virtual_buy_number, g.user_buy_number, g.user_pay_number' . ', (g.virtual_buy_number + g.user_pay_number) as total_buy_number', $searchParamArray, $orderByParam, $pageNo * $pageSize, $pageSize); if (empty($goodsArray)) { goto out_display; } $smarty->assign('goodsArray', $goodsArray); $smarty->assign('totalCount', $totalCount); $smarty->assign('pageNo', $pageNo); $smarty->assign('pageSize', $pageSize); // SEO 考虑,网页标题加上分类的名称 $smarty->assign('seo_title', $category['meta_name'] . ',' . $smarty->getTemplateVars('seo_title')); out_display: // 滑动图片广告 $goods_search_adv_slider = json_decode(bzf_get_option_value('goods_search_adv_slider'), true); if (!empty($goods_search_adv_slider)) { $smarty->assign('goods_search_adv_slider', $goods_search_adv_slider); } $smarty->display('goods_category.tpl', $smartyCacheId); return; out_fail: // 失败从这里返回 RouteHelper::reRoute($this, '/'); // 返回首页 }
public function Statistics($f3) { global $smarty; $errorMessage = ''; $smartyCacheId = null; // 参数验证 $validator = new Validator($f3->get('GET')); $goods_id = $validator->required()->digits()->min(1)->validate('goods_id'); if (!$this->validate($validator)) { $errorMessage = '商品ID非法'; goto out_fail; } // 生成 smarty 的缓存 id $smartyCacheId = 'Goods|' . $goods_id . '|Search|Statistics'; enableSmartyCache(true, 300); // 缓存 5 分钟 if ($smarty->isCached('goods_search_ajax_statistics.tpl', $smartyCacheId)) { goto out_display; } // 权限检查 $authUser = AuthHelper::getAuthUser(); $goodsBasicService = new GoodsBasicService(); $goodsInfo = $goodsBasicService->loadGoodsById($goods_id, 300); // 缓存 300 秒 if ($goodsInfo['suppliers_id'] !== $authUser['suppliers_id']) { $errorMessage = '商品ID非法'; goto out_fail; } // 查询统计结果 $statisticsService = new Statistics(); $statistics = $statisticsService->goodsSaleStat($goods_id, 300); // 缓存 300 秒 $smarty->assign('goodsInfo', $goodsInfo); $smarty->assign('statistics', $statistics); out_fail: $smarty->assign('errorMessage', $errorMessage); if (!empty($errorMessage)) { // 有错误,不缓存 enableSmartyCache(false, 0); } out_display: $smarty->display('goods_search_ajax_statistics.tpl', $smartyCacheId); }
/** * 输出 sitemapIndex 文件 */ public function outputSiteMapXml($f3, $fileName) { global $smarty; //缓存 60 分钟 enableSmartyCache(true, 3600, \Smarty::CACHING_LIFETIME_CURRENT); $smartyCacheId = 'Api|' . md5(__NAMESPACE__ . '\\' . __CLASS__ . '\\' . __METHOD__); // 判断是否有缓存 if ($smarty->isCached('empty.tpl', $smartyCacheId)) { goto out_display; } // sitemap 列表 $siteMapFileList = ''; // 当前时间 $currentTime = time(); /***************** 生成 /Goods/View 列表 *******************/ // 查询商品数量,决定分页有多少页 $currentThemeInstance = ThemeHelper::getCurrentSystemThemeInstance(); $totalGoodsCount = SearchHelper::count(SearchHelper::Module_Goods, array(array(QueryBuilder::buildGoodsFilterForSystem($currentThemeInstance->getGoodsFilterSystemArray(), 'g')))); $pageCount = ceil($totalGoodsCount / $this->pageSize); // 取得当前的目录路径 $currentUrl = RouteHelper::getFullURL(); $currentUrl = substr($currentUrl, 0, strrpos($currentUrl, $fileName)); // 生成 goods 页面索引 for ($index = 0; $index < $pageCount; $index++) { $siteMapFileList .= '<sitemap><loc>' . $currentUrl . 'GoodsView_' . $currentTime . '_' . $index . '.xml</loc></sitemap>'; } /***************** 生成 /Goods/Search 列表 *******************/ // 生成 search 页面索引 $siteMapFileList .= '<sitemap><loc>' . $currentUrl . 'GoodsSearch_' . $currentTime . '_0.xml</loc></sitemap>'; /***************** 生成 /Article/View 列表 *******************/ // 查询商品数量,决定分页有多少页 $totalArticleCount = SearchHelper::count(SearchHelper::Module_Article, QueryBuilder::buildSearchParamArray(array('a.is_open' => 1))); $pageCount = ceil($totalArticleCount / $this->pageSize); // 生成 Article 页面索引 for ($index = 0; $index < $pageCount; $index++) { $siteMapFileList .= '<sitemap><loc>' . $currentUrl . 'ArticleView_' . $currentTime . '_' . $index . '.xml</loc></sitemap>'; } $apiXml = <<<XML <?xml version="1.0" encoding="utf-8" ?> <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> {$siteMapFileList} </sitemapindex> XML; $smarty->assign('outputContent', $apiXml); out_display: header('Content-Type:text/xml;charset=utf-8'); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 //查询信息 $smarty->display('empty.tpl', $smartyCacheId); }
public function get($f3) { global $smarty; // 生成 smarty 的缓存 id $smartyCacheId = 'Mobile|Index'; // 开启并设置 smarty 缓存时间 enableSmartyCache(true, MobileThemePlugin::getOptionValue('smarty_cache_time_goods_index')); // 缓存页面 if ($smarty->isCached('mobile_index.tpl', $smartyCacheId)) { goto out_display; } $categoryLevel = 3; // 取得分类下面 3 层的商品 $categoryGoodsSzie = 4; // 每个分类下面取 4 个商品 // 取得分类列表 $categoryService = new CategoryService(); $categoryArray = $categoryService->fetchCategoryArray(0); //取得分类 // 取得商品列表 $categoryGoodsArray = array(); $goodsIdArray = array(); foreach ($categoryArray as $category) { // 分类下面 3 层子分类, 取 4 个商品 $goodsArray = $categoryService->fetchGoodsArray($category['meta_id'], $categoryLevel, PluginHelper::SYSTEM_MOBILE, 0, $categoryGoodsSzie); if (!empty($goodsArray)) { $categoryGoodsArray[$category['meta_id']] = $goodsArray; foreach ($goodsArray as $goodsItem) { $goodsIdArray[] = $goodsItem['goods_id']; } } } // 网站完全没有商品? 不缓存 if (empty($goodsIdArray)) { goto out_display; } // 取得商品的图片 $goodsGalleryService = new GoodsGalleryService(); $goodsGalleryArray = $goodsGalleryService->fetchGoodsGalleryArrayByGoodsIdArray($goodsIdArray); $currentGoodsId = -1; $goodsThumbImageArray = array(); $goodsImageArray = array(); foreach ($goodsGalleryArray as $goodsGalleryItem) { if ($currentGoodsId == $goodsGalleryItem['goods_id']) { continue; //每个商品我们只需要一张图片,跳过其它的图片 } $currentGoodsId = $goodsGalleryItem['goods_id']; // 新的商品 id $goodsThumbImageArray[$currentGoodsId] = RouteHelper::makeImageUrl($goodsGalleryItem['thumb_url']); $goodsImageArray[$currentGoodsId] = RouteHelper::makeImageUrl($goodsGalleryItem['img_url']); } // 赋值给模板 $smarty->assign('categoryArray', $categoryArray); $smarty->assign('categoryGoodsArray', $categoryGoodsArray); $smarty->assign('goodsThumbImageArray', $goodsThumbImageArray); $smarty->assign('goodsImageArray', $goodsImageArray); out_display: $smarty->assign('seo_title', $smarty->getTemplateVars('seo_title') . ',' . $f3->get('HOST')); $smarty->display('mobile_index.tpl', $smartyCacheId); }
public function get($f3) { global $smarty; // 首先做参数合法性验证 $validator = new Validator($f3->get('GET')); $goods_id = $validator->required('商品id不能为空')->digits('商品id非法')->min(1, true, '商品id非法')->validate('goods_id'); $pageNo = $validator->digits()->min(0)->validate('pageNo'); if (!$this->validate($validator)) { goto out_fail; } // 生成 smarty 的缓存 id $smartyCacheId = 'Goods|' . $goods_id . '|AjaxGoodsComment_' . $pageNo; // 开启并设置 smarty 缓存时间 enableSmartyCache(true, bzf_get_option_value('smarty_cache_time_goods_view')); if ($smarty->isCached('ajax_goodscomment.tpl', $smartyCacheId)) { goto out_display; } $this->preparePage($goods_id, $pageNo); out_display: $f3->expire(600); // 让客户端缓存 10 分钟 $smarty->display('ajax_goodscomment.tpl', $smartyCacheId); return; out_fail: // output nothing return; }
public function get($f3) { global $smarty; // 首先做参数合法性验证 $validator = new Validator($f3->get('GET')); $pageNo = $validator->digits('pageNo 参数非法')->min(0, true, 'pageNo 参数非法')->validate('pageNo'); // 搜索参数数组 $searchFormQuery = array(); $searchFormQuery['category_id'] = $validator->digits('分类id非法')->min(1, true, '分类id非法')->filter('ValidatorIntValue')->validate('category_id'); $searchFormQuery['suppliers_id'] = $validator->digits('供货商id非法')->min(1, true, '供货商id非法')->filter('ValidatorIntValue')->validate('suppliers_id'); $searchFormQuery['goods_name'] = $validator->validate('goods_name'); // 价格区间查询 $shopPriceMin = $validator->filter('ValidatorFloatValue')->validate('shop_price_min'); $shopPriceMax = $validator->filter('ValidatorFloatValue')->validate('shop_price_max'); $searchFormQuery['shop_price'] = array($shopPriceMin, $shopPriceMax); // 排序 $orderBy = $validator->oneOf(array('', 'total_buy_number', 'shop_price', 'add_time'))->validate('orderBy'); $orderDir = $validator->oneOf(array('', 'asc', 'desc'))->validate('orderDir'); $orderByParam = array(); if (!empty($orderBy)) { $orderByParam = array(array($orderBy, $orderDir)); } //增加一些我们的缺省排序 $orderByParam[] = array('sort_order', 'desc'); $orderByParam[] = array('goods_id', 'desc'); // 参数验证 if (!$this->validate($validator) || empty($searchFormQuery)) { goto out_fail; } $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0; $pageSize = 10; // 每页固定显示 10 个商品 // 生成 smarty 的缓存 id $smartyCacheId = 'Goods|Search|' . md5(json_encode($searchFormQuery) . json_encode($orderByParam) . '_' . $pageNo . '_' . $pageSize); // 开启并设置 smarty 缓存时间 enableSmartyCache(true, MobileThemePlugin::getOptionValue('smarty_cache_time_goods_search')); if ($smarty->isCached('goods_search.tpl', $smartyCacheId)) { goto out_display; } // 合并查询参数 $searchParamArray = array_merge(QueryBuilder::buildSearchParamArray($searchFormQuery), $this->searchExtraCondArray); $totalCount = SearchHelper::count(SearchHelper::Module_Goods, $searchParamArray); if ($totalCount <= 0) { goto out_display; // 没有商品,直接显示 } // 页号可能是用户乱输入的,我们需要检查 if ($pageNo * $pageSize >= $totalCount) { goto out_fail; // 返回首页 } $goodsArray = SearchHelper::search(SearchHelper::Module_Goods, $this->searchFieldSelector, $searchParamArray, $orderByParam, $pageNo * $pageSize, $pageSize); if (empty($goodsArray)) { goto out_display; } // 取得 商品ID 列表 $goodsIdArray = array(); foreach ($goodsArray as $goodsItem) { $goodsIdArray[] = $goodsItem['goods_id']; } // 取得商品的图片 $goodsGalleryService = new GoodsGalleryService(); $goodsGalleryArray = $goodsGalleryService->fetchGoodsGalleryArrayByGoodsIdArray($goodsIdArray); $currentGoodsId = -1; $goodsThumbImageArray = array(); $goodsImageArray = array(); foreach ($goodsGalleryArray as $goodsGalleryItem) { if ($currentGoodsId == $goodsGalleryItem['goods_id']) { continue; //每个商品我们只需要一张图片,跳过其它的图片 } $currentGoodsId = $goodsGalleryItem['goods_id']; // 新的商品 id $goodsThumbImageArray[$currentGoodsId] = RouteHelper::makeImageUrl($goodsGalleryItem['thumb_url']); $goodsImageArray[$currentGoodsId] = RouteHelper::makeImageUrl($goodsGalleryItem['img_url']); } // 赋值给模板 $smarty->assign('totalCount', $totalCount); $smarty->assign('pageNo', $pageNo); $smarty->assign('pageSize', $pageSize); $smarty->assign('goodsArray', $goodsArray); $smarty->assign('goodsThumbImageArray', $goodsThumbImageArray); $smarty->assign('goodsImageArray', $goodsImageArray); out_display: $smarty->display('goods_search.tpl', $smartyCacheId); return; out_fail: // 失败从这里返回 RouteHelper::reRoute($this, '/'); // 返回首页 }
public function get($f3) { global $smarty; // 首先做参数合法性验证 $validator = new Validator($f3->get('GET')); $pageNo = $validator->digits('pageNo 参数非法')->min(0, true, 'pageNo 参数非法')->validate('pageNo'); // 搜索参数数组 $searchFormQuery = array(); $searchKeywords = $validator->validate('keywords'); $searchFormQuery['g.goods_name'] = $searchKeywords; // 这里支持多品牌查询 $searchFormQuery['g.brand_id'] = array('=', $validator->validate('brand_id')); // 价格区间查询 $shopPriceMin = $validator->filter('ValidatorFloatValue')->validate('shop_price_min'); $shopPriceMin = null == $shopPriceMin ? null : Money::toStorage($shopPriceMin); $shopPriceMax = $validator->filter('ValidatorFloatValue')->validate('shop_price_max'); $shopPriceMax = null == $shopPriceMax ? null : Money::toStorage($shopPriceMax); $searchFormQuery['g.shop_price'] = array($shopPriceMin, $shopPriceMax); // 排序 $orderBy = $validator->oneOf(array('', 'total_buy_number', 'shop_price', 'add_time'))->validate('orderBy'); $orderDir = $validator->oneOf(array('', 'asc', 'desc'))->validate('orderDir'); $orderByParam = array(); if (!empty($orderBy)) { $orderByParam = array(array($orderBy, $orderDir)); } //增加一些我们的缺省排序 $orderByParam[] = array('g.sort_order', 'desc'); $orderByParam[] = array('g.goods_id', 'desc'); // 参数验证 if (!$this->validate($validator) || empty($searchFormQuery)) { goto out_fail; } $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0; $pageSize = 45; // 每页固定显示 45 个商品 // 生成 smarty 的缓存 id $smartyCacheId = 'Goods|Search|' . md5(json_encode($searchFormQuery) . json_encode($orderByParam) . '_' . $pageNo . '_' . $pageSize); // 开启并设置 smarty 缓存时间 enableSmartyCache(true, bzf_get_option_value('smarty_cache_time_goods_search')); if ($smarty->isCached('goods_search.tpl', $smartyCacheId)) { goto out_display; } $goodsCategoryService = new GoodsCategoryService(); // 1. 我们需要在左侧显示分类层级结构 $goodsCategoryTreeArray = $goodsCategoryService->fetchCategoryTreeArray(0, false, 1800); $smarty->assign('goodsCategoryTreeArray', $goodsCategoryTreeArray); /** * 构造 Filter 数组,结构如下 * * array( * '商品品牌' => array( * filterKey => 'brand_id' * filterValueArray => array( array(value=>'13', text=>'品牌1'), ...) * ), * '颜色' => array( * filterKey => 'filter', * filterValueArray => array( array(value=>'13', text=>'品牌1'), ...) * ) * ) * */ $goodsFilterArray = array(); // filter 查询在这个条件下进行 $goodsFilterQueryCond = array_merge(QueryBuilder::buildSearchParamArray(array('g.goods_name' => $searchKeywords)), $this->searchExtraCondArray); // 2. 商品品牌查询 $goodsBrandIdArray = SearchHelper::search(SearchHelper::Module_Goods, 'distinct(g.brand_id)', array_merge($goodsFilterQueryCond, array(array('g.brand_id > 0'))), null, 0, 0); $brandIdArray = array_map(function ($elem) { return $elem['brand_id']; }, $goodsBrandIdArray); if (!empty($brandIdArray)) { $goodsBrandService = new GoodsBrandService(); $goodsBrandArray = $goodsBrandService->fetchBrandArrayByIdArray(array_unique(array_values($brandIdArray))); $filterBrandArray = array(); foreach ($goodsBrandArray as $brand) { $filterBrandArray[] = array('value' => $brand['brand_id'], 'text' => $brand['brand_name']); } if (!empty($filterBrandArray)) { $goodsFilterArray['品牌'] = array('filterKey' => 'brand_id', 'filterValueArray' => $filterBrandArray); } } if (!empty($goodsFilterArray)) { $smarty->assign('goodsFilterArray', $goodsFilterArray); } // 3. 商品属性过滤 TODO: 等以后扩展,看看 Search 怎么做属性过滤 // 4. 商品查询 // 构造 filter 参数,注意 filter 参数在 GoodsGoodsAttr 中具体解析 // 合并查询参数 $searchParamArray = array_merge(QueryBuilder::buildSearchParamArray($searchFormQuery), $this->searchExtraCondArray); $totalCount = SearchHelper::count(SearchHelper::Module_GoodsGoodsAttr, $searchParamArray); if ($totalCount <= 0) { goto out_display; // 没有商品,直接显示 } // 页号可能是用户乱输入的,我们需要检查 if ($pageNo * $pageSize >= $totalCount) { goto out_fail; // 返回首页 } $goodsArray = SearchHelper::search(SearchHelper::Module_GoodsGoodsAttr, 'g.goods_id, g.cat_id, g.goods_sn, g.goods_name, g.brand_id, g.goods_number, g.market_price' . ', g.shop_price, g.suppliers_id, g.virtual_buy_number, g.user_buy_number, g.user_pay_number' . ', (g.virtual_buy_number + g.user_pay_number) as total_buy_number', $searchParamArray, $orderByParam, $pageNo * $pageSize, $pageSize); if (empty($goodsArray)) { goto out_display; } $smarty->assign('goodsArray', $goodsArray); $smarty->assign('totalCount', $totalCount); $smarty->assign('pageNo', $pageNo); $smarty->assign('pageSize', $pageSize); // SEO 考虑,网页标题加上分类的名称 $smarty->assign('seo_title', '商品搜索,' . $searchKeywords . ',' . $smarty->getTemplateVars('seo_title')); out_display: // 滑动图片广告 $goods_search_adv_slider = json_decode(bzf_get_option_value('goods_search_adv_slider'), true); if (!empty($goods_search_adv_slider)) { $smarty->assign('goods_search_adv_slider', $goods_search_adv_slider); } $smarty->display('goods_search.tpl', $smartyCacheId); return; out_fail: // 失败从这里返回 RouteHelper::reRoute($this, '/'); // 返回首页 }