ConsumerOrdersService.cs 9.0 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 ConsumerOrdersService
  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("MerchantId"); //商户
  32. fields.Add("ConsumerId"); //消费者
  33. fields.Add("OrderNo"); //订单号
  34. fields.Add("PayMode"); //支付方式
  35. fields.Add("PayMoney"); //支付金额
  36. fields.Add("ReturnMoney"); //已返金额
  37. fields.Add("SnNo"); //SN号
  38. fields.Add("MaxDivi"); //最大分红
  39. fields.Add("CurDivi"); //当前分红
  40. fields.Add("IsAct"); //是否活动
  41. fields.Add("ReturnFlag");
  42. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("ConsumerOrders", relationData, orderBy, page, limit, condition, fields);
  43. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  44. count = int.Parse(obj["count"].ToString());
  45. return diclist;
  46. }
  47. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  48. {
  49. List<string> fields = new List<string>(); //要显示的列
  50. fields.Add("Id");
  51. fields.Add("CreateDate"); //添加时间
  52. fields.Add("Status"); //状态
  53. fields.Add("MerchantId"); //商户
  54. fields.Add("ConsumerId"); //消费者
  55. fields.Add("OrderNo"); //订单号
  56. fields.Add("PayMode"); //支付方式
  57. fields.Add("PayMoney"); //支付金额
  58. fields.Add("ReturnMoney"); //已返金额
  59. fields.Add("SnNo"); //SN号
  60. fields.Add("MaxDivi"); //最大分红
  61. fields.Add("CurDivi"); //当前分红
  62. fields.Add("IsAct"); //是否活动
  63. fields.Add("ReturnFlag");
  64. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("ConsumerOrders", relationData, orderBy, page, limit, condition, fields);
  65. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  66. return diclist;
  67. }
  68. /// <summary>
  69. /// 查询一条记录
  70. /// </summary>
  71. /// <param name="Id">主键Id</param>
  72. /// <returns></returns>
  73. public static ConsumerOrders Query(int Id)
  74. {
  75. WebCMSEntities db = new WebCMSEntities();
  76. ConsumerOrders editData = db.ConsumerOrders.FirstOrDefault(m => m.Id == Id) ?? new ConsumerOrders();
  77. db.Dispose();
  78. return editData;
  79. }
  80. public static ConsumerOrders Query(string condition, string fields = "*")
  81. {
  82. var consumerOrders = new DbService(AppConfig.Base.mainTables, _conn).Query(fields, "ConsumerOrders", condition);
  83. if (consumerOrders.Count > 0)
  84. {
  85. return Newtonsoft.Json.JsonConvert.DeserializeObject<ConsumerOrders>(Newtonsoft.Json.JsonConvert.SerializeObject(consumerOrders));
  86. }
  87. return new ConsumerOrders();
  88. }
  89. public static decimal Sum(string condition, string field)
  90. {
  91. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Sum(" + field + ") " + field, "ConsumerOrders", condition);
  92. decimal amount = 0;
  93. if (dt.Count > 0)
  94. {
  95. amount = decimal.Parse(dt[field].ToString());
  96. }
  97. return amount;
  98. }
  99. /// <summary>
  100. /// 查询记录数
  101. /// </summary>
  102. /// <param name="Id">主键Id</param>
  103. /// <returns></returns>
  104. public static int Count(string condition = "", string field = "Id")
  105. {
  106. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Count(" + field + ") " + field, "ConsumerOrders", condition);
  107. int result = 0;
  108. if (dt.Count > 0)
  109. {
  110. result = int.Parse(dt[field].ToString());
  111. }
  112. return result;
  113. }
  114. /// <summary>
  115. /// 查询是否存在
  116. /// </summary>
  117. /// <param name="Id">主键Id</param>
  118. /// <returns></returns>
  119. public static bool Exist(int Id)
  120. {
  121. WebCMSEntities db = new WebCMSEntities();
  122. bool check = db.ConsumerOrders.Any(m => m.Id == Id);
  123. db.Dispose();
  124. return check;
  125. }
  126. /// <summary>
  127. /// 添加数据
  128. /// </summary>
  129. /// <param name="Fields">要设置的字段</param>
  130. /// <returns></returns>
  131. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  132. {
  133. if (check)
  134. {
  135. if (string.IsNullOrEmpty(fields["IsAct"].ToString()))
  136. {
  137. return new AppResultJson() { Status = "-1", Info = "请填写是否活动" };
  138. }
  139. }
  140. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("ConsumerOrders", fields, 0);
  141. return new AppResultJson() { Status = "1", Data = Id };
  142. }
  143. /// <summary>
  144. /// 修改数据
  145. /// </summary>
  146. /// <param name="Fields">要设置的字段</param>
  147. /// <param name="Id">主键Id</param>
  148. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  149. {
  150. if (check)
  151. {
  152. if (string.IsNullOrEmpty(fields["IsAct"].ToString()))
  153. {
  154. return new AppResultJson() { Status = "-1", Info = "请填写是否活动" };
  155. }
  156. }
  157. new DbService(AppConfig.Base.mainTables, _conn).Edit("ConsumerOrders", fields, Id);
  158. return new AppResultJson() { Status = "1", Data = Id };
  159. }
  160. /// <summary>
  161. /// 逻辑删除
  162. /// </summary>
  163. /// <param name="Id">主键Id</param>
  164. public static void Remove(int Id)
  165. {
  166. Dictionary<string, object> fields = new Dictionary<string, object>();
  167. fields.Add("Status", -1);
  168. new DbService(AppConfig.Base.mainTables, _conn).Edit("ConsumerOrders", fields, Id);
  169. }
  170. /// <summary>
  171. /// 删除数据
  172. /// </summary>
  173. /// <param name="Id">主键Id</param>
  174. public static void Delete(int Id)
  175. {
  176. new DbService(AppConfig.Base.mainTables, _conn).Delete("ConsumerOrders", Id);
  177. }
  178. /// <summary>
  179. /// 排序
  180. /// </summary>
  181. /// <param name="Id">主键Id</param>
  182. /// <param name="Sort">排序序号</param>
  183. public static void Sort(int Id, int Sort)
  184. {
  185. new DbService(AppConfig.Base.mainTables, _conn).Sort("ConsumerOrders", Sort, Id);
  186. }
  187. /// <summary>
  188. /// 导入数据
  189. /// </summary>
  190. /// <param name="ExcelData">json数据</param>
  191. public static void Import(string ExcelData)
  192. {
  193. WebCMSEntities db = new WebCMSEntities();
  194. JsonData list = JsonMapper.ToObject(ExcelData);
  195. for (int i = 1; i < list.Count; i++)
  196. {
  197. JsonData dr = list[i];
  198. db.ConsumerOrders.Add(new ConsumerOrders()
  199. {
  200. CreateDate = DateTime.Now,
  201. UpdateDate = DateTime.Now,
  202. });
  203. db.SaveChanges();
  204. }
  205. db.Dispose();
  206. }
  207. /// <summary>
  208. /// 导出excel表格
  209. /// </summary>
  210. /// <param name="fields">查询条件(单个字段)</param>
  211. /// <param name="condition">查询条件(sql语句)</param>
  212. /// <returns></returns>
  213. // public static void ExportExcel(List<RelationData> relationData, string condition)
  214. // {
  215. // }
  216. }
  217. }