|
|
|
@ -563,150 +563,154 @@ namespace Shentun.Peis.RegisterAsbitems |
|
|
|
[HttpPost("api/app/registerasbitem/registerasbitemcharge")] |
|
|
|
public async Task<RegisterCheckAsbitemChargeDto> RegisterAsbitemChargeAsync(RegisterCheckAsbitemCheckChargeRequestDto input) |
|
|
|
{ |
|
|
|
if (input != null && input.Asbitems.Any() && input.ChargePays.Any()) |
|
|
|
if (!input.Asbitems.Any()) |
|
|
|
{ |
|
|
|
#region 验证是否多张同样的卡
|
|
|
|
throw new UserFriendlyException("收费项目不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
if (!input.ChargePays.Any()) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("收费方式不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
#region 验证是否多张同样的卡
|
|
|
|
|
|
|
|
var cardList = input.ChargePays.Where(m => m.PayModeId == "05").ToList(); |
|
|
|
if (cardList.Any()) |
|
|
|
var cardList = input.ChargePays.Where(m => m.PayModeId == "05").ToList(); |
|
|
|
if (cardList.Any()) |
|
|
|
{ |
|
|
|
if (cardList.GroupBy(g => g.CardRegisterId).Count() < cardList.Count) |
|
|
|
{ |
|
|
|
if (cardList.GroupBy(g => g.CardRegisterId).Count() < cardList.Count) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("同一张会员卡不能重复提交"); |
|
|
|
} |
|
|
|
throw new UserFriendlyException("同一张会员卡不能重复提交"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 验证项目金额跟收费的金额合计是否一致
|
|
|
|
#region 验证项目金额跟收费的金额合计是否一致
|
|
|
|
|
|
|
|
if (input.Asbitems.Sum(s => s.ChargePrice * s.Amount) != input.ChargePays.Sum(s => s.ChargeMoney)) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("收费金额合计跟项目金额合计不一致"); |
|
|
|
} |
|
|
|
if (input.Asbitems.Sum(s => s.ChargePrice * s.Amount) != input.ChargePays.Sum(s => s.ChargeMoney)) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("收费金额合计跟项目金额合计不一致"); |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
//更新收费状态
|
|
|
|
List<RegisterCheckAsbitem> registerAsbitems = await _registerCheckAsbitemRepository.GetListAsync(m => input.Asbitems.Select(s => s.RegisterAsbitemId).Contains(m.Id)); |
|
|
|
registerAsbitems.ForEach(f => f.IsCharge = 'Y'); |
|
|
|
#region 插入主表Charge
|
|
|
|
Guid chargeId = GuidGenerator.Create(); |
|
|
|
//更新收费状态
|
|
|
|
List<RegisterCheckAsbitem> registerAsbitems = await _registerCheckAsbitemRepository.GetListAsync(m => input.Asbitems.Select(s => s.RegisterAsbitemId).Contains(m.Id)); |
|
|
|
registerAsbitems.ForEach(f => f.IsCharge = 'Y'); |
|
|
|
#region 插入主表Charge
|
|
|
|
Guid chargeId = GuidGenerator.Create(); |
|
|
|
|
|
|
|
Charge charge = new Charge(chargeId) |
|
|
|
{ |
|
|
|
ChargeFlag = '0', |
|
|
|
InvoiceNo = input.InvoiceNo, |
|
|
|
InvoiceOrgName = input.InvoiceOrgName, |
|
|
|
PatientRegisterId = input.PatientRegisterId |
|
|
|
}; |
|
|
|
Charge charge = new Charge(chargeId) |
|
|
|
{ |
|
|
|
ChargeFlag = '0', |
|
|
|
InvoiceNo = input.InvoiceNo, |
|
|
|
InvoiceOrgName = input.InvoiceOrgName, |
|
|
|
PatientRegisterId = input.PatientRegisterId |
|
|
|
}; |
|
|
|
|
|
|
|
var charge_new = await _chargeRepository.InsertAsync(charge); |
|
|
|
var charge_new = await _chargeRepository.InsertAsync(charge); |
|
|
|
|
|
|
|
#region 收费项目
|
|
|
|
#region 收费项目
|
|
|
|
|
|
|
|
List<ChargeAsbitem> chargeAsbitems = new List<ChargeAsbitem>(); |
|
|
|
List<ChargeAsbitem> chargeAsbitems = new List<ChargeAsbitem>(); |
|
|
|
|
|
|
|
foreach (var item in input.Asbitems) |
|
|
|
foreach (var item in input.Asbitems) |
|
|
|
{ |
|
|
|
chargeAsbitems.Add(new ChargeAsbitem |
|
|
|
{ |
|
|
|
chargeAsbitems.Add(new ChargeAsbitem |
|
|
|
{ |
|
|
|
Amount = item.Amount, |
|
|
|
AsbitemId = item.AsbitemId, |
|
|
|
ChargeId = chargeId, |
|
|
|
RegisterAsbitemId = item.RegisterAsbitemId, |
|
|
|
ChargePrice = item.ChargePrice |
|
|
|
}); |
|
|
|
Amount = item.Amount, |
|
|
|
AsbitemId = item.AsbitemId, |
|
|
|
ChargeId = chargeId, |
|
|
|
RegisterAsbitemId = item.RegisterAsbitemId, |
|
|
|
ChargePrice = item.ChargePrice |
|
|
|
}); |
|
|
|
|
|
|
|
registerAsbitems.Find(f => f.Id == item.RegisterAsbitemId).ChargePrice = item.ChargePrice; |
|
|
|
registerAsbitems.Find(f => f.Id == item.RegisterAsbitemId).ChargePrice = item.ChargePrice; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
await _chargeAsbitemRepository.InsertManyAsync(chargeAsbitems); |
|
|
|
await _chargeAsbitemRepository.InsertManyAsync(chargeAsbitems); |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 收费方式
|
|
|
|
List<ChargePay> chargePays = new List<ChargePay>(); |
|
|
|
#region 收费方式
|
|
|
|
List<ChargePay> chargePays = new List<ChargePay>(); |
|
|
|
|
|
|
|
foreach (var item in input.ChargePays) |
|
|
|
foreach (var item in input.ChargePays) |
|
|
|
{ |
|
|
|
if (item.PayModeId == "05") |
|
|
|
{ |
|
|
|
if (item.PayModeId == "05") |
|
|
|
{ |
|
|
|
|
|
|
|
Guid cardBillId = GuidGenerator.Create(); |
|
|
|
|
|
|
|
//会员卡
|
|
|
|
CardBill cardBill = new CardBill(cardBillId) |
|
|
|
{ |
|
|
|
PayModeId = item.PayModeId, |
|
|
|
BillFlag = CardBillFlag.Deduction, |
|
|
|
BillMoney = item.ChargeMoney, |
|
|
|
CardRegisterId = item.CardRegisterId.Value |
|
|
|
}; |
|
|
|
cardBill = _cardBillManager.CreateAsync(cardBill); |
|
|
|
await _cardBillRepository.InsertAsync(cardBill); |
|
|
|
Guid cardBillId = GuidGenerator.Create(); |
|
|
|
|
|
|
|
|
|
|
|
//会员卡
|
|
|
|
CardBill cardBill = new CardBill(cardBillId) |
|
|
|
{ |
|
|
|
PayModeId = item.PayModeId, |
|
|
|
BillFlag = CardBillFlag.Deduction, |
|
|
|
BillMoney = item.ChargeMoney, |
|
|
|
CardRegisterId = item.CardRegisterId.Value |
|
|
|
}; |
|
|
|
cardBill = _cardBillManager.CreateAsync(cardBill); |
|
|
|
await _cardBillRepository.InsertAsync(cardBill); |
|
|
|
|
|
|
|
chargePays.Add(new ChargePay |
|
|
|
{ |
|
|
|
ChargeMoney = item.ChargeMoney, |
|
|
|
PayModeId = item.PayModeId, |
|
|
|
ChargeId = charge_new.Id, |
|
|
|
CardBillId = cardBillId |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
#region 扣除会员卡余额
|
|
|
|
chargePays.Add(new ChargePay |
|
|
|
{ |
|
|
|
ChargeMoney = item.ChargeMoney, |
|
|
|
PayModeId = item.PayModeId, |
|
|
|
ChargeId = charge_new.Id, |
|
|
|
CardBillId = cardBillId |
|
|
|
}); |
|
|
|
|
|
|
|
var cardRegisterEnt = await _cardRegisterRepository.FirstOrDefaultAsync(f => f.Id == item.CardRegisterId.Value); |
|
|
|
if (cardRegisterEnt != null) |
|
|
|
{ |
|
|
|
if (item.ChargeMoney > cardRegisterEnt.CardBalance) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("会员卡余额不足"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
cardRegisterEnt.CardBalance -= item.ChargeMoney; |
|
|
|
await _cardRegisterRepository.UpdateAsync(cardRegisterEnt); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
#endregion
|
|
|
|
#region 扣除会员卡余额
|
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
var cardRegisterEnt = await _cardRegisterRepository.FirstOrDefaultAsync(f => f.Id == item.CardRegisterId.Value); |
|
|
|
if (cardRegisterEnt != null) |
|
|
|
{ |
|
|
|
chargePays.Add(new ChargePay |
|
|
|
if (item.ChargeMoney > cardRegisterEnt.CardBalance) |
|
|
|
{ |
|
|
|
ChargeMoney = item.ChargeMoney, |
|
|
|
PayModeId = item.PayModeId, |
|
|
|
ChargeId = charge_new.Id |
|
|
|
}); |
|
|
|
throw new UserFriendlyException("会员卡余额不足"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
cardRegisterEnt.CardBalance -= item.ChargeMoney; |
|
|
|
await _cardRegisterRepository.UpdateAsync(cardRegisterEnt); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
chargePays.Add(new ChargePay |
|
|
|
{ |
|
|
|
ChargeMoney = item.ChargeMoney, |
|
|
|
PayModeId = item.PayModeId, |
|
|
|
ChargeId = charge_new.Id |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
await _chargePayRepository.InsertManyAsync(chargePays); |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
await _chargePayRepository.InsertManyAsync(chargePays); |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 修改收费状态
|
|
|
|
#region 修改收费状态
|
|
|
|
|
|
|
|
await _registerCheckAsbitemRepository.UpdateManyAsync(registerAsbitems); |
|
|
|
await _registerCheckAsbitemRepository.UpdateManyAsync(registerAsbitems); |
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
return new RegisterCheckAsbitemChargeDto { code = 1, msg = "收费成功", ChargeId = charge_new.Id }; |
|
|
|
|
|
|
|
return new RegisterCheckAsbitemChargeDto { code = 1, msg = "收费成功", ChargeId = charge_new.Id }; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
throw new UserFriendlyException("参数有误"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|