OperateAddService.cs 3.0 KB

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