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 == 付款状态.付款成功)
|
|
throw new Exception("付款单已付款!");
|
|
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[] QueryTrustPay(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;
|
|
}
|
|
}
|
|
}
|