feat: 对接银行模块接口,即将上线功能
This commit is contained in:
@@ -1,13 +1,31 @@
|
||||
using Volo.Abp.Domain.Services;
|
||||
using Volo.Abp.EventBus.Local;
|
||||
using Yi.Framework.Bbs.Domain.Entities.Bank;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Enums;
|
||||
using Yi.Framework.Bbs.Domain.Shared.Etos;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.Bbs.Domain.Managers
|
||||
{
|
||||
public class BankManager : DomainService
|
||||
{
|
||||
private ISqlSugarRepository<BankCardEntity> _repository;
|
||||
private ILocalEventBus _localEventBus;
|
||||
private ISqlSugarRepository<InterestRecordsEntity> _interestRepository;
|
||||
public BankManager(ISqlSugarRepository<BankCardEntity> repository, ILocalEventBus localEventBus, ISqlSugarRepository<InterestRecordsEntity> interestRepository)
|
||||
{
|
||||
_repository = repository;
|
||||
_localEventBus = localEventBus;
|
||||
_interestRepository = interestRepository;
|
||||
}
|
||||
|
||||
public BankManager() { }
|
||||
|
||||
public decimal CurrentInterestRate => GetCurrentInterestRate();
|
||||
private decimal GetCurrentInterestRate()
|
||||
{
|
||||
//先判断时间是否与当前时间差1小时,小于1小时直接返回即可,可以由一个单例类提供
|
||||
GetThirdPartyValue();
|
||||
return 1.30m;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取第三方的值
|
||||
@@ -22,39 +40,96 @@ namespace Yi.Framework.Bbs.Domain.Managers
|
||||
/// 创建一个记录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public InterestRecordsEntity CreateInterestRecords()
|
||||
public async Task<InterestRecordsEntity> CreateInterestRecordsAsync()
|
||||
{
|
||||
return new InterestRecordsEntity();
|
||||
//获取最新的实体
|
||||
var newEntity = await _interestRepository._DbQueryable.OrderByDescending(x => x.CreationTime).FirstAsync();
|
||||
decimal oldValue = 1.3m;
|
||||
if (newEntity is not null)
|
||||
{
|
||||
oldValue = newEntity.Value;
|
||||
}
|
||||
var currentValue = GetThirdPartyValue();
|
||||
var entity = new InterestRecordsEntity(currentValue, false, oldValue);
|
||||
var output = await _interestRepository.InsertReturnEntityAsync(entity);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 给用户申请银行卡
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task ApplyingBankCardAsync(Guid userId)
|
||||
public async Task ApplyingBankCardAsync(Guid userId, int cardNumber)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
var entities = Enumerable.Range(1, cardNumber).Select(x => new BankCardEntity(userId)).ToList();
|
||||
await _repository.InsertManyAsync(entities);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 给银行卡提款
|
||||
/// 进行银行卡提款
|
||||
/// </summary>
|
||||
/// <param name="CardId"></param>
|
||||
/// <param name="cardId"></param>
|
||||
/// <returns></returns>
|
||||
public Task DrawMoneyAsync(Guid CardId)
|
||||
public async Task DrawMoneyAsync(Guid cardId)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
var entity = await _repository.GetByIdAsync(cardId);
|
||||
if (entity.BankCardState == BankCardStateEnum.Unused)
|
||||
{
|
||||
throw new UserFriendlyException("当前银行卡状态不能提款");
|
||||
}
|
||||
|
||||
//这里其实不存在这个状态,只有等待状态,不需要去主动触发,前端判断即可
|
||||
if (entity.BankCardState == BankCardStateEnum.Full)
|
||||
{
|
||||
throw new UserFriendlyException("当前银行卡状态不能存款");
|
||||
}
|
||||
|
||||
//可以提款
|
||||
if (entity.BankCardState == BankCardStateEnum.Wait)
|
||||
{
|
||||
decimal changeMoney = 0;
|
||||
//判断是否存满时间
|
||||
if (entity.IsStorageFull())
|
||||
{
|
||||
changeMoney = this.CurrentInterestRate * entity.StorageMoney;
|
||||
}
|
||||
else
|
||||
{
|
||||
changeMoney = entity.StorageMoney;
|
||||
}
|
||||
|
||||
//提款
|
||||
entity.SetDrawMoney();
|
||||
await _repository.UpdateAsync(entity);
|
||||
|
||||
//打钱,该卡状态钱更新,并提款加到用户钱钱里
|
||||
await _localEventBus.PublishAsync(new MoneyChangeEventArgs(entity.UserId, changeMoney));
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 给银行卡存款
|
||||
/// </summary>
|
||||
/// <param name="CardId"></param>
|
||||
/// <param name="cardId"></param>
|
||||
/// <param name="moneyNum"></param>
|
||||
/// <returns></returns>
|
||||
public Task DepositAsync(Guid CardId, decimal moneyNum)
|
||||
public async Task DepositAsync(Guid cardId, decimal moneyNum)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
var entity = await _repository.GetByIdAsync(cardId);
|
||||
if (entity.BankCardState != BankCardStateEnum.Unused)
|
||||
{
|
||||
throw new UserFriendlyException("当前银行卡状态不能存款");
|
||||
}
|
||||
//存款
|
||||
entity.SetStorageMoney(moneyNum);
|
||||
|
||||
await _repository.UpdateAsync(entity);
|
||||
await _localEventBus.PublishAsync(new MoneyChangeEventArgs(entity.UserId, -moneyNum));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user