SetDesposit.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Threading;
  6. using MySystem.Models;
  7. using Library;
  8. namespace MySystem
  9. {
  10. /// <summary>
  11. /// 设置预发机超过30天预发押金自动扣减
  12. /// </summary>
  13. public class SetDesposit
  14. {
  15. public readonly static SetDesposit Instance = new SetDesposit();
  16. private SetDesposit()
  17. { }
  18. public void Start()
  19. {
  20. Thread th = new Thread(doSomething);
  21. th.IsBackground = true;
  22. th.Start();
  23. }
  24. public void doSomething()
  25. {
  26. while (true)
  27. {
  28. if (DateTime.Now.Hour > 0 && DateTime.Now.Hour < 17)
  29. {
  30. try
  31. {
  32. string check = function.ReadInstance("/SetDesposit/check" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
  33. if (string.IsNullOrEmpty(check))
  34. {
  35. function.WritePage("/SetDesposit/", "check" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", DateTime.Now.ToString("HH:mm:ss"));
  36. WebCMSEntities db = new WebCMSEntities();
  37. var date = DateTime.Now.AddDays(-30);
  38. bool op = true;
  39. while (op)
  40. {
  41. var smallPos = db.PreSendStockDetail.Where(m => m.Status == 1 && m.Sort == 0 && m.CreateDate <= date && m.ApplyFlag == 0).ToList();
  42. foreach (var item in smallPos)
  43. {
  44. var tuserAccount = db.UserAccount.FirstOrDefault(m => m.Id == item.ToUserId) ?? new UserAccount();
  45. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == item.BrandId);
  46. var amount = 0;
  47. if (brandInfo.Name.Contains("电签"))
  48. {
  49. amount = 200;
  50. }
  51. if (brandInfo.Name.Contains("大POS"))
  52. {
  53. amount = 300;
  54. }
  55. if (tuserAccount.Id > 0)
  56. {
  57. tuserAccount.SmallStoreDeposit += amount;//添加小分仓押金
  58. var add = db.UserAccountRecord.Add(new UserAccountRecord()
  59. {
  60. CreateDate = DateTime.Now,
  61. Remark = "小分仓押金暂扣",
  62. ChangeType = 63,
  63. BeforeBalanceAmount = tuserAccount.SmallStoreDeposit - amount, //变更前余额
  64. AfterBalanceAmount = tuserAccount.SmallStoreDeposit, //变更后余额
  65. ChangeAmount = amount, //变更金额
  66. UserId = item.ToUserId,
  67. }).Entity;
  68. db.SaveChanges();
  69. }
  70. item.Sort = 1;
  71. db.SaveChanges();
  72. }
  73. }
  74. db.Dispose();
  75. }
  76. }
  77. catch (Exception ex)
  78. {
  79. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "设置预发机超过30天预发押金自动扣减异常");
  80. }
  81. }
  82. Thread.Sleep(5000);
  83. }
  84. }
  85. }
  86. }