Commit 19781c4e authored by 黄奎's avatar 黄奎

Merge branch 'master' of http://gitlab.oytour.com/Kui2/education

parents 4610f6d4 341670f7
......@@ -47,6 +47,11 @@ namespace Edu.Common.Enum.Course
/// 耗材出库
/// </summary>
[EnumField("耗材出库")]
SuppliesStockOut = 7
SuppliesStockOut = 7,
/// <summary>
/// 学费收入
/// </summary>
[EnumField("学费收入")]
Tuition = 8
}
}
......@@ -9,7 +9,7 @@ namespace Edu.Common.WeChatPayAPIv3.Model.WxPayCallback
/// <summary>
/// 返回状态码,错误码,SUCCESS为清算机构接收成功,其他错误码为失败。
/// </summary>
public string code { set; get; } = "SUCCESS";
public string code { set; get; } = "FAIL";//"SUCCESS";
/// <summary>
/// 返回信息,如非空,为错误原因。
......
......@@ -20,7 +20,7 @@ namespace Edu.Common.WeChatPayAPIv3.Model
/// 密钥,用商户平台上设置的APIv3密钥【微信商户平台—>账户设置—>API安全—>设置APIv3密钥】,记为key;
/// 官方资料:https://kf.qq.com/faq/180830E36vyQ180830AZFZvu.html
/// </summary>
public static string APIV3Key => "WECHATPAY2-SHA256-RSA2048";
public static string APIV3Key => "8A6453965FB561BC90CC4CB290F26469";
/// <summary>
/// 直连商户的商户号,由微信支付生成并下发。
......
......@@ -79,12 +79,14 @@ namespace Edu.Common.WeChatPayAPIv3
var client = new HttpClient(new WxPayRequestHandler(_mchid, _serialNo, _privateKey));
// var bodyJson = new StringContent(req.ToJson(), Encoding.UTF8, "application/json");
var bodyJson = new StringContent(Common.Plugin.JsonHelper.Serialize(req), Encoding.UTF8, "application/json");
var resp = await client.PostAsync(url, bodyJson);
// 注意!!! 这个resp只是http的结果,需要把接口具体返回的值读取出来,如果接口报错的话,这地方可以看到具体的错误信息,我就是在这里入坑的。
var respStr = await resp.Content.ReadAsStringAsync();
// 如果下单成功,就解析返回的结果,把prepay_id解析出来
// var viewModel = respStr.ToObject<WxPayRespModel>();
Plugin.LogHelper.WriteInfo(respStr);
var viewModel = Common.Plugin.JsonHelper.DeserializeObject<WxPayRespModel>(respStr);
return viewModel;
}
......@@ -99,6 +101,7 @@ namespace Edu.Common.WeChatPayAPIv3
var client = new HttpClient(new WxPayRequestHandler(_mchid, _serialNo, _privateKey));
var resp = await client.GetAsync(url);
var respStr = await resp.Content.ReadAsStringAsync();
Plugin.LogHelper.WriteInfo("查询订单的支付结果信息:"+respStr);
var payModel = Common.Plugin.JsonHelper.DeserializeObject<WxPayStatusRespModel>(respStr);// respStr.ToObject<WxPayStatusRespModel>();
return payModel;
}
......@@ -170,6 +173,7 @@ namespace Edu.Common.WeChatPayAPIv3
var client = new HttpClient(new WxPayRequestHandler(_mchid, _serialNo, _privateKey));
var resp = await client.GetAsync(url);
var respStr = await resp.Content.ReadAsStringAsync();
Plugin.LogHelper.WriteInfo("查询订单的退款结果信息:" + respStr);
var payModel = Common.Plugin.JsonHelper.DeserializeObject<QueryRefundsOrderRespModel>(respStr); //respStr.ToObject<QueryRefundsOrderRespModel>();
return payModel;
}
......
......@@ -71,5 +71,10 @@ namespace Edu.Model.Entity.Course
/// 币种id
/// </summary>
public int CurrencyId { get; set; }
/// <summary>
/// ClientID=74 的时候是学费收款账户id
/// </summary>
public int ClientID { get; set; }
}
}
......@@ -71,7 +71,10 @@ namespace Edu.Module.Course
/// </summary>
private readonly RB_Online_Trade_DetailRepository OnlineTradeDetailRepository = new RB_Online_Trade_DetailRepository();
/// <summary>
/// 财务配置
/// </summary>
private readonly RB_Finance_ConfigRepository finance_ConfigRepository = new RB_Finance_ConfigRepository();
/// <summary>
/// 获取学员信息
......@@ -324,6 +327,19 @@ namespace Edu.Module.Course
#region 合同订单信息
/// <summary>
/// 获取财务配置列表
/// </summary>
/// <param name="dmodel"></param>
/// <returns></returns>
public List<RB_Finance_Config_ViewModel> GetFinanceConfigList(RB_Finance_Config_ViewModel dmodel)
{
return finance_ConfigRepository.GetList(dmodel);
}
/// <summary>
/// 新增合同的付款记录
/// </summary>
......
......@@ -46,7 +46,7 @@ namespace Edu.WebApi.Controllers.WeChatPay
/// 订单处理类对象
/// </summary>
private readonly OrderModule orderModule = AOP.AOPHelper.CreateAOPObject<OrderModule>();
private readonly object _lock = new object();
/// <summary>
/// 统一下单接口
/// </summary>
......@@ -64,7 +64,7 @@ namespace Edu.WebApi.Controllers.WeChatPay
var helper = new WxPayHelper(WxPayConst.appid, WxPayConst.mchid, WxPayConst.serialNo, WxPayConst.privateKey);
var notify_url = Config.sTenpayNotifyUrl;//ConfigurationManager.AppSettings["notify_url"]; //这个放在配置文件,从配置文件读取比较灵活,或者写到数据库中
Task<WxPayRespModel> payodel= helper.UnionGenerateOrder(orderModle.CourseName, Convert.ToInt32(orderModle.Money * 100), orderNumber, notify_url, orderModle.OrderId.ToString());
Task<WxPayRespModel> payodel = helper.UnionGenerateOrder(orderModle.CourseName, Convert.ToInt32(orderModle.Money * 100), orderNumber, notify_url, orderModle.OrderId.ToString());
#region APP生成下单所需的参数,看个人实际需求,也可以APP自己生成所需的参数
......@@ -72,7 +72,7 @@ namespace Edu.WebApi.Controllers.WeChatPay
#endregion
return ApiResult.Success(data: signModel) ;
return ApiResult.Success(data: signModel);
}
......@@ -84,36 +84,15 @@ namespace Edu.WebApi.Controllers.WeChatPay
[HttpPost]
[HttpGet]
[AllowAnonymous]
public async Task<WxPayCallbackRespModel> WxPayCallback()
public async Task<WxPayCallbackRespModel> WxPayCallback(WxPayNotifyModel wxPayNotifyModel)
{
#region 获取字符串流
//System.IO.Stream s = HttpContext.Current.Request.InputStream;
//int count = 0;
//byte[] buffer = new byte[1024];
//StringBuilder builder = new StringBuilder();
//while ((count = s.Read(buffer, 0, 1024)) > 0)
//{
// builder.Append(Encoding.UTF8.GetString(buffer, 0, count));
//}
//s.Flush();
//s.Close();
//s.Dispose();
var buffer = new MemoryStream();
Request.Body.CopyTo(buffer);
#endregion
//我没有使用官方的那种验证数据安全性的方法,我解密出来数据之后,直接拿着订单号再去查询一下订单状态,然后再更新到数据库中。我嫌麻烦……
// var str = Encoding.UTF8.GetString(buffer);
var str = Encoding.UTF8.GetString(buffer.GetBuffer());
LogHelper.WriteInfo("订单回调信息" + str);
var viewModel = new WxPayCallbackRespModel();
try
{
var wxPayNotifyModel = Common.Plugin.JsonHelper.DeserializeObject<WxPayNotifyModel>(str); //str.ToObject<WxPayNotifyModel>();
// var wxPayNotifyModel = Common.Plugin.JsonHelper.DeserializeObject<WxPayNotifyModel>(Request.Body.ToString()); //str.ToObject<WxPayNotifyModel>();
var resource = wxPayNotifyModel?.resource ?? new WxPayResourceModel();
var decryptStr = AesGcmHelper.AesGcmDecrypt(resource.associated_data, resource.nonce, resource.ciphertext, WxPayConst.APIV3Key);
LogHelper.WriteInfo("订单回调信息decryptStr" + decryptStr);
var decryptModel = Common.Plugin.JsonHelper.DeserializeObject<WxPayResourceDecryptModel>(decryptStr); //decryptStr.ToObject<WxPayResourceDecryptModel>();
......@@ -128,13 +107,18 @@ namespace Edu.WebApi.Controllers.WeChatPay
var payModel = await QueryOrder(decryptModel.out_trade_no);
if (payModel != null && payModel.trade_state == "SUCCESS")//生成财务单据
{
lock (_lock)
{
int contractId = Convert.ToInt32(payModel.out_trade_no[17..]);
var orderModle = educationContractModule.GetEducationContractModule(contractId);
var orderModel = orderModule.GetClassOrderInfo(orderModle.OrderId);
var financeConfig = educationContractModule.GetFinanceConfigList(new Model.ViewModel.Course.RB_Finance_Config_ViewModel { Group_Id = orderModle.Group_Id, Type = Common.Enum.Course.FinanceConfigTypeEnum.Tuition }).FirstOrDefault();
if (financeConfig == null)
{
financeConfig = new Model.ViewModel.Course.RB_Finance_Config_ViewModel();
}
var userInfo = employeeModule.GetEmployeeListModule(new Model.ViewModel.User.Employee_ViewModel { Id = orderModel.EnterID, Group_Id = orderModel.Group_Id }).ToList().FirstOrDefault();
var OriginalFee = Math.Round(Convert.ToDecimal((Convert.ToDecimal(Config.SettlementRate) / 100) * (payModel.amount.payer_total / 100)), 2, MidpointRounding.AwayFromZero);//手续费
var OriginalFee = Math.Round((Convert.ToDecimal(Config.SettlementRate) / 100) * (Convert.ToDecimal(payModel.amount.payer_total) / 100), 2, MidpointRounding.AwayFromZero);//手续费
RB_Online_Trade_Detail model = new RB_Online_Trade_Detail();
RB_Finance_OrderRecord orderRecordModel = new RB_Finance_OrderRecord
{
......@@ -148,29 +132,29 @@ namespace Edu.WebApi.Controllers.WeChatPay
RB_School_Id = orderModle.School_Id,
OutTradeNo = payModel.out_trade_no,
TransactionId = payModel.transaction_id,
TotalPrice = Convert.ToDecimal((payModel.amount.payer_total / 100)),
TotalPrice = Convert.ToDecimal(payModel.amount.payer_total) / 100,
ServiceFee = OriginalFee
};
var detailList = new List<object>();
detailList.Add(new
{
CostTypeId = 533,
CostTypeId = financeConfig?.CostTypeId ?? 533,
Number = 1,
OriginalMoney = Convert.ToDecimal((payModel.amount.payer_total / 100)),
UnitPrice = Convert.ToDecimal((payModel.amount.payer_total / 100)),
OriginalMoney = Convert.ToDecimal(payModel.amount.payer_total) / 100,
UnitPrice = Convert.ToDecimal(payModel.amount.payer_total) / 100,
Remark = orderModle.StudentName + orderModle.CourseName + payModel.out_trade_no
});
var financeObj = new
{
IsPublic = 0,
BType = 2,//item.AccountType,
AccountId = 74,
WBMoney = Convert.ToDecimal((payModel.amount.payer_total / 100)),
IsPublic = 1,
BType = 1,//item.AccountType,
AccountId = financeConfig?.ClientID ?? 54,
WBMoney = Convert.ToDecimal(payModel.amount.payer_total) / 100,
TradeDate = System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"),
AccountNumber = System.DateTime.Now.AddDays(-1).ToString("yyyyMMdd"),
TemplateId = 139,
TemplateId = financeConfig?.TempleteId ?? 139,
OrderSource = 17,
Remark = System.DateTime.Now.ToString("yyyy年MM月dd日") + "自动生成财务单据",
detailList,
......@@ -194,7 +178,7 @@ namespace Edu.WebApi.Controllers.WeChatPay
{
msg = sign,
};
string apiResult = Common.Plugin.HttpHelper.HttpPost(Config.ReadConfigKey("PaymentFinanceApi"), JsonHelper.Serialize(resultInfo), "");
string apiResult = Common.Plugin.HttpHelper.HttpPost(Config.ReadConfigKey("IncomeFinanceApi"), JsonHelper.Serialize(resultInfo), "");
JObject parmsJob = JObject.Parse(apiResult);
string resultCode = parmsJob.GetStringValue("resultCode");
int frid = parmsJob.GetInt("data", 0);
......@@ -210,7 +194,7 @@ namespace Edu.WebApi.Controllers.WeChatPay
Pay_Order = "",
Trade_Order = payModel.out_trade_no,
Third_Order = payModel.transaction_id,
Money = Convert.ToDecimal((payModel.amount.payer_total / 100)),
Money = Convert.ToDecimal(payModel.amount.payer_total) / 100,
Pay_Way = 1,
Interface_Company = 0,
Version = "",
......@@ -224,7 +208,7 @@ namespace Edu.WebApi.Controllers.WeChatPay
Card_Type = 0,
Remarks = "教育订单信息财务单据:" + frid,
Pay_Result = 0,
Pay_Date = !string.IsNullOrWhiteSpace(payModel?.success_time ?? "") ? Convert.ToDateTime(payModel.success_time) : Convert.ToDateTime("1990-01-01"),
Pay_Date = !string.IsNullOrWhiteSpace(payModel?.success_time ?? "") ? DateTime.SpecifyKind(Convert.ToDateTime(payModel.success_time), DateTimeKind.Utc) : Convert.ToDateTime("1990-01-01"),
Payer_Id = orderModle.GuestId,
Payer_Type = 0,
Data_Source = frid,
......@@ -239,7 +223,13 @@ namespace Edu.WebApi.Controllers.WeChatPay
};
}
educationContractModule.SetEducationContractFinance(model, orderRecordModel);
bool result = educationContractModule.SetEducationContractFinance(model, orderRecordModel);
}
viewModel.code = "SUCCESS";
viewModel.message = "数据接收成功";
}
//然后进行数据库更新处理……等等其他操作
......@@ -296,17 +286,10 @@ namespace Edu.WebApi.Controllers.WeChatPay
[HttpPost]
[HttpGet]
[AllowAnonymous]
public async Task<RefundsCallbackRespModel> RefundsCallback()
public async Task<RefundsCallbackRespModel> RefundsCallback(RefundsCallbackModel wxPayNotifyModel)
{
#region 获取字符串流
var buffer = new MemoryStream();
Request.Body.CopyTo(buffer);
#endregion
//我没有使用官方的那种验证数据安全性的方法,我解密出来数据之后,直接拿着商户退款订单号再去查询一下订单状态,然后再更新到数据库中。我嫌麻烦……
var str = Encoding.UTF8.GetString(buffer.GetBuffer());
var wxPayNotifyModel = Common.Plugin.JsonHelper.DeserializeObject<RefundsCallbackModel>(str);
var resource = wxPayNotifyModel?.resource ?? new RefundsCallbackResourceModel();
var decryptStr = AesGcmHelper.AesGcmDecrypt(resource.associated_data, resource.nonce, resource.ciphertext, WxPayConst.APIV3Key);
var decryptModel = Common.Plugin.JsonHelper.DeserializeObject<RefundsCallbackDecryptModel>(decryptStr); //decryptStr.ToObject<RefundsCallbackDecryptModel>();
......@@ -322,14 +305,15 @@ namespace Edu.WebApi.Controllers.WeChatPay
var payModel = await QueryRefunds(decryptModel.out_refund_no);
if (payModel != null && payModel.status == "SUCCESS")//生成财务单据
{
lock (_lock)
{
int contractId = Convert.ToInt32(payModel.out_trade_no[17..]);
var orderModle = educationContractModule.GetEducationContractModule(contractId);
var orderModel = orderModule.GetClassOrderInfo(orderModle.OrderId);
var oldOrderRecordModel = educationContractModule.GetOrderRecordList(new RB_Finance_OrderRecord { ContractId = contractId, OutTradeNo = payModel.out_trade_no }).FirstOrDefault();
var userInfo = employeeModule.GetEmployeeListModule(new Model.ViewModel.User.Employee_ViewModel { Id = orderModel.EnterID, Group_Id = orderModel.Group_Id }).ToList().FirstOrDefault();
var OriginalFee = Math.Round(Convert.ToDecimal((Convert.ToDecimal(Config.SettlementRate) / 100) * (payModel.amount.payer_total / 100)), 2, MidpointRounding.AwayFromZero);//手续费
var OriginalFee = Math.Round(Convert.ToDecimal((Convert.ToDecimal(Config.SettlementRate) / 100) * (Convert.ToDecimal(payModel.amount.payer_total) / 100)), 2, MidpointRounding.AwayFromZero);//手续费
RB_Online_Trade_Detail model = new RB_Online_Trade_Detail();
RB_Finance_OrderRecord orderRecordModel = new RB_Finance_OrderRecord
{
......@@ -341,13 +325,16 @@ namespace Edu.WebApi.Controllers.WeChatPay
CreateDate = System.DateTime.Now,
RB_Group_Id = orderModle.Group_Id,
RB_School_Id = orderModle.School_Id,
OutTradeNo = payModel.out_trade_no,
OutTradeNo = payModel.out_refund_no,
OrderRecordId = oldOrderRecordModel?.ID ?? 0,
TransactionId = payModel.refund_id,
TotalPrice = Convert.ToDecimal((payModel.amount.payer_total / 100)),
TotalPrice = Convert.ToDecimal(payModel.amount.payer_total) / 100,
ServiceFee = OriginalFee
};
educationContractModule.SetEducationContractFinance(model, orderRecordModel);
bool result = educationContractModule.SetEducationContractFinance(model, orderRecordModel);
}
viewModel.code = "SUCCESS";
viewModel.message = "数据接收成功";
}
//然后进行数据库更新处理……等等其他操作
}
......@@ -375,9 +362,13 @@ namespace Edu.WebApi.Controllers.WeChatPay
int contractId = Convert.ToInt32(payModel.out_trade_no[17..]);
var orderModle = educationContractModule.GetEducationContractModule(contractId);
var orderModel = orderModule.GetClassOrderInfo(orderModle.OrderId);
var financeConfig = educationContractModule.GetFinanceConfigList(new Model.ViewModel.Course.RB_Finance_Config_ViewModel { Group_Id = orderModle.Group_Id, Type = Common.Enum.Course.FinanceConfigTypeEnum.Tuition }).FirstOrDefault();
if (financeConfig == null)
{
financeConfig = new Model.ViewModel.Course.RB_Finance_Config_ViewModel();
}
var userInfo = employeeModule.GetEmployeeListModule(new Model.ViewModel.User.Employee_ViewModel { Id = orderModel.EnterID, Group_Id = orderModel.Group_Id }).ToList().FirstOrDefault();
var OriginalFee = Math.Round(Convert.ToDecimal((Convert.ToDecimal(Config.SettlementRate) / 100) * (payModel.amount.payer_total / 100)), 2, MidpointRounding.AwayFromZero);//手续费
var OriginalFee = Math.Round((Convert.ToDecimal(Config.SettlementRate) / 100) * (Convert.ToDecimal(payModel.amount.payer_total) / 100), 2, MidpointRounding.AwayFromZero);//手续费
RB_Online_Trade_Detail model = new RB_Online_Trade_Detail();
RB_Finance_OrderRecord orderRecordModel = new RB_Finance_OrderRecord
{
......@@ -391,14 +382,14 @@ namespace Edu.WebApi.Controllers.WeChatPay
RB_School_Id = orderModle.School_Id,
OutTradeNo = payModel.out_trade_no,
TransactionId = payModel.transaction_id,
TotalPrice = Convert.ToDecimal((payModel.amount.payer_total / 100)),
TotalPrice = Convert.ToDecimal(payModel.amount.payer_total) / 100,
ServiceFee = OriginalFee
};
var detailList = new List<object>();
detailList.Add(new
{
CostTypeId = 533,
CostTypeId = financeConfig?.CostTypeId ?? 533,
Number = 1,
OriginalMoney = Convert.ToDecimal((payModel.amount.payer_total / 100)),
UnitPrice = Convert.ToDecimal((payModel.amount.payer_total / 100)),
......@@ -407,13 +398,13 @@ namespace Edu.WebApi.Controllers.WeChatPay
var financeObj = new
{
IsPublic = 0,
BType = 2,//item.AccountType,
AccountId = 74,
IsPublic = 1,
BType = 1,//item.AccountType,
AccountId = financeConfig?.ClientID ?? 54,
WBMoney = Convert.ToDecimal((payModel.amount.payer_total / 100)),
TradeDate = System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"),
AccountNumber = System.DateTime.Now.AddDays(-1).ToString("yyyyMMdd"),
TemplateId = 139,
TemplateId = financeConfig?.TempleteId ?? 139,
OrderSource = 17,
Remark = System.DateTime.Now.ToString("yyyy年MM月dd日") + "自动生成财务单据",
detailList,
......@@ -444,6 +435,9 @@ namespace Edu.WebApi.Controllers.WeChatPay
if (resultCode == "1" && frid > 0)//新增记录
{
orderRecordModel.FinanceId = frid;
// var Pay_Date = !string.IsNullOrWhiteSpace(payModel?.success_time ?? "") ? Convert.ToDateTime(payModel.success_time) : Convert.ToDateTime("1990-01-01");
DateTime myDt = DateTime.SpecifyKind(Convert.ToDateTime(payModel.success_time), DateTimeKind.Utc);
model = new RB_Online_Trade_Detail
{
ID = 0,
......@@ -467,7 +461,7 @@ namespace Edu.WebApi.Controllers.WeChatPay
Card_Type = 0,
Remarks = "教育订单信息财务单据:" + frid,
Pay_Result = 0,
Pay_Date = !string.IsNullOrWhiteSpace(payModel?.success_time ?? "") ? Convert.ToDateTime(payModel.success_time) : Convert.ToDateTime("1990-01-01"),
Pay_Date = myDt,
Payer_Id = orderModle.GuestId,
Payer_Type = 0,
Data_Source = frid,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment