|
@@ -91,6 +91,11 @@ namespace Fuel.Application.Service
|
|
|
decimal ProductPrice = _product.First().ProductPrice.HasValue ? _product.First().ProductPrice.Value : 0m;
|
|
|
decimal qty = decimalValue / ProductPrice;
|
|
|
uploadTransactions.Qty = qty;
|
|
|
+ //订单金额不能小于2元、订单金额不能大于9900元
|
|
|
+ if (uploadTransactions.OriginalAmount < 2 || uploadTransactions.OriginalAmount > 9900)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error(HttpStatusCode.NonAuthoritativeInformation, "订单金额不能小于2元、订单金额不能大于9900元");
|
|
|
+ }
|
|
|
}
|
|
|
else if (uploadTransactions.Qty != null)
|
|
|
{
|
|
@@ -98,11 +103,16 @@ namespace Fuel.Application.Service
|
|
|
decimal ProductPrice = _product.First().ProductPrice.HasValue ? _product.First().ProductPrice.Value : 0m;
|
|
|
decimal OriginalAmount = decimalValue * ProductPrice;
|
|
|
uploadTransactions.OriginalAmount = OriginalAmount;
|
|
|
+ if (uploadTransactions.Qty < 1 || OriginalAmount > 9900)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error(HttpStatusCode.NonAuthoritativeInformation, "升数不能小于1升,订单升数乘单价不能大于9900元");
|
|
|
+ }
|
|
|
}
|
|
|
else if (uploadTransactions.OriginalAmount == null && uploadTransactions.Qty == null)
|
|
|
{
|
|
|
return ServiceResponse.Error("金额与升数为空");
|
|
|
}
|
|
|
+
|
|
|
uploadTransactions.MiniProgramID = user.Id;
|
|
|
}
|
|
|
else//后支付
|
|
@@ -132,7 +142,7 @@ namespace Fuel.Application.Service
|
|
|
.First();
|
|
|
string jsonString = JsonConvert.SerializeObject(insertedTransaction);
|
|
|
|
|
|
- RedisHelper.SetAsync(key, jsonString, 3600);
|
|
|
+ RedisHelper.SetAsync(key, jsonString, 600);
|
|
|
return ServiceResponse.Ok(insertedTransaction);
|
|
|
}
|
|
|
else
|
|
@@ -179,16 +189,22 @@ namespace Fuel.Application.Service
|
|
|
{
|
|
|
// var nozzle = _nozzle.Where(_ => _.Id == item.NozzleId)?.First();//根据油枪id查询外部枪号
|
|
|
var nozzle = _nozzle.FirstOrDefault(_ => _.Id == item.NozzleId);//根据油枪id查询外部枪号
|
|
|
- var userid = user.Where(_ => _.Id == item.MiniProgramID).First();
|
|
|
+
|
|
|
+
|
|
|
var pay = paytype.FirstOrDefault(_ => _.Id == item.PaymentMethod)?.Name;
|
|
|
TransactionsList transactions = new TransactionsList();
|
|
|
transactions.TransactionNumber = item.TransactionNumber;
|
|
|
transactions.SiteName = site.Name;
|
|
|
- transactions.NozzleProductName = nozzle?.ExternalGunNumber + " | " + item.ProductName;
|
|
|
+ transactions.NozzleProductName = item.NozzleId + " | " + item.ProductName;
|
|
|
transactions.ActualPaymentAmount = item.ActualPaymentAmount.ToString();
|
|
|
transactions.TransactionTime = item.TransactionTime?.ToString("yyyy-MM-dd hh:mm:ss");
|
|
|
transactions.OrderStatus = GetChineseStatus(item.OrderStatus);
|
|
|
- transactions.UserName = userid.UserName;
|
|
|
+ transactions.RefundAmount = item.RefundAmount;
|
|
|
+ if (item.MiniProgramID != null)
|
|
|
+ {
|
|
|
+ var userid = user.Where(_ => _.Id == item.MiniProgramID).FirstOrDefault();
|
|
|
+ transactions.UserName = userid?.UserName;
|
|
|
+ }
|
|
|
transactions.PriceQty = item.Price + " | " + item.Qty;
|
|
|
transactions.PaymentMethod = pay;
|
|
|
list.Add(transactions);
|
|
@@ -213,6 +229,7 @@ namespace Fuel.Application.Service
|
|
|
var user = _fsql.Select<miniprogramusers>().Where(_ => _.OpenId == userSession.openid).First();
|
|
|
where = CombineExpressions(where, p => p.MiniProgramID == user.Id && p.OrderStatus == transactionsORDERSTATUS.Unpaid && p.TransactionTime >= dayBeforeTime);
|
|
|
var result = await _entityHelper.GetEntitiesAsync<transactions>(where);
|
|
|
+ result = result.OrderByDescending(x => x.CreateTime).ToList();
|
|
|
return ServiceResponse.Ok(result);
|
|
|
}
|
|
|
|
|
@@ -234,6 +251,7 @@ namespace Fuel.Application.Service
|
|
|
var _nozzle = _fsql.Select<nozzle>().Where(_ => _.Id == NozzleId).First();//根据油枪id查询外部枪号
|
|
|
where = CombineExpressions(where, p => p.NozzleId == _nozzle.ExternalGunNumber && p.OrderStatus == transactionsORDERSTATUS.Unpaid && p.TransactionTime >= dayBeforeTime);
|
|
|
var result = await _entityHelper.GetEntitiesAsync<transactions>(where);
|
|
|
+ result = result.OrderByDescending(x => x.CreateTime).ToList();
|
|
|
return ServiceResponse.Ok(result);
|
|
|
}
|
|
|
/// <summary>
|
|
@@ -340,13 +358,13 @@ namespace Fuel.Application.Service
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
public async Task<ServiceResponse> RefundTrx(int trxId,
|
|
|
- double longitude = 0.0,
|
|
|
- double latitude = 0.0)
|
|
|
+ decimal? OriginalQty = null)
|
|
|
{
|
|
|
Guid Buid = HttpRequestReader.GetCurrentBuId(); //站点id
|
|
|
var businessunitinfo = _entityHelper.GetEntitiesAsync<businessunitinfo>(_ => _.Buid == Buid).Result.FirstOrDefault();
|
|
|
if (businessunitinfo == null)
|
|
|
{
|
|
|
+ logger.Debug($"RefundTrx,退款失败,站点为空,Buid={Buid} ,trxId={trxId}");
|
|
|
return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "站点为空");
|
|
|
}
|
|
|
string[] parts = businessunitinfo.GpsCoordinates.Split(',');
|
|
@@ -370,37 +388,50 @@ namespace Fuel.Application.Service
|
|
|
var trx = _entityHelper.GetEntitiesAsync<transactions>(_ => _.Id == trxId).Result.FirstOrDefault();
|
|
|
if (trx == null)
|
|
|
{
|
|
|
+ logger.Debug($"退款失败,未查询到订单,Buid={Buid} ,trxId={trxId}");
|
|
|
return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "未查询到订单!");
|
|
|
}
|
|
|
else if (trx.RefundStatus == RefundStatus.FullyRefunded)
|
|
|
{
|
|
|
+ logger.Debug($"该订单已退款,未查询到订单,Buid={Buid} ,trxId={trxId}");
|
|
|
return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "该订单已退款");
|
|
|
}
|
|
|
else if (trx.RefundStatus == RefundStatus.PartiallyRefunded)
|
|
|
{
|
|
|
+ logger.Debug($"该订单已部分退款,Buid={Buid} ,trxId={trxId}");
|
|
|
return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "该订单已部分退款");
|
|
|
}
|
|
|
else if (trx.OrderStatus == transactionsORDERSTATUS.Unpaid)
|
|
|
{
|
|
|
- return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "该订单未支付");
|
|
|
- }
|
|
|
- else if (trx.OrderStatus == transactionsORDERSTATUS.Unpaid)
|
|
|
- {
|
|
|
+ logger.Debug($"该订单已退款,该订单未支付,Buid={Buid} ,trxId={trxId}");
|
|
|
return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "该订单未支付");
|
|
|
}
|
|
|
//获取单价
|
|
|
decimal? ProductPrice = _entityHelper.GetEntitiesAsync<product>(_ => _.Id == trx.ProductId).Result.FirstOrDefault().ProductPrice;
|
|
|
if (ProductPrice == null)
|
|
|
{
|
|
|
+ logger.Debug($"该订单已退款,单价获取失败,Buid={Buid} ,trxId={trxId}");
|
|
|
return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "单价获取失败");
|
|
|
}
|
|
|
//计算退款金额
|
|
|
//decimal RefundAmount = (decimal)trx.ActualPaymentAmount;
|
|
|
- decimal RefundAmount = (decimal)((trx.Qty - trx.OriginalQty) * ProductPrice.Value);
|
|
|
- //if (RefundAmount <= 0.0M)
|
|
|
- //{
|
|
|
- // return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "该笔单无需退款");
|
|
|
- //}
|
|
|
+ decimal RefundAmount = 0.0M;
|
|
|
+ if (businessunitinfo.PaymentMode == 0)//后支付
|
|
|
+ {
|
|
|
+ logger.Debug($"后支付模式无法退款!,Buid={Buid} ,trxId={trxId}");
|
|
|
+ return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "后支付模式无法退款!");
|
|
|
+ // RefundAmount = (decimal)((trx.Qty - trx.OriginalQty) * ProductPrice.Value);
|
|
|
+ }
|
|
|
+ else if (businessunitinfo.PaymentMode == 1)//预支付
|
|
|
+ {
|
|
|
+ decimal volume = OriginalQty ?? 0m;
|
|
|
+ RefundAmount = (decimal)((trx.Qty - volume) * trx.Price);
|
|
|
+ //RefundAmount = (decimal)((trx.Qty - OriginalQty) * ProductPrice.Value);
|
|
|
+ }
|
|
|
+ if (RefundAmount <= 0.0M)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "该笔单无需退款");
|
|
|
+ }
|
|
|
//退款
|
|
|
var serviceResult = await _payService.ReturnProcess(RefundAmount, (decimal)trx.ActualPaymentAmount, "WX_SCAN", trx.BillNumber);
|
|
|
Payment.Core.Models.ElectronicOrderProcessResultModel payResult = (Payment.Core.Models.ElectronicOrderProcessResultModel)serviceResult.Data;
|
|
@@ -419,36 +450,43 @@ namespace Fuel.Application.Service
|
|
|
trx.OrderStatus = transactionsORDERSTATUS.Cancelled;
|
|
|
trx.RefundAmount = RefundAmount;
|
|
|
int affectedRows = _fsql.Update<transactions>().SetSource(trx).ExecuteAffrows();
|
|
|
+ var user = _fsql.Select<miniprogramusers>().Where(_ => _.Id == trx.MiniProgramID).First();
|
|
|
+ string jsonString = JsonConvert.SerializeObject(trx);
|
|
|
+ await _mqttService.SubscribeAsync("refund/" + Buid);
|
|
|
+ await Task.Delay(2000);
|
|
|
+ var sendjson = new { data = jsonString, UserName = user.UserName, UserPhoneNumber = user.UserPhoneNumber };
|
|
|
+ await _mqttService.PublishAsync("refund/" + Buid, JsonConvert.SerializeObject(sendjson));
|
|
|
return ServiceResponse.Ok(trx);
|
|
|
}
|
|
|
public async Task<ServiceResponse> UnifiedOrder(int trxId)
|
|
|
{
|
|
|
+ Guid Buid = HttpRequestReader.GetCurrentBuId(); //站点id
|
|
|
try
|
|
|
{
|
|
|
logger.Debug("UnifiedOrder start++");
|
|
|
|
|
|
- Guid Buid = HttpRequestReader.GetCurrentBuId(); //站点id
|
|
|
string WachatID = HttpRequestReader.GetWachatID(); //用户
|
|
|
- //var userSession = WechatUserSessionRepo.GetUserSession(WachatID.ToString());
|
|
|
- //if (userSession == null)
|
|
|
- //{
|
|
|
- // return ServiceResponse.Error(HttpStatusCode.NonAuthoritativeInformation, "未找到用户!");
|
|
|
- //}
|
|
|
- var userSession = new WechatUserSessionResponse() { buId = "12345678-9abc-def0-1234-56789abcdef0", openid = "o8pFb5cWH1KkBDvGls2X7yMiFkGA" };
|
|
|
+ var userSession = WechatUserSessionRepo.GetUserSession(WachatID.ToString());
|
|
|
+ if (userSession == null)
|
|
|
+ {
|
|
|
+ return ServiceResponse.Error(HttpStatusCode.NonAuthoritativeInformation, "未找到用户!");
|
|
|
+ }
|
|
|
+ //var userSession = new WechatUserSessionResponse() { buId = "12345678-9abc-def0-1234-56789abcdef0", openid = "o8pFb5cWH1KkBDvGls2X7yMiFkGA" };
|
|
|
var site = _fsql.Select<businessunitinfo>().Where(_ => _.Buid == Buid).First();
|
|
|
var weChatService = new WeChatService(site.Appid, site.Secret);
|
|
|
var user = _fsql.Select<miniprogramusers>().Where(_ => _.OpenId == userSession.openid).First();
|
|
|
var trx = _entityHelper.GetEntitiesAsync<transactions>(_ => _.Id == trxId).Result.FirstOrDefault();
|
|
|
if (trx == null)
|
|
|
{
|
|
|
+ logger.Debug($"统一下单,Buid={Buid} ,trxId={trxId},未查询到订单");
|
|
|
return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "未查询到订单!");
|
|
|
}
|
|
|
- logger.Debug("统一下单开始");
|
|
|
+ logger.Debug($"统一下单开始,Buid={Buid} ,trxId={trxId}");
|
|
|
var serviceResult = await _payService.UnifiedOrder(trx.OriginalAmount.Value, "WX_SCAN", userSession.openid);
|
|
|
var dataProperties = serviceResult.Data.GetType().GetProperty("UnifiedOrderResult");
|
|
|
if (!serviceResult.IsSuccessful() || dataProperties == null)
|
|
|
{
|
|
|
- logger.Debug("统一下单失败" );
|
|
|
+ logger.Debug($"统一下单失败,Buid={Buid} ,trxId={trxId}" );
|
|
|
return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "统一下单失败");
|
|
|
}
|
|
|
|
|
@@ -462,11 +500,13 @@ namespace Fuel.Application.Service
|
|
|
var dataProperties = serviceResult.Data.GetType().GetProperty("eOrder");
|
|
|
var orderModel = (Fuel.Payment.Core.Models.ElectronicOrderModel)dataProperties.GetValue(serviceResult.Data);
|
|
|
var genericResponse = await _payService.QueryOrder(orderModel);
|
|
|
+ logger.Debug($"统一下单,Buid={Buid} ,trxId={trxId},genericResponse.Data={genericResponse.Data}");
|
|
|
if (genericResponse.IsSuccessful() && orderModel.TradeStatus == Fuel.Payment.Core.Models.TradeStatus.SUCCESS)
|
|
|
{
|
|
|
trx.OrderStatus = transactionsORDERSTATUS.Paid;//将订单状态更改成已支付
|
|
|
trx.MiniProgramID = user.Id;
|
|
|
trx.BillNumber = orderModel.BillNumber;
|
|
|
+ trx.BillNumberBase62 = NumericBase62Converter.Encode(orderModel.BillNumber);
|
|
|
trx.ActualPaymentAmount = trx.OriginalAmount;
|
|
|
trx.PaymentMethod = 2;//2 :微信支付
|
|
|
try
|
|
@@ -475,15 +515,18 @@ namespace Fuel.Application.Service
|
|
|
string jsonString = JsonConvert.SerializeObject(trx);
|
|
|
await Task.Delay(2000);
|
|
|
var sendjson = new { data = jsonString, UserName = user.UserName, UserPhoneNumber = user.UserPhoneNumber };
|
|
|
+ logger.Debug($"统一下单,Buid={Buid} ,trxId={trxId},订单推送fcc sendjson={System.Text.Json.JsonSerializer.Serialize(sendjson)}");
|
|
|
//支付完成将订单信息推送到fcc
|
|
|
- await scopedMqttService.PublishAsync("paid/" + Buid, JsonConvert.SerializeObject(sendjson));
|
|
|
+ scopedMqttService.PublishAsync("paid/" + Buid, JsonConvert.SerializeObject(sendjson));
|
|
|
+
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
-
|
|
|
+ logger.Debug($"统一下单,Buid={Buid} ,trxId={trxId},异常:"+ ex.Message);
|
|
|
}
|
|
|
-
|
|
|
+ logger.Debug($"统一下单,Buid={Buid} ,trxId={trxId},更新订单信息");
|
|
|
int affectedRows = _fsql.Update<transactions>().SetSource(trx).ExecuteAffrows();
|
|
|
+ logger.Debug($"统一下单,Buid={Buid} ,trxId={trxId},更新状态" + affectedRows);
|
|
|
//SendMessage(trx,Buid);
|
|
|
}
|
|
|
}
|
|
@@ -494,24 +537,26 @@ namespace Fuel.Application.Service
|
|
|
IgnoreReadOnlyProperties = true // 忽略只读属性
|
|
|
};
|
|
|
string serializedUnifiedOrderResult = System.Text.Json.JsonSerializer.Serialize(unifiedOrderResult, options);
|
|
|
- logger.Debug("统一下单 支付信息 " + serializedUnifiedOrderResult);
|
|
|
+ logger.Debug($"统一下单,Buid={Buid} ,trxId={trxId}, 支付信息 " + serializedUnifiedOrderResult);
|
|
|
return ServiceResponse.Ok(unifiedOrderResult);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- logger.Debug("统一下单: "+ex.Message);
|
|
|
+ logger.Debug($"统一下单,Buid={Buid} ,trxId={trxId},Exception:" +ex.Message);
|
|
|
return ServiceResponse.Error(ex.Message);
|
|
|
}
|
|
|
}
|
|
|
- public async Task<ServiceResponse> Redeem(int trxId, decimal OriginalQty)
|
|
|
+ public async Task<ServiceResponse> Redeem(int trxId, decimal OriginalQty, decimal FuelItemPumpTotalizerVolume)
|
|
|
{
|
|
|
var trx = _entityHelper.GetEntitiesAsync<transactions>(_ => _.Id == trxId).Result.FirstOrDefault();
|
|
|
if (trx == null)
|
|
|
{
|
|
|
return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "未查询到订单!");
|
|
|
}
|
|
|
+ var refund = await RefundTrx(trxId, OriginalQty);
|
|
|
+ trx = _entityHelper.GetEntitiesAsync<transactions>(_ => _.Id == trxId).Result.FirstOrDefault();
|
|
|
trx.OriginalQty = OriginalQty;
|
|
|
- var refund = await RefundTrx(trxId);
|
|
|
+ trx.FuelItemPumpTotalizerVolume = FuelItemPumpTotalizerVolume;
|
|
|
if (refund.IsSuccessful() || refund.StatusCode == HttpStatusCode.NotAcceptable)
|
|
|
{
|
|
|
trx.OrderStatus = transactionsORDERSTATUS.Completed;
|
|
@@ -546,14 +591,21 @@ namespace Fuel.Application.Service
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ //将金额小数改成俩位
|
|
|
+ if (trx.ActualPaymentAmount.HasValue)
|
|
|
+ {
|
|
|
+ decimal roundedValue = Math.Round(trx.ActualPaymentAmount.Value, 2, MidpointRounding.AwayFromZero);
|
|
|
+ trx.ActualPaymentAmount = roundedValue;
|
|
|
+ }
|
|
|
+ // var BillNumber = EncodeBillNumber(trx.BillNumber);
|
|
|
var config = JsonConvert.DeserializeObject<TemplateConfig>(template.Value);
|
|
|
var dataDict = new Dictionary<string, object>();
|
|
|
var dynamicData = new Dictionary<string, object>
|
|
|
{
|
|
|
- { "orderType", orderType },
|
|
|
- { "BillNumber", trx.BillNumber},
|
|
|
- { "ProductName_Qty", trx.ProductName + " | " + trx.Qty + "L"},
|
|
|
- { "ActualPaymentAmount", trx.ActualPaymentAmount },
|
|
|
+ { "orderType", orderType},
|
|
|
+ { "BillNumber", trx.BillNumberBase62 },//trx.BillNumber
|
|
|
+ { "ProductName_Qty", trx.ProductName + " & " + trx.Qty + "L"},
|
|
|
+ { "ActualPaymentAmount",trx.ActualPaymentAmount.ToString() + "元" },
|
|
|
{ "TransactionTime", ToFormattedString(trx.TransactionTime) }
|
|
|
};
|
|
|
|
|
@@ -603,6 +655,7 @@ namespace Fuel.Application.Service
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
public static string GetChineseStatus(transactionsORDERSTATUS status)
|
|
|
{
|
|
|
switch (status)
|
|
@@ -618,7 +671,7 @@ namespace Fuel.Application.Service
|
|
|
case transactionsORDERSTATUS.Completed:
|
|
|
return "订单已完成";
|
|
|
case transactionsORDERSTATUS.Cancelled:
|
|
|
- return "已取消";
|
|
|
+ return "已退款";
|
|
|
default:
|
|
|
throw new ArgumentOutOfRangeException(nameof(status), status, null);
|
|
|
}
|