Exemple #1
0
        public ActionResult Index(int pageSize = 10, int pageNo = 1)
        {
            OrderQuery query = new OrderQuery();

            query.PageNo   = pageNo;
            query.PageSize = pageSize;
            query.UserId   = CurrentUser.Id;
            query.Status   = OrderInfo.OrderOperateStatus.Finish;
            var orders     = _iOrderService.GetOrders(query);
            var complaints = OrderApplication.GetOrderComplaintByOrders(orders.Models.Select(p => p.Id).ToList());
            var model      = orders.Models.Where(o => !complaints.Any(p => p.OrderId == o.Id));

            ViewBag.Complaints = complaints;
            var orderItems = _iOrderService.GetOrderItemsByOrderId(orders.Models.Select(p => p.Id));

            if (orderItems != null)
            {
                foreach (var item in orderItems)
                {
                    Entities.TypeInfo typeInfo = _iTypeService.GetTypeByProductId(item.ProductId);
                    var productInfo            = Mall.Application.ProductManagerApplication.GetProduct(item.ProductId);
                    item.ColorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    item.SizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    item.VersionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                }
            }
            ViewBag.OrderItems = orderItems;
            #region 分页控制
            PagingInfo info = new PagingInfo
            {
                CurrentPage  = pageNo,
                ItemsPerPage = pageSize,
                TotalItems   = orders.Total
            };
            ViewBag.pageInfo  = info;
            ViewBag.UserPhone = CurrentUser.CellPhone;
            ViewBag.UserId    = CurrentUser.Id;
            #endregion
            ViewBag.Keyword  = string.IsNullOrWhiteSpace(SiteSettings.SearchKeyword) ? SiteSettings.Keyword : SiteSettings.SearchKeyword;
            ViewBag.Keywords = SiteSettings.HotKeyWords;
            return(View(model));
        }
        public ActionResult ShowSkuInfo(FightGroupActiveModel data)
        {
            if (data == null)
            {
                throw new HimallException("错误的活动信息");
            }
            ProductShowSkuInfoModel model = new ProductShowSkuInfoModel();

            model.MinSalePrice     = data.MiniGroupPrice;
            model.ProductImagePath = data.ProductImgPath;
            model.MaxBuyCount      = data.LimitQuantity.HasValue ? data.LimitQuantity.Value : 0;

            #region 商品规格
            Entities.TypeInfo typeInfo     = _iTypeService.GetTypeByProductId((long)data.ProductId);
            string            colorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
            string            sizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
            string            versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
            var product = ProductManagerApplication.GetProduct((long)data.ProductId);
            if (product != null)
            {
                colorAlias   = !string.IsNullOrWhiteSpace(product.ColorAlias) ? product.ColorAlias : colorAlias;
                sizeAlias    = !string.IsNullOrWhiteSpace(product.SizeAlias) ? product.SizeAlias : sizeAlias;
                versionAlias = !string.IsNullOrWhiteSpace(product.VersionAlias) ? product.VersionAlias : versionAlias;
            }
            model.ColorAlias   = colorAlias;
            model.SizeAlias    = sizeAlias;
            model.VersionAlias = versionAlias;

            if (data.ActiveItems != null && data.ActiveItems.Count() > 0)
            {
                model.StockAll = (int)data.ActiveItems.Where(p => p.SkuId.Contains(product.Id + "_")).Sum(p => p.ActiveStock);//总库存(它where一次是因为有效规格是“产品ID_”,过滤无效“{0}_”)
                long colorId = 0, sizeId = 0, versionId = 0;
                foreach (var sku in data.ActiveItems)
                {
                    var specs = sku.SkuId.Split('_');
                    if (specs.Count() > 0 && !string.IsNullOrEmpty(sku.Color))
                    {
                        if (long.TryParse(specs[1], out colorId))
                        {
                        }
                        if (colorId != 0)
                        {
                            if (!model.Color.Any(v => v.Value.Equals(sku.Color)))
                            {
                                var c = data.ActiveItems.Where(s => s.Color.Equals(sku.Color)).Sum(s => s.ActiveStock);
                                model.Color.Add(new Himall.Web.Areas.Web.Models.ProductSKU
                                {
                                    //Name = "选择颜色",
                                    Name         = "选择" + colorAlias,
                                    EnabledClass = c != 0 ? "enabled" : "disabled",
                                    //SelectedClass = !model.Color.Any(c1 => c1.SelectedClass.Equals("selected")) && c != 0 ? "selected" : "",
                                    SelectedClass = "",
                                    SkuId         = colorId,
                                    Value         = sku.Color,
                                    Img           = sku.ShowPic
                                });
                            }
                        }
                    }
                    if (specs.Count() > 1)
                    {
                        if (long.TryParse(specs[2], out sizeId))
                        {
                        }
                        if (sizeId != 0 && !string.IsNullOrEmpty(sku.Size))
                        {
                            if (!model.Size.Any(v => v.Value.Equals(sku.Size)))
                            {
                                var ss = data.ActiveItems.Where(s => s.Size.Equals(sku.Size)).Sum(s1 => s1.ActiveStock);
                                model.Size.Add(new Himall.Web.Areas.Web.Models.ProductSKU
                                {
                                    //Name = "选择尺码",
                                    Name         = "选择" + sizeAlias,
                                    EnabledClass = ss != 0 ? "enabled" : "disabled",
                                    //SelectedClass = !model.Size.Any(s1 => s1.SelectedClass.Equals("selected")) && ss != 0 ? "selected" : "",
                                    SelectedClass = "",
                                    SkuId         = sizeId,
                                    Value         = sku.Size
                                });
                            }
                        }
                    }

                    if (specs.Count() > 2)
                    {
                        if (long.TryParse(specs[3], out versionId))
                        {
                        }
                        if (versionId != 0 && !string.IsNullOrEmpty(sku.Version))
                        {
                            if (!model.Version.Any(v => v.Value.Equals(sku.Version)))
                            {
                                var v = data.ActiveItems.Where(s => s.Version.Equals(sku.Version)).Sum(s => s.ActiveStock);
                                model.Version.Add(new Himall.Web.Areas.Web.Models.ProductSKU
                                {
                                    //Name = "选择版本",
                                    Name         = "选择" + versionAlias,
                                    EnabledClass = v != 0 ? "enabled" : "disabled",
                                    //SelectedClass = !model.Version.Any(v1 => v1.SelectedClass.Equals("selected")) && v != 0 ? "selected" : "",
                                    SelectedClass = "",
                                    SkuId         = versionId,
                                    Value         = sku.Version
                                });
                            }
                        }
                    }
                }
            }
            #endregion

            return(View(model));
        }
Exemple #3
0
        public object GetLimitBuyProduct(long id)
        {
            ProductDetailModelForMobie model = new ProductDetailModelForMobie()
            {
                Product = new ProductInfoModel(),
                Shop    = new ShopInfoModel(),
                Color   = new CollectionSKU(),
                Size    = new CollectionSKU(),
                Version = new CollectionSKU()
            };

            Entities.ProductInfo product = null;
            Entities.ShopInfo    shop    = null;
            FlashSaleModel       market  = null;

            market = ServiceProvider.Instance <ILimitTimeBuyService> .Create.Get(id);

            if (market == null || market.Status != FlashSaleInfo.FlashSaleStatus.Ongoing)
            {
                //可能参数是商品ID
                market = market == null ? ServiceProvider.Instance <ILimitTimeBuyService> .Create.GetFlaseSaleByProductId(id) : market;

                if (market == null || market.Status != FlashSaleInfo.FlashSaleStatus.Ongoing)
                {
                    //跳转到404页面
                    throw new MallApiException("你所请求的限时购或者商品不存在!");
                }
            }

            if (market != null && (market.Status != FlashSaleInfo.FlashSaleStatus.Ongoing || DateTime.Parse(market.EndDate) < DateTime.Now))
            {
                return(new { success = true, IsValidLimitBuy = false });
            }

            model.MaxSaleCount = market.LimitCountOfThePeople;
            model.Title        = market.Title;

            product = ServiceProvider.Instance <IProductService> .Create.GetProduct(market.ProductId);

            bool hasSku = false;

            #region 商品SKU
            Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetType(product.TypeId);

            string colorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
            string sizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
            string versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
            if (product != null)
            {
                colorAlias   = !string.IsNullOrWhiteSpace(product.ColorAlias) ? product.ColorAlias : colorAlias;
                sizeAlias    = !string.IsNullOrWhiteSpace(product.SizeAlias) ? product.SizeAlias : sizeAlias;
                versionAlias = !string.IsNullOrWhiteSpace(product.VersionAlias) ? product.VersionAlias : versionAlias;
            }
            var skus = ProductManagerApplication.GetSKUs(product.Id);
            if (skus.Count > 0)
            {
                hasSku = true;
                long colorId = 0, sizeId = 0, versionId = 0;
                foreach (var sku in skus)
                {
                    var specs = sku.Id.Split('_');
                    if (specs.Count() > 0 && !string.IsNullOrEmpty(sku.Color))
                    {
                        if (long.TryParse(specs[1], out colorId))
                        {
                        }
                        if (colorId != 0)
                        {
                            if (!model.Color.Any(v => v.Value == sku.Color))
                            {
                                var c = skus.Where(s => s.Color == sku.Color).Sum(s => s.Stock);
                                model.Color.Add(new ProductSKU
                                {
                                    //Name = "选择颜色" ,
                                    Name          = "选择" + colorAlias,
                                    EnabledClass  = c != 0 ? "enabled" : "disabled",
                                    SelectedClass = "",
                                    SkuId         = colorId,
                                    Value         = sku.Color,
                                    Img           = sku.ShowPic
                                });
                            }
                        }
                    }
                    if (specs.Count() > 1 && !string.IsNullOrEmpty(sku.Size))
                    {
                        if (long.TryParse(specs[2], out sizeId))
                        {
                        }
                        if (sizeId != 0)
                        {
                            if (!model.Size.Any(v => v.Value.Equals(sku.Size)))
                            {
                                var ss = skus.Where(s => s.Size.Equals(sku.Size)).Sum(s1 => s1.Stock);
                                model.Size.Add(new ProductSKU
                                {
                                    //Name = "选择尺码" ,
                                    Name         = "选择" + sizeAlias,
                                    EnabledClass = ss != 0 ? "enabled" : "disabled",
                                    //SelectedClass = !model.Size.Any(s1 => s1.SelectedClass.Equals("selected")) && ss != 0 ? "selected" : "",
                                    SelectedClass = "",
                                    SkuId         = sizeId,
                                    Value         = sku.Size
                                });
                            }
                        }
                    }

                    if (specs.Count() > 2 && !string.IsNullOrEmpty(sku.Version))
                    {
                        if (long.TryParse(specs[3], out versionId))
                        {
                        }
                        if (versionId != 0)
                        {
                            if (!model.Version.Any(v => v.Value.Equals(sku.Version)))
                            {
                                var v = skus.Where(s => s.Version.Equals(sku.Version)).Sum(s => s.Stock);
                                model.Version.Add(new ProductSKU
                                {
                                    //Name = "选择版本" ,
                                    Name         = "选择" + versionAlias,
                                    EnabledClass = v != 0 ? "enabled" : "disabled",
                                    //SelectedClass = !model.Version.Any(v1 => v1.SelectedClass.Equals("selected")) && v != 0 ? "selected" : "",
                                    SelectedClass = "",
                                    SkuId         = versionId,
                                    Value         = sku.Version
                                });
                            }
                        }
                    }
                }
            }
            #endregion

            #region 店铺
            shop = ServiceProvider.Instance <IShopService> .Create.GetShop(product.ShopId);

            var mark = Web.Framework.ShopServiceMark.GetShopComprehensiveMark(shop.Id);
            model.Shop.PackMark          = mark.PackMark;
            model.Shop.ServiceMark       = mark.ServiceMark;
            model.Shop.ComprehensiveMark = mark.ComprehensiveMark;
            model.Shop.Name        = shop.ShopName;
            model.Shop.ProductMark = CommentApplication.GetProductAverageMark(product.Id);
            model.Shop.Id          = product.ShopId;
            model.Shop.FreeFreight = shop.FreeFreight;
            model.Shop.ProductNum  = ServiceProvider.Instance <IProductService> .Create.GetShopOnsaleProducts(product.ShopId);


            var shopStatisticOrderComments = ServiceProvider.Instance <IShopService> .Create.GetShopStatisticOrderComments(product.ShopId);

            var productAndDescription = shopStatisticOrderComments.FirstOrDefault(c => c.CommentKey == StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescription);
            var sellerServiceAttitude = shopStatisticOrderComments.FirstOrDefault(c => c.CommentKey == StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitude);
            var sellerDeliverySpeed   = shopStatisticOrderComments.FirstOrDefault(c => c.CommentKey == StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeed);

            var productAndDescriptionPeer = shopStatisticOrderComments.FirstOrDefault(c => c.CommentKey == StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescriptionPeer);
            var sellerServiceAttitudePeer = shopStatisticOrderComments.FirstOrDefault(c => c.CommentKey == StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitudePeer);
            var sellerDeliverySpeedPeer   = shopStatisticOrderComments.FirstOrDefault(c => c.CommentKey == StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeedPeer);



            decimal defaultValue = 5;
            //宝贝与描述
            if (productAndDescription != null && productAndDescriptionPeer != null)
            {
                model.Shop.ProductAndDescription = productAndDescription.CommentValue;
            }
            else
            {
                model.Shop.ProductAndDescription = defaultValue;
            }
            //卖家服务态度
            if (sellerServiceAttitude != null && sellerServiceAttitudePeer != null)
            {
                model.Shop.SellerServiceAttitude = sellerServiceAttitude.CommentValue;
            }
            else
            {
                model.Shop.SellerServiceAttitude = defaultValue;
            }
            //卖家发货速度
            if (sellerDeliverySpeedPeer != null && sellerDeliverySpeed != null)
            {
                model.Shop.SellerDeliverySpeed = sellerDeliverySpeed.CommentValue;
            }
            else
            {
                model.Shop.SellerDeliverySpeed = defaultValue;
            }
            if (ServiceProvider.Instance <IVShopService> .Create.GetVShopByShopId(shop.Id) == null)
            {
                model.Shop.VShopId = -1;
            }
            else
            {
                model.Shop.VShopId = ServiceProvider.Instance <IVShopService> .Create.GetVShopByShopId(shop.Id).Id;
            }

            //优惠券
            var result = GetCouponList(shop.Id);//取设置的优惠券
            if (result != null)
            {
                var couponCount = result.Count();
                model.Shop.CouponCount = couponCount;
            }
            #endregion

            #region 商品
            var consultations = ServiceProvider.Instance <IConsultationService> .Create.GetConsultations(product.Id);

            var  comments   = CommentApplication.GetCommentsByProduct(product.Id);
            var  total      = comments.Count;
            var  niceTotal  = comments.Count(item => item.ReviewMark >= 4);
            bool isFavorite = false;
            if (CurrentUser == null)
            {
                isFavorite = false;
            }
            else
            {
                isFavorite = ServiceProvider.Instance <IProductService> .Create.IsFavorite(product.Id, CurrentUser.Id);
            }
            var limitBuy = ServiceProvider.Instance <ILimitTimeBuyService> .Create.GetLimitTimeMarketItemByProductId(product.Id);

            var productImage = new List <string>();

            var env = EngineContext.Current.Resolve <IWebHostEnvironment>();

            for (int i = 1; i < 6; i++)
            {
                if (System.IO.File.Exists(env.ContentRootPath + product.RelativePath + string.Format("/{0}.png", i)))
                {
                    productImage.Add(Core.MallIO.GetRomoteImagePath(product.RelativePath + string.Format("/{0}.png", i)));
                }
            }
            var desc = ProductManagerApplication.GetProductDescription(product.Id);
            model.Product = new ProductInfoModel()
            {
                ProductId          = product.Id,
                CommentCount       = CommentApplication.GetCommentCountByProduct(product.Id),
                Consultations      = consultations.Count(),
                ImagePath          = productImage,
                IsFavorite         = isFavorite,
                MarketPrice        = market.MinPrice,
                MinSalePrice       = product.MinSalePrice,
                NicePercent        = model.Shop.ProductMark == 0 ? 100 : (int)((niceTotal / total) * 100),
                ProductName        = product.ProductName,
                ProductSaleStatus  = product.SaleStatus,
                AuditStatus        = product.AuditStatus,
                ShortDescription   = product.ShortDescription,
                ProductDescription = desc.ShowMobileDescription,
                MeasureUnit        = product.MeasureUnit,
                IsOnLimitBuy       = limitBuy != null,
                VideoPath          = string.IsNullOrWhiteSpace(product.VideoPath) ? string.Empty : Mall.Core.MallIO.GetRomoteImagePath(product.VideoPath),
            };
            #endregion

            LogProduct(market.ProductId);
            //统计商品浏览量、店铺浏览人数
            StatisticApplication.StatisticVisitCount(product.Id, product.ShopId);

            TimeSpan end    = new TimeSpan(DateTime.Parse(market.EndDate).Ticks);
            TimeSpan start  = new TimeSpan(DateTime.Now.Ticks);
            TimeSpan ts     = end.Subtract(start);
            var      second = ts.TotalSeconds < 0 ? 0 : ts.TotalSeconds;

            return(new
            {
                success = true,
                IsOnLimitBuy = true,
                HasSku = hasSku,
                MaxSaleCount = market.LimitCountOfThePeople,
                Title = market.Title,
                Second = second,
                Product = model.Product,
                Shop = model.Shop,
                Color = model.Color.OrderBy(p => p.SkuId),
                Size = model.Size.OrderBy(p => p.SkuId),
                Version = model.Version.OrderBy(p => p.SkuId),
                ColorAlias = colorAlias,
                SizeAlias = sizeAlias,
                VersionAlias = versionAlias
            });
        }
