public async Task <IActionResult> CreatePhysicalProductAsync([FromBody] CreateProductOfDoctorCloudRequestDto requestDto) { if (string.IsNullOrEmpty(requestDto.PictureGuid)) { return(Failed(ErrorCode.Empty, "封面图片未上传")); } requestDto.MerchantGuid = UserID; var merchantModel = await new MerchantBiz().GetModelAsync(requestDto.MerchantGuid); if (merchantModel == null) { return(Failed(ErrorCode.Empty, "未查询到此商铺数据")); } if (!string.IsNullOrEmpty(requestDto.SearchKey?.Trim())) { if (requestDto.SearchKey.Length > 30) { return(Failed(ErrorCode.Empty, "搜索关键词超过最大长度限制")); } } if (!string.IsNullOrEmpty(requestDto.ProductTitle?.Trim())) { if (requestDto.ProductTitle.Length > 255) { return(Failed(ErrorCode.Empty, "商品副标题超过最大长度限制")); } } if (requestDto.ApprovalNumber.Length > 30) { return(Failed(ErrorCode.Empty, "批准文号超过最大长度限制")); } if (requestDto.ProductCode.Length > 50) { return(Failed(ErrorCode.Empty, "商品编码超过最大长度限制")); } if (requestDto.Standerd.Length > 30) { return(Failed(ErrorCode.Empty, "规格超过最大长度限制")); } var productBiz = new ProductBiz(); var checkProductName = await productBiz.CheckProductNameRepeatAsync(requestDto.ProductName, UserID); if (checkProductName) { return(Failed(ErrorCode.UserData, $"已存在“{requestDto.ProductName}”同名产品,请检查")); } var model = await productBiz.GetByCodeAsync(requestDto.MerchantGuid, requestDto.ProductCode); if (model != null) { return(Failed(ErrorCode.UserData, $"商品编码“{requestDto.ProductCode}”被占用")); } var productGuid = Guid.NewGuid().ToString("N"); List <RichtextModel> richtexts = new List <RichtextModel>(); //商品介绍富文本 var introduceTextModel = new RichtextModel { TextGuid = Guid.NewGuid().ToString("N"), OwnerGuid = productGuid, Content = requestDto.Introduce, CreatedBy = UserID, LastUpdatedBy = UserID, OrgGuid = string.Empty }; //商品详情富文本 var detailTextModel = new RichtextModel { TextGuid = Guid.NewGuid().ToString("N"), OwnerGuid = productGuid, Content = requestDto.ProductDetail, CreatedBy = UserID, LastUpdatedBy = UserID, OrgGuid = string.Empty }; richtexts.AddRange(new List <RichtextModel> { introduceTextModel, detailTextModel }); List <BannerModel> banners = new List <BannerModel>(); var sort = 1; foreach (var item in requestDto.Banners) { banners.Add(new BannerModel { BannerGuid = Guid.NewGuid().ToString("N"), OwnerGuid = productGuid, PictureGuid = item.PictureGuid, TargetUrl = item.TargetUrl, Sort = item.Sort ?? (item.Sort = sort++).Value, BannerName = string.IsNullOrWhiteSpace(item.BannerName) ? $"banner{item.Sort}" : item.BannerName, Description = item.Description, CreatedBy = UserID, LastUpdatedBy = UserID, OrgGuid = string.Empty }); } var categoryName = ""; var categoryDicModel = await new DictionaryBiz().GetAsync(requestDto.CategoryGuid); categoryName = categoryDicModel?.ConfigName; var productModel = new ProductModel { ProductGuid = productGuid, ProductCode = requestDto.ProductCode, ProductTitle = requestDto.ProductTitle, MerchantGuid = requestDto.MerchantGuid, CategoryGuid = requestDto.CategoryGuid, CategoryName = categoryName ?? "", PictureGuid = requestDto.PictureGuid, ProductName = requestDto.ProductName, ProductLabel = requestDto.SearchKey, Brand = requestDto.BrandGuid, Standerd = requestDto.Standerd, RetentionPeriod = requestDto.RetentionPeriod, Manufacture = requestDto.Manufacture, ApprovalNumber = requestDto.ApprovalNumber, Price = requestDto.Price, CostPrice = requestDto.CostPrice, MarketPrice = requestDto.MarketPrice, Freight = requestDto.Freight, IntroduceGuid = introduceTextModel.TextGuid, ProDetailGuid = detailTextModel.TextGuid, Inventory = requestDto.Inventory, WarningInventory = requestDto.WarningInventory, OnSale = requestDto.OnSale, OperationTime = requestDto.OperationTime, CreatedBy = UserID, LastUpdatedBy = UserID, ProductForm = ProductFormEnum.Physical.ToString(), OrgGuid = "", PlatformType = merchantModel.PlatformType }; var result = await productBiz.CreateProductOfDoctorCloudAsync(productModel, richtexts, banners); return(result ? Success() : Failed(ErrorCode.DataBaseError, "发布商品失败")); }