Exemplo n.º 1
0
        /// <summary>添加日销售量
        /// </summary>
        /// <param name="orderInfo"></param>
        /// <param name="detailList"></param>
        /// <param name="dicAvgSettlePrice"></param>
        public void SaveGoodsDaySalesStatistics(GoodsOrderInfo orderInfo, IList <GoodsOrderDetailInfo> detailList, IDictionary <Guid, decimal> dicAvgSettlePrice)
        {
            if (orderInfo.HostingFilialeId == Guid.Empty)
            {
                orderInfo.HostingFilialeId = WMSSao.GetHostingFilialeIdByWarehouseIdGoodsTypes(orderInfo.DeliverWarehouseId, orderInfo.SaleFilialeId, detailList.Select(ent => ent.GoodsType).Distinct());
            }
            var goodsSeriesList = _goodsCenterSao.GetGoodsSeriesList(orderInfo.SaleFilialeId, detailList.Select(w => w.GoodsID).Distinct().ToList());
            //根据订单Id获取实际商品价格(参加促销活动的商品要抵扣相应的促销价,从而得到新的实际商品价格)
            Dictionary <Guid, decimal> dicGoodsPriceDict = _promotionSao.GetGoodsPriceDict(orderInfo.OrderId);

            var list = new List <GoodsDaySalesStatisticsInfo>();

            foreach (var goodsOrderDetailInfo in detailList)
            {
                var gdsinfo = new GoodsDaySalesStatisticsInfo
                {
                    DeliverWarehouseId = orderInfo.DeliverWarehouseId,
                    SaleFilialeId      = orderInfo.SaleFilialeId,
                    SalePlatformId     = orderInfo.SalePlatformId,
                    GoodsId            = goodsOrderDetailInfo.GoodsID,
                    RealGoodsId        = goodsOrderDetailInfo.RealGoodsID,
                    GoodsSales         = goodsOrderDetailInfo.Quantity,
                    DayTime            = orderInfo.OrderTime,
                    Specification      = goodsOrderDetailInfo.PurchaseSpecification,
                    SellPrice          = ((dicGoodsPriceDict != null && dicGoodsPriceDict.ContainsKey(goodsOrderDetailInfo.GoodsID)) ? dicGoodsPriceDict[goodsOrderDetailInfo.GoodsID] : goodsOrderDetailInfo.SellPrice) * (decimal)goodsOrderDetailInfo.Quantity,
                    GoodsName          = goodsOrderDetailInfo.GoodsName,
                    GoodsCode          = goodsOrderDetailInfo.GoodsCode,
                    ClassId            = Guid.Empty,
                    AvgSettlePrice     = ((dicAvgSettlePrice != null && dicAvgSettlePrice.Any() && dicAvgSettlePrice.ContainsKey(goodsOrderDetailInfo.GoodsID)) ? dicAvgSettlePrice[goodsOrderDetailInfo.GoodsID] : 0) * (decimal)goodsOrderDetailInfo.Quantity,
                    HostingFilialeId   = orderInfo.HostingFilialeId
                };
                if (goodsSeriesList != null && goodsSeriesList.Count > 0)
                {
                    var result = goodsSeriesList.FirstOrDefault(p => p.GoodsID.Equals(goodsOrderDetailInfo.GoodsID));
                    if (result != null)
                    {
                        gdsinfo.GoodsName = result.GoodsName;
                        gdsinfo.GoodsCode = result.GoodsCode;
                        gdsinfo.ClassId   = result.ClassID;
                        gdsinfo.BrandId   = result.BrandId;
                        gdsinfo.SeriesId  = result.SeriesId;
                    }
                }
                list.Add(gdsinfo);
            }
            _goodsOrderDetail.SaveGoodsSales(list);
        }
