From db4e141a67c57c9dce8d8a018282065c614a1e10 Mon Sep 17 00:00:00 2001 From: JianWeie Date: Sat, 4 Sep 2021 00:38:08 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E4=BD=A3=E9=87=91=E7=BB=93=E7=AE=97=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E9=98=9F=E5=88=97=E4=B8=BA=E5=BB=B6=E8=BF=9F=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E9=98=9F=E5=88=97=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=B9=B6=E5=8F=91=E4=B8=8B=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=90=8C=E6=AD=A5=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RedisCache/IRedisOperationRepository.cs | 9 +++++++++ .../AutoMate/RedisCache/RedisOperationRepository.cs | 13 +++++++++++++ .../Order/ICoreCmsOrderServices.cs | 4 ++-- .../Subscribe/OrderFinishCommandSubscribe.cs | 10 +++++----- CoreCms.Net.Services/Order/CoreCmsOrderServices.cs | 13 +++++++++---- 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/CoreCms.Net.Caching/AutoMate/RedisCache/IRedisOperationRepository.cs b/CoreCms.Net.Caching/AutoMate/RedisCache/IRedisOperationRepository.cs index 671c07d..143a2d6 100644 --- a/CoreCms.Net.Caching/AutoMate/RedisCache/IRedisOperationRepository.cs +++ b/CoreCms.Net.Caching/AutoMate/RedisCache/IRedisOperationRepository.cs @@ -130,5 +130,14 @@ namespace CoreCms.Net.Caching.AutoMate.RedisCache /// Task ListClearAsync(string redisKey); + + /// + /// 有序集合/定时任务延迟队列用的多 + /// + /// key + /// 元素 + /// 分数 + Task SortedSetAddAsync(string redisKey, string redisValue, double score); + } } diff --git a/CoreCms.Net.Caching/AutoMate/RedisCache/RedisOperationRepository.cs b/CoreCms.Net.Caching/AutoMate/RedisCache/RedisOperationRepository.cs index 496546d..d70ef80 100644 --- a/CoreCms.Net.Caching/AutoMate/RedisCache/RedisOperationRepository.cs +++ b/CoreCms.Net.Caching/AutoMate/RedisCache/RedisOperationRepository.cs @@ -226,5 +226,18 @@ namespace CoreCms.Net.Caching.AutoMate.RedisCache { await _database.ListTrimAsync(redisKey, 1, 0); } + + + /// + /// 有序集合/定时任务延迟队列用的多 + /// + /// key + /// 元素 + /// 分数 + public async Task SortedSetAddAsync(string redisKey, string redisValue, double score) + { + await _database.SortedSetAddAsync(redisKey, redisValue, score); + } + } } diff --git a/CoreCms.Net.IServices/Order/ICoreCmsOrderServices.cs b/CoreCms.Net.IServices/Order/ICoreCmsOrderServices.cs index 385dccf..980f1a8 100644 --- a/CoreCms.Net.IServices/Order/ICoreCmsOrderServices.cs +++ b/CoreCms.Net.IServices/Order/ICoreCmsOrderServices.cs @@ -206,14 +206,14 @@ namespace CoreCms.Net.IServices int storeId = 0, int shipAreaId = 0, string deliveryCompanyId = ""); - /// /// 后台完成订单 /// /// + /// 有序队列积分 /// /// - Task CompleteOrder(string orderId, string remark = "后台订单完成操作"); + Task CompleteOrder(string orderId, int score = 0, string remark = "后台订单完成操作"); /// /// 确认签收订单 diff --git a/CoreCms.Net.RedisMQ/Subscribe/OrderFinishCommandSubscribe.cs b/CoreCms.Net.RedisMQ/Subscribe/OrderFinishCommandSubscribe.cs index bca6e37..ad00e8b 100644 --- a/CoreCms.Net.RedisMQ/Subscribe/OrderFinishCommandSubscribe.cs +++ b/CoreCms.Net.RedisMQ/Subscribe/OrderFinishCommandSubscribe.cs @@ -40,11 +40,11 @@ namespace CoreCms.Net.RedisMQ.Subscribe } /// - /// 订单完成时,结算该订单 + /// 订单完成时,结算该订单|延迟队列 /// /// /// - [Subscribe(RedisMessageQueueKey.OrderFinishCommand)] + [SubscribeDelay(RedisMessageQueueKey.OrderFinishCommand)] private async Task OrderFinishCommand(string msg) { @@ -57,11 +57,11 @@ namespace CoreCms.Net.RedisMQ.Subscribe } else { + await _distributionOrderServices.FinishOrder(msg); + await _agentOrderServices.FinishOrder(msg); NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.RedisMessageQueue, "订单完结结佣", "订单编号获取正常:" + msg); } - await _distributionOrderServices.FinishOrder(msg); - await _agentOrderServices.FinishOrder(msg); - + } catch (Exception ex) { diff --git a/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs b/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs index 2fbe4d9..979dfb9 100644 --- a/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs +++ b/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs @@ -1845,12 +1845,15 @@ namespace CoreCms.Net.Services #region 完成订单 + /// /// 完成订单 /// /// + /// 有序队列积分 + /// /// - public async Task CompleteOrder(string orderId, string remark = "后台订单完成操作") + public async Task CompleteOrder(string orderId, int score = 0, string remark = "后台订单完成操作") { var jm = new WebApiCallBack(); @@ -1911,7 +1914,7 @@ namespace CoreCms.Net.Services await _orderLogServices.InsertAsync(orderLog); //订单完成结算订单 - await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderFinishCommand, orderInfo.orderId); + await _redisOperationRepository.SortedSetAddAsync(RedisMessageQueueKey.OrderFinishCommand, orderInfo.orderId, score); jm.status = true; jm.msg = "订单完成"; @@ -2127,9 +2130,11 @@ namespace CoreCms.Net.Services if (orderInfos != null && orderInfos.Any()) { - foreach (var item in orderInfos) + for (var i = 0; i < orderInfos.Count; i++) { - await CompleteOrder(item.orderId, "定时任务操作"); + var item = orderInfos[i]; + var score = 2 * (i + 1); + await CompleteOrder(item.orderId, score, "定时任务操作"); } } //插入日志