HomeController.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. namespace MySystem.Controllers
  14. {
  15. public class HomeController : Controller
  16. {
  17. private readonly ILogger<HomeController> _logger;
  18. public HomeController(ILogger<HomeController> logger)
  19. {
  20. _logger = logger;
  21. }
  22. public IActionResult Index()
  23. {
  24. return View();
  25. }
  26. public string test(decimal a, decimal b, decimal g)
  27. {
  28. // List<int> MerchantIds = new List<int>();
  29. // MerchantIds.Add(5);
  30. // foreach(int MerchantId in MerchantIds)
  31. // {
  32. // RedisDbconn.Instance.AddList("MerchantConfirmHdQueue", "{\"MerchantId\":\"" + MerchantId + "\"}");
  33. // }
  34. // TianYuVoiceHelper.Instance.doSomething(DateTime.Now.ToString("yyyyMMddHHmmssfff"),"2023100701","100");
  35. // MqLinksHelper.Instance.doSomething("LKB01230600250000585","100");
  36. // WebCMSEntities db = new WebCMSEntities();
  37. // Dictionary<string, decimal> ids = new Dictionary<string, decimal>();
  38. // ids.Add("2023123120272680842405573", 30.08M);
  39. // foreach(string orderno in ids.Keys)
  40. // {
  41. // decimal cur = ids[orderno];
  42. // ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.OrderNo == orderno) ?? new ConsumerOrders();
  43. // order.CurDivi = cur;
  44. // order.SeoDescription = Regex.Replace(function.CheckNull(order.SeoDescription), "\"UpdateDate\":\".*?\"", "\"UpdateDate\":\"" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + "\"");
  45. // order.SeoDescription = Regex.Replace(function.CheckNull(order.SeoDescription), "\"ProfitDays\":.*?,", "\"ProfitDays\":90,");
  46. // RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + order.PayMode + ":" + order.MerchantId, order);
  47. // }
  48. // string content = function.ReadInstance("/222.log");
  49. // string[] contents = content.Split('\n');
  50. // foreach(string sub in contents)
  51. // {
  52. // // RedisDbconn.Instance.AddList("WeChatPayBackHd", sub);
  53. // RedisDbconn.Instance.AddList("PartOrderQueue", sub);
  54. // }
  55. // DataTable dt = CustomerSqlConn.dtable("select tb.Id,tb.PayMode,p.Id pId from (select Id,PayMode from ConsumerOrders where CreateDate>='2024-01-18 00:00:00' and `Status`>0) tb left join ConsumerProfit p on tb.Id=p.OrderId", AppConfig.Base.SqlConnStr);
  56. // foreach(DataRow dr in dt.Rows)
  57. // {
  58. // string Id = dr["Id"].ToString();
  59. // string PayMode = dr["PayMode"].ToString();
  60. // string pId = dr["pId"].ToString();
  61. // if(string.IsNullOrEmpty(pId))
  62. // {
  63. // RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + PayMode + ":List", Id);
  64. // }
  65. // }
  66. // List<int> orders = RedisDbconn.Instance.GetList<ConsumerOrders>("ConsumerOrdersHd:Divi:2:1272").Select(m => m.Id).ToList();
  67. // DataTable dt = CustomerSqlConn.dtable("select OrderId,sum(GetMoney) money from ConsumerProfit where MerchantId=1272 group by OrderId order by OrderId", AppConfig.Base.SqlConnStr);
  68. // foreach(DataRow dr in dt.Rows)
  69. // {
  70. // decimal cur = decimal.Parse(dr["money"].ToString());
  71. // int OrderId = int.Parse(dr["OrderId"].ToString());
  72. // if(!orders.Contains(OrderId))
  73. // {
  74. // // string orderno = dr["OrderNo"].ToString();
  75. // ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == OrderId) ?? new ConsumerOrders();
  76. // if(order.MaxDivi - cur >= 1)
  77. // {
  78. // order.CurDivi = cur;
  79. // order.SeoDescription = Regex.Replace(function.CheckNull(order.SeoDescription), "\"UpdateDate\":\".*?\"", "\"UpdateDate\":\"" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + "\"");
  80. // order.SeoDescription = Regex.Replace(function.CheckNull(order.SeoDescription), "\"ProfitDays\":.*?,", "\"ProfitDays\":365,");
  81. // RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + order.PayMode + ":" + order.MerchantId, order);
  82. // var list = db.ConsumerProfit.Where(m => m.OrderId == order.Id).OrderBy(m => m.Id).ToList();
  83. // foreach(var sub in list)
  84. // {
  85. // if(cur >= sub.GetMoney)
  86. // {
  87. // cur -= sub.GetMoney;
  88. // }
  89. // else
  90. // {
  91. // if(cur > 0)
  92. // {
  93. // var edit = db.ConsumerProfit.FirstOrDefault(m => m.OrderId == order.Id);
  94. // if(edit != null)
  95. // {
  96. // edit.GetMoney = cur;
  97. // db.SaveChanges();
  98. // }
  99. // }
  100. // else
  101. // {
  102. // var edit = db.ConsumerProfit.FirstOrDefault(m => m.OrderId == order.Id);
  103. // if(edit != null)
  104. // {
  105. // db.ConsumerProfit.Remove(edit);
  106. // db.SaveChanges();
  107. // }
  108. // }
  109. // }
  110. // }
  111. // }
  112. // }
  113. // }
  114. // List<int> ids = new List<int>();
  115. // ids.Add(4058);
  116. // List<ConsumerOrders> orders = RedisDbconn.Instance.GetList<ConsumerOrders>("ConsumerOrdersHd:Divi:2:1271");
  117. // foreach(int oid in ids)
  118. // {
  119. // function.WriteLog("oid:" + oid, "返现id");
  120. // decimal curDivi = 0;
  121. // ConsumerOrders order = orders.FirstOrDefault(m => m.Id == oid);
  122. // if(order == null)
  123. // {
  124. // order = db.ConsumerOrders.FirstOrDefault(m => m.Id == oid);
  125. // curDivi = order.MaxDivi;
  126. // function.WriteLog("出局", "返现id");
  127. // }
  128. // else
  129. // {
  130. // function.WriteLog("未出局", "返现id");
  131. // curDivi = order.CurDivi;
  132. // }
  133. // if(order != null)
  134. // {
  135. // List<ConsumerProfit> profits = db.ConsumerProfit.Where(m => m.OrderId == oid).ToList();
  136. // foreach(ConsumerProfit profit in profits)
  137. // {
  138. // if(curDivi >= profit.GetMoney)
  139. // {
  140. // curDivi -= profit.GetMoney;
  141. // }
  142. // else
  143. // {
  144. // function.WriteLog(profit.Id.ToString(), "返现id");
  145. // }
  146. // }
  147. // }
  148. // function.WriteLog("\n\n", "返现id");
  149. // }
  150. // db.Dispose();
  151. // decimal settleAmount = b / 100M;
  152. // decimal divideAmt = (1 - 0.0038M) * a;
  153. // divideAmt = decimal.Parse(divideAmt.ToString("f2"));
  154. // decimal hdfee = 0.0038M * a * (1 - g / 100 - 0.01M);
  155. // hdfee = decimal.Parse(hdfee.ToString("f2"));
  156. // decimal servicefee = 0.01M * a - hdfee;
  157. // servicefee = decimal.Parse(servicefee.ToString("f2"));
  158. // decimal amount = a*(1-0.0038M) - servicefee;
  159. // amount = decimal.Parse(amount.ToString("f2"));
  160. // decimal otherAmt = settleAmount - servicefee - amount;
  161. // if(otherAmt != 0)
  162. // {
  163. // amount += otherAmt;
  164. // }
  165. // amount = amount * 100; //金额(分)
  166. // servicefee = servicefee * 100;
  167. // string seviceAmount = servicefee.ToString("f0"); //服务费
  168. // string amountAmount = amount.ToString("f0");
  169. // return amountAmount + ":" + seviceAmount;
  170. return "ok";
  171. }
  172. public string bindapp(int mid)
  173. {
  174. // DataTable dt = CustomerSqlConn.dtable("select Id,MchtNo from MerchantAddInfo where HdStatus=3 and CreateDate>='2023-10-01 00:00:00' and MchtNo!='' and MchtNo is not null", AppConfig.Base.SqlConnStr);
  175. // DataTable dt = CustomerSqlConn.dtable("select Id,MchtNo from MerchantAddInfo where Id=" + mid, AppConfig.Base.SqlConnStr);
  176. // foreach(DataRow dr in dt.Rows)
  177. // {
  178. // CheckWeChatSignService.Instance.StartDo(new QueryMerchantStatus()
  179. // {
  180. // MerchantId = dr["Id"].ToString(),
  181. // MerchantNo = dr["MchtNo"].ToString(),
  182. // });
  183. // }
  184. Models.Main1.WebCMSEntities db1 = new Models.Main1.WebCMSEntities();
  185. WebCMSEntities db = new WebCMSEntities();
  186. MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == 1147);
  187. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == 1147);
  188. string pwd = "417027";
  189. merchant.LoginPwd = function.MD532(pwd);
  190. Models.Main1.MerchantLoginInfo info = db1.MerchantLoginInfo.FirstOrDefault(m => m.LoginMobile == merchantadd.MobilePhone);
  191. if (info == null)
  192. {
  193. info = db1.MerchantLoginInfo.Add(new Models.Main1.MerchantLoginInfo()
  194. {
  195. LoginMobile = merchantadd.MobilePhone,
  196. }).Entity;
  197. db1.SaveChanges();
  198. }
  199. info.LoginPwd = function.MD532(pwd);
  200. db1.SaveChanges();
  201. Models.Main1.MerchantAccountLinkInfo infolink = db1.MerchantAccountLinkInfo.FirstOrDefault(m => m.LoginId == info.Id && m.MerchantId == merchantadd.Id && m.Kind == 2);
  202. if (infolink == null)
  203. {
  204. infolink = db1.MerchantAccountLinkInfo.Add(new Models.Main1.MerchantAccountLinkInfo()
  205. {
  206. LoginId = info.Id,
  207. MerchantId = merchantadd.Id,
  208. Kind = 2,
  209. }).Entity;
  210. db1.SaveChanges();
  211. }
  212. db1.Dispose();
  213. db.Dispose();
  214. return "ok";
  215. }
  216. public string clearQueue(int OrderId, int MerchantId, int PayMode)
  217. {
  218. List<ConsumerOrders> list = RedisDbconn.Instance.GetList<ConsumerOrders>("ConsumerOrdersHd:Divi:" + PayMode + ":" + MerchantId + "", 1, 100000);
  219. foreach(ConsumerOrders sub in list)
  220. {
  221. if(sub.Id == OrderId)
  222. {
  223. RedisDbconn.Instance.DelFromList("ConsumerOrdersHd:Divi:2:1272", sub);
  224. }
  225. }
  226. return "ok";
  227. }
  228. }
  229. }