AutoOpOrderService.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using System.Threading;
  6. using MySystem.Models;
  7. using Library;
  8. using LitJson;
  9. namespace MySystem
  10. {
  11. public class AutoOpOrderService
  12. {
  13. public readonly static AutoOpOrderService Instance = new AutoOpOrderService();
  14. private AutoOpOrderService()
  15. { }
  16. public void StartOrderCancel()
  17. {
  18. Thread th = new Thread(StartOrderCancelDo);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. private void StartOrderCancelDo()
  23. {
  24. while (true)
  25. {
  26. try
  27. {
  28. string conn = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  29. string checkDate = DateTime.Now.AddMinutes(-20).ToString("yyyy-MM-dd HH:mm:ss");
  30. CustomerSqlConn.op("update OrderProduct set Status=-1 where OrderId in (select Id from Orders where Status=0 and CreateDate<'" + checkDate + "')", conn);
  31. CustomerSqlConn.op("update Orders set Status=-1 where Status=0 and CreateDate<'" + checkDate + "'", conn);
  32. Thread.Sleep(60000);
  33. }
  34. catch (Exception ex)
  35. {
  36. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "定时取消未支付订单异常");
  37. }
  38. }
  39. }
  40. public void StartOrderConfirm()
  41. {
  42. Thread th = new Thread(StartOrderConfirmDo);
  43. th.IsBackground = true;
  44. th.Start();
  45. }
  46. private void StartOrderConfirmDo()
  47. {
  48. while (true)
  49. {
  50. try
  51. {
  52. string conn = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  53. string checkDate = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd HH:mm:ss");
  54. CustomerSqlConn.op("update Orders set Status=-1 where Status=2 and SendDate<'" + checkDate + "'", conn);
  55. Thread.Sleep(3600000);
  56. }
  57. catch (Exception ex)
  58. {
  59. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "定时自动确认收货异常");
  60. }
  61. }
  62. }
  63. }
  64. }