1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using MySystem.SpModels;
- using Library;
- using LitJson;
- namespace MySystem
- {
- public class SycnSpMerchantService
- {
- public readonly static SycnSpMerchantService Instance = new SycnSpMerchantService();
- private SycnSpMerchantService()
- { }
- public void Start()
- {
- WebCMSEntities spdb = new WebCMSEntities();
- PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
- DateTime start = DateTime.Now.AddDays(-2);
- var Mers = spdb.Merchants.Where(m => m.CreateTime >= start && m.Status == 1).OrderByDescending(m => m.Id).ToList();
- foreach (var Mer in Mers)
- {
- PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo) ?? new PxcModels.MachineForMerNo();
- PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId) ?? new PxcModels.PosMachinesTwo();
- if (pos.BindingState == 1)
- {
- PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
- int TopUserId = 0;
- if (!string.IsNullOrEmpty(user.ParentNav))
- {
- TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
- }
- int BrandId = int.Parse(Mer.ProductType);
- if(Mer.MerNo.StartsWith("M900"))
- {
- BrandId = 3;
- }
- PxcModels.PosMerchantInfo add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
- {
- CreateDate = Mer.CreateTime,
- UpdateDate = Mer.UpdateTime,
- TopUserId = TopUserId,
- MerUserType = user.MerchantType,
- BrandId = BrandId,
- SnStoreId = pos.StoreId,
- SnType = pos.PosSnType,
- UserId = pos.UserId,
- MgrName = Mer.AgentName,
- MerStatus = 1,
- KqSnNo = Mer.SnNo,
- KqMerNo = Mer.MerNo,
- MerIdcardNo = Mer.MerIdcardNo,
- MerRealName = Mer.MerRealName,
- MerchantMobile = Mer.MerMobile,
- MerchantName = Mer.MerName,
- MerchantNo = Mer.MerNo,
- }).Entity;
- db.SaveChanges();
- pos.BindMerchantId = add.Id;
- Merchants edit = spdb.Merchants.FirstOrDefault(m => m.Id == Mer.Id);
- if (edit != null)
- {
- edit.Status = 2;
- }
- }
- }
- spdb.SaveChanges();
- spdb.Dispose();
- db.SaveChanges();
- db.Dispose();
- }
- }
- }
|