Exemple #4
0
        public ActionResult Detail(string id)
        {
            LimitTimeBuyDetailModel detailModel = new LimitTimeBuyDetailModel();
            string price = "";

            #region 定义Model和变量

            LimitTimeProductDetailModel model = new LimitTimeProductDetailModel
            {
                MainId = long.Parse(id),
                HotAttentionProducts = new List <HotProductInfo>(),
                HotSaleProducts      = new List <HotProductInfo>(),
                Product      = new Entities.ProductInfo(),
                Shop         = new ShopInfoModel(),
                ShopCategory = new List <CategoryJsonModel>(),
                Color        = new CollectionSKU(),
                Size         = new CollectionSKU(),
                Version      = new CollectionSKU()
            };

            FlashSaleModel    market = null;
            Entities.ShopInfo shop   = null;

            long gid = 0, mid = 0;

            #endregion

            #region 商品Id不合法
            if (long.TryParse(id, out mid))
            {
            }
            if (mid == 0)
            {
                //跳转到出错页面
                return(RedirectToAction("Error404", "Error", new { area = "Mobile" }));
            }
            #endregion

            #region 初始化商品和店铺
            //参数是限时购活动ID
            try
            {
                market = _iLimitTimeBuyService.Get(mid);
            }
            catch
            {
                market = null;
            }
            if (market != null)
            {
                switch (market.Status)
                {
                case FlashSaleInfo.FlashSaleStatus.Ended:
                    return(RedirectToAction("Detail", "Product", new { id = market.ProductId }));

                case FlashSaleInfo.FlashSaleStatus.Cancelled:
                    return(RedirectToAction("Detail", "Product", new { id = market.ProductId }));
                }

                model.FlashSale = market;
            }
            if (market == null || market.Status != FlashSaleInfo.FlashSaleStatus.Ongoing)
            {
                //可能参数是商品ID
                market = market == null?_iLimitTimeBuyService.GetFlaseSaleByProductId(mid) : market;

                if (market == null)
                {
                    //跳转到404页面
                    return(RedirectToAction("Error404", "Error", new { area = "Mobile" }));
                }
                if (market.Status != FlashSaleInfo.FlashSaleStatus.Ongoing)
                {
                    return(RedirectToAction("Detail", "Product", new { id = market.ProductId }));
                }
                market = _iLimitTimeBuyService.Get(market.Id);
            }
            model.FlashSale = market;

            if (market != null && (market.Status != FlashSaleInfo.FlashSaleStatus.Ongoing || DateTime.Parse(market.EndDate) < DateTime.Now))
            {
                return(RedirectToAction("Detail", "Product", new { id = market.ProductId }));
            }

            model.MaxSaleCount = market.LimitCountOfThePeople;
            model.Title        = market.Title;

            shop = _iShopService.GetShop(market.ShopId);

            #endregion

            #region  存在的商品
            if (null == market || market.Id == 0)
            {
                //跳转到出错页面
                return(RedirectToAction("Error404", "Error", new { area = "Web" }));
            }
            #endregion

            #region 商品描述
            var product = _iProductService.GetProduct(market.ProductId);
            gid = market.ProductId;

            model.Product = product;
            var description = ProductManagerApplication.GetProductDescription(product.Id);
            model.ProductDescription = description.ShowMobileDescription;
            if (description.DescriptionPrefixId != 0)
            {
                var desc = _iProductDescriptionTemplateService
                           .GetTemplate(description.DescriptionPrefixId, product.ShopId);
                model.DescriptionPrefix = desc == null ? "" : desc.Content;
            }

            if (description.DescriptiondSuffixId != 0)
            {
                var desc = _iProductDescriptionTemplateService
                           .GetTemplate(description.DescriptiondSuffixId, product.ShopId);
                model.DescriptiondSuffix = desc == null ? "" : desc.Content;
            }

            var mark = ShopServiceMark.GetShopComprehensiveMark(shop.Id);
            model.Shop.PackMark          = mark.PackMark;
            model.Shop.ServiceMark       = mark.ServiceMark;
            model.Shop.ComprehensiveMark = mark.ComprehensiveMark;
            model.Shop.Name               = shop.ShopName;
            model.Shop.ProductMark        = CommentApplication.GetProductAverageMark(gid);
            model.Shop.Id                 = product.ShopId;
            model.Shop.FreeFreight        = shop.FreeFreight;
            detailModel.ProductNum        = _iProductService.GetShopOnsaleProducts(product.ShopId);
            detailModel.FavoriteShopCount = _iShopService.GetShopFavoritesCount(product.ShopId);
            if (CurrentUser == null)
            {
                detailModel.IsFavorite     = false;
                detailModel.IsFavoriteShop = false;
            }
            else
            {
                detailModel.IsFavorite = _iProductService.IsFavorite(product.Id, CurrentUser.Id);
                var favoriteShopIds = _iShopService.GetFavoriteShopInfos(CurrentUser.Id).Select(item => item.ShopId).ToArray();//获取已关注店铺
                detailModel.IsFavoriteShop = favoriteShopIds.Contains(product.ShopId);
            }
            #endregion

            #region 店铺分类

            var categories = _iShopCategoryService.GetShopCategory(product.ShopId);
            List <Entities.ShopCategoryInfo> allcate = categories.ToList();
            foreach (var main in allcate.Where(s => s.ParentCategoryId == 0))
            {
                var topC = new CategoryJsonModel()
                {
                    Name        = main.Name,
                    Id          = main.Id.ToString(),
                    SubCategory = new List <SecondLevelCategory>()
                };
                foreach (var secondItem in allcate.Where(s => s.ParentCategoryId == main.Id))
                {
                    var secondC = new SecondLevelCategory()
                    {
                        Name = secondItem.Name,
                        Id   = secondItem.Id.ToString(),
                    };

                    topC.SubCategory.Add(secondC);
                }
                model.ShopCategory.Add(topC);
            }

            #endregion

            #region 热门销售

            var sale = _iProductService.GetHotSaleProduct(shop.Id, 5);
            if (sale != null)
            {
                foreach (var item in sale.ToArray())
                {
                    model.HotSaleProducts.Add(new HotProductInfo
                    {
                        ImgPath   = item.ImagePath,
                        Name      = item.ProductName,
                        Price     = item.MinSalePrice,
                        Id        = item.Id,
                        SaleCount = (int)item.SaleCounts + Mall.Core.Helper.TypeHelper.ObjectToInt(item.VirtualSaleCounts)
                    });
                }
            }

            #endregion

            #region 热门关注

            var hot = _iProductService.GetHotConcernedProduct(shop.Id, 5);
            if (hot != null)
            {
                foreach (var item in hot.ToArray())
                {
                    model.HotAttentionProducts.Add(new HotProductInfo
                    {
                        ImgPath   = item.ImagePath,
                        Name      = item.ProductName,
                        Price     = item.MinSalePrice,
                        Id        = item.Id,
                        SaleCount = (int)item.ConcernedCount
                    });
                }
            }
            #endregion

            #region 商品规格

            Entities.TypeInfo typeInfo     = _iTypeService.GetType(product.TypeId);
            string            colorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
            string            sizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
            string            versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
            if (product != null)
            {
                colorAlias   = !string.IsNullOrWhiteSpace(product.ColorAlias) ? product.ColorAlias : colorAlias;
                sizeAlias    = !string.IsNullOrWhiteSpace(product.SizeAlias) ? product.SizeAlias : sizeAlias;
                versionAlias = !string.IsNullOrWhiteSpace(product.VersionAlias) ? product.VersionAlias : versionAlias;
            }
            model.ColorAlias   = colorAlias;
            model.SizeAlias    = sizeAlias;
            model.VersionAlias = versionAlias;
            var skus = ProductManagerApplication.GetSKUs(product.Id);
            if (skus.Count > 0)
            {
                long colorId = 0, sizeId = 0, versionId = 0;
                foreach (var sku in skus)
                {
                    var specs = sku.Id.Split('_');
                    if (specs.Count() > 0 && !string.IsNullOrEmpty(sku.Color))
                    {
                        if (long.TryParse(specs[1], out colorId))
                        {
                        }
                        if (colorId != 0)
                        {
                            if (!model.Color.Any(v => v.Value.Equals(sku.Color)))
                            {
                                var c = skus.Where(s => s.Color.Equals(sku.Color)).Sum(s => s.Stock);
                                model.Color.Add(new ProductSKU
                                {
                                    //Name = "选择颜色",
                                    Name         = "选择" + colorAlias,
                                    EnabledClass = c != 0 ? "enabled" : "disabled",
                                    //SelectedClass = !model.Color.Any(c1 => c1.SelectedClass.Equals("selected")) && c != 0 ? "selected" : "",
                                    SelectedClass = "",
                                    SkuId         = colorId,
                                    Value         = sku.Color,
                                    Img           = Core.MallIO.GetImagePath(sku.ShowPic)
                                });
                            }
                        }
                    }
                    if (specs.Count() > 1 && !string.IsNullOrEmpty(sku.Size))
                    {
                        if (long.TryParse(specs[2], out sizeId))
                        {
                        }
                        if (sizeId != 0)
                        {
                            if (!model.Size.Any(v => v.Value.Equals(sku.Size)))
                            {
                                var ss = skus.Where(s => s.Size.Equals(sku.Size)).Sum(s1 => s1.Stock);
                                model.Size.Add(new ProductSKU
                                {
                                    //Name = "选择尺码",
                                    Name         = "选择" + sizeAlias,
                                    EnabledClass = ss != 0 ? "enabled" : "disabled",
                                    //SelectedClass = !model.Size.Any(s1 => s1.SelectedClass.Equals("selected")) && ss != 0 ? "selected" : "",
                                    SelectedClass = "",
                                    SkuId         = sizeId,
                                    Value         = sku.Size
                                });
                            }
                        }
                    }

                    if (specs.Count() > 2 && !string.IsNullOrEmpty(sku.Version))
                    {
                        if (long.TryParse(specs[3], out versionId))
                        {
                        }
                        if (versionId != 0)
                        {
                            if (!model.Version.Any(v => v.Value.Equals(sku.Version)))
                            {
                                var v = skus.Where(s => s.Version.Equals(sku.Version)).Sum(s => s.Stock);
                                model.Version.Add(new ProductSKU
                                {
                                    //Name = "选择版本",
                                    Name         = "选择" + versionAlias,
                                    EnabledClass = v != 0 ? "enabled" : "disabled",
                                    //SelectedClass = !model.Version.Any(v1 => v1.SelectedClass.Equals("selected")) && v != 0 ? "selected" : "",
                                    SelectedClass = "",
                                    SkuId         = versionId,
                                    Value         = sku.Version
                                });
                            }
                        }
                    }
                }
                //var min = skus.Where(s => s.Stock >= 0).Min(s => s.SalePrice);
                //var max = skus.Where(s => s.Stock >= 0).Max(s => s.SalePrice);
                //if (min == 0 && max == 0)
                //{
                //    price = product.MinSalePrice.ToString("f2");
                //}
                //else if (max > min)
                //{
                //    price = string.Format("{0}-{1}", min.ToString("f2"), max.ToString("f2"));
                //}
                //else
                //{
                //    price = string.Format("{0}", min.ToString("f2"));
                //}
                price = ProductWebApplication.GetProductPriceStr2(product, skus);//最小价或区间价文本
            }
            detailModel.Price = string.IsNullOrWhiteSpace(price) ? product.MinSalePrice.ToString("f2") : price;
            #endregion

            #region 商品属性
            List <TypeAttributesModel> ProductAttrs = new List <TypeAttributesModel>();
            var prodAttrs = ProductManagerApplication.GetProductAttributes(product.Id);
            foreach (var attr in prodAttrs)
            {
                if (!ProductAttrs.Any(p => p.AttrId == attr.AttributeId))
                {
                    var attribute = _iTypeService.GetAttribute(attr.AttributeId);
                    var values    = _iTypeService.GetAttributeValues(attr.AttributeId);
                    TypeAttributesModel attrModel = new TypeAttributesModel()
                    {
                        AttrId     = attr.AttributeId,
                        AttrValues = new List <TypeAttrValue>(),
                        Name       = attribute.Name
                    };
                    foreach (var attrV in values)
                    {
                        if (prodAttrs.Any(p => p.ValueId == attrV.Id))
                        {
                            attrModel.AttrValues.Add(new TypeAttrValue
                            {
                                Id   = attrV.Id.ToString(),
                                Name = attrV.Value
                            });
                        }
                    }
                    ProductAttrs.Add(attrModel);
                }
                else
                {
                    var attrTemp = ProductAttrs.FirstOrDefault(p => p.AttrId == attr.AttributeId);
                    var values   = _iTypeService.GetAttributeValues(attr.AttributeId);
                    if (!attrTemp.AttrValues.Any(p => p.Id == attr.ValueId.ToString()))
                    {
                        attrTemp.AttrValues.Add(new TypeAttrValue
                        {
                            Id   = attr.ValueId.ToString(),
                            Name = values.FirstOrDefault(a => a.Id == attr.ValueId).Value
                        });
                    }
                }
            }
            detailModel.ProductAttrs = ProductAttrs;
            #endregion

            #region 获取评论、咨询数量

            var comments = CommentApplication.GetCommentsByProduct(product.Id);
            detailModel.CommentCount = comments.Count;

            var consultations = ServiceApplication.Create <IConsultationService>().GetConsultations(gid);

            var total     = comments.Count;
            var niceTotal = comments.Count(item => item.ReviewMark >= 4);
            detailModel.NicePercent   = (int)((niceTotal / (double)total) * 100);
            detailModel.Consultations = consultations.Count();

            if (_iVShopService.GetVShopByShopId(shop.Id) == null)
            {
                detailModel.VShopId = -1;
            }
            else
            {
                detailModel.VShopId = _iVShopService.GetVShopByShopId(shop.Id).Id;
            }
            #endregion

            #region 累加浏览次数、 加入历史记录
            //if (CurrentUser != null)
            //{
            //    BrowseHistrory.AddBrowsingProduct(product.Id, CurrentUser.Id);
            //}
            //else
            //{
            //    BrowseHistrory.AddBrowsingProduct(product.Id);
            //}
            //_iProductService.LogProductVisti(gid);
            #endregion

            #region 获取店铺的评价统计
            var shopStatisticOrderComments = _iShopService.GetShopStatisticOrderComments(product.ShopId);

            var productAndDescription = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescription).FirstOrDefault();
            var sellerServiceAttitude = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitude).FirstOrDefault();
            var sellerDeliverySpeed   = shopStatisticOrderComments.Where(c => c.CommentKey ==
                                                                         Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeed).FirstOrDefault();

            var productAndDescriptionPeer = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescriptionPeer).FirstOrDefault();
            var sellerServiceAttitudePeer = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitudePeer).FirstOrDefault();
            var sellerDeliverySpeedPeer   = shopStatisticOrderComments.Where(c => c.CommentKey ==
                                                                             Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeedPeer).FirstOrDefault();

            var productAndDescriptionMax = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescriptionMax).FirstOrDefault();
            var productAndDescriptionMin = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescriptionMin).FirstOrDefault();

            var sellerServiceAttitudeMax = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitudeMax).FirstOrDefault();
            var sellerServiceAttitudeMin = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitudeMin).FirstOrDefault();

            var sellerDeliverySpeedMax = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeedMax).FirstOrDefault();
            var sellerDeliverySpeedMin = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeedMin).FirstOrDefault();

            decimal defaultValue = 5;
            //宝贝与描述
            if (productAndDescription != null && productAndDescriptionPeer != null && !shop.IsSelf)
            {
                detailModel.ProductAndDescription     = productAndDescription.CommentValue;
                detailModel.ProductAndDescriptionPeer = productAndDescriptionPeer.CommentValue;
                detailModel.ProductAndDescriptionMin  = productAndDescriptionMin.CommentValue;
                detailModel.ProductAndDescriptionMax  = productAndDescriptionMax.CommentValue;
            }
            else
            {
                detailModel.ProductAndDescription     = defaultValue;
                detailModel.ProductAndDescriptionPeer = defaultValue;
                detailModel.ProductAndDescriptionMin  = defaultValue;
                detailModel.ProductAndDescriptionMax  = defaultValue;
            }
            //卖家服务态度
            if (sellerServiceAttitude != null && sellerServiceAttitudePeer != null && !shop.IsSelf)
            {
                detailModel.SellerServiceAttitude     = sellerServiceAttitude.CommentValue;
                detailModel.SellerServiceAttitudePeer = sellerServiceAttitudePeer.CommentValue;
                detailModel.SellerServiceAttitudeMax  = sellerServiceAttitudeMax.CommentValue;
                detailModel.SellerServiceAttitudeMin  = sellerServiceAttitudeMin.CommentValue;
            }
            else
            {
                detailModel.SellerServiceAttitude     = defaultValue;
                detailModel.SellerServiceAttitudePeer = defaultValue;
                detailModel.SellerServiceAttitudeMax  = defaultValue;
                detailModel.SellerServiceAttitudeMin  = defaultValue;
            }
            //卖家发货速度
            if (sellerDeliverySpeedPeer != null && sellerDeliverySpeed != null && !shop.IsSelf)
            {
                detailModel.SellerDeliverySpeed     = sellerDeliverySpeed.CommentValue;
                detailModel.SellerDeliverySpeedPeer = sellerDeliverySpeedPeer.CommentValue;
                detailModel.SellerDeliverySpeedMax  = sellerDeliverySpeedMax != null ? sellerDeliverySpeedMax.CommentValue : 0;
                detailModel.sellerDeliverySpeedMin  = sellerDeliverySpeedMin != null ? sellerDeliverySpeedMin.CommentValue : 0;
            }
            else
            {
                detailModel.SellerDeliverySpeed     = defaultValue;
                detailModel.SellerDeliverySpeedPeer = defaultValue;
                detailModel.SellerDeliverySpeedMax  = defaultValue;
                detailModel.sellerDeliverySpeedMin  = defaultValue;
            }
            #endregion

            #region 是否收藏此商品
            if (CurrentUser != null && CurrentUser.Id > 0)
            {
                model.IsFavorite = _iProductService.IsFavorite(product.Id, CurrentUser.Id);
            }
            else
            {
                model.IsFavorite = false;
            }
            #endregion

            long vShopId;
            var  vshopinfo = _iVShopService.GetVShopByShopId(shop.Id);
            if (vshopinfo == null)
            {
                vShopId = -1;
            }
            else
            {
                vShopId = vshopinfo.Id;
            }
            detailModel.VShopId = vShopId;
            model.Shop.VShopId  = vShopId;

            model.VShopLog = _iVShopService.GetVShopLog(model.Shop.VShopId);
            if (string.IsNullOrWhiteSpace(model.VShopLog))
            {
                //throw new Mall.Core.MallException("店铺未开通微店功能");
                model.VShopLog = SiteSettings.WXLogo;
            }
            detailModel.Logined = (null != CurrentUser) ? 1 : 0;
            model.EnabledBuy    = product.AuditStatus == Entities.ProductInfo.ProductAuditStatus.Audited && DateTime.Parse(market.BeginDate) <= DateTime.Now && DateTime.Parse(market.EndDate) > DateTime.Now && product.SaleStatus == Entities.ProductInfo.ProductSaleStatus.OnSale;
            int saleCounts = 0;
            saleCounts = market.SaleCount;
            if (market.Status == FlashSaleInfo.FlashSaleStatus.Ongoing && DateTime.Parse(market.BeginDate) < DateTime.Now && DateTime.Parse(market.EndDate) > DateTime.Now)
            {
                TimeSpan end   = new TimeSpan(DateTime.Parse(market.EndDate).Ticks);
                TimeSpan start = new TimeSpan(DateTime.Now.Ticks);
                TimeSpan ts    = end.Subtract(start);
                detailModel.Second = ts.TotalSeconds < 0 ? 0 : ts.TotalSeconds;
            }
            else if (market.Status == FlashSaleInfo.FlashSaleStatus.Ongoing && DateTime.Parse(market.BeginDate) > DateTime.Now)
            {
                TimeSpan end   = new TimeSpan(DateTime.Parse(market.BeginDate).Ticks);
                TimeSpan start = new TimeSpan(DateTime.Now.Ticks);
                TimeSpan ts    = end.Subtract(start);
                detailModel.Second = ts.TotalSeconds < 0 ? 0 : ts.TotalSeconds;
                saleCounts         = Mall.Core.Helper.TypeHelper.ObjectToInt(product.SaleCounts) + Mall.Core.Helper.TypeHelper.ObjectToInt(product.VirtualSaleCounts);
            }
            ViewBag.DetailModel = detailModel;

            var customerServices = CustomerServiceApplication.GetMobileCustomerServiceAndMQ(market.ShopId);
            ViewBag.CustomerServices = customerServices;

            //统计商品浏览量、店铺浏览人数
            StatisticApplication.StatisticVisitCount(product.Id, product.ShopId);

            model.IsSaleCountOnOff = SiteSettingApplication.SiteSettings.ProductSaleCountOnOff == 1;                                          //是否显示销量
            model.SaleCount        = saleCounts;                                                                                              //销量
            model.FreightTemplate  = FreightTemplateApplication.GetFreightTemplate(product.FreightTemplateId);
            model.Freight          = FreightTemplateApplication.GetFreightStr(market.ProductId, model.FreightTemplate, CurrentUser, product); //运费或免运费
            model.StockAll         = market.Quantity;

            return(View(model));
        }
Exemple #5
0
        /// <summary>
        /// 退款申请
        /// </summary>
        /// <param name="id"></param>
        /// <param name="itemId"></param>
        /// <returns></returns>
        public ActionResult RefundApply(long orderid, long?itemId, long?refundid)
        {
            RefundApplyModel model = new RefundApplyModel();

            model.RefundMode  = null;
            model.OrderItemId = null;
            var order = _iOrderService.GetOrder(orderid, CurrentUser.Id);

            if (order == null)
            {
                throw new Mall.Core.MallException("该订单已删除或不属于该用户");
            }
            if (order.OrderType != OrderInfo.OrderTypes.Virtual && (int)order.OrderStatus < 2)
            {
                throw new Mall.Core.MallException("错误的售后申请,订单状态有误");
            }
            if (order.OrderType != OrderInfo.OrderTypes.Virtual && itemId == null && order.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitDelivery && order.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp)
            {
                throw new Mall.Core.MallException("错误的订单退款申请,订单状态有误");
            }
            //售后时间限制
            if (order.OrderType != OrderInfo.OrderTypes.Virtual && _iOrderService.IsRefundTimeOut(orderid))
            {
                throw new Mall.Core.MallException("订单已超过售后期");
            }
            if (order.OrderType == OrderInfo.OrderTypes.Virtual)
            {
                //如果为虚拟商品,则要判断该商品是否允许退款,且该订单中是否至少有一个待核销的核销码
                var orderItemInfo = OrderApplication.GetOrderItemsByOrderId(order.Id).FirstOrDefault();
                if (orderItemInfo != null)
                {
                    itemId = orderItemInfo.Id;
                    var virtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(orderItemInfo.ProductId);
                    if (virtualProductInfo != null)
                    {
                        if (virtualProductInfo.SupportRefundType == 3)
                        {
                            throw new Mall.Core.MallException("该商品不支持退款");
                        }
                        if (virtualProductInfo.SupportRefundType == 1 && DateTime.Now > virtualProductInfo.EndDate.Value)
                        {
                            throw new Mall.Core.MallException("该商品不支持过期退款");
                        }
                        var orderVerificationCodes = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>()
                        {
                            order.Id
                        });
                        long num = orderVerificationCodes.Where(a => a.Status == OrderInfo.VerificationCodeStatus.WaitVerification).Count();
                        if (num == 0)
                        {
                            throw new Mall.Core.MallException("该商品没有可退的核销码");
                        }
                    }
                }
            }

            //计算可退金额 预留
            _iOrderService.CalculateOrderItemRefund(orderid);

            var item = new Entities.OrderItemInfo();

            model.MaxRefundGoodsNumber = 0;
            model.MaxRefundAmount      = order.OrderEnabledRefundAmount;
            if (itemId == null)
            {
                model.OrderItems = _iOrderService.GetOrderItemsByOrderId(order.Id);
                if (model.OrderItems.Count == 1)
                {
                    item = model.OrderItems.FirstOrDefault();
                }
            }
            else
            {
                item = _iOrderService.GetOrderItem(itemId.Value);
                model.OrderItems.Add(item);
                model.MaxRefundGoodsNumber = item.Quantity - item.ReturnQuantity;
                model.MaxRefundAmount      = item.EnabledRefundAmount - item.RefundPrice;
            }
            if (order.OrderType == OrderInfo.OrderTypes.Virtual)
            {
                var count = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>()
                {
                    order.Id
                }).Where(a => a.Status != OrderInfo.VerificationCodeStatus.WaitVerification).ToList().Count;
                if (item.EnabledRefundAmount.HasValue)
                {
                    decimal price = item.EnabledRefundAmount.Value / item.Quantity;
                    model.MaxRefundAmount = item.EnabledRefundAmount.Value - Math.Round(count * price, 2, MidpointRounding.AwayFromZero);
                }
            }
            foreach (var orderItem in model.OrderItems)
            {
                Entities.TypeInfo typeInfo = _iTypeService.GetTypeByProductId(orderItem.ProductId);
                var productInfo            = ProductManagerApplication.GetProduct(orderItem.ProductId);
                orderItem.ColorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                orderItem.SizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                orderItem.VersionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                if (productInfo != null)
                {
                    orderItem.ColorAlias   = !string.IsNullOrWhiteSpace(productInfo.ColorAlias) ? productInfo.ColorAlias : orderItem.ColorAlias;
                    orderItem.SizeAlias    = !string.IsNullOrWhiteSpace(productInfo.SizeAlias) ? productInfo.SizeAlias : orderItem.SizeAlias;
                    orderItem.VersionAlias = !string.IsNullOrWhiteSpace(productInfo.VersionAlias) ? productInfo.VersionAlias : orderItem.VersionAlias;
                }
            }
            if (!model.MaxRefundAmount.HasValue)
            {
                model.MaxRefundAmount = 0;
            }
            bool isCanApply = false;
            var  refundser  = _iRefundService;

            Entities.OrderRefundInfo refunddata;

            if (order.OrderStatus == Entities.OrderInfo.OrderOperateStatus.WaitDelivery)
            {
                isCanApply = refundser.CanApplyRefund(orderid, item.Id);
            }
            else
            {
                isCanApply = refundser.CanApplyRefund(orderid, item.Id, false);
            }
            if (!refundid.HasValue)
            {
                if (order.OrderType != OrderInfo.OrderTypes.Virtual)
                {
                    if (!isCanApply)
                    {
                        var orderRefunds = OrderApplication.GetOrderRefunds(new long[] { item.Id });
                        if (orderRefunds.Count == 1)
                        {
                            Response.Redirect("/OrderRefund/Detail/" + orderRefunds[0].Id);
                        }

                        throw new Mall.Core.MallException("您已申请过售后,不可重复申请");
                    }
                }
                //model.ContactPerson = CurrentUser.RealName;
                //model.ContactCellPhone = CurrentUser.CellPhone;
                //model.ContactCellPhone = order.CellPhone;

                model.ContactPerson    = string.IsNullOrEmpty(order.ShipTo) ? CurrentUser.RealName : order.ShipTo;
                model.ContactCellPhone = string.IsNullOrEmpty(order.CellPhone) ? CurrentUser.CellPhone : order.CellPhone;
                model.OrderItemId      = itemId;
                if (!model.OrderItemId.HasValue)
                {
                    model.IsOrderAllRefund = true;
                    model.RefundMode       = Entities.OrderRefundInfo.OrderRefundMode.OrderRefund;
                }
            }
            else
            {
                refunddata = refundser.GetOrderRefund(refundid.Value, CurrentUser.Id);
                if (refunddata == null)
                {
                    throw new Mall.Core.MallException("错误的售后数据");
                }
                if (order.OrderType != OrderInfo.OrderTypes.Virtual && refunddata.SellerAuditStatus != Entities.OrderRefundInfo.OrderRefundAuditStatus.UnAudit)
                {
                    throw new Mall.Core.MallException("错误的售后状态,不可激活");
                }
                model.ContactPerson      = refunddata.ContactPerson;
                model.ContactCellPhone   = refunddata.ContactCellPhone;
                model.OrderItemId        = refunddata.OrderItemId;
                model.IsOrderAllRefund   = (refunddata.RefundMode == Entities.OrderRefundInfo.OrderRefundMode.OrderRefund);
                model.RefundMode         = refunddata.RefundMode;
                model.RefundReasonValue  = refunddata.Reason;
                model.RefundReasonDetail = refunddata.ReasonDetail;
                model.RefundWayValue     = refunddata.RefundPayType;
                model.CertPic1           = refunddata.CertPic1;
                model.CertPic2           = refunddata.CertPic2;
                model.CertPic3           = refunddata.CertPic3;
            }
            if (!model.IsOrderAllRefund && item.EnabledRefundAmount.HasValue)
            {
                model.RefundGoodsPrice = item.EnabledRefundAmount.Value / item.Quantity;
            }
            model.OrderInfo = order;
            model.OrderId   = orderid;
            model.RefundId  = refundid;

            var reasons = refundser.GetRefundReasons();

            foreach (var _ir in reasons)
            {
                _ir.AfterSalesText = _ir.AfterSalesText.Trim();
            }
            List <SelectListItem> reasel = new List <SelectListItem>();
            SelectListItem        _tmpsel;

            _tmpsel = new SelectListItem {
                Text = "选择售后理由", Value = ""
            };
            reasel.Add(_tmpsel);
            foreach (var _i in reasons)
            {
                _tmpsel = new SelectListItem {
                    Text = _i.AfterSalesText, Value = _i.AfterSalesText
                };
                if (!string.IsNullOrWhiteSpace(model.RefundReasonValue))
                {
                    if (_i.AfterSalesText == model.RefundReasonValue)
                    {
                        _tmpsel.Selected = true;
                    }
                }
                reasel.Add(_tmpsel);
            }
            model.RefundReasons = reasel;

            List <SelectListItem> list = new List <SelectListItem> {
                new SelectListItem {
                    Text  = OrderRefundInfo.OrderRefundPayType.BackCapital.ToDescription(),
                    Value = ((int)OrderRefundInfo.OrderRefundPayType.BackCapital).ToString()
                }
            };

            if (order.CanBackOut())
            {
                _tmpsel = new SelectListItem
                {
                    Text  = OrderRefundInfo.OrderRefundPayType.BackOut.ToDescription(),
                    Value = ((int)OrderRefundInfo.OrderRefundPayType.BackOut).ToString()
                };
                //if (model.RefundWayValue.HasValue)
                //{
                //    if (_tmpsel.Value == model.RefundWayValue.ToString())
                //    {
                //        _tmpsel.Selected = true;
                //    }
                //}
                _tmpsel.Selected = true;  //若订单支付方式为支付宝、微信支付则退款方式默认选中“退款原路返回”
                list.Add(_tmpsel);
            }
            model.RefundWay = list;

            if (order.DeliveryType == CommonModel.DeliveryType.SelfTake)
            {
                var shopBranch = ShopBranchApplication.GetShopBranchById(order.ShopBranchId);
                model.ReturnGoodsAddress  = RegionApplication.GetFullName(shopBranch.AddressId);
                model.ReturnGoodsAddress += " " + shopBranch.AddressDetail;
                model.ReturnGoodsAddress += " " + shopBranch.ContactPhone;
            }

            ViewBag.Keyword  = string.IsNullOrWhiteSpace(SiteSettings.SearchKeyword) ? SiteSettings.Keyword : SiteSettings.SearchKeyword;
            ViewBag.Keywords = SiteSettings.HotKeyWords;
            #region 虚拟订单退款
            ViewBag.orderVerificationCode = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>()
            {
                order.Id
            }).Where(a => a.Status == OrderInfo.VerificationCodeStatus.WaitVerification).ToList();
            #endregion
            ViewBag.IsVirtual = order.OrderType == OrderInfo.OrderTypes.Virtual ? 1 : 0;
            return(View(model));
        }
