|
@@ -13,6 +13,11 @@ using FuelServer.Core.Entity;
|
|
|
using Fuel.Core.Nozzle.Dto;
|
|
|
using Org.BouncyCastle.Asn1.X509;
|
|
|
using System.Linq.Expressions;
|
|
|
+using Fuel.Core.Models;
|
|
|
+using DFS.Core.Abstractions.View;
|
|
|
+using System.Net;
|
|
|
+using Fuel.Payment.Service.Pay;
|
|
|
+
|
|
|
|
|
|
namespace Fuel.Application.Service
|
|
|
{
|
|
@@ -20,15 +25,22 @@ namespace Fuel.Application.Service
|
|
|
{
|
|
|
private readonly EntityHelper _entityHelper;
|
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
- public TransactionsService(EntityHelper entityHelper, IHttpContextAccessor httpContextAccessor)
|
|
|
+ private readonly IPayService _payService;
|
|
|
+ public TransactionsService(EntityHelper entityHelper, IHttpContextAccessor httpContextAccessor, IPayService payService)
|
|
|
{
|
|
|
_entityHelper = entityHelper;
|
|
|
_httpContextAccessor = httpContextAccessor;
|
|
|
+ _payService = payService;
|
|
|
}
|
|
|
|
|
|
- public async Task<transactions> CreateTransactions(UploadTransactions uploadTransactions)
|
|
|
+ /// <summary>
|
|
|
+ /// 创建订单
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="uploadTransactions"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<ServiceResponse> CreateTransactions(UploadTransactions uploadTransactions)
|
|
|
{
|
|
|
- string Buid = _httpContextAccessor.HttpContext.Request.Headers["Buid"].FirstOrDefault();
|
|
|
+ string Buid = _httpContextAccessor.HttpContext.Request.Headers["Buid"].FirstOrDefault();
|
|
|
Guid guid = Guid.Parse(Buid);
|
|
|
string key = string.Empty;
|
|
|
if (uploadTransactions.Type == 1)//预支付
|
|
@@ -52,7 +64,7 @@ namespace Fuel.Application.Service
|
|
|
transactions output = await GetRedisTransactions(uploadTransactions, key);
|
|
|
if (output != null)
|
|
|
{
|
|
|
- return output;
|
|
|
+ return ServiceResponse.Ok(output);
|
|
|
}
|
|
|
var _product = await _entityHelper.GetEntitiesAsync<product>(_ => _.Buid == guid && _.ProductName == uploadTransactions.Product);
|
|
|
var _nozzle = await _entityHelper.GetEntitiesAsync<nozzle>(_ => _.Buid == guid && _.ExternalGunNumber == uploadTransactions.NozzleId);
|
|
@@ -61,9 +73,9 @@ namespace Fuel.Application.Service
|
|
|
string jsonString = JsonConvert.SerializeObject(respond);
|
|
|
|
|
|
RedisHelper.SetAsync(key, jsonString, 3600);
|
|
|
- return respond;
|
|
|
+ return ServiceResponse.Ok(respond);
|
|
|
}
|
|
|
- public async Task<List<transactions>> GetTransactionsAsync(TransactionsInput input)
|
|
|
+ public async Task<ServiceResponse> GetTransactionsAsync(TransactionsInput input)
|
|
|
{
|
|
|
string Buid = _httpContextAccessor.HttpContext.Request.Headers["Buid"].FirstOrDefault();
|
|
|
Guid guid = Guid.Parse(Buid);
|
|
@@ -93,14 +105,44 @@ namespace Fuel.Application.Service
|
|
|
{
|
|
|
where = CombineExpressions(where, p => p.ProductName == input.Product);
|
|
|
}
|
|
|
-
|
|
|
- return await _entityHelper.GetEntitiesAsync<transactions>(where);
|
|
|
+ var result = await _entityHelper.GetEntitiesAsync<transactions>(where);
|
|
|
+ return ServiceResponse.Ok(result);
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 提交支付
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="input"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<ServiceResponse> CommitPayment(int trxId, string AuthCode)
|
|
|
+ {
|
|
|
+ bool paymentOK = false;
|
|
|
+ var trx = _entityHelper.GetEntitiesAsync<transactions>(_ => _.Id == trxId).Result.FirstOrDefault();
|
|
|
+ if (trx == null)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "未查询到订单!");
|
|
|
+ }
|
|
|
+ var paytype = _entityHelper.GetEntitiesAsync<paytype>(_ => _.Id == trx.PaymentMethod).Result.FirstOrDefault();
|
|
|
+ string billNumber = SequenceNumber.Next();//订单编号
|
|
|
+ trx.TransactionNumber = billNumber;
|
|
|
+ decimal payDueAmount = (decimal)trx.OriginalAmount;
|
|
|
+ string Channel = paytype.Channel;
|
|
|
+ var serviceResult = await _payService.PerformElectronicProcess(AuthCode, payDueAmount, billNumber);
|
|
|
+ Payment.Core.Models.ElectronicOrderProcessResultModel payResult = (Payment.Core.Models.ElectronicOrderProcessResultModel)serviceResult.Data;
|
|
|
+ if (!serviceResult.IsSuccessful() || payResult.ResultCode == "PAY_ERROR")
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "支付失败");
|
|
|
+ }
|
|
|
+ trx.ActualPaymentAmount = payDueAmount;//实际支付金额
|
|
|
+ trx.ResultCode = payResult?.ResultCode;//支付成功应该为0
|
|
|
+ trx.ErrorDetail = payResult?.ErrorDetail;
|
|
|
+ _entityHelper.UpdateAsync(trx);
|
|
|
+ return ServiceResponse.Ok(trx);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 查询redis订单缓存
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<transactions> GetRedisTransactions(UploadTransactions uploadTransactions,string key)
|
|
|
+ public async Task<transactions> GetRedisTransactions(UploadTransactions uploadTransactions, string key)
|
|
|
{
|
|
|
string Buid = _httpContextAccessor.HttpContext.Request.Headers["Buid"].FirstOrDefault();
|
|
|
var respond = RedisHelper.GetAsync(key).Result;
|