BusinessPartnerMerchantService.cs 9.5 KB

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