public void AddFlashSale(FlashSaleModel model) { CheckFlashSale(model); var product = DbFactory.Default.Get <ProductInfo>().Where(p => p.Id == model.ProductId).FirstOrDefault(); DbFactory.Default.InTransaction(() => { FlashSaleInfo flashSale = new FlashSaleInfo(); flashSale.Title = model.Title; flashSale.ShopId = model.ShopId; flashSale.ProductId = model.ProductId; flashSale.Status = model.Status; flashSale.BeginDate = DateTime.Parse(model.BeginDate); flashSale.EndDate = DateTime.Parse(model.EndDate); flashSale.CategoryName = model.CategoryName; flashSale.LimitCountOfThePeople = model.LimitCountOfThePeople; flashSale.SaleCount = model.SaleCount; flashSale.ImagePath = product.RelativePath; flashSale.MinPrice = model.Details.Min(p => p.Price); DbFactory.Default.Add(flashSale); foreach (var detail in model.Details) { FlashSaleDetailInfo fsd = new FlashSaleDetailInfo(); fsd.FlashSaleId = flashSale.Id; fsd.ProductId = flashSale.ProductId; fsd.SkuId = detail.SkuId; fsd.Price = detail.Price; fsd.TotalCount = detail.TotalCount; DbFactory.Default.Add(fsd); } }); }
public ActionResult EditFS(string fsmodel) { try { FlashSaleModel model = (FlashSaleModel)JsonConvert.DeserializeObject(fsmodel, typeof(FlashSaleModel)); if (Convert.ToDateTime(model.BeginDate) > Convert.ToDateTime(model.EndDate)) { return(Json(new Result { msg = "开始时间不能大于结束时间!", success = false })); } model.ShopId = CurrentSellerManager.ShopId; if (SiteSettingApplication.SiteSettings.LimitTimeBuyNeedAuditing) { model.Status = FlashSaleInfo.FlashSaleStatus.WaitForAuditing; } _iLimitTimeBuyService.UpdateFlashSale(model); ProductManagerApplication.SaveCaculateMinPrice(model.ProductId, CurrentShop.Id); //delete-pengjiangxiong //foreach (var d in model.Details) //{ // LimitOrderHelper.ModifyLimitStock(d.SkuId, d.TotalCount, DateTime.Parse(model.EndDate)); //} return(Json(new Result { msg = "修改活动成功!", success = true })); } catch (Exception ex) { return(Json(new Result { msg = ex.Message, success = false })); } }
public FlashSaleModel GetDetailInfo(long productId) { var product = DbFactory.Default.Get <ProductInfo>().Where(p => p.Id == productId).FirstOrDefault(); var fs = new FlashSaleModel(); fs.ProductId = productId; fs.ProductImg = product.ImagePath; List <FlashSaleDetailModel> list = new List <FlashSaleDetailModel>(); var result = DbFactory.Default.Get <SKUInfo>().Where(p => p.ProductId == productId).ToList(); #region 阶梯商品价格--ZYF var price = GetMinLadderPrice(productId); #endregion foreach (var item in result) { FlashSaleDetailModel mdoel = new FlashSaleDetailModel(); mdoel.SkuId = item.Id; mdoel.Color = item.Color; mdoel.Size = item.Size; mdoel.Version = item.Version; mdoel.Stock = (int)item.Stock; mdoel.SalePrice = price > 0 ? price : item.SalePrice; mdoel.CostPrice = item.CostPrice; list.Add(mdoel); } fs.Details = list; return(fs); }
public ActionResult EditFS(string fsmodel) { try { FlashSaleModel model = (FlashSaleModel)JsonConvert.DeserializeObject(fsmodel, typeof(FlashSaleModel)); if (Convert.ToDateTime(model.BeginDate) > Convert.ToDateTime(model.EndDate)) { return(Json(new Result { msg = "开始时间不能大于结束时间!", success = false })); } model.ShopId = CurrentSellerManager.ShopId; _iLimitTimeBuyService.UpdateFlashSale(model); foreach (var d in model.Details) { LimitOrderHelper.ModifyLimitStock(d.SkuId, d.Stock, DateTime.Parse(model.EndDate)); } return(Json(new Result { msg = "添加活动成功!", success = true })); } catch (Exception ex) { return(Json(new Result { msg = ex.Message, success = false })); } }
public ActionResult AddFS(string fsmodel) { try { FlashSaleModel model = (FlashSaleModel)JsonConvert.DeserializeObject(fsmodel, typeof(FlashSaleModel)); if (Convert.ToDateTime(model.BeginDate) > Convert.ToDateTime(model.EndDate)) { return(Json(new Result { msg = "开始时间不能大于结束时间!", success = false })); } if (!_iFightGroupService.ProductCanJoinActive(model.ProductId)) { return(Json(new Result { msg = "该商品已参与拼团或其他营销活动,请重新选择!", success = false })); } model.ShopId = CurrentSellerManager.ShopId; _iLimitTimeBuyService.AddFlashSale(model); foreach (var d in model.Details) { LimitOrderHelper.AddLimitStock(d.SkuId, d.Stock, DateTime.Parse(model.EndDate)); } return(Json(new Result { msg = "添加活动成功!", success = true })); } catch (Exception ex) { return(Json(new Result { msg = ex.Message, success = false })); } }
public ActionResult GetSkus(long id) { FlashSaleModel data = this._iLimitTimeBuyService.Get(id); if (data != null) { return(base.Json(data)); } return(base.Json(null)); }
public JsonResult LoadProducts(long topicId, long moduleId, int page, int pageSize) { IEnumerable <long> ids = from item in (from item in this._iTopicService.GetTopicInfo(topicId).TopicModuleInfo.FirstOrDefault <TopicModuleInfo>(item => (item.Id == moduleId)).ModuleProductInfo where (item.ProductInfo.SaleStatus == ProductInfo.ProductSaleStatus.OnSale) && (item.ProductInfo.AuditStatus == ProductInfo.ProductAuditStatus.Audited) orderby item.Id select item).Skip <ModuleProductInfo>((pageSize * (page - 1))).Take <ModuleProductInfo>(pageSize) select item.ProductId; var data = this._iProductService.GetProductByIds(ids).ToArray <ProductInfo>().Select(delegate(ProductInfo item) { FlashSaleModel flaseSaleByProductId = this._iLimitTimeBuyService.GetFlaseSaleByProductId(item.Id); return(new { name = item.ProductName, id = item.Id, image = item.GetImage(ImageSize.Size_350, 1), price = (flaseSaleByProductId != null) ? flaseSaleByProductId.MinPrice : item.MinSalePrice, marketPrice = item.MarketPrice }); }); return(base.Json(data)); }
public JsonResult GetlimitTimeProducts(LimitTimeQuery query) { query.ShopId = this.CurrentShop.Id;//只取当前商家的限时购商品 // var result = EngineContext.Current.Resolve<ILimitTimeBuyService>().GetFlashSaleInfos(query); var result = EngineContext.Current.Resolve <ILimitTimeBuyService>().GetFlashSaleInfos(query); var products = ProductManagerApplication.GetProducts(result.Models.Select(p => p.ProductId)); var shops = ShopApplication.GetShops(result.Models.Select(p => p.ShopId)); var market = result.Models.Select(item => { var product = products.FirstOrDefault(p => p.Id == item.ProductId); var shop = shops.FirstOrDefault(p => p.Id == item.ShopId); var m = new FlashSaleModel { Id = item.Id, Title = item.Title, BeginDate = item.BeginDate.ToString("yyyy-MM-dd"), EndDate = item.EndDate.ToString("yyyy-MM-dd"), ShopName = shop.ShopName, ProductName = product.ProductName, ProductId = item.ProductId, StatusStr = item.Status.ToDescription() }; if (item.Status != FlashSaleInfo.FlashSaleStatus.WaitForAuditing && item.Status != FlashSaleInfo.FlashSaleStatus.AuditFailed && item.BeginDate > DateTime.Now && item.EndDate < DateTime.Now) { m.StatusStr = "进行中"; } else if (item.Status != FlashSaleInfo.FlashSaleStatus.WaitForAuditing && item.Status != FlashSaleInfo.FlashSaleStatus.AuditFailed && item.BeginDate > DateTime.Now) { m.StatusStr = "未开始"; } m.SaleCount = item.SaleCount; m.MinPrice = item.MinPrice; m.MarketPrice = product.MarketPrice; m.ProductImg = MallIO.GetProductSizeImage(product.ImagePath, 1, (int)ImageSize.Size_350); return(m); }); var dataGrid = new DataGridModel <FlashSaleModel>() { rows = market, total = result.Total }; return(Json(dataGrid)); }
public ActionResult GetData(int index, int size, string cname) { FlashSaleQuery query = new FlashSaleQuery { ItemName = cname, IsPreheat = true, PageNo = index, PageSize = size, AuditStatus = FlashSaleInfo.FlashSaleStatus.Ongoing, CheckProductStatus = true }; ObsoletePageModel <FlashSaleInfo> all = this._iLimitTimeBuyService.GetAll(query); List <FlashSaleModel> list = new List <FlashSaleModel>(); foreach (FlashSaleInfo info in all.Models.ToList <FlashSaleInfo>()) { FlashSaleModel item = new FlashSaleModel { Id = info.Id, Title = info.Title, ShopId = info.ShopId, ProductId = info.ProductId, Status = info.Status, ProductName = info.Himall_Products.ProductName, ProductImg = HimallIO.GetProductSizeImage(info.Himall_Products.RelativePath, 1, 0), MarketPrice = info.Himall_Products.MarketPrice, BeginDate = info.BeginDate.ToString("yyyy-MM-dd HH:mm"), EndDate = info.EndDate.ToString("yyyy-MM-dd HH:mm"), LimitCountOfThePeople = info.LimitCountOfThePeople, SaleCount = info.SaleCount, CategoryName = info.CategoryName, MinPrice = info.MinPrice }; list.Add(item); } DataGridModel <FlashSaleModel> data = new DataGridModel <FlashSaleModel> { total = all.Total, rows = list }; return(base.Json(data)); }
public JsonResult List(int?status, int page, int rows, string shopName, string title) { if (status == null) { status = 0; } ObsoletePageModel <FlashSaleInfo> result = _iLimitTimeBuyService.GetAll((int)status, shopName, title, page, rows); IEnumerable <FlashSaleModel> market = result.Models.ToArray().Select(item => { var m = new FlashSaleModel(); m.Id = item.Id; m.Title = item.Title; m.BeginDate = item.BeginDate.ToString("yyyy-MM-dd"); m.EndDate = item.EndDate.ToString("yyyy-MM-dd"); m.ShopName = item.Himall_Shops.ShopName; m.ProductName = item.Himall_Products.ProductName; m.ProductId = item.ProductId; //StatusStr = item.EndDate < DateTime.Now ?FlashSaleInfo.FlashSaleStatus.Ended.ToDescription() : item.Status.ToDescription() , m.StatusStr = item.Status.ToDescription(); if (item.Status != FlashSaleInfo.FlashSaleStatus.WaitForAuditing && item.Status != FlashSaleInfo.FlashSaleStatus.AuditFailed && item.BeginDate > DateTime.Now && item.EndDate < DateTime.Now) { m.StatusStr = "进行中"; } else if (item.Status != FlashSaleInfo.FlashSaleStatus.WaitForAuditing && item.Status != FlashSaleInfo.FlashSaleStatus.AuditFailed && item.BeginDate > DateTime.Now) { m.StatusStr = "未开始"; } m.SaleCount = item.SaleCount; return(m); }); DataGridModel <FlashSaleModel> dataGrid = new DataGridModel <FlashSaleModel>() { rows = market, total = result.Total }; return(Json(dataGrid)); }
public ActionResult GetData(int index, int size, string cname) { #region 初始化查询Model FlashSaleQuery query = new FlashSaleQuery() { ItemName = cname, IsPreheat = true, PageNo = index, PageSize = size, AuditStatus = FlashSaleInfo.FlashSaleStatus.Ongoing, CheckProductStatus = true }; #endregion var obj = _iLimitTimeBuyService.GetAll(query); List <FlashSaleModel> list = new List <FlashSaleModel>(); foreach (var model in obj.Models.ToList()) { FlashSaleModel result = new FlashSaleModel(); result.Id = model.Id; result.Title = model.Title; result.ShopId = model.ShopId; result.ProductId = model.ProductId; result.Status = model.Status; result.ProductName = model.Himall_Products.ProductName; result.ProductImg = Himall.Core.HimallIO.GetProductSizeImage(model.Himall_Products.RelativePath, 1); result.MarketPrice = model.Himall_Products.MarketPrice; result.BeginDate = model.BeginDate.ToString("yyyy-MM-dd HH:mm"); result.EndDate = model.EndDate.ToString("yyyy-MM-dd HH:mm"); result.LimitCountOfThePeople = model.LimitCountOfThePeople; result.SaleCount = model.SaleCount; result.CategoryName = model.CategoryName; result.MinPrice = model.MinPrice; list.Add(result); } DataGridModel <FlashSaleModel> x = new DataGridModel <FlashSaleModel>(); x.total = obj.Total; x.rows = list; return(Json(x)); }
public ActionResult GetData(int index, int size, string cname) { #region 初始化查询Model FlashSaleQuery query = new FlashSaleQuery() { ItemName = cname, OrderKey = 5, /* 排序项(1:默认,2:销量,3:价格,4 : 结束时间,5:状态 开始排前面) */ IsPreheat = true, PageNo = index, PageSize = size, AuditStatus = FlashSaleInfo.FlashSaleStatus.Ongoing, CheckProductStatus = true }; #endregion var obj = _iLimitTimeBuyService.GetAll(query); var products = ProductManagerApplication.GetProducts(obj.Models.Select(p => p.ProductId)); List <FlashSaleModel> list = new List <FlashSaleModel>(); foreach (var model in obj.Models) { var product = products.FirstOrDefault(p => p.Id == model.ProductId); FlashSaleModel result = new FlashSaleModel(); result.Id = model.Id; result.Title = model.Title; result.ShopId = model.ShopId; result.ProductId = model.ProductId; result.Status = model.Status; result.ProductName = product.ProductName; result.ProductImg = Mall.Core.MallIO.GetProductSizeImage(product.RelativePath, 1); result.MarketPrice = product.MarketPrice; result.BeginDate = model.BeginDate.ToString("yyyy-MM-dd HH:mm"); result.EndDate = model.EndDate.ToString("yyyy-MM-dd HH:mm"); result.LimitCountOfThePeople = model.LimitCountOfThePeople; result.SaleCount = model.SaleCount; result.CategoryName = model.CategoryName; result.MinPrice = model.MinPrice; list.Add(result); } return(Json(new { success = true, data = list, total = obj.Total })); }
public FlashSaleModel GetFlaseSaleByProductId(long pid) { if (pid <= 0) { throw new MallException("商品Id不能识别"); } var model = DbFactory.Default .Get <FlashSaleInfo>() .Where(m => m.ProductId == pid && m.Status == FlashSaleInfo.FlashSaleStatus.Ongoing && m.BeginDate <= DateTime.Now && m.EndDate > DateTime.Now) .FirstOrDefault(); FlashSaleModel result = new FlashSaleModel(); if (model != null) { var product = ProductManagerApplication.GetProduct(model.ProductId); result.Id = model.Id; result.Title = model.Title; result.ShopId = model.ShopId; result.ProductId = model.ProductId; result.Status = model.Status; result.ProductName = product.ProductName; result.ProductImg = product.RelativePath; result.StatusStr = model.Status.ToDescription(); result.BeginDate = model.BeginDate.ToString("yyyy-MM-dd HH:mm"); result.EndDate = model.EndDate.ToString("yyyy-MM-dd HH:mm"); result.LimitCountOfThePeople = model.LimitCountOfThePeople; result.SaleCount = model.SaleCount; result.CategoryName = model.CategoryName; result.MinPrice = model.MinPrice; result.Details = new List <FlashSaleDetailModel>(); return(result); } else { return(null); } }
public FlashSaleModel SelectFlashSaleDataByActivityID(Guid activityId) { FlashSaleModel result = null; try { using (var client = new FlashSaleClient()) { var data = client.SelectFlashSaleDataByActivityID(activityId); if (!data.Success && data.Exception != null) { throw data.Exception; } result = data.Result; } } catch (Exception ex) { logger.Error(ex); } return(result); }
private void CheckFlashSale(FlashSaleModel model) { if (DbFactory.Default.Get <FlashSaleInfo>().Where(p => (p.Id != 0 && p.Id != model.Id && p.ShopId == model.ShopId && p.ProductId == model.ProductId && p.EndDate > DateTime.Now && p.Status == FlashSaleInfo.FlashSaleStatus.Ongoing) || (p.Id != 0 && p.Id != model.Id && p.ShopId == model.ShopId && p.ProductId == model.ProductId && p.EndDate > DateTime.Now && p.Status == FlashSaleInfo.FlashSaleStatus.WaitForAuditing)).Exist()) { throw new MallException("此商品已存在限时购活动"); } var co = DbFactory.Default.Get <ActiveMarketServiceInfo>().Where(a => a.TypeId == MarketType.LimitTimeBuy && a.ShopId == model.ShopId).FirstOrDefault(); if (co == null) { throw new MallException("您没有订购此服务"); } var date = Convert.ToDateTime(model.EndDate); var endtime = MarketApplication.GetServiceEndTime(co.Id); var newEnd = DateTime.Parse(endtime.ToString("yyyy-MM-dd") + " 23:59:59"); if (newEnd < date) { //throw new MallException("结束日期不能超过购买限时购服务的日期"); throw new MallException(string.Format("活动结束时间不得超过服务到期时间,<br/>您的服务到期时间为{0}", newEnd.ToString("yyyy-MM-dd HH:mm:ss"))); } }
public FlashSaleModel IsFlashSaleDoesNotStarted(long productid) { string cacheKey = CacheKeyCollection.CACHE_PRODUCTLIMITNOTSTART(productid); if (Cache.Exists(cacheKey)) { return(Cache.Get <FlashSaleModel>(cacheKey)); } var model = DbFactory.Default.Get <FlashSaleInfo>().Where(p => p.ProductId == productid && p.Status == FlashSaleInfo.FlashSaleStatus.Ongoing && p.BeginDate > DateTime.Now).FirstOrDefault(); if (model != null) { var product = ProductManagerApplication.GetProduct(model.ProductId); FlashSaleModel result = new FlashSaleModel(); result.Id = model.Id; result.Title = model.Title; result.ShopId = model.ShopId; result.ProductId = model.ProductId; result.Status = model.Status; result.ProductName = product.ProductName; result.ProductImg = product.ImagePath; result.StatusStr = model.Status.ToDescription(); result.BeginDate = model.BeginDate.ToString("yyyy-MM-dd HH:mm"); result.EndDate = model.EndDate.ToString("yyyy-MM-dd HH:mm"); result.LimitCountOfThePeople = model.LimitCountOfThePeople; result.SaleCount = model.SaleCount; result.CategoryName = model.CategoryName; result.MinPrice = model.MinPrice; Cache.Insert <FlashSaleModel>(cacheKey, result, model.BeginDate.AddSeconds(-10));//缓存至开始时间前10秒 return(result); } Cache.Insert <FlashSaleModel>(cacheKey, null, 60); return(null); }
public ActionResult Detail(string id) { ProductDescriptionTemplateInfo template; long num15; TimeSpan span; TimeSpan span2; TimeSpan span3; ParameterExpression expression; LimitTimeBuyDetailModel model = new LimitTimeBuyDetailModel(); string str = ""; LimitTimeProductDetailModel model2 = new LimitTimeProductDetailModel { MainId = long.Parse(id), HotAttentionProducts = new List <HotProductInfo>(), HotSaleProducts = new List <HotProductInfo>(), Product = new ProductInfo(), Shop = new ShopInfoModel(), ShopCategory = new List <CategoryJsonModel>(), Color = new CollectionSKU(), Size = new CollectionSKU(), Version = new CollectionSKU() }; FlashSaleModel model3 = null; ShopInfo shop = null; long productId = 0L; long result = 0L; if (long.TryParse(id, out result)) { } if (result == 0L) { return(base.RedirectToAction("Error404", "Error", new { area = "Mobile" })); } model3 = this._iLimitTimeBuyService.Get(result); switch (model3.Status) { case FlashSaleInfo.FlashSaleStatus.Ended: return(base.RedirectToAction("Detail", "Product", new { id = model3.ProductId })); case FlashSaleInfo.FlashSaleStatus.Cancelled: return(base.RedirectToAction("Detail", "Product", new { id = model3.ProductId })); } model2.FlashSale = model3; if ((model3 == null) || (model3.Status != FlashSaleInfo.FlashSaleStatus.Ongoing)) { model3 = (model3 == null) ? this._iLimitTimeBuyService.GetFlaseSaleByProductId(result) : model3; if (model3 == null) { return(base.RedirectToAction("Error404", "Error", new { area = "Mobile" })); } if (model3.Status != FlashSaleInfo.FlashSaleStatus.Ongoing) { return(base.RedirectToAction("Detail", "Product", new { id = model3.ProductId })); } } if ((model3 != null) && ((model3.Status != FlashSaleInfo.FlashSaleStatus.Ongoing) || (DateTime.Parse(model3.EndDate) < DateTime.Now))) { return(base.RedirectToAction("Detail", "Product", new { id = model3.ProductId })); } model2.MaxSaleCount = model3.LimitCountOfThePeople; model2.Title = model3.Title; shop = this._iShopService.GetShop(model3.ShopId, false); if ((model3 == null) || (model3.Id == 0L)) { return(base.RedirectToAction("Error404", "Error", new { area = "Web" })); } ProductInfo product = this._iProductService.GetProduct(model3.ProductId); productId = model3.ProductId; model2.Product = product; model2.ProductDescription = product.ProductDescriptionInfo.ShowMobileDescription; if (product.ProductDescriptionInfo.DescriptionPrefixId != 0L) { template = this._iProductDescriptionTemplateService.GetTemplate(product.ProductDescriptionInfo.DescriptionPrefixId, product.ShopId); model2.DescriptionPrefix = (template == null) ? "" : template.Content; } if (product.ProductDescriptionInfo.DescriptiondSuffixId != 0L) { template = this._iProductDescriptionTemplateService.GetTemplate(product.ProductDescriptionInfo.DescriptiondSuffixId, product.ShopId); model2.DescriptiondSuffix = (template == null) ? "" : template.Content; } ShopServiceMarkModel shopComprehensiveMark = ShopServiceMark.GetShopComprehensiveMark(shop.Id); model2.Shop.PackMark = shopComprehensiveMark.PackMark; model2.Shop.ServiceMark = shopComprehensiveMark.ServiceMark; model2.Shop.ComprehensiveMark = shopComprehensiveMark.ComprehensiveMark; IQueryable <ProductCommentInfo> commentsByProductId = this._iCommentService.GetCommentsByProductId(productId); model2.Shop.Name = shop.ShopName; Decimal num1; if (commentsByProductId != null && Queryable.Count <ProductCommentInfo>(commentsByProductId) != 0) { num1 = Queryable.Average <ProductCommentInfo>(commentsByProductId, (Expression <Func <ProductCommentInfo, Decimal> >)(p => (Decimal)p.ReviewMark)); } else { num1 = new Decimal(0); } model2.Shop.ProductMark = num1; model2.Shop.Id = product.ShopId; model2.Shop.FreeFreight = shop.FreeFreight; model.ProductNum = this._iProductService.GetShopOnsaleProducts(product.ShopId); model.FavoriteShopCount = this._iShopService.GetShopFavoritesCount(product.ShopId); if (base.CurrentUser == null) { model.IsFavorite = false; model.IsFavoriteShop = false; } else { model.IsFavorite = this._iProductService.IsFavorite(product.Id, base.CurrentUser.Id); model.IsFavoriteShop = (from item in this._iShopService.GetFavoriteShopInfos(base.CurrentUser.Id) select item.ShopId).ToArray <long>().Contains <long>(product.ShopId); } List <ShopCategoryInfo> source = this._iShopCategoryService.GetShopCategory(product.ShopId).ToList <ShopCategoryInfo>(); using (IEnumerator <ShopCategoryInfo> enumerator = (from s in source where s.ParentCategoryId == 0L select s).GetEnumerator()) { while (enumerator.MoveNext()) { Func <ShopCategoryInfo, bool> predicate = null; ShopCategoryInfo main = enumerator.Current; CategoryJsonModel model5 = new CategoryJsonModel { Name = main.Name, Id = main.Id.ToString(), SubCategory = new List <SecondLevelCategory>() }; if (predicate == null) { predicate = s => s.ParentCategoryId == main.Id; } foreach (ShopCategoryInfo info4 in source.Where <ShopCategoryInfo>(predicate)) { SecondLevelCategory category = new SecondLevelCategory { Name = info4.Name, Id = info4.Id.ToString() }; model5.SubCategory.Add(category); } model2.ShopCategory.Add(model5); } } IQueryable <ProductInfo> hotSaleProduct = this._iProductService.GetHotSaleProduct(shop.Id, 5); if (hotSaleProduct != null) { foreach (ProductInfo info5 in hotSaleProduct.ToArray <ProductInfo>()) { HotProductInfo info6 = new HotProductInfo { ImgPath = info5.ImagePath, Name = info5.ProductName, Price = info5.MinSalePrice, Id = info5.Id, SaleCount = (int)info5.SaleCounts }; model2.HotSaleProducts.Add(info6); } } IQueryable <ProductInfo> hotConcernedProduct = this._iProductService.GetHotConcernedProduct(shop.Id, 5); if (hotConcernedProduct != null) { foreach (ProductInfo info5 in hotConcernedProduct.ToArray <ProductInfo>()) { HotProductInfo info7 = new HotProductInfo { ImgPath = info5.ImagePath, Name = info5.ProductName, Price = info5.MinSalePrice, Id = info5.Id, SaleCount = info5.ConcernedCount }; model2.HotAttentionProducts.Add(info7); } } ProductTypeInfo type = this._iTypeService.GetType(product.TypeId); string str2 = ((type == null) || string.IsNullOrEmpty(type.ColorAlias)) ? SpecificationType.Color.ToDescription() : type.ColorAlias; string str3 = ((type == null) || string.IsNullOrEmpty(type.SizeAlias)) ? SpecificationType.Size.ToDescription() : type.SizeAlias; string str4 = ((type == null) || string.IsNullOrEmpty(type.VersionAlias)) ? SpecificationType.Version.ToDescription() : type.VersionAlias; model2.ColorAlias = str2; model2.SizeAlias = str3; model2.VersionAlias = str4; if ((product.SKUInfo != null) && (product.SKUInfo.Count <SKUInfo>() > 0)) { long num3 = 0L; long num4 = 0L; long num5 = 0L; using (IEnumerator <SKUInfo> enumerator3 = product.SKUInfo.GetEnumerator()) { while (enumerator3.MoveNext()) { Func <ProductSKU, bool> func2 = null; Func <SKUInfo, bool> func3 = null; Func <ProductSKU, bool> func4 = null; Func <SKUInfo, bool> func5 = null; Func <ProductSKU, bool> func6 = null; Func <SKUInfo, bool> func7 = null; SKUInfo sku = enumerator3.Current; string[] strArray = sku.Id.Split(new char[] { '_' }); if (strArray.Count <string>() > 0) { if (long.TryParse(strArray[1], out num3)) { } if (num3 != 0L) { if (func2 == null) { func2 = v => v.Value.Equals(sku.Color); } if (!model2.Color.Any <ProductSKU>(func2)) { if (func3 == null) { func3 = s => s.Color.Equals(sku.Color); } long num6 = product.SKUInfo.Where <SKUInfo>(func3).Sum <SKUInfo>((Func <SKUInfo, long>)(s => s.Stock)); ProductSKU tsku = new ProductSKU { Name = "选择" + str2, EnabledClass = (num6 != 0L) ? "enabled" : "disabled", SelectedClass = "", SkuId = num3, Value = sku.Color, Img = sku.ShowPic }; model2.Color.Add(tsku); } } } if (strArray.Count <string>() > 1) { if (long.TryParse(strArray[2], out num4)) { } if (num4 != 0L) { if (func4 == null) { func4 = v => v.Value.Equals(sku.Size); } if (!model2.Size.Any <ProductSKU>(func4)) { if (func5 == null) { func5 = s => s.Size.Equals(sku.Size); } long num7 = product.SKUInfo.Where <SKUInfo>(func5).Sum <SKUInfo>((Func <SKUInfo, long>)(s1 => s1.Stock)); ProductSKU tsku2 = new ProductSKU { Name = "选择" + str3, EnabledClass = (num7 != 0L) ? "enabled" : "disabled", SelectedClass = "", SkuId = num4, Value = sku.Size }; model2.Size.Add(tsku2); } } } if (strArray.Count <string>() > 2) { if (long.TryParse(strArray[3], out num5)) { } if (num5 != 0L) { if (func6 == null) { func6 = v => v.Value.Equals(sku.Version); } if (!model2.Version.Any <ProductSKU>(func6)) { if (func7 == null) { func7 = s => s.Version.Equals(sku.Version); } long num8 = product.SKUInfo.Where <SKUInfo>(func7).Sum <SKUInfo>((Func <SKUInfo, long>)(s => s.Stock)); ProductSKU tsku3 = new ProductSKU { Name = "选择" + str4, EnabledClass = (num8 != 0L) ? "enabled" : "disabled", SelectedClass = "", SkuId = num5, Value = sku.Version }; model2.Version.Add(tsku3); } } } } } decimal num9 = 0M; decimal num10 = 0M; num9 = (from s in product.SKUInfo where s.Stock >= 0L select s).Min <SKUInfo>((Func <SKUInfo, decimal>)(s => s.SalePrice)); num10 = (from s in product.SKUInfo where s.Stock >= 0L select s).Max <SKUInfo>((Func <SKUInfo, decimal>)(s => s.SalePrice)); if ((num9 == 0M) && (num10 == 0M)) { str = product.MinSalePrice.ToString("f2"); } else if (num10 > num9) { str = string.Format("{0}-{1}", num9.ToString("f2"), num10.ToString("f2")); } else { str = string.Format("{0}", num9.ToString("f2")); } } model.Price = string.IsNullOrWhiteSpace(str) ? product.MinSalePrice.ToString("f2") : str; List <TypeAttributesModel> list2 = new List <TypeAttributesModel>(); List <ProductAttributeInfo> list3 = this._iProductService.GetProductAttribute(product.Id).ToList <ProductAttributeInfo>(); using (List <ProductAttributeInfo> .Enumerator enumerator4 = list3.GetEnumerator()) { while (enumerator4.MoveNext()) { Func <TypeAttributesModel, bool> func9 = null; Func <TypeAttributesModel, bool> func10 = null; Func <TypeAttrValue, bool> func11 = null; Func <AttributeValueInfo, bool> func12 = null; ProductAttributeInfo attr = enumerator4.Current; if (func9 == null) { func9 = p => p.AttrId == attr.AttributeId; } if (!list2.Any <TypeAttributesModel>(func9)) { TypeAttributesModel model7 = new TypeAttributesModel { AttrId = attr.AttributeId, AttrValues = new List <TypeAttrValue>(), Name = attr.AttributesInfo.Name }; using (IEnumerator <AttributeValueInfo> enumerator5 = attr.AttributesInfo.AttributeValueInfo.GetEnumerator()) { while (enumerator5.MoveNext()) { Func <ProductAttributeInfo, bool> func8 = null; AttributeValueInfo attrV = enumerator5.Current; if (func8 == null) { func8 = p => p.ValueId == attrV.Id; } if (list3.Any <ProductAttributeInfo>(func8)) { TypeAttrValue value2 = new TypeAttrValue { Id = attrV.Id.ToString(), Name = attrV.Value }; model7.AttrValues.Add(value2); } } } list2.Add(model7); } else { if (func10 == null) { func10 = p => p.AttrId == attr.AttributeId; } TypeAttributesModel model9 = list2.FirstOrDefault <TypeAttributesModel>(func10); if (func11 == null) { func11 = p => p.Id == attr.ValueId.ToString(); } if (!model9.AttrValues.Any <TypeAttrValue>(func11)) { TypeAttrValue value3 = new TypeAttrValue { Id = attr.ValueId.ToString() }; if (func12 == null) { func12 = a => a.Id == attr.ValueId; } value3.Name = attr.AttributesInfo.AttributeValueInfo.FirstOrDefault <AttributeValueInfo>(func12).Value; model9.AttrValues.Add(value3); } } } } model.ProductAttrs = list2; IEnumerable <ProductCommentInfo> enumerable = Enumerable.Where <ProductCommentInfo>((IEnumerable <ProductCommentInfo>)product.Himall_ProductComments, (Func <ProductCommentInfo, bool>)(item => !item.IsHidden.HasValue || !item.IsHidden.Value)); int num11 = enumerable.Count <ProductCommentInfo>(); model.CommentCount = num11; IQueryable <ProductConsultationInfo> consultations = this._iConsultationService.GetConsultations(productId); model.Consultations = consultations.Count <ProductConsultationInfo>(); double num12 = num11; double num13 = enumerable.Count <ProductCommentInfo>(item => item.ReviewMark >= 4); model.NicePercent = (int)((num13 / num12) * 100.0); model.Consultations = consultations.Count <ProductConsultationInfo>(); if (this._iVShopService.GetVShopByShopId(shop.Id) == null) { model.VShopId = -1L; } else { model.VShopId = this._iVShopService.GetVShopByShopId(shop.Id).Id; } IQueryable <StatisticOrderCommentsInfo> shopStatisticOrderComments = this._iShopService.GetShopStatisticOrderComments(product.ShopId); StatisticOrderCommentsInfo info9 = (from c in shopStatisticOrderComments where ((int)c.CommentKey) == 1 select c).FirstOrDefault <StatisticOrderCommentsInfo>(); StatisticOrderCommentsInfo info10 = (from c in shopStatisticOrderComments where ((int)c.CommentKey) == 9 select c).FirstOrDefault <StatisticOrderCommentsInfo>(); StatisticOrderCommentsInfo info11 = (from c in shopStatisticOrderComments where ((int)c.CommentKey) == 5 select c).FirstOrDefault <StatisticOrderCommentsInfo>(); StatisticOrderCommentsInfo info12 = (from c in shopStatisticOrderComments where ((int)c.CommentKey) == 2 select c).FirstOrDefault <StatisticOrderCommentsInfo>(); StatisticOrderCommentsInfo info13 = (from c in shopStatisticOrderComments where ((int)c.CommentKey) == 10 select c).FirstOrDefault <StatisticOrderCommentsInfo>(); StatisticOrderCommentsInfo info14 = (from c in shopStatisticOrderComments where ((int)c.CommentKey) == 6 select c).FirstOrDefault <StatisticOrderCommentsInfo>(); StatisticOrderCommentsInfo info15 = (from c in shopStatisticOrderComments where ((int)c.CommentKey) == 3 select c).FirstOrDefault <StatisticOrderCommentsInfo>(); StatisticOrderCommentsInfo info16 = (from c in shopStatisticOrderComments where ((int)c.CommentKey) == 4 select c).FirstOrDefault <StatisticOrderCommentsInfo>(); StatisticOrderCommentsInfo info17 = (from c in shopStatisticOrderComments where ((int)c.CommentKey) == 11 select c).FirstOrDefault <StatisticOrderCommentsInfo>(); StatisticOrderCommentsInfo info18 = (from c in shopStatisticOrderComments where ((int)c.CommentKey) == 12 select c).FirstOrDefault <StatisticOrderCommentsInfo>(); StatisticOrderCommentsInfo info19 = (from c in shopStatisticOrderComments where ((int)c.CommentKey) == 7 select c).FirstOrDefault <StatisticOrderCommentsInfo>(); StatisticOrderCommentsInfo info20 = (from c in shopStatisticOrderComments where ((int)c.CommentKey) == 8 select c).FirstOrDefault <StatisticOrderCommentsInfo>(); decimal num14 = 5M; if (!(((info9 == null) || (info12 == null)) || shop.IsSelf)) { model.ProductAndDescription = info9.CommentValue; model.ProductAndDescriptionPeer = info12.CommentValue; model.ProductAndDescriptionMin = info16.CommentValue; model.ProductAndDescriptionMax = info15.CommentValue; } else { model.ProductAndDescription = num14; model.ProductAndDescriptionPeer = num14; model.ProductAndDescriptionMin = num14; model.ProductAndDescriptionMax = num14; } if (!(((info10 == null) || (info13 == null)) || shop.IsSelf)) { model.SellerServiceAttitude = info10.CommentValue; model.SellerServiceAttitudePeer = info13.CommentValue; model.SellerServiceAttitudeMax = info17.CommentValue; model.SellerServiceAttitudeMin = info18.CommentValue; } else { model.SellerServiceAttitude = num14; model.SellerServiceAttitudePeer = num14; model.SellerServiceAttitudeMax = num14; model.SellerServiceAttitudeMin = num14; } if (!(((info14 == null) || (info11 == null)) || shop.IsSelf)) { model.SellerDeliverySpeed = info11.CommentValue; model.SellerDeliverySpeedPeer = info14.CommentValue; model.SellerDeliverySpeedMax = (info19 != null) ? info19.CommentValue : 0M; model.sellerDeliverySpeedMin = (info20 != null) ? info20.CommentValue : 0M; } else { model.SellerDeliverySpeed = num14; model.SellerDeliverySpeedPeer = num14; model.SellerDeliverySpeedMax = num14; model.sellerDeliverySpeedMin = num14; } if ((base.CurrentUser != null) && (base.CurrentUser.Id > 0L)) { model2.IsFavorite = this._iProductService.IsFavorite(product.Id, base.CurrentUser.Id); } else { model2.IsFavorite = false; } VShopInfo vShopByShopId = this._iVShopService.GetVShopByShopId(shop.Id); if (vShopByShopId == null) { num15 = -1L; } else { num15 = vShopByShopId.Id; } model.VShopId = num15; model2.Shop.VShopId = num15; model2.VShopLog = this._iVShopService.GetVShopLog(model2.Shop.VShopId); if (string.IsNullOrWhiteSpace(model2.VShopLog)) { model2.VShopLog = base.CurrentSiteSetting.WXLogo; } model.Logined = (base.CurrentUser != null) ? 1 : 0; model2.EnabledBuy = (((product.AuditStatus == ProductInfo.ProductAuditStatus.Audited) && (DateTime.Parse(model3.BeginDate) <= DateTime.Now)) && (DateTime.Parse(model3.EndDate) > DateTime.Now)) && (product.SaleStatus == ProductInfo.ProductSaleStatus.OnSale); if (((model3.Status == FlashSaleInfo.FlashSaleStatus.Ongoing) && (DateTime.Parse(model3.BeginDate) < DateTime.Now)) && (DateTime.Parse(model3.EndDate) > DateTime.Now)) { span = new TimeSpan(DateTime.Parse(model3.EndDate).Ticks); span2 = new TimeSpan(DateTime.Now.Ticks); span3 = span.Subtract(span2); model.Second = (span3.TotalSeconds < 0.0) ? 0.0 : span3.TotalSeconds; } else if ((model3.Status == FlashSaleInfo.FlashSaleStatus.Ongoing) && (DateTime.Parse(model3.BeginDate) > DateTime.Now)) { span = new TimeSpan(DateTime.Parse(model3.BeginDate).Ticks); span2 = new TimeSpan(DateTime.Now.Ticks); span3 = span.Subtract(span2); model.Second = (span3.TotalSeconds < 0.0) ? 0.0 : span3.TotalSeconds; } ((dynamic)base.ViewBag).DetailModel = model; List <Himall.DTO.CustomerService> mobileCustomerService = CustomerServiceApplication.GetMobileCustomerService(model3.ShopId); Himall.DTO.CustomerService service = Enumerable.FirstOrDefault <Himall.DTO.CustomerService>((IEnumerable <Himall.DTO.CustomerService>)CustomerServiceApplication.GetPreSaleByShopId(model3.ShopId), (Func <Himall.DTO.CustomerService, bool>)(p => p.Tool == CustomerServiceInfo.ServiceTool.MeiQia)); if (service != null) { mobileCustomerService.Insert(0, service); } ((dynamic)base.ViewBag).CustomerServices = mobileCustomerService; StatisticApplication.StatisticVisitCount(product.Id, product.ShopId); return(base.View(model2)); }
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 }); }
private TiresFloorActivityConfig ConvertDetails(TiresFloorActivityConfig result, FlashSaleModel flashSaleInfo, List <DataAccess.Entity.TiresActivity.SimpleTireProductInfo> tireInfo) { try { result.ProductList = (from fs in flashSaleInfo.Products join pl in result.ProductList ?? new List <DataAccess.Entity.TiresActivity.TiresActivityProductConfig>() on fs.PID equals pl.ProductId into temp from t in temp.DefaultIfEmpty() join tp in tireInfo on fs.PID equals tp.PID into infoData from o in infoData.DefaultIfEmpty() select new DataAccess.Entity.TiresActivity.TiresActivityProductConfig() { ActivityId = fs.ActivityID, ProductId = fs.PID, ProductName = fs.ProductName, Position = fs.Position, Price = fs.Price, Size = o != null ? o.CP_Tire_Rim : string.Empty, Specification = o != null && !string.IsNullOrEmpty(o.CP_Tire_Width) ? (o.CP_Tire_Width + "/" + (!string.IsNullOrEmpty(o.CP_Tire_AspectRatio) ? o.CP_Tire_AspectRatio : string.Empty)) : string.Empty, MaxQuantity = fs.MaxQuantity, TotalQuantity = fs.TotalQuantity, AdvertiseTitle = t != null && !string.IsNullOrEmpty(t.AdvertiseTitle) ? t.AdvertiseTitle : fs.AdvertiseTitle, IsShow = t != null && !string.IsNullOrEmpty(t.AdvertiseTitle), SpecialCondition = t != null ? t.SpecialCondition : 0, IsCancelProgressBar = t != null ? t.IsCancelProgressBar : false }).ToList(); } catch (Exception ex) { logger.Error(ex); } return(result); }
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)); }
public object GetLimitBuyProduct(long id) { ProductDetailModelForMobie model = new ProductDetailModelForMobie() { Product = new ProductInfoModel(), Shop = new ShopInfoModel(), Color = new CollectionSKU(), Size = new CollectionSKU(), Version = new CollectionSKU() }; ProductInfo product = null; 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页面 return(Json(new { Success = "false", ErrorMsg = "你所请求的限时购或者诊疗项目不存在!" })); } } if (market != null && (market.Status != FlashSaleInfo.FlashSaleStatus.Ongoing || DateTime.Parse(market.EndDate) < DateTime.Now)) { return(Json(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 ProductTypeInfo 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.SKUInfo != null && product.SKUInfo.Count() > 0) { hasSku = true; long colorId = 0, sizeId = 0, versionId = 0; foreach (var sku in product.SKUInfo) { var specs = sku.Id.Split('_'); if (specs.Count() > 0) { if (long.TryParse(specs[1], out colorId)) { } if (colorId != 0) { if (!model.Color.Any(v => v.Value.Equals(sku.Color))) { var c = product.SKUInfo.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 = sku.ShowPic }); } } } if (specs.Count() > 1) { if (long.TryParse(specs[2], out sizeId)) { } if (sizeId != 0) { if (!model.Size.Any(v => v.Value.Equals(sku.Size))) { var ss = product.SKUInfo.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) { if (long.TryParse(specs[3], out versionId)) { } if (versionId != 0) { if (!model.Version.Any(v => v.Value.Equals(sku.Version))) { var v = product.SKUInfo.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 = ShopServiceMark.GetShopComprehensiveMark(shop.Id); model.Shop.PackMark = mark.PackMark; model.Shop.ServiceMark = mark.ServiceMark; model.Shop.ComprehensiveMark = mark.ComprehensiveMark; var comm = ServiceProvider.Instance <ICommentService> .Create.GetCommentsByProductId(product.Id); model.Shop.Name = shop.ShopName; model.Shop.ProductMark = (comm == null || comm.Count() == 0) ? 0 : comm.Average(p => ( decimal )p.ReviewMark); 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.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescription).FirstOrDefault(); var sellerServiceAttitude = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitude).FirstOrDefault(); var sellerDeliverySpeed = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeed).FirstOrDefault(); var productAndDescriptionPeer = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionPeer).FirstOrDefault(); var sellerServiceAttitudePeer = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudePeer).FirstOrDefault(); var sellerDeliverySpeedPeer = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeedPeer).FirstOrDefault(); var productAndDescriptionMax = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionMax).FirstOrDefault(); var productAndDescriptionMin = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionMin).FirstOrDefault(); var sellerServiceAttitudeMax = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudeMax).FirstOrDefault(); var sellerServiceAttitudeMin = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudeMin).FirstOrDefault(); var sellerDeliverySpeedMax = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeedMax).FirstOrDefault(); var sellerDeliverySpeedMin = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeedMin).FirstOrDefault(); 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); double total = product.Himall_ProductComments.Count(); double niceTotal = product.Himall_ProductComments.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 (File.Exists(HttpContext.Current.Server.MapPath(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 = product.Himall_ProductComments.Count(), 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 = product.ProductDescriptionInfo.ShowMobileDescription, IsOnLimitBuy = limitBuy != null }; #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(Json(new { Success = "true", IsOnLimitBuy = "true", HasSku = hasSku, MaxSaleCount = market.LimitCountOfThePeople, Title = market.Title, Second = second, Product = model.Product, Shop = model.Shop, Color = model.Color, Size = model.Size, Version = model.Version, ColorAlias = colorAlias, SizeAlias = sizeAlias, VersionAlias = versionAlias })); }
public FlashSaleModel Get(long id) { var model = DbFactory.Default.Get <FlashSaleInfo>().Where(p => p.Id == id).FirstOrDefault(); if (model == null) { throw new MallException("活动不存在!"); } var product = ProductManagerApplication.GetProduct(model.ProductId); FlashSaleModel result = new FlashSaleModel(); result.Id = model.Id; result.Title = model.Title; result.ShopId = model.ShopId; result.ProductId = model.ProductId; result.Status = model.Status; result.ProductName = product.ProductName; result.ProductImg = product.RelativePath; result.MarketPrice = product.MarketPrice; result.StatusStr = model.Status.ToDescription(); result.BeginDate = model.BeginDate.ToString("yyyy-MM-dd HH:mm"); result.EndDate = model.EndDate.ToString("yyyy-MM-dd HH:mm"); result.LimitCountOfThePeople = model.LimitCountOfThePeople; result.SaleCount = model.SaleCount; result.CategoryName = model.CategoryName; result.MinPrice = result.SkuMinPrice = result.SkuMaxPrice = model.MinPrice; result.Details = new List <FlashSaleDetailModel>(); var details = DbFactory.Default.Get <FlashSaleDetailInfo>().Where(p => p.FlashSaleId == result.Id).ToList(); var skus = DbFactory.Default.Get <SKUInfo>().Where(p => p.ProductId == model.ProductId).ToList(); #region 阶梯商品价格--ZYF var price = GetMinLadderPrice(model.ProductId); #endregion if (details != null && details.Count() > 0) { result.SkuMinPrice = details.Min(t => t.Price); result.SkuMaxPrice = details.Max(t => t.Price); } foreach (var sku in skus) { var detail = details.FirstOrDefault(p => p.SkuId == sku.Id); FlashSaleDetailModel d = new FlashSaleDetailModel(); d.Id = detail == null ? 0 : detail.Id; d.SkuId = sku.Id; d.Price = detail == null ? sku.SalePrice : (decimal)detail.Price; d.Color = sku.Color; d.Size = sku.Size; d.Version = sku.Version; d.Stock = (int)sku.Stock; d.TotalCount = detail == null ? 0 : Math.Min((int)sku.Stock, detail.TotalCount); d.CostPrice = sku.CostPrice; d.SalePrice = price > 0 ? price : sku.SalePrice; d.minMath = 0; result.Details.Add(d); } result.Quantity = result.Details.Sum(a => a.TotalCount); //if( details != null ) //{ // foreach( var detail in details ) // { // var sku = context.SKUInfo.FirstOrDefault( p => p.Id == detail.SkuId ); // if( sku == null ) // { // //如果sku为空,证明限时购的sku记录与商品的不一致 // //证明商品在限时购已存在的情况下修改了sku相关信息 // //暂时还没做处理 // break; // } // FlashSaleDetailModel d = new FlashSaleDetailModel(); // d.Id = detail.Id; // d.SkuId = detail.SkuId; // d.Price = ( decimal )detail.Price; // d.Color = sku.Color; // d.Size = sku.Size; // d.Version = sku.Version; // d.Stock = ( int )sku.Stock; // d.CostPrice = sku.CostPrice; // d.SalePrice = sku.SalePrice; // result.Details.Add( d ); // } //} return(result); }
///// <summary> ///// 获取限时抢购商品详情 ///// </summary> ///// <param name="id"></param> ///// <returns></returns> public object 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() }; ProductInfo product = null; 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(new { Success = "false", ErrorMsg = "你所请求的限时购或者商品不存在!" })); } } if (market != null && (market.Status != FlashSaleInfo.FlashSaleStatus.Ongoing || DateTime.Parse(market.EndDate) < DateTime.Now)) { return(Json(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 ProductTypeInfo 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>(); if (product.SKUInfo != null && product.SKUInfo.Count() > 0) { hasSku = true; #region 颜色 long colorId = 0, sizeId = 0, versionId = 0; List <object> colorAttributeValue = new List <object>(); List <string> listcolor = new List <string>(); foreach (var sku in product.SKUInfo) { var specs = sku.Id.Split('_'); if (specs.Count() > 0) { if (long.TryParse(specs[1], out colorId)) { } //相同颜色规格累加对应值 if (colorId != 0) { if (!listcolor.Contains(sku.Color)) { var c = product.SKUInfo.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 = colorAlias, AttributeId = product.TypeId, AttributeValue = colorAttributeValue }; if (colorId > 0) { SkuItemList.Add(color); } #endregion #region 容量 List <object> sizeAttributeValue = new List <object>(); List <string> listsize = new List <string>(); foreach (var sku in product.SKUInfo) { 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 = product.SKUInfo.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 = sizeAlias, AttributeId = product.TypeId, AttributeValue = sizeAttributeValue }; if (sizeId > 0) { SkuItemList.Add(size); } #endregion #region 规格 List <object> versionAttributeValue = new List <object>(); List <string> listversion = new List <string>(); foreach (var sku in product.SKUInfo) { 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 = product.SKUInfo.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 = versionAlias, AttributeId = product.TypeId, AttributeValue = versionAttributeValue }; if (versionId > 0) { SkuItemList.Add(version); } #endregion #region Sku值 foreach (var sku in product.SKUInfo) { 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 = 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.Price //限时抢购价格 }; Skus.Add(prosku); } #endregion } #endregion #region 店铺 shop = ServiceProvider.Instance <IShopService> .Create.GetShop(product.ShopId); var mark = ShopServiceMark.GetShopComprehensiveMark(shop.Id); model.Shop.PackMark = mark.PackMark; model.Shop.ServiceMark = mark.ServiceMark; model.Shop.ComprehensiveMark = mark.ComprehensiveMark; var comm = ServiceProvider.Instance <ICommentService> .Create.GetCommentsByProductId(product.Id); model.Shop.Name = shop.ShopName; model.Shop.ProductMark = (comm == null || comm.Count() == 0) ? 0 : comm.Average(p => (decimal)p.ReviewMark); 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.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescription).FirstOrDefault(); var sellerServiceAttitude = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitude).FirstOrDefault(); var sellerDeliverySpeed = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeed).FirstOrDefault(); var productAndDescriptionPeer = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionPeer).FirstOrDefault(); var sellerServiceAttitudePeer = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudePeer).FirstOrDefault(); var sellerDeliverySpeedPeer = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeedPeer).FirstOrDefault(); var productAndDescriptionMax = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionMax).FirstOrDefault(); var productAndDescriptionMin = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionMin).FirstOrDefault(); var sellerServiceAttitudeMax = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudeMax).FirstOrDefault(); var sellerServiceAttitudeMin = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudeMin).FirstOrDefault(); var sellerDeliverySpeedMax = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeedMax).FirstOrDefault(); var sellerDeliverySpeedMin = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeedMin).FirstOrDefault(); 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; } 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()) { 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 = "店铺通用", 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); double total = product.Himall_ProductComments.Count(); double niceTotal = product.Himall_ProductComments.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 (File.Exists(HttpContext.Current.Server.MapPath(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 = product.Himall_ProductComments.Count(), 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 = product.ProductDescriptionInfo.ShowMobileDescription, IsOnLimitBuy = limitBuy != null }; #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++) { 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 } //Normal:正常 //PullOff:已下架 //NoJoin:未参与 //AboutToBegin:即将开始 //ActivityEnd:已结束 //SoldOut:已抢完 var json = new { Status = "OK", Data = 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 = model.Product.ProductDescription, ShortDescription = product.ShortDescription, ShowSaleCounts = product.SaleCounts.ToString(), Weight = product.Weight.ToString(), MinSalePrice = market.MinPrice.ToString("0.##"), //product.SKUInfo.Min(c => c.SalePrice).ToString("0.##"),//限时抢购价格 MaxSalePrice = product.MarketPrice, Stock = market.Quantity, //限时抢购库存 MarketPrice = product.MarketPrice, //product.SKUInfo.Min(c => c.SalePrice).ToString("0.##"), IsfreeShipping = product.Himall_Shops.FreeFreight, //product.Product.IsfreeShipping.ToString(), ThumbnailUrl60 = Core.HimallIO.GetRomoteProductSizeImage(product.ImagePath, 1, (int)ImageSize.Size_350), ProductImgs = ProductImgs, SkuItemList = SkuItemList, Skus = Skus, Freight = 0, Coupons = coupons, } }; return(json); }
///// <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内发货") : ""), //运费模板发货时间 })); }
public RegionMarketingModel GetRegionActivityConfigByActivityId(Guid activityId) { RegionMarketingModel result = null; FlashSaleModel flashSaleInfo = null; List <DataAccess.Entity.RegionMarketing.SimpleTireProductInfo> tireInfo = new List <DataAccess.Entity.RegionMarketing.SimpleTireProductInfo>(); try { if (activityId != Guid.Empty) { dbScopeReadManager.Execute(conn => { result = DALRegionMarketing.SelectRegionConfigByActivityId(conn, activityId); if (result != null) { result.ImgList = DALRegionMarketing.SelectActivityImgById(conn, result.ActivityId); result.ProductList = DALRegionMarketing.SelectRegionProductsByActivityId(conn, result.ActivityId); flashSaleInfo = SelectFlashSaleDataByActivityID(activityId); if (flashSaleInfo != null && flashSaleInfo.Products != null && flashSaleInfo.Products.Any()) { var products = flashSaleInfo.Products; var pidStr = string.Join(",", products.Select(x => x.PID)); tireInfo = DALRegionMarketing.SelectProductInfoByPID(conn, pidStr); } } }); if (result != null) { if (flashSaleInfo != null && flashSaleInfo.Products != null && flashSaleInfo.Products.Any()) { result.ProductList = (from fs in flashSaleInfo.Products join pl in result.ProductList on fs.PID equals pl.ProductId into temp from t in temp.DefaultIfEmpty() join tp in tireInfo on fs.PID equals tp.PID into infoData from o in infoData.DefaultIfEmpty() select new RegionMarketingProductConfig() { ActivityId = fs.ActivityID, ProductId = fs.PID, ProductName = fs.ProductName, Price = fs.Price, Size = o != null ? o.CP_Tire_Rim : string.Empty, Specification = o != null && !string.IsNullOrEmpty(o.CP_Tire_Width) ? (o.CP_Tire_Width + "/" + (!string.IsNullOrEmpty(o.CP_Tire_AspectRatio) ? o.CP_Tire_AspectRatio : string.Empty)) : string.Empty, MaxQuantity = fs.MaxQuantity, TotalQuantity = fs.TotalQuantity, AdvertiseTitle = t != null && !string.IsNullOrEmpty(t.AdvertiseTitle) ? t.AdvertiseTitle : fs.AdvertiseTitle, IsShow = t != null && !string.IsNullOrEmpty(t.AdvertiseTitle), SpecialCondition = t != null ? t.SpecialCondition : 0 }).ToList(); } } } } catch (Exception ex) { logger.Log(Level.Error, ex, "GetRegionMarketingConfig"); } return(result); }
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 Model.ProductInfo(), Shop = new ShopInfoModel(), ShopCategory = new List <CategoryJsonModel>(), Color = new CollectionSKU(), Size = new CollectionSKU(), Version = new CollectionSKU() }; FlashSaleModel market = null; 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 FlashSaleInfo.FlashSaleStatus.Ended: return(RedirectToAction("Detail", "Product", new { id = market.ProductId })); break; case FlashSaleInfo.FlashSaleStatus.Cancelled: return(RedirectToAction("Detail", "Product", new { id = market.ProductId })); break; } if (market.Status != 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; //product.MarketPrice = market.MinPrice; //product.SaleCounts = market.SaleCount; var brandModel = ServiceHelper.Create <IBrandService>().GetBrand(product.BrandId); product.BrandName = brandModel == null ? "" : brandModel.Name; model.Product = product; model.ProductDescription = product.ProductDescriptionInfo.Description; if (product.ProductDescriptionInfo.DescriptionPrefixId != 0) { var desc = _iProductDescriptionTemplateService .GetTemplate(product.ProductDescriptionInfo.DescriptionPrefixId, product.ShopId); model.DescriptionPrefix = desc == null ? "" : desc.Content; } if (product.ProductDescriptionInfo.DescriptiondSuffixId != 0) { var desc = _iProductDescriptionTemplateService .GetTemplate(product.ProductDescriptionInfo.DescriptiondSuffixId, product.ShopId); model.DescriptiondSuffix = desc == null ? "" : desc.Content; } #endregion #region 诊所 var categories = _iShopCategoryService.GetShopCategory(product.ShopId); List <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 热门使用 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 }); } } #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 诊疗项目规格 ProductTypeInfo 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; model.ColorAlias = colorAlias; model.SizeAlias = sizeAlias; model.VersionAlias = versionAlias; if (product.SKUInfo != null && product.SKUInfo.Count() > 0) { long colorId = 0, sizeId = 0, versionId = 0; foreach (var sku in product.SKUInfo) { var specs = sku.Id.Split('_'); if (specs.Count() > 0) { if (long.TryParse(specs[1], out colorId)) { } if (colorId != 0) { if (!model.Color.Any(v => v.Value.Equals(sku.Color))) { var c = product.SKUInfo.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 }); } } } if (specs.Count() > 1) { if (long.TryParse(specs[2], out sizeId)) { } if (sizeId != 0) { if (!model.Size.Any(v => v.Value.Equals(sku.Size))) { var ss = product.SKUInfo.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) { if (long.TryParse(specs[3], out versionId)) { } if (versionId != 0) { if (!model.Version.Any(v => v.Value.Equals(sku.Version))) { var v = product.SKUInfo.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 }); } } } } decimal min = 0, max = 0; if (product.SKUInfo.FirstOrDefault(s => s.Stock >= 0) != null) { min = product.SKUInfo.Where(s => s.Stock >= 0).Min(s => s.SalePrice); } if (product.SKUInfo.FirstOrDefault(s => s.Stock >= 0) != null) { max = product.SKUInfo.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")); } } model.Price = string.IsNullOrWhiteSpace(price) ? product.MinSalePrice.ToString("f2") : price; #endregion #region 诊疗项目属性 List <TypeAttributesModel> ProductAttrs = new List <TypeAttributesModel>(); var prodAttrs = _iProductService.GetProductAttribute(product.Id).ToList(); foreach (var attr in prodAttrs) { if (!ProductAttrs.Any(p => p.AttrId == attr.AttributeId)) { TypeAttributesModel attrModel = new TypeAttributesModel() { AttrId = attr.AttributeId, AttrValues = new List <TypeAttrValue>(), Name = attr.AttributesInfo.Name }; foreach (var attrV in attr.AttributesInfo.AttributeValueInfo) { 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); if (!attrTemp.AttrValues.Any(p => p.Id == attr.ValueId.ToString())) { attrTemp.AttrValues.Add(new TypeAttrValue { Id = attr.ValueId.ToString(), Name = attr.AttributesInfo.AttributeValueInfo.FirstOrDefault(a => a.Id == attr.ValueId).Value }); } } } model.ProductAttrs = ProductAttrs; #endregion #region 获取评论、咨询数量 //var comments = _iCommentService.GetComments( new CommentQuery //{ // ProductID = product.Id , // PageNo = 1 , // PageSize = 10000 //} ); //model.CommentCount = comments.Total; var com = product.Himall_ProductComments.Where(item => !item.IsHidden.HasValue || item.IsHidden.Value == false); var comCount = com.Count(); model.CommentCount = comCount; 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 = ServiceHelper.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 == StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescription).FirstOrDefault(); var sellerServiceAttitude = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitude).FirstOrDefault(); var sellerDeliverySpeed = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeed).FirstOrDefault(); var productAndDescriptionPeer = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionPeer).FirstOrDefault(); var sellerServiceAttitudePeer = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudePeer).FirstOrDefault(); var sellerDeliverySpeedPeer = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeedPeer).FirstOrDefault(); var productAndDescriptionMax = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionMax).FirstOrDefault(); var productAndDescriptionMin = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionMin).FirstOrDefault(); var sellerServiceAttitudeMax = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudeMax).FirstOrDefault(); var sellerServiceAttitudeMin = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudeMin).FirstOrDefault(); var sellerDeliverySpeedMax = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeedMax).FirstOrDefault(); var sellerDeliverySpeedMin = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.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 = ServiceHelper.Create <ICustomerService>().GetCustomerService(shop.Id).Where(c => c.Type == CustomerServiceInfo.ServiceType.PreSale && c.TerminalType == CustomerServiceInfo.ServiceTerminalType.PC).OrderBy(m => m.Tool); #endregion #region 开团提醒场景二维码 var siteSetting = _iSiteSettingService.GetSiteSettings(); if (DateTime.Parse(model.FlashSale.BeginDate) > DateTime.Now && WXIsConfig(siteSetting.WeixinAppId, siteSetting.WeixinAppSecret)) { var token = AccessTokenContainer.TryGetToken(siteSetting.WeixinAppId, siteSetting.WeixinAppSecret); SceneHelper helper = new SceneHelper(); Himall.Model.SceneModel scene = new SceneModel(QR_SCENE_Type.FlashSaleRemind, model.FlashSale.Id); int sceneId = helper.SetModel(scene); var ticket = Senparc.Weixin.MP.AdvancedAPIs.QrCode.QrCodeApi.Create(token, 86400, sceneId).ticket; ViewBag.ticket = ticket; } #endregion model.Logined = (null != CurrentUser) ? 1 : 0; model.EnabledBuy = product.AuditStatus == ProductInfo.ProductAuditStatus.Audited && DateTime.Parse(market.BeginDate) <= DateTime.Now && DateTime.Parse(market.EndDate) > DateTime.Now && product.SaleStatus == 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; return(View(model)); }
public void UpdateFlashSale(FlashSaleModel model) { CheckFlashSale(model); FlashSaleInfo flashSale = DbFactory.Default.Get <FlashSaleInfo>().Where(p => p.Id == model.Id).FirstOrDefault(); if (flashSale == null) { throw new MallException("此活动已被删除"); } DbFactory.Default.InTransaction(() => { DbFactory.Default.Del <FlashSaleDetailInfo>().Where(p => p.ProductId == model.ProductId).Succeed(); if (flashSale.Status == FlashSaleInfo.FlashSaleStatus.WaitForAuditing) { if (flashSale.ProductId != model.ProductId) { var product = DbFactory.Default.Get <ProductInfo>().Where(p => p.Id == model.ProductId).FirstOrDefault(); flashSale.ImagePath = product.RelativePath; } flashSale.Title = model.Title; flashSale.ShopId = model.ShopId; flashSale.ProductId = model.ProductId; flashSale.BeginDate = DateTime.Parse(model.BeginDate); flashSale.CategoryName = model.CategoryName; flashSale.EndDate = DateTime.Parse(model.EndDate); flashSale.LimitCountOfThePeople = model.LimitCountOfThePeople; flashSale.MinPrice = model.Details.Min(p => p.Price); if (model.Status == FlashSaleInfo.FlashSaleStatus.WaitForAuditing) { flashSale.Status = FlashSaleInfo.FlashSaleStatus.WaitForAuditing; } DbFactory.Default.Update(flashSale); foreach (var detail in model.Details) { FlashSaleDetailInfo fsd = new FlashSaleDetailInfo(); fsd.ProductId = flashSale.ProductId; fsd.SkuId = detail.SkuId; fsd.Price = detail.Price; fsd.TotalCount = detail.TotalCount; fsd.FlashSaleId = flashSale.Id; DbFactory.Default.Add(fsd); } } else if (flashSale.Status == FlashSaleInfo.FlashSaleStatus.Ongoing) { flashSale.Title = model.Title; flashSale.CategoryName = model.CategoryName; flashSale.LimitCountOfThePeople = model.LimitCountOfThePeople; flashSale.EndDate = DateTime.Parse(model.EndDate); flashSale.MinPrice = model.Details.Min(p => p.Price); if (model.Status == FlashSaleInfo.FlashSaleStatus.WaitForAuditing) { flashSale.Status = FlashSaleInfo.FlashSaleStatus.WaitForAuditing; } DbFactory.Default.Update(flashSale); foreach (var detail in model.Details) { FlashSaleDetailInfo fsd = new FlashSaleDetailInfo(); fsd.ProductId = flashSale.ProductId; fsd.SkuId = detail.SkuId; fsd.Price = detail.Price; fsd.TotalCount = detail.TotalCount; fsd.FlashSaleId = flashSale.Id; DbFactory.Default.Add(fsd); } } }); }
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)); }