Example #1
0
        /// <summary>
        /// 拼生活的商品详情页
        /// </summary>
        /// <returns></returns>
        public ActionResult FightDetail(string sku, int pid)
        {
            IList <ProductInfoModel> productsDetail   = new List <ProductInfoModel>();
            ProductInfoModel         productInfoModel = new ProductInfoModel();
            IList <ProductInfoModel> images           = new List <ProductInfoModel>();

            try
            {
                productsDetail   = productBll.GetProductFightDetail(sku, base.ExchangeRate, pid);
                productInfoModel = productsDetail.FirstOrDefault();
                if (!string.IsNullOrEmpty(productInfoModel.NationalFlag))
                {
                    productInfoModel.NationalFlag = productInfoModel.NationalFlag + PathHelper.NationalFlagImageExtension;
                }
                string neight = commonBll.getProductDetailName(productInfoModel.MainDicValue, productInfoModel.SubDicValue, productInfoModel.NetWeightUnit);
                if (!neight.Equals(""))
                {
                    productInfoModel.MainValue = Convert.ToDecimal(productInfoModel.MainValue).ToNumberStringFloat();
                }
                productInfoModel.NetWeightUnit = neight;
                int realTaxType    = Utility.Uitl.TotalTaxHelper.GetRealTaxType(productInfoModel.ReportStatus, productInfoModel.IsCrossBorderEBTax, StringUtils.ToAmt(productInfoModel.MinPrice));
                var taxPrice       = StringUtils.ToAmt(TotalTaxHelper.GetTotalTaxAmount(realTaxType, StringUtils.ToAmt(productInfoModel.MinPrice), productInfoModel.CBEBTaxRate, productInfoModel.ConsumerTaxRate, productInfoModel.VATTaxRate, productInfoModel.PPATaxRate));
                int minRealTaxType = Utility.Uitl.TotalTaxHelper.GetRealTaxType(productInfoModel.ReportStatus, productInfoModel.IsCrossBorderEBTax, StringUtils.ToAmt(productInfoModel.DiscountPrice));
                var minRatePrice   = StringUtils.ToAmt(TotalTaxHelper.GetTotalTaxAmount(minRealTaxType, StringUtils.ToAmt(productInfoModel.DiscountPrice), productInfoModel.CBEBTaxRate, productInfoModel.ConsumerTaxRate, productInfoModel.VATTaxRate, productInfoModel.PPATaxRate));

                productInfoModel.realTaxType    = realTaxType;
                productInfoModel.minRealTaxType = minRealTaxType;
                productInfoModel.taxPrice       = taxPrice;
                productInfoModel.minRatePrice   = minRatePrice;
                foreach (var product in productsDetail)
                {
                    images.Add(product);
                }
                productInfoModel.Images = images;
                //var sortProductInfoModel=productInfoModel
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(View(productInfoModel));;
        }
Example #2
0
        public static SkuAttributeViewModel AsSkuAttributeViewModelD(this IList <ProductSkuEntity> entities, decimal exchangeRate, IList <PromotionEntity> promotions, string selectedSku = "", ItemViewSupporter dto = null)
        {
            if (entities == null || !entities.Any())
            {
                return(null);
            }

            SkuAttributeViewModel model = new SkuAttributeViewModel();

            #region 元数据组装

            var template = entities.FirstOrDefault();
            if (template == null)
            {
                return(null);
            }
            if (dto != null)
            {
                model.ProductName = dto.Name;
                var firstOrDefault = dto.Images.FirstOrDefault();
                if (firstOrDefault != null)
                {
                    model.ImgUrl = firstOrDefault.ImagePath.GetImageSmallUrl();
                }

                model.InitPrice = promotions.FirstOrDefault(m => m.Sku == template.Sku).GetSalePrice(dto.MinPriceOriginal, exchangeRate).ToNumberRoundString();
                //(GetDisplayPrice(promotions.FirstOrDefault(m => m.Sku == template.Sku), (template.MinPrice)) *exchangeRate).ToNumberRoundString(); //dto.MinPrice.ToNumberRoundString();
                //dto.SkuDtos.ToList().Min(d=>d.Price)
                var skuDto = dto.SkuDtos.ToList().OrderBy(d => d.Price).FirstOrDefault();

                model.TaxAmount = TotalTaxHelper.GetTotalTaxAmount(TotalTaxHelper.GetRealTaxType(skuDto.ReportStatus, skuDto.IsCrossBorderEBTax,
                                                                                                 promotions.FirstOrDefault(m => m.Sku == skuDto.Sku).GetSalePrice(skuDto.Price, null)),
                                                                   promotions.FirstOrDefault(m => m.Sku == skuDto.Sku).GetSalePrice(skuDto.Price, null),
                                                                   skuDto.CBEBTaxRate, skuDto.ConsumerTaxRate, skuDto.VATTaxRate, skuDto.PPATaxRate).ToNumberRound();
                model.IsDutyOnSeller = dto.IsDutyOnSeller;
                model.RealTaxType    = TotalTaxHelper.GetRealTaxType(skuDto.ReportStatus, skuDto.IsCrossBorderEBTax,
                                                                     promotions.FirstOrDefault(m => m.Sku == skuDto.Sku).GetSalePrice(skuDto.Price, exchangeRate));
            }
            else
            {
                model.ProductName = template.Name;
                model.ImgUrl      = "";
                model.InitPrice   = promotions.FirstOrDefault(m => m.Sku == template.Sku).GetSalePrice(template.MinPrice, exchangeRate).ToNumberRoundString();
                //(GetDisplayPrice(promotions.FirstOrDefault(m => m.Sku == template.Sku), (template.MinPrice)) *exchangeRate).ToNumberRoundString(); //dto.MinPrice.ToNumberRoundString();//template.MinPrice.ToNumberRoundString();
            }
            model.MainName = template.MainDicValue;
            model.MainCode = template.MainDicKey;
            model.SubName  = template.SubDicValue;
            model.SubCode  = template.SubDicKey;

            #endregion

            List <MainSkuAttribute> mainList = new List <MainSkuAttribute>();
            List <SubSkuAttribute>  subList  = new List <SubSkuAttribute>();
            //只有一个销售属性
            if (string.IsNullOrEmpty(model.SubCode) && string.IsNullOrEmpty(model.SubName))
            {
                mainList = entities.DistinctBy(d => new { d.MainKey, d.MainValue }).Select(n => new MainSkuAttribute()
                {
                    MetaCode      = n.MainDicKey,
                    Id            = n.MainKey,
                    Name          = n.MainValue,
                    NetWeightUnit = n.NetWeightUnit,
                    Sku           = n.Sku,
                    Flag          = n.Qty == 0 ? -1 : (!string.IsNullOrEmpty(selectedSku) && selectedSku == n.Sku) == true ? 1 : 0,
                    ForOrder      = n.Qty,
                    Price         = promotions.FirstOrDefault(m => m.Sku == n.Sku).GetSalePrice(n.Price, exchangeRate),//(GetDisplayPrice(promotions.FirstOrDefault(m => m.Sku == n.Sku), (n.Price)) * exchangeRate).ToNumberRound(),
                    OriginalPrice = (n.Price * exchangeRate).ToNumberRound(),
                    Promotion     = GetPromotionItem(promotions.FirstOrDefault(m => m.Sku == n.Sku), exchangeRate),

                    TaxAmount = TotalTaxHelper.GetTotalTaxAmount(TotalTaxHelper.GetRealTaxType(n.ReportStatus, n.IsCrossBorderEBTax,
                                                                                               promotions.FirstOrDefault(m => m.Sku == n.Sku).GetSalePrice(n.Price, exchangeRate)),
                                                                 promotions.FirstOrDefault(m => m.Sku == n.Sku).GetSalePrice(n.Price, exchangeRate),
                                                                 n.CBEBTaxRate, n.ConsumerTaxRate, n.VATTaxRate, n.PPATaxRate).ToNumberRound(),
                    IsDutyOnSeller = n.IsDutyOnSeller,
                    RealTaxType    = TotalTaxHelper.GetRealTaxType(n.ReportStatus, n.IsCrossBorderEBTax,
                                                                   promotions.FirstOrDefault(m => m.Sku == n.Sku).GetSalePrice(n.Price, exchangeRate)),

                    SubAttributes = new List <SubSkuAttribute>(0)
                }).OrderBy(n => n.Id.As(0)).ToList();
            }
            else
            {
                var comparer1 = Equality <SubSkuAttribute> .CreateComparer(p => p.Id);

                subList = entities.DistinctBy(d => new { d.SubKey, d.SubValue }).Select(ss => new SubSkuAttribute()
                {
                    Flag     = -1,
                    Id       = ss.SubKey,
                    MetaCode = ss.SubDicKey,
                    Name     = ss.SubValue,
                }).OrderBy(nn => nn.Id.As(0)).ToList();

                mainList = entities.DistinctBy(d => new { d.MainKey, d.MainValue }).Select(n => new MainSkuAttribute()
                {
                    MetaCode      = n.MainDicKey,
                    Id            = n.MainKey,
                    Name          = n.MainValue,
                    Flag          = entities.Where(s => s.MainKey == n.MainKey && s.MainDicKey == n.MainDicKey).Any(nn => nn.Sku == selectedSku) ? 1 : 0,
                    NetWeightUnit = n.NetWeightUnit,
                    Sku           = "",
                    ForOrder      = n.Qty,
                    Price         = promotions.FirstOrDefault(m => m.Sku == n.Sku).GetSalePrice(n.Price, exchangeRate),
                    OriginalPrice = (n.Price * exchangeRate).ToNumberRound(),
                    Promotion     = GetPromotionItem(promotions.FirstOrDefault(m => m.Sku == n.Sku), exchangeRate),
                    TaxAmount     = TotalTaxHelper.GetTotalTaxAmount(TotalTaxHelper.GetRealTaxType(n.ReportStatus, n.IsCrossBorderEBTax,
                                                                                                   promotions.FirstOrDefault(m => m.Sku == n.Sku).GetSalePrice(n.Price, exchangeRate)),
                                                                     promotions.FirstOrDefault(m => m.Sku == n.Sku).GetSalePrice(n.Price, exchangeRate),
                                                                     n.CBEBTaxRate, n.ConsumerTaxRate, n.VATTaxRate, n.PPATaxRate).ToNumberRound(),
                    IsDutyOnSeller = n.IsDutyOnSeller,
                    RealTaxType    = TotalTaxHelper.GetRealTaxType(n.ReportStatus, n.IsCrossBorderEBTax,
                                                                   promotions.FirstOrDefault(m => m.Sku == n.Sku).GetSalePrice(n.Price, exchangeRate)),



                    SubAttributes = entities.Where(s => s.MainKey == n.MainKey && s.MainDicKey == n.MainDicKey).Select(ss => new SubSkuAttribute()
                    {
                        Flag          = ss.Qty == 0 ? -1 : (!string.IsNullOrEmpty(selectedSku) && selectedSku == ss.Sku) == true ? 1 : 0,
                        ForOrder      = ss.Qty,
                        Id            = ss.SubKey,
                        MetaCode      = ss.SubDicKey,
                        Name          = ss.SubValue,
                        Price         = promotions.FirstOrDefault(m => m.Sku == n.Sku).GetSalePrice(ss.Price, exchangeRate),//(GetDisplayPrice(promotions.FirstOrDefault(m => m.Sku == n.Sku), (ss.Price))).ToNumberRound(),
                        OriginalPrice = (ss.Price * exchangeRate).ToNumberRound(),
                        Promotion     = GetPromotionItem(promotions.FirstOrDefault(m => m.Sku == n.Sku), exchangeRate),
                        Sku           = ss.Sku,
                        TaxAmount     = TotalTaxHelper.GetTotalTaxAmount(TotalTaxHelper.GetRealTaxType(ss.ReportStatus, ss.IsCrossBorderEBTax,
                                                                                                       promotions.FirstOrDefault(m => m.Sku == ss.Sku).GetSalePrice(ss.Price, exchangeRate)),
                                                                         promotions.FirstOrDefault(m => m.Sku == ss.Sku).GetSalePrice(ss.Price, exchangeRate),
                                                                         ss.CBEBTaxRate, ss.ConsumerTaxRate, ss.VATTaxRate, ss.PPATaxRate).ToNumberRound(),
                        IsDutyOnSeller = ss.IsDutyOnSeller,
                        RealTaxType    = TotalTaxHelper.GetRealTaxType(ss.ReportStatus, ss.IsCrossBorderEBTax,
                                                                       promotions.FirstOrDefault(m => m.Sku == ss.Sku).GetSalePrice(ss.Price, exchangeRate))
                    }).ToList().Union <SubSkuAttribute>(subList, comparer1).OrderBy(nn => nn.Id.As(0)).ToList()
                }).ToList();
            }

            model.MainAttributes = mainList;
            model.SubAttributes  = subList;
            //如果为净重   增加单位
            if (model.MainName != null && model.MainName != "")
            {
                if (model.MainName.Equals("净重") || model.MainName.Equals("淨重") || model.MainName.Equals("净含量") || model.MainName.Equals("凈含量"))
                {
                    for (int i = 0; i < model.MainAttributes.Count; i++)
                    {
                        var mainAttribute = model.MainAttributes[i];

                        //当数值带有小数点,且末尾有0,则清小数点后空末尾处的0,然后再拼接单位
                        string number = mainAttribute.Name;
                        if (string.IsNullOrEmpty(number))
                        {
                            number = "0";
                        }
                        double result = 0;
                        if (Double.TryParse(number, out result))
                        {
                            mainAttribute.Name = string.Format("{0}{1}", result, mainAttribute.NetWeightUnit);
                        }
                        else
                        {
                            mainAttribute.Name = "抱歉,数据有误!";
                        };
                    }
                }
            }

            return(model);
        }