UserMonthFeeHelper.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Linq;
  5. using System.Data;
  6. using MySystem;
  7. using MySystem.PxcModels;
  8. using Library;
  9. using LitJson;
  10. public class UserMonthFeeHelper
  11. {
  12. public readonly static UserMonthFeeHelper Instance = new UserMonthFeeHelper();
  13. private UserMonthFeeHelper()
  14. {
  15. }
  16. public void Start()
  17. {
  18. Thread th = new Thread(DoWorks);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. private void DoWorks()
  23. {
  24. while (true)
  25. {
  26. try
  27. {
  28. string content = RedisDbconn.Instance.RPop<string>("UserMonthFeeQueue");
  29. if(!string.IsNullOrEmpty(content))
  30. {
  31. WebCMSEntities db = new WebCMSEntities();
  32. DoSomething(db);
  33. db.Dispose();
  34. }
  35. }
  36. catch (Exception ex)
  37. {
  38. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "创客每月月费扣款异常");
  39. }
  40. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "创客每月月费扣款日志");
  41. Thread.Sleep(60000);
  42. }
  43. }
  44. public void DoSomething(WebCMSEntities db)
  45. {
  46. var Users = db.UserAccount.Select(m => new { m.Id, m.BalanceAmount }).Where(m => m.BalanceAmount > 0).ToList();
  47. foreach(var User in Users)
  48. {
  49. if(User.BalanceAmount > 10)
  50. {
  51. AlipayPayBack2Service.Instance.ChangeAccount(db, new Orders(), User.Id, -10, 125);
  52. }
  53. else
  54. {
  55. AlipayPayBack2Service.Instance.ChangeAccount(db, new Orders(), User.Id, -User.BalanceAmount, 125);
  56. }
  57. }
  58. }
  59. }