/** * 用于生成系统的操作链接,符合系统 URL 调用规范 * * 在模板中的使用方法 {{makeUrl controller='/User/Login' username='******' password='******' }} * * 必须要有 controller 用于指定控制器,其它参数可以没有 * * */ function smarty_helper_function_make_system_url(array $paramArray, $smarty) { $system = isset($paramArray['system']) ? $paramArray['system'] : ''; $controller = isset($paramArray['controller']) ? $paramArray['controller'] : '/Error/E404'; $static = isset($paramArray['static']) ? $paramArray['static'] : null; if (empty($system)) { return ''; } // 去除 system,controller, static ,其它都是控制器的参数 unset($paramArray['system']); unset($paramArray['controller']); unset($paramArray['static']); return RouteHelper::makeShopSystemUrl($system, $controller, $paramArray, $static); }
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); }
/** * 生成商品查看的 toolbar,用户可以查看 团购、商城、移动 * * @param array $paramArray * @param $smarty * * @return string */ function smarty_helper_function_goods_view_toolbar(array $paramArray, $smarty) { $goods_id = isset($paramArray['goods_id']) ? intval($paramArray['goods_id']) : 0; $system_tag_list = isset($paramArray['system_tag_list']) ? $paramArray['system_tag_list'] : ''; // 参数不对,没有东西可以输出 if ($goods_id <= 0) { return 'goods_id [' . $goods_id . '] 非法'; } // 如果不提供 system_tag_list 参数,我们从数据库查询 if (!array_key_exists('system_tag_list', $paramArray)) { static $goodsBasicService = null; if (!$goodsBasicService) { $goodsBasicService = new GoodsBasicService(); } // 缓存 5 秒钟 $goods = $goodsBasicService->loadGoodsById($goods_id, 5); if (!$goods->isEmpty()) { $system_tag_list = $goods['system_tag_list']; } else { return 'goods_id [' . $goods_id . '] 非法'; } } // 解析成 System Array $systemArray = \Core\Helper\Utility\Utils::parseTagString($system_tag_list); $htmlContent = '<div class="btn-group">'; $system_url_base_array = json_decode(\Theme\Manage\ManageThemePlugin::getOptionValue('system_url_base_array'), true); if (!empty($system_url_base_array)) { foreach ($systemArray as $system) { if (!array_key_exists($system, $system_url_base_array)) { // 不存在的系统,跳过 continue; } $themeSystem = $system_url_base_array[$system]; $htmlContent .= '<a title="查看' . $themeSystem['name'] . '商品详情" target="_blank" href="' . RouteHelper::makeShopSystemUrl($system, '/Goods/View', array('goods_id' => $goods_id)) . '" class="btn btn-mini btn-info">' . $themeSystem['name'] . '</a>'; } } $htmlContent .= '</div>'; return htmlspecialchars($htmlContent); }
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, '/'); // 返回首页 }