CheckWeChatSignService.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.Models;
  5. using Library;
  6. using LitJson;
  7. namespace MySystem
  8. {
  9. public class CheckWeChatSignService
  10. {
  11. public readonly static CheckWeChatSignService Instance = new CheckWeChatSignService();
  12. private CheckWeChatSignService()
  13. { }
  14. public void Start(JobMqMsg jobInfo)
  15. {
  16. try
  17. {
  18. WebCMSEntities db = new WebCMSEntities();
  19. List<MerchantSign> deletes = new List<MerchantSign>();
  20. List<MerchantSign> signs = TendisDbconn.Instance.GetList<MerchantSign>("WeChatSignList", 1, 10000000);
  21. foreach (MerchantSign sign in signs)
  22. {
  23. Dictionary<string, object> dic = new WeChatFunction().QueryMerchant(sign.BusinessCode);
  24. if (dic["applyment_state"].ToString() == "APPLYMENT_STATE_TO_BE_SIGNED")
  25. {
  26. string sign_url = dic["sign_url"].ToString();
  27. MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId && m.Status == 0);
  28. if (merchantadd != null)
  29. {
  30. merchantadd.Status = 1;
  31. string SignUrlList = function.CheckNull(merchantadd.SeoKeyword);
  32. if (string.IsNullOrEmpty(SignUrlList))
  33. {
  34. SignUrlList = "WeChat:" + sign_url + ";";
  35. }
  36. else
  37. {
  38. SignUrlList += "WeChat:" + sign_url+ ";";
  39. }
  40. merchantadd.SeoKeyword = SignUrlList;
  41. db.SaveChanges();
  42. PxcModels.WebCMSEntities dbpxc = new PxcModels.WebCMSEntities();
  43. PxcModels.MerchantAddInfo merchantadd2 = dbpxc.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId && m.Status == 0);
  44. if (merchantadd2 != null)
  45. {
  46. merchantadd2.Status = 1;
  47. merchantadd2.SeoKeyword = SignUrlList;
  48. dbpxc.SaveChanges();
  49. }
  50. dbpxc.Dispose();
  51. BothdisDbconn.Instance.Set("MerchantAddInfo:" + sign.MerchantAddInfoId, merchantadd);
  52. }
  53. }
  54. else if (dic["applyment_state"].ToString() == "APPLYMENT_STATE_FINISHED")
  55. {
  56. MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId && m.Status == 1);
  57. if (merchantadd != null)
  58. {
  59. merchantadd.Status = 2;
  60. db.SaveChanges();
  61. PxcModels.WebCMSEntities dbpxc = new PxcModels.WebCMSEntities();
  62. PxcModels.MerchantAddInfo merchantadd2 = dbpxc.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId && m.Status == 1);
  63. if (merchantadd2 != null)
  64. {
  65. merchantadd2.Status = 2;
  66. dbpxc.SaveChanges();
  67. }
  68. dbpxc.Dispose();
  69. BothdisDbconn.Instance.Set("MerchantAddInfo:" + sign.MerchantAddInfoId, merchantadd);
  70. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
  71. List<MerchantInfo> merchants = RedisDbconn.Instance.GetList<MerchantInfo>("TmpMerchantInfo:" + merchant.UserId, 1, 1000000);
  72. MerchantInfo check = merchants.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId);
  73. if (check != null)
  74. {
  75. merchants.Remove(check);
  76. RedisDbconn.Instance.Clear("TmpMerchantInfo:" + merchant.UserId);
  77. RedisDbconn.Instance.AddList("TmpMerchantInfo:" + merchant.UserId, merchants.ToArray());
  78. }
  79. deletes.Add(sign);
  80. }
  81. }
  82. }
  83. if (deletes.Count > 0)
  84. {
  85. foreach (MerchantSign delete in deletes)
  86. {
  87. signs.Remove(delete);
  88. }
  89. TendisDbconn.Instance.Clear("WeChatSignList");
  90. TendisDbconn.Instance.AddList("WeChatSignList", signs.ToArray());
  91. }
  92. jobInfo.Status = 1;
  93. jobInfo.Msg = "执行完成";
  94. RabbitMQClient.Instance.SendMsg(Newtonsoft.Json.JsonConvert.SerializeObject(jobInfo), "PublicBack");
  95. }
  96. catch (Exception ex)
  97. {
  98. TendisDbconn.Instance.AddList("public:merchant:signerr", DateTime.Now.ToString() + ":" + ex.ToString());
  99. }
  100. }
  101. }
  102. }