Browse Source

增加余额支付队列

lichunlei 2 years ago
parent
commit
41f6cabcf1

+ 156 - 324
AppStart/Helper/AlipayPayBack2Service.cs

@@ -72,277 +72,22 @@ namespace MySystem
                 foreach (string idString in ids)
                 {
                     int OrderId = int.Parse(idString);
-                    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;
-                                db.SaveChanges();
-                                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 == "电签POS")
-                                    {
-                                        Kind = 1;
-                                    }
-                                    else if (pro.NormDetail == "大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;
-                                    }
-                                }
-                                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", "推荐下单奖励监控日志");
-                            }
-                        }
-                    }
+                    DoOrder(db, OrderId);
                 }
             }
             db.Dispose();
         }
 
-        public void checkOrder(int OrderId)
+        public void DoOrder(WebCMSEntities db, int OrderId)
         {
-            WebCMSEntities db = new WebCMSEntities();
-            Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId);
+            Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId && m.Status == 0);
             if (order != null)
             {
-                if (order.Status == 0)
-                {
-                    order.Status = 1;
-                    order.PayDate = DateTime.Now;
-                    order.PayStatus = 1;
-                    db.SaveChanges();
-                    RedisDbconn.Instance.Set("Orders:" + order.Id, order);
-                }
+                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);
@@ -350,11 +95,8 @@ namespace MySystem
                 {
                     if (pro.ProductId == 10 || pro.ProductId == 11 || pro.ProductId == 12 || pro.ProductId == 13)
                     {
-                        if (order.Status == 1)
-                        {
-                            order.Status = 2;
-                            db.SaveChanges();
-                        }
+                        order.Status = 2;
+                        db.SaveChanges();
                         int BuyCount = pro.ProductCount;
                         int Kind = 0;
                         if (pro.ProductId == 10)
@@ -368,36 +110,94 @@ namespace MySystem
                         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 == "电签POS")
-                            { 
+                            {
                                 Kind = 1;
                             }
                             else if (pro.NormDetail == "大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;
+                            }
                         }
                         string Codes = "";
-                        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)
+                        if(Kind > 2)
                         {
-                            PosCoupons item = db.PosCoupons.FirstOrDefault(m => m.Id == coupon.Id);
-                            if (item != null)
+                            Dictionary<int, int> couponData = new Dictionary<int, int>();
+                            if(Kind == 3)
                             {
-                                item.CreateDate = DateTime.Now;
-                                item.UserId = order.UserId;
-                                item.UpdateDate = DateTime.Now.AddDays(180);
-                                Codes += item.ExchangeCode + ",";
+                                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(',');
@@ -442,70 +242,102 @@ namespace MySystem
                     //推荐下单奖励
                     if (pro.ProductId == 10 || pro.ProductId == 11)
                     {
-                        int SelfBuy = db.OrderProduct.Count(m => m.UserId == order.UserId && m.OrderId != OrderId && (m.ProductId == 10 || m.ProductId == 11));
-                        if (SelfBuy == 1)
+                        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;
-                                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张券
-                                if (machineCount + ActiveCount + couponCount >= 3)
+                                while(ParentUserId > 0)
                                 {
-                                    UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == ParentUserId);
-                                    if (account == null)
+                                    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)
                                     {
-                                        account = db.UserAccount.Add(new UserAccount()
+                                        function.WriteLog("满足条件", "推荐下单奖励监控日志");
+                                        UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == ParentUserId);
+                                        if (account == null)
                                         {
-                                            Id = ParentUserId,
-                                            UserId = ParentUserId,
+                                            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();
-                                    }
-                                    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, //变更后余额
-                                    }).Entity;
-                                    db.SaveChanges();
-                                    RedisDbconn.Instance.Set("UserAccount:" + ParentUserId, account);
+                                        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);
-                                    foreach (var subPos in posList)
-                                    {
-                                        PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
-                                        if (pos != null)
+                                        //推荐下单上级获得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)
                                         {
-                                            pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
+                                            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;
                                     }
-                                    db.SaveChanges();
                                 }
                             }
                         }
+                        function.WriteLog("\r\n\r\n", "推荐下单奖励监控日志");
                     }
                 }
             }
+        }
+
+        public void checkOrder(int OrderId)
+        {
+            WebCMSEntities db = new WebCMSEntities();
+            DoOrder(db, OrderId);
             db.Dispose();
         }
 

+ 68 - 0
AppStart/Helper/BalancePayBackService.cs

