SettleAmountCheckHelper.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using MySystem.Models.Main;
  6. using Library;
  7. using System.Threading;
  8. using Microsoft.Extensions.Hosting;
  9. using System.Threading.Tasks;
  10. using LitJson;
  11. namespace MySystem
  12. {
  13. public class SettleAmountCheckHelper
  14. {
  15. public readonly static SettleAmountCheckHelper Instance = new SettleAmountCheckHelper();
  16. private SettleAmountCheckHelper()
  17. {
  18. }
  19. public void Start()
  20. {
  21. Thread th = new Thread(StartDo);
  22. th.IsBackground = true;
  23. th.Start();
  24. }
  25. public void StartDo()
  26. {
  27. while (true)
  28. {
  29. DoSomeThing();
  30. Thread.Sleep(2000);
  31. }
  32. }
  33. public void DoSomeThing()
  34. {
  35. try
  36. {
  37. WebCMSEntities db = new WebCMSEntities();
  38. DateTime starDate = DateTime.Parse("2025-01-01 00:00:00");
  39. DateTime checkDate = DateTime.Now.AddMinutes(-10);
  40. var orders = db.ConsumerOrders.Select(m => new { m.Id, m.Status, m.IsAct, m.UpdateDate, m.SettleAmount }).Where(m => m.Status > 0 && m.IsAct == 1 && m.UpdateDate >= starDate && m.UpdateDate < checkDate && m.SettleAmount == 0).ToList();
  41. foreach(var sub in orders)
  42. {
  43. ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == sub.Id);
  44. if (order != null)
  45. {
  46. string text = function.GetWebRequest(Library.ConfigurationManager.AppSettings["SpHost"].ToString() + "/Api/PublicMethod/GetSettleOrderAmount?orderNo=" + order.SeoTitle + "&date=" + order.CreateDate.Value.ToString("yyyy-M-d"));
  47. order.SettleAmount = int.Parse(function.CheckInt(text));
  48. db.SaveChanges();
  49. }
  50. }
  51. db.Dispose();
  52. }
  53. catch(Exception ex)
  54. {
  55. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "检查未结算分账订单异常");
  56. }
  57. }
  58. }
  59. }