UserTradeDbconn.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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(" + fieldList + ") " + fieldList + ",";
  26. }
  27. DataTable dt = CustomerSqlConn.dtable("select " + fieldList.TrimEnd(',') + " from MerchantTradeSummary" + TradeDate + " where MerchantId=" + MerchantId + " and ", 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][0].ToString());
  33. }
  34. }
  35. return AmtList;
  36. }
  37. /// <summary>
  38. /// 获取交易统计列表
  39. /// </summary>
  40. /// <param name="MerchantId">商户Id</param>
  41. /// <param name="TradeMonth">月份(yyyyMM)</param>
  42. /// <param name="fields">字段(多个用逗号隔开)</param>
  43. /// <returns></returns>
  44. public List<Dictionary<string, object>> GetDateTradeList(int MerchantId, string TradeMonth, string fields)
  45. {
  46. List<Dictionary<string, object>> AmtList = new List<Dictionary<string, object>>();
  47. DataTable dt = CustomerSqlConn.dtable("select " + fields + " from MerchantTradeSummary" + TradeMonth + " where MerchantId=" + MerchantId + " and Trade", AppConfig.Base.StatConnRds);
  48. if(dt.Rows.Count > 0)
  49. {
  50. Dictionary<string, object> Item = new Dictionary<string, object>();
  51. foreach(string field in fields.Split(','))
  52. {
  53. Item.Add(field, dt.Rows[0][0].ToString());
  54. }
  55. AmtList.Add(Item);
  56. }
  57. return AmtList;
  58. }
  59. /// <summary>
  60. /// 获取交易统计列表
  61. /// </summary>
  62. /// <param name="MerchantId">商户Id</param>
  63. /// <param name="TradeMonth">月份(yyyyMM)</param>
  64. /// <param name="fields">字段(多个用逗号隔开)</param>
  65. /// <returns></returns>
  66. public List<Dictionary<string, object>> GetMonthTradeList(int MerchantId, string fields)
  67. {
  68. List<Dictionary<string, object>> AmtList = new List<Dictionary<string, object>>();
  69. string fieldList = "";
  70. foreach(string field in fields.Split(','))
  71. {
  72. fieldList += "sum(" + field + ") " + field + ",";
  73. }
  74. for(int i = 0; i < 6; i ++)
  75. {
  76. Dictionary<string, object> Item = new Dictionary<string, object>();
  77. Item.Add("TradeDate", DateTime.Now.AddMonths(-i).ToString("yyyy-MM"));
  78. DataTable dt = CustomerSqlConn.dtable("select " + fieldList.TrimEnd(',') + " from MerchantTradeSummary" + DateTime.Now.AddMonths(-i).ToString("yyyyMM") + " where MerchantId=" + MerchantId + "", AppConfig.Base.StatConnRds);
  79. if(dt.Rows.Count > 0)
  80. {
  81. foreach(string field in fields.Split(','))
  82. {
  83. Item.Add(field, function.CheckNum(dt.Rows[0][0].ToString()));
  84. }
  85. }
  86. else
  87. {
  88. foreach(string field in fields.Split(','))
  89. {
  90. Item.Add(field, "0");
  91. }
  92. }
  93. AmtList.Add(Item);
  94. }
  95. return AmtList;
  96. }
  97. }
  98. }