public JsonResult SaveTemplate(string templateinfo)
        {
            FreightTemplateInfo freightTemplateInfo = JsonConvert.DeserializeObject <FreightTemplateInfo>(templateinfo);

            ServiceHelper.Create <IFreightTemplateService>().UpdateFreightTemplate(freightTemplateInfo);
            return(Json(new { successful = true }));
        }
예제 #2
0
        public FreightTemplateInfo SearchByid(string id)
        {
            FreightTemplateInfo info       = new FreightTemplateInfo();
            MySqlParameter      idparamter = new MySqlParameter("id", MySqlDbType.Int64);

            idparamter.Value = id;
            DataTable dt = Luolu.Common.MySqlHelper.Search("SELECT * FROM himall_freighttemplate WHERE Id=@id", new MySqlParameter[] { idparamter });

            if (dt.Rows.Count == 1)
            {
                info.Id              = long.Parse(dt.Rows[0]["Id"].ToString());
                info.Name            = dt.Rows[0]["Name"].ToString();
                info.SourceAddress   = int.Parse(dt.Rows[0]["SourceAddress"].ToString());
                info.SendTime        = dt.Rows[0]["SendTime"].ToString();
                info.IsFree          = int.Parse(dt.Rows[0]["IsFree"].ToString());
                info.ValuationMethod = int.Parse(dt.Rows[0]["ValuationMethod"].ToString());
                if (string.IsNullOrEmpty(dt.Rows[0]["ShippingMethod"].ToString()))
                {
                    info.ShippingMethod = null;
                }
                else
                {
                    info.ShippingMethod = int.Parse(dt.Rows[0]["ShippingMethod"].ToString());
                }
                info.ShopID      = long.Parse(dt.Rows[0]["ShopID"].ToString());
                info.Description = dt.Rows[0]["Description"].ToString();
            }
            return(info);
        }
예제 #3
0
        //计算物流费用
        private decimal GetFreight(int freightTemplateId, List <OrderItemInfo> orderItemList, int cityId)
        {
            IFreightTemplateService freightTemplateService = ServiceHelper.Create <IFreightTemplateService>();
            decimal freight2 = 0;

            foreach (var orderItem in orderItemList)
            {
                FreightTemplateInfo freightTemplate = freightTemplateService.GetFreightTemplate(freightTemplateId);
                if (freightTemplate == null || freightTemplate.IsFree != FreightTemplateInfo.FreightTemplateType.SelfDefine)
                {
                    continue;
                }
                FreightAreaContentInfo freightAreaContentInfo = (
                    from item in freightTemplate.ChemCloud_FreightAreaContent
                    where item.AreaContent.Split(new char[] { ',' }).Contains <string>(cityId.ToString())
                    select item).FirstOrDefault() ?? freightTemplate.ChemCloud_FreightAreaContent.Where((FreightAreaContentInfo item) =>
                {
                    byte?isDefault = item.IsDefault;
                    if (isDefault.GetValueOrDefault() != 1)
                    {
                        return(false);
                    }
                    return(isDefault.HasValue);
                }).FirstOrDefault();
                if (freightTemplate.ValuationMethod == FreightTemplateInfo.ValuationMethodType.Weight)
                {
                    int     value  = freightAreaContentInfo.FirstUnit.Value;
                    decimal value1 = (decimal)freightAreaContentInfo.FirstUnitMonry.Value;
                    int     value2 = freightAreaContentInfo.AccumulationUnit.Value;
                    float?  accumulationUnitMoney = freightAreaContentInfo.AccumulationUnitMoney;
                    freight2 = freight2 + GetFreight2(orderItem.Quantity, value, value1, value2, (decimal)accumulationUnitMoney.Value);
                }
                else if (freightTemplate.ValuationMethod != FreightTemplateInfo.ValuationMethodType.Bulk)
                {
                    int     num4     = Convert.ToInt32(orderItem.Quantity);
                    decimal num5     = num4;
                    int     value3   = freightAreaContentInfo.FirstUnit.Value;
                    decimal value4   = (decimal)freightAreaContentInfo.FirstUnitMonry.Value;
                    int     value5   = freightAreaContentInfo.AccumulationUnit.Value;
                    float?  nullable = freightAreaContentInfo.AccumulationUnitMoney;
                    freight2 = freight2 + GetFreight2(num5, value3, value4, value5, (decimal)nullable.Value);
                }
                else
                {
                    decimal num6   = Convert.ToInt32(orderItem.Quantity);
                    int     value6 = freightAreaContentInfo.FirstUnit.Value;
                    decimal value7 = (decimal)freightAreaContentInfo.FirstUnitMonry.Value;
                    int     num7   = freightAreaContentInfo.AccumulationUnit.Value;
                    float?  accumulationUnitMoney1 = freightAreaContentInfo.AccumulationUnitMoney;
                    freight2 = freight2 + GetFreight2(num6, value6, value7, num7, (decimal)accumulationUnitMoney1.Value);
                }
            }

            return(freight2);
        }
