SetDespositHelper.cs 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 SetDespositHelper
  14. {
  15. public readonly static SetDespositHelper Instance = new SetDespositHelper();
  16. private SetDespositHelper()
  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 < 9)
  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 && m.AuthFlag == 1).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. tuserAccount.ValidPreAmount += amount;//添加小分仓可用额度
  59. var add = db.UserAccountRecord.Add(new UserAccountRecord()
  60. {
  61. CreateDate = DateTime.Now,
  62. Remark = "小分仓押金暂扣",
  63. ChangeType = 63,
  64. BeforeBalanceAmount = tuserAccount.SmallStoreDeposit - amount, //变更前余额
  65. AfterBalanceAmount = tuserAccount.SmallStoreDeposit, //变更后余额
  66. ChangeAmount = amount, //变更金额
  67. UserId = item.ToUserId,
  68. }).Entity;
  69. db.SaveChanges();
  70. }
  71. item.Sort = 1;
  72. db.SaveChanges();
  73. }
  74. }
  75. db.Dispose();
  76. }
  77. }
  78. catch (Exception ex)
  79. {
  80. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "设置预发机超过30天预发押金自动扣减异常");
  81. }
  82. }
  83. Thread.Sleep(5000);
  84. }
  85. }
  86. }
  87. }