PosCouponsService.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 PosCouponsService
  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("QueryCount");
  30. fields.Add("CreateDate"); //添加时间
  31. fields.Add("Status"); //状态
  32. fields.Add("UserId"); //创客
  33. fields.Add("ExchangeCode"); //兑换码
  34. fields.Add("IsUse"); //是否使用
  35. fields.Add("IsLock"); //是否锁定
  36. fields.Add("UseDate"); //使用时间
  37. fields.Add("LeaderUserId"); //大盟主
  38. fields.Add("HelpProfitFlag"); //助利宝标记
  39. fields.Add("HelpProfitStatus"); //助利宝状态
  40. fields.Add("HelpProfitMerchantId"); //助利宝商户
  41. fields.Add("OrderId"); //订单
  42. fields.Add("OpId"); //运营中心Id
  43. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("PosCoupons", relationData, orderBy, page, limit, condition, fields);
  44. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  45. count = int.Parse(obj["count"].ToString());
  46. return diclist;
  47. }
  48. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  49. {
  50. List<string> fields = new List<string>(); //要显示的列
  51. fields.Add("Id");
  52. fields.Add("QueryCount");
  53. fields.Add("CreateDate"); //添加时间
  54. fields.Add("Status"); //状态
  55. fields.Add("UserId"); //创客
  56. fields.Add("ExchangeCode"); //兑换码
  57. fields.Add("IsUse"); //是否使用
  58. fields.Add("IsLock"); //是否锁定
  59. fields.Add("UseDate"); //使用时间
  60. fields.Add("LeaderUserId"); //大盟主
  61. fields.Add("HelpProfitFlag"); //助利宝标记
  62. fields.Add("HelpProfitStatus"); //助利宝状态
  63. fields.Add("HelpProfitMerchantId"); //助利宝商户
  64. fields.Add("OrderId"); //订单
  65. fields.Add("OpId"); //运营中心Id
  66. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("PosCoupons", relationData, orderBy, page, limit, condition, fields);
  67. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  68. return diclist;
  69. }
  70. /// <summary>
  71. /// 查询一条记录
  72. /// </summary>
  73. /// <param name="Id">主键Id</param>
  74. /// <returns></returns>
  75. public static PosCoupons Query(int Id)
  76. {
  77. WebCMSEntities db = new WebCMSEntities();
  78. PosCoupons editData = db.PosCoupons.FirstOrDefault(m => m.Id == Id) ?? new PosCoupons();
  79. db.Dispose();
  80. return editData;
  81. }
  82. public static PosCoupons Query(string condition, string fields = "*")
  83. {
  84. // DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail(fields, "PosCoupons", condition);
  85. // if (dt.Rows.Count > 0)
  86. // {
  87. // Dictionary<string, object> row = new Dictionary<string, object>();
  88. // foreach (DataColumn dc in dt.Columns)
  89. // {
  90. // row.Add(dc.ColumnName, dt.Rows[0][dc.ColumnName].ToString());
  91. // }
  92. // return Newtonsoft.Json.JsonConvert.DeserializeObject<PosCoupons>(Newtonsoft.Json.JsonConvert.SerializeObject(row));
  93. // }
  94. var posCoupons = new DbService(AppConfig.Base.mainTables, _conn).Query(fields, "PosCoupons", condition);
  95. if (posCoupons.Count > 0)
  96. {
  97. return Newtonsoft.Json.JsonConvert.DeserializeObject<PosCoupons>(Newtonsoft.Json.JsonConvert.SerializeObject(posCoupons));
  98. }
  99. return new PosCoupons();
  100. }
  101. public static decimal Sum(string condition, string field)
  102. {
  103. // DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail("Sum(" + field + ")", "PosCoupons", condition);
  104. // decimal amount = 0;
  105. // if (dt.Rows.Count > 0)
  106. // {
  107. // amount = decimal.Parse(dt.Rows[0][0].ToString());
  108. // }
  109. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Sum(" + field + ") " + field, "PosCoupons", condition);
  110. decimal amount = 0;
  111. if (dt.Count > 0)
  112. {
  113. amount = decimal.Parse(dt[field].ToString());
  114. }
  115. return amount;
  116. }
  117. /// <summary>
  118. /// 查询记录数
  119. /// </summary>
  120. /// <param name="Id">主键Id</param>
  121. /// <returns></returns>
  122. public static int Count(string condition = "", string field = "Id")
  123. {
  124. // int result = 0;
  125. // DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail("count(" + field + ")", "PosCoupons", condition);
  126. // if (dt.Rows.Count > 0)
  127. // {
  128. // result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  129. // }
  130. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Count(" + field + ") " + field, "PosCoupons", condition);
  131. int result = 0;
  132. if (dt.Count > 0)
  133. {
  134. result = int.Parse(dt[field].ToString());
  135. }
  136. return result;
  137. }
  138. /// <summary>
  139. /// 查询是否存在
  140. /// </summary>
  141. /// <param name="Id">主键Id</param>
  142. /// <returns></returns>
  143. public static bool Exist(int Id)
  144. {
  145. WebCMSEntities db = new WebCMSEntities();
  146. bool check = db.PosCoupons.Any(m => m.Id == Id);
  147. db.Dispose();
  148. return check;
  149. }
  150. /// <summary>
  151. /// 添加数据
  152. /// </summary>
  153. /// <param name="Fields">要设置的字段</param>
  154. /// <returns></returns>
  155. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  156. {
  157. if (check)
  158. {
  159. }
  160. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("PosCoupons", fields, 0);
  161. return new AppResultJson() { Status = "1", Data = Id };
  162. }
  163. /// <summary>
  164. /// 修改数据
  165. /// </summary>
  166. /// <param name="Fields">要设置的字段</param>
  167. /// <param name="Id">主键Id</param>
  168. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  169. {
  170. if (check)
  171. {
  172. }
  173. new DbService(AppConfig.Base.mainTables, _conn).Edit("PosCoupons", fields, Id);
  174. return new AppResultJson() { Status = "1", Data = Id };
  175. }
  176. /// <summary>
  177. /// 逻辑删除
  178. /// </summary>
  179. /// <param name="Id">主键Id</param>
  180. public static void Remove(int Id)
  181. {
  182. Dictionary<string, object> fields = new Dictionary<string, object>();
  183. fields.Add("Status", -1);
  184. new DbService(AppConfig.Base.mainTables, _conn).Edit("PosCoupons", fields, Id);
  185. }
  186. /// <summary>
  187. /// 删除数据
  188. /// </summary>
  189. /// <param name="Id">主键Id</param>
  190. public static void Delete(int Id)
  191. {
  192. new DbService(AppConfig.Base.mainTables, _conn).Delete("PosCoupons", Id);
  193. }
  194. /// <summary>
  195. /// 排序
  196. /// </summary>
  197. /// <param name="Id">主键Id</param>
  198. /// <param name="Sort">排序序号</param>
  199. public static void Sort(int Id, int Sort)
  200. {
  201. new DbService(AppConfig.Base.mainTables, _conn).Sort("PosCoupons", Sort, Id);
  202. }
  203. /// <summary>
  204. /// 导入数据
  205. /// </summary>
  206. /// <param name="ExcelData">json数据</param>
  207. public static void Import(string ExcelData)
  208. {
  209. WebCMSEntities db = new WebCMSEntities();
  210. JsonData list = JsonMapper.ToObject(ExcelData);
  211. for (int i = 1; i < list.Count; i++)
  212. {
  213. JsonData dr = list[i];
  214. db.PosCoupons.Add(new PosCoupons()
  215. {
  216. CreateDate = DateTime.Now,
  217. UpdateDate = DateTime.Now,
  218. });
  219. db.SaveChanges();
  220. }
  221. db.Dispose();
  222. }
  223. /// <summary>
  224. /// 导出excel表格
  225. /// </summary>
  226. /// <param name="fields">查询条件(单个字段)</param>
  227. /// <param name="condition">查询条件(sql语句)</param>
  228. /// <returns></returns>
  229. // public static void ExportExcel(List<RelationData> relationData, string condition)
  230. // {
  231. // }
  232. }
  233. }