MerchantAccountLinkInfoService.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.MainModels;
  5. using Library;
  6. using LitJson;
  7. namespace MySystem
  8. {
  9. public class MerchantAccountLinkInfoService
  10. {
  11. string _conn = "";
  12. public MerchantAccountLinkInfoService()
  13. {
  14. _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  15. }
  16. /// <summary>
  17. /// 查询列表
  18. /// </summary>
  19. /// <param name="fields">查询条件(单个字段)</param>
  20. /// <param name="condition">查询条件(sql语句)</param>
  21. /// <param name="page">页码</param>
  22. /// <param name="limit">每页条数</param>
  23. /// <returns></returns>
  24. public List<Dictionary<string, object>> List(List<FieldItem> fields, string condition, int page = 1, int limit = 30, string orderby = "Id desc")
  25. {
  26. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantAccountLinkInfo", fields, orderby, "0", page, limit, condition);
  27. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  28. return diclist;
  29. }
  30. public List<Dictionary<string, object>> List(int LoginId)
  31. {
  32. List<Dictionary<string, object>> diclist = new List<Dictionary<string, object>>();
  33. WebCMSEntities db = new WebCMSEntities();
  34. var list = db.MerchantAccountLinkInfo.Where(m => m.LoginId == LoginId).ToList();
  35. foreach(var item in list)
  36. {
  37. Dictionary<string, object> row = new Dictionary<string, object>();
  38. if(item.Kind == 1)
  39. {
  40. var merchant = new MerchantAddInfoService().Query(item.MerchantId);
  41. if(merchant.Status >= 1 || merchant.QueryCount >= 1)
  42. {
  43. row.Add("MerchantId", merchant.Id);
  44. row.Add("MerchantName", merchant.CertMerchantName);
  45. row.Add("Kind", item.Kind);
  46. diclist.Add(row);
  47. }
  48. }
  49. else
  50. {
  51. var merchant = new MerchantAddInfo2Service().Query(item.MerchantId);
  52. if(merchant.HdStatus > 0)
  53. {
  54. row.Add("MerchantId", merchant.Id);
  55. row.Add("MerchantName", merchant.CertMerchantName);
  56. row.Add("Kind", item.Kind);
  57. diclist.Add(row);
  58. }
  59. }
  60. }
  61. db.Dispose();
  62. return diclist;
  63. }
  64. /// <summary>
  65. /// 查询一条记录
  66. /// </summary>
  67. /// <param name="Id">主键Id</param>
  68. /// <returns></returns>
  69. public MerchantAccountLinkInfo Query(int Id)
  70. {
  71. WebCMSEntities db = new WebCMSEntities();
  72. MerchantAccountLinkInfo editData = db.MerchantAccountLinkInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAccountLinkInfo();
  73. db.Dispose();
  74. return editData;
  75. }
  76. /// <summary>
  77. /// 添加数据
  78. /// </summary>
  79. /// <param name="Fields">要设置的字段</param>
  80. /// <returns></returns>
  81. public int Add(Dictionary<string, object> Fields)
  82. {
  83. return new DbService(AppConfig.Base.mainTables, _conn).Add("MerchantAccountLinkInfo", Fields, 0);
  84. }
  85. /// <summary>
  86. /// 修改数据
  87. /// </summary>
  88. /// <param name="Fields">要设置的字段</param>
  89. /// <param name="Id">主键Id</param>
  90. public void Edit(Dictionary<string, object> Fields, int Id)
  91. {
  92. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantAccountLinkInfo", Fields, Id);
  93. }
  94. /// <summary>
  95. /// 删除数据
  96. /// </summary>
  97. /// <param name="Id">主键Id</param>
  98. public void Delete(int Id)
  99. {
  100. new DbService(AppConfig.Base.mainTables, _conn).Delete("MerchantAccountLinkInfo", Id);
  101. }
  102. /// <summary>
  103. /// 排序
  104. /// </summary>
  105. /// <param name="Id">主键Id</param>
  106. /// <param name="Sort">排序序号</param>
  107. public void Sort(int Id, int Sort)
  108. {
  109. new DbService(AppConfig.Base.mainTables, _conn).Sort("MerchantAccountLinkInfo", Sort, Id);
  110. }
  111. /// <summary>
  112. /// 导入数据
  113. /// </summary>
  114. /// <param name="ExcelData">json数据</param>
  115. public void Import(string ExcelData)
  116. {
  117. WebCMSEntities db = new WebCMSEntities();
  118. JsonData list = JsonMapper.ToObject(ExcelData);
  119. for (int i = 1; i < list.Count;i++ )
  120. {
  121. JsonData dr = list[i];
  122. db.MerchantAccountLinkInfo.Add(new MerchantAccountLinkInfo()
  123. {
  124. CreateDate = DateTime.Now,
  125. UpdateDate = DateTime.Now,
  126. });
  127. db.SaveChanges();
  128. }
  129. db.Dispose();
  130. }
  131. /// <summary>
  132. /// 导出excel表格
  133. /// </summary>
  134. /// <param name="fields">查询条件(单个字段)</param>
  135. /// <param name="condition">查询条件(sql语句)</param>
  136. /// <returns></returns>
  137. public Dictionary<string, object> ExportExcel(List<FieldItem> fields, string condition, string orderby = "Id desc")
  138. {
  139. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantAccountLinkInfo", fields, orderby, "0", 1, 20000, condition, "Id", false);
  140. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  141. foreach (Dictionary<string, object> dic in diclist)
  142. {
  143. }
  144. Dictionary<string, object> result = new Dictionary<string, object>();
  145. result.Add("Status", "1");
  146. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  147. result.Add("Obj", diclist);
  148. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  149. result.Add("Fields", ReturnFields);
  150. return result;
  151. }
  152. }
  153. }