LiShuaFeeSetService.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Threading;
  6. using MySystem.PxcModels;
  7. using Library;
  8. using LitJson;
  9. namespace MySystem
  10. {
  11. /// <summary>
  12. /// 设置机具费率标记并推送消息
  13. /// </summary>
  14. public class LiShuaFeeSetService
  15. {
  16. public readonly static LiShuaFeeSetService Instance = new LiShuaFeeSetService();
  17. private LiShuaFeeSetService()
  18. { }
  19. public void Start()
  20. {
  21. Thread th = new Thread(doSomething);
  22. th.IsBackground = true;
  23. th.Start();
  24. }
  25. public void doSomething()
  26. {
  27. while (true)
  28. {
  29. try
  30. {
  31. DateTime check = DateTime.Now.AddHours(1);
  32. WebCMSEntities db = new WebCMSEntities();
  33. var list = db.LiShuaFeeSetRecord.Where(m => m.CreateDate < check && string.IsNullOrEmpty(m.TradeFeeAmt) && string.IsNullOrEmpty(m.TradeFeeRate)).OrderBy(m => m.Id).ToList();
  34. foreach(var sub in list)
  35. {
  36. string back = PublicImportDataService.Instance.QueryLiSDeposit(sub.MerNo, "");
  37. JsonData jsonObj = JsonMapper.ToObject(back);
  38. if(jsonObj["ret_code"].ToString() == "00")
  39. {
  40. string TradeFeeAmt = "";
  41. string TradeFeeRate = "";
  42. JsonData feeList = jsonObj["feeList"];
  43. for (int i = 0; i < feeList.Count; i++)
  44. {
  45. string feeCalcType = feeList["feeCalcType"].ToString();
  46. if(feeCalcType == "M5") TradeFeeRate = feeList["rate"].ToString();
  47. if(feeCalcType == "T0") TradeFeeAmt = feeList["rate"].ToString();
  48. }
  49. if(!string.IsNullOrEmpty(TradeFeeAmt) && !string.IsNullOrEmpty(TradeFeeRate))
  50. {
  51. LiShuaFeeSetRecord edit = db.LiShuaFeeSetRecord.FirstOrDefault(m => m.Id == sub.Id);
  52. if(edit != null)
  53. {
  54. edit.TradeFeeAmt = TradeFeeAmt;
  55. edit.TradeFeeRate = TradeFeeRate;
  56. db.SaveChanges();
  57. }
  58. }
  59. }
  60. }
  61. db.Dispose();
  62. }
  63. catch (Exception ex)
  64. {
  65. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "立刷费率查询异常");
  66. }
  67. Thread.Sleep(600000);
  68. }
  69. }
  70. public void StartDo()
  71. {
  72. Thread th = new Thread(doSomethingDo);
  73. th.IsBackground = true;
  74. th.Start();
  75. }
  76. public void doSomethingDo()
  77. {
  78. while (true)
  79. {
  80. try
  81. {
  82. DateTime check = DateTime.Now.AddHours(1);
  83. WebCMSEntities db = new WebCMSEntities();
  84. var list = db.LiShuaFeeSetRecord.Where(m => m.CreateDate < check && !string.IsNullOrEmpty(m.TradeFeeAmt) && !string.IsNullOrEmpty(m.TradeFeeRate)).OrderBy(m => m.Id).ToList();
  85. foreach(var sub in list)
  86. {
  87. AddData(db, sub.PosSn, sub.TradeFeeRate, sub.TradeFeeAmt);
  88. LiShuaFeeSetRecord item = db.LiShuaFeeSetRecord.FirstOrDefault(m => m.Id == sub.Id);
  89. if(item != null)
  90. {
  91. db.LiShuaFeeSetRecord.Remove(item);
  92. db.SaveChanges();
  93. }
  94. }
  95. db.Dispose();
  96. }
  97. catch (Exception ex)
  98. {
  99. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "立刷费率提交报警异常");
  100. }
  101. Thread.Sleep(600000);
  102. }
  103. }
  104. public void AddData(WebCMSEntities db, string posSn, string feeRate, string feeAmt)
  105. {
  106. if(feeRate != "0.63" && feeRate != "0.6")
  107. {
  108. return;
  109. }
  110. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == posSn);
  111. if(pos != null)
  112. {
  113. bool op = false;
  114. if(feeRate == "0.63" && feeAmt == "3" && pos.UpFeeFlag == 1 && pos.DownFeeFlag == 0) //稳定期
  115. {
  116. op = true;
  117. }
  118. else if(feeRate == "0.63" && feeAmt == "0" && pos.DownFeeFlag == 1 && pos.DownFee == 0.63M) //稳定期A
  119. {
  120. op = true;
  121. }
  122. else if(feeRate == "0.6" && feeAmt == "0" && pos.DownFeeFlag == 0 && pos.DownFee == 0M) //扶持期
  123. {
  124. op = true;
  125. }
  126. else if(feeRate == "0.6" && feeAmt == "0" && pos.DownFeeFlag == 1 && pos.DownFee == 0.6M) //稳定期B
  127. {
  128. op = true;
  129. }
  130. if(!op)
  131. {
  132. DateTime check = DateTime.Now.AddHours(-1);
  133. if(!db.PosFeeWarningRecord.Any(m => m.PosSn == posSn && m.CreateDate >= check))
  134. {
  135. db.PosFeeWarningRecord.Add(new PosFeeWarningRecord()
  136. {
  137. CreateDate = DateTime.Now,
  138. UpdateDate = DateTime.Now,
  139. DownFee = pos.DownFee,
  140. DownFeeFlag = pos.DownFeeFlag,
  141. UpFeeFlag = pos.UpFeeFlag,
  142. TradeFeeAmt = feeAmt,
  143. TradeFeeRate = feeRate,
  144. PosSn = posSn,
  145. PosId = pos.Id,
  146. BrandId = pos.BrandId,
  147. });
  148. db.SaveChanges();
  149. }
  150. }
  151. }
  152. }
  153. }
  154. }