Exemple #1
0
        /// <summary>
        /// 更新检测信息
        /// </summary>
        /// <param name="register"></param>
        /// <returns></returns>
        public virtual RMARegisterInfo UpdateCheckInfo(RMARegisterInfo register)
        {
            if (register == null)
            {
                throw new ArgumentNullException("register");
            }

            register.CheckInfo.CheckUserSysNo = ServiceContext.Current.UserSysNo;
            register.CheckInfo.CheckTime      = DateTime.Now;

            CommonCheck.VerifyNotNull("SysNo", register.CheckInfo.SysNo);

            RMARegisterInfo origin = LoadBySysNo(register.CheckInfo.SysNo.Value);

            if (origin.BasicInfo.Status == RMARequestStatus.Complete || origin.BasicInfo.Status == RMARequestStatus.Abandon)
            {
                string msg = ResouceManager.GetMessageString("RMA.Request", "CannotEditWhenClosedOrAbandon");
                throw new BizException(msg);
            }
            CommonCheck.VerifyNotNull("CheckUserSysNo", register.CheckInfo.CheckUserSysNo);

            string userName = ExternalDomainBroker.GetUserInfo(ServiceContext.Current.UserSysNo).UserDisplayName;

            register.CheckInfo.CheckDesc = string.Format(
                "{0}\r\n{1} {2}",
                register.CheckInfo.CheckDesc,
                userName,
                DateTime.Now.ToString("yyyy-MM-dd")
                );

            register.VerifyFieldsLength();

            registerDA.UpdateCheckInfo(register);

            ExternalDomainBroker.CreateOperationLog("RMA_Register_Check", BizLogType.RMA_Register_Check, register.SysNo.Value, origin.CompanyCode);

            return(LoadForEditBySysNo(register.CheckInfo.SysNo.Value));
        }
Exemple #2
0
        /// <summary>
        /// 待发货
        /// </summary>
        /// <param name="register"></param>
        /// <returns></returns>
        public virtual RMARegisterInfo SetWaitingRevert(RMARegisterInfo register)
        {
            register.VerifyWaitingRevert();

            RMARegisterInfo original = LoadBySysNo(register.RevertInfo.SysNo.Value);

            original.RevertInfo.NewProductStatus     = register.RevertInfo.NewProductStatus;
            original.RevertInfo.SetWaitingRevertTime = DateTime.Now;
            // 非换货时 RevertStockSysNo 留空
            original.RevertInfo.RevertStockSysNo = register.RevertInfo.NewProductStatus == RMANewProductStatus.Origin
                ? null
                : register.RevertInfo.RevertStockSysNo;
            // 非换货或者调新品时,直接将原始 ProductSysNo 设置到 RevertProductSysNo
            original.RevertInfo.RevertProductSysNo = (register.RevertInfo.NewProductStatus == RMANewProductStatus.Origin || register.RevertInfo.NewProductStatus == RMANewProductStatus.NewProduct)
                ? register.BasicInfo.ProductSysNo
                : register.RevertInfo.RevertProductSysNo;
            // 非当前 Case 产品需要进行审批
            original.RevertInfo.RevertStatus = register.RevertInfo.NewProductStatus == RMANewProductStatus.OtherProduct
                ? RMARevertStatus.WaitingAudit
                : RMARevertStatus.WaitingRevert;
            //同步到ERP
            SyncERPAction(original);

            TransactionOptions options = new TransactionOptions();

            options.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
            options.Timeout        = TimeSpan.FromMinutes(2);
            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, options))
            {
                registerDA.UpdateRevertStatus(original);

                ExternalDomainBroker.CreateOperationLog("RMA_Register_Revert", BizLogType.RMA_Register_Revert, register.SysNo.Value, original.CompanyCode);

                ts.Complete();
            }

            return(LoadBySysNo(register.SysNo.Value));
        }
Exemple #3
0
        /// <summary>
        /// 重新打开单件
        /// </summary>
        /// <param name="sysNo"></param>
        /// <returns></returns>
        public virtual RMARegisterInfo ReOpen(int sysNo)
        {
            if (!registerDA.CanReOpen(sysNo))
            {
                string msg = ResouceManager.GetMessageString("RMA.Request", "CannotReopen");
                throw new BizException(msg);
            }

            RMARegisterInfo register = new RMARegisterInfo();

            register.BasicInfo.SysNo          = sysNo;
            register.BasicInfo.CloseUserSysNo = null;
            register.BasicInfo.CloseTime      = null;
            register.BasicInfo.Status         = RMARequestStatus.Handling;

            bool result = registerDA.ReOpen(register);

            RMARegisterInfo re = LoadBySysNo(sysNo);

            ExternalDomainBroker.CreateOperationLog("RMA_Register_Close", BizLogType.RMA_Register_Close, sysNo, re.CompanyCode);

            return(re);
        }
Exemple #4
0
        /// <summary>
        /// 取消待发货
        /// </summary>
        /// <param name="sysNo"></param>
        /// <param name="revertAudit"></param>
        /// <param name="register"></param>
        /// <returns></returns>
        public virtual bool CancelWaitingRevert(int sysNo, bool revertAudit, params RMARegisterInfo[] register)
        {
            if (!registerDA.CanCancelWaitingRevert(sysNo))
            {
                string msg = ResouceManager.GetMessageString("RMA.Request", "CannotCancelWaitingRevert");
                throw new BizException(msg);
            }
            RMARegisterInfo    original   = LoadBySysNo(sysNo);
            RegisterRevertInfo revertInfo = original.RevertInfo;

            revertInfo.RevertStatus         = null;
            revertInfo.NewProductStatus     = RMANewProductStatus.Origin;
            revertInfo.RevertProductSysNo   = null;
            revertInfo.RevertStockSysNo     = null;
            revertInfo.SetWaitingRevertTime = null;
            if (revertAudit)
            {
                if (register != null && register.Length > 0)
                {
                    revertInfo.RevertAuditUserSysNo = register[0].RevertInfo.RevertAuditUserSysNo;
                    revertInfo.RevertAuditMemo      = register[0].RevertInfo.RevertAuditMemo;
                    revertInfo.RevertAuditTime      = register[0].RevertInfo.RevertAuditTime;
                }
            }
            else
            {
                revertInfo.RevertAuditUserSysNo = null;
                revertInfo.RevertAuditMemo      = null;
                revertInfo.RevertAuditTime      = null;
            }

            bool result = registerDA.UpdateRevertStatus(original);

            ExternalDomainBroker.CreateOperationLog("RMA_Register_Revert", BizLogType.RMA_Register_Revert, sysNo, original.CompanyCode);

            return(result);
        }
