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, "定时任务操作"); } } //插入日志