|
@@ -72,12 +72,269 @@ namespace MySystem
|
|
foreach (string idString in ids)
|
|
foreach (string idString in ids)
|
|
{
|
|
{
|
|
int OrderId = int.Parse(idString);
|
|
int OrderId = int.Parse(idString);
|
|
- DoOrder(db, OrderId);
|
|
|
|
|
|
+ DoOrderV2(db, OrderId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
db.Dispose();
|
|
db.Dispose();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void DoOrderV2(WebCMSEntities db, int OrderId)
|
|
|
|
+ {
|
|
|
|
+ Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId && m.Status == 0);
|
|
|
|
+ if (order != null)
|
|
|
|
+ {
|
|
|
|
+ order.Status = 1;
|
|
|
|
+ order.PayDate = DateTime.Now;
|
|
|
|
+ order.PayStatus = 1;
|
|
|
|
+ db.SaveChanges();
|
|
|
|
+ RedisDbconn.Instance.Set("Orders:" + order.Id, order);
|
|
|
|
+
|
|
|
|
+ //机具券逻辑
|
|
|
|
+ OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == OrderId);
|
|
|
|
+ if (pro != null)
|
|
|
|
+ {
|
|
|
|
+ if (pro.ProductId == 10 || pro.ProductId == 11 || pro.ProductId == 12 || pro.ProductId == 13)
|
|
|
|
+ {
|
|
|
|
+ order.Status = 2;
|
|
|
|
+ int BuyCount = pro.ProductCount;
|
|
|
|
+ int Kind = 0;
|
|
|
|
+ if (pro.ProductId == 10)
|
|
|
|
+ {
|
|
|
|
+ Kind = 1;
|
|
|
|
+ }
|
|
|
|
+ else if (pro.ProductId == 11)
|
|
|
|
+ {
|
|
|
|
+ Kind = 2;
|
|
|
|
+ }
|
|
|
|
+ else if (pro.ProductId == 12)
|
|
|
|
+ {
|
|
|
|
+ if (pro.NormDetail == "电签POS")
|
|
|
|
+ {
|
|
|
|
+ Kind = 1;
|
|
|
|
+ }
|
|
|
|
+ else if (pro.NormDetail == "大POS")
|
|
|
|
+ {
|
|
|
|
+ Kind = 2;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ else if (pro.ProductId == 13)
|
|
|
|
+ {
|
|
|
|
+ if (pro.NormDetail == "300电签POS")
|
|
|
|
+ {
|
|
|
|
+ Kind = 1;
|
|
|
|
+ }
|
|
|
|
+ else if (pro.NormDetail == "200大POS")
|
|
|
|
+ {
|
|
|
|
+ Kind = 2;
|
|
|
|
+ }
|
|
|
|
+ else if (pro.NormDetail == "50大机券+225电签券")
|
|
|
|
+ {
|
|
|
|
+ Kind = 3;
|
|
|
|
+ }
|
|
|
|
+ else if (pro.NormDetail == "100大机券+150电签券")
|
|
|
|
+ {
|
|
|
|
+ Kind = 4;
|
|
|
|
+ }
|
|
|
|
+ else if (pro.NormDetail == "150大机券+75电签券")
|
|
|
|
+ {
|
|
|
|
+ Kind = 5;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ db.SaveChanges();
|
|
|
|
+ string Codes = "";
|
|
|
|
+ if(Kind > 2)
|
|
|
|
+ {
|
|
|
|
+ Dictionary<int, int> couponData = new Dictionary<int, int>();
|
|
|
|
+ if(Kind == 3)
|
|
|
|
+ {
|
|
|
|
+ couponData.Add(1, 225); //电签数量
|
|
|
|
+ couponData.Add(2, 50); //大机数量
|
|
|
|
+ }
|
|
|
|
+ else if(Kind == 4)
|
|
|
|
+ {
|
|
|
|
+ couponData.Add(1, 150); //电签数量
|
|
|
|
+ couponData.Add(2, 100); //大机数量
|
|
|
|
+ }
|
|
|
|
+ else if(Kind == 5)
|
|
|
|
+ {
|
|
|
|
+ couponData.Add(1, 75); //电签数量
|
|
|
|
+ couponData.Add(2, 150); //大机数量
|
|
|
|
+ }
|
|
|
|
+ foreach(int kindNum in couponData.Keys)
|
|
|
|
+ {
|
|
|
|
+ int BuyCountByKind = couponData[kindNum];
|
|
|
|
+ var coupons = db.PosCoupons.Where(m => m.IsLock == 0 && m.IsUse == 0 && m.UserId == 0 && m.QueryCount == kindNum).OrderBy(m => m.Id).Take(BuyCountByKind).ToList();
|
|
|
|
+ foreach (var coupon in coupons)
|
|
|
|
+ {
|
|
|
|
+ PosCoupons item = db.PosCoupons.FirstOrDefault(m => m.Id == coupon.Id);
|
|
|
|
+ if (item != null)
|
|
|
|
+ {
|
|
|
|
+ item.CreateDate = DateTime.Now;
|
|
|
|
+ item.UserId = order.UserId;
|
|
|
|
+ item.UpdateDate = DateTime.Now.AddDays(180);
|
|
|
|
+ if (pro.ProductId == 13)
|
|
|
|
+ {
|
|
|
|
+ item.LeaderUserId = order.UserId;
|
|
|
|
+ }
|
|
|
|
+ Codes += item.ExchangeCode + ",";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ var coupons = db.PosCoupons.Where(m => m.IsLock == 0 && m.IsUse == 0 && m.UserId == 0 && m.QueryCount == Kind).OrderBy(m => m.Id).Take(BuyCount).ToList();
|
|
|
|
+ foreach (var coupon in coupons)
|
|
|
|
+ {
|
|
|
|
+ PosCoupons item = db.PosCoupons.FirstOrDefault(m => m.Id == coupon.Id);
|
|
|
|
+ if (item != null)
|
|
|
|
+ {
|
|
|
|
+ item.CreateDate = DateTime.Now;
|
|
|
|
+ item.UserId = order.UserId;
|
|
|
|
+ item.UpdateDate = DateTime.Now.AddDays(180);
|
|
|
|
+ if (pro.ProductId == 13)
|
|
|
|
+ {
|
|
|
|
+ item.LeaderUserId = order.UserId;
|
|
|
|
+ }
|
|
|
|
+ Codes += item.ExchangeCode + ",";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ order.SnNos = Codes.TrimEnd(',');
|
|
|
|
+ string ChangeRecordNo = "SC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
|
|
|
|
+ PosCouponForUser forUser = db.PosCouponForUser.FirstOrDefault(m => m.Id == order.UserId);
|
|
|
|
+ if (forUser == null)
|
|
|
|
+ {
|
|
|
|
+ forUser = db.PosCouponForUser.Add(new PosCouponForUser()
|
|
|
|
+ {
|
|
|
|
+ Id = order.UserId,
|
|
|
|
+ }).Entity;
|
|
|
|
+ db.SaveChanges();
|
|
|
|
+ }
|
|
|
|
+ int BeforeOut = forUser.OutNum;
|
|
|
|
+ int BeforeTotal = forUser.TotalNum;
|
|
|
|
+ int BeforeStock = forUser.StockNum;
|
|
|
|
+ forUser.TotalNum += BuyCount;
|
|
|
|
+ forUser.StockNum += BuyCount;
|
|
|
|
+ int AfterOut = forUser.OutNum;
|
|
|
|
+ int AfterTotal = forUser.TotalNum;
|
|
|
|
+ int AfterStock = forUser.StockNum;
|
|
|
|
+ PosCouponOrders stat = db.PosCouponOrders.Add(new PosCouponOrders()
|
|
|
|
+ {
|
|
|
|
+ QueryCount = Kind,
|
|
|
|
+ CreateDate = DateTime.Now,
|
|
|
|
+ ChangeKind = 1,
|
|
|
|
+ ChangeCount = BuyCount,
|
|
|
|
+ AfterOut = AfterOut,
|
|
|
|
+ AfterTotal = AfterTotal,
|
|
|
|
+ AfterStock = AfterStock,
|
|
|
|
+ BeforeOut = BeforeOut,
|
|
|
|
+ BeforeTotal = BeforeTotal,
|
|
|
|
+ BeforeStock = BeforeStock,
|
|
|
|
+ OrderNo = ChangeRecordNo,
|
|
|
|
+ ToUserId = order.UserId,
|
|
|
|
+ FromUserId = 0,
|
|
|
|
+ }).Entity;
|
|
|
|
+ db.SaveChanges();
|
|
|
|
+ RedisDbconn.Instance.Clear("Orders:" + order.Id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //推荐下单奖励
|
|
|
|
+ if (pro.ProductId == 10 || pro.ProductId == 11)
|
|
|
|
+ {
|
|
|
|
+ bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId);
|
|
|
|
+ int SelfBuy = 0;
|
|
|
|
+ OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
|
|
|
|
+ DataTable stat = OtherMySqlConn.dtable("select count(Id) from Orders where Id in (select OrderId from OrderProduct where UserId=" + order.UserId + " and (ProductId=10 or ProductId=11)) and Status>0 and TotalPrice>0");
|
|
|
|
+ if (stat.Rows.Count > 0)
|
|
|
|
+ {
|
|
|
|
+ SelfBuy = int.Parse(function.CheckInt(stat.Rows[0][0].ToString()));
|
|
|
|
+ }
|
|
|
|
+ // OtherMySqlConn.connstr = ;
|
|
|
|
+ function.WriteLog("OrderId:" + OrderId, "推荐下单奖励监控日志");
|
|
|
|
+ function.WriteLog("checkPrize:" + checkPrize, "推荐下单奖励监控日志");
|
|
|
|
+ function.WriteLog("SelfBuy:" + SelfBuy, "推荐下单奖励监控日志");
|
|
|
|
+ if (SelfBuy == 1 && !checkPrize)
|
|
|
|
+ {
|
|
|
|
+ Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
|
|
|
|
+ if (user != null)
|
|
|
|
+ {
|
|
|
|
+ int ParentUserId = user.ParentUserId;
|
|
|
|
+ while(ParentUserId > 0)
|
|
|
|
+ {
|
|
|
|
+ int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 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张券
|
|
|
|
+ function.WriteLog("MakerCode:" + user.MakerCode, "推荐下单奖励监控日志");
|
|
|
|
+ function.WriteLog("machineCount:" + machineCount, "推荐下单奖励监控日志");
|
|
|
|
+ function.WriteLog("ActiveCount:" + ActiveCount, "推荐下单奖励监控日志");
|
|
|
|
+ if (machineCount + ActiveCount + couponCount >= 3)
|
|
|
|
+ {
|
|
|
|
+ function.WriteLog("满足条件", "推荐下单奖励监控日志");
|
|
|
|
+ UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == ParentUserId);
|
|
|
|
+ if (account == null)
|
|
|
|
+ {
|
|
|
|
+ account = db.UserAccount.Add(new UserAccount()
|
|
|
|
+ {
|
|
|
|
+ Id = ParentUserId,
|
|
|
|
+ UserId = ParentUserId,
|
|
|
|
+ }).Entity;
|
|
|
|
+ db.SaveChanges();
|
|
|
|
+ }
|
|
|
|
+ decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
|
|
|
|
+ decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
|
|
|
|
+ decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
|
|
|
|
+ account.BalanceAmount += 100;
|
|
|
|
+ account.TotalAmount += 100;
|
|
|
|
+ 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 = ParentUserId, //创客
|
|
|
|
+ ChangeType = 112, //变动类型
|
|
|
|
+ ChangeAmount = 100, //变更金额
|
|
|
|
+ BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
|
|
|
|
+ AfterTotalAmount = AfterTotalAmount, //变更后总金额
|
|
|
|
+ BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
|
|
|
|
+ AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
|
|
|
|
+ BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
|
|
|
|
+ AfterBalanceAmount = AfterBalanceAmount, //变更后余额
|
|
|
|
+ QueryCount = OrderId,
|
|
|
|
+ }).Entity;
|
|
|
|
+ db.SaveChanges();
|
|
|
|
+ RedisDbconn.Instance.Set("UserAccount:" + ParentUserId, account);
|
|
|
|
+
|
|
|
|
+ //推荐下单上级获得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();
|
|
|
|
+ ParentUserId = 0;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
|
|
|
|
+ ParentUserId = puser.ParentUserId;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ function.WriteLog("\r\n\r\n", "推荐下单奖励监控日志");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public void DoOrder(WebCMSEntities db, int OrderId)
|
|
public void DoOrder(WebCMSEntities db, int OrderId)
|
|
{
|
|
{
|
|
Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId && m.Status == 0);
|
|
Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId && m.Status == 0);
|