/// <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 Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO AddYXCommodityExt(Jinher.AMP.BTP.Deploy.JdCommodityDTO input) { try { if (input == null) { return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { ResultCode = 2, isSuccess = false, Message = "参数不能为空~" }); } if (!string.IsNullOrEmpty(input.JDCode) && !IsExistsJdCodeExt(input.JDCode, input.AppId)) { return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { ResultCode = 2, isSuccess = false, Message = "列表中已存在该备注编码~" }); } Guid userId = this.ContextDTO.LoginUserID; var SPUIdLis = YXSV.GetAllSPU(); if (SPUIdLis.IndexOf(input.Code) > 0) { return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { ResultCode = 2, isSuccess = false, Message = "备注编码在严选商品池中不存在" }); } ContextSession contextSession = ContextFactory.CurrentThreadContext; JdCommodity JdCom = JdCommodity.CreateJdCommodity(); JdCom.TaxRate = input.TaxRate; JdCom.InputRax = input.InputRax; JdCom.TaxClassCode = input.TaxClassCode; JdCom.State = 0; //是否补全 JdCom.SubId = userId; JdCom.SubTime = DateTime.Now; JdCom.AppId = input.AppId; JdCom.JDCode = input.JDCode; JdCom.SaleAreas = "430000,220000,420000,210000,310000,120000,140000,410000,320000,340000,350000,510000,440000,450000,500000,370000,530000,460000,610000,110000,230000,360000,620000,330000,640000,520000,130000,630000";//出去港澳台 新疆 西藏 JdCom.No_Code = JdCom.JDCode + "0000"; JdCom.ErQiCode = input.ErQiCode; JdCom.CostPrice = input.CostPrice; JdCom.IsAssurance = input.IsAssurance; JdCom.IsReturns = input.IsReturns; JdCom.Isnsupport = input.Isnsupport; JdCom.ServiceSettingId = input.ServiceSettingId; JdCom.TechSpecs = input.TechSpecs; JdCom.SaleService = input.SaleService; JdCom.CategoryName = input.CategoryName; //商城分类借用字段 JdCom.VideoName = input.VideoName; contextSession.SaveObject(JdCom); contextSession.SaveChanges(); } catch (Exception ex) { LogHelper.Error("YXCommodityBP.AddYXCommodityExt 异常", ex); return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { isSuccess = false, Message = ex.Message }); } return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { isSuccess = true, Message = "添加成功" }); }
/// <summary> /// 导入严选商品信息 /// </summary> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> ImportYXCommodityDataExt(System.Collections.Generic.List <Jinher.AMP.BTP.Deploy.JdCommodityDTO> JdComList, System.Guid AppId) { try { JdCommoditySearchDTO JdComDTO = new JdCommoditySearchDTO(); var SPUIdLis = YXSV.GetAllSPU(); List <string> SPUIds = JdComList.Select(s => s.JDCode).ToList(); //严选商品池不存在的SKUid JdComDTO.InvalidData = SPUIds.Except(SPUIdLis).ToList(); //店铺中已存在的严选 JdComDTO.RepeatData = Commodity.ObjectSet().Where(p => SPUIds.Contains(p.JDCode) && !p.IsDel && p.AppId == AppId).Select(s => s.JDCode).ToList(); //严选商品表中已存在的备注编码 JdComDTO.JdRepeatData = JdCommodity.ObjectSet().Where(p => SPUIds.Contains(p.JDCode) && !p.IsDel && p.AppId == AppId && p.State != 1).Select(s => s.JDCode).ToList(); if (JdComDTO.InvalidData.Any() || JdComDTO.JdRepeatData.Any()) { return(new ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> { Data = JdComDTO, ResultCode = 1, isSuccess = false, Message = "存在重复备注编码和无效备注编码,请核对后再导入~" }); } //获取运费模板 var FreightTemplateInfo = FreightTemplate.ObjectSet().FirstOrDefault(p => p.AppId == AppId && p.IsDefault == 1); ContextSession contextSession = ContextFactory.CurrentThreadContext; Guid userId = this.ContextDTO.LoginUserID; //获取不到商品类目的 List <string> NoCategoryData = new List <string>(); foreach (var input in JdComList) { JdCommodity JdCom = JdCommodity.CreateJdCommodity(); JdCom.Barcode = input.JDCode; JdCom.TaxRate = input.TaxRate; JdCom.InputRax = input.InputRax; JdCom.TaxClassCode = input.TaxClassCode; JdCom.State = 0; //是否补全 JdCom.SubId = userId; JdCom.SubTime = DateTime.Now; JdCom.AppId = input.AppId; JdCom.JDCode = input.JDCode; JdCom.FreightTemplateId = FreightTemplateInfo.Id; JdCom.SaleAreas = "430000,220000,420000,210000,310000,120000,140000,410000,320000,340000,350000,510000,440000,450000,500000,370000,530000,460000,610000,110000,230000,360000,620000,330000,640000,520000,130000,630000";//出去港澳台 新疆 西藏 JdCom.No_Code = input.JDCode; JdCom.ErQiCode = input.ErQiCode; JdCom.IsAssurance = input.IsAssurance; JdCom.IsReturns = input.IsReturns; JdCom.Isnsupport = input.Isnsupport; JdCom.ServiceSettingId = input.ServiceSettingId; JdCom.TechSpecs = input.TechSpecs; JdCom.SaleService = input.SaleService; JdCom.CategoryName = input.CategoryName; JdCom.VideoName = input.VideoName; contextSession.SaveObject(JdCom); } int count = contextSession.SaveChanges(); return(new ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> { Data = JdComDTO, ResultCode = 0, isSuccess = true, Message = "导入成功" }); } catch (Exception ex) { LogHelper.Error("YXCommodityBP.ImportYXCommodityDataExt 异常", ex); return(new ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> { isSuccess = false, ResultCode = 2, Message = ex.Message }); } }