SycnSpMerchantService.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.SpModels;
  5. using Library;
  6. using LitJson;
  7. namespace MySystem
  8. {
  9. public class SycnSpMerchantService
  10. {
  11. public readonly static SycnSpMerchantService Instance = new SycnSpMerchantService();
  12. private SycnSpMerchantService()
  13. { }
  14. public void Start()
  15. {
  16. WebCMSEntities spdb = new WebCMSEntities();
  17. PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
  18. DateTime start = DateTime.Now.AddDays(-2);
  19. var Mers = spdb.Merchants.Where(m => m.CreateTime >= start && m.Status == 1).OrderByDescending(m => m.Id).ToList();
  20. foreach (var Mer in Mers)
  21. {
  22. PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo) ?? new PxcModels.MachineForMerNo();
  23. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId) ?? new PxcModels.PosMachinesTwo();
  24. if (pos.BindingState == 1)
  25. {
  26. PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
  27. int TopUserId = 0;
  28. if (!string.IsNullOrEmpty(user.ParentNav))
  29. {
  30. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  31. }
  32. PxcModels.PosMerchantInfo add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
  33. {
  34. CreateDate = Mer.CreateTime,
  35. UpdateDate = Mer.UpdateTime,
  36. TopUserId = TopUserId,
  37. MerUserType = user.MerchantType,
  38. BrandId = int.Parse(Mer.ProductType),
  39. SnStoreId = pos.StoreId,
  40. SnType = pos.PosSnType,
  41. UserId = pos.UserId,
  42. MgrName = Mer.AgentName,
  43. MerStatus = 1,
  44. KqSnNo = Mer.SnNo,
  45. KqMerNo = Mer.MerNo,
  46. MerIdcardNo = Mer.MerIdcardNo,
  47. MerRealName = Mer.MerRealName,
  48. MerchantMobile = Mer.MerMobile,
  49. MerchantName = Mer.MerName,
  50. MerchantNo = Mer.MerNo,
  51. }).Entity;
  52. db.SaveChanges();
  53. pos.BindMerchantId = add.Id;
  54. Merchants edit = spdb.Merchants.FirstOrDefault(m => m.Id == Mer.Id);
  55. if (edit != null)
  56. {
  57. edit.Status = 2;
  58. }
  59. }
  60. }
  61. spdb.SaveChanges();
  62. spdb.Dispose();
  63. db.SaveChanges();
  64. db.Dispose();
  65. }
  66. }
  67. }