예제 #4
0
        public ActionResult Index1()
        {
            IFreightTemplate freBll = Instance <IFreightTemplate, FreightTemplateService> .Create;
            //IFreightTemplate freBll = new FreightTemplateService();
            FreightTemplateInfo fre = freBll.SearchByid("13676");

            //IProductInfo proBll = new ProductInfoService();
            //List<ProductInfo> list = proBll.SearchBypage(1, 20);
            //int num = proBll.Searchcount();
            return(View(fre));
        }
        public ActionResult Edit(long?id)
        {
            long num = (id.HasValue ? id.Value : 0);
            FreightTemplateInfoExtend freightTemplateInfoExtend = new FreightTemplateInfoExtend()
            {
                ShopID = base.CurrentSellerManager.ShopId
            };

            ViewBag.IsUsed = 0;
            if (id.HasValue)
            {
                FreightTemplateInfo freightTemplate = ServiceHelper.Create <IFreightTemplateService>().GetFreightTemplate(num);
                if (freightTemplate.ShopID != base.CurrentSellerManager.ShopId)
                {
                    throw new HimallException(string.Concat("该运费模板不存在", id));
                }
                IRegionService regionService = ServiceHelper.Create <IRegionService>();
                if (freightTemplate.SourceAddress.HasValue)
                {
                    IRegionService regionService1 = regionService;
                    int?           sourceAddress  = freightTemplate.SourceAddress;
                    freightTemplateInfoExtend.SourceAddressStr = regionService1.GetRegionIdPath(sourceAddress.Value);
                }
                freightTemplateInfoExtend.Id                 = freightTemplate.Id;
                freightTemplateInfoExtend.IsFree             = freightTemplate.IsFree;
                freightTemplateInfoExtend.Name               = freightTemplate.Name;
                freightTemplateInfoExtend.ShopID             = freightTemplate.ShopID;
                freightTemplateInfoExtend.SendTime           = freightTemplate.SendTime;
                freightTemplateInfoExtend.SourceAddress      = freightTemplate.SourceAddress;
                freightTemplateInfoExtend.ValuationMethod    = freightTemplate.ValuationMethod;
                freightTemplateInfoExtend.FreightAreaContent =
                    from e in freightTemplate.ChemCloud_FreightAreaContent
                    select new FreightAreaContentInfoExtend()
                {
                    AreaContent           = e.AreaContent,
                    AreaContentCN         = regionService.GetRegionName(e.AreaContent, ","),
                    AccumulationUnit      = e.AccumulationUnit,
                    AccumulationUnitMoney = e.AccumulationUnitMoney,
                    FirstUnit             = e.FirstUnit,
                    FirstUnitMonry        = e.FirstUnitMonry,
                    IsDefault             = e.IsDefault,
                    FreightTemplateId     = e.FreightTemplateId,
                    Id = e.Id
                };
                if (ServiceHelper.Create <IFreightTemplateService>().GetProductUseFreightTemp(num).Count() > 0)
                {
                    ViewBag.IsUsed = 1;
                }
            }
            return(View(freightTemplateInfoExtend));
        }
예제 #6
0
        public void UpdateFreightTemplate(FreightTemplateInfo templateInfo)
        {
            FreightTemplateInfo name;

            if (templateInfo.Id == 0)
            {
                name = context.FreightTemplateInfo.Add(templateInfo);
                context.SaveChanges();
                return;
            }
            name = (
                from e in context.FreightTemplateInfo
                where e.Id == templateInfo.Id
                select e).FirstOrDefault();
            name.Name            = templateInfo.Name;
            name.IsFree          = templateInfo.IsFree;
            name.ValuationMethod = templateInfo.ValuationMethod;
            name.ShopID          = templateInfo.ShopID;
            name.SourceAddress   = templateInfo.SourceAddress;
            name.SendTime        = templateInfo.SendTime;
            using (TransactionScope transactionScope = new TransactionScope())
            {
                context.FreightAreaContentInfo.RemoveRange(
                    from e in context.FreightAreaContentInfo
                    where e.FreightTemplateId == name.Id
                    select e);
                context.SaveChanges();
                if (name.IsFree == FreightTemplateInfo.FreightTemplateType.SelfDefine)
                {
                    templateInfo.ChemCloud_FreightAreaContent.ToList().ForEach((FreightAreaContentInfo e) =>
                    {
                        FreightAreaContentInfo freightAreaContentInfo = new FreightAreaContentInfo()
                        {
                            AreaContent           = e.AreaContent,
                            FirstUnit             = e.FirstUnit,
                            FirstUnitMonry        = e.FirstUnitMonry,
                            AccumulationUnit      = e.AccumulationUnit,
                            AccumulationUnitMoney = e.AccumulationUnitMoney,
                            IsDefault             = e.IsDefault,
                            FreightTemplateId     = name.Id
                        };
                        context.FreightAreaContentInfo.Add(freightAreaContentInfo);
                    });
                }
                context.SaveChanges();
                transactionScope.Complete();
            }
        }
예제 #7
0
        /// <summary>
        /// 批量创建索引
        /// </summary>
        /// <param name="pagecount"></param>
        private void CreateIndex(int pagecount, List <ProductInfo> templist)
        {
            List <Index> result = new List <Index>();

            for (int i = 0; i < templist.Count(); i++)
            {
                Index temp = new Index();
                temp.Id         = templist[i].Id;
                temp.ImagePath  = templist[i].RelativePath;
                temp.Price      = templist[i].MinSalePrice;
                temp.AddDate    = templist[i].AddedDate;
                temp.BrandId    = templist[i].BrandId;
                temp.CategoryId = templist[i].CategoryId;
                long productid = templist[i].Id;
                temp.Comments    = db.ProductCommentInfo.Where(t => t.ProductId == productid).Count();
                temp.ProductName = templist[i].ProductName;
                temp.SaleCount   = templist[i].SaleCounts;
                temp.ShopId      = templist[i].ShopId;
                temp.TypeId      = templist[i].TypeId;
                long     sid  = templist[i].ShopId;
                ShopInfo shop = db.ShopInfo.Where(e => e.Id == sid).FirstOrDefault();
                if (shop != null)
                {
                    temp.ShopName = shop.ShopName;
                }
                temp.ShopName     = templist[i].Himall_Shops.ShopName;
                temp.CategoryPath = templist[i].CategoryPath;
                temp.EndDate      = templist[i].Himall_Shops.EndDate.Value;
                long fid = templist[i].FreightTemplateId;
                FreightTemplateInfo ftl = db.FreightTemplateInfo.Where(e => e.Id == fid).FirstOrDefault();
                if (ftl != null && ftl.SourceAddress != null)
                {
                    long regionId = ftl.SourceAddress.Value;
                    temp.Address = GetRegionShortName(regionId);
                }
                var attrs = templist[i].ProductAttributeInfo.Where(t => t.ProductId == templist[i].Id).ToList();
                foreach (var t in attrs)
                {
                    temp.AttrValueIds.Add(t.AttributeId + "_" + t.ValueId);
                }
                result.Add(temp);
            }
            search.CreateIndex(result);
        }
