Beispiel #1
0
        public virtual void Split()
        {
            SubSOList = new List <SOInfo>();
            //  1.  效验是否满足基本拆分条件
            Precheck();

            //拆当前订单
            SplitCurrentSO();

            // 子订单分摊计算
            CalculateSubSO(SubSOList);

            #region 保存订单信息到数据库

            // 保存订单信息到数据库
            TransactionOptions options = new TransactionOptions();
            options.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                #region 保存主订单信息
                SOStatusChangeInfo statusChangeInfo = new SOStatusChangeInfo
                {
                    ChangeTime    = DateTime.Now,
                    OldStatus     = CurrentSO.BaseInfo.Status.Value,
                    OperatorSysNo = ServiceContext.Current.UserSysNo,
                    OperatorType  = SOOperatorType.User,
                    Status        = SOStatus.Split,
                    SOSysNo       = CurrentSO.SysNo
                };
                //更新主单状态
                if (!SODA.UpdateSOStatusToSplit(statusChangeInfo))
                {
                    BizExceptionHelper.Throw("SO_Split_SOStatus_NotOriginal");
                }
                //更新主单标记为已拆分
                CurrentSO.BaseInfo.Status = SOStatus.Split;
                #endregion

                //插入子单数据到数据库
                foreach (SOInfo subSOInfo in SubSOList)
                {
                    SaveSubSO(subSOInfo);
                }
                #region 调整订单相关日志
                //调整礼品卡使用日志
                List <SOBaseInfo> subSOBaseInfoList = SubSOList.Select <SOInfo, SOBaseInfo>(subSOInfo => subSOInfo.BaseInfo).ToList();
                if (CurrentSO.SOGiftCardList.Count > 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.SplitSOGiftCard(CurrentSO.BaseInfo, subSOGiftCardDictionary);
                }

                //调整积分
                //调整余额支付
                //作废主单积分日志
                if (CurrentSO.BaseInfo.PointPay > 0)
                {
                    ExternalDomainBroker.SplitSOPoint(CurrentSO.BaseInfo, subSOBaseInfoList);
                }

                //作废主单余额日志
                if (CurrentSO.BaseInfo.PrepayAmount > 0)
                {
                    ExternalDomainBroker.AdjustPrePay(new BizEntity.Customer.CustomerPrepayLog
                    {
                        AdjustAmount  = CurrentSO.BaseInfo.PrepayAmount,
                        PrepayType    = ECCentral.BizEntity.Customer.PrepayType.SOPay,
                        SOSysNo       = SOSysNo,
                        Note          = "拆分订单,作废主订单余额支付",
                        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          = "拆分订单,子订单使用余额支付",
                                CustomerSysNo = subSOInfo.BaseInfo.CustomerSysNo
                            });
                        }
                    });
                }

                //如果是款到发货订单,拆分NetPay
                if (!CurrentSO.BaseInfo.PayWhenReceived.Value)
                {
                    ExternalDomainBroker.SplitSOIncome(CurrentSO.BaseInfo, subSOBaseInfoList);
                }
                #endregion
                scope.Complete();
            }
            #endregion
            //给客户发拆分邮件
            ObjectFactory <SOSendMessageProcessor> .Instance.SendSplitSOEmail(CurrentSO, SubSOList);

            if (IsAutoSplit)
            {
                foreach (SOInfo subSO in SubSOList)
                {
                    SOAction soAction = SOActionFactory.Create(new SOCommandInfo {
                        Command = SOCommand.Audit, SOInfo = subSO
                    });
                    if (soAction is SOAudit)
                    {
                        (soAction as SOAudit).SendMessage();
                    }
                }
            }
            //记录增票更改日志记录
            if (CurrentSO.InvoiceInfo.IsVAT.Value)
            {
                WriteSOChangeVATLog(SubSOList);
            }

            //记日志
            WriteLog();
        }
Beispiel #2
0
 /// <summary>
 /// 处理订单
 /// </summary>
 /// <param name="soInfo"></param>
 /// <param name="command"></param>
 public void ProcessSO(SOAction.SOCommandInfo command)
 {
     SOActionFactory.Create(command).Do();
 }