MerchantAuthService.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 MerchantAuthService
  14. {
  15. string _conn = "";
  16. public MerchantAuthService()
  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("ChannelCode"); //渠道编码
  36. fields.Add("ChannelName"); //渠道名称
  37. fields.Add("MerNo"); //商户编号
  38. fields.Add("RealName"); //真实姓名
  39. fields.Add("IdCardNo"); //身份证号
  40. fields.Add("BankCardAccount"); //银行卡账号
  41. fields.Add("BankName"); //银行名称
  42. fields.Add("BankMobile"); //银行预留手机号码
  43. fields.Add("AuthType"); //实名类型
  44. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("MerchantAuth", relationData, orderBy, page, limit, condition, fields);
  45. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  46. count = int.Parse(obj["count"].ToString());
  47. return diclist;
  48. }
  49. public List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  50. {
  51. List<string> fields = new List<string>(); //要显示的列
  52. fields.Add("Id");
  53. fields.Add("CreateDate"); //添加时间
  54. fields.Add("Status"); //状态
  55. fields.Add("ChannelCode"); //渠道编码
  56. fields.Add("ChannelName"); //渠道名称
  57. fields.Add("MerNo"); //商户编号
  58. fields.Add("RealName"); //真实姓名
  59. fields.Add("IdCardNo"); //身份证号
  60. fields.Add("BankCardAccount"); //银行卡账号
  61. fields.Add("BankName"); //银行名称
  62. fields.Add("BankMobile"); //银行预留手机号码
  63. fields.Add("AuthType"); //实名类型
  64. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("MerchantAuth", relationData, orderBy, page, limit, condition, fields);
  65. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  66. return diclist;
  67. }
  68. /// <summary>
  69. /// 查询一条记录
  70. /// </summary>
  71. /// <param name="Id">主键Id</param>
  72. /// <returns></returns>
  73. public MerchantAuth Query(int Id)
  74. {
  75. WebCMSEntities db = new WebCMSEntities();
  76. MerchantAuth editData = db.MerchantAuth.FirstOrDefault(m => m.Id == Id) ?? new MerchantAuth();
  77. db.Dispose();
  78. return editData;
  79. }
  80. /// <summary>
  81. /// 查询记录数
  82. /// </summary>
  83. /// <param name="Id">主键Id</param>
  84. /// <returns></returns>
  85. public int Count(string condition = "")
  86. {
  87. int result = 0;
  88. DataTable dt = CustomerSqlConn.dtable("select count(Id) from MerchantAuth where 1=1" + condition, _conn);
  89. if(dt.Rows.Count > 0)
  90. {
  91. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  92. }
  93. return result;
  94. }
  95. /// <summary>
  96. /// 查询是否存在
  97. /// </summary>
  98. /// <param name="Id">主键Id</param>
  99. /// <returns></returns>
  100. public bool Exist(int Id)
  101. {
  102. WebCMSEntities db = new WebCMSEntities();
  103. bool check = db.MerchantAuth.Any(m => m.Id == Id);
  104. db.Dispose();
  105. return check;
  106. }
  107. /// <summary>
  108. /// 添加数据
  109. /// </summary>
  110. /// <param name="Fields">要设置的字段</param>
  111. /// <returns></returns>
  112. public AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  113. {
  114. if(check)
  115. {
  116. if (string.IsNullOrEmpty(fields["IdCardNo"].ToString()))
  117. {
  118. return new AppResultJson() { Status = "-1", Info = "请填写身份证号" };
  119. }
  120. if (function.CheckIdCard(fields["IdCardNo"].ToString()) == "")
  121. {
  122. return new AppResultJson() { Status = "-1", Info = "请填写正确的身份证号" };
  123. }
  124. if (string.IsNullOrEmpty(fields["BankCardAccount"].ToString()))
  125. {
  126. return new AppResultJson() { Status = "-1", Info = "请填写银行卡账号" };
  127. }
  128. }
  129. int Id = new DbService(AppConfig.Base.dbTables, _conn).Add("MerchantAuth", fields, 0);
  130. return new AppResultJson(){ Status = "1", Data = Id };
  131. }
  132. /// <summary>
  133. /// 修改数据
  134. /// </summary>
  135. /// <param name="Fields">要设置的字段</param>
  136. /// <param name="Id">主键Id</param>
  137. public AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  138. {
  139. if(check)
  140. {
  141. if (string.IsNullOrEmpty(fields["IdCardNo"].ToString()))
  142. {
  143. return new AppResultJson() { Status = "-1", Info = "请填写身份证号" };
  144. }
  145. if (function.CheckIdCard(fields["IdCardNo"].ToString()) == "")
  146. {
  147. return new AppResultJson() { Status = "-1", Info = "请填写正确的身份证号" };
  148. }
  149. if (string.IsNullOrEmpty(fields["BankCardAccount"].ToString()))
  150. {
  151. return new AppResultJson() { Status = "-1", Info = "请填写银行卡账号" };
  152. }
  153. }
  154. new DbService(AppConfig.Base.dbTables, _conn).Edit("MerchantAuth", fields, Id);
  155. return new AppResultJson(){ Status = "1", Data = Id };
  156. }
  157. /// <summary>
  158. /// 逻辑删除
  159. /// </summary>
  160. /// <param name="Id">主键Id</param>
  161. public void Remove(int Id)
  162. {
  163. Dictionary<string, object> fields = new Dictionary<string, object>();
  164. fields.Add("Status", -1);
  165. new DbService(AppConfig.Base.dbTables, _conn).Edit("MerchantAuth", fields, Id);
  166. }
  167. /// <summary>
  168. /// 删除数据
  169. /// </summary>
  170. /// <param name="Id">主键Id</param>
  171. public void Delete(int Id)
  172. {
  173. new DbService(AppConfig.Base.dbTables, _conn).Delete("MerchantAuth", Id);
  174. }
  175. /// <summary>
  176. /// 排序
  177. /// </summary>
  178. /// <param name="Id">主键Id</param>
  179. /// <param name="Sort">排序序号</param>
  180. public void Sort(int Id, int Sort)
  181. {
  182. new DbService(AppConfig.Base.dbTables, _conn).Sort("MerchantAuth", Sort, Id);
  183. }
  184. /// <summary>
  185. /// 导入数据
  186. /// </summary>
  187. /// <param name="ExcelData">json数据</param>
  188. public void Import(string ExcelData)
  189. {
  190. WebCMSEntities db = new WebCMSEntities();
  191. JsonData list = JsonMapper.ToObject(ExcelData);
  192. for (int i = 1; i < list.Count;i++ )
  193. {
  194. JsonData dr = list[i];
  195. db.MerchantAuth.Add(new MerchantAuth()
  196. {
  197. CreateDate = DateTime.Now,
  198. UpdateDate = DateTime.Now,
  199. });
  200. db.SaveChanges();
  201. }
  202. db.Dispose();
  203. }
  204. /// <summary>
  205. /// 导出excel表格
  206. /// </summary>
  207. /// <param name="fields">查询条件(单个字段)</param>
  208. /// <param name="condition">查询条件(sql语句)</param>
  209. /// <returns></returns>
  210. // public void ExportExcel(List<RelationData> relationData, string condition)
  211. // {
  212. // }
  213. }
  214. }