CouponAssignRecordsService.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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 CouponAssignRecordsService
  14. {
  15. string _conn = "";
  16. public CouponAssignRecordsService()
  17. {
  18. _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  19. }
  20. /// <summary>
  21. /// 查询列表
  22. /// </summary>
  23. /// <param name="relationData">关联表</param>
  24. /// <param name="condition">查询条件(sql语句)</param>
  25. /// <param name="count">总数(输出)</param>
  26. /// <param name="page">页码</param>
  27. /// <param name="limit">每页条数</param>
  28. /// <returns></returns>
  29. public 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")
  30. {
  31. List<string> fields = new List<string>(); //要显示的列
  32. fields.Add("Id");
  33. fields.Add("CreateDate"); //添加时间
  34. fields.Add("Status"); //状态
  35. fields.Add("UserMinLevel"); //创客最低等级
  36. fields.Add("UserMaxLevel"); //创客最高等级
  37. fields.Add("TotalOrderMoneyMin"); //最小消费总额
  38. fields.Add("TotalOrderMoneyMax"); //最大消费总额
  39. fields.Add("TotalUseIntegralMin"); //最小消耗积分总额
  40. fields.Add("TotalUseIntegralMax"); //最大消耗积分总额
  41. fields.Add("CurMoneyMin"); //当前最低余额
  42. fields.Add("CurMoneyMax"); //当前最高余额
  43. fields.Add("UserGroupId"); //创客分组
  44. fields.Add("Areas"); //创客所在地区
  45. fields.Add("Mobile"); //手机号
  46. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("CouponAssignRecords", relationData, orderBy, page, limit, condition, fields);
  47. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  48. count = int.Parse(obj["count"].ToString());
  49. return diclist;
  50. }
  51. public List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  52. {
  53. List<string> fields = new List<string>(); //要显示的列
  54. fields.Add("Id");
  55. fields.Add("CreateDate"); //添加时间
  56. fields.Add("Status"); //状态
  57. fields.Add("UserMinLevel"); //创客最低等级
  58. fields.Add("UserMaxLevel"); //创客最高等级
  59. fields.Add("TotalOrderMoneyMin"); //最小消费总额
  60. fields.Add("TotalOrderMoneyMax"); //最大消费总额
  61. fields.Add("TotalUseIntegralMin"); //最小消耗积分总额
  62. fields.Add("TotalUseIntegralMax"); //最大消耗积分总额
  63. fields.Add("CurMoneyMin"); //当前最低余额
  64. fields.Add("CurMoneyMax"); //当前最高余额
  65. fields.Add("UserGroupId"); //创客分组
  66. fields.Add("Areas"); //创客所在地区
  67. fields.Add("Mobile"); //手机号
  68. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("CouponAssignRecords", relationData, orderBy, page, limit, condition, fields);
  69. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  70. return diclist;
  71. }
  72. /// <summary>
  73. /// 查询一条记录
  74. /// </summary>
  75. /// <param name="Id">主键Id</param>
  76. /// <returns></returns>
  77. public CouponAssignRecords Query(int Id)
  78. {
  79. WebCMSEntities db = new WebCMSEntities();
  80. CouponAssignRecords editData = db.CouponAssignRecords.FirstOrDefault(m => m.Id == Id) ?? new CouponAssignRecords();
  81. db.Dispose();
  82. return editData;
  83. }
  84. /// <summary>
  85. /// 查询记录数
  86. /// </summary>
  87. /// <param name="Id">主键Id</param>
  88. /// <returns></returns>
  89. public int Count(string condition = "")
  90. {
  91. int result = 0;
  92. DataTable dt = CustomerSqlConn.dtable("select count(Id) from CouponAssignRecords where 1=1" + condition, _conn);
  93. if(dt.Rows.Count > 0)
  94. {
  95. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  96. }
  97. return result;
  98. }
  99. /// <summary>
  100. /// 查询是否存在
  101. /// </summary>
  102. /// <param name="Id">主键Id</param>
  103. /// <returns></returns>
  104. public bool Exist(int Id)
  105. {
  106. WebCMSEntities db = new WebCMSEntities();
  107. bool check = db.CouponAssignRecords.Any(m => m.Id == Id);
  108. db.Dispose();
  109. return check;
  110. }
  111. /// <summary>
  112. /// 添加数据
  113. /// </summary>
  114. /// <param name="Fields">要设置的字段</param>
  115. /// <returns></returns>
  116. public AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  117. {
  118. if(check)
  119. {
  120. if (string.IsNullOrEmpty(fields["TotalOrderMoneyMin"].ToString()))
  121. {
  122. return new AppResultJson() { Status = "-1", Info = "请填写最小消费总额" };
  123. }
  124. if (!function.IsNum(fields["TotalOrderMoneyMin"].ToString()))
  125. {
  126. return new AppResultJson() { Status = "-1", Info = "请填写正确的最小消费总额" };
  127. }
  128. if (string.IsNullOrEmpty(fields["TotalOrderMoneyMax"].ToString()))
  129. {
  130. return new AppResultJson() { Status = "-1", Info = "请填写最大消费总额" };
  131. }
  132. if (!function.IsNum(fields["TotalOrderMoneyMax"].ToString()))
  133. {
  134. return new AppResultJson() { Status = "-1", Info = "请填写正确的最大消费总额" };
  135. }
  136. if (string.IsNullOrEmpty(fields["TotalUseIntegralMin"].ToString()))
  137. {
  138. return new AppResultJson() { Status = "-1", Info = "请填写最小消耗积分总额" };
  139. }
  140. if (!function.IsNum(fields["TotalUseIntegralMin"].ToString()))
  141. {
  142. return new AppResultJson() { Status = "-1", Info = "请填写正确的最小消耗积分总额" };
  143. }
  144. if (string.IsNullOrEmpty(fields["TotalUseIntegralMax"].ToString()))
  145. {
  146. return new AppResultJson() { Status = "-1", Info = "请填写最大消耗积分总额" };
  147. }
  148. if (!function.IsNum(fields["TotalUseIntegralMax"].ToString()))
  149. {
  150. return new AppResultJson() { Status = "-1", Info = "请填写正确的最大消耗积分总额" };
  151. }
  152. if (string.IsNullOrEmpty(fields["CurMoneyMin"].ToString()))
  153. {
  154. return new AppResultJson() { Status = "-1", Info = "请填写当前最低余额" };
  155. }
  156. if (!function.IsNum(fields["CurMoneyMin"].ToString()))
  157. {
  158. return new AppResultJson() { Status = "-1", Info = "请填写正确的当前最低余额" };
  159. }
  160. if (string.IsNullOrEmpty(fields["CurMoneyMax"].ToString()))
  161. {
  162. return new AppResultJson() { Status = "-1", Info = "请填写当前最高余额" };
  163. }
  164. if (!function.IsNum(fields["CurMoneyMax"].ToString()))
  165. {
  166. return new AppResultJson() { Status = "-1", Info = "请填写正确的当前最高余额" };
  167. }
  168. }
  169. int Id = new DbService(AppConfig.Base.dbTables, _conn).Add("CouponAssignRecords", fields, 0);
  170. return new AppResultJson(){ Status = "1", Data = Id };
  171. }
  172. /// <summary>
  173. /// 修改数据
  174. /// </summary>
  175. /// <param name="Fields">要设置的字段</param>
  176. /// <param name="Id">主键Id</param>
  177. public AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  178. {
  179. if(check)
  180. {
  181. if (string.IsNullOrEmpty(fields["TotalOrderMoneyMin"].ToString()))
  182. {
  183. return new AppResultJson() { Status = "-1", Info = "请填写最小消费总额" };
  184. }
  185. if (!function.IsNum(fields["TotalOrderMoneyMin"].ToString()))
  186. {
  187. return new AppResultJson() { Status = "-1", Info = "请填写正确的最小消费总额" };
  188. }
  189. if (string.IsNullOrEmpty(fields["TotalOrderMoneyMax"].ToString()))
  190. {
  191. return new AppResultJson() { Status = "-1", Info = "请填写最大消费总额" };
  192. }
  193. if (!function.IsNum(fields["TotalOrderMoneyMax"].ToString()))
  194. {
  195. return new AppResultJson() { Status = "-1", Info = "请填写正确的最大消费总额" };
  196. }
  197. if (string.IsNullOrEmpty(fields["TotalUseIntegralMin"].ToString()))
  198. {
  199. return new AppResultJson() { Status = "-1", Info = "请填写最小消耗积分总额" };
  200. }
  201. if (!function.IsNum(fields["TotalUseIntegralMin"].ToString()))
  202. {
  203. return new AppResultJson() { Status = "-1", Info = "请填写正确的最小消耗积分总额" };
  204. }
  205. if (string.IsNullOrEmpty(fields["TotalUseIntegralMax"].ToString()))
  206. {
  207. return new AppResultJson() { Status = "-1", Info = "请填写最大消耗积分总额" };
  208. }
  209. if (!function.IsNum(fields["TotalUseIntegralMax"].ToString()))
  210. {
  211. return new AppResultJson() { Status = "-1", Info = "请填写正确的最大消耗积分总额" };
  212. }
  213. if (string.IsNullOrEmpty(fields["CurMoneyMin"].ToString()))
  214. {
  215. return new AppResultJson() { Status = "-1", Info = "请填写当前最低余额" };
  216. }
  217. if (!function.IsNum(fields["CurMoneyMin"].ToString()))
  218. {
  219. return new AppResultJson() { Status = "-1", Info = "请填写正确的当前最低余额" };
  220. }
  221. if (string.IsNullOrEmpty(fields["CurMoneyMax"].ToString()))
  222. {
  223. return new AppResultJson() { Status = "-1", Info = "请填写当前最高余额" };
  224. }
  225. if (!function.IsNum(fields["CurMoneyMax"].ToString()))
  226. {
  227. return new AppResultJson() { Status = "-1", Info = "请填写正确的当前最高余额" };
  228. }
  229. }
  230. new DbService(AppConfig.Base.dbTables, _conn).Edit("CouponAssignRecords", fields, Id);
  231. return new AppResultJson(){ Status = "1", Data = Id };
  232. }
  233. /// <summary>
  234. /// 逻辑删除
  235. /// </summary>
  236. /// <param name="Id">主键Id</param>
  237. public void Remove(int Id)
  238. {
  239. Dictionary<string, object> fields = new Dictionary<string, object>();
  240. fields.Add("Status", -1);
  241. new DbService(AppConfig.Base.dbTables, _conn).Edit("CouponAssignRecords", fields, Id);
  242. }
  243. /// <summary>
  244. /// 删除数据
  245. /// </summary>
  246. /// <param name="Id">主键Id</param>
  247. public void Delete(int Id)
  248. {
  249. new DbService(AppConfig.Base.dbTables, _conn).Delete("CouponAssignRecords", Id);
  250. }
  251. /// <summary>
  252. /// 排序
  253. /// </summary>
  254. /// <param name="Id">主键Id</param>
  255. /// <param name="Sort">排序序号</param>
  256. public void Sort(int Id, int Sort)
  257. {
  258. new DbService(AppConfig.Base.dbTables, _conn).Sort("CouponAssignRecords", Sort, Id);
  259. }
  260. /// <summary>
  261. /// 导入数据
  262. /// </summary>
  263. /// <param name="ExcelData">json数据</param>
  264. public void Import(string ExcelData)
  265. {
  266. WebCMSEntities db = new WebCMSEntities();
  267. JsonData list = JsonMapper.ToObject(ExcelData);
  268. for (int i = 1; i < list.Count;i++ )
  269. {
  270. JsonData dr = list[i];
  271. db.CouponAssignRecords.Add(new CouponAssignRecords()
  272. {
  273. CreateDate = DateTime.Now,
  274. UpdateDate = DateTime.Now,
  275. });
  276. db.SaveChanges();
  277. }
  278. db.Dispose();
  279. }
  280. /// <summary>
  281. /// 导出excel表格
  282. /// </summary>
  283. /// <param name="fields">查询条件(单个字段)</param>
  284. /// <param name="condition">查询条件(sql语句)</param>
  285. /// <returns></returns>
  286. // public void ExportExcel(List<RelationData> relationData, string condition)
  287. // {
  288. // }
  289. }
  290. }