UserTradeDbconn.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using System.Data;
  5. namespace MySystem
  6. {
  7. public class UserTradeDbconn
  8. {
  9. public readonly static UserTradeDbconn Instance = new UserTradeDbconn();
  10. public UserTradeDbconn()
  11. { }
  12. /// <summary>
  13. /// 获取交易统计数据
  14. /// </summary>
  15. /// <param name="MerchantId">商户Id</param>
  16. /// <param name="TradeDate">日期/月份(yyyyMMdd或yyyyMM)</param>
  17. /// <param name="fields">字段(多个用逗号隔开)</param>
  18. /// <returns></returns>
  19. public Dictionary<string, object> GetTrade(int MerchantId, string TradeDate, string fields)
  20. {
  21. Dictionary<string, object> AmtList = new Dictionary<string, object>();
  22. string fieldList = "";
  23. foreach(string field in fields.Split(','))
  24. {
  25. fieldList += "sum(" + field + ") " + field + ",";
  26. }
  27. DataTable dt = CustomerSqlConn.dtable("select " + fieldList.TrimEnd(',') + " from MerchantTradeSummary" + TradeDate + " where MerchantId=" + MerchantId + "", AppConfig.Base.StatConnRds);
  28. if(dt.Rows.Count > 0)
  29. {
  30. foreach(string field in fields.Split(','))
  31. {
  32. AmtList.Add(field, dt.Rows[0][field].ToString());
  33. }
  34. }
  35. else
  36. {
  37. foreach(string field in fields.Split(','))
  38. {
  39. AmtList.Add(field, "0");
  40. }
  41. }
  42. return AmtList;
  43. }
  44. /// <summary>
  45. /// 获取交易统计列表
  46. /// </summary>
  47. /// <param name="MerchantId">商户Id</param>
  48. /// <param name="TradeMonth">月份(yyyyMM)</param>
  49. /// <param name="fields">字段(多个用逗号隔开)</param>
  50. /// <returns></returns>
  51. public List<Dictionary<string, object>> GetDateTradeList(int MerchantId, string TradeMonth, string fields)
  52. {
  53. List<Dictionary<string, object>> AmtList = new List<Dictionary<string, object>>();
  54. DataTable dt = CustomerSqlConn.dtable("select " + fields + " from MerchantTradeSummary" + TradeMonth + " where MerchantId=" + MerchantId + " and Trade", AppConfig.Base.StatConnRds);
  55. if(dt.Rows.Count > 0)
  56. {
  57. Dictionary<string, object> Item = new Dictionary<string, object>();
  58. foreach(string field in fields.Split(','))
  59. {
  60. Item.Add(field, dt.Rows[0][field].ToString());
  61. }
  62. AmtList.Add(Item);
  63. }
  64. return AmtList;
  65. }
  66. /// <summary>
  67. /// 获取交易统计列表
  68. /// </summary>
  69. /// <param name="MerchantId">商户Id</param>
  70. /// <param name="TradeMonth">月份(yyyyMM)</param>
  71. /// <param name="fields">字段(多个用逗号隔开)</param>
  72. /// <returns></returns>
  73. public List<Dictionary<string, object>> GetMonthTradeList(int MerchantId, string fields)
  74. {
  75. List<Dictionary<string, object>> AmtList = new List<Dictionary<string, object>>();
  76. string fieldList = "";
  77. foreach(string field in fields.Split(','))
  78. {
  79. fieldList += "sum(" + field + ") " + field + ",";
  80. }
  81. for(int i = 0; i < 6; i ++)
  82. {
  83. Dictionary<string, object> Item = new Dictionary<string, object>();
  84. Item.Add("TradeDate", DateTime.Now.AddMonths(-i).ToString("yyyy-MM"));
  85. DataTable dt = CustomerSqlConn.dtable("select " + fieldList.TrimEnd(',') + " from MerchantTradeSummary" + DateTime.Now.AddMonths(-i).ToString("yyyyMM") + " where MerchantId=" + MerchantId + "", AppConfig.Base.StatConnRds);
  86. if(dt.Rows.Count > 0)
  87. {
  88. foreach(string field in fields.Split(','))
  89. {
  90. Item.Add(field, function.CheckNum(dt.Rows[0][field].ToString()));
  91. }
  92. }
  93. else
  94. {
  95. foreach(string field in fields.Split(','))
  96. {
  97. Item.Add(field, "0");
  98. }
  99. }
  100. AmtList.Add(Item);
  101. }
  102. return AmtList;
  103. }
  104. }
  105. }