/// <summary> /// 代扣 /// </summary> /// <param name="tradeView"></param> public static global::PoolPay.DomainModel.Trade.PayTrade AutoPay(AccountTradeDTO tradeView, WithholdingAccountType type) { global::PoolPay.DomainModel.Trade.PayTrade pay = null; string success = ""; if (type == WithholdingAccountType.Poolpay) { pay = AccountTradeService.AccountPay(tradeView, ""); if (pay != null && pay.Status == global::PoolPay.DataTransferObject.PayStatus.PaySuccess) { success = "SUCCESS"; } else { throw new Exception("支付失败!"); } } else if (type == WithholdingAccountType.Alipay) { success = AccountTradeService.InterfacePay(tradeView); } if (success != "") { if (success.ToUpper() == "SUCCESS") { using (var command = Factory.CreateCommand()) { var autoPayRepository = Factory.CreateAutoPayRepository(command); autoPayRepository.UpdateSuccess(decimal.Parse(tradeView.OutOrderId)); } } else { throw new Exception("支付失败!"); } var tradementLog = new Log.Domain.TradementLog { OrderId = decimal.Parse(tradeView.OutOrderId), Request = "订单号:" + tradeView.OutOrderId, Response = success, Time = DateTime.Now, Remark = "修改代扣处理状态", }; LogService.SaveTradementLog(tradementLog); } return(pay); }
private void process() { showMessage("开始下一批处理"); var noPorcess = AutoPayService.QueryNoPorcess(); //var str = Environment.CurrentDirectory; string msg = ""; foreach (var item in noPorcess) { if (!_run) { break; } AccountTradeDTO tradeView = null; //处理订单 if (item.OrderType == OrderType.Order) { OrderProcessService.Payable(item.OrderId, out msg); if (string.IsNullOrEmpty(msg)) { Order order = OrderQueryService.QueryOrder(item.OrderId); tradeView = getPayTradeView(order, getPayAccountNo(item.PayType, order.Purchaser.Amount, order.Purchaser.CompanyId), ""); } } //处理申请单 else if (item.OrderType == OrderType.Postpone) { ApplyformProcessService.Payable(item.OrderId, out msg); if (string.IsNullOrEmpty(msg)) { PostponeApplyform applyform = ApplyformQueryService.QueryPostponeApplyform(item.OrderId); if (applyform.PayBill.Tradement == null) { msg = "申请单:" + item.OrderId + " 不能进行代扣,无支付信息!"; } tradeView = getPayTradeView(applyform, getPayAccountNo(item.PayType, Math.Abs(applyform.PayBill.Applier.Amount), applyform.PurchaserId), ""); } } if (item.PayType == WithholdingAccountType.Alipay) { tradeView.BuyerEmail = item.PayAccountNo; } try { if (string.IsNullOrEmpty(msg)) { global::PoolPay.DomainModel.Trade.PayTrade pay = AutoPayService.AutoPay(tradeView, item.PayType); if (item.PayType == WithholdingAccountType.Poolpay) { //如果是国付通代扣就直接修改订单状态 if (pay != null && pay.Status == global::PoolPay.DataTransferObject.PayStatus.PaySuccess) { NotifyService.PaySuccess(item.OrderId, pay.CustomParameter, pay.Id.ToString(), pay.FillChargeId.ToString(), pay.PayDate.Value, "", (pay.BuyerAccount.Character as global::PoolPay.DomainModel.Accounts.CreditAccount) == null ? "0" : "1", pay.BuyerAccount.AccountNo); } } showMessage("处理成功"); } else { showMessage("处理失败" + Environment.NewLine + "原因:" + msg); } } catch (Exception ex) { showMessage("处理失败" + Environment.NewLine + "原因:" + ex.Message); } AutoPayService.UpdateProcess(item.OrderId); System.Threading.Thread.Sleep(50); } showMessage("当前批次处理结束,共处理 " + noPorcess.Count + " 条"); }