ConsumerProfitService.cs 8.3 KB

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