HelpProfitPreMerchantHelper.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using MySystem.PxcModels;
  6. using Library;
  7. using System.Threading;
  8. using Microsoft.Extensions.Hosting;
  9. using System.Threading.Tasks;
  10. namespace MySystem
  11. {
  12. public class HelpProfitPreMerchantHelper
  13. {
  14. public readonly static HelpProfitPreMerchantHelper Instance = new HelpProfitPreMerchantHelper();
  15. private HelpProfitPreMerchantHelper()
  16. {
  17. }
  18. public void Start()
  19. {
  20. Thread th = new Thread(StartFor);
  21. th.IsBackground = true;
  22. th.Start();
  23. }
  24. public void StartFor()
  25. {
  26. while (true)
  27. {
  28. if(DateTime.Now.Hour >= 2 && DateTime.Now.Hour <= 3)
  29. {
  30. StatEveryDay(DateTime.Now.ToString("yyyyMMdd"));
  31. }
  32. Thread.Sleep(600000);
  33. }
  34. }
  35. public void StatEveryDay(string Date)
  36. {
  37. string check = function.ReadInstance("/HelpProfitResetMerchant/" + Date + ".txt");
  38. if (!string.IsNullOrEmpty(check))
  39. {
  40. return;
  41. }
  42. function.WritePage("/HelpProfitResetMerchant/", Date + ".txt", DateTime.Now.ToString());
  43. DateTime start = DateTime.Parse(Date.Substring(0, 4) + "-" + Date.Substring(4, 2) + "-" + Date.Substring(6, 2) + " 00:00:00");
  44. string Month1 = start.ToString("yyyyMM");
  45. string Month2 = start.AddMonths(-1).ToString("yyyyMM");
  46. string Month3 = start.AddMonths(-2).ToString("yyyyMM");
  47. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
  48. string GetCount = function.ReadInstance("/PublicParam/HelpProfitMerCount.txt");
  49. if(string.IsNullOrEmpty(GetCount))
  50. {
  51. GetCount = "1000";
  52. function.WritePage("/PublicParam/", "HelpProfitMerCount.txt", GetCount);
  53. }
  54. RedisDbconn.Instance.Clear("HelpProfitMerchantIds");
  55. DataTable dt = OtherMySqlConn.dtable("SELECT MerchantId,sum FROM( SELECT MerchantId,SUM(TradeAmount) sum FROM PosMerchantTradeSummay WHERE MerchantId not in (select MerchantId from HelpProfitMerIds) AND TradeMonth in ('" + Month1 + "','" + Month2 + "','" + Month3 + "') GROUP BY MerchantId)a WHERE a.sum/3 >= 35000 and a.sum/3 <= 50000 limit " + GetCount);
  56. foreach(DataRow dr in dt.Rows)
  57. {
  58. RedisDbconn.Instance.AddList("HelpProfitMerchantIds", int.Parse(function.CheckInt(dr["MerchantId"].ToString())));
  59. }
  60. }
  61. }
  62. }