Exemple #1
0
 /// <summary>
 /// 取消积分支付,返还积分
 /// </summary>
 protected virtual void CancelPointPay()
 {
     if (CurrentSO.BaseInfo.PointPay > 0)
     {
         ExternalDomainBroker.AdjustPoint(new BizEntity.Customer.AdjustPointRequest
         {
             CustomerSysNo = CurrentSO.BaseInfo.CustomerSysNo,
             Point         = CurrentSO.BaseInfo.PointPay,
             PointType     = (int)ECCentral.BizEntity.Customer.AdjustPointType.AbandonSO,
             SOSysNo       = SOSysNo,
             Memo          = ResourceHelper.Get("Res_SO_Abandon_AdjustPoint"),
             Source        = SOConst.DomainName,
             OperationType = ECCentral.BizEntity.Customer.AdjustPointOperationType.Abandon,
         });
     }
 }
        //关闭订单
        /// <summary>
        /// 关闭订单
        /// </summary>
        /// <param name="soSysNo">订单编号</param>
        public virtual void Close(int soSysNo)
        {
            SOPending oldEntity = ObjectFactory <ISOPendingDA> .Instance.GetBySysNo(soSysNo);

            if (oldEntity == null)
            {
                //不存在的单据
                BizExceptionHelper.Throw("SO_Pending_UnknowOrder");
            }
            if (oldEntity.Status != SOPendingStatus.Complete)
            {
                m_da.UpdateSOPendingStatus(soSysNo, SOPendingStatus.Complete);
                ExternalDomainBroker.WriteBizLog(ResourceHelper.Get("SO_Pending_CloseLogFormat", oldEntity.SOSysNo)
                                                 , BizLogType.Sale_SO_Update
                                                 , oldEntity.SOSysNo.Value
                                                 , oldEntity.CompanyCode);
            }
        }
Exemple #3
0
 private void WriteSOChangeVATLog(List <SOInfo> subSOList)
 {
     if (subSOList != null && subSOList.Count > 0)
     {
         foreach (SOInfo subSO in subSOList)
         {
             if (!subSO.InvoiceInfo.IsVAT.Value)
             {
                 ECCentral.BizEntity.SO.SOInvoiceChangeLogInfo invoiceChanageLog = new SOInvoiceChangeLogInfo
                 {
                     SOSysNo     = subSO.SysNo.Value,
                     ChangeTime  = DateTime.Now,
                     ChangeType  = InvoiceChangeType.VATToGeneral,
                     CompanyCode = subSO.CouponCode,
                     UserSysNo   = ServiceContext.Current.UserSysNo,
                     Note        = ResourceHelper.Get("Res_SO_Invoice_Change", subSO.InvoiceInfo.VATInvoiceInfo.TaxNumber, subSO.InvoiceInfo.InvoiceNo)
                 };
                 ObjectFactory <ISOLogDA> .Instance.InsertSOInvoiceChangeLogInfo(invoiceChanageLog);
             }
         }
     }
 }
