|
@@ -25,6 +25,7 @@ namespace MySystem
|
|
|
{
|
|
|
function.WritePage("/Stat/", doDate + ".txt", DateTime.Now.ToString("HH:mm:ss"));
|
|
|
dosomething1(doDate);
|
|
|
+ dosomething11(doDate);
|
|
|
dosomething2(doDate);
|
|
|
}
|
|
|
string Msg = "success";
|
|
@@ -48,6 +49,43 @@ namespace MySystem
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void ActiveReward(JobMqMsg jobInfo)
|
|
|
+ {
|
|
|
+ string content = "";
|
|
|
+ try
|
|
|
+ {
|
|
|
+ dosomething3();
|
|
|
+ string Msg = "success";
|
|
|
+ jobInfo.Status = Msg == "success" ? 1 : 0;
|
|
|
+ jobInfo.Msg = Msg == "success" ? "执行完成" : Msg;
|
|
|
+ RabbitMQClient.Instance.SendMsg(Newtonsoft.Json.JsonConvert.SerializeObject(jobInfo), "PublicBack");
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(content))
|
|
|
+ {
|
|
|
+ Dictionary<string, string> data = new Dictionary<string, string>();
|
|
|
+ data.Add("ErrTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ data.Add("ErrMsg", ex.ToString());
|
|
|
+ function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(data), "public_err");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "public_service");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public void clear()
|
|
|
{
|
|
|
RedisDbconn.Instance.Clear("TotalAmount*");
|
|
@@ -102,15 +140,39 @@ namespace MySystem
|
|
|
pos.SeoTitle = user.Id.ToString(); // 记录商户型创客的Id
|
|
|
}
|
|
|
db.SaveChanges();
|
|
|
- BothdisDbconn.Instance.SendMq("Pop:Users", user);
|
|
|
- BothdisDbconn.Instance.SendMq("Pop:PosMerchantInfo", merchant);
|
|
|
- BothdisDbconn.Instance.SendMq("Pop:PosMachinesTwo", pos);
|
|
|
+ RedisDbconn.Instance.Set("Users:" + user.Id, user);
|
|
|
+ RedisDbconn.Instance.Set("PosMerchantInfo:" + merchant.Id, merchant);
|
|
|
+ RedisDbconn.Instance.Set("PosMachinesTwo:" + pos.Id, pos);
|
|
|
}
|
|
|
}
|
|
|
spdb.Dispose();
|
|
|
db.Dispose();
|
|
|
}
|
|
|
|
|
|
+ // 1. 前一天的商户型创客,判断名下是否3台激活机器,是则变为非商户型创客
|
|
|
+ public void dosomething11(string date)
|
|
|
+ {
|
|
|
+ WebCMSEntities db = new WebCMSEntities();
|
|
|
+ DateTime yesterday = DateTime.Parse(date + " 00:00:00");
|
|
|
+ DateTime today = DateTime.Parse(DateTime.Parse(date).AddDays(1).ToString("yyyy-MM-dd") + " 00:00:00");
|
|
|
+ var users = db.Users.Select(m => new { m.Id, m.MerchantType }).Where(m => m.MerchantType == 1).ToList();
|
|
|
+ foreach (var user in users)
|
|
|
+ {
|
|
|
+ int machineCount = db.PosMachinesTwo.Count(m => m.UserId == user.Id && m.ActivationState == 1);
|
|
|
+ if (machineCount >= 3)
|
|
|
+ {
|
|
|
+ Users edit = db.Users.FirstOrDefault(m => m.Id == user.Id);
|
|
|
+ if (edit != null)
|
|
|
+ {
|
|
|
+ edit.MerchantType = 0;
|
|
|
+ db.SaveChanges();
|
|
|
+ RedisDbconn.Instance.Set("Users:" + user.Id, user);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ db.Dispose();
|
|
|
+ }
|
|
|
+
|
|
|
// 2. 每天统计前一天的交易额,每笔交易判断商户号的所属人是商户型创客,如果是,则从此人开始累计交易额,若不是,则从此人上级开始累计交易额
|
|
|
public void dosomething2(string date)
|
|
|
{
|
|
@@ -193,98 +255,155 @@ namespace MySystem
|
|
|
}
|
|
|
|
|
|
// 3. 前一天的激活记录,根据创客类型,如果是商户型创客,则激活奖励的起始人从此人上级计算。如果不是,则从此人开始计算
|
|
|
- public void dosomething3(string date)
|
|
|
+ public void dosomething3()
|
|
|
{
|
|
|
WebCMSEntities db = new WebCMSEntities();
|
|
|
- DateTime yesterday = DateTime.Parse(date + " 00:00:00");
|
|
|
- DateTime today = DateTime.Parse(DateTime.Parse(date).AddDays(1).ToString("yyyy-MM-dd") + " 00:00:00");
|
|
|
- List<PosMachinesTwo> posList = db.PosMachinesTwo.Where(m => m.ActivationTime >= yesterday && m.ActivationTime < today).ToList();
|
|
|
+ DateTime yesterday = DateTime.Now.AddHours(-1);
|
|
|
+ DateTime today = DateTime.Now;
|
|
|
+ List<PosMachinesTwo> posList = db.PosMachinesTwo.Where(m => m.ActivationState == 1 && m.ActivationTime >= yesterday && m.ActivationTime < today && !string.IsNullOrEmpty(m.SeoKeyword)).ToList();
|
|
|
foreach (PosMachinesTwo pos in posList)
|
|
|
{
|
|
|
- int GetUserId = pos.UserId;
|
|
|
- string ParentNav = "";
|
|
|
- Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId);
|
|
|
- if (user != null)
|
|
|
+ PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
|
|
|
+ if (merchant != null)
|
|
|
{
|
|
|
- ParentNav = user.ParentNav;
|
|
|
- if (user.MerchantType == 1)
|
|
|
- {
|
|
|
- Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId);
|
|
|
- if (puser != null)
|
|
|
+ Users user = db.Users.FirstOrDefault(m => m.Id == merchant.UserId);
|
|
|
+ if (user != null)
|
|
|
+ {
|
|
|
+ if (user.MerchantType == 1)
|
|
|
{
|
|
|
- GetUserId = puser.Id;
|
|
|
- ParentNav = puser.ParentNav;
|
|
|
+ user = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId);
|
|
|
}
|
|
|
}
|
|
|
- int TopUserId = 0;
|
|
|
- if (!string.IsNullOrEmpty(ParentNav))
|
|
|
- {
|
|
|
- TopUserId = int.Parse(ParentNav.Trim(',').Replace(",,", ","));
|
|
|
- }
|
|
|
- decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoTitle)) / 100;
|
|
|
- if (ActPrize > 0)
|
|
|
+ string ParentNav = "";
|
|
|
+ if (user != null)
|
|
|
{
|
|
|
- PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
|
|
|
- Users merUser = db.Users.FirstOrDefault(m => m.Id == merchant.UserId) ?? new Users();
|
|
|
- db.ActiveReward.Add(new ActiveReward()
|
|
|
+ int GetUserId = user.Id;
|
|
|
+ ParentNav = user.ParentNav;
|
|
|
+ int TopUserId = 0;
|
|
|
+ if (!string.IsNullOrEmpty(ParentNav))
|
|
|
{
|
|
|
- CreateDate = DateTime.Now,
|
|
|
- UpdateDate = DateTime.Now,
|
|
|
- UserId = GetUserId, //创客
|
|
|
- MerchantId = pos.BindMerchantId, //商户
|
|
|
- StandardDate = pos.ActivationTime, //达标日期
|
|
|
- RewardAmount = ActPrize, //奖励金额
|
|
|
- BrandId = pos.BrandId, //品牌
|
|
|
- UserNav = ParentNav, //创客父级
|
|
|
- DirectBuddyNo = merchant.UserId, //商户直属创客
|
|
|
- KqMerNo = merchant.KqMerNo, //渠道商户编号
|
|
|
- KqSnNo = pos.PosSn, //渠道SN号
|
|
|
- SnType = pos.PosSnType, //机具类型
|
|
|
- SnApplyUserId = pos.BuyUserId, //机具申请创客
|
|
|
- ActType = 0, //激活类型
|
|
|
- SnStoreId = pos.StoreId, //SN仓库
|
|
|
- RewardTips = "激活奖励", //奖励描述
|
|
|
- Remark = "激活奖励", //备注
|
|
|
- ActDate = pos.ActivationTime, //激活时间
|
|
|
- TopUserId = TopUserId, //顶级创客
|
|
|
- });
|
|
|
- db.SaveChanges();
|
|
|
- string IdBrand = GetUserId + "_" + pos.BrandId;
|
|
|
- UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
|
|
|
- if (userData == null)
|
|
|
+ TopUserId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
|
|
|
+ }
|
|
|
+ decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword)) / 100;
|
|
|
+ if (ActPrize > 0)
|
|
|
{
|
|
|
- userData = db.UserMachineData.Add(new UserMachineData()
|
|
|
+ bool check = db.ActiveReward.Any(m => m.KqSnNo == pos.PosSn);
|
|
|
+ if (!check)
|
|
|
{
|
|
|
- IdBrand = IdBrand,
|
|
|
- }).Entity;
|
|
|
- db.SaveChanges();
|
|
|
- }
|
|
|
- userData.ActProfit += ActPrize;
|
|
|
- db.SaveChanges();
|
|
|
- RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, userData);
|
|
|
+ if (ActPrize == 99)
|
|
|
+ {
|
|
|
+ ActPrize = 100;
|
|
|
+ }
|
|
|
+ else if (ActPrize == 199)
|
|
|
+ {
|
|
|
+ ActPrize = 200;
|
|
|
+ }
|
|
|
+ else if (ActPrize == 299)
|
|
|
+ {
|
|
|
+ ActPrize = 300;
|
|
|
+ }
|
|
|
+ Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
|
|
|
+ db.ActiveReward.Add(new ActiveReward()
|
|
|
+ {
|
|
|
+ CreateDate = DateTime.Now,
|
|
|
+ UpdateDate = DateTime.Now,
|
|
|
+ UserId = GetUserId, //创客
|
|
|
+ MerchantId = pos.BindMerchantId, //商户
|
|
|
+ StandardDate = pos.ActivationTime, //达标日期
|
|
|
+ RewardAmount = ActPrize, //奖励金额
|
|
|
+ BrandId = pos.BrandId, //品牌
|
|
|
+ UserNav = ParentNav, //创客父级
|
|
|
+ DirectBuddyNo = merchant.UserId, //商户直属创客
|
|
|
+ KqMerNo = merchant.KqMerNo, //渠道商户编号
|
|
|
+ KqSnNo = pos.PosSn, //渠道SN号
|
|
|
+ SnType = pos.PosSnType, //机具类型
|
|
|
+ SnApplyUserId = pos.BuyUserId, //机具申请创客
|
|
|
+ ActType = 0, //激活类型
|
|
|
+ SnStoreId = pos.StoreId, //SN仓库
|
|
|
+ RewardTips = "激活奖励", //奖励描述
|
|
|
+ Remark = "激活奖励", //备注
|
|
|
+ ActDate = pos.ActivationTime, //激活时间
|
|
|
+ TopUserId = TopUserId, //顶级创客
|
|
|
+ SeoTitle = machineUser.RealName,
|
|
|
+ });
|
|
|
+ db.SaveChanges();
|
|
|
+ string IdBrand = GetUserId + "_" + 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.ActProfit += ActPrize;
|
|
|
+ db.SaveChanges();
|
|
|
+ RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, userData);
|
|
|
+ UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
|
|
|
+ if (account == null)
|
|
|
+ {
|
|
|
+ account = db.UserAccount.Add(new UserAccount()
|
|
|
+ {
|
|
|
+ Id = GetUserId,
|
|
|
+ UserId = GetUserId,
|
|
|
+ }).Entity;
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+ decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
|
|
|
+ decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
|
|
|
+ decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
|
|
|
+ account.BalanceAmount += ActPrize;
|
|
|
+ account.TotalAmount += ActPrize;
|
|
|
+ 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 = GetUserId, //创客
|
|
|
+ ChangeType = 0, //变动类型
|
|
|
+ ProductType = pos.BrandId, //产品类型
|
|
|
+ ChangeAmount = ActPrize, //变更金额
|
|
|
+ BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
|
|
|
+ AfterTotalAmount = AfterTotalAmount, //变更后总金额
|
|
|
+ BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
|
|
|
+ AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
|
|
|
+ BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
|
|
|
+ AfterBalanceAmount = AfterBalanceAmount, //变更后余额
|
|
|
+ }).Entity;
|
|
|
+ db.SaveChanges();
|
|
|
+ RedisDbconn.Instance.Set("UserAccount:" + GetUserId, account);
|
|
|
|
|
|
- string dateString = DateTime.Now.ToString("yyyyMMdd");
|
|
|
- string monthString = DateTime.Now.ToString("yyyyMMdd");
|
|
|
- // 激活奖励列表
|
|
|
- List<string> dates = RedisDbconn.Instance.GetList<string>("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId);
|
|
|
- if (!dates.Contains(dateString))
|
|
|
- {
|
|
|
- RedisDbconn.Instance.AddList("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId, dateString);
|
|
|
- RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + dateString, ActPrize);
|
|
|
- }
|
|
|
- List<string> months = RedisDbconn.Instance.GetList<string>("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId);
|
|
|
- if (!months.Contains(monthString))
|
|
|
- {
|
|
|
- RedisDbconn.Instance.AddList("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId, monthString);
|
|
|
- RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + monthString, ActPrize);
|
|
|
- }
|
|
|
+ string dateString = yesterday.ToString("yyyyMMdd");
|
|
|
+ string monthString = yesterday.ToString("yyyyMM");
|
|
|
+ // 激活奖励列表
|
|
|
+ List<string> dates = RedisDbconn.Instance.GetList<string>("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId);
|
|
|
+ if (!dates.Contains(dateString))
|
|
|
+ {
|
|
|
+ RedisDbconn.Instance.AddList("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId, dateString);
|
|
|
+ RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + dateString, ActPrize);
|
|
|
+ }
|
|
|
+ List<string> months = RedisDbconn.Instance.GetList<string>("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId);
|
|
|
+ if (!months.Contains(monthString))
|
|
|
+ {
|
|
|
+ RedisDbconn.Instance.AddList("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId, monthString);
|
|
|
+ RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + monthString, ActPrize);
|
|
|
+ }
|
|
|
|
|
|
- // 激活奖励详情
|
|
|
- List<int> actPrizeList = RedisDbconn.Instance.GetList<int>("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString);
|
|
|
- if (!actPrizeList.Contains(pos.BindMerchantId))
|
|
|
- {
|
|
|
- RedisDbconn.Instance.AddList("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString, pos.BindMerchantId);
|
|
|
- RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + pos.BindMerchantId + ":" + pos.BrandId + ":" + dateString, ActPrize);
|
|
|
+ // 激活奖励详情
|
|
|
+ List<int> actPrizeList = RedisDbconn.Instance.GetList<int>("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString);
|
|
|
+ if (!actPrizeList.Contains(pos.BindMerchantId))
|
|
|
+ {
|
|
|
+ RedisDbconn.Instance.AddList("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString, pos.BindMerchantId);
|
|
|
+ RedisDbconn.Instance.AddNumber("ActiveRewardAmt:mer:" + pos.BindMerchantId + ":" + pos.BrandId + ":" + dateString, ActPrize);
|
|
|
+ }
|
|
|
+
|
|
|
+ //收支明细
|
|
|
+ RedisDbconn.Instance.AddList("UserAccountRecord:" + GetUserId + ":1:" + monthString, userAccountRecord);
|
|
|
+ RedisDbconn.Instance.AddNumber("UserAccount:" + GetUserId + ":1:" + monthString, ActPrize);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -304,99 +423,160 @@ namespace MySystem
|
|
|
{
|
|
|
if (pos.ActivationTime > DateTime.Now.AddDays(-20))
|
|
|
{
|
|
|
- decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoTitle));
|
|
|
+ decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
|
|
|
if (ActPrize > 0)
|
|
|
{
|
|
|
- Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
|
|
|
- PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
|
|
|
- if (!string.IsNullOrEmpty(user.ParentNav))
|
|
|
+ PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
|
|
|
+ if (merchant != null)
|
|
|
{
|
|
|
- decimal Prize = 20;
|
|
|
- string[] ParentNavs = user.ParentNav.Trim(',').Replace(",,", ",").Split(',');
|
|
|
- for (int i = ParentNavs.Length - 1; i >= 0; i--)
|
|
|
+ Users user = db.Users.FirstOrDefault(m => m.Id == merchant.UserId);
|
|
|
+ if (user != null)
|
|
|
{
|
|
|
- int UserId = int.Parse(ParentNavs[i]);
|
|
|
- Users puser = db.Users.FirstOrDefault(m => m.Id == UserId && m.AuthFlag == 1);
|
|
|
- if (puser != null)
|
|
|
+ if (user.MerchantType == 1)
|
|
|
{
|
|
|
- int pTopUserId = 0;
|
|
|
- if (!string.IsNullOrEmpty(puser.ParentNav))
|
|
|
- {
|
|
|
- pTopUserId = int.Parse(puser.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
|
|
|
- }
|
|
|
- OpenRewardDetail detail = db.OpenRewardDetail.Add(new OpenRewardDetail()
|
|
|
- {
|
|
|
- CreateDate = DateTime.Now,
|
|
|
- UpdateDate = DateTime.Now,
|
|
|
- TradeMonth = yesterday.ToString("yyyyMM"), //交易月
|
|
|
- TradeDate = yesterday, //达标日期
|
|
|
- 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, //顶级创客
|
|
|
- }).Entity;
|
|
|
- db.OpenReward.Add(new OpenReward()
|
|
|
- {
|
|
|
- CreateDate = DateTime.Now,
|
|
|
- UpdateDate = DateTime.Now,
|
|
|
- TradeMonth = yesterday.ToString("yyyyMM"), //交易月
|
|
|
- TradeDate = DateTime.Now, //达标日期
|
|
|
- UserId = puser.Id, //创客
|
|
|
- BrandId = pos.BrandId, //品牌
|
|
|
- RewardType = 2, //奖励类型
|
|
|
- CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
|
|
|
- DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
|
|
|
- CreditRewardAmount = Prize, //贷记卡交易奖励金额
|
|
|
- RewardDesc = "开机奖励", //奖励描述
|
|
|
- TopUserId = pTopUserId, //顶级创客
|
|
|
- });
|
|
|
- Prize -= 10;
|
|
|
- string IdBrand = puser.Id + "_" + pos.BrandId;
|
|
|
- UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
|
|
|
- if (userData == null)
|
|
|
+ user = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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--)
|
|
|
{
|
|
|
- userData = db.UserMachineData.Add(new UserMachineData()
|
|
|
+ int UserId = int.Parse(ParentNavs[i]);
|
|
|
+ Users puser = db.Users.FirstOrDefault(m => m.Id == UserId && m.AuthFlag == 1);
|
|
|
+ if (puser != null && Prize > 0)
|
|
|
{
|
|
|
- IdBrand = IdBrand,
|
|
|
- }).Entity;
|
|
|
- db.SaveChanges();
|
|
|
- }
|
|
|
- userData.OpenProfit += Prize;
|
|
|
- db.SaveChanges();
|
|
|
- RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, userData);
|
|
|
+ int machineCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.PosSnType == 0 && m.ActivationState == 1); //判断是否拥有3台激活机
|
|
|
+ if (machineCount >= 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.UserId) ?? new Users();
|
|
|
+ OpenRewardDetail detail = db.OpenRewardDetail.Add(new OpenRewardDetail()
|
|
|
+ {
|
|
|
+ CreateDate = DateTime.Now,
|
|
|
+ UpdateDate = DateTime.Now,
|
|
|
+ TradeMonth = yesterday.ToString("yyyyMM"), //交易月
|
|
|
+ TradeDate = yesterday, //达标日期
|
|
|
+ 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 = yesterday.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();
|
|
|
+ RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, userData);
|
|
|
+ //账户入库
|
|
|
+ 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();
|
|
|
+ RedisDbconn.Instance.Set("UserAccount:" + puser.Id, account);
|
|
|
|
|
|
- string dateString = DateTime.Now.ToString("yyyyMMdd");
|
|
|
- string monthString = DateTime.Now.ToString("yyyyMMdd");
|
|
|
- // 开机奖励列表
|
|
|
- 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);
|
|
|
- }
|
|
|
+ string dateString = yesterday.ToString("yyyyMMdd");
|
|
|
+ string monthString = yesterday.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);
|
|
|
+ // 开机奖励详情
|
|
|
+ RedisDbconn.Instance.AddList("OpenRewardDetail:" + puser.Id + ":" + pos.BrandId + ":" + dateString, detail);
|
|
|
+
|
|
|
+ //收支明细
|
|
|
+ RedisDbconn.Instance.AddList("UserAccountRecord:" + puser.Id + ":1:" + monthString, userAccountRecord);
|
|
|
+ RedisDbconn.Instance.AddNumber("UserAccount:" + puser.Id + ":1:" + monthString, ActPrize);
|
|
|
+
|
|
|
+ Prize -= 10;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|