You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
191 lines
7.3 KiB
191 lines
7.3 KiB
using Shentun.Peis.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using TencentCloud.Ic.V20190307.Models;
|
|
using TencentCloud.Sqlserver.V20180328.Models;
|
|
using Volo.Abp;
|
|
using Volo.Abp.Domain.Repositories;
|
|
using Volo.Abp.Domain.Services;
|
|
using static log4net.Appender.RollingFileAppender;
|
|
|
|
namespace Shentun.Peis.CardRegisters
|
|
{
|
|
public class CardRegisterManager : DomainService
|
|
{
|
|
private readonly IRepository<CardRegister, Guid> _repository;
|
|
public CardRegisterManager(IRepository<CardRegister, Guid> repository)
|
|
{
|
|
_repository = repository;
|
|
|
|
}
|
|
/// <summary>
|
|
/// 创建
|
|
/// </summary>
|
|
/// <param name="entity"></param>
|
|
/// <returns></returns>
|
|
public async Task<CardRegister> CreateAsync(
|
|
CardRegister entity
|
|
)
|
|
{
|
|
Verify(entity);
|
|
var queryable = await _repository.GetQueryableAsync();
|
|
var findedEntity = queryable.Where(x => x.CardNo == entity.CardNo && x.IsActive == 'Y').FirstOrDefault();
|
|
if (findedEntity != null)
|
|
{
|
|
throw new UserFriendlyException($"卡号已经被{findedEntity.CustomerName}使用");
|
|
}
|
|
return new CardRegister(
|
|
GuidGenerator.Create()
|
|
)
|
|
{
|
|
CardBalance = 0,
|
|
IsActive = entity.IsActive,
|
|
CardNo = entity.CardNo,
|
|
CardPassword = entity.CardPassword,
|
|
CardTypeId = entity.CardTypeId,
|
|
CustomerName = entity.CustomerName,
|
|
Discount = entity.Discount,
|
|
ExpiryDate = entity.ExpiryDate,
|
|
IdNo = entity.IdNo,
|
|
MobileTelephone = entity.MobileTelephone,
|
|
OrganizationUnitId = entity.OrganizationUnitId,
|
|
Remark = entity.Remark,
|
|
Telephone = entity.Telephone
|
|
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新
|
|
/// </summary>
|
|
/// <param name="sourceEntity"></param>
|
|
/// <param name="targetEntity"></param>
|
|
/// <returns></returns>
|
|
public void UpdateAsync(
|
|
CardRegister sourceEntity,
|
|
CardRegister targetEntity
|
|
)
|
|
{
|
|
DataHelper.CheckVerifyData(sourceEntity);
|
|
DataHelper.CheckVerifyData(targetEntity);
|
|
Verify(sourceEntity);
|
|
if (sourceEntity.CardNo != targetEntity.CardNo)
|
|
{
|
|
throw new ArgumentException("卡号不允许修改");
|
|
}
|
|
if (sourceEntity.CardBalance != targetEntity.CardBalance)
|
|
{
|
|
throw new ArgumentException("卡余额不允许修改");
|
|
}
|
|
targetEntity.IsActive = sourceEntity.IsActive;
|
|
targetEntity.CardPassword = sourceEntity.CardPassword;
|
|
targetEntity.CardTypeId = sourceEntity.CardTypeId;
|
|
targetEntity.CustomerName = sourceEntity.CustomerName;
|
|
targetEntity.Discount = sourceEntity.Discount;
|
|
targetEntity.ExpiryDate = sourceEntity.ExpiryDate;
|
|
targetEntity.IdNo = sourceEntity.IdNo;
|
|
targetEntity.MobileTelephone = sourceEntity.MobileTelephone;
|
|
targetEntity.OrganizationUnitId = sourceEntity.OrganizationUnitId;
|
|
targetEntity.Remark = sourceEntity.Remark;
|
|
targetEntity.Telephone = sourceEntity.Telephone;
|
|
|
|
}
|
|
|
|
public async Task UpdateActive(CardRegister entity, char isActive)
|
|
{
|
|
DataHelper.CheckVerifyData(entity);
|
|
DataHelper.CheckVerifyData(isActive, "使用标志", true);
|
|
|
|
if (isActive == 'N')
|
|
{
|
|
entity.IsActive = isActive;
|
|
}
|
|
else
|
|
{
|
|
//检查卡号是否用过
|
|
var queryable = await _repository.GetQueryableAsync();
|
|
var findedEntity = queryable.Where(x => x.Id != entity.Id && x.CardNo == entity.CardNo && x.IsActive == 'Y').FirstOrDefault();
|
|
if (findedEntity != null)
|
|
{
|
|
throw new UserFriendlyException($"卡号已经被{findedEntity.CustomerName}使用");
|
|
}
|
|
}
|
|
}
|
|
|
|
public CardBill CreateCardBill(CardRegister entity, string payModeId, char billFlag, decimal amount)
|
|
{
|
|
DataHelper.CheckVerifyData(entity);
|
|
DataHelper.CheckVerifyData(billFlag, "记账标志");
|
|
if (amount == 0)
|
|
{
|
|
throw new ArgumentException("金额等于0");
|
|
};
|
|
if (billFlag == Shentun.Peis.Enums.CardBillFlag.Charge && amount < 0)
|
|
{
|
|
throw new ArgumentException("充值金额不能小于0");
|
|
}
|
|
else if (billFlag != Shentun.Peis.Enums.CardBillFlag.Charge && amount > 0)
|
|
{
|
|
throw new ArgumentException("扣费或退费金额不能大于0");
|
|
}
|
|
if ((entity.CardBalance + amount) < 0)
|
|
{
|
|
throw new ArgumentException($"扣费或退费金额不能小于余额{entity.CardBalance}");
|
|
}
|
|
entity.CardBalance += amount;
|
|
var cardBill = new CardBill(GuidGenerator.Create())
|
|
{
|
|
CardRegisterId = entity.Id,
|
|
PayModeId = payModeId,
|
|
BillFlag = billFlag,
|
|
BillMoney = amount,
|
|
};
|
|
return cardBill;
|
|
}
|
|
|
|
public void AddCardBill(CardRegister entity, string payModeId, char billFlag, decimal amount)
|
|
{
|
|
DataHelper.CheckVerifyData(entity);
|
|
DataHelper.CheckVerifyData(billFlag, "记账标志");
|
|
if (amount == 0)
|
|
{
|
|
throw new ArgumentException("金额等于0");
|
|
};
|
|
if (billFlag == Shentun.Peis.Enums.CardBillFlag.Charge && amount < 0)
|
|
{
|
|
throw new ArgumentException("充值金额不能小于0");
|
|
}
|
|
else if (billFlag != Shentun.Peis.Enums.CardBillFlag.Charge && amount > 0)
|
|
{
|
|
throw new ArgumentException("扣费或退费金额不能大于0");
|
|
}
|
|
if ((entity.CardBalance + amount) < 0)
|
|
{
|
|
throw new ArgumentException($"扣费或退费金额不能小于余额{entity.CardBalance}");
|
|
}
|
|
entity.CardBalance += amount;
|
|
var cardBill = new CardBill(GuidGenerator.Create())
|
|
{
|
|
CardRegisterId = entity.Id,
|
|
PayModeId = payModeId,
|
|
BillFlag = billFlag,
|
|
BillMoney = amount,
|
|
};
|
|
entity.CardBills.Add(cardBill);
|
|
}
|
|
private void Verify(CardRegister entity)
|
|
{
|
|
DataHelper.CheckVerifyData(entity);
|
|
DataHelper.CheckVerifyData(entity.CardNo, "卡号");
|
|
DataHelper.CheckVerifyData(entity.CustomerName, "领用者");
|
|
DataHelper.CheckVerifyData(entity.IdNo, "身份证号");
|
|
DataHelper.CheckVerifyData(entity.IdNo, "手机号");
|
|
DataHelper.CheckVerifyData(entity.CardTypeId, "卡类型");
|
|
DataHelper.CheckVerifyData(entity.OrganizationUnitId, "体检中心");
|
|
DataHelper.CheckVerifyData(entity.IsActive, "使用标志", true);
|
|
}
|
|
}
|
|
}
|