Merge branch 'feat-wallet' into development
This commit is contained in:
@@ -187,37 +187,6 @@ public class MealSupplementRecordService : IMealSupplementRecordService
|
||||
DepartmentNo = gainfo.DepartmentNo,
|
||||
DeviceUniqueNo = null
|
||||
});
|
||||
|
||||
await CommonHelper.RetryAsync(async () =>
|
||||
{
|
||||
var mealUser = await _dbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == request.Code).FirstAsync();
|
||||
if (mealUser == null)
|
||||
{
|
||||
mealUser = new GainfoMealEntity
|
||||
{
|
||||
UserCode = gainfo.Code,
|
||||
Balance = 0,
|
||||
BalanceOfRecharge = 0,
|
||||
BalanceOfSubsidies = 0,
|
||||
Version = 0
|
||||
};
|
||||
|
||||
await _dbContext.InsertAsync(mealUser);
|
||||
}
|
||||
|
||||
//重新核算
|
||||
var balance = await _dbContext.Queryable<BalanceRecordEntity>()
|
||||
.Where(x => x.UserCode == request.Code)
|
||||
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
|
||||
.SumAsync(x => x.Amount);
|
||||
|
||||
await _dbContext.Updateable<GainfoMealEntity>()
|
||||
.SetColumns(x => x.Version == x.Version + 1)
|
||||
.SetColumns(x => x.Balance == balance)
|
||||
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||
.Where(x => x.UserCode == mealUser.UserCode && x.Version == mealUser.Version)
|
||||
.ExecuteCommandThrowVersionAsync();
|
||||
}, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,11 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data;
|
||||
using System.Data;
|
||||
using Dlhis.Canteen.Order.Request;
|
||||
using Dlhis.Canteen.Order.Response;
|
||||
using Dlhis.Canteen.Order.Services;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using Kurisu.AspNetCore;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Canteen.Order.Controllers;
|
||||
|
||||
@@ -167,36 +162,4 @@ public class BalancesController : ControllerBase
|
||||
{
|
||||
await _balanceService.ManuallyImportBalanceAndReCalcAsync(requests);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重算
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
[Authorize(Roles = "admin")]
|
||||
[HttpPost("recalc")]
|
||||
[IgnoreTenant]
|
||||
[Transactional(IsolationLevel.ReadCommitted)]
|
||||
public async Task ReCalcAsync(BalanceReCalcRequest request)
|
||||
{
|
||||
await _balanceService.ReCalcAsync(request.UserCode);
|
||||
}
|
||||
|
||||
[HttpPost("recalc1")]
|
||||
[Transactional(IsolationLevel.ReadCommitted)]
|
||||
[IgnoreTenant]
|
||||
public async Task ReC5()
|
||||
{
|
||||
var sp = App.GetServiceProvider();
|
||||
var db = sp.GetService<IDbContext>();
|
||||
var middleService = sp.GetService<IMiddleService>();
|
||||
var others = await db.Queryable<BalanceRecordEntity>().AS("LocalBalanceRecordEntity")
|
||||
.Where(x => SqlFunc.Subqueryable<BalanceRecordEntity>().Where(p => p.No == x.No).NotAny())
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var item in others)
|
||||
{
|
||||
await middleService.MiddleUploadAsync(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using Dlhis.Canteen.Dishes.Request;
|
||||
using Dlhis.Canteen.Order.Request;
|
||||
using Dlhis.Canteen.Order.Request;
|
||||
using Dlhis.Canteen.Order.Response;
|
||||
using Dlhis.Canteen.Order.Services;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
@@ -19,12 +18,10 @@ namespace Dlhis.Canteen.Order.Controllers;
|
||||
public class OrdersController : ControllerBase
|
||||
{
|
||||
private readonly IOrderService _orderService;
|
||||
private readonly IBookingOrderService _bookingOrderService;
|
||||
|
||||
public OrdersController(IOrderService orderService, IBookingOrderService bookingOrderService)
|
||||
public OrdersController(IOrderService orderService)
|
||||
{
|
||||
_orderService = orderService;
|
||||
_bookingOrderService = bookingOrderService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -37,8 +34,7 @@ public class OrdersController : ControllerBase
|
||||
[IgnoreTenant]
|
||||
public async Task<DefaultApiResult<OrderResultResponse>> AddAsync(OrderAddRequest request)
|
||||
{
|
||||
var result = await _orderService.AddAsync(request);
|
||||
return result.Response;
|
||||
return await _orderService.AddAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -51,8 +47,7 @@ public class OrdersController : ControllerBase
|
||||
[IgnoreTenant]
|
||||
public async Task<DefaultApiResult<OrderResultResponse>> DeviceConsume(OrderAddRequest request)
|
||||
{
|
||||
var result = await _orderService.AddAsync(request);
|
||||
return result.Response;
|
||||
return await _orderService.AddAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -66,56 +61,56 @@ public class OrdersController : ControllerBase
|
||||
return await _orderService.GetOrdersAggregationAsync(page);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消订单
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("user-cancel")]
|
||||
[Transactional]
|
||||
[IgnoreTenant]
|
||||
public async Task CancelOrderAsync(OrderCancelRequest request)
|
||||
{
|
||||
await _bookingOrderService.UserCancelOrderAsync(request);
|
||||
}
|
||||
// /// <summary>
|
||||
// /// 取消订单
|
||||
// /// </summary>
|
||||
// /// <param name="request"></param>
|
||||
// /// <returns></returns>
|
||||
// [HttpPut("user-cancel")]
|
||||
// [Transactional]
|
||||
// [IgnoreTenant]
|
||||
// public async Task CancelOrderAsync(OrderCancelRequest request)
|
||||
// {
|
||||
// await _bookingOrderService.UserCancelOrderAsync(request);
|
||||
// }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 取消订单
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("manager-cancel")]
|
||||
[Transactional]
|
||||
[IgnoreTenant]
|
||||
public async Task ManagerCancelOrderAsync(OrderCancelRequest request)
|
||||
{
|
||||
await _bookingOrderService.ManagerCancelOrderAsync(request);
|
||||
}
|
||||
|
||||
//************************************************************** 订餐功能 **********************************************************************************
|
||||
|
||||
/// <summary>
|
||||
/// 取消订单
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("booking")]
|
||||
[Transactional]
|
||||
[IgnoreTenant]
|
||||
public async Task<BookingResponse> Booking(BookingMealRequest request)
|
||||
{
|
||||
return await _bookingOrderService.BookingAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 订单分页
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("booking/page")]
|
||||
public async Task<Pagination<OrderBookingResponse>> GetBookingPageAsync([FromQuery] OrderBookingPageRequest request)
|
||||
{
|
||||
return await _bookingOrderService.GetBookingPageAsync(request);
|
||||
}
|
||||
//
|
||||
// /// <summary>
|
||||
// /// 取消订单
|
||||
// /// </summary>
|
||||
// /// <param name="request"></param>
|
||||
// /// <returns></returns>
|
||||
// [HttpPut("manager-cancel")]
|
||||
// [Transactional]
|
||||
// [IgnoreTenant]
|
||||
// public async Task ManagerCancelOrderAsync(OrderCancelRequest request)
|
||||
// {
|
||||
// await _bookingOrderService.ManagerCancelOrderAsync(request);
|
||||
// }
|
||||
//
|
||||
// //************************************************************** 订餐功能 **********************************************************************************
|
||||
//
|
||||
// /// <summary>
|
||||
// /// 取消订单
|
||||
// /// </summary>
|
||||
// /// <param name="request"></param>
|
||||
// /// <returns></returns>
|
||||
// [HttpPost("booking")]
|
||||
// [Transactional]
|
||||
// [IgnoreTenant]
|
||||
// public async Task<BookingResponse> Booking(BookingMealRequest request)
|
||||
// {
|
||||
// return await _bookingOrderService.BookingAsync(request);
|
||||
// }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// 订单分页
|
||||
// /// </summary>
|
||||
// /// <param name="request"></param>
|
||||
// /// <returns></returns>
|
||||
// [HttpGet("booking/page")]
|
||||
// public async Task<Pagination<OrderBookingResponse>> GetBookingPageAsync([FromQuery] OrderBookingPageRequest request)
|
||||
// {
|
||||
// return await _bookingOrderService.GetBookingPageAsync(request);
|
||||
// }
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
|
||||
namespace Dlhis.Canteen.Order.Dto
|
||||
namespace Dlhis.Canteen.Order.Dto;
|
||||
|
||||
public class OrderPreCheckDto
|
||||
{
|
||||
public class OrderPreCheckDto
|
||||
{
|
||||
public DateTime CostDate { get; set; }
|
||||
public BusinessShiftMealRelationshipEntity Shift { get; set; }
|
||||
public string Factory { get; set; }
|
||||
|
||||
public string BusinessPlaceTenantId { get; set; }
|
||||
public DateTime CostDate { get; set; }
|
||||
|
||||
public Guid BusinessPlaceCode { get; set; }
|
||||
public ShiftEnumType ShiftType { get; set; }
|
||||
|
||||
public Guid BusinessShiftCode { get; set; }
|
||||
}
|
||||
public Guid BusinessPlaceCode { get; set; }
|
||||
|
||||
public Guid BusinessShiftCode { get; set; }
|
||||
}
|
||||
40
Src/Dlhis.Canteen/Order/Repository/IBalanceRepository.cs
Normal file
40
Src/Dlhis.Canteen/Order/Repository/IBalanceRepository.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
|
||||
namespace Dlhis.Canteen.Order.Repository;
|
||||
|
||||
public interface IBalanceRepository : IScopeDependency
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取余额
|
||||
/// </summary>
|
||||
/// <param name="userCode"></param>
|
||||
/// <param name="factory"></param>
|
||||
/// <returns></returns>
|
||||
Task<decimal> GetBalanceAsync(string userCode, string factory);
|
||||
|
||||
/// <summary>
|
||||
/// 获取消费明细
|
||||
/// </summary>
|
||||
/// <param name="userCode"></param>
|
||||
/// <param name="factory"></param>
|
||||
/// <param name="startTime"></param>
|
||||
/// <param name="endTime"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<BalanceRecordEntity>> GetBalanceRecordsAsync(string userCode, string factory, DateTime startTime, DateTime endTime);
|
||||
|
||||
/// <summary>
|
||||
/// 获取钱包厂区
|
||||
/// </summary>
|
||||
/// <param name="factory"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<string>> GetWalletFactoriesAsync(string factory);
|
||||
|
||||
/// <summary>
|
||||
/// 检测余额是否足够
|
||||
/// </summary>
|
||||
/// <param name="userCode"></param>
|
||||
/// <param name="factory"></param>
|
||||
/// <param name="cost"></param>
|
||||
/// <returns></returns>
|
||||
Task CheckConsumableAsync(string userCode, string factory, decimal cost);
|
||||
}
|
||||
11
Src/Dlhis.Canteen/Order/Repository/IOrderRepository.cs
Normal file
11
Src/Dlhis.Canteen/Order/Repository/IOrderRepository.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Dlhis.Canteen.Order.Dto;
|
||||
using Dlhis.Canteen.Order.Request;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
|
||||
namespace Dlhis.Canteen.Order.Repository;
|
||||
|
||||
public interface IOrderRepository : IScopeDependency
|
||||
{
|
||||
Task<CanteenOrderEntity> CreateDeviceConsumeOrderAsync(OrderPreCheckDto checkData, ConsumeRequest request, GainfoEntity gainfo);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.Canteen.Order.Repository.Implements;
|
||||
|
||||
public class BalanceRepository : IBalanceRepository
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public BalanceRepository(IDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task<decimal> GetBalanceAsync(string userCode, string factory)
|
||||
{
|
||||
var queryable = _dbContext.Queryable<BalanceRecordEntity>()
|
||||
.Where(x => x.UserCode == userCode && x.Status == BalanceRecordStatusEnumType.Valid)
|
||||
.Where(x => x.Source != BalanceRecordSourceEnumType.EMealVoucher);
|
||||
|
||||
if (!factory.IsPresent())
|
||||
{
|
||||
return await queryable.SumAsync(x => x.Amount);
|
||||
}
|
||||
|
||||
var factories = await GetWalletFactoriesAsync(factory);
|
||||
return await queryable.Where(x => factories.Contains(x.TenantId)).SumAsync(x => x.Amount);
|
||||
}
|
||||
|
||||
public async Task<List<BalanceRecordEntity>> GetBalanceRecordsAsync(string userCode, string factory, DateTime startTime, DateTime endTime)
|
||||
{
|
||||
var factories = await GetWalletFactoriesAsync(factory);
|
||||
|
||||
return await _dbContext.Queryable<BalanceRecordEntity>()
|
||||
.Where(x => x.UserCode == userCode)
|
||||
.Where(x => factories.Contains(x.TenantId))
|
||||
.Where(x => x.Type == BalanceRecordTypeEnumType.Out)
|
||||
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
|
||||
.Where(x => x.CostDateTime >= startTime && x.CostDateTime <= endTime)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<string>> GetWalletFactoriesAsync(string factory)
|
||||
{
|
||||
var wallets = await _dbContext.Queryable<WalletEntity>().ToListAsync();
|
||||
var code = wallets.First(x => x.Factory == factory).Code;
|
||||
|
||||
return wallets.Where(x => x.Code == code).Select(x => x.Factory).ToList();
|
||||
}
|
||||
|
||||
|
||||
public async Task CheckConsumableAsync(string userCode, string factory, decimal cost)
|
||||
{
|
||||
var balance = await GetBalanceAsync(userCode, factory);
|
||||
var isEnough = balance - Math.Abs(cost) >= 0;
|
||||
isEnough.ThrowIfFalse($"钱包余额不足({balance}元)");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using Dlhis.Canteen.Order.Dto;
|
||||
using Dlhis.Canteen.Order.Request;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.Canteen.Order.Repository.Implements;
|
||||
|
||||
public class OrderRepository : IOrderRepository
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public OrderRepository(IDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<CanteenOrderEntity> CreateDeviceConsumeOrderAsync(OrderPreCheckDto checkData, ConsumeRequest request, GainfoEntity gainfo)
|
||||
{
|
||||
var order = new CanteenOrderEntity
|
||||
{
|
||||
RequestJson = request.ToJson(),
|
||||
IsOffline = request.IsOffline,
|
||||
No = SnowFlakeHelper.Instance.NextId().ToString(),
|
||||
ThirdNo = request.ThirdNo,
|
||||
Type = BalanceRecordTypeEnumType.Out,
|
||||
ApplicationType = CanteenApplicationTypeEnumType.Device,
|
||||
Name = gainfo.Name,
|
||||
Source = request.Source,
|
||||
UserNo = gainfo.No,
|
||||
UserCode = gainfo.Code,
|
||||
Amount = request.Amount,
|
||||
BusinessPlaceCode = checkData.BusinessPlaceCode,
|
||||
BusinessShiftCode = checkData.BusinessShiftCode,
|
||||
ShiftType = checkData.ShiftType,
|
||||
CostDate = checkData.CostDate,
|
||||
CostDateTime = request.CostDateTime,
|
||||
CostId = gainfo.CostId,
|
||||
DepartmentNo = gainfo.DepartmentNo,
|
||||
DeviceUniqueNo = request.DeviceUniqueNo,
|
||||
|
||||
Remark = null,
|
||||
DeliveryAddress = null,
|
||||
Result = null,
|
||||
IP = null,
|
||||
|
||||
IsCostCrossTenant = gainfo.Factory != checkData.Factory,
|
||||
|
||||
Werks = gainfo.Werks,
|
||||
OriginTenantId = gainfo.Factory,
|
||||
//标识当前消费的基地
|
||||
TenantId = checkData.Factory,
|
||||
|
||||
Status = BalanceRecordStatusEnumType.Valid,
|
||||
OrderStatus = CanteenOrderStatusEnumType.Wait,
|
||||
|
||||
IsDeleted = false,
|
||||
};
|
||||
|
||||
var orderId = await _dbContext.InsertReturnIdentityAsync(order);
|
||||
order.Id = orderId;
|
||||
return order;
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,11 @@ public class BalanceRecordUserPageRequest : PageDto, IValidatableObject
|
||||
/// </summary>
|
||||
public DateTimePeriod SearchDateTimePeriod { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 钱包code
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "请选择钱包")]
|
||||
public string WalletCode { get; set; }
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
@@ -27,4 +32,4 @@ public class BalanceRecordUserPageRequest : PageDto, IValidatableObject
|
||||
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,4 +32,13 @@ public class OrderResultResponse
|
||||
/// 余额
|
||||
/// </summary>
|
||||
public string Balance => CurrentBalance.ToString("f2");
|
||||
}
|
||||
|
||||
|
||||
[JsonIgnore]
|
||||
public decimal CurrentTotalBalance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总余额
|
||||
/// </summary>
|
||||
public string TotalBalance => CurrentTotalBalance.ToString("f2");
|
||||
}
|
||||
@@ -1,16 +1,12 @@
|
||||
using Dlhis.Canteen.Setting.Services;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Mapster;
|
||||
|
||||
namespace Dlhis.Canteen.Order.Services;
|
||||
|
||||
public abstract class BaseOrderService
|
||||
{
|
||||
private readonly ICanteenSettingService _canteenSettingService;
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly ILogger _logger;
|
||||
@@ -21,7 +17,6 @@ public abstract class BaseOrderService
|
||||
ICurrentUser currentUser,
|
||||
ILogger logger)
|
||||
{
|
||||
_canteenSettingService = canteenSettingService;
|
||||
_dbContext = dbContext;
|
||||
_currentUser = currentUser;
|
||||
_logger = logger;
|
||||
@@ -32,37 +27,4 @@ public abstract class BaseOrderService
|
||||
protected IDbContext DbContext => _dbContext;
|
||||
|
||||
protected ICurrentUser CurrentUser => _currentUser;
|
||||
|
||||
/// <summary>
|
||||
/// 获取参数配置
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="userNo"></param>
|
||||
/// <param name="tenantId"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="defaultValue"></param>
|
||||
/// <returns></returns>
|
||||
protected async Task<T> GetSettingAsync<T>(string userNo, string tenantId, CanteenSettingItemEnumType item, T defaultValue = default)
|
||||
{
|
||||
_settings ??= await _canteenSettingService.GetUserSettingAsync(userNo, tenantId);
|
||||
|
||||
if (_settings.TryGetValue(item, out var v))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (int.TryParse(v, out var n))
|
||||
{
|
||||
return n.Adapt<T>();
|
||||
}
|
||||
|
||||
return v.Adapt<T>();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ public interface IBalanceService : IScopeDependency
|
||||
|
||||
|
||||
Task<Pagination<BalanceRecordResponse>> GetUserBalanceGroupAsync(BalanceRecordUserGroupPageRequest request);
|
||||
|
||||
|
||||
|
||||
Task SupplementBalanceAsync(BalanceSupplementRequest request);
|
||||
|
||||
@@ -40,6 +40,4 @@ public interface IBalanceService : IScopeDependency
|
||||
|
||||
|
||||
Task ManuallyImportBalanceAndReCalcAsync(List<BalanceManuallyImportRequest> requests);
|
||||
|
||||
Task ReCalcAsync(string userCode);
|
||||
}
|
||||
@@ -1,19 +1,20 @@
|
||||
using Dlhis.Canteen.Order.Request;
|
||||
using Dlhis.Canteen.Order.Response;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
||||
|
||||
namespace Dlhis.Canteen.Order.Services;
|
||||
|
||||
public interface IOrderService : IScopeDependency
|
||||
{
|
||||
Task<OrderResultResponseWithLogs> AddAsync(OrderAddRequest request);
|
||||
Task<DefaultApiResult<OrderResultResponse>> AddAsync(OrderAddRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 设备消费
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task<OrderResultResponseWithLogs> DeviceConsume(OrderAddRequest request);
|
||||
Task<DefaultApiResult<OrderResultResponse>> DeviceConsume(OrderAddRequest request);
|
||||
|
||||
Task<Pagination<OrderAggregationResponse>> GetOrdersAggregationAsync(PageDto page);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Dlhis.Basic.Api;
|
||||
using Dlhis.Canteen.Order.Repository;
|
||||
using Dlhis.Canteen.Order.Request;
|
||||
using Dlhis.Canteen.Order.Response;
|
||||
using Dlhis.Canteen.Setting.Services;
|
||||
@@ -29,6 +30,7 @@ public class BalanceService : IBalanceService
|
||||
private readonly ITenantApi _tenantApi;
|
||||
private readonly ICanteenSettingService _canteenSettingService;
|
||||
private readonly RedisCache _redisCache;
|
||||
private readonly IBalanceRepository _balanceRepository;
|
||||
private readonly IBusinessPlacePermissionsApi _businessPlacePermissionsApi;
|
||||
|
||||
public BalanceService(IDbContext dbContext,
|
||||
@@ -36,6 +38,7 @@ public class BalanceService : IBalanceService
|
||||
ITenantApi tenantApi,
|
||||
ICanteenSettingService canteenSettingService,
|
||||
RedisCache redisCache,
|
||||
IBalanceRepository balanceRepository,
|
||||
IBusinessPlacePermissionsApi businessPlacePermissionsApi)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
@@ -43,6 +46,7 @@ public class BalanceService : IBalanceService
|
||||
_tenantApi = tenantApi;
|
||||
_canteenSettingService = canteenSettingService;
|
||||
_redisCache = redisCache;
|
||||
_balanceRepository = balanceRepository;
|
||||
_businessPlacePermissionsApi = businessPlacePermissionsApi;
|
||||
}
|
||||
|
||||
@@ -123,11 +127,7 @@ public class BalanceService : IBalanceService
|
||||
balanceRecord.Remark = "退款";
|
||||
await _dbContext.UpdateAsync(balanceRecord);
|
||||
|
||||
if (balanceRecord.Source is BalanceRecordSourceEnumType.Face or BalanceRecordSourceEnumType.QrCode)
|
||||
{
|
||||
await ReCalcAsync(balanceRecord.UserCode);
|
||||
}
|
||||
else if (balanceRecord.Source == BalanceRecordSourceEnumType.EMealVoucher)
|
||||
if (balanceRecord.Source == BalanceRecordSourceEnumType.EMealVoucher)
|
||||
{
|
||||
var originData = balanceRecord.UserNo.Split(":");
|
||||
var eNo = originData[0];
|
||||
@@ -324,39 +324,29 @@ public class BalanceService : IBalanceService
|
||||
await _dbContext.Client.Ado.RollbackTranAsync();
|
||||
throw;
|
||||
}
|
||||
|
||||
await CommonHelper.RetryAsync(async () =>
|
||||
{
|
||||
var gainfoMeal = await _dbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == balanceInfo.UserCode).SingleAsync();
|
||||
var balance = gainfoMeal.Balance + Math.Abs(balanceInfo.Amount) + request.Amount;
|
||||
|
||||
await _dbContext.Updateable<GainfoMealEntity>()
|
||||
.SetColumns(x => x.Balance == balance)
|
||||
.SetColumns(x => x.Version == x.Version + 1)
|
||||
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||
.Where(x => x.UserCode == balanceInfo.UserCode && x.Version == gainfoMeal.Version)
|
||||
.ExecuteCommandThrowVersionAsync();
|
||||
}, 10);
|
||||
}
|
||||
|
||||
public async Task<BalanceRecordUserResultResponse> GetPageByUserAsync(BalanceRecordUserPageRequest request)
|
||||
{
|
||||
var jinkoCode = _currentUser.GetUserClaim("jinko-code") ?? string.Empty;
|
||||
var userCode = _currentUser.GetUserClaim("jinko-code") ?? 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);
|
||||
|
||||
var page = await _dbContext.Queryable<BalanceRecordEntity>()
|
||||
.LeftJoin<GainfoEntity>((record, ga) => record.UserNo == ga.No)
|
||||
.LeftJoin<DepartmentEntity>((record, ga, department) => ga.DepartmentNo == department.No)
|
||||
.LeftJoin<BusinessPlaceEntity>((record, ga, department, bPlace) => record.BusinessPlaceCode == bPlace.Code)
|
||||
.Where((record, ga) => record.UserCode == jinkoCode)
|
||||
.Where(record => record.Type == BalanceRecordTypeEnumType.Out && (record.Status == BalanceRecordStatusEnumType.Valid || record.Status == BalanceRecordStatusEnumType.Obsolute))
|
||||
.Where(record => record.Source != BalanceRecordSourceEnumType.EMealVoucher)
|
||||
.Where((record, ga) => record.UserCode == userCode && factories.Contains(record.TenantId))
|
||||
.Where(record => record.Status == BalanceRecordStatusEnumType.Valid || record.Status == BalanceRecordStatusEnumType.Obsolute)
|
||||
.Where(record => record.Source != BalanceRecordSourceEnumType.EMealVoucher) //不展示电子餐券信息
|
||||
.WhereIF(request.SearchDateTimePeriod.HasValue(), record => record.CostDate >= request.SearchDateTimePeriod.Start && record.CostDate <= request.SearchDateTimePeriod.End)
|
||||
.WhereIF(request.ApplicationType.HasValue, record => record.ApplicationType == request.ApplicationType)
|
||||
.OrderBy(record => record.CostDateTime)
|
||||
.Select((record, ga, department, bPlace) => new BalanceRecordUserPageResponse
|
||||
{
|
||||
Id = record.Id,
|
||||
CurrentAmount = SqlFunc.Abs(record.Amount),
|
||||
CurrentAmount = record.Amount,
|
||||
Source = record.Source,
|
||||
Status = record.Status,
|
||||
No = SqlFunc.IIF(record.Status == BalanceRecordStatusEnumType.Obsolute, "(已退)" + record.No, record.No),
|
||||
@@ -372,11 +362,11 @@ public class BalanceService : IBalanceService
|
||||
var monthEnd = monthStart.AddMonths(1).AddSeconds(-1);
|
||||
|
||||
var monthSum = await _dbContext.Queryable<BalanceRecordEntity>()
|
||||
.Where(x => x.CostDateTime >= monthStart && x.CostDateTime <= monthEnd)
|
||||
.Where(x => x.Type == BalanceRecordTypeEnumType.Out && x.Status == BalanceRecordStatusEnumType.Valid)
|
||||
.Where(x => x.UserCode == userCode && factories.Contains(x.TenantId))
|
||||
.Where(x => x.CostDate >= monthStart && x.CostDate <= monthEnd)
|
||||
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
|
||||
.Where(x => x.Source != BalanceRecordSourceEnumType.EMealVoucher)
|
||||
.Where(x => x.UserCode == jinkoCode)
|
||||
.SumAsync(x => SqlFunc.Abs(x.Amount));
|
||||
.SumAsync(x => x.Amount);
|
||||
|
||||
return new BalanceRecordUserResultResponse
|
||||
{
|
||||
@@ -544,82 +534,10 @@ public class BalanceService : IBalanceService
|
||||
Werks = gainfo.Werks,
|
||||
IsDeleted = false
|
||||
});
|
||||
|
||||
await CommonHelper.RetryAsync(async () =>
|
||||
{
|
||||
var gainfoMeal = await _dbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == gainfo.Code).FirstAsync();
|
||||
if (gainfoMeal == null)
|
||||
{
|
||||
gainfoMeal = new GainfoMealEntity
|
||||
{
|
||||
UserCode = gainfo.Code,
|
||||
Balance = 0,
|
||||
BalanceOfRecharge = 0,
|
||||
BalanceOfSubsidies = 0,
|
||||
Version = 0
|
||||
};
|
||||
|
||||
await _dbContext.InsertAsync(gainfoMeal);
|
||||
}
|
||||
|
||||
//重新核算
|
||||
var balance = await _dbContext.Queryable<BalanceRecordEntity>()
|
||||
.Where(x => x.UserCode == gainfo.Code)
|
||||
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
|
||||
.SumAsync(x => x.Amount);
|
||||
|
||||
await _dbContext.Updateable<GainfoMealEntity>()
|
||||
.SetColumns(x => x.Version == x.Version + 1)
|
||||
.SetColumns(x => x.Balance == balance)
|
||||
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||
.Where(x => x.UserCode == gainfoMeal.UserCode && x.Version == gainfoMeal.Version)
|
||||
.ExecuteCommandThrowVersionAsync();
|
||||
}, 5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task ReCalcAsync(string userCode)
|
||||
{
|
||||
await CommonHelper.RetryAsync(async () =>
|
||||
{
|
||||
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == userCode).SingleAsync()
|
||||
?? await _dbContext.Queryable<GainfoLeaveEntity>().Where(x => x.Code == userCode).SingleAsync();
|
||||
|
||||
gainfo.ThrowIfNull("档案不存在");
|
||||
|
||||
var gainfoMeal = await _dbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == gainfo.Code).FirstAsync();
|
||||
if (gainfoMeal == null)
|
||||
{
|
||||
gainfoMeal = new GainfoMealEntity
|
||||
{
|
||||
UserCode = gainfo.Code,
|
||||
Balance = 0,
|
||||
BalanceOfRecharge = 0,
|
||||
BalanceOfSubsidies = 0,
|
||||
Version = 0
|
||||
};
|
||||
|
||||
await _dbContext.InsertAsync(gainfoMeal);
|
||||
}
|
||||
|
||||
//重新核算
|
||||
var balance = await _dbContext.Queryable<BalanceRecordEntity>()
|
||||
.Where(x => x.UserCode == gainfo.Code)
|
||||
.Where(x => x.Source != BalanceRecordSourceEnumType.EMealVoucher)
|
||||
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
|
||||
.SumAsync(x => x.Amount);
|
||||
|
||||
await _dbContext.Updateable<GainfoMealEntity>()
|
||||
.SetColumns(x => x.Version == x.Version + 1)
|
||||
.SetColumns(x => x.Balance == balance)
|
||||
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||
.Where(x => x.UserCode == gainfoMeal.UserCode && x.Version == gainfoMeal.Version)
|
||||
.ExecuteCommandThrowVersionAsync();
|
||||
}, 5);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取离线设备
|
||||
/// </summary>
|
||||
|
||||
@@ -1,300 +1,302 @@
|
||||
using Dlhis.Canteen.Dishes.Request;
|
||||
using Dlhis.Canteen.Order.Request;
|
||||
using Dlhis.Canteen.Order.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.AspNetCore.Utils;
|
||||
using Dlhis.Canteen.Setting.Services;
|
||||
using Dlhis.Basic.Api;
|
||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using SqlSugar;
|
||||
using Mapster;
|
||||
|
||||
namespace Dlhis.Canteen.Order.Services.Implements;
|
||||
|
||||
public class BookingOrderService : BaseOrderService, IBookingOrderService
|
||||
{
|
||||
private readonly IDishesMenuApi _dishesMenuApi;
|
||||
private readonly IBusinessPlacePermissionsApi _businessPlacePermissionsApi;
|
||||
|
||||
public BookingOrderService(ICanteenSettingService canteenSettingService, IDbContext dbContext,
|
||||
IDishesMenuApi dishesMenuApi,
|
||||
IBusinessPlacePermissionsApi businessPlacePermissionsApi,
|
||||
ICurrentUser currentUser, ILogger<BookingOrderService> logger)
|
||||
: base(canteenSettingService, dbContext, currentUser, logger)
|
||||
{
|
||||
_dishesMenuApi = dishesMenuApi;
|
||||
_businessPlacePermissionsApi = businessPlacePermissionsApi;
|
||||
}
|
||||
|
||||
public async Task<BookingResponse> BookingAsync(BookingMealRequest request)
|
||||
{
|
||||
var gainfo = await CheckExistsMyBookingsAsync(request.BookingDate, request.ShiftType);
|
||||
|
||||
var businessPlace = await DbContext.Queryable<BusinessPlaceEntity>().Where(x => x.Code == request.BusinessPlaceCode).FirstAsync();
|
||||
|
||||
//预定时间
|
||||
var now = DateTime.Now;
|
||||
|
||||
var bookingDeadline = await GetSettingAsync<TimeOnly?>(gainfo.No, businessPlace.TenantId, CanteenSettingItemEnumType.BookingDeadline) ?? new TimeOnly(20, 30, 00);
|
||||
var dealLine = DateTime.Today.Add(bookingDeadline.ToTimeSpan());
|
||||
(now >= dealLine).ThrowIfTrue("超出订餐时间");
|
||||
|
||||
//菜单存在
|
||||
var menuDetailResult = await _dishesMenuApi.GetBookingDishesDetailAsync(request.BookingDate, request.BusinessPlaceCode, (int)request.ShiftType, request.DishesCode);
|
||||
var menuDetail = menuDetailResult.Data;
|
||||
menuDetail.ThrowIfNull("预定失败,菜品已经下架");
|
||||
|
||||
var order = new CanteenOrderEntity
|
||||
{
|
||||
RequestJson = request.ToJson(),
|
||||
ThirdNo = string.Empty,
|
||||
Type = BalanceRecordTypeEnumType.Out,
|
||||
ApplicationType = CanteenApplicationTypeEnumType.Booking,
|
||||
Name = gainfo.Name,
|
||||
Source = request.Source,
|
||||
UserNo = gainfo.No,
|
||||
UserCode = gainfo.Code,
|
||||
Amount = -Math.Abs(menuDetail.Price * request.Number),
|
||||
BusinessPlaceCode = request.BusinessPlaceCode,
|
||||
BusinessShiftCode = null,
|
||||
ShiftType = request.ShiftType,
|
||||
CostDate = now.Date,
|
||||
CostId = gainfo.CostId,
|
||||
DepartmentNo = gainfo.DepartmentNo,
|
||||
DeviceUniqueNo = string.Empty,
|
||||
DeliveryAddress = request.DeliveryAddress,
|
||||
|
||||
No = SnowFlakeHelper.Instance.NextId().ToString(),
|
||||
IsOffline = false,
|
||||
IsCostCrossTenant = await GetSettingAsync<bool>(gainfo.No, businessPlace.TenantId, CanteenSettingItemEnumType.AllowCrossTenant),
|
||||
|
||||
OriginTenantId = gainfo.Factory, //人员可能跨基地消费
|
||||
|
||||
Status = BalanceRecordStatusEnumType.Valid,
|
||||
OrderStatus = CanteenOrderStatusEnumType.Success,
|
||||
|
||||
CostDateTime = now,
|
||||
|
||||
//标识当前消费的基地
|
||||
TenantId = businessPlace.TenantId,
|
||||
};
|
||||
|
||||
await DbContext.InsertAsync(order);
|
||||
await CommonHelper.RetryAsync(async () =>
|
||||
{
|
||||
await _dishesMenuApi.GetBookingDishesDetailAsync(request.BookingDate, request.BusinessPlaceCode, (int)request.ShiftType, request.DishesCode);
|
||||
menuDetail = menuDetailResult.Data;
|
||||
menuDetail.ThrowIfNull("预定失败,菜品已经下架");
|
||||
menuDetail.Number -= request.Number;
|
||||
|
||||
(menuDetail.Number < 0).ThrowIfTrue($"{menuDetail.DishesName}剩余数量不足");
|
||||
|
||||
//餐补
|
||||
if (request.Source == BalanceRecordSourceEnumType.LocalTenantSubsidies)
|
||||
{
|
||||
var mealInfo = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == order.UserCode).FirstAsync();
|
||||
mealInfo.ThrowIfNull("余额不足,无法消费");
|
||||
|
||||
//金额+-
|
||||
mealInfo.Balance += order.Amount;
|
||||
(mealInfo.Balance < 0).ThrowIfTrue("余额不足,无法消费");
|
||||
|
||||
await DbContext.Updateable<GainfoMealEntity>()
|
||||
.SetColumns(x => x.Balance == mealInfo.Balance)
|
||||
.SetColumns(x => x.Version == x.Version + 1)
|
||||
.SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||
.Where(x => x.UserCode == order.UserCode && x.Version == mealInfo.Version) //必须与查询时的version一致
|
||||
.ExecuteCommandThrowVersionAsync();
|
||||
}
|
||||
|
||||
await DbContext.Updateable<DishesMenuEntity>()
|
||||
.SetColumns(x => x.Number == menuDetail.Number)
|
||||
.SetColumns(x => x.Version == x.Version + 1)
|
||||
.SetColumns(x => x.ModifiedTime == now)
|
||||
.Where(x => x.StartDate <= menuDetail.Date && menuDetail.Date <= x.EndDate
|
||||
&& x.ShiftType == request.ShiftType
|
||||
&& x.BusinessPlaceCode == request.BusinessPlaceCode
|
||||
&& x.DishesCode == request.DishesCode
|
||||
&& x.Version == menuDetail.Version
|
||||
)
|
||||
.ExecuteCommandThrowVersionAsync();
|
||||
|
||||
//写入记录
|
||||
var balanceRecord = order.Adapt<BalanceRecordEntity>();
|
||||
await DbContext.InsertAsync(balanceRecord);
|
||||
|
||||
await DbContext.InsertAsync(new CanteenOrderDetailEntity
|
||||
{
|
||||
OrderNo = order.No,
|
||||
BookingDate = request.BookingDate,
|
||||
DishesCode = request.DishesCode,
|
||||
Price = menuDetail.Price,
|
||||
Unit = request.Unit,
|
||||
Number = request.Number,
|
||||
TenantId = order.TenantId,
|
||||
});
|
||||
}, 10);
|
||||
|
||||
|
||||
return new BookingResponse
|
||||
{
|
||||
No = order.No,
|
||||
CreateTime = order.CreateTime,
|
||||
Source = order.Source,
|
||||
Amount = Math.Abs(order.Amount)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public async Task<Pagination<OrderBookingResponse>> GetBookingPageAsync(OrderBookingPageRequest request)
|
||||
{
|
||||
var myCodes = (await _businessPlacePermissionsApi.GetMyAsync()).Data.Select(x => (Guid?)x.Code).ToList();
|
||||
|
||||
var page = await DbContext.Queryable<CanteenOrderEntity>()
|
||||
.LeftJoin<GainfoEntity>((x, ga) => x.UserNo == ga.No)
|
||||
.LeftJoin<DepartmentEntity>((x, ga, dept) => dept.No == ga.DepartmentNo)
|
||||
.Where(x => myCodes.Contains(x.BusinessPlaceCode))
|
||||
.WhereIF(request.OrderStatus.HasValue, x => x.OrderStatus == request.OrderStatus)
|
||||
.WhereIF(request.Source.HasValue, x => x.Source == request.Source)
|
||||
.WhereIF(request.Search.IsPresent(), (x, ga) => x.UserCode == request.Search || ga.Name.Contains(request.Search))
|
||||
.WhereIF(request.BookingPeriod?.Start.HasValue == true && request.BookingPeriod?.End.HasValue == true, x =>
|
||||
SqlFunc.Subqueryable<CanteenOrderDetailEntity>()
|
||||
.Where(p => p.OrderNo == x.No)
|
||||
.Where(p => p.BookingDate >= request.BookingPeriod.Start)
|
||||
.Where(p => p.BookingDate <= request.BookingPeriod.End)
|
||||
.Any()
|
||||
)
|
||||
.WhereIF(request.ShiftType.HasValue, x => x.ShiftType == request.ShiftType)
|
||||
.Select((x, ga, dept) => new OrderBookingResponse
|
||||
{
|
||||
No = x.No,
|
||||
DeliveryAddress = x.DeliveryAddress,
|
||||
Remark = x.Remark,
|
||||
Amount = SqlFunc.Abs(x.Amount),
|
||||
CreateTime = x.CreateTime,
|
||||
ShiftType = x.ShiftType,
|
||||
Status = x.OrderStatus,
|
||||
UserCode = x.UserCode,
|
||||
UserName = ga.Name,
|
||||
Source = x.Source,
|
||||
DepartmentName = dept.Name,
|
||||
})
|
||||
.ToPageListAsync(request);
|
||||
|
||||
var nos = page.Data.Select(x => x.No).ToList();
|
||||
var details = await DbContext.Queryable<CanteenOrderDetailEntity>()
|
||||
.LeftJoin<DishesEntity>((x, dishes) => x.DishesCode == dishes.CustomCode)
|
||||
.Where(x => nos.Contains(x.OrderNo))
|
||||
.Select((x, dishes) => new { x.OrderNo, x.BookingDate, x.Number, dishes.Name }).ToListAsync();
|
||||
|
||||
page.Data.ForEach(x =>
|
||||
{
|
||||
x.BookingDate = details.First(item => item.OrderNo == x.No).BookingDate;
|
||||
x.TotalNumber = details.Where(item => item.OrderNo == x.No).Sum(item => item.Number);
|
||||
x.DishesInfos = details.Where(item => item.OrderNo == x.No).Select(item => new
|
||||
{
|
||||
item.Name
|
||||
})
|
||||
.ToList();
|
||||
});
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
public async Task UserCancelOrderAsync(OrderCancelRequest request)
|
||||
{
|
||||
var order = await DbContext.Queryable<CanteenOrderEntity>().Where(x => x.No == request.No).FirstAsync();
|
||||
order.ThrowIfNull("订单不存在");
|
||||
|
||||
var bookingDeadline = await GetSettingAsync<TimeOnly?>(order.No, order.TenantId, CanteenSettingItemEnumType.BookingDeadline) ?? new TimeOnly(20, 30, 00);
|
||||
var dealLine = DateTime.Today.Add(bookingDeadline.ToTimeSpan());
|
||||
(DateTime.Now >= dealLine).ThrowIfTrue("不在订单取消允许范围内,不可操作");
|
||||
|
||||
await ManagerCancelOrderAsync(new OrderCancelRequest
|
||||
{
|
||||
No = request.No,
|
||||
Reason = request.Reason,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public async Task ManagerCancelOrderAsync(OrderCancelRequest request)
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
var userId = CurrentUser.GetIntSubjectId();
|
||||
|
||||
var order = await DbContext.Queryable<CanteenOrderEntity>().Where(x => x.No == request.No).FirstAsync();
|
||||
order.ThrowIfNull("订单不存在");
|
||||
|
||||
await DbContext.Updateable<CanteenOrderEntity>()
|
||||
.SetColumns(x => x.OrderStatus == CanteenOrderStatusEnumType.Cancel)
|
||||
.SetColumns(x => x.Remark == request.Reason)
|
||||
.SetColumns(x => x.ModifiedTime == now)
|
||||
.SetColumns(x => x.ModifiedBy == userId)
|
||||
.Where(x => x.No == request.No)
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
await DbContext.Updateable<BalanceRecordEntity>()
|
||||
.SetColumns(x => x.Status == BalanceRecordStatusEnumType.Obsolute)
|
||||
.SetColumns(x => x.Remark == request.Reason)
|
||||
.SetColumns(x => x.ModifiedTime == now)
|
||||
.SetColumns(x => x.ModifiedBy == userId)
|
||||
.Where(x => x.No == request.No)
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
if (order.Source == BalanceRecordSourceEnumType.LocalTenantSubsidies)
|
||||
{
|
||||
await CommonHelper.RetryAsync(async () =>
|
||||
{
|
||||
var mealInfo = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == order.UserCode).FirstAsync();
|
||||
var setBalance = mealInfo.Balance + Math.Abs(order.Amount);
|
||||
await DbContext.Updateable<GainfoMealEntity>()
|
||||
.SetColumns(x => x.Version == x.Version + 1)
|
||||
.SetColumns(x => x.Balance == setBalance)
|
||||
.SetColumns(x => x.ModifiedTime == now)
|
||||
.SetColumns(x => x.ModifiedBy == userId)
|
||||
.Where(x => x.Id == mealInfo.Id && x.Version == mealInfo.Version)
|
||||
.ExecuteCommandThrowVersionAsync();
|
||||
}, 5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 检查我的订餐是否存在,存在抛出异常
|
||||
/// </summary>
|
||||
/// <param name="bookingDate"></param>
|
||||
/// <param name="shiftType"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<GainfoEntity> CheckExistsMyBookingsAsync(DateTime bookingDate, ShiftEnumType shiftType)
|
||||
{
|
||||
var subjectId = CurrentUser.GetIntSubjectId();
|
||||
var gainfo = await DbContext.Queryable<GainfoEntity>().Where(x => x.IdentityUserId == subjectId).FirstAsync();
|
||||
var jinkoCode = CurrentUser.GetUserClaim("jinko-code") ?? string.Empty;
|
||||
if (jinkoCode.IsPresent())
|
||||
{
|
||||
gainfo = await DbContext.Queryable<GainfoEntity>().Where(x => x.Code == jinkoCode).FirstAsync();
|
||||
}
|
||||
|
||||
var start = bookingDate.Date.AddDays(-1);
|
||||
var end = start.AddDays(1).AddSeconds(-1);
|
||||
|
||||
var exists = await DbContext.Queryable<CanteenOrderEntity>()
|
||||
.Where(x => x.ApplicationType == CanteenApplicationTypeEnumType.Booking)
|
||||
.Where(x => x.OrderStatus == CanteenOrderStatusEnumType.Success)
|
||||
.Where(x => x.ShiftType == shiftType)
|
||||
.Where(x => x.UserNo == gainfo.No)
|
||||
.Where(x => x.CreateTime >= start && x.CreateTime <= end)
|
||||
.AnyAsync();
|
||||
|
||||
exists.ThrowIfTrue("不可重复订餐");
|
||||
|
||||
return gainfo;
|
||||
}
|
||||
}
|
||||
// using Dlhis.Canteen.Dishes.Request;
|
||||
// using Dlhis.Canteen.Order.Request;
|
||||
// using Dlhis.Canteen.Order.Response;
|
||||
// using Dlhis.Entity.Basic.Entity;
|
||||
// using Dlhis.Entity.Canteen.Entities;
|
||||
// using Dlhis.Entity.Canteen.Enums;
|
||||
// using Kurisu.AspNetCore.Utils.Extensions;
|
||||
// using Kurisu.AspNetCore.Utils;
|
||||
// using Dlhis.Canteen.Setting.Services;
|
||||
// using Dlhis.Basic.Api;
|
||||
// using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||
// using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
// using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
// using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
// using SqlSugar;
|
||||
// using Mapster;
|
||||
//
|
||||
// namespace Dlhis.Canteen.Order.Services.Implements;
|
||||
//
|
||||
// public class BookingOrderService : BaseOrderService, IBookingOrderService
|
||||
// {
|
||||
// private readonly ICanteenSettingService _canteenSettingService;
|
||||
// private readonly IDishesMenuApi _dishesMenuApi;
|
||||
// private readonly IBusinessPlacePermissionsApi _businessPlacePermissionsApi;
|
||||
//
|
||||
// public BookingOrderService(ICanteenSettingService canteenSettingService, IDbContext dbContext,
|
||||
// IDishesMenuApi dishesMenuApi,
|
||||
// IBusinessPlacePermissionsApi businessPlacePermissionsApi,
|
||||
// ICurrentUser currentUser, ILogger<BookingOrderService> logger)
|
||||
// : base(canteenSettingService, dbContext, currentUser, logger)
|
||||
// {
|
||||
// _canteenSettingService = canteenSettingService;
|
||||
// _dishesMenuApi = dishesMenuApi;
|
||||
// _businessPlacePermissionsApi = businessPlacePermissionsApi;
|
||||
// }
|
||||
//
|
||||
// public async Task<BookingResponse> BookingAsync(BookingMealRequest request)
|
||||
// {
|
||||
// var gainfo = await CheckExistsMyBookingsAsync(request.BookingDate, request.ShiftType);
|
||||
//
|
||||
// var businessPlace = await DbContext.Queryable<BusinessPlaceEntity>().Where(x => x.Code == request.BusinessPlaceCode).FirstAsync();
|
||||
//
|
||||
// //预定时间
|
||||
// var now = DateTime.Now;
|
||||
//
|
||||
// var bookingDeadline = await _canteenSettingService.GetSettingAsync(CanteenSettingItemEnumType.BookingDeadline, businessPlace.TenantId, gainfo.No, new TimeOnly(20, 30, 00));
|
||||
// var dealLine = DateTime.Today.Add(bookingDeadline.ToTimeSpan());
|
||||
// (now >= dealLine).ThrowIfTrue("超出订餐时间");
|
||||
//
|
||||
// //菜单存在
|
||||
// var menuDetailResult = await _dishesMenuApi.GetBookingDishesDetailAsync(request.BookingDate, request.BusinessPlaceCode, (int)request.ShiftType, request.DishesCode);
|
||||
// var menuDetail = menuDetailResult.Data;
|
||||
// menuDetail.ThrowIfNull("预定失败,菜品已经下架");
|
||||
//
|
||||
// var order = new CanteenOrderEntity
|
||||
// {
|
||||
// RequestJson = request.ToJson(),
|
||||
// ThirdNo = string.Empty,
|
||||
// Type = BalanceRecordTypeEnumType.Out,
|
||||
// ApplicationType = CanteenApplicationTypeEnumType.Booking,
|
||||
// Name = gainfo.Name,
|
||||
// Source = request.Source,
|
||||
// UserNo = gainfo.No,
|
||||
// UserCode = gainfo.Code,
|
||||
// Amount = -Math.Abs(menuDetail.Price * request.Number),
|
||||
// BusinessPlaceCode = request.BusinessPlaceCode,
|
||||
// BusinessShiftCode = null,
|
||||
// ShiftType = request.ShiftType,
|
||||
// CostDate = now.Date,
|
||||
// CostId = gainfo.CostId,
|
||||
// DepartmentNo = gainfo.DepartmentNo,
|
||||
// DeviceUniqueNo = string.Empty,
|
||||
// DeliveryAddress = request.DeliveryAddress,
|
||||
//
|
||||
// No = SnowFlakeHelper.Instance.NextId().ToString(),
|
||||
// IsOffline = false,
|
||||
// IsCostCrossTenant = await _canteenSettingService.GetSettingAsync<bool>(CanteenSettingItemEnumType.AllowCrossTenant, businessPlace.TenantId, gainfo.No),
|
||||
//
|
||||
// OriginTenantId = gainfo.Factory, //人员可能跨基地消费
|
||||
//
|
||||
// Status = BalanceRecordStatusEnumType.Valid,
|
||||
// OrderStatus = CanteenOrderStatusEnumType.Success,
|
||||
//
|
||||
// CostDateTime = now,
|
||||
//
|
||||
// //标识当前消费的基地
|
||||
// TenantId = businessPlace.TenantId,
|
||||
// };
|
||||
//
|
||||
// await DbContext.InsertAsync(order);
|
||||
// await CommonHelper.RetryAsync(async () =>
|
||||
// {
|
||||
// await _dishesMenuApi.GetBookingDishesDetailAsync(request.BookingDate, request.BusinessPlaceCode, (int)request.ShiftType, request.DishesCode);
|
||||
// menuDetail = menuDetailResult.Data;
|
||||
// menuDetail.ThrowIfNull("预定失败,菜品已经下架");
|
||||
// menuDetail.Number -= request.Number;
|
||||
//
|
||||
// (menuDetail.Number < 0).ThrowIfTrue($"{menuDetail.DishesName}剩余数量不足");
|
||||
//
|
||||
// //餐补
|
||||
// if (request.Source == BalanceRecordSourceEnumType.LocalTenantSubsidies)
|
||||
// {
|
||||
// var mealInfo = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == order.UserCode).FirstAsync();
|
||||
// mealInfo.ThrowIfNull("余额不足,无法消费");
|
||||
//
|
||||
// //金额+-
|
||||
// mealInfo.Balance += order.Amount;
|
||||
// (mealInfo.Balance < 0).ThrowIfTrue("余额不足,无法消费");
|
||||
//
|
||||
// await DbContext.Updateable<GainfoMealEntity>()
|
||||
// .SetColumns(x => x.Balance == mealInfo.Balance)
|
||||
// .SetColumns(x => x.Version == x.Version + 1)
|
||||
// .SetColumns(x => x.ModifiedTime == DateTime.Now)
|
||||
// .Where(x => x.UserCode == order.UserCode && x.Version == mealInfo.Version) //必须与查询时的version一致
|
||||
// .ExecuteCommandThrowVersionAsync();
|
||||
// }
|
||||
//
|
||||
// await DbContext.Updateable<DishesMenuEntity>()
|
||||
// .SetColumns(x => x.Number == menuDetail.Number)
|
||||
// .SetColumns(x => x.Version == x.Version + 1)
|
||||
// .SetColumns(x => x.ModifiedTime == now)
|
||||
// .Where(x => x.StartDate <= menuDetail.Date && menuDetail.Date <= x.EndDate
|
||||
// && x.ShiftType == request.ShiftType
|
||||
// && x.BusinessPlaceCode == request.BusinessPlaceCode
|
||||
// && x.DishesCode == request.DishesCode
|
||||
// && x.Version == menuDetail.Version
|
||||
// )
|
||||
// .ExecuteCommandThrowVersionAsync();
|
||||
//
|
||||
// //写入记录
|
||||
// var balanceRecord = order.Adapt<BalanceRecordEntity>();
|
||||
// await DbContext.InsertAsync(balanceRecord);
|
||||
//
|
||||
// await DbContext.InsertAsync(new CanteenOrderDetailEntity
|
||||
// {
|
||||
// OrderNo = order.No,
|
||||
// BookingDate = request.BookingDate,
|
||||
// DishesCode = request.DishesCode,
|
||||
// Price = menuDetail.Price,
|
||||
// Unit = request.Unit,
|
||||
// Number = request.Number,
|
||||
// TenantId = order.TenantId,
|
||||
// });
|
||||
// }, 10);
|
||||
//
|
||||
//
|
||||
// return new BookingResponse
|
||||
// {
|
||||
// No = order.No,
|
||||
// CreateTime = order.CreateTime,
|
||||
// Source = order.Source,
|
||||
// Amount = Math.Abs(order.Amount)
|
||||
// };
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public async Task<Pagination<OrderBookingResponse>> GetBookingPageAsync(OrderBookingPageRequest request)
|
||||
// {
|
||||
// var myCodes = (await _businessPlacePermissionsApi.GetMyAsync()).Data.Select(x => (Guid?)x.Code).ToList();
|
||||
//
|
||||
// var page = await DbContext.Queryable<CanteenOrderEntity>()
|
||||
// .LeftJoin<GainfoEntity>((x, ga) => x.UserNo == ga.No)
|
||||
// .LeftJoin<DepartmentEntity>((x, ga, dept) => dept.No == ga.DepartmentNo)
|
||||
// .Where(x => myCodes.Contains(x.BusinessPlaceCode))
|
||||
// .WhereIF(request.OrderStatus.HasValue, x => x.OrderStatus == request.OrderStatus)
|
||||
// .WhereIF(request.Source.HasValue, x => x.Source == request.Source)
|
||||
// .WhereIF(request.Search.IsPresent(), (x, ga) => x.UserCode == request.Search || ga.Name.Contains(request.Search))
|
||||
// .WhereIF(request.BookingPeriod?.Start.HasValue == true && request.BookingPeriod?.End.HasValue == true, x =>
|
||||
// SqlFunc.Subqueryable<CanteenOrderDetailEntity>()
|
||||
// .Where(p => p.OrderNo == x.No)
|
||||
// .Where(p => p.BookingDate >= request.BookingPeriod.Start)
|
||||
// .Where(p => p.BookingDate <= request.BookingPeriod.End)
|
||||
// .Any()
|
||||
// )
|
||||
// .WhereIF(request.ShiftType.HasValue, x => x.ShiftType == request.ShiftType)
|
||||
// .Select((x, ga, dept) => new OrderBookingResponse
|
||||
// {
|
||||
// No = x.No,
|
||||
// DeliveryAddress = x.DeliveryAddress,
|
||||
// Remark = x.Remark,
|
||||
// Amount = SqlFunc.Abs(x.Amount),
|
||||
// CreateTime = x.CreateTime,
|
||||
// ShiftType = x.ShiftType,
|
||||
// Status = x.OrderStatus,
|
||||
// UserCode = x.UserCode,
|
||||
// UserName = ga.Name,
|
||||
// Source = x.Source,
|
||||
// DepartmentName = dept.Name,
|
||||
// })
|
||||
// .ToPageListAsync(request);
|
||||
//
|
||||
// var nos = page.Data.Select(x => x.No).ToList();
|
||||
// var details = await DbContext.Queryable<CanteenOrderDetailEntity>()
|
||||
// .LeftJoin<DishesEntity>((x, dishes) => x.DishesCode == dishes.CustomCode)
|
||||
// .Where(x => nos.Contains(x.OrderNo))
|
||||
// .Select((x, dishes) => new { x.OrderNo, x.BookingDate, x.Number, dishes.Name }).ToListAsync();
|
||||
//
|
||||
// page.Data.ForEach(x =>
|
||||
// {
|
||||
// x.BookingDate = details.First(item => item.OrderNo == x.No).BookingDate;
|
||||
// x.TotalNumber = details.Where(item => item.OrderNo == x.No).Sum(item => item.Number);
|
||||
// x.DishesInfos = details.Where(item => item.OrderNo == x.No).Select(item => new
|
||||
// {
|
||||
// item.Name
|
||||
// })
|
||||
// .ToList();
|
||||
// });
|
||||
//
|
||||
// return page;
|
||||
// }
|
||||
//
|
||||
// public async Task UserCancelOrderAsync(OrderCancelRequest request)
|
||||
// {
|
||||
// var order = await DbContext.Queryable<CanteenOrderEntity>().Where(x => x.No == request.No).FirstAsync();
|
||||
// order.ThrowIfNull("订单不存在");
|
||||
//
|
||||
// var bookingDeadline = await _canteenSettingService.GetSettingAsync(CanteenSettingItemEnumType.BookingDeadline, order.TenantId, order.No, new TimeOnly(20, 30, 00));
|
||||
// var dealLine = DateTime.Today.Add(bookingDeadline.ToTimeSpan());
|
||||
// (DateTime.Now >= dealLine).ThrowIfTrue("不在订单取消允许范围内,不可操作");
|
||||
//
|
||||
// await ManagerCancelOrderAsync(new OrderCancelRequest
|
||||
// {
|
||||
// No = request.No,
|
||||
// Reason = request.Reason,
|
||||
// });
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public async Task ManagerCancelOrderAsync(OrderCancelRequest request)
|
||||
// {
|
||||
// var now = DateTime.Now;
|
||||
// var userId = CurrentUser.GetIntSubjectId();
|
||||
//
|
||||
// var order = await DbContext.Queryable<CanteenOrderEntity>().Where(x => x.No == request.No).FirstAsync();
|
||||
// order.ThrowIfNull("订单不存在");
|
||||
//
|
||||
// await DbContext.Updateable<CanteenOrderEntity>()
|
||||
// .SetColumns(x => x.OrderStatus == CanteenOrderStatusEnumType.Cancel)
|
||||
// .SetColumns(x => x.Remark == request.Reason)
|
||||
// .SetColumns(x => x.ModifiedTime == now)
|
||||
// .SetColumns(x => x.ModifiedBy == userId)
|
||||
// .Where(x => x.No == request.No)
|
||||
// .ExecuteCommandAsync();
|
||||
//
|
||||
// await DbContext.Updateable<BalanceRecordEntity>()
|
||||
// .SetColumns(x => x.Status == BalanceRecordStatusEnumType.Obsolute)
|
||||
// .SetColumns(x => x.Remark == request.Reason)
|
||||
// .SetColumns(x => x.ModifiedTime == now)
|
||||
// .SetColumns(x => x.ModifiedBy == userId)
|
||||
// .Where(x => x.No == request.No)
|
||||
// .ExecuteCommandAsync();
|
||||
//
|
||||
// if (order.Source == BalanceRecordSourceEnumType.LocalTenantSubsidies)
|
||||
// {
|
||||
// await CommonHelper.RetryAsync(async () =>
|
||||
// {
|
||||
// var mealInfo = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == order.UserCode).FirstAsync();
|
||||
// var setBalance = mealInfo.Balance + Math.Abs(order.Amount);
|
||||
// await DbContext.Updateable<GainfoMealEntity>()
|
||||
// .SetColumns(x => x.Version == x.Version + 1)
|
||||
// .SetColumns(x => x.Balance == setBalance)
|
||||
// .SetColumns(x => x.ModifiedTime == now)
|
||||
// .SetColumns(x => x.ModifiedBy == userId)
|
||||
// .Where(x => x.Id == mealInfo.Id && x.Version == mealInfo.Version)
|
||||
// .ExecuteCommandThrowVersionAsync();
|
||||
// }, 5);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /// <summary>
|
||||
// /// 检查我的订餐是否存在,存在抛出异常
|
||||
// /// </summary>
|
||||
// /// <param name="bookingDate"></param>
|
||||
// /// <param name="shiftType"></param>
|
||||
// /// <returns></returns>
|
||||
// private async Task<GainfoEntity> CheckExistsMyBookingsAsync(DateTime bookingDate, ShiftEnumType shiftType)
|
||||
// {
|
||||
// var subjectId = CurrentUser.GetIntSubjectId();
|
||||
// var gainfo = await DbContext.Queryable<GainfoEntity>().Where(x => x.IdentityUserId == subjectId).FirstAsync();
|
||||
// var jinkoCode = CurrentUser.GetUserClaim("jinko-code") ?? string.Empty;
|
||||
// if (jinkoCode.IsPresent())
|
||||
// {
|
||||
// gainfo = await DbContext.Queryable<GainfoEntity>().Where(x => x.Code == jinkoCode).FirstAsync();
|
||||
// }
|
||||
//
|
||||
// var start = bookingDate.Date.AddDays(-1);
|
||||
// var end = start.AddDays(1).AddSeconds(-1);
|
||||
//
|
||||
// var exists = await DbContext.Queryable<CanteenOrderEntity>()
|
||||
// .Where(x => x.ApplicationType == CanteenApplicationTypeEnumType.Booking)
|
||||
// .Where(x => x.OrderStatus == CanteenOrderStatusEnumType.Success)
|
||||
// .Where(x => x.ShiftType == shiftType)
|
||||
// .Where(x => x.UserNo == gainfo.No)
|
||||
// .Where(x => x.CreateTime >= start && x.CreateTime <= end)
|
||||
// .AnyAsync();
|
||||
//
|
||||
// exists.ThrowIfTrue("不可重复订餐");
|
||||
//
|
||||
// return gainfo;
|
||||
// }
|
||||
// }
|
||||
@@ -1,3 +1,4 @@
|
||||
using Dlhis.Canteen.Order.Repository;
|
||||
using Dlhis.Canteen.Order.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
@@ -8,12 +9,12 @@ namespace Dlhis.Canteen.Order.Services.Implements;
|
||||
public class MiddleService : IMiddleService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly IBalanceService _balanceService;
|
||||
private readonly IBalanceRepository _balanceRepository;
|
||||
|
||||
public MiddleService(IDbContext dbContext, IBalanceService balanceService)
|
||||
public MiddleService(IDbContext dbContext, IBalanceRepository balanceRepository)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_balanceService = balanceService;
|
||||
_balanceRepository = balanceRepository;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -25,21 +26,21 @@ public class MiddleService : IMiddleService
|
||||
if (!await _dbContext.Queryable<BalanceRecordEntity>().AnyAsync(x => x.No == entity.No))
|
||||
{
|
||||
await _dbContext.InsertAsync(entity);
|
||||
await _balanceService.ReCalcAsync(entity.UserCode);
|
||||
}
|
||||
|
||||
var balance = await _balanceRepository.GetBalanceAsync(entity.UserCode, string.Empty);
|
||||
|
||||
//获取人员余额
|
||||
return await _dbContext.Queryable<GainfoMealEntity>()
|
||||
.LeftJoin<GainfoEntity>((x, ga) => x.UserCode == ga.Code)
|
||||
.LeftJoin<DepartmentEntity>((x, ga, department) => ga.DepartmentNo == department.No)
|
||||
.Where(x => x.UserCode == entity.UserCode)
|
||||
.Select((x, ga, department) => new OrderResultResponse
|
||||
return await _dbContext.Queryable<GainfoEntity>()
|
||||
.LeftJoin<DepartmentEntity>((x, department) => x.DepartmentNo == department.No)
|
||||
.Where(x => x.Code == entity.UserCode)
|
||||
.Select((x, department) => new OrderResultResponse
|
||||
{
|
||||
UserCode = ga.Code,
|
||||
UserName = ga.Name,
|
||||
DepartmentNo = ga.DepartmentNo,
|
||||
UserCode = x.Code,
|
||||
UserName = x.Name,
|
||||
DepartmentNo = x.DepartmentNo,
|
||||
DepartmentName = department.Name,
|
||||
CurrentBalance = x.Balance
|
||||
CurrentBalance = balance
|
||||
})
|
||||
.SingleAsync();
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
46
Src/Dlhis.Canteen/Setting/Controllers/WalletsController.cs
Normal file
46
Src/Dlhis.Canteen/Setting/Controllers/WalletsController.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Dlhis.Canteen.Setting.Response;
|
||||
using Dlhis.Canteen.Setting.Services;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.Canteen.Setting.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 钱包
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class WalletsController : ControllerBase
|
||||
{
|
||||
private readonly IWalletService _walletService;
|
||||
|
||||
public WalletsController(IWalletService walletService)
|
||||
{
|
||||
_walletService = walletService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 钱包列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
public async Task<List<WalletResponse>> GetListAsync()
|
||||
{
|
||||
return await _walletService.GetListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 余额
|
||||
/// </summary>
|
||||
/// <param name="walletCode">钱包code</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("balance")]
|
||||
[IgnoreTenant]
|
||||
public async Task<decimal> GetBalanceAsync([Required] string walletCode)
|
||||
{
|
||||
return await _walletService.GetBalanceAsync(walletCode);
|
||||
}
|
||||
}
|
||||
19
Src/Dlhis.Canteen/Setting/Response/WalletResponse.cs
Normal file
19
Src/Dlhis.Canteen/Setting/Response/WalletResponse.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace Dlhis.Canteen.Setting.Response;
|
||||
|
||||
public class WalletResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 钱包编码
|
||||
/// </summary>
|
||||
public string Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 钱包名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 厂区
|
||||
/// </summary>
|
||||
public List<string> Factories { get; set; }
|
||||
}
|
||||
@@ -7,10 +7,25 @@ namespace Dlhis.Canteen.Setting.Services;
|
||||
|
||||
public interface ICanteenSettingService : IScopeDependency
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取配置分页数据
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task<Pagination<CanteenSettingResponse>> GetPageAsync(CanteenSettingPageRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 保存配置
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task SaveSettingAsync(CanteenSettingSaveRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 设置配置启用开关
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task SetEnableAsync(CanteenSettingSetEnableRequest request);
|
||||
|
||||
/// <summary>
|
||||
@@ -21,7 +36,21 @@ public interface ICanteenSettingService : IScopeDependency
|
||||
/// <returns></returns>
|
||||
Task<Dictionary<CanteenSettingItemEnumType, string>> GetUserSettingAsync(string userNo, string tenantId);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取营业点切换时间
|
||||
/// </summary>
|
||||
/// <param name="tenantId"></param>
|
||||
/// <returns></returns>
|
||||
Task<TimeOnly?> GetBusinessSwitchTimeAsync(string tenantId);
|
||||
}
|
||||
|
||||
|
||||
Task<T> GetSettingAsync<T>(CanteenSettingItemEnumType item, string factory, string userNo, T defaultValue = default);
|
||||
|
||||
/// <summary>
|
||||
/// 获取消费日期
|
||||
/// </summary>
|
||||
/// <param name="factory"></param>
|
||||
/// <param name="costDateTime"></param>
|
||||
/// <returns></returns>
|
||||
Task<DateTime> GetCostDateAsync(string factory, DateTime costDateTime);
|
||||
}
|
||||
10
Src/Dlhis.Canteen/Setting/Services/IWalletService.cs
Normal file
10
Src/Dlhis.Canteen/Setting/Services/IWalletService.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Dlhis.Canteen.Setting.Response;
|
||||
|
||||
namespace Dlhis.Canteen.Setting.Services;
|
||||
|
||||
public interface IWalletService : IScopeDependency
|
||||
{
|
||||
Task<List<WalletResponse>> GetListAsync();
|
||||
|
||||
Task<decimal> GetBalanceAsync(string walletCode);
|
||||
}
|
||||
@@ -114,6 +114,49 @@ public class CanteenSettingService : ICanteenSettingService
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<T> GetSettingAsync<T>(CanteenSettingItemEnumType item, string factory, string userNo, T defaultValue = default)
|
||||
{
|
||||
var settings = await GetUserSettingAsync(userNo, factory);
|
||||
|
||||
if (settings.TryGetValue(item, out var v))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (int.TryParse(v, out var n))
|
||||
{
|
||||
return n.Adapt<T>();
|
||||
}
|
||||
|
||||
return v.Adapt<T>();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<DateTime> GetCostDateAsync(string factory, DateTime costDateTime)
|
||||
{
|
||||
var switchTime = await GetSettingAsync<TimeOnly?>(CanteenSettingItemEnumType.BusinessSwitchTime, factory, string.Empty);
|
||||
|
||||
var costDate = costDateTime.Date;
|
||||
|
||||
if (!switchTime.HasValue) return costDate;
|
||||
|
||||
var beginOfDay = costDateTime.Date;
|
||||
|
||||
var setTime = beginOfDay.Add(switchTime.Value.ToTimeSpan());
|
||||
if (costDateTime < setTime)
|
||||
costDate = costDateTime.Date.AddDays(-1);
|
||||
|
||||
return costDate;
|
||||
}
|
||||
|
||||
//*********************************************** help methods ***************************************************//
|
||||
|
||||
private async Task CheckDuplicateSettingAsync(CanteenSettingSaveRequest request)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
using Dlhis.Canteen.Order.Repository;
|
||||
using Dlhis.Canteen.Setting.Response;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Canteen.Setting.Services.Implements;
|
||||
|
||||
public class WalletService : IWalletService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly IBalanceRepository _balanceRepository;
|
||||
|
||||
public WalletService(IDbContext dbContext, ICurrentUser currentUser, IBalanceRepository balanceRepository)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_currentUser = currentUser;
|
||||
_balanceRepository = balanceRepository;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<WalletResponse>> GetListAsync()
|
||||
{
|
||||
return await _dbContext.Queryable<WalletEntity>()
|
||||
.GroupBy(x => new { x.Code, x.Name })
|
||||
.Select(x => new WalletResponse
|
||||
{
|
||||
Code = x.Code,
|
||||
Name = x.Name + "钱包",
|
||||
Factories = SqlFunc.Subqueryable<WalletEntity>().Where(p => p.Code == x.Code).ToList(p => p.Factory)
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<decimal> GetBalanceAsync(string walletCode)
|
||||
{
|
||||
var userCode = _currentUser.GetUserClaim("jinko-code");
|
||||
var factory = await _dbContext.Queryable<WalletEntity>().Where(x => x.Code == walletCode).Select(x => x.Factory).FirstAsync();
|
||||
|
||||
return await _balanceRepository.GetBalanceAsync(userCode, factory);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user