Пример #1
0
        public void SKUURL_Action(CMS_SKU_Model WPModel, EcomEntities db)
        {
            if (String.IsNullOrEmpty(WPModel.URL))
            {
                return;
            }
            var query = db.SKUURL.FirstOrDefault(s => s.SKUOrder == WPModel.SKU && s.MerchantID == WPModel.ChannelName && s.URL == WPModel.URL);

            if (query == null)
            {
                db.SKUURL.Add(new SKUURL
                {
                    MerchantID = WPModel.ChannelName,
                    SKUOrder   = WPModel.SKU,
                    URL        = WPModel.URL
                });
            }
        }
Пример #2
0
        /// <summary>
        /// 组合产品的和基础产品的关联表,存在基础产品就更新,不存在就插入
        /// </summary>
        /// <param name="HMModel"></param>
        /// <param name="db"></param>
        public void HMNUMGroup_Action(CMS_SKU_Model skuModel, EcomEntities db, ref int pieces)
        {
            CMS_HMNUM_Model HMModel = skuModel.SKU_HM_Relation.CMS_HMNUM;

            pieces = 0;
            if (!HMModel.IsGroup)
            {
                return;
            }
            foreach (var subHM in HMModel.Children_CMS_HMNUM_List)
            {
                var subImgPath = string.Empty;
                var hmPImgObj  = subHM.MediaList.FirstOrDefault(m => m.IsPrimaryImages == true);
                if (hmPImgObj != null)
                {
                    subImgPath = Path.Combine(skuModel.CMSPhysicalPath, hmPImgObj.HMNUM + "\\" + hmPImgObj.ImgName + hmPImgObj.fileFormat);
                }
                this.HMNUM_Action(subHM, db, 1, subImgPath, decimal.Parse(skuModel.SKU_Costing.EstimateFreight, NumberStyles.Currency, new CultureInfo("en-US")));//调用内部方法,插入or更新HMNUM 2014年4月22日16:17:23
                pieces += subHM.SellSets;
                var query = db.ProductGroup.FirstOrDefault(g => g.HMNUM == subHM.HMNUM && g.HMNUMParent == HMModel.HMNUM);
                if (query == null)//【不】存在基础产品-组合产品的一条记录
                {
                    db.ProductGroup.Add(new ProductGroup
                    {
                        HMNUMParent = HMModel.HMNUM,
                        HMNUM       = subHM.HMNUM,
                        Description = subHM.ProductName,
                        SellSets    = subHM.SellSets
                    });
                }
                else//存在基础产品-组合产品的一条记录
                {
                    query.SellSets    = subHM.SellSets;
                    query.Description = subHM.ProductName;
                }
            }
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="HMModel"></param>
        /// <param name="db"></param>
        /// <param name="UnitQTY">用于给eCom前端展示及套件,比如4张椅子1个座子,就是S/5,5件套</param>
        /// <param name="imagePath">源文件路径 Formate: D:\\CMS\\Files\\123.jpg</param>
        /// <param name="SKUFreight">SKU的运费,用于给eCom同步的2014年5月28日</param>
        public void HMNUM_Action(CMS_HMNUM_Model HMModel, EcomEntities db, int UnitQTY, string imagePath, decimal SKUFreight)
        {
            if (HMModel.CMS_ShipVia_Type == null)//HMModel.CMS_ShipVia_Type.CMS_ShipVia_Default.SHIPVIA
            {
                throw new Exception("This HMNUM does not set ShipVia Type");
            }
            if (HMModel.CMS_ShipVia_Type.CMS_ShipVia_Default == null)
            {
                throw new Exception("This HMNUM does not set ShipVia");
            }
            var query = db.Product.FirstOrDefault(p => p.HMNUM == HMModel.HMNUM);

            if (!string.IsNullOrEmpty(imagePath) && File.Exists(imagePath))
            {
                //如果不存在,需要增加图片拷贝和略缩图生成的步骤的步骤
                var eComImageStoragePath = ConfigurationManager.AppSettings["eComImageStoragePath"];
                var strNewPath           = Path.Combine(eComImageStoragePath, HMModel.HMNUM);

                //先判断Width长还是height长

                CMSImageTools.SmallImageGenerator(imagePath, strNewPath + "_320.jpg", 320);

                CMSImageTools.SmallImageGenerator(imagePath, strNewPath + "_80.jpg", 80);
            }
            if (query == null)//不存在插入Product
            {
                db.Product.Add(new Product
                {
                    HMNUM          = HMModel.HMNUM,
                    StockID        = 0,
                    SKUBest        = HMModel.StockKey,
                    TAGNUM         = string.Empty,
                    Location       = string.Empty,
                    BarUPC         = string.Empty,                                     //暂时为空
                    ProductPicture = imagePath == "" ? null : HMModel.HMNUM + "_80.jpg",
                    Unit           = HMModel.IsGroup == true ? "S/" + UnitQTY : "S/1", //【注意:】这里不应该拿SellSets,应该拿Pieces!
                    Colour         = HMModel.HMColour == null ? null : HMModel.HMColour.ColourName,
                    Weight         = Convert.ToDouble(HMModel.NetWeight),
                    MasterPack     = Convert.ToInt16(HMModel.MasterPack),
                    //SellSets = HMModel.SellSets,
                    SellSets = HMModel.IsGroup == true ? 1 : HMModel.SellSets,//eComd的组合产品也有SellSets这个概念,默认设置为12014年5月6日17:59:05
                    Boxes    = 1,
                    //Freight = HMModel.HM_Costing == null ? 0 : decimal.Parse(HMModel.HM_Costing.EstimateFreight, NumberStyles.Currency, new CultureInfo("en-US")),//wl -1
                    Freight       = SKUFreight == 0 ? 1 : SKUFreight, //wl -1
                    CostHM        = HMModel.HM_Costing == null ? 0 : decimal.Parse(HMModel.HM_Costing.FirstCost, NumberStyles.Currency, new CultureInfo("en-US")),
                    Status        = "Pending",                        //让当前新增的HMNUM进入eCom的审核列表!
                    Comment       = HMModel.Comments,
                    DescriptionHM = HMModel.ProductName,
                    SHIPVIA       = HMModel.CMS_ShipVia_Type.CMS_ShipVia_Default.SHIPVIA,//2014年5月14日10:42:29
                    ColourHM      = HMModel.HMColour == null ? null : HMModel.HMColour.ColourName,
                    Category      = HMModel.Category == null ? null : HMModel.Category.ParentCategoryName,
                    SubCategory   = HMModel.Category == null ? null : HMModel.Category.CategoryName,
                    IsGroup       = HMModel.IsGroup,
                    LowStock      = 10
                });
            }
            else//存在跟新Product
            {
                query.ProductPicture = imagePath == "" ? query.ProductPicture : HMModel.HMNUM + "_80.jpg";
                query.SKUBest        = HMModel.StockKey;
                query.Comment        = HMModel.Comments;
                query.Weight         = Convert.ToDouble(HMModel.NetWeight);
                query.MasterPack     = Convert.ToInt16(HMModel.MasterPack);
                query.DescriptionHM  = HMModel.ProductName;
                //query.SellSets = HMModel.SellSets;
                query.SellSets    = HMModel.IsGroup == true ? 1 : HMModel.SellSets;//eComd的组合产品也有SellSets这个概念
                query.Category    = HMModel.Category == null ? null : HMModel.Category.ParentCategoryName;
                query.SubCategory = HMModel.Category == null ? null : HMModel.Category.CategoryName;
                query.CostHM      = HMModel.HM_Costing == null ? 0 : decimal.Parse(HMModel.HM_Costing.FirstCost, NumberStyles.Currency, new CultureInfo("en-US"));
                //query.Freight = decimal.Parse(HMModel.HM_Costing.EstimateFreight, NumberStyles.Currency, new CultureInfo("en-US")); //wl-1

                //query.SHIPVIA = HMModel.CMS_ShipVia_Type.CMS_ShipVia_Default.SHIPVIA;先不同步! 2014年6月9日17:29:22
            }
        }
Пример #4
0
        /// <summary>
        /// 对于箱柜尺寸的处理,就是先根据HMNUM删除所有信息,再重新插入
        /// </summary>
        /// <param name="HMModel"></param>
        /// <param name="db"></param>
        public void Carton_Action(CMS_HMNUM_Model HMModel, EcomEntities db)
        {
            var IsExistCTN = db.ProductCartons.FirstOrDefault(c => c.HMNUM == HMModel.HMNUM);//存在,则删之

            if (IsExistCTN != null)
            {
                //由于CMS整理出来的HM-ALL item的箱柜尺寸的信息不是非常的规范,所以暂时对已经存在于eCOM的这些信息不做任何处理
                //db.ProductCartons.Delete(p => p.HMNUM == HMModel.HMNUM);
                return;
            }

            if (HMModel.IsGroup)//如果箱柜为空,则拿CMS的数据插入
            {
                foreach (var subHM in HMModel.Children_CMS_HMNUM_List)
                {
                    int ctnNum = 1;
                    foreach (var ctn in subHM.CTNList)//一个HMNUM可以对应多个HMNUM
                    {
                        db.ProductCartons.Add(new ProductCartons
                        {
                            HMNUM        = HMModel.HMNUM,//这里取的不是基础产品,而是组合产品!
                            CartonNumber = ctnNum++,
                            Description  = subHM.ProductName,
                            CL           = Convert.ToDouble(ctn.CTNLength),
                            CW           = Convert.ToDouble(ctn.CTNWidth),
                            CH           = Convert.ToDouble(ctn.CTNHeight),

                            PL = Convert.ToDouble(subHM.DimList[0].DimLength),//默认取第一个,原因在Dimesion这个类的注释里面做说明了
                            PW = Convert.ToDouble(subHM.DimList[0].DimWidth),
                            PH = Convert.ToDouble(subHM.DimList[0].DimHeight),

                            //WEIGHTOFPRODUCT = 0,
                            WEIGHTOFPRODUCT  = Convert.ToInt32(HMModel.NetWeight), //产品净重量
                            WEIGHTOFSHIPMENT = Convert.ToInt32(ctn.CTNWeight),     //产品+箱子重量
                            COMMENTS         = ctn.CTNComment,
                            SubHMNUM         = subHM.HMNUM
                        });
                    }
                }
            }
            else
            {
                int ctnNum = 1;
                foreach (var ctn in HMModel.CTNList)
                {
                    db.ProductCartons.Add(new ProductCartons
                    {
                        HMNUM        = HMModel.HMNUM,
                        CartonNumber = ctnNum++,
                        Description  = HMModel.ProductName,
                        CL           = Convert.ToDouble(ctn.CTNLength),
                        CW           = Convert.ToDouble(ctn.CTNWidth),
                        CH           = Convert.ToDouble(ctn.CTNHeight),

                        PL = Convert.ToDouble(HMModel.DimList[0].DimLength),//默认取第一个,原因在Dimesion这个类的注释里面做说明了
                        PW = Convert.ToDouble(HMModel.DimList[0].DimWidth),
                        PH = Convert.ToDouble(HMModel.DimList[0].DimHeight),

                        WEIGHTOFPRODUCT  = Convert.ToInt32(HMModel.NetWeight),//产品净重量
                        WEIGHTOFSHIPMENT = Convert.ToInt32(ctn.CTNWeight),
                        COMMENTS         = ctn.CTNComment,
                        SubHMNUM         = string.Empty
                    });
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Ecom中的定义:
        /// Sellset,组合产品中的定义,在Group中,用于标识子产品在组合产品中的PCS数量
        /// Sellpack,销售数量定义,表示网站订单1QTY对应系统中销售N个产品的意思
        /// boxnum就是sellpack,一个货号我卖6个,装3箱,则:pcs 6 mp2 sellpack 3 Add Remark:2014年4月15日15:09:08
        /// </summary>
        /// <param name="WPModel"></param>
        /// <param name="db"></param>
        public void SKU_Action(CMS_SKU_Model WPModel, EcomEntities db)
        {
            if (WPModel.CMS_ShipViaType == null)//HMModel.CMS_ShipVia_Type.CMS_ShipVia_Default.SHIPVIA
            {
                throw new Exception("This SKU does not set ShipVia Type");
            }
            if (WPModel.CMS_ShipViaType.CMS_ShipVia_Default == null)
            {
                throw new Exception("This SKU does not set ShipVia");
            }

            var query = db.SKU.FirstOrDefault(s => s.SKUOrder == WPModel.SKU && s.MerchantID == WPModel.ChannelName);

            if (query == null)
            {
                var newSKU = new SKU
                {
                    MerchantID = WPModel.ChannelName,
                    HMNUM      = WPModel.SKU_HM_Relation.CMS_HMNUM.HMNUM,
                    SKUOrder   = WPModel.SKU,
                    SKUBest    = WPModel.SKU,
                    SellPack   = WPModel.SKU_HM_Relation.R_QTY / Convert.ToInt32(WPModel.SKU_HM_Relation.CMS_HMNUM.MasterPack),
                    //Description = WPModel.ProductName, eCom的Description其实是CMS的ProductName, 2014年4月9日
                    Description = WPModel.ProductName,
                    URL         = WPModel.URL,
                    UPC         = WPModel.UPC,
                    SHIPVIA     = WPModel.CMS_ShipViaType.CMS_ShipVia_Default.SHIPVIA,
                    Status      = WPModel.StatusName
                };
                db.SKU.Add(newSKU);

                db.SaveChanges();//!! 这里如果不保存,则SKUID =0 !!!

                //新增:SKU对应的Costing表
                db.Costing.Add(new Costing
                {
                    HMNUM          = newSKU.HMNUM,
                    MerchantID     = newSKU.MerchantID,
                    SKUID          = newSKU.SKUID,
                    SKUOrder       = newSKU.SKUOrder,
                    EffectiveDate  = WPModel.SKU_Costing.EffectiveDate,
                    Cost           = decimal.Parse(WPModel.SKU_Costing.SalePrice, NumberStyles.Currency, new CultureInfo("en-US")),
                    Coupon         = 0,//以后再做,Promo这一块 2014年4月24日11:53:47 (Boonie)
                    Retail         = WPModel.RetailPrice,
                    Freight        = decimal.Parse(WPModel.SKU_Costing.EstimateFreight, NumberStyles.Currency, new CultureInfo("en-US")),
                    MerchantCoupon = 0
                });
            }
            else
            {
                query.MerchantID = WPModel.ChannelName;
                query.HMNUM      = WPModel.SKU_HM_Relation.CMS_HMNUM.HMNUM;
                query.SKUOrder   = WPModel.SKU;
                query.SellPack   = WPModel.SKU_HM_Relation.R_QTY / Convert.ToInt32(WPModel.SKU_HM_Relation.CMS_HMNUM.MasterPack);
                //query.SellPack = WPModel.SKU_HM_Relation.CMS_HMNUM.IsGroup ? 1 : WPModel.SKU_HM_Relation.R_QTY;
                //query.Description = WPModel.ProductDesc;eCom的Description其实是CMS的ProductName, 2014年4月9日
                query.Description = WPModel.ProductName;
                query.URL         = WPModel.URL;
                query.UPC         = WPModel.UPC;
                //query.SHIPVIA = WPModel.CMS_ShipViaType.CMS_ShipVia_Default.SHIPVIA;

                //取出当前eCom.dbo.Costing表的数据
                var eComCostings = db.Costing.Where(s => s.SKUOrder == WPModel.SKU && s.MerchantID == WPModel.ChannelName && s.EffectiveDate != null);
                if (eComCostings.FirstOrDefault() == null)
                {
                    db.Costing.Add(new Costing
                    {
                        HMNUM          = query.HMNUM,
                        MerchantID     = query.MerchantID,
                        SKUID          = query.SKUID,
                        SKUOrder       = query.SKUOrder,
                        EffectiveDate  = WPModel.SKU_Costing.EffectiveDate,
                        Cost           = decimal.Parse(WPModel.SKU_Costing.SalePrice, NumberStyles.Currency, new CultureInfo("en-US")),
                        Coupon         = 0,//以后再做,Promo这一块 2014年4月24日11:53:47 (Boonie)
                        Retail         = WPModel.RetailPrice,
                        Freight        = decimal.Parse(WPModel.SKU_Costing.EstimateFreight, NumberStyles.Currency, new CultureInfo("en-US")),
                        MerchantCoupon = 0
                    });
                }
                else
                {
                    //如果已经存在并且不止一列,取出最大的那个时间点做比较
                    if (WPModel.SKU_Costing.EffectiveDate == eComCostings.Max(s => s.EffectiveDate).Value)//前面过滤了null值,所以这里不会出现null值了
                    {
                        //相等说明CMS没有做价格变动
                    }
                    else
                    {
                        //插入新的Costing
                        db.Costing.Add(new Costing
                        {
                            HMNUM          = query.HMNUM,
                            MerchantID     = query.MerchantID,
                            SKUID          = query.SKUID,
                            SKUOrder       = query.SKUOrder,
                            EffectiveDate  = WPModel.SKU_Costing.EffectiveDate,
                            Cost           = decimal.Parse(WPModel.SKU_Costing.SalePrice, NumberStyles.Currency, new CultureInfo("en-US")),
                            Coupon         = 0,//以后再做,Promo这一块 2014年4月24日11:53:47 (Boonie)
                            Retail         = WPModel.RetailPrice,
                            Freight        = decimal.Parse(WPModel.SKU_Costing.EstimateFreight, NumberStyles.Currency, new CultureInfo("en-US")),
                            MerchantCoupon = 0
                        });
                    }
                }

                //db.SaveChanges();为什么要在这里Save导致不能做transaction?2014年4月24日10:41:57
            }
        }
Пример #6
0
        /// <summary>
        /// Change1:既然文件类型的LOG已经记录了StackTrace,那么 数据库只要记录一个Message就足够了,不要再记录StackTrace了。2014年5月14日11:24:52
        /// </summary>
        /// <param name="model"></param>
        public void Processing(CMS_SKU_Model model)
        {
            HMNUMServices hmSvr  = new HMNUMServices();
            SKUServices   skuSvr = new SKUServices();

            IDictionary <string, string> ls = new Dictionary <string, string>();

            using (EcomEntities db = new EcomEntities())
            {
                try
                {
                    int UnitQTY = 0;
                    hmSvr.HMNUMGroup_Action(model, db, ref UnitQTY);
                    hmSvr.HMNUM_Action(model.SKU_HM_Relation.CMS_HMNUM, db, UnitQTY, model.Send2eComPath,
                                       decimal.Parse(model.SKU_Costing.EstimateFreight, NumberStyles.Currency, new CultureInfo("en-US")));
                    hmSvr.Carton_Action(model.SKU_HM_Relation.CMS_HMNUM, db);
                    skuSvr.SKU_Action(model, db);
                    skuSvr.SKUURL_Action(model, db);
                    db.SaveChanges();
                    UpdateStatus(model, "", 1, "Synchronized");
                    LogInsertEcom(model, "");
                }
                catch (DbEntityValidationException ex)
                {
                    var exMsg = String.Empty;

                    foreach (var eve in ex.EntityValidationErrors)
                    {
                        NBCMSLoggerManager.Error("");
                        NBCMSLoggerManager.Error("");
                        //HMLog.Error("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            string temp = string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage);
                            NBCMSLoggerManager.Error(temp);
                            exMsg += temp;
                        }
                        NBCMSLoggerManager.Error("");
                    }
                    exMsg += ex.Message + ":" + ex.StackTrace;
                    UpdateStatus(model, ex.Message, 2, "Failed");
                    LogInsertEcom(model, ex.Message);
                }
                catch (Exception ex)
                {
                    var  exMsg     = String.Empty;
                    bool isInnerEx = false;
                    if (ex.InnerException != null)
                    {
                        if (ex.InnerException.InnerException != null)
                        {
                            NBCMSLoggerManager.Error("InnerException.InnerException");
                            NBCMSLoggerManager.Error(ex.InnerException.InnerException.Message);
                            NBCMSLoggerManager.Error(ex.InnerException.InnerException.Source);
                            NBCMSLoggerManager.Error(ex.InnerException.InnerException.StackTrace);
                            NBCMSLoggerManager.Error("");
                            exMsg     = ex.InnerException.InnerException.Message;// +":" + ex.InnerException.InnerException.StackTrace;
                            isInnerEx = true;
                        }
                        if (!isInnerEx)
                        {
                            NBCMSLoggerManager.Error(ex.InnerException.Message);
                            NBCMSLoggerManager.Error(ex.InnerException.Source);
                            NBCMSLoggerManager.Error(ex.InnerException.StackTrace);
                            NBCMSLoggerManager.Error("");
                            exMsg = ex.InnerException.Message;// +":" + ex.InnerException.StackTrace;
                        }
                    }
                    if (!isInnerEx)
                    {
                        NBCMSLoggerManager.Error("");
                        NBCMSLoggerManager.Error(ex.Message);
                        NBCMSLoggerManager.Error(ex.StackTrace);
                        NBCMSLoggerManager.Error("");
                        exMsg = ex.Message;//+ ":" + ex.StackTrace;
                    }
                    UpdateStatus(model, exMsg, 2, "Failed");
                    LogInsertEcom(model, exMsg);
                }
            }
        }