public async Task <IActionResult> ModifyServiceProductBasicInfoAsync([FromBody] ModifyPhysicalProductBasicInfoRequestDto requestDto)
        {
            if (string.IsNullOrEmpty(requestDto.PictureGuid))
            {
                return(Failed(ErrorCode.Empty, "封面图片未上传"));
            }

            if (requestDto.Price <= 0)
            {
                return(Failed(ErrorCode.Empty, "价格必须大于0"));
            }

            var productBiz = new ProductBiz();

            var productModel = await productBiz.GetModelByGuidAsync(requestDto.ProductGuid);

            if (productModel == null)
            {
                return(Failed(ErrorCode.Empty, "未查询到此商品信息"));
            }

            var checkProductName = await productBiz.CheckProductNameRepeatAsync(requestDto.ProductName, UserID, requestDto.ProductGuid);

            if (checkProductName)
            {
                return(Failed(ErrorCode.UserData, "门店下已存在同名商品,请检查"));
            }

            var category = (await new MerchantCategoryBiz().GetModelByClassifyGuidAsync(requestDto.CategoryGuid, UserID));

            if (category is null)
            {
                return(Failed(ErrorCode.Empty, "产品分类不存在"));
            }

            productModel.Recommend       = requestDto.Recommend;
            productModel.ProductName     = requestDto.ProductName;
            productModel.ProductTitle    = requestDto.ProductTitle;
            productModel.Price           = requestDto.Price;
            productModel.EffectiveDays   = requestDto.EffectiveDays;
            productModel.PictureGuid     = requestDto.PictureGuid;
            productModel.OnSale          = requestDto.OnSale;
            productModel.CategoryGuid    = requestDto.CategoryGuid;
            productModel.CategoryName    = category.ClassifyName;
            productModel.LastUpdatedBy   = UserID;
            productModel.LastUpdatedDate = DateTime.Now;

            var response = await productBiz.UpdateAsync(productModel);

            return(response ? Success() : Failed(ErrorCode.DataBaseError, "修改商品基础信息失败"));
        }
        public async Task <IActionResult> ModifyPhysicalProductBasicInfoAsync([FromBody] ModifyProductBasicInfoOfDoctorCloudRequestDto requestDto)
        {
            if (string.IsNullOrEmpty(requestDto.PictureGuid))
            {
                return(Failed(ErrorCode.Empty, "封面图片未上传"));
            }

            var productBiz = new ProductBiz();

            var productModel = await productBiz.GetModelByGuidAsync(requestDto.ProductGuid);

            if (productModel == 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 checkProductName = await productBiz.CheckProductNameRepeatAsync(requestDto.ProductName, UserID, requestDto.ProductGuid);

            if (checkProductName)
            {
                return(Failed(ErrorCode.UserData, "门店下已存在同名商品,请检查"));
            }

            var model = await productBiz.GetByCodeAsync(UserID, requestDto.ProductCode);

            if (model != null && !model.ProductGuid.Equals(requestDto.ProductGuid))
            {
                return(Failed(ErrorCode.DataBaseError, $"商品编码“{requestDto.ProductCode}”已被占用"));
            }

            productModel.ApprovalNumber  = requestDto.ApprovalNumber;
            productModel.ProductTitle    = requestDto.ProductTitle;
            productModel.ProductLabel    = requestDto.SearchKey;
            productModel.Brand           = requestDto.BrandGuid;
            productModel.Manufacture     = requestDto.Manufacture;
            productModel.RetentionPeriod = requestDto.RetentionPeriod;
            productModel.ProductName     = requestDto.ProductName;
            productModel.PictureGuid     = requestDto.PictureGuid;
            productModel.ProductCode     = requestDto.ProductCode;
            productModel.Standerd        = requestDto.Standerd;

            var response = await productBiz.UpdateAsync(productModel);

            return(response ? Success() : Failed(ErrorCode.DataBaseError, "修改商品基础信息失败"));
        }
        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, "发布商品失败"));
        }
        public async Task <IActionResult> CreateServiceProductAsync([FromBody] CreateServiceProductRequestDto requestDto)
        {
            if (string.IsNullOrEmpty(requestDto.PictureGuid))
            {
                return(Failed(ErrorCode.Empty, "封面图片未上传"));
            }

            var merchantModel = await new MerchantBiz().GetModelAsync(UserID);

            if (merchantModel == null)
            {
                return(Failed(ErrorCode.Empty, "未查询到此商铺数据"));
            }

            var productBiz = new ProductBiz();

            var checkProductName = await productBiz.CheckProductNameRepeatAsync(requestDto.ProductName, UserID);

            if (checkProductName)
            {
                return(Failed(ErrorCode.UserData, $"已存在“{requestDto.ProductName}”同名产品,请检查"));
            }

            List <ProductModel> productModels = new List <ProductModel>();

            List <ProductProjectModel> productProjectModels = new List <ProductProjectModel>();

            List <RichtextModel> richtextModels = new List <RichtextModel>();

            List <BannerModel> bannerModels = new List <BannerModel>();

            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
            });
            richtextModels.AddRange(richtexts);

            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          = sort,
                    BannerName    = string.IsNullOrWhiteSpace(item.BannerName) ? $"banner{sort}" : item.BannerName,
                    Description   = item.Description,
                    CreatedBy     = UserID,
                    LastUpdatedBy = UserID,
                    OrgGuid       = string.Empty
                });
                sort++;
            }

            bannerModels.AddRange(banners);

            var productModel = new ProductModel
            {
                ProductGuid      = productGuid,
                ProductCode      = Guid.NewGuid().ToString("N"),
                ProductTitle     = requestDto.ProductTitle,
                MerchantGuid     = UserID,
                CategoryGuid     = requestDto.CategoryGuid,
                CategoryName     = requestDto.CategoryName,
                PictureGuid      = requestDto.PictureGuid,
                ProductName      = requestDto.ProductName,
                Price            = requestDto.Price,
                IntroduceGuid    = introduceTextModel.TextGuid,
                ProDetailGuid    = detailTextModel.TextGuid,
                OnSale           = requestDto.OnSale,
                CreatedBy        = UserID,
                LastUpdatedBy    = UserID,
                OrgGuid          = "",
                ProductForm      = ProductFormEnum.Service.ToString(),
                PlatformType     = merchantModel.PlatformType,
                EffectiveDays    = requestDto.EffectiveDays,
                ProjectThreshold = requestDto.ProjectThreshold,
                Recommend        = requestDto.Recommend
            };

#warning 因未开通线上支付,现所有商品均为可预付款,预付款比例为0,即所有商品金额均到店支付

            productModels.Add(productModel);
            List <ProductProjectModel> productProjects = new List <ProductProjectModel>();
            if (requestDto.ProjectGuids != null)
            {
                productProjects.AddRange(requestDto.ProjectGuids.Select(a => new ProductProjectModel
                {
                    ProductProjectGuid = Guid.NewGuid().ToString("N"),
                    ProductGuid        = productModel.ProductGuid,
                    ProjectGuid        = a.ProjectGuid,
                    ProjectTimes       = a.Infinite ? 999 : a.ProjectTimes,
                    PlatformType       = merchantModel.PlatformType,
                    CreatedBy          = UserID,
                    LastUpdatedBy      = UserID,
                    OrgGuid            = ""
                }).ToList());
            }

            productProjectModels.AddRange(productProjects);

            var result = await productBiz.CreateProductAsync(productModels, richtextModels, bannerModels, productProjectModels);

            return(result ? Success() : Failed(ErrorCode.DataBaseError, "创建产品失败"));
        }