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.

542 lines
24 KiB

3 years ago
3 years ago
3 years ago
6 months ago
2 years ago
3 years ago
4 months ago
3 years ago
6 months ago
3 years ago
6 months ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
6 months ago
4 months ago
3 years ago
3 years ago
2 years ago
6 months ago
4 months ago
3 years ago
3 years ago
2 years ago
6 months ago
4 months ago
3 years ago
6 months ago
3 years ago
6 months ago
3 years ago
6 months ago
3 years ago
3 years ago
6 months ago
3 years ago
3 years ago
6 months ago
3 years ago
4 months ago
3 years ago
6 months ago
3 years ago
6 months ago
3 years ago
3 years ago
6 months ago
3 years ago
3 years ago
6 months ago
3 years ago
3 years ago
3 years ago
6 months ago
3 years ago
6 months ago
3 years ago
3 years ago
6 months ago
3 years ago
6 months ago
3 years ago
6 months ago
3 years ago
6 months ago
3 years ago
3 years ago
6 months ago
3 years ago
3 years ago
3 years ago
6 months ago
4 months ago
6 months ago
3 years ago
3 years ago
4 months ago
4 months ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
4 months ago
1 month ago
4 months ago
3 years ago
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
  4. using Microsoft.EntityFrameworkCore;
  5. using NPOI.Util;
  6. using Shentun.Peis.CardBills;
  7. using Shentun.Peis.CardTypes;
  8. using Shentun.Peis.Enums;
  9. using Shentun.Peis.MedicalConclusionTypes;
  10. using Shentun.Peis.Models;
  11. using Shentun.Peis.PatientRegisters;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using Volo.Abp;
  18. using Volo.Abp.Application.Dtos;
  19. using Volo.Abp.Application.Services;
  20. using Volo.Abp.Domain.Repositories;
  21. using Volo.Abp.Identity;
  22. using Volo.Abp.ObjectMapping;
  23. namespace Shentun.Peis.CardRegisters
  24. {
  25. [ApiExplorerSettings(GroupName = "Work")]
  26. [Authorize]
  27. public class CardRegisterAppService : ApplicationService
  28. {
  29. private readonly IRepository<CardRegister, Guid> _cardRegisterRepository;
  30. private readonly IRepository<CardBill, Guid> _cardBillRepository;
  31. private readonly IRepository<IdentityUser, Guid> _userRepository;
  32. private readonly IRepository<OrganizationUnit, Guid> _organizationUnitRepository;
  33. private readonly CardRegisterManager _manager;
  34. private readonly CardBillManager _cardBillManager;
  35. private readonly IRepository<CardType, Guid> _cardTypeRepository;
  36. private readonly CacheService _cacheService;
  37. private readonly IRepository<PayMode> _payModeRepository;
  38. public CardRegisterAppService(
  39. IRepository<CardRegister, Guid> cardRegisterRepository,
  40. IRepository<CardBill, Guid> cardBillRepository,
  41. IRepository<IdentityUser, Guid> userRepository,
  42. IRepository<OrganizationUnit, Guid> organizationUnitRepository,
  43. CardRegisterManager manager,
  44. CardBillManager cardBillManager,
  45. IRepository<CardType, Guid> cardTypeRepository,
  46. CacheService cacheService,
  47. IRepository<PayMode> payModeRepository)
  48. {
  49. this._cardRegisterRepository = cardRegisterRepository;
  50. this._cardBillRepository = cardBillRepository;
  51. this._userRepository = userRepository;
  52. this._organizationUnitRepository = organizationUnitRepository;
  53. this._manager = manager;
  54. this._cardBillManager = cardBillManager;
  55. _cardTypeRepository = cardTypeRepository;
  56. _cacheService = cacheService;
  57. _payModeRepository = payModeRepository;
  58. }
  59. ///// <summary>
  60. ///// 查询会员卡列表 带联合搜索条件
  61. ///// </summary>
  62. ///// <param name="input"></param>
  63. ///// <returns></returns>
  64. //[HttpPost("api/app/cardregister/getcardregisterlist")]
  65. //public async Task<List<CardRegisterDto>> GetCardRegisterListAsync(GetCardRegisterListDto input)
  66. //{
  67. // if (input != null)
  68. // {
  69. // var cardRegisterList = (await _cardRegisterRepository.GetDbSetAsync())
  70. // .Include(x => x.CardType).AsEnumerable();
  71. // if (input.CardModeId != null)
  72. // {
  73. // cardRegisterList = cardRegisterList.Where(m => m.CardType.CardModeId == input.CardModeId);
  74. // }
  75. // if (input.CardTypeId != null && input.CardTypeId != Guid.Empty)
  76. // {
  77. // cardRegisterList = cardRegisterList.Where(m => m.CardTypeId == input.CardTypeId);
  78. // }
  79. // if (!string.IsNullOrEmpty(input.CardNo))
  80. // {
  81. // cardRegisterList = cardRegisterList.Where(m => m.CardNo == input.CardNo);
  82. // }
  83. // if (!string.IsNullOrEmpty(input.IdNo))
  84. // {
  85. // cardRegisterList = cardRegisterList.Where(m => m.IdNo == input.IdNo);
  86. // }
  87. // if (!string.IsNullOrEmpty(input.CustomerName))
  88. // {
  89. // cardRegisterList = cardRegisterList.Where(m => !string.IsNullOrEmpty(m.CustomerName) && m.CustomerName.Contains(input.CustomerName));
  90. // }
  91. // if (input.IsActive != null)
  92. // {
  93. // cardRegisterList = cardRegisterList.Where(m => m.IsActive == input.IsActive);
  94. // }
  95. // if (!string.IsNullOrEmpty(input.Phone))
  96. // {
  97. // cardRegisterList = cardRegisterList.Where(m => (!string.IsNullOrEmpty(m.Telephone) && m.Telephone.Contains(input.Phone)) || (!string.IsNullOrEmpty(m.MobileTelephone) && m.MobileTelephone.Contains(input.Phone)));
  98. // }
  99. // if (!string.IsNullOrEmpty(input.StartDate) && !string.IsNullOrEmpty(input.EndDate))
  100. // {
  101. // if (input.DateType != null)
  102. // {
  103. // if (input.DateType == '1')
  104. // {
  105. // cardRegisterList = cardRegisterList.Where(m => m.CreationTime >= Convert.ToDateTime(input.StartDate) &&
  106. // m.CreationTime < Convert.ToDateTime(input.EndDate).AddDays(1));
  107. // }
  108. // else if (input.DateType == '2')
  109. // {
  110. // cardRegisterList = cardRegisterList.Where(m => m.ExpiryDate != null && m.ExpiryDate >= Convert.ToDateTime(input.StartDate) &&
  111. // m.ExpiryDate < Convert.ToDateTime(input.EndDate).AddDays(1));
  112. // }
  113. // }
  114. // }
  115. // var organizationUnitQueryable = await _organizationUnitRepository.GetQueryableAsync();
  116. // var userQueryable = await _userRepository.GetQueryableAsync();
  117. // var entlist = from a in cardRegisterList
  118. // join b in userQueryable on a.CreatorId equals b.Id into bb
  119. // from ab in bb.DefaultIfEmpty()
  120. // join c in userQueryable on a.LastModifierId equals c.Id into cc
  121. // from ac in cc.DefaultIfEmpty()
  122. // join d in organizationUnitQueryable on a.MedicalCenterId equals d.Id into dd
  123. // from ad in dd.DefaultIfEmpty()
  124. // select new { a, CreatorName = ab != null ? ab.Surname : "", LastModifierName = ac != null ? ac.Surname : "", OrganizationUnitName = ad != null ? ad.DisplayName : "" };
  125. // var entdtolist = entlist.Select(s => new CardRegisterDto
  126. // {
  127. // CardBalance = s.a.CardBalance,
  128. // IsActive = s.a.IsActive,
  129. // CardModeId = s.a.CardType.CardModeId,
  130. // CardNo = s.a.CardNo,
  131. // CardPassword = s.a.CardPassword,
  132. // CardTypeId = s.a.CardTypeId,
  133. // CardTypeName = s.a.CardType.DisplayName,
  134. // CreationTime = s.a.CreationTime,
  135. // CreatorId = s.a.CreatorId,
  136. // Discount = s.a.Discount,
  137. // ExpiryDate = DataHelper.ConversionDateToString(s.a.ExpiryDate),
  138. // Id = s.a.Id,
  139. // IdNo = s.a.IdNo,
  140. // LastModificationTime = s.a.LastModificationTime,
  141. // LastModifierId = s.a.LastModifierId,
  142. // CustomerName = s.a.CustomerName,
  143. // MobileTelephone = s.a.MobileTelephone,
  144. // Remark = s.a.Remark,
  145. // Telephone = s.a.Telephone,
  146. // CreatorName = s.CreatorName,
  147. // LastModifierName = s.LastModifierName,
  148. // OrganizationUnitName = s.OrganizationUnitName
  149. // }).ToList();
  150. // return entdtolist;
  151. // }
  152. // else
  153. // {
  154. // throw new UserFriendlyException("参数有误");
  155. // }
  156. //}
  157. /// <summary>
  158. /// 查询会员卡列表 带联合搜索条件
  159. /// </summary>
  160. /// <param name="input"></param>
  161. /// <returns></returns>
  162. [HttpPost("api/app/cardregister/getcardregisterlist")]
  163. public async Task<PagedResultDto<CardRegisterDto>> GetCardRegisterListAsync(GetCardRegisterListDto input)
  164. {
  165. if (input != null)
  166. {
  167. var cardRegisterList = from cardRegister in await _cardRegisterRepository.GetQueryableAsync()
  168. join cardType in await _cardTypeRepository.GetQueryableAsync() on cardRegister.CardTypeId equals cardType.Id
  169. join organizationUnit in await _organizationUnitRepository.GetQueryableAsync() on cardRegister.MedicalCenterId equals organizationUnit.Id
  170. select new
  171. {
  172. cardRegister,
  173. cardType,
  174. organizationUnitName = organizationUnit.DisplayName
  175. };
  176. if (input.CardModeId != null)
  177. {
  178. cardRegisterList = cardRegisterList.Where(m => m.cardType.CardModeId == input.CardModeId);
  179. }
  180. if (input.CardTypeId != null && input.CardTypeId != Guid.Empty)
  181. {
  182. cardRegisterList = cardRegisterList.Where(m => m.cardRegister.CardTypeId == input.CardTypeId);
  183. }
  184. if (!string.IsNullOrEmpty(input.CardNo))
  185. {
  186. cardRegisterList = cardRegisterList.Where(m => m.cardRegister.CardNo.ToUpper() == input.CardNo.ToUpper());
  187. }
  188. if (!string.IsNullOrEmpty(input.IdNo))
  189. {
  190. cardRegisterList = cardRegisterList.Where(m => m.cardRegister.IdNo == input.IdNo);
  191. }
  192. if (!string.IsNullOrEmpty(input.CustomerName))
  193. {
  194. cardRegisterList = cardRegisterList.Where(m => !string.IsNullOrEmpty(m.cardRegister.CustomerName) && m.cardRegister.CustomerName.Contains(input.CustomerName));
  195. }
  196. if (input.IsActive != null)
  197. {
  198. cardRegisterList = cardRegisterList.Where(m => m.cardRegister.IsActive == input.IsActive);
  199. }
  200. if (!string.IsNullOrEmpty(input.Phone))
  201. {
  202. cardRegisterList = cardRegisterList.Where(m => (!string.IsNullOrEmpty(m.cardRegister.Telephone) && m.cardRegister.Telephone.Contains(input.Phone)) || (!string.IsNullOrEmpty(m.cardRegister.MobileTelephone) && m.cardRegister.MobileTelephone.Contains(input.Phone)));
  203. }
  204. if (!string.IsNullOrEmpty(input.StartDate) && !string.IsNullOrEmpty(input.EndDate))
  205. {
  206. if (input.DateType != null)
  207. {
  208. if (input.DateType == '1')
  209. {
  210. cardRegisterList = cardRegisterList.Where(m => m.cardRegister.CreationTime >= Convert.ToDateTime(input.StartDate) &&
  211. m.cardRegister.CreationTime < Convert.ToDateTime(input.EndDate).AddDays(1));
  212. }
  213. else if (input.DateType == '2')
  214. {
  215. cardRegisterList = cardRegisterList.Where(m => m.cardRegister.ExpiryDate >= Convert.ToDateTime(input.StartDate) &&
  216. m.cardRegister.ExpiryDate < Convert.ToDateTime(input.EndDate).AddDays(1));
  217. }
  218. }
  219. }
  220. int totalCount = cardRegisterList.Count();
  221. cardRegisterList = cardRegisterList.OrderBy(o => o.cardType.CardModeId).ThenBy(o => o.cardRegister.Id).Skip(input.SkipCount * input.MaxResultCount).Take(input.MaxResultCount);
  222. var entDtoList = cardRegisterList.ToList().Select(s => new CardRegisterDto
  223. {
  224. CardBalance = s.cardRegister.CardBalance,
  225. IsActive = s.cardRegister.IsActive,
  226. CardModeId = s.cardType.CardModeId,
  227. CardNo = s.cardRegister.CardNo,
  228. CardPassword = s.cardRegister.CardPassword,
  229. CardTypeId = s.cardRegister.CardTypeId,
  230. CardTypeName = s.cardType.DisplayName,
  231. CreationTime = s.cardRegister.CreationTime,
  232. CreatorId = s.cardRegister.CreatorId,
  233. Discount = s.cardRegister.Discount,
  234. ExpiryDate = DataHelper.ConversionDateToString(s.cardRegister.ExpiryDate),
  235. Id = s.cardRegister.Id,
  236. IdNo = s.cardRegister.IdNo,
  237. LastModificationTime = s.cardRegister.LastModificationTime,
  238. LastModifierId = s.cardRegister.LastModifierId,
  239. CustomerName = s.cardRegister.CustomerName,
  240. MobileTelephone = s.cardRegister.MobileTelephone,
  241. Remark = s.cardRegister.Remark,
  242. Telephone = s.cardRegister.Telephone,
  243. CreatorName = _cacheService.GetSurnameAsync(s.cardRegister.CreatorId).GetAwaiter().GetResult(),
  244. LastModifierName = _cacheService.GetSurnameAsync(s.cardRegister.LastModifierId).GetAwaiter().GetResult(),
  245. OrganizationUnitName = s.organizationUnitName,
  246. MedicalCenterId = s.cardRegister.MedicalCenterId
  247. }).ToList();
  248. return new PagedResultDto<CardRegisterDto>(totalCount, entDtoList);
  249. }
  250. else
  251. {
  252. throw new UserFriendlyException("参数有误");
  253. }
  254. }
  255. /// <summary>
  256. /// 收费时检索会员卡信息
  257. /// </summary>
  258. /// <param name="input"></param>
  259. /// <returns></returns>
  260. [HttpPost("api/app/CardRegister/GetCardRegisterCharge")]
  261. public async Task<List<GetCardRegisterChargeDto>> GetCardRegisterChargeAsync(GetCardRegisterChargeInputDto input)
  262. {
  263. var cardRegisterList = from cardRegister in await _cardRegisterRepository.GetQueryableAsync()
  264. join cardType in await _cardTypeRepository.GetQueryableAsync() on cardRegister.CardTypeId equals cardType.Id
  265. where cardRegister.IsActive == 'Y'
  266. select new
  267. {
  268. cardRegister,
  269. cardType
  270. };
  271. if (input.CardModeId != null)
  272. {
  273. cardRegisterList = cardRegisterList.Where(m => m.cardType.CardModeId == input.CardModeId);
  274. }
  275. if (!string.IsNullOrEmpty(input.CardNo))
  276. {
  277. cardRegisterList = cardRegisterList.Where(m => m.cardRegister.CardNo.ToUpper() == input.CardNo.ToUpper());
  278. }
  279. if (!string.IsNullOrEmpty(input.IdNo))
  280. {
  281. cardRegisterList = cardRegisterList.Where(m => m.cardRegister.IdNo == input.IdNo);
  282. }
  283. if (!string.IsNullOrEmpty(input.CustomerName))
  284. {
  285. cardRegisterList = cardRegisterList.Where(m => m.cardRegister.CustomerName == input.CustomerName);
  286. }
  287. if (!string.IsNullOrEmpty(input.Phone))
  288. {
  289. cardRegisterList = cardRegisterList.Where(m => m.cardRegister.Telephone == input.Phone || m.cardRegister.MobileTelephone == input.Phone);
  290. }
  291. var entDtoList = cardRegisterList.ToList().Select(s => new GetCardRegisterChargeDto
  292. {
  293. CardBalance = s.cardRegister.CardBalance,
  294. CardModeId = s.cardType.CardModeId,
  295. CardNo = s.cardRegister.CardNo,
  296. CardTypeName = s.cardType.DisplayName,
  297. Discount = s.cardRegister.Discount,
  298. ExpiryDate = DataHelper.ConversionDateToString(s.cardRegister.ExpiryDate),
  299. Id = s.cardRegister.Id,
  300. IdNo = s.cardRegister.IdNo,
  301. CustomerName = s.cardRegister.CustomerName,
  302. MobileTelephone = s.cardRegister.MobileTelephone,
  303. Remark = s.cardRegister.Remark,
  304. Telephone = s.cardRegister.Telephone
  305. }).ToList();
  306. return entDtoList;
  307. }
  308. /// <summary>
  309. /// 根据ID查实体内容
  310. /// </summary>
  311. /// <param name="id"></param>
  312. /// <returns></returns>
  313. [HttpGet("api/app/cardregister/get")]
  314. public async Task<CardRegisterDto> GetAsync(Guid id)
  315. {
  316. var userList = await _userRepository.GetListAsync();
  317. var entity = await _cardRegisterRepository.GetAsync(id);
  318. var entityDto = ObjectMapper.Map<CardRegister, CardRegisterDto>(entity);
  319. entityDto.CreatorName = EntityHelper.GetSurnameNoSql(userList, entityDto.CreatorId);
  320. entityDto.LastModifierName = EntityHelper.GetSurnameNoSql(userList, entityDto.LastModifierId);
  321. return entityDto;
  322. }
  323. /// <summary>
  324. /// 创建
  325. /// </summary>
  326. /// <param name="input"></param>
  327. /// <returns></returns>
  328. [HttpPost("api/app/cardregister/create")]
  329. public async Task<CardRegisterDto> CreateAsync(CreateCardRegisterDto input)
  330. {
  331. Guid cardRegisterId = GuidGenerator.Create();
  332. var createEntity = ObjectMapper.Map<CreateCardRegisterDto, CardRegister>(input);
  333. var entity = await _manager.CreateAsync(createEntity, cardRegisterId);
  334. entity = await _cardRegisterRepository.InsertAsync(entity);
  335. var dto = ObjectMapper.Map<CardRegister, CardRegisterDto>(entity);
  336. return dto;
  337. }
  338. /// <summary>
  339. /// 修改
  340. /// </summary>
  341. /// <param name="id"></param>
  342. /// <param name="input"></param>
  343. /// <returns></returns>
  344. [HttpPost("api/app/cardregister/update")]
  345. public async Task<CardRegisterDto> UpdateAsync(Guid id, UpdateCardRegisterDto input)
  346. {
  347. var entity = await _cardRegisterRepository.GetAsync(id);
  348. var sourceEntity = ObjectMapper.Map<UpdateCardRegisterDto, CardRegister>(input);
  349. _manager.UpdateAsync(sourceEntity, entity);
  350. entity = await _cardRegisterRepository.UpdateAsync(entity);
  351. return ObjectMapper.Map<CardRegister, CardRegisterDto>(entity);
  352. }
  353. /// <summary>
  354. /// 删除
  355. /// </summary>
  356. /// <param name="id"></param>
  357. /// <returns></returns>
  358. [HttpPost("api/app/cardregister/delete")]
  359. public Task DeleteAsync(Guid id)
  360. {
  361. throw new Exception("卡禁止删除");
  362. }
  363. /// <summary>
  364. /// 更新启用状态
  365. /// </summary>
  366. /// <param name="id"></param>
  367. /// <param name="updateCardRegisterActiveDto"></param>
  368. /// <returns></returns>
  369. [HttpPost("api/app/cardregister/updateactive")]
  370. public async Task UpdateActive(Guid id, UpdateCardRegisterActiveDto updateCardRegisterActiveDto)
  371. {
  372. Check.NotNull<UpdateCardRegisterActiveDto>(updateCardRegisterActiveDto, nameof(updateCardRegisterActiveDto));
  373. var entity = await _cardRegisterRepository.GetAsync(id);
  374. await _manager.UpdateActive(entity, updateCardRegisterActiveDto.IsActive);
  375. await _cardRegisterRepository.UpdateAsync(entity);
  376. }
  377. /*
  378. /// <summary>
  379. /// 会员卡充值 delete by zhh 2024-03-17
  380. /// </summary>
  381. /// <returns></returns>
  382. [HttpPost("api/app/cardregister/cardregisterrecharge")]
  383. public async Task CardRegisterRechargeAsync(CardRegisterRechargeDto input)
  384. {
  385. if (input != null)
  386. {
  387. var cardRegisterEnt = await _cardRegisterRepository.FindAsync(m => m.Id == input.CardRegisterId);
  388. if (cardRegisterEnt != null)
  389. {
  390. cardRegisterEnt.CardBalance += input.RechargeAmount;
  391. await _cardRegisterRepository.UpdateAsync(cardRegisterEnt);
  392. //增加充值记录
  393. var cardBill = new CardBill(GuidGenerator.Create())
  394. {
  395. BillFlag = '2',
  396. BillMoney = input.RechargeAmount,
  397. CardRegisterId = input.CardRegisterId,
  398. PayModeId = input.PayModeId
  399. };
  400. cardBill = _cardBillManager.CreateAsync(cardBill);
  401. await _cardBillRepository.InsertAsync(cardBill);
  402. }
  403. else
  404. {
  405. throw new UserFriendlyException("会员卡不存在");
  406. }
  407. }
  408. else
  409. {
  410. throw new UserFriendlyException("参数有误");
  411. }
  412. }
  413. */
  414. /// <summary>
  415. /// 会员卡充值、退费
  416. /// </summary>
  417. /// <returns></returns>
  418. [HttpPost("api/app/cardregister/addcardbill")]
  419. public async Task AddCardBill(CreateCardBillDto createCardBillDto)
  420. {
  421. DataHelper.CheckEntityIsNull(createCardBillDto);
  422. //Check.NotNull<CreateCardBillDto>(createCardBillDto, "CreateCardBillDto");
  423. var cardRegister = await _cardRegisterRepository.GetAsync(createCardBillDto.CardRegisterId);
  424. var cardBill = _manager.CreateCardBill(cardRegister,
  425. createCardBillDto.PayModeId, createCardBillDto.BillFlag, createCardBillDto.BillMoney);
  426. await _cardRegisterRepository.UpdateAsync(cardRegister);
  427. await _cardBillRepository.InsertAsync(cardBill);
  428. }
  429. /// <summary>
  430. /// excel文档创建会员卡
  431. /// </summary>
  432. /// <returns></returns>
  433. [HttpPost("api/app/CardRegister/BatchCreateCardRegisterByExcel")]
  434. public async Task BatchCreateCardRegisterByExcelAsync(BatchCreateCardRegisterByExcelInputDto input)
  435. {
  436. var cardTypeEntity = await _cardTypeRepository.FirstOrDefaultAsync(f => f.DisplayName == input.CardTypeName.Trim());
  437. if (cardTypeEntity == null)
  438. {
  439. throw new UserFriendlyException($"当前数据卡类型不存在,卡号:{input.CardNo},姓名:{input.CustomerName}");
  440. }
  441. Guid cardRegisterId = GuidGenerator.Create();
  442. var cardRegisterEntity = new CardRegister
  443. {
  444. CardNo = input.CardNo,
  445. CardPassword = "",
  446. CardTypeId = cardTypeEntity.Id,
  447. CustomerName = input.CustomerName,
  448. Discount = input.Discount,
  449. ExpiryDate = DateTime.Parse(input.ExpiryDate),
  450. IdNo = input.IdNo,
  451. IsActive = 'Y',
  452. MobileTelephone = input.MobileTelephone,
  453. Remark = input.Remark,
  454. Telephone = input.Telephone,
  455. MedicalCenterId = input.MedicalCenterId
  456. };
  457. cardRegisterEntity = await _manager.CreateAsync(cardRegisterEntity, cardRegisterId);
  458. if (input.CardBalance > 0)
  459. {
  460. if (string.IsNullOrWhiteSpace(input.PayModeName))
  461. {
  462. throw new UserFriendlyException("充值支付方式不能为空");
  463. }
  464. var payModeEntity = await _payModeRepository.FirstOrDefaultAsync(f => f.DisplayName == input.PayModeName.Trim());
  465. if (payModeEntity == null)
  466. {
  467. throw new UserFriendlyException($"当前数据充值支付方式不存在,卡号:{input.CardNo},姓名:{input.CustomerName}");
  468. }
  469. var cardBillEntity = _manager.CreateCardBill(cardRegisterEntity, payModeEntity.Id, CardBillFlag.Charge, input.CardBalance);
  470. await _cardRegisterRepository.InsertAsync(cardRegisterEntity);
  471. await _cardBillRepository.InsertAsync(cardBillEntity);
  472. }
  473. else
  474. {
  475. await _cardRegisterRepository.InsertAsync(cardRegisterEntity);
  476. }
  477. }
  478. }
  479. }