MerchantTradeSummaryService.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*
  2. * 商户交易统计
  3. */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Data;
  8. using MySystem.Models.Main;
  9. using Library;
  10. using LitJson;
  11. namespace MySystem.Service.Main
  12. {
  13. public class MerchantTradeSummaryService
  14. {
  15. static string _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  16. /// <summary>
  17. /// 查询列表
  18. /// </summary>
  19. /// <param name="relationData">关联表</param>
  20. /// <param name="condition">查询条件(sql语句)</param>
  21. /// <param name="count">总数(输出)</param>
  22. /// <param name="page">页码</param>
  23. /// <param name="limit">每页条数</param>
  24. /// <returns></returns>
  25. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, string TradeTime, out int count, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  26. {
  27. List<string> fields = new List<string>(); //要显示的列
  28. fields.Add("Id");
  29. fields.Add("Sort");
  30. fields.Add("QueryCount");
  31. fields.Add("Status");
  32. fields.Add("CreateDate");
  33. fields.Add("UpdateDate");
  34. fields.Add("SeoTitle");
  35. fields.Add("SeoKeyword");
  36. fields.Add("SeoDescription");
  37. fields.Add("OderCount"); // 订单数
  38. fields.Add("PayMode"); //支付方式
  39. fields.Add("TradeAmount"); //订单金额
  40. fields.Add("InFactAmount"); //实收金额
  41. fields.Add("WeChatInfactAmount"); //微信实收金额
  42. fields.Add("AliPayInFactAmount"); //支付宝实收金额
  43. fields.Add("ActAmount"); //活动总金额
  44. fields.Add("NonActAmount"); //非活动总金额
  45. fields.Add("TradeDate"); //日期
  46. fields.Add("TradeMonth"); //月份
  47. fields.Add("MerchantId"); //商户Id
  48. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantTradeSummary" + TradeTime, relationData, orderBy, page, limit, condition, fields);
  49. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  50. count = int.Parse(obj["count"].ToString());
  51. return diclist;
  52. }
  53. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, string TradeTime, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  54. {
  55. List<string> fields = new List<string>(); //要显示的列
  56. fields.Add("Id");
  57. fields.Add("Sort");
  58. fields.Add("QueryCount");
  59. fields.Add("Status");
  60. fields.Add("CreateDate");
  61. fields.Add("UpdateDate");
  62. fields.Add("SeoTitle");
  63. fields.Add("SeoKeyword");
  64. fields.Add("SeoDescription");
  65. fields.Add("OderCount"); // 订单数
  66. fields.Add("PayMode"); //支付方式
  67. fields.Add("TradeAmount"); //订单金额
  68. fields.Add("InFactAmount"); //实收金额
  69. fields.Add("WeChatInfactAmount"); //微信实收金额
  70. fields.Add("AliPayInFactAmount"); //支付宝实收金额
  71. fields.Add("ActAmount"); //活动总金额
  72. fields.Add("NonActAmount"); //非活动总金额
  73. fields.Add("TradeDate"); //日期
  74. fields.Add("TradeMonth"); //月份
  75. fields.Add("MerchantId"); //商户Id
  76. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantTradeSummary" + TradeTime, relationData, orderBy, page, limit, condition, fields);
  77. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  78. return diclist;
  79. }
  80. public static List<Dictionary<string, object>> List2(List<RelationData> relationData, string condition, string TradeTime, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  81. {
  82. List<string> fields = new List<string>(); //要显示的列
  83. fields.Add("Id");
  84. fields.Add("Sort");
  85. fields.Add("QueryCount");
  86. fields.Add("Status");
  87. fields.Add("CreateDate");
  88. fields.Add("UpdateDate");
  89. fields.Add("SeoTitle");
  90. fields.Add("SeoKeyword");
  91. fields.Add("SeoDescription");
  92. fields.Add("OderCount"); // 订单数
  93. fields.Add("TradeAmount"); //订单金额
  94. fields.Add("InFactAmount"); //实收金额
  95. fields.Add("WeChatInfactAmount"); //微信实收金额
  96. fields.Add("AliPayInFactAmount"); //支付宝实收金额
  97. fields.Add("ActAmount"); //活动总金额
  98. fields.Add("NonActAmount"); //非活动总金额
  99. fields.Add("TradeDate"); //日期
  100. fields.Add("TradeMonth"); //月份
  101. fields.Add("MerchantId"); //商户Id
  102. Dictionary<string, object> obj = new DbService(AppConfig.Base.statTables, AppConfig.Base.StatConnRds).IndexData("MerchantTradeSummaryList" + TradeTime, relationData, orderBy, page, limit, condition, fields);
  103. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  104. return diclist;
  105. }
  106. public bool CheckTableExist(string date)
  107. {
  108. DataTable dt = CustomerSqlConn.dtable("show Tables like 'MerchantTradeSummaryList" + date + "'", AppConfig.Base.StatConnRds);
  109. if(dt.Rows.Count > 0)
  110. {
  111. return true;
  112. }
  113. return false;
  114. }
  115. /// <summary>
  116. /// 查询一条记录
  117. /// </summary>
  118. /// <param name="Id">主键Id</param>
  119. /// <returns></returns>
  120. public static MerchantTradeSummary Query(int Id, string TradeTime)
  121. {
  122. WebCMSEntities db = new WebCMSEntities();
  123. MerchantTradeSummary editData = db.MerchantTradeSummary.FirstOrDefault(m => m.Id == Id) ?? new MerchantTradeSummary();
  124. db.Dispose();
  125. return editData;
  126. }
  127. public static MerchantTradeSummary Query(string condition, string TradeTime, string fields = "*")
  128. {
  129. var merchantTradeSummary = new DbService(AppConfig.Base.mainTables, _conn).Query(fields, "MerchantTradeSummary" + TradeTime, condition);
  130. if (merchantTradeSummary.Count > 0)
  131. {
  132. return Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantTradeSummary>(Newtonsoft.Json.JsonConvert.SerializeObject(merchantTradeSummary));
  133. }
  134. return new MerchantTradeSummary();
  135. }
  136. public static decimal Sum(string condition, string TradeTime, string field)
  137. {
  138. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Sum(" + field + ") " + field, "MerchantTradeSummary" + TradeTime, condition);
  139. decimal amount = 0;
  140. if (dt.Count > 0)
  141. {
  142. amount = decimal.Parse(dt[field].ToString());
  143. }
  144. return amount;
  145. }
  146. /// <summary>
  147. /// 查询记录数
  148. /// </summary>
  149. /// <param name="Id">主键Id</param>
  150. /// <returns></returns>
  151. public static int Count(string TradeTime, string condition = "", string field = "Id")
  152. {
  153. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Count(" + field + ") " + field, "MerchantTradeSummary" + TradeTime, condition);
  154. int result = 0;
  155. if (dt.Count > 0)
  156. {
  157. result = int.Parse(dt[field].ToString());
  158. }
  159. return result;
  160. }
  161. /// <summary>
  162. /// 查询是否存在
  163. /// </summary>
  164. /// <param name="Id">主键Id</param>
  165. /// <returns></returns>
  166. public static bool Exist(int Id, string TradeTime)
  167. {
  168. WebCMSEntities db = new WebCMSEntities();
  169. bool check = db.MerchantTradeSummary.Any(m => m.Id == Id);
  170. db.Dispose();
  171. return check;
  172. }
  173. /// <summary>
  174. /// 添加数据
  175. /// </summary>
  176. /// <param name="Fields">要设置的字段</param>
  177. /// <returns></returns>
  178. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  179. {
  180. if (check)
  181. {
  182. }
  183. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("MerchantTradeSummary", fields, 0);
  184. return new AppResultJson() { Status = "1", Data = Id };
  185. }
  186. /// <summary>
  187. /// 修改数据
  188. /// </summary>
  189. /// <param name="Fields">要设置的字段</param>
  190. /// <param name="Id">主键Id</param>
  191. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  192. {
  193. if (check)
  194. {
  195. if (string.IsNullOrEmpty(fields["NickName"].ToString()))
  196. {
  197. return new AppResultJson() { Status = "-1", Info = "请填写昵称" };
  198. }
  199. }
  200. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantTradeSummary", fields, Id);
  201. return new AppResultJson() { Status = "1", Data = Id };
  202. }
  203. /// <summary>
  204. /// 逻辑删除
  205. /// </summary>
  206. /// <param name="Id">主键Id</param>
  207. public static void Remove(int Id)
  208. {
  209. Dictionary<string, object> fields = new Dictionary<string, object>();
  210. fields.Add("Status", -1);
  211. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantTradeSummary", fields, Id);
  212. }
  213. /// <summary>
  214. /// 删除数据
  215. /// </summary>
  216. /// <param name="Id">主键Id</param>
  217. public static void Delete(int Id)
  218. {
  219. new DbService(AppConfig.Base.mainTables, _conn).Delete("MerchantTradeSummary", Id);
  220. }
  221. /// <summary>
  222. /// 排序
  223. /// </summary>
  224. /// <param name="Id">主键Id</param>
  225. /// <param name="Sort">排序序号</param>
  226. public static void Sort(int Id, int Sort)
  227. {
  228. new DbService(AppConfig.Base.mainTables, _conn).Sort("MerchantTradeSummary", Sort, Id);
  229. }
  230. /// <summary>
  231. /// 导入数据
  232. /// </summary>
  233. /// <param name="ExcelData">json数据</param>
  234. public static void Import(string ExcelData)
  235. {
  236. WebCMSEntities db = new WebCMSEntities();
  237. JsonData list = JsonMapper.ToObject(ExcelData);
  238. for (int i = 1; i < list.Count; i++)
  239. {
  240. JsonData dr = list[i];
  241. db.MerchantTradeSummary.Add(new MerchantTradeSummary()
  242. {
  243. CreateDate = DateTime.Now,
  244. UpdateDate = DateTime.Now,
  245. });
  246. db.SaveChanges();
  247. }
  248. db.Dispose();
  249. }
  250. /// <summary>
  251. /// 导出excel表格
  252. /// </summary>
  253. /// <param name="fields">查询条件(单个字段)</param>
  254. /// <param name="condition">查询条件(sql语句)</param>
  255. /// <returns></returns>
  256. // public static void ExportExcel(List<RelationData> relationData, string condition)
  257. // {
  258. // }
  259. }
  260. }