/** * 删除一个分类 * * @param $f3 */ public function Remove($f3) { // 权限检查 $this->requirePrivilege('manage_goods_category_edit'); // 参数验证 $validator = new Validator($f3->get('GET')); $meta_id = $validator->required()->digits()->min(1)->validate('meta_id'); if (!$this->validate($validator)) { goto out; } $goodsCategoryService = new GoodsCategoryService(); $category = $goodsCategoryService->loadCategoryById($meta_id); if ($category->isEmpty()) { $this->addFlashMessage('分类不存在'); goto out; } // 检查当前分类是否存在子分类 $childArray = $goodsCategoryService->fetchCategoryArray($category['meta_id'], true); if (!empty($childArray)) { $this->addFlashMessage('当前分类有子分类,不能删除'); goto out; } // 检查当前分类是否有商品 $categoryGoodsCountArray = $goodsCategoryService->calcCategoryGoodsCount(); foreach ($categoryGoodsCountArray as $categoryItem) { if ($meta_id == $categoryItem['cat_id'] && $categoryItem['goods_count'] > 0) { $this->addFlashMessage('当前分类有商品,不能删除'); goto out; } } // 删除分类 $category->erase(); // 清除商品分类的缓存 ClearHelper::clearGoodsCategory(); $this->addFlashMessage('分类删除成功'); out: RouteHelper::reRoute($this, RouteHelper::getRefer(), false); }
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); }
/** * 生成网页左侧分类列表的显示 */ function smarty_helper_function_category_list(array $paramArray, $smarty) { $basicCategoryService = new BasicCategoryService(); $liHead = '<li><a data-transition="flow" href="'; // 我们只显示顶级分类 $categoryArray = $basicCategoryService->fetchCategoryArray(0, false, 1800); // 缓存 30 分钟 $output = $liHead . RouteHelper::makeUrl('/') . '">网站首页</a></li>'; foreach ($categoryArray as $categoryItem) { $output .= $liHead . RouteHelper::makeUrl('/Goods/Search', array('category_id' => $categoryItem['meta_id']), false, false, false) . '">' . $categoryItem['meta_name'] . '</a></li>'; } return $output; }