SycnSpMerchantService.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. int BrandId = int.Parse(Mer.ProductType);
  33. if(Mer.MerNo.StartsWith("M900"))
  34. {
  35. BrandId = 3;
  36. }
  37. PxcModels.PosMerchantInfo add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
  38. {
  39. CreateDate = Mer.CreateTime,
  40. UpdateDate = Mer.UpdateTime,
  41. TopUserId = TopUserId,
  42. MerUserType = user.MerchantType,
  43. BrandId = BrandId,
  44. SnStoreId = pos.StoreId,
  45. SnType = pos.PosSnType,
  46. UserId = pos.UserId,
  47. MgrName = Mer.AgentName,
  48. MerStatus = 1,
  49. KqSnNo = Mer.SnNo,
  50. KqMerNo = Mer.MerNo,
  51. MerIdcardNo = Mer.MerIdcardNo,
  52. MerRealName = Mer.MerRealName,
  53. MerchantMobile = Mer.MerMobile,
  54. MerchantName = Mer.MerName,
  55. MerchantNo = Mer.MerNo,
  56. }).Entity;
  57. db.SaveChanges();
  58. pos.BindMerchantId = add.Id;
  59. Merchants edit = spdb.Merchants.FirstOrDefault(m => m.Id == Mer.Id);
  60. if (edit != null)
  61. {
  62. edit.Status = 2;
  63. }
  64. }
  65. }
  66. spdb.SaveChanges();
  67. spdb.Dispose();
  68. db.SaveChanges();
  69. db.Dispose();
  70. }
  71. }
  72. }