Exemplo n.º 1
0
 private void btnCreate_Click(object sender, EventArgs e)
 {
     if (label1.Text == "발주 수정")
     {
         OrderService service = new OrderService();
         OrderListVO  vo      = new OrderListVO()
         {
             order_id    = Convert.ToInt32(label1.Tag),
             order_edate = dtpEdate.Text,
             order_count = Convert.ToInt32(nuCount.Value)
         };
         if (service.UpdateOrder(vo) == 1)
         {
             MessageBox.Show("수정 완료");
             this.Close();
         }
     }
     else
     {
         SOService service = new SOService();
         SOListVO  vo      = new SOListVO()
         {
             so_id     = Convert.ToInt32(label1.Tag),
             so_edate  = dtpEdate.Text,
             so_ocount = Convert.ToInt32(nuCount.Value)
         };
         if (service.UpdateSO(vo) == 1)
         {
             MessageBox.Show("수정 완료");
             this.Close();
         }
     }
 }
Exemplo n.º 2
0
        private void frmSOPopUP_Load(object sender, EventArgs e)
        {
            CommonUtil.SetInitGridView(dgvCompany);
            CommonUtil.AddGridTextColumn(dgvCompany, "업체명", "company_name", 200);
            CommonUtil.SetInitGridView(dgvProd);
            CommonUtil.AddGridTextColumn(dgvProd, "업체명", "company_name", 200);
            CommonUtil.AddGridTextColumn(dgvProd, "업체번호", "company_id", 0, false);
            CommonUtil.AddGridTextColumn(dgvProd, "품목명", "product_name", 200);
            CommonUtil.AddGridTextColumn(dgvProd, "품목번호", "product_id", 0, false);
            CommonUtil.AddGridTextColumn(dgvProd, "현재고", "", 120);
            //CommonUtil.AddGridTextColumn(dgvProduct, "발주수량", "", 120);
            DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn();

            col.Name       = "";
            col.HeaderText = "수주수량";
            col.Width      = 120;
            col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;

            dgvProd.Columns.Add(col);

            SOService service = new SOService();

            list = service.OrderPList();
            dgvCompany.DataSource = service.CompanyList();
            if (so_id != 0)
            {
                label1.Text = "발주 수정";
            }
        }
Exemplo n.º 3
0
        public void SOList()
        {
            SOService service = new SOService();

            list             = service.SOList();
            dgvSO.DataSource = list;
        }
Exemplo n.º 4
0
        public static bool SendSMSForSO(int soSysNo, SMSType smsType)
        {
            SOInfo            soInfo               = SOService.GetSOInfo(soSysNo);
            CustomerBasicInfo customerInfo         = CustomerService.GetCustomerInfo(soInfo.CustomerSysNo);
            string            customerLanguageCode = customerInfo.LanguageCode;

            var sms        = CommonDA.GetShipTypeSMSInfo(soInfo.ShipType.ShipTypeSysNo, smsType, null);
            var smsContent = sms.SMSContent;

            if (string.IsNullOrEmpty(smsContent))
            {
                return(false);
            }
            string mobilePhone = string.Empty;

            if (!string.IsNullOrEmpty(soInfo.ReceiveCellPhone))
            {
                mobilePhone = soInfo.ReceiveCellPhone;
            }
            else
            {
                mobilePhone = soInfo.ReceivePhone;
            }

            if (smsContent.IndexOf("SO#") != -1)
            {
                smsContent = smsContent.Replace("SO#", soInfo.SOSysNo.ToString());
            }
            else
            {
                return(false);
            }

            return(SendSMS(mobilePhone, smsContent, SMSPriority.Normal));
        }
Exemplo n.º 5
0
        public ActionResult AjaxMaintainUpdate()
        {
            var soUpdateInfo = SerializationUtility.JsonDeserialize2 <SOUpdateInfo>(Request.Form["data"]);

            SOService.SOUpdate(soUpdateInfo);
            return(new JsonResult());
        }
