コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <summary>
        /// 新建
        /// </summary>
        public static GoodsSkuInfo New()
        {
            GoodsSkuInfo goodsSkuInfo = new GoodsSkuInfo();

            goodsSkuInfo.Skuid            = 0;
            goodsSkuInfo.Goodsid          = 0;
            goodsSkuInfo.SkuName          = string.Empty;
            goodsSkuInfo.SkuOriginalPrice = decimal.Zero;
            goodsSkuInfo.SkuMaketPrice    = decimal.Zero;
            goodsSkuInfo.SkuFactoryPrice  = decimal.Zero;
            goodsSkuInfo.SkuVipPrice      = decimal.Zero;
            goodsSkuInfo.Stock            = 0;
            return(goodsSkuInfo);
        }
コード例 #3
0
        /// <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);
        }