OperateAddService.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using System.Threading;
  6. using MySystem.PxcModels;
  7. using Library;
  8. using LitJson;
  9. namespace MySystem
  10. {
  11. public class OperateAddService
  12. {
  13. public readonly static OperateAddService Instance = new OperateAddService();
  14. private OperateAddService()
  15. { }
  16. public void Start()
  17. {
  18. Thread th = new Thread(ready);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. private void ready()
  23. {
  24. bool op = true;
  25. while (op)
  26. {
  27. string content = RedisDbconn.Instance.RPop<string>("OperateAddServiceQueue");
  28. if (!string.IsNullOrEmpty(content))
  29. {
  30. try
  31. {
  32. dosomething(int.Parse(function.CheckInt(content)));
  33. }
  34. catch(Exception ex)
  35. {
  36. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "添加运营中心合伙人异常");
  37. }
  38. }
  39. else
  40. {
  41. Thread.Sleep(2000);
  42. }
  43. }
  44. }
  45. public void dosomething(int Id)
  46. {
  47. WebCMSEntities db = new WebCMSEntities();
  48. OpModels.WebCMSEntities opdb = new OpModels.WebCMSEntities();
  49. OpModels.SysAdmin edit = opdb.SysAdmin.FirstOrDefault(m => m.Id == Id);
  50. if (edit != null)
  51. {
  52. decimal ReturnAmount = 160000M;
  53. // if(edit.ReturnAmount > 0)
  54. // {
  55. // ReturnAmount = edit.ReturnAmount;
  56. // }
  57. // if(edit.ReturnFlag == 0)
  58. // {
  59. // return;
  60. // }
  61. UserRankItem orderUser = PosCouponPrizeService.Instance.GetUserLevel(db, edit.UserId);
  62. if(orderUser.UserType != 1)
  63. {
  64. return;
  65. }
  66. string ParentNav = orderUser.ParentNav;
  67. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  68. Array.Reverse(ParentNavList);
  69. int index = 0;
  70. bool PrizeFlag = false; //奖励发放标识
  71. // bool DirectPrizeFlag = false; //奖励发放标识
  72. foreach(string ParentId in ParentNavList)
  73. {
  74. UserRankItem parentUser = PosCouponPrizeService.Instance.GetUserLevel(db, int.Parse(ParentId));
  75. index += 1;
  76. if(parentUser.OperateLevel > 1 && PosCouponPrizeService.Instance.CheckOpReserve(opdb, ReturnAmount, parentUser.Id) && !PrizeFlag)
  77. {
  78. //扣减备用金
  79. PosCouponPrizeService.Instance.OperateAmountChange(opdb, parentUser.Id, ReturnAmount, 2, 1, "购买运营中心", true, Id);
  80. //返回到余额
  81. PosCouponPrizeService.Instance.OperateAmountChange(opdb, parentUser.Id, ReturnAmount, 1, 2, "购买运营中心", true, Id);
  82. PrizeFlag = true;
  83. }
  84. // if((parentUser.OperateLevel > 0 || parentUser.LeaderLevel > 0) && !DirectPrizeFlag)
  85. // {
  86. // //发放5888推荐奖励
  87. // PosCouponPrizeService.Instance.OpAccount(db, parentUser.Id, parentUser.Id, 5888, 1, 129);
  88. // DirectPrizeFlag = true;
  89. // }
  90. }
  91. }
  92. db.Dispose();
  93. opdb.Dispose();
  94. }
  95. }
  96. }