MerchantInfoService.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 MerchantInfoService
  14. {
  15. string _conn = "";
  16. public MerchantInfoService()
  17. {
  18. _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  19. }
  20. /// <summary>
  21. /// 查询列表
  22. /// </summary>
  23. /// <param name="relationData">关联表</param>
  24. /// <param name="condition">查询条件(sql语句)</param>
  25. /// <param name="count">总数(输出)</param>
  26. /// <param name="page">页码</param>
  27. /// <param name="limit">每页条数</param>
  28. /// <returns></returns>
  29. public 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")
  30. {
  31. List<string> fields = new List<string>(); //要显示的列
  32. fields.Add("Id");
  33. fields.Add("CreateDate"); //添加时间
  34. fields.Add("Status"); //状态
  35. fields.Add("Name"); //名称
  36. fields.Add("Mobile"); //手机号
  37. fields.Add("Areas"); //所在地区
  38. fields.Add("Address"); //详细地址
  39. fields.Add("IsAuth"); //是否认证
  40. fields.Add("TotalAmount"); //平台总收益
  41. fields.Add("TotalOrder"); //累计订单
  42. fields.Add("TotalCustomer"); //累计客户
  43. fields.Add("TotalUser"); //会员数
  44. fields.Add("TotalActual"); //营收总额
  45. fields.Add("LastAddConsumerDate"); //最后加入会员时间
  46. fields.Add("TotalConsumeCount"); //累计消费次数
  47. fields.Add("LastConsumeDate"); //最后消费时间
  48. fields.Add("UserId"); //所属创客
  49. fields.Add("ActivationStatus"); //激活状态
  50. fields.Add("ActivationDate"); //激活时间
  51. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("MerchantInfo", relationData, orderBy, page, limit, condition, fields);
  52. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  53. count = int.Parse(obj["count"].ToString());
  54. return diclist;
  55. }
  56. public List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  57. {
  58. List<string> fields = new List<string>(); //要显示的列
  59. fields.Add("Id");
  60. fields.Add("CreateDate"); //添加时间
  61. fields.Add("Status"); //状态
  62. fields.Add("Name"); //名称
  63. fields.Add("Mobile"); //手机号
  64. fields.Add("Areas"); //所在地区
  65. fields.Add("Address"); //详细地址
  66. fields.Add("IsAuth"); //是否认证
  67. fields.Add("TotalAmount"); //平台总收益
  68. fields.Add("TotalOrder"); //累计订单
  69. fields.Add("TotalCustomer"); //累计客户
  70. fields.Add("TotalUser"); //会员数
  71. fields.Add("TotalActual"); //营收总额
  72. fields.Add("LastAddConsumerDate"); //最后加入会员时间
  73. fields.Add("TotalConsumeCount"); //累计消费次数
  74. fields.Add("LastConsumeDate"); //最后消费时间
  75. fields.Add("UserId"); //所属创客
  76. fields.Add("ActivationStatus"); //激活状态
  77. fields.Add("ActivationDate"); //激活时间
  78. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("MerchantInfo", relationData, orderBy, page, limit, condition, fields);
  79. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  80. return diclist;
  81. }
  82. /// <summary>
  83. /// 查询一条记录
  84. /// </summary>
  85. /// <param name="Id">主键Id</param>
  86. /// <returns></returns>
  87. public MerchantInfo Query(int Id)
  88. {
  89. WebCMSEntities db = new WebCMSEntities();
  90. MerchantInfo editData = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  91. db.Dispose();
  92. return editData;
  93. }
  94. /// <summary>
  95. /// 查询记录数
  96. /// </summary>
  97. /// <param name="Id">主键Id</param>
  98. /// <returns></returns>
  99. public int Count(string condition = "")
  100. {
  101. int result = 0;
  102. DataTable dt = CustomerSqlConn.dtable("select count(Id) from MerchantInfo where 1=1" + condition, _conn);
  103. if(dt.Rows.Count > 0)
  104. {
  105. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  106. }
  107. return result;
  108. }
  109. /// <summary>
  110. /// 查询是否存在
  111. /// </summary>
  112. /// <param name="Id">主键Id</param>
  113. /// <returns></returns>
  114. public bool Exist(int Id)
  115. {
  116. WebCMSEntities db = new WebCMSEntities();
  117. bool check = db.MerchantInfo.Any(m => m.Id == Id);
  118. db.Dispose();
  119. return check;
  120. }
  121. /// <summary>
  122. /// 添加数据
  123. /// </summary>
  124. /// <param name="Fields">要设置的字段</param>
  125. /// <returns></returns>
  126. public AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  127. {
  128. if(check)
  129. {
  130. if (string.IsNullOrEmpty(fields["Name"].ToString()))
  131. {
  132. return new AppResultJson() { Status = "-1", Info = "请填写名称" };
  133. }
  134. if (string.IsNullOrEmpty(fields["Mobile"].ToString()))
  135. {
  136. return new AppResultJson() { Status = "-1", Info = "请填写手机号" };
  137. }
  138. }
  139. int Id = new DbService(AppConfig.Base.dbTables, _conn).Add("MerchantInfo", fields, 0);
  140. return new AppResultJson(){ Status = "1", Data = Id };
  141. }
  142. /// <summary>
  143. /// 修改数据
  144. /// </summary>
  145. /// <param name="Fields">要设置的字段</param>
  146. /// <param name="Id">主键Id</param>
  147. public AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  148. {
  149. if(check)
  150. {
  151. if (string.IsNullOrEmpty(fields["Name"].ToString()))
  152. {
  153. return new AppResultJson() { Status = "-1", Info = "请填写名称" };
  154. }
  155. if (string.IsNullOrEmpty(fields["Mobile"].ToString()))
  156. {
  157. return new AppResultJson() { Status = "-1", Info = "请填写手机号" };
  158. }
  159. }
  160. new DbService(AppConfig.Base.dbTables, _conn).Edit("MerchantInfo", fields, Id);
  161. return new AppResultJson(){ Status = "1", Data = Id };
  162. }
  163. /// <summary>
  164. /// 逻辑删除
  165. /// </summary>
  166. /// <param name="Id">主键Id</param>
  167. public void Remove(int Id)
  168. {
  169. Dictionary<string, object> fields = new Dictionary<string, object>();
  170. fields.Add("Status", -1);
  171. new DbService(AppConfig.Base.dbTables, _conn).Edit("MerchantInfo", fields, Id);
  172. }
  173. /// <summary>
  174. /// 删除数据
  175. /// </summary>
  176. /// <param name="Id">主键Id</param>
  177. public void Delete(int Id)
  178. {
  179. new DbService(AppConfig.Base.dbTables, _conn).Delete("MerchantInfo", Id);
  180. }
  181. /// <summary>
  182. /// 排序
  183. /// </summary>
  184. /// <param name="Id">主键Id</param>
  185. /// <param name="Sort">排序序号</param>
  186. public void Sort(int Id, int Sort)
  187. {
  188. new DbService(AppConfig.Base.dbTables, _conn).Sort("MerchantInfo", Sort, Id);
  189. }
  190. /// <summary>
  191. /// 导入数据
  192. /// </summary>
  193. /// <param name="ExcelData">json数据</param>
  194. public void Import(string ExcelData)
  195. {
  196. WebCMSEntities db = new WebCMSEntities();
  197. JsonData list = JsonMapper.ToObject(ExcelData);
  198. for (int i = 1; i < list.Count;i++ )
  199. {
  200. JsonData dr = list[i];
  201. db.MerchantInfo.Add(new MerchantInfo()
  202. {
  203. CreateDate = DateTime.Now,
  204. UpdateDate = DateTime.Now,
  205. });
  206. db.SaveChanges();
  207. }
  208. db.Dispose();
  209. }
  210. /// <summary>
  211. /// 导出excel表格
  212. /// </summary>
  213. /// <param name="fields">查询条件(单个字段)</param>
  214. /// <param name="condition">查询条件(sql语句)</param>
  215. /// <returns></returns>
  216. // public void ExportExcel(List<RelationData> relationData, string condition)
  217. // {
  218. // }
  219. }
  220. }