OperateAddService.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 = edit.ReturnAmount;
  53. if(ReturnAmount == 0)
  54. {
  55. return;
  56. }
  57. UserRankItem orderUser = PosCouponPrizeService.Instance.GetUserLevel(db, edit.UserId);
  58. if(orderUser.UserType != 1)
  59. {
  60. return;
  61. }
  62. string ParentNav = orderUser.ParentNav;
  63. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  64. Array.Reverse(ParentNavList);
  65. int index = 0;
  66. bool PrizeFlag = false; //奖励发放标识
  67. // bool DirectPrizeFlag = false; //奖励发放标识
  68. foreach(string ParentId in ParentNavList)
  69. {
  70. UserRankItem parentUser = PosCouponPrizeService.Instance.GetUserLevel(db, int.Parse(ParentId));
  71. index += 1;
  72. if(parentUser.OperateLevel > 1 && PosCouponPrizeService.Instance.CheckOpReserve(opdb, ReturnAmount, parentUser.Id) && !PrizeFlag)
  73. {
  74. //扣减备用金
  75. PosCouponPrizeService.Instance.OperateAmountChange(opdb, parentUser.Id, ReturnAmount, 2, 1, "购买运营中心", true, Id);
  76. //返回到余额
  77. PosCouponPrizeService.Instance.OperateAmountChange(opdb, parentUser.Id, ReturnAmount, 1, 2, "购买运营中心", true, Id);
  78. PrizeFlag = true;
  79. }
  80. // if((parentUser.OperateLevel > 0 || parentUser.LeaderLevel > 0) && !DirectPrizeFlag)
  81. // {
  82. // //发放5888推荐奖励
  83. // PosCouponPrizeService.Instance.OpAccount(db, parentUser.Id, parentUser.Id, 5888, 1, 129);
  84. // DirectPrizeFlag = true;
  85. // }
  86. }
  87. }
  88. db.Dispose();
  89. opdb.Dispose();
  90. }
  91. }
  92. }