This commit is contained in:
zpc 2025-09-20 15:11:31 +08:00
parent 09018795bf
commit 1796ec7b50
3 changed files with 110 additions and 4 deletions

View File

@ -1553,6 +1553,8 @@ namespace CoreCms.Net.Configuration
/// </summary> /// </summary>
[Description("通用类型")] [Description("通用类型")]
Common = 11, Common = 11,
} }

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using CoreCms.Net.Caching.AccressToken; using CoreCms.Net.Caching.AccressToken;
using CoreCms.Net.Configuration; using CoreCms.Net.Configuration;
using CoreCms.Net.IServices; using CoreCms.Net.IServices;
@ -10,10 +11,13 @@ using CoreCms.Net.Model.ViewModels.UI;
using CoreCms.Net.WeChat.Service.Enums; using CoreCms.Net.WeChat.Service.Enums;
using CoreCms.Net.WeChat.Service.HttpClients; using CoreCms.Net.WeChat.Service.HttpClients;
using CoreCms.Net.WeChat.Service.Models; using CoreCms.Net.WeChat.Service.Models;
using InitQ.Abstractions; using InitQ.Abstractions;
using InitQ.Attributes; using InitQ.Attributes;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using SKIT.FlurlHttpClient.Wechat.Api; using SKIT.FlurlHttpClient.Wechat.Api;
using SKIT.FlurlHttpClient.Wechat.Api.Models; using SKIT.FlurlHttpClient.Wechat.Api.Models;
@ -44,7 +48,7 @@ namespace CoreCms.Net.RedisMQ.Subscribe
/// <param name="msg"></param> /// <param name="msg"></param>
/// <returns></returns> /// <returns></returns>
[Subscribe(RedisMessageQueueKey.SendWxTemplateMessage)] [Subscribe(RedisMessageQueueKey.SendWxTemplateMessage)]
private async Task SendWxTemplateMessage(string msg) public async Task SendWxTemplateMessage(string msg)
{ {
try try
{ {
@ -146,6 +150,20 @@ namespace CoreCms.Net.RedisMQ.Subscribe
templateMessageData[templateData.data04] = new CgibinMessageSubscribeSendRequest.Types.DataItem() { Value = parameters["paymentCode"].ToString() }; templateMessageData[templateData.data04] = new CgibinMessageSubscribeSendRequest.Types.DataItem() { Value = parameters["paymentCode"].ToString() };
templateMessageData[templateData.data05] = new CgibinMessageSubscribeSendRequest.Types.DataItem() { Value = parameters["createTime"].ToString() }; templateMessageData[templateData.data05] = new CgibinMessageSubscribeSendRequest.Types.DataItem() { Value = parameters["createTime"].ToString() };
} }
else if (request.code == GlobalEnumVars.WeChatMsgTemplateType.reservation_success.ToString())
{
templateMessageData[templateData.data01] = new CgibinMessageSubscribeSendRequest.Types.DataItem() { Value = parameters["createTime"].ToString() };
templateMessageData[templateData.data02] = new CgibinMessageSubscribeSendRequest.Types.DataItem() { Value = parameters["title"].ToString() };
templateMessageData[templateData.data03] = new CgibinMessageSubscribeSendRequest.Types.DataItem() { Value = parameters["roomName"].ToString() };
templateMessageData[templateData.data04] = new CgibinMessageSubscribeSendRequest.Types.DataItem() { Value = parameters["tips"].ToString() };
}
else if (request.code == GlobalEnumVars.WeChatMsgTemplateType.reservation_change.ToString())
{
templateMessageData[templateData.data01] = new CgibinMessageSubscribeSendRequest.Types.DataItem() { Value = parameters["title"].ToString() };
templateMessageData[templateData.data02] = new CgibinMessageSubscribeSendRequest.Types.DataItem() { Value = parameters["createTime"].ToString() };
templateMessageData[templateData.data03] = new CgibinMessageSubscribeSendRequest.Types.DataItem() { Value = parameters["context"].ToString() };
templateMessageData[templateData.data04] = new CgibinMessageSubscribeSendRequest.Types.DataItem() { Value = parameters["tips"].ToString() };
}
var result = await Send(weChatUserInfo.openid, templateData.templateId, templateMessageData, pageUrl); var result = await Send(weChatUserInfo.openid, templateData.templateId, templateMessageData, pageUrl);
NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.RedisMessageQueue, "微信模板消息", JsonConvert.SerializeObject(result)); NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.RedisMessageQueue, "微信模板消息", JsonConvert.SerializeObject(result));
@ -200,7 +218,7 @@ namespace CoreCms.Net.RedisMQ.Subscribe
} }
else else
{ {
return null; newCode = code;
} }
var info = await _userWeChatMsgSubscriptionServices.QueryByClauseAsync(p => p.userId == userId && p.type == newCode); var info = await _userWeChatMsgSubscriptionServices.QueryByClauseAsync(p => p.userId == userId && p.type == newCode);

