OperateAddService.cs 3.3 KB

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