Your Name 2 недель назад
Родитель
Сommit
4a083289e2

+ 1 - 0
FuelCloud/Fuel.Application/MqttService/MqttClientService .cs

@@ -95,6 +95,7 @@ namespace Fuel.Application.MqttService
             try
             {
                 await _mqttClient.PublishAsync(message);
+                _logger.LogError($"PublishAsync,topic:{topic},payload:{payload},推送成功");
             }
             catch (ObjectDisposedException ex)
             {

+ 2 - 3
FuelCloud/Fuel.Application/Service/ITransactionsService.cs

@@ -19,9 +19,8 @@ namespace Fuel.Application.Service
         Task<ServiceResponse> GetMiniProgramTransactionsUnpaidNozzleAsync(long NozzleId);
         Task<ServiceResponse> GetMiniProgramTransactionsPaidAsync(TransactionsInput input);
         Task<ServiceResponse> RefundTrx(int trxId,
-            double longitude,
-            double latitude);
-        Task<ServiceResponse> Redeem(int trxId, decimal OriginalQty);
+            decimal? OriginalQty = null);
+        Task<ServiceResponse> Redeem(int trxId, decimal OriginalQty, decimal FuelItemPumpTotalizerVolume);
         Task<ServiceResponse> UnifiedOrder(int trxId);
         Task<ServiceResponse> WXFindOrders(DateTime? dateTime, int pageNum, int lineCount);
         Task SendMessage(int trxId, string orderType);

+ 13 - 3
FuelCloud/Fuel.Application/Service/NozzleService.cs

@@ -26,6 +26,7 @@ namespace Fuel.Application.Service
         private readonly EntityHelper _entityHelper;
         public readonly IFreeSql _fsql;
         private readonly IMqttClientService _mqttService;