@@ -0,0 +1,68 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Data;
+using System.Threading;
+using MySystem.PxcModels;
+using Library;
+using LitJson;
+
+namespace MySystem
+{
+    public class BalancePayBackService
+    {
+        public readonly static BalancePayBackService Instance = new BalancePayBackService();
+        private BalancePayBackService()
+        { }
+
+        public void Start()
+        {
+            Thread th = new Thread(dosomething);
+            th.IsBackground = true;
+            th.Start();
+        }
+        
+        private void dosomething()
+        {
+            while (true)
+            {
+                try
+                {
+                    string content = RedisDbconn.Instance.RPop<string>("BalancePayQueue");
+                    if (!string.IsNullOrEmpty(content))
+                    {
+                        sloveAlipayCallBack(content);
+                    }
+                    else
+                    {
+                        Thread.Sleep(2000);
+                    }
+                }
+                catch (Exception ex)
+                {
+                    function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "商城订单余额支付异常");
+                    Thread.Sleep(2000);
+                }
+            }
+        }
+
+        public void sloveAlipayCallBack(string content)
+        { 
+            int OrderId = int.Parse(function.CheckInt(content));            
+            WebCMSEntities db = new WebCMSEntities();
+            AlipayPayBack2Service.Instance.DoOrder(db, OrderId);
+
+            Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId && m.PayMode == 3 && m.PayStatus == 1);
+            if(order != null)
+            {
+                UserAccount account = db.UserAccount.FirstOrDefault(m=>m.Id == order.UserId);
+                if(account != null)
+                {
+                    account.FreezeAmount -= order.TotalPrice;
+                    db.SaveChanges();
+                }
+            }
+            db.Dispose();
+        }
+    }
+}

+ 2 - 1
AppStart/Helper/StatService.cs

@@ -1223,7 +1223,8 @@ namespace MySystem
                             foreach (DataRow selfDr in selfDt.Rows)
                             {
                                 int UserId = int.Parse(selfDr["UserId"].ToString());
-                                string ParentNav = selfDr["ParentNav"].ToString();
+                                Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
+                                string ParentNav = user.ParentNav; //selfDr["ParentNav"].ToString();
                                 int BrandId = int.Parse(selfDr["BrandId"].ToString());
                                 int BankCardType = int.Parse(selfDr["BankCardType"].ToString());
                                 int QrPayFlag = int.Parse(selfDr["QrPayFlag"].ToString());

+ 18 - 17
Startup.cs

@@ -90,9 +90,9 @@ namespace MySystem
             // services.AddHostedService<PopService>();
             // services.AddHostedService<SycnSpTimer>(); //同步SP数据
 
-            // services.AddHostedService<TimerStatTimer>(); //实时统计创客、激活商户数
-            // services.AddHostedService<PosTradeStatTimer>(); // 统计头天的交易额、商户型创客、激活奖励、开机奖励
-            // services.AddHostedService<AlipayPayBack2Timer>(); //支付宝回调处理
+            services.AddHostedService<TimerStatTimer>(); //实时统计创客、激活商户数
+            services.AddHostedService<PosTradeStatTimer>(); // 统计头天的交易额、商户型创客、激活奖励、开机奖励
+            services.AddHostedService<AlipayPayBack2Timer>(); //支付宝回调处理
 
             //services.AddHttpContextAccessor();
 
@@ -190,22 +190,23 @@ namespace MySystem
             // TradeStatTimer2.Instance.Start(); //交易统计
 
             //必须打开的
-            // ActiveRewardTimer.Instance.Start(); //实时处理激活记录
-            // TradeStatTimer.Instance.Start(); //交易统计
-            // ChangePosTimer.Instance.Start(); //售后换新执行机具数据转移
-            // MakeReferenceQrCodeService.Instance.StartListen(); //生成创客邀请二维码
-            // SycnSpBindService.Instance.Start(); //同步SP绑定数据
-            // SycnSpMerchantService.Instance.Start(); //同步SP商户数据
-            // SycnSpActiveService.Instance.Start(); //同步SP激活数据
-            // SycnSpTradeService.Instance.Start(); //同步SP交易数据
-            // SycnSpChangeBindService.Instance.Start(); //同步SP换绑数据
-            // SycnSpUnBindService.Instance.Start(); //同步SP解绑数据
-            // RedPackageHelper.Instance.Start(); //每天生成300个红包
-            // RedPackageHelper.Instance.StartStatTop10(); //红包活动统计排行
-            // RedPackageHelper.Instance.StartSendPrize(); //红包活动发奖
+            ActiveRewardTimer.Instance.Start(); //实时处理激活记录
+            TradeStatTimer.Instance.Start(); //交易统计
+            ChangePosTimer.Instance.Start(); //售后换新执行机具数据转移
+            MakeReferenceQrCodeService.Instance.StartListen(); //生成创客邀请二维码
+            SycnSpBindService.Instance.Start(); //同步SP绑定数据
+            SycnSpMerchantService.Instance.Start(); //同步SP商户数据
+            SycnSpActiveService.Instance.Start(); //同步SP激活数据
+            SycnSpTradeService.Instance.Start(); //同步SP交易数据
+            SycnSpChangeBindService.Instance.Start(); //同步SP换绑数据
+            SycnSpUnBindService.Instance.Start(); //同步SP解绑数据
+            RedPackageHelper.Instance.Start(); //每天生成300个红包
+            RedPackageHelper.Instance.StartStatTop10(); //红包活动统计排行
+            RedPackageHelper.Instance.StartSendPrize(); //红包活动发奖
+            BalancePayBackService.Instance.Start(); //余额支付队列
             //必须打开的
 
-            StatService.Instance.StartPosActNum(); //实时统计激活数
+            // StatService.Instance.StartPosActNum(); //实时统计激活数
             // StatService.Instance.StartNewUserNum(); //实时统计新增创客数
             // StatService.Instance.StatProfit(); //实时统计创客收益
             // LeaderPrizeService.Instance.Start(); //大盟主奖励发奖