|
@@ -1093,5 +1093,139 @@ namespace MySystem.Controllers
|
|
|
}
|
|
|
return "ok";
|
|
|
}
|
|
|
+
|
|
|
+ public string checkLeaderOrder(int OrderId)
|
|
|
+ {
|
|
|
+ WebCMSEntities db = new WebCMSEntities();
|
|
|
+ Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId);
|
|
|
+ if (order != null)
|
|
|
+ {
|
|
|
+ OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == OrderId);
|
|
|
+ if (pro != null)
|
|
|
+ {
|
|
|
+ //推荐下单奖励
|
|
|
+ if (pro.ProductId == 10 || pro.ProductId == 11)
|
|
|
+ {
|
|
|
+ bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
|
|
|
+ function.WriteLog("OrderId:" + OrderId, "推荐下单奖励监控日志");
|
|
|
+ function.WriteLog("checkPrize:" + checkPrize, "推荐下单奖励监控日志");
|
|
|
+ if (!checkPrize)
|
|
|
+ {
|
|
|
+ Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
|
|
|
+ if (user != null)
|
|
|
+ {
|
|
|
+ bool directPrize = false; //直推奖标记
|
|
|
+ bool buyPrize = false; //返100购机奖励标记
|
|
|
+ int leaderFlag = 0; //返600备用金标记
|
|
|
+ if(user.LeaderLevel > 0)
|
|
|
+ {
|
|
|
+ UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId) ?? new UserAccount();
|
|
|
+ if(acccount.LeaderReserve >= order.TotalPrice)
|
|
|
+ {
|
|
|
+ if(order.PayMode == 4)
|
|
|
+ {
|
|
|
+ //扣减备用金
|
|
|
+ AlipayPayBack2Service.Instance.OpReserve(db, order, order.UserId, order.TotalPrice, 2, 0, "商城购机");
|
|
|
+ //返回到余额
|
|
|
+ // OpAccount(db, order, order.UserId, order.TotalPrice / pro.ProductCount, pro.ProductCount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //获得100元奖励
|
|
|
+ AlipayPayBack2Service.Instance.OpAccount(db, order, order.UserId, 100, pro.ProductCount);
|
|
|
+ //推荐奖励
|
|
|
+ AlipayPayBack2Service.Instance.DirectPrize(db, order.Id, order.UserId, pro.ProductCount);
|
|
|
+ //推荐下单上级获得30天的机具循环天数
|
|
|
+ var posList = db.PosMachinesTwo.Select(m => new { m.Id, m.UserId, m.BindingState, m.RecycEndDate }).Where(m => m.UserId == order.UserId && m.BindingState == 0 && m.RecycEndDate != null).ToList();
|
|
|
+ foreach (var subPos in posList)
|
|
|
+ {
|
|
|
+ PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
|
|
|
+ if (pos != null)
|
|
|
+ {
|
|
|
+ pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ db.SaveChanges();
|
|
|
+ if(user.LeaderLevel != 2)
|
|
|
+ {
|
|
|
+ int PUserId = user.ParentUserId;
|
|
|
+ while(PUserId > 0)
|
|
|
+ {
|
|
|
+ Users puser = db.Users.FirstOrDefault(m => m.Id == PUserId) ?? new Users();
|
|
|
+ if(puser.LeaderLevel == 2)
|
|
|
+ {
|
|
|
+ UserAccount acc = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
|
|
|
+ if(acc.LeaderReserve >= order.TotalPrice)
|
|
|
+ {
|
|
|
+ //扣减备用金
|
|
|
+ AlipayPayBack2Service.Instance.OpReserve(db, order, puser.Id, order.TotalPrice, 2, order.UserId, "购机奖励");
|
|
|
+ //返回到余额
|
|
|
+ AlipayPayBack2Service.Instance.OpAccount(db, order, puser.Id, order.TotalPrice / pro.ProductCount, pro.ProductCount);
|
|
|
+ }
|
|
|
+ PUserId = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PUserId = puser.ParentUserId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "自己就是盟主,发放成功";
|
|
|
+ }
|
|
|
+ int ParentUserId = user.ParentUserId;
|
|
|
+ // List<int> proids = new List<int>();
|
|
|
+ // proids.Add(10);
|
|
|
+ // proids.Add(11);
|
|
|
+ while(ParentUserId > 0)
|
|
|
+ {
|
|
|
+ Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
|
|
|
+ int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
|
|
|
+ int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
|
|
|
+ int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
|
|
|
+ if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
|
|
|
+ {
|
|
|
+ // 盟主直推奖励,可以每次下单获得
|
|
|
+ AlipayPayBack2Service.Instance.DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
|
|
|
+ directPrize = true;
|
|
|
+
|
|
|
+ //推荐下单上级获得30天的机具循环天数
|
|
|
+ var posList = db.PosMachinesTwo.Select(m => new { m.Id, m.UserId, m.BindingState, m.RecycEndDate }).Where(m => m.UserId == ParentUserId && m.BindingState == 0 && m.RecycEndDate != null).ToList();
|
|
|
+ foreach (var subPos in posList)
|
|
|
+ {
|
|
|
+ PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
|
|
|
+ if (pos != null)
|
|
|
+ {
|
|
|
+ pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+ if(puser.LeaderLevel > 0)
|
|
|
+ {
|
|
|
+ UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
|
|
|
+ if(acccount.LeaderReserve >= order.TotalPrice && !buyPrize)
|
|
|
+ {
|
|
|
+ //购机奖励
|
|
|
+ AlipayPayBack2Service.Instance.OpAccount(db, order, puser.Id, 100, pro.ProductCount);
|
|
|
+ buyPrize = true;
|
|
|
+ }
|
|
|
+ if(acccount.LeaderReserve >= order.TotalPrice && puser.LeaderLevel > leaderFlag)
|
|
|
+ {
|
|
|
+ //扣减备用金
|
|
|
+ AlipayPayBack2Service.Instance.OpReserve(db, order, puser.Id, order.TotalPrice, 2, order.UserId, "购机奖励");
|
|
|
+ //返回到余额
|
|
|
+ AlipayPayBack2Service.Instance.OpAccount(db, order, puser.Id, order.TotalPrice / pro.ProductCount, pro.ProductCount);
|
|
|
+ leaderFlag = puser.LeaderLevel;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ParentUserId = puser.ParentUserId;
|
|
|
+ }
|
|
|
+ return "找到上级盟主,发放成功";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "失败";
|
|
|
+ }
|
|
|
}
|
|
|
}
|