Exemplo n.º 2
0
        public int AddNewApplyStock(ApplyStockInfo applyStockInfo, IList <ApplyStockDetailInfo> applyStockDetailInfoList, IDictionary <Guid, decimal> settledics, out string errorMsg)
        {
            var isalliance = FilialeManager.IsAllianceShopFiliale(applyStockInfo.FilialeId, out errorMsg);

            if (isalliance)//联盟店
            {
                if (applyStockInfo.CompanyWarehouseId == Guid.Empty)
                {
                    applyStockInfo.PurchaseType = (int)PurchaseType.FromPurchase;
                }

                var filialeInfo = FilialeManager.Get(applyStockInfo.CompanyId);
                applyStockInfo.CompanyName = filialeInfo != null && filialeInfo.ID != Guid.Empty ? filialeInfo.Name : "-";

                //新增加盟店采购申请添加时待确认
                if (applyStockInfo.StockState >= (int)ApplyStockState.Delivering)
                {
                    var goodsIds   = applyStockDetailInfoList.Select(ent => ent.CompGoodsID).Distinct().ToList();
                    var goodsInfos = _goodsInfoSao.GetGoodsListByGoodsIds(goodsIds);
                    if (goodsInfos == null || goodsInfos.Count != goodsIds.Count)
                    {
                        errorMsg = "GMS商品信息获取失败";
                        return(-1);
                    }
                    var hostingFilialeId = WMSSao.GetHostingFilialeIdByWarehouseIdGoodsTypes(applyStockInfo.CompanyWarehouseId, applyStockInfo.CompanyId, goodsInfos.Select(ent => ent.GoodsType).Distinct());
                    if (hostingFilialeId == Guid.Empty)
                    {
                        errorMsg = "获取仓库对应的物流公司失败";
                        return(-1);
                    }
                    var flag = IsMatchSendCondition(applyStockInfo, applyStockDetailInfoList, hostingFilialeId, goodsInfos.ToDictionary(k => k.GoodsId, v => v), settledics, out errorMsg);
                    //确认不通过修改采购申请状态为等待确认
                    if (!flag)
                    {
                        applyStockInfo.StockState = (int)ApplyStockState.Confirming;
                    }
                }
            }
            if (_applyStockDao.Insert(applyStockInfo) && _applyStockDao.InsertDetail(applyStockDetailInfoList) > 0)
            {
                errorMsg = "";
                return(applyStockInfo.StockState);
            }
            errorMsg = "添加申请明细时失败";
            return(-1);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 新增门店采购单
        /// </summary>
        /// <param name="applyStockInfo"></param>
        /// <param name="applyStockDetailInfoList"></param>
        /// <param name="errorMsg"> </param>
        /// <returns>采购申请状态</returns>
        public int Add(ApplyStockInfo applyStockInfo, IList <ApplyStockDetailInfo> applyStockDetailInfoList, out string errorMsg)
        {
            int state = -1;

            try
            {
                var isalliance = FilialeManager.IsAllianceShopFiliale(applyStockInfo.FilialeId, out errorMsg);
                if (isalliance)//联盟店
                {
                    if (applyStockInfo.CompanyWarehouseId == Guid.Empty)
                    {
                        applyStockInfo.PurchaseType = (int)PurchaseType.FromPurchase;
                    }

                    var filialeInfo = FilialeManager.Get(applyStockInfo.CompanyId);
                    applyStockInfo.CompanyName = filialeInfo != null && filialeInfo.ID != Guid.Empty ? filialeInfo.Name : "-";

                    //新增加盟店采购申请添加时待确认
                    if (applyStockInfo.StockState >= (int)ApplyStockState.Delivering)
                    {
                        var goodsIds   = applyStockDetailInfoList.Select(ent => ent.CompGoodsID).Distinct().ToList();
                        var goodsInfos = _goodsInfoSao.GetGoodsListByGoodsIds(goodsIds);
                        if (goodsInfos == null || goodsInfos.Count != goodsIds.Count)
                        {
                            errorMsg = "GMS商品信息获取失败";
                            return(state);
                        }
                        var hostingFilialeId = WMSSao.GetHostingFilialeIdByWarehouseIdGoodsTypes(applyStockInfo.CompanyWarehouseId, applyStockInfo.CompanyId, goodsInfos.Select(ent => ent.GoodsType).Distinct());
                        if (hostingFilialeId == Guid.Empty)
                        {
                            errorMsg = "获取仓库对应的物流公司失败";
                            return(state);
                        }
                        var settleDics = _grossSettlementDal.GetLatestUnitPriceListByMultiGoods(hostingFilialeId, goodsIds);
                        var flag       = IsMatchSendCondition(applyStockInfo, applyStockDetailInfoList, hostingFilialeId, goodsInfos.ToDictionary(k => k.GoodsId, v => v), settleDics, out errorMsg);
                        //确认不通过修改采购申请状态为等待确认
                        if (!flag)
                        {
                            applyStockInfo.StockState = (int)ApplyStockState.Confirming;
                        }
                    }
                }
                using (var ts = new TransactionScope(TransactionScopeOption.Required))
                {
                    bool isSuccess = _applyStockDao.Insert(applyStockInfo);
                    if (isSuccess)
                    {
                        if (_applyStockDao.InsertDetail(applyStockDetailInfoList) > 0)
                        {
                            state = applyStockInfo.StockState;
                        }
                        else
                        {
                            isSuccess = false;
                            errorMsg  = "添加申请明细时失败";
                        }
                    }
                    else
                    {
                        errorMsg = "添加申请记录失败";
                    }
                    if (isSuccess)
                    {
                        ts.Complete();
                    }
                }
                return(state);
            }
            catch (Exception exp)
            {
                SAL.LogCenter.LogService.LogError(string.Format("新增采购申请报错: applyStockInfo={0}, applyStockDetailInfoList={1}", new Framework.Core.Serialize.JsonSerializer().Serialize(applyStockInfo), new Framework.Core.Serialize.JsonSerializer().Serialize(applyStockDetailInfoList)), "采购管理", exp);
                errorMsg = exp.Message;
                return(-1);
            }
        }
Exemplo n.º 4
0
        public bool UpdateApplyStockState(ApplyStockInfo applyInfo, int state, bool alliance, out IDictionary <Guid, decimal> settleDics, out string msg)
        {
            msg = string.Empty;
            var dics = new Dictionary <Guid, string>();

            settleDics = new Dictionary <Guid, decimal>();
            if (state == (int)ApplyStockState.Delivering && !alliance)
            {
                var detailList = FindDetailList(applyInfo.ApplyId);
                var goodsIds   = detailList.Select(ent => ent.CompGoodsID).Distinct().ToList();
                var goodsInfos = _goodsInfoSao.GetGoodsListByGoodsIds(goodsIds);
                if (goodsInfos == null || goodsInfos.Count != goodsIds.Count)
                {
                    msg = "GMS商品信息获取失败";
                    return(false);
                }
                var hostingFilialeId = WMSSao.GetHostingFilialeIdByWarehouseIdGoodsTypes(applyInfo.CompanyWarehouseId, applyInfo.CompanyId, goodsInfos.Select(ent => ent.GoodsType).Distinct());
                if (hostingFilialeId == Guid.Empty)
                {
                    msg = "获取仓库对应的物流公司失败";
                    return(false);
                }
                settleDics = _grossSettlementDal.GetLatestUnitPriceListByMultiGoods(hostingFilialeId, goodsIds);
                var result = IsMatchSendCondition(applyInfo, detailList, hostingFilialeId, goodsInfos.ToDictionary(k => k.GoodsId, v => v), settleDics, out msg);
                if (!result)
                {
                    //更新采购申请信息
                    state = (int)ApplyStockState.Confirming;
                    dics  = detailList.Where(act => act.IsComfirmed).ToDictionary(k => k.GoodsId, v => v.ComfirmTips);
                }
            }
            bool flag = _applyStockDao.UpdateApplyStockState(applyInfo.ApplyId, state);

            //修改明细中商品需确认标识
            if (flag && dics.Count > 0)
            {
                if (dics.Select(dic => _applyStockDao.UpdateDetailTips(applyInfo.ApplyId, dic.Key, dic.Value, true)).Any(result => !result))
                {
                    flag = false;
                }
            }
            if (!flag)
            {
                msg = "修改对应门店采购申请状态失败!";
            }
            else
            {
                if (alliance)
                {
                    string message;
                    var    parenId = FilialeManager.GetShopHeadFilialeId(applyInfo.FilialeId);
                    //联盟店备注格式:[XX]
                    var result = ShopSao.UpdatePurchaseState(parenId, applyInfo.ApplyId, state, string.Empty, out message);
                    if (!result)
                    {
                        msg  = message;
                        flag = false;
                    }
                }
            }
            return(flag);
        }
Exemplo n.º 5
0
        /// <summary>新架构完成订单创建所需往来账   2015-01-19  陈重文
        /// </summary>
        /// <param name="goodsOrderInfo">订单信息</param>
        /// <param name="goodsOrderDetailInfoList">订单明细</param>
        /// <param name="goodsOrderDeliverInfo">订单运费信息</param>
        /// <param name="errorMsg">错误信息</param>
        /// <returns></returns>
        public IEnumerable <ReckoningInfo> NewCreateReckoningInfoList(GoodsOrderInfo goodsOrderInfo, IList <GoodsOrderDetailInfo> goodsOrderDetailInfoList, out GoodsOrderDeliverInfo goodsOrderDeliverInfo, out string errorMsg)
        {
            if (goodsOrderInfo.HostingFilialeId == Guid.Empty)
            {
                goodsOrderInfo.HostingFilialeId = WMSSao.GetHostingFilialeIdByWarehouseIdGoodsTypes(goodsOrderInfo.DeliverWarehouseId, goodsOrderInfo.SaleFilialeId, goodsOrderDetailInfoList.Select(ent => ent.GoodsType).Distinct());
            }
            //所需添加的往来帐集合
            IList <ReckoningInfo> reckoningList = new List <ReckoningInfo>();

            goodsOrderDeliverInfo = null;
            var orderCarriageInfo = _wmsSao.GetOrderNoCarriage(goodsOrderInfo.OrderNo, out errorMsg);

            if (orderCarriageInfo == null)
            {
                return(reckoningList);
            }
            var carriage = orderCarriageInfo.Carriage;

            if (carriage != 0)
            {
                goodsOrderDeliverInfo = new GoodsOrderDeliverInfo
                {
                    OrderId       = goodsOrderInfo.OrderId,
                    TotalWeight   = orderCarriageInfo.PackageWeight == 0 ? 0 : Convert.ToDouble(orderCarriageInfo.PackageWeight) / 1000,
                    CarriageFee   = Convert.ToDouble(orderCarriageInfo.Carriage),
                    ExpressId     = goodsOrderInfo.ExpressId,
                    ExpressNo     = goodsOrderInfo.ExpressNo,
                    MaxWrongValue = 0,
                    ProvinceName  = orderCarriageInfo.Province,
                    CityName      = orderCarriageInfo.City
                };
            }

            #region [检查快递往来单位信息]

            Guid companyId = Express.Instance.Get(goodsOrderInfo.ExpressId).CompanyId;
            CompanyCussentInfo expressCompanyInfo = _companyCussent.GetCompanyCussent(companyId);
            if (expressCompanyInfo == null)
            {
                errorMsg = "快递公司的往来对账信息没有建立!";
                return(new List <ReckoningInfo>());
            }

            #endregion

            //获取销售公司名称
            string saleFilialeName    = FilialeManager.GetName(goodsOrderInfo.SaleFilialeId);
            string hostingFilialeName = FilialeManager.GetName(goodsOrderInfo.HostingFilialeId);
            #region [运费往来帐]
            if (carriage > 0)
            {
                #region [销售公司对快递公司应付快递运费帐]
                //销售公司对快递公司的应付快递运费帐
                var saleFilialeToCarriage = new ReckoningInfo
                {
                    ContructType       = ContructType.Insert,
                    ReckoningId        = Guid.NewGuid(),
                    TradeCode          = _codeManager.GetCode(CodeType.PY),
                    DateCreated        = DateTime.Now,
                    ReckoningType      = (int)ReckoningType.Defray,
                    State              = (int)ReckoningStateType.Currently,
                    IsChecked          = (int)CheckType.NotCheck,
                    AuditingState      = (int)AuditingState.Yes,
                    LinkTradeCode      = goodsOrderInfo.ExpressNo,
                    WarehouseId        = goodsOrderInfo.DeliverWarehouseId,
                    FilialeId          = goodsOrderInfo.HostingFilialeId,
                    ThirdCompanyID     = expressCompanyInfo.CompanyId,
                    Description        = string.Format("[完成订单,{0}对快递公司{1}运费应付款]", hostingFilialeName, expressCompanyInfo.CompanyName),
                    AccountReceivable  = -carriage,
                    JoinTotalPrice     = -carriage,
                    ReckoningCheckType = (int)ReckoningCheckType.Carriage,
                    IsOut              = goodsOrderInfo.IsOut,
                    LinkTradeType      = (int)ReckoningLinkTradeType.Express,
                };
                reckoningList.Add(saleFilialeToCarriage);
                #endregion
            }
            #endregion

            #region 销售公司对快递公司的订单代收帐

            if (goodsOrderInfo.PayMode == (int)PayMode.COD || goodsOrderInfo.PayMode == (int)PayMode.COM)
            {
                #region [销售公司对快递公司的订单代收帐]

                //销售公司对快递公司的订单代收帐
                var saleFilialeToRealTotalPrice = new ReckoningInfo
                {
                    ContructType       = ContructType.Insert,
                    ReckoningId        = Guid.NewGuid(),
                    TradeCode          = _codeManager.GetCode(CodeType.GT),
                    DateCreated        = DateTime.Now,
                    ReckoningType      = (int)ReckoningType.Income,
                    State              = (int)ReckoningStateType.Currently,
                    IsChecked          = (int)CheckType.NotCheck,
                    AuditingState      = (int)AuditingState.Yes,
                    LinkTradeCode      = goodsOrderInfo.ExpressNo,
                    WarehouseId        = goodsOrderInfo.DeliverWarehouseId,
                    FilialeId          = goodsOrderInfo.SaleFilialeId,
                    ThirdCompanyID     = expressCompanyInfo.CompanyId,
                    Description        = string.Format("[完成订单,{0}对快递公司{1}的订单应收货款]", saleFilialeName, expressCompanyInfo.CompanyName),
                    AccountReceivable  = WebRudder.ReadInstance.CurrencyValue(goodsOrderInfo.RealTotalPrice),
                    ReckoningCheckType = (int)ReckoningCheckType.Collection,
                    IsOut              = goodsOrderInfo.IsOut,
                    LinkTradeType      = (int)ReckoningLinkTradeType.GoodsOrder,
                };

                reckoningList.Add(saleFilialeToRealTotalPrice);
                #endregion
            }
            #endregion

            return(reckoningList);
        }
Exemplo n.º 6
0
        /// <summary> 售后更新日销量
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="afterSaleDetailList"></param>
        /// zal 2016-03-04
        /// 售后的商品在日销量表中单独插入一条负销量的数据,且插入销量的日期是退换货当天(需求1883)
        public void AfterSaleUpdateGoodsDaySalesStatistics(Guid orderId, IList <AfterSaleDetailInfo> afterSaleDetailList)
        {
            return;

            var list           = new List <GoodsDaySalesStatisticsInfo>();
            var goodsOrderInfo = _goodsOrderDal.GetGoodsOrder(orderId);

            if (goodsOrderInfo != null && goodsOrderInfo.OrderId != Guid.Empty)
            {
                var goodsOrderDetailList = _goodsOrderDetail.GetGoodsOrderDetailByOrderId(orderId);
                if (goodsOrderInfo.HostingFilialeId == Guid.Empty)
                {
                    goodsOrderInfo.HostingFilialeId = WMSSao.GetHostingFilialeIdByWarehouseIdGoodsTypes(goodsOrderInfo.DeliverWarehouseId, goodsOrderInfo.SaleFilialeId, goodsOrderDetailList.Select(ent => ent.GoodsType).Distinct());
                }
                #region 售后商品的价格,不在使用B2C传过来的价格,改从ERP这边取(原因:当商品做二次售后时,价格应该是0,而B2C每次传过来的价格都是原单的价格) zal 2016-03-18
                foreach (var item in afterSaleDetailList)
                {
                    var goodsOrderDetailInfo = goodsOrderDetailList.FirstOrDefault(p => p.RealGoodsID.Equals(item.RealGoodsId));
                    if (goodsOrderDetailInfo != null)
                    {
                        item.SellPrice = goodsOrderDetailInfo.SellPrice;
                    }
                }
                #endregion

                var goodsSeriesList = _goodsCenterSao.GetGoodsSeriesList(goodsOrderInfo.SaleFilialeId, afterSaleDetailList.Select(w => w.GoodsId).Distinct().ToList());
                //根据订单Id获取实际商品价格(参加促销活动的商品要抵扣相应的促销价,从而得到新的实际商品价格)
                Dictionary <Guid, decimal> dicGoodsPriceDict = _promotionSao.GetGoodsPriceDict(orderId);

                //获取指定时间下某公司的某商品的最近结算价
                var dicFilialeIdAndGoodsIdAvgSettlePrice = _realTimeGrossSettlementDal.GetFilialeIdGoodsIdAvgSettlePrice(goodsOrderInfo.OrderTime);

                foreach (var afterSaleDetailInfo in afterSaleDetailList)
                {
                    if (afterSaleDetailInfo.AgainCount == 0)
                    {
                        continue;
                    }
                    var gdsinfo = new GoodsDaySalesStatisticsInfo
                    {
                        DeliverWarehouseId = goodsOrderInfo.DeliverWarehouseId,
                        SaleFilialeId      = goodsOrderInfo.SaleFilialeId,
                        SalePlatformId     = goodsOrderInfo.SalePlatformId,
                        GoodsId            = afterSaleDetailInfo.GoodsId,
                        RealGoodsId        = afterSaleDetailInfo.RealGoodsId,
                        GoodsSales         = -afterSaleDetailInfo.AgainCount,
                        DayTime            = DateTime.Now,
                        Specification      = afterSaleDetailInfo.Specification,
                        SellPrice          = ((dicGoodsPriceDict != null && dicGoodsPriceDict.ContainsKey(afterSaleDetailInfo.GoodsId)) ? dicGoodsPriceDict[afterSaleDetailInfo.GoodsId] : afterSaleDetailInfo.SellPrice) * (-afterSaleDetailInfo.AgainCount),
                        GoodsName          = afterSaleDetailInfo.GoodsName,
                        GoodsCode          = afterSaleDetailInfo.GoodsCode,
                        ClassId            = Guid.Empty,
                        HostingFilialeId   = goodsOrderInfo.HostingFilialeId,
                        AvgSettlePrice     = ((dicFilialeIdAndGoodsIdAvgSettlePrice != null && dicFilialeIdAndGoodsIdAvgSettlePrice.Any() && dicFilialeIdAndGoodsIdAvgSettlePrice.ContainsKey(goodsOrderInfo.SaleFilialeId)) ? (dicFilialeIdAndGoodsIdAvgSettlePrice[goodsOrderInfo.SaleFilialeId].ContainsKey(afterSaleDetailInfo.GoodsId) ? dicFilialeIdAndGoodsIdAvgSettlePrice[goodsOrderInfo.SaleFilialeId][afterSaleDetailInfo.GoodsId] : 0) : 0) * (-afterSaleDetailInfo.AgainCount)
                    };
                    if (goodsSeriesList != null && goodsSeriesList.Count > 0)
                    {
                        var result = goodsSeriesList.FirstOrDefault(p => p.GoodsID.Equals(afterSaleDetailInfo.GoodsId));
                        if (result != null)
                        {
                            gdsinfo.ClassId   = result.ClassID;
                            gdsinfo.GoodsName = result.GoodsName;
                            gdsinfo.GoodsCode = result.GoodsCode;
                            gdsinfo.BrandId   = result.BrandId;
                            gdsinfo.SeriesId  = result.SeriesId;
                        }
                    }
                    list.Add(gdsinfo);
                }
            }
            _goodsOrderDetail.SaveGoodsSales(list, true);
        }
Exemplo n.º 7
0
        /// <summary>修改日销量
        /// </summary>
        /// <param name="orderInfo">订单</param>
        /// <param name="goodsOrderDetailInfos"></param>
        /// <param name="isUpdate">false、作废,true、修改</param>
        ///<param name="oldDetailInfos"></param>
        /// <param name="dicAvgSettlePrice"></param>
        public void UpdateGoodsDaySalesStatistics(GoodsOrderInfo orderInfo, IList <GoodsOrderDetailInfo> goodsOrderDetailInfos, bool isUpdate, IList <GoodsOrderDetailInfo> oldDetailInfos, IDictionary <Guid, decimal> dicAvgSettlePrice)
        {
            var list = new List <GoodsDaySalesStatisticsInfo>();

            if (orderInfo.HostingFilialeId == Guid.Empty)
            {
                orderInfo.HostingFilialeId = WMSSao.GetHostingFilialeIdByWarehouseIdGoodsTypes(orderInfo.DeliverWarehouseId, orderInfo.SaleFilialeId, goodsOrderDetailInfos.Select(ent => ent.GoodsType).Distinct());
            }
            var goodsSeriesList = _goodsCenterSao.GetGoodsSeriesList(orderInfo.SaleFilialeId, goodsOrderDetailInfos.Select(w => w.GoodsID).Distinct().ToList());
            //根据订单Id获取实际商品价格(参加促销活动的商品要抵扣相应的促销价,从而得到新的实际商品价格)
            Dictionary <Guid, decimal> dicGoodsPriceDict = _promotionSao.GetGoodsPriceDict(orderInfo.OrderId);

            #region 作废
            if (!isUpdate)  //作废
            {
                foreach (var goodsOrderDetailInfo in goodsOrderDetailInfos)
                {
                    var goodsDaySalesStatisticsInfo = new GoodsDaySalesStatisticsInfo
                    {
                        DeliverWarehouseId = orderInfo.DeliverWarehouseId,
                        SaleFilialeId      = orderInfo.SaleFilialeId,
                        SalePlatformId     = orderInfo.SalePlatformId,
                        GoodsId            = goodsOrderDetailInfo.GoodsID,
                        RealGoodsId        = goodsOrderDetailInfo.RealGoodsID,
                        GoodsSales         = -goodsOrderDetailInfo.Quantity,
                        DayTime            = orderInfo.OrderTime,
                        Specification      = goodsOrderDetailInfo.PurchaseSpecification,
                        SellPrice          = ((dicGoodsPriceDict != null && dicGoodsPriceDict.ContainsKey(goodsOrderDetailInfo.GoodsID)) ? dicGoodsPriceDict[goodsOrderDetailInfo.GoodsID] : goodsOrderDetailInfo.SellPrice) * (decimal) - goodsOrderDetailInfo.Quantity,
                        GoodsName          = goodsOrderDetailInfo.GoodsName,
                        GoodsCode          = goodsOrderDetailInfo.GoodsCode,
                        HostingFilialeId   = orderInfo.HostingFilialeId,
                        AvgSettlePrice     = ((dicAvgSettlePrice != null && dicAvgSettlePrice.Any() && dicAvgSettlePrice.ContainsKey(goodsOrderDetailInfo.GoodsID)) ? dicAvgSettlePrice[goodsOrderDetailInfo.GoodsID] : 0) * (decimal) - goodsOrderDetailInfo.Quantity
                    };
                    if (goodsSeriesList != null && goodsSeriesList.Count > 0)
                    {
                        var result = goodsSeriesList.FirstOrDefault(p => p.GoodsID.Equals(goodsOrderDetailInfo.GoodsID));
                        if (result != null)
                        {
                            goodsDaySalesStatisticsInfo.GoodsName = result.GoodsName;
                            goodsDaySalesStatisticsInfo.GoodsCode = result.GoodsCode;
                            goodsDaySalesStatisticsInfo.ClassId   = result.ClassID;
                            goodsDaySalesStatisticsInfo.BrandId   = result.BrandId;
                            goodsDaySalesStatisticsInfo.SeriesId  = result.SeriesId;
                        }
                    }
                    list.Add(goodsDaySalesStatisticsInfo);
                }
            }
            #endregion
            #region [修改]
            else  //修改
            {
                if (orderInfo.OrderState == (int)OrderState.StockUp)
                {
                    var oldGoodsDaySalesStatistics = new List <GoodsDaySalesStatisticsInfo>(); //修改前订单销量明细
                    var newGoodsDaySalesStatistics = new List <GoodsDaySalesStatisticsInfo>(); //修改后的订单销量明细
                    foreach (var goodsOrderDetailInfo in oldDetailInfos)                       //原始订单明细
                    {
                        var goodsDaySalesInfo = oldGoodsDaySalesStatistics.FirstOrDefault(act => act.RealGoodsId == goodsOrderDetailInfo.RealGoodsID);
                        if (goodsDaySalesInfo != null)
                        {
                            goodsDaySalesInfo.GoodsSales     += goodsOrderDetailInfo.Quantity;
                            goodsDaySalesInfo.SellPrice      += ((dicGoodsPriceDict != null && dicGoodsPriceDict.ContainsKey(goodsOrderDetailInfo.GoodsID)) ? dicGoodsPriceDict[goodsOrderDetailInfo.GoodsID] : goodsOrderDetailInfo.SellPrice) * (decimal)goodsOrderDetailInfo.Quantity;
                            goodsDaySalesInfo.AvgSettlePrice += ((dicAvgSettlePrice != null && dicAvgSettlePrice.Any() && dicAvgSettlePrice.ContainsKey(goodsOrderDetailInfo.GoodsID)) ? dicAvgSettlePrice[goodsOrderDetailInfo.GoodsID] : 0) * (decimal)goodsOrderDetailInfo.Quantity;
                        }
                        else
                        {
                            var gdsinfo = new GoodsDaySalesStatisticsInfo
                            {
                                DeliverWarehouseId = orderInfo.DeliverWarehouseId,
                                SaleFilialeId      = orderInfo.SaleFilialeId,
                                SalePlatformId     = orderInfo.SalePlatformId,
                                GoodsId            = goodsOrderDetailInfo.GoodsID,
                                RealGoodsId        = goodsOrderDetailInfo.RealGoodsID,
                                GoodsSales         = goodsOrderDetailInfo.Quantity,
                                DayTime            = orderInfo.OrderTime,
                                Specification      = goodsOrderDetailInfo.PurchaseSpecification,
                                SellPrice          = ((dicGoodsPriceDict != null && dicGoodsPriceDict.ContainsKey(goodsOrderDetailInfo.GoodsID)) ? dicGoodsPriceDict[goodsOrderDetailInfo.GoodsID] : goodsOrderDetailInfo.SellPrice) * (decimal)goodsOrderDetailInfo.Quantity,
                                GoodsName          = goodsOrderDetailInfo.GoodsName,
                                GoodsCode          = goodsOrderDetailInfo.GoodsCode,
                                ClassId            = Guid.Empty,
                                HostingFilialeId   = orderInfo.HostingFilialeId,
                                AvgSettlePrice     = ((dicAvgSettlePrice != null && dicAvgSettlePrice.Any() && dicAvgSettlePrice.ContainsKey(goodsOrderDetailInfo.GoodsID)) ? dicAvgSettlePrice[goodsOrderDetailInfo.GoodsID] : 0) * (decimal)goodsOrderDetailInfo.Quantity
                            };
                            oldGoodsDaySalesStatistics.Add(gdsinfo);
                        }
                    }
                    foreach (var goodsOrderDetailInfo in goodsOrderDetailInfos)  //当前销量
                    {
                        var goodsDaySalesInfo = newGoodsDaySalesStatistics.FirstOrDefault(act => act.RealGoodsId == goodsOrderDetailInfo.RealGoodsID);
                        if (goodsDaySalesInfo != null)
                        {
                            goodsDaySalesInfo.GoodsSales     += goodsOrderDetailInfo.Quantity;
                            goodsDaySalesInfo.SellPrice      += ((dicGoodsPriceDict != null && dicGoodsPriceDict.ContainsKey(goodsOrderDetailInfo.GoodsID)) ? dicGoodsPriceDict[goodsOrderDetailInfo.GoodsID] : goodsOrderDetailInfo.SellPrice) * (decimal)goodsOrderDetailInfo.Quantity;
                            goodsDaySalesInfo.AvgSettlePrice += ((dicAvgSettlePrice != null && dicAvgSettlePrice.Any() && dicAvgSettlePrice.ContainsKey(goodsOrderDetailInfo.GoodsID)) ? dicAvgSettlePrice[goodsOrderDetailInfo.GoodsID] : 0) * (decimal)goodsOrderDetailInfo.Quantity;
                        }
                        else
                        {
                            goodsDaySalesInfo = new GoodsDaySalesStatisticsInfo
                            {
                                DeliverWarehouseId = orderInfo.DeliverWarehouseId,
                                SaleFilialeId      = orderInfo.SaleFilialeId,
                                SalePlatformId     = orderInfo.SalePlatformId,
                                GoodsId            = goodsOrderDetailInfo.GoodsID,
                                RealGoodsId        = goodsOrderDetailInfo.RealGoodsID,
                                GoodsSales         = goodsOrderDetailInfo.Quantity,
                                DayTime            = orderInfo.OrderTime,
                                Specification      = goodsOrderDetailInfo.PurchaseSpecification,
                                SellPrice          = ((dicGoodsPriceDict != null && dicGoodsPriceDict.ContainsKey(goodsOrderDetailInfo.GoodsID)) ? dicGoodsPriceDict[goodsOrderDetailInfo.GoodsID] : goodsOrderDetailInfo.SellPrice) * (decimal)goodsOrderDetailInfo.Quantity,
                                GoodsName          = goodsOrderDetailInfo.GoodsName,
                                GoodsCode          = goodsOrderDetailInfo.GoodsCode,
                                ClassId            = Guid.Empty,
                                HostingFilialeId   = orderInfo.HostingFilialeId,
                                AvgSettlePrice     = ((dicAvgSettlePrice != null && dicAvgSettlePrice.Any() && dicAvgSettlePrice.ContainsKey(goodsOrderDetailInfo.GoodsID)) ? dicAvgSettlePrice[goodsOrderDetailInfo.GoodsID] : 0) * (decimal)goodsOrderDetailInfo.Quantity
                            };
                            newGoodsDaySalesStatistics.Add(goodsDaySalesInfo);
                        }
                    }
                    //修改后删除的商品
                    foreach (var goodsDaySalesStatisticsInfo in oldGoodsDaySalesStatistics)
                    {
                        var info = newGoodsDaySalesStatistics.All(act => act.RealGoodsId != goodsDaySalesStatisticsInfo.RealGoodsId);
                        if (info)
                        {
                            goodsDaySalesStatisticsInfo.GoodsSales     = -goodsDaySalesStatisticsInfo.GoodsSales;
                            goodsDaySalesStatisticsInfo.SellPrice      = -goodsDaySalesStatisticsInfo.SellPrice;
                            goodsDaySalesStatisticsInfo.AvgSettlePrice = -goodsDaySalesStatisticsInfo.AvgSettlePrice;
                            //_goodsOrderDetail.SaveGoodsSales(goodsDaySalesStatisticsInfo);
                            list.Add(goodsDaySalesStatisticsInfo);
                            //newGoodsDaySalesStatistics.Add(goodsDaySalesStatisticsInfo);
                        }
                    }

                    foreach (var goodsDaySalesStatisticsInfo in newGoodsDaySalesStatistics)
                    {
                        var info = oldGoodsDaySalesStatistics.FirstOrDefault(act => act.RealGoodsId == goodsDaySalesStatisticsInfo.RealGoodsId);
                        if (info != null)
                        {
                            goodsDaySalesStatisticsInfo.GoodsSales     -= info.GoodsSales;
                            goodsDaySalesStatisticsInfo.SellPrice      -= info.SellPrice;
                            goodsDaySalesStatisticsInfo.AvgSettlePrice -= info.AvgSettlePrice;
                        }
                        if (Math.Abs(goodsDaySalesStatisticsInfo.GoodsSales) > 0 || Math.Abs(goodsDaySalesStatisticsInfo.SellPrice) > 0)
                        {
                            if (oldGoodsDaySalesStatistics.All(act => act.RealGoodsId != goodsDaySalesStatisticsInfo.RealGoodsId))
                            {
                                if (goodsSeriesList != null && goodsSeriesList.Count > 0)
                                {
                                    var result = goodsSeriesList.FirstOrDefault(p => p.GoodsID.Equals(goodsDaySalesStatisticsInfo.GoodsId));
                                    if (result != null)
                                    {
                                        goodsDaySalesStatisticsInfo.GoodsName = result.GoodsName;
                                        goodsDaySalesStatisticsInfo.GoodsCode = result.GoodsCode;
                                        goodsDaySalesStatisticsInfo.ClassId   = result.ClassID;
                                        goodsDaySalesStatisticsInfo.BrandId   = result.BrandId;
                                        goodsDaySalesStatisticsInfo.SeriesId  = result.SeriesId;
                                    }
                                }
                            }
                            //_goodsOrderDetail.SaveGoodsSales(goodsDaySalesStatisticsInfo);
                            list.Add(goodsDaySalesStatisticsInfo);
                        }
                    }
                }
            }
            #endregion
            _goodsOrderDetail.SaveGoodsSales(list);
        }
Exemplo n.º 8
0
        /// <summary>订单导入
        /// </summary>
        public bool AddOrderAndInvoice(GoodsOrderInfo goodsOrder, IList <GoodsOrderDetailInfo> goodsOrderDetailList, InvoiceInfo invoiceInfo, out string errorMessage)
        {
            errorMessage = string.Empty;

            if (goodsOrderDetailList.Count == 0)
            {
                errorMessage = "订单明细没有数据!";
                return(false);
            }
            Boolean isEdit = false;

            #region 验证B2C订单信息  (订单目前是走推送服务)
            var filialeList = FilialeManager.GetB2CFilialeList();
            if (filialeList.Any(act => act.ID == goodsOrder.SaleFilialeId))
            {
                try
                {
                    var info = OrderSao.GetGoodsOrderInfo(goodsOrder.SaleFilialeId, goodsOrder.OrderId);
                    if (info == null)
                    {
                        errorMessage = "获取B2C订单信息不存在";
                        return(false);
                    }
                    if (info.OrderState == (int)OrderState.Cancellation)
                    {
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    errorMessage = "获取B2C订单信息异常" + ex.Message;
                    throw ex;
                }
            }
            #endregion

            var localGoodsOrderInfo = _goodsOrderDao.GetGoodsOrder(goodsOrder.OrderId);
            goodsOrder.HostingFilialeId = WMSSao.GetHostingFilialeIdByWarehouseIdGoodsTypes(goodsOrder.DeliverWarehouseId, goodsOrder.SaleFilialeId, goodsOrderDetailList.Select(ent => ent.GoodsType).Distinct());
            IList <GoodsOrderDetailInfo> localGoodsOrderDetails = new List <GoodsOrderDetailInfo>();
            if (localGoodsOrderInfo != null && localGoodsOrderInfo.OrderId != Guid.Empty)
            {
                isEdit = true;
                if (localGoodsOrderInfo.OrderState == (int)OrderState.Cancellation)
                {
                    return(true);
                }
                localGoodsOrderDetails = _goodsOrderDetailDao.GetGoodsOrderDetailList(goodsOrder.OrderId);
            }

            using (var ts = new TransactionScope(TransactionScopeOption.Required))
            {
                //1.订单导入,先删后插
                if (isEdit)
                {
                    var success = _goodsOrderDao.Delete(goodsOrder.OrderId);
                    if (!success)
                    {
                        errorMessage = "删除订单失败";
                        return(false);
                    }
                }

                //2.插入订单和订单明细
                var insertSuccess = _goodsOrderDao.Insert(goodsOrder, out errorMessage);
                if (!insertSuccess)
                {
                    errorMessage = string.Format("添加订单信息失败:{0}", errorMessage);
                    return(false);
                }
                var insertDetailSuccess = _goodsOrderDetailDao.Insert(goodsOrderDetailList, goodsOrder, out errorMessage);
                if (!insertDetailSuccess)
                {
                    errorMessage = string.Format("添加订单商品明细失败:{0}", errorMessage);
                    return(false);
                }

                //3.记录销量
                //异步销量
                if (goodsOrder.OrderState == (int)OrderState.WaitOutbound || goodsOrder.OrderState == (int)OrderState.StockUp || goodsOrder.OrderState == (int)OrderState.RequirePurchase || goodsOrder.OrderState == (int)OrderState.Redeploy)
                {
                    var orderJsonStr       = new Framework.Core.Serialize.JsonSerializer().Serialize(goodsOrder);
                    var orderDetailJsonStr = new Framework.Core.Serialize.JsonSerializer().Serialize(goodsOrderDetailList);
                    var asynGoodsDaySalesStatisticsInfo = isEdit ?
                                                          ASYN_GoodsDaySalesStatisticsInfo.EditGoodsDaySale(goodsOrder.OrderNo, orderJsonStr, orderDetailJsonStr, new Framework.Core.Serialize.JsonSerializer().Serialize(localGoodsOrderDetails)) :
                                                          ASYN_GoodsDaySalesStatisticsInfo.AddGoodsDaySale(goodsOrder.OrderNo, orderJsonStr, orderDetailJsonStr);
                    var asynResult = _goodsOrderDetailDao.InsertASYN_GoodsDaySalesStatisticsInfo(asynGoodsDaySalesStatisticsInfo);
                    if (!asynResult)
                    {
                        errorMessage = "销量记录到异步失败!";
                        return(false);
                    }
                }

                //4.发票插入
                if (invoiceInfo != null && invoiceInfo.InvoiceId != Guid.Empty)
                {
                    invoiceInfo.DeliverWarehouseId = goodsOrder.DeliverWarehouseId;
                    var insertInvoiceSuccess = _invoiceDao.Insert(invoiceInfo, new Dictionary <Guid, string> {
                        { goodsOrder.OrderId, goodsOrder.OrderNo }
                    });
                    if (!insertInvoiceSuccess)
                    {
                        errorMessage = "插入发票失败";
                        return(false);
                    }
                }
                //5.配货中,会员中心交互
                MemberCenterSao.OrderAllocateGoods(goodsOrder.SalePlatformId, goodsOrder.OrderId);
                //提交事务
                ts.Complete();
                return(true);
            }
        }