MerchantAmountSummayService.cs 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 MerchantAmountSummayService
  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, 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("PayMode"); //支付方式
  38. fields.Add("TotalActual"); //实际返现金额
  39. fields.Add("TradeAmount"); //订单金额
  40. fields.Add("TradeDate"); //日期
  41. fields.Add("TradeMonth"); //月份
  42. fields.Add("MerchantId"); //商户
  43. fields.Add("TradeCount"); //交易笔数
  44. fields.Add("IsAct"); //交易笔数
  45. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantAmountSummay", relationData, orderBy, page, limit, condition, fields);
  46. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  47. count = int.Parse(obj["count"].ToString());
  48. return diclist;
  49. }
  50. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  51. {
  52. List<string> fields = new List<string>(); //要显示的列
  53. fields.Add("Id");
  54. fields.Add("Sort");
  55. fields.Add("QueryCount");
  56. fields.Add("Status");
  57. fields.Add("CreateDate");
  58. fields.Add("UpdateDate");
  59. fields.Add("SeoTitle");
  60. fields.Add("SeoKeyword");
  61. fields.Add("SeoDescription");
  62. fields.Add("PayMode"); //支付方式
  63. fields.Add("TotalActual"); //实际返现金额
  64. fields.Add("TradeAmount"); //订单金额
  65. fields.Add("TradeDate"); //日期
  66. fields.Add("TradeMonth"); //月份
  67. fields.Add("MerchantId"); //商户
  68. fields.Add("TradeCount"); //交易笔数
  69. fields.Add("IsAct"); //交易笔数
  70. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantAmountSummay", relationData, orderBy, page, limit, condition, fields);
  71. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  72. return diclist;
  73. }
  74. /// <summary>
  75. /// 查询一条记录
  76. /// </summary>
  77. /// <param name="Id">主键Id</param>
  78. /// <returns></returns>
  79. public static MerchantAmountSummay Query(int Id)
  80. {
  81. WebCMSEntities db = new WebCMSEntities();
  82. MerchantAmountSummay editData = db.MerchantAmountSummay.FirstOrDefault(m => m.Id == Id) ?? new MerchantAmountSummay();
  83. db.Dispose();
  84. return editData;
  85. }
  86. public static MerchantAmountSummay Query(string condition, string fields = "*")
  87. {
  88. var merchantAmountSummay = new DbService(AppConfig.Base.mainTables, _conn).Query(fields, "MerchantAmountSummay", condition);
  89. if (merchantAmountSummay.Count > 0)
  90. {
  91. return Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantAmountSummay>(Newtonsoft.Json.JsonConvert.SerializeObject(merchantAmountSummay));
  92. }
  93. return new MerchantAmountSummay();
  94. }
  95. // public static decimal Sum(string condition, string field)
  96. // {
  97. // var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Sum(" + field + ") " + field, "MerchantAmountSummay", condition);
  98. // decimal amount = 0;
  99. // if (dt.Count > 0)
  100. // {
  101. // amount = decimal.Parse(dt[field].ToString());
  102. // }
  103. // return amount;
  104. // }
  105. public static Dictionary<string, string> Sum(string field, string condition)
  106. {
  107. Dictionary<string, string> result = new Dictionary<string, string>();
  108. string sumString = "";
  109. string[] fieldlist = field.Split(',');
  110. foreach (string f in fieldlist)
  111. {
  112. sumString += "sum(" + f + ") " + f + ",";
  113. }
  114. sumString = sumString.TrimEnd(',');
  115. DataTable dt = CustomerSqlConn.dtable("select " + sumString + " from MerchantAmountSummay where 1=1" + condition, _conn);
  116. if (dt.Rows.Count > 0)
  117. {
  118. foreach (string f in fieldlist)
  119. {
  120. result.Add(f, function.CheckNum(dt.Rows[0][f].ToString()));
  121. }
  122. }
  123. return result;
  124. }
  125. /// <summary>
  126. /// 查询记录数
  127. /// </summary>
  128. /// <param name="Id">主键Id</param>
  129. /// <returns></returns>
  130. public static int Count(string condition = "", string field = "Id")
  131. {
  132. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Count(" + field + ") " + field, "MerchantAmountSummay", condition);
  133. int result = 0;
  134. if (dt.Count > 0)
  135. {
  136. result = int.Parse(dt[field].ToString());
  137. }
  138. return result;
  139. }
  140. /// <summary>
  141. /// 查询是否存在
  142. /// </summary>
  143. /// <param name="Id">主键Id</param>
  144. /// <returns></returns>
  145. public static bool Exist(int Id)
  146. {
  147. WebCMSEntities db = new WebCMSEntities();
  148. bool check = db.MerchantAmountSummay.Any(m => m.Id == Id);
  149. db.Dispose();
  150. return check;
  151. }
  152. /// <summary>
  153. /// 添加数据
  154. /// </summary>
  155. /// <param name="Fields">要设置的字段</param>
  156. /// <returns></returns>
  157. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  158. {
  159. if (check)
  160. {
  161. }
  162. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("MerchantAmountSummay", fields, 0);
  163. return new AppResultJson() { Status = "1", Data = Id };
  164. }
  165. /// <summary>
  166. /// 修改数据
  167. /// </summary>
  168. /// <param name="Fields">要设置的字段</param>
  169. /// <param name="Id">主键Id</param>
  170. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  171. {
  172. if (check)
  173. {
  174. if (string.IsNullOrEmpty(fields["NickName"].ToString()))
  175. {
  176. return new AppResultJson() { Status = "-1", Info = "请填写昵称" };
  177. }
  178. }
  179. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantAmountSummay", fields, Id);
  180. return new AppResultJson() { Status = "1", Data = Id };
  181. }
  182. /// <summary>
  183. /// 逻辑删除
  184. /// </summary>
  185. /// <param name="Id">主键Id</param>
  186. public static void Remove(int Id)
  187. {
  188. Dictionary<string, object> fields = new Dictionary<string, object>();
  189. fields.Add("Status", -1);
  190. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantAmountSummay", fields, Id);
  191. }
  192. /// <summary>
  193. /// 删除数据
  194. /// </summary>
  195. /// <param name="Id">主键Id</param>
  196. public static void Delete(int Id)
  197. {
  198. new DbService(AppConfig.Base.mainTables, _conn).Delete("MerchantAmountSummay", Id);
  199. }
  200. /// <summary>
  201. /// 排序
  202. /// </summary>
  203. /// <param name="Id">主键Id</param>
  204. /// <param name="Sort">排序序号</param>
  205. public static void Sort(int Id, int Sort)
  206. {
  207. new DbService(AppConfig.Base.mainTables, _conn).Sort("MerchantAmountSummay", Sort, Id);
  208. }
  209. /// <summary>
  210. /// 导入数据
  211. /// </summary>
  212. /// <param name="ExcelData">json数据</param>
  213. public static void Import(string ExcelData)
  214. {
  215. WebCMSEntities db = new WebCMSEntities();
  216. JsonData list = JsonMapper.ToObject(ExcelData);
  217. for (int i = 1; i < list.Count; i++)
  218. {
  219. JsonData dr = list[i];
  220. db.MerchantAmountSummay.Add(new MerchantAmountSummay()
  221. {
  222. CreateDate = DateTime.Now,
  223. UpdateDate = DateTime.Now,
  224. });
  225. db.SaveChanges();
  226. }
  227. db.Dispose();
  228. }
  229. /// <summary>
  230. /// 导出excel表格
  231. /// </summary>
  232. /// <param name="fields">查询条件(单个字段)</param>
  233. /// <param name="condition">查询条件(sql语句)</param>
  234. /// <returns></returns>
  235. // public static void ExportExcel(List<RelationData> relationData, string condition)
  236. // {
  237. // }
  238. }
  239. }