feat tickets

This commit is contained in:
2025-02-11 16:33:21 +08:00
parent c9df417799
commit 964e033583
33 changed files with 473 additions and 28 deletions

View File

@@ -22,6 +22,7 @@
<ItemGroup>
<ProjectReference Include="..\Dlhis.Basic.Api\Dlhis.Basic.Api.csproj" />
<ProjectReference Include="..\Dlhis.Constants\Dlhis.Constants.csproj" />
<ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" />
<ProjectReference Include="..\Dlhis.Sys.Api\Dlhis.Sys.Api.csproj" />
</ItemGroup>

View File

@@ -3,6 +3,7 @@ using Dlhis.Canteen.EMealVoucher.Request;
using Dlhis.Canteen.EMealVoucher.Response;
using Dlhis.Canteen.Order.Request;
using Dlhis.Canteen.Order.Response;
using Dlhis.Constants;
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Canteen.Entities;
using Dlhis.Entity.Canteen.Enums;
@@ -65,7 +66,7 @@ public class EMealVoucherService : IEMealVoucherService
public async Task<Pagination<EMealVoucherMyPageResponse>> GetMyEMealVoucherPageAsync(EMealVoucherPageRequest request)
{
var code = _currentUser.GetUserClaim("jinko-code");
var code = _currentUser.GetUserClaim(UserClaimConstants.JinkoCode);
return await _dbContext.Queryable<EMealVoucherEntity>()
.Where(x => x.Code == code)
@@ -126,7 +127,7 @@ public class EMealVoucherService : IEMealVoucherService
var ts = DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString().Reverse().Join(string.Empty);
var originData = string.Concat(eMealVoucher.No, ":", ts, ":", eMealVoucher.Code, ":", eMealVoucherDetail.IdNo);
var qrCode = "02" + originData.ToArray().Select(x =>
var qrCode = QrCodeConstants.EMealVoucher + originData.ToArray().Select(x =>
{
var b = Encoding.ASCII.GetBytes(x.ToString());
int i = b[0];

View File

@@ -1,5 +1,6 @@
using Dlhis.Canteen.MealSupplementRecord.Request;
using Dlhis.Canteen.MealSupplementRecord.Response;
using Dlhis.Constants;
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Canteen.Entities;
using Dlhis.Entity.Canteen.Enums;
@@ -93,7 +94,7 @@ public class MealSupplementRecordService : IMealSupplementRecordService
public async Task<MealSupplementRecordMyResponse> GetMyMealSupplementRecords(MealSupplementRecordMyRequest request)
{
var code = _currentUser.GetUserClaim("jinko-code") ?? string.Empty;
var code = _currentUser.GetUserClaim(UserClaimConstants.JinkoCode) ?? string.Empty;
var data = await _dbContext.Queryable<BalanceRecordEntity>()
.Where(x => x.CostDateTime >= request.SearchDateTimePeriod.Start && x.CostDateTime <= request.SearchDateTimePeriod.End)

View File

@@ -3,6 +3,7 @@ using Dlhis.Canteen.Order.Repository;
using Dlhis.Canteen.Order.Request;
using Dlhis.Canteen.Order.Response;
using Dlhis.Canteen.Setting.Services;
using Dlhis.Constants;
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Canteen.Entities;
using Dlhis.Entity.Canteen.Enums;
@@ -334,7 +335,7 @@ public class BalanceService : IBalanceService
public async Task<BalanceRecordUserResultResponse> GetPageByUserAsync(BalanceRecordUserPageRequest request)
{
var userCode = _currentUser.GetUserClaim("jinko-code") ?? string.Empty;
var userCode = _currentUser.GetUserClaim(UserClaimConstants.JinkoCode) ?? string.Empty;
var factory = await _dbContext.Queryable<WalletEntity>().Where(x => x.Code == request.WalletCode).Select(x => x.Factory).FirstAsync();
var factories = await _balanceRepository.GetWalletFactoriesAsync(factory);

View File

@@ -21,6 +21,7 @@ using Kurisu.AspNetCore.DataAccess.Dto;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
using Kurisu.AspNetCore.UnifyResultAndValidation;
using Dlhis.Constants;
namespace Dlhis.Canteen.Order.Services.Implements;
@@ -88,7 +89,7 @@ public class OrderService : IOrderService
{
var subjectId = _currentUser.GetIntSubjectId();
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.IdentityUserId == subjectId).FirstAsync();
var jinkoCode = _currentUser.GetUserClaim("jinko-code") ?? string.Empty;
var jinkoCode = _currentUser.GetUserClaim(UserClaimConstants.JinkoCode) ?? string.Empty;
if (jinkoCode.IsPresent())
{
gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == jinkoCode).SingleAsync();
@@ -153,12 +154,12 @@ public class OrderService : IOrderService
if (request.Source == BalanceRecordSourceEnumType.QrCode)
{
if (request.UserUniqueNo.StartsWith("01"))
if (request.UserUniqueNo.StartsWith(QrCodeConstants.User))
{
gainfo = await GetUserByQrCodeAsync(request.UserUniqueNo);
await CheckPermissionAsync(gainfo.Code, request.DeviceUniqueNo);
}
else if (request.UserUniqueNo.StartsWith("02"))
else if (request.UserUniqueNo.StartsWith(QrCodeConstants.EMealVoucher))
{
request.Source = BalanceRecordSourceEnumType.EMealVoucher;
var eMealVoucherQrCode = await _dbContext.Queryable<EMealVoucherDetailQrCodeEntity>().Where(x => x.QrCode == request.UserUniqueNo).SingleAsync();
@@ -166,6 +167,12 @@ public class OrderService : IOrderService
var code = eMealVoucherQrCode.OriginData.Split(':')[2];
gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == code).SingleAsync();
}
else if (request.UserUniqueNo.StartsWith(QrCodeConstants.Birthday))
{
var ticket = await _dbContext.Queryable<TicketEntity>().Where(x => x.Type == TicketEnumType.Birthday).Where(x => x.QrCode == request.UserUniqueNo).SingleAsync();
ticket.ThrowIfNull("无法识别");
gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == ticket.UserCode).SingleAsync();
}
else
{
throw new UserFriendlyException($"无法识别{request.UserUniqueNo}");

View File

@@ -1,5 +1,6 @@
using Dlhis.Canteen.Order.Repository;
using Dlhis.Canteen.Setting.Response;
using Dlhis.Constants;
using Dlhis.Entity.Canteen.Entities;
using Kurisu.AspNetCore.Authentication.Abstractions;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
@@ -37,7 +38,7 @@ public class WalletService : IWalletService
/// <inheritdoc />
public async Task<decimal> GetBalanceAsync(string walletCode)
{
var userCode = _currentUser.GetUserClaim("jinko-code");
var userCode = _currentUser.GetUserClaim(UserClaimConstants.JinkoCode);
if (!await _dbContext.Queryable<UserBalanceEntity>().Where(x => x.UserCode == userCode).AnyAsync())
{

View File

@@ -0,0 +1,50 @@
using Dlhis.Canteen.Tickets.Request;
using Dlhis.Canteen.Tickets.Response;
using Dlhis.Canteen.Tickets.Services;
using Kurisu.AspNetCore.DataAccess.Dto;
using Kurisu.AspNetCore.Utils.Extensions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Dlhis.Canteen.Tickets.Controllers;
/// <summary>
/// 券
/// </summary>
[Authorize]
[Route("api/[controller]")]
[ApiController]
public class TicketsController : ControllerBase
{
private readonly INamedResolver _namedResolver;
public TicketsController(INamedResolver namedResolver)
{
_namedResolver = namedResolver;
}
/// <summary>
/// 获取分页数据(按券类型)
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpGet("page")]
public async Task<Pagination<TicketPageResponse>> GetPageAsync(TicketPageRequest request)
{
return await _namedResolver.GetService<ITicketService>(request.Type.ToString()).GetPageAsync(request);
}
/// <summary>
/// 创建券
/// </summary>
/// <param name="type">券类型,需要后端支持</param>
[AllowAnonymous]
[HttpPost("{type:required}/create")]
public async Task CreateAsync(string type)
{
var srv = _namedResolver.GetService<ITicketService>(type);
srv.ThrowIfNull("不支持的券类型");
await srv.CreateAsync();
}
}

View File

@@ -0,0 +1,19 @@
using System.ComponentModel.DataAnnotations;
using Dlhis.Entity.Canteen.Enums;
using Kurisu.AspNetCore.DataAccess.Dto;
namespace Dlhis.Canteen.Tickets.Request;
public class TicketPageRequest : PageDto
{
/// <summary>
/// 类型
/// </summary>
[EnumDataType(typeof(TicketEnumType))]
public TicketEnumType Type { get; set; }
/// <summary>
/// 工号
/// </summary>
public string UserCode { get; set; }
}

View File

@@ -0,0 +1,41 @@
using Dlhis.Entity.Canteen.Enums;
namespace Dlhis.Canteen.Tickets.Response;
public class TicketPageResponse
{
/// <summary>
/// 券类型
/// </summary>
public TicketEnumType Type { get; set; }
/// <summary>
/// 工号
/// </summary>
public string UserCode { get; set; }
/// <summary>
/// 用户名称
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 初始余额
/// </summary>
public decimal OriginalAmount { get; set; }
/// <summary>
/// 当前余额
/// </summary>
public decimal Amount { get; set; }
/// <summary>
/// 消费码
/// </summary>
public string QrCode { get; set; }
/// <summary>
/// 备注
/// </summary>
public string Remark { get; set; }
}

View File

@@ -0,0 +1,6 @@
namespace Dlhis.Canteen.Tickets.Services;
public interface IBirthdayTicketService : ITicketService
{
}

View 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();
}

View File

@@ -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;
}
}

View File

@@ -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();
}