From 5d77e5475c479b1c8fc53589b66efe7e06cb3356 Mon Sep 17 00:00:00 2001
From: wxd <123@qq.com>
Date: Sun, 24 Nov 2024 20:35:30 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BD=93=E6=A3=80=E9=80=80=E6=AC=BE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AppQueueRegisterPlugIns.cs | 15 ++
.../AppointPatientRegisterIdsInputDto.cs | 14 ++
...ppointPatientRegisterWithAsbitemListDto.cs | 72 ++++++++
...dateAppointPatientAsbitemStatusInputDto.cs | 27 +++
.../AppointPatientRegisterAppService.cs | 156 +++++++++++++++++-
.../Charges/ChargeAppService.cs | 29 +++-
.../Charges/ChargeManager.cs | 5 +-
7 files changed, 315 insertions(+), 3 deletions(-)
create mode 100644 src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/AppointPatientRegisterIdsInputDto.cs
create mode 100644 src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/GerAppointPatientRegisterWithAsbitemListDto.cs
create mode 100644 src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/UpdateAppointPatientAsbitemStatusInputDto.cs
diff --git a/Shentun.WebPeis.Plugins/AppQueueRegisterPlugIns.cs b/Shentun.WebPeis.Plugins/AppQueueRegisterPlugIns.cs
index 6816232..34728a2 100644
--- a/Shentun.WebPeis.Plugins/AppQueueRegisterPlugIns.cs
+++ b/Shentun.WebPeis.Plugins/AppQueueRegisterPlugIns.cs
@@ -28,6 +28,7 @@ namespace Shentun.WebPeis.Plugins
private string? _appPassword;
private string? _appQueueRegisterUrl;
private string? _appIsPeisRegisterUrl;
+ private string? _appUpdateAppointPatientAsbitemStatusUrl;
public AppQueueRegisterPlugIns()
{
Init();
@@ -49,6 +50,8 @@ namespace Shentun.WebPeis.Plugins
.GetSection("AppQueueRegisterUrl").Value;
_appIsPeisRegisterUrl = AppConfig.GetSection("Peis")
.GetSection("AppIsPeisRegisterUrl").Value;
+ _appUpdateAppointPatientAsbitemStatusUrl= AppConfig.GetSection("Peis")
+ .GetSection("AppUpdateAppointPatientAsbitemStatusUrl").Value;
}
@@ -81,6 +84,18 @@ namespace Shentun.WebPeis.Plugins
}
+ ///
+ /// 小程序退款成功后,更新体检系统项目收费状态
+ ///
+ ///
+ ///
+ public async Task UpdateAppointPatientAsbitemStatusAsync(UpdateAppointPatientAsbitemStatusInputDto input)
+ {
+ await CallAppServiceAsync(_appUpdateAppointPatientAsbitemStatusUrl,
+ input);
+ }
+
+
public async Task CallAppServiceAsync(string url, TInput data, string method = "post")
{
string baseAddress = _appBaseAddress;
diff --git a/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/AppointPatientRegisterIdsInputDto.cs b/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/AppointPatientRegisterIdsInputDto.cs
new file mode 100644
index 0000000..42058dc
--- /dev/null
+++ b/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/AppointPatientRegisterIdsInputDto.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Shentun.WebPeis.AppointPatientRegisters
+{
+ public class AppointPatientRegisterIdsInputDto
+ {
+ ///
+ /// 预约id集合
+ ///
+ public List AppointPatientRegisterIds { get; set; } = new List();
+ }
+}
diff --git a/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/GerAppointPatientRegisterWithAsbitemListDto.cs b/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/GerAppointPatientRegisterWithAsbitemListDto.cs
new file mode 100644
index 0000000..9858a05
--- /dev/null
+++ b/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/GerAppointPatientRegisterWithAsbitemListDto.cs
@@ -0,0 +1,72 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Shentun.WebPeis.AppointPatientRegisters
+{
+ public class GerAppointPatientRegisterWithAsbitemListDto
+ {
+ ///
+ /// 预约id
+ ///
+ public Guid AppointPatientRegisterId { get; set; }
+
+ ///
+ /// 收费状态 0-未收费 1-已收费 2-已退费
+ ///
+ public char ChargeFlag { get; set; }
+
+ ///
+ /// 预约日期
+ ///
+ public string AppointDate { get; set; }
+
+ ///
+ /// 预约项目
+ ///
+ public List AppointRegisterAsbitemDetail { get; set; } = new List();
+ }
+
+
+ public class GerAppointPatientRegisterWithAsbitemListChargeAsbitemDto
+ {
+ ///
+ /// 主键
+ ///
+ public Guid AppointRegisterAsbitemId { get; set; }
+ ///
+ /// 组合项目ID
+ ///
+ public Guid AsbitemId { get; set; }
+ ///
+ /// 组合项目名称
+ ///
+ public string AsbitemName { get; set; }
+
+ ///
+ /// 标准价格
+ ///
+ public decimal StandardPrice { get; set; }
+ ///
+ /// 收费价格
+ ///
+ public decimal ChargePrice { get; set; }
+ ///
+ /// 支付类别标准
+ ///
+ public char PayTypeFlag { get; set; }
+ ///
+ /// 是否收费
+ ///
+ public char IsCharge { get; set; }
+
+
+
+ ///
+ /// 数量
+ ///
+ public short Amount { get; set; }
+
+
+ }
+}
diff --git a/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/UpdateAppointPatientAsbitemStatusInputDto.cs b/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/UpdateAppointPatientAsbitemStatusInputDto.cs
new file mode 100644
index 0000000..b8d089c
--- /dev/null
+++ b/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/UpdateAppointPatientAsbitemStatusInputDto.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Shentun.WebPeis.AppointPatientRegisters
+{
+ public class UpdateAppointPatientAsbitemStatusInputDto
+ {
+ ///
+ /// 预约id
+ ///
+ public Guid AppointPatientRegisterId { get; set; }
+
+ ///
+ /// 收费项目状态
+ ///
+ public List ChargeAsbitemDetail { get; set; } = new List();
+
+ }
+
+ public class UpdateAppointPatientAsbitemStatusInputDetailDto
+ {
+ public Guid AsbitemId { get; set; }
+
+ public char IsCharge { get; set; }
+ }
+}
diff --git a/src/Shentun.WebPeis.Application/AppointPatientRegisters/AppointPatientRegisterAppService.cs b/src/Shentun.WebPeis.Application/AppointPatientRegisters/AppointPatientRegisterAppService.cs
index 9574511..504e10c 100644
--- a/src/Shentun.WebPeis.Application/AppointPatientRegisters/AppointPatientRegisterAppService.cs
+++ b/src/Shentun.WebPeis.Application/AppointPatientRegisters/AppointPatientRegisterAppService.cs
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
+using Microsoft.Extensions.Configuration;
using Shentun.WebPeis.AppointRegisterAsbitems;
using Shentun.WebPeis.AppointScheduleTimes;
using Shentun.WebPeis.CustomerOrgs;
@@ -10,9 +11,12 @@ using Shentun.WebPeis.Models;
using Shentun.WebPeis.OrganizationUnits;
using Shentun.WebPeis.PatientRegisters;
using Shentun.WebPeis.Persons;
+using Shentun.WebPeis.Plugins;
using Shentun.WebPeis.QuestionRegisters;
using Shentun.WebPeis.SysParmValues;
using Shentun.WebPeis.Wechats;
+using SKIT.FlurlHttpClient.Wechat.TenpayV3;
+using SKIT.FlurlHttpClient.Wechat.TenpayV3.Models;
using System;
using System.Collections;
using System.Collections.Generic;
@@ -76,6 +80,10 @@ namespace Shentun.WebPeis.AppointPatientRegisters
private readonly IRepository _chargeRepository;
private readonly IRepository _chargePayRepository;
private readonly IRepository _chargeAsbitemRepository;
+ private readonly IRepository _weChatOrderRepository;
+ private readonly IRepository _weChatOrderRefundRepository;
+ private readonly IConfiguration _configuration;
+ private readonly IWechatTenpayClientFactory _wechatTenpayClientFactory;
public AppointPatientRegisterAppService(IRepository repository,
CacheService cacheService,
IRepository itemTypeRepository,
@@ -113,7 +121,11 @@ namespace Shentun.WebPeis.AppointPatientRegisters
WeChatOrderAppService weChatOrderAppService,
IRepository chargeRepository,
IRepository chargePayRepository,
- IRepository chargeAsbitemRepository)
+ IRepository chargeAsbitemRepository,
+ IRepository weChatOrderRepository,
+ IRepository weChatOrderRefundRepository,
+ IConfiguration configuration,
+ IWechatTenpayClientFactory wechatTenpayClientFactory)
{
_repository = repository;
_cacheService = cacheService;
@@ -154,6 +166,10 @@ namespace Shentun.WebPeis.AppointPatientRegisters
_chargeRepository = chargeRepository;
_chargePayRepository = chargePayRepository;
_chargeAsbitemRepository = chargeAsbitemRepository;
+ _weChatOrderRepository = weChatOrderRepository;
+ _weChatOrderRefundRepository = weChatOrderRefundRepository;
+ _configuration = configuration;
+ _wechatTenpayClientFactory = wechatTenpayClientFactory;
}
///
/// 创建预约,小程序使用 部分单位跟个人
@@ -1131,6 +1147,7 @@ namespace Shentun.WebPeis.AppointPatientRegisters
}
}
+
#region 提供给体检系统调用
@@ -1394,6 +1411,143 @@ namespace Shentun.WebPeis.AppointPatientRegisters
}
+
+
+ ///
+ /// 获取预约记录,包含收费项目 体检退费时用
+ ///
+ ///
+ ///
+ [AllowAnonymous]
+ [HttpPost("api/app/AppointPatientRegister/GerAppointPatientRegisterWithAsbitemList")]
+ public async Task> GerAppointPatientRegisterWithAsbitemListAsync(AppointPatientRegisterIdsInputDto input)
+ {
+
+ if (!input.AppointPatientRegisterIds.Any())
+ {
+ throw new UserFriendlyException("无预约数据");
+ }
+
+ var query = (from appointPatientRegister in await _repository.GetQueryableAsync()
+ join appointRegisterAsbitem in await _appointRegisterAsbitemRepository.GetQueryableAsync()
+ on appointPatientRegister.AppointPatientRegisterId equals appointRegisterAsbitem.AppointPatientRegisterId
+ join asbitem in await _asbitemRepository.GetQueryableAsync() on appointRegisterAsbitem.AsbitemId equals asbitem.AsbitemId
+ where appointPatientRegister.ChargeFlag == ChargeFlag.Charge
+ && input.AppointPatientRegisterIds.Contains(appointPatientRegister.AppointPatientRegisterId)
+ select new
+ {
+ appointPatientRegister,
+ appointRegisterAsbitem,
+ asbitem
+ }).ToList();
+
+
+ var appointPatientRegisterGroup = query.GroupBy(g => g.appointPatientRegister);
+
+ var entListDto = appointPatientRegisterGroup.Select(s => new GerAppointPatientRegisterWithAsbitemListDto
+ {
+ AppointPatientRegisterId = s.Key.AppointPatientRegisterId,
+ ChargeFlag = s.Key.ChargeFlag,
+ AppointDate = DataHelper.ConversionDateShortToString(s.Key.AppointDate),
+ AppointRegisterAsbitemDetail = s.Select(ss => new GerAppointPatientRegisterWithAsbitemListChargeAsbitemDto
+ {
+ Amount = ss.appointRegisterAsbitem.Amount,
+ AppointRegisterAsbitemId = ss.appointRegisterAsbitem.AppointRegisterAsbitemId,
+ AsbitemId = ss.appointRegisterAsbitem.AsbitemId,
+ AsbitemName = ss.asbitem.AsbitemName,
+ ChargePrice = ss.appointRegisterAsbitem.ChargePrice,
+ StandardPrice = ss.appointRegisterAsbitem.StandardPrice,
+ IsCharge = ss.appointRegisterAsbitem.IsCharge,
+ PayTypeFlag = ss.appointRegisterAsbitem.PayTypeFlag
+ }).ToList()
+ }).ToList();
+
+
+
+
+ return entListDto;
+ }
+
+
+ ///
+ /// 体检系统申请退款
+ ///
+ ///
+ ///
+ [AllowAnonymous]
+ [HttpPost("api/app/AppointPatientRegister/CreateWeChatOrderRefund")]
+ public async Task CreateWeChatOrderRefundAsync(CreateWeChatOrderRefundInputDto input)
+ {
+
+ var weChatOrderEnt = await _weChatOrderRepository.FirstOrDefaultAsync(f => f.AppointPatientRegisterId == input.AppointPatientRegisterId
+ && f.Status == "SUCCESS");
+ if (weChatOrderEnt != null)
+ {
+ if (input.RefundMoney * 100 > weChatOrderEnt.OrderMoney)
+ {
+ throw new UserFriendlyException($"退款金额不能大于支付金额");
+ }
+
+ var weChatOrderRefundEnt = await _weChatOrderRefundRepository.FirstOrDefaultAsync(f => f.WeChatOrderId == weChatOrderEnt.WeChatOrderId);
+ if (weChatOrderRefundEnt == null)
+ {
+ string appid = _configuration.GetSection("WeChat:Appid").Value;
+ string mchid = _configuration.GetSection("Merchant:MchId").Value;
+ string notifyUrl = _configuration.GetSection("Merchant:NotifyUrl").Value;
+ string outRefundNo = $"T{DateTime.Now.ToString("yyyyMMddHHmmss")}{new Random().Next(100000, 999999)}";
+
+ var _wechatTenpayClient = await _wechatTenpayClientFactory.Create(false);
+ var request = new CreateRefundDomesticRefundRequest()
+ {
+ TransactionId = weChatOrderEnt.TransactionId,
+ OutRefundNumber = outRefundNo,
+ Amount = new CreateRefundDomesticRefundRequest.Types.Amount()
+ {
+ Total = weChatOrderEnt.OrderMoney,
+ Refund = Convert.ToInt32(Math.Round(input.RefundMoney * 100))
+ },
+ Reason = "体检系统申请退款",
+ NotifyUrl = notifyUrl
+ };
+ var response = await _wechatTenpayClient.ExecuteCreateRefundDomesticRefundAsync(request);
+ if (response.IsSuccessful())
+ {
+ #region 生成订单
+
+
+ weChatOrderRefundEnt = new WeChatOrderRefund
+ {
+ RefundMoney = request.Amount.Refund,
+ Status = "PROCESSING",
+ OutRefundNo = outRefundNo,
+ Channel = response.Channel,
+ RefundId = response.RefundId,
+ UserReceivedAccount = response.UserReceivedAccount,
+ WeChatOrderId = weChatOrderEnt.WeChatOrderId,
+ WeChatOrderRefundId = GuidGenerator.Create()
+ };
+
+ var isAdd = await _weChatOrderRefundRepository.InsertAsync(weChatOrderRefundEnt);
+
+
+ #endregion
+ }
+ else
+ {
+ throw new UserFriendlyException($"发起退款失败:{response.ErrorCode},{response.ErrorMessage}");
+ }
+ }
+ else
+ {
+ throw new UserFriendlyException($"已申请过退款,不要重复退款");
+ }
+ }
+ else
+ {
+ throw new UserFriendlyException("预约Id不正确");
+ }
+ }
+
#endregion
}
}
diff --git a/src/Shentun.WebPeis.Application/Charges/ChargeAppService.cs b/src/Shentun.WebPeis.Application/Charges/ChargeAppService.cs
index c743f30..71ed24e 100644
--- a/src/Shentun.WebPeis.Application/Charges/ChargeAppService.cs
+++ b/src/Shentun.WebPeis.Application/Charges/ChargeAppService.cs
@@ -2,6 +2,7 @@
using Microsoft.Extensions.Logging;
using Shentun.WebPeis.AppointPatientRegisters;
using Shentun.WebPeis.Models;
+using Shentun.WebPeis.Plugins;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -72,7 +73,33 @@ namespace Shentun.WebPeis.Charges
var appointPatientRegisterEnt = await _appointPatientRegisterRepository.FirstOrDefaultAsync(f => f.AppointPatientRegisterId == input.AppointPatientRegisterId);
if (appointPatientRegisterEnt != null)
{
- await _chargeManager.CreateChargeBackAsync(appointPatientRegisterEnt, input.ChargeBackMoney);
+ var chargeAsbitems = await _chargeManager.CreateChargeBackAsync(appointPatientRegisterEnt, input.ChargeBackMoney);
+
+ //处理完退费,同步数据到体检系统
+
+ #region 调用体检服务,更新登记的项目状态
+
+ try
+ {
+ var appQueueRegisterPlugIns = new AppQueueRegisterPlugIns();
+
+ await appQueueRegisterPlugIns.UpdateAppointPatientAsbitemStatusAsync(
+ new UpdateAppointPatientAsbitemStatusInputDto
+ {
+ AppointPatientRegisterId = input.AppointPatientRegisterId,
+ ChargeAsbitemDetail = chargeAsbitems.Select(s => new UpdateAppointPatientAsbitemStatusInputDetailDto
+ {
+ AsbitemId = s.AsbitemId,
+ IsCharge = 'N'
+ }).ToList()
+ });
+ }
+ catch (Exception ex)
+ {
+ _logger.LogInformation($"同步数据到体检系统异常,{ex.Message}");
+ }
+
+ #endregion
}
else
{
diff --git a/src/Shentun.WebPeis.Domain/Charges/ChargeManager.cs b/src/Shentun.WebPeis.Domain/Charges/ChargeManager.cs
index 8b8cba3..500a441 100644
--- a/src/Shentun.WebPeis.Domain/Charges/ChargeManager.cs
+++ b/src/Shentun.WebPeis.Domain/Charges/ChargeManager.cs
@@ -128,7 +128,7 @@ namespace Shentun.WebPeis.Charges
///
///
///
- public async Task CreateChargeBackAsync(
+ public async Task> CreateChargeBackAsync(
AppointPatientRegister appointPatientRegister,
decimal chargeMoney
)
@@ -180,10 +180,13 @@ namespace Shentun.WebPeis.Charges
appointPatientRegister.CompleteFlag = AppointPatientRegisterCompleteFlag.CancelAppoint;
await _appointPatientRegisterRepository.UpdateAsync(appointPatientRegister);
+
+ return chargeAsbitems;
}
else
{
_logger.LogInformation($"退费时,{appointPatientRegister.AppointPatientRegisterId}Id未找到收费记录");
+ return new List();
}
}