OperateStockService.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using System.Data;
  7. using System.Threading;
  8. using MySystem.OpModels;
  9. namespace MySystem
  10. {
  11. public class OperateStockService
  12. {
  13. public readonly static OperateStockService Instance = new OperateStockService();
  14. private OperateStockService()
  15. { }
  16. public void Start()
  17. {
  18. Thread th = new Thread(dosomething);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. public void dosomething()
  23. {
  24. while (true)
  25. {
  26. try
  27. {
  28. string sql = "";
  29. string conn = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  30. DataTable dt = CustomerSqlConn.dtable("select UserId,sum(LaveNum)+(select count(Id) from PreSendStockDetail where FromUserId=s.UserId and `Status`>=0 and `Status`<=1 and ApplyFlag=0) from StoreHouse s where `Status`>-1 group by UserId", conn);
  31. foreach(DataRow dr in dt.Rows)
  32. {
  33. sql += "update Users set StoreStock=" + dr[1].ToString() + " where Id=" + dr["UserId"].ToString() + ";";
  34. }
  35. CustomerSqlConn.op(sql, conn);
  36. }
  37. catch (Exception ex)
  38. {
  39. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "运营中心返额度异常");
  40. }
  41. Thread.Sleep(600000);
  42. }
  43. }
  44. }
  45. }