Exemple #6
0
        /// <summary>
        /// 订单信息转换
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private trade_list_model OrderInfoMapChange(Entities.OrderInfo data)
        {
            #region 基础信息初始化
            var    UserInfo = _iMemberService.GetMemberByName(data.UserName);
            string state = "", city = "", district = "", town = "";
            if (!string.IsNullOrWhiteSpace(data.RegionFullName))
            {
                string[] adressArray = data.RegionFullName.Split(new string[] { " ", ",", "," }, StringSplitOptions.RemoveEmptyEntries);
                if (adressArray != null && adressArray.Length > 1)
                {
                    state    = adressArray[0];
                    city     = adressArray[1];
                    district = adressArray[2];
                    if (adressArray.Length == 4)
                    {
                        town = adressArray[3];
                    }
                    else
                    {
                        town = string.Empty;
                    }
                }
            }
            string status = string.Empty;
            switch (data.OrderStatus)
            {
            case Entities.OrderInfo.OrderOperateStatus.Close:
                status = "TRADE_CLOSED";
                break;

            case Entities.OrderInfo.OrderOperateStatus.Finish:
                status = "TRADE_FINISHED";
                break;

            case Entities.OrderInfo.OrderOperateStatus.WaitDelivery:
                status = "WAIT_SELLER_SEND_GOODS";
                //拼团订单信息修正
                if (data.OrderType == Entities.OrderInfo.OrderTypes.FightGroup)
                {
                    var fgord = _iFightGroupService.GetOrder(data.Id);
                    if (fgord != null)
                    {
                        if (fgord.GetJoinStatus != FightGroupOrderJoinStatus.BuildSuccess)
                        {
                            //未拼团成功的订单为待付款状态返回
                            status = "WAIT_BUYER_PAY";
                        }
                    }
                }
                break;

            case Entities.OrderInfo.OrderOperateStatus.WaitPay:
                status = "WAIT_BUYER_PAY";
                break;

            case Entities.OrderInfo.OrderOperateStatus.WaitReceiving:
                status = "WAIT_BUYER_CONFIRM_GOODS";
                break;

            default:
                status = string.Empty;
                break;
            }
            #endregion

            trade_list_model result = new trade_list_model();
            result.tid               = data.Id.ToString();
            result.buyer_memo        = data.PayRemark;
            result.seller_memo       = data.SellerRemark;
            result.seller_flag       = "";
            result.discount_fee      = data.DiscountAmount;
            result.status            = status;
            result.close_memo        = data.CloseReason;
            result.created           = data.OrderDate;
            result.modified          = data.OrderDate;
            result.pay_time          = data.PayDate;
            result.consign_time      = data.ShippingDate;
            result.end_time          = data.FinishDate;
            result.buyer_uname       = data.UserName;
            result.buyer_email       = UserInfo.Email;
            result.buyer_nick        = UserInfo.Nick;
            result.buyer_area        = regionService.GetFullName(UserInfo.RegionId, "");
            result.receiver_name     = data.ShipTo;
            result.receiver_state    = state;
            result.receiver_city     = city;
            result.receiver_district = district;
            result.receiver_town     = town;
            result.receiver_address  = data.Address;
            result.receiver_zip      = ""; //无邮编
            result.receiver_mobile   = data.CellPhone;
            result.seller_id         = data.ShopId.ToString();
            result.seller_name       = data.ShopName;
            result.seller_mobile     = data.SellerPhone;
            result.invoice_fee       = data.Tax;
            result.invoice_title     = "";  //data.InvoiceTitle;
            result.payment           = data.ProductTotalAmount;
            result.storeId           = "0"; //无门店功能,云商城有
            result.orders            = new List <trade_itme_model>();

            #region 子订单装配
            var orderitems = _iOrderService.GetOrderItemsByOrderId(data.Id);
            foreach (var orderitem in orderitems)
            {
                Entities.TypeInfo typeInfo = _iTypeService.GetTypeByProductId(orderitem.ProductId);
                var    productInfo         = Himall.Application.ProductManagerApplication.GetProduct(orderitem.ProductId);
                string colorAlias          = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                string sizeAlias           = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                string versionAlias        = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                if (productInfo != null)
                {
                    colorAlias   = !string.IsNullOrWhiteSpace(productInfo.ColorAlias) ? productInfo.ColorAlias : colorAlias;
                    sizeAlias    = !string.IsNullOrWhiteSpace(productInfo.SizeAlias) ? productInfo.SizeAlias : sizeAlias;
                    versionAlias = !string.IsNullOrWhiteSpace(productInfo.VersionAlias) ? productInfo.VersionAlias : versionAlias;
                }
                trade_itme_model tradesItem = new trade_itme_model();
                tradesItem.sku_id = orderitem.SkuId;
                //tradesItem.num_id = orderitem.SKU;
                tradesItem.outer_sku_id = orderitem.SKU;
                tradesItem.title        = orderitem.ProductName;
                string skuFullName = "";
                if (!string.IsNullOrEmpty(orderitem.Color))
                {
                    skuFullName = colorAlias + ":" + orderitem.Color + ";";
                }
                //skuFullName = "颜色:" + orderitem.Color + ";";
                if (!string.IsNullOrEmpty(orderitem.Size))
                {
                    skuFullName = sizeAlias + ":" + orderitem.Size + ";";
                }
                //skuFullName = "尺码:" + orderitem.Size + ";";
                if (!string.IsNullOrEmpty(orderitem.Version))
                {
                    skuFullName = versionAlias + ":" + orderitem.Version + ";";
                }
                //skuFullName = "版本:" + orderitem.Version + ";";
                if (!string.IsNullOrEmpty(skuFullName))
                {
                    skuFullName = skuFullName.TrimEnd(';');
                }
                tradesItem.sku_properties_name = skuFullName;
                tradesItem.price    = orderitem.SalePrice;
                tradesItem.num      = (int)orderitem.Quantity;
                tradesItem.pic_path = OpenAPIHelper.HostUrl + orderitem.ThumbnailsUrl;

                tradesItem.refund_status = status;
                result.orders.Add(tradesItem);
            }
            #endregion

            return(result);
        }
Exemple #7
0
        /// <summary>
        /// 商品信息转换
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private product_item_model ProductInfoMapChange(Entities.ProductInfo data)
        {
            var prodata = data;

            if (prodata == null)
            {
                throw new MallApiException(OpenApiErrorCode.Product_Not_Exists, "num_iid");
            }
            product_item_model result = new product_item_model();

            #region 装配信息
            result.num_iid    = (int)prodata.Id;
            result.outer_id   = prodata.ProductCode;
            result.brand_id   = (int)prodata.BrandId;
            result.brand_name = prodata.BrandName;
            result.cid        = (int)prodata.CategoryId;
            result.type_id    = (int)prodata.TypeId;

            var category = CategoryApplication.GetCategory(prodata.CategoryId);
            var desc     = ProductManagerApplication.GetProductDescription(prodata.Id);
            if (category != null)
            {
                result.cat_name = category.Name;
                var type = TypeApplication.GetType(category.TypeId);
                if (type != null)
                {
                    result.type_name = type.Name;
                }
            }
            result.title            = prodata.ProductName.Trim();
            result.list_time        = prodata.AddedDate;
            result.modified         = prodata.AddedDate;
            result.display_sequence = (int)prodata.DisplaySequence;
            result.sold_quantity    = (int)prodata.SaleCounts;
            result.desc             = desc.Description;
            result.wap_desc         = desc.MobileDescription;
            result.pic_url.Add(System.IO.Path.Combine(OpenAPIHelper.HostUrl, prodata.GetImage(ImageSize.Size_350, 1)));
            ProductStatus ps = GetProductStatus(prodata);
            result.approve_status = ps.ToString();

            #region 商品属性填充
            var prodAttrs      = ProductManagerApplication.GetProductAttributes(prodata.Id);
            var prodAttrids    = prodAttrs.Select(d => d.AttributeId).ToList();
            var prodAttrValues = _iTypeService.GetAttributeValues(prodAttrids);
            result.props_name = "";
            if (prodAttrids.Count > 0)
            {
                List <string> propslst    = new List <string>();
                List <string> propsvallst = new List <string>();
                foreach (var curattid in prodAttrids)
                {
                    var item = prodAttrs.FirstOrDefault(d => d.AttributeId == curattid);
                    propsvallst.Clear();
                    var attribute = _iTypeService.GetAttribute(item.AttributeId);
                    var values    = prodAttrValues.Where(p => p.AttributeId == curattid);
                    foreach (var attrV in values)
                    {
                        if (prodAttrs.Any(p => p.ValueId == attrV.Id))
                        {
                            propsvallst.Add(attrV.Value);
                        }
                    }
                    propslst.Add(attribute.Name + "#cln#[" + string.Join(",", propsvallst.ToArray()) + "]");
                }
                result.props_name = string.Join("#scln#", propslst.ToArray());
            }
            #endregion

            #region  发货地区

            var prolocid = FreightTemplateApplication.GetFreightTemplate(prodata.FreightTemplateId).SourceAddress;
            result.location = "";

            var locpath = _iRegionService.GetFullName(prolocid, ",");
            result.location = "{'city':'#c#', 'state':'#p#'}";
            if (!string.IsNullOrWhiteSpace(locpath))
            {
                var _tmparr = locpath.Split(',');
                result.location = result.location.Replace("#p#", _tmparr[0]);
                if (_tmparr.Length > 1)
                {
                    result.location = result.location.Replace("#c#", _tmparr[1]);
                }
                else
                {
                    result.location = result.location.Replace("#c#", "");
                }
            }

            #endregion

            #region SKUS

            Entities.TypeInfo typeInfo     = _iTypeService.GetType(data.TypeId);
            string            colorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
            string            sizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
            string            versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
            if (prodata != null)
            {
                colorAlias   = !string.IsNullOrWhiteSpace(prodata.ColorAlias) ? prodata.ColorAlias : colorAlias;
                sizeAlias    = !string.IsNullOrWhiteSpace(prodata.SizeAlias) ? prodata.SizeAlias : sizeAlias;
                versionAlias = !string.IsNullOrWhiteSpace(prodata.VersionAlias) ? prodata.VersionAlias : versionAlias;
            }
            result.skus = new List <product_sku_model>();
            var skus = ProductManagerApplication.GetSKUs(prodata.Id);
            foreach (var item in skus)
            {
                product_sku_model skudata = new product_sku_model();
                skudata.sku_id       = item.Id;
                skudata.outer_sku_id = item.Sku;
                skudata.price        = item.SalePrice;
                skudata.quantity     = (int)item.Stock;
                //skudata.sku_properties_name = "颜色:" + item.Color + "尺寸:" + item.Size + "版本:" + item.Version;
                skudata.sku_properties_name = colorAlias + ":" + item.Color + " " + sizeAlias + ":" + item.Size + " " + versionAlias + ":" + item.Version;
                string sku_properties_name = item.Color + " " + item.Size + " " + item.Version;
                if (string.IsNullOrWhiteSpace(sku_properties_name))
                {
                    skudata.sku_properties_name = "";
                }
                if (!string.IsNullOrWhiteSpace(skudata.sku_properties_name))
                {
                    result.skus.Add(skudata);
                }
            }
            #endregion

            #endregion

            return(result);
        }
