Exemple #1
0
        /// <summary>
        /// 恢复主单为待审核状态,并作废所有子单
        /// </summary>
        /// <param name="soSysNo">子单系统编号</param>
        /// <param name="companyCode"></param>
        /// <returns></returns>
        public void RestoreSOMaster()
        {
            SOInfo masterSO = CurrentSO;
            //查询所有子单
            List <SOInfo> subSOList = ObjectFactory <SOProcessor> .Instance.GetSubSOByMasterSOSysNo(CurrentSO.SysNo.Value);

            if (subSOList == null && subSOList.Count == 0)
            {
                BizExceptionHelper.Throw("SO_CancelSplit_NotExistSubSO");
                return;
            }

            //检查主单和子单的状态
            foreach (SOInfo subSO in subSOList)
            {
                if (subSO.BaseInfo.Status == SOStatus.Abandon ||
                    subSO.BaseInfo.Status == SOStatus.OutStock ||
                    subSO.BaseInfo.Status == SOStatus.Split)
                {
                    BizExceptionHelper.Throw("SO_CancelSplit_SubIsOutStock");
                }
            }
            if (masterSO.BaseInfo.Status != SOStatus.Split)
            {
                BizExceptionHelper.Throw("SO_CancelSplit_MasterSOStatusIsChanged");
            }

            List <SOBaseInfo> subSOBaseInfoList = subSOList.Select <SOInfo, SOBaseInfo>(subSOInfo => subSOInfo.BaseInfo).ToList();

            TransactionOptions options = new TransactionOptions();

            options.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                //重新创建主单积分日志
                if (masterSO.BaseInfo.PointPay > 0)
                {
                    ExternalDomainBroker.CancelSplitSOPoint(masterSO.BaseInfo, subSOBaseInfoList);
                }

                if (masterSO.BaseInfo.PrepayAmount > 0)
                {
                    ExternalDomainBroker.AdjustPrePay(new BizEntity.Customer.CustomerPrepayLog
                    {
                        AdjustAmount  = -CurrentSO.BaseInfo.PrepayAmount,
                        PrepayType    = ECCentral.BizEntity.Customer.PrepayType.SOPay,
                        SOSysNo       = SOSysNo,
                        Note          = "Res_SO_CancelSplit_MasterSOPrePay",
                        CustomerSysNo = CurrentSO.BaseInfo.CustomerSysNo
                    });

                    subSOList.ForEach(subSOInfo =>
                    {
                        if (subSOInfo.BaseInfo.PrepayAmount.Value != 0M)
                        {
                            ExternalDomainBroker.AdjustPrePay(new BizEntity.Customer.CustomerPrepayLog
                            {
                                AdjustAmount  = subSOInfo.BaseInfo.PrepayAmount,
                                PrepayType    = ECCentral.BizEntity.Customer.PrepayType.SOPay,
                                SOSysNo       = SOSysNo,
                                Note          = "Res_SO_CancelSplit_AbandonSubSOPrePay",
                                CustomerSysNo = subSOInfo.BaseInfo.CustomerSysNo
                            });
                        }
                    });
                }
                if (masterSO.BaseInfo.GiftCardPay > 0)
                {
                    Dictionary <int, List <ECCentral.BizEntity.IM.GiftCardRedeemLog> > subSOGiftCardDictionary = new Dictionary <int, List <ECCentral.BizEntity.IM.GiftCardRedeemLog> >();
                    subSOList.ForEach(subSOInfo =>
                    {
                        subSOGiftCardDictionary.Add(subSOInfo.SysNo.Value, subSOInfo.SOGiftCardList);
                    });
                    ExternalDomainBroker.CancelSplitSOGiftCard(masterSO.BaseInfo, subSOGiftCardDictionary);
                }

                //款到发货订单,恢复主单NetPay记录
                if (!masterSO.BaseInfo.PayWhenReceived.Value)
                {
                    ExternalDomainBroker.CancelSplitSOIncome(masterSO.BaseInfo, subSOBaseInfoList);
                }

                SODA.UpdateSOStatus(new SOStatusChangeInfo
                {
                    ChangeTime    = DateTime.Now,
                    OldStatus     = masterSO.BaseInfo.Status,
                    Status        = SOStatus.Origin,
                    OperatorType  = ServiceContext.Current.UserSysNo == 0 ? SOOperatorType.System : SOOperatorType.User,
                    OperatorSysNo = ServiceContext.Current.UserSysNo,
                    SOSysNo       = CurrentSO.SysNo
                });
                masterSO.BaseInfo.Status = SOStatus.Origin;
                foreach (SOInfo subSO in subSOList)
                {
                    SODA.UpdateSOStatus(new SOStatusChangeInfo
                    {
                        ChangeTime    = DateTime.Now,
                        OldStatus     = subSO.BaseInfo.Status,
                        Status        = SOStatus.Abandon,
                        OperatorType  = ServiceContext.Current.UserSysNo == 0 ? SOOperatorType.System : SOOperatorType.User,
                        OperatorSysNo = ServiceContext.Current.UserSysNo,
                        SOSysNo       = subSO.SysNo
                    });
                }

                scope.Complete();
            }

            SendMsgToWMS(subSOList);
        }