MerchantLoginInfoService.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 MerchantLoginInfoService
  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("MerchantLoginInfo", 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("MerchantLoginInfo", 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 MerchantLoginInfo Query(int Id)
  80. {
  81. WebCMSEntities db = new WebCMSEntities();
  82. MerchantLoginInfo editData = db.MerchantLoginInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantLoginInfo();
  83. db.Dispose();
  84. return editData;
  85. }
  86. public static MerchantLoginInfo Query(string condition, string fields = "*")
  87. {
  88. var merchantLoginInfo = new DbService(AppConfig.Base.mainTables, _conn).Query(fields, "MerchantLoginInfo", condition);
  89. if (merchantLoginInfo.Count > 0)
  90. {
  91. return Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantLoginInfo>(Newtonsoft.Json.JsonConvert.SerializeObject(merchantLoginInfo));
  92. }
  93. return new MerchantLoginInfo();
  94. }
  95. public static decimal Sum(string condition, string field)
  96. {
  97. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Sum(" + field + ") " + field, "MerchantLoginInfo", condition);
  98. decimal amount = 0;
  99. if (dt.Count > 0)
  100. {
  101. amount = decimal.Parse(dt[field].ToString());
  102. }
  103. return amount;
  104. }
  105. /// <summary>
  106. /// 查询记录数
  107. /// </summary>
  108. /// <param name="Id">主键Id</param>
  109. /// <returns></returns>
  110. public static int Count(string condition = "", string field = "Id")
  111. {
  112. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Count(" + field + ") " + field, "MerchantLoginInfo", condition);
  113. int result = 0;
  114. if (dt.Count > 0)
  115. {
  116. result = int.Parse(dt[field].ToString());
  117. }
  118. return result;
  119. }
  120. /// <summary>
  121. /// 查询是否存在
  122. /// </summary>
  123. /// <param name="Id">主键Id</param>
  124. /// <returns></returns>
  125. public static bool Exist(int Id)
  126. {
  127. WebCMSEntities db = new WebCMSEntities();
  128. bool check = db.MerchantLoginInfo.Any(m => m.Id == Id);
  129. db.Dispose();
  130. return check;
  131. }
  132. /// <summary>
  133. /// 添加数据
  134. /// </summary>
  135. /// <param name="Fields">要设置的字段</param>
  136. /// <returns></returns>
  137. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  138. {
  139. if (check)
  140. {
  141. }
  142. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("MerchantLoginInfo", fields, 0);
  143. return new AppResultJson() { Status = "1", Data = Id };
  144. }
  145. /// <summary>
  146. /// 修改数据
  147. /// </summary>
  148. /// <param name="Fields">要设置的字段</param>
  149. /// <param name="Id">主键Id</param>
  150. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  151. {
  152. if (check)
  153. {
  154. if (string.IsNullOrEmpty(fields["NickName"].ToString()))
  155. {
  156. return new AppResultJson() { Status = "-1", Info = "请填写昵称" };
  157. }
  158. }
  159. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantLoginInfo", fields, Id);
  160. return new AppResultJson() { Status = "1", Data = Id };
  161. }
  162. /// <summary>
  163. /// 逻辑删除
  164. /// </summary>
  165. /// <param name="Id">主键Id</param>
  166. public static void Remove(int Id)
  167. {
  168. Dictionary<string, object> fields = new Dictionary<string, object>();
  169. fields.Add("Status", -1);
  170. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantLoginInfo", fields, Id);
  171. }
  172. /// <summary>
  173. /// 删除数据
  174. /// </summary>
  175. /// <param name="Id">主键Id</param>
  176. public static void Delete(int Id)
  177. {
  178. new DbService(AppConfig.Base.mainTables, _conn).Delete("MerchantLoginInfo", Id);
  179. }
  180. /// <summary>
  181. /// 排序
  182. /// </summary>
  183. /// <param name="Id">主键Id</param>
  184. /// <param name="Sort">排序序号</param>
  185. public static void Sort(int Id, int Sort)
  186. {
  187. new DbService(AppConfig.Base.mainTables, _conn).Sort("MerchantLoginInfo", Sort, Id);
  188. }
  189. /// <summary>
  190. /// 导入数据
  191. /// </summary>
  192. /// <param name="ExcelData">json数据</param>
  193. public static void Import(string ExcelData)
  194. {
  195. WebCMSEntities db = new WebCMSEntities();
  196. JsonData list = JsonMapper.ToObject(ExcelData);
  197. for (int i = 1; i < list.Count; i++)
  198. {
  199. JsonData dr = list[i];
  200. db.MerchantLoginInfo.Add(new MerchantLoginInfo()
  201. {
  202. CreateDate = DateTime.Now,
  203. UpdateDate = DateTime.Now,
  204. });
  205. db.SaveChanges();
  206. }
  207. db.Dispose();
  208. }
  209. /// <summary>
  210. /// 导出excel表格
  211. /// </summary>
  212. /// <param name="fields">查询条件(单个字段)</param>
  213. /// <param name="condition">查询条件(sql语句)</param>
  214. /// <returns></returns>
  215. // public static void ExportExcel(List<RelationData> relationData, string condition)
  216. // {
  217. // }
  218. }
  219. }