UserAuthRecordService.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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 UserAuthRecordService
  14. {
  15. string _conn = "";
  16. public UserAuthRecordService()
  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("UserId"); //创客
  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("UserAuthRecord", 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("UserId"); //创客
  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("UserAuthRecord", 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 UserAuthRecord Query(int Id)
  74. {
  75. WebCMSEntities db = new WebCMSEntities();
  76. UserAuthRecord editData = db.UserAuthRecord.FirstOrDefault(m => m.Id == Id) ?? new UserAuthRecord();
  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 UserAuthRecord 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.UserAuthRecord.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["ChannelCode"].ToString()))
  117. {
  118. return new AppResultJson() { Status = "-1", Info = "请填写渠道编码" };
  119. }
  120. if (string.IsNullOrEmpty(fields["RealName"].ToString()))
  121. {
  122. return new AppResultJson() { Status = "-1", Info = "请填写真实姓名" };
  123. }
  124. if (string.IsNullOrEmpty(fields["IdcardNo"].ToString()))
  125. {
  126. return new AppResultJson() { Status = "-1", Info = "请填写身份证号码" };
  127. }
  128. if (function.CheckIdCard(fields["IdcardNo"].ToString()) == "")
  129. {
  130. return new AppResultJson() { Status = "-1", Info = "请填写正确的身份证号码" };
  131. }
  132. if (string.IsNullOrEmpty(fields["BankCardAccount"].ToString()))
  133. {
  134. return new AppResultJson() { Status = "-1", Info = "请填写银行卡账号" };
  135. }
  136. }
  137. int Id = new DbService(AppConfig.Base.dbTables, _conn).Add("UserAuthRecord", fields, 0);
  138. return new AppResultJson(){ Status = "1", Data = Id };
  139. }
  140. /// <summary>
  141. /// 修改数据
  142. /// </summary>
  143. /// <param name="Fields">要设置的字段</param>
  144. /// <param name="Id">主键Id</param>
  145. public AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  146. {
  147. if(check)
  148. {
  149. if (string.IsNullOrEmpty(fields["ChannelCode"].ToString()))
  150. {
  151. return new AppResultJson() { Status = "-1", Info = "请填写渠道编码" };
  152. }
  153. if (string.IsNullOrEmpty(fields["RealName"].ToString()))
  154. {
  155. return new AppResultJson() { Status = "-1", Info = "请填写真实姓名" };
  156. }
  157. if (string.IsNullOrEmpty(fields["IdcardNo"].ToString()))
  158. {
  159. return new AppResultJson() { Status = "-1", Info = "请填写身份证号码" };
  160. }
  161. if (function.CheckIdCard(fields["IdcardNo"].ToString()) == "")
  162. {
  163. return new AppResultJson() { Status = "-1", Info = "请填写正确的身份证号码" };
  164. }
  165. if (string.IsNullOrEmpty(fields["BankCardAccount"].ToString()))
  166. {
  167. return new AppResultJson() { Status = "-1", Info = "请填写银行卡账号" };
  168. }
  169. }
  170. new DbService(AppConfig.Base.dbTables, _conn).Edit("UserAuthRecord", fields, Id);
  171. return new AppResultJson(){ Status = "1", Data = Id };
  172. }
  173. /// <summary>
  174. /// 逻辑删除
  175. /// </summary>
  176. /// <param name="Id">主键Id</param>
  177. public void Remove(int Id)
  178. {
  179. Dictionary<string, object> fields = new Dictionary<string, object>();
  180. fields.Add("Status", -1);
  181. new DbService(AppConfig.Base.dbTables, _conn).Edit("UserAuthRecord", fields, Id);
  182. }
  183. /// <summary>
  184. /// 删除数据
  185. /// </summary>
  186. /// <param name="Id">主键Id</param>
  187. public void Delete(int Id)
  188. {
  189. new DbService(AppConfig.Base.dbTables, _conn).Delete("UserAuthRecord", Id);
  190. }
  191. /// <summary>
  192. /// 排序
  193. /// </summary>
  194. /// <param name="Id">主键Id</param>
  195. /// <param name="Sort">排序序号</param>
  196. public void Sort(int Id, int Sort)
  197. {
  198. new DbService(AppConfig.Base.dbTables, _conn).Sort("UserAuthRecord", Sort, Id);
  199. }
  200. /// <summary>
  201. /// 导入数据
  202. /// </summary>
  203. /// <param name="ExcelData">json数据</param>
  204. public void Import(string ExcelData)
  205. {
  206. WebCMSEntities db = new WebCMSEntities();
  207. JsonData list = JsonMapper.ToObject(ExcelData);
  208. for (int i = 1; i < list.Count;i++ )
  209. {
  210. JsonData dr = list[i];
  211. db.UserAuthRecord.Add(new UserAuthRecord()
  212. {
  213. CreateDate = DateTime.Now,
  214. UpdateDate = DateTime.Now,
  215. });
  216. db.SaveChanges();
  217. }
  218. db.Dispose();
  219. }
  220. /// <summary>
  221. /// 导出excel表格
  222. /// </summary>
  223. /// <param name="fields">查询条件(单个字段)</param>
  224. /// <param name="condition">查询条件(sql语句)</param>
  225. /// <returns></returns>
  226. // public void ExportExcel(List<RelationData> relationData, string condition)
  227. // {
  228. // }
  229. }
  230. }