Пример #1
0
        /// <summary>
        /// 处理商品销量库存
        /// </summary>
        /// <param name="orderId">订单ID</param>
        /// <param name="inoutDetailList">订单明细</param>
        /// <param name="actionType">操作类型 1=提交订单;2=取消订单</param>
        /// <param name="loggingSessionInfo"></param>
        public void SetStock(string orderId, IList <InoutDetailInfo> inoutDetailList, int actionType, LoggingSessionInfo loggingSessionInfo)
        {
            var itemPropertyBLL = new T_Item_PropertyBLL(loggingSessionInfo);
            var skuPriceBLL     = new T_Sku_PriceBLL(loggingSessionInfo);

            var inoutService = new InoutService(loggingSessionInfo);

            foreach (var item in inoutDetailList)
            {
                //商品总库存
                var stockInfo = itemPropertyBLL.QueryByEntity(new T_Item_PropertyEntity()
                {
                    item_id = item.item_id, prop_id = "34FF4445D39F49AD8174954D18BC1346"
                }, null).FirstOrDefault();
                if (stockInfo != null)
                {
                    decimal stock = decimal.Parse(stockInfo.prop_value);
                    if (actionType == 1)
                    {
                        stock -= item.enter_qty;
                    }
                    else if (actionType == 2)
                    {
                        stock += item.enter_qty;
                    }
                    stockInfo.prop_value = stock.ToString();
                    itemPropertyBLL.Update(stockInfo);
                }
                //商品总销量
                var salesCountInfo = itemPropertyBLL.QueryByEntity(new T_Item_PropertyEntity()
                {
                    item_id = item.item_id, prop_id = "34FF4445D39F49AD8174954D18BC1347"
                }, null).FirstOrDefault();
                if (salesCountInfo != null)
                {
                    decimal salesCount = decimal.Parse(salesCountInfo.prop_value);
                    if (actionType == 1)
                    {
                        salesCount += item.enter_qty;
                    }
                    else if (actionType == 2)
                    {
                        salesCount -= item.enter_qty;
                    }

                    salesCountInfo.prop_value = salesCount.ToString();
                    itemPropertyBLL.Update(salesCountInfo);
                }
                //sku库存
                var skuStockInfo = skuPriceBLL.QueryByEntity(new T_Sku_PriceEntity()
                {
                    sku_id = item.sku_id, item_price_type_id = "77850286E3F24CD2AC84F80BC625859E", status = "1"
                }, null).FirstOrDefault();
                if (skuStockInfo != null)
                {
                    if (actionType == 1)
                    {
                        skuStockInfo.sku_price -= item.enter_qty;
                    }
                    else if (actionType == 2)
                    {
                        skuStockInfo.sku_price += item.enter_qty;
                    }

                    skuPriceBLL.Update(skuStockInfo);
                }
                //sku销量
                var skuSalesCountInfo = skuPriceBLL.QueryByEntity(new T_Sku_PriceEntity()
                {
                    sku_id = item.sku_id, item_price_type_id = "77850286E3F24CD2AC84F80BC625859f", status = "1"
                }, null).FirstOrDefault();
                if (skuSalesCountInfo != null)
                {
                    if (actionType == 1)
                    {
                        skuSalesCountInfo.sku_price += item.enter_qty;
                    }
                    else
                    {
                        skuSalesCountInfo.sku_price -= item.enter_qty;
                    }

                    skuPriceBLL.Update(skuSalesCountInfo);
                }
            }
        }