PosMerchantInfoDbconn.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.MainModels;
  5. namespace MySystem
  6. {
  7. public class PosMerchantInfoDbconn
  8. {
  9. public readonly static PosMerchantInfoDbconn Instance = new PosMerchantInfoDbconn();
  10. #region 获取单个字段
  11. public PosMerchantInfo Get(int Id)
  12. {
  13. WebCMSEntities db = new WebCMSEntities();
  14. PosMerchantInfo order = db.PosMerchantInfo.FirstOrDefault(m => m.Id == Id);
  15. if (order != null)
  16. {
  17. }
  18. db.Dispose();
  19. return order;
  20. }
  21. #endregion
  22. #region 获取列表
  23. public List<PosMerchantInfo> GetList(int UserId, int pageNum = 1, int pageSize = 10)
  24. {
  25. string key = "PosMerchantInfoList:" + UserId;
  26. List<PosMerchantInfo> list = new List<PosMerchantInfo>();
  27. if (RedisDbconn.Instance.Exists(key))
  28. {
  29. list = RedisDbconn.Instance.GetList<PosMerchantInfo>(key, pageNum, pageSize);
  30. if (list.Count > 0)
  31. {
  32. return list;
  33. }
  34. }
  35. RedisDbconn.Instance.GetLock(key + ":lock");
  36. WebCMSEntities db = new WebCMSEntities();
  37. List<PosMerchantInfo> newlist = new List<PosMerchantInfo>();
  38. var mysqllist = db.PosMachinesTwo.Select(m => new { m.BuyUserId, m.UserId, m.BindingState, m.Id, m.BindMerchantId, m.Status }).Where(m => m.Status > -1 && m.BuyUserId == UserId && m.BindingState == 1).OrderByDescending(m => m.Id).ToList();
  39. if (mysqllist.Count > 0)
  40. {
  41. foreach (var sub in mysqllist)
  42. {
  43. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == sub.BindMerchantId) ?? new PosMerchantInfo();
  44. newlist.Add(merchant);
  45. }
  46. RedisDbconn.Instance.Clear(key);
  47. foreach (PosMerchantInfo sub in newlist)
  48. {
  49. RedisDbconn.Instance.AddRightList(key, sub);
  50. }
  51. RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(300, 600));
  52. }
  53. db.Dispose();
  54. RedisDbconn.Instance.ReleaseLock(key + ":lock");
  55. return newlist;
  56. }
  57. #endregion
  58. #region 获取列表子账号
  59. public List<PosMerchantInfo> GetChildList(int PartnerId, int UserId, int pageNum = 1, int pageSize = 10)
  60. {
  61. string key = "PosMerchantInfoList:" + PartnerId;
  62. List<PosMerchantInfo> list = new List<PosMerchantInfo>();
  63. if (RedisDbconn.Instance.Exists(key))
  64. {
  65. list = RedisDbconn.Instance.GetList<PosMerchantInfo>(key, pageNum, pageSize);
  66. if (list.Count > 0)
  67. {
  68. return list;
  69. }
  70. }
  71. RedisDbconn.Instance.GetLock(key + ":lock");
  72. WebCMSEntities db = new WebCMSEntities();
  73. List<int> posId = new List<int>();
  74. var Id = db.BusinessPartnerPos.Where(m => m.Id == PartnerId).ToList();
  75. foreach (var item in Id)
  76. {
  77. posId.Add(item.PosId);
  78. }
  79. List<PosMerchantInfo> newlist = new List<PosMerchantInfo>();
  80. var mysqllist = db.PosMachinesTwo.Select(m => new { m.BuyUserId, m.UserId, m.BindingState, m.Id, m.BindMerchantId, m.Status }).Where(m => m.Status > -1 && m.BuyUserId == UserId && m.BindingState == 1 && posId.Contains(m.Id)).OrderByDescending(m => m.Id).ToList();
  81. if (mysqllist.Count > 0)
  82. {
  83. foreach (var sub in mysqllist)
  84. {
  85. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == sub.BindMerchantId) ?? new PosMerchantInfo();
  86. newlist.Add(merchant);
  87. }
  88. RedisDbconn.Instance.Clear(key);
  89. foreach (PosMerchantInfo sub in newlist)
  90. {
  91. RedisDbconn.Instance.AddRightList(key, sub);
  92. }
  93. RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(300, 600));
  94. }
  95. db.Dispose();
  96. RedisDbconn.Instance.ReleaseLock(key + ":lock");
  97. return newlist;
  98. }
  99. #endregion
  100. }
  101. }