예제 #8
0
        /// <summary>
        /// 用户当前商品运费显示文本
        /// </summary>
        /// <param name="productId">商品Id</param>
        /// <param name="freightTemplate">运费末班</param>
        /// <param name="member">访问的用户</param>
        /// <param name="product">商品实体</param>
        /// <param name="buynumber">购买件数</param>
        /// <returns></returns>
        public static string GetFreightStr(long productId, FreightTemplateInfo freightTemplate, MemberInfo member = null, ProductInfo product = null, int buynumber = 1)
        {
            string freightStr = "免运费";

            if (freightTemplate == null || freightTemplate.IsFree == CommonModel.FreightTemplateType.Free)
            {
                return(freightStr);
            }

            IProductService productService = ServiceApplication.Create <IProductService>();

            #region 是否虚拟商品,如是虚拟商品免运费
            if (product == null)
            {
                product = productService.GetProduct(productId);
                if (product == null || product.ProductType == 1)//虚拟商品无运费
                {
                    return(freightStr);
                }
            }
            #endregion

            int addressId = 0;
            if (member != null)
            {
                var addressInfo = ShippingAddressApplication.GetDefaultUserShippingAddressByUserId(member.Id);
                if (addressInfo != null)
                {
                    addressId = addressInfo.RegionId;
                }
            }

            #region 当前是否是指定地区包邮
            if (addressId > 0)
            {
                bool    isFree = false; //当前地区是否为自定包邮
                decimal price  = 0;     //购买商品的金额

                var freeRegions = Service.GetShippingFreeRegions(freightTemplate.Id);
                if (freeRegions != null && freeRegions.Count() > 0)
                {
                    IRegionService regionService = ServiceProvider.Instance <IRegionService> .Create;
                    freeRegions.ForEach(p =>
                    {
                        p.RegionSubList = regionService.GetSubsNew(p.RegionId, true).Select(a => a.Id).ToList();
                    });
                    var regions = freeRegions.Where(p => p.RegionSubList.Contains(addressId));//根据模板设置的包邮地区过滤出当前配送地址所在地址
                    if (regions != null && regions.Count() > 0)
                    {
                        var groupIds   = regions.Select(p => p.GroupId).ToList();
                        var freeGroups = Service.GetShippingFreeGroupInfos(freightTemplate.Id, groupIds);

                        //只要有一个符合包邮,则退出
                        decimal amount = price * buynumber;
                        freeGroups.ForEach(p =>
                        {
                            if (p.ConditionType == 1)//购买件数
                            {
                                if (buynumber >= int.Parse(p.ConditionNumber))
                                {
                                    isFree = true;
                                    return;
                                }
                            }
                            else if (p.ConditionType == 2)//金额
                            {
                                if (amount >= decimal.Parse(p.ConditionNumber))
                                {
                                    isFree = true;
                                    return;
                                }
                            }
                            else if (p.ConditionType == 3)//件数+金额
                            {
                                var condition1 = int.Parse(p.ConditionNumber.Split('$')[0]);
                                var condition2 = decimal.Parse(p.ConditionNumber.Split('$')[1]);
                                if (buynumber >= condition1 && amount >= condition2)
                                {
                                    isFree = true;
                                    return;
                                }
                            }
                        });
                    }
                }

                if (isFree)
                {
                    return(freightStr);//直接返回免运费
                }
            }
            #endregion

            decimal freight = productService.GetFreight(new List <long>()
            {
                productId
            }, new List <int>()
            {
                1
            }, addressId, true);
            freightStr = freight <= 0 ? "免运费" : string.Format("运费 {0}元", freight.ToString("f2"));

            return(freightStr);
        }
        public JsonResult GetFreightTemplateInfo(long templateid)
        {
            FreightTemplateInfo freightTemplate = ServiceHelper.Create <IFreightTemplateService>().GetFreightTemplate(templateid);

            return(Json(new { model = freightTemplate, success = true }));
        }
예제 #10
0
        //public void CopyTemplate(long templateId)
        //{
        //    var model = Context.FreightTemplateInfo.Where(e => e.Id == templateId).FirstOrDefault();
        //    FreightTemplateInfo templateInfo = new FreightTemplateInfo();
        //    templateInfo.IsFree = model.IsFree;
        //    templateInfo.Name = model.Name + "复制";
        //    templateInfo.SendTime = model.SendTime;
        //    templateInfo.ShippingMethod = model.ShippingMethod;
        //    templateInfo.ShopID = model.ShopID;
        //    templateInfo.ValuationMethod = model.ValuationMethod;
        //    templateInfo.SourceAddress = model.SourceAddress;
        //    templateInfo.Himall_FreightAreaContent = model.Himall_FreightAreaContent;
        //    Context.FreightTemplateInfo.Add(templateInfo);
        //    Context.SaveChanges();
        //    var oldArea = Context.FreightAreaDetailInfo.Where(a => a.FreightTemplateId == templateId).ToList();

        //    List<FreightAreaDetailInfo> infos = new List<FreightAreaDetailInfo>();
        //    var newAreas = templateInfo.Himall_FreightAreaContent.ToList();
        //    for (int i= 0;i < newAreas.Count; i++)
        //    {
        //        FreightAreaDetailInfo info = new FreightAreaDetailInfo();
        //        info.FreightAreaId = newAreas[i].Id;
        //        info.FreightTemplateId = newAreas[i].FreightTemplateId;
        //        info.CityId
        //    }
        //}



        public void UpdateFreightTemplate(FreightTemplateInfo templateInfo)
        {
            FreightTemplateInfo model;

            if (templateInfo.Id == 0)
            {
                model = Context.FreightTemplateInfo.Add(templateInfo);
                Context.SaveChanges();
                foreach (var t in templateInfo.Himall_FreightAreaContent)
                {
                    foreach (var d in t.FreightAreaDetailInfo)
                    {
                        d.FreightAreaId     = t.Id;
                        d.FreightTemplateId = t.FreightTemplateId;
                        Context.FreightAreaDetailInfo.Add(d);
                    }
                }
                Context.SaveChanges();
            }
            else
            {
                model                 = Context.FreightTemplateInfo.Where(e => e.Id == templateInfo.Id).FirstOrDefault();
                model.Name            = templateInfo.Name;
                model.IsFree          = templateInfo.IsFree;
                model.ValuationMethod = templateInfo.ValuationMethod;
                model.ShopID          = templateInfo.ShopID;
                model.SourceAddress   = templateInfo.SourceAddress;
                model.SendTime        = templateInfo.SendTime;
                using (TransactionScope scope = new TransactionScope())
                {
                    //先删除
                    Context.FreightAreaContentInfo.RemoveRange(Context.FreightAreaContentInfo.Where(e => e.FreightTemplateId == model.Id).ToList());
                    //删除详情表
                    Context.FreightAreaDetailInfo.RemoveRange(Context.FreightAreaDetailInfo.Where(a => a.FreightTemplateId == model.Id).ToList());
                    Context.SaveChanges();//保存主表

                    if (model.IsFree == FreightTemplateType.SelfDefine)
                    {
                        //重新插入地区运费
                        //model = context.FreightTemplateInfo.Where(e => e.Id == templateInfo.Id).FirstOrDefault();

                        //  List<FreightAreaContentInfo> fre = new List<FreightAreaContentInfo>();

                        templateInfo.Himall_FreightAreaContent.ToList().ForEach(e =>
                        {
                            //var freightContent = new FreightAreaContentInfo();
                            //freightContent.AreaContent = e.AreaContent;
                            //freightContent.FirstUnit = e.FirstUnit;
                            //freightContent.FirstUnitMonry = e.FirstUnitMonry;
                            //freightContent.AccumulationUnit = e.AccumulationUnit;
                            //freightContent.AccumulationUnitMoney = e.AccumulationUnitMoney;
                            //freightContent.IsDefault = e.IsDefault;
                            //freightContent.FreightTemplateId = model.Id;
                            e.FreightTemplateId = model.Id;
                            // fre.Add(freightContent);
                        });
                        Context.FreightAreaContentInfo.AddRange(templateInfo.Himall_FreightAreaContent.ToList());
                        Context.SaveChanges();
                        //  var index = 0;
                        foreach (var t in templateInfo.Himall_FreightAreaContent)
                        {
                            foreach (var d in t.FreightAreaDetailInfo)
                            {
                                d.FreightAreaId     = t.Id;
                                d.FreightTemplateId = model.Id;
                                Context.FreightAreaDetailInfo.Add(d);
                            }
                        }
                        Context.SaveChanges();
                    }
                    scope.Complete();
                }
                Cache.Remove(CacheKeyCollection.CACHE_FREIGHTTEMPLATE(templateInfo.Id));
                Cache.Remove(CacheKeyCollection.CACHE_FREIGHTAREADETAIL(templateInfo.Id));
            }
        }
