123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using MySystem.SpModels;
- using Library;
- using LitJson;
- using System.Threading;
- namespace MySystem
- {
- public class SycnSpActiveService
- {
- public readonly static SycnSpActiveService Instance = new SycnSpActiveService();
- private SycnSpActiveService()
- { }
- public void Start()
- {
- Thread th = new Thread(StartDo);
- th.IsBackground = true;
- th.Start();
- }
- public void StartDo()
- {
- while (true)
- {
- try
- {
- WebCMSEntities spdb = new WebCMSEntities();
- PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
- string Month = DateTime.Now.ToString("yyyyMM");
- string Date = DateTime.Now.ToString("yyyyMMdd");
- DateTime start = DateTime.Now.AddDays(-5);
- DateTime end = DateTime.Now.AddMinutes(-1);
- int StartId = int.Parse(function.CheckInt(function.ReadInstance("/SycnSp/ActivateRecordId.txt")));
- IQueryable<ActivateRecord> acts = spdb.ActivateRecord.Where(m => m.Id >= StartId && m.ActivateDate >= start && m.ActivateDate < end && m.Status == 1).OrderByDescending(m => m.Id);
- foreach (ActivateRecord act in acts.ToList())
- {
- PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == act.MerNo) ?? new PxcModels.MachineForMerNo();
- PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
- if (pos != null)
- {
- PxcModels.KqProducts kqproduct = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new PxcModels.KqProducts();
- if (kqproduct.SingleDepositApi == 1)
- {
- pos.SeoKeyword = act.SeoTitle;
- if(pos.BrandId == 15 || pos.BrandId == 16) //来客吧
- {
- pos.Detail = ""; //清除激活奖励标记
- RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString()); //发开机奖励
- }
- db.SaveChanges();
- PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PxcModels.PosMerchantInfo();
- if(pos.BrandId < 18 || pos.BrandId > 21) //来客吧
- {
- StatService.Instance.PreActPrize(db, pos, merchant, act.SeoTitle);
- }
- }
- if(pos.BrandId == 7 || pos.BrandId == 12 || pos.BrandId == 13 || pos.BrandId == 15 || pos.BrandId == 16)
- {
- decimal CheckMoney = kqproduct.ActTradeAmount > 0 ? kqproduct.ActTradeAmount : 1000;
- int CheckDays = 30;
- SycnSpTradeService.Instance.ActPos(db, pos, CheckMoney, CheckDays);
- if(pos.ActivationState == 1)
- {
- decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
- DateTime now = DateTime.Now;
- function.WriteLog("大盟主---Deposit:" + Deposit + ";LeaderUserId:" + pos.LeaderUserId + ";pos.IsFirst:" + pos.IsFirst + ";pos.BindingTime:" + pos.BindingTime + ";now.AddDays(-CheckDays):" + now.AddDays(-CheckDays) + ";", "押金推送发放奖励监控");
- if (Deposit > 0 && pos.LeaderUserId > 0 && db.Leaders.Any(m => m.Id == pos.LeaderUserId && m.ExpiredDate > now) && pos.BindingTime > now.AddDays(-CheckDays) && pos.CardType < 100)
- {
- function.WriteLog("大盟主奖发放", "押金推送发放奖励监控");
- RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
- }
- //发放运营中心奖励
- if (Deposit > 0 && pos.BindingTime > now.AddDays(-CheckDays) && pos.CardType < 100)
- {
- function.WriteLog("运营中心奖发放", "押金推送发放奖励监控");
- RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
- }
- }
- }
- if(pos.BrandId == 18 || pos.BrandId == 19 || pos.BrandId == 20 || pos.BrandId == 21)
- {
- decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
- decimal Prize = 0;
- if(Deposit == 198) Prize = 70;
- if(Deposit == 249) Prize = 100;
- if(Deposit == 228) Prize = 61;
- if(Deposit == 380) Prize = 151;
- if(Deposit == 399) Prize = 100;
- if(Prize > 0)
- {
- DateTime now = DateTime.Now;
- PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PxcModels.PosMerchantInfo();
- PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new PxcModels.Users();
- int TopUserId = 0;
- if (!string.IsNullOrEmpty(user.ParentNav))
- {
- TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
- }
- pos.ActivationState = 1;
- pos.ActivationTime = now;
- merchant.ActiveStatus = 1;
- merchant.MerStandardDate = now;
- StatService.Instance.doActiveReward(db, merchant, pos, pos.BuyUserId, user.ParentNav, TopUserId, Prize);
- if(pos.CardType < 100)
- {
- RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString());
- }
- if (Deposit > 0 && pos.LeaderUserId > 0 && db.Leaders.Any(m => m.Id == pos.LeaderUserId && m.ExpiredDate > now) && pos.CardType < 100)
- {
- RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id);
- }
- //发放运营中心奖励
- if (Deposit > 0 && pos.CardType < 100)
- {
- RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id);
- }
- }
- }
- ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
- if (edit != null)
- {
- edit.Status = 2;
- }
- }
- pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId && m.ActivationState == 1);
- if (pos != null)
- {
- ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
- if (edit != null)
- {
- edit.Status = 2;
- }
- }
- }
- spdb.SaveChanges();
- spdb.Dispose();
- db.SaveChanges();
- db.Dispose();
- }
- catch (Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP激活数据到MAIN异常");
- }
- Thread.Sleep(1000);
- }
- }
- }
- }
|