コード例 #1
0
ファイル: JdCommodityBPExt.cs プロジェクト: GSIL-Monitor/BTP
        /// <summary>
        /// 新建商品信息
        /// </summary>
        public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO AddJdCommodityExt(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;
                //获取协议价格和京东价格
                List <string> skuIds = new List <string>();
                skuIds.Add(input.JDCode);
                List <JdPriceDto> jdPrices = new List <JdPriceDto>();
                jdPrices.AddRange(JDSV.GetPrice(skuIds));
                if (!jdPrices.Any())
                {
                    return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO {
                        ResultCode = 2, isSuccess = false, Message = "备注编码在京东商品池中不存在"
                    });
                }
                var            JdPriceinfo    = jdPrices.FirstOrDefault(p => p.SkuId == input.JDCode);
                ContextSession contextSession = ContextFactory.CurrentThreadContext;
                JdCommodity    JdCom          = JdCommodity.CreateJdCommodity();
                JdCom.Price        = JdPriceinfo.JdPrice;
                JdCom.CostPrice    = JdPriceinfo.Price;
                JdCom.TaxRate      = input.TaxRate;
                JdCom.InputRax     = input.InputRax;
                JdCom.TaxClassCode = input.TaxClassCode;
                JdCom.Stock        = 999;
                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.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("JdCommodityBP.AddJdCommodityExt 异常", 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 = "添加成功"
            });
        }
コード例 #2
0
ファイル: JdCommodityBPExt.cs プロジェクト: GSIL-Monitor/BTP
 /// <summary>
 /// 导入数据
 /// </summary>
 public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> ImportJdCommodityDataExt(System.Collections.Generic.List <Jinher.AMP.BTP.Deploy.JdCommodityDTO> JdComList, Guid AppId)
 {
     try
     {
         JdCommoditySearchDTO JdComDTO = new JdCommoditySearchDTO();
         List <string>        skuIds   = JdComList.Select(s => s.JDCode).ToList();
         List <JdPriceDto>    jdPrices = new List <JdPriceDto>();
         for (int i = 0; i < skuIds.Count; i += 99)
         {
             jdPrices.AddRange(JDSV.GetPrice(skuIds.Skip(i).Take(99).ToList()));
         }
         //京东商品池不存在的SKUid
         JdComDTO.InvalidData = skuIds.Except(jdPrices.Select(s => s.SkuId)).ToList();
         //店铺中已存在的京东编码
         JdComDTO.RepeatData = Commodity.ObjectSet().Where(p => skuIds.Contains(p.JDCode) && !p.IsDel && p.AppId == AppId).Select(s => s.JDCode).ToList();
         //京东商品表中已存在的备注编码
         JdComDTO.JdRepeatData = JdCommodity.ObjectSet().Where(p => skuIds.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 = "存在重复备注编码和无效备注编码,请核对后再导入~"
             });
         }
         ContextSession contextSession = ContextFactory.CurrentThreadContext;
         Guid           userId         = this.ContextDTO.LoginUserID;
         //获取不到商品类目的
         List <string> NoCategoryData = new List <string>();
         foreach (var input in JdComList)
         {
             var         jdPrice = jdPrices.Where(p => p.SkuId == input.JDCode).FirstOrDefault();
             JdCommodity JdCom   = JdCommodity.CreateJdCommodity();
             JdCom.CostPrice        = jdPrice.Price;
             JdCom.Price            = jdPrice.JdPrice;
             JdCom.Barcode          = input.JDCode;
             JdCom.TaxRate          = input.TaxRate;
             JdCom.InputRax         = input.InputRax;
             JdCom.TaxClassCode     = input.TaxClassCode;
             JdCom.Stock            = 999;
             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.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("YJEmployeeBP.AddYJEmployeeExt 异常", ex);
         return(new ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> {
             isSuccess = false, ResultCode = 2, Message = ex.Message
         });
     }
 }