using System; using System.Collections.Generic; using Library; using System.Data; namespace MySystem { public class UserTradeDbconn { public readonly static UserTradeDbconn Instance = new UserTradeDbconn(); public UserTradeDbconn() { } /// /// 获取交易统计数据 /// /// 商户Id /// 日期/月份(yyyyMMdd或yyyyMM) /// 字段(多个用逗号隔开) /// public Dictionary GetTrade(int MerchantId, string TradeDate, string fields) { Dictionary AmtList = new Dictionary(); string fieldList = ""; foreach(string field in fields.Split(',')) { fieldList += "sum(" + field + ") " + field + ","; } DataTable dt = CustomerSqlConn.dtable("select " + fieldList.TrimEnd(',') + " from MerchantTradeSummary" + TradeDate + " where MerchantId=" + MerchantId + "", AppConfig.Base.StatConnRds); if(dt.Rows.Count > 0) { foreach(string field in fields.Split(',')) { AmtList.Add(field, dt.Rows[0][field].ToString()); } } else { foreach(string field in fields.Split(',')) { AmtList.Add(field, "0"); } } return AmtList; } /// /// 获取交易统计列表 /// /// 商户Id /// 月份(yyyyMM) /// 字段(多个用逗号隔开) /// public List> GetDateTradeList(int MerchantId, string TradeMonth, string fields) { List> AmtList = new List>(); DataTable dt = CustomerSqlConn.dtable("select " + fields + " from MerchantTradeSummary" + TradeMonth + " where MerchantId=" + MerchantId + " and Trade", AppConfig.Base.StatConnRds); if(dt.Rows.Count > 0) { Dictionary Item = new Dictionary(); foreach(string field in fields.Split(',')) { Item.Add(field, dt.Rows[0][field].ToString()); } AmtList.Add(Item); } return AmtList; } /// /// 获取交易统计列表 /// /// 商户Id /// 月份(yyyyMM) /// 字段(多个用逗号隔开) /// public List> GetMonthTradeList(int MerchantId, string fields) { List> AmtList = new List>(); string fieldList = ""; foreach(string field in fields.Split(',')) { fieldList += "sum(" + field + ") " + field + ","; } for(int i = 0; i < 6; i ++) { Dictionary Item = new Dictionary(); Item.Add("TradeDate", DateTime.Now.AddMonths(-i).ToString("yyyy-MM")); DataTable dt = CustomerSqlConn.dtable("select " + fieldList.TrimEnd(',') + " from MerchantTradeSummary" + DateTime.Now.AddMonths(-i).ToString("yyyyMM") + " where MerchantId=" + MerchantId + "", AppConfig.Base.StatConnRds); if(dt.Rows.Count > 0) { foreach(string field in fields.Split(',')) { Item.Add(field, function.CheckNum(dt.Rows[0][field].ToString())); } } else { foreach(string field in fields.Split(',')) { Item.Add(field, "0"); } } AmtList.Add(Item); } return AmtList; } } }