예제 #11
0
        public void UpdateFreightTemplate(FreightTemplateInfo templateInfo)
        {
            FreightTemplateInfo model;

            if (templateInfo.Id == 0)
            {
                DbFactory.Default.InTransaction(() =>
                {
                    var ret1 = DbFactory.Default.Add(templateInfo);

                    foreach (var t in templateInfo.FreightAreaContentInfo)
                    {
                        t.FreightTemplateId = templateInfo.Id;
                    }

                    if (templateInfo.FreightAreaContentInfo.Count() > 0)
                    {
                        var ret2 = DbFactory.Default.Add <FreightAreaContentInfo>(templateInfo.FreightAreaContentInfo);
                    }

                    var areaDetailList = new List <FreightAreaDetailInfo>();
                    foreach (var t in templateInfo.FreightAreaContentInfo)
                    {
                        foreach (var d in t.FreightAreaDetailInfo)
                        {
                            d.FreightAreaId     = t.Id;
                            d.FreightTemplateId = t.FreightTemplateId;
                            areaDetailList.Add(d);
                        }
                    }

                    if (areaDetailList.Count > 0)
                    {
                        var ret3 = DbFactory.Default.Add <FreightAreaDetailInfo>(areaDetailList);
                    }

                    #region 指定地区包邮
                    if (templateInfo.ShippingFreeGroupInfo != null)
                    {
                        foreach (var t in templateInfo.ShippingFreeGroupInfo)
                        {
                            t.TemplateId = templateInfo.Id;//模板ID

                            DbFactory.Default.Add(t);
                            if (t.Id > 0)
                            {
                                foreach (var item in t.ShippingFreeRegionInfo)
                                {
                                    item.GroupId    = t.Id;            //组ID
                                    item.TemplateId = templateInfo.Id; //模板ID
                                    DbFactory.Default.Add(item);
                                }
                            }
                        }
                    }
                });
                #endregion
            }
            else
            {
                model                 = DbFactory.Default.Get <FreightTemplateInfo>().Where(e => e.Id == templateInfo.Id).FirstOrDefault();
                model.Name            = templateInfo.Name;
                model.IsFree          = templateInfo.IsFree;
                model.ValuationMethod = templateInfo.ValuationMethod;
                model.ShopID          = templateInfo.ShopID;
                model.SourceAddress   = templateInfo.SourceAddress;
                model.SendTime        = templateInfo.SendTime;


                var flag = DbFactory.Default.InTransaction(() =>
                {
                    DbFactory.Default.Update(model);
                    //先删除
                    DbFactory.Default.Del <FreightAreaContentInfo>(e => e.FreightTemplateId == model.Id);
                    //删除详情表
                    DbFactory.Default.Del <FreightAreaDetailInfo>(e => e.FreightTemplateId == model.Id);

                    if (model.IsFree == FreightTemplateType.SelfDefine)
                    {
                        //重新插入地区运费
                        templateInfo.FreightAreaContentInfo.ForEach(e =>
                        {
                            e.FreightTemplateId = model.Id;
                        });

                        if (templateInfo.FreightAreaContentInfo.Count > 0)
                        {
                            DbFactory.Default.Add <FreightAreaContentInfo>(templateInfo.FreightAreaContentInfo);
                        }

                        var detailList = new List <FreightAreaDetailInfo>();
                        foreach (var t in templateInfo.FreightAreaContentInfo)
                        {
                            foreach (var d in t.FreightAreaDetailInfo)
                            {
                                d.FreightAreaId     = t.Id;
                                d.FreightTemplateId = model.Id;
                                detailList.Add(d);
                            }
                        }
                        if (detailList.Count > 0)
                        {
                            DbFactory.Default.Add <FreightAreaDetailInfo>(detailList);
                        }
                    }

                    #region 指定地区包邮
                    DbFactory.Default.Del <ShippingFreeGroupInfo>(e => e.TemplateId == model.Id);
                    DbFactory.Default.Del <ShippingFreeRegionInfo>(e => e.TemplateId == model.Id);

                    if (templateInfo.ShippingFreeGroupInfo != null)
                    {
                        foreach (var t in templateInfo.ShippingFreeGroupInfo)
                        {
                            t.TemplateId = model.Id;//模板ID
                            DbFactory.Default.Add(t);
                            if (t.Id > 0)
                            {
                                foreach (var item in t.ShippingFreeRegionInfo)
                                {
                                    item.GroupId    = t.Id;     //组ID
                                    item.TemplateId = model.Id; //模板ID

                                    DbFactory.Default.Add(item);
                                }
                            }
                        }
                    }
                    #endregion
                    return(true);
                });
                Cache.Remove(CacheKeyCollection.CACHE_FREIGHTTEMPLATE(templateInfo.Id));
                Cache.Remove(CacheKeyCollection.CACHE_FREIGHTAREADETAIL(templateInfo.Id));
            }
        }
