HomeController.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using Microsoft.AspNetCore.Mvc;
  7. using Microsoft.Extensions.Logging;
  8. using Library;
  9. using LitJson;
  10. using System.Text;
  11. using MySystem.Models.Main;
  12. namespace MySystem.Controllers
  13. {
  14. public class HomeController : Controller
  15. {
  16. private readonly ILogger<HomeController> _logger;
  17. public HomeController(ILogger<HomeController> logger)
  18. {
  19. _logger = logger;
  20. }
  21. public IActionResult Index()
  22. {
  23. return View();
  24. }
  25. public string addsubmer()
  26. {
  27. WebCMSEntities db = new WebCMSEntities();
  28. List<string> data = new List<string>();
  29. // data.Add("015510108266178|成都红地餐饮管理有限公司|20241112");
  30. foreach(string sub in data)
  31. {
  32. string[] list = sub.Split('|');
  33. string merNo = list[0];
  34. string merName = list[1];
  35. string bindDateString = list[2];
  36. string bindDate = bindDateString.Substring(0, 4) + "-" + bindDateString.Substring(4, 2) + "-" + bindDateString.Substring(6, 2);
  37. if(!db.MerchantAddInfo.Any(m => m.MchtNo == merNo))
  38. {
  39. MerchantAddInfo source = db.MerchantAddInfo.FirstOrDefault(m => m.CertMerchantName == merName && m.ParentId == 0);
  40. int sourceCount = db.MerchantAddInfo.Count(m => m.CertMerchantName == merName && m.ParentId == 0);
  41. if(source != null && sourceCount == 1)
  42. {
  43. MerchantInfo sourceInfo = db.MerchantInfo.FirstOrDefault(m => m.Id == source.Id) ?? new MerchantInfo();
  44. MerchantInfo info = db.MerchantInfo.Add(new MerchantInfo()
  45. {
  46. CreateDate = DateTime.Parse(bindDate),
  47. UpdateDate = DateTime.Parse(bindDate),
  48. Name = merName,
  49. UserId = sourceInfo.UserId,
  50. ParentId = source.Id,
  51. Status = 2,
  52. QueryCount = 2,
  53. Sort = 1,
  54. }).Entity;
  55. db.SaveChanges();
  56. db.MerchantAddInfo.Add(new MerchantAddInfo()
  57. {
  58. Id = info.Id,
  59. CreateDate = DateTime.Parse(bindDate),
  60. UpdateDate = DateTime.Parse(bindDate),
  61. CertMerchantName = merName,
  62. MchtNo = merNo,
  63. ParentId = source.Id,
  64. StoreNo = source.StoreNo,
  65. OutMchtNo = source.OutMchtNo,
  66. BrandId = source.BrandId,
  67. AgentName = source.AgentName,
  68. Status = 2,
  69. QueryCount = 2,
  70. HdStatus = 1,
  71. });
  72. db.SaveChanges();
  73. }
  74. }
  75. }
  76. db.Dispose();
  77. return "ok";
  78. }
  79. }
  80. }