MerchantParamSetService.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 MerchantParamSetService
  14. {
  15. string _conn = "";
  16. public MerchantParamSetService()
  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. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantParamSet", relationData, orderBy, page, limit, condition, fields);
  36. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  37. count = int.Parse(obj["count"].ToString());
  38. return diclist;
  39. }
  40. public List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  41. {
  42. List<string> fields = new List<string>(); //要显示的列
  43. fields.Add("Id");
  44. fields.Add("CreateDate"); //添加时间
  45. fields.Add("Status"); //状态
  46. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantParamSet", relationData, orderBy, page, limit, condition, fields);
  47. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  48. return diclist;
  49. }
  50. /// <summary>
  51. /// 查询一条记录
  52. /// </summary>
  53. /// <param name="Id">主键Id</param>
  54. /// <returns></returns>
  55. public MerchantParamSet Query(int Id)
  56. {
  57. WebCMSEntities db = new WebCMSEntities();
  58. MerchantParamSet editData = db.MerchantParamSet.FirstOrDefault(m => m.Id == Id) ?? new MerchantParamSet();
  59. db.Dispose();
  60. return editData;
  61. }
  62. /// <summary>
  63. /// 查询记录数
  64. /// </summary>
  65. /// <param name="Id">主键Id</param>
  66. /// <returns></returns>
  67. public int Count(string condition = "")
  68. {
  69. int result = 0;
  70. DataTable dt = CustomerSqlConn.dtable("select count(Id) from MerchantParamSet where 1=1" + condition, _conn);
  71. if(dt.Rows.Count > 0)
  72. {
  73. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  74. }
  75. return result;
  76. }
  77. /// <summary>
  78. /// 查询是否存在
  79. /// </summary>
  80. /// <param name="Id">主键Id</param>
  81. /// <returns></returns>
  82. public bool Exist(int Id)
  83. {
  84. WebCMSEntities db = new WebCMSEntities();
  85. bool check = db.MerchantParamSet.Any(m => m.Id == Id);
  86. db.Dispose();
  87. return check;
  88. }
  89. /// <summary>
  90. /// 添加数据
  91. /// </summary>
  92. /// <param name="Fields">要设置的字段</param>
  93. /// <returns></returns>
  94. public AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  95. {
  96. if(check)
  97. {
  98. if (string.IsNullOrEmpty(fields["IsAll"].ToString()))
  99. {
  100. return new AppResultJson() { Status = "-1", Info = "请填写是否收全额" };
  101. }
  102. if (string.IsNullOrEmpty(fields["MinPayMoney"].ToString()))
  103. {
  104. return new AppResultJson() { Status = "-1", Info = "请填写订单参与门槛" };
  105. }
  106. if (string.IsNullOrEmpty(fields["GetPercent"].ToString()))
  107. {
  108. return new AppResultJson() { Status = "-1", Info = "请填写商家实收比例" };
  109. }
  110. if (string.IsNullOrEmpty(fields["ProfitDays"].ToString()))
  111. {
  112. return new AppResultJson() { Status = "-1", Info = "请填写分红期限(天)" };
  113. }
  114. if (!function.IsInt(fields["ProfitDays"].ToString()))
  115. {
  116. return new AppResultJson() { Status = "-1", Info = "请填写正确的分红期限(天)" };
  117. }
  118. if (string.IsNullOrEmpty(fields["DiviPercent"].ToString()))
  119. {
  120. return new AppResultJson() { Status = "-1", Info = "请填写最大分红比例" };
  121. }
  122. if (string.IsNullOrEmpty(fields["DiviPersons"].ToString()))
  123. {
  124. return new AppResultJson() { Status = "-1", Info = "请填写单笔订单分红人数" };
  125. }
  126. if (!function.IsInt(fields["DiviPersons"].ToString()))
  127. {
  128. return new AppResultJson() { Status = "-1", Info = "请填写正确的单笔订单分红人数" };
  129. }
  130. }
  131. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("MerchantParamSet", fields, 0);
  132. return new AppResultJson(){ Status = "1", Data = Id };
  133. }
  134. /// <summary>
  135. /// 修改数据
  136. /// </summary>
  137. /// <param name="Fields">要设置的字段</param>
  138. /// <param name="Id">主键Id</param>
  139. public AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  140. {
  141. if(check)
  142. {
  143. if (string.IsNullOrEmpty(fields["IsAll"].ToString()))
  144. {
  145. return new AppResultJson() { Status = "-1", Info = "请填写是否收全额" };
  146. }
  147. if (string.IsNullOrEmpty(fields["MinPayMoney"].ToString()))
  148. {
  149. return new AppResultJson() { Status = "-1", Info = "请填写订单参与门槛" };
  150. }
  151. if (string.IsNullOrEmpty(fields["GetPercent"].ToString()))
  152. {
  153. return new AppResultJson() { Status = "-1", Info = "请填写商家实收比例" };
  154. }
  155. if (string.IsNullOrEmpty(fields["ProfitDays"].ToString()))
  156. {
  157. return new AppResultJson() { Status = "-1", Info = "请填写分红期限(天)" };
  158. }
  159. if (!function.IsInt(fields["ProfitDays"].ToString()))
  160. {
  161. return new AppResultJson() { Status = "-1", Info = "请填写正确的分红期限(天)" };
  162. }
  163. if (string.IsNullOrEmpty(fields["DiviPercent"].ToString()))
  164. {
  165. return new AppResultJson() { Status = "-1", Info = "请填写最大分红比例" };
  166. }
  167. if (string.IsNullOrEmpty(fields["DiviPersons"].ToString()))
  168. {
  169. return new AppResultJson() { Status = "-1", Info = "请填写单笔订单分红人数" };
  170. }
  171. if (!function.IsInt(fields["DiviPersons"].ToString()))
  172. {
  173. return new AppResultJson() { Status = "-1", Info = "请填写正确的单笔订单分红人数" };
  174. }
  175. }
  176. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantParamSet", fields, Id);
  177. return new AppResultJson(){ Status = "1", Data = Id };
  178. }
  179. /// <summary>
  180. /// 逻辑删除
  181. /// </summary>
  182. /// <param name="Id">主键Id</param>
  183. public void Remove(int Id)
  184. {
  185. Dictionary<string, object> fields = new Dictionary<string, object>();
  186. fields.Add("Status", -1);
  187. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantParamSet", fields, Id);
  188. }
  189. /// <summary>
  190. /// 删除数据
  191. /// </summary>
  192. /// <param name="Id">主键Id</param>
  193. public void Delete(int Id)
  194. {
  195. new DbService(AppConfig.Base.mainTables, _conn).Delete("MerchantParamSet", Id);
  196. }
  197. /// <summary>
  198. /// 排序
  199. /// </summary>
  200. /// <param name="Id">主键Id</param>
  201. /// <param name="Sort">排序序号</param>
  202. public void Sort(int Id, int Sort)
  203. {
  204. new DbService(AppConfig.Base.mainTables, _conn).Sort("MerchantParamSet", Sort, Id);
  205. }
  206. /// <summary>
  207. /// 导入数据
  208. /// </summary>
  209. /// <param name="ExcelData">json数据</param>
  210. public 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.MerchantParamSet.Add(new MerchantParamSet()
  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 void ExportExcel(List<RelationData> relationData, string condition)
  233. // {
  234. // }
  235. }
  236. }