protected override EmptyResponseData ProcessRequest(APIRequest <SetSuperRetailTraderItemStatusRP> pRequest)
        {
            SetSuperRetailTraderItemStatusRP rp = pRequest.Parameters;
            EmptyResponseData rd = new EmptyResponseData();

            var superRetailTraderItemMappingBll = new T_SuperRetailTraderItemMappingBLL(CurrentUserInfo);
            var superRetailTraderSkuMappingBll  = new T_SuperRetailTraderSkuMappingBLL(CurrentUserInfo);

            List <SuperRetailTraderItem> ItemIdList = rp.ItemIdList.GroupBy(n => new { n.ItemId }).Select(n => new SuperRetailTraderItem()
            {
                ItemId        = n.Key.ItemId,
                IsAllSelected = n.Min(t => t.IsAllSelected), // IsAllSelected = 0(不是移除,上架,下架该商品的所有Sku)
            }).ToList();

            List <SuperRetailTraderItem> SkuIdList = rp.ItemIdList.Select(n => new SuperRetailTraderItem()
            {
                ItemId = n.ItemId, SkuId = n.SkuId
            }).ToList();

            if (rp.Status == 10) //上架操作
            {
                //商品上架
                foreach (var item in ItemIdList)
                {
                    var entity = superRetailTraderItemMappingBll.QueryByEntity(new T_SuperRetailTraderItemMappingEntity()
                    {
                        ItemId = item.ItemId, CustomerID = CurrentUserInfo.ClientID, Status = 90
                    }, null).FirstOrDefault();
                    if (entity != null)
                    {
                        entity.Status           = 10;
                        entity.OffShelfDatetime = DateTime.Now;
                        superRetailTraderItemMappingBll.Update(entity);
                    }
                }
                //Sku上架
                foreach (var sku in SkuIdList)
                {
                    var entity = superRetailTraderSkuMappingBll.QueryByEntity(new T_SuperRetailTraderSkuMappingEntity()
                    {
                        SkuId = sku.SkuId, ItemId = sku.ItemId, CustomerID = CurrentUserInfo.ClientID, Status = 90
                    }, null).FirstOrDefault();
                    if (entity != null)
                    {
                        entity.Status           = 10;
                        entity.OffShelfDatetime = DateTime.Now;
                        superRetailTraderSkuMappingBll.Update(entity);
                    }
                }
            }

            if (rp.Status == 90) //下架操作
            {
                //Sku下架
                foreach (var sku in SkuIdList)
                {
                    var entity = superRetailTraderSkuMappingBll.QueryByEntity(new T_SuperRetailTraderSkuMappingEntity()
                    {
                        SkuId = sku.SkuId, ItemId = sku.ItemId, CustomerID = CurrentUserInfo.ClientID, Status = 10
                    }, null).FirstOrDefault();
                    if (entity != null)
                    {
                        entity.Status           = 90;
                        entity.OffShelfDatetime = DateTime.Now;
                        superRetailTraderSkuMappingBll.Update(entity);
                    }
                }
                //商品下架
                foreach (var item in ItemIdList)
                {
                    var skuEntity = superRetailTraderSkuMappingBll.QueryByEntity(new T_SuperRetailTraderSkuMappingEntity()
                    {
                        ItemId = item.ItemId, CustomerID = CurrentUserInfo.ClientID, Status = 10
                    }, null);
                    var entity = superRetailTraderItemMappingBll.QueryByEntity(new T_SuperRetailTraderItemMappingEntity()
                    {
                        ItemId = item.ItemId, CustomerID = CurrentUserInfo.ClientID, Status = 10
                    }, null).FirstOrDefault();
                    if (entity != null && skuEntity.Count() == 0) //所有sku下架
                    {
                        entity.Status           = 90;
                        entity.OffShelfDatetime = DateTime.Now;
                        superRetailTraderItemMappingBll.Update(entity);
                    }
                }
            }
            if (rp.Status == 0) //移除操作
            {
                //sku移除
                foreach (var sku in SkuIdList)
                {
                    var entity = superRetailTraderSkuMappingBll.QueryByEntity(new T_SuperRetailTraderSkuMappingEntity()
                    {
                        SkuId = sku.SkuId, ItemId = sku.ItemId, CustomerID = CurrentUserInfo.ClientID
                    }, null).FirstOrDefault();
                    if (entity != null)
                    {
                        superRetailTraderSkuMappingBll.Delete(entity);
                    }
                }
                //商品移除
                foreach (var item in ItemIdList)
                {
                    var skuEntity = superRetailTraderSkuMappingBll.QueryByEntity(new T_SuperRetailTraderSkuMappingEntity()
                    {
                        ItemId = item.ItemId, CustomerID = CurrentUserInfo.ClientID
                    }, null);
                    var entity = superRetailTraderItemMappingBll.QueryByEntity(new T_SuperRetailTraderItemMappingEntity()
                    {
                        ItemId = item.ItemId, CustomerID = CurrentUserInfo.ClientID
                    }, null).FirstOrDefault();
                    if (entity != null && skuEntity.Count() == 0) //sku全部移除
                    {
                        superRetailTraderItemMappingBll.Delete(entity);
                    }
                }
            }
            return(rd);
        }
