HomeController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. public string test()
  120. {
  121. // WebCMSEntities db = new WebCMSEntities();
  122. // MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == 5660) ?? new MerchantAddInfo();
  123. // SortedList<string, string> obj = new SortedList<string, string>();
  124. // obj.Add("bind_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  125. // obj.Add("merch_no", merchantadd.MchtNo);
  126. // obj.Add("name", merchantadd.CertMerchantName);
  127. // string IdCardNumber = merchantadd.IdCardNumber;
  128. // if(!string.IsNullOrEmpty(IdCardNumber))
  129. // {
  130. // IdCardNumber = IdCardNumber.Substring(0, 6) + "**********" + IdCardNumber.Substring(IdCardNumber.Length - 4);
  131. // }
  132. // obj.Add("supplement_info", IdCardNumber);
  133. // obj.Add("mobile", merchantadd.MobilePhone);
  134. // obj.Add("maker_code", "C00000001");
  135. // PushHelper.Instance.Do(obj);
  136. // string content = function.ReadInstance("/好哒地区.txt");
  137. // string[] contents = content.Split('\n');
  138. // foreach(string sub in contents)
  139. // {
  140. // string[] data = sub.Split(',');
  141. // if(data.Length == 6)
  142. // {
  143. // string CityName = "中国," + data[1];
  144. // bool op = db.OpenBankCityTable.Any(m => m.CityName == CityName);
  145. // if(!op)
  146. // {
  147. // db.OpenBankCityTable.Add(new OpenBankCityTable()
  148. // {
  149. // CityName = CityName,
  150. // Code = data[0] + "0000",
  151. // });
  152. // db.SaveChanges();
  153. // }
  154. // CityName = "中国," + data[1] + "," + data[3];
  155. // op = db.OpenBankCityTable.Any(m => m.CityName == CityName);
  156. // if(!op)
  157. // {
  158. // db.OpenBankCityTable.Add(new OpenBankCityTable()
  159. // {
  160. // CityName = CityName,
  161. // Code = data[2] + "00",
  162. // });
  163. // db.SaveChanges();
  164. // }
  165. // CityName = "中国," + data[1] + "," + data[3] + "," + data[5];
  166. // op = db.OpenBankCityTable.Any(m => m.CityName == CityName);
  167. // if(!op)
  168. // {
  169. // db.OpenBankCityTable.Add(new OpenBankCityTable()
  170. // {
  171. // CityName = CityName,
  172. // Code = data[4],
  173. // });
  174. // db.SaveChanges();
  175. // }
  176. // }
  177. // else
  178. // {
  179. // string CityName = "中国,," + data[1];
  180. // bool op = db.OpenBankCityTable.Any(m => m.CityName == CityName);
  181. // if(!op)
  182. // {
  183. // db.OpenBankCityTable.Add(new OpenBankCityTable()
  184. // {
  185. // CityName = CityName,
  186. // Code = data[0] + "0000",
  187. // });
  188. // db.SaveChanges();
  189. // }
  190. // CityName = "中国,," + data[1] + "," + data[3];
  191. // op = db.OpenBankCityTable.Any(m => m.CityName == CityName);
  192. // if(!op)
  193. // {
  194. // db.OpenBankCityTable.Add(new OpenBankCityTable()
  195. // {
  196. // CityName = CityName,
  197. // Code = data[2],
  198. // });
  199. // db.SaveChanges();
  200. // }
  201. // }
  202. // }
  203. // db.Dispose();
  204. DateTime start = DateTime.Parse("2025-01-01 00:00:00");
  205. Models.KxsMain.WebCMSEntities db = new Models.KxsMain.WebCMSEntities();
  206. List<Models.KxsMain.ChangeTypes> brands = db.ChangeTypes.ToList();
  207. List<Models.KxsMain.UserAccountRecord> records = db.UserAccountRecord.Where(m => m.CreateDate >= start && m.ChangeType > 300).ToList();
  208. foreach(Models.KxsMain.UserAccountRecord record in records)
  209. {
  210. string name = brands.FirstOrDefault(m => m.Id == record.ChangeType).Name;
  211. PrizePushHelper.Instance.Do(DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), name, record.ChangeType.ToString(), record.ChangeAmount, record.UserId, "{\"brand_id\":101,\"user_id\":" + record.UserId + "}");
  212. }
  213. db.SaveChanges();
  214. return "ok";
  215. }
  216. }
  217. }