PosMachinesService.cs 9.9 KB

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