Exemple #4
0
        ///// <summary>
        ///// 此订单已被拆分,不允许操作!
        ///// </summary>
        //public static string Message_SO_Hold_SplitComplete
        //{
        //    get
        //    {
        //        return ResouceManager.GetMessageString(MessagePath_SOInfo, "SO_Hold_SplitComplete");
        //    }
        //}
        ///// <summary>
        ///// 此订单已作废,不允许操作!
        ///// </summary>
        //public static string Message_SO_Hold_Abandoned
        //{
        //    get
        //    {
        //        return ResouceManager.GetMessageString(MessagePath_SOInfo, "SO_Hold_Abandoned");
        //    }
        //}
        ///// <summary>
        ///// 此订单已出库,不允许操作!
        ///// </summary>
        //public static string Message_SO_Hold_OutStock
        //{
        //    get
        //    {
        //        return ResouceManager.GetMessageString(MessagePath_SOInfo, "SO_Hold_OutStock");
        //    }
        //}
        ///// <summary>
        ///// 此订单被锁定,不允许操作!
        ///// </summary>
        //public static string Message_SO_Hold_BackHold
        //{
        //    get
        //    {
        //        return ResouceManager.GetMessageString(MessagePath_SOInfo, "SO_Hold_BackHold");
        //    }
        //}
        ///// <summary>
        ///// 订单已被前台锁定,不允许操作!
        ///// </summary>
        //public static string Message_SO_Hold_WebHold
        //{
        //    get
        //    {
        //        return ResouceManager.GetMessageString(MessagePath_SOInfo, "SO_Hold_WebHold");
        //    }
        //}
        ///// <summary>
        ///// 前台正在修改并提交订单信息,不允许操作!
        ///// </summary>
        //public static string Message_SO_Hold_Processing
        //{
        //    get
        //    {
        //        return ResouceManager.GetMessageString(MessagePath_SOInfo, "SO_Hold_Processing");
        //    }
        //}
        ///// <summary>
        ///// 订单不存在!
        ///// </summary>
        //public static string Message_SO_Hold_SOIsNotExist
        //{
        //    get
        //    {
        //        return ResouceManager.GetMessageString(MessagePath_SOInfo, "SO_SOIsNotExist");
        //    }
        //}

        ///// <summary>
        ///// 订单不存在主商品!
        ///// </summary>
        //public static string Message_SO_Create_SOHaveNotMainItem
        //{
        //    get
        //    {
        //        return ResouceManager.GetMessageString(MessagePath_SOInfo, "SO_Create_SOHaveNotMainItem");
        //    }
        //}

        ///// <summary>
        ///// 抛出业务异常信息
        ///// </summary>
        ///// <param name="message">业务异常信息</param>
        //public static void Throw(string message)
        //{
        //    throw new BizException(message);
        //}
        #endregion

        /// <summary>
        /// 抛出业务异常信息
        /// </summary>
        /// <param name="sourceKey">资源键值</param>
        /// <param name="value">对应的值,适用于:键对应的值为:PID:{0}商品已处理   value:10030047</param>
        /// <param name="message">业务异常信息</param>
        public static void Throw(string sourceKey, params string[] value)
        {
            throw new BizException(ResourceHelper.Get(sourceKey, value));
        }
        //改单
        /// <summary>
        /// 改单
        /// </summary>
        /// <param name="soSysNo">订单编号</param>
        public virtual void Update(int soSysNo)
        {
            var soProcessor = ObjectFactory <SOProcessor> .Instance;

            var soInfo = soProcessor.GetSOBySOSysNo(soSysNo);

            if (soInfo == null)
            {
                BizExceptionHelper.Throw("SO_SOIsNotExist");
            }

            //是否货到付款
            bool isPayWhenRecv = soProcessor.IsPayWhenReceived(soInfo.BaseInfo.PayTypeSysNo.Value);

            //查询订单出库记录
            string outStock = m_da.GetOutStockString(soSysNo);

            //还没有出仓记录
            if (string.IsNullOrEmpty(outStock))
            {
                //直接作废
                soProcessor.ProcessSO(new SOAction.SOCommandInfo
                {
                    SOInfo  = soInfo,
                    Command = SOAction.SOCommand.Abandon
                });
                return;
            }
            //获取出库收款信息
            var invoiceMasterList = ExternalDomainBroker.GetSOInvoiceMaster(soSysNo);
            //计算总出库金额相关数据

            //保价费
            decimal premiumAmt = invoiceMasterList
                                 .Where(p => p.PremiumAmt.HasValue)
                                 .Sum(p => p.PremiumAmt.Value);

            //运费
            decimal shippingCharge = invoiceMasterList
                                     .Where(p => p.ShippingCharge.HasValue)
                                     .Sum(p => p.ShippingCharge.Value);

            //附加费
            decimal extraAmt = invoiceMasterList
                               .Where(p => p.ExtraAmt.HasValue)
                               .Sum(p => p.ExtraAmt.Value);

            //折扣金额
            decimal discountAmt = invoiceMasterList
                                  .Where(p => p.DiscountAmt.HasValue)
                                  .Sum(p => p.DiscountAmt.Value);

            //优惠卷抵扣
            decimal promotionAmt = invoiceMasterList
                                   .Where(p => p.PromotionAmt.HasValue)
                                   .Sum(p => p.PromotionAmt.Value);

            //获得积分?
            int pointAmt = invoiceMasterList
                           .Where(p => p.GainPoint.HasValue)
                           .Sum(p => p.GainPoint.Value);

            //出库发票额
            decimal sumExtendPrice = invoiceMasterList
                                     .Where(p => p.InvoiceAmt.HasValue)
                                     .Sum(p => p.InvoiceAmt.Value);

            //礼品卡支付总额
            decimal sumGiftCardPay = invoiceMasterList
                                     .Where(p => p.GiftCardPayAmt.HasValue)
                                     .Sum(p => p.GiftCardPayAmt.Value);

            //积分支付总额
            decimal pointPay = invoiceMasterList
                               .Where(p => p.PointPaid.HasValue)
                               .Sum(p => p.PointPaid.Value);
            //计算多余额应退金额
            decimal returnAmt = GetReturnAmt(soSysNo, sumExtendPrice, soInfo.BaseInfo.GiftCardPay.Value);

            //计算应退积分
            int returnPoint = GetReturnPoint(soInfo, pointPay);

            //已预付款
            decimal prePayAmount = invoiceMasterList
                                   .Where(p => p.PrepayAmt.HasValue)
                                   .Sum(p => p.PrepayAmt.Value);

            //预退款总额
            decimal preReturnAmount = soInfo.BaseInfo.PrepayAmount.Value
                                      + prePayAmount;

            TransactionOptions options = new TransactionOptions();

            options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            options.Timeout        = TransactionManager.DefaultTimeout;
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                //删除未出库分仓的所有Item
                DeleteOrderItem4UpdatePending(soInfo.Items, soInfo.SysNo.Value, outStock);

                #region 更新so单据信息

                //更新so单据信息
                //删除后的SOInfo需要重新读取
                //注意这里虽然事务没有提交,但是可以读取脏数据的方法获取
                soInfo = soProcessor.GetSOBySOSysNo(soSysNo);
                soInfo.BaseInfo.PremiumAmount   = premiumAmt;
                soInfo.BaseInfo.ShipPrice       = shippingCharge;
                soInfo.BaseInfo.PayPrice        = extraAmt;
                soInfo.BaseInfo.PointPay        = 0;
                soInfo.BaseInfo.PromotionAmount = discountAmt;
                soInfo.BaseInfo.CouponAmount    = promotionAmt;
                soInfo.BaseInfo.GainPoint       = pointAmt;

                soInfo.BaseInfo.SOAmount = 0.0M;
                soInfo.Items.ForEach(x =>
                {
                    if (x.ProductType.HasValue &&
                        x.ProductType.Value != SOProductType.Coupon)
                    {
                        soInfo.BaseInfo.SOAmount += x.OriginalPrice * x.Quantity;
                    }
                });

                //现金支付为只读
                //soInfo.BaseInfo.CashPay = soInfo.SOMaster.SOAmt + soInfo.SOMaster.PromotionValue + soMP.PointPay;
                soInfo.BaseInfo.PointPay = Convert.ToInt32(-1 * pointPay * ExternalDomainBroker.GetPointToMoneyRatio());

                if (prePayAmount < 0.0M)
                {
                    soInfo.BaseInfo.PrepayAmount = (-1) * prePayAmount;
                }

                soInfo.BaseInfo.GiftCardPay = (-1) * sumGiftCardPay;
                soProcessor.ProcessSO(new SOAction.SOCommandInfo
                {
                    Command = SOAction.SOCommand.Update,
                    SOInfo  = soInfo
                });

                #endregion 更新so单据信息

                //更新改单状态
                m_da.UpdateSOPendingStatus(soSysNo, SOPendingStatus.ChangeOrder);

#warning 需要重构 重新计算是否并单
                //重新计算是否并单
                ObjectFactory <ISODA> .Instance.UpdateSOCombineInfo(soInfo.BaseInfo.SysNo.Value);

                //金额拆分
                SOPriceSpliter priceSpliter = ObjectFactory <SOPriceSpliter> .Instance;
                priceSpliter.CurrentSO = soInfo;
                priceSpliter.SplitSO();

                //重发消息
                Resend_ShippingMessage(soSysNo);

                #region 调整积分

                var pointAdjustReq = new ECCentral.BizEntity.Customer.AdjustPointRequest();
                pointAdjustReq.CustomerSysNo = soInfo.BaseInfo.CustomerSysNo;
                pointAdjustReq.OperationType = ECCentral.BizEntity.Customer.AdjustPointOperationType.Abandon;
                pointAdjustReq.Point         = returnPoint;
                pointAdjustReq.SOSysNo       = soInfo.SysNo;
                pointAdjustReq.Source        = "OrderMgmt";
                pointAdjustReq.PointType     = (int)ECCentral.BizEntity.Customer.AdjustPointType.UpdateSO;
                pointAdjustReq.Memo          = ResourceHelper.Get("SO_Pending_ReturnPointMemo");
                ExternalDomainBroker.AdjustPoint(pointAdjustReq);

                #endregion 调整积分

                #region 退款(退余额)

                if (isPayWhenRecv)
                {
                    //支持货到付款的改单
                    if (preReturnAmount > 0.0M) //(prepayAmt > sumExtendPrice) //预付款大于已出库总金额,要将多余的钱退回客户
                    {
                        var customerPrepayReq = new CustomerPrepayLog();
                        customerPrepayReq.CustomerSysNo = soInfo.BaseInfo.CustomerSysNo;
                        customerPrepayReq.SOSysNo       = soInfo.SysNo;
                        customerPrepayReq.AdjustAmount  = preReturnAmount;
                        customerPrepayReq.PrepayType    = PrepayType.RemitReturn;
                        customerPrepayReq.Note          = ResourceHelper.Get("SO_Pending_PreReturnMemo", preReturnAmount);
                        ExternalDomainBroker.AdjustPrePay(customerPrepayReq);
                    }
                }
                else
                {//生成对应的多付款退款记录(invoiceservice)更新财务收款单中的OrderAmt金额(invoiceservice)
                    if (returnAmt > 0)
                    {
                        //查询收款单
                        var incomeOrg = ExternalDomainBroker.GetValidSOIncomeInfo(soSysNo, SOIncomeOrderType.SO);
                        if (incomeOrg == null)
                        {
                            BizExceptionHelper.Throw("SO_Income_Unknow", soSysNo.ToString());
                        }

                        //修改原始的订单金额
                        incomeOrg.OrderAmt = incomeOrg.OrderAmt - returnAmt;

                        ExternalDomainBroker.UpdateSOIncomeOrderAmount(incomeOrg.SysNo.Value, incomeOrg.OrderAmt.Value);
                        //更新

                        //创建付款收支单
                        var income = new SOIncomeInfo
                        {
                            OrderSysNo = soInfo.SysNo
                            ,
                            OrderAmt = -returnAmt
                            ,
                            IncomeAmt = -returnAmt
                            ,
                            OrderType = SOIncomeOrderType.OverPayment
                            ,
                            Note = ResourceHelper.Get("SO_Pending_ReturnMemo")
                            ,
                            Status = SOIncomeStatus.Origin
                            ,
                            IncomeStyle = SOIncomeOrderStyle.Advanced
                            ,
                            CompanyCode = soInfo.CompanyCode
                        };
                        ExternalDomainBroker.CreateSOIncome(income);

                        //创建银行收支单
                        SOIncomeRefundInfo refundInfo = new SOIncomeRefundInfo
                        {
                            SOSysNo = soInfo.SysNo
                            ,
                            OrderSysNo = soInfo.SysNo
                            ,
                            OrderType = RefundOrderType.OverPayment
                            ,
                            RefundPayType = RefundPayType.PrepayRefund
                            ,
                            RefundReason = 5
                            ,
                            Status = RefundStatus.Origin
                            ,
                            Note = ResourceHelper.Get("SO_Pending_ReturnMemo")
                            ,
                            RefundCashAmt = returnAmt
                            ,
                            RefundPoint = 0
                            ,
                            ToleranceAmt = 0
                            ,
                            CompanyCode = soInfo.CompanyCode
                        };
                        ExternalDomainBroker.CreateSOIncomeRefundInfo(refundInfo);
                    }
                }

                #endregion 退款(退余额)

                #region 退礼品卡

                //退礼品卡
                if (sumGiftCardPay < 0.0M)
                {
                    if (soInfo.SOGiftCardList != null)
                    {
                        List <GiftCard> reqList      = new List <GiftCard>();
                        decimal         needToPayAmt = sumGiftCardPay * (-1);
                        for (int i = 0; i < soInfo.SOGiftCardList.Count; i++)
                        {
                            if (needToPayAmt <= 0)
                            {
                                soInfo.SOGiftCardList.RemoveAt(i);
                                i--;
                                continue;
                            }

                            soInfo.SOGiftCardList[i].AvailAmount = soInfo.SOGiftCardList[i].Amount.HasValue
                                                                        ? soInfo.SOGiftCardList[i].Amount.Value : 0;

                            if (soInfo.SOGiftCardList[i].AvailAmount >= needToPayAmt)
                            {
                                soInfo.SOGiftCardList[i].Amount       = needToPayAmt;
                                soInfo.SOGiftCardList[i].AvailAmount -= needToPayAmt;
                                needToPayAmt = 0;
                            }
                            else
                            {
                                soInfo.SOGiftCardList[i].Amount      = soInfo.SOGiftCardList[i].AvailAmount;
                                soInfo.SOGiftCardList[i].AvailAmount = 0;
                                needToPayAmt -= soInfo.SOGiftCardList[i].Amount.Value;
                            }
                            reqList.Add(new GiftCard
                            {
                                Code             = soInfo.SOGiftCardList[i].Code,
                                ReferenceSOSysNo = soSysNo,
                                CustomerSysNo    = soInfo.SOGiftCardList[i].CustomerSysNo.Value,
                                ConsumeAmount    = soInfo.SOGiftCardList[i].Amount.Value
                            });
                        }
                        ExternalDomainBroker.GiftCardDeduction(reqList, soInfo.CompanyCode);
                    }
                }

                #endregion 退礼品卡

                scope.Complete();
            }

            ExternalDomainBroker.WriteBizLog(ResourceHelper.Get("SO_Pending_UpdateLogFormat", soSysNo)
                                             , BizLogType.Sale_SO_Update
                                             , soSysNo
                                             , soInfo.CompanyCode);
        }
