Beispiel #1
0
        public static RMARefundInfo Confirm(int rmaRefundSysNo, LoginUser operateUser)
        {
            RMARefundInfo info = LoadWithRefundSysNo(rmaRefundSysNo, operateUser.SellerSysNo);

            if (info == null)
            {
                throw new BusinessException(L("未找到编号为【{0}】的退款单", rmaRefundSysNo));
            }
            if (info.Status != RMARefundStatus.WaitingRefund)
            {
                throw new BusinessException(L("退款单不是“待退款”,不能确认退款"));
            }
            SOInfo soInfo = SOService.GetSOInfo(info.SOSysNo.Value);

            if (soInfo == null)
            {
                throw new BusinessException(L("订单不存在"));
            }
            info.Status          = RMARefundStatus.Refunded;
            info.SOIncomeStatus  = SOIncomeStatus.Confirmed;
            info.RefundUserSysNo = operateUser.UserSysNo;
            info.RefundUserName  = operateUser.UserDisplayName;
            info.RefundDate      = DateTime.Now;

            //using (ITransaction ts = TransactionManager.Create(
            //     System.Transactions.TransactionScopeOption.Required, System.Transactions.IsolationLevel.ReadUncommitted))
            using (ITransaction ts = TransactionManager.Create())
            {
                //积分撤销
                ReturnProductPoint(info, operateUser.UserSysNo);
                //退入余额帐户
                RefundPrepay(info);

                //更新客户累计购买金额
                if (info.CashAmt != 0)
                {
                    CustomerService.UpdateCustomerOrderedAmt(info.CustomerSysNo.Value, -1 * info.CashAmt.Value);
                }
                RMARefundDA.Update(info);
                RMARefundDA.BatchUpdateRegisterRefundStatusAndStatus(info.SysNo.Value, RMARefundStatus.Refunded, RMARequestStatus.Complete);
                //RMARefundDA.ConfirmRefundSOIncome(info);
                SOIncomeInfo soIncomeInfo = new SOIncomeInfo()
                {
                    OrderType      = SOIncomeOrderType.RO,
                    OrderSysNo     = info.SysNo,
                    OrderAmt       = -1 * info.CashAmt,
                    IncomeStyle    = SOIncomeOrderStyle.RO,
                    IncomeAmt      = -1 * info.CashAmt,
                    PayAmount      = -1 * info.CashAmt,
                    InUserSysNo    = operateUser.UserSysNo,
                    InUserName     = operateUser.UserDisplayName,
                    Status         = SOIncomeStatus.Origin,
                    PointPay       = info.PointPay,
                    GiftCardPayAmt = info.GiftCardAmt,
                };
                RMARefundDA.CreateRefundSOIncome(soIncomeInfo);


                var rmaRequstSysNoList = RMARefundDA.QueryRMARequsetSysNoByRefundSysNo(info.SysNo.Value);
                if (rmaRequstSysNoList != null && rmaRequstSysNoList.Count > 0)
                {
                    foreach (var rmaRequestSysNo in rmaRequstSysNoList)
                    {
                        RMARequestService.RefreshRequestStatus(rmaRequestSysNo, operateUser.SellerSysNo);
                    }
                }

                SOIncomeInfo rmaIncomeInfo = SOIncomeDA.GetValidSOIncomeInfo(info.SysNo.Value, SOIncomeOrderType.RO);
                //ECC确认退款开始
                if (info.RefundPayType == RefundPayType.NetWorkRefund)
                {
                    //发起银行网关退款
                    RefundResult result = ProcessNetWorkRefund(rmaIncomeInfo, soInfo);
                    if (!result.Result)
                    {
                        throw new BusinessException(result.Message);
                    }
                    else
                    {
                        rmaIncomeInfo.ExternalKey = result.ExternalKey;       //退款流水号
                        rmaIncomeInfo.Status      = SOIncomeStatus.Confirmed; //等待银行后台回调处理中
                        RMARefundDA.ConfirmRefundSOIncomeNet(info, soIncomeInfo);
                    }
                }
                else if (info.RefundPayType == RefundPayType.BankRefund)
                {
                    RMARefundDA.ConfirmRefundSOIncome(info);
                }


                ts.Complete();
            }
            return(info);
        }