mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 22:43:25 +08:00
# 2022-03-14
### 1.3.9 开源社区版: 【修复】修复BaseRepository数据交互层仓储SqlWith.NoLock使用方式异常的问题。 ### 0.2.8 专业版: 【新增】增加日历签到功能。实现通过日历签到获得积分,余额。【非破坏性无缝增加功能】 【新增】增加“连续签到周期”定时任务,用于根据后台的设置,实时重置清零用户连续签到计数。 【修复】修复BaseRepository数据交互层仓储SqlWith.NoLock使用方式异常的问题。
This commit is contained in:
118
CoreCms.Net.Web.WebApi/Controllers/CheckInController.cs
Normal file
118
CoreCms.Net.Web.WebApi/Controllers/CheckInController.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Auth.HttpContextUser;
|
||||
using CoreCms.Net.IRepository;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Nito.AsyncEx;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 签到控制器
|
||||
/// </summary>
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class CheckInController : ControllerBase
|
||||
{
|
||||
private readonly ICoreCmsUserCheckInDetailsServices _userCheckInDetailsServices;
|
||||
private readonly IHttpContextUser _user;
|
||||
|
||||
//简单的异步锁
|
||||
private readonly AsyncLock _mutex = new AsyncLock();
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public CheckInController(IHttpContextUser user, ICoreCmsUserCheckInDetailsServices userCheckInDetailsServices)
|
||||
{
|
||||
_user = user;
|
||||
_userCheckInDetailsServices = userCheckInDetailsServices;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 用户签到
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> DoUserCheckIn([FromBody] FMDoUserCheckIn entity)
|
||||
{
|
||||
using (await _mutex.LockAsync())
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
var isHave = await _userCheckInDetailsServices.ExistsAsync(p => p.userId == _user.ID && p.checkInData == entity.date);
|
||||
if (isHave)
|
||||
{
|
||||
jm.msg = "今日您已签到";
|
||||
return jm;
|
||||
}
|
||||
var detail = new CoreCmsUserCheckInDetails
|
||||
{
|
||||
userId = _user.ID,
|
||||
checkInData = entity.date,
|
||||
createTime = DateTime.Now
|
||||
};
|
||||
var callBack = await _userCheckInDetailsServices.DoCheckIn(detail);
|
||||
jm.status = callBack.code == 0;
|
||||
jm.msg = callBack.msg;
|
||||
jm.data = callBack.data;
|
||||
return jm;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户总签到次数
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetUserCheckCount()
|
||||
{
|
||||
var jm = new WebApiCallBack
|
||||
{
|
||||
status = true,
|
||||
data = await _userCheckInDetailsServices.GetCountAsync(p => p.userId == _user.ID),
|
||||
msg = "获取成功"
|
||||
};
|
||||
return jm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户按月签到数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<WebApiCallBack> GetUserCheckByMonth([FromBody] FMGetUserCheckInByMonth entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var dt = new DateTime(entity.year, entity.month, 1);
|
||||
|
||||
var min = dt.AddDays(-1);
|
||||
var max = dt.AddMonths(1);
|
||||
|
||||
var list = await _userCheckInDetailsServices.QueryListByClauseAsync(p => p.userId == _user.ID && p.checkInData > min && p.checkInData < max);
|
||||
|
||||
var stringArr = new List<string>();
|
||||
foreach (var item in list)
|
||||
{
|
||||
var stringStr = item.checkInData.ToString("yyyy-MM-dd");
|
||||
stringArr.Add(stringStr);
|
||||
}
|
||||
|
||||
jm.status = true;
|
||||
jm.data = stringArr;
|
||||
jm.msg = "获取成功";
|
||||
|
||||
return jm;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user