Exemple #6
0
        /// <summary>
        /// 创建财务负收款并作废订单
        /// </summary>
        /// <param name="refundInfo"></param>
        /// <returns></returns>
        public void CreateAOAndAbandonSO(SOIncomeRefundInfo refundInfo)
        {
            IsOutStockOrder = false;
            if (CurrentSO.BaseInfo.Status == SOStatus.CustomsPass)
            {
                IsOutStockOrder = true;
            }
            if (CurrentSO.BaseInfo.Status != SOStatus.Origin &&
                CurrentSO.BaseInfo.Status != SOStatus.WaitingOutStock
                //&& CurrentSO.BaseInfo.Status != SOStatus.OutStock
                )
            {
                BizExceptionHelper.Throw("SO_CreateAO_SOStatusIsError");
            }

            if (CurrentSOIncome == null)
            {
                BizExceptionHelper.Throw("SO_CreateAO_SOIncomeIsNull");
            }

            SOIncomeInfo soIncomeInfo = new SOIncomeInfo
            {
                OrderAmt       = -CurrentSOIncome.OrderAmt,
                OrderType      = SOIncomeOrderType.AO,
                Note           = ResourceHelper.Get("Res_SO_Abandon_CreateAO"),
                ReferenceID    = "",
                Status         = SOIncomeStatus.Origin,
                OrderSysNo     = CurrentSO.SysNo,
                IncomeAmt      = -(CurrentSOIncome.OrderAmt - CurrentSOIncome.PrepayAmt - CurrentSOIncome.GiftCardPayAmt),
                PayAmount      = -(CurrentSOIncome.OrderAmt - CurrentSOIncome.PrepayAmt - CurrentSOIncome.GiftCardPayAmt),
                IncomeStyle    = CurrentSOIncome.IncomeStyle,
                PrepayAmt      = -CurrentSOIncome.PrepayAmt,
                GiftCardPayAmt = -CurrentSOIncome.GiftCardPayAmt,
                PointPay       = -CurrentSOIncome.PointPay,
                CompanyCode    = CurrentSO.CompanyCode
            };

            SOIncomeRefundInfo soIncomeRefundInfo = new SOIncomeRefundInfo
            {
                OrderSysNo     = refundInfo.SOSysNo,
                OrderType      = RefundOrderType.AO,
                SOSysNo        = refundInfo.SOSysNo,
                RefundPayType  = refundInfo.RefundPayType,
                BankName       = refundInfo.BankName,
                BranchBankName = refundInfo.BranchBankName,
                CardNumber     = refundInfo.CardNumber,
                CardOwnerName  = refundInfo.CardOwnerName,
                PostAddress    = refundInfo.PostAddress,
                PostCode       = refundInfo.PostCode,
                ReceiverName   = refundInfo.ReceiverName,
                Note           = refundInfo.Note,
                HaveAutoRMA    = false,
                RefundPoint    = 0,
                RefundReason   = refundInfo.RefundReason,
                CompanyCode    = CurrentSO.CompanyCode
            };

            if (refundInfo.RefundPayType == RefundPayType.CashRefund)
            {
                soIncomeRefundInfo.Status = RefundStatus.Audit;
            }
            else
            {
                soIncomeRefundInfo.Status = RefundStatus.Origin;
            }
            if (refundInfo.RefundPayType == RefundPayType.TransferPointRefund)
            {
                soIncomeInfo.IncomeAmt            = 0;
                soIncomeRefundInfo.RefundCashAmt  = 0;
                soIncomeRefundInfo.RefundPoint    = Convert.ToInt32(Decimal.Round(CurrentSO.BaseInfo.SOAmount.Value * ExternalDomainBroker.GetPointToMoneyRatio(), 0));
                soIncomeRefundInfo.RefundGiftCard = CurrentSOIncome.GiftCardPayAmt;
            }
            else
            {
                soIncomeRefundInfo.RefundCashAmt  = CurrentSOIncome.OrderAmt - CurrentSOIncome.GiftCardPayAmt;
                soIncomeRefundInfo.RefundGiftCard = CurrentSOIncome.GiftCardPayAmt;
            }

            ValidateAbandonSO(false);

            bool isHold = CurrentSO.BaseInfo.HoldStatus == SOHoldStatus.BackHold;

            if (IsOutStockOrder)
            {
                isHold = true;
            }
            //如果后台锁定
            if (!isHold)
            {
                isHold = Holder.Hold(SOHolder.SOHoldReason.AbandonOrder, OPCCallBackType.AOAbandonCallBack);
                if (!isHold)
                {
                    BizExceptionHelper.Throw("SO_Abandon_HoldIsAsyn");
                }
            }
            if (isHold) //如果订单已经锁定
            {
                CreateAOAndAbandonSO(soIncomeInfo, soIncomeRefundInfo);
                if (IsOutStockOrder)
                {
                    SODA.UpdateSOStatusToReportedFailure(CurrentSO.SysNo.Value);
                    CurrentSO.BaseInfo.Status = SOStatus.Reject;
                }
                SendMessage();
            }
        }
