MerchantParamSetService.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. 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. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantParamSet", relationData, orderBy, page, limit, condition, fields);
  32. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  33. count = int.Parse(obj["count"].ToString());
  34. return diclist;
  35. }
  36. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  37. {
  38. List<string> fields = new List<string>(); //要显示的列
  39. fields.Add("Id");
  40. fields.Add("CreateDate"); //添加时间
  41. fields.Add("Status"); //状态
  42. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantParamSet", relationData, orderBy, page, limit, condition, fields);
  43. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  44. return diclist;
  45. }
  46. /// <summary>
  47. /// 查询一条记录
  48. /// </summary>
  49. /// <param name="Id">主键Id</param>
  50. /// <returns></returns>
  51. public static MerchantParamSet Query(int Id)
  52. {
  53. WebCMSEntities db = new WebCMSEntities();
  54. MerchantParamSet editData = db.MerchantParamSet.FirstOrDefault(m => m.Id == Id) ?? new MerchantParamSet();
  55. db.Dispose();
  56. return editData;
  57. }
  58. public static MerchantParamSet Query(string condition, string fields = "*")
  59. {
  60. var merchantParamSet = new DbService(AppConfig.Base.mainTables, _conn).Query(fields, "MerchantParamSet", condition);
  61. if (merchantParamSet.Count > 0)
  62. {
  63. return Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantParamSet>(Newtonsoft.Json.JsonConvert.SerializeObject(merchantParamSet));
  64. }
  65. return new MerchantParamSet();
  66. }
  67. public static decimal Sum(string condition, string field)
  68. {
  69. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Sum(" + field + ") " + field, "MerchantParamSet", condition);
  70. decimal amount = 0;
  71. if (dt.Count > 0)
  72. {
  73. amount = decimal.Parse(dt[field].ToString());
  74. }
  75. return amount;
  76. }
  77. /// <summary>
  78. /// 查询记录数
  79. /// </summary>
  80. /// <param name="Id">主键Id</param>
  81. /// <returns></returns>
  82. public static int Count(string condition = "", string field = "Id")
  83. {
  84. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Count(" + field + ") " + field, "MerchantParamSet", condition);
  85. int result = 0;
  86. if (dt.Count > 0)
  87. {
  88. result = int.Parse(dt[field].ToString());
  89. }
  90. return result;
  91. }
  92. /// <summary>
  93. /// 查询是否存在
  94. /// </summary>
  95. /// <param name="Id">主键Id</param>
  96. /// <returns></returns>
  97. public static bool Exist(int Id)
  98. {
  99. WebCMSEntities db = new WebCMSEntities();
  100. bool check = db.MerchantParamSet.Any(m => m.Id == Id);
  101. db.Dispose();
  102. return check;
  103. }
  104. /// <summary>
  105. /// 添加数据
  106. /// </summary>
  107. /// <param name="Fields">要设置的字段</param>
  108. /// <returns></returns>
  109. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  110. {
  111. if(check)
  112. {
  113. if (string.IsNullOrEmpty(fields["IsAll"].ToString()))
  114. {
  115. return new AppResultJson() { Status = "-1", Info = "请填写是否收全额" };
  116. }
  117. if (string.IsNullOrEmpty(fields["MinPayMoney"].ToString()))
  118. {
  119. return new AppResultJson() { Status = "-1", Info = "请填写订单参与门槛" };
  120. }
  121. if (string.IsNullOrEmpty(fields["GetPercent"].ToString()))
  122. {
  123. return new AppResultJson() { Status = "-1", Info = "请填写商家实收比例" };
  124. }
  125. if (string.IsNullOrEmpty(fields["ProfitDays"].ToString()))
  126. {
  127. return new AppResultJson() { Status = "-1", Info = "请填写分红期限(天)" };
  128. }
  129. if (!function.IsInt(fields["ProfitDays"].ToString()))
  130. {
  131. return new AppResultJson() { Status = "-1", Info = "请填写正确的分红期限(天)" };
  132. }
  133. if (string.IsNullOrEmpty(fields["DiviPercent"].ToString()))
  134. {
  135. return new AppResultJson() { Status = "-1", Info = "请填写最大分红比例" };
  136. }
  137. if (string.IsNullOrEmpty(fields["DiviPersons"].ToString()))
  138. {
  139. return new AppResultJson() { Status = "-1", Info = "请填写单笔订单分红人数" };
  140. }
  141. if (!function.IsInt(fields["DiviPersons"].ToString()))
  142. {
  143. return new AppResultJson() { Status = "-1", Info = "请填写正确的单笔订单分红人数" };
  144. }
  145. }
  146. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("MerchantParamSet", fields, 0);
  147. return new AppResultJson(){ Status = "1", Data = Id };
  148. }
  149. /// <summary>
  150. /// 修改数据
  151. /// </summary>
  152. /// <param name="Fields">要设置的字段</param>
  153. /// <param name="Id">主键Id</param>
  154. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  155. {
  156. if(check)
  157. {
  158. if (string.IsNullOrEmpty(fields["IsAll"].ToString()))
  159. {
  160. return new AppResultJson() { Status = "-1", Info = "请填写是否收全额" };
  161. }
  162. if (string.IsNullOrEmpty(fields["MinPayMoney"].ToString()))
  163. {
  164. return new AppResultJson() { Status = "-1", Info = "请填写订单参与门槛" };
  165. }
  166. if (string.IsNullOrEmpty(fields["GetPercent"].ToString()))
  167. {
  168. return new AppResultJson() { Status = "-1", Info = "请填写商家实收比例" };
  169. }
  170. if (string.IsNullOrEmpty(fields["ProfitDays"].ToString()))
  171. {
  172. return new AppResultJson() { Status = "-1", Info = "请填写分红期限(天)" };
  173. }
  174. if (!function.IsInt(fields["ProfitDays"].ToString()))
  175. {
  176. return new AppResultJson() { Status = "-1", Info = "请填写正确的分红期限(天)" };
  177. }
  178. if (string.IsNullOrEmpty(fields["DiviPercent"].ToString()))
  179. {
  180. return new AppResultJson() { Status = "-1", Info = "请填写最大分红比例" };
  181. }
  182. if (string.IsNullOrEmpty(fields["DiviPersons"].ToString()))
  183. {
  184. return new AppResultJson() { Status = "-1", Info = "请填写单笔订单分红人数" };
  185. }
  186. if (!function.IsInt(fields["DiviPersons"].ToString()))
  187. {
  188. return new AppResultJson() { Status = "-1", Info = "请填写正确的单笔订单分红人数" };
  189. }
  190. }
  191. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantParamSet", fields, Id);
  192. return new AppResultJson(){ Status = "1", Data = Id };
  193. }
  194. /// <summary>
  195. /// 逻辑删除
  196. /// </summary>
  197. /// <param name="Id">主键Id</param>
  198. public static void Remove(int Id)
  199. {
  200. Dictionary<string, object> fields = new Dictionary<string, object>();
  201. fields.Add("Status", -1);
  202. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantParamSet", fields, Id);
  203. }
  204. /// <summary>
  205. /// 删除数据
  206. /// </summary>
  207. /// <param name="Id">主键Id</param>
  208. public static void Delete(int Id)
  209. {
  210. new DbService(AppConfig.Base.mainTables, _conn).Delete("MerchantParamSet", Id);
  211. }
  212. /// <summary>
  213. /// 排序
  214. /// </summary>
  215. /// <param name="Id">主键Id</param>
  216. /// <param name="Sort">排序序号</param>
  217. public static void Sort(int Id, int Sort)
  218. {
  219. new DbService(AppConfig.Base.mainTables, _conn).Sort("MerchantParamSet", Sort, Id);
  220. }
  221. /// <summary>
  222. /// 导入数据
  223. /// </summary>
  224. /// <param name="ExcelData">json数据</param>
  225. public static void Import(string ExcelData)
  226. {
  227. WebCMSEntities db = new WebCMSEntities();
  228. JsonData list = JsonMapper.ToObject(ExcelData);
  229. for (int i = 1; i < list.Count;i++ )
  230. {
  231. JsonData dr = list[i];
  232. db.MerchantParamSet.Add(new MerchantParamSet()
  233. {
  234. CreateDate = DateTime.Now,
  235. UpdateDate = DateTime.Now,
  236. });
  237. db.SaveChanges();
  238. }
  239. db.Dispose();
  240. }
  241. /// <summary>
  242. /// 导出excel表格
  243. /// </summary>
  244. /// <param name="fields">查询条件(单个字段)</param>
  245. /// <param name="condition">查询条件(sql语句)</param>
  246. /// <returns></returns>
  247. // public static void ExportExcel(List<RelationData> relationData, string condition)
  248. // {
  249. // }
  250. }
  251. }