using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CY.BLL.EC;
using CY.Model;
using CY.Infrastructure.Common;
using CY.Model.Pay;
using CY.BLL;
using CY.WebForm.Pages.common;
namespace CY.WebForm.Pages.business
{
///
/// 卖家退款
///
public partial class SellerRefund : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
btnSubmit.ServerClick += new EventHandler(btnSubmit_ServerClick);
}
///
/// 隐藏按钮点击事件
///
///
///
void btnSubmit_ServerClick(object sender, EventArgs e)
{
if (!Refund()) { Response.End(); }
}
///
/// 退款
///
private bool Refund()
{
Pay_PaymentAccount buyerAccount = null;
Pay_PaymentAccount sellerAccount = null;
EC_OrderBasic orderBasic = null;
int? orderId = null;
decimal? money = null;
string errorResult = "-2";
try
{
money = MyConvert.ConvertToDecimal(Request["txtPayablePrice"]);
if (!money.HasValue || money.Value <= 0) { Response.Write(errorResult); return false; } else ;
orderId = MyConvert.ConvertToInt32(Request["orderId"]);
EC_OrderBLL eC_OrderBLL = new EC_OrderBLL();
if (!orderId.HasValue) { Response.Write(errorResult); return false; } else ;
orderBasic = eC_OrderBLL.GetOrderById(orderId.Value);
if (null == orderBasic) { Response.Write("-5"); return false; } else ;
if (!CurrentUser.MemberId.Equals(orderBasic.SellerId)) { Response.Write("-5"); return false; } else ;
Pay_PaymentAccountBLL pay_PaymentAccountBLL = new BLL.Pay_PaymentAccountBLL();
buyerAccount = pay_PaymentAccountBLL.GetModel(orderBasic.BuyerId);
sellerAccount = pay_PaymentAccountBLL.GetModel(orderBasic.SellerId);
}
catch (Exception ex)
{
PAGEHandleException(ex);
//throw ex;
}
EC_OrderOperate orderOperate = new EC_OrderOperate();
orderOperate.OrderId = orderId;
orderOperate.Operator = CurrentUser.ShortName;
orderOperate.Remark = "退款给买家";//需求变动,不终止订单
orderOperate.OperateType = -4;//非订单流程状态,不会被变更为此状态
Pay_Request toSellerRequest = new Pay_Request();
Pay_Request toBuyerRequest = new Pay_Request();
toBuyerRequest.UsedCredit = toSellerRequest.UsedCredit = 0;
toBuyerRequest.Subject = toSellerRequest.Subject = string.Format(UtilConst.ORDER_REFUND_SUBJECT_FORMT, orderBasic.Keyid, orderBasic.SellerOrderId, orderBasic.DocumentName);
toBuyerRequest.Payerid = toSellerRequest.Payerid = AdminAccount.Keyid.Value;
toSellerRequest.Payeeid = CurrentPayAccount.Keyid.Value;
toBuyerRequest.Payeeid = buyerAccount.Keyid.Value;
toSellerRequest.Payeeid = sellerAccount.Keyid.Value;
toSellerRequest.Paymoney = orderBasic.TradingSingle.OnlineMoney.Value - money.Value;
toBuyerRequest.Paymoney = money.Value;
List payRequests = new List() { toBuyerRequest };
if (toSellerRequest.Paymoney < 0)//支付给买家多余部分会从卖家帐户扣除
payRequests.Add(toSellerRequest);
Request.RequestContext.RouteData.DataTokens.Add("orderOperate", orderOperate);
Request.RequestContext.RouteData.DataTokens.Add("payRequests", payRequests.ToArray());
Server.Transfer("/Pages/common/PayAbout.aspx");
return true;
}
}
}