【修复】修复日历签到连续签到的统计错误的问题,增加用户签到redis锁。

This commit is contained in:
大灰灰
2022-10-21 14:26:00 +08:00
parent c88951e1f3
commit c8175d1090
2 changed files with 74 additions and 25 deletions

View File

@@ -67,15 +67,45 @@ namespace CoreCms.Net.Services
var jm = new AdminUiCallBack();
try
{
var dt = DateTime.Now;
var dtStr = dt.ToString("yyyy-MM-dd");
var checkDataStr = entity.checkInData.ToString("yyyy-MM-dd");
if (dtStr != checkDataStr)
{
jm.msg = "签到日期不符,签到提交日期非今日";
return jm;
}
var id = await _dal.InsertAsync(entity);
var userCheckIn = await _userCheckInServices.QueryByClauseAsync(p => p.userId == entity.userId);
if (userCheckIn != null)
{
userCheckIn.continuousCheckInCount += 1;
//累计签到
userCheckIn.cumulativeCheckInCount += 1;
//判断是否是连续签到
//判断是否是连续签到逻辑是获取用户最后一次的签到记录检查查询到的签到记录的checkInData是不是昨天的checkInData是的话就是连续签到continuousCheckInCount++,不是的话就是断签了continuousCheckInCount设置成1重新开始就行了。
var lastCheck = await _dal.QueryByClauseAsync(p => p.id < id, true);
if (lastCheck == null)
{
userCheckIn.continuousCheckInCount = 1;
}
else
{
var yesterdayDataStr = dt.AddDays(-1).ToString("yyyy-MM-dd");
var lastCheckDataStr = lastCheck.checkInData.ToString("yyyy-MM-dd");
if (yesterdayDataStr == lastCheckDataStr)
{
//累加
userCheckIn.continuousCheckInCount += 1;
}
else
{
//重置
userCheckIn.continuousCheckInCount = 1;
}
}
await _userCheckInServices.UpdateAsync(userCheckIn);
}
else