|
@@ -20,6 +20,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|
|
using static Fuel.Core.WechatServer.WeChatService;
|
|
|
using System.Linq.Dynamic.Core;
|
|
|
using System.Text.Json;
|
|
|
+using Org.BouncyCastle.Asn1.Ocsp;
|
|
|
|
|
|
|
|
|
namespace Fuel.Application.Service
|
|
@@ -58,6 +59,16 @@ namespace Fuel.Application.Service
|
|
|
return ServiceResponse.Error("站点信息查询为空 buid: " + Buid);
|
|
|
}
|
|
|
string key = string.Empty;
|
|
|
+ var _product = await _entityHelper.GetEntitiesAsync<product>(_ => _.Buid == Buid && _.ProductName == uploadTransactions.Product);
|
|
|
+ if (_product.Count() <= 0)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error("油品查询失败,油品名称:" + uploadTransactions.Product);
|
|
|
+ }
|
|
|
+ var _nozzle = await _entityHelper.GetEntitiesAsync<nozzle>(_ => _.Buid == Buid && _.ExternalGunNumber == uploadTransactions.ExternalGunNumber);
|
|
|
+ if (_nozzle.Count() <= 0)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error("油枪查询失败,油枪名称:" + uploadTransactions.ExternalGunNumber);
|
|
|
+ }
|
|
|
if (site.PaymentMode == 1)//预支付
|
|
|
{
|
|
|
key = uploadTransactions.ExternalGunNumber + ":" +
|
|
@@ -65,6 +76,34 @@ namespace Fuel.Application.Service
|
|
|
uploadTransactions.Qty + ":" +
|
|
|
uploadTransactions.MiniProgramID + ":" +
|
|
|
Buid.ToString();
|
|
|
+ string WachatID = HttpRequestReader.GetWachatID(); //用户
|
|
|
+ var userSession = WechatUserSessionRepo.GetUserSession(WachatID.ToString());
|
|
|
+ if (userSession == null)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error(HttpStatusCode.NonAuthoritativeInformation, "未找到用户!");
|
|
|
+ }
|
|
|
+ var user = _fsql.Select<miniprogramusers>().Where(_ => _.OpenId == userSession.openid).First();
|
|
|
+
|
|
|
+
|
|
|
+ if (uploadTransactions.OriginalAmount != null)
|
|
|
+ {
|
|
|
+ decimal decimalValue = uploadTransactions.OriginalAmount.HasValue ? uploadTransactions.OriginalAmount.Value : 0m;
|
|
|
+ decimal ProductPrice = _product.First().ProductPrice.HasValue ? _product.First().ProductPrice.Value : 0m;
|
|
|
+ decimal qty = decimalValue / ProductPrice;
|
|
|
+ uploadTransactions.Qty = qty;
|
|
|
+ }
|
|
|
+ else if (uploadTransactions.Qty != null)
|
|
|
+ {
|
|
|
+ decimal decimalValue = uploadTransactions.Qty.HasValue ? uploadTransactions.Qty.Value : 0m;
|
|
|
+ decimal ProductPrice = _product.First().ProductPrice.HasValue ? _product.First().ProductPrice.Value : 0m;
|
|
|
+ decimal OriginalAmount = decimalValue * ProductPrice;
|
|
|
+ uploadTransactions.OriginalAmount = OriginalAmount;
|
|
|
+ }
|
|
|
+ else if (uploadTransactions.OriginalAmount == null && uploadTransactions.Qty == null)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error("金额与升数为空");
|
|
|
+ }
|
|
|
+ uploadTransactions.MiniProgramID = user.Id;
|
|
|
}
|
|
|
else//后支付
|
|
|
{
|
|
@@ -81,16 +120,7 @@ namespace Fuel.Application.Service
|
|
|
{
|
|
|
return ServiceResponse.Ok(output);
|
|
|
}
|
|
|
- var _product = await _entityHelper.GetEntitiesAsync<product>(_ => _.Buid == Buid && _.ProductName == uploadTransactions.Product);
|
|
|
- if (_product.Count() <= 0)
|
|
|
- {
|
|
|
- return ServiceResponse.Error("油品查询失败,油品名称:" + uploadTransactions.Product);
|
|
|
- }
|
|
|
- var _nozzle = await _entityHelper.GetEntitiesAsync<nozzle>(_ => _.Buid == Buid && _.ExternalGunNumber == uploadTransactions.ExternalGunNumber);
|
|
|
- if (_nozzle.Count() <= 0)
|
|
|
- {
|
|
|
- return ServiceResponse.Error("油枪查询失败,油枪名称:" + uploadTransactions.ExternalGunNumber);
|
|
|
- }
|
|
|
+
|
|
|
var trx = uploadTransactions.ToTransactions(uploadTransactions, Buid, _product.FirstOrDefault(), _nozzle.FirstOrDefault(), site.PaymentMode);
|
|
|
//int affectedRows = _fsql.Insert<transactions>().AppendData(trx).ExecuteAffrows();
|
|
|
// var affectedRows = _fsql.Insert<transactions>().AppendData(trx).ExecuteInserted();
|
|
@@ -143,7 +173,6 @@ namespace Fuel.Application.Service
|
|
|
// where = CombineExpressions(where, p => p.TransactionTime == input.TransactionETime);
|
|
|
//}
|
|
|
var result = await _entityHelper.GetEntitiesAsync<transactions>(where);
|
|
|
- var sdfsd = _fsql.Select<transactions>().Where(where).ToList();
|
|
|
|
|
|
List<TransactionsList> list = new List<TransactionsList>();
|
|
|
foreach (var item in result)
|
|
@@ -291,6 +320,11 @@ namespace Fuel.Application.Service
|
|
|
return null;
|
|
|
}
|
|
|
transactions transactions = JsonConvert.DeserializeObject<transactions>(respond);
|
|
|
+ var trx = _entityHelper.GetEntitiesAsync<transactions>(_ => _.Id == transactions.Id).Result.FirstOrDefault();
|
|
|
+ if (trx == null || trx.OrderStatus != transactionsORDERSTATUS.Unpaid)
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
return transactions;
|
|
|
}
|
|
|
// 辅助方法:组合两个表达式
|
|
@@ -306,8 +340,8 @@ namespace Fuel.Application.Service
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
public async Task<ServiceResponse> RefundTrx(int trxId,
|
|
|
- double longitude,
|
|
|
- double latitude)
|
|
|
+ double longitude = 0.0,
|
|
|
+ double latitude = 0.0)
|
|
|
{
|
|
|
Guid Buid = HttpRequestReader.GetCurrentBuId(); //站点id
|
|
|
var businessunitinfo = _entityHelper.GetEntitiesAsync<businessunitinfo>(_ => _.Buid == Buid).Result.FirstOrDefault();
|
|
@@ -316,22 +350,22 @@ namespace Fuel.Application.Service
|
|
|
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))
|
|
|
- {
|
|
|
+ // 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公里");
|
|
|
- }
|
|
|
+ // }
|
|
|
+ // 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)
|
|
@@ -361,8 +395,8 @@ namespace Fuel.Application.Service
|
|
|
return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "单价获取失败");
|
|
|
}
|
|
|
//计算退款金额
|
|
|
- decimal RefundAmount = (decimal)trx.ActualPaymentAmount;
|
|
|
- //decimal RefundAmount = (decimal)((trx.Qty - trx.OriginalQty) * ProductPrice.Value);
|
|
|
+ //decimal RefundAmount = (decimal)trx.ActualPaymentAmount;
|
|
|
+ decimal RefundAmount = (decimal)((trx.Qty - trx.OriginalQty) * ProductPrice.Value);
|
|
|
//if (RefundAmount <= 0.0M)
|
|
|
//{
|
|
|
// return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "该笔单无需退款");
|
|
@@ -382,6 +416,7 @@ namespace Fuel.Application.Service
|
|
|
{
|
|
|
trx.RefundStatus = RefundStatus.PartiallyRefunded;//部分退款
|
|
|
}
|
|
|
+ trx.OrderStatus = transactionsORDERSTATUS.Cancelled;
|
|
|
trx.RefundAmount = RefundAmount;
|
|
|
int affectedRows = _fsql.Update<transactions>().SetSource(trx).ExecuteAffrows();
|
|
|
return ServiceResponse.Ok(trx);
|
|
@@ -409,7 +444,7 @@ namespace Fuel.Application.Service
|
|
|
return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "未查询到订单!");
|
|
|
}
|
|
|
logger.Debug("统一下单开始");
|
|
|
- var serviceResult = await _payService.UnifiedOrder((decimal)0.01, "WX_SCAN", userSession.openid);
|
|
|
+ var serviceResult = await _payService.UnifiedOrder(trx.OriginalAmount.Value, "WX_SCAN", userSession.openid);
|
|
|
var dataProperties = serviceResult.Data.GetType().GetProperty("UnifiedOrderResult");
|
|
|
if (!serviceResult.IsSuccessful() || dataProperties == null)
|
|
|
{
|
|
@@ -436,12 +471,12 @@ namespace Fuel.Application.Service
|
|
|
trx.PaymentMethod = 2;//2 :微信支付
|
|
|
try
|
|
|
{
|
|
|
- await scopedMqttService.SubscribeAsync("fromClound/" + Buid);
|
|
|
+ await scopedMqttService.SubscribeAsync("paid/" + Buid);
|
|
|
string jsonString = JsonConvert.SerializeObject(trx);
|
|
|
await Task.Delay(2000);
|
|
|
- var sendjson = new { type = 3, data = jsonString, UserName = user.UserName, UserPhoneNumber = user.UserPhoneNumber };
|
|
|
+ var sendjson = new { data = jsonString, UserName = user.UserName, UserPhoneNumber = user.UserPhoneNumber };
|
|
|
//支付完成将订单信息推送到fcc
|
|
|
- await scopedMqttService.PublishAsync("fromClound/" + Buid, JsonConvert.SerializeObject(sendjson));
|
|
|
+ await scopedMqttService.PublishAsync("paid/" + Buid, JsonConvert.SerializeObject(sendjson));
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -476,7 +511,12 @@ namespace Fuel.Application.Service
|
|
|
return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "未查询到订单!");
|
|
|
}
|
|
|
trx.OriginalQty = OriginalQty;
|
|
|
- _entityHelper.UpdateAsync(trx);
|
|
|
+ var refund = await RefundTrx(trxId);
|
|
|
+ if (refund.IsSuccessful() || refund.StatusCode == HttpStatusCode.NotAcceptable)
|
|
|
+ {
|
|
|
+ trx.OrderStatus = transactionsORDERSTATUS.Completed;
|
|
|
+ }
|
|
|
+ int affectedRows = _fsql.Update<transactions>().SetSource(trx).ExecuteAffrows();
|
|
|
return ServiceResponse.Ok(trx);
|
|
|
}
|
|
|
/// <summary>
|