Exemple #7
0
        /// <summary>
        /// 作废订单
        /// </summary>
        /// <param name="OperatorType">作废订单的用户类型</param>
        /// <param name="IsImmediatelyReturnStock">是否立即将订单中商品的库存返回给仓库,true表示是立即返回,false表示不是</param>
        public virtual void Abandon()
        {
            //  1.  判断订单是否被前台锁定,锁定后不能作废
            Holder.CheckSOIsWebHold();

            //  2.  订单作废检查,检查是否有有效收款,积分使用,余额使用,优惠券使用,账期支付等
            try
            {
                ValidateAbandonSO(true);
            }
            catch (BizException bizex)
            {
                if (CurrentSO.BaseInfo.HoldStatus == SOHoldStatus.BackHold)
                {
                    throw bizex;
                }
                CurrentSO.BaseInfo.HoldReason = ResourceHelper.Get("Res_SO_Abandon_Hold");

                Holder.Hold(ECCentral.Service.SO.BizProcessor.SOHolder.SOHoldReason.AbandonOrder, OPCCallBackType.HoldCallBack);

                throw new BizException(String.Format("{0}\r\n{1}", bizex.Message, ResourceHelper.Get("SO_Abandon_Hold")));
            }

            //  3.  先锁定订单,再作订单。如果已经锁定就直接作废,否则先锁定订单
            bool isHold = CurrentSO.BaseInfo.HoldStatus == SOHoldStatus.BackHold;

            if (!isHold)
            {
                isHold = Holder.Hold(ECCentral.Service.SO.BizProcessor.SOHolder.SOHoldReason.AbandonOrder, OPCCallBackType.AbandonCallBack);

                if (!isHold)
                {
                    BizExceptionHelper.Throw("SO_Abandon_HoldIsAsyn");
                }
            }
            if (isHold)
            {
                //TransactionOptions option = new TransactionOptions();
                //option.IsolationLevel = IsolationLevel.ReadUncommitted;
                //option.Timeout = TransactionManager.DefaultTimeout;
                //using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, option))
                //{
                //    AbandonSO();
                //    PublishMessage();
                //    scope.Complete();
                //}
                TransactionOptions options = new TransactionOptions
                {
                    IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted
                };
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
                {
                    AbandonSO();
                    scope.Complete();
                }
                PublishMessage();


                if (ServiceContext.Current.UserSysNo == 1)
                {
                    SOSendMessageProcessor soMail = new SOSendMessageProcessor();
                    //soMail.AbandonSOEmailToCustomer(this.CurrentSO);
                }
            }
        }