예제 #12
0
        public object GetProductDetail(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;

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

            var cashDepositModel = ServiceProvider.Instance <ICashDepositsService> .Create.GetCashDepositsObligation(product.Id);//提供服务(消费者保障、七天无理由、及时发货)

            model.CashDepositsServer = cashDepositModel;
            #region 根据运费模板获取发货地址
            var freightTemplateService   = ServiceHelper.Create <IFreightTemplateService>();
            FreightTemplateInfo template = freightTemplateService.GetFreightTemplate(product.FreightTemplateId);
            string productAddress        = string.Empty;
            if (template != null && template.SourceAddress.HasValue)
            {
                var fullName = ServiceHelper.Create <IRegionService>().GetFullName(template.SourceAddress.Value);
                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 店铺Logo
            long vShopId;
            shop = ServiceProvider.Instance <IShopService> .Create.GetShop(product.ShopId);

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

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

            #endregion

            model.Shop.FavoriteShopCount = ServiceProvider.Instance <IShopService> .Create.GetShopFavoritesCount(product.ShopId);//关注人数

            var com = product.Himall_ProductComments.Where(item => !item.IsHidden.HasValue || item.IsHidden.Value == false);

            var limitBuy = ServiceProvider.Instance <ILimitTimeBuyService> .Create.GetLimitTimeMarketItemByProductId(id);

            #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 (limitBuy != null)
            {
                var limitSku = ServiceProvider.Instance <ILimitTimeBuyService> .Create.Get(limitBuy.Id);

                var limitSkuItem = limitSku.Details.OrderBy(d => d.Price).FirstOrDefault();
                if (limitSkuItem != null)
                {
                    product.MinSalePrice = limitSkuItem.Price;
                }
            }
            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,
                                    Img           = Himall.Core.HimallIO.GetRomoteImagePath(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(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 couponCount = GetCouponList(shop.Id);//取设置的优惠券
            if (couponCount > 0)
            {
                model.Shop.CouponCount = couponCount;
            }

            // 客服
            var customerServices = CustomerServiceApplication.GetMobileCustomerService(shop.Id);
            var meiqia           = CustomerServiceApplication.GetPreSaleByShopId(shop.Id).FirstOrDefault(p => p.Tool == CustomerServiceInfo.ServiceTool.MeiQia);
            if (meiqia != null)
            {
                customerServices.Insert(0, meiqia);
            }
            #endregion

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

            double  total          = product.Himall_ProductComments.Count();
            double  niceTotal      = product.Himall_ProductComments.Count(item => item.ReviewMark >= 4);
            bool    isFavorite     = false;
            bool    IsFavoriteShop = false;
            decimal discount       = 1M;
            if (CurrentUser == null)
            {
                isFavorite     = false;
                IsFavoriteShop = false;
            }
            else
            {
                isFavorite = ServiceProvider.Instance <IProductService> .Create.IsFavorite(product.Id, CurrentUser.Id);

                var favoriteShopIds = ServiceProvider.Instance <IShopService> .Create.GetFavoriteShopInfos(CurrentUser.Id).Select(item => item.ShopId).ToArray();//获取已关注店铺

                IsFavoriteShop = favoriteShopIds.Contains(product.ShopId);
                discount       = CurrentUser.MemberDiscount;
            }

            var productImage = new List <string>();
            for (int i = 1; i < 6; i++)
            {
                if (Core.HimallIO.ExistFile(product.RelativePath + string.Format("/{0}.png", i)))
                {
                    var path = Core.HimallIO.GetRomoteProductSizeImage(product.RelativePath, i, (int)Himall.CommonModel.ImageSize.Size_350);
                    productImage.Add(path);
                }
            }
            //File.Exists(HttpContext.Current.Server.MapPath(product.ImagePath + string.Format("/{0}.png", 1)));
            decimal minSalePrice    = shop.IsSelf ? product.MinSalePrice * discount : product.MinSalePrice;
            var     isValidLimitBuy = "false";
            if (limitBuy != null)
            {
                isValidLimitBuy = "true";
                minSalePrice    = limitBuy.MinPrice; //限时购不打折
            }
            bool isFightGroupActive = false;
            var  activeInfo         = ServiceProvider.Instance <IFightGroupService> .Create.GetActiveByProId(product.Id);

            if (activeInfo != null && activeInfo.ActiveStatus > FightGroupActiveStatus.Ending)
            {
                isFightGroupActive = true;
            }

            model.Product = new ProductInfoModel()
            {
                ProductId          = product.Id,
                CommentCount       = com.Count(),//product.Himall_ProductComments.Count(),
                Consultations      = consultations.Count(),
                ImagePath          = productImage,
                IsFavorite         = isFavorite,
                MarketPrice        = product.MarketPrice,
                MinSalePrice       = minSalePrice,
                NicePercent        = model.Shop.ProductMark == 0 ? 100 : (int)((niceTotal / total) * 100),
                ProductName        = product.ProductName,
                ProductSaleStatus  = product.SaleStatus,
                AuditStatus        = product.AuditStatus,
                ShortDescription   = product.ShortDescription,
                ProductDescription = GetProductDescription(product.ProductDescriptionInfo),
                IsOnLimitBuy       = limitBuy != null
            };
            #endregion

            #region 佣金
            var     probroker      = DistributionApplication.GetDistributionProductInfo(id);
            var     IsDistribution = false;
            decimal Brokerage      = 0;
            if (probroker != null)
            {
                IsDistribution = true;
                Brokerage      = probroker.Commission;
            }
            #endregion

            #region  代金红包

            var bonus = ServiceProvider.Instance <IShopBonusService> .Create.GetByShopId(shop.Id);

            int     BonusCount             = 0;
            decimal BonusGrantPrice        = 0;
            decimal BonusRandomAmountStart = 0;
            decimal BonusRandomAmountEnd   = 0;

            if (bonus != null)
            {
                BonusCount             = bonus.Count;
                BonusGrantPrice        = bonus.GrantPrice;
                BonusRandomAmountStart = bonus.RandomAmountStart;
                BonusRandomAmountEnd   = bonus.RandomAmountEnd;
            }

            var fullDiscount = FullDiscountApplication.GetOngoingActiveByProductId(id, shop.Id);

            #endregion

            LogProduct(id);
            //统计商品浏览量、店铺浏览人数
            StatisticApplication.StatisticVisitCount(product.Id, product.ShopId);
            var IsPromoter = false;
            if (CurrentUser != null && CurrentUser.Id > 0)
            {
                var prom = DistributionApplication.GetPromoterByUserId(CurrentUser.Id);
                if (prom != null && prom.Status == PromoterInfo.PromoterStatus.Audited)
                {
                    IsPromoter = true;
                }
            }
            return(Json(new
            {
                Success = "true",
                IsOnLimitBuy = isValidLimitBuy,
                IsFightGroupActive = isFightGroupActive,
                ActiveId = isFightGroupActive ? activeInfo.Id : 0,
                ActiveStatus = activeInfo != null ? activeInfo.ActiveStatus.GetHashCode() : 0,
                MaxSaleCount = limitBuy == null ? 0 : limitBuy.LimitCountOfThePeople,
                Title = limitBuy == null ? string.Empty : limitBuy.Title,
                Second = limitBuy == null ? 0 : (limitBuy.EndDate - DateTime.Now).TotalSeconds,
                Product = model.Product,
                CashDepositsServer = model.CashDepositsServer,                                //提供服务(消费者保障、七天无理由、及时发货)
                ProductAddress = model.ProductAddress,                                        //发货地址
                Free = model.FreightTemplate.IsFree == FreightTemplateType.Free ? "免运费" : "", //是否免运费
                VShopLog = Himall.Core.HimallIO.GetRomoteImagePath(model.VShopLog),
                Shop = model.Shop,
                IsFavoriteShop = IsFavoriteShop,
                Color = model.Color,
                Size = model.Size,
                Version = model.Version,
                BonusCount = BonusCount,
                BonusGrantPrice = BonusGrantPrice,
                BonusRandomAmountStart = BonusRandomAmountStart,
                BonusRandomAmountEnd = BonusRandomAmountEnd,
                fullDiscount = fullDiscount,
                ColorAlias = colorAlias,
                SizeAlias = sizeAlias,
                VersionAlias = versionAlias,
                IsDistribution = IsDistribution,
                Brokerage = Brokerage.ToString("f2"),
                IsPromoter = IsPromoter,
                userId = CurrentUser == null ? 0 : CurrentUser.Id,
                IsOpenStore = SiteSettingApplication.GetSiteSettings() != null && SiteSettingApplication.GetSiteSettings().IsOpenStore,
                CustomerServices = customerServices
            }));
        }
예제 #13
0
        private static void CreateIndex(List <ProductInfo> list)
        {
            IProductShopCategoryInfo shopBll    = new ProductShopCategoryService();
            IFreightTemplate         freBll     = new FreightTemplateService();
            IProductInfo             pBll       = new ProductInfoService();
            IProductAttributeInfo    proAttrBll = new ProductAttributeService();
            IAttributeValueInfo      attrBll    = new AttributeValueService();
            string indexpath = ConfigurationManager.AppSettings["Indexpath"];
            IProductDescriptionInfo desBll = new ProductDescriptionInfoService();
            IBrandInfo braBll = new BrandInfoService();

            FSDirectory directory = FSDirectory.Open(new DirectoryInfo(indexpath), new NativeFSLockFactory());
            //IndexReader:对索引库进行读取的类
            bool isExist = IndexReader.IndexExists(directory);  //是否存在索引库文件夹以及索引库特征文件

            if (isExist)
            {
                //如果索引目录被锁定(比如索引过程中程序异常退出或另一进程在操作索引库),则解锁
                //Q:存在问题 如果一个用户正在对索引库写操作 此时是上锁的 而另一个用户过来操作时 将锁解开了 于是产生冲突 --解决方法后续
                if (IndexWriter.IsLocked(directory))
                {
                    IndexWriter.Unlock(directory);
                }
            }

            IndexWriter writer = new IndexWriter(directory, new PanGuAnalyzer(), !isExist, IndexWriter.MaxFieldLength.UNLIMITED);

            try
            {
                foreach (var pitem in list)
                {
                    string shopcategoryid = "";
                    List <ProductShopCategoryInfo> shoplist = new List <ProductShopCategoryInfo>();
                    shoplist = shopBll.SearchbyProid(pitem.Id.ToString());
                    foreach (var shopitem in shoplist)
                    {
                        shopcategoryid += shopitem.ShopCategoryId.ToString() + ",";
                    }
                    FreightTemplateInfo freinfo = new FreightTemplateInfo();
                    freinfo = freBll.SearchByid(pitem.FreightTemplateId.ToString());

                    List <ProductAttributeInfo> attrlist = new List <ProductAttributeInfo>();
                    string proattr = ",";
                    string attrval = "";
                    string attr    = "";
                    attrlist = proAttrBll.SearchByproductid(pitem.Id.ToString());     //产品属性
                    foreach (var attitem in attrlist)
                    {
                        proattr += attitem.ValueId + ","; //属性ID用于精确查找
                        attr     = attrBll.GetAttributeValueById(attitem.ValueId);
                        attrval += attr + ",";            //属性值用于模糊查询
                    }
                    string desinfo = "";
                    desinfo = desBll.GetByProductId(pitem.Id);  //产品描述  用于模糊查询

                    string brand = "";
                    brand    = braBll.GetNameById(pitem.BrandId); //品牌名字  用于模糊查询
                    attrval += brand;                             //品牌属性

                    Document document    = new Document();
                    Field    id          = new Field("Id", pitem.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED);                                             //商品ID
                    Field    ProductName = new Field("ProductName", pitem.ProductName, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS); //商品名称
                    ProductName.SetBoost(0.5f);
                    //Field BrandName = new Field("BrandName", brand, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);   //品牌名字
                    Field Description = new Field("Description", desinfo, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);           //描述
                    Description.SetBoost(0.15f);
                    Field BrandAttribution = new Field("BrandAttribution", attrval, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS); //品牌属性
                    BrandAttribution.SetBoost(0.35f);

                    Field        AuditStatus       = new Field("AuditStatus", pitem.AuditStatus.ToString(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS); //
                    Field        SaleStatus        = new Field("SaleStatus", pitem.SaleStatus.ToString(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);   //销售状态
                    NumericField ShopId            = new NumericField("ShopId", Field.Store.YES, true).SetLongValue(pitem.ShopId);                                                           //商家ID
                    Field        CategoryPath      = new Field("CategoryPath", pitem.CategoryPath, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);          //分类路径
                    NumericField CategoryId        = new NumericField("CategoryId", Field.Store.YES, true).SetLongValue(pitem.CategoryId);                                                   //分类ID
                    NumericField BrandId           = new NumericField("BrandId", Field.Store.YES, true).SetLongValue(pitem.BrandId);                                                         //品牌ID
                    NumericField MinSalePrice      = new NumericField("MinSalePrice", Field.Store.YES, true).SetDoubleValue(Convert.ToDouble(pitem.MinSalePrice));                           //价格
                    NumericField SaleCounts        = new NumericField("SaleCounts", Field.Store.YES, true).SetLongValue(pitem.SaleCounts);                                                   //销售数量
                    NumericField AddedDate         = new NumericField("AddedDate", Field.Store.YES, true).SetLongValue(pitem.AddedDate.Ticks);                                               //商品上架时间
                    Field        FreightTemplateId = new Field("FreightTemplateId", pitem.FreightTemplateId.ToString(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
                    Field        Shopcategoryid    = new Field("Shopcategoryid", shopcategoryid, Field.Store.YES, Field.Index.NOT_ANALYZED);                                                 //商家分类ID
                    Field        ProductAttribute  = new Field("ProductAttribute", proattr, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);                 //商品属性
                    Field        ProductImage      = new Field("ProductImage", string.IsNullOrEmpty(pitem.ImagePath) ? "未知" : pitem.ImagePath, Field.Store.YES, Field.Index.NOT_ANALYZED);
                    Field        SaleUnit          = new Field("SaleUnit", string.IsNullOrEmpty(pitem.MeasureUnit) ? "未知" : pitem.MeasureUnit, Field.Store.YES, Field.Index.NOT_ANALYZED);   //销售单位

                    int SourceAddress = 0;
                    if (freinfo.SourceAddress != null)
                    {
                        SourceAddress = (int)freinfo.SourceAddress;
                    }
                    NumericField AddressId  = new NumericField("AddressId", Field.Store.YES, true).SetIntValue(SourceAddress); //地区ID
                    int          commentnum = pBll.SearchComments(pitem.Id.ToString());
                    NumericField CommentNum = new NumericField("CommentNum", Field.Store.YES, true).SetIntValue(commentnum);   //评论数
                    document.Add(id);
                    document.Add(ProductName);
                    //document.Add(BrandName);
                    document.Add(Description);
                    document.Add(BrandAttribution);
                    document.Add(AuditStatus);
                    document.Add(SaleStatus);
                    document.Add(ShopId);
                    document.Add(CategoryPath);
                    document.Add(CategoryId);
                    document.Add(BrandId);
                    document.Add(MinSalePrice);
                    document.Add(SaleCounts);
                    document.Add(AddedDate);
                    document.Add(FreightTemplateId);
                    document.Add(Shopcategoryid);
                    document.Add(ProductAttribute);
                    document.Add(ProductImage);
                    document.Add(SaleUnit);
                    document.Add(AddressId);
                    document.Add(CommentNum);
                    writer.AddDocument(document);  //文档写入索引库
                }
                writer.Optimize();
                writer.Close();      //会自动解锁
                directory.Close();   //不要忘了Close,否则索引结果搜不到
            }
            catch (Exception ex)
            {
                Utility.writelog("创建索引出问题:" + ex + "");
            }
        }
예제 #14
0
        /// <summary>
        /// 拼团活动商品详情
        /// </summary>
        /// <param name="id">拼团活动ID</param>
        /// /// <param name="grouId">团活动ID</param>
        /// <returns></returns>
        public object GetActiveDetail(long id, long grouId = 0, bool isFirst = true, string ids = "")
        {
            var userList = new List <FightGroupOrderInfo>();
            var data     = ServiceProvider.Instance <IFightGroupService> .Create.GetActive(id, true, true);

            Mapper.CreateMap <FightGroupActiveInfo, FightGroupActiveModel>();
            //规格映射
            Mapper.CreateMap <FightGroupActiveItemInfo, FightGroupActiveItemModel>();


            FightGroupActiveModel result = Mapper.Map <FightGroupActiveInfo, FightGroupActiveModel>(data);

            if (result != null)
            {
                result.IsEnd = true;
                if (data.EndTime.Value.Date >= DateTime.Now.Date)
                {
                    result.IsEnd = false;
                }
                //商品图片地址修正
                result.ProductDefaultImage = HimallIO.GetRomoteProductSizeImage(data.ProductImgPath, 1, (int)ImageSize.Size_350);
                result.ProductImgPath      = HimallIO.GetRomoteProductSizeImage(data.ProductImgPath, 1);
            }
            //result.InitProductImages();
            if (!string.IsNullOrWhiteSpace(result.ProductDefaultImage))
            {
                //补充图片地址
                for (var n = 2; n < 6; n++)
                {
                    var _imgurl = HimallIO.GetProductSizeImage(result.ProductDefaultImage, n, (int)ImageSize.Size_350);
                    if (this.IsExist(_imgurl))
                    {
                        result.ProductImages.Add(_imgurl);
                    }
                }
            }
            if (!string.IsNullOrWhiteSpace(result.IconUrl))
            {
                result.IconUrl = Himall.Core.HimallIO.GetRomoteImagePath(result.IconUrl);
            }
            bool IsUserEnter = false;
            long currentUser = 0;

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

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

            //if (product == null)
            //{
            //    throw new Himall.Core.HimallException("产品编号错误");
            //}

            //if (product.IsDeleted)
            //{
            //    throw new Himall.Core.HimallException("产品编号错误");
            //}


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

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

            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;
            model.ColorAlias   = colorAlias;
            model.SizeAlias    = sizeAlias;
            model.VersionAlias = versionAlias;

            if (result.ActiveItems != null && result.ActiveItems.Count() > 0)
            {
                long colorId = 0, sizeId = 0, versionId = 0;
                var  skus = ServiceProvider.Instance <IProductService> .Create.GetSKUs((long)result.ProductId);

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

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

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

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

            #region 商品评论
            ProductCommentShowModel modelSay = new ProductCommentShowModel();
            modelSay.ProductId = (long)result.ProductId;
            var productSay = ServiceProvider.Instance <IProductService> .Create.GetProduct((long)result.ProductId);

            modelSay.CommentList       = new List <ProductDetailCommentModel>();
            modelSay.IsShowColumnTitle = true;
            modelSay.IsShowCommentList = true;

            if (productSay == null)
            {
                //跳转到404页面
                throw new Core.HimallException("商品不存在");
            }
            if (product.IsDeleted)
            {
                //跳转到404页面
                throw new Core.HimallException("商品不存在");
            }
            var com      = product.Himall_ProductComments.Where(item => !item.IsHidden.HasValue || item.IsHidden.Value == false);
            var comCount = com.Count();
            modelSay.CommentCount = comCount;
            if (comCount > 0)
            {
                modelSay.CommentList = com.OrderByDescending(a => a.ReviewDate).Take(1).Select(c => new ProductDetailCommentModel
                {
                    Sku                = ServiceProvider.Instance <IProductService> .Create.GetSkuString(c.Himall_OrderItems.SkuId),
                    UserName           = c.UserName,
                    ReviewContent      = c.ReviewContent,
                    AppendContent      = c.AppendContent,
                    AppendDate         = c.AppendDate,
                    ReplyAppendContent = c.ReplyAppendContent,
                    ReplyAppendDate    = c.ReplyAppendDate,
                    FinshDate          = c.Himall_OrderItems.OrderInfo.FinishDate,
                    Images             = c.Himall_ProductCommentsImages.Where(a => a.CommentType == 0).Select(a => a.CommentImage).ToList(),
                    AppendImages       = c.Himall_ProductCommentsImages.Where(a => a.CommentType == 1).Select(a => a.CommentImage).ToList(),
                    ReviewDate         = c.ReviewDate,
                    ReplyContent       = string.IsNullOrWhiteSpace(c.ReplyContent) ? "暂无回复" : c.ReplyContent,
                    ReplyDate          = c.ReplyDate,
                    ReviewMark         = c.ReviewMark,
                    BuyDate            = c.Himall_OrderItems.OrderInfo.OrderDate
                }).ToList();
                foreach (var citem in modelSay.CommentList)
                {
                    if (citem.Images.Count > 0)
                    {
                        for (var _imgn = 0; _imgn < citem.Images.Count; _imgn++)
                        {
                            citem.Images[_imgn] = Himall.Core.HimallIO.GetImagePath(citem.Images[_imgn]);
                        }
                    }
                    if (citem.AppendImages.Count > 0)
                    {
                        for (var _imgn = 0; _imgn < citem.AppendImages.Count; _imgn++)
                        {
                            citem.AppendImages[_imgn] = Himall.Core.HimallIO.GetImagePath(citem.AppendImages[_imgn]);
                        }
                    }
                }
            }
            #endregion

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

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

            modelShopScore.ShopName = shop.ShopName;

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

            var productAndDescription = shopStatisticOrderComments.Where(c => c.CommentKey == 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;

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

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

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

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

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

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

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

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

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

            // 客服
            var customerServices = CustomerServiceApplication.GetMobileCustomerService(shop.Id);
            var meiqia           = CustomerServiceApplication.GetPreSaleByShopId(shop.Id).FirstOrDefault(p => p.Tool == CustomerServiceInfo.ServiceTool.MeiQia);
            if (meiqia != null)
            {
                customerServices.Insert(0, meiqia);
            }
            #endregion
            #region 根据运费模板获取发货地址
            var freightTemplateService   = ServiceHelper.Create <IFreightTemplateService>();
            FreightTemplateInfo template = freightTemplateService.GetFreightTemplate(product.FreightTemplateId);
            string productAddress        = string.Empty;
            if (template != null && template.SourceAddress.HasValue)
            {
                var fullName = ServiceHelper.Create <IRegionService>().GetFullName(template.SourceAddress.Value);
                if (fullName != null)
                {
                    var ass = fullName.Split(' ');
                    if (ass.Length >= 2)
                    {
                        productAddress = ass[0] + " " + ass[1];
                    }
                    else
                    {
                        productAddress = ass[0];
                    }
                }
            }

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

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

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

            modelVshop.FreeFreight = shop.FreeFreight;


            var bonus = ServiceHelper.Create <IShopBonusService>().GetByShopId(result.ShopId);
            if (bonus != null)
            {
                modelVshop.BonusCount             = bonus.Count;
                modelVshop.BonusGrantPrice        = bonus.GrantPrice;
                modelVshop.BonusRandomAmountStart = bonus.RandomAmountStart;
                modelVshop.BonusRandomAmountEnd   = bonus.RandomAmountEnd;
            }
            #endregion
            //商品描述
            var ProductDescription = ServiceHelper.Create <IProductService>().GetProductDescription((long)result.ProductId);
            if (ProductDescription == null)
            {
                throw new Himall.Core.HimallException("错误的商品编号");
            }
            //统计商品浏览量、店铺浏览人数
            StatisticApplication.StatisticVisitCount(product.Id, product.ShopId);

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

            return(Json(new
            {
                FightGroupData = fightGroupData,
                ShowSkuInfo = model,
                ShowPromotion = modelVshop,
                ShowNewCanJoinGroup = GroupsData,
                ProductCommentShow = modelSay,
                ProductDescription = ProductDescription.ShowMobileDescription.Replace("src=\"/Storage/", "src=\"" + Core.HimallIO.GetRomoteImagePath("/Storage/")),
                ShopScore = modelShopScore,
                CashDepositsServer = cashDepositModel,
                ProductAddress = ProductAddress,
                Free = FreightTemplate.IsFree == FreightTemplateType.Free ? "免运费" : "",
                userList = userList,
                IsUserEnter = IsUserEnter,
                SkuData = skudata,
                CustomerServices = customerServices
            }));
        }