using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;
using Yi.Framework.Bbs.Domain.Shared.Enums;
namespace Yi.Framework.Bbs.Domain.Entities.Bank
{
///
/// 银行卡
///
[SugarTable("BankCard")]
public class BankCardAggregateRoot : AggregateRoot, IHasCreationTime
{
public BankCardAggregateRoot()
{
}
public BankCardAggregateRoot(Guid userId)
{
this.UserId = userId;
}
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
public override Guid Id { get; protected set; }
public DateTime CreationTime { get; set; }
///
/// 上一次存款日期
///
public DateTime? LastDepositTime { get; set; }
///
/// 上一次取款日期
///
public DateTime? LastDrawTime { get; set; }
///
/// 用户id
///
public Guid UserId { get; set; }
///
/// 当前存储的钱
///
public decimal StorageMoney { get; set; } = 0;
///
/// 最大可存储的钱钱
///
public decimal MaxStorageMoney { get; set; } = 100;
///
/// 满期限时间,可空
///
public DateTime? FulltermTime { get; set; }
///
/// 银行卡状态
///
public BankCardStateEnum BankCardState { get; set; } = BankCardStateEnum.Unused;
public bool IsStorageFull()
{
if (FulltermTime is null)
{
return false;
}
return DateTime.Now >= FulltermTime;
}
public void SetDrawMoney()
{
this.BankCardState = BankCardStateEnum.Unused;
LastDrawTime = DateTime.Now;
this.FulltermTime = null;
this.StorageMoney = 0;
}
public void SetStorageMoney(decimal storageMoney)
{
if (storageMoney > MaxStorageMoney)
{
throw new UserFriendlyException($"存款数不能大于该卡的上限-【{MaxStorageMoney}】钱钱");
}
StorageMoney = storageMoney;
LastDepositTime = DateTime.Now;
FulltermTime = LastDepositTime + TimeSpan.FromDays(3);
this.BankCardState = BankCardStateEnum.Wait;
}
}
}