/// <summary> /// 全量获取严选SPU /// </summary> public static void AutoGetAllSPU() { if (isSyncSPU) { LogHelper.Info("JdOrderHelper.AutoGetAllSPU 正在全量获取严选SPU,跳过。。。"); return; } isSyncSPU = true; LogHelper.Info("YXJobHelper.AutoGetAllSPU 开始写入严选SPU"); try { ContextSession contextSession = ContextFactory.CurrentThreadContext; //全量取出SPU var SPUlist = YXSV.GetAllSPU(); if (!SPUlist.Any()) { LogHelper.Info("JdOrderHelper.AutoGetAllSPU 未获取到严选SPU,跳出~"); return; } //清除表中全部数据 if (SPUlist.Any()) { YXComInfo.ObjectSet().Context.ExecuteStoreCommand("DELETE FROM YXComInfo"); } foreach (var item in SPUlist) { YXComInfo YXCom = YXComInfo.CreateYXComInfo(); YXCom.Id = Guid.NewGuid(); YXCom.SPU = item; YXCom.SubTime = DateTime.Now; contextSession.SaveObject(YXCom); } contextSession.SaveChanges(); } catch (Exception ex) { LogHelper.Error("YXJobHelper.AutoGetAllSPU 异常", ex); isSyncSPU = false; throw; } LogHelper.Info("YXJobHelper.AutoGetAllSPU 全量获取严选商品信息"); isSyncSPU = false; }
/// <summary> /// 全量获取严选价格信息 /// </summary> public static Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO AutoUpdateYXComPrice() { Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO result = new Deploy.CustomDTO.ResultDTO() { isSuccess = false, ResultCode = 1 }; if (isSyncYXComInfo) { LogHelper.Info("YXJobHelper.AutoUpdateYXComInfo 正在全量获取严选价格信息,跳过。。。"); return(result); } isSyncYXComInfo = true; LogHelper.Info("YXJobHelper.AutoUpdateYXComInfo 开始写入严选价格信息"); try { ContextSession contextSession = ContextFactory.CurrentThreadContext; int count = 0; AutoGetAllSPU(); var YXComList = YXComInfo.ObjectSet().ToList(); var UpdateSpuList = YXComList.Select(s => s.SPU).ToList(); List <YXComDetailDTO> YXComLists = new List <YXComDetailDTO>(); for (int i = 0; i < YXComList.Count; i += 30) { YXComLists.AddRange(YXSV.GetComDetailList(UpdateSpuList.Skip(i).Take(30).ToList())); //Thread.Sleep(1000); } foreach (var YXComlist in YXComLists) { foreach (var item in YXComlist.skuList) { YXComInfo YXCom = YXComInfo.CreateYXComInfo(); YXCom.Id = Guid.NewGuid(); YXCom.SPU = YXComlist.id; YXCom.SKU = item.id; YXCom.Price = item.channelPrice; YXCom.CostPrice = item.channelPrice * Convert.ToDecimal(0.8); YXCom.SubTime = DateTime.Now; contextSession.SaveObject(YXCom); } } count = contextSession.SaveChanges(); YXComInfo.ObjectSet().Context.ExecuteStoreCommand("delete from YXComInfo where SKU is null"); //取出最细你的严选价格信息 var YXComNewList = YXComInfo.ObjectSet().ToList(); //取出所有网易严选的商品信息 Guid AppId = new Guid("1d769e14-f870-4b19-82ab-875a9e8678e4"); var YXCom1 = Commodity.ObjectSet().Where(p => p.AppId == AppId).ToList(); LogHelper.Info(string.Format("取出严选商品条数:{0}", YXCom1.Count())); int savecount = 0; //取出定时改价中严选商品 List <Guid> YXappids = CustomConfig.YxAppIdList; var timingComIds = Jinher.AMP.BTP.TPS.YJBSV.GetYXChangeComInfo(YXappids).Data.Select(s => s.CommodityId).ToList(); for (int i = 0; i < YXCom1.Count; i += 100) { var YxComList = YXCom1.Skip(i).Take(100).ToList();//取出商品id var ComIds = YxComList.Select(s => s.Id); LogHelper.Info(string.Format("严选商品Id:{0}", JsonHelper.JsonSerializer(ComIds))); var YXComStock = CommodityStock.ObjectSet().Where(p => ComIds.Contains(p.CommodityId) && !timingComIds.Contains(p.Id)).ToList(); foreach (var item in YXComStock) { LogHelper.Info(string.Format("获取严选sku:{0}", item.JDCode)); var NewPriceInfo = YXComNewList.FirstOrDefault(p => p.SKU == item.JDCode); if (NewPriceInfo == null) { LogHelper.Info(string.Format("不存在严选sku:{0}", item.JDCode)); item.IsDel = true; item.ModifiedOn = DateTime.Now; } if (NewPriceInfo != null && NewPriceInfo.Price.HasValue && NewPriceInfo.CostPrice.HasValue && NewPriceInfo.Price > 0 && NewPriceInfo.CostPrice > 0) { LogHelper.Info(string.Format("获取严选商品sku:{0},售价:{1},进货价:{2}", NewPriceInfo.SKU, NewPriceInfo.Price, NewPriceInfo.CostPrice)); item.Price = NewPriceInfo.Price ?? item.Price; item.CostPrice = NewPriceInfo.CostPrice ?? item.CostPrice; item.IsDel = false; item.ModifiedOn = DateTime.Now; } } foreach (var item1 in YxComList) { var YXComMinPrice = YXComNewList.Where(p => p.SPU == item1.Barcode).OrderBy(p => p.Price).FirstOrDefault(); if (YXComMinPrice == null) { LogHelper.Info(string.Format("不存在严选SPU:{0}", item1.Barcode)); item1.IsDel = true; item1.State = 0; } if (YXComMinPrice != null && YXComMinPrice.Price > 0 && YXComMinPrice.CostPrice > 0) { LogHelper.Info(string.Format("获取严选商品最小价格sku:{0},售价:{1},进货价:{2}", YXComMinPrice.SKU, YXComMinPrice.Price, YXComMinPrice.CostPrice)); item1.Price = YXComMinPrice.Price ?? item1.Price; item1.CostPrice = YXComMinPrice.CostPrice ?? item1.CostPrice; item1.ModifiedOn = DateTime.Now; } } savecount += contextSession.SaveChanges(); LogHelper.Info(string.Format("获取苏宁价格保存条数:{0}", count)); } result.isSuccess = true; result.Message = "严选接口保存成功" + count + "条;商品表修改条数:" + savecount; isSyncYXComInfo = false; return(result); } catch (Exception ex) { LogHelper.Error("YXJobHelper.AutoUpdateYXComPrice 异常", ex); isSyncYXComInfo = false; return(result); } }
/// <summary> /// 全量获取严选价格信息 /// </summary> public static void AutoUpdateYXComInfo() { if (isSyncYXComInfo) { LogHelper.Info("YXJobHelper.AutoUpdateYXComInfo 正在全量获取严选价格信息,跳过。。。"); return; } isSyncYXComInfo = true; LogHelper.Info("YXJobHelper.AutoUpdateYXComInfo 开始写入严选价格信息"); try { AutoGetAllSPU(); var YXComList = YXComInfo.ObjectSet().ToList(); var UpdateSpuList = YXComList.Select(s => s.SPU).ToList(); List <YXComDetailDTO> YXComLists = new List <YXComDetailDTO>(); for (int i = 0; i < YXComList.Count; i += 30) { YXComLists.AddRange(YXSV.GetComDetailList(UpdateSpuList.Skip(i).Take(30).ToList())); //Thread.Sleep(1000); } ContextSession contextSession = ContextFactory.CurrentThreadContext; List <string> SkuIds = new List <string>(); foreach (var YXComlist in YXComLists) { foreach (var item in YXComlist.skuList) { YXComInfo YXCom = YXComInfo.CreateYXComInfo(); YXCom.Id = Guid.NewGuid(); YXCom.SPU = YXComlist.id; YXCom.SKU = item.id; YXCom.Price = item.channelPrice; YXCom.CostPrice = item.channelPrice * Convert.ToDecimal(0.8); YXCom.SubTime = DateTime.Now; contextSession.SaveObject(YXCom); SkuIds.Add(item.id); } } int count1 = contextSession.SaveChanges(); YXComInfo.ObjectSet().Context.ExecuteStoreCommand("delete from YXComInfo where SKU is null"); #region //取出定时改价中严选商品 List <Guid> YXappids = CustomConfig.YxAppIdList; var timingComIds = Jinher.AMP.BTP.TPS.YJBSV.GetYXChangeComInfo(YXappids).Data.Select(s => s.CommodityId).ToList(); //最新价格更新到YXComInfo,对比库存表和价格审核表 判断是否需要审核(过滤掉定时改价中严选的商品) var ComStockList = CommodityStock.ObjectSet().Where(p => SkuIds.Contains(p.JDCode) && !timingComIds.Contains(p.Id)).ToList(); var ComIds = ComStockList.Select(s => s.CommodityId).Distinct().ToList(); var ComList = Commodity.ObjectSet().Where(p => ComIds.Contains(p.Id)).ToList(); var YXComInfoList = YXComInfo.ObjectSet().Where(p => SkuIds.Contains(p.SKU)).ToList(); var AuditAuditModeApp = JDAuditMode.ObjectSet().Where(_ => _.PriceModeState == 0).Select(_ => _.AppId).ToList(); List <Guid> autoAuditPriceIds = new List <Guid>(); int count = 0; foreach (var group in ComList) { int addCount = 0; var Com = ComList.FirstOrDefault(p => p.Id == group.Id); var auditCom = AddCommodityAudit(Com); var ComStocks = ComStockList.Where(p => p.CommodityId == group.Id).ToList(); foreach (var item in ComStocks) { var YXComNew = YXComInfoList.FirstOrDefault(p => p.SKU == item.JDCode); if (YXComNew != null && YXComNew.Price.HasValue && item.Price != YXComNew.Price) { var latestAuditData = JdAuditCommodityStock.ObjectSet().Where(p => p.CommodityStockId == item.Id && p.AuditType == 2).OrderByDescending(p => p.SubTime).FirstOrDefault(); if (latestAuditData == null || latestAuditData.Price != item.Price) { count++; addCount++; var auditStock = AddCommodityStockAudit(contextSession, group.AppId, item, Deploy.Enum.OperateTypeEnum.京东修改现价); auditStock.AuditType = 2; auditStock.JdAuditCommodityId = auditCom.Id; auditStock.JdPrice = YXComNew.Price; auditStock.CostPrice = YXComNew.Price * Convert.ToDecimal(0.8); contextSession.SaveObject(auditStock); if (AuditAuditModeApp.Contains(group.AppId)) { autoAuditPriceIds.Add(auditStock.Id); } LogHelper.Info("YXJobHelper.AutoUpdateYXComInfo 更新商品售价,商品Id: " + item.Id + ",SkuId: " + item.JDCode); } } } if (addCount > 0) { contextSession.SaveObject(auditCom); } } int ccc = contextSession.SaveChanges(); // 自动审核 var auditComFacade = new JDAuditComFacade(); auditComFacade.ContextDTO = AuthorizeHelper.InitAuthorizeInfo(); if (autoAuditPriceIds.Count > 0) { auditComFacade.AuditJDCostPrice(autoAuditPriceIds, 1, "自动审核", 0, 0); } #endregion } catch (Exception ex) { LogHelper.Error("YXJobHelper.AutoUpdateYXComInfo 异常", ex); isSyncYXComInfo = false; throw; } LogHelper.Info("YXJobHelper.AutoUpdateYXComInfo 全量获取严选商品信息"); isSyncYXComInfo = false; }