Example #1
0
 /**
  * 更新或者新建一个分类
  *
  * @param $f3
  */
 public function Edit($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_category_edit');
     // 参数验证
     $validator = new Validator($f3->get('POST'));
     $meta_id = $validator->digits()->validate('meta_id');
     $meta_id = $meta_id ?: 0;
     $meta_name = $validator->validate('meta_name');
     $parent_meta_id = $validator->digits()->validate('parent_meta_id');
     $meta_sort_order = $validator->digits()->validate('meta_sort_order');
     $meta_status = $validator->digits()->validate('meta_status');
     // 筛选属性
     $filterTypeIdArray = $validator->validate('filterTypeIdArray');
     $filterAttrItemIdArray = $validator->validate('filterAttrItemIdArray');
     if (!$this->validate($validator)) {
         goto out;
     }
     if ($parent_meta_id > 0 && $parent_meta_id == $meta_id) {
         $this->addFlashMessage('父分类不能指向自己');
         goto out;
     }
     // 构造筛选属性结构
     $filterArray = array();
     $count = min(count($filterTypeIdArray), count($filterAttrItemIdArray));
     for ($index = 0; $index < $count; $index++) {
         $typeId = abs(intval($filterTypeIdArray[$index]));
         $attrItemId = abs(intval($filterAttrItemIdArray[$index]));
         if ($typeId <= 0 || $attrItemId <= 0) {
             // 非法值跳过
             continue;
         }
         $filterArray[] = array('typeId' => $typeId, 'attrItemId' => $attrItemId);
     }
     $meta_data = array('filterArray' => $filterArray);
     $goodsCategoryService = new GoodsCategoryService();
     $goodsCategoryService->saveCategoryById($meta_id, $parent_meta_id, $meta_name, null, json_encode($meta_data), $meta_sort_order, $meta_status);
     // 清除商品分类的缓存
     ClearHelper::clearGoodsCategory();
     $this->addFlashMessage('商品分类保存成功');
     out:
     RouteHelper::reRoute($this, '/Goods/Category');
 }