/// <summary> /// 获取收货地址 /// </summary> /// <param name="regionId"></param> /// <returns></returns> private Entities.ShippingAddressInfo GetShippingAddress(long?regionId) { Entities.ShippingAddressInfo result = null; if (regionId != null) { result = ShippingAddressApplication.GetUserShippingAddress((long)regionId); } else { result = ShippingAddressApplication.GetDefaultUserShippingAddressByUserId(CurrentUser.Id); } return(result); }
public object GetShopBranchs(long shopId, bool getParent, string skuIds, string counts, int page, int rows, long shippingAddressId, long regionId) { string[] _skuIds = skuIds.Split(','); int[] _counts = counts.Split(',').Select(p => Mall.Core.Helper.TypeHelper.ObjectToInt(p)).ToArray(); var shippingAddressInfo = ShippingAddressApplication.GetUserShippingAddress(shippingAddressId); int streetId = 0, districtId = 0;//收货地址的街道、区域 var query = new ShopBranchQuery() { ShopId = shopId, PageNo = page, PageSize = rows, Status = CommonModel.ShopBranchStatus.Normal, ShopBranchProductStatus = ShopBranchSkuStatus.Normal }; if (shippingAddressInfo != null) { query.FromLatLng = string.Format("{0},{1}", shippingAddressInfo.Latitude, shippingAddressInfo.Longitude);//需要收货地址的经纬度 streetId = shippingAddressInfo.RegionId; var parentAreaInfo = RegionApplication.GetRegion(shippingAddressInfo.RegionId, Region.RegionLevel.Town);//判断当前区域是否为第四级 if (parentAreaInfo != null && parentAreaInfo.ParentId > 0) districtId = parentAreaInfo.ParentId; else { districtId = streetId; streetId = 0; } } bool hasLatLng = false; if (!string.IsNullOrWhiteSpace(query.FromLatLng)) hasLatLng = query.FromLatLng.Split(',').Length == 2; var region = RegionApplication.GetRegion(regionId, getParent ? CommonModel.Region.RegionLevel.City : CommonModel.Region.RegionLevel.County);//同城内门店 if (region != null) query.AddressPath = region.GetIdPath(); #region 3.0版本排序规则 var skuInfos = ProductManagerApplication.GetSKUs(_skuIds); query.ProductIds = skuInfos.Select(p => p.ProductId).ToArray(); var data = ShopBranchApplication.GetShopBranchsAll(query); var shopBranchSkus = ShopBranchApplication.GetSkus(shopId, data.Models.Select(p => p.Id).ToList());//获取该商家下具有订单内所有商品的门店状态正常数据,不考虑库存 data.Models.ForEach(p => { p.Enabled = skuInfos.All(skuInfo => shopBranchSkus.Any(sbSku => sbSku.ShopBranchId == p.Id && sbSku.Stock >= _counts[skuInfos.IndexOf(skuInfo)] && sbSku.SkuId == skuInfo.Id)); }); List<Mall.DTO.ShopBranch> newList = new List<Mall.DTO.ShopBranch>(); List<long> fillterIds = new List<long>(); var currentList = data.Models.Where(p => hasLatLng && p.Enabled && (p.Latitude > 0 && p.Longitude > 0)).OrderBy(p => p.Distance).ToList(); if (currentList != null && currentList.Count() > 0) { fillterIds.AddRange(currentList.Select(p => p.Id)); newList.AddRange(currentList); } var currentList2 = data.Models.Where(p => !fillterIds.Contains(p.Id) && p.Enabled && p.AddressPath.Contains(CommonConst.ADDRESS_PATH_SPLIT + streetId + CommonConst.ADDRESS_PATH_SPLIT)).ToList(); if (currentList2 != null && currentList2.Count() > 0) { fillterIds.AddRange(currentList2.Select(p => p.Id)); newList.AddRange(currentList2); } var currentList3 = data.Models.Where(p => !fillterIds.Contains(p.Id) && p.Enabled && p.AddressPath.Contains(CommonConst.ADDRESS_PATH_SPLIT + districtId + CommonConst.ADDRESS_PATH_SPLIT)).ToList(); if (currentList3 != null && currentList3.Count() > 0) { fillterIds.AddRange(currentList3.Select(p => p.Id)); newList.AddRange(currentList3); } var currentList4 = data.Models.Where(p => !fillterIds.Contains(p.Id) && p.Enabled).ToList();//非同街、非同区,但一定会同市 if (currentList4 != null && currentList4.Count() > 0) { fillterIds.AddRange(currentList4.Select(p => p.Id)); newList.AddRange(currentList4); } var currentList5 = data.Models.Where(p => !fillterIds.Contains(p.Id)).ToList();//库存不足的排最后 if (currentList5 != null && currentList5.Count() > 0) { newList.AddRange(currentList5); } if (newList.Count() != data.Models.Count())//如果新组合的数据与原数据数量不一致 { return new { success = false }; } var needDistance = false; if (shippingAddressInfo != null && shippingAddressInfo.Latitude!=0 && shippingAddressInfo.Longitude!=0) { needDistance = true; } var storeList = newList.Select(sb => { return new { ContactUser = sb.ContactUser, ContactPhone = sb.ContactPhone, AddressDetail = sb.AddressDetail, ShopBranchName = sb.ShopBranchName, Id = sb.Id, Enabled = sb.Enabled, Distance = needDistance ? RegionApplication.GetDistance(sb.Latitude, sb.Longitude, shippingAddressInfo.Latitude, shippingAddressInfo.Longitude) : 0 }; }); #endregion var result = new { success = true, StoreList = storeList }; return result; }
public JsonResult GetShopBranchs(long shopId, long regionId, bool getParent, string[] skuIds, int[] counts, int page, int rows, long shippingAddressId) { var shippingAddressInfo = ShippingAddressApplication.GetUserShippingAddress(shippingAddressId); int streetId = 0, districtId = 0;//收货地址的街道、区域 var query = new ShopBranchQuery() { ShopId = shopId, PageNo = page, PageSize = rows, Status = ShopBranchStatus.Normal, ShopBranchProductStatus = ShopBranchSkuStatus.Normal }; if (shippingAddressInfo != null) { query.FromLatLng = string.Format("{0},{1}", shippingAddressInfo.Latitude, shippingAddressInfo.Longitude); //需要收货地址的经纬度 streetId = shippingAddressInfo.RegionId; var parentAreaInfo = RegionApplication.GetRegion(shippingAddressInfo.RegionId, Region.RegionLevel.Town); //判断当前区域是否为第四级 if (parentAreaInfo != null && parentAreaInfo.ParentId > 0) { districtId = parentAreaInfo.ParentId; } else { districtId = streetId; streetId = 0; } } bool hasLatLng = false; if (!string.IsNullOrWhiteSpace(query.FromLatLng)) { hasLatLng = query.FromLatLng.Split(',').Length == 2; } var region = RegionApplication.GetRegion(regionId, getParent ? Region.RegionLevel.City : Region.RegionLevel.County); if (region != null) { query.AddressPath = region.GetIdPath(); } #region 旧排序规则 //var skuInfos = ProductManagerApplication.GetSKUs(skuIds); //query.ProductIds = skuInfos.Select(p => p.ProductId).ToArray(); //var data = ShopBranchApplication.GetShopBranchs(query); //var shopBranchSkus = ShopBranchApplication.GetSkus(shopId, data.Models.Select(p => p.Id)); //var models = new //{ // Rows = data.Models.Select(sb => new // { // sb.ContactUser, // sb.ContactPhone, // sb.AddressDetail, // sb.ShopBranchName, // sb.Id, // Enabled = skuInfos.All(skuInfo => shopBranchSkus.Any(sbSku => sbSku.ShopBranchId == sb.Id && sbSku.Stock >= counts[skuInfos.IndexOf(skuInfo)] && sbSku.SkuId == skuInfo.Id)) // }).OrderByDescending(p => p.Enabled).ToArray(), // data.Total //}; #endregion #region 3.0版本排序规则 var skuInfos = ProductManagerApplication.GetSKUs(skuIds); query.ProductIds = skuInfos.Select(p => p.ProductId).ToArray(); var data = ShopBranchApplication.GetShopBranchsAll(query); var shopBranchSkus = ShopBranchApplication.GetSkus(shopId, data.Models.Select(p => p.Id).ToList());//获取该商家下具有订单内所有商品的门店状态正常数据,不考虑库存 data.Models.ForEach(p => { p.Enabled = skuInfos.All(skuInfo => shopBranchSkus.Any(sbSku => sbSku.ShopBranchId == p.Id && sbSku.Stock >= counts[skuInfos.IndexOf(skuInfo)] && sbSku.SkuId == skuInfo.Id)); }); List <ShopBranch> newList = new List <ShopBranch>(); List <long> fillterIds = new List <long>(); var currentList = data.Models.Where(p => hasLatLng && p.Enabled && (p.Latitude > 0 && p.Longitude > 0)).OrderBy(p => p.Distance).ToList(); if (currentList != null && currentList.Count() > 0) { fillterIds.AddRange(currentList.Select(p => p.Id)); newList.AddRange(currentList); } var currentList2 = data.Models.Where(p => !fillterIds.Contains(p.Id) && p.Enabled && p.AddressPath.Contains(CommonConst.ADDRESS_PATH_SPLIT + streetId + CommonConst.ADDRESS_PATH_SPLIT)).ToList(); if (currentList2 != null && currentList2.Count() > 0) { fillterIds.AddRange(currentList2.Select(p => p.Id)); newList.AddRange(currentList2); } var currentList3 = data.Models.Where(p => !fillterIds.Contains(p.Id) && p.Enabled && p.AddressPath.Contains(CommonConst.ADDRESS_PATH_SPLIT + districtId + CommonConst.ADDRESS_PATH_SPLIT)).ToList(); if (currentList3 != null && currentList3.Count() > 0) { fillterIds.AddRange(currentList3.Select(p => p.Id)); newList.AddRange(currentList3); } var currentList4 = data.Models.Where(p => !fillterIds.Contains(p.Id) && p.Enabled).ToList();//非同街、非同区,但一定会同市 if (currentList4 != null && currentList4.Count() > 0) { fillterIds.AddRange(currentList4.Select(p => p.Id)); newList.AddRange(currentList4); } var currentList5 = data.Models.Where(p => !fillterIds.Contains(p.Id)).ToList();//库存不足的排最后 if (currentList5 != null && currentList5.Count() > 0) { newList.AddRange(currentList5); } if (newList.Count() != data.Models.Count())//如果新组合的数据与原数据数量不一致,则异常 { return(Json <dynamic>(true, data: new { Rows = "" }, camelCase: true)); } var needDistance = false; if (shippingAddressInfo != null && shippingAddressInfo.Latitude != 0 && shippingAddressInfo.Longitude != 0) { needDistance = true; } var models = new { Rows = newList.Select(sb => new { sb.ContactUser, sb.ContactPhone, sb.AddressDetail, sb.ShopBranchName, sb.Id, Enabled = sb.Enabled, Distance = needDistance ? RegionApplication.GetDistance(sb.Latitude, sb.Longitude, shippingAddressInfo.Latitude, shippingAddressInfo.Longitude) : 0 }).ToArray(), Total = newList.Count }; #endregion return(SuccessResult <dynamic>(data: models, camelCase: true)); }
public JsonResult GetShopBranchs(long shopId, long regionId, bool getParent, string[] skuIds, int[] counts, int page, int rows, long shippingAddressId) { ShippingAddressInfo userShippingAddress = ShippingAddressApplication.GetUserShippingAddress(shippingAddressId); int streetId = 0; int districtId = 0; ShopBranchQuery query = new ShopBranchQuery { ShopId = shopId, PageNo = page, PageSize = rows, Status = 0 }; if (userShippingAddress != null) { query.FromLatLng = string.Format("{0},{1}", userShippingAddress.Latitude, userShippingAddress.Longitude); streetId = userShippingAddress.RegionId; Region region = RegionApplication.GetRegion((long)userShippingAddress.RegionId, Region.RegionLevel.Town); if ((region != null) && (region.ParentId > 0)) { districtId = region.ParentId; } else { districtId = streetId; streetId = 0; } } bool hasLatLng = false; if (!string.IsNullOrWhiteSpace(query.FromLatLng)) { hasLatLng = query.FromLatLng.Split(new char[] { ',' }).Length == 2; } Region region2 = RegionApplication.GetRegion(regionId, getParent ? Region.RegionLevel.City : Region.RegionLevel.County); if (region2 != null) { query.AddressPath = region2.GetIdPath(","); } List <SKU> skuInfos = ProductManagerApplication.GetSKUs(skuIds); query.ProductIds = (from p in skuInfos select p.ProductId).ToArray <long>(); QueryPageModel <ShopBranch> shopBranchsAll = ShopBranchApplication.GetShopBranchsAll(query); List <ShopBranchSkusInfo> shopBranchSkus = ShopBranchApplication.GetSkus(shopId, from p in shopBranchsAll.Models select p.Id); shopBranchsAll.Models.ForEach(delegate(ShopBranch p) { p.Enabled = skuInfos.All <SKU>(skuInfo => shopBranchSkus.Any <ShopBranchSkusInfo>(sbSku => ((sbSku.ShopBranchId == p.Id) && (sbSku.Stock >= counts[skuInfos.IndexOf(skuInfo)])) && (sbSku.SkuId == skuInfo.Id))); }); List <ShopBranch> source = new List <ShopBranch>(); List <long> fillterIds = new List <long>(); List <ShopBranch> list2 = (from p in shopBranchsAll.Models where (hasLatLng && p.Enabled) && ((p.Latitude > 0f) && (p.Longitude > 0f)) orderby p.Distance select p).ToList <ShopBranch>(); if ((list2 != null) && (list2.Count <ShopBranch>() > 0)) { fillterIds.AddRange(from p in list2 select p.Id); source.AddRange(list2); } List <ShopBranch> list3 = (from p in shopBranchsAll.Models where (!fillterIds.Contains(p.Id) && p.Enabled) && p.AddressPath.Contains("," + streetId + ",") select p).ToList <ShopBranch>(); if ((list3 != null) && (list3.Count <ShopBranch>() > 0)) { fillterIds.AddRange(from p in list3 select p.Id); source.AddRange(list3); } List <ShopBranch> list4 = (from p in shopBranchsAll.Models where (!fillterIds.Contains(p.Id) && p.Enabled) && p.AddressPath.Contains("," + districtId + ",") select p).ToList <ShopBranch>(); if ((list4 != null) && (list4.Count <ShopBranch>() > 0)) { fillterIds.AddRange(from p in list4 select p.Id); source.AddRange(list4); } List <ShopBranch> list5 = (from p in shopBranchsAll.Models where !fillterIds.Contains(p.Id) && p.Enabled select p).ToList <ShopBranch>(); if ((list5 != null) && (list5.Count <ShopBranch>() > 0)) { fillterIds.AddRange(from p in list5 select p.Id); source.AddRange(list5); } List <ShopBranch> list6 = (from p in shopBranchsAll.Models where !fillterIds.Contains(p.Id) select p).ToList <ShopBranch>(); if ((list6 != null) && (list6.Count <ShopBranch>() > 0)) { source.AddRange(list6); } if (source.Count <ShopBranch>() != shopBranchsAll.Models.Count <ShopBranch>()) { return(base.Json(new { Rows = "" }, true)); } var data = new { Rows = (from sb in source select new { ContactUser = sb.ContactUser, ContactPhone = sb.ContactPhone, AddressDetail = sb.AddressDetail, ShopBranchName = sb.ShopBranchName, Id = sb.Id, Enabled = sb.Enabled }).ToArray(), Total = source.Count }; return(base.Json(data, true)); }
public object GetShopBranchs(long shopId, bool getParent, string skuIds, string counts, int page, int rows, long shippingAddressId, long regionId) { string[] strArray = skuIds.Split(','); int[] _counts = Enumerable.ToArray <int>(Enumerable.Select <string, int>((IEnumerable <string>)counts.Split(','), (Func <string, int>)(p => TypeHelper.ObjectToInt((object)p)))); ShippingAddressInfo userShippingAddress = ShippingAddressApplication.GetUserShippingAddress(shippingAddressId); int streetId = 0; int districtId = 0; ShopBranchQuery shopBranchQuery = new ShopBranchQuery(); shopBranchQuery.ShopId = shopId; shopBranchQuery.PageNo = page; shopBranchQuery.PageSize = rows; shopBranchQuery.Status = new ShopBranchStatus?(ShopBranchStatus.Normal); ShopBranchQuery query = shopBranchQuery; if (userShippingAddress != null) { query.FromLatLng = string.Format("{0},{1}", (object)userShippingAddress.Latitude, (object)userShippingAddress.Longitude); streetId = userShippingAddress.RegionId; Region region = RegionApplication.GetRegion((long)userShippingAddress.RegionId, Region.RegionLevel.Town); if (region != null && region.ParentId > 0) { districtId = region.ParentId; } else { districtId = streetId; streetId = 0; } } bool hasLatLng = false; if (!string.IsNullOrWhiteSpace(query.FromLatLng)) { hasLatLng = (query.FromLatLng.Split(',').Length == 2 ? 1 : 0) != 0; } Region region1 = RegionApplication.GetRegion(regionId, getParent ? Region.RegionLevel.City : Region.RegionLevel.County); if (region1 != null) { query.AddressPath = region1.GetIdPath(","); } List <SKU> skuInfos = ProductManagerApplication.GetSKUs((IEnumerable <string>)strArray); query.ProductIds = Enumerable.ToArray <long>(Enumerable.Select <SKU, long>((IEnumerable <SKU>)skuInfos, (Func <SKU, long>)(p => p.ProductId))); QueryPageModel <ShopBranch> shopBranchsAll = ShopBranchApplication.GetShopBranchsAll(query); List <ShopBranchSkusInfo> shopBranchSkus = ShopBranchApplication.GetSkus(shopId, Enumerable.Select <ShopBranch, long>((IEnumerable <ShopBranch>)shopBranchsAll.Models, (Func <ShopBranch, long>)(p => p.Id))); shopBranchsAll.Models.ForEach((Action <ShopBranch>)(p => p.Enabled = Enumerable.All <SKU>((IEnumerable <SKU>)skuInfos, (Func <SKU, bool>)(skuInfo => Enumerable.Any <ShopBranchSkusInfo>((IEnumerable <ShopBranchSkusInfo>)shopBranchSkus, (Func <ShopBranchSkusInfo, bool>)(sbSku => sbSku.ShopBranchId == p.Id && sbSku.Stock >= _counts[skuInfos.IndexOf(skuInfo)] && sbSku.SkuId == skuInfo.Id)))))); List <ShopBranch> list1 = new List <ShopBranch>(); List <long> fillterIds = new List <long>(); List <ShopBranch> list2 = Enumerable.ToList <ShopBranch>((IEnumerable <ShopBranch>)Enumerable.OrderBy <ShopBranch, double>(Enumerable.Where <ShopBranch>((IEnumerable <ShopBranch>)shopBranchsAll.Models, (Func <ShopBranch, bool>)(p => hasLatLng && p.Enabled && ((double)p.Latitude > 0.0 && (double)p.Longitude > 0.0))), (Func <ShopBranch, double>)(p => p.Distance))); if (list2 != null && Enumerable.Count <ShopBranch>((IEnumerable <ShopBranch>)list2) > 0) { fillterIds.AddRange(Enumerable.Select <ShopBranch, long>((IEnumerable <ShopBranch>)list2, (Func <ShopBranch, long>)(p => p.Id))); list1.AddRange((IEnumerable <ShopBranch>)list2); } List <ShopBranch> list3 = Enumerable.ToList <ShopBranch>(Enumerable.Where <ShopBranch>((IEnumerable <ShopBranch>)shopBranchsAll.Models, (Func <ShopBranch, bool>)(p => !fillterIds.Contains(p.Id) && p.Enabled && p.AddressPath.Contains("," + (object)streetId + ",")))); if (list3 != null && Enumerable.Count <ShopBranch>((IEnumerable <ShopBranch>)list3) > 0) { fillterIds.AddRange(Enumerable.Select <ShopBranch, long>((IEnumerable <ShopBranch>)list3, (Func <ShopBranch, long>)(p => p.Id))); list1.AddRange((IEnumerable <ShopBranch>)list3); } List <ShopBranch> list4 = Enumerable.ToList <ShopBranch>(Enumerable.Where <ShopBranch>((IEnumerable <ShopBranch>)shopBranchsAll.Models, (Func <ShopBranch, bool>)(p => !fillterIds.Contains(p.Id) && p.Enabled && p.AddressPath.Contains("," + (object)districtId + ",")))); if (list4 != null && Enumerable.Count <ShopBranch>((IEnumerable <ShopBranch>)list4) > 0) { fillterIds.AddRange(Enumerable.Select <ShopBranch, long>((IEnumerable <ShopBranch>)list4, (Func <ShopBranch, long>)(p => p.Id))); list1.AddRange((IEnumerable <ShopBranch>)list4); } List <ShopBranch> list5 = Enumerable.ToList <ShopBranch>(Enumerable.Where <ShopBranch>((IEnumerable <ShopBranch>)shopBranchsAll.Models, (Func <ShopBranch, bool>)(p => !fillterIds.Contains(p.Id) && p.Enabled))); if (list5 != null && Enumerable.Count <ShopBranch>((IEnumerable <ShopBranch>)list5) > 0) { fillterIds.AddRange(Enumerable.Select <ShopBranch, long>((IEnumerable <ShopBranch>)list5, (Func <ShopBranch, long>)(p => p.Id))); list1.AddRange((IEnumerable <ShopBranch>)list5); } List <ShopBranch> list6 = Enumerable.ToList <ShopBranch>(Enumerable.Where <ShopBranch>((IEnumerable <ShopBranch>)shopBranchsAll.Models, (Func <ShopBranch, bool>)(p => !fillterIds.Contains(p.Id)))); if (list6 != null && Enumerable.Count <ShopBranch>((IEnumerable <ShopBranch>)list6) > 0) { list1.AddRange((IEnumerable <ShopBranch>)list6); } if (Enumerable.Count <ShopBranch>((IEnumerable <ShopBranch>)list1) != Enumerable.Count <ShopBranch>((IEnumerable <ShopBranch>)shopBranchsAll.Models)) { return((object)this.Json(new { Success = false })); } var content = new { Success = true, StoreList = Enumerable.Select((IEnumerable <ShopBranch>)list1, sb => { var fAnonymousType37 = new { ContactUser = sb.ContactUser, ContactPhone = sb.ContactPhone, AddressDetail = sb.AddressDetail, ShopBranchName = sb.ShopBranchName, Id = sb.Id, Enabled = sb.Enabled }; return(fAnonymousType37); }) }; return((object)this.Json(content)); }
///// <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内发货") : ""), //运费模板发货时间 })); }