View File

@ -1,4 +1,11 @@
using CoreCms.Net.IServices; using CoreCms.Net.Caching.AutoMate.RedisCache;
using CoreCms.Net.Configuration;
using CoreCms.Net.IServices;
using DotLiquid.Tags;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SqlSugar; using SqlSugar;
@ -8,6 +15,8 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using static SKIT.FlurlHttpClient.Wechat.Api.Models.CgibinUserInfoBatchGetRequest.Types;
namespace CoreCms.Net.Task namespace CoreCms.Net.Task
{ {
/// <summary> /// <summary>
@ -17,11 +26,14 @@ namespace CoreCms.Net.Task
{ {
private readonly ISQReservationsServices _reservationsServices; private readonly ISQReservationsServices _reservationsServices;
private readonly ISQReservationParticipantsServices _participantsServices; private readonly ISQReservationParticipantsServices _participantsServices;
private readonly IRedisOperationRepository _redisOperationRepository;
public SQReservationJob(ISQReservationsServices reservationsServices, public SQReservationJob(ISQReservationsServices reservationsServices,
ISQReservationParticipantsServices participantsServices) ISQReservationParticipantsServices participantsServices,
IRedisOperationRepository redisOperationRepository)
{ {
_reservationsServices = reservationsServices; _reservationsServices = reservationsServices;
_participantsServices = participantsServices; _participantsServices = participantsServices;
_redisOperationRepository = redisOperationRepository;
} }
public async System.Threading.Tasks.Task Execute() public async System.Threading.Tasks.Task Execute()
@ -58,6 +70,57 @@ namespace CoreCms.Net.Task
await _reservationsServices.UpdateAsync(startedList); await _reservationsServices.UpdateAsync(startedList);
} }
// 2.5) 到达开始时间但人数未满的预约置为取消4
Console.WriteLine("到达开始时间但人数未满的预约置为取消4");
var toCancelList = await _reservationsServices.QueryListByClauseAsync(
r => r.status == 0 && r.start_time <= now && r.end_time > now,
r => r.id, OrderByType.Asc);
if (toCancelList != null && toCancelList.Count > 0)
{
foreach (var item in toCancelList)
{
var count = await _participantsServices.GetCountAsync(p => p.reservation_id == item.id && p.status == 0);
if (count < item.player_count)
{
item.status = 4;
item.updated_at = now;
}
}
var toCancelChanged = toCancelList.Where(x => x.status == 4).ToList();
if (toCancelChanged.Count > 0)
{
await _reservationsServices.UpdateAsync(toCancelChanged);
foreach (var item in toCancelChanged)
{
var userList = await _participantsServices.QueryListByClauseAsync(p => p.reservation_id == item.id && p.status == 0);
foreach (var user in userList)
{
JObject parameters = new JObject();
parameters.Add("title", item.title);
parameters.Add("context", $"组局失败!");
parameters.Add("createTime", item.start_time);
parameters.Add("tips", $"组局人数未满,自动解散!");
var @params = new JObject();
@params.Add("parameters", parameters);
var data = new
{
user.user_id,
code = "reservation_change",
parameters = @params
};
await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.SendWxTemplateMessage, JsonConvert.SerializeObject(data));
}
}
}
}
// 3) 开始前30分钟内人数已凑齐则置为锁定1 // 3) 开始前30分钟内人数已凑齐则置为锁定1
Console.WriteLine("开始前30分钟内人数已凑齐则置为锁定1"); Console.WriteLine("开始前30分钟内人数已凑齐则置为锁定1");
var threshold = now.AddMinutes(30); var threshold = now.AddMinutes(30);
@ -81,6 +144,29 @@ namespace CoreCms.Net.Task
if (changed.Count > 0) if (changed.Count > 0)
{ {
await _reservationsServices.UpdateAsync(changed); await _reservationsServices.UpdateAsync(changed);
foreach (var item in changed)
{
var userList = await _participantsServices.QueryListByClauseAsync(p => p.reservation_id == item.id && p.status == 0);
foreach (var user in userList)
{
JObject parameters = new JObject();
parameters.Add("title", item.title);
parameters.Add("roomName", item.room_name);
parameters.Add("createTime", item.start_time);
parameters.Add("tips", $"组局成功!");
var @params = new JObject();
@params.Add("parameters", parameters);
var data = new
{
user.user_id,
code = "reservation_success",
parameters = @params
};
await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.SendWxTemplateMessage, JsonConvert.SerializeObject(data));
}
}
} }
} }