MerchantInfoService.cs 10 KB

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