+        static NLog.Logger logger = NLog.LogManager.LoadConfiguration("nlog.xml").GetLogger("Main");
 
         public NozzleService(EntityHelper entityHelper, IFreeSql fsql, IMqttClientService mqttService)
         {
@@ -224,7 +225,7 @@ namespace Fuel.Application.Service
             _nozzle.TankId = _tanks.Id;
             _nozzle.InternalGunNumber = uploadNozzle.InternalGunNumber;
             _nozzle.ExternalGunNumber = uploadNozzle.ExternalGunNumber;
-            _nozzle.ProductID = _product.Id;
+            _nozzle.ProductID = _product.ProductId;
             _nozzle.NozzleId = uploadNozzle.NozzleId;
             long id = _fsql.Insert<nozzle>().AppendData(_nozzle).ExecuteIdentity();
             if (id <= 0)
@@ -305,7 +306,7 @@ namespace Fuel.Application.Service
             Guid guid = HttpRequestReader.GetCurrentBuId(); //站点id
             return _entityHelper._fsql.Select<nozzle, tanks, product>()
                     .LeftJoin((a, b, c) => a.TankId == b.Id)
-                    .LeftJoin((a, b, c) => a.ProductID == c.Id)
+                    .LeftJoin((a, b, c) => a.ProductID == c.ProductId && c.Buid == guid)
                     .Where((a, b, c) => a.Buid == guid && a.Id == Nozzleid)
                     .ToList((a, b, c) => new NozzleInfo()
                     {
@@ -353,34 +354,43 @@ namespace Fuel.Application.Service
         /// <returns></returns>
         public async Task<ServiceResponse> NozzleAuthorizationAsync(int trxId)
         {
+
             Guid guid = HttpRequestReader.GetCurrentBuId(); //站点id
+            logger.Debug($"向fcc发起油枪授权,Buid={guid} ,trxId={trxId}");
             var trx = _entityHelper.GetEntitiesAsync<transactions>(_ => _.Id == trxId).Result.FirstOrDefault();
             if (trx == null)
             {
+                logger.Debug($"向fcc发起油枪授权,Buid={guid} ,trxId={trxId},未查询到订单!");
                 return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "未查询到订单!");
             }
             var user = _fsql.Select<miniprogramusers>().Where(_ => _.Id == trx.MiniProgramID).First();
             string key = guid + "_" + trx.NozzleId;//授权结果的key
+            logger.Debug($"向fcc发起油枪授权,Buid={guid} ,trxId={trxId},授权key:"+ key);
             string jsonString = JsonConvert.SerializeObject(trx);
+            logger.Debug($"向fcc发起油枪授权,Buid={guid} ,trxId={trxId},jsonString:" + jsonString);
             await _mqttService.SubscribeAsync("authorization/" + guid);
             await Task.Delay(2000);
             var sendjson = new { data = jsonString, UserName = user.UserName, UserPhoneNumber = user.UserPhoneNumber };
             await _mqttService.PublishAsync("authorization/" + guid, JsonConvert.SerializeObject(sendjson));
+            logger.Debug($"向fcc发起油枪授权,Buid={guid} ,trxId={trxId},发起授权");
             KeyValueCache.AddOrUpdate("authGun", key, AuthorizationStatus.WaitAuthorization);//添加字典,用于监听授权结果
             bool changed = await KeyValueCache.MonitorDictionaryChanges("authGun", key, AuthorizationStatus.WaitAuthorization);
             if (!changed)
             {
+                logger.Debug($"向fcc发起油枪授权,Buid={guid} ,trxId={trxId},授权失败");
                 return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "授权失败");
             }
 
             var auth = KeyValueCache.GetValueOrDefault<NozzleAuthorization>("authGun", key);
             if (auth == null || auth.OilMachineStatus != OilMachineStatus.Success)
             {
+                logger.Debug($"向fcc发起油枪授权,Buid={guid} ,trxId={trxId},授权失败,fcc返回状态:" + auth.OilMachineStatus);
                 return ServiceResponse.Error(HttpStatusCode.NotAcceptable, "授权失败");
             }
             trx.TransactionNumber = auth.TransactionNumber;
             trx.authorizationStatus = AuthorizationStatus.Authorized;//将订单授权状态更改成已授权
             int affectedRows = _fsql.Update<transactions>().SetSource(trx).ExecuteAffrows();
+            logger.Debug($"向fcc发起油枪授权,Buid={guid} ,trxId={trxId},订单更新:" + (affectedRows == 1 ? true : false));
             return ServiceResponse.Ok("授权成功");
         }
         /// <summary>
@@ -436,7 +446,7 @@ namespace Fuel.Application.Service
                 {
                     return ServiceResponse.Error("油枪查询失败,油枪名称:" + nozzleAuthorization.NozzleId);
                 }
-                var trx = _entityHelper.GetEntitiesAsync<transactions>(_ => _.Buid == guid && _.NozzleId == _nozzle.First().Id).Result.FirstOrDefault();
+                var trx = _entityHelper.GetEntitiesAsync<transactions>(_ => _.Buid == guid && _.NozzleId == _nozzle.First().ExternalGunNumber && _.TransactionNumber == nozzleAuthorization.TransactionNumber && _.Id == nozzleAuthorization.TransactionID).Result.FirstOrDefault();
                 if (trx != null)
                 {
                     trx.authorizationStatus = AuthorizationStatus.Unauthorized;

+ 4 - 4
FuelCloud/Fuel.Application/Service/SiteService.cs

@@ -82,10 +82,10 @@ namespace Fuel.Application.Service
                 },
                 userInfo = new
                 {
-                    UserName = user.UserName,//用户名称
-                    UserAvatarUrl = user.UserAvatarUrl,//用户头像地址
-                    UserAddress = user.Address,//用户地址
-                    UserPhoneNumber = user.UserPhoneNumber//用户手机号
+                    UserName = user?.UserName,//用户名称
+                    UserAvatarUrl = user?.UserAvatarUrl,//用户头像地址
+                    UserAddress = user?.Address,//用户地址
+                    UserPhoneNumber = user?.UserPhoneNumber//用户手机号
                 }
             };
             return ServiceResponse.Ok(SiteInfo);

+ 89 - 36
FuelCloud/Fuel.Application/Service/TransactionsService.cs

@@ -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);
             }

+ 2 - 2
FuelCloud/src/Fuel.Payment.Server/Controllers/TransactionsController.cs