Exemple #5
0
        /// <summary>
        /// 发还审核
        /// </summary>
        /// <param name="register"></param>
        /// <param name="approved">是否通过</param>
        /// <returns></returns>
        public virtual RMARegisterInfo RevertAudit(RMARegisterInfo register, bool approved)
        {
            register.VerifyRevertAudit();

            bool result;

            if (approved)
            {
                register.RevertInfo.RevertStatus         = RMARevertStatus.WaitingRevert;
                register.RevertInfo.RevertAuditUserSysNo = ServiceContext.Current.UserSysNo;
                register.RevertInfo.RevertAuditTime      = DateTime.Now;

                result = registerDA.UpdateRevertStatus(register);
            }
            else
            {
                result = CancelWaitingRevert(register.RevertInfo.SysNo.Value, true, register);
            }


            ExternalDomainBroker.CreateOperationLog("RMA_Register_RevertAudit", BizLogType.RMA_Register_RevertAudit, register.SysNo.Value, register.CompanyCode);

            return(LoadForEditBySysNo(register.SysNo.Value));
        }
        /// <summary>
        /// 退款后更新退款调整单信息
        /// </summary>
        /// <param name="sysNo"></param>
        /// <param name="ROAmt"></param>
        private void UpdateRefundBalanceForRefund(int sysNo, decimal ROAmt, out int NewOrderSysNo)
        {
            RefundBalanceInfo newEntity = new RefundBalanceInfo();

            if (ROAmt > 0)
            {
                newEntity.NewOrderSysNo = ObjectFactory <IRefundDA> .Instance.CreateSysNo();

                newEntity.BalanceOrderType = RefundBalanceType.RO;
            }
            else//生成虚拟SO
            {
                newEntity.NewOrderSysNo    = ExternalDomainBroker.NewSOSysNo();
                newEntity.BalanceOrderType = RefundBalanceType.SO;
            }

            NewOrderSysNo = newEntity.NewOrderSysNo.Value;

            newEntity.SysNo           = sysNo;
            newEntity.Status          = RefundBalanceStatus.Refunded;
            newEntity.RefundTime      = DateTime.Now;
            newEntity.RefundUserSysNo = ServiceContext.Current.UserSysNo;
            this.refundBalanceDA.UpdateRefundBalance(newEntity);
        }
        public void CreateRequest4AutoRMA(int soSysNo, string inUser)
        {
            //0. Load Data
            SOInfo soInfo = ExternalDomainBroker.GetSOInfo(soSysNo);

            //1. Validation
            ValidateSOInfo(soInfo, soSysNo);
            ValidateIfExistValidRMA(soInfo.SysNo.Value);
            ValidateCanCallRequest(soInfo);

            //2. Create Request
            int    requestSysNo    = 0;
            string requestState    = "F";
            int    wareHouseNumber = -1;
            int    vendorSysNo     = GetVendorSysNoFromInUser(inUser);
            int    userSysNo       = AutoRMAUserSysNo;

            wareHouseNumber = GetWarehouseNumber(soInfo);

            string note = string.Empty;
            string memo = string.Empty;
            SellerPortalAutoRMALog sellerPortalAutoRMALog = GetSellerPortalAutoRMALog(soSysNo);

            if (sellerPortalAutoRMALog == null)
            {
                InsertSellerPortalAutoRMALog(soSysNo, inUser);
                sellerPortalAutoRMALog = GetSellerPortalAutoRMALog(soSysNo);
            }

            try
            {
                if (CreateRequest(soSysNo, userSysNo, note, memo, wareHouseNumber, ref requestSysNo))
                {
                    //设置日志状态
                    requestState = "S";
                }
            }
            catch (Exception ex)
            {
                requestState = "F";
                ExceptionHelper.HandleException(ex);
            }
            finally
            {
                UpdateSellerPortalAutoRMALog(soSysNo, requestState, DateTime.Now, sellerPortalAutoRMALog.RefundStatus, sellerPortalAutoRMALog.RefundTime.Value);
                sellerPortalAutoRMALog = GetSellerPortalAutoRMALog(soSysNo);
            }
            //3. Create Refund
            string refundStatus = "F";

            try
            {
                if (ObjectFactory <SellerPortalRefundProcessor> .Instance.CreateRMAAutoRefund(soSysNo, memo, wareHouseNumber, userSysNo, vendorSysNo))
                {
                    refundStatus = "S";
                }
            }
            catch (Exception ex)
            {
                refundStatus = "F";
                ExceptionHelper.HandleException(ex);
            }
            finally
            {
                UpdateSellerPortalAutoRMALog(soSysNo, sellerPortalAutoRMALog.RequestStatus, sellerPortalAutoRMALog.RequestTime.Value, refundStatus, DateTime.Now);
            }
        }
        /// <summary>
        /// 提交审核(审核银行信息)
        /// </summary>
        /// <param name="entity"></param>
        public virtual RefundBalanceInfo SubmitAudit(RefundBalanceInfo entity)
        {
            RefundBalanceInfo refundBalanceInfo = GetRefundBalanceBySysNo(entity.SysNo.Value);

            if (refundBalanceInfo == null)
            {
                throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "RefundBalanceNotExists"));
            }
            refundBalanceInfo.PointAmt = refundBalanceInfo.PointAmt ?? 0;

            if (refundBalanceInfo.Status != RefundBalanceStatus.WaitingRefund)
            {
                throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "Audit_RefundBalanceWaitingRefundValid"));
            }
            if (refundBalanceInfo.CashAmt == null)
            {
                throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "CashAmtRequired"));
            }
            if (refundBalanceInfo.CashAmt.Value < 0)
            {
                throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "Audit_CashAmtValid"));
            }
            SOIncomeRefundInfo oldIncomeBankInfo = ExternalDomainBroker.GetSOIncomeRefundInfo(entity.SysNo.Value, RefundOrderType.RO_Balance);
            SOIncomeRefundInfo newIncomeBankInfo = new SOIncomeRefundInfo()
            {
                RefundReason   = 9, // RefundReason.RefundBalance
                BankName       = entity.IncomeBankInfo.BankName,
                BranchBankName = entity.IncomeBankInfo.BranchBankName,
                CardNumber     = entity.IncomeBankInfo.CardNumber,
                CardOwnerName  = entity.IncomeBankInfo.CardOwnerName,
                PostAddress    = entity.IncomeBankInfo.PostAddress,
                PostCode       = entity.IncomeBankInfo.PostCode,
                ReceiverName   = entity.IncomeBankInfo.ReceiverName,
                Note           = entity.IncomeBankInfo.Note,
                CompanyCode    = refundBalanceInfo.CompanyCode
            };

            TransactionScopeFactory.TransactionAction(() =>
            {
                if (oldIncomeBankInfo == null)
                {
                    newIncomeBankInfo.RefundPayType = refundBalanceInfo.RefundPayType;
                    newIncomeBankInfo.SOSysNo       = refundBalanceInfo.OriginalSOSysNo;
                    newIncomeBankInfo.OrderType     = RefundOrderType.RO_Balance;
                    newIncomeBankInfo.OrderSysNo    = refundBalanceInfo.SysNo;
                    newIncomeBankInfo.HaveAutoRMA   = false;

                    if (newIncomeBankInfo.RefundPayType == RefundPayType.CashRefund)
                    {
                        newIncomeBankInfo.Status = ECCentral.BizEntity.Invoice.RefundStatus.Audit;
                    }
                    else
                    {
                        newIncomeBankInfo.Status = ECCentral.BizEntity.Invoice.RefundStatus.Origin;
                    }

                    if (newIncomeBankInfo.RefundPayType == RefundPayType.TransferPointRefund)
                    {
                        newIncomeBankInfo.RefundCashAmt = 0;
                        newIncomeBankInfo.RefundPoint   = Convert.ToInt32(Decimal.Round((refundBalanceInfo.CashAmt ?? 0M)
                                                                                        * pointExchangeRate, 0));
                        if (refundBalanceInfo.PointAmt > 0)//如果有积分累加到bankInfo的PointAmt字段上
                        {
                            newIncomeBankInfo.RefundPoint += refundBalanceInfo.PointAmt;
                        }
                    }
                    else
                    {
                        newIncomeBankInfo.RefundCashAmt = refundBalanceInfo.CashAmt;
                        newIncomeBankInfo.RefundPoint   = refundBalanceInfo.PointAmt;
                    }
                    newIncomeBankInfo.RefundGiftCard = refundBalanceInfo.GiftCardAmt;

                    ExternalDomainBroker.CreateSOIncomeRefundInfo(newIncomeBankInfo);
                }
                else if (oldIncomeBankInfo.Status == RefundStatus.Origin ||
                         (oldIncomeBankInfo.Status != RefundStatus.Origin && oldIncomeBankInfo.RefundPayType == RefundPayType.CashRefund))
                {
                    newIncomeBankInfo.SysNo          = oldIncomeBankInfo.SysNo;
                    newIncomeBankInfo.OrderType      = oldIncomeBankInfo.OrderType;
                    newIncomeBankInfo.RefundPayType  = oldIncomeBankInfo.RefundPayType;
                    newIncomeBankInfo.RefundReason   = oldIncomeBankInfo.RefundReason;
                    newIncomeBankInfo.HaveAutoRMA    = oldIncomeBankInfo.HaveAutoRMA;
                    newIncomeBankInfo.RefundCashAmt  = oldIncomeBankInfo.RefundCashAmt;
                    newIncomeBankInfo.RefundGiftCard = oldIncomeBankInfo.RefundGiftCard;
                    newIncomeBankInfo.RefundPoint    = oldIncomeBankInfo.RefundPoint;
                    newIncomeBankInfo.ToleranceAmt   = oldIncomeBankInfo.ToleranceAmt;
                    newIncomeBankInfo.Status         = oldIncomeBankInfo.Status;

                    ExternalDomainBroker.UpdateSOIncomeRefundInfo(newIncomeBankInfo);
                }
                else if (oldIncomeBankInfo.Status == RefundStatus.Abandon)
                {
                    throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "Audit_RefundBalanceAbandonStatusValid"));
                }
                else
                {
                    throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "Audit_RefundBalanceStatusValid"));
                }
                entity.IncomeBankInfo = newIncomeBankInfo;

                //完成RMA退款调整单待审核 - 待办事项:
                EventPublisher.Publish <RMACompleteRefundBalanceWaitingForAuditMessage>(new RMACompleteRefundBalanceWaitingForAuditMessage()
                {
                    RefundBalanceSysNo = entity.SysNo.Value,
                    RefundSysNo        = entity.OriginalRefundSysNo.Value,
                    CurrentUserSysNo   = ServiceContext.Current.UserSysNo
                });
            });
            return(entity);
        }
