/// <summary>
        /// 修改商品属性状态
        /// </summary>
        /// <param name="skuId"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public bool ModifySkuStatus(int skuId, int checkSkuId, long userId, GoodsSkuInfoStatus status)
        {
            if (skuId <= 0)
            {
                return(false);
            }
            //需要逻辑删除的商品属性
            GoodsSkuInfo skuEntity = goodsSkuInfoRepository.GetByCache(w => w.Skuid == skuId, skuId);

            if (skuEntity == null && skuEntity.Skuid > 0)
            {
                return(false);
            }
            skuEntity.Status    = (int)status;
            skuEntity.IsDefault = false;
            //商品属性对应的商品信息
            GoodsInfo infoEntity = goodsInfoRepository.GetByCache(w => w.Goodsid == skuEntity.Goodsid, skuEntity.Goodsid);

            if (infoEntity == null && infoEntity.Goodsid > 0)
            {
                return(false);
            }

            //需要默认到商品信息上的商品属性
            GoodsSkuInfo checkEntity = goodsSkuInfoRepository.GetByCache(w => w.Skuid == checkSkuId, checkSkuId);

            if (checkEntity != null && checkEntity.Skuid > 0)
            {
                //将默认信息更新到商品上显示
                infoEntity.ImageUrl       = checkEntity.SkuImage;
                infoEntity.GoodsPrice     = checkEntity.SkuMaketPrice;
                infoEntity.GoodsRealPrice = checkEntity.SkuFactoryPrice;
            }
            //更新商品总库存
            infoEntity.Stock = infoEntity.Stock - skuEntity.Stock;
            //添加商品出库记录
            GoodsSkuInout inoutEntity = GoodsSkuInout.New();

            inoutEntity.Goodsid     = skuEntity.Goodsid;
            inoutEntity.Skuid       = skuEntity.Skuid;
            inoutEntity.InoutNumber = skuEntity.Stock;
            inoutEntity.IsOut       = true;
            inoutEntity.DateCreated = DateTime.Now;
            //操作记录以后调整为配置数据获取模板方式
            inoutEntity.Operation = string.Format("管理用户:{0}、删除商品属性:“{1}”、规格:“{2}”、损耗库存{3}、时间:{4}", userId, infoEntity.GoodsName, skuEntity.SkuName, inoutEntity.InoutNumber, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

            var result = goodsSkuInfoRepository.ModifySkuStatus(skuEntity, checkEntity, infoEntity, inoutEntity);

            if (result)
            {
                //删除成功后更新缓存
                goodsInfoRepository.UpdateCacheByEntity(infoEntity);
                goodsSkuInoutRepository.InsertCacheByEntity(inoutEntity);
            }
            return(result);
        }
        /// <summary>
        /// 新建
        /// </summary>
        public static GoodsSkuInout New()
        {
            GoodsSkuInout goodsSkuInout = new GoodsSkuInout();

            goodsSkuInout.Id          = 0;
            goodsSkuInout.Goodsid     = 0;
            goodsSkuInout.Skuid       = 0;
            goodsSkuInout.InoutNumber = 0;
            goodsSkuInout.IsOut       = false;
            goodsSkuInout.DateCreated = DateTime.UtcNow;
            return(goodsSkuInout);
        }
 /// <summary>
 /// Sku规格入库
 /// </summary>
 /// <param name="skuEntitys"></param>
 /// <param name="goodsId"></param>
 private void InoutGoodsLog(List <GoodsSkuInfo> skuEntitys, GoodsInfo infoEntity, long userId)
 {
     if (skuEntitys != null && infoEntity.Goodsid > 0)
     {
         List <GoodsSkuInout> inoutEntitys = new List <GoodsSkuInout>();
         foreach (var entity in skuEntitys)
         {
             GoodsSkuInout inoutEntity = GoodsSkuInout.New();
             entity.Goodsid = infoEntity.Goodsid;
             object objId = goodsSkuInfoRepository.AddByCache(entity, true);
             var    skuId = 0;
             int.TryParse(objId.ToString(), out skuId);
             inoutEntity.Goodsid     = infoEntity.Goodsid;
             inoutEntity.Skuid       = skuId;
             inoutEntity.InoutNumber = entity.Stock;
             inoutEntity.IsOut       = false;
             inoutEntity.DateCreated = DateTime.Now;
             inoutEntity.Operation   = string.Format("管理用户:{0}、发布商品属性:“{1}”、规格:“{2}”、入库{3}、 时间:{4}", userId, infoEntity.GoodsName, entity.SkuName, inoutEntity.InoutNumber, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
             inoutEntitys.Add(inoutEntity);
         }
         goodsSkuInoutRepository.AddByCache(inoutEntitys);
     }
 }
        /// <summary>
        /// 修改商品属性状态
        /// </summary>
        /// <param name="skuId"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public bool ModifySkuStatus(GoodsSkuInfo skuEntity, GoodsSkuInfo checkEntity, GoodsInfo infoEntity, GoodsSkuInout inoutEntity)
        {
            if (skuEntity == null)
            {
                return(false);
            }

            using (var db = DbService.GetInstance())
            {
                try
                {
                    db.BeginTran();
                    var result = db.Update <GoodsSkuInfo>(skuEntity);
                    if (checkEntity != null && checkEntity.Skuid > 0)
                    {
                        checkEntity.IsDefault = true;
                        db.Update <GoodsSkuInfo>(checkEntity);
                    }
                    if (result)
                    {
                        RealTimeCacheHelper.IncreaseAreaVersion("Goodsid", skuEntity.Goodsid);
                        db.Insert(inoutEntity, true);
                        db.Update <GoodsInfo>(new { stock = infoEntity.Stock }, w => w.Goodsid == infoEntity.Goodsid);

                        db.CommitTran();
                        return(true);
                    }
                    db.RollbackTran();
                    return(false);
                }
                catch
                {
                    db.RollbackTran();
                    return(false);
                }
            }
        }
        /// <summary>
        /// 设置商品属性
        /// </summary>
        public bool SetGoodsSkuInfo(GoodsInfo entity, List <GoodsSkuInfo> skuEntitys, long userId)
        {
            var errorCount = 0;
            List <GoodsSkuInout> inoutEntitys = new List <GoodsSkuInout>();
            var result = goodsInfoRepository.UpdateCache(entity);

            if (result)
            {
                goodsSkuInfoRepository.UpdateCacheByParame("Goodsid", entity.Goodsid);
                foreach (var skuEntity in skuEntitys)
                {
                    GoodsSkuInout inoutEntity = GoodsSkuInout.New();
                    inoutEntity.Goodsid     = entity.Goodsid;
                    inoutEntity.DateCreated = DateTime.Now;
                    GoodsSkuInfo goodsSkuInfo = goodsSkuInfoRepository.GetByCache(w => w.Skuid == skuEntity.Skuid, skuEntity.Skuid);
                    if (goodsSkuInfo != null && goodsSkuInfo.Skuid > 0)
                    {
                        if (goodsSkuInfo.Stock != skuEntity.Stock)
                        {
                            inoutEntity.Skuid       = skuEntity.Skuid;
                            inoutEntity.IsOut       = goodsSkuInfo.Stock - skuEntity.Stock > 0 ? true : false;
                            inoutEntity.InoutNumber = Math.Abs(goodsSkuInfo.Stock - skuEntity.Stock);
                            var formatOut = inoutEntity.IsOut ? "出库" + inoutEntity.InoutNumber : "入库" + inoutEntity.InoutNumber;
                            inoutEntity.Operation = string.Format("管理用户:{0}、编辑商品属性:“{1}”、规格:“{2}”、{3} 时间:{4}", userId, entity.GoodsName, skuEntity.SkuName, formatOut, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                            inoutEntitys.Add(inoutEntity);

                            result = goodsSkuInfoRepository.UpdateByEntity(skuEntity);
                            if (result)
                            {
                                if (!goodsSkuInoutRepository.AddByCache(inoutEntitys))
                                {
                                    errorCount++;
                                }
                                else
                                {
                                    if (!inoutEntity.IsOut)
                                    {
                                        entity.Stock += inoutEntity.InoutNumber;
                                    }
                                    else
                                    {
                                        if (entity.Stock - inoutEntity.InoutNumber < 0)
                                        {
                                            entity.Stock = 0;
                                        }
                                        else
                                        {
                                            entity.Stock -= inoutEntity.InoutNumber;
                                        }
                                    }

                                    if (!goodsInfoRepository.UpdateCache(entity, new { stock = entity.Stock }, w => w.Goodsid == entity.Goodsid))
                                    {
                                        errorCount++;
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (!goodsSkuInfoRepository.UpdateByEntity(skuEntity))
                            {
                                errorCount++;
                            }
                        }
                    }
                    else
                    {
                        object objId = goodsSkuInfoRepository.AddByCache(skuEntity, true);
                        var    skuId = 0;
                        int.TryParse(objId.ToString(), out skuId);
                        inoutEntity.Skuid       = skuId;
                        inoutEntity.IsOut       = false;
                        inoutEntity.InoutNumber = skuEntity.Stock;
                        inoutEntity.Operation   = string.Format("管理用户:{0}、新增商品属性:“{1}”、规格:“{2}”、入库{3}  时间:{4}", userId, entity.GoodsName, skuEntity.SkuName, inoutEntity.InoutNumber, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        inoutEntitys.Add(inoutEntity);
                        if (!goodsSkuInoutRepository.AddByCache(inoutEntitys))
                        {
                            errorCount++;
                        }
                        else
                        {
                            entity.Stock += skuEntity.Stock;
                            if (!goodsInfoRepository.UpdateCache(entity, new { stock = entity.Stock }, w => w.Goodsid == entity.Goodsid))
                            {
                                errorCount++;
                            }
                        }
                    }
                }
            }
            return(errorCount == 0 ? true : false);
        }