|
@@ -24,7 +24,8 @@ namespace MySystem
|
|
|
if (string.IsNullOrEmpty(flag))
|
|
|
{
|
|
|
function.WritePage("/Stat/", doDate + ".txt", DateTime.Now.ToString("HH:mm:ss"));
|
|
|
- dosomething(doDate);
|
|
|
+ dosomething1(doDate);
|
|
|
+ dosomething2(doDate);
|
|
|
}
|
|
|
string Msg = "success";
|
|
|
jobInfo.Status = Msg == "success" ? 1 : 0;
|
|
@@ -56,17 +57,62 @@ namespace MySystem
|
|
|
RedisDbconn.Instance.Clear("TeamTotalCloudPayAmount*");
|
|
|
RedisDbconn.Instance.Clear("TeamTotalPosAmount*");
|
|
|
|
|
|
- RedisDbconn.Instance.Clear("TotalUser*");
|
|
|
- RedisDbconn.Instance.Clear("TeamTotalUser*");
|
|
|
- RedisDbconn.Instance.Clear("AddUser*");
|
|
|
- RedisDbconn.Instance.Clear("TeamAddUser*");
|
|
|
+ // RedisDbconn.Instance.Clear("TotalUser*");
|
|
|
+ // RedisDbconn.Instance.Clear("TeamTotalUser*");
|
|
|
+ // RedisDbconn.Instance.Clear("AddUser*");
|
|
|
+ // RedisDbconn.Instance.Clear("TeamAddUser*");
|
|
|
|
|
|
- RedisDbconn.Instance.Clear("TotalPosMerchant*");
|
|
|
- RedisDbconn.Instance.Clear("TeamTotalPosMerchant*");
|
|
|
+ // RedisDbconn.Instance.Clear("TotalPosMerchant*");
|
|
|
+ // RedisDbconn.Instance.Clear("TeamTotalPosMerchant*");
|
|
|
|
|
|
RedisDbconn.Instance.Clear("MerTotalAmount*");
|
|
|
}
|
|
|
- public void dosomething(string date)
|
|
|
+
|
|
|
+
|
|
|
+ // 1. 前一天的绑定记录和创客信息匹配,设置商户型创客
|
|
|
+ public void dosomething1(string date)
|
|
|
+ {
|
|
|
+ // TODO: 每天扫描非商户型创客的持有机具数量
|
|
|
+ SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
|
|
|
+ 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<SpModels.BindRecord> binds = spdb.BindRecord.Where(m => m.CreateTime >= yesterday && m.CreateTime < today).ToList();
|
|
|
+ foreach (SpModels.BindRecord bind in binds)
|
|
|
+ {
|
|
|
+ string Mobile = bind.MerNewSnNo;
|
|
|
+ string MerNo = bind.MerNo;
|
|
|
+ string BeforeNum = "";
|
|
|
+ string AfterNum = "";
|
|
|
+ if (Mobile.Contains("****") && Mobile.Length == 11)
|
|
|
+ {
|
|
|
+ BeforeNum = Mobile.Substring(0, 3);
|
|
|
+ AfterNum = Mobile.Substring(7);
|
|
|
+ }
|
|
|
+ string Name = bind.MerName;
|
|
|
+ PxcModels.Users user = db.Users.FirstOrDefault(m => m.Mobile.StartsWith(BeforeNum) && m.Mobile.EndsWith(AfterNum) && m.RealName == Name && m.AuthFlag == 1 && m.MerchantType == 0);
|
|
|
+ if (user != null)
|
|
|
+ {
|
|
|
+ user.MerchantType = 1;
|
|
|
+ PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PxcModels.PosMerchantInfo();
|
|
|
+ merchant.MerUserType = 1;
|
|
|
+ PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.BindMerchantId == merchant.Id);
|
|
|
+ if (pos != null)
|
|
|
+ {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ spdb.Dispose();
|
|
|
+ db.Dispose();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 每天统计前一天的交易额,每笔交易判断商户号的所属人是商户型创客,如果是,则从此人开始累计交易额,若不是,则从此人上级开始累计交易额
|
|
|
+ public void dosomething2(string date)
|
|
|
{
|
|
|
WebCMSEntities db = new WebCMSEntities();
|
|
|
string yesterday = date + " 00:00:00";
|
|
@@ -81,6 +127,14 @@ namespace MySystem
|
|
|
int MerchantId = int.Parse(dr["MerchantId"].ToString()); //商户Id
|
|
|
int QrPayFlag = int.Parse(dr["QrPayFlag"].ToString()); //云闪付
|
|
|
decimal TradeAmount = decimal.Parse(dr[4].ToString()); //当日交易额
|
|
|
+ PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == MerchantId) ?? new PosMerchantInfo();
|
|
|
+ MachineForMerNo machineFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == merchant.KqMerNo) ?? new MachineForMerNo();
|
|
|
+ PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
|
|
|
+ int MerchantTypeUserId = int.Parse(function.CheckInt(pos.SeoTitle));
|
|
|
+ if (MerchantTypeUserId > 0)
|
|
|
+ {
|
|
|
+ UserId = MerchantTypeUserId;
|
|
|
+ }
|
|
|
RedisDbconn.Instance.AddNumber("MerTotalAmount:" + MerchantId, TradeAmount);
|
|
|
RedisDbconn.Instance.AddNumber("MerTotalAmount:" + MerchantId + ":" + TradeMonth, TradeAmount); //商户当月交易
|
|
|
RedisDbconn.Instance.AddNumber("MerTotalAmount:" + MerchantId + ":" + TradeDate, TradeAmount); //商户当日交易
|
|
@@ -129,6 +183,224 @@ namespace MySystem
|
|
|
}
|
|
|
UserId = user.ParentUserId;
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UserId = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ db.Dispose();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 前一天的激活记录,根据创客类型,如果是商户型创客,则激活奖励的起始人从此人上级计算。如果不是,则从此人开始计算
|
|
|
+ public void dosomething3(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");
|
|
|
+ List<PosMachinesTwo> posList = db.PosMachinesTwo.Where(m => m.ActivationTime >= yesterday && m.ActivationTime < today).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)
|
|
|
+ {
|
|
|
+ ParentNav = user.ParentNav;
|
|
|
+ if (user.MerchantType == 1)
|
|
|
+ {
|
|
|
+ Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId);
|
|
|
+ if (puser != null)
|
|
|
+ {
|
|
|
+ GetUserId = puser.Id;
|
|
|
+ ParentNav = puser.ParentNav;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ 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()
|
|
|
+ {
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ userData = db.UserMachineData.Add(new UserMachineData()
|
|
|
+ {
|
|
|
+ IdBrand = IdBrand,
|
|
|
+ }).Entity;
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+ userData.ActProfit += ActPrize;
|
|
|
+ db.SaveChanges();
|
|
|
+ RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, userData);
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 激活奖励详情
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ db.Dispose();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //3. 前一天的激活记录,根据创客类型,如果是商户型创客,则开机奖励的起始人从此人上级计算。如果不是,则从此人开始计算
|
|
|
+ public void dosomething4(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");
|
|
|
+ List<PosMachinesTwo> posList = db.PosMachinesTwo.Where(m => m.CreditTrade >= 1000).ToList();
|
|
|
+ foreach (PosMachinesTwo pos in posList)
|
|
|
+ {
|
|
|
+ if (pos.ActivationTime > DateTime.Now.AddDays(-20))
|
|
|
+ {
|
|
|
+ decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoTitle));
|
|
|
+ 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))
|
|
|
+ {
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ userData = db.UserMachineData.Add(new UserMachineData()
|
|
|
+ {
|
|
|
+ IdBrand = IdBrand,
|
|
|
+ }).Entity;
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+ userData.OpenProfit += Prize;
|
|
|
+ db.SaveChanges();
|
|
|
+ RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, userData);
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 开机奖励详情
|
|
|
+ RedisDbconn.Instance.AddList("OpenRewardDetail:" + puser.Id + ":" + pos.BrandId + ":" + dateString, detail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
db.Dispose();
|