Exemple #8
0
        /// <summary>
        /// 更新团购订单
        /// </summary>
        /// <param name="CurrentSO"></param>
        /// <returns></returns>
        public void Update()
        {
            ValidationSOEntity();
            ValidationGroupBuyingRules();

            SOItemInfo groupBuyProduct = CurrentSO.Items.Find(item => item.ProductSysNo == ProductSysNo);

            if (groupBuyProduct == null)
            {
                return;
            }
            //可能有赠品,但是只会有一个主商品
            int groupBuySysNo = groupBuyProduct.ReferenceSysNo.Value;

            GroupBuyingInfo gbInfo    = ExternalDomainBroker.GetGroupBuyInfoBySysNo(groupBuySysNo);
            decimal         dealPrice = gbInfo.GBPrice.HasValue ? gbInfo.GBPrice.Value : -1;

            if (dealPrice < 0)
            {
                throw new BizException(ResourceHelper.Get("SO_Audit_GroupNotDealPrice", CurrentSO.SysNo));
            }

            if (groupBuyProduct != null && dealPrice < groupBuyProduct.Price)
            {
                SOInfo newSOInfo = new SOInfo();
                //newSOInfo.SOItemList = SerializeHelper.DeepClone(soInfo.SOItemList);

                List <SOItemInfo> otherItems = CurrentSO.Items.FindAll(x => x.ProductSysNo != ProductSysNo);

                decimal oldSOAmt = 0.0m;

                if (otherItems != null && otherItems.Count > 0)
                {
                    oldSOAmt = otherItems.Sum(x => x.OriginalPrice.Value * x.Quantity.Value);
                }



                decimal newSOAmt = oldSOAmt;


                if (groupBuyProduct.ProductType == SOProductType.Product)
                {
                    groupBuyProduct.Price            = dealPrice;
                    groupBuyProduct.OriginalPrice    = dealPrice;
                    groupBuyProduct.SettlementStatus = SettlementStatus.Success;
                    //团购订单不能用优惠卷
                    newSOAmt += dealPrice * groupBuyProduct.Quantity.Value;
                }


                int     refundPoint    = 0;
                decimal refundPrepay   = 0.0m;
                decimal refundGiftCard = 0.0m;
                decimal difference     = CurrentSO.BaseInfo.SOAmount.Value - newSOAmt;

                decimal newPrepayAmt   = CurrentSO.BaseInfo.PrepayAmount.Value;
                decimal newGiftCardPay = CurrentSO.BaseInfo.GiftCardPay.Value;
                decimal newPremiumAmt  = CurrentSO.BaseInfo.PremiumAmount.Value;
                int     newPointPay    = CurrentSO.BaseInfo.PointPay.Value;
                decimal newCashPay     = newSOAmt - Math.Abs(CurrentSO.BaseInfo.PointPayAmount.Value);

                ECCentral.BizEntity.Common.ShippingType shippingType = ExternalDomainBroker.GetShippingTypeBySysNo(CurrentSO.ShippingInfo.ShipTypeSysNo.Value);
                if (CurrentSO.BaseInfo.IsPremium.Value)
                {
                    if (shippingType != null && newSOAmt > shippingType.PremiumBase)
                    {
                        newPremiumAmt = UtilityHelper.ToMoney(newSOAmt * shippingType.PremiumRate.Value);
                    }
                }
                decimal pointToMoneyRatio = ExternalDomainBroker.GetPointToMoneyRatio();
                #region 退款逻辑
                //退款优先级:1.先退现金支付(注意:不在这里退还),2.退余额支付,3.退礼品卡支付,4.退积分支付
                //  1.  需退还的:余额支付金额,退礼支付品金额,积分支付金额的总合
                decimal refundPayAmount = CurrentSO.BaseInfo.PrepayAmount.Value + CurrentSO.BaseInfo.GiftCardPay.Value + CurrentSO.BaseInfo.PointPayAmount.Value -
                                          (newSOAmt + newPremiumAmt + CurrentSO.BaseInfo.ShipPrice.Value);
                //  2.  如果使用余额支付,退到余额
                if (refundPayAmount > 0)
                {
                    refundPrepay    = refundPayAmount > CurrentSO.BaseInfo.PrepayAmount ? CurrentSO.BaseInfo.PrepayAmount.Value : refundPayAmount;
                    newPrepayAmt    = CurrentSO.BaseInfo.PrepayAmount.Value - refundPrepay;
                    refundPayAmount = refundPayAmount - refundPrepay;

                    //  3.  如果使用礼品卡支付,退到礼品卡
                    if (refundPayAmount > 0)
                    {
                        refundGiftCard  = refundPayAmount > CurrentSO.BaseInfo.GiftCardPay ? CurrentSO.BaseInfo.GiftCardPay.Value : refundPayAmount;
                        newGiftCardPay  = CurrentSO.BaseInfo.GiftCardPay.Value - refundGiftCard;
                        refundPayAmount = refundPayAmount - refundGiftCard;

                        //  4.  如果使用积分支付,退积分
                        if (refundPayAmount > 0)
                        {
                            decimal refundPointAmount = refundPayAmount > CurrentSO.BaseInfo.PointPayAmount ? CurrentSO.BaseInfo.PointPayAmount.Value : refundPayAmount;
                            refundPayAmount = refundPayAmount - refundPointAmount;
                            decimal newPontPayAmount = CurrentSO.BaseInfo.PointPayAmount.Value - refundPointAmount;
                            newPointPay = (int)(newPontPayAmount * pointToMoneyRatio);
                            refundPoint = (int)(refundPointAmount * pointToMoneyRatio);
                            newCashPay  = newSOAmt - newPontPayAmount;
                        }
                    }
                }

                #endregion
                ECCentral.BizEntity.Common.PayType payType = ExternalDomainBroker.GetPayTypeBySysNo(CurrentSO.BaseInfo.PayTypeSysNo.Value);
                decimal newPayPrice = Math.Max(UtilityHelper.ToMoney(payType.PayRate.Value *
                                                                     (newCashPay + CurrentSO.BaseInfo.ShipPrice.Value + newPremiumAmt - newPrepayAmt - newGiftCardPay)), 0M);

                CurrentSO.BaseInfo.SOAmount       = newSOAmt;
                CurrentSO.BaseInfo.PremiumAmount  = newPremiumAmt;
                CurrentSO.BaseInfo.PayPrice       = newPayPrice;
                CurrentSO.BaseInfo.GiftCardPay    = newGiftCardPay;
                CurrentSO.BaseInfo.PointPay       = newPointPay;
                CurrentSO.BaseInfo.PointPayAmount = CurrentSO.BaseInfo.PointPay.Value / pointToMoneyRatio;
                CurrentSO.BaseInfo.PrepayAmount   = newPrepayAmt;

                TransactionOptions options = new TransactionOptions();
                options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
                {
                    SODA.UpdateGroupBuySOAmount(CurrentSO.BaseInfo);

                    SODA.UpdateGroupBuyProduct(groupBuyProduct);


                    if (refundPrepay > 0)
                    {
                        ExternalDomainBroker.AdjustPrePay(new BizEntity.Customer.CustomerPrepayLog
                        {
                            AdjustAmount  = refundPrepay,
                            CustomerSysNo = CurrentSO.BaseInfo.CustomerSysNo,
                            Note          = "Update SO For GroupBuying",
                            PrepayType    = ECCentral.BizEntity.Customer.PrepayType.SOPay,
                            SOSysNo       = CurrentSO.SysNo,
                        });
                    }

                    if (refundGiftCard > 0)
                    {
                        ExternalDomainBroker.GiftCardVoidForSOUpdate(newGiftCardPay, CurrentSO.SOGiftCardList, CurrentSO.CompanyCode);
                    }

                    if (refundPoint > 0)
                    {
                        ExternalDomainBroker.AdjustPoint(new BizEntity.Customer.AdjustPointRequest
                        {
                            CustomerSysNo = CurrentSO.BaseInfo.CustomerSysNo,
                            Memo          = "Update Group Buying SO",
                            OperationType = ECCentral.BizEntity.Customer.AdjustPointOperationType.AddOrReduce,
                            Point         = refundPoint,
                            PointType     = (int)ECCentral.BizEntity.Customer.AdjustPointType.UpdateSO,
                            SOSysNo       = CurrentSO.SysNo,
                            Source        = SOConst.DomainName
                        });
                    }
                    scope.Complete();
                }
            }
            WriteLog(BizEntity.Common.BizLogType.Sale_SO_Update, "IPP更改团购订单");
        }
