feat 生日券功能,自动上传消费数据,提醒访客到期

This commit is contained in:
2025-12-09 11:35:05 +08:00
parent 323eb367d0
commit c1462a03dc
60 changed files with 1451 additions and 409 deletions

View File

@@ -76,87 +76,6 @@ public class AssignmentsController : ControllerBase
await _assignmentService.UpdateDeviceTaskStatusAsync(requests);
}
[AllowAnonymous]
[HttpPost("balance/calc/{month:int}")]
[IgnoreTenant]
public async Task Calc([FromRoute] int month)
{
if (month is < 1 or > 12)
{
throw new UserFriendlyException("月份错误");
}
var s = new DateTime(2025, month, 1);
var e = new DateTime(2025, month + 1, 1);
var userCodes = await _dbContext.Queryable<UserBalanceEntity>()
.Where(x => SqlFunc.Subqueryable<UserBalanceTmpEntity>().Where(p => p.UserCode == x.UserCode).NotAny())
.Select(x => x.UserCode)
.Distinct()
.ToListAsync();
foreach (var userCode in userCodes)
{
if (!await _dbContext.Queryable<UserBalanceTmpEntity>().Where(x => x.UserCode == userCode).AnyAsync())
{
await _dbContext.InsertAsync(new UserBalanceTmpEntity
{
UserCode = userCode,
Balance = 0,
Version = 0
});
}
var balance = await _dbContext.Queryable<BalanceRecordEntity>()
.Where(x => x.UserCode == userCode)
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
.Where(x => x.Type == BalanceRecordTypeEnumType.Out)
.Where(x => x.CostDate >= s && x.CostDate < e)
.Where(x => !BalanceRecordSourceConstants.IgnoreSources.Contains(x.Source))
.SumAsync(x => x.Amount);
await _dbContext.Updateable<UserBalanceTmpEntity>()
.SetColumns(x => x.Balance == balance)
.SetColumns(x => x.ModifiedTime == DateTime.Now)
.Where(x => x.UserCode == userCode)
.ExecuteCommandAsync();
}
//
// var userCodes = await _dbContext.Queryable<GainfoLeaveEntity>().Where(x => x.ResignationDate.HasValue && x.ResignationDate >= s && x.ResignationDate <= e)
// .Where(x => x.Type != GainfoUserTypeEnumType.External && x.Type != GainfoUserTypeEnumType.Outsource)
// .Select(x => x.Code)
// .Distinct()
// .ToListAsync();
//
// foreach (var userCode in userCodes)
// {
// if (!await _dbContext.Queryable<UserBalanceTmpEntity>().Where(x => x.UserCode == userCode).AnyAsync())
// {
// await _dbContext.InsertAsync(new UserBalanceTmpEntity
// {
// UserCode = userCode,
// Balance = 0,
// Version = 0
// });
// }
//
// var balance = await _dbContext.Queryable<BalanceRecordEntity>()
// .Where(x => x.UserCode == userCode)
// .Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
// .Where(x => !BalanceRecordSourceConstants.IgnoreSources.Contains(x.Source))
// .Where(x => x.CostDate >= s && x.CostDate <= e)
// .Where(x => x.Type == BalanceRecordTypeEnumType.In)
// .SumAsync(x => x.Amount);
//
// await _dbContext.Updateable<UserBalanceTmpEntity>()
// .SetColumns(x => x.Balance == balance)
// .SetColumns(x => x.ModifiedTime == DateTime.Now)
// .Where(x => x.UserCode == userCode)
// .ExecuteCommandAsync();
// }
}
[Obsolete]
[AllowAnonymous]
[IgnoreTenant]