Exemple #8
0
        public JsonResult List(int page, int rows, string productName, bool?isReply = null, int Rank = -1, bool hasAppend = false)
        {
            if (!string.IsNullOrEmpty(productName))
            {
                productName = productName.Trim();
            }
            var orderItemService = _iOrderService;
            var iTypeService     = _iTypeService;
            var query            = new CommentQuery()
            {
                PageNo = page, PageSize = rows, HasAppend = hasAppend, ProductName = productName, Rank = Rank, ShopID = base.CurrentSellerManager.ShopId, IsReply = isReply
            };
            var result       = _iCommentService.GetComments(query);
            var orderItemIds = result.Models.Select(a => a.SubOrderId).ToList();

            var orderItems = orderItemService.GetOrderItemsByOrderItemId(orderItemIds).ToDictionary(item => item.Id, item => item);
            var comments   = result.Models.Select(item =>
            {
                var product = ProductManagerApplication.GetProduct(item.ProductId);
                return(new ProductCommentModel()
                {
                    CommentContent = item.ReviewContent,
                    CommentDate = item.ReviewDate,
                    ReplyContent = item.ReplyContent,
                    AppendContent = item.AppendContent,
                    AppendDate = item.AppendDate,
                    ReplyAppendDate = item.ReplyAppendDate,
                    CommentMark = item.ReviewMark,
                    ReplyDate = item.ReplyDate,
                    Id = item.Id,
                    ProductName = (product == null) ? "" : product.ProductName,
                    ProductId = item.ProductId,
                    ImagePath = orderItems[item.SubOrderId].ThumbnailsUrl,
                    UserName = item.UserName,
                    OderItemId = item.SubOrderId,
                    Color = "",
                    Version = "",
                    Size = "",
                    UserId = item.UserId
                });
            }).ToList();

            //TODO LRL 2015/08/06 从评价信息添加商品的规格信息
            foreach (var item in comments)
            {
                item.ImagePath = Core.MallIO.GetProductSizeImage(item.ImagePath, 1, (int)ImageSize.Size_100);
                if (item.OderItemId.HasValue)
                {
                    var obj = orderItemService.GetOrderItem(item.OderItemId.Value);
                    if (obj != null)
                    {
                        item.Color   = obj.Color;
                        item.Size    = obj.Size;
                        item.Version = obj.Version;
                        item.OrderId = obj.OrderId;

                        var member = MemberApplication.GetMember(item.UserId);
                        if (member != null)
                        {
                            item.UserName  = member.UserName;
                            item.UserPhone = member.CellPhone;
                        }
                    }
                }
                Entities.TypeInfo typeInfo = iTypeService.GetTypeByProductId(item.ProductId);
                item.ColorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                item.SizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                item.VersionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                var productInfo = ProductManagerApplication.GetProduct(item.ProductId);
                if (productInfo != null)
                {
                    item.ColorAlias   = !string.IsNullOrWhiteSpace(productInfo.ColorAlias) ? productInfo.ColorAlias : item.ColorAlias;
                    item.SizeAlias    = !string.IsNullOrWhiteSpace(productInfo.SizeAlias) ? productInfo.SizeAlias : item.SizeAlias;
                    item.VersionAlias = !string.IsNullOrWhiteSpace(productInfo.VersionAlias) ? productInfo.VersionAlias : item.VersionAlias;
                }
            }
            DataGridModel <ProductCommentModel> model = new DataGridModel <ProductCommentModel>()
            {
                rows = comments, total = result.Total
            };

            return(Json(model));
        }
        public object GetVerificationRecordDetail(long id)
        {
            CheckUserLogin();

            var recordInfo = OrderApplication.GetVerificationRecordInfoById(id);

            if (recordInfo == null)
            {
                return new { success = false, msg = "错误的ID" }
            }
            ;

            var order = OrderApplication.GetOrderInfo(recordInfo.OrderId);

            if (order == null)
            {
                return new { success = false, msg = "该核销码无效" }
            }
            ;

            if (order.ShopBranchId != this.CurrentShopBranch.Id)
            {
                return new { success = false, msg = "非本店核销记录" }
            }
            ;

            var orderItem = Application.OrderApplication.GetOrderItemsByOrderId(order.Id);

            foreach (var item in orderItem)
            {
                item.ThumbnailsUrl = Core.HimallIO.GetRomoteProductSizeImage(item.ThumbnailsUrl, 1, (int)Himall.CommonModel.ImageSize.Size_100);

                Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetTypeByProductId(item.ProductId);

                item.ColorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                item.SizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                item.VersionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                var productInfo = ProductManagerApplication.GetProduct(item.ProductId);
                if (productInfo != null)
                {
                    item.ColorAlias   = !string.IsNullOrWhiteSpace(productInfo.ColorAlias) ? productInfo.ColorAlias : item.ColorAlias;
                    item.SizeAlias    = !string.IsNullOrWhiteSpace(productInfo.SizeAlias) ? productInfo.SizeAlias : item.SizeAlias;
                    item.VersionAlias = !string.IsNullOrWhiteSpace(productInfo.VersionAlias) ? productInfo.VersionAlias : item.VersionAlias;
                }
            }
            int validityType = 0; string startDate = string.Empty, endDate = string.Empty;
            var virtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(orderItem.FirstOrDefault().ProductId);

            if (virtualProductInfo != null)
            {
                validityType = virtualProductInfo.ValidityType ? 1 : 0;
                if (validityType == 1)
                {
                    startDate = virtualProductInfo.StartDate.Value.ToString("yyyy-MM-dd");
                    endDate   = virtualProductInfo.EndDate.Value.ToString("yyyy-MM-dd");
                }
            }

            var verificationCode = recordInfo.VerificationCodeIds.Trim(',').Split(',').ToList();

            verificationCode = verificationCode.Select(a => a = Regex.Replace(a, @"(\d{4})", "$1 ")).ToList();
            var virtualOrderItemInfos = OrderApplication.GetVirtualOrderItemInfosByOrderId(order.Id).Select(p =>
            {
                return(new
                {
                    VirtualProductItemType = p.VirtualProductItemType,
                    VirtualProductItemName = p.VirtualProductItemName,
                    Content = ReplaceImage(p.Content, p.VirtualProductItemType)
                });
            });

            order.OrderStatusText = order.OrderStatus.ToDescription();
            return(new { success = true, order = order, orderItem = orderItem, virtualOrderItemInfos = virtualOrderItemInfos, verificationCodes = verificationCode, validityType = validityType, startDate = startDate, endDate = endDate, verificationTime = recordInfo.VerificationTime.ToString("yyyy-MM-dd HH:mm:ss"), verificationUser = recordInfo.VerificationUser });
        }
        /// <summary>
        /// 根据提货码取订单
        /// </summary>
        /// <param name="pickcode"></param>
        /// <returns></returns>
        public object GetShopBranchOrder(string pickcode)
        {
            CheckUserLogin();

            var codeInfo = OrderApplication.GetOrderVerificationCodeInfoByCode(pickcode);

            if (codeInfo != null)
            {
                var order = OrderApplication.GetOrderInfo(codeInfo.OrderId);
                if (order == null)
                {
                    return new { success = false, msg = "该核销码无效" }
                }
                ;

                if (order.OrderType != OrderInfo.OrderTypes.Virtual)
                {
                    return new { success = false, msg = "核销订单无效" }
                }
                ;

                if (order.ShopBranchId != CurrentShopBranch.Id)
                {
                    return new { success = false, msg = "非本店核销码,请买家核对信息" }
                }
                ;

                if (codeInfo.Status == OrderInfo.VerificationCodeStatus.AlreadyVerification)
                {
                    return new { success = false, msg = string.Format("该核销码于{0}已核销", codeInfo.VerificationTime.Value.ToString("yyyy-MM-dd HH:mm")) }
                }
                ;

                if (codeInfo.Status == OrderInfo.VerificationCodeStatus.Expired)
                {
                    return new { success = false, msg = "此核销码已过期,无法核销" }
                }
                ;

                if (codeInfo.Status == OrderInfo.VerificationCodeStatus.Refund)
                {
                    return new { success = false, msg = "此核销码正处于退款中,无法核销" }
                }
                ;

                if (codeInfo.Status == OrderInfo.VerificationCodeStatus.RefundComplete)
                {
                    return new { success = false, msg = "此核销码已经退款成功,无法核销" }
                }
                ;

                var orderItem          = Application.OrderApplication.GetOrderItemsByOrderId(order.Id);
                var orderItemInfo      = orderItem.FirstOrDefault();
                var virtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(orderItemInfo.ProductId);
                if (virtualProductInfo != null && virtualProductInfo.ValidityType && DateTime.Now < virtualProductInfo.StartDate.Value)
                {
                    return(new { success = false, msg = "该核销码暂时不能核销,请留意生效时间!" });
                }
                if (orderItemInfo.EffectiveDate.HasValue)
                {
                    if (DateTime.Now < orderItemInfo.EffectiveDate.Value)
                    {
                        return new { success = false, msg = "该核销码暂时不能核销,请留意生效时间!" }
                    }
                    ;
                }

                foreach (var item in orderItem)
                {
                    item.ThumbnailsUrl = Core.HimallIO.GetRomoteProductSizeImage(item.ThumbnailsUrl, 1, (int)Himall.CommonModel.ImageSize.Size_100);
                    Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetTypeByProductId(item.ProductId);

                    item.ColorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    item.SizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    item.VersionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    var productInfo = ProductManagerApplication.GetProduct(item.ProductId);
                    if (productInfo != null)
                    {
                        item.ColorAlias = !string.IsNullOrWhiteSpace(productInfo.ColorAlias) ? productInfo.ColorAlias : item.ColorAlias;

                        item.SizeAlias    = !string.IsNullOrWhiteSpace(productInfo.SizeAlias) ? productInfo.SizeAlias : item.SizeAlias;
                        item.VersionAlias = !string.IsNullOrWhiteSpace(productInfo.VersionAlias) ? productInfo.VersionAlias : item.VersionAlias;
                    }
                }

                var verifications = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>()
                {
                    order.Id
                }).Where(a => a.Status == OrderInfo.VerificationCodeStatus.WaitVerification);
                var codes = verifications.ToList();//待消费的核销码
                if (codes != null)
                {
                    codes.ForEach(a =>
                    {
                        a.SourceCode       = a.VerificationCode;
                        a.VerificationCode = System.Text.RegularExpressions.Regex.Replace(a.VerificationCode, "(\\d{4})\\d{4}(\\d{4})", "$1****$2");
                    });
                }
                var virtualOrderItemInfos = OrderApplication.GetVirtualOrderItemInfosByOrderId(order.Id).Select(p =>
                {
                    return(new
                    {
                        VirtualProductItemType = p.VirtualProductItemType,
                        VirtualProductItemName = p.VirtualProductItemName,
                        Content = ReplaceImage(p.Content, p.VirtualProductItemType)
                    });
                });
                order.OrderStatusText = order.OrderStatus.ToDescription();
                order.PaymentTypeName = PaymentApplication.GetPaymentTypeDescById(order.PaymentTypeGateway) ?? order.PaymentTypeName;//统一显示支付方式名称
                return(new { success = true, order = order, orderItem = orderItem, virtualProductInfo = virtualProductInfo, virtualOrderItemInfos = virtualOrderItemInfos, verificationCodes = codes });
            }
            else
            {
                var order = Application.OrderApplication.GetOrderByPickCode(pickcode);
                if (order == null)
                {
                    return new { success = false, msg = "该核销码无效" }
                }
                ;
                if (order.ShopBranchId != CurrentShopBranch.Id)
                {
                    return new { success = false, msg = "非本门店核销码,请买家核对提货信息" }
                }
                ;
                if (order.OrderStatus == Entities.OrderInfo.OrderOperateStatus.Finish && order.DeliveryType == CommonModel.DeliveryType.SelfTake)
                {
                    return new { success = false, msg = "该核销码于" + order.FinishDate.ToString() + "已核销" }
                }
                ;
                var orderRefundInfo = RefundApplication.GetOrderRefundByOrderId(order.Id);
                if (orderRefundInfo != null && orderRefundInfo.ManagerConfirmStatus == OrderRefundInfo.OrderRefundConfirmStatus.Confirmed)
                {
                    return(new { success = false, msg = "该订单已退款,不能再核销" });
                }
                var orderItem = Application.OrderApplication.GetOrderItemsByOrderId(order.Id);
                foreach (var item in orderItem)
                {
                    item.ThumbnailsUrl = Core.HimallIO.GetRomoteProductSizeImage(item.ThumbnailsUrl, 1, (int)Himall.CommonModel.ImageSize.Size_100);
                    Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetTypeByProductId(item.ProductId);

                    item.ColorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    item.SizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    item.VersionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    var productInfo = ProductManagerApplication.GetProduct(item.ProductId);
                    if (productInfo != null)
                    {
                        item.ColorAlias   = !string.IsNullOrWhiteSpace(productInfo.ColorAlias) ? productInfo.ColorAlias : item.ColorAlias;
                        item.SizeAlias    = !string.IsNullOrWhiteSpace(productInfo.SizeAlias) ? productInfo.SizeAlias : item.SizeAlias;
                        item.VersionAlias = !string.IsNullOrWhiteSpace(productInfo.VersionAlias) ? productInfo.VersionAlias : item.VersionAlias;
                    }
                }
                //退款状态
                var refundobjs = OrderApplication.GetOrderRefunds(orderItem.Select(e => e.Id));
                //小于4表示商家未确认;与平台未审核,都算退款、退货中
                var refundProcessing = refundobjs.Where(e => (int)e.SellerAuditStatus > 4 && ((int)e.SellerAuditStatus < 4 || e.ManagerConfirmStatus == OrderRefundInfo.OrderRefundConfirmStatus.UnConfirm));
                if (refundProcessing.Count() > 0)
                {
                    order.RefundStats = 1;
                }

                order.OrderStatusText = order.OrderStatus.ToDescription();
                return(new { success = true, order = order, orderItem = orderItem });
            }
        }
        public object GetOrders(int?status, int pageIndex, int pageSize = 8)
        {
            CheckUserLogin();
            var orderService = ServiceProvider.Instance <IOrderService> .Create;

            if (status.HasValue && status == 0)
            {
                status = null;
            }
            var queryModel = new OrderQuery()
            {
                Status   = (OrderInfo.OrderOperateStatus?)status,
                UserId   = CurrentUser.Id,
                PageSize = pageSize,
                PageNo   = pageIndex,
                IsFront  = true
            };

            if (queryModel.Status.HasValue && queryModel.Status.Value == Entities.OrderInfo.OrderOperateStatus.WaitReceiving)
            {
                if (queryModel.MoreStatus == null)
                {
                    queryModel.MoreStatus = new List <Entities.OrderInfo.OrderOperateStatus>()
                    {
                    };
                }
                queryModel.MoreStatus.Add(Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp);
            }
            if (status.GetValueOrDefault() == (int)OrderInfo.OrderOperateStatus.Finish)
            {
                queryModel.Commented = false;//只查询未评价的订单
            }
            var orders             = orderService.GetOrders <OrderInfo>(queryModel);
            var productService     = ServiceProvider.Instance <IProductService> .Create;
            var vshopService       = ServiceProvider.Instance <IVShopService> .Create;
            var orderRefundService = ServiceProvider.Instance <IRefundService> .Create;
            var orderItems         = OrderApplication.GetOrderItemsByOrderId(orders.Models.Select(p => p.Id));
            var orderRefunds       = OrderApplication.GetOrderRefunds(orderItems.Select(p => p.Id));
            var shopBranchs        = ShopBranchApplication.GetShopBranchByIds(orders.Models.Where(a => a.ShopBranchId > 0).Select(p => p.ShopBranchId).ToList());
            var result             = orders.Models.Select(item =>
            {
                var orderitems     = orderItems.Where(p => p.OrderId == item.Id);
                var shopBranchInfo = shopBranchs.FirstOrDefault(a => a.Id == item.ShopBranchId);//当前订单所属门店信息
                if (item.OrderStatus >= Entities.OrderInfo.OrderOperateStatus.WaitDelivery)
                {
                    orderService.CalculateOrderItemRefund(item.Id);
                }
                var vshop      = vshopService.GetVShopByShopId(item.ShopId);
                var _ordrefobj = orderRefundService.GetOrderRefundByOrderId(item.Id) ?? new Entities.OrderRefundInfo {
                    Id = 0
                };
                if (item.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitDelivery && item.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp)
                {
                    _ordrefobj = new Entities.OrderRefundInfo {
                        Id = 0
                    };
                }
                int?ordrefstate = (_ordrefobj == null ? null : (int?)_ordrefobj.SellerAuditStatus);
                ordrefstate     = (ordrefstate > 4 ? (int?)_ordrefobj.ManagerConfirmStatus : ordrefstate);
                //参照PC端会员中心的状态描述信息
                string statusText = item.OrderStatus.ToDescription();
                if (item.OrderStatus == Entities.OrderInfo.OrderOperateStatus.WaitDelivery || item.OrderStatus == Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp)
                {
                    if (ordrefstate.HasValue && ordrefstate != 0 && ordrefstate != 4)
                    {
                        statusText = "退款中";
                    }
                }
                //是否可售后
                bool IsShowReturn    = OrderApplication.CanRefund(item, ordrefstate, null);
                var hasAppendComment = ServiceProvider.Instance <ICommentService> .Create.HasAppendComment(orderitems.FirstOrDefault().Id);
                return(new
                {
                    OrderId = item.Id,
                    StatusText = statusText,
                    Status = item.OrderStatus,
                    orderType = item.OrderType,
                    orderTypeName = item.OrderType.ToDescription(),
                    shopname = item.ShopName,
                    vshopId = vshop == null ? 0 : vshop.Id,
                    Amount = item.OrderTotalAmount.ToString("F2"),
                    Quantity = OrderApplication.GetOrderTotalProductCount(item.Id),
                    commentCount = OrderApplication.GetOrderCommentCount(item.Id),
                    pickupCode = item.PickupCode,
                    EnabledRefundAmount = item.OrderEnabledRefundAmount,
                    LineItems = orderitems.Select(a =>
                    {
                        var prodata = productService.GetProduct(a.ProductId);
                        Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetType(prodata.TypeId);
                        string colorAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                        string sizeAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                        string versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                        var itemStatusText = "";
                        var itemrefund = orderRefunds.Where(or => or.OrderItemId == a.Id).FirstOrDefault(d => d.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund);
                        int?itemrefstate = (itemrefund == null ? 0 : (int?)itemrefund.SellerAuditStatus);
                        itemrefstate = (itemrefstate > 4 ? (int?)itemrefund.ManagerConfirmStatus : itemrefstate);
                        if (itemrefund != null)
                        {     //默认为商家处理进度
                            if (itemrefstate == 4)
                            { //商家拒绝
                                itemStatusText = "";
                            }
                            else
                            {
                                itemStatusText = "售后处理中";
                            }
                        }
                        if (itemrefstate > 4)
                        {//如果商家已经处理完,则显示平台处理进度
                            if (itemrefstate == 7)
                            {
                                itemStatusText = "退款成功";
                            }
                        }
                        return new
                        {
                            Status = itemrefstate,
                            StatusText = itemStatusText,
                            Id = a.SkuId,
                            productId = a.ProductId,
                            Name = a.ProductName,
                            Image = Core.MallIO.GetRomoteProductSizeImage(a.ThumbnailsUrl, 1, (int)Mall.CommonModel.ImageSize.Size_350),
                            Amount = a.Quantity,
                            Price = a.SalePrice,
                            Unit = prodata == null ? "" : prodata.MeasureUnit,
                            SkuText = colorAlias + ":" + a.Color + " " + sizeAlias + ":" + a.Size + " " + versionAlias + ":" + a.Version,
                            color = a.Color,
                            size = a.Size,
                            version = a.Version,
                            ColorAlias = (prodata != null && !string.IsNullOrWhiteSpace(prodata.ColorAlias)) ? prodata.ColorAlias : colorAlias,//如果商品有自定义规格名称则用
                            SizeAlias = (prodata != null && !string.IsNullOrWhiteSpace(prodata.SizeAlias)) ? prodata.SizeAlias : sizeAlias,
                            VersionAlias = (prodata != null && !string.IsNullOrWhiteSpace(prodata.VersionAlias)) ? prodata.VersionAlias : versionAlias,
                            RefundStats = itemrefstate,
                            OrderRefundId = (itemrefund == null ? 0 : itemrefund.Id),
                            EnabledRefundAmount = a.EnabledRefundAmount,
                            IsShowRefund = IsShowReturn,
                            IsShowAfterSale = IsShowReturn
                        };
                    }),
                    RefundStats = ordrefstate,
                    OrderRefundId = _ordrefobj.Id,
                    IsShowLogistics = !string.IsNullOrWhiteSpace(item.ShipOrderNumber) || item.DeliveryType == DeliveryType.ShopStore,
                    ShipOrderNumber = item.ShipOrderNumber,
                    IsShowCreview = (item.OrderStatus == Entities.OrderInfo.OrderOperateStatus.Finish && !hasAppendComment),
                    IsShowPreview = false,
                    //Invoice = item.InvoiceType.ToDescription(),
                    //InvoiceValue = (int)item.InvoiceType,
                    //InvoiceContext = item.InvoiceContext,
                    //InvoiceTitle = item.InvoiceTitle,
                    PaymentType = item.PaymentType.ToDescription(),
                    PaymentTypeValue = (int)item.PaymentType,
                    IsShowClose = (item.OrderStatus == Entities.OrderInfo.OrderOperateStatus.WaitPay),
                    IsShowFinishOrder = (item.OrderStatus == Entities.OrderInfo.OrderOperateStatus.WaitReceiving),
                    IsShowRefund = IsShowReturn,
                    IsShowReturn = IsShowReturn,
                    IsShowTakeCodeQRCode = (!string.IsNullOrWhiteSpace(item.PickupCode) && item.OrderStatus != Entities.OrderInfo.OrderOperateStatus.Finish && item.OrderStatus != Entities.OrderInfo.OrderOperateStatus.Close),
                    OrderDate = item.OrderDate,
                    SupplierId = 0,
                    ShipperName = string.Empty,
                    StoreName = shopBranchInfo != null ? shopBranchInfo.ShopBranchName : string.Empty,
                    IsShowCertification = false,
                    HasAppendComment = hasAppendComment,
                    CreviewText = OrderApplication.GetOrderCommentCount(item.Id) > 0 ? "追加评论" : "评价订单",
                    ProductCommentPoint = 0,
                    DeliveryType = (int)item.DeliveryType
                });
            });
            var statistic = StatisticApplication.GetMemberOrderStatistic(CurrentUser.Id);

            return(Json(
                       new
            {
                AllOrderCounts = statistic.OrderCount,
                WaitingForComments = statistic.WaitingForComments,
                WaitingForRecieve = statistic.WaitingForRecieve,
                WaitingForPay = statistic.WaitingForPay,
                Data = result
            }));
        }
        public object GetOrderDetail(long orderId)
        {
            CheckUserLogin();
            var orderService       = ServiceProvider.Instance <IOrderService> .Create;
            var order              = orderService.GetOrder(orderId, CurrentUser.Id);
            var orderitems         = orderService.GetOrderItemsByOrderId(order.Id);
            var orderRefundService = ServiceProvider.Instance <IRefundService> .Create;
            var productService     = ServiceProvider.Instance <IProductService> .Create;
            var coupon             = ServiceProvider.Instance <ICouponService> .Create.GetCouponRecordInfo(order.UserId, order.Id);

            string  couponName  = "";
            decimal couponAmout = 0;

            if (coupon != null)
            {
                var c = CouponApplication.GetCouponInfo(coupon.CouponId);
                couponName  = c.CouponName;
                couponAmout = c.Price;
            }

            //订单信息是否正常
            if (order == null)
            {
                throw new MallException("订单号不存在!");
            }
            dynamic expressTrace = new ExpandoObject();

            //取订单物流信息
            if (!string.IsNullOrWhiteSpace(order.ShipOrderNumber))
            {
                var expressData = ServiceProvider.Instance <IExpressService> .Create.GetExpressData(order.ExpressCompanyName, order.ShipOrderNumber);

                if (expressData.Success)
                {
                    expressData.ExpressDataItems = expressData.ExpressDataItems.OrderByDescending(item => item.Time);//按时间逆序排列
                    expressTrace.traces          = expressData.ExpressDataItems.Select(item => new
                    {
                        acceptTime    = item.Time.ToString("yyyy-MM-dd HH:mm:ss"),
                        acceptStation = item.Content
                    });
                }
            }
            var orderRefunds     = OrderApplication.GetOrderRefunds(orderitems.Select(p => p.Id));
            var isCanOrderReturn = OrderApplication.CanRefund(order);
            //获取订单商品项数据
            var orderDetail = new
            {
                ShopId = order.ShopId,
                EnabledRefundAmount = order.OrderEnabledRefundAmount,
                OrderItems          = orderitems.Select(item =>
                {
                    var productinfo            = productService.GetProduct(item.ProductId);
                    Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetType(productinfo.TypeId);
                    string colorAlias          = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    string sizeAlias           = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    string versionAlias        = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    var itemStatusText         = "";
                    var itemrefund             = orderRefunds.Where(or => or.OrderItemId == item.Id).FirstOrDefault(d => d.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund);
                    int?itemrefstate           = (itemrefund == null ? 0 : (int?)itemrefund.SellerAuditStatus);
                    itemrefstate = (itemrefstate > 4 ? (int?)itemrefund.ManagerConfirmStatus : itemrefstate);
                    if (itemrefund != null)
                    {     //默认为商家处理进度
                        if (itemrefstate == 4)
                        { //商家拒绝,可以再发起申请
                            itemStatusText = "";
                        }
                        else
                        {
                            itemStatusText = "售后处理中";
                        }
                    }
                    if (itemrefstate > 4)
                    {//如果商家已经处理完,则显示平台处理进度
                        if (itemrefstate == 7)
                        {
                            itemStatusText = "退款成功";
                        }
                    }
                    if (productinfo != null)
                    {
                        colorAlias   = (!string.IsNullOrWhiteSpace(productinfo.ColorAlias)) ? productinfo.ColorAlias : colorAlias;//如果商品有自定义规格名称,则用
                        sizeAlias    = (!string.IsNullOrWhiteSpace(productinfo.SizeAlias)) ? productinfo.SizeAlias : sizeAlias;
                        versionAlias = (!string.IsNullOrWhiteSpace(productinfo.VersionAlias)) ? productinfo.VersionAlias : versionAlias;
                    }

                    long activeId   = 0;
                    int activetype  = 0;
                    var limitbuyser = ServiceProvider.Instance <ILimitTimeBuyService> .Create;
                    var limitBuy    = limitbuyser.GetLimitTimeMarketItemByProductId(item.ProductId);
                    if (limitBuy != null)
                    {
                        //salePrice = limitBuy.MinPrice;
                        activeId   = limitBuy.Id;
                        activetype = 1;
                    }
                    else
                    {
                        #region 限时购预热
                        var FlashSale       = limitbuyser.IsFlashSaleDoesNotStarted(item.ProductId);
                        var FlashSaleConfig = limitbuyser.GetConfig();

                        if (FlashSale != null)
                        {
                            TimeSpan flashSaleTime = DateTime.Parse(FlashSale.BeginDate) - DateTime.Now; //开始时间还剩多久
                            TimeSpan preheatTime   = new TimeSpan(FlashSaleConfig.Preheat, 0, 0);        //预热时间是多久
                            if (preheatTime >= flashSaleTime)                                            //预热大于开始
                            {
                                if (!FlashSaleConfig.IsNormalPurchase)
                                {
                                    activeId   = FlashSale.Id;
                                    activetype = 1;
                                }
                            }
                        }
                        #endregion
                    }

                    return(new
                    {
                        Status = itemrefstate,
                        StatusText = itemStatusText,
                        Id = item.Id,
                        SkuId = item.SkuId,
                        ProductId = item.ProductId,
                        Name = item.ProductName,
                        Amount = item.Quantity,
                        Price = item.SalePrice,
                        //ProductImage = "http://" + Url.Request.RequestUri.Host + productService.GetProduct(item.ProductId).GetImage(ProductInfo.ImageSize.Size_100),
                        Image = Core.MallIO.GetRomoteProductSizeImage(productService.GetProduct(item.ProductId).RelativePath, 1, (int)Mall.CommonModel.ImageSize.Size_100),
                        color = item.Color,
                        size = item.Size,
                        version = item.Version,
                        IsCanRefund = OrderApplication.CanRefund(order, itemrefstate, itemId: item.Id),
                        ColorAlias = colorAlias,
                        SizeAlias = sizeAlias,
                        VersionAlias = versionAlias,
                        SkuText = colorAlias + ":" + item.Color + ";" + sizeAlias + ":" + item.Size + ";" + versionAlias + ":" + item.Version,
                        EnabledRefundAmount = item.EnabledRefundAmount,
                        ActiveId = activeId,    //活动Id
                        ActiveType = activetype //活动类型(1代表限购,2代表团购,3代表商品预售,4代表限购预售,5代表团购预售)
                    });
                })
            };

            //取拼团订单状态
            var fightGroupOrderInfo = ServiceProvider.Instance <IFightGroupService> .Create.GetFightGroupOrderStatusByOrderId(order.Id);

            #region 门店信息
            var branchInfo = new ShopBranch();
            if (order.ShopBranchId > 0)
            {
                branchInfo = ShopBranchApplication.GetShopBranchById(order.ShopBranchId);
            }
            else
            {
                branchInfo = null;
            }
            #endregion

            #region 虚拟订单信息
            VirtualProductInfo virtualProductInfo = null;
            int            validityType = 0; string startDate = string.Empty, endDate = string.Empty;
            List <dynamic> orderVerificationCodes = null;
            List <dynamic> virtualOrderItemInfos  = null;
            bool           isCanRefundVirtual     = false;
            if (order.OrderType == OrderInfo.OrderTypes.Virtual)
            {
                var orderItemInfo = orderitems.FirstOrDefault();
                if (orderItemInfo != null)
                {
                    virtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(orderItemInfo.ProductId);
                    if (virtualProductInfo != null)
                    {
                        validityType = virtualProductInfo.ValidityType ? 1 : 0;
                        if (validityType == 1)
                        {
                            startDate = virtualProductInfo.StartDate.Value.ToString("yyyy-MM-dd");
                            endDate   = virtualProductInfo.EndDate.Value.ToString("yyyy-MM-dd");
                        }
                    }
                    var codes = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>()
                    {
                        order.Id
                    });
                    orderVerificationCodes = codes.Select(p =>
                    {
                        return(new
                        {
                            VerificationCode = Regex.Replace(p.VerificationCode, @"(\d{4})", "$1 "),
                            Status = p.Status,
                            StatusText = p.Status.ToDescription(),
                            QRCode = GetQRCode(p.VerificationCode)
                        });
                    }).ToList <dynamic>();

                    var virtualItems = OrderApplication.GetVirtualOrderItemInfosByOrderId(order.Id);
                    virtualOrderItemInfos = virtualItems.Select(p =>
                    {
                        return(new
                        {
                            VirtualProductItemName = p.VirtualProductItemName,
                            Content = ReplaceImage(p.Content, p.VirtualProductItemType),
                            VirtualProductItemType = p.VirtualProductItemType
                        });
                    }).ToList <dynamic>();
                }
            }
            if (order.OrderStatus == Mall.Entities.OrderInfo.OrderOperateStatus.WaitVerification)
            {
                if (virtualProductInfo != null)
                {
                    if (virtualProductInfo.SupportRefundType == 2)
                    {
                        isCanRefundVirtual = true;
                    }
                    else if (virtualProductInfo.SupportRefundType == 1)
                    {
                        if (virtualProductInfo.EndDate.Value > DateTime.Now)
                        {
                            isCanRefundVirtual = true;
                        }
                    }
                    else if (virtualProductInfo.SupportRefundType == 3)
                    {
                        isCanRefundVirtual = false;
                    }

                    if (isCanRefundVirtual)
                    {
                        long num = orderVerificationCodes.Where(a => a.Status == OrderInfo.VerificationCodeStatus.WaitVerification).Count();
                        if (num > 0)
                        {
                            isCanRefundVirtual = true;
                        }
                        else
                        {
                            isCanRefundVirtual = false;
                        }
                    }
                }
            }
            #endregion
            #region 虚拟订单核销地址信息
            string shipperAddress = string.Empty, shipperTelPhone = string.Empty;
            if (order.OrderType == OrderInfo.OrderTypes.Virtual)
            {
                if (order.ShopBranchId > 0 && branchInfo != null)
                {
                    shipperAddress  = RegionApplication.GetFullName(branchInfo.AddressId) + " " + branchInfo.AddressDetail;
                    shipperTelPhone = branchInfo.ContactPhone;
                }
                else
                {
                    var verificationShipper = ShopShippersApplication.GetDefaultVerificationShipper(order.ShopId);
                    if (verificationShipper != null)
                    {
                        shipperAddress  = RegionApplication.GetFullName(verificationShipper.RegionId) + " " + verificationShipper.Address;
                        shipperTelPhone = verificationShipper.TelPhone;
                    }
                }
            }
            #endregion
            var bonusmodel = ServiceProvider.Instance <IShopBonusService> .Create.GetGrantByUserOrder(orderId, CurrentUser.Id);

            bool   hasBonus    = bonusmodel != null ? true : false;
            string shareHref   = "";
            string shareTitle  = "";
            string shareDetail = "";
            string shareImg    = "";
            if (hasBonus)
            {
                shareHref = "/m-weixin/ShopBonus/Index/" + ServiceProvider.Instance <IShopBonusService> .Create.GetGrantIdByOrderId(orderId);

                var bonus = ShopBonusApplication.GetBonus(bonusmodel.ShopBonusId);
                shareTitle  = bonus.ShareTitle;
                shareDetail = bonus.ShareDetail;
                shareImg    = MallIO.GetRomoteImagePath(bonus.ShareImg);
            }
            var orderModel = new
            {
                OrderId             = order.Id,
                Status              = (int)order.OrderStatus,
                StatusText          = order.OrderStatus.ToDescription(),
                EnabledRefundAmount = order.OrderEnabledRefundAmount,
                OrderTotal          = order.OrderTotalAmount,
                CapitalAmount       = order.CapitalAmount,
                OrderAmount         = order.ProductTotalAmount,
                DeductionPoints     = 0,
                DeductionMoney      = order.IntegralDiscount,
                //CouponAmount = couponAmout.ToString("F2"),//优惠劵金额
                CouponAmount                = order.DiscountAmount, //优惠劵金额
                CouponName                  = couponName,           //优惠劵名称
                RefundAmount                = order.RefundTotalAmount,
                Tax                         = order.Tax,
                AdjustedFreight             = order.Freight,
                OrderDate                   = order.OrderDate.ToString("yyyy-MM-dd HH:mm:ss"),
                ItemStatus                  = 0,
                ItemStatusText              = "",
                ShipTo                      = order.ShipTo,
                ShipToDate                  = order.ShippingDate.HasValue ? order.ShippingDate.Value.ToString("yyyy-MM-dd HH:mm:ss") : "",
                Cellphone                   = order.CellPhone,
                Address                     = order.DeliveryType == CommonModel.DeliveryType.SelfTake && branchInfo != null ? branchInfo.AddressFullName : (order.RegionFullName + " " + order.Address),
                FreightFreePromotionName    = string.Empty,
                ReducedPromotionName        = string.Empty,
                ReducedPromotionAmount      = order.FullDiscount,
                SentTimesPointPromotionName = string.Empty,
                CanBackReturn               = !string.IsNullOrWhiteSpace(order.PaymentTypeGateway),
                CanCashierReturn            = false,
                PaymentType                 = order.PaymentType.ToDescription(),
                OrderPayAmount              = order.OrderPayAmount,//订单需要第三方支付的金额
                PaymentTypeName             = PaymentApplication.GetPaymentTypeDescById(order.PaymentTypeGateway) ?? order.PaymentTypeName,
                PaymentTypeDesc             = order.PaymentTypeDesc,
                Remark                      = string.IsNullOrEmpty(order.OrderRemarks) ? "" : order.OrderRemarks,
                //InvoiceTitle = order.InvoiceTitle,
                //Invoice = order.InvoiceType.ToDescription(),
                //InvoiceValue = (int)order.InvoiceType,
                //InvoiceContext = order.InvoiceContext,
                //InvoiceCode = order.InvoiceCode,
                ModeName               = order.DeliveryType.ToDescription(),
                LogisticsData          = expressTrace,
                TakeCode               = order.PickupCode,
                LineItems              = orderDetail.OrderItems,
                IsCanRefund            = !(orderDetail.OrderItems.Any(e => e.IsCanRefund == true)) && OrderApplication.CanRefund(order, null, null),
                IsSelfTake             = order.DeliveryType == Mall.CommonModel.DeliveryType.SelfTake ? 1 : 0,
                BranchInfo             = branchInfo,
                DeliveryType           = (int)order.DeliveryType,
                OrderInvoice           = OrderApplication.GetOrderInvoiceInfo(order.Id),
                ValidityType           = validityType,
                StartDate              = startDate,
                EndDate                = endDate,
                OrderVerificationCodes = orderVerificationCodes,
                VirtualOrderItemInfos  = virtualOrderItemInfos,
                IsCanRefundVirtual     = isCanRefundVirtual,
                ShipperAddress         = shipperAddress,
                ShipperTelPhone        = shipperTelPhone,
                OrderType              = order.OrderType,
                JoinStatus             = fightGroupOrderInfo == null ? -2 : fightGroupOrderInfo.JoinStatus,
                HasBonus               = hasBonus,
                ShareHref              = shareHref,
                ShareTitle             = shareTitle,
                ShareDetail            = shareDetail,
                ShareImg               = shareImg,
                ShopName               = order.ShopName
            };

            return(Json(orderModel));
        }
        /// <summary>
        /// 根据核销码取订单
        /// </summary>
        /// <param name="pickcode"></param>
        /// <returns></returns>
        public object GetShopOrder(string pickcode)
        {
            CheckUserLogin();

            var codeInfo = OrderApplication.GetOrderVerificationCodeInfoByCode(pickcode);

            if (codeInfo == null)
            {
                return new { success = false, msg = "该核销码无效" }
            }
            ;

            var order = OrderApplication.GetOrderInfo(codeInfo.OrderId);

            if (order == null)
            {
                return new { success = false, msg = "该核销码无效" }
            }
            ;

            if (order.OrderType != OrderInfo.OrderTypes.Virtual)
            {
                return new { success = false, msg = "核销订单无效" }
            }
            ;

            if (order.ShopId != this.CurrentShop.Id)
            {
                return new { success = false, msg = "非本店核销码,请买家核对信息" }
            }
            ;

            if (order.ShopBranchId > 0)//商家只能核销本商家,而非下面门店的
            {
                return new { success = false, msg = "非本店核销码,请买家核对信息" }
            }
            ;

            if (codeInfo.Status == OrderInfo.VerificationCodeStatus.AlreadyVerification)
            {
                return new { success = false, msg = string.Format("该核销码于{0}已核销", codeInfo.VerificationTime.Value.ToString("yyyy-MM-dd HH:mm")) }
            }
            ;

            if (codeInfo.Status == OrderInfo.VerificationCodeStatus.Expired)
            {
                return new { success = false, msg = "此核销码已过期,无法核销" }
            }
            ;

            if (codeInfo.Status == OrderInfo.VerificationCodeStatus.Refund)
            {
                return new { success = false, msg = "此核销码正处于退款中,无法核销" }
            }
            ;

            if (codeInfo.Status == OrderInfo.VerificationCodeStatus.RefundComplete)
            {
                return new { success = false, msg = "此核销码已经退款成功,无法核销" }
            }
            ;

            var orderItem          = Application.OrderApplication.GetOrderItemsByOrderId(order.Id);
            var orderItemInfo      = orderItem.FirstOrDefault();
            var virtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(orderItemInfo.ProductId);

            if (virtualProductInfo != null && virtualProductInfo.ValidityType && DateTime.Now < virtualProductInfo.StartDate.Value)
            {
                return(new { success = false, msg = "该核销码暂时不能核销,请留意生效时间!" });
            }
            if (orderItemInfo.EffectiveDate.HasValue)
            {
                if (DateTime.Now < orderItemInfo.EffectiveDate.Value)
                {
                    return new { success = false, msg = "该核销码暂时不能核销,请留意生效时间!" }
                }
                ;
            }

            foreach (var item in orderItem)
            {
                item.ThumbnailsUrl = Core.HimallIO.GetRomoteProductSizeImage(item.ThumbnailsUrl, 1, (int)Himall.CommonModel.ImageSize.Size_100);
                Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetTypeByProductId(item.ProductId);

                item.ColorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                item.SizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                item.VersionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                var productInfo = ProductManagerApplication.GetProduct(item.ProductId);
                if (productInfo != null)
                {
                    item.ColorAlias = !string.IsNullOrWhiteSpace(productInfo.ColorAlias) ? productInfo.ColorAlias : item.ColorAlias;

                    item.SizeAlias    = !string.IsNullOrWhiteSpace(productInfo.SizeAlias) ? productInfo.SizeAlias : item.SizeAlias;
                    item.VersionAlias = !string.IsNullOrWhiteSpace(productInfo.VersionAlias) ? productInfo.VersionAlias : item.VersionAlias;
                }
            }
            int validityType = 0; string startDate = string.Empty, endDate = string.Empty;

            if (virtualProductInfo != null)
            {
                validityType = virtualProductInfo.ValidityType ? 1 : 0;
                if (validityType == 1)
                {
                    startDate = virtualProductInfo.StartDate.Value.ToString("yyyy-MM-dd");
                    endDate   = virtualProductInfo.EndDate.Value.ToString("yyyy-MM-dd");
                }
            }
            var verifications = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>()
            {
                order.Id
            }).Where(a => a.Status == OrderInfo.VerificationCodeStatus.WaitVerification);
            var codes = verifications.ToList();//待消费的核销码

            if (codes != null)
            {
                codes.ForEach(a =>
                {
                    a.SourceCode       = a.VerificationCode;
                    a.VerificationCode = System.Text.RegularExpressions.Regex.Replace(a.VerificationCode, "(\\d{4})\\d{4}(\\d{4})", "$1****$2");
                });
            }
            var verificationCode = codes.Select(p =>
            {
                return(new
                {
                    Status = p.Status,
                    VerificationCode = p.VerificationCode,
                    SourceCode = p.SourceCode
                });
            });
            var virtualOrderItemInfos = OrderApplication.GetVirtualOrderItemInfosByOrderId(order.Id).Select(p =>
            {
                return(new
                {
                    VirtualProductItemType = p.VirtualProductItemType,
                    VirtualProductItemName = p.VirtualProductItemName,
                    Content = ReplaceImage(p.Content, p.VirtualProductItemType)
                });
            });

            order.OrderStatusText = order.OrderStatus.ToDescription();
            order.PaymentTypeName = PaymentApplication.GetPaymentTypeDescById(order.PaymentTypeGateway) ?? order.PaymentTypeName;//统一显示支付方式名称
            return(new { success = true, order = order, orderItem = orderItem, virtualOrderItemInfos = virtualOrderItemInfos, verificationCodes = verificationCode, validityType = validityType, startDate = startDate, endDate = endDate });
        }
        ///// <summary>
        ///// 获取限时抢购商品详情
        ///// </summary>
        ///// <param name="id"></param>
        ///// <returns></returns>
        public JsonResult <Result <dynamic> > GetLimitBuyProduct(string openId, long countDownId)
        {
            //CheckUserLogin();
            ProductDetailModelForMobie model = new ProductDetailModelForMobie()
            {
                Product = new ProductInfoModel(),
                Shop    = new ShopInfoModel(),
                Color   = new CollectionSKU(),
                Size    = new CollectionSKU(),
                Version = new CollectionSKU()
            };

            Entities.ShopInfo shop   = null;
            FlashSaleModel    market = null;

            market = ServiceProvider.Instance <ILimitTimeBuyService> .Create.Get(countDownId);


            if (market == null || market.Status != FlashSaleInfo.FlashSaleStatus.Ongoing)
            {
                //可能参数是商品ID
                market = market == null ? ServiceProvider.Instance <ILimitTimeBuyService> .Create.GetFlaseSaleByProductId(countDownId) : market;

                if (market == null || market.Status != FlashSaleInfo.FlashSaleStatus.Ongoing)
                {
                    //跳转到404页面
                    return(Json(ErrorResult <dynamic>("你所请求的限时购或者商品不存在!")));
                }
            }

            if (market != null && (market.Status != FlashSaleInfo.FlashSaleStatus.Ongoing || DateTime.Parse(market.EndDate) < DateTime.Now))
            {
                return(JsonResult <dynamic>(new { IsValidLimitBuy = false }));
            }

            model.MaxSaleCount = market.LimitCountOfThePeople;
            model.Title        = market.Title;

            var product = ServiceProvider.Instance <IProductService> .Create.GetProduct(market.ProductId);

            var description = ProductManagerApplication.GetProductDescription(product.Id);


            #region 根据运费模板获取发货地址
            var freightTemplateService = ServiceApplication.Create <IFreightTemplateService>();
            var template = freightTemplateService.GetFreightTemplate(product.FreightTemplateId);
            //string productAddress = string.Empty;
            //if (template != null)
            //{
            //    var fullName = ServiceApplication.Create<IRegionService>().GetFullName(template.SourceAddress);
            //    if (fullName != null)
            //    {
            //        var ass = fullName.Split(' ');
            //        if (ass.Length >= 2)
            //        {
            //            productAddress = ass[0] + " " + ass[1];
            //        }
            //        else
            //        {
            //            productAddress = ass[0];
            //        }
            //    }
            //}

            //model.ProductAddress = productAddress;
            model.FreightTemplate = template;
            #endregion

            #region 商品SKU
            Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetType(product.TypeId);

            string colorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
            string sizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
            string versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;


            List <object> SkuItemList = new List <object>();
            List <object> Skus        = new List <object>();
            var           skus        = ProductManagerApplication.GetSKUs(product.Id);

            if (skus.Count > 0)
            {
                #region 颜色
                long          colorId = 0, sizeId = 0, versionId = 0;
                List <object> colorAttributeValue = new List <object>();
                List <string> listcolor           = new List <string>();
                foreach (var sku in skus)
                {
                    var specs = sku.Id.Split('_');
                    if (specs.Count() > 0 && !string.IsNullOrEmpty(sku.Color))
                    {
                        if (long.TryParse(specs[1], out colorId))
                        {
                        }                                            //相同颜色规格累加对应值
                        if (colorId != 0)
                        {
                            if (!listcolor.Contains(sku.Color))
                            {
                                var c          = skus.Where(s => s.Color.Equals(sku.Color)).Sum(s => s.Stock);
                                var colorvalue = new
                                {
                                    ValueId           = colorId,
                                    UseAttributeImage = "False",
                                    Value             = sku.Color,
                                    ImageUrl          = Himall.Core.HimallIO.GetRomoteImagePath(sku.ShowPic)
                                };
                                listcolor.Add(sku.Color);
                                colorAttributeValue.Add(colorvalue);
                            }
                        }
                    }
                }

                var color = new
                {
                    AttributeName  = !string.IsNullOrWhiteSpace(product.ColorAlias) ? product.ColorAlias : colorAlias,//如果商品有自定义规格名称则用
                    AttributeId    = product.TypeId,
                    AttributeValue = colorAttributeValue,
                    AttributeIndex = 0,
                };
                if (colorId > 0)
                {
                    SkuItemList.Add(color);
                }
                #endregion

                #region 容量
                List <object> sizeAttributeValue = new List <object>();
                List <string> listsize           = new List <string>();
                foreach (var sku in skus)
                {
                    var specs = sku.Id.Split('_');
                    if (specs.Count() > 1)
                    {
                        if (long.TryParse(specs[2], out sizeId))
                        {
                        }
                        if (sizeId != 0)
                        {
                            if (!listsize.Contains(sku.Size))
                            {
                                var ss        = skus.Where(s => s.Size.Equals(sku.Size)).Sum(s1 => s1.Stock);
                                var sizeValue = new
                                {
                                    ValueId           = sizeId,
                                    UseAttributeImage = false,
                                    Value             = sku.Size,
                                    //ImageUrl = Himall.Core.HimallIO.GetRomoteImagePath(sku.ShowPic)
                                };
                                listsize.Add(sku.Size);
                                sizeAttributeValue.Add(sizeValue);
                            }
                        }
                    }
                }

                var size = new
                {
                    AttributeName  = !string.IsNullOrWhiteSpace(product.SizeAlias) ? product.SizeAlias : sizeAlias,
                    AttributeId    = product.TypeId,
                    AttributeValue = sizeAttributeValue,
                    AttributeIndex = 1,
                };
                if (sizeId > 0)
                {
                    SkuItemList.Add(size);
                }

                #endregion

                #region 规格
                List <object> versionAttributeValue = new List <object>();
                List <string> listversion           = new List <string>();
                foreach (var sku in skus)
                {
                    var specs = sku.Id.Split('_');
                    if (specs.Count() > 2)
                    {
                        if (long.TryParse(specs[3], out versionId))
                        {
                        }
                        if (versionId != 0)
                        {
                            if (!listversion.Contains(sku.Version))
                            {
                                var v            = skus.Where(s => s.Version.Equals(sku.Version));
                                var versionValue = new
                                {
                                    ValueId           = versionId,
                                    UseAttributeImage = false,
                                    Value             = sku.Version,
                                    //ImageUrl = Himall.Core.HimallIO.GetRomoteImagePath(sku.ShowPic)
                                };
                                listversion.Add(sku.Version);
                                versionAttributeValue.Add(versionValue);
                            }
                        }
                    }
                }

                var version = new
                {
                    AttributeName  = !string.IsNullOrWhiteSpace(product.VersionAlias) ? product.VersionAlias : versionAlias,
                    AttributeId    = product.TypeId,
                    AttributeValue = versionAttributeValue,
                    AttributeIndex = 2,
                };
                if (versionId > 0)
                {
                    SkuItemList.Add(version);
                }
                #endregion

                #region Sku值

                foreach (var sku in skus)
                {
                    FlashSaleDetailInfo detailInfo = ServiceProvider.Instance <ILimitTimeBuyService> .Create.GetDetail(sku.Id);

                    var prosku = new
                    {
                        SkuItems        = "",
                        MemberPrices    = "",
                        SkuId           = sku.Id,
                        ProductId       = product.Id,
                        SKU             = sku.Sku,
                        Weight          = 0,
                        Stock           = detailInfo == null? sku.Stock: Math.Min(detailInfo.TotalCount, sku.Stock),
                        WarningStock    = sku.SafeStock,
                        CostPrice       = sku.CostPrice,
                        SalePrice       = sku.SalePrice,//限时抢购价格
                        StoreStock      = 0,
                        StoreSalePrice  = 0,
                        OldSalePrice    = 0,
                        ImageUrl        = "",
                        ThumbnailUrl40  = "",
                        ThumbnailUrl410 = "",
                        MaxStock        = 15,
                        FreezeStock     = 0,
                        ActivityStock   = sku.Stock,                                            //限时抢购库存
                        ActivityPrice   = detailInfo == null ? sku.SalePrice : detailInfo.Price //限时抢购价格
                    };
                    Skus.Add(prosku);
                }

                #endregion
            }
            #endregion

            #region 店铺
            shop = ServiceProvider.Instance <IShopService> .Create.GetShop(product.ShopId);

            var vshopinfo = ServiceProvider.Instance <IVShopService> .Create.GetVShopByShopId(shop.Id);

            if (vshopinfo != null)
            {
                model.VShopLog     = vshopinfo.WXLogo;
                model.Shop.VShopId = vshopinfo.Id;
            }
            else
            {
                model.Shop.VShopId = -1;
                model.VShopLog     = string.Empty;
            }
            var mark = Web.Framework.ShopServiceMark.GetShopComprehensiveMark(shop.Id);
            model.Shop.PackMark          = mark.PackMark;
            model.Shop.ServiceMark       = mark.ServiceMark;
            model.Shop.ComprehensiveMark = mark.ComprehensiveMark;

            model.Shop.Name        = shop.ShopName;
            model.Shop.ProductMark = CommentApplication.GetProductAverageMark(product.Id);
            model.Shop.Id          = product.ShopId;
            model.Shop.FreeFreight = shop.FreeFreight;
            model.Shop.ProductNum  = ServiceProvider.Instance <IProductService> .Create.GetShopOnsaleProducts(product.ShopId);

            var shopStatisticOrderComments = ShopApplication.GetStatisticOrderComment(product.ShopId);
            //宝贝与描述
            model.Shop.ProductAndDescription = shopStatisticOrderComments.ProductAndDescription;
            //卖家服务态度
            model.Shop.SellerServiceAttitude = shopStatisticOrderComments.SellerServiceAttitude;
            //卖家发货速度
            model.Shop.SellerDeliverySpeed = shopStatisticOrderComments.SellerDeliverySpeed;

            if (ServiceProvider.Instance <IVShopService> .Create.GetVShopByShopId(shop.Id) == null)
            {
                model.Shop.VShopId = -1;
            }
            else
            {
                model.Shop.VShopId = ServiceProvider.Instance <IVShopService> .Create.GetVShopByShopId(shop.Id).Id;
            }

            List <object> coupons = new List <object>();
            //优惠券
            var result = GetCouponList(shop.Id);//取设置的优惠券
            if (result != null)
            {
                var couponCount = result.Count();
                model.Shop.CouponCount = couponCount;
                if (result.ToList().Count > 0)
                {
                    foreach (var item in result.ToList())
                    {
                        if (CurrentUser != null)
                        {//登录才处理已领
                            var Receive = CouponApplication.GetReceiveStatus(CurrentUserId, item.ShopId, item.Id);
                            if (Receive == 2 || Receive == 4)
                            {//不符合领取条件
                                continue;
                            }
                        }
                        var couponInfo = new
                        {
                            CouponId           = item.Id,
                            CouponName         = item.CouponName,
                            Price              = item.Price,
                            SendCount          = item.Num,
                            UserLimitCount     = item.PerMax,
                            OrderUseLimit      = item.OrderAmount,
                            StartTime          = item.StartTime.ToString("yyyy-MM-dd HH:mm:ss"),
                            ClosingTime        = item.EndTime.ToString("yyyy-MM-dd HH:mm:ss"),
                            CanUseProducts     = "",
                            ObtainWay          = item.ReceiveType,
                            NeedPoint          = item.NeedIntegral,
                            UseWithGroup       = false,
                            UseWithPanicBuying = false,
                            UseWithFireGroup   = false,
                            LimitText          = item.CouponName,
                            CanUseProduct      = item.UseArea == 1 ? "部分商品可用" : "全店通用",
                            StartTimeText      = item.StartTime.ToString("yyyy.MM.dd"),
                            ClosingTimeText    = item.EndTime.ToString("yyyy.MM.dd")
                        };
                        coupons.Add(couponInfo);
                    }
                }
            }


            #endregion

            #region 商品
            var consultations = ServiceProvider.Instance <IConsultationService> .Create.GetConsultations(product.Id);

            var  comments   = CommentApplication.GetCommentsByProduct(product.Id);
            var  total      = comments.Count();
            var  niceTotal  = comments.Count(item => item.ReviewMark >= 4);
            bool isFavorite = false;
            if (CurrentUser == null)
            {
                isFavorite = false;
            }
            else
            {
                isFavorite = ServiceProvider.Instance <IProductService> .Create.IsFavorite(product.Id, CurrentUser.Id);
            }
            var limitBuy = ServiceProvider.Instance <ILimitTimeBuyService> .Create.GetLimitTimeMarketItemByProductId(product.Id);

            var productImage = new List <string>();
            for (int i = 1; i < 6; i++)
            {
                if (i == 1 || Himall.Core.HimallIO.ExistFile(product.RelativePath + string.Format("/{0}.png", i)))
                {
                    productImage.Add(Core.HimallIO.GetRomoteImagePath(product.RelativePath + string.Format("/{0}.png", i)));
                }
            }

            model.Product = new ProductInfoModel()
            {
                ProductId          = product.Id,
                CommentCount       = CommentApplication.GetCommentCountByProduct(product.Id),
                Consultations      = consultations.Count(),
                ImagePath          = productImage,
                IsFavorite         = isFavorite,
                MarketPrice        = product.MarketPrice,
                MinSalePrice       = product.MinSalePrice,
                NicePercent        = model.Shop.ProductMark == 0 ? 100 : (int)((niceTotal / total) * 100),
                ProductName        = product.ProductName,
                ProductSaleStatus  = product.SaleStatus,
                AuditStatus        = product.AuditStatus,
                ShortDescription   = product.ShortDescription,
                ProductDescription = description.ShowMobileDescription,
                IsOnLimitBuy       = limitBuy != null,
                MeasureUnit        = product.MeasureUnit
            };

            #endregion

            //LogProduct(market.ProductId);
            //统计商品浏览量、店铺浏览人数
            StatisticApplication.StatisticVisitCount(product.Id, product.ShopId);

            TimeSpan end    = new TimeSpan(DateTime.Parse(market.EndDate).Ticks);
            TimeSpan start  = new TimeSpan(DateTime.Now.Ticks);
            TimeSpan ts     = end.Subtract(start);
            var      second = ts.TotalSeconds < 0 ? 0 : ts.TotalSeconds;

            List <object> ProductImgs = new List <object>();
            for (int i = 1; i < 5; i++)
            {
                if (i == 1 || Himall.Core.HimallIO.ExistFile(product.RelativePath + string.Format("/{0}.png", i)))
                {
                    ProductImgs.Add(Core.HimallIO.GetRomoteProductSizeImage(product.ImagePath, i, (int)ImageSize.Size_350));
                }
            }

            var countDownStatus = 0;

            if (market.Status == FlashSaleInfo.FlashSaleStatus.Ended)
            {
                countDownStatus = 4;//"PullOff";  //已下架
            }
            else if (market.Status == FlashSaleInfo.FlashSaleStatus.Cancelled || market.Status == FlashSaleInfo.FlashSaleStatus.AuditFailed || market.Status == FlashSaleInfo.FlashSaleStatus.WaitForAuditing)
            {
                countDownStatus = 4;//"NoJoin";  //未参与
            }
            else if (DateTime.Parse(market.BeginDate) > DateTime.Now)
            {
                countDownStatus = 6; // "AboutToBegin";  //即将开始   6
            }
            else if (DateTime.Parse(market.EndDate) < DateTime.Now)
            {
                countDownStatus = 4;// "ActivityEnd";   //已结束  4
            }
            else if (market.Status == FlashSaleInfo.FlashSaleStatus.Ended)
            {
                countDownStatus = 6;// "SoldOut";  //已抢完
            }
            else
            {
                countDownStatus = 2;//"Normal";  //正常  2
            }

            long saleCounts = 0;
            if (countDownStatus == 2)
            {
                saleCounts = market.SaleCount;
            }
            else
            {
                saleCounts = product.SaleCounts + Himall.Core.Helper.TypeHelper.ObjectToInt(product.VirtualSaleCounts);
            }
            //Normal:正常
            //PullOff:已下架
            //NoJoin:未参与
            //AboutToBegin:即将开始
            //ActivityEnd:已结束
            //SoldOut:已抢完

            decimal discount  = 1M;//限时购不考虑会员折
            int     addressId = 0;
            if (CurrentUser != null)
            {
                var addressInfo = ShippingAddressApplication.GetDefaultUserShippingAddressByUserId(CurrentUser.Id);
                if (addressInfo != null)
                {
                    addressId = addressInfo.RegionId;
                }
            }


            //商品关联版式
            string DescriptionPrefix = "", DescriptiondSuffix = "";
            var    iprodestempser = ServiceApplication.Create <IProductDescriptionTemplateService>();
            if (description.DescriptionPrefixId != 0)
            {
                var desc = iprodestempser.GetTemplate(description.DescriptionPrefixId, product.ShopId);
                DescriptionPrefix = desc == null ? "" : desc.MobileContent;
            }

            if (description.DescriptiondSuffixId != 0)
            {
                var desc = iprodestempser.GetTemplate(description.DescriptiondSuffixId, product.ShopId);
                DescriptiondSuffix = desc == null ? "" : desc.MobileContent;
            }

            var    productDescription = DescriptionPrefix + model.Product.ProductDescription + DescriptiondSuffix;
            string skuId = skus.FirstOrDefault()?.Id ?? string.Empty;

            return(JsonResult <dynamic>(new
            {
                CountDownId = market.Id,//.CountDownId,
                MaxCount = market.LimitCountOfThePeople,
                CountDownStatus = countDownStatus,
                StartDate = DateTime.Parse(market.BeginDate).ToString("yyyy/MM/dd HH:mm:ss"),
                EndDate = DateTime.Parse(market.EndDate).ToString("yyyy/MM/dd HH:mm:ss"),
                NowTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo),
                ProductId = product.Id,
                ProductName = product.ProductName,
                MetaDescription = productDescription.Replace("\"/Storage/Shop", "\"" + Core.HimallIO.GetRomoteImagePath("/Storage/Shop")),//替换链接  /Storage/Shop,
                ShortDescription = product.ShortDescription,
                ShowSaleCounts = saleCounts,
                IsSaleCountOnOff = SiteSettingApplication.SiteSettings.ProductSaleCountOnOff == 1,
                Weight = product.Weight.ToString(),
                MinSalePrice = market.MinPrice.ToString("0.##"), //限时抢购价格
                MaxSalePrice = market.SkuMaxPrice,
                Stock = market.Quantity,                         //限时抢购库存
                MarketPrice = product.MarketPrice,
                IsfreeShipping = shop.FreeFreight,
                ThumbnailUrl60 = Core.HimallIO.GetRomoteProductSizeImage(product.ImagePath, 1, (int)ImageSize.Size_350),
                ProductImgs = ProductImgs,
                SkuItemList = SkuItemList,
                Skus = Skus,
                Shop = model.Shop,
                VShopLog = Himall.Core.HimallIO.GetRomoteImagePath(model.VShopLog),
                Freight = GetFreightStr(product.Id, discount, skuId, addressId),
                Coupons = coupons,
                IsValidLimitBuy = true,
                CommentsNumber = CommentApplication.GetCommentCountByProduct(product.Id),
                VideoPath = string.IsNullOrWhiteSpace(product.VideoPath) ? string.Empty : Himall.Core.HimallIO.GetRomoteImagePath(product.VideoPath),
                MeasureUnit = string.IsNullOrEmpty(product.MeasureUnit)?"":product.MeasureUnit,                                                                       //单位
                SendTime = (model.FreightTemplate != null && !string.IsNullOrEmpty(model.FreightTemplate.SendTime) ? (model.FreightTemplate.SendTime + "h内发货") : ""), //运费模板发货时间
            }));
        }
        /// <summary>
        /// 拼团活动商品详情
        /// </summary>
        /// <param name="id">拼团活动ID</param>
        /// /// <param name="grouId">团活动ID</param>
        /// <returns></returns>
        public JsonResult <Result <dynamic> > GetActiveDetail(long id, long grouId = 0, bool isFirst = true, string ids = "")
        {
            var userList = new List <FightGroupOrderInfo>();
            var data     = FightGroupApplication.GetActive(id, true, true);
            FightGroupActiveModel result = data;

            //先初始化拼团商品主图
            result.InitProductImages();
            var imgpath = data.ProductImgPath;

            if (result != null)
            {
                result.IsEnd = true;
                if (data.EndTime.Date >= DateTime.Now.Date)
                {
                    result.IsEnd = false;
                }
                //商品图片地址修正
                result.ProductDefaultImage = HimallIO.GetRomoteProductSizeImage(imgpath, 1, (int)ImageSize.Size_350);
                result.ProductImgPath      = HimallIO.GetRomoteProductSizeImage(imgpath, 1);
            }
            if (result.ProductImages != null)
            {//将主图相对路径处理为绝对路径
                result.ProductImages = result.ProductImages.Select(e => HimallIO.GetRomoteImagePath(e)).ToList();
            }

            if (!string.IsNullOrWhiteSpace(result.IconUrl))
            {
                result.IconUrl = Himall.Core.HimallIO.GetRomoteImagePath(result.IconUrl);
            }
            bool IsUserEnter = false;
            long currentUser = 0;

            if (CurrentUser != null)
            {
                currentUser = CurrentUser.Id;
            }
            if (grouId > 0)//获取已参团的用户
            {
                userList = ServiceProvider.Instance <IFightGroupService> .Create.GetActiveUsers(id, grouId);

                foreach (var item in userList)
                {
                    item.Photo        = !string.IsNullOrWhiteSpace(item.Photo) ? Core.HimallIO.GetRomoteImagePath(item.Photo) : "";
                    item.HeadUserIcon = !string.IsNullOrWhiteSpace(item.HeadUserIcon) ? Core.HimallIO.GetRomoteImagePath(item.HeadUserIcon) : "";
                    if (currentUser.Equals(item.OrderUserId))
                    {
                        IsUserEnter = true;
                    }
                }
            }
            #region 商品规格
            var product = ProductManagerApplication.GetProduct((long)result.ProductId);

            ProductShowSkuInfoModel model = new ProductShowSkuInfoModel();
            model.MinSalePrice     = data.MiniSalePrice;
            model.ProductImagePath = string.IsNullOrWhiteSpace(imgpath) ? "" : HimallIO.GetRomoteProductSizeImage(imgpath, 1, (int)Himall.CommonModel.ImageSize.Size_350);

            List <SKUDataModel> skudata = data.ActiveItems.Where(d => d.ActiveStock > 0).Select(d => new SKUDataModel
            {
                SkuId     = d.SkuId,
                Color     = d.Color,
                Size      = d.Size,
                Version   = d.Version,
                Stock     = (int)d.ActiveStock,
                CostPrice = d.ProductCostPrice,
                SalePrice = d.ProductPrice,
                Price     = d.ActivePrice,
            }).ToList();

            Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetType(product.TypeId);

            string colorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
            string sizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
            string versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
            if (product != null)
            {
                colorAlias   = !string.IsNullOrWhiteSpace(product.ColorAlias) ? product.ColorAlias : colorAlias;
                sizeAlias    = !string.IsNullOrWhiteSpace(product.SizeAlias) ? product.SizeAlias : sizeAlias;
                versionAlias = !string.IsNullOrWhiteSpace(product.VersionAlias) ? product.VersionAlias : versionAlias;
            }
            model.ColorAlias   = colorAlias;
            model.SizeAlias    = sizeAlias;
            model.VersionAlias = versionAlias;

            if (result.ActiveItems != null && result.ActiveItems.Count() > 0)
            {
                long colorId = 0, sizeId = 0, versionId = 0;
                var  skus = ProductManagerApplication.GetSKUs((long)result.ProductId);
                foreach (var sku in result.ActiveItems)
                {
                    var specs = sku.SkuId.Split('_');
                    if (specs.Count() > 0 && !string.IsNullOrEmpty(sku.Color))
                    {
                        if (long.TryParse(specs[1], out colorId))
                        {
                        }
                        if (colorId != 0)
                        {
                            if (!model.Color.Any(v => v.Value.Equals(sku.Color)))
                            {
                                var c = result.ActiveItems.Where(s => s.Color.Equals(sku.Color)).Sum(s => s.ActiveStock);
                                model.Color.Add(new ProductSKU
                                {
                                    //Name = "选择颜色",
                                    Name         = "选择" + colorAlias,
                                    EnabledClass = c != 0 ? " " : "disabled",
                                    //SelectedClass = !model.Color.Any(c1 => c1.SelectedClass.Equals("selected")) && c != 0 ? "selected" : "",
                                    SelectedClass = "",
                                    SkuId         = colorId,
                                    Value         = sku.Color,
                                    Img           = string.IsNullOrWhiteSpace(sku.ShowPic) ? "" : Core.HimallIO.GetRomoteImagePath(sku.ShowPic)
                                });
                            }
                        }
                    }
                    if (specs.Count() > 1 && !string.IsNullOrEmpty(sku.Size))
                    {
                        if (long.TryParse(specs[2], out sizeId))
                        {
                        }
                        if (sizeId != 0)
                        {
                            if (!model.Size.Any(v => v.Value.Equals(sku.Size)))
                            {
                                var ss = result.ActiveItems.Where(s => s.Size.Equals(sku.Size)).Sum(s1 => s1.ActiveStock);
                                model.Size.Add(new ProductSKU
                                {
                                    //Name = "选择尺码",
                                    Name          = "选择" + sizeAlias,
                                    EnabledClass  = ss != 0 ? "enabled" : "disabled",
                                    SelectedClass = "",
                                    SkuId         = sizeId,
                                    Value         = sku.Size
                                });
                            }
                        }
                    }

                    if (specs.Count() > 2 && !string.IsNullOrEmpty(sku.Version))
                    {
                        if (long.TryParse(specs[3], out versionId))
                        {
                        }
                        if (versionId != 0)
                        {
                            if (!model.Version.Any(v => v.Value.Equals(sku.Version)))
                            {
                                var v = result.ActiveItems.Where(s => s.Version.Equals(sku.Version)).Sum(s => s.ActiveStock);
                                model.Version.Add(new ProductSKU
                                {
                                    //Name = "选择规格",
                                    Name          = "选择" + versionAlias,
                                    EnabledClass  = v != 0 ? "enabled" : "disabled",
                                    SelectedClass = "",
                                    SkuId         = versionId,
                                    Value         = sku.Version
                                });
                            }
                        }
                    }
                }
            }
            #endregion

            var cashDepositModel = CashDepositsApplication.GetCashDepositsObligation((long)result.ProductId);//提供服务(消费者保障、七天无理由、及时发货)

            var GroupsData = new List <FightGroupsListModel>();
            List <FightGroupBuildStatus> stlist = new List <FightGroupBuildStatus>();
            stlist.Add(FightGroupBuildStatus.Ongoing);
            GroupsData = FightGroupApplication.GetGroups(id, stlist, null, null, 1, 10).Models.ToList();
            foreach (var item in GroupsData)
            {
                TimeSpan mid = item.AddGroupTime.AddHours((double)item.LimitedHour) - DateTime.Now;
                item.Seconds         = (int)mid.TotalSeconds;
                item.EndHourOrMinute = item.ShowHourOrMinute(item.GetEndHour);
                item.HeadUserIcon    = !string.IsNullOrWhiteSpace(item.HeadUserIcon) ? Core.HimallIO.GetRomoteImagePath(item.HeadUserIcon) : "";
            }

            #region 商品评论
            ProductCommentShowModel modelSay = new ProductCommentShowModel();
            modelSay.ProductId = (long)result.ProductId;
            var productSay = ProductManagerApplication.GetProduct((long)result.ProductId);
            modelSay.CommentList       = new List <ProductDetailCommentModel>();
            modelSay.IsShowColumnTitle = true;
            modelSay.IsShowCommentList = true;

            if (productSay == null)
            {
                //跳转到404页面
                throw new Core.HimallException("商品不存在");
            }
            var comments = CommentApplication.GetCommentsByProduct(product.Id);
            modelSay.CommentCount = comments.Count;
            if (comments.Count > 0)
            {
                var comment   = comments.OrderByDescending(a => a.ReviewDate).FirstOrDefault();
                var orderItem = OrderApplication.GetOrderItem(comment.SubOrderId);
                var order     = OrderApplication.GetOrder(orderItem.OrderId);
                modelSay.CommentList = comments.OrderByDescending(a => a.ReviewDate)
                                       .Take(1)
                                       .Select(c => {
                    var images = CommentApplication.GetProductCommentImagesByCommentIds(new List <long> {
                        c.Id
                    });
                    return(new ProductDetailCommentModel
                    {
                        Sku = ServiceProvider.Instance <IProductService> .Create.GetSkuString(orderItem.SkuId),
                        UserName = c.UserName,
                        ReviewContent = c.ReviewContent,
                        AppendContent = c.AppendContent,
                        AppendDate = c.AppendDate,
                        ReplyAppendContent = c.ReplyAppendContent,
                        ReplyAppendDate = c.ReplyAppendDate,
                        FinshDate = order.FinishDate,
                        Images = images.Where(a => a.CommentType == 0).Select(a => a.CommentImage).ToList(),
                        AppendImages = images.Where(a => a.CommentType == 1).Select(a => a.CommentImage).ToList(),
                        ReviewDate = c.ReviewDate,
                        ReplyContent = string.IsNullOrWhiteSpace(c.ReplyContent) ? "暂无回复" : c.ReplyContent,
                        ReplyDate = c.ReplyDate,
                        ReviewMark = c.ReviewMark,
                        BuyDate = order.OrderDate
                    });
                }).ToList();
                foreach (var citem in modelSay.CommentList)
                {
                    if (citem.Images.Count > 0)
                    {
                        for (var _imgn = 0; _imgn < citem.Images.Count; _imgn++)
                        {
                            citem.Images[_imgn] = Himall.Core.HimallIO.GetRomoteImagePath(citem.Images[_imgn]);
                        }
                    }
                    if (citem.AppendImages.Count > 0)
                    {
                        for (var _imgn = 0; _imgn < citem.AppendImages.Count; _imgn++)
                        {
                            citem.AppendImages[_imgn] = Himall.Core.HimallIO.GetRomoteImagePath(citem.AppendImages[_imgn]);
                        }
                    }
                }
            }
            #endregion

            #region 店铺信息
            VShopShowShopScoreModel modelShopScore = new VShopShowShopScoreModel();
            modelShopScore.ShopId = result.ShopId;
            var shop = ServiceProvider.Instance <IShopService> .Create.GetShop(result.ShopId);

            if (shop == null)
            {
                throw new HimallException("错误的店铺信息");
            }

            modelShopScore.ShopName = shop.ShopName;

            #region 获取店铺的评价统计
            var shopStatisticOrderComments = ServiceProvider.Instance <IShopService> .Create.GetShopStatisticOrderComments(result.ShopId);

            var productAndDescription = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescription).FirstOrDefault();
            var sellerServiceAttitude = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitude).FirstOrDefault();
            var sellerDeliverySpeed   = shopStatisticOrderComments.Where(c => c.CommentKey ==
                                                                         Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeed).FirstOrDefault();

            var productAndDescriptionPeer = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescriptionPeer).FirstOrDefault();
            var sellerServiceAttitudePeer = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitudePeer).FirstOrDefault();
            var sellerDeliverySpeedPeer   = shopStatisticOrderComments.Where(c => c.CommentKey ==
                                                                             Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeedPeer).FirstOrDefault();

            var productAndDescriptionMax = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescriptionMax).FirstOrDefault();
            var productAndDescriptionMin = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescriptionMin).FirstOrDefault();

            var sellerServiceAttitudeMax = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitudeMax).FirstOrDefault();
            var sellerServiceAttitudeMin = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitudeMin).FirstOrDefault();

            var sellerDeliverySpeedMax = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeedMax).FirstOrDefault();
            var sellerDeliverySpeedMin = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeedMin).FirstOrDefault();

            decimal defaultValue = 5;

            modelShopScore.SellerServiceAttitude     = defaultValue;
            modelShopScore.SellerServiceAttitudePeer = defaultValue;
            modelShopScore.SellerServiceAttitudeMax  = defaultValue;
            modelShopScore.SellerServiceAttitudeMin  = defaultValue;

            //宝贝与描述
            if (productAndDescription != null && productAndDescriptionPeer != null && !shop.IsSelf)
            {
                modelShopScore.ProductAndDescription     = productAndDescription.CommentValue;
                modelShopScore.ProductAndDescriptionPeer = productAndDescriptionPeer.CommentValue;
                modelShopScore.ProductAndDescriptionMin  = productAndDescriptionMin.CommentValue;
                modelShopScore.ProductAndDescriptionMax  = productAndDescriptionMax.CommentValue;
            }
            else
            {
                modelShopScore.ProductAndDescription     = defaultValue;
                modelShopScore.ProductAndDescriptionPeer = defaultValue;
                modelShopScore.ProductAndDescriptionMin  = defaultValue;
                modelShopScore.ProductAndDescriptionMax  = defaultValue;
            }

            //卖家服务态度
            if (sellerServiceAttitude != null && sellerServiceAttitudePeer != null && !shop.IsSelf)
            {
                modelShopScore.SellerServiceAttitude     = sellerServiceAttitude.CommentValue;
                modelShopScore.SellerServiceAttitudePeer = sellerServiceAttitudePeer.CommentValue;
                modelShopScore.SellerServiceAttitudeMax  = sellerServiceAttitudeMax.CommentValue;
                modelShopScore.SellerServiceAttitudeMin  = sellerServiceAttitudeMin.CommentValue;
            }
            else
            {
                modelShopScore.SellerServiceAttitude     = defaultValue;
                modelShopScore.SellerServiceAttitudePeer = defaultValue;
                modelShopScore.SellerServiceAttitudeMax  = defaultValue;
                modelShopScore.SellerServiceAttitudeMin  = defaultValue;
            }
            //卖家发货速度
            if (sellerDeliverySpeedPeer != null && sellerDeliverySpeed != null && !shop.IsSelf)
            {
                modelShopScore.SellerDeliverySpeed     = sellerDeliverySpeed.CommentValue;
                modelShopScore.SellerDeliverySpeedPeer = sellerDeliverySpeedPeer.CommentValue;
                modelShopScore.SellerDeliverySpeedMax  = sellerDeliverySpeedMax != null ? sellerDeliverySpeedMax.CommentValue : 0;
                modelShopScore.sellerDeliverySpeedMin  = sellerDeliverySpeedMin != null ? sellerDeliverySpeedMin.CommentValue : 0;
            }
            else
            {
                modelShopScore.SellerDeliverySpeed     = defaultValue;
                modelShopScore.SellerDeliverySpeedPeer = defaultValue;
                modelShopScore.SellerDeliverySpeedMax  = defaultValue;
                modelShopScore.sellerDeliverySpeedMin  = defaultValue;
            }
            #endregion

            modelShopScore.ProductNum = ServiceProvider.Instance <IProductService> .Create.GetShopOnsaleProducts(result.ShopId);

            modelShopScore.IsFavoriteShop    = false;
            modelShopScore.FavoriteShopCount = ServiceProvider.Instance <IShopService> .Create.GetShopFavoritesCount(result.ShopId);

            if (CurrentUser != null)
            {
                modelShopScore.IsFavoriteShop = ServiceProvider.Instance <IShopService> .Create.GetFavoriteShopInfos(CurrentUser.Id).Any(d => d.ShopId == result.ShopId);
            }

            long vShopId;
            var  vshopinfo = ServiceProvider.Instance <IVShopService> .Create.GetVShopByShopId(shop.Id);

            if (vshopinfo == null)
            {
                vShopId = -1;
            }
            else
            {
                vShopId = vshopinfo.Id;
            }
            modelShopScore.VShopId  = vShopId;
            modelShopScore.VShopLog = ServiceProvider.Instance <IVShopService> .Create.GetVShopLog(vShopId);

            if (!string.IsNullOrWhiteSpace(modelShopScore.VShopLog))
            {
                modelShopScore.VShopLog = Himall.Core.HimallIO.GetRomoteImagePath(modelShopScore.VShopLog);
            }

            // 客服
            var customerServices = CustomerServiceApplication.GetMobileCustomerServiceAndMQ(shop.Id);
            #endregion
            #region 根据运费模板获取发货地址
            var    freightTemplateService = ServiceApplication.Create <IFreightTemplateService>();
            var    template       = freightTemplateService.GetFreightTemplate(product.FreightTemplateId);
            string productAddress = string.Empty;
            if (template != null)
            {
                var fullName = ServiceApplication.Create <IRegionService>().GetFullName(template.SourceAddress);
                if (fullName != null)
                {
                    var ass = fullName.Split(' ');
                    if (ass.Length >= 2)
                    {
                        productAddress = ass[0] + " " + ass[1];
                    }
                    else
                    {
                        productAddress = ass[0];
                    }
                }
            }

            var ProductAddress  = productAddress;
            var FreightTemplate = template;
            #endregion

            #region 获取店铺优惠信息
            VShopShowPromotionModel modelVshop = new VShopShowPromotionModel();
            modelVshop.ShopId = result.ShopId;
            var shopInfo = ServiceProvider.Instance <IShopService> .Create.GetShop(result.ShopId);

            if (shopInfo == null)
            {
                throw new HimallException("错误的店铺编号");
            }

            modelVshop.FreeFreight = shop.FreeFreight;


            var bonus = ServiceApplication.Create <IShopBonusService>().GetByShopId(result.ShopId);
            if (bonus != null)
            {
                modelVshop.BonusCount             = bonus.Count;
                modelVshop.BonusGrantPrice        = bonus.GrantPrice;
                modelVshop.BonusRandomAmountStart = bonus.RandomAmountStart;
                modelVshop.BonusRandomAmountEnd   = bonus.RandomAmountEnd;
            }
            FullDiscountActive fullDiscount = null;
            //var fullDiscount = FullDiscountApplication.GetOngoingActiveByProductId(id, shop.Id);
            #endregion
            //商品描述

            var description = ProductManagerApplication.GetProductDescription(result.ProductId);
            if (description == null)
            {
                throw new HimallException("错误的商品编号");
            }

            string DescriptionPrefix = "", DescriptiondSuffix = "";
            var    iprodestempser = ServiceApplication.Create <IProductDescriptionTemplateService>();
            if (description.DescriptionPrefixId != 0)
            {
                var desc = iprodestempser.GetTemplate(description.DescriptionPrefixId, product.ShopId);
                DescriptionPrefix = desc == null ? "" : desc.MobileContent;
            }

            if (description.DescriptiondSuffixId != 0)
            {
                var desc = iprodestempser.GetTemplate(description.DescriptiondSuffixId, product.ShopId);
                DescriptiondSuffix = desc == null ? "" : desc.MobileContent;
            }
            var productDescription = DescriptionPrefix + description.ShowMobileDescription + DescriptiondSuffix;
            //统计商品浏览量、店铺浏览人数
            StatisticApplication.StatisticVisitCount(product.Id, product.ShopId);

            AutoMapper.Mapper.CreateMap <FightGroupActiveModel, FightGroupActiveResult>();
            var     fightGroupData = AutoMapper.Mapper.Map <FightGroupActiveResult>(result);
            decimal discount       = 1M;
            if (CurrentUser != null)
            {
                discount = CurrentUser.MemberDiscount;
            }
            var shopItem = ShopApplication.GetShop(result.ShopId);
            fightGroupData.MiniSalePrice = shopItem.IsSelf ? fightGroupData.MiniSalePrice * discount : fightGroupData.MiniSalePrice;

            string loadShowPrice = string.Empty;//app拼团详细页加载时显示的区间价
            loadShowPrice = fightGroupData.MiniSalePrice.ToString("f2");

            if (fightGroupData != null && fightGroupData.ActiveItems.Count() > 0)
            {
                decimal min = fightGroupData.ActiveItems.Min(s => s.ActivePrice);
                decimal max = fightGroupData.ActiveItems.Max(s => s.ActivePrice);
                loadShowPrice = (min < max) ? (min.ToString("f2") + " - " + max.ToString("f2")) : min.ToString("f2");
            }

            var _result = new
            {
                success        = true,
                FightGroupData = fightGroupData,
                ShowSkuInfo    = new
                {
                    ColorAlias       = model.ColorAlias,
                    SizeAlias        = model.SizeAlias,
                    VersionAlias     = model.VersionAlias,
                    MinSalePrice     = model.MinSalePrice,
                    ProductImagePath = model.ProductImagePath,
                    Color            = model.Color.OrderByDescending(p => p.SkuId),
                    Size             = model.Size.OrderByDescending(p => p.SkuId),
                    Version          = model.Version.OrderByDescending(p => p.SkuId)
                },
                ShowPromotion       = modelVshop,
                fullDiscount        = fullDiscount,
                ShowNewCanJoinGroup = GroupsData,
                ProductCommentShow  = modelSay,
                ProductDescription  = productDescription.Replace("src=\"/Storage/", "src=\"" + Core.HimallIO.GetRomoteImagePath("/Storage") + "/"),
                ShopScore           = modelShopScore,
                CashDepositsServer  = cashDepositModel,
                ProductAddress      = ProductAddress,
                //Free = FreightTemplate.IsFree == FreightTemplateType.Free ? "免运费" : "",
                userList              = userList,
                IsUserEnter           = IsUserEnter,
                SkuData               = skudata,
                CustomerServices      = customerServices,
                IsOpenLadder          = product.IsOpenLadder,
                VideoPath             = string.IsNullOrWhiteSpace(product.VideoPath) ? string.Empty : Himall.Core.HimallIO.GetRomoteImagePath(product.VideoPath),
                LoadShowPrice         = loadShowPrice,                                                                                                           //商品时区间价
                ProductSaleCountOnOff = (SiteSettingApplication.SiteSettings.ProductSaleCountOnOff == 1),                                                        //是否显示销量
                SaleCounts            = data.ActiveItems.Sum(d => d.BuyCount),                                                                                   //销量
                FreightStr            = FreightTemplateApplication.GetFreightStr(product.Id, FreightTemplate, CurrentUser, product),                             //运费多少或免运费
                SendTime              = (FreightTemplate != null && !string.IsNullOrEmpty(FreightTemplate.SendTime) ? (FreightTemplate.SendTime + "h内发货") : ""), //运费模板发货时间
            };
            return(JsonResult <dynamic>(_result));
        }
