SycnSpMerchantService.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == Mer.SnNo) ?? new PxcModels.MachineForSnNo();
  23. PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId) ?? new PxcModels.PosMachinesTwo();
  24. PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
  25. int TopUserId = 0;
  26. if (!string.IsNullOrEmpty(user.ParentNav))
  27. {
  28. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  29. }
  30. PxcModels.PosMerchantInfo add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
  31. {
  32. CreateDate = Mer.CreateTime,
  33. UpdateDate = Mer.UpdateTime,
  34. TopUserId = TopUserId,
  35. MerUserType = user.MerchantType,
  36. BrandId = int.Parse(Mer.ProductType),
  37. SnStoreId = pos.StoreId,
  38. SnType = pos.PosSnType,
  39. UserId = pos.UserId,
  40. MgrName = Mer.AgentName,
  41. MerStatus = 1,
  42. KqSnNo = Mer.SnNo,
  43. KqMerNo = Mer.MerNo,
  44. MerIdcardNo = Mer.MerIdcardNo,
  45. MerRealName = Mer.MerRealName,
  46. MerchantMobile = Mer.MerMobile,
  47. MerchantName = Mer.MerName,
  48. MerchantNo = Mer.MerNo,
  49. }).Entity;
  50. db.SaveChanges();
  51. pos.BindMerchantId = add.Id;
  52. Merchants edit = spdb.Merchants.FirstOrDefault(m => m.Id == Mer.Id);
  53. if (edit != null)
  54. {
  55. edit.Status = 2;
  56. }
  57. }
  58. spdb.SaveChanges();
  59. spdb.Dispose();
  60. db.SaveChanges();
  61. db.Dispose();
  62. }
  63. }
  64. }