Exemple #9
0
        /// <summary>
        /// 处理无效的团购订单
        /// </summary>
        /// <returns></returns>
        public void ProcessorInvalidGroupBuySO(SOInfo soInfo)
        {
            if (soInfo == null || !soInfo.SysNo.HasValue)
            {
                return;
            }
            int soSysNo = soInfo.SysNo.Value;

            try
            {
                //获取所有Item
                List <SOItemInfo> items = (from item in soInfo.Items
                                           where item.ActivityType == SOProductActivityType.GroupBuy
                                           select item).ToList();

                if (items == null || items.Count == 0)
                {
                    return;
                }

                //如果含有未处理的团购商品就过
                if (items.Exists(x => x.ReferenceSysNo.HasValue && x.ReferenceSysNo != 0 && !x.SettlementStatus.HasValue))
                {
                    return;
                }
                else if (items.Exists(x => x.SettlementStatus == SettlementStatus.Fail))
                {
                    //更新订单团购处理状态
                    SODA.UpdateGroupBuySOSettlementStatusBySOSysNo(soSysNo, SettlementStatus.Fail);
                }
                else if (items.Exists(x => x.SettlementStatus == SettlementStatus.PlanFail))
                {
                    //只含P,作废
                    if (!items.Exists(x => x.SettlementStatus != SettlementStatus.PlanFail))
                    {
                        ECCentral.BizEntity.Invoice.NetPayInfo netPayInfo = ExternalDomainBroker.GetSOValidNetPay(soSysNo);
                        if (netPayInfo != null)
                        {
                            //ExternalDomainBroker.AuditNetPay(netPayInfo.SysNo.Value);
                            ExternalDomainBroker.AuditNetPay4GroupBuy(netPayInfo.SysNo.Value);
                            ExternalDomainBroker.CreateAOForJob(soSysNo, BizEntity.Invoice.RefundPayType.PrepayRefund, ResourceHelper.Get("Res_SO_Job_GropBuySOAbandon"), null);
                        }

                        ObjectFactory <SOProcessor> .Instance.ProcessSO(new SOAction.SOCommandInfo {
                            Command = SOAction.SOCommand.Abandon, SOInfo = soInfo
                        });
                    }
                    else
                    {
                        //更新订单团购处理状态
                        SODA.UpdateGroupBuySOSettlementStatusBySOSysNo(soSysNo, SettlementStatus.PlanFail);
                    }
                }
                else if (!items.Exists(x => x.ReferenceSysNo.HasValue && x.ReferenceSysNo != 0 && x.SettlementStatus != SettlementStatus.Success))
                {
                    ECCentral.BizEntity.Invoice.NetPayInfo netPayInfo = ExternalDomainBroker.GetSOValidNetPay(soSysNo);
                    //审核NetPay
                    if (netPayInfo != null)
                    {
                        //ExternalDomainBroker.AuditNetPay(netPayInfo.SysNo.Value);
                        ExternalDomainBroker.AuditNetPay4GroupBuy(netPayInfo.SysNo.Value);
                    }

                    SODA.UpdateGroupBuySOSettlementStatusBySOSysNo(soSysNo, SettlementStatus.Success);
                }
            }
            catch (Exception ex)
            {
                SODA.UpdateGroupBuySOSettlementStatusBySOSysNo(soSysNo, SettlementStatus.Fail);
                ExceptionHelper.HandleException(ex);
            }
        }
        //更新 订单投诉信息
        /// <summary>
        /// 更新 订单投诉信息
        /// </summary>
        /// <param name="info">请求的实体</param>
        /// <returns>修改后的订单</returns>
        public virtual SOComplaintInfo Update(SOComplaintInfo info)
        {
            if (!info.ProcessInfo.IsSure.HasValue &&
                (info.ProcessInfo.Status == SOComplainStatus.Review ||
                 info.ProcessInfo.Status == SOComplainStatus.Dealing ||
                 info.ProcessInfo.Status == SOComplainStatus.Complete))
            {
                BizExceptionHelper.Throw("SO_Complain_UpdateAuditError");
            }

            if (info.ProcessInfo.ReasonCodeSysNo.HasValue)
            {
                var reasonPath = ExternalDomainBroker.GetReasonCodePath(info.ProcessInfo.ReasonCodeSysNo.Value, info.ComplaintCotentInfo.CompanyCode);
                //spilt reasonPath
                var reasons = reasonPath.Split('>');
                if (reasons.Length > 1)
                {
                    //构造投诉大类
                    info.ProcessInfo.CSConfirmComplainType = reasons[1];
                    if (reasons.Length > 2)
                    {
                        //构造投诉类别
                        info.ProcessInfo.CSConfirmComplainTypeDetail = reasons[2];
                        if (reasons.Length > 3)
                        {
                            info.ProcessInfo.ResponsibleDepartment = CodeNamePairManager.GetCode(SOConst.DomainName, "ResponsibleDept", reasons[3]);
                        }
                    }
                }
            }

            //处理情况加入到投诉内容中
            if (!string.IsNullOrEmpty(info.ProcessInfo.ProcessedNote))
            {
                info.ComplaintCotentInfo.ComplainContent = info.ComplaintCotentInfo.ComplainContent
                                                           + "\r\n\r\n"
                                                           + ResourceHelper.Get("SO_Complain_ContentFormat"
                                                                                , DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                                                                                )
                                                           + "\r\n"
                                                           + info.ProcessInfo.ProcessedNote.Trim();
                info.ProcessInfo.ProcessedNote = null;
            }

            //复核审查
            if (info.ProcessInfo.Status == SOComplainStatus.Review)
            {
                //如果是复核状态
                info.ProcessInfo.ReopenCount++;
            }
            else if (info.ProcessInfo.Status == SOComplainStatus.Complete)
            {
                //如果是处理完毕,更新所用工时
                double worktime = CommonUtility.CalWorkMinute(info.ComplaintCotentInfo.ComplainTime.Value, DateTime.Now, 0);
                info.ProcessInfo.SpendHours = Convert.ToInt32(worktime / 60);
            }

            info = m_da.UpdateComplainMaster(info);

            AddHistory(info, ReplyOperatorType.Update);
            //重新获取日志
            info.ReplyHistory = m_da.GetHistory(info);

            //处理完毕和作废的最终状态通知客户
            if (info.ProcessInfo.Status == SOComplainStatus.Abandoned ||
                info.ProcessInfo.Status == SOComplainStatus.Complete)
            {
                //更新CallingStatus
                ExternalDomainBroker.CallingCustomStatus(info.SysNo.Value
                                                         , CallingReferenceType.Complain
                                                         , info.ProcessInfo.ComplainNote);
            }
            return(info);
        }