Exemple #16
0
        private List <CartProductModel> PackageCartProducts(Mall.Entities.ShoppingCartInfo cart, decimal prodPrice, decimal discount, IProductService productService, IShopService shopService, IShopBranchService shopBranchService, IVShopService vshopService, ITypeService typeservice, bool isBranch = false)
        {
            List <CartProductModel> products = new List <CartProductModel>();
            var limitProducts = LimitTimeApplication.GetPriceByProducrIds(cart.Items.Select(e => e.ProductId).ToList());//限时购价格
            var groupCart     = cart.Items.Where(item => item.ShopBranchId == 0).Select(c =>
            {
                var cItem   = new Mall.Entities.ShoppingCartItem();
                var skuInfo = productService.GetSku(c.SkuId);
                if (skuInfo != null)
                {
                    cItem = c;
                }
                return(cItem);
            }).GroupBy(i => i.ProductId).ToList();

            foreach (var item in cart.Items)
            {
                var                        product       = ProductManagerApplication.GetProduct(item.ProductId);
                var                        shop          = shopService.GetShop(product.ShopId);
                DTO.ShopBranch             shopbranch    = null;
                Entities.ShopBranchSkuInfo shopbranchsku = null;
                if (item.ShopBranchId > 0)
                {
                    shopbranch    = ShopBranchApplication.GetShopBranchById(item.ShopBranchId);
                    shopbranchsku = shopBranchService.GetSkusByIds(item.ShopBranchId, new List <string> {
                        item.SkuId
                    }).FirstOrDefault();
                }

                if (null != shop)
                {
                    var vshop = vshopService.GetVShopByShopId(shop.Id);
                    var sku   = ProductManagerApplication.GetSKU(item.SkuId);
                    if (sku == null)
                    {
                        continue;
                    }
                    //处理限时购、会员折扣价格
                    var prod = limitProducts.FirstOrDefault(e => e.ProductId == item.ProductId);
                    prodPrice = sku.SalePrice;
                    if (prod != null && !isBranch)
                    {
                        prodPrice = prod.MinPrice;
                    }
                    else
                    {
                        if (shop.IsSelf)
                        {//官方自营店才计算会员折扣
                            prodPrice = sku.SalePrice * discount;
                        }
                    }
                    #region 阶梯价--张宇枫
                    //阶梯价
                    if (product.IsOpenLadder)
                    {
                        var quantity = groupCart.Where(i => i.Key == item.ProductId).ToList().Sum(cartitem => cartitem.Sum(i => i.Quantity));
                        prodPrice = ProductManagerApplication.GetProductLadderPrice(item.ProductId, quantity);
                        if (shop.IsSelf)
                        {
                            prodPrice = prodPrice * discount;
                        }
                    }
                    #endregion
                    Entities.TypeInfo typeInfo     = typeservice.GetType(product.TypeId);
                    string            colorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    string            sizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    string            versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    if (product != null)
                    {
                        colorAlias   = !string.IsNullOrWhiteSpace(product.ColorAlias) ? product.ColorAlias : colorAlias;
                        sizeAlias    = !string.IsNullOrWhiteSpace(product.SizeAlias) ? product.SizeAlias : sizeAlias;
                        versionAlias = !string.IsNullOrWhiteSpace(product.VersionAlias) ? product.VersionAlias : versionAlias;
                    }
                    if (sku != null)
                    {
                        #region 正在参加限时抢购商品在购物车失效 TDO:ZYF
                        var isLimit = false;
                        //门店商品,在参加限时购,也可以正常购买
                        var limit = LimitTimeApplication.GetLimitTimeMarketItemByProductId(item.ProductId);
                        if (limit != null && !isBranch)
                        {
                            isLimit = limit.Status == Entities.FlashSaleInfo.FlashSaleStatus.Ongoing;
                        }
                        #endregion
                        var _tmp = new CartProductModel
                        {
                            CartItemId     = item.Id.ToString(),
                            SkuId          = item.SkuId,
                            Id             = product.Id.ToString(),
                            ImgUrl         = Core.MallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)Mall.CommonModel.ImageSize.Size_150),
                            Name           = product.ProductName,
                            Price          = prodPrice.ToString("F2"),
                            Count          = item.Quantity.ToString(),
                            ShopId         = shop.Id.ToString(),
                            Size           = sku.Size,
                            Color          = sku.Color,
                            Version        = sku.Version,
                            VShopId        = vshop == null ? "0" : vshop.Id.ToString(),
                            ShopName       = shop.ShopName,
                            ShopLogo       = vshop == null ? "" : Core.MallIO.GetRomoteImagePath(vshop.StrLogo),
                            Url            = Core.MallIO.GetRomoteImagePath("/m-IOS/product/detail/") + item.ProductId,
                            ProductStatus  = isLimit ? 0 : (sku.Stock <= 0 ? ProductInfo.ProductSaleStatus.InStock.GetHashCode() : product.SaleStatus.GetHashCode()),
                            Status         = isLimit ? 1 : ProductManagerApplication.GetProductShowStatus(product, sku, shopbranch == null ? 1 : item.Quantity, shopbranch, shopbranchsku),// 0:正常;1:已失效;2:库存不足;3:已下架;
                            ColorAlias     = colorAlias,
                            SizeAlias      = sizeAlias,
                            VersionAlias   = versionAlias,
                            AddTime        = item.AddTime,
                            ShopBranchId   = item.ShopBranchId,
                            ShopBranchName = null == shopbranch ? "" : shopbranch.ShopBranchName,
                            ShopBranchLogo = null == shopbranch ? "" : Core.MallIO.GetRomoteImagePath(shopbranch.ShopImages)
                        };
                        products.Add(_tmp);
                    }
                }
            }
            return(products);
        }
        public object GetOrderDetail(long id)
        {
            CheckUserLogin();
            long shopid = CurrentShopBranch.ShopId;
            long sbid   = CurrentUser.ShopBranchId;

            var ordser = ServiceProvider.Instance <IOrderService> .Create;

            Entities.OrderInfo order = ordser.GetOrder(id);
            if (order == null || order.ShopBranchId != sbid)
            {
                throw new HimallApiException("错误的订单编号");
            }
            var bonusService       = ServiceProvider.Instance <IShopBonusService> .Create;
            var orderRefundService = ServiceProvider.Instance <IRefundService> .Create;
            var shopService        = ServiceProvider.Instance <IShopService> .Create;
            var productService     = ServiceProvider.Instance <IProductService> .Create;
            var vshop = ServiceProvider.Instance <IVShopService> .Create.GetVShopByShopId(order.ShopId);

            var  orderitems = OrderApplication.GetOrderItems(order.Id);
            bool isCanApply = false;
            //获取订单商品项数据
            var orderDetail = new
            {
                ShopName   = shopService.GetShop(order.ShopId).ShopName,
                ShopId     = order.ShopId,
                OrderItems = orderitems.Select(item =>
                {
                    var productinfo = productService.GetProduct(item.ProductId);
                    if (order.OrderStatus == Entities.OrderInfo.OrderOperateStatus.WaitDelivery)
                    {
                        isCanApply = orderRefundService.CanApplyRefund(id, item.Id);
                    }
                    else
                    {
                        isCanApply = orderRefundService.CanApplyRefund(id, item.Id, false);
                    }

                    Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetType(productinfo.TypeId);
                    string colorAlias          = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    string sizeAlias           = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    string versionAlias        = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    if (productinfo != null)
                    {
                        colorAlias   = !string.IsNullOrWhiteSpace(productinfo.ColorAlias) ? productinfo.ColorAlias : colorAlias;
                        sizeAlias    = !string.IsNullOrWhiteSpace(productinfo.SizeAlias) ? productinfo.SizeAlias : sizeAlias;
                        versionAlias = !string.IsNullOrWhiteSpace(productinfo.VersionAlias) ? productinfo.VersionAlias : versionAlias;
                    }
                    return(new
                    {
                        ItemId = item.Id,
                        ProductId = item.ProductId,
                        ProductName = item.ProductName,
                        Count = item.Quantity,
                        Price = item.SalePrice,
                        //ProductImage = "http://" + Url.Request.RequestUri.Host + productService.GetProduct(item.ProductId).GetImage(ProductInfo.ImageSize.Size_100),
                        ProductImage = Core.HimallIO.GetRomoteProductSizeImage(productService.GetProduct(item.ProductId).RelativePath, 1, (int)Himall.CommonModel.ImageSize.Size_100),
                        color = item.Color,
                        size = item.Size,
                        version = item.Version,
                        IsCanRefund = isCanApply,
                        ColorAlias = colorAlias,
                        SizeAlias = sizeAlias,
                        VersionAlias = versionAlias
                    });
                })
            };

            VirtualProductInfo virtualProductInfo = null;
            List <dynamic>     codes = null;
            List <dynamic>     virtualItems = null;
            int validityType = 0; string startDate = string.Empty, endDate = string.Empty;

            if (order.OrderType == OrderInfo.OrderTypes.Virtual && orderDetail.OrderItems != null)
            {
                virtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(orderDetail.OrderItems.FirstOrDefault().ProductId);
                if (virtualProductInfo != null)
                {
                    validityType = virtualProductInfo.ValidityType ? 1 : 0;
                    if (validityType == 1)
                    {
                        startDate = virtualProductInfo.StartDate.Value.ToString("yyyy-MM-dd");
                        endDate   = virtualProductInfo.EndDate.Value.ToString("yyyy-MM-dd");
                    }
                }
                var verificationCodes = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>()
                {
                    order.Id
                });
                if (verificationCodes != null)
                {
                    verificationCodes.ForEach(a =>
                    {
                        if (a.Status == OrderInfo.VerificationCodeStatus.WaitVerification || a.Status == OrderInfo.VerificationCodeStatus.Refund)
                        {
                            a.VerificationCode = System.Text.RegularExpressions.Regex.Replace(a.VerificationCode, "(\\d{4})\\d{4}(\\d{4})", "$1****$2");
                        }
                        a.VerificationCode = System.Text.RegularExpressions.Regex.Replace(a.VerificationCode, @"(\d{4})", "$1 ");
                    });
                }
                codes = verificationCodes.Select(p =>
                {
                    return(new
                    {
                        VerificationCode = p.VerificationCode,
                        Status = p.Status,
                        StatusText = p.Status.ToDescription()
                    });
                }).ToList <dynamic>();

                var virtualOrderItems = OrderApplication.GetVirtualOrderItemInfosByOrderId(order.Id);
                virtualItems = virtualOrderItems.Select(p =>
                {
                    return(new
                    {
                        VirtualProductItemName = p.VirtualProductItemName,
                        VirtualProductItemType = p.VirtualProductItemType,
                        Content = ReplaceImage(p.Content, p.VirtualProductItemType)
                    });
                }).ToList <dynamic>();
            }
            var orderModel = new
            {
                Id                 = order.Id,
                OrderType          = order.OrderType,
                OrderTypeName      = order.OrderType.ToDescription(),
                Status             = order.OrderStatus.ToDescription(),
                ShipTo             = order.ShipTo,
                Phone              = order.CellPhone,
                Address            = order.RegionFullName + " " + order.Address,
                HasExpressStatus   = !string.IsNullOrWhiteSpace(order.ShipOrderNumber),
                ExpressCompanyName = order.ExpressCompanyName,
                Freight            = order.Freight,
                Tax                = order.Tax,
                IntegralDiscount   = order.IntegralDiscount,
                RealTotalAmount    = order.OrderTotalAmount - order.RefundTotalAmount,
                CapitalAmount      = order.CapitalAmount,
                RefundTotalAmount  = order.RefundTotalAmount,
                ProductTotalAmount = order.ProductTotalAmount,
                OrderDate          = order.OrderDate.ToString("yyyy-MM-dd HH:mm:ss"),
                ShopName           = order.ShopName,
                ShopBranchName     = CurrentShopBranch.ShopBranchName,
                VShopId            = vshop == null ? 0 : vshop.Id,
                commentCount       = OrderApplication.GetOrderCommentCount(order.Id),
                ShopId             = order.ShopId,
                orderStatus        = (int)order.OrderStatus,
                //Invoice = order.InvoiceType.ToDescription(),
                //InvoiceValue = (int)order.InvoiceType,
                //InvoiceContext = order.InvoiceContext,
                //InvoiceTitle = order.InvoiceTitle,
                PaymentType      = order.PaymentType.ToDescription(),
                PaymentTypeValue = (int)order.PaymentType,
                PaymentTypeDesc  = order.PaymentTypeDesc,
                OrderPayAmount   = order.OrderPayAmount,
                PaymentTypeName  = PaymentApplication.GetPaymentTypeDescById(order.PaymentTypeGateway) ?? order.PaymentTypeName,
                FullDiscount     = order.FullDiscount,
                DiscountAmount   = order.DiscountAmount,
                OrderRemarks     = order.OrderRemarks,
                DeliveryType     = order.DeliveryType,
                //InvoiceCode = order.InvoiceCode,
                OrderInvoice = OrderApplication.GetOrderInvoiceInfo(order.Id)
            };

            return(new { success = true, Order = orderModel, OrderItem = orderDetail.OrderItems, VerificationCodes = codes, VirtualOrderItems = virtualItems, StartDate = startDate, EndDate = endDate, ValidityType = validityType });
        }
        private List <OrderRefundApiModel> FullModel(List <OrderRefund> refunds)
        {
            var orders     = Application.OrderApplication.GetOrders(refunds.Select(p => p.OrderId));
            var orderItems = Application.OrderApplication.GetOrderItemsByOrderId(refunds.Select(p => p.OrderId));
            var members    = Application.MemberApplication.GetMembers(orders.Select(p => p.UserId).ToList());

            AutoMapper.Mapper.CreateMap <OrderRefund, OrderRefundApiModel>();
            var result = refunds.Select(item =>
            {
                var orditems = new List <DTO.OrderItem>();
                var order    = orders.FirstOrDefault(o => o.Id == item.OrderId);

                if (item.RefundMode == OrderRefundInfo.OrderRefundMode.OrderRefund)
                {
                    orditems = orderItems.Where(d => d.OrderId == item.OrderId).ToList();
                }
                else
                {
                    orditems.Add(orderItems.FirstOrDefault(oi => oi.Id == item.OrderItemId));
                }
                foreach (var orderItem in orditems)
                {
                    orderItem.ThumbnailsUrl    = HimallIO.GetRomoteProductSizeImage(orderItem.ThumbnailsUrl, 1, (int)Himall.CommonModel.ImageSize.Size_100);
                    Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetTypeByProductId(orderItem.ProductId);
                    orderItem.ColorAlias       = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    orderItem.SizeAlias        = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    orderItem.VersionAlias     = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    orderItem.ShipTo           = order.ShipTo;
                    orderItem.CellPhone        = order.CellPhone;
                    orderItem.RegionFullName   = order.RegionFullName;
                    orderItem.Address          = order.Address;
                    var productInfo            = ProductManagerApplication.GetProduct(orderItem.ProductId);
                    if (productInfo != null)
                    {
                        orderItem.ColorAlias   = !string.IsNullOrWhiteSpace(productInfo.ColorAlias) ? productInfo.ColorAlias : orderItem.ColorAlias;
                        orderItem.SizeAlias    = !string.IsNullOrWhiteSpace(productInfo.SizeAlias) ? productInfo.SizeAlias : orderItem.SizeAlias;
                        orderItem.VersionAlias = !string.IsNullOrWhiteSpace(productInfo.VersionAlias) ? productInfo.VersionAlias : orderItem.VersionAlias;
                    }
                }
                var member = members.FirstOrDefault(m => m.Id == order.UserId);

                var model    = item.Map <OrderRefundApiModel>();
                model.Status = item.SellerAuditStatus == OrderRefundInfo.OrderRefundAuditStatus.Audited ? (int)item.ManagerConfirmStatus : (int)item.SellerAuditStatus;
                //model.StatusDescription = item.SellerAuditStatus == OrderRefundInfo.OrderRefundAuditStatus.Audited ? item.ManagerConfirmStatus.ToDescription() : ((CommonModel.Enum.OrderRefundShopAuditStatus)item.SellerAuditStatus).ToDescription();
                model.StatusDescription = item.SellerAuditStatus == OrderRefundInfo.OrderRefundAuditStatus.Audited ? item.ManagerConfirmStatus.ToDescription() : (order.ShopBranchId > 0 ?
                                                                                                                                                                  ((CommonModel.Enum.OrderRefundShopAuditStatus)item.SellerAuditStatus).ToDescription() : item.SellerAuditStatus.ToDescription());
                //model.UserName = member == null ? "" : member.RealName;
                //model.UserCellPhone = member == null ? "" : member.CellPhone;
                model.IsShopBranchOrder = item.IsShopBranchOrder;
                if (item.IsShopBranchOrder)
                {
                    model.StatusDescription = model.StatusDescription.Replace("商家", "门店");
                    model.RefundStatus      = model.RefundStatus.Replace("商家", "门店");
                }
                model.UserName        = item.ContactPerson;
                model.UserCellPhone   = item.ContactCellPhone;
                model.OrderItem       = orditems;
                model.CertPics        = new string[3];
                model.CertPics[0]     = HimallIO.GetRomoteImagePath(model.CertPic1);
                model.CertPics[1]     = HimallIO.GetRomoteImagePath(model.CertPic2);
                model.CertPics[2]     = HimallIO.GetRomoteImagePath(model.CertPic3);
                string shopBranchName = order.ShopName;
                if (order.ShopBranchId > 0)
                {
                    var shopBranchInfo = ShopBranchApplication.GetShopBranchById(order.ShopBranchId);
                    if (shopBranchInfo != null)
                    {
                        shopBranchName = shopBranchInfo.ShopBranchName;
                    }
                }
                model.ShopName         = shopBranchName;
                model.ReasonDetail     = item.ReasonDetail;
                model.OrderTotalAmount = order.OrderTotalAmount;

                return(model);
            });

            return(result.ToList());
        }
        public ActionResult Detail(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(RedirectToAction("Error404", "Error", new { area = "Web" }));
            }
            string price = "";

            #region 定义Model和变量

            LimitTimeProductDetailModel model = new LimitTimeProductDetailModel
            {
                MainId = long.Parse(id),
                HotAttentionProducts = new List <HotProductInfo>(),
                HotSaleProducts      = new List <HotProductInfo>(),
                Product      = new Entities.ProductInfo(),
                Shop         = new ShopInfoModel(),
                ShopCategory = new List <CategoryJsonModel>(),
                Color        = new CollectionSKU(),
                Size         = new CollectionSKU(),
                Version      = new CollectionSKU()
            };

            FlashSaleModel    market = null;
            Entities.ShopInfo shop   = null;

            long gid = 0, mid = 0;

            #endregion


            #region 商品Id不合法
            if (long.TryParse(id, out mid))
            {
            }
            if (mid == 0)
            {
                //跳转到出错页面
                return(RedirectToAction("Error404", "Error", new { area = "Web" }));
            }
            #endregion


            #region 初始化商品和店铺

            market = _iLimitTimeBuyService.Get(mid);

            switch (market.Status)
            {
            case Entities.FlashSaleInfo.FlashSaleStatus.Ended:
                return(RedirectToAction("Detail", "Product", new { id = market.ProductId }));

            case Entities.FlashSaleInfo.FlashSaleStatus.Cancelled:
                return(RedirectToAction("Detail", "Product", new { id = market.ProductId }));
            }
            if (market.Status != Entities.FlashSaleInfo.FlashSaleStatus.Ongoing)
            {
                return(RedirectToAction("Home"));
            }
            model.FlashSale = market;
            if (market == null || market.Id == 0 || market.Status != FlashSaleInfo.FlashSaleStatus.Ongoing)
            {
                //可能参数是商品ID
                market = market == null?_iLimitTimeBuyService.GetFlaseSaleByProductId(mid) : market;

                if (market == null)
                {
                    //跳转到404页面
                    return(RedirectToAction("Error404", "Error", new { area = "Mobile" }));
                }
                if (market.Status != FlashSaleInfo.FlashSaleStatus.Ongoing)
                {
                    return(RedirectToAction("Detail", "Product", new { id = market.ProductId }));
                }
            }

            model.MaxSaleCount = market.LimitCountOfThePeople;
            model.Title        = market.Title;

            shop            = _iShopService.GetShop(market.ShopId);
            model.Shop.Name = shop.ShopName;
            #endregion

            #region 商品描述
            var product = _iProductService.GetProduct(market.ProductId);
            gid = market.ProductId;


            var brandModel = ServiceApplication.Create <IBrandService>().GetBrand(product.BrandId);
            product.BrandName = brandModel == null ? "" : brandModel.Name;
            if (CurrentUser != null && CurrentUser.Id > 0)
            {
                product.IsFavorite = ProductManagerApplication.IsFavorite(product.Id, CurrentUser.Id);
            }
            model.Product = product;
            model.Skus    = ProductManagerApplication.GetSKUsByProduct(new List <long> {
                product.Id
            });
            var description = ProductManagerApplication.GetProductDescription(product.Id);
            model.ProductDescription = description.Description;
            if (description.DescriptionPrefixId != 0)
            {
                var desc = _iProductDescriptionTemplateService
                           .GetTemplate(description.DescriptionPrefixId, product.ShopId);
                model.DescriptionPrefix = desc == null ? "" : desc.Content;
            }

            if (description.DescriptiondSuffixId != 0)
            {
                var desc = _iProductDescriptionTemplateService
                           .GetTemplate(description.DescriptiondSuffixId, product.ShopId);
                model.DescriptiondSuffix = desc == null ? "" : desc.Content;
            }

            #endregion

            #region 店铺

            var categories = _iShopCategoryService.GetShopCategory(product.ShopId);
            List <Entities.ShopCategoryInfo> allcate = categories.ToList();
            foreach (var main in allcate.Where(s => s.ParentCategoryId == 0))
            {
                var topC = new CategoryJsonModel()
                {
                    Name        = main.Name,
                    Id          = main.Id.ToString(),
                    SubCategory = new List <SecondLevelCategory>()
                };
                foreach (var secondItem in allcate.Where(s => s.ParentCategoryId == main.Id))
                {
                    var secondC = new SecondLevelCategory()
                    {
                        Name = secondItem.Name,
                        Id   = secondItem.Id.ToString(),
                    };

                    topC.SubCategory.Add(secondC);
                }
                model.ShopCategory.Add(topC);
            }
            model.CashDeposits = _iCashDepositsService.GetCashDepositsObligation(product.Id);

            #endregion

            #region 热门销售

            //会员折扣
            decimal discount   = 1M;
            long    SelfShopId = 0;
            if (CurrentUser != null)
            {
                discount = CurrentUser.MemberDiscount;
                var shopInfo = ShopApplication.GetSelfShop();
                SelfShopId = shopInfo.Id;
            }
            var sale = _iProductService.GetHotSaleProduct(shop.Id, 5);
            if (sale != null)
            {
                foreach (var item in sale.ToArray())
                {
                    var salePrice = item.MinSalePrice;
                    if (item.ShopId == SelfShopId)
                    {
                        salePrice = item.MinSalePrice * discount;
                    }
                    var limitBuy = LimitTimeApplication.GetLimitTimeMarketItemByProductId(item.Id);
                    if (limitBuy != null)
                    {
                        salePrice = limitBuy.MinPrice;
                    }
                    model.HotSaleProducts.Add(new HotProductInfo
                    {
                        ImgPath   = item.ImagePath,
                        Name      = item.ProductName,
                        Price     = Math.Round(salePrice, 2),
                        Id        = item.Id,
                        SaleCount = (int)item.SaleCounts + Mall.Core.Helper.TypeHelper.ObjectToInt(item.VirtualSaleCounts)
                    });
                }
            }

            #endregion

            #region 热门关注

            var hot = _iProductService.GetHotConcernedProduct(shop.Id, 5);
            if (hot != null)
            {
                foreach (var item in hot.ToArray())
                {
                    model.HotAttentionProducts.Add(new HotProductInfo
                    {
                        ImgPath   = item.ImagePath,
                        Name      = item.ProductName,
                        Price     = item.MinSalePrice,
                        Id        = item.Id,
                        SaleCount = (int)item.ConcernedCount
                    });
                }
            }
            #endregion

            #region 商品规格

            Entities.TypeInfo typeInfo     = _iTypeService.GetType(product.TypeId);
            string            colorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
            string            sizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
            string            versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
            if (product != null)
            {
                colorAlias   = !string.IsNullOrWhiteSpace(product.ColorAlias) ? product.ColorAlias : colorAlias;
                sizeAlias    = !string.IsNullOrWhiteSpace(product.SizeAlias) ? product.SizeAlias : sizeAlias;
                versionAlias = !string.IsNullOrWhiteSpace(product.VersionAlias) ? product.VersionAlias : versionAlias;
            }
            model.ColorAlias   = colorAlias;
            model.SizeAlias    = sizeAlias;
            model.VersionAlias = versionAlias;
            var skus = _iProductService.GetSKUs(product.Id);
            if (skus.Count > 0)
            {
                long colorId = 0, sizeId = 0, versionId = 0;
                foreach (var sku in skus)
                {
                    var specs = sku.Id.Split('_');
                    if (specs.Count() > 0 && !string.IsNullOrEmpty(sku.Color))
                    {
                        if (long.TryParse(specs[1], out colorId))
                        {
                        }
                        if (colorId != 0)
                        {
                            if (!model.Color.Any(v => v.Value.Equals(sku.Color)))
                            {
                                var c = skus.Where(s => s.Color.Equals(sku.Color)).Sum(s => s.Stock);
                                model.Color.Add(new ProductSKU
                                {
                                    //Name = "选择颜色",
                                    Name         = "选择" + colorAlias,
                                    EnabledClass = c != 0 ? "enabled" : "disabled",
                                    //SelectedClass = !model.Color.Any(c1 => c1.SelectedClass.Equals("selected")) && c != 0 ? "selected" : "",
                                    SelectedClass = "",
                                    SkuId         = colorId,
                                    Value         = sku.Color,
                                    Img           = Mall.Core.MallIO.GetImagePath(sku.ShowPic)
                                });
                            }
                        }
                    }
                    if (specs.Count() > 1 && !string.IsNullOrEmpty(sku.Size))
                    {
                        if (long.TryParse(specs[2], out sizeId))
                        {
                        }
                        if (sizeId != 0)
                        {
                            if (!model.Size.Any(v => v.Value.Equals(sku.Size)))
                            {
                                var ss = skus.Where(s => s.Size.Equals(sku.Size)).Sum(s1 => s1.Stock);
                                model.Size.Add(new ProductSKU
                                {
                                    //Name = "选择尺码",
                                    Name         = "选择" + sizeAlias,
                                    EnabledClass = ss != 0 ? "enabled" : "disabled",
                                    //SelectedClass = !model.Size.Any(s1 => s1.SelectedClass.Equals("selected")) && ss != 0 ? "selected" : "",
                                    SelectedClass = "",
                                    SkuId         = sizeId,
                                    Value         = sku.Size
                                });
                            }
                        }
                    }

                    if (specs.Count() > 2 && !string.IsNullOrEmpty(sku.Version))
                    {
                        if (long.TryParse(specs[3], out versionId))
                        {
                        }
                        if (versionId != 0)
                        {
                            if (!model.Version.Any(v => v.Value.Equals(sku.Version)))
                            {
                                var v = skus.Where(s => s.Version.Equals(sku.Version)).Sum(s => s.Stock);
                                model.Version.Add(new ProductSKU
                                {
                                    //Name = "选择版本",
                                    Name         = "选择" + versionAlias,
                                    EnabledClass = v != 0 ? "enabled" : "disabled",
                                    //SelectedClass = !model.Version.Any(v1 => v1.SelectedClass.Equals("selected")) && v != 0 ? "selected" : "",
                                    SelectedClass = "",
                                    SkuId         = versionId,
                                    Value         = sku.Version
                                });
                            }
                        }
                    }
                }

                price = ProductWebApplication.GetProductPriceStr(product, skus, discount);//最小价或区间价文本
            }
            model.Price = string.IsNullOrWhiteSpace(price) ? product.MinSalePrice.ToString("f2") : price;
            #endregion

            #region 商品属性
            List <TypeAttributesModel> ProductAttrs = new List <TypeAttributesModel>();
            var prodAttrs = ProductManagerApplication.GetProductAttributes(product.Id);
            foreach (var attr in prodAttrs)
            {
                if (!ProductAttrs.Any(p => p.AttrId == attr.AttributeId))
                {
                    var attribute = _iTypeService.GetAttribute(attr.AttributeId);
                    var values    = _iTypeService.GetAttributeValues(attr.AttributeId);
                    var attrModel = new TypeAttributesModel()
                    {
                        AttrId     = attr.AttributeId,
                        AttrValues = new List <TypeAttrValue>(),
                        Name       = attribute.Name
                    };
                    foreach (var attrV in values)
                    {
                        if (prodAttrs.Any(p => p.ValueId == attrV.Id))
                        {
                            attrModel.AttrValues.Add(new TypeAttrValue
                            {
                                Id   = attrV.Id.ToString(),
                                Name = attrV.Value
                            });
                        }
                    }
                    ProductAttrs.Add(attrModel);
                }
                else
                {
                    var attrTemp = ProductAttrs.FirstOrDefault(p => p.AttrId == attr.AttributeId);
                    var values   = _iTypeService.GetAttributeValues(attr.AttributeId);
                    if (!attrTemp.AttrValues.Any(p => p.Id == attr.ValueId.ToString()))
                    {
                        attrTemp.AttrValues.Add(new TypeAttrValue
                        {
                            Id   = attr.ValueId.ToString(),
                            Name = values.FirstOrDefault(a => a.Id == attr.ValueId).Value
                        });
                    }
                }
            }
            model.ProductAttrs = ProductAttrs;
            #endregion

            #region 获取评论、咨询数量

            model.CommentCount = CommentApplication.GetCommentCountByProduct(product.Id);

            var consultations = _iConsultationService.GetConsultations(gid);
            model.Consultations = consultations.Count();

            #endregion

            #region 累加浏览次数、 加入历史记录
            if (CurrentUser != null)
            {
                BrowseHistrory.AddBrowsingProduct(product.Id, CurrentUser.Id);
            }
            else
            {
                BrowseHistrory.AddBrowsingProduct(product.Id);
            }

            //_iProductService.LogProductVisti(gid);
            //统计商品浏览量、店铺浏览人数
            StatisticApplication.StatisticVisitCount(product.Id, product.ShopId);
            #endregion

            #region 红包
            var bonus = ServiceApplication.Create <IShopBonusService>().GetByShopId(product.ShopId);
            if (bonus != null)
            {
                model.GrantPrice = bonus.GrantPrice;
            }
            else
            {
                model.GrantPrice = 0;
            }
            #endregion

            #region 获取店铺的评价统计

            var shopStatisticOrderComments = _iShopService.GetShopStatisticOrderComments(shop.Id);

            var productAndDescription = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescription).FirstOrDefault();
            var sellerServiceAttitude = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitude).FirstOrDefault();
            var sellerDeliverySpeed   = shopStatisticOrderComments.Where(c => c.CommentKey ==
                                                                         Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeed).FirstOrDefault();

            var productAndDescriptionPeer = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescriptionPeer).FirstOrDefault();
            var sellerServiceAttitudePeer = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitudePeer).FirstOrDefault();
            var sellerDeliverySpeedPeer   = shopStatisticOrderComments.Where(c => c.CommentKey ==
                                                                             Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeedPeer).FirstOrDefault();

            var productAndDescriptionMax = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescriptionMax).FirstOrDefault();
            var productAndDescriptionMin = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescriptionMin).FirstOrDefault();

            var sellerServiceAttitudeMax = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitudeMax).FirstOrDefault();
            var sellerServiceAttitudeMin = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitudeMin).FirstOrDefault();

            var sellerDeliverySpeedMax = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeedMax).FirstOrDefault();
            var sellerDeliverySpeedMin = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeedMin).FirstOrDefault();

            decimal defaultValue = 5;
            //宝贝与描述
            if (productAndDescription != null && productAndDescriptionPeer != null)
            {
                ViewBag.ProductAndDescription     = productAndDescription.CommentValue;
                ViewBag.ProductAndDescriptionPeer = productAndDescriptionPeer.CommentValue;
                ViewBag.ProductAndDescriptionMin  = productAndDescriptionMin.CommentValue;
                ViewBag.ProductAndDescriptionMax  = productAndDescriptionMax.CommentValue;
            }
            else
            {
                ViewBag.ProductAndDescription     = defaultValue;
                ViewBag.ProductAndDescriptionPeer = defaultValue;
                ViewBag.ProductAndDescriptionMin  = defaultValue;
                ViewBag.ProductAndDescriptionMax  = defaultValue;
            }
            //卖家服务态度
            if (sellerServiceAttitude != null && sellerServiceAttitudePeer != null)
            {
                ViewBag.SellerServiceAttitude     = sellerServiceAttitude.CommentValue;
                ViewBag.SellerServiceAttitudePeer = sellerServiceAttitudePeer.CommentValue;
                ViewBag.SellerServiceAttitudeMax  = sellerServiceAttitudeMax.CommentValue;
                ViewBag.SellerServiceAttitudeMin  = sellerServiceAttitudeMin.CommentValue;
            }
            else
            {
                ViewBag.SellerServiceAttitude     = defaultValue;
                ViewBag.SellerServiceAttitudePeer = defaultValue;
                ViewBag.SellerServiceAttitudeMax  = defaultValue;
                ViewBag.SellerServiceAttitudeMin  = defaultValue;
            }
            //卖家发货速度
            if (sellerDeliverySpeedPeer != null && sellerDeliverySpeed != null)
            {
                ViewBag.SellerDeliverySpeed     = sellerDeliverySpeed.CommentValue;
                ViewBag.SellerDeliverySpeedPeer = sellerDeliverySpeedPeer.CommentValue;
                ViewBag.SellerDeliverySpeedMax  = sellerDeliverySpeedMax.CommentValue;
                ViewBag.sellerDeliverySpeedMin  = sellerDeliverySpeedMin.CommentValue;
            }
            else
            {
                ViewBag.SellerDeliverySpeed     = defaultValue;
                ViewBag.SellerDeliverySpeedPeer = defaultValue;
                ViewBag.SellerDeliverySpeedMax  = defaultValue;
                ViewBag.sellerDeliverySpeedMin  = defaultValue;
            }
            #endregion

            #region 客服
            model.Service = ServiceApplication.Create <ICustomerService>().GetCustomerService(shop.Id).Where(c => c.Type == Entities.CustomerServiceInfo.ServiceType.PreSale && c.TerminalType == Entities.CustomerServiceInfo.ServiceTerminalType.PC).OrderBy(m => m.Tool);
            #endregion

            #region 开团提醒场景二维码
            var siteSetting = SiteSettingApplication.SiteSettings;
            if (DateTime.Parse(model.FlashSale.BeginDate) > DateTime.Now && WXIsConfig(siteSetting.WeixinAppId, siteSetting.WeixinAppSecret))
            {
                try
                {
                    var         token   = AccessTokenContainer.TryGetAccessToken(siteSetting.WeixinAppId, siteSetting.WeixinAppSecret);
                    SceneHelper helper  = new SceneHelper();
                    SceneModel  scene   = new SceneModel(QR_SCENE_Type.FlashSaleRemind, model.FlashSale.Id);
                    int         sceneId = helper.SetModel(scene);
                    var         ticket  = QrCodeApi.Create(token, 86400, sceneId, Senparc.Weixin.MP.QrCode_ActionName.QR_LIMIT_SCENE, null).ticket;
                    ViewBag.ticket = ticket;
                }
                catch { }
            }
            #endregion

            model.Logined    = (null != CurrentUser) ? 1 : 0;
            model.EnabledBuy = product.AuditStatus == Entities.ProductInfo.ProductAuditStatus.Audited && DateTime.Parse(market.BeginDate) <= DateTime.Now && DateTime.Parse(market.EndDate) > DateTime.Now && product.SaleStatus == Entities.ProductInfo.ProductSaleStatus.OnSale;
            if (market.Status == FlashSaleInfo.FlashSaleStatus.Ongoing && DateTime.Parse(market.BeginDate) < DateTime.Now && DateTime.Parse(market.EndDate) > DateTime.Now)
            {
                TimeSpan end   = new TimeSpan(DateTime.Parse(market.EndDate).Ticks);
                TimeSpan start = new TimeSpan(DateTime.Now.Ticks);
                TimeSpan ts    = end.Subtract(start);
                model.Second = ts.TotalSeconds < 0 ? 0 : ts.TotalSeconds;
            }
            else if (market.Status == FlashSaleInfo.FlashSaleStatus.Ongoing && DateTime.Parse(market.BeginDate) > DateTime.Now)
            {
                TimeSpan end   = new TimeSpan(DateTime.Parse(market.BeginDate).Ticks);
                TimeSpan start = new TimeSpan(DateTime.Now.Ticks);
                TimeSpan ts    = end.Subtract(start);
                model.Second = ts.TotalSeconds < 0 ? 0 : ts.TotalSeconds;
            }

            //补充当前店铺红包功能
            ViewBag.isShopPage     = true;
            ViewBag.CurShopId      = product.ShopId;
            TempData["isShopPage"] = true;
            TempData["CurShopId"]  = product.ShopId;

            ViewBag.Keyword          = SiteSettings.Keyword;
            ViewBag.Quantity         = market.Quantity;//总活动库存
            model.VirtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(product.Id);
            model.FreightTemplate    = FreightTemplateApplication.GetFreightTemplate(product.FreightTemplateId);
            return(View(model));
        }