Beispiel #2
0
        protected override EmptyResponseData ProcessRequest(APIRequest <SetSuperRetailTraderItemRP> pRequest)
        {
            SetSuperRetailTraderItemRP rp = pRequest.Parameters;

            var superRetailTraderItemMappingBll = new T_SuperRetailTraderItemMappingBLL(CurrentUserInfo);
            var superRetailTraderSkuMappingBll  = new T_SuperRetailTraderSkuMappingBLL(CurrentUserInfo);

            List <ItemIdInfo> ItemIdList = rp.ItemIdList.GroupBy(n => new{ n.ItemId }).Select(n => new ItemIdInfo()
            {
                ItemId = n.Key.ItemId
            }).ToList();

            List <ItemIdInfo> SkuIdList = rp.ItemIdList.Select(n => new ItemIdInfo()
            {
                ItemId = n.ItemId, SkuId = n.SkuId
            }).ToList();

            //初始化分销商商品信息
            foreach (var item in ItemIdList)
            {
                var itemEntity = superRetailTraderItemMappingBll.QueryByEntity(new T_SuperRetailTraderItemMappingEntity {
                    ItemId = item.ItemId
                }, null).FirstOrDefault();
                if (itemEntity == null)
                {
                    T_SuperRetailTraderItemMappingEntity superRetailTraderItemMappingEntity = new T_SuperRetailTraderItemMappingEntity()
                    {
                        SuperRetailTraderItemMappingId = Guid.NewGuid(),
                        ItemId               = item.ItemId,
                        DistributerStock     = 0,
                        SalesQty             = 0,
                        DistributerCostPrice = 0,
                        DistributerPrice     = 0,
                        Status               = 90,
                        OnShelfDatetime      = DateTime.Now,
                        CustomerID           = CurrentUserInfo.ClientID
                    };
                    superRetailTraderItemMappingBll.Create(superRetailTraderItemMappingEntity);
                    itemEntity = superRetailTraderItemMappingEntity;
                }
                //初始化分销商Sku信息
                foreach (var sku in SkuIdList.Where(n => n.ItemId == item.ItemId))
                {
                    var SkuEntity = superRetailTraderSkuMappingBll.QueryByEntity(new T_SuperRetailTraderSkuMappingEntity {
                        SkuId = sku.SkuId
                    }, null);
                    if (SkuEntity.Count() == 0)
                    {
                        T_SuperRetailTraderSkuMappingEntity superRetailTraderSkuMappingEntity = new T_SuperRetailTraderSkuMappingEntity()
                        {
                            Id = Guid.NewGuid(),
                            SuperRetailTraderItemMappingId = itemEntity.SuperRetailTraderItemMappingId,
                            ItemId               = item.ItemId,
                            SkuId                = sku.SkuId,
                            DistributerStock     = 0,
                            SalesQty             = 0,
                            DistributerCostPrice = 0,
                            Status               = 90,
                            OnShelfDatetime      = DateTime.Now,
                            CustomerID           = CurrentUserInfo.ClientID
                        };
                        superRetailTraderSkuMappingBll.Create(superRetailTraderSkuMappingEntity);
                    }
                }
            }
            return(new EmptyResponseData());
        }
        protected override EmptyResponseData ProcessRequest(APIRequest <SetSuperRetailTraderItemInfoRP> pRequest)
        {
            SetSuperRetailTraderItemInfoRP rp = pRequest.Parameters;
            EmptyResponseData rd = new EmptyResponseData();

            var superRetailTraderItemMappingBll = new T_SuperRetailTraderItemMappingBLL(CurrentUserInfo);
            var superRetailTraderSkuMappingBll  = new T_SuperRetailTraderSkuMappingBLL(CurrentUserInfo);

            List <SuperRetailTraderItem> ItemIdList = rp.ItemList.GroupBy(n => new { n.ItemId }).Select(n => new SuperRetailTraderItem()
            {
                ItemId               = n.Key.ItemId,
                DistributerStock     = n.Sum(t => t.DistributerStock),
                DistributerCostPrice = n.Min(t => t.DistributerCostPrice)
            }).ToList();
            List <SuperRetailTraderItem> SkuIdList = rp.ItemList.Select(n => n).ToList();

            //修改商品成本价和库存
            foreach (var item in ItemIdList)
            {
                //获取商品信息
                var entity = superRetailTraderItemMappingBll.QueryByEntity(new T_SuperRetailTraderItemMappingEntity()
                {
                    ItemId = item.ItemId, CustomerID = CurrentUserInfo.ClientID
                }, null).FirstOrDefault();
                if (entity != null)
                {
                    if (entity.DistributerStock == 0 && entity.DistributerCostPrice == 0) //如果是初始化数据,直接修改
                    {
                        entity.DistributerStock     = item.DistributerStock;
                        entity.DistributerCostPrice = item.DistributerCostPrice;
                        superRetailTraderItemMappingBll.Update(entity);
                    }
                    else //如果是非初始化数据,创建新的,删除旧的
                    {
                        T_SuperRetailTraderItemMappingEntity newEntity = new T_SuperRetailTraderItemMappingEntity()
                        {
                            SuperRetailTraderItemMappingId = Guid.NewGuid(),
                            ItemId               = item.ItemId,
                            DistributerStock     = item.DistributerStock + entity.SalesQty,
                            SalesQty             = entity.SalesQty,
                            DistributerCostPrice = item.DistributerCostPrice,
                            DistributerPrice     = entity.DistributerPrice,
                            Status               = entity.Status,
                            OnShelfDatetime      = entity.OnShelfDatetime,
                            OffShelfDatetime     = entity.OffShelfDatetime,
                            CustomerID           = CurrentUserInfo.ClientID
                        };
                        superRetailTraderItemMappingBll.Delete(entity);
                        superRetailTraderItemMappingBll.Create(newEntity);
                    }
                }
            }
            //修改Sku成本价和库存
            foreach (var sku in SkuIdList)
            {
                var entity = superRetailTraderSkuMappingBll.QueryByEntity(new T_SuperRetailTraderSkuMappingEntity()
                {
                    SkuId = sku.SkuId, ItemId = sku.ItemId, CustomerID = CurrentUserInfo.ClientID
                }, null).FirstOrDefault();
                if (entity != null)
                {
                    if (entity.DistributerStock == 0 && entity.DistributerCostPrice == 0) //如果是初始化数据,直接修改
                    {
                        entity.DistributerStock     = sku.DistributerStock;
                        entity.DistributerCostPrice = sku.DistributerCostPrice;
                        superRetailTraderSkuMappingBll.Update(entity);
                    }
                    else //如果是非初始化数据,创建新的,删除旧的
                    {
                        T_SuperRetailTraderSkuMappingEntity newEntity = new T_SuperRetailTraderSkuMappingEntity()
                        {
                            SuperRetailTraderItemMappingId = entity.SuperRetailTraderItemMappingId,
                            ItemId               = entity.ItemId,
                            SkuId                = entity.SkuId,
                            DistributerStock     = sku.DistributerStock + entity.SalesQty,
                            SalesQty             = entity.SalesQty,
                            DistributerCostPrice = sku.DistributerCostPrice,
                            RefId                = entity.SuperRetailTraderItemMappingId,
                            Status               = entity.Status,
                            OnShelfDatetime      = entity.OnShelfDatetime,
                            OffShelfDatetime     = entity.OffShelfDatetime,
                            CustomerID           = CurrentUserInfo.ClientID
                        };
                        superRetailTraderSkuMappingBll.Delete(entity);
                        superRetailTraderSkuMappingBll.Create(newEntity);
                    }
                }
            }

            return(rd);
        }