public ReturnMSG SaveProduct(Entities.ProductInfo prod) { Log.Current.WriteLog("Begin"); ReturnMSG response = UtilEx.TryCatch <ReturnMSG>(() => { return(BangGoServerProxy.SaveProduct(prod)); }); return(response); }
/// <summary> /// 商品列表信息项转换 /// </summary> /// <param name="data"></param> /// <returns></returns> private product_list_model ProductInfoListMapChange(Entities.ProductInfo data) { product_list_model dresult = null; var prodata = data; dresult = new product_list_model(); if (prodata == null) { throw new MallApiException(OpenApiErrorCode.Product_Not_Exists, "num_iid"); } #region 装配信息 dresult.num_iid = (int)prodata.Id; dresult.outer_id = prodata.ProductCode; dresult.brand_id = (int)prodata.BrandId; dresult.brand_name = prodata.BrandName; dresult.cid = (int)prodata.CategoryId; dresult.type_id = (int)prodata.TypeId; var category = CategoryApplication.GetCategory(prodata.CategoryId); if (category != null) { dresult.cat_name = category.Name; var type = TypeApplication.GetType(category.TypeId); if (type != null) { dresult.type_name = type.Name; } } dresult.price = prodata.MinSalePrice; var skus = ProductManagerApplication.GetSKUs(prodata.Id); if (skus.Count > 0) { dresult.num = (int)skus.Sum(d => d.Stock); } else { dresult.num = 0; dresult.num = prodata.Quantity; } dresult.title = prodata.ProductName.Trim(); dresult.list_time = prodata.AddedDate; dresult.modified = prodata.AddedDate; dresult.sold_quantity = (int)prodata.SaleCounts; dresult.pic_url = new System.Collections.ArrayList(); dresult.pic_url.Add(System.IO.Path.Combine(OpenAPIHelper.HostUrl, prodata.GetImage(ImageSize.Size_350, 1))); ProductStatus ps = GetProductStatus(prodata); dresult.approve_status = ps.ToString(); #endregion return(dresult); }
/// <summary> /// 获取商品状态 /// </summary> /// <param name="data"></param> /// <returns></returns> private ProductStatus GetProductStatus(Entities.ProductInfo data) { ProductStatus result = ProductStatus.Un_Sale; if (data.AuditStatus == Entities.ProductInfo.ProductAuditStatus.Audited && data.SaleStatus == Entities.ProductInfo.ProductSaleStatus.OnSale) { result = ProductStatus.On_Sale; } if (data.SaleStatus == Entities.ProductInfo.ProductSaleStatus.InStock) { result = ProductStatus.In_Stock; } return(result); }
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 }); }
// GET: Admin/TemplateVisualizationProcess public ActionResult GoodsListAction() { var data = this.ControllerContext.RouteData.Values; var layout = data["Layout"]; string ids = ""; bool showIco = false, showPrice = false, showName = false; bool showWarp = true; string warpId = ""; if (layout != null) { ids = data["IDs"].ToString(); showIco = bool.Parse(data["ShowIco"].ToString()); showPrice = bool.Parse(data["showPrice"].ToString()); showName = data["showName"].ToString() == "1"; warpId = data["ID"].ToString(); showWarp = true; } else { layout = Request["Layout"]; ids = Request["IDs"]; showIco = bool.Parse(Request["ShowIco"]); showPrice = bool.Parse(Request["showPrice"]); showName = Request["showName"] == "1"; if (!string.IsNullOrWhiteSpace(Request["showWarp"])) { showWarp = bool.Parse(Request["showWarp"]); } } var name = "~/Views/Shared/GoodGroup" + layout + ".cshtml"; ProductAjaxModel model = new ProductAjaxModel() { list = new List <ProductContent>() }; model.showIco = showIco; model.showPrice = showPrice; model.showName = showName; model.showWarp = showWarp; model.warpId = warpId; var productSaleCountOnOff = SiteSettingApplication.SiteSettings.ProductSaleCountOnOff == 1; List <long> idArray = new List <long>(); idArray = ids.Split(',').Where(d => !string.IsNullOrWhiteSpace(d)).Select(d => long.Parse(d)).ToList(); if (idArray != null && idArray.Count > 0) { var products = ProductManagerApplication.GetProductByIds(idArray); model.list = new List <ProductContent>(); var selfshop = _iShopService.GetSelfShop(); decimal discount = 1m; if (CurrentUser != null) { discount = CurrentUser.MemberDiscount; } foreach (var id in idArray) { Entities.ProductInfo d = products.FirstOrDefault(p => p.Id == id); if (null == d) { continue; } decimal minprice = d.MinSalePrice; if (selfshop != null && d.ShopId == selfshop.Id) { minprice = d.MinSalePrice * discount; } var _tmp = new ProductContent { product_id = d.Id, link = "/m-wap/Product/Detail/" + d.Id.ToString(), price = minprice.ToString("f2"), original_price = d.MarketPrice.ToString("f2"), pic = Core.HimallIO.GetProductSizeImage(d.RelativePath, 1, (int)ImageSize.Size_350), title = d.ProductName, is_limitbuy = _iProductService.IsLimitBuy(d.Id), SaleCounts = d.SaleCounts + (int)d.VirtualSaleCounts, ProductSaleCountOnOff = productSaleCountOnOff, productType = d.ProductType }; model.list.Add(_tmp); } } return(PartialView(name, model)); }
/// <summary> /// 商品信息转换 /// </summary> /// <param name="data"></param> /// <returns></returns> private product_item_model ProductInfoMapChange(Entities.ProductInfo data) { var prodata = data; if (prodata == null) { throw new MallApiException(OpenApiErrorCode.Product_Not_Exists, "num_iid"); } product_item_model result = new product_item_model(); #region 装配信息 result.num_iid = (int)prodata.Id; result.outer_id = prodata.ProductCode; result.brand_id = (int)prodata.BrandId; result.brand_name = prodata.BrandName; result.cid = (int)prodata.CategoryId; result.type_id = (int)prodata.TypeId; var category = CategoryApplication.GetCategory(prodata.CategoryId); var desc = ProductManagerApplication.GetProductDescription(prodata.Id); if (category != null) { result.cat_name = category.Name; var type = TypeApplication.GetType(category.TypeId); if (type != null) { result.type_name = type.Name; } } result.title = prodata.ProductName.Trim(); result.list_time = prodata.AddedDate; result.modified = prodata.AddedDate; result.display_sequence = (int)prodata.DisplaySequence; result.sold_quantity = (int)prodata.SaleCounts; result.desc = desc.Description; result.wap_desc = desc.MobileDescription; result.pic_url.Add(System.IO.Path.Combine(OpenAPIHelper.HostUrl, prodata.GetImage(ImageSize.Size_350, 1))); ProductStatus ps = GetProductStatus(prodata); result.approve_status = ps.ToString(); #region 商品属性填充 var prodAttrs = ProductManagerApplication.GetProductAttributes(prodata.Id); var prodAttrids = prodAttrs.Select(d => d.AttributeId).ToList(); var prodAttrValues = _iTypeService.GetAttributeValues(prodAttrids); result.props_name = ""; if (prodAttrids.Count > 0) { List <string> propslst = new List <string>(); List <string> propsvallst = new List <string>(); foreach (var curattid in prodAttrids) { var item = prodAttrs.FirstOrDefault(d => d.AttributeId == curattid); propsvallst.Clear(); var attribute = _iTypeService.GetAttribute(item.AttributeId); var values = prodAttrValues.Where(p => p.AttributeId == curattid); foreach (var attrV in values) { if (prodAttrs.Any(p => p.ValueId == attrV.Id)) { propsvallst.Add(attrV.Value); } } propslst.Add(attribute.Name + "#cln#[" + string.Join(",", propsvallst.ToArray()) + "]"); } result.props_name = string.Join("#scln#", propslst.ToArray()); } #endregion #region 发货地区 var prolocid = FreightTemplateApplication.GetFreightTemplate(prodata.FreightTemplateId).SourceAddress; result.location = ""; var locpath = _iRegionService.GetFullName(prolocid, ","); result.location = "{'city':'#c#', 'state':'#p#'}"; if (!string.IsNullOrWhiteSpace(locpath)) { var _tmparr = locpath.Split(','); result.location = result.location.Replace("#p#", _tmparr[0]); if (_tmparr.Length > 1) { result.location = result.location.Replace("#c#", _tmparr[1]); } else { result.location = result.location.Replace("#c#", ""); } } #endregion #region SKUS Entities.TypeInfo typeInfo = _iTypeService.GetType(data.TypeId); string colorAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias; string sizeAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias; string versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias; if (prodata != null) { colorAlias = !string.IsNullOrWhiteSpace(prodata.ColorAlias) ? prodata.ColorAlias : colorAlias; sizeAlias = !string.IsNullOrWhiteSpace(prodata.SizeAlias) ? prodata.SizeAlias : sizeAlias; versionAlias = !string.IsNullOrWhiteSpace(prodata.VersionAlias) ? prodata.VersionAlias : versionAlias; } result.skus = new List <product_sku_model>(); var skus = ProductManagerApplication.GetSKUs(prodata.Id); foreach (var item in skus) { product_sku_model skudata = new product_sku_model(); skudata.sku_id = item.Id; skudata.outer_sku_id = item.Sku; skudata.price = item.SalePrice; skudata.quantity = (int)item.Stock; //skudata.sku_properties_name = "颜色:" + item.Color + "尺寸:" + item.Size + "版本:" + item.Version; skudata.sku_properties_name = colorAlias + ":" + item.Color + " " + sizeAlias + ":" + item.Size + " " + versionAlias + ":" + item.Version; string sku_properties_name = item.Color + " " + item.Size + " " + item.Version; if (string.IsNullOrWhiteSpace(sku_properties_name)) { skudata.sku_properties_name = ""; } if (!string.IsNullOrWhiteSpace(skudata.sku_properties_name)) { result.skus.Add(skudata); } } #endregion #endregion return(result); }