Пример #1
0
 public function clearGoodsCategory($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_misc_cache');
     ClearHelper::clearGoodsCategory();
     $this->addFlashMessage('商品类目页面清理成功');
     RouteHelper::reRoute($this, RouteHelper::getRefer(), false);
 }
Пример #2
0
 /**
  * 删除一个分类
  *
  * @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);
 }