Exemple #9
0
        /// <summary>
        /// 接收申请单
        /// </summary>
        /// <param name="request">申请单信息</param>
        /// <returns>申请单信息</returns>
        public virtual RMARequestInfo Receive(RMARequestInfo request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request is required!");
            }
            if (!request.SysNo.HasValue)
            {
                throw new ArgumentNullException("request.SysNo is required!");
            }

            RMARequestInfo original = LoadWithRegistersBySysNo(request.SysNo.Value);

            request.VerifyReceive(original);

            original.ReceiveWarehouse = request.ReceiveWarehouse;
            original.ReceiveTime      = DateTime.Now;
            original.ReceiveUserSysNo = ServiceContext.Current.UserSysNo;
            //获取UI上需要的接收人名称
            original.ReceiveUserName  = ExternalDomainBroker.GetUserInfoBySysNo(original.ReceiveUserSysNo.Value);
            original.IsViaPostOffice  = request.IsViaPostOffice;
            original.PostageToPoint   = request.PostageToPoint;
            original.Status           = RMARequestStatus.Handling;
            original.CustomerSendTime = request.CustomerSendTime;
            original.ShipViaCode      = request.ShipViaCode;
            original.IsRejectRMA      = request.IsRejectRMA;
            original.TrackingNumber   = request.TrackingNumber;
            original.Phone            = request.Phone;
            original.Contact          = request.Contact;
            original.Address          = request.Address;
            original.ETakeDate        = request.ETakeDate;
            original.AreaSysNo        = request.AreaSysNo;
            original.Memo             = request.Memo;
            original.Note             = request.Note;
            original.IsReceiveMsg     = request.IsReceiveMsg;

            request.ReturnPoint = request.PostageToPoint;

            // data format:
            // { RegisterSysNo: [ HaveInvoice, IsFullAccessory, IsFullPackage ] }
            Dictionary <int, bool?[]> dic = new Dictionary <int, bool?[]>();

            request.Registers.ForEach(reg =>
            {
                dic.Add(
                    reg.BasicInfo.SysNo.Value,
                    new bool?[] { reg.BasicInfo.IsHaveInvoice, reg.BasicInfo.IsFullAccessory, reg.BasicInfo.IsFullPackage }
                    );
            });

            Dictionary <int, decimal> costs = GetSOItemsCost(request.SysNo.Value);
            bool isWithin7Days = IsWithin7Days(request.SOSysNo.Value, request.CustomerSendTime.Value);

            original.Registers.ForEach(reg =>
            {
                reg.BasicInfo.OwnBy             = RMAOwnBy.Customer;
                reg.BasicInfo.Location          = RMALocation.Self;
                reg.BasicInfo.LocationWarehouse = request.ReceiveWarehouse;
                reg.BasicInfo.OwnByWarehouse    = ((int)RMAOwnBy.Origin).ToString();
                reg.BasicInfo.Cost            = costs[reg.BasicInfo.ProductSysNo.Value];
                reg.BasicInfo.IsWithin7Days   = isWithin7Days;
                reg.BasicInfo.Status          = request.Status;
                reg.BasicInfo.IsHaveInvoice   = dic[reg.BasicInfo.SysNo.Value][0];
                reg.BasicInfo.IsFullAccessory = dic[reg.BasicInfo.SysNo.Value][1];
                reg.BasicInfo.IsFullPackage   = dic[reg.BasicInfo.SysNo.Value][2];
            });

            TransactionOptions options = new TransactionOptions();

            options.IsolationLevel = IsolationLevel.ReadCommitted;
            options.Timeout        = TransactionManager.DefaultTimeout;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                UpdateWithRegisters(original);

                UpdateInventory(original.Registers, true);

                scope.Complete();
            }

            var customer = ExternalDomainBroker.GetCustomerInfo(request.CustomerSysNo.Value);

            //SendEmail(customer.BasicInfo.Email, request.RequestID);

            ExternalDomainBroker.CreateOperationLog("RMA_Request_Recieve", BizLogType.RMA_Request_Receive, request.SysNo.Value, original.CompanyCode);

            return(original);
        }
Exemple #10
0
        private string ozzShip = AppSettingManager.GetSetting("RMA", "PushShipTypeName"); // 上门取件物流  "OZZO奥硕物流";

        /// <summary>
        /// 创建申请单
        /// </summary>
        /// <param name="request">申请单信息</param>
        /// <returns>申请单信息</returns>
        public virtual RMARequestInfo Create(RMARequestInfo request)
        {
            request.VerifyForCreate();

            if (request.ShipViaCode.Trim() == ozzShip)
            {
                //奥硕上门地点判断
                //ValidOZZOFetchToHome(request);
            }

            var refundItems = ObjectFactory <IRefundDA> .Instance.GetMasterByOrderSysNo(request.SOSysNo.Value);

            if (refundItems != null)
            {
                refundItems.ForEach(p =>
                {
                    if (p.Status == RMARefundStatus.Refunded && p.RefundReason.HasValue && p.RefundReason == 2)
                    {
                        throw new BizException(ResouceManager.GetMessageString("RMA.Request", "ExsitsNotCreateRequest"));
                    }
                });
            }

            SOInfo so = ExternalDomainBroker.GetSOInfo(request.SOSysNo.Value);

            if (so.BaseInfo.Status.Value != SOStatus.OutStock && so.BaseInfo.Status.Value != SOStatus.Shipping && so.BaseInfo.Status != SOStatus.Complete && so.BaseInfo.Status != SOStatus.Reported)
            {
                throw new BizException(ResouceManager.GetMessageString("RMA.Request", "OutStockNotCreateRequest"));
            }

            if (so.BaseInfo.SOType == SOType.ElectronicCard || so.BaseInfo.SOType == SOType.PhysicalCard)
            {
                throw new BizException(ResouceManager.GetMessageString("RMA.Request", "GiftCardNoRMA"));
            }
            if (so.BaseInfo.PayTypeSysNo == 203)
            {
                throw new BizException(ResouceManager.GetMessageString("RMA.Request", "RedeemGiftCertificatesNoRMA"));
            }


            if (so.BaseInfo.PayTypeSysNo.HasValue)
            {
                int t;

                if (int.TryParse(AppSettingManager.GetSetting(SOConst.DomainName, "GiftVoucher_PayTypeSysNo"), out t))
                {
                    if (so.BaseInfo.PayTypeSysNo.Value == t)
                    {
                        throw new BizException(ResouceManager.GetMessageString("RMA.Request", "GiftCertificatesNoRMA"));
                    }
                }
            }


            CustomerContactInfo customerContactInfoEntity = GetCustomerContactInfo(request);

            BizEntity.Invoice.DeliveryType shipType = BizEntity.Invoice.DeliveryType.SELF;
            InvoiceType?invoceType    = InvoiceType.SELF;
            StockType?  stockType     = StockType.SELF;
            int         merchantSysNo = 1;

            if (so != null)
            {
                shipType      = so.ShippingInfo.ShippingType;
                invoceType    = so.InvoiceInfo.InvoiceType;
                stockType     = so.ShippingInfo.StockType;
                merchantSysNo = so.BaseInfo.Merchant.MerchantID ?? 0;
            }

            using (TransactionScope tran = new TransactionScope())
            {
                request.SysNo     = CreateSysNo();
                request.RequestID = GenerateId(request.SysNo.Value);
                //创建申请单初始状态为【待审核】 add by norton 2012.11.21
                request.Status        = RMARequestStatus.WaitingAudit;
                request.IsSubmit      = true;
                request.ShippingType  = shipType;
                request.InvoiceType   = invoceType;
                request.StockType     = stockType;
                request.MerchantSysNo = merchantSysNo;
                requestDA.Create(request);

                customerContactInfoEntity.RMARequestSysNo = request.SysNo;

                customerContactInfoEntity.ReceiveCellPhone = so.ReceiverInfo.MobilePhone;
                customerContactInfoEntity.ReceiveZip       = so.ReceiverInfo.Zip;

                ObjectFactory <CustomerContactProcessor> .Instance.Create(customerContactInfoEntity);

                request.Registers.ForEach(register =>
                {
                    register.SysNo                       = registerDA.CreateSysNo();
                    register.BasicInfo.Status            = RMARequestStatus.Origin;
                    register.BasicInfo.OwnBy             = RMAOwnBy.Origin;
                    register.BasicInfo.Location          = RMALocation.Origin;
                    register.BasicInfo.IsWithin7Days     = false;
                    register.CheckInfo.IsRecommendRefund = false;
                    register.RevertInfo.NewProductStatus = RMANewProductStatus.Origin;
                    register.BasicInfo.NextHandler       = RMANextHandler.RMA;
                    register.CompanyCode                 = request.CompanyCode;

                    SOItemInfo item = so.Items.FirstOrDefault(p => p.ProductSysNo == register.BasicInfo.ProductSysNo.Value);
                    register.BasicInfo.ShippedWarehouse = item.StockSysNo.ToString();

                    register.VerifyCreate();

                    registerDA.Create(register);

                    registerDA.InsertRequestItem(request.SysNo.Value, register.SysNo.Value);

                    //创建成功后,发送邮件
                    //if (request.VerifyForSendCreateEmail())
                    //{
                    //    var customer = ExternalDomainBroker.GetCustomerInfo(request.CustomerSysNo.Value);
                    //    SendCreateEmail(customer.BasicInfo.Email, request.RequestID);
                    //}
                });

                tran.Complete();
            }

            ExternalDomainBroker.CreateOperationLog("RMA_Request_Create", BizLogType.RMA_Request_Create, request.SysNo.Value, request.CompanyCode);

            return(request);
        }
Exemple #11
0
        /// <summary>
        /// 验证奥硕是否支持上门取件
        /// </summary>
        /// <param name="areaSysNo">申请地区编号</param>
        //void ValidOZZOFetchToHome(RMARequestInfo request)
        //{
        //    //根据行政区划判断是否可以上门取件,如不支持进行提示,且不能保存。
        //    int? areaSysNo = request.AreaSysNo;
        //    bool isFetch = true;

        //    var ozzoShipTypeAreasSysNo = new int[] { 21, 65, 370 };

        //    //获取不支持的地区的列表
        //    var unFetchAreaList = ObjectFactory<IBizInteract.ICommonBizInteract>.Instance.QueryShipAreaUnByAreaSysNo(ozzoShipTypeAreasSysNo, areaSysNo.Value);
        //    // QueryModelProxy.CommonDataQueryProvider.QueryShipAreaUnByAreaSysNo(ozzoShipTypeAreasSysNo, areaSysNo.Value);
        //    if (unFetchAreaList.Count > 0)
        //    {
        //        isFetch = false;
        //        //判断逻辑为:如果有一种配送点可支持上门取件,那判断将终止
        //        foreach (int shipTypeAreaSysNo in ozzoShipTypeAreasSysNo)
        //        {
        //            //可配送的终止条件为配送点没有在不支持地区中配置
        //            if (unFetchAreaList.Count(p => p.ShipTypeSysNo == shipTypeAreaSysNo) == 0)
        //            {
        //                isFetch = true;
        //                break;
        //            }
        //        }
        //    }

        //    //不支持抛出异常
        //    if (!isFetch)
        //    {
        //        throw new BizException("本地区不支持上门取件服务!");
        //    }

        //}


        /// <summary>
        /// 更新申请单(包括单件信息)
        /// </summary>
        /// <param name="request">申请单信息</param>
        public virtual void Update(RMARequestInfo request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (!request.SysNo.HasValue)
            {
                throw new ArgumentNullException("request.SysNo");
            }
            request.VerifyUpdate(LoadBySysNo(request.SysNo.Value));

            if (request.ShipViaCode.Trim() == ozzShip)
            {
                //ValidOZZOFetchToHome(request);

                #region [时间限制]

                //if (!request.ETakeDate.HasValue)
                //{
                //    request.ETakeDate = request.CustomerSendTime;
                //}
                //else
                //{
                //    request.CustomerSendTime = request.ETakeDate;
                //}
                //DateTime minReceiveDate = DateTime.Now;
                //DateTime tmpDate = DateTime.Now;
                ////周一四点后
                //if (request.CreateDate.Value.DayOfWeek == DayOfWeek.Monday && request.CreateDate.Value.Hour >= 16)
                //{

                //    tmpDate = request.CreateDate.Value.AddDays(2);
                //    minReceiveDate = new DateTime(tmpDate.Year, tmpDate.Month, tmpDate.Day, 0, 0, 0);
                //    if (request.CustomerSendTime.Value < minReceiveDate)
                //    {

                //        throw new BizException("周一下午四点之后至周二下午四点前申请,预约取货时间最早可选周三取件!");
                //    }

                //}
                ////周二四点前
                //else if (request.CreateDate.Value.DayOfWeek == DayOfWeek.Tuesday && request.CreateDate.Value.Hour < 16)
                //{

                //    tmpDate = request.CreateDate.Value.AddHours(25 - request.CreateDate.Value.Hour);
                //    minReceiveDate = new DateTime(tmpDate.Year, tmpDate.Month, tmpDate.Day, 0, 0, 0);
                //    if (request.CustomerSendTime.Value < minReceiveDate)
                //    {
                //        throw new BizException("周一下午四点之后至周二下午四点前申请,预约取货时间最早可选周三取件!");
                //    }
                //}
                ////周二四点后
                //else if (request.CreateDate.Value.DayOfWeek == DayOfWeek.Tuesday && request.CreateDate.Value.Hour >= 16)
                //{

                //    tmpDate = request.CreateDate.Value.AddDays(2);
                //    minReceiveDate = new DateTime(tmpDate.Year, tmpDate.Month, tmpDate.Day, 0, 0, 0);
                //    if (request.CustomerSendTime.Value < minReceiveDate)
                //    {
                //        throw new BizException("周二下午四点后至周三下午四点前申请,预约取货时间最早可选周四取件!");
                //    }

                //}
                ////周三四点前
                //else if (request.CreateDate.Value.DayOfWeek == DayOfWeek.Wednesday && request.CreateDate.Value.Hour < 16)
                //{

                //    tmpDate = request.CreateDate.Value.AddHours(25 - request.CreateDate.Value.Hour);
                //    minReceiveDate = new DateTime(tmpDate.Year, tmpDate.Month, tmpDate.Day, 0, 0, 0);
                //    if (request.CustomerSendTime.Value < minReceiveDate)
                //    {
                //        throw new BizException("周二下午四点后至周三下午四点前申请,预约取货时间最早可选周四取件!");
                //    }
                //}
                ////周三四点后
                //else if (request.CreateDate.Value.DayOfWeek == DayOfWeek.Wednesday && request.CreateDate.Value.Hour >= 16)
                //{

                //    tmpDate = request.CreateDate.Value.AddDays(2);
                //    minReceiveDate = new DateTime(tmpDate.Year, tmpDate.Month, tmpDate.Day, 0, 0, 0);
                //    if (request.CustomerSendTime.Value < minReceiveDate)
                //    {
                //        throw new BizException("周三下午四点后至周四下午四点前申请,预约取货时间最早可选周五取件!");

                //    }

                //}
                ////周四四点前Thursday
                //else if (request.CreateDate.Value.DayOfWeek == DayOfWeek.Thursday && request.CreateDate.Value.Hour < 16)
                //{

                //    tmpDate = request.CreateDate.Value.AddHours(25 - request.CreateDate.Value.Hour);
                //    minReceiveDate = new DateTime(tmpDate.Year, tmpDate.Month, tmpDate.Day, 0, 0, 0);
                //    if (request.CustomerSendTime.Value < minReceiveDate)
                //    {
                //        throw new BizException("周三下午四点后至周四下午四点前申请,预约取货时间最早可选周五取件!");
                //    }
                //}
                ////周四四点后
                //else if (request.CreateDate.Value.DayOfWeek == DayOfWeek.Thursday && request.CreateDate.Value.Hour >= 16)
                //{

                //    tmpDate = request.CreateDate.Value.AddDays(2);
                //    minReceiveDate = new DateTime(tmpDate.Year, tmpDate.Month, tmpDate.Day, 0, 0, 0);
                //    if (request.CustomerSendTime.Value < minReceiveDate)
                //    {
                //        throw new BizException("周四下午四点后至周五下午四点前申请,预约取货时间最早可选周六取件!");
                //    }

                //}
                ////周五四点前
                //else if (request.CreateDate.Value.DayOfWeek == DayOfWeek.Friday && request.CreateDate.Value.Hour < 16)
                //{

                //    tmpDate = request.CreateDate.Value.AddHours(25 - request.CreateDate.Value.Hour);
                //    minReceiveDate = new DateTime(tmpDate.Year, tmpDate.Month, tmpDate.Day, 0, 0, 0);
                //    if (request.CustomerSendTime.Value < minReceiveDate)
                //    {
                //        throw new BizException("周四下午四点后至周五下午四点前申请,预约取货时间最早可选周六取件!");
                //    }
                //}
                ////周五四点后
                //else if (request.CreateDate.Value.DayOfWeek == DayOfWeek.Friday && request.CreateDate.Value.Hour >= 16)
                //{

                //    tmpDate = request.CreateDate.Value.AddDays(4);
                //    minReceiveDate = new DateTime(tmpDate.Year, tmpDate.Month, tmpDate.Day, 0, 0, 0);
                //    if (request.CustomerSendTime.Value < minReceiveDate)
                //    {

                //        throw new BizException("周五下午四点之后至周一下午四点前申请,预约取货时间最早可选下周二取件!");
                //    }
                //}
                ////周六全天
                //else if (request.CreateDate.Value.DayOfWeek == DayOfWeek.Saturday)
                //{

                //    tmpDate = request.CreateDate.Value.AddDays(3);
                //    minReceiveDate = new DateTime(tmpDate.Year, tmpDate.Month, tmpDate.Day, 0, 0, 0);
                //    if (request.CustomerSendTime.Value < minReceiveDate)
                //    {
                //        throw new BizException("周五下午四点之后至周一下午四点前申请,预约取货时间最早可选下周二取件!");
                //    }
                //}
                ////周日全天
                //else if (request.CreateDate.Value.DayOfWeek == DayOfWeek.Sunday)
                //{
                //    tmpDate = request.CreateDate.Value.AddDays(2);
                //    minReceiveDate = new DateTime(tmpDate.Year, tmpDate.Month, tmpDate.Day, 0, 0, 0);
                //    if (request.CustomerSendTime.Value < minReceiveDate)
                //    {
                //        throw new BizException("周五下午四点之后至周一下午四点前申请,预约取货时间最早可选下周二取件!");
                //    }
                //}
                ////周一四点前
                //else if (request.CreateDate.Value.DayOfWeek == DayOfWeek.Monday && request.CreateDate.Value.Hour < 16)
                //{

                //    tmpDate = request.CreateDate.Value.AddHours(25 - request.CreateDate.Value.Hour);
                //    minReceiveDate = new DateTime(tmpDate.Year, tmpDate.Month, tmpDate.Day, 0, 0, 0);
                //    if (request.CustomerSendTime.Value < minReceiveDate)
                //    {
                //        throw new BizException("周五下午四点之后至周一下午四点前申请,预约取货时间最早可选下周二取件!");
                //    }
                //}

                #endregion
            }

            if (request.CreateDate.Value.Year > request.CustomerSendTime.Value.Year ||
                (request.CreateDate.Value.Year == request.CustomerSendTime.Value.Year && (request.CreateDate.Value.DayOfYear - request.CustomerSendTime.Value.DayOfYear) > 7))
            {
                throw new BizException(ResouceManager.GetMessageString("RMA.Request", "OrderTimeNotPreviousWeek"));
            }


            request.Registers = registerProcessor.LoadByRequestSysNo(request.SysNo.Value);

            CustomerContactInfo customerContactInfo = GetCustomerContactInfo(request);

            TransactionOptions options = new TransactionOptions();
            options.IsolationLevel = IsolationLevel.ReadCommitted;
            options.Timeout        = TransactionManager.DefaultTimeout;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                customerContactDA.UpdateByRequestSysNo(customerContactInfo);

                bool?isWithin7Days = null;
                if (request.CustomerSendTime.HasValue)
                {
                    isWithin7Days = IsWithin7Days(request.SOSysNo.Value, request.CustomerSendTime.Value);
                }
                request.Registers.ForEach(reg =>
                {
                    reg.BasicInfo.IsWithin7Days = isWithin7Days;
                });

                UpdateWithRegisters(request);

                scope.Complete();
            }

            ExternalDomainBroker.CreateOperationLog("RMA_Request_Update", BizLogType.RMA_Request_Update, request.SysNo.Value, request.CompanyCode);
        }
