|
@@ -7,6 +7,7 @@ using Fuel.Core.Models;
|
|
|
using System.Net;
|
|
|
using Fuel.Payment.Service.Pay;
|
|
|
using DFS.Core.Abstractions.View;
|
|
|
+using Fuel.Core;
|
|
|
|
|
|
|
|
|
namespace Fuel.Application.Service
|
|
@@ -102,7 +103,7 @@ namespace Fuel.Application.Service
|
|
|
/// 小程序查询未支付订单
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<ServiceResponse> GetMiniProgramTransactionsUnpaidAsync(TransactionsInput input)
|
|
|
+ public async Task<ServiceResponse> GetMiniProgramTransactionsUnpaidAsync(TransactionsInput input)
|
|
|
{
|
|
|
string Buid = _httpContextAccessor.HttpContext.Request.Headers["Buid"].FirstOrDefault();
|
|
|
Guid guid = Guid.Parse(Buid);
|
|
@@ -184,6 +185,95 @@ namespace Fuel.Application.Service
|
|
|
Expression body = Expression.AndAlso(expr1.Body, Expression.Invoke(expr2, param));
|
|
|
return Expression.Lambda<Func<T, bool>>(body, param);
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// 退款
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="input"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<ServiceResponse> RefundTrx(int trxId,
|
|
|
+ double longitude,
|
|
|
+ double latitude)
|
|
|
+ {
|
|
|
+ string Buid = _httpContextAccessor.HttpContext.Request.Headers["Buid"].FirstOrDefault();
|
|
|
+ Guid guid = Guid.Parse(Buid);
|
|
|
+ var businessunitinfo = _entityHelper.GetEntitiesAsync<businessunitinfo>(_ => _.Buid == guid).Result.FirstOrDefault();
|
|
|
+ if (businessunitinfo == null)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "站点为空");
|
|
|
+ }
|
|
|
+ string[] parts = businessunitinfo.GpsCoordinates.Split(',');
|
|
|
+ if (parts.Length == 2 &&
|
|
|
+ double.TryParse(parts[0], out double latitude2) &&
|
|
|
+ double.TryParse(parts[1], out double longitude2))
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "站点经纬度获取失败");
|
|
|
+ }
|
|
|
+ //计算调用方和油站的距离,超过距离判定为恶意请求
|
|
|
+ double distance = DistanceCalculator.CalculateDistance(longitude, latitude, longitude2, latitude2);
|
|
|
+ if (distance > 5)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "该请求大于油站地址5公里");
|
|
|
+ }
|
|
|
+
|
|
|
+ var trx = _entityHelper.GetEntitiesAsync<transactions>(_ => _.Id == trxId).Result.FirstOrDefault();
|
|
|
+ if (trx == null)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "未查询到订单!");
|
|
|
+ }
|
|
|
+ else if (trx.OrderStatus == transactionsORDERSTATUS.FullyRefunded)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "该订单已退款");
|
|
|
+ }
|
|
|
+ else if (trx.OrderStatus == transactionsORDERSTATUS.PartiallyRefunded)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "该订单已部分退款");
|
|
|
+ }
|
|
|
+ else if (trx.OrderStatus == transactionsORDERSTATUS.Unpaid)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "该订单未支付");
|
|
|
+ }
|
|
|
+ else if (trx.OrderStatus == transactionsORDERSTATUS.Unpaid)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "该订单未支付");
|
|
|
+ }
|
|
|
+ //获取单价
|
|
|
+ decimal? ProductPrice = _entityHelper.GetEntitiesAsync<product>(_ => _.Id == trx.ProductId).Result.FirstOrDefault().ProductPrice;
|
|
|
+ if (ProductPrice == null)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "单价获取失败");
|
|
|
+ }
|
|
|
+ //计算退款金额
|
|
|
+ decimal RefundAmount = (decimal)((trx.Qty - trx.OriginalQty) * ProductPrice.Value);
|
|
|
+ if (RefundAmount <= 0.0M)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "该笔单无需退款");
|
|
|
+ }
|
|
|
+ //退款
|
|
|
+ var serviceResult = await _payService.ReturnProcess(RefundAmount, trx.TransactionNumber);
|
|
|
+ Payment.Core.Models.ElectronicOrderProcessResultModel payResult = (Payment.Core.Models.ElectronicOrderProcessResultModel)serviceResult.Data;
|
|
|
+ if (!serviceResult.IsSuccessful() || payResult.ResultCode == "PAY_ERROR")
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "退款失败");
|
|
|
+ }
|
|
|
|
|
|
+ trx.RefundAmount = RefundAmount;
|
|
|
+ _entityHelper.UpdateAsync(trx);
|
|
|
+ return ServiceResponse.Ok(trx);
|
|
|
+ }
|
|
|
+ public async Task<ServiceResponse> Redeem(int trxId, decimal OriginalQty)
|
|
|
+ {
|
|
|
+ var trx = _entityHelper.GetEntitiesAsync<transactions>(_ => _.Id == trxId).Result.FirstOrDefault();
|
|
|
+ if (trx == null)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "未查询到订单!");
|
|
|
+ }
|
|
|
+ trx.OriginalQty = OriginalQty;
|
|
|
+ _entityHelper.UpdateAsync(trx);
|
|
|
+ return ServiceResponse.Ok(trx);
|
|
|
+ }
|
|
|
}
|
|
|
}
|