MerchantAddInfoService.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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 MerchantAddInfoService
  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("ApplymentState"); //申请单状态
  32. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantAddInfo", relationData, orderBy, page, limit, condition, fields);
  33. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  34. count = int.Parse(obj["count"].ToString());
  35. return diclist;
  36. }
  37. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  38. {
  39. List<string> fields = new List<string>(); //要显示的列
  40. fields.Add("Id");
  41. fields.Add("CreateDate"); //添加时间
  42. fields.Add("Status"); //状态
  43. fields.Add("ApplymentState"); //申请单状态
  44. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantAddInfo", relationData, orderBy, page, limit, condition, fields);
  45. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  46. return diclist;
  47. }
  48. /// <summary>
  49. /// 查询一条记录
  50. /// </summary>
  51. /// <param name="Id">主键Id</param>
  52. /// <returns></returns>
  53. public static MerchantAddInfo Query(int Id)
  54. {
  55. WebCMSEntities db = new WebCMSEntities();
  56. MerchantAddInfo editData = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  57. db.Dispose();
  58. return editData;
  59. }
  60. public static MerchantAddInfo Query(string condition, string fields = "*")
  61. {
  62. var merchantAddInfo = new DbService(AppConfig.Base.mainTables, _conn).Query(fields, "MerchantAddInfo", condition);
  63. if (merchantAddInfo.Count > 0)
  64. {
  65. return Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantAddInfo>(Newtonsoft.Json.JsonConvert.SerializeObject(merchantAddInfo));
  66. }
  67. return new MerchantAddInfo();
  68. }
  69. public static decimal Sum(string condition, string field)
  70. {
  71. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Sum(" + field + ") " + field, "MerchantAddInfo", condition);
  72. decimal amount = 0;
  73. if (dt.Count > 0)
  74. {
  75. amount = decimal.Parse(dt[field].ToString());
  76. }
  77. return amount;
  78. }
  79. /// <summary>
  80. /// 查询记录数
  81. /// </summary>
  82. /// <param name="Id">主键Id</param>
  83. /// <returns></returns>
  84. public static int Count(string condition = "", string field = "Id")
  85. {
  86. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Count(" + field + ") " + field, "MerchantAddInfo", condition);
  87. int result = 0;
  88. if (dt.Count > 0)
  89. {
  90. result = int.Parse(dt[field].ToString());
  91. }
  92. return result;
  93. }
  94. /// <summary>
  95. /// 查询是否存在
  96. /// </summary>
  97. /// <param name="Id">主键Id</param>
  98. /// <returns></returns>
  99. public static bool Exist(int Id)
  100. {
  101. WebCMSEntities db = new WebCMSEntities();
  102. bool check = db.MerchantAddInfo.Any(m => m.Id == Id);
  103. db.Dispose();
  104. return check;
  105. }
  106. /// <summary>
  107. /// 添加数据
  108. /// </summary>
  109. /// <param name="Fields">要设置的字段</param>
  110. /// <returns></returns>
  111. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  112. {
  113. if (check)
  114. {
  115. if (string.IsNullOrEmpty(fields["ContactName"].ToString()))
  116. {
  117. return new AppResultJson() { Status = "-1", Info = "请填写管理员姓名" };
  118. }
  119. if (string.IsNullOrEmpty(fields["ContactIdNumber"].ToString()))
  120. {
  121. return new AppResultJson() { Status = "-1", Info = "请填写管理员身份证件号码" };
  122. }
  123. if (function.CheckIdCard(fields["ContactIdNumber"].ToString()) == "")
  124. {
  125. return new AppResultJson() { Status = "-1", Info = "请填写正确的管理员身份证件号码" };
  126. }
  127. if (string.IsNullOrEmpty(fields["OpenId"].ToString()))
  128. {
  129. return new AppResultJson() { Status = "-1", Info = "请填写管理员微信openid" };
  130. }
  131. if (string.IsNullOrEmpty(fields["MobilePhone"].ToString()))
  132. {
  133. return new AppResultJson() { Status = "-1", Info = "请填写联系手机" };
  134. }
  135. if (function.CheckMobile(fields["MobilePhone"].ToString()) == "")
  136. {
  137. return new AppResultJson() { Status = "-1", Info = "请填写正确的联系手机" };
  138. }
  139. if (string.IsNullOrEmpty(fields["ContactEmail"].ToString()))
  140. {
  141. return new AppResultJson() { Status = "-1", Info = "请填写联系邮箱" };
  142. }
  143. if (string.IsNullOrEmpty(fields["SubjectType"].ToString()))
  144. {
  145. return new AppResultJson() { Status = "-1", Info = "请填写主体类型" };
  146. }
  147. if (string.IsNullOrEmpty(fields["LicenseNumber"].ToString()))
  148. {
  149. return new AppResultJson() { Status = "-1", Info = "请填写统一社会信用代码" };
  150. }
  151. if (string.IsNullOrEmpty(fields["LegalPerson"].ToString()))
  152. {
  153. return new AppResultJson() { Status = "-1", Info = "请填写个体户经营者/法人姓名" };
  154. }
  155. if (string.IsNullOrEmpty(fields["MerchantShortname"].ToString()))
  156. {
  157. return new AppResultJson() { Status = "-1", Info = "请填写商户简称" };
  158. }
  159. if (string.IsNullOrEmpty(fields["SalesScenesType"].ToString()))
  160. {
  161. return new AppResultJson() { Status = "-1", Info = "请填写经营场景类型" };
  162. }
  163. if (string.IsNullOrEmpty(fields["BizStoreName"].ToString()))
  164. {
  165. return new AppResultJson() { Status = "-1", Info = "请填写门店名称" };
  166. }
  167. if (string.IsNullOrEmpty(fields["BizAddressCode"].ToString()))
  168. {
  169. return new AppResultJson() { Status = "-1", Info = "请填写门店省市编码" };
  170. }
  171. if (string.IsNullOrEmpty(fields["BizStoreAddress"].ToString()))
  172. {
  173. return new AppResultJson() { Status = "-1", Info = "请填写门店地址" };
  174. }
  175. if (string.IsNullOrEmpty(fields["MpAppid"].ToString()))
  176. {
  177. return new AppResultJson() { Status = "-1", Info = "请填写服务商公众号APPID" };
  178. }
  179. if (string.IsNullOrEmpty(fields["MpSubAppid"].ToString()))
  180. {
  181. return new AppResultJson() { Status = "-1", Info = "请填写商家公众号APPID" };
  182. }
  183. if (string.IsNullOrEmpty(fields["MiniProgramAppid"].ToString()))
  184. {
  185. return new AppResultJson() { Status = "-1", Info = "请填写服务商小程序APPID" };
  186. }
  187. if (string.IsNullOrEmpty(fields["MiniProgramSubAppid"].ToString()))
  188. {
  189. return new AppResultJson() { Status = "-1", Info = "请填写商家小程序APPID" };
  190. }
  191. if (string.IsNullOrEmpty(fields["AppAppid"].ToString()))
  192. {
  193. return new AppResultJson() { Status = "-1", Info = "请填写服务商应用APPID" };
  194. }
  195. if (string.IsNullOrEmpty(fields["AppSubAppid"].ToString()))
  196. {
  197. return new AppResultJson() { Status = "-1", Info = "请填写商家应用APPID" };
  198. }
  199. if (string.IsNullOrEmpty(fields["WebDomain"].ToString()))
  200. {
  201. return new AppResultJson() { Status = "-1", Info = "请填写互联网网站域名" };
  202. }
  203. if (string.IsNullOrEmpty(fields["WebAppId"].ToString()))
  204. {
  205. return new AppResultJson() { Status = "-1", Info = "请填写互联网网站对应的商家APPID" };
  206. }
  207. if (string.IsNullOrEmpty(fields["SubCorpId"].ToString()))
  208. {
  209. return new AppResultJson() { Status = "-1", Info = "请填写商家企业微信CorpID" };
  210. }
  211. if (string.IsNullOrEmpty(fields["SettlementId"].ToString()))
  212. {
  213. return new AppResultJson() { Status = "-1", Info = "请填写入驻结算规则ID" };
  214. }
  215. if (string.IsNullOrEmpty(fields["QualificationType"].ToString()))
  216. {
  217. return new AppResultJson() { Status = "-1", Info = "请填写所属行业" };
  218. }
  219. if (string.IsNullOrEmpty(fields["ActivitiesId"].ToString()))
  220. {
  221. return new AppResultJson() { Status = "-1", Info = "请填写优惠费率活动ID" };
  222. }
  223. if (string.IsNullOrEmpty(fields["BankAccountType"].ToString()))
  224. {
  225. return new AppResultJson() { Status = "-1", Info = "请填写账户类型" };
  226. }
  227. if (string.IsNullOrEmpty(fields["AccountName"].ToString()))
  228. {
  229. return new AppResultJson() { Status = "-1", Info = "请填写开户名称" };
  230. }
  231. if (string.IsNullOrEmpty(fields["AccountBank"].ToString()))
  232. {
  233. return new AppResultJson() { Status = "-1", Info = "请填写开户银行" };
  234. }
  235. if (string.IsNullOrEmpty(fields["BankAddressCode"].ToString()))
  236. {
  237. return new AppResultJson() { Status = "-1", Info = "请填写开户银行省市编码" };
  238. }
  239. if (string.IsNullOrEmpty(fields["BankBranchId"].ToString()))
  240. {
  241. return new AppResultJson() { Status = "-1", Info = "请填写开户银行联行号" };
  242. }
  243. if (string.IsNullOrEmpty(fields["BankName"].ToString()))
  244. {
  245. return new AppResultJson() { Status = "-1", Info = "请填写开户银行全称" };
  246. }
  247. if (string.IsNullOrEmpty(fields["AccountNumber"].ToString()))
  248. {
  249. return new AppResultJson() { Status = "-1", Info = "请填写银行账号" };
  250. }
  251. }
  252. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("MerchantAddInfo", fields, 0);
  253. return new AppResultJson() { Status = "1", Data = Id };
  254. }
  255. /// <summary>
  256. /// 修改数据
  257. /// </summary>
  258. /// <param name="Fields">要设置的字段</param>
  259. /// <param name="Id">主键Id</param>
  260. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  261. {
  262. if (check)
  263. {
  264. if (string.IsNullOrEmpty(fields["ContactName"].ToString()))
  265. {
  266. return new AppResultJson() { Status = "-1", Info = "请填写管理员姓名" };
  267. }
  268. if (string.IsNullOrEmpty(fields["ContactIdNumber"].ToString()))
  269. {
  270. return new AppResultJson() { Status = "-1", Info = "请填写管理员身份证件号码" };
  271. }
  272. if (function.CheckIdCard(fields["ContactIdNumber"].ToString()) == "")
  273. {
  274. return new AppResultJson() { Status = "-1", Info = "请填写正确的管理员身份证件号码" };
  275. }
  276. if (string.IsNullOrEmpty(fields["OpenId"].ToString()))
  277. {
  278. return new AppResultJson() { Status = "-1", Info = "请填写管理员微信openid" };
  279. }
  280. if (string.IsNullOrEmpty(fields["MobilePhone"].ToString()))
  281. {
  282. return new AppResultJson() { Status = "-1", Info = "请填写联系手机" };
  283. }
  284. if (function.CheckMobile(fields["MobilePhone"].ToString()) == "")
  285. {
  286. return new AppResultJson() { Status = "-1", Info = "请填写正确的联系手机" };
  287. }
  288. if (string.IsNullOrEmpty(fields["ContactEmail"].ToString()))
  289. {
  290. return new AppResultJson() { Status = "-1", Info = "请填写联系邮箱" };
  291. }
  292. if (string.IsNullOrEmpty(fields["SubjectType"].ToString()))
  293. {
  294. return new AppResultJson() { Status = "-1", Info = "请填写主体类型" };
  295. }
  296. if (string.IsNullOrEmpty(fields["LicenseNumber"].ToString()))
  297. {
  298. return new AppResultJson() { Status = "-1", Info = "请填写统一社会信用代码" };
  299. }
  300. if (string.IsNullOrEmpty(fields["LegalPerson"].ToString()))
  301. {
  302. return new AppResultJson() { Status = "-1", Info = "请填写个体户经营者/法人姓名" };
  303. }
  304. if (string.IsNullOrEmpty(fields["MerchantShortname"].ToString()))
  305. {
  306. return new AppResultJson() { Status = "-1", Info = "请填写商户简称" };
  307. }
  308. if (string.IsNullOrEmpty(fields["SalesScenesType"].ToString()))
  309. {
  310. return new AppResultJson() { Status = "-1", Info = "请填写经营场景类型" };
  311. }
  312. if (string.IsNullOrEmpty(fields["BizStoreName"].ToString()))
  313. {
  314. return new AppResultJson() { Status = "-1", Info = "请填写门店名称" };
  315. }
  316. if (string.IsNullOrEmpty(fields["BizAddressCode"].ToString()))
  317. {
  318. return new AppResultJson() { Status = "-1", Info = "请填写门店省市编码" };
  319. }
  320. if (string.IsNullOrEmpty(fields["BizStoreAddress"].ToString()))
  321. {
  322. return new AppResultJson() { Status = "-1", Info = "请填写门店地址" };
  323. }
  324. if (string.IsNullOrEmpty(fields["MpAppid"].ToString()))
  325. {
  326. return new AppResultJson() { Status = "-1", Info = "请填写服务商公众号APPID" };
  327. }
  328. if (string.IsNullOrEmpty(fields["MpSubAppid"].ToString()))
  329. {
  330. return new AppResultJson() { Status = "-1", Info = "请填写商家公众号APPID" };
  331. }
  332. if (string.IsNullOrEmpty(fields["MiniProgramAppid"].ToString()))
  333. {
  334. return new AppResultJson() { Status = "-1", Info = "请填写服务商小程序APPID" };
  335. }
  336. if (string.IsNullOrEmpty(fields["MiniProgramSubAppid"].ToString()))
  337. {
  338. return new AppResultJson() { Status = "-1", Info = "请填写商家小程序APPID" };
  339. }
  340. if (string.IsNullOrEmpty(fields["AppAppid"].ToString()))
  341. {
  342. return new AppResultJson() { Status = "-1", Info = "请填写服务商应用APPID" };
  343. }
  344. if (string.IsNullOrEmpty(fields["AppSubAppid"].ToString()))
  345. {
  346. return new AppResultJson() { Status = "-1", Info = "请填写商家应用APPID" };
  347. }
  348. if (string.IsNullOrEmpty(fields["WebDomain"].ToString()))
  349. {
  350. return new AppResultJson() { Status = "-1", Info = "请填写互联网网站域名" };
  351. }
  352. if (string.IsNullOrEmpty(fields["WebAppId"].ToString()))
  353. {
  354. return new AppResultJson() { Status = "-1", Info = "请填写互联网网站对应的商家APPID" };
  355. }
  356. if (string.IsNullOrEmpty(fields["SubCorpId"].ToString()))
  357. {
  358. return new AppResultJson() { Status = "-1", Info = "请填写商家企业微信CorpID" };
  359. }
  360. if (string.IsNullOrEmpty(fields["SettlementId"].ToString()))
  361. {
  362. return new AppResultJson() { Status = "-1", Info = "请填写入驻结算规则ID" };
  363. }
  364. if (string.IsNullOrEmpty(fields["QualificationType"].ToString()))
  365. {
  366. return new AppResultJson() { Status = "-1", Info = "请填写所属行业" };
  367. }
  368. if (string.IsNullOrEmpty(fields["ActivitiesId"].ToString()))
  369. {
  370. return new AppResultJson() { Status = "-1", Info = "请填写优惠费率活动ID" };
  371. }
  372. if (string.IsNullOrEmpty(fields["BankAccountType"].ToString()))
  373. {
  374. return new AppResultJson() { Status = "-1", Info = "请填写账户类型" };
  375. }
  376. if (string.IsNullOrEmpty(fields["AccountName"].ToString()))
  377. {
  378. return new AppResultJson() { Status = "-1", Info = "请填写开户名称" };
  379. }
  380. if (string.IsNullOrEmpty(fields["AccountBank"].ToString()))
  381. {
  382. return new AppResultJson() { Status = "-1", Info = "请填写开户银行" };
  383. }
  384. if (string.IsNullOrEmpty(fields["BankAddressCode"].ToString()))
  385. {
  386. return new AppResultJson() { Status = "-1", Info = "请填写开户银行省市编码" };
  387. }
  388. if (string.IsNullOrEmpty(fields["BankBranchId"].ToString()))
  389. {
  390. return new AppResultJson() { Status = "-1", Info = "请填写开户银行联行号" };
  391. }
  392. if (string.IsNullOrEmpty(fields["BankName"].ToString()))
  393. {
  394. return new AppResultJson() { Status = "-1", Info = "请填写开户银行全称" };
  395. }
  396. if (string.IsNullOrEmpty(fields["AccountNumber"].ToString()))
  397. {
  398. return new AppResultJson() { Status = "-1", Info = "请填写银行账号" };
  399. }
  400. }
  401. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantAddInfo", fields, Id);
  402. return new AppResultJson() { Status = "1", Data = Id };
  403. }
  404. /// <summary>
  405. /// 逻辑删除
  406. /// </summary>
  407. /// <param name="Id">主键Id</param>
  408. public static void Remove(int Id)
  409. {
  410. Dictionary<string, object> fields = new Dictionary<string, object>();
  411. fields.Add("Status", -1);
  412. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantAddInfo", fields, Id);
  413. }
  414. /// <summary>
  415. /// 删除数据
  416. /// </summary>
  417. /// <param name="Id">主键Id</param>
  418. public static void Delete(int Id)
  419. {
  420. new DbService(AppConfig.Base.mainTables, _conn).Delete("MerchantAddInfo", Id);
  421. }
  422. /// <summary>
  423. /// 排序
  424. /// </summary>
  425. /// <param name="Id">主键Id</param>
  426. /// <param name="Sort">排序序号</param>
  427. public static void Sort(int Id, int Sort)
  428. {
  429. new DbService(AppConfig.Base.mainTables, _conn).Sort("MerchantAddInfo", Sort, Id);
  430. }
  431. /// <summary>
  432. /// 导入数据
  433. /// </summary>
  434. /// <param name="ExcelData">json数据</param>
  435. public static void Import(string ExcelData)
  436. {
  437. WebCMSEntities db = new WebCMSEntities();
  438. JsonData list = JsonMapper.ToObject(ExcelData);
  439. for (int i = 1; i < list.Count; i++)
  440. {
  441. JsonData dr = list[i];
  442. db.MerchantAddInfo.Add(new MerchantAddInfo()
  443. {
  444. CreateDate = DateTime.Now,
  445. UpdateDate = DateTime.Now,
  446. });
  447. db.SaveChanges();
  448. }
  449. db.Dispose();
  450. }
  451. /// <summary>
  452. /// 导出excel表格
  453. /// </summary>
  454. /// <param name="fields">查询条件(单个字段)</param>
  455. /// <param name="condition">查询条件(sql语句)</param>
  456. /// <returns></returns>
  457. // public static void ExportExcel(List<RelationData> relationData, string condition)
  458. // {
  459. // }
  460. }
  461. }