HyfAddPrizeService.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using System.Threading;
  7. using MySystem.PxcModels;
  8. using System.Data;
  9. namespace MySystem
  10. {
  11. public class HyfAddPrizeService
  12. {
  13. public readonly static HyfAddPrizeService Instance = new HyfAddPrizeService();
  14. private HyfAddPrizeService()
  15. { }
  16. public void Start()
  17. {
  18. Thread th = new Thread(StartDo);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. public void StartDo()
  23. {
  24. while(true)
  25. {
  26. try
  27. {
  28. DoSomething();
  29. }
  30. catch(Exception ex)
  31. {
  32. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "盒力四射加码奖励异常");
  33. }
  34. Thread.Sleep(20000);
  35. }
  36. }
  37. public void DoSomething()
  38. {
  39. WebCMSEntities db = new WebCMSEntities();
  40. DateTime online = DateTime.Parse("2024-06-25 00:00:00");
  41. DateTime end = DateTime.Parse("2025-01-01 00:00:00");
  42. if(DateTime.Now > end) return;
  43. List<PosMachinesTwo> posList = db.PosMachinesTwo.Where(m => m.BindingState == 1 && m.ActivationState == 1 && m.BindingTime >= online && (m.BrandId == 12 || m.BrandId == 13) && m.Sort == 0).ToList();
  44. foreach (PosMachinesTwo pos in posList)
  45. {
  46. function.WriteLog(str: "机具号:" + pos.PosSn, "盒力四射加码奖励日志");
  47. DateTime leftTime = pos.BindingTime.Value.AddDays(7);
  48. DateTime rightTime = pos.BindingTime.Value.AddDays(30);
  49. decimal amt = 0;
  50. DataTable dt = CustomerSqlConn.dtable("select sum(TradeAmount) from PosMerchantTradeSummay where TradeDate>='" + leftTime.ToString("yyyyMMdd") + "' and TradeDate<='" + rightTime.ToString("yyyyMMdd") + "' and MerchantId=" + pos.BindMerchantId + "", MysqlConn.ReadSqlConnStr);
  51. if(dt.Rows.Count > 0)
  52. {
  53. amt = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString()));
  54. }
  55. if(amt >= 1000)
  56. {
  57. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  58. if (user != null)
  59. {
  60. function.WriteLog("机具所属人:" + user.Id, "盒力四射加码奖励日志");
  61. int GetUserId = user.Id;
  62. AlipayPayBack2Service.Instance.ChangeAccount(db, new Orders() { Id = pos.Id }, GetUserId, 50, 139);
  63. PosMachinesTwo edit = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.Id);
  64. if(edit != null)
  65. {
  66. edit.Sort = 1;
  67. db.SaveChanges();
  68. }
  69. }
  70. }
  71. function.WriteLog("\n\n\n", "盒力四射加码奖励日志");
  72. }
  73. db.Dispose();
  74. }
  75. }
  76. }