HomeController.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Data;
  6. using System.Threading.Tasks;
  7. using Microsoft.AspNetCore.Mvc;
  8. using Microsoft.Extensions.Logging;
  9. using MySystem.Models;
  10. using System.Threading;
  11. using Library;
  12. using LitJson;
  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 IActionResult Error()
  27. {
  28. string isapi = Request.Headers["Api"].ToString();
  29. if (isapi != "1")
  30. {
  31. if (Response.StatusCode == 500)
  32. {
  33. return Redirect("/public/errpage/pc/500.html");
  34. }
  35. else if (Response.StatusCode == 502)
  36. {
  37. return Redirect("/public/errpage/pc/502.html");
  38. }
  39. else if (Response.StatusCode == 404)
  40. {
  41. return Redirect("/public/errpage/pc/404.html");
  42. }
  43. }
  44. return View();
  45. }
  46. public string test(int id = 0)
  47. {
  48. string txt = "ok";
  49. // txt = WeChatFunction.Instance.QueryProfitShare("1646405429","4200001807202306098649105270","2023060910241258564572510");
  50. // ProfitHelper.Instance.ReturnStat(Id, 2);
  51. WebCMSEntities db = new WebCMSEntities();
  52. List<int> oids = new List<int>();
  53. if(id > 0)
  54. {
  55. oids.Add(id);
  56. }
  57. else
  58. {
  59. oids.Add(15);
  60. oids.Add(16);
  61. oids.Add(17);
  62. oids.Add(18);
  63. oids.Add(19);
  64. oids.Add(20);
  65. }
  66. foreach(int oid in oids)
  67. {
  68. ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == oid);
  69. if(order != null)
  70. {
  71. RedisDbconn.Instance.AddList("ConsumerOrders:Divi:2:List", order.Id.ToString());
  72. // RedisDbconn.Instance.AddList("ConsumerOrders:Divi:2:" + order.MerchantId, order);
  73. }
  74. }
  75. db.Dispose();
  76. return txt;
  77. }
  78. public string testAlipay()
  79. {
  80. // string content = AlipayFunction.Instance.QuerySignStatus("2023061317351531100060045");
  81. // List<RoyaltyParameters> Parameters = new List<RoyaltyParameters>();
  82. // Parameters.Add(new RoyaltyParameters()
  83. // {
  84. // Account = "2088141704579033",
  85. // Amount = "0.01",
  86. // });
  87. // string content = AlipayFunction.Instance.Settle("2023061615441556447868073", "2023061622001451251436120885", Parameters);
  88. // string content = AlipayFunction.Instance.BindSettleRelation(DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), "2088141704579033");
  89. // string content = AlipayFunction.Instance.Refund("2023061622001451251436120885", "0.01", "门店消费补贴");
  90. // string content = AlipayFunction.Instance.QuerySettle("2023071214274372011988068", "2023071222001457121457238496", "202307BB6d61386d17104395831e3ea6309f0X57");
  91. // MerchantConfirmService.Instance.StartDo(68, 2);
  92. // string content = AlipayFunction.Instance.BindSettleRelation(DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), AlipayFunction.Instance.Pid, "202307BB6d61386d17104395831e3ea6309f0X57");
  93. List<string> ordernos = new List<string>();
  94. ordernos.Add("2023100319505443423678128");
  95. WebCMSEntities db = new WebCMSEntities();
  96. List<ConsumerOrders> orders = db.ConsumerOrders.Where(m => ordernos.Contains(m.OrderNo)).OrderBy(m => m.Id).ToList();
  97. foreach(ConsumerOrders order in orders)
  98. {
  99. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantInfo();
  100. MerchantParamSet set = db.MerchantParamSet.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantParamSet();
  101. if(order.IsAct == 1 && order.PayMoney >= set.MinPayMoney)
  102. {
  103. MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
  104. // //添加分账接收方
  105. // if(merchantAdd.Sort == 0)
  106. // {
  107. // string content = AlipayFunction.Instance.BindSettleRelation(DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), AlipayFunction.Instance.Pid, merchantAdd.AlipayAuthToken);
  108. // LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + content, "支付宝添加分账方");
  109. // merchantAdd.Sort = 1;
  110. // db.SaveChanges();
  111. // }
  112. // //发起分账
  113. // decimal fee = order.PayMoney * 0.01M;
  114. // if(fee >= 0.01M)
  115. // {
  116. // string TradeNo = order.SeoTitle;
  117. // string OrderNo = order.OrderNo;
  118. // List<RoyaltyParameters> Parameters = new List<RoyaltyParameters>();
  119. // Parameters.Add(new RoyaltyParameters()
  120. // {
  121. // Account = AlipayFunction.Instance.Pid,
  122. // Amount = fee.ToString("f2"),
  123. // });
  124. // AlipayFunction.Instance.Settle(OrderNo, TradeNo, Parameters, merchantAdd.AlipayAuthToken);
  125. // //开始监听分账状态
  126. // Dictionary<string, object> req = new Dictionary<string, object>();
  127. // req.Add("TradeNo", TradeNo); //支付宝订单号
  128. // req.Add("OrderNo", OrderNo); //商户订单号
  129. // req.Add("AuthToken", merchantAdd.AlipayAuthToken);
  130. // RedisDbconn.Instance.AddList("AlipayShareQueue", Newtonsoft.Json.JsonConvert.SerializeObject(req));
  131. // }
  132. //添加分账接收方
  133. if(merchant.Version == 0)
  134. {
  135. WeChatFunction.Instance.AddReceive(merchantAdd.SubMchid, "MERCHANT_ID", WeChatFunction.Instance.MchId, WeChatFunction.Instance.MchName, "PARTNER");
  136. merchant.Version = 1;
  137. db.SaveChanges();
  138. }
  139. //发起分账
  140. decimal fee = order.PayMoney; //单位:分
  141. if(fee >= 1)
  142. {
  143. string TradeNo = order.SeoTitle;
  144. string OrderNo = order.OrderNo;
  145. List<ReceiverList> Receivers = new List<ReceiverList>();
  146. Receivers.Add(new ReceiverList()
  147. {
  148. type = "MERCHANT_ID", //分账接收方类型
  149. account = WeChatFunction.Instance.MchId, //分账接收方账号
  150. amount = int.Parse(fee.ToString("f0")), //分账金额
  151. description = "服务费", //分账描述
  152. });
  153. WeChatFunction.Instance.ProfitShare(merchantAdd.SubMchid, TradeNo, OrderNo, Receivers);
  154. //开始监听分账状态
  155. Dictionary<string, object> req = new Dictionary<string, object>();
  156. req.Add("SubMchid", merchantAdd.SubMchid); //子商户号
  157. req.Add("TradeNo", TradeNo); //微信订单号
  158. req.Add("OrderNo", OrderNo); //商户订单号
  159. RedisDbconn.Instance.AddList("ProfitShareQueue", Newtonsoft.Json.JsonConvert.SerializeObject(req));
  160. }
  161. }
  162. }
  163. db.Dispose();
  164. return "ok";
  165. }
  166. public string test1()
  167. {
  168. // ProfitHelper.Instance.DoProfit();
  169. List<string> list = new List<string>();
  170. list.Add("LKB01230900199998516");
  171. WebCMSEntities db = new WebCMSEntities();
  172. foreach(string sub in list)
  173. {
  174. bool op = db.PosMachinesTwo.Any(m => m.PosSn == sub);
  175. if(!op)
  176. {
  177. //insert into PosMachinesTwo (CreateDate,SourceStoreId,StoreId,PosSn,SourcePosSn) values (now(),2,2,'
  178. db.PosMachinesTwo.Add(new PosMachinesTwo()
  179. {
  180. CreateDate = DateTime.Now,
  181. SourceStoreId = 2,
  182. StoreId = 2,
  183. PosSn = sub,
  184. SourcePosSn = sub,
  185. });
  186. db.SaveChanges();
  187. }
  188. }
  189. db.Dispose();
  190. return "ok";
  191. }
  192. }
  193. }