@@ -128,7 +128,7 @@ namespace Fuel.PaymentServer.Controllers
         [HttpPost]
         public async Task<IActionResult> RefundTrx(RefundTrxRequest refundTrx)
         {
-            var serviceResult = await _transactionsService.RefundTrx(refundTrx.trxId, refundTrx.longitude, refundTrx.latitude);
+            var serviceResult = await _transactionsService.RefundTrx(refundTrx.trxId);
             return Ok(serviceResult);
         }
         /// <summary>
@@ -141,7 +141,7 @@ namespace Fuel.PaymentServer.Controllers
         [HttpPost]
         public async Task<IActionResult> Redeem(RedeemRequest redeemRequest)
         {
-            var serviceResult = await _transactionsService.Redeem(redeemRequest.trxId, redeemRequest.OriginalQty);
+            var serviceResult = await _transactionsService.Redeem(redeemRequest.trxId, redeemRequest.OriginalQty,redeemRequest.FuelItemPumpTotalizerVolume);
             return Ok(serviceResult);
         }
         /// <summary>

+ 2 - 2
FuelCloud/src/Fuel.Payment.Server/Program.cs

@@ -128,9 +128,9 @@ builder.Services.AddCors(options =>
 
 builder.WebHost.ConfigureKestrel(options =>
 {
-    options.Listen(System.Net.IPAddress.Parse("192.168.0.202"), 5006); // 监听特定IPv4地址的5002端口
+    //options.Listen(System.Net.IPAddress.Parse("192.168.0.202"), 5006); // 监听特定IPv4地址的5002端口
     //options.Listen(System.Net.IPAddress.Parse("172.31.2.202"), 5006); // 监听特定IPv4地址的5002端口
-    options.Listen(System.Net.IPAddress.Parse("::1"), 5006); // 监听特定IPv6地址(这里是localhost)的5003端口
+    options.Listen(System.Net.IPAddress.Parse("::1"), 5007); // 监听特定IPv6地址(这里是localhost)的5003端口
 });
 builder.Services.AddControllers()
     .AddJsonOptions(options =>

+ 2 - 1
FuelCloud/src/Fuel.Payment.Server/appsettings.json

@@ -1,6 +1,7 @@
 {
   "ConnectionStrings": {
-    "MysqlConnection": "Server=localhost; Port=3306; Database=fuellite; Uid=root; Pwd=HS1205; Charset=utf8mb4;"
+    //"MysqlConnection": "Server=localhost; Port=3306; Database=fuellite; Uid=root; Pwd=HS1205; Charset=utf8mb4;"
+    "MysqlConnection": "Server=47.97.120.160; Port=3307; Database=fuellite; Uid=root; Pwd=Wayne@123; Charset=utf8mb4;"
   },
   "Logging": {
     "LogLevel": {

+ 23 - 11
FuelCloud/src/Fuel.Payment.Service/WeChatPaymentProcessor/Wechat/WechatPaymentProcessor.cs

@@ -158,18 +158,30 @@ namespace Fuel.Payment.Service.WeChatPaymentProcessor.Wechat
 
         protected override async Task<GenericProcessResponse> Initialize(ElectronicOrderModel order)
         {
-            string sourceFilePath = @"C:\cw\Code\smartfuel_lite\FuelCloud\src\Fuel.Payment.Server\File\Certificate\12345678-9abc-def0-1234-56789abcdef0\apiclient_cert.p12";
-            //string sourceFilePath = @"D:/fuelcloud/fabu/File/Certificate/12345678-9abc-def0-1234-56789abcdef0/apiclient_cert.p12";
-            string config = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<WxPayConfig>  \r\n  <APPID>wxb198dafff060e651</APPID>  \r\n  <SUBAPPID></SUBAPPID>\r\n  <MINI_PROGRAM_APPID>wxb198dafff060e651</MINI_PROGRAM_APPID>\r\n  <MCHID>1617253894</MCHID>\r\n  <SUBMCHID></SUBMCHID>\r\n  <KEY>Kguangzhouhengshangongsi20250211</KEY>\r\n  <APPSECRET>2e6ee037b95c8fb90eb415bb559f8259</APPSECRET>\r\n  <SSLCERT>apiclient_cert.p12</SSLCERT>\r\n  <SSLCERT_PASSWORD>1617253894</SSLCERT_PASSWORD>\r\n  <NOTIFY_URL>http://paysdk.weixin.qq.com/example/ResultNotifyPage.aspx</NOTIFY_URL>\r\n  <IP>8.8.8.8</IP>\r\n  <PROXY_URL>http://10.152.18.220:8080</PROXY_URL>\r\n  <REPORT_LEVENL>1</REPORT_LEVENL>\r\n</WxPayConfig>";
-            FileHandler fileHandler = new FileHandler();
-            byte[] fileBytes = fileHandler.ReadFileToByteArray(sourceFilePath);
-            order.Certification = fileHandler.GetWxPayCertificationInfo(fileBytes, "1617253894").Result.Certification;
-            WayneCloud.Models.Models.WxPayConfig wxPayConfig = WayneCloud.Models.Models.WxPayConfig.DeserializeFromXmlString(config);
-            order.Config = wxPayConfig;
-            return new GenericProcessResponse()
+            try
             {
-                electronicOrderModel = order
-            };
+                string sourceFilePath = @"C:\cw\Code\smartfuel_lite\FuelCloud\src\Fuel.Payment.Server\File\Certificate\12345678-9abc-def0-1234-56789abcdef0\apiclient_cert.p12";
+                //string sourceFilePath = @"D:/fuelcloud/fabu/File/Certificate/12345678-9abc-def0-1234-56789abcdef0/apiclient_cert.p12";
+                string config = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<WxPayConfig>  \r\n  <APPID>wxb198dafff060e651</APPID>  \r\n  <SUBAPPID></SUBAPPID>\r\n  <MINI_PROGRAM_APPID>wxb198dafff060e651</MINI_PROGRAM_APPID>\r\n  <MCHID>1617253894</MCHID>\r\n  <SUBMCHID></SUBMCHID>\r\n  <KEY>Kguangzhouhengshangongsi20250211</KEY>\r\n  <APPSECRET>2e6ee037b95c8fb90eb415bb559f8259</APPSECRET>\r\n  <SSLCERT>apiclient_cert.p12</SSLCERT>\r\n  <SSLCERT_PASSWORD>1617253894</SSLCERT_PASSWORD>\r\n  <NOTIFY_URL>http://paysdk.weixin.qq.com/example/ResultNotifyPage.aspx</NOTIFY_URL>\r\n  <IP>8.8.8.8</IP>\r\n  <PROXY_URL>http://10.152.18.220:8080</PROXY_URL>\r\n  <REPORT_LEVENL>1</REPORT_LEVENL>\r\n</WxPayConfig>";
+                FileHandler fileHandler = new FileHandler();
+                byte[] fileBytes = fileHandler.ReadFileToByteArray(sourceFilePath);
+                order.Certification = fileHandler.GetWxPayCertificationInfo(fileBytes, "1617253894").Result.Certification;
+                WayneCloud.Models.Models.WxPayConfig wxPayConfig = WayneCloud.Models.Models.WxPayConfig.DeserializeFromXmlString(config);
+                order.Config = wxPayConfig;
+                return new GenericProcessResponse()
+                {
+                    electronicOrderModel = order
+                };
+            }
+            catch(Exception ex)
+            {
+                Log.Info("UnifiedOrder", "Initialize :" + ex.Message);
+                return new GenericProcessResponse()
+                {
+
+                };
+            }
+
         }
 
         protected override async Task<ElectronicOrderModel> PaymentResult(GenericProcessResponse order, ElectronicOrderModel electronicOrderModel)

+ 1 - 1
FuelCloud/src/FuelServer.Core/Entity/businessunitinfo.cs

@@ -62,7 +62,7 @@ namespace FuelServer.Core.Entity
 		[JsonProperty, Column(StringLength = 100)]
 		public string Secret { get; set; }
         /// <summary>
-        /// 预支付:1,后支付:2
+        /// 预支付:1,后支付:0
         /// </summary>
         [JsonProperty]
         public int PaymentMode { get; set; }

+ 10 - 5
FuelCloud/src/FuelServer.Core/Entity/transactions.cs

@@ -171,6 +171,11 @@ namespace FuelServer.Core.Entity
         [JsonProperty, Column(StringLength = 50, IsNullable = false)]
         public string BillNumber { get; set; }
         /// <summary>
+        /// 订单编号,编码后
+        /// </summary>
+        [JsonProperty, Column(StringLength = 100, IsNullable = false)]
+        public string BillNumberBase62 { get; set; }
+        /// <summary>
         /// 退款状态
         /// </summary>
         [JsonProperty]
@@ -258,14 +263,14 @@ namespace FuelServer.Core.Entity
     /// </summary>
     public enum transactionsORDERTYPE
     {
-        /// <summary>
-        /// 预支付订单。
-        /// </summary>
-        Prepayment,
 
         /// <summary>
         /// 后支付订单。
         /// </summary>
-        Postpayment
+        Postpayment,
+        /// <summary>
+        /// 预支付订单。
+        /// </summary>
+        Prepayment
     }
 }

+ 4 - 0
FuelCloud/src/FuelServer.Core/Nozzle/Dto/UploadNozzle.cs

@@ -93,6 +93,10 @@ namespace Fuel.Core.Nozzle.Dto
         public string TransactionNumber { get; set; }
         public OilMachineStatus OilMachineStatus { get; set; }
 
+        /// <summary>
+        /// 订单id
+        /// </summary>
+        public long? TransactionID { get; set; }
     }
     public enum OilMachineStatus
     {

+ 58 - 0
FuelCloud/src/FuelServer.Core/NumericBase62Converter.cs

@@ -0,0 +1,58 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Numerics;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Fuel.Core
+{
+    public class NumericBase62Converter
+    {
+        // 标准字符顺序:0-9, A-Z, a-z
+        private const string CharacterSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+        /// <summary>
+        /// 将长数字字符串编码为Base62(修正版)
+        /// </summary>
+        public static string Encode(string numericString)
+        {
+            // 验证输入是否为纯数字
+            if (!BigInteger.TryParse(numericString, out var number) || number < 0)
+                throw new ArgumentException("Input must be a non-negative numeric string");
+
+            // 特殊处理0值
+            if (number == 0) return "0";
+
+            var buffer = new StringBuilder();
+            BigInteger divisor = 62;
+
+            while (number > 0)
+            {
+                // 计算余数并获取对应字符
+                number = BigInteger.DivRem(number, divisor, out var remainder);
+                int index = (int)remainder;
+                buffer.Insert(0, CharacterSet[index]); // 插入到结果最前面
+            }
+
+            return buffer.ToString();
+        }
+
+        /// <summary>
+        /// 解码Base62字符串回原始数字
+        /// </summary>
+        public static string Decode(string base62String)
+        {
+            BigInteger result = 0;
+            foreach (char c in base62String)
+            {
+                int value = CharacterSet.IndexOf(c);
+                if (value == -1)
+                    throw new ArgumentException($"Invalid character: {c}");
+
+                result = result * 62 + value;
+            }
+            return result.ToString();
+        }
+    }
+}

+ 5 - 0
FuelCloud/src/FuelServer.Core/Transactions/Dto/RefundTrxRequest.cs

@@ -22,5 +22,10 @@ namespace Fuel.Core.Transactions.Dto
     {
         public int trxId { get; set; }
         public decimal OriginalQty { get; set; }
+        /// <summary>
+        /// 泵码
+        /// </summary>
+        public decimal FuelItemPumpTotalizerVolume { get; set; }
+
     }
 }

+ 4 - 0
FuelCloud/src/FuelServer.Core/Transactions/TransactionsList.cs

@@ -46,5 +46,9 @@ namespace Fuel.Core.Transactions
         /// </summary>
         public string PaymentMethod { get; set; }
         public string UserName { get; set; }
+        /// <summary>
+        /// 退款金额
+        /// </summary>
+        public decimal? RefundAmount { get; set; }
     }
 }