Exemplo n.º 6
0
        public ActionResult AjaxSOVoid()
        {
            SOIncomeRefundInfo refundInfo = SerializationUtility.JsonDeserialize2 <SOIncomeRefundInfo>(Request.Form["data"]);
            LoginUser          user       = EntityConverter <UserAuthVM, LoginUser> .Convert(UserAuthHelper.GetCurrentUser());

            SOService.VoidSO(refundInfo.SOSysNo.Value, refundInfo, loginUser: user);
            return(new JsonResult());
        }
Exemplo n.º 7
0
        public ActionResult AjaxSOOutStock()
        {
            SOOutStockWaitReportRequest outStockWaitReportRequest = SerializationUtility.JsonDeserialize2 <SOOutStockWaitReportRequest>(Request.Form["data"]);
            LoginUser user = EntityConverter <UserAuthVM, LoginUser> .Convert(UserAuthHelper.GetCurrentUser());

            outStockWaitReportRequest.User = user;
            SOService.OutStockWaitReport(outStockWaitReportRequest);
            return(new JsonResult());
        }
Exemplo n.º 8
0
        public ActionResult AjaxAOQuery()
        {
            //每页显示条数:
            var qFilter = BuildQueryFilterEntity <AOQueryFilter>();

            qFilter.MerchantSysNo = UserAuthHelper.GetCurrentUser().SellerSysNo;
            QueryResult result = SOService.AOQuery(qFilter);

            return(AjaxGridJson(result));
        }
Exemplo n.º 9
0
        public static async Task DoSyncSO()
        {
            var hour = DateTime.Now.Hour;

            if (hour >= 8 && hour <= 20)
            {
                var soService = new SOService();
                await soService.SyncSOs();
            }
        }
