Ejemplo n.º 1
0
        protected void lbtnSave_Click(object sender, EventArgs e)
        {
            ShowShop.Model.Admin.AdminInfo adminInfo = (ShowShop.Model.Admin.AdminInfo)ShowShop.Common.AdministrorManager.Get();
            if (Convert.ToDecimal(this.txtRefundmentMoney.Text.Trim()) + Convert.ToDecimal(this.txtPoundAge.Text.Trim()) > Convert.ToDecimal(GetPayed(this.lblOrderId.Text)))
            {
                this.ltlMsg.Text = "退款的金额不能大于已付的金额!";
                this.pnlMsg.Visible = true;
                this.pnlMsg.CssClass = "actionErr";
                return;
            }
            //银行支付
            ShowShop.BLL.Order.RemittanceInfo remBll = new ShowShop.BLL.Order.RemittanceInfo();
            ShowShop.Model.Order.RemittanceInfo remModel = remBll.GetModelByOrderId(this.lblOrderId.Text);
            //现金支付
            ShowShop.BLL.Order.PaymentMoney payBll = new ShowShop.BLL.Order.PaymentMoney();
            ShowShop.Model.Order.PaymentMoney payModel = payBll.GetModelByOrderId(this.lblOrderId.Text);
            //预付款
            ShowShop.BLL.Order.PrepayMoney preBll = new ShowShop.BLL.Order.PrepayMoney();
            ShowShop.Model.Order.PrepayMoney preModel = preBll.GetModelByOrderId(this.lblOrderId.Text);
            //订单信息
            ShowShop.BLL.Order.Orders orderBll = new ShowShop.BLL.Order.Orders();
            ShowShop.Model.Order.Orders orderModel = orderBll.GetModel(this.lblOrderId.Text);

            #region 退款信息
            ShowShop.BLL.Order.RefundMent refBll = new ShowShop.BLL.Order.RefundMent();
            ShowShop.Model.Order.RefundMent refModel = new ShowShop.Model.Order.RefundMent();
            refModel.OrderId = this.lblOrderId.Text;
            refModel.UserName = this.lblUserId.Text;
            refModel.PaymentDate = Convert.ToDateTime(this.txtPaymentDate.Text);
            refModel.PoundAge = Convert.ToDecimal(this.txtPoundAge.Text.Trim());
            refModel.RefundMentMoney = Convert.ToDecimal(this.txtRefundmentMoney.Text.Trim());
            refModel.RefundMentMode = this.rabRefundmentMode.SelectedItem.Text;
            refModel.Remark = this.txtRemark.Text;
            refModel.InformMode = GetInforMode(cbxInformMode)["txt"]; //通知方式
            refModel.NoteDate = DateTime.Now;
            refModel.NoteName = adminInfo.AdminName;
            #endregion

            #region 用户交易明细
            ShowShop.Model.Member.UserinAndExp userModel = new ShowShop.Model.Member.UserinAndExp();
            ShowShop.BLL.Member.UserinAndExp userBll = new ShowShop.BLL.Member.UserinAndExp();

            //银行资金的明细
            userModel.UID = this.GetUidByUserId(this.lblUserId.Text);
            userModel.AdsumMoneyDate = Convert.ToDateTime(this.txtPaymentDate.Text);
            userModel.AdsumMoney = Convert.ToDecimal(this.txtRefundmentMoney.Text);
            userModel.PresentCoupons = 0;
            userModel.RemitMode = 1;
            userModel.RemitBank = string.Empty;
            userModel.Remark = this.txtRemark.Text;
            userModel.FormMode = GetInforMode(cbxInformMode)["txt"]; //通知方式
            userModel.BosomNote = this.txtBosomNote.Text;
            userModel.NoteDate = DateTime.Now;
            userModel.NoteName = adminInfo.AdminName;
            userModel.InComeandExpState = 0;
            userModel.State = 0;
            userModel.UserId = this.lblUserId.Text;
            #endregion

            try
            {
                if (refModel.RefundMentMoney == orderModel.FactPrice)//如果退款和订单价 匹配
                {
                    remBll.Delete(remModel.ID.ToString());
                    payBll.Delete(payModel.ID.ToString());
                    preBll.Delete(preModel.ID.ToString());
                }
                else
                {
                    if (remModel.RemittanceMoney > 0) //银行汇款
                    {
                        if (remModel.RemittanceMoney <= refModel.RefundMentMoney)
                        {
                            remBll.Delete(remModel.ID.ToString());
                        }
                        else
                        {
                            remModel.RemittanceMoney = remModel.RemittanceMoney - refModel.RefundMentMoney;
                            remBll.Amend(remModel);
                        }
                    }
                    if (preModel.PayoutMoney > 0) //预付款
                    {
                        if (preModel.PayoutMoney <= refModel.RefundMentMoney)
                        {
                            preBll.Delete(preModel.ID.ToString());
                        }
                        else
                        {
                            preModel.PayoutMoney = (preModel.PayoutMoney + remModel.RemittanceMoney) - refModel.RefundMentMoney;
                            preBll.Amend(preModel);
                        }
                    }
                    if (payModel.GatheringMoney > 0) //现金支付
                    {
                        if (payModel.GatheringMoney == (refModel.RefundMentMoney - remModel.RemittanceMoney - preModel.PayoutMoney))
                        {
                            payBll.Delete(payModel.ID.ToString());
                        }
                        else
                        {
                            payModel.GatheringMoney = (remModel.RemittanceMoney + preModel.PayoutMoney + payModel.GatheringMoney) - refModel.RefundMentMoney;
                            payBll.Amend(payModel);
                        }
                    }
                }

                refBll.Add(refModel); //退款信息
                userBll.Add(userModel); //明细记录

                //已付款
                decimal payTotail = Convert.ToDecimal(this.GetPayed(this.lblOrderId.Text));
                if ((payTotail - (Convert.ToDecimal(this.txtRefundmentMoney.Text.Trim()))) < 0)
                {
                    orderModel.PaymentStatus = ShowShop.Common.OrdersStatusEnum.PaymentStatu.等待汇款.GetHashCode();
                }
                else
                {
                    orderModel.PaymentStatus = ShowShop.Common.OrdersStatusEnum.PaymentStatu.已收定金.GetHashCode();

                }
                orderModel.OrderStatus = ShowShop.Common.OrdersStatusEnum.OrderStatu.已经确认.GetHashCode();
                orderBll.Update(orderModel);
                ChangeHope.WebPage.BasePage.PageRight("已保存该信息.", "order_bank_pay.aspx?OrderId=" + orderModel.Id, "<li><a href='order_order_info.aspx?OrderId=" + orderModel.Id.ToString() + "'>返回信息页</a></li>");

            }
            catch
            {
                this.ltlMsg.Text = "操作失败!";
                this.pnlMsg.Visible = true;
                this.pnlMsg.CssClass = "actionErr";
            }
            finally
            {
                adminInfo = null;
                remModel = null;
                remBll = null;
                userModel = null;
                userBll = null;
                payBll = null;
                payModel = null;
                preBll = null;
                preModel = null;
                orderBll = null;
                orderModel = null;
                GC.Collect();
            }
        }