/** * support multiple id to delete the category * @param $id,string * @param $accountId,MongoId */ public static function deleteCategory($id, $accountId) { $idList = self::getCategoryList($id, ','); //check the category to make sure the category have not product foreach ($idList as $val) { $productWhere = ['category.id' => new \MongoId($val)]; $product = Product::findByCondition($productWhere, true); if ($product) { throw new ServerErrorHttpException('This category have products.'); } } $where = array_merge(['in', '_id', $idList], ['accountId' => $accountId, 'isDeleted' => false]); if (ProductCategory::deleteAll($where) == false) { throw new ServerErrorHttpException('Failed to delete the object for unknown reason.'); } self::deleteProductCategory($id, $accountId); }