HomeController.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using Microsoft.AspNetCore.Mvc;
  7. using Microsoft.Extensions.Logging;
  8. using Library;
  9. using LitJson;
  10. using System.Data;
  11. using MySystem.Models.Main;
  12. using System.Text.RegularExpressions;
  13. using Aop.Api.Domain;
  14. using MySystem.Models;
  15. using Microsoft.Extensions.Localization;
  16. namespace MySystem.Controllers
  17. {
  18. public class HomeController : Controller
  19. {
  20. private readonly ILogger<HomeController> _logger;
  21. public HomeController(ILogger<HomeController> logger)
  22. {
  23. _logger = logger;
  24. }
  25. public IActionResult Index()
  26. {
  27. return View();
  28. }
  29. public string getHdOrder()
  30. {
  31. GetHaoDaFTPInfoService.Instance.GetFTPDataInfoYesterday();
  32. return "ok";
  33. }
  34. public string partorder()
  35. {
  36. List<string> hdorders = new List<string>();
  37. WebCMSEntities db = new WebCMSEntities();
  38. var list = db.ConsumerOrders.Select(m => new { m.Id, m.SettleAmount, m.IsAct, m.SeoTitle }).Where(m => hdorders.Contains(m.SeoTitle) && m.IsAct == 1 && m.SettleAmount == 0).OrderBy(m => m.Id).ToList();
  39. foreach (var sub in list)
  40. {
  41. ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == sub.Id);
  42. if (order != null)
  43. {
  44. int Status = 2;
  45. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantInfo();
  46. MerchantParamSet set = Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantParamSet>(order.SeoDescription);
  47. if (order.IsAct == 1 && order.PayMoney >= set.MinPayMoney)
  48. {
  49. MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
  50. //获取结算金额
  51. if(order.SettleAmount == 0)
  52. {
  53. string settleString = HaoDaHelper.Instance.QueryOrderDivideDetail(merchantAdd.OutMchtNo, order.SeoTitle);
  54. JsonData jsonData = JsonMapper.ToObject(settleString);
  55. if(jsonData["resultCode"].ToString() == "1")
  56. {
  57. string settleAmountString = jsonData["data"]["settleAmount"].ToString();
  58. order.SettleAmount = int.Parse(settleAmountString);
  59. }
  60. }
  61. //发起分账
  62. decimal fee = order.PayMoney;
  63. if (fee >= 1 && order.SettleAmount > 0)
  64. {
  65. string applyNo = "FZ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //批次号
  66. string mchtNo = merchantAdd.OutMchtNo; //慧掌柜商户号
  67. string orderNo = order.SeoTitle; //交易订单号(好哒平台订单号,G开头)
  68. string acctNo = AppConfig.Haoda.AcctNo; //账户号,分账接收方账户号
  69. string sacctNo = merchantAdd.MchtNo; //账户号,收款商户号
  70. string acctType = "0"; //账户类型(0:商户收款账户(大B),1:分账接收方账户(小B))
  71. decimal settleAmount = (decimal)order.SettleAmount / 100M;
  72. decimal divideAmt = (1 - 0.0038M) * order.PayMoney;
  73. divideAmt = decimal.Parse(divideAmt.ToString("f2"));
  74. decimal hdfee = 0.0038M * order.PayMoney * (1 - set.GetPercent / 100 - 0.01M);
  75. hdfee = decimal.Parse(hdfee.ToString("f2"));
  76. decimal servicefee = 0.01M * order.PayMoney - hdfee;
  77. servicefee = decimal.Parse(servicefee.ToString("f2"));
  78. decimal amount = order.PayMoney * (1 - 0.0038M) - servicefee;
  79. amount = decimal.Parse(amount.ToString("f2"));
  80. decimal otherAmt = settleAmount - servicefee - amount;
  81. if (otherAmt != 0)
  82. {
  83. amount += otherAmt;
  84. }
  85. amount = amount * 100; //金额(分)
  86. servicefee = servicefee * 100;
  87. string seviceAmount = servicefee.ToString("f0"); //服务费
  88. string amountAmount = amount.ToString("f0");
  89. string result = HaoDaHelper.Instance.OrderDivideAccounts(OrderDivideAccountsUtil.AddValue(applyNo, mchtNo, orderNo, acctNo, sacctNo, acctType, amountAmount, seviceAmount), merchantAdd.BrandId);
  90. order.DivideLog = "请求分账日志:" + result;
  91. order.TradePayNo = applyNo;
  92. if (result.Contains("\"resultCode\":\"0\"") && (result.Contains("分账金额不足") || result.Contains("不存在")))
  93. {
  94. Status = 1;
  95. }
  96. }
  97. }
  98. order.Status = Status;
  99. if (Status == 2)
  100. {
  101. order.DivideFlag = 1;
  102. order.DivideDate = DateTime.Now;
  103. }
  104. }
  105. }
  106. db.SaveChanges();
  107. db.Dispose();
  108. return "ok";
  109. }
  110. public string addreturn()
  111. {
  112. List<int> ids = new List<int>();
  113. foreach(int id in ids)
  114. {
  115. RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:2:List", id.ToString());
  116. }
  117. return "ok";
  118. }
  119. }
  120. }