Exemple #1
0
        /// <summary>
        /// 获取商城品类
        /// </summary>
        /// <param name="AppId"></param>
        /// <returns></returns>
        public System.Collections.Generic.List <Jinher.AMP.BTP.Deploy.InnerCategoryDTO> GetCategoriesExt(System.Guid AppId)
        {
            var ParentIds = InnerCategory.ObjectSet().Where(p => p.ParentId != Guid.Empty && p.AppId == AppId && p.IsDel == false).Select(s => s.ParentId).ToList();
            var query     = InnerCategory.ObjectSet().Where(p => !ParentIds.Contains(p.Id) && p.AppId == AppId && p.IsDel == false).Select(s => new InnerCategoryDTO {
                Id = s.Id, Name = s.Name
            }).ToList();

            return(query);
        }
Exemple #2
0
        /// <summary>
        /// 自动同步严选商品信息
        /// </summary>
        /// <param name="AppId"></param>
        /// <param name="Ids"></param>
        /// <returns></returns>
        public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> AutoSyncYXCommodityInfoExt(System.Guid AppId, System.Collections.Generic.List <System.Guid> Ids)
        {
            try
            {
                Jinher.AMP.App.Deploy.CustomDTO.AppIdOwnerIdTypeDTO appModel = APPSV.Instance.GetAppOwnerInfo(AppId);
                bool isFnull = true;
                if (appModel.OwnerType == 0)
                {
                    CBC.Deploy.CustomDTO.OrgInfoNewDTO orgInfoDTO = CBCSV.Instance.GetOrgInfoNewBySubId(appModel.OwnerId);
                    if (orgInfoDTO == null || string.IsNullOrEmpty(orgInfoDTO.CompanyPhone))
                    {
                        isFnull = false;
                    }
                }
                JdCommoditySearchDTO JdComDTO = new JdCommoditySearchDTO();
                Guid           userId         = this.ContextDTO.LoginUserID;
                ContextSession contextSession = ContextFactory.CurrentThreadContext;
                if (isFnull)
                {
                    //取出补全的商品信息
                    var                   YXComList       = JdCommodity.ObjectSet().Where(p => p.AppId == AppId && Ids.Contains(p.Id)).ToList();
                    List <string>         skuIds          = YXComList.Select(s => s.JDCode).ToList();
                    List <YXComDetailDTO> YXComDetailList = new List <YXComDetailDTO>();

                    for (int i = 0; i < skuIds.Count; i += 30)
                    {
                        YXComDetailList.AddRange(YXSV.GetComDetailList(skuIds.Skip(i).Take(30).ToList()));
                    }
                    if (!YXComDetailList.Any())
                    {
                        return(new ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> {
                            Data = JdComDTO, ResultCode = 1, isSuccess = false, Message = "未获取到严选商品信息"
                        });
                    }
                    #region 获取所有skuid库存 处理严选商品属性

                    List <StockDTO>             YXstockNumList = new List <StockDTO>();             //库存信息
                    List <itemSkuSpecValueList> skuAttr        = new List <itemSkuSpecValueList>(); //商品属性

                    if (YXComDetailList.Any())
                    {
                        List <string> Sku = new List <string>();
                        foreach (var item in YXComDetailList)
                        {
                            Sku.AddRange(item.skuList.Select(s => s.id).ToList());
                            foreach (var it in item.skuList)
                            {
                                skuAttr.AddRange(it.itemSkuSpecValueList);
                            }
                        }
                        //批量获取严选库存信息
                        for (int i = 0; i < Sku.Count; i += 90)
                        {
                            YXstockNumList.AddRange(YXSV.GetStockNum(Sku.Skip(i).Take(90).ToList()));
                            //Thread.Sleep(1000);
                        }
                        //写入严选商品属性
                        List <ComAttribute> ComAttr = new List <ComAttribute>();
                        foreach (var item in skuAttr)
                        {
                            ComAttribute Com = new ComAttribute();
                            Com.AttrName  = item.skuSpec.name;
                            Com.Attrvalue = item.skuSpecValue.value;
                            ComAttr.Add(Com);
                        }
                        var firstAttributeName = ComAttr.Select(s => s.AttrName).ToList();
                        //写入不存在的商品属性
                        List <string> colorAndSize = new List <string>()
                        {
                            "颜色", "尺寸"
                        };
                        var NoExistAttr = firstAttributeName.Except(Jinher.AMP.BTP.BE.Attribute.ObjectSet().Where(p => p.AppId == AppId && p.IsDel == false).Select(s => s.Name).ToList().Union(colorAndSize)).ToList();
                        if (NoExistAttr.Any())
                        {
                            foreach (var item in NoExistAttr)
                            {
                                AttributeDTO attrDTO = new AttributeDTO();
                                attrDTO.Id          = Guid.NewGuid();
                                attrDTO.Name        = item;
                                attrDTO.AppId       = AppId;
                                attrDTO.EntityState = System.Data.EntityState.Added;
                                Jinher.AMP.BTP.BE.Attribute attribute = new Jinher.AMP.BTP.BE.Attribute().FromEntityData(attrDTO);
                                attribute.SubId   = userId;
                                attribute.SubTime = DateTime.Now;
                                contextSession.SaveObject(attribute);
                            }
                        }
                    }
                    #endregion
                    #region 获取所有的商城分类  商品类目
                    //获取商城品类
                    var InnerCategoryNameList = YXComList.Select(s => s.VideoName.Trim()).ToList();

                    //获取商品分类
                    var           CategoryNameList = YXComList.Select(s => s.CategoryName).ToList();//获取所有的商品分类
                    string        ggg  = string.Join(",", CategoryNameList.ToArray());
                    List <string> list = new List <string>(ggg.Split(','));
                    //易捷北京
                    var CategoryList = Category.ObjectSet().Where(p => p.AppId == new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6") && !p.IsDel && CategoryNameList.Contains(p.Name)).ToList();
                    var categoryList = InnerCategory.ObjectSet().Where(p => InnerCategoryNameList.Contains(p.Name) && p.AppId == new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6") && !p.IsDel).ToList();
                    //本地调试
                    //var categoryList = InnerCategory.ObjectSet().Where(p => InnerCategoryNameList.Contains(p.Name) && p.AppId == AppId && !p.IsDel).ToList();
                    //var CategoryList = Category.ObjectSet().Where(p => p.AppId == AppId && !p.IsDel && list.Distinct().Contains(p.Name)).ToList();
                    #endregion

                    //获取不到商品类目的
                    List <string> NoCategoryData = new List <string>();
                    //店铺中存在的备注编码进行更新  不存在则插入
                    var ExistCommodity = Commodity.ObjectSet().Where(p => skuIds.Contains(p.Barcode) && !p.IsDel && p.AppId == AppId).ToList();
                    JdComDTO.RepeatData = ExistCommodity.Select(s => s.Barcode).ToList();

                    foreach (var item in ExistCommodity)
                    {
                        var YXCom           = YXComList.FirstOrDefault(p => p.JDCode == item.Barcode);
                        var YXComDetailInfo = YXComDetailList.Where(p => p.id == item.Barcode).FirstOrDefault();

                        var minSortValueQuery = (from m in Commodity.ObjectSet()
                                                 where m.AppId == AppId && m.CommodityType == 0
                                                 select m);
                        int?minSort      = minSortValueQuery.Min(m => (int?)m.SortValue);
                        int minSortValue = 2;
                        if (minSort.HasValue)
                        {
                            minSortValue = minSort.Value;
                        }
                        item.Name         = "网易严选 " + YXComDetailInfo.name;
                        item.SubId        = userId;
                        item.No_Number    = YXCom.No_Number ?? 0;
                        item.Price        = YXComDetailInfo.skuList.Min(p => p.channelPrice);
                        item.Stock        = YXCom.Stock;
                        item.PicturesPath = YXComDetailInfo.listPicUrl;
                        item.Description  = "<div class=\"JD-goods\">" + YXComDetailInfo.itemDetail.detailHtml + "</div>";

                        //Com.State = 1; 只更新商品信息,不更新商品上下架状态
                        item.IsDel             = false;
                        item.AppId             = YXCom.AppId;
                        item.TotalCollection   = 0;
                        item.TotalReview       = 0;
                        item.Salesvolume       = 0;
                        item.ModifiedOn        = DateTime.Now;
                        item.ComAttribute      = YXCom.ComAttribute;
                        item.CategoryName      = YXCom.CategoryName;
                        item.SortValue         = minSortValue - 1;
                        item.FreightTemplateId = YXCom.FreightTemplateId;  //99元以下商品8元运费
                        item.MarketPrice       = YXCom.MarketPrice;
                        //Com.Weight = YXComDetailInfo.;
                        //Com.SaleService = JdComDetailInfo.wareQD + "<br>" + JdComDetailInfo.shouhou;
                        item.SaleAreas     = YXCom.SaleAreas;
                        item.SharePercent  = YXCom.SharePercent;
                        item.CommodityType = 0;
                        item.Duty          = YXCom.Duty;
                        item.TaxRate       = YXCom.TaxRate;
                        item.TaxClassCode  = YXCom.TaxClassCode;
                        item.Unit          = "件";
                        item.InputRax      = YXCom.InputRax;

                        if (YXComDetailInfo.skuList.Count() == 1)
                        {
                            //单条属性与库存表保持一致
                            item.JDCode  = YXComDetailInfo.skuList.FirstOrDefault().id;
                            item.Code    = item.JDCode;
                            item.Barcode = YXComDetailInfo.id;
                            item.No_Code = item.JDCode;
                        }
                        else
                        {
                            //多条属性存储SPU
                            item.JDCode  = YXComDetailInfo.skuList.OrderBy(p => p.channelPrice).FirstOrDefault().id;
                            item.Code    = item.JDCode;
                            item.Barcode = YXComDetailInfo.id; //存严选商品的SPU
                            item.No_Code = item.JDCode;
                        }

                        item.CostPrice        = item.Price * Convert.ToDecimal(0.8);
                        item.ServiceSettingId = YXCom.ServiceSettingId;
                        //Com.TechSpecs = JdComDetailInfo.param;
                        item.SaleService        = YXCom.SaleService;
                        item.Type               = 0;
                        item.YJCouponActivityId = "";
                        item.YJCouponType       = "";
                        item.ModifieId          = userId;
                        List <ComAttributeDTO> ComAttr = new List <ComAttributeDTO>();
                        foreach (var skuitem in YXComDetailInfo.skuList)
                        {
                            foreach (var it in skuitem.itemSkuSpecValueList)
                            {
                                ComAttributeDTO ComAtt = new ComAttributeDTO();
                                ComAtt.Attribute       = it.skuSpec.name;
                                ComAtt.SecondAttribute = it.skuSpecValue.value;
                                ComAttr.Add(ComAtt);
                            }
                        }
                        item.ComAttribute = JsonHelper.JsonSerializer <List <ComAttributeDTO> >(ComAttr);
                        item.RefreshCache(EntityState.Modified);
                        //更新库存表
                        UpdateCommodityStock(item, YXComDetailInfo, YXstockNumList, contextSession);
                        int count1 = contextSession.SaveChanges();
                        //更新JdCommodity表中状态
                        YXCom.State = 1;
                        #region 商品图片
                        //删除图片
                        ProductDetailsPictureBP pdpbp = new ProductDetailsPictureBP();
                        pdpbp.DeletePictures(item.Id);

                        List <string> PicList = new List <string>();
                        PicList.Add(YXComDetailInfo.itemDetail.picUrl1);
                        PicList.Add(YXComDetailInfo.itemDetail.picUrl2);
                        PicList.Add(YXComDetailInfo.itemDetail.picUrl3);
                        PicList.Add(YXComDetailInfo.itemDetail.picUrl4);
                        //添加图片
                        int sort = 1;
                        foreach (var itempic in PicList)
                        {
                            if (!string.IsNullOrWhiteSpace(itempic) && itempic.Length >= 50)
                            {
                                ProductDetailsPicture pic = ProductDetailsPicture.CreateProductDetailsPicture();
                                pic.Name         = "商品图片";
                                pic.SubId        = userId;
                                pic.SubTime      = DateTime.Now;
                                pic.PicturesPath = itempic;
                                pic.CommodityId  = item.Id;
                                pic.Sort         = sort;
                                contextSession.SaveObject(pic);
                                sort++;
                            }
                        }
                        #endregion
                        #region 商品分类
                        //删除商品分类
                        var catList = CommodityCategory.ObjectSet().Where(c => c.CommodityId == item.Id).ToList();
                        foreach (var commodityCategory in catList)
                        {
                            contextSession.Delete(commodityCategory);
                        }
                        //添加商品分类
                        var ComCategory = CategoryList.Where(p => YXCom.CategoryName.Contains(p.Name)).ToList();
                        if (ComCategory.Any())
                        {
                            foreach (var itemcate in ComCategory)
                            {
                                CommodityCategory comcate = CommodityCategory.CreateCommodityCategory();
                                comcate.CategoryId  = itemcate.Id;
                                comcate.CommodityId = item.Id;
                                comcate.SubId       = userId;
                                comcate.SubTime     = DateTime.Now;
                                comcate.Name        = "商品分类";
                                comcate.IsDel       = false;
                                #region 本地测试
                                //comcate.SubId = AppId;
                                //comcate.AppId = AppId;
                                //comcate.CrcAppId = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(AppId);
                                #endregion
                                //正式环境
                                comcate.SubId    = new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6");
                                comcate.AppId    = new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6");
                                comcate.CrcAppId = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6"));
                                contextSession.SaveObject(comcate);
                            }
                        }
                        else
                        {
                            NoCategoryData.Add(YXCom.JDCode);
                        }
                        #endregion
                        #region 商城分类
                        //删除商城分类
                        var oldCCs = CommodityInnerCategory.ObjectSet().Where(c => c.CommodityId == item.Id).ToList();
                        foreach (var commodityCategory in oldCCs)
                        {
                            contextSession.Delete(commodityCategory);
                        }
                        //添加商城分类
                        var innerCateid = categoryList.Where(p => p.Name == YXCom.VideoName.Trim()).FirstOrDefault();
                        if (innerCateid != null)
                        {
                            CommodityInnerCategory comInnerCate = CommodityInnerCategory.CreateCommodityInnerCategory();
                            comInnerCate.CategoryId  = innerCateid.Id;
                            comInnerCate.CommodityId = item.Id;
                            comInnerCate.SubId       = userId;
                            comInnerCate.SubTime     = DateTime.Now;
                            comInnerCate.Name        = "商品分类";
                            comInnerCate.IsDel       = false;
                            comInnerCate.SubId       = AppId;
                            comInnerCate.AppId       = AppId;
                            comInnerCate.CrcAppId    = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(AppId);
                            contextSession.SaveObject(comInnerCate);
                        }
                        #endregion
                    }
                    #region 商品中不存在的插入
                    var NoExist = YXComList.Where(p => !JdComDTO.RepeatData.Contains(p.Barcode)).ToList();
                    foreach (var item in NoExist)
                    {
                        var YXComDetailInfo = YXComDetailList.Where(p => p.id == item.JDCode).FirstOrDefault();

                        var minSortValueQuery = (from m in Commodity.ObjectSet()
                                                 where m.AppId == AppId && m.CommodityType == 0
                                                 select m);
                        int?minSort      = minSortValueQuery.Min(m => (int?)m.SortValue);
                        int minSortValue = 2;
                        if (minSort.HasValue)
                        {
                            minSortValue = minSort.Value;
                        }
                        Commodity Com = Commodity.CreateCommodity();
                        Com.Id                = Guid.NewGuid();
                        Com.Name              = "网易严选 " + YXComDetailInfo.name;
                        Com.SubTime           = DateTime.Now;
                        Com.SubId             = userId;
                        Com.No_Number         = item.No_Number ?? 0;
                        Com.Price             = YXComDetailInfo.skuList.Min(p => p.channelPrice);
                        Com.Stock             = item.Stock;
                        Com.PicturesPath      = YXComDetailInfo.listPicUrl;
                        Com.Description       = "<div class=\"JD-goods\">" + YXComDetailInfo.itemDetail.detailHtml + "</div>";
                        Com.State             = 1; //只更新商品信息,不更新商品上下架状态
                        Com.IsDel             = false;
                        Com.AppId             = item.AppId;
                        Com.TotalCollection   = 0;
                        Com.TotalReview       = 0;
                        Com.Salesvolume       = 0;
                        Com.ModifiedOn        = DateTime.Now;
                        Com.ComAttribute      = item.ComAttribute;
                        Com.CategoryName      = item.CategoryName;
                        Com.SortValue         = minSortValue - 1;
                        Com.FreightTemplateId = item.FreightTemplateId;  //99元以下商品8元运费
                        Com.MarketPrice       = item.MarketPrice;
                        //Com.Weight = YXComDetailInfo.;
                        //Com.SaleService = JdComDetailInfo.wareQD + "<br>" + JdComDetailInfo.shouhou;
                        Com.SaleAreas     = item.SaleAreas;
                        Com.SharePercent  = item.SharePercent;
                        Com.CommodityType = 0;
                        Com.Duty          = item.Duty;
                        Com.TaxRate       = item.TaxRate;
                        Com.TaxClassCode  = item.TaxClassCode;
                        Com.Unit          = "件";
                        Com.InputRax      = item.InputRax;

                        if (YXComDetailInfo.skuList.Count() == 1)
                        {
                            //单条属性与库存表保持一致
                            Com.JDCode  = YXComDetailInfo.skuList.FirstOrDefault().id;
                            Com.Code    = Com.JDCode;
                            Com.Barcode = YXComDetailInfo.id;
                            Com.No_Code = Com.JDCode;
                        }
                        else
                        {
                            //多条属性存储SPU
                            Com.JDCode  = YXComDetailInfo.skuList.OrderBy(p => p.channelPrice).FirstOrDefault().id;
                            Com.Code    = Com.JDCode;
                            Com.Barcode = YXComDetailInfo.id; //存严选商品的SPU
                            Com.No_Code = Com.JDCode;
                        }

                        Com.CostPrice        = Com.Price * Convert.ToDecimal(0.8);
                        Com.ServiceSettingId = item.ServiceSettingId;
                        //Com.TechSpecs = JdComDetailInfo.param;
                        Com.SaleService        = item.SaleService;
                        Com.Type               = 0;
                        Com.YJCouponActivityId = "";
                        Com.YJCouponType       = "";
                        Com.ModifieId          = userId;
                        List <ComAttributeDTO> ComAttr = new List <ComAttributeDTO>();
                        foreach (var skuitem in YXComDetailInfo.skuList)
                        {
                            foreach (var it in skuitem.itemSkuSpecValueList)
                            {
                                ComAttributeDTO ComAtt = new ComAttributeDTO();
                                ComAtt.Attribute       = it.skuSpec.name;
                                ComAtt.SecondAttribute = it.skuSpecValue.value;
                                ComAttr.Add(ComAtt);
                            }
                        }
                        Com.ComAttribute = JsonHelper.JsonSerializer <List <ComAttributeDTO> >(ComAttr);
                        contextSession.SaveObject(Com);
                        SaveCommodityStock(Com, YXComDetailInfo, YXstockNumList, contextSession);

                        //更新JdCommodity表中状态
                        item.State = 1;
                        #region 商品图片
                        List <string> PicList = new List <string>();
                        PicList.Add(YXComDetailInfo.itemDetail.picUrl1);
                        PicList.Add(YXComDetailInfo.itemDetail.picUrl2);
                        PicList.Add(YXComDetailInfo.itemDetail.picUrl3);
                        PicList.Add(YXComDetailInfo.itemDetail.picUrl4);
                        //添加图片
                        int sort = 1;
                        foreach (var itempic in PicList)
                        {
                            if (!string.IsNullOrEmpty(itempic))
                            {
                                ProductDetailsPicture pic = ProductDetailsPicture.CreateProductDetailsPicture();
                                pic.Name         = "商品图片";
                                pic.SubId        = userId;
                                pic.SubTime      = DateTime.Now;
                                pic.PicturesPath = itempic;
                                pic.CommodityId  = Com.Id;
                                pic.Sort         = sort;
                                contextSession.SaveObject(pic);
                                sort++;
                            }
                        }
                        #endregion
                        #region 商品分类
                        var ComCategory = CategoryList.Where(p => item.CategoryName.Contains(p.Name)).ToList();
                        if (ComCategory.Any())
                        {
                            foreach (var itemcate in ComCategory)
                            {
                                CommodityCategory comcate = CommodityCategory.CreateCommodityCategory();
                                comcate.CategoryId  = itemcate.Id;
                                comcate.CommodityId = Com.Id;
                                comcate.SubId       = userId;
                                comcate.SubTime     = DateTime.Now;
                                comcate.Name        = "商品分类";
                                comcate.IsDel       = false;
                                #region 本地测试
                                //comcate.SubId = AppId;
                                //comcate.AppId = AppId;
                                //comcate.CrcAppId = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(AppId);
                                #endregion
                                comcate.SubId    = new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6");
                                comcate.AppId    = new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6");
                                comcate.CrcAppId = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6"));
                                contextSession.SaveObject(comcate);
                            }
                        }
                        else
                        {
                            NoCategoryData.Add(item.JDCode);
                        }
                        #endregion
                        #region 商城分类
                        var innerCateid = categoryList.Where(p => p.Name == item.VideoName.Trim()).FirstOrDefault();
                        if (innerCateid != null)
                        {
                            CommodityInnerCategory comInnerCate = CommodityInnerCategory.CreateCommodityInnerCategory();
                            comInnerCate.CategoryId  = innerCateid.Id;
                            comInnerCate.CommodityId = Com.Id;
                            comInnerCate.SubId       = userId;
                            comInnerCate.SubTime     = DateTime.Now;
                            comInnerCate.Name        = "商品分类";
                            comInnerCate.IsDel       = false;
                            comInnerCate.SubId       = AppId;
                            comInnerCate.AppId       = AppId;
                            comInnerCate.CrcAppId    = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(AppId);
                            contextSession.SaveObject(comInnerCate);
                        }
                        #endregion
                    }
                    #endregion

                    int count = contextSession.SaveChanges();
                    JdComDTO.NoCategoryData = NoCategoryData;
                }
                return(new ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> {
                    Data = JdComDTO, ResultCode = 0, isSuccess = true, Message = "自动同步成功"
                });
            }
            catch (Exception ex)
            {
                LogHelper.Error("YJEmployeeBP.AutoSyncCommodityInfoExt 异常", ex);
                return(new ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> {
                    ResultCode = 1, isSuccess = false, Message = ex.Message
                });
            }
        }
Exemple #3
0
        /// <summary>
        /// 自动同步商品信息
        /// </summary>
        /// <param name="AppId"></param>
        /// <param name="Ids"></param>
        /// <returns></returns>
        public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> AutoSyncCommodityInfoExt(System.Guid AppId, System.Collections.Generic.List <System.Guid> Ids)
        {
            try
            {
                Jinher.AMP.App.Deploy.CustomDTO.AppIdOwnerIdTypeDTO appModel =
                    APPSV.Instance.GetAppOwnerInfo(AppId);
                bool isFnull = true;
                if (appModel.OwnerType == 0)
                {
                    CBC.Deploy.CustomDTO.OrgInfoNewDTO orgInfoDTO = CBCSV.Instance.GetOrgInfoNewBySubId(appModel.OwnerId);
                    if (orgInfoDTO == null || string.IsNullOrEmpty(orgInfoDTO.CompanyPhone))
                    {
                        isFnull = false;
                    }
                }
                JdCommoditySearchDTO JdComDTO = new JdCommoditySearchDTO();
                Guid           userId         = this.ContextDTO.LoginUserID;
                ContextSession contextSession = ContextFactory.CurrentThreadContext;
                if (isFnull)
                {
                    //取出补全的商品信息
                    var                     JdComList = JdCommodity.ObjectSet().Where(p => p.AppId == AppId && Ids.Contains(p.Id)).ToList();
                    List <string>           skuIds    = JdComList.Select(s => s.JDCode).ToList();
                    List <JdComPicturesDto> JdComPics = new List <JdComPicturesDto>();
                    for (int i = 0; i < skuIds.Count; i += 99)
                    {
                        JdComPics.AddRange(JDSV.GetComPictures(skuIds.Skip(i).Take(99).ToList()));
                    }
                    //获取京东商品详情
                    List <JdComDetailDto> JdComDetailList = new List <JdComDetailDto>();
                    foreach (var item in skuIds)
                    {
                        var JdComDetailInfo = JDSV.GetJdDetail(item);
                        JdComDetailList.Add(JdComDetailInfo);
                    }
                    //获取商城品类
                    var InnerCategoryNameList = JdComList.Select(s => s.VideoName.Trim()).ToList();
                    //获取运费模板
                    var FreightTemplateInfo = FreightTemplate.ObjectSet().FirstOrDefault(p => p.AppId == AppId && p.IsDefault == 1);
                    //获取商品分类
                    var           CategoryNameList = JdComList.Select(s => s.CategoryName).ToList();//获取所有的商品分类
                    string        ggg  = string.Join(",", CategoryNameList.ToArray());
                    List <string> list = new List <string>(ggg.Split(','));
                    //易捷北京
                    var CategoryList = Category.ObjectSet().Where(p => p.AppId == new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6") && !p.IsDel && CategoryNameList.Contains(p.Name)).ToList();
                    var categoryList = InnerCategory.ObjectSet().Where(p => InnerCategoryNameList.Contains(p.Name) && p.AppId == new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6") && !p.IsDel).ToList();
                    //本地调试
                    //var categoryList = InnerCategory.ObjectSet().Where(p => InnerCategoryNameList.Contains(p.Name) && p.AppId == AppId && !p.IsDel).ToList();
                    //var CategoryList = Category.ObjectSet().Where(p => p.AppId == AppId && !p.IsDel && list.Distinct().Contains(p.Name)).ToList();

                    //获取不到商品类目的
                    List <string> NoCategoryData = new List <string>();
                    //店铺中存在的备注编码进行更新  不存在则插入
                    var ExistCommodity = Commodity.ObjectSet().Where(p => skuIds.Contains(p.JDCode) && !p.IsDel && p.AppId == AppId).ToList();
                    JdComDTO.RepeatData = ExistCommodity.Select(s => s.JDCode).ToList();

                    foreach (var item in ExistCommodity)
                    {
                        var JdCom           = JdComList.FirstOrDefault(p => p.JDCode == item.JDCode);
                        var JdComPic        = JdComPics.Where(p => p.skuId == item.JDCode);
                        var JdComDetailInfo = JdComDetailList.Where(p => p.sku == item.JDCode).FirstOrDefault();

                        var minSortValueQuery = (from m in Commodity.ObjectSet()
                                                 where m.AppId == AppId && m.CommodityType == 0
                                                 select m);
                        int?minSort      = minSortValueQuery.Min(m => (int?)m.SortValue);
                        int minSortValue = 2;
                        if (minSort.HasValue)
                        {
                            minSortValue = minSort.Value;
                        }
                        Commodity Com = new Commodity();
                        Com.Id           = item.Id;
                        Com.Name         = JdComDetailInfo.name;
                        Com.Code         = JdCom.Code;
                        Com.SubTime      = DateTime.Now;
                        Com.SubId        = userId;
                        Com.No_Number    = JdCom.No_Number ?? 0;
                        Com.Price        = JdCom.Price ?? 0;
                        Com.Stock        = JdCom.Stock;
                        Com.PicturesPath = "http://img13.360buyimg.com/n1/" + JdComPic.FirstOrDefault(p => p.isPrimary == "1").path;
                        if (JdComDetailInfo.appintroduce != null && JdComDetailInfo.appintroduce != "")
                        {
                            string Div = JdComDetailInfo.appintroduce.Substring(0, 10);
                            if (Div.Contains("<div"))
                            {
                                Com.Description = "<div class=\"JD-goods\">" + JdComDetailInfo.appintroduce.Replace("\'", "\"").Replace("\'", "\"") + "</div>";
                            }
                            else
                            {
                                Com.Description = JdComDetailInfo.appintroduce.Replace("\'", "\"").Replace("\'", "\"");
                            }
                        }
                        else
                        {
                            string Div = JdComDetailInfo.introduction.Substring(0, 10);
                            if (Div.Contains("<div"))
                            {
                                Com.Description = "<div class=\"JD-goods\">" + JdComDetailInfo.introduction.Replace("\'", "\"").Replace("\'", "\"") + "</div>";
                            }
                            else
                            {
                                Com.Description = JdComDetailInfo.introduction.Replace("\'", "\"").Replace("\'", "\"");
                            }
                        }
                        //Com.State = 1; 只更新商品信息,不更新商品上下架状态
                        Com.IsDel             = false;
                        Com.AppId             = JdCom.AppId;
                        Com.No_Code           = JdCom.No_Code;
                        Com.TotalCollection   = 0;
                        Com.TotalReview       = 0;
                        Com.Salesvolume       = 0;
                        Com.ModifiedOn        = DateTime.Now;
                        Com.ComAttribute      = JdCom.ComAttribute;
                        Com.CategoryName      = JdCom.CategoryName;
                        Com.SortValue         = minSortValue - 1;
                        Com.FreightTemplateId = FreightTemplateInfo.Id;  //99元以下商品8元运费
                        Com.MarketPrice       = JdCom.MarketPrice;
                        Com.Weight            = JdComDetailInfo.weight;
                        Com.SaleService       = JdComDetailInfo.wareQD + "<br>" + JdComDetailInfo.shouhou;
                        Com.SaleAreas         = JdCom.SaleAreas;
                        Com.SharePercent      = JdCom.SharePercent;
                        Com.CommodityType     = 0;
                        Com.Duty               = JdCom.Duty;
                        Com.TaxRate            = JdCom.TaxRate;
                        Com.TaxClassCode       = JdCom.TaxClassCode;
                        Com.Unit               = string.IsNullOrEmpty(JdComDetailInfo.saleUnit) ? "件" : JdComDetailInfo.saleUnit;
                        Com.InputRax           = JdCom.InputRax;
                        Com.Barcode            = JdComDetailInfo.upc;
                        Com.JDCode             = JdCom.JDCode;
                        Com.CostPrice          = JdCom.CostPrice;
                        Com.ServiceSettingId   = JdCom.ServiceSettingId;
                        Com.TechSpecs          = JdComDetailInfo.param;
                        Com.SaleService        = JdCom.SaleService;
                        Com.Type               = 0;
                        Com.YJCouponActivityId = "";
                        Com.YJCouponType       = "";
                        Com.ModifieId          = userId;
                        Com.EntityState        = EntityState.Modified;
                        contextSession.SaveObject(Com);
                        Com.RefreshCache(EntityState.Modified);
                        //更新库存表
                        UpdateCommodityStock(Com, contextSession);
                        int count1 = contextSession.SaveChanges();
                        //更新JdCommodity表中状态
                        JdCom.State = 1;
                        #region 商品图片
                        //删除图片
                        ProductDetailsPictureBP pdpbp = new ProductDetailsPictureBP();
                        pdpbp.DeletePictures(item.Id);
                        //添加图片
                        foreach (var itempic in JdComPic)
                        {
                            ProductDetailsPicture pic = ProductDetailsPicture.CreateProductDetailsPicture();
                            pic.Name         = "商品图片";
                            pic.SubId        = userId;
                            pic.SubTime      = DateTime.Now;
                            pic.PicturesPath = "http://img13.360buyimg.com/n1/" + itempic.path;
                            pic.CommodityId  = Com.Id;
                            pic.Sort         = Convert.ToInt32(itempic.orderSort);
                            contextSession.SaveObject(pic);
                        }
                        #endregion
                        #region 商品分类
                        //删除商品分类
                        var catList = CommodityCategory.ObjectSet().Where(c => c.CommodityId == item.Id).ToList();
                        foreach (var commodityCategory in catList)
                        {
                            contextSession.Delete(commodityCategory);
                        }
                        //添加商品分类
                        var ComCategory = CategoryList.Where(p => JdCom.CategoryName.Contains(p.Name)).ToList();
                        if (ComCategory.Any())
                        {
                            foreach (var itemcate in ComCategory)
                            {
                                CommodityCategory comcate = CommodityCategory.CreateCommodityCategory();
                                comcate.CategoryId  = itemcate.Id;
                                comcate.CommodityId = Com.Id;
                                comcate.SubId       = userId;
                                comcate.SubTime     = DateTime.Now;
                                comcate.Name        = "商品分类";
                                comcate.IsDel       = false;
                                #region 本地测试
                                //comcate.SubId = AppId;
                                //comcate.AppId = AppId;
                                //comcate.CrcAppId = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(AppId);
                                #endregion
                                comcate.SubId    = new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6");
                                comcate.AppId    = new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6");
                                comcate.CrcAppId = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6"));
                                contextSession.SaveObject(comcate);
                            }
                        }
                        else
                        {
                            NoCategoryData.Add(JdCom.JDCode);
                        }
                        #endregion
                        #region 商城分类
                        //删除商城分类
                        var oldCCs = CommodityInnerCategory.ObjectSet().Where(c => c.CommodityId == item.Id).ToList();
                        foreach (var commodityCategory in oldCCs)
                        {
                            contextSession.Delete(commodityCategory);
                        }
                        //添加商城分类
                        var innerCateid = categoryList.Where(p => p.Name == JdCom.VideoName.Trim()).FirstOrDefault();
                        if (innerCateid != null)
                        {
                            CommodityInnerCategory comInnerCate = CommodityInnerCategory.CreateCommodityInnerCategory();
                            comInnerCate.CategoryId  = innerCateid.Id;
                            comInnerCate.CommodityId = Com.Id;
                            comInnerCate.SubId       = userId;
                            comInnerCate.SubTime     = DateTime.Now;
                            comInnerCate.Name        = "商品分类";
                            comInnerCate.IsDel       = false;
                            comInnerCate.SubId       = AppId;
                            comInnerCate.AppId       = AppId;
                            comInnerCate.CrcAppId    = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(AppId);
                            contextSession.SaveObject(comInnerCate);
                        }
                        #endregion
                    }
                    #region 商品中不存在的插入
                    var NoExist = JdComList.Where(p => !JdComDTO.RepeatData.Contains(p.JDCode)).ToList();
                    foreach (var item in NoExist)
                    {
                        var JdComPic        = JdComPics.Where(p => p.skuId == item.JDCode);
                        var JdComDetailInfo = JdComDetailList.Where(p => p.sku == item.JDCode).FirstOrDefault();

                        var minSortValueQuery = (from m in Commodity.ObjectSet()
                                                 where m.AppId == AppId && m.CommodityType == 0
                                                 select m);
                        int?minSort      = minSortValueQuery.Min(m => (int?)m.SortValue);
                        int minSortValue = 2;
                        if (minSort.HasValue)
                        {
                            minSortValue = minSort.Value;
                        }
                        Commodity Com = Commodity.CreateCommodity();
                        Com.Id           = item.Id;
                        Com.Name         = JdComDetailInfo.name;
                        Com.Code         = item.Code;
                        Com.SubTime      = DateTime.Now;
                        Com.SubId        = userId;
                        Com.No_Number    = item.No_Number ?? 0;
                        Com.Price        = item.Price ?? 0;
                        Com.Stock        = item.Stock;
                        Com.PicturesPath = "http://img13.360buyimg.com/n1/" + JdComPic.FirstOrDefault(p => p.isPrimary == "1").path;
                        if (JdComDetailInfo.appintroduce != null && JdComDetailInfo.appintroduce != "")
                        {
                            string Div = JdComDetailInfo.appintroduce.Substring(0, 10);
                            if (Div.Contains("<div"))
                            {
                                Com.Description = "<div class=\"JD-goods\">" + JdComDetailInfo.appintroduce.Replace("\'", "\"").Replace("\'", "\"") + "</div>";
                            }
                            else
                            {
                                Com.Description = JdComDetailInfo.appintroduce.Replace("\'", "\"").Replace("\'", "\"");
                            }
                        }
                        else
                        {
                            string Div = JdComDetailInfo.introduction.Substring(0, 10);
                            if (Div.Contains("<div"))
                            {
                                Com.Description = "<div class=\"JD-goods\">" + JdComDetailInfo.introduction.Replace("\'", "\"").Replace("\'", "\"") + "</div>";
                            }
                            else
                            {
                                Com.Description = JdComDetailInfo.introduction.Replace("\'", "\"").Replace("\'", "\"");
                            }
                        }
                        Com.State             = 1;
                        Com.IsDel             = false;
                        Com.AppId             = AppId;
                        Com.No_Code           = item.No_Code;
                        Com.TotalCollection   = 0;
                        Com.TotalReview       = 0;
                        Com.Salesvolume       = 0;
                        Com.ModifiedOn        = DateTime.Now;
                        Com.ComAttribute      = item.ComAttribute;
                        Com.CategoryName      = item.CategoryName;
                        Com.SortValue         = minSortValue - 1;
                        Com.FreightTemplateId = FreightTemplateInfo.Id;  //99元以下商品8元运费
                        Com.MarketPrice       = item.MarketPrice;
                        Com.Weight            = JdComDetailInfo.weight;
                        Com.SaleService       = JdComDetailInfo.wareQD + "<br>" + JdComDetailInfo.shouhou;
                        Com.SaleAreas         = item.SaleAreas;
                        Com.SharePercent      = item.SharePercent;
                        Com.CommodityType     = 0;
                        Com.Duty               = item.Duty;
                        Com.TaxRate            = item.TaxRate;
                        Com.TaxClassCode       = item.TaxClassCode;
                        Com.Unit               = string.IsNullOrEmpty(JdComDetailInfo.saleUnit)? "件" : JdComDetailInfo.saleUnit;
                        Com.InputRax           = item.InputRax;
                        Com.Barcode            = JdComDetailInfo.upc;
                        Com.JDCode             = item.JDCode;
                        Com.CostPrice          = item.CostPrice;
                        Com.ServiceSettingId   = item.ServiceSettingId;
                        Com.TechSpecs          = JdComDetailInfo.param;
                        Com.SaleService        = item.SaleService;
                        Com.Type               = 0;
                        Com.YJCouponActivityId = "";
                        Com.YJCouponType       = "";
                        Com.ModifieId          = userId;
                        contextSession.SaveObject(Com);
                        SaveCommodityStock(Com, contextSession);

                        //更新JdCommodity表中状态
                        item.State = 1;
                        #region 商品图片
                        foreach (var itempic in JdComPic)
                        {
                            ProductDetailsPicture pic = ProductDetailsPicture.CreateProductDetailsPicture();
                            pic.Name         = "商品图片";
                            pic.SubId        = userId;
                            pic.SubTime      = DateTime.Now;
                            pic.PicturesPath = "http://img13.360buyimg.com/n1/" + itempic.path;
                            pic.CommodityId  = Com.Id;
                            pic.Sort         = Convert.ToInt32(itempic.orderSort);
                            contextSession.SaveObject(pic);
                        }
                        #endregion
                        #region 商品分类
                        var ComCategory = CategoryList.Where(p => item.CategoryName.Contains(p.Name)).ToList();
                        if (ComCategory.Any())
                        {
                            foreach (var itemcate in ComCategory)
                            {
                                CommodityCategory comcate = CommodityCategory.CreateCommodityCategory();
                                comcate.CategoryId  = itemcate.Id;
                                comcate.CommodityId = Com.Id;
                                comcate.SubId       = userId;
                                comcate.SubTime     = DateTime.Now;
                                comcate.Name        = "商品分类";
                                comcate.IsDel       = false;
                                #region 本地测试
                                //comcate.SubId = AppId;
                                //comcate.AppId = AppId;
                                //comcate.CrcAppId = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(AppId);
                                #endregion
                                comcate.SubId    = new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6");
                                comcate.AppId    = new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6");
                                comcate.CrcAppId = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6"));
                                contextSession.SaveObject(comcate);
                            }
                        }
                        else
                        {
                            NoCategoryData.Add(item.JDCode);
                        }
                        #endregion
                        #region 商城分类
                        var innerCateid = categoryList.Where(p => p.Name == item.VideoName.Trim()).FirstOrDefault();
                        if (innerCateid != null)
                        {
                            CommodityInnerCategory comInnerCate = CommodityInnerCategory.CreateCommodityInnerCategory();
                            comInnerCate.CategoryId  = innerCateid.Id;
                            comInnerCate.CommodityId = Com.Id;
                            comInnerCate.SubId       = userId;
                            comInnerCate.SubTime     = DateTime.Now;
                            comInnerCate.Name        = "商品分类";
                            comInnerCate.IsDel       = false;
                            comInnerCate.SubId       = AppId;
                            comInnerCate.AppId       = AppId;
                            comInnerCate.CrcAppId    = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(AppId);
                            contextSession.SaveObject(comInnerCate);
                        }
                        #endregion
                    }
                    #endregion

                    int count = contextSession.SaveChanges();
                    JdComDTO.NoCategoryData = NoCategoryData;
                }
                return(new ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> {
                    Data = JdComDTO, ResultCode = 0, isSuccess = true, Message = "自动同步成功"
                });
            }
            catch (Exception ex)
            {
                LogHelper.Error("YJEmployeeBP.AutoSyncCommodityInfoExt 异常", ex);
                return(new ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> {
                    ResultCode = 1, isSuccess = false, Message = ex.Message
                });
            }
        }