MerchantAddInfoService.cs 23 KB

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