feat tickets
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
namespace Dlhis.Canteen.Tickets.Services;
|
||||
|
||||
public interface IBirthdayTicketService : ITicketService
|
||||
{
|
||||
|
||||
}
|
||||
24
Src/Dlhis.Canteen/Tickets/Services/ITicketService.cs
Normal file
24
Src/Dlhis.Canteen/Tickets/Services/ITicketService.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Dlhis.Canteen.Tickets.Request;
|
||||
using Dlhis.Canteen.Tickets.Response;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Canteen.Tickets.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 券
|
||||
/// </summary>
|
||||
public interface ITicketService : IScopeDependency
|
||||
{
|
||||
/// <summary>
|
||||
/// 分页数据
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task<Pagination<TicketPageResponse>> GetPageAsync(TicketPageRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 创建
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task CreateAsync();
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using System.Text;
|
||||
using Dlhis.Constants;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.Entity;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Canteen.Tickets.Services.Implements;
|
||||
|
||||
[Service(nameof(TicketEnumType.Birthday))]
|
||||
public class BirthdayTicketService : BaseTicketService, IBirthdayTicketService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public BirthdayTicketService(IDbContext dbContext) : base(dbContext)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override async Task CreateAsync()
|
||||
{
|
||||
await DbContext.IgnoreAsync<ITenantId>(async () =>
|
||||
{
|
||||
var today = DateTime.Today;
|
||||
var userCodes = await DbContext.Queryable<GainfoEntity>()
|
||||
.Where(x => SqlFunc.DateIsSame(SqlFunc.ToDate(x.Birthday), today, DateType.Day))
|
||||
.Select(x => new { x.Code, x.Factory })
|
||||
.ToListAsync();
|
||||
|
||||
const decimal amount = 30;
|
||||
var todayStr = today.ToString("yyyy-MM-dd");
|
||||
foreach (var item in userCodes)
|
||||
{
|
||||
var qrCode = GetQrCode(item.Code + todayStr);
|
||||
if (!await DbContext.Queryable<TicketEntity>().Where(x => x.Type == TicketEnumType.Birthday && x.UserCode == item.Code && x.QrCode == qrCode).AnyAsync())
|
||||
{
|
||||
await DbContext.InsertAsync(new TicketEntity
|
||||
{
|
||||
Type = TicketEnumType.Birthday,
|
||||
UserCode = item.Code,
|
||||
OriginalAmount = amount,
|
||||
Amount = amount,
|
||||
QrCode = qrCode,
|
||||
Remark = todayStr + "生日券",
|
||||
TenantId = item.Factory
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static string GetQrCode(string data)
|
||||
{
|
||||
var qrCode = QrCodeConstants.Birthday + data.ToArray().Select(x =>
|
||||
{
|
||||
var b = Encoding.ASCII.GetBytes(x.ToString());
|
||||
int i = b[0];
|
||||
return Convert.ToString(i);
|
||||
}).Join(string.Empty);
|
||||
|
||||
return qrCode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Dlhis.Canteen.Tickets.Request;
|
||||
using Dlhis.Canteen.Tickets.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.Canteen.Tickets.Services.Implements;
|
||||
|
||||
public abstract class BaseTicketService : ITicketService
|
||||
{
|
||||
protected IDbContext DbContext { get; set; }
|
||||
|
||||
protected BaseTicketService(IDbContext dbContext)
|
||||
{
|
||||
DbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task<Pagination<TicketPageResponse>> GetPageAsync(TicketPageRequest request)
|
||||
{
|
||||
return await DbContext.Queryable<TicketEntity>()
|
||||
.LeftJoin<GainfoEntity>((x, ga) => x.UserCode == ga.Code)
|
||||
.Where(x => x.Type == request.Type)
|
||||
.WhereIF(request.UserCode.IsPresent(), x => x.UserCode == request.UserCode)
|
||||
.Select((x, ga) => new TicketPageResponse { UserName = ga.Name }, true)
|
||||
.ToPageListAsync(request);
|
||||
}
|
||||
|
||||
public abstract Task CreateAsync();
|
||||
}
|
||||
Reference in New Issue
Block a user