Exemple #12
0
        private void VoidTransferPostage2Point(RMARequestInfo request)
        {
            var customerRank = ExternalDomainBroker.GetCustomerRank(request.CustomerSysNo.Value);

            TriStatus?stat = null;

            DateTime oldMaxReceiveTime;

            if (!string.IsNullOrEmpty(AppSettingManager.GetSetting("RMA", "OldMaxReceiveTime")))
            {
                oldMaxReceiveTime = DateTime.Parse(AppSettingManager.GetSetting("RMA", "OldMaxReceiveTime"));
            }
            else
            {
                oldMaxReceiveTime = DateTime.Parse("2010-2-23 10:00:00");
            }

            if (request.ReceiveTime < oldMaxReceiveTime && (int)customerRank >= (int)CustomerRank.Golden)
            {
                request.PostageToPoint = 50;
                if (!(request.ShipViaCode.ToLower().Contains("ozzo") ||
                      request.ShipViaCode.ToLower().Contains("奥硕")))
                {
                    int point = 0 - request.PostageToPoint.Value;
                    AdjustPointRequest adjustInfo = new AdjustPointRequest();
                    adjustInfo.CustomerSysNo = request.CustomerSysNo.Value;
                    adjustInfo.Point         = point;
                    adjustInfo.PointType     = (int)AdjustPointType.RMAPostageManuToPoints;
                    adjustInfo.Source        = "RMA";
                    adjustInfo.Memo          = ResouceManager.GetMessageString("RMA.Request", "AdjustInfoMemo");
                    adjustInfo.OperationType = AdjustPointOperationType.Abandon;
                    adjustInfo.SOSysNo       = request.SysNo;
                    ExternalDomainBroker.AdjustPoint(adjustInfo);
                }
            }
            else if (request.ShipViaCode == RMAConst.ShipVia_PostOffice &&
                     request.PostageToPoint.HasValue &&
                     request.PostageToPoint.Value > 0)
            {
                try
                {
                    int re = ExternalDomainBroker.GetCustomerPointAddRequestStatus(request.SysNo.Value);
                    stat = (TriStatus)re;
                }
                catch (BizException e)
                {
                    //邮资转积分有可能关闭,此时将没有调整记录
                    if (string.Compare(e.Message, "Cannot find any matched AdjustPointRequest") == 0)
                    {
                        return;
                    }
                    else
                    {
                        throw e;
                    }
                }
                if (stat != null && stat.Value == TriStatus.Origin)
                {
                    ExternalDomainBroker.AbandonAdjustPointRequest(request.SysNo.Value);
                }
            }
        }
        /// <summary>
        /// 计算可退款金额(运费,现金,礼品卡,积分)
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="soBaseInfo"></param>
        /// <param name="availShipPrice">可退运费</param>
        /// <param name="cashRemoveGiftCard">可退现金</param>
        /// <param name="availGiftCard">可退礼品卡</param>
        /// <param name="availPointAmt">可退积分</param>
        /// <param name="totalRoBoBalanceAmt">历史退款总额</param>
        private void CalculateAvailRefundAmt(RefundBalanceInfo entity, SOBaseInfo soBaseInfo, out decimal availShipPrice,
                                             out decimal cashRemoveGiftCard, out decimal availGiftCard, out int availPointAmt, out decimal totalRoBoBalanceAmt)
        {
            string stockID = ExternalDomainBroker.GetSOItemList(soBaseInfo.SysNo.Value).FirstOrDefault().StockSysNo.Value.ToString();

            #region 历史退款

            //正常商品退款总额
            HistoryRefundAmount historyAmt          = refundProcessor.GetHistoryRefundAmt(entity.OriginalSOSysNo.Value, entity.ProductSysNo.Value, stockID);
            decimal             totalGiftAmtHistory = historyAmt.TotalGiftCardAmt;
            int totalPointAmtHistory = historyAmt.TotalPointAmt;
            totalRoBoBalanceAmt = historyAmt.TotalRoBalanceAmt;
            historyAmt          = refundProcessor.GetHistoryRefundAmt(entity.OriginalSOSysNo.Value, 0, stockID);
            decimal totalCashAmtHistory = historyAmt.TotalCashAmt;
            //运费补偿退款总额
            decimal totalShipPriceAmtHistory = historyAmt.TotalShipPriceAmt;

            #endregion 历史退款

            #region 计算可退现金/积分/礼品卡

            //运费总额(运费+保价费+附加费)
            decimal shipPrice = GetShipFee(soBaseInfo.SysNo.Value, stockID);
            //可退运费(运费总额-已退运费总额)
            availShipPrice = shipPrice - totalShipPriceAmtHistory;
            if (availShipPrice < 0)
            {
                availShipPrice = 0;
            }
            //可退现金
            cashRemoveGiftCard = soBaseInfo.CashPay + shipPrice + soBaseInfo.PromotionAmount.Value
                                 - soBaseInfo.GiftCardPay.Value - totalCashAmtHistory;

            if (soBaseInfo.GiftCardPay == 0 && availShipPrice > 0 && entity.ProductSysNo != 0)
            {
                cashRemoveGiftCard -= availShipPrice;
            }
            if (cashRemoveGiftCard < 0)
            {
                cashRemoveGiftCard = 0;
            }
            ///可退礼品卡金额
            availGiftCard = soBaseInfo.GiftCardPay.Value - totalGiftAmtHistory;

            if (soBaseInfo.GiftCardPay.Value > 0 && availShipPrice > 0 && entity.ProductSysNo != 0)
            {
                availGiftCard -= availShipPrice;
            }
            if (availGiftCard < 0)
            {
                availGiftCard = 0;
            }
            //可退积分
            availPointAmt = soBaseInfo.PointPay.Value - totalPointAmtHistory;
            if (availPointAmt < 0)
            {
                availPointAmt = 0;
            }

            #endregion 计算可退现金/积分/礼品卡
        }
        /// <summary>
        /// 退款
        /// </summary>
        /// <param name="entity"></param>
        public virtual void Refund(RefundBalanceInfo entity)
        {
            RefundBalanceInfo refundBalanceInfo;
            SOInfo            soInfo;

            VerifyForRefund(entity, out soInfo, out refundBalanceInfo);
            soInfo.BaseInfo.GiftCardPay   = soInfo.BaseInfo.GiftCardPay ?? 0M;
            refundBalanceInfo.GiftCardAmt = refundBalanceInfo.GiftCardAmt ?? 0M;
            refundBalanceInfo.PointAmt    = refundBalanceInfo.PointAmt ?? 0;

            decimal availShipPrice, cashRemoveGiftCard, availGiftCard, totalRoBoBalanceAmt;
            int     availPointAmt;

            CalculateAvailRefundAmt(entity, soInfo.BaseInfo, out availShipPrice, out cashRemoveGiftCard, out availGiftCard, out availPointAmt, out totalRoBoBalanceAmt);

            if (refundBalanceInfo.CashAmt > cashRemoveGiftCard || refundBalanceInfo.GiftCardAmt > availGiftCard ||
                refundBalanceInfo.PointAmt > availPointAmt)
            {
                throw new BizException(
                          ResouceManager.GetMessageString("RMA.RefundBalance", "Refund_ReCreateRefundBalance"));
            }


            decimal ROAmt;

            PreCheckForRefund(refundBalanceInfo, totalRoBoBalanceAmt, availShipPrice, out ROAmt);

            int tmpNewOrderSysNo = 0;

            #region 事务中执行退款操作
            TransactionOptions options = new TransactionOptions();
            options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            options.Timeout        = TransactionManager.DefaultTimeout;
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                AbandonPoint(refundBalanceInfo);

                if (refundBalanceInfo.RefundPayType == RefundPayType.PrepayRefund)
                {
                    if (refundBalanceInfo.CashAmt.Value > soInfo.BaseInfo.SOAmount)
                    {
                        throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "Refund_CashAmtValid"));
                    }

                    RefundPrepay(refundBalanceInfo);
                }
                else if (refundBalanceInfo.RefundPayType == RefundPayType.TransferPointRefund)
                {
                    if (refundBalanceInfo.CashAmt.Value > soInfo.BaseInfo.SOAmount)
                    {
                        throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "Refund_CashAmtValid"));
                    }

                    TransferPointRefund(refundBalanceInfo);
                }

                CreateSOIncome(refundBalanceInfo);

                // 现金部分生成新礼品卡
                RefundInfo refundInfo = refundProcessor.LoadBySysNo(entity.OriginalRefundSysNo.Value);
                if (refundBalanceInfo.RefundPayType == RefundPayType.GiftCardRefund && refundBalanceInfo.CashAmt > 0)
                {
                    refundProcessor.CreateElectronicGiftCard(refundInfo, refundBalanceInfo.CashAmt.Value, "ROBalance");
                }
                //礼品卡部分依次退返
                if (refundBalanceInfo.GiftCardAmt > 0)
                {
                    refundProcessor.RefundGiftCard(refundInfo, refundBalanceInfo.GiftCardAmt.Value, "ROBalance", refundBalanceInfo.SysNo.Value);
                }

                UpdateRefundBalanceForRefund(entity.SysNo.Value, ROAmt, out tmpNewOrderSysNo);

                //20130808 Chester Added:完成RMA退款调整单待审核- 待办事项:
                EventPublisher.Publish <RMACompleteRefundBalanceWaitingForAuditMessage>(new RMACompleteRefundBalanceWaitingForAuditMessage()
                {
                    RefundBalanceSysNo = entity.SysNo.Value,
                    RefundSysNo        = entity.OriginalRefundSysNo.Value,
                    CurrentUserSysNo   = ServiceContext.Current.UserSysNo
                });

                scope.Complete();
            }
            #endregion

            //发送SSB
            string stockID = ExternalDomainBroker.GetSOItemList(soInfo.SysNo.Value).FirstOrDefault().StockSysNo.Value.ToString();

            if (stockID != null && soInfo != null)
            {
                //if (stockID.Trim() == RMAConst.WarehouseNo_GZ
                //   || stockID.Trim() == RMAConst.WarehouseNo_XA
                //   || soInfo.InvoiceInfo.IsVAT == true)
                if (soInfo.InvoiceInfo.IsVAT == true)
                {
                    ObjectFactory <SendSSBProcessor> .Instance.SendADJUSTMessage(tmpNewOrderSysNo, stockID, entity.CompanyCode);
                }
            }
        }
Exemple #15
0
        public virtual void SendDunEmail(int OutboundSysNo, int RegisterSysNo, int SendMailCount, int SOSysNo)
        {
            if (outBoundDA.UpdateOutboundItemSendEmailCount(OutboundSysNo, RegisterSysNo, SendMailCount))
            {
                #region 构建邮件模板,调用EmailService发送邮件

                RMARegisterInfo registerInfo = ObjectFactory <IRegisterDA> .Instance.LoadBySysNo(RegisterSysNo);

                int productSysNo = registerInfo.BasicInfo.ProductSysNo.Value;

                ProductManagerInfo pmInfo  = ExternalDomainBroker.GetPMInfoByProductSysNo(productSysNo);
                ProductInfo        product = ExternalDomainBroker.GetProductInfo(productSysNo);

                DataRow  dr         = outBoundDA.GetOutboundBySysNo(OutboundSysNo);
                string   vendorName = string.Empty;
                DateTime outTime    = DateTime.Now;
                if (dr != null)
                {
                    vendorName = dr["VendorName"].ToString();
                    outTime    = Convert.ToDateTime(dr["OutTime"]);
                }
                int        vendorSysNo = Convert.ToInt32(dr["VendorSysNo"]);
                VendorInfo vendorInfo  = ExternalDomainBroker.GetVendorFinanceInfoByVendorSysNo(vendorSysNo);

                SOInfo soInfo   = ExternalDomainBroker.GetSOInfo(SOSysNo);
                string SODate   = soInfo.BaseInfo.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                string Warranty = soInfo.Items.Where(p => p.ProductSysNo == productSysNo).FirstOrDefault().Warranty;

                //填充邮件模板
                KeyValueVariables vars = new KeyValueVariables();
                vars.Add("CurrentYear", DateTime.Now.Year);
                vars.Add("CurrentMonth", DateTime.Now.Month);
                vars.Add("CurrentDay", DateTime.Now.Day);
                vars.Add("CurrentTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                ///Load单件填充的数据
                vars.Add("RegisterSysNo", registerInfo.SysNo.Value);
                vars.Add("ProductID", product.ProductID);
                vars.Add("ProductName", product.ProductName);
                vars.Add("Memo", registerInfo.BasicInfo.Memo);
                vars.Add("RefundStatus", registerInfo.BasicInfo.RefundStatus);
                vars.Add("RevertStatus", registerInfo.RevertInfo.RevertStatus);
                vars.Add("ProductCost", registerInfo.BasicInfo.Cost);

                vars.Add("PMName", pmInfo.UserInfo.UserDisplayName);

                vars.Add("Day", GetTimeSpan(outTime).Days);
                vars.Add("Hour", GetTimeSpan(outTime).Hours);
                vars.Add("Secend", GetTimeSpan(outTime).Minutes);
                vars.Add("VendorName", vendorName);
                vars.Add("OutTime", outTime.ToString("yyyy-MM-dd HH:mm:ss"));

                vars.Add("SOSysNo", SOSysNo);
                vars.Add("SODate", SODate);
                vars.Add("Warranty", Warranty);

                vars.Add("IsContact", IsContactDesc(vendorInfo));
                vars.Add("PayPeriodType", vendorInfo.VendorFinanceInfo.PayPeriodType.PayTermsName);

                string ccAddress = AppSettingManager.GetSetting("RMA", "OutBoundNotReturnEmails");
                EmailHelper.SendEmailByTemplate(pmInfo.UserInfo.EmailAddress, ccAddress, "", "SendDunMailForOutBoundNotReturn", vars, null, true, true);
                #endregion
            }
        }
        /// <summary>
        /// 创建申请单于单件
        /// </summary>
        /// <param name="soNumber"></param>
        /// <param name="userID"></param>
        /// <param name="strNote"></param>
        /// <param name="strMemo"></param>
        /// <param name="warehouseNumber"></param>
        /// <param name="refRequestSysNo"></param>
        /// <returns></returns>
        private bool CreateRequest(int soNumber, int userSysNo, string strNote, string strMemo, int warehouseNumber, ref int refRequestSysNo)
        {
            bool result = false;

            SOInfo so = ExternalDomainBroker.GetSOInfo(soNumber);

            RMARequestInfo request = new RMARequestInfo();

            int requestSysNo = rmaSellerPortalDA.CreateSequence(TableName_RMA_Request_Sequence);

            string strRequestID = GenerateID(requestSysNo);

            request.SysNo            = requestSysNo;
            request.RequestID        = strRequestID;
            request.SOSysNo          = soNumber;
            request.CustomerSysNo    = so.BaseInfo.CustomerSysNo;
            request.Address          = so.ReceiverInfo.Address;
            request.Contact          = so.ReceiverInfo.Name;
            request.Phone            = so.ReceiverInfo.Phone;
            request.ReceiveTime      = DateTime.Now;
            request.ReceiveUserSysNo = userSysNo;
            request.Note             = strNote;
            request.Memo             = strMemo;
            request.Status           = RMARequestStatus.Handling;
            request.AreaSysNo        = so.ReceiverInfo.AreaSysNo;
            request.CustomerSendTime = DateTime.Now;
            request.IsRejectRMA      = true;
            request.ReceiveWarehouse = warehouseNumber.ToString();
            request.IsSubmit         = true;
            request.ShipViaCode      = "退换货自动处理,快递方式缺省";
            refRequestSysNo          = requestSysNo;
            request.CompanyCode      = so.CompanyCode;

            TransactionOptions options = new TransactionOptions();

            options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            options.Timeout        = TransactionManager.DefaultTimeout;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                requestDA.Create(request);

#if DEBUG
                if (Transaction.Current != null)
                {
                    Debug.WriteLine(string.Format("LocalIdentifier:[{0}] Status:[{1}]",
                                                  Transaction.Current.TransactionInformation.LocalIdentifier,
                                                  Transaction.Current.TransactionInformation.Status.ToString())
                                    );
                }
#endif
                foreach (SOItemInfo soItem in so.Items)
                {
                    if (soItem.ProductType == SOProductType.Coupon)
                    {
                        continue;
                    }

                    for (int i = 0; i < soItem.Quantity; i++)
                    {
                        RMARegisterInfo register = new RMARegisterInfo();
                        register.CompanyCode = so.CompanyCode;

                        int registerSysNo = rmaSellerPortalDA.CreateSequence(TableName_RMA_Register_Sequence);

                        register.SysNo = registerSysNo;

                        if (soItem.ProductType == SOProductType.ExtendWarranty)
                        {
                            register.BasicInfo.ProductSysNo = int.Parse(soItem.MasterProductSysNo);
                            register.BasicInfo.OwnBy        = RMAOwnBy.Origin;
                            register.BasicInfo.Location     = RMALocation.Origin;
                        }
                        else
                        {
                            register.BasicInfo.ProductSysNo = soItem.ProductSysNo;
                            register.BasicInfo.OwnBy        = RMAOwnBy.Customer;
                            register.BasicInfo.Location     = RMALocation.Self;
                        }

                        register.RequestType            = RMARequestType.Return;
                        register.BasicInfo.CustomerDesc = "物流拒收";

                        register.BasicInfo.NextHandler   = RMANextHandler.RMA;
                        register.BasicInfo.Status        = RMARequestStatus.Handling;
                        register.BasicInfo.IsWithin7Days = true;

                        register.CheckInfo.IsRecommendRefund = true;

                        //HACK:大小写 Cost
                        register.BasicInfo.Cost            = soItem.CostPrice;
                        register.BasicInfo.RMAReason       = 0;//质量问题
                        register.BasicInfo.CloseUserSysNo  = userSysNo;
                        register.BasicInfo.CloseTime       = DateTime.Now;
                        register.BasicInfo.IsHaveInvoice   = true;
                        register.BasicInfo.IsFullAccessory = true;
                        register.BasicInfo.IsFullPackage   = true;
                        //RMA Warehouse
                        register.BasicInfo.LocationWarehouse = warehouseNumber.ToString();
                        register.BasicInfo.OwnByWarehouse    = ((int)RMAOwnBy.Origin).ToString();

                        //使用传过来的warehouseNumber
                        register.BasicInfo.ShippedWarehouse = warehouseNumber.ToString();

                        register.BasicInfo.SOItemType = soItem.ProductType;

                        bool insertRegisterResult = registerDA.Create(register);

                        bool inserRequestItemResult = registerDA.InsertRequestItem(requestSysNo, registerSysNo);

                        if (insertRegisterResult && inserRequestItemResult)
                        {
                            result = true;
                        }
                    }
                }
                scope.Complete();
            }

            return(result);
        }
 /// <summary>
 /// 关闭RMA跟进单
 /// </summary>
 /// <param name="msg"></param>
 public virtual void CloseRMATracking(InternalMemoInfo msg)
 {
     //关闭RMA跟进单的同时需要关闭客户来电记录
     ExternalDomainBroker.CloseCustomerCalling(msg.SysNo.Value, msg.Note);
     DA.Close(msg);
 }
        /// <summary>
        /// 计算退现金、初算退礼品卡、退现金、退礼品卡
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="soBaseInfo"></param>
        private void Calc(RefundBalanceInfo entity, SOBaseInfo soBaseInfo)
        {
            decimal availShipPrice, cashRemoveGiftCard, availGiftCard, totalRoBoBalanceAmt;
            int     availPointAmt;

            CalculateAvailRefundAmt(entity, soBaseInfo, out availShipPrice, out cashRemoveGiftCard, out availGiftCard, out availPointAmt, out totalRoBoBalanceAmt);
            soBaseInfo.GiftCardPay = soBaseInfo.GiftCardPay ?? 0M;

            #region 根据可用退现金,修正调整单金额的现金、礼品卡、积分部分

            if (entity.CashAmt > 0)
            {
                if (cashRemoveGiftCard >= entity.CashAmt)//有现金可作调整单
                {
                    entity.GiftCardAmt = 0;
                    entity.PointAmt    = 0;
                }
                else if (cashRemoveGiftCard == 0)//可退现金为0
                {
                    if (availGiftCard > 0)
                    {
                        if (entity.CashAmt <= availGiftCard)//礼品卡可用
                        {
                            entity.GiftCardAmt = entity.CashAmt;
                            entity.PointAmt    = 0;
                        }
                        else//退完礼品卡还有金额转为积分
                        {
                            entity.GiftCardAmt = availGiftCard;

                            entity.PointAmt = Convert.ToInt32(Decimal.Round((entity.CashAmt.Value - availGiftCard) * pointExchangeRate, 0));
                            if (entity.PointAmt > availPointAmt)
                            {
                                entity.PointAmt = availPointAmt;
                            }
                            if (availGiftCard == 0 && availPointAmt == 0)
                            {
                                throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "RefundTooMuch"));
                            }
                            if (availGiftCard == 0 && entity.CashAmt.Value < 0.1m)
                            {
                                throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "OnlyAdjustPoints"));
                            }
                        }
                    }
                    else
                    {
                        entity.PointAmt = Convert.ToInt32(Decimal.Round(entity.CashAmt.Value * pointExchangeRate, 0));
                    }
                    entity.CashAmt = 0;
                }
                else//有部分现金可退,剩余部分使用礼品卡
                {
                    entity.GiftCardAmt = entity.CashAmt - cashRemoveGiftCard;
                    if (entity.GiftCardAmt > availGiftCard)
                    {
                        entity.PointAmt = Convert.ToInt32(Decimal.Round((entity.GiftCardAmt.Value - availGiftCard) * pointExchangeRate, 0));
                        if (entity.PointAmt > availPointAmt)
                        {
                            entity.PointAmt = availPointAmt;
                        }
                        entity.GiftCardAmt = availGiftCard;
                    }
                    else
                    {
                        entity.PointAmt = 0;
                    }
                    entity.CashAmt = cashRemoveGiftCard;
                }
            }
            else
            {
                entity.GiftCardAmt = 0;
                entity.PointAmt    = 0;
            }

            #endregion 根据可用退现金,修正调整单金额的现金、礼品卡、积分部分

            if (entity.ProductSysNo != 0) //商品调整
            {
                #region SOItem

                RefundItemInfo refundItem = refundBalanceDA.GetRefundTotalAmount(entity);

                decimal tempRefunded = (refundItem.RefundPrice ?? 0M) + entity.CashAmt.Value + totalRoBoBalanceAmt;
                decimal productValue = refundItem.ProductValue ?? 0;

                if (productValue < tempRefunded)
                {
                    throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "RefundTooMuch"));
                }
                if (tempRefunded < 0)
                {
                    throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "NotGreaterThanRefundedAmt"));
                }

                #region 现金、礼品卡、积分金额划分

                decimal refundAmt = entity.CashAmt.Value + entity.GiftCardAmt.Value;
                if (refundAmt > 0 && entity.PointAmt == 0)
                {
                    #region 计算 现金与积分比率

                    decimal originalSOCashPointRate = 0;          //不四舍五入的比率:现金部分与总额的比例

                    decimal           pointOnly = 0;              // 仅积分支付部分对应的价值
                    decimal           cashOnly  = 0;              // 仅现金支付部分对应的价值
                    decimal           totalPromotionDiscount = 0; //优惠券
                    List <SOItemInfo> soItems = ExternalDomainBroker.GetSOItemList(entity.OriginalSOSysNo.Value);
                    soItems.ForEach(item =>
                    {
                        if (item.PayType == ProductPayType.PointOnly)
                        {
                            pointOnly += item.Price.Value * item.Quantity.Value + item.PromotionAmount.Value;
                        }
                        else if (item.PayType == ProductPayType.MoneyOnly)
                        {
                            cashOnly += item.Price.Value * item.Quantity.Value + item.PromotionAmount.Value;
                        }

                        totalPromotionDiscount += item.PromotionAmount.Value * item.Quantity.Value;
                    });

                    //表示只有仅积分或仅现金部分,没有均支持
                    if ((soBaseInfo.SOAmount + soBaseInfo.PromotionAmount) - (totalPromotionDiscount + pointOnly + cashOnly) == 0M)
                    {   //仅现金
                        if (pointOnly == 0 && cashOnly > 0)
                        {
                            originalSOCashPointRate = 1;
                        }
                        else //仅积分
                        {
                            originalSOCashPointRate = 0;
                        }
                    }
                    else if (soBaseInfo.CashPay - cashOnly == 0)
                    {
                        originalSOCashPointRate = 1;
                    }
                    else if (soBaseInfo.PointPay - pointOnly == 0)
                    {
                        originalSOCashPointRate = 0;
                    }
                    else
                    {   //表示均支持的现金部分与均支持的总额的比例
                        originalSOCashPointRate = (soBaseInfo.CashPay + soBaseInfo.PromotionAmount.Value - cashOnly)
                                                  / (soBaseInfo.SOAmount.Value + soBaseInfo.PromotionAmount.Value - (totalPromotionDiscount + pointOnly + cashOnly));
                    }

                    #endregion 计算 现金与积分比率

                    //根据单件退款额度,调整比率精度
                    int decimals = Decimal.Round(refundAmt, 0).ToString().Length + 2;
                    //实际计算精度
                    decimal SOCashPointRate = Decimal.Round(originalSOCashPointRate, decimals);

                    int refundPoint = Convert.ToInt32(Decimal.Round(refundAmt * (1 - SOCashPointRate) * pointExchangeRate, 0));

                    decimal refundCash = refundAmt - (Decimal.Round(refundAmt * (1 - SOCashPointRate), 2));

                    //积分补偿
                    decimal pointRedeem = -Decimal.Round((Decimal.Round(refundAmt * (1 - SOCashPointRate) * pointExchangeRate, 0)
                                                          - (refundAmt * (1 - SOCashPointRate) * pointExchangeRate)) / pointExchangeRate, 2);

                    refundCash += pointRedeem;

                    #region 分配现金、礼品卡

                    if (refundPoint < 0)
                    {
                        refundPoint = 0;
                    }
                    if (entity.CashAmt > 0)
                    {
                        if (entity.GiftCardAmt == 0)
                        {
                            entity.CashAmt = refundCash;
                        }
                        else
                        {
                            if (entity.CashAmt > refundCash)
                            {
                                entity.GiftCardAmt = entity.CashAmt - refundCash;
                            }
                            else
                            {
                                entity.GiftCardAmt = refundCash - entity.CashAmt;
                            }
                        }
                    }
                    else
                    {
                        entity.GiftCardAmt = refundCash;
                    }
                    entity.PointAmt = refundPoint;
                    if (entity.PointAmt > availPointAmt)
                    {
                        entity.PointAmt = availPointAmt;
                    }

                    #endregion 分配现金、礼品卡

                    #endregion 现金、礼品卡、积分金额划分
                }

                #endregion SOItem
            }
            else //运费补偿及其他
            {
                #region 运费补偿及其他

                if (availShipPrice < entity.CashAmt.Value)
                {
                    throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "OverfullShipFee"));
                }
                //if (entity.CashAmt.Value < 0)
                //{
                //    throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "NotGreaterThanRefundedAmt"));
                //}
                if (entity.PointAmt > 0)
                {
                    throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "CannotUsePointsForRefundShipFee"));
                }

                #endregion 运费补偿及其他
            }
        }