using System; using System.Collections.Generic; using System.Linq; using MySystem.SpModels; using Library; using LitJson; using System.Threading; namespace MySystem { public class SycnSpTradeService { public readonly static SycnSpTradeService Instance = new SycnSpTradeService(); private SycnSpTradeService() { } //激活逻辑 public void ActPos(PxcModels.WebCMSEntities db, PxcModels.PosMachinesTwo pos, decimal CheckMoney, int CheckDays, bool PrizeFlag = true, string ActivationTime = "") { DateTime now = DateTime.Now; if(!string.IsNullOrEmpty(ActivationTime)) { now = DateTime.Parse(ActivationTime); } DateTime TransferTime = pos.TransferTime == null ? DateTime.Now : pos.TransferTime.Value; int minute = 30; if (pos.CreditTrade >= CheckMoney && pos.BuyUserId > 0 && pos.ActivationState == 0 && TransferTime.AddMinutes(-minute) < pos.BindingTime) { pos.ActivationState = 1; pos.ActivationTime = now; if(pos.CardType == 101) { pos.IsPurchase = 1; } Utils.WriteLog("机具" + pos.PosSn, "开机奖励在激活中监控"); Utils.WriteLog("PrizeFlag:" + PrizeFlag, "开机奖励在激活中监控"); PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId); if (merchant != null) { Utils.WriteLog("查询到商户", "开机奖励在激活中监控"); merchant.ActiveStatus = 1; merchant.MerStandardDate = now; db.SaveChanges(); Utils.WriteLog("商户" + merchant.KqMerNo, "开机奖励在激活中监控"); //发放开机奖励 Utils.WriteLog("首台" + pos.IsFirst, "开机奖励在激活中监控"); if(pos.BindingTime > now.AddDays(-CheckDays) && pos.CardType < 100 && PrizeFlag) { Utils.WriteLog("开机奖发放", "开机奖励在激活中监控"); RedisDbconn.Instance.AddList("OpenRewardQueue", pos.Id.ToString()); if(pos.BrandId == 14) { if(pos.LeaderUserId > 0 && db.Leaders.Any(m => m.Id == pos.LeaderUserId && m.ExpiredDate > now)) { RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id); } RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id); } } } //发放大盟主奖励 Utils.WriteLog("大盟主---PrizeFlag:" + PrizeFlag + ";LeaderUserId:" + pos.LeaderUserId + ";pos.IsFirst:" + pos.IsFirst + ";pos.BindingTime:" + pos.BindingTime + ";now.AddDays(-CheckDays):" + now.AddDays(-CheckDays) + ";", "开机奖励在激活中监控"); decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword)); 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 && PrizeFlag) { Utils.WriteLog("大盟主奖发放", "开机奖励在激活中监控"); RedisDbconn.Instance.AddList("LeaderPrizeQueue", pos.Id); } //发放运营中心奖励 if (Deposit > 0 && pos.BindingTime > now.AddDays(-CheckDays) && pos.CardType < 100 && PrizeFlag) { Utils.WriteLog("运营中心奖发放", "开机奖励在激活中监控"); RedisDbconn.Instance.AddList("OperatePrizeQueue", pos.Id); } if(pos.CardType < 100) { // AlipayPayBack2Service.Instance.ActReserveBack(pos.OpId, pos.OpReserve1, pos.OpReserve2, pos.OpReserve3); //统计激活数 RedisDbconn.Instance.AddList("StatActQueue", "{\"TradeDate\":\"" + now.ToString("yyyyMMdd") + "\",\"UserId\":\"" + pos.BuyUserId + "\",\"BrandId\":\"" + pos.BrandId + "\"}"); //运营中心额度变更 OpAmountItem item = new OpAmountItem() { UserId = pos.OpId, OperateType = 1, ChangeType = 9, Remark = "机具激活", UseAmount = pos.OpReserve1 + pos.OpReserve2 + pos.OpReserve3, UseValidForGetAmount = pos.OpReserve2, UseTotalAmt = pos.OpReserve1, UseValidAmount = pos.OpReserve3, DataType = 2, DataId = pos.Id, }; RedisDbconn.Instance.AddList("OperateAmountRecordServiceQueue", item); } //清理预扣款 RedisDbconn.Instance.AddList("PosWithholdQueue", "{\"UserId\":\"" + pos.BuyUserId + "\",\"SnNo\":\"" + pos.PosSn + "\"}"); } } } }