Exemplo n.º 10
0
        public ActionResult AjaxIsNetPayed()
        {
            var soInfo = SOService.GetSOInfo(int.Parse(Request.QueryString["soSysNo"]));
            var result = new JsonResult
            {
                Data = soInfo.IsNetPayed == 1,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };

            return(result);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 接收退货
        /// </summary>
        /// <param name="rmaRequestSysNo">退换货申请单编号</param>
        /// <param name="userSysNo">操作人用户</param>
        /// <returns></returns>
        public static RMARequestInfo Receive(int rmaRequestSysNo, LoginUser operateUser)
        {
            RMARequestInfo request = LoadWithRequestSysNo(rmaRequestSysNo, operateUser.SellerSysNo);

            if (request == null)
            {
                throw new BusinessException(L("未找到编号为【{0}】的退换货申请单", rmaRequestSysNo));
            }
            if (request.Status != RMARequestStatus.Origin)
            {
                throw new BusinessException(L("不能接收非“待处理”状态的申请单"));
            }
            if (request.Registers == null || request.Registers.Count <= 0)
            {
                throw new BusinessException(L("没有需要退换货的商品"));
            }
            //TODO: 虚拟仓库编码
            request.ReceiveWarehouse = "90";
            request.RecvTime         = DateTime.Now;
            request.RecvUserSysNo    = operateUser.UserSysNo;
            request.RecvUserName     = operateUser.UserDisplayName;
            //收货后状态变成“处理中”,这个时候可以进行退货或退款操作
            request.Status = RMARequestStatus.Handling;

            bool isWithin7Days = false;

            if (request.CustomerSendTime.HasValue)
            {
                isWithin7Days = request.CustomerSendTime.Value.AddDays(-7) < DateTime.Now;
            }
            List <SOItemInfo> soItems = SOService.GetSOItemInfoList(request.SOSysNo.Value);
            SOItemInfo        soItem  = null;

            foreach (var reg in request.Registers)
            {
                reg.OwnBy             = RMAOwnBy.Customer;
                reg.Location          = RMALocation.Self;
                reg.LocationWarehouse = request.ReceiveWarehouse;
                reg.IsWithin7Days     = isWithin7Days;
                reg.Status            = request.Status;

                soItem = soItems.Find(x => x.ProductSysNo == reg.ProductSysNo.Value &&
                                      x.ProductType == reg.SoItemType.Value);
                if (soItem == null)
                {
                    throw new BusinessException(L("订单中不存在申请退换货的商品:{0}【1】", reg.ProductName, reg.ProductID));
                }
                reg.Cost = soItem.Cost;
            }
            ;

            UpdateWithRegisters(request);
            return(request);
        }
Exemplo n.º 12
0
        public JsonResult AjaxRefund(string SOSysNo)
        {
            int soSysNo;

            if (string.IsNullOrWhiteSpace(SOSysNo) || !int.TryParse(SOSysNo, out soSysNo) || soSysNo <= 0)
            {
                throw new BusinessException(ECommerce.WebFramework.LanguageHelper.GetText("订单编号不正确,退款失败"));
            }
            SOService.AORefund(soSysNo, UserAuthHelper.GetCurrentUser().SellerSysNo
                               , UserAuthHelper.GetCurrentUser().UserSysNo);
            return(Json(new { SOSysNo = soSysNo }));
        }
Exemplo n.º 13
0
        private void newBtns1_btnDelete_Event(object sender, EventArgs e)
        {
            string    msg     = Properties.Resources.msgDelete;
            SOService service = new SOService();

            if (MessageBox.Show(msg, "삭제확인", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                if (service.DeleteSO(so_id) != 0)
                {
                    MessageBox.Show("삭제완료");
                    SOList();
                }
            }
        }
Exemplo n.º 14
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            SOService service = new SOService();

            if (so_id == 0)
            {
                soList[0].so_edate   = dtpEdate.Text;
                soList[0].so_rep     = txtRep.Text;
                soList[0].so_comment = txtComment.Text;
                if (service.RegistSO(soList) != 0)
                {
                    MessageBox.Show("수주 완료");
                    this.Close();
                }
            }
            else
            {
            }
        }
Exemplo n.º 15
0
        public ActionResult AjaxSOOpreate()
        {
            var soSysNos    = SerializationUtility.JsonDeserialize2 <int[]>(Request.Form["data"]);
            var opreateName = Request.Form["opreateName"];

            switch (opreateName)
            {
            case "AuditAccept":
                SOService.AuditAccept(soSysNos);
                break;

            case "BatchVoid":
                LoginUser user = EntityConverter <UserAuthVM, LoginUser> .Convert(UserAuthHelper.GetCurrentUser());

                SOService.BatchVoidSO(soSysNos, user: user);
                break;

            case "BatchOutStock":
                SOService.BatchOutStock(soSysNos);
                break;

            case "BatcReported":
                SOService.BatcReported(soSysNos);
                break;

            case "BatchCustomsPass":
                SOService.BatchCustomsPass(soSysNos);
                break;

            case "BatchUpdateToPaid":
                SOService.BatcUpdateToPaid(soSysNos);
                break;

            default:
                throw new BusinessException(LanguageHelper.GetText("无效的操作类型"));
            }

            return(new JsonResult());
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
        public ActionResult AjaxSaveExcel()
        {
            var data = SerializationUtility.JsonDeserialize2 <List <ExcelInfo> >(Request.Form["data"]);

            if (!string.IsNullOrEmpty(data[0].Url))
            {
                System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(".");
                System.Text.RegularExpressions.Match m = r.Match(data[0].Url);
                if (m.Success)
                {
                    string suffix = data[0].Url.Substring(data[0].Url.LastIndexOf(".") + 1);
                    if (suffix != "xls" && suffix != "xlsx" && suffix != "xlsm")
                    {
                        throw new BusinessException(LanguageHelper.GetText("只能导入Excel格式,请参考模板!!!"));
                    }
                }
            }
            string    Url = System.Web.HttpContext.Current.Server.MapPath(string.Format("~/UploadFiles/{0}", data[0].Url));
            DataTable dt  = FileSvr.GetExcelDatatable(Url, data[0].Name);

            if (dt.Rows.Count > 0)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("<SOTrackingInfos>");
                string    UserID          = UserAuthHelper.GetCurrentUser().UserID;
                int       SellerSysNo     = UserAuthHelper.GetCurrentUser().SellerSysNo;
                int[]     soSysNos        = new int[dt.Rows.Count];
                ArrayList TrackingNumbers = new ArrayList();
                int       i = 0;
                foreach (DataRow dr in dt.Rows)
                {
                    SOOutStockWaitReportRequest outStockWaitReportRequest = new Entity.SO.SOOutStockWaitReportRequest();
                    outStockWaitReportRequest.Logistics = new LogisticsInfo();
                    //如果订单号为空,SOSysNo=0
                    if (!string.IsNullOrEmpty(dr[0].ToString()))
                    {
                        try
                        {
                            outStockWaitReportRequest.SOSysNo = int.Parse(dr[0].ToString());
                        }
                        catch (Exception ex)
                        {
                            throw new BusinessException(LanguageHelper.GetText("订单号只能是正整数"));
                        }
                    }
                    else
                    {
                        outStockWaitReportRequest.SOSysNo = 0;
                    }
                    outStockWaitReportRequest.Logistics.TrackingNumber = string.IsNullOrEmpty(dr[1].ToString()) ? "" : dr[1].ToString();
                    soSysNos.SetValue(outStockWaitReportRequest.SOSysNo, i++);
                    TrackingNumbers.Add(outStockWaitReportRequest.Logistics.TrackingNumber);
                    stringBuilder.Append("<SOTrackingInfo><SONumber>" + outStockWaitReportRequest.SOSysNo + "</SONumber><TrackingNumber>" + outStockWaitReportRequest.Logistics.TrackingNumber + "</TrackingNumber></SOTrackingInfo>");
                }
                stringBuilder.Append("</SOTrackingInfos>");
                SOService.CreatMoreSOSysNoAndTrackingNumber(stringBuilder.ToString(), UserID, SellerSysNo, soSysNos, TrackingNumbers);
                return(Json(new { Success = true, Message = LanguageHelper.GetText("操作成功") }));
            }
            else
            {
                return(Json(new { Error = true, Message = LanguageHelper.GetText("Excel没有数据") }));
            }
        }
Exemplo n.º 18
0
        private static void CalcRefundAmount(RMARefundInfo refundInfo, RMARequestInfo request)
        {
            refundInfo.RefundItems = new List <RMARefundItemInfo>();
            SOInfo soInfo = SOService.GetSOInfo(request.SOSysNo.Value);

            //计算积分支付比例
            decimal originalSOCashPointRate = soInfo.PointAmt / (
                soInfo.Amount.SOAmt
                + soInfo.Amount.ShipPrice
                - Math.Abs(soInfo.PromotionAmt)
                - Math.Abs(soInfo.Amount.DiscountAmt));

            refundInfo.SOCashPointRate = Decimal.Round(originalSOCashPointRate, 4);

            List <SOItemInfo> soItems = SOService.GetSOItemInfoList(request.SOSysNo.Value);
            //计算总计应退金额,包括应退现金+积分+余额
            decimal totalRefundProductValue = Decimal.Round(request.Registers.Sum(registerInfo =>
            {
                var soItem = soItems.Find(x => x.ProductSysNo == registerInfo.ProductSysNo.Value &&
                                          x.ProductType == registerInfo.SoItemType.Value);
                return(soItem.OriginalPrice - Math.Abs(soItem.PromotionDiscount) - Math.Abs(soItem.DiscountAmt / soItem.Quantity));
            }), 2);

            decimal assignedRefundCashAmt = 0m;

            refundInfo.OrgCashAmt = 0m; refundInfo.OrgPointAmt = 0; refundInfo.PointPay = 0;

            for (var index = 0; index < request.Registers.Count; index++)
            {
                RMARegisterInfo   registerInfo = request.Registers[index];
                RMARefundItemInfo refundItem   = new RMARefundItemInfo();
                var soItem = soItems.Find(x => x.ProductSysNo == registerInfo.ProductSysNo.Value &&
                                          x.ProductType == registerInfo.SoItemType.Value);

                refundItem.OrgPrice             = soItem.OriginalPrice;
                refundItem.OrgPoint             = soItem.Point;
                refundItem.PointType            = soItem.PointType;
                refundItem.UnitDiscount         = soItem.DiscountAmt / soItem.Quantity;
                refundItem.ProductValue         = (soItem.OriginalPrice - Math.Abs(soItem.PromotionDiscount)) - Math.Abs(refundItem.UnitDiscount.Value);
                refundItem.RefundCost           = soItem.Cost;
                refundItem.RefundCostWithoutTax = soItem.UnitCostWithoutTax;
                refundItem.RefundPoint          = soItem.Point;
                refundItem.RegisterSysNo        = registerInfo.SysNo;

                if (totalRefundProductValue <= 0m)
                {
                    refundItem.RefundCash = 0m;
                }
                else
                {
                    //按商品价值比例计算单个商品退款金额
                    if (index < request.Registers.Count - 1)
                    {
                        refundItem.RefundCash =
                            ((refundItem.ProductValue / totalRefundProductValue) * refundInfo.CashAmt * (1 - originalSOCashPointRate)).Value;
                    }
                    else
                    {
                        refundItem.RefundCash = refundInfo.CashAmt.Value - assignedRefundCashAmt;
                    }
                }
                refundItem.RefundPrice     = refundItem.RefundCash;
                refundItem.RefundPoint     = Convert.ToInt32(Decimal.Round((refundItem.RefundCash * originalSOCashPointRate).Value, 0));
                refundItem.RefundPriceType = RefundPriceType.OriginPrice;

                refundInfo.OrgCashAmt  += refundItem.RefundCash.Value;
                refundInfo.OrgPointAmt += (-1) * refundItem.RefundPoint.Value;
                refundInfo.PointPay    += refundInfo.OrgPointAmt;

                assignedRefundCashAmt += refundItem.RefundCash.Value;
                refundInfo.RefundItems.Add(refundItem);
            }

            #region 计算顾客积分归还积分折合现金

            refundInfo.DeductPointFromAccount     = 0;
            refundInfo.DeductPointFromCurrentCash = 0m;
            if (refundInfo.OrgPointAmt < 0)
            {
                CustomerBasicInfo customer = CustomerService.GetCustomerInfo(refundInfo.CustomerSysNo.Value);
                if (refundInfo.OrgPointAmt * -1 < customer.ValidScore)
                {
                    refundInfo.DeductPointFromAccount = refundInfo.OrgPointAmt * -1;
                }
                else
                {
                    refundInfo.DeductPointFromAccount     = customer.ValidScore;
                    refundInfo.DeductPointFromCurrentCash =
                        Decimal.Round(((refundInfo.OrgPointAmt ?? 0) * -1
                                       - (customer.ValidScore ?? 0)) / CustomerService.GetPointToMoneyRatio(), 2);
                }
            }
            #endregion
        }
Exemplo n.º 19
0
 public async Task DoSyncSO(Guid sessionId)
 {
     var soService = new SOService(sessionId);
     await soService.SyncSOs();
 }
Exemplo n.º 20
0
        public static RMARefundInfo Create(RMARefundInfo refundInfo, LoginUser operateUser)
        {
            if (!refundInfo.SOSysNo.HasValue)
            {
                throw new BusinessException(L("订单号不能为空"));
            }

            if (refundInfo.RefundPayType == RefundPayType.BankRefund)
            {
                if (string.IsNullOrWhiteSpace(refundInfo.CardOwnerName))
                {
                    throw new BusinessException(L("收款人不能为空"));
                }
                if (string.IsNullOrWhiteSpace(refundInfo.BankName))
                {
                    throw new BusinessException(L("银行名称不能为空"));
                }
                if (string.IsNullOrWhiteSpace(refundInfo.CardNumber))
                {
                    throw new BusinessException(L("银行卡号不能为空"));
                }
                if (!refundInfo.CashAmt.HasValue || refundInfo.CashAmt.Value < 0m)
                {
                    throw new BusinessException(L("退款金额不能小于0"));
                }
                var maxRefundAmt = Decimal.Round(refundInfo.RefundItems.Sum(x => x.ProductValue.Value), 2, MidpointRounding.AwayFromZero);
                if (refundInfo.CashAmt > maxRefundAmt)
                {
                    throw new BusinessException(L("实际退款金额不能大于应退金额:{0}", maxRefundAmt));
                }
            }

            #region 检查订单最大可退金额
            //数据check不包含在事务中
            using (ITransaction trans = TransactionManager.SuppressTransaction())
            {
                var     soItemList      = SOService.GetSOItemInfoList(refundInfo.SOSysNo.Value);
                decimal maxRMARefundAmt = soItemList.Sum(soItem =>
                {
                    return((soItem.OriginalPrice - Math.Abs(soItem.PromotionDiscount)
                            - Math.Abs(soItem.DiscountAmt / soItem.Quantity)) * soItem.Quantity);
                });

                decimal thisRefundAmt = Math.Abs(refundInfo.CashAmt.GetValueOrDefault()) + Math.Abs(refundInfo.PointPay.GetValueOrDefault() * pointExchangeRate)
                                        + Math.Abs(refundInfo.GiftCardAmt.GetValueOrDefault());
                decimal historyRefundAmt = 0m;

                var validRefundList = RMARefundDA.GetValidRefundListBySOSysNo(refundInfo.SOSysNo.Value);
                if (validRefundList != null && validRefundList.Count > 0)
                {
                    historyRefundAmt = validRefundList.Sum(info =>
                    {
                        return(Math.Abs(info.CashAmt.GetValueOrDefault()) + Math.Abs(info.PointPay.GetValueOrDefault() * pointExchangeRate)
                               + Math.Abs(info.GiftCardAmt.GetValueOrDefault()));
                    });
                }
                if (thisRefundAmt + historyRefundAmt > Decimal.Round(maxRMARefundAmt, 2))
                {
                    throw new BusinessException(L("超过原始购物订单#{0}的最大可退金额{1},不能再退款", refundInfo.SOSysNo, Decimal.Round(maxRMARefundAmt, 2)));
                }
                trans.Complete();
            }
            #endregion

            refundInfo.Status         = RMARefundStatus.WaitingAudit;
            refundInfo.SOIncomeStatus = SOIncomeStatus.Origin;
            refundInfo.InUserSysNo    = operateUser.UserSysNo;
            refundInfo.InUserName     = operateUser.UserDisplayName;
            using (ITransaction trans = TransactionManager.Create())
            {
                int newSysNo = RMARefundDA.CreateNewRefundSysNo();
                refundInfo.SysNo    = newSysNo;
                refundInfo.RefundID = String.Format("R3{0:00000000}", newSysNo);
                //创建RMA Refund记录
                RMARefundDA.Create(refundInfo);

                //创建退款银行信息
                SOIncomeRefundInfo soIncomeRefundInfo = new SOIncomeRefundInfo()
                {
                    OrderType       = refundInfo.OrderType,
                    OrderSysNo      = refundInfo.SysNo,
                    SOSysNo         = refundInfo.SOSysNo,
                    BankName        = refundInfo.BankName,
                    CardNumber      = refundInfo.CardNumber,
                    CardOwnerName   = refundInfo.CardOwnerName,
                    RefundPayType   = refundInfo.RefundPayType,
                    CreateUserSysNo = operateUser.UserSysNo,
                    CreateUserName  = operateUser.UserDisplayName,
                    Status          = RefundStatus.Origin,
                    HaveAutoRMA     = false,
                    RefundCashAmt   = refundInfo.CashAmt,
                    RefundPoint     = refundInfo.PointPay,
                    RefundGiftCard  = refundInfo.GiftCardAmt
                };
                RMARefundDA.CreateRefundBankInfo(soIncomeRefundInfo);

                if (refundInfo.RefundItems != null)
                {
                    foreach (var item in refundInfo.RefundItems)
                    {
                        item.RefundSysNo = refundInfo.SysNo;
                        RMARefundDA.CreateItem(item);
                    }
                }
                trans.Complete();
            }

            return(refundInfo);
        }