diff --git a/Src/Dlhis.Canteen/Setting/Controllers/WalletsController.cs b/Src/Dlhis.Canteen/Setting/Controllers/WalletsController.cs index 2bcbf0dc..53a38aaa 100644 --- a/Src/Dlhis.Canteen/Setting/Controllers/WalletsController.cs +++ b/Src/Dlhis.Canteen/Setting/Controllers/WalletsController.cs @@ -1,7 +1,6 @@ -using Dlhis.Canteen.Order.Repository; +using System.ComponentModel.DataAnnotations; using Dlhis.Canteen.Setting.Response; using Dlhis.Canteen.Setting.Services; -using Kurisu.AspNetCore.Authentication.Abstractions; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -16,14 +15,10 @@ namespace Dlhis.Canteen.Setting.Controllers; public class WalletsController : ControllerBase { private readonly IWalletService _walletService; - private readonly IBalanceRepository _balanceRepository; - private readonly ICurrentUser _currentUser; - public WalletsController(IWalletService walletService, IBalanceRepository balanceRepository, ICurrentUser currentUser) + public WalletsController(IWalletService walletService) { _walletService = walletService; - _balanceRepository = balanceRepository; - _currentUser = currentUser; } /// @@ -39,12 +34,11 @@ public class WalletsController : ControllerBase /// /// 余额 /// - /// + /// 钱包code /// [HttpGet("balance")] - public async Task GetBalanceAsync(string factory) + public async Task GetBalanceAsync([Required] string walletCode) { - var code = _currentUser.GetUserClaim("jinko-code"); - return await _balanceRepository.GetBalanceAsync(code, factory); + return await _walletService.GetBalanceAsync(walletCode); } } \ No newline at end of file diff --git a/Src/Dlhis.Canteen/Setting/Services/IWalletService.cs b/Src/Dlhis.Canteen/Setting/Services/IWalletService.cs index 614c7c1f..38aa63f8 100644 --- a/Src/Dlhis.Canteen/Setting/Services/IWalletService.cs +++ b/Src/Dlhis.Canteen/Setting/Services/IWalletService.cs @@ -5,4 +5,6 @@ namespace Dlhis.Canteen.Setting.Services; public interface IWalletService : IScopeDependency { Task> GetListAsync(); + + Task GetBalanceAsync(string walletCode); } \ No newline at end of file diff --git a/Src/Dlhis.Canteen/Setting/Services/Implements/WalletService.cs b/Src/Dlhis.Canteen/Setting/Services/Implements/WalletService.cs index 819cfabe..20ac1476 100644 --- a/Src/Dlhis.Canteen/Setting/Services/Implements/WalletService.cs +++ b/Src/Dlhis.Canteen/Setting/Services/Implements/WalletService.cs @@ -1,5 +1,7 @@ +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; @@ -8,10 +10,14 @@ 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) + public WalletService(IDbContext dbContext, ICurrentUser currentUser, IBalanceRepository balanceRepository) { _dbContext = dbContext; + _currentUser = currentUser; + _balanceRepository = balanceRepository; } /// @@ -27,4 +33,13 @@ public class WalletService : IWalletService }) .ToListAsync(); } + + /// + public async Task GetBalanceAsync(string walletCode) + { + var userCode = _currentUser.GetUserClaim("jinko-code"); + var factory = await _dbContext.Queryable().Where(x => x.Code == walletCode).Select(x => x.Factory).FirstAsync(); + + return await _balanceRepository.GetBalanceAsync(userCode, factory); + } } \ No newline at end of file