| @ -0,0 +1,126 @@ | |||||
| using System; | |||||
| using System.Web.UI; | |||||
| using System.Web.UI.WebControls; | |||||
| using BWP.B3QingDaoWanFu.BL; | |||||
| using BWP.B3QingDaoWanFu.BO; | |||||
| using BWP.BWPTrustPayClient.BO.NamedValueTemplate; | |||||
| using BWP.BWPTrustPayClient.TrustPayRequests; | |||||
| using BWP.Web.CustomPageLayout; | |||||
| using BWP.Web.Layout; | |||||
| using BWP.Web.WebControls; | |||||
| using TSingSoft.WebControls2; | |||||
| namespace BWP.Web.Pages.B3QingDaoWanFu.TrustPay_ { | |||||
| class TrustPayEdit : BaseDmoEditPage<TrustPay, ITrustPayBL> { | |||||
| protected override void OnLoad(EventArgs e) { | |||||
| if (!IsPostBack && !String.IsNullOrEmpty(Request["MSG"])) { | |||||
| var result = new B3PaymentResult(Request["MSG"]).Parse(); | |||||
| if (result.IsSuccess) { | |||||
| mBL.ABCPaySuccess(Dmo); | |||||
| AspUtil.AlertAndClose(this, "付款成功"); | |||||
| } else { | |||||
| AspUtil.Alert(this, result.ErrorMessage); | |||||
| } | |||||
| } | |||||
| base.OnLoad(e); | |||||
| } | |||||
| protected override void AddActions(ButtonGroup buttonGroup) { | |||||
| //AddSaveAction(buttonGroup); | |||||
| } | |||||
| protected override void BuildBasePropertiesEditor(TitlePanel titlePanel, PageLayoutSection pageLayoutSection) { | |||||
| var layoutManager = new LayoutManager("", mDFInfo, mDFContainer); | |||||
| layoutManager.Add("PayState", new DFValueLabel()); | |||||
| layoutManager.Add("Money", new DFTextBox()); | |||||
| layoutManager.Add("CreateTime", new DFValueLabel()); | |||||
| var config = new AutoLayoutConfig(); | |||||
| config.Add("AccountCustomer_ID"); | |||||
| config.Add("Money"); | |||||
| config.Add("PayState"); | |||||
| config.Add("CreateTime"); | |||||
| config.Add("Remark"); | |||||
| pageLayoutSection.ApplyLayout(layoutManager, config, mPageLayoutManager, mDFInfo); | |||||
| layoutManager.Config = config; | |||||
| titlePanel.Controls.Add(layoutManager.CreateLayout()); | |||||
| } | |||||
| protected override void BuildBody(Control parent) { | |||||
| base.BuildBody(parent); | |||||
| AddAbcPay(parent); | |||||
| } | |||||
| public override void AppToUI() { | |||||
| base.AppToUI(); | |||||
| mDFContainer.Readonly = !IsNew; | |||||
| } | |||||
| private void AddAbcPay(Control parent) { | |||||
| var titlePanel = new TitlePanel("农行支付"); | |||||
| parent.Controls.Add(titlePanel); | |||||
| var vPanel = new VLayoutPanel(); | |||||
| titlePanel.Controls.Add(vPanel); | |||||
| var layoutManager = new LayoutManager("Pay", mDFInfo, mDFContainer); | |||||
| var config = new AutoLayoutConfig() { | |||||
| }; | |||||
| if (IsNew) { | |||||
| vPanel.Add(new TSButton("新建付款", delegate { | |||||
| mDFContainer.GetFromUI(); | |||||
| var id = mBL.CreateRequest(Dmo); | |||||
| var url = AspUtil.AddParamToUrl(Request.RawUrl, "ID", id.ToString()); | |||||
| AspUtil.RedirectAndAlert(this, url, "新建付款成功"); | |||||
| })); | |||||
| } else if (MinDmo.PayState == 付款状态.未付款) { | |||||
| vPanel.Add(new TSButton("请求付款", delegate { | |||||
| mBL.ABCPayRequest(Dmo); | |||||
| AspUtil.RedirectAndAlert(this, Request.RawUrl, "请求付款成功"); | |||||
| })); | |||||
| } else { | |||||
| layoutManager.Add("ABCPay_No", new DFValueLabel()); | |||||
| var link = new HyperLink(); | |||||
| link.Target = "_blank"; | |||||
| link.Text = "前往支付"; | |||||
| link.NavigateUrl = MinDmo.ABCPay_PaymentURL; | |||||
| layoutManager.Add("ABCPay_PaymentURL", link); | |||||
| layoutManager["ABCPay_PaymentURL"].NoLabel = true; | |||||
| config.Add("ABCPay_No"); | |||||
| config.Add("ABCPay_PaymentURL"); | |||||
| layoutManager.Config = config; | |||||
| vPanel.Add(layoutManager.CreateLayout()); | |||||
| if (MinDmo.PayState == 付款状态.请求支付) { | |||||
| vPanel.Add(new TSButton("完成付款", delegate { | |||||
| mBL.ABCPaySuccess(Dmo); | |||||
| AspUtil.RedirectAndAlert(this, Request.RawUrl, "完成付款成功"); | |||||
| })); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,50 @@ | |||||
| using BWP.B3Frameworks; | |||||
| using BWP.B3QingDaoWanFu.BO; | |||||
| using BWP.Web.Layout; | |||||
| using Forks.EnterpriseServices.DomainObjects2.DQuery; | |||||
| using TSingSoft.WebControls2; | |||||
| namespace BWP.Web.Pages.B3QingDaoWanFu.TrustPay_ { | |||||
| class TrustPayList : EntityListPage<TrustPay > { | |||||
| protected override bool NotWaitingUserInput() { | |||||
| return true; | |||||
| } | |||||
| protected override void AddQueryControls(VLayoutPanel vPanel) { | |||||
| var layoutManager = new LayoutManager("", mDFInfo, mQueryContainer); | |||||
| var config = new AutoLayoutConfig(); | |||||
| config.Add("ID"); | |||||
| config.Add("AccountCustomer_ID"); | |||||
| config.Add("ABCPay_No"); | |||||
| config.Add("CreateUser_Name"); | |||||
| config.Add("CreateTime"); | |||||
| layoutManager.Config = config; | |||||
| var section = mPageLayoutManager.AddSection(B3FrameworksConsts.PageLayouts.QueryConditions, B3FrameworksConsts.PageLayouts.QueryConditions_DisplayName); | |||||
| section.ApplyLayout(layoutManager, config, mPageLayoutManager, mDFInfo); | |||||
| vPanel.Add(layoutManager.CreateLayout()); | |||||
| } | |||||
| protected override void CreateDFBrowseGridColumns(DFBrowseGrid grid) | |||||
| { | |||||
| grid.Add(new DFBrowseGridColumn("ID")); | |||||
| grid.Add(new DFBrowseGridColumn("ABCPay_No")); | |||||
| grid.Add(new DFBrowseGridColumn("AccountCustomer_Name")); | |||||
| grid.Add(new DFBrowseGridColumn("Money")); | |||||
| grid.Add(new DFBrowseGridColumn("PayState")); | |||||
| grid.Add(new DFBrowseGridColumn("CreateTime")); | |||||
| grid.Add(new DFBrowseGridColumn("Gathering_ID")); | |||||
| } | |||||
| protected override DQueryDom GetQueryDom() { | |||||
| var query = base.GetQueryDom(); | |||||
| query.Where.Conditions.Add(DQCondition.EQ("Domain_ID", DomainContext.Current.ID)); | |||||
| return query; | |||||
| } | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,40 @@ | |||||
| <?xml version="1.0" encoding="utf-8" ?> | |||||
| <Select xmlns="urn:XDQuery"> | |||||
| <Columns> | |||||
| <Field name="ID"/> | |||||
| </Columns> | |||||
| <From> | |||||
| <DmoClass class="BWP.B3QingDaoWanFu.BO.TrustPay, B3QingDaoWanFu"/> | |||||
| </From> | |||||
| <Where> | |||||
| <And> | |||||
| <EQ> | |||||
| <Field name="ID"/> | |||||
| <QBE paramName="ID"/> | |||||
| </EQ> | |||||
| <EQ> | |||||
| <Field name="AccountCustomer_ID"/> | |||||
| <QBE paramName="AccountCustomer_ID"/> | |||||
| </EQ> | |||||
| <Contains> | |||||
| <Field name="CreateUser_Name"/> | |||||
| <QBE paramName="CreateUser_Name"/> | |||||
| </Contains> | |||||
| <Contains> | |||||
| <Field name="ABCPay_No"/> | |||||
| <QBE paramName="ABCPay_No"/> | |||||
| </Contains> | |||||
| <GreaterThanOrEqual> | |||||
| <Field name="CreateTime"/> | |||||
| <QBE paramName="MinCreateTime" /> | |||||
| </GreaterThanOrEqual> | |||||
| <LessThanOrEqual> | |||||
| <Field name="CreateTime"/> | |||||
| <QBE paramName="MaxCreateTime"/> | |||||
| </LessThanOrEqual> | |||||
| </And> | |||||
| </Where> | |||||
| </Select> | |||||
| @ -0,0 +1,91 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Web; | |||||
| using BWP.B3Frameworks; | |||||
| using BWP.B3Frameworks.BL; | |||||
| using BWP.B3Frameworks.Utils; | |||||
| using BWP.B3QingDaoWanFu.BO; | |||||
| using BWP.BWPTrustPayClient.BO.NamedValueTemplate; | |||||
| using BWP.BWPTrustPayClient.TrustPayRequests; | |||||
| using Forks.EnterpriseServices.BusinessInterfaces; | |||||
| using TSingSoft.WebPluginFramework; | |||||
| namespace BWP.B3QingDaoWanFu.BL { | |||||
| [BusinessInterface(typeof(TrustPayBL))] | |||||
| public interface ITrustPayBL : IEntityBL<TrustPay> { | |||||
| long CreateRequest(TrustPay dmo); | |||||
| void ABCPayRequest(TrustPay dmo); | |||||
| void ABCPaySuccess(TrustPay dmo); | |||||
| } | |||||
| public class TrustPayBL : EntityBL<TrustPay>, ITrustPayBL { | |||||
| protected override List<string> MinDmoProperties { | |||||
| get { | |||||
| var list = base.MinDmoProperties; | |||||
| list.Add("PayState"); | |||||
| list.Add("Money"); | |||||
| list.Add("ABCPay_PaymentURL"); | |||||
| return list; | |||||
| } | |||||
| } | |||||
| protected override void doInsert(TrustPay dmo) { | |||||
| dmo.Domain_ID = DomainContext.Current.ID; | |||||
| dmo.CreateUser_ID = BLContext.User.ID; | |||||
| base.doInsert(dmo); | |||||
| } | |||||
| public long CreateRequest(TrustPay dmo) { | |||||
| Insert(dmo); | |||||
| return dmo.ID; | |||||
| } | |||||
| public void ABCPayRequest(TrustPay dmo) { | |||||
| if (dmo.PayState != 付款状态.未付款) { | |||||
| throw new Exception("当前不能提交付款请求"); | |||||
| } | |||||
| var req = new B3PaymentRequest(); | |||||
| req.Money = dmo.Money.Value; | |||||
| req.ResultNotifyURL = HttpContext.Current.Request.Url.ToString(); | |||||
| req.Time = DateTime.Now; | |||||
| //#if DEBUG | |||||
| // req.Money = 0.51m; | |||||
| //#endif | |||||
| var res = req.Submit(); | |||||
| if (res.IsSuccess) { | |||||
| dmo.ABCPay_No = req.OrderNo; | |||||
| dmo.ABCPay_PaymentURL = res.PaymentURL; | |||||
| dmo.ABCPay_ResultNotifyURL = req.ResultNotifyURL; | |||||
| dmo.PayState = 付款状态.请求支付; | |||||
| InnerBLUtil.UpdateEntityProperties(Session, dmo, "PayState", "ABCPay_No", "ABCPay_PaymentURL", "ABCPay_ResultNotifyURL"); | |||||
| } else { | |||||
| throw new Exception(res.ErrorMessage); | |||||
| } | |||||
| } | |||||
| public void ABCPaySuccess(TrustPay dmo) { | |||||
| var req = new B3QueryOrderRequest(); | |||||
| req.OrderNo = dmo.ABCPay_No; | |||||
| var res = req.Submit(); | |||||
| if (!res.IsSuccess) { | |||||
| throw new Exception(res.ErrorMessage); | |||||
| } | |||||
| if (!res.StatusIsSuccess()) { | |||||
| throw new Exception(B3QueryOrderRequest.Response.GetStatusName(res.Status)); | |||||
| } | |||||
| dmo.PayState = 付款状态.付款成功; | |||||
| InnerBLUtil.UpdateEntityProperties(Session, dmo, "PayState"); | |||||
| AfterFinishPay(dmo); | |||||
| } | |||||
| void AfterFinishPay(TrustPay dmo) { | |||||
| //创建收款单 | |||||
| } | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,67 @@ | |||||
| using System; | |||||
| using BWP.B3Frameworks; | |||||
| using BWP.B3Frameworks.BO; | |||||
| using BWP.B3Frameworks.BO.MoneyTemplate; | |||||
| using BWP.B3Sale.BO; | |||||
| using BWP.B3Sale.Utils; | |||||
| using BWP.BWPTrustPayClient.BO.NamedValueTemplate; | |||||
| using Forks.EnterpriseServices; | |||||
| using Forks.EnterpriseServices.DataForm; | |||||
| using Forks.EnterpriseServices.DomainObjects2; | |||||
| using Forks.Utils; | |||||
| using TSingSoft.WebPluginFramework; | |||||
| namespace BWP.B3QingDaoWanFu.BO { | |||||
| [Serializable] | |||||
| [LogicName("农行付款")] | |||||
| public class TrustPay : Entity { | |||||
| [LogicName("请求时间")] | |||||
| public DateTime? ReqTime { get; set; } | |||||
| [LogicName("结账客户")] | |||||
| [DFDataKind(B3SaleDataSources.结账客户)] | |||||
| [DFExtProperty(B3FrameworksConsts.DFExtProperties.DisplayField, "AccountCustomer_Name")] | |||||
| [DFNotEmpty] | |||||
| public long? AccountCustomer_ID { get; set; } | |||||
| [LogicName("付款金额")] | |||||
| public Money<金额> Money { get; set; } | |||||
| [LogicName("付款状态")] | |||||
| [DbColumn(DefaultValue = 0)] | |||||
| public NamedValue<付款状态> PayState { get; set; } | |||||
| [LogicName("请求付款号")] | |||||
| public string ABCPay_No { get; set; } | |||||
| [LogicName("付款地址")] | |||||
| [DbColumn(Length = 1000)] | |||||
| public string ABCPay_PaymentURL { get; set; } | |||||
| [LogicName("支付结果回传网址")] | |||||
| [DbColumn(Length = 1000)] | |||||
| public string ABCPay_ResultNotifyURL { get; set; } | |||||
| [LogicName("收款单号")] | |||||
| public long? Gathering_ID { get; set; } | |||||
| [LogicName("板块ID")] | |||||
| public long Domain_ID { get; set; } | |||||
| [LogicName("创建人ID")] | |||||
| [DFPrompt("创建人")] | |||||
| public long? CreateUser_ID { get; set; } | |||||
| [ReferenceTo(typeof(Customer), "Name")] | |||||
| [Join("AccountCustomer_ID", "ID")] | |||||
| [LogicName("结账客户")] | |||||
| public string AccountCustomer_Name { get; set; } | |||||
| [ReferenceTo(typeof(WpfUser), "Name")] | |||||
| [Join("CreateUser_ID", "ID")] | |||||
| [LogicName("创建人")] | |||||
| public string CreateUser_Name { get; set; } | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,120 @@ | |||||
| using System; | |||||
| using System.Linq; | |||||
| using System.Web; | |||||
| using BWP.B3Frameworks.BO.NamedValueTemplate; | |||||
| using BWP.B3Frameworks.Utils; | |||||
| using BWP.B3QingDaoWanFu.BL; | |||||
| using BWP.B3QingDaoWanFu.BO; | |||||
| using BWP.B3Sale.BO; | |||||
| using BWP.B3Sale.Utils; | |||||
| using BWP.B3UnitedInfos.Rpcs; | |||||
| using BWP.BWPTrustPayClient.BO.NamedValueTemplate; | |||||
| using Forks.EnterpriseServices.BusinessInterfaces; | |||||
| using Forks.EnterpriseServices.DataForm; | |||||
| using Forks.EnterpriseServices.DomainObjects2; | |||||
| using Forks.EnterpriseServices.DomainObjects2.DQuery; | |||||
| using Forks.EnterpriseServices.JsonRpc; | |||||
| using Forks.EnterpriseServices.SqlDoms; | |||||
| using Forks.Utils; | |||||
| using TSingSoft.WebPluginFramework; | |||||
| namespace BWP.B3QingDaoWanFu.Rpc { | |||||
| [Rpc] | |||||
| public static class TrustPayRpc { | |||||
| [Rpc] | |||||
| public static long CreatePayment(long accountCustomerID, decimal money) { | |||||
| var bl = BIFactory.Create<ITrustPayBL>(); | |||||
| var pay = new TrustPay(); | |||||
| pay.Money = money; | |||||
| pay.AccountCustomer_ID = accountCustomerID; | |||||
| bl.CreateRequest(pay); | |||||
| return pay.ID; | |||||
| } | |||||
| [Rpc] | |||||
| public static String PaySubmit(long billID) { | |||||
| var payBL = BIFactory.Create<ITrustPayBL>(); | |||||
| var pay = payBL.Load(billID); | |||||
| if (pay == null) | |||||
| throw new Exception("付款单不存在"); | |||||
| if (pay.PayState == 付款状态.请求支付) { | |||||
| return GetTokenFromUrl(pay.ABCPay_PaymentURL); | |||||
| } | |||||
| if (pay.PayState == 付款状态.未付款) { | |||||
| payBL.ABCPayRequest(pay); | |||||
| return GetTokenFromUrl(pay.ABCPay_PaymentURL); | |||||
| } | |||||
| if (pay.PayState == 付款状态.付款成功) | |||||
| return "付款单已付款!"; | |||||
| throw new Exception(string.Format("不支持的付款状态{0}", pay.PayState.Name)); | |||||
| } | |||||
| [Rpc] | |||||
| public static void FinishPay(long billID) { | |||||
| var payBL = BIFactory.Create<ITrustPayBL>(); | |||||
| var pay = payBL.Load(billID); | |||||
| if (pay.PayState == 付款状态.请求支付) { | |||||
| payBL.ABCPaySuccess(pay); | |||||
| } else if (pay.PayState == 付款状态.未付款) { | |||||
| throw new Exception("付款单未付款"); | |||||
| } | |||||
| } | |||||
| static string GetTokenFromUrl(string url) { | |||||
| return HttpUtility.ParseQueryString(new Uri(url).Query)["TOKEN"]; | |||||
| } | |||||
| [Rpc] | |||||
| public static DFDataTable LoadAccountCustomer() { | |||||
| var dom = Load(typeof(Customer)); | |||||
| UserVsCustomerUtil.AddUserCustomerCondition(dom, dom.From.RootSource.Alias, "ID"); | |||||
| OrganizationUtil.AddOrganizationLimit(dom, typeof(Customer)); | |||||
| return new DFDataAdapter(new LoadArguments(dom)).Fill(); | |||||
| } | |||||
| [Rpc] | |||||
| public static TrustPay[] QueryOrder(RpcQueryObj queryObj) { | |||||
| var query = new DQueryDom(new JoinAlias(typeof(TrustPay))); | |||||
| query.Where.Conditions.Add(DQCondition.EQ("CreateUser_ID", BLContext.User.ID)); | |||||
| if (!queryObj.Select.Any()) { | |||||
| queryObj.Select.Add("ID"); | |||||
| queryObj.Select.Add("AccountCustomer_Name"); | |||||
| queryObj.Select.Add("Money"); | |||||
| queryObj.Select.Add("PayState"); | |||||
| queryObj.Select.Add("CreateTime"); | |||||
| queryObj.Select.Add("Gathering_ID"); | |||||
| } | |||||
| foreach (var item in queryObj.OrderBy) { | |||||
| query.OrderBy.Expressions.Add(DQOrderByExpression.Create(item.Name, item.Desc)); | |||||
| } | |||||
| if (queryObj.PageSize > 0) { | |||||
| query.Range = SelectRange.Top(queryObj.PageSize * (queryObj.CurrentPageIndex + 1)); | |||||
| } | |||||
| var result = query.EExecuteDmoList<TrustPay>(queryObj.Select.ToArray()); | |||||
| if (queryObj.PageSize > 0) { | |||||
| return result.Skip(queryObj.PageSize * queryObj.CurrentPageIndex).ToArray(); | |||||
| } | |||||
| return result.ToArray(); | |||||
| } | |||||
| private static DQueryDom Load(Type type) { | |||||
| var query = new DQueryDom(new JoinAlias(type)); | |||||
| query.Columns.Add(DQSelectColumn.Field("ID")); | |||||
| query.Columns.Add(DQSelectColumn.Field("Name")); | |||||
| query.Where.Conditions.Add(DQCondition.EQ("Stopped", false)); | |||||
| query.OrderBy.Expressions.Add(DQOrderByExpression.Create("Name")); | |||||
| return query; | |||||
| } | |||||
| } | |||||
| } | |||||