|
@@ -813,7 +813,7 @@ namespace MySystem
|
|
|
// 开机奖励详情
|
|
|
RedisDbconn.Instance.AddList("OpenRewardDetail:" + puser.Id + ":" + pos.BrandId + ":" + dateString, detail);
|
|
|
|
|
|
- Prize -= 10;
|
|
|
+ Prize = 0;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -827,6 +827,189 @@ namespace MySystem
|
|
|
db.Dispose();
|
|
|
}
|
|
|
|
|
|
+ //实时获取开机奖励
|
|
|
+ public void StartOpenReward()
|
|
|
+ {
|
|
|
+ Thread th = new Thread(StartOpenRewardDo);
|
|
|
+ th.IsBackground = true;
|
|
|
+ th.Start();
|
|
|
+ }
|
|
|
+ public void StartOpenRewardDo()
|
|
|
+ {
|
|
|
+ string content = RedisDbconn.Instance.RPop<string>("OpenRewardQueue");
|
|
|
+ if(!string.IsNullOrEmpty(content))
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ int PosId = int.Parse(content);
|
|
|
+ WebCMSEntities db = new WebCMSEntities();
|
|
|
+ List<PosMachinesTwo> posList = db.PosMachinesTwo.Where(m => m.Id == PosId && m.ActivationState == 1 && !string.IsNullOrEmpty(m.SeoKeyword) && m.SeoKeyword != "0" && m.CreditTrade >= 1000).ToList();
|
|
|
+ foreach (PosMachinesTwo pos in posList)
|
|
|
+ {
|
|
|
+ if (pos.BindingTime > DateTime.Now.AddDays(-30))
|
|
|
+ {
|
|
|
+ decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
|
|
|
+ if (ActPrize > 0)
|
|
|
+ {
|
|
|
+ PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
|
|
|
+ if (merchant != null)
|
|
|
+ {
|
|
|
+ Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
|
|
|
+ if (user != null)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(user.ParentNav))
|
|
|
+ {
|
|
|
+ decimal Prize = 20;
|
|
|
+ string[] ParentNavs = user.ParentNav.Trim(',').Replace(",,", ",").Split(',');
|
|
|
+ for (int i = ParentNavs.Length - 1; i >= 0; i--)
|
|
|
+ {
|
|
|
+ int UserId = int.Parse(ParentNavs[i]);
|
|
|
+ Users puser = db.Users.FirstOrDefault(m => m.Id == UserId && m.AuthFlag == 1);
|
|
|
+ if (puser != null && Prize > 0)
|
|
|
+ {
|
|
|
+ int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
|
|
|
+ int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
|
|
|
+ int couponCount = db.PosCoupons.Count(m => m.UserId == puser.Id && m.IsUse == 0); //判断是否拥有3张券
|
|
|
+ // int BigCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.BrandId == 3); //判断是否拥有2台大机
|
|
|
+ // int BigActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1 && m.BrandId == 3); //判断是否拥有2台激活大机(不限购买或赠送)
|
|
|
+ if (machineCount + ActiveCount + couponCount >= 3)
|
|
|
+ {
|
|
|
+ int pTopUserId = 0;
|
|
|
+ if (!string.IsNullOrEmpty(puser.ParentNav))
|
|
|
+ {
|
|
|
+ pTopUserId = int.Parse(puser.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
|
|
|
+ }
|
|
|
+ Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
|
|
|
+ OpenRewardDetail detail = db.OpenRewardDetail.Add(new OpenRewardDetail()
|
|
|
+ {
|
|
|
+ CreateDate = DateTime.Now,
|
|
|
+ UpdateDate = DateTime.Now,
|
|
|
+ TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
|
|
|
+ TradeDate = DateTime.Now, //达标日期
|
|
|
+ UserId = puser.Id, //创客
|
|
|
+ BrandId = pos.BrandId, //品牌
|
|
|
+ ProductName = RelationClass.GetKqProductsInfo(pos.BrandId), //产品名称
|
|
|
+ MerchantId = pos.BindMerchantId, //商户
|
|
|
+ DirectUserId = merchant.UserId, //商户直属人
|
|
|
+ SnNo = pos.PosSn, //SN号
|
|
|
+ MerNo = merchant.KqMerNo, //渠道商户号
|
|
|
+ SnType = pos.PosSnType, //机具类型
|
|
|
+ StandardDate = pos.ActivationTime, //商户的激活日期
|
|
|
+ SnStoreId = pos.StoreId, //SN仓库
|
|
|
+ MerBuddyType = puser.MerchantType, //商户创客类型
|
|
|
+ RewardType = 1, //奖励类型 1-开机直接奖励,2-开机间接奖励
|
|
|
+ RewardTips = "开机奖励", //奖励描述
|
|
|
+ CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
|
|
|
+ DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
|
|
|
+ CreditRewardAmount = Prize, //贷记卡交易奖励金额
|
|
|
+ RewardDesc = "开机奖励", //奖励描述
|
|
|
+ TopUserId = pTopUserId, //顶级创客
|
|
|
+ SeoTitle = machineUser.RealName,
|
|
|
+ }).Entity;
|
|
|
+ db.OpenReward.Add(new OpenReward()
|
|
|
+ {
|
|
|
+ CreateDate = DateTime.Now,
|
|
|
+ UpdateDate = DateTime.Now,
|
|
|
+ TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
|
|
|
+ TradeDate = DateTime.Now, //达标日期
|
|
|
+ UserId = puser.Id, //创客
|
|
|
+ BrandId = pos.BrandId, //品牌
|
|
|
+ RewardType = 2, //奖励类型
|
|
|
+ CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
|
|
|
+ DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
|
|
|
+ CreditRewardAmount = Prize, //贷记卡交易奖励金额
|
|
|
+ RewardDesc = "开机奖励", //奖励描述
|
|
|
+ TopUserId = pTopUserId, //顶级创客
|
|
|
+ });
|
|
|
+ string IdBrand = puser.Id + "_" + pos.BrandId;
|
|
|
+ UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
|
|
|
+ if (userData == null)
|
|
|
+ {
|
|
|
+ userData = db.UserMachineData.Add(new UserMachineData()
|
|
|
+ {
|
|
|
+ IdBrand = IdBrand,
|
|
|
+ }).Entity;
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+ userData.OpenProfit += Prize;
|
|
|
+ db.SaveChanges();
|
|
|
+ //账户入库
|
|
|
+ UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id);
|
|
|
+ if (account == null)
|
|
|
+ {
|
|
|
+ account = db.UserAccount.Add(new UserAccount()
|
|
|
+ {
|
|
|
+ Id = puser.Id,
|
|
|
+ UserId = puser.Id,
|
|
|
+ }).Entity;
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+ //收支明细入库
|
|
|
+ decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
|
|
|
+ decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
|
|
|
+ decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
|
|
|
+ account.BalanceAmount += Prize;
|
|
|
+ account.TotalAmount += Prize;
|
|
|
+ decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
|
|
|
+ decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
|
|
|
+ decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
|
|
|
+ UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
|
|
|
+ {
|
|
|
+ CreateDate = DateTime.Now,
|
|
|
+ UpdateDate = DateTime.Now,
|
|
|
+ UserId = puser.Id, //创客
|
|
|
+ ChangeType = 50, //变动类型
|
|
|
+ ProductType = pos.BrandId, //产品类型
|
|
|
+ ChangeAmount = Prize, //变更金额
|
|
|
+ BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
|
|
|
+ AfterTotalAmount = AfterTotalAmount, //变更后总金额
|
|
|
+ BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
|
|
|
+ AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
|
|
|
+ BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
|
|
|
+ AfterBalanceAmount = AfterBalanceAmount, //变更后余额
|
|
|
+ }).Entity;
|
|
|
+ db.SaveChanges();
|
|
|
+
|
|
|
+ string dateString = DateTime.Now.ToString("yyyyMMdd");
|
|
|
+ string monthString = DateTime.Now.ToString("yyyyMM");
|
|
|
+ // 开机奖励列表
|
|
|
+ List<string> dates = RedisDbconn.Instance.GetList<string>("OpenRewardDay:" + puser.Id + ":" + pos.BrandId);
|
|
|
+ if (!dates.Contains(dateString))
|
|
|
+ {
|
|
|
+ RedisDbconn.Instance.AddList("OpenRewardDay:" + puser.Id + ":" + pos.BrandId, dateString);
|
|
|
+ }
|
|
|
+ RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + dateString, Prize);
|
|
|
+
|
|
|
+ List<string> months = RedisDbconn.Instance.GetList<string>("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId);
|
|
|
+ if (!months.Contains(monthString))
|
|
|
+ {
|
|
|
+ RedisDbconn.Instance.AddList("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId, monthString);
|
|
|
+ }
|
|
|
+ RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + monthString, Prize);
|
|
|
+
|
|
|
+ // 开机奖励详情
|
|
|
+ RedisDbconn.Instance.AddList("OpenRewardDetail:" + puser.Id + ":" + pos.BrandId + ":" + dateString, detail);
|
|
|
+
|
|
|
+ Prize = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ db.Dispose();
|
|
|
+ }
|
|
|
+ catch(Exception ex)
|
|
|
+ {
|
|
|
+ function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "实时获取开机奖励异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void dosomething42(string date)
|
|
|
{
|
|
|
WebCMSEntities db = new WebCMSEntities();
|