瀏覽代碼

直推奖日志
直推奖上级递归,找到为止
增加手动补直推奖
每天执行商户型创客条件加上注册时间
增加乐刷
分润统计加上准贷记卡
SP到MAIN的数据改为线程执行

lichunlei 3 年之前
父節點
當前提交
f2834f2cb4

+ 226 - 49
AppStart/Helper/AlipayPayBack2Service.cs

@@ -175,70 +175,82 @@ namespace MySystem
                             //推荐下单奖励
                             if (pro.ProductId == 10 || pro.ProductId == 11)
                             {
+                                bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId);
                                 int SelfBuy = db.OrderProduct.Count(m => m.UserId == order.UserId && (m.ProductId == 10 || m.ProductId == 11));
-                                if (SelfBuy == 1)
+                                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台激活机(不限购买或赠送)
-                                        function.WriteLog("MakerCode:" + user.MakerCode, "推荐下单奖励监控日志");
-                                        function.WriteLog("machineCount:" + machineCount, "推荐下单奖励监控日志");
-                                        function.WriteLog("ActiveCount:" + ActiveCount, "推荐下单奖励监控日志");
-                                        function.WriteLog("OrderId:" + OrderId, "推荐下单奖励监控日志");
-                                        if (machineCount + ActiveCount >= 3)
+                                        while(ParentUserId > 0)
                                         {
-                                            function.WriteLog("满足条件", "推荐下单奖励监控日志");
-                                            function.WriteLog("\r\n\r\n", "推荐下单奖励监控日志");
-                                            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台激活机(不限购买或赠送)
+                                            function.WriteLog("MakerCode:" + user.MakerCode, "推荐下单奖励监控日志");
+                                            function.WriteLog("machineCount:" + machineCount, "推荐下单奖励监控日志");
+                                            function.WriteLog("ActiveCount:" + ActiveCount, "推荐下单奖励监控日志");
+                                            if (machineCount + ActiveCount >= 3)
                                             {
-                                                account = db.UserAccount.Add(new UserAccount()
+                                                function.WriteLog("满足条件", "推荐下单奖励监控日志");
+                                                function.WriteLog("\r\n\r\n", "推荐下单奖励监控日志");
+                                                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, //变更后余额
-                                                QueryCount = OrderId,
-                                            }).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).ToList();
-                                            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();
                                         }
                                     }
                                 }
@@ -428,5 +440,170 @@ namespace MySystem
             }
             db.Dispose();
         }
+
+        public void addcoupon(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 || pro.ProductId == 12 || pro.ProductId == 13)
+                    {
+                        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;
+                            }
+                        }
+                        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)
+                        {
+                            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);
+                                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)
+                    {
+                        int SelfBuy = db.OrderProduct.Count(m => m.UserId == order.UserId && m.OrderId != OrderId && (m.ProductId == 10 || m.ProductId == 11));
+                        if (SelfBuy == 1)
+                        {
+                            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台激活机(不限购买或赠送)
+                                if (machineCount >= 3 || ActiveCount >= 3)
+                                {
+                                    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, //变更后余额
+                                    }).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);
+                                    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();
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            db.Dispose();
+        }
     }
 }

+ 2 - 3
AppStart/Helper/Profit/ProfitHelper.cs

@@ -2061,8 +2061,7 @@ namespace MySystem
                     sum(QrCreditTradeProfit) as QrCreditTradeProfit
                     from ProfitRewardRecord where MerchantId>0
                     GROUP BY UserId,ProfitType,BrandId,MerchantId
-                    ) tb left join Users u on tb.UserId=u.Id LEFT JOIN KqProducts k ON k.Id=tb.BrandId left join PosMachinesTwo p on tb.MerchantId=p.BindMerchantId
-                    ORDER BY p.PosSn,u.MakerCode
+                    ) tb left join Users u on tb.UserId=u.Id LEFT JOIN KqProducts k ON k.Id=tb.BrandId left join PosMachinesTwo p on tb.MerchantId=p.BindMerchantId ORDER BY p.PosSn,u.MakerCode
 
                     //查补贴
                     select u.MakerCode,u.RealName,u.UserLevel,m.KqMerNo,m.MerchantName,(case when SubsidyType=1 then '直营' else '团队' end) as DirectFlag,
@@ -2086,7 +2085,7 @@ namespace MySystem
                 DataTable dt = new DataTable();
                 if (BankCardType == 1)
                 {
-                    dt = dbconn.dtable("select SnNo,QrPayFlag,sum(TradeAmount) from TradeRecordTest where CreateDate>='" + start + "' and CreateDate<'" + end + "' and BankCardType=1 and BrandId=" + BrandId + " group by SnNo,QrPayFlag");
+                    dt = dbconn.dtable("select SnNo,QrPayFlag,sum(TradeAmount) from TradeRecordTest where CreateDate>='" + start + "' and CreateDate<'" + end + "' and BankCardType>=1 and BankCardType<=2 and BrandId=" + BrandId + " group by SnNo,QrPayFlag");
                 }
                 if (BankCardType == 0)
                 {

+ 126 - 125
AppStart/Helper/StatService.cs

@@ -140,7 +140,7 @@ namespace MySystem
                         Name = Name.Split('_')[1];
                     }
                 }
-                PxcModels.Users user = db.Users.FirstOrDefault(m => m.Mobile.StartsWith(BeforeNum) && m.Mobile.EndsWith(AfterNum) && m.RealName == Name && m.AuthFlag == 1 && m.MerchantType == 0);
+                PxcModels.Users user = db.Users.FirstOrDefault(m => m.Mobile.StartsWith(BeforeNum) && m.Mobile.EndsWith(AfterNum) && m.RealName == Name && m.AuthFlag == 1 && m.MerchantType == 0 && m.CreateDate >= yesterday && m.CreateDate < today);
                 if (user != null)
                 {
                     user.MerchantType = 1;
@@ -269,144 +269,145 @@ namespace MySystem
                     // {
                     //     otherInfo.PrizeFlag1 = 1;
                     //     db.SaveChanges();
-                        string ParentNav = "";
-                        Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId);
-                        if (user != null)
+                    string ParentNav = "";
+                    Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId);
+                    if (user != null)
+                    {
+                        int GetUserId = user.Id;
+                        ParentNav = user.ParentNav;
+                        int TopUserId = 0;
+                        if (!string.IsNullOrEmpty(ParentNav))
                         {
-                            int GetUserId = user.Id;
-                            ParentNav = user.ParentNav;
-                            int TopUserId = 0;
-                            if (!string.IsNullOrEmpty(ParentNav))
-                            {
-                                TopUserId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
-                            }
-                            decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
-                            if (pos.BrandId == 1 || pos.BrandId == 3)
-                            {
-                                ActPrize = ActPrize / 100;
-                            }
-                            if (ActPrize > 0)
+                            TopUserId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
+                        }
+                        decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
+                        if (pos.BrandId == 1 || pos.BrandId == 3 || pos.BrandId == 4 || pos.BrandId == 5)
+                        {
+                            ActPrize = ActPrize / 100;
+                        }
+                        if (ActPrize > 0)
+                        {
+                            bool check = db.ActiveReward.Any(m => m.KqMerNo == merchant.KqMerNo);
+                            if (!check)
                             {
-                                bool check = db.ActiveReward.Any(m => m.KqMerNo == merchant.KqMerNo);
-                                if (!check)
+                                if (ActPrize == 99)
                                 {
-                                    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)
+                                    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()
                                     {
-                                        userData = db.UserMachineData.Add(new UserMachineData()
-                                        {
-                                            IdBrand = IdBrand,
-                                        }).Entity;
-                                        db.SaveChanges();
-                                    }
-                                    userData.ActProfit += ActPrize;
+                                        IdBrand = IdBrand,
+                                    }).Entity;
                                     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()
+                                }
+                                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()
                                     {
-                                        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, //变更后余额
+                                        Id = GetUserId,
+                                        UserId = GetUserId,
                                     }).Entity;
                                     db.SaveChanges();
-                                    RedisDbconn.Instance.Set("UserAccount:" + GetUserId, account);
-
-                                    string dateString = pos.ActivationTime.Value.ToString("yyyyMMdd");
-                                    string monthString = pos.ActivationTime.Value.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);
+                                }
+                                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);
 
-                                    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 = pos.ActivationTime.Value.ToString("yyyyMMdd");
+                                string monthString = pos.ActivationTime.Value.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<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);
+                                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);
 
-                                    //收支明细
-                                    RedisDbconn.Instance.AddList("UserAccountRecord:" + GetUserId + ":1:" + monthString, userAccountRecord);
-                                    RedisDbconn.Instance.AddNumber("UserAccount:" + GetUserId + ":1:" + 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:mer:" + pos.BindMerchantId + ":" + pos.BrandId + ":" + dateString, ActPrize);
+
+                                //收支明细
+                                RedisDbconn.Instance.AddList("UserAccountRecord:" + GetUserId + ":1:" + monthString, userAccountRecord);
+                                RedisDbconn.Instance.AddNumber("UserAccount:" + GetUserId + ":1:" + monthString, ActPrize);
+                                RedisDbconn.Instance.Clear("UserAccount:Income:" + GetUserId + ":" + monthString);
                             }
                         }
+                    }
                     // }
                 }
             }

+ 76 - 64
AppStart/Helper/SycnSpServer/SycnSpActiveService.cs

@@ -4,6 +4,7 @@ using System.Linq;
 using MySystem.SpModels;
 using Library;
 using LitJson;
+using System.Threading;
 
 namespace MySystem
 {
@@ -13,83 +14,94 @@ namespace MySystem
         private SycnSpActiveService()
         { }
 
-        public void Start(int Id = 0)
+        public void Start()
         {
-            WebCMSEntities spdb = new WebCMSEntities();
-            PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
-            string Month = DateTime.Now.ToString("yyyyMM");
-            string Date = DateTime.Now.ToString("yyyyMMdd");
-            DateTime start = DateTime.Now.AddDays(-5);
-            IQueryable<ActivateRecord> acts = spdb.ActivateRecord;
-            if (Id > 0)
-            {
-                acts = acts.Where(m => m.Id == Id && m.Status == 1);
-            }
-            else
-            { 
-                acts = acts.Where(m => m.ActivateDate >= start && m.Status == 1);
-            }
-            acts = acts.OrderByDescending(m => m.Id);
-            foreach (ActivateRecord act in acts.ToList())
+            Thread th = new Thread(StartDo);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void StartDo()
+        {
+            while (true)
             {
-                bool op = false;
-                if (act.ActivateStatus == "00" && act.ProductType == "1")
-                { 
-                    op = true;
-                }
-                else if (act.ProductType == "2")
-                { 
-                    op = true;
-                }
-                if(op)
+                try
                 {
-                    PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == act.MerNo) ?? new PxcModels.MachineForMerNo();
-                    PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
-                    if (pos != null)
+                    WebCMSEntities spdb = new WebCMSEntities();
+                    PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
+                    string Month = DateTime.Now.ToString("yyyyMM");
+                    string Date = DateTime.Now.ToString("yyyyMMdd");
+                    DateTime start = DateTime.Now.AddDays(-5);
+                    IQueryable<ActivateRecord> acts = spdb.ActivateRecord;
+                    acts = acts.Where(m => m.ActivateDate >= start && m.Status == 1);
+                    acts = acts.OrderByDescending(m => m.Id);
+                    foreach (ActivateRecord act in acts.ToList())
                     {
-                        // pos.ActivationState = 1;
-                        // pos.ActivationTime = DateTime.Now;
-                        if (pos.BrandId == 2)
+                        bool op = false;
+                        if (act.ActivateStatus == "00" && act.ProductType == "1")
                         {
-                            pos.SeoKeyword = act.SeoTitle;
-                            db.SaveChanges();
-                            RedisDbconn.Instance.Set("PosMachinesTwo:" + pos.Id, pos);
-                            RedisDbconn.Instance.Set("PosMachinesTwo:" + pos.PosSn, pos);
+                            op = true;
                         }
-
-                        // PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
-                        // if (merchant != null)
-                        // {
-                        //     merchant.ActiveStatus = 1;
-                        //     merchant.MerStandardDate = DateTime.Now;
-                        //     db.SaveChanges();
-                        //     RedisDbconn.Instance.Set("PosMerchantInfo:" + merchant.Id, merchant);
-                        // }
-
-                        ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
-                        if (edit != null)
+                        else if (act.ProductType == "2" || act.ProductType == "4")
                         {
-                            edit.Status = 2;
+                            op = true;
                         }
-
-                        // 激活奖励
-                        // ProfitHelper.Instance.StartListenActiveDo(pos);
-                    }
-                    pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId && m.ActivationState == 1);
-                    if (pos != null)
-                    {
-                        ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
-                        if (edit != null)
+                        if (op)
                         {
-                            edit.Status = 2;
+                            PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == act.MerNo) ?? new PxcModels.MachineForMerNo();
+                            PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
+                            if (pos != null)
+                            {
+                                // pos.ActivationState = 1;
+                                // pos.ActivationTime = DateTime.Now;
+                                if (pos.BrandId == 2 || pos.BrandId == 4 || pos.BrandId == 5)
+                                {
+                                    pos.SeoKeyword = act.SeoTitle;
+                                    db.SaveChanges();
+                                    RedisDbconn.Instance.Set("PosMachinesTwo:" + pos.Id, pos);
+                                    RedisDbconn.Instance.Set("PosMachinesTwo:" + pos.PosSn, pos);
+                                }
+
+                                // PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
+                                // if (merchant != null)
+                                // {
+                                //     merchant.ActiveStatus = 1;
+                                //     merchant.MerStandardDate = DateTime.Now;
+                                //     db.SaveChanges();
+                                //     RedisDbconn.Instance.Set("PosMerchantInfo:" + merchant.Id, merchant);
+                                // }
+
+                                ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
+                                if (edit != null)
+                                {
+                                    edit.Status = 2;
+                                }
+
+                                // 激活奖励
+                                // ProfitHelper.Instance.StartListenActiveDo(pos);
+                            }
+                            pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId && m.ActivationState == 1);
+                            if (pos != null)
+                            {
+                                ActivateRecord edit = spdb.ActivateRecord.FirstOrDefault(m => m.Id == act.Id);
+                                if (edit != null)
+                                {
+                                    edit.Status = 2;
+                                }
+                            }
                         }
                     }
+                    spdb.SaveChanges();
+                    spdb.Dispose();
+                    db.SaveChanges();
+                    db.Dispose();
+                }
+                catch (Exception ex)
+                {
+                    function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP激活数据到MAIN异常");
                 }
+                Thread.Sleep(1000);
             }
-            spdb.SaveChanges();
-            spdb.Dispose();
-            db.SaveChanges();
-            db.Dispose();
         }
     }
 }

+ 65 - 46
AppStart/Helper/SycnSpServer/SycnSpBindService.cs

@@ -4,6 +4,7 @@ using System.Linq;
 using MySystem.SpModels;
 using Library;
 using LitJson;
+using System.Threading;
 
 namespace MySystem
 {
@@ -15,68 +16,86 @@ namespace MySystem
 
         public void Start()
         {
-            WebCMSEntities spdb = new WebCMSEntities();
-            PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
-            DateTime start = DateTime.Now.AddDays(-2);
-            var Binds = spdb.BindRecord.Select(m => new { m.Id, m.CreateTime, m.Status, m.MerNo, m.MerSnNo }).Where(m => m.CreateTime >= start && m.Status == 1).OrderByDescending(m => m.Id).ToList();
-            foreach (var Bind in Binds)
+            Thread th = new Thread(StartDo);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void StartDo()
+        {
+            while (true)
             {
-                var tran = db.Database.BeginTransaction();
                 try
                 {
-                    PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == Bind.MerSnNo) ?? new PxcModels.MachineForSnNo();
-                    PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
-                    if (pos != null)
+                    WebCMSEntities spdb = new WebCMSEntities();
+                    PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
+                    DateTime start = DateTime.Now.AddDays(-5);
+                    var Binds = spdb.BindRecord.Select(m => new { m.Id, m.CreateTime, m.Status, m.MerNo, m.MerSnNo }).Where(m => m.CreateTime >= start && m.Status == 1).OrderByDescending(m => m.Id).ToList();
+                    foreach (var Bind in Binds)
                     {
-                        pos.BindingState = 1;
-                        pos.BindingTime = Bind.CreateTime;
-                        PxcModels.MachineForMerNo merFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.MerNo);
-                        if (merFor == null)
+                        var tran = db.Database.BeginTransaction();
+                        try
                         {
-                            merFor = db.MachineForMerNo.Add(new PxcModels.MachineForMerNo()
+                            PxcModels.MachineForSnNo posFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == Bind.MerSnNo) ?? new PxcModels.MachineForSnNo();
+                            PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
+                            if (pos != null)
                             {
-                                MerNo = Bind.MerNo,
-                                SnId = pos.Id,
-                            }).Entity;
-                        }
-                        db.SaveChanges();
-                        RedisDbconn.Instance.Set("PosMachinesTwo", pos);
+                                pos.BindingState = 1;
+                                pos.BindingTime = Bind.CreateTime;
+                                PxcModels.MachineForMerNo merFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.MerNo);
+                                if (merFor == null)
+                                {
+                                    merFor = db.MachineForMerNo.Add(new PxcModels.MachineForMerNo()
+                                    {
+                                        MerNo = Bind.MerNo,
+                                        SnId = pos.Id,
+                                    }).Entity;
+                                }
+                                db.SaveChanges();
+                                RedisDbconn.Instance.Set("PosMachinesTwo", pos);
 
-                        BindRecord edit = spdb.BindRecord.FirstOrDefault(m => m.Id == Bind.Id);
-                        if (edit != null)
-                        {
-                            edit.Status = 2;
-                            spdb.SaveChanges();
-                        }
+                                BindRecord edit = spdb.BindRecord.FirstOrDefault(m => m.Id == Bind.Id);
+                                if (edit != null)
+                                {
+                                    edit.Status = 2;
+                                    spdb.SaveChanges();
+                                }
 
-                        string IdBrand = pos.UserId + "_" + pos.BrandId;
-                        PxcModels.UserMachineData MachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
-                        if (MachineData == null)
+                                string IdBrand = pos.UserId + "_" + pos.BrandId;
+                                PxcModels.UserMachineData MachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
+                                if (MachineData == null)
+                                {
+                                    MachineData = db.UserMachineData.Add(new PxcModels.UserMachineData()
+                                    {
+                                        IdBrand = IdBrand,
+                                    }).Entity;
+                                    db.SaveChanges();
+                                }
+                                MachineData.BindCount += 1;
+                                MachineData.UnBindCount -= 1;
+                                db.SaveChanges();
+                                tran.Commit();
+                                RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, MachineData);
+                            }
+                        }
+                        catch (Exception ex)
                         {
-                            MachineData = db.UserMachineData.Add(new PxcModels.UserMachineData()
-                            {
-                                IdBrand = IdBrand,
-                            }).Entity;
-                            db.SaveChanges();
+                            tran.Rollback();
+                            function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Bind.Id, "同步SP绑定数据到MAIN异常");
                         }
-                        MachineData.BindCount += 1;
-                        MachineData.UnBindCount -= 1;
-                        db.SaveChanges();
-                        tran.Commit();
-                        RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, MachineData);
+                        tran.Dispose();
                     }
+                    spdb.SaveChanges();
+                    spdb.Dispose();
+                    db.SaveChanges();
+                    db.Dispose();
                 }
                 catch (Exception ex)
                 {
-                    tran.Rollback();
-                    function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Bind.Id, "同步SP绑定数据到MAIN异常");
+                    function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP绑定数据到MAIN异常");
                 }
-                tran.Dispose();
+                Thread.Sleep(1000);
             }
-            spdb.SaveChanges();
-            spdb.Dispose();
-            db.SaveChanges();
-            db.Dispose();
         }
     }
 }

+ 75 - 52
AppStart/Helper/SycnSpServer/SycnSpMerchantService.cs

@@ -4,6 +4,7 @@ using System.Linq;
 using MySystem.SpModels;
 using Library;
 using LitJson;
+using System.Threading;
 
 namespace MySystem
 {
@@ -15,72 +16,94 @@ namespace MySystem
 
         public void Start()
         {
-            WebCMSEntities spdb = new WebCMSEntities();
-            PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
-            DateTime start = DateTime.Now.AddDays(-2);
-            var Mers = spdb.Merchants.Where(m => m.CreateTime >= start && m.Status == 1).OrderByDescending(m => m.Id).ToList();
-            foreach (var Mer in Mers)
+            Thread th = new Thread(StartDo);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void StartDo()
+        {
+            while (true)
             {
-                var tran = db.Database.BeginTransaction();
                 try
                 {
-                    PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo) ?? new PxcModels.MachineForMerNo();
-                    PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId) ?? new PxcModels.PosMachinesTwo();
-                    if (pos.BindingState == 1)
+                    WebCMSEntities spdb = new WebCMSEntities();
+                    PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
+                    DateTime start = DateTime.Now.AddDays(-5);
+                    var Mers = spdb.Merchants.Where(m => m.CreateTime >= start && m.Status == 1).OrderByDescending(m => m.Id).ToList();
+                    foreach (var Mer in Mers)
                     {
-                        PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
-                        int TopUserId = 0;
-                        if (!string.IsNullOrEmpty(user.ParentNav))
+                        var tran = db.Database.BeginTransaction();
+                        try
                         {
-                            TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
+                            PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo) ?? new PxcModels.MachineForMerNo();
+                            PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId) ?? new PxcModels.PosMachinesTwo();
+                            if (pos.BindingState == 1)
+                            {
+                                PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
+                                int TopUserId = 0;
+                                if (!string.IsNullOrEmpty(user.ParentNav))
+                                {
+                                    TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
+                                }
+                                int BrandId = int.Parse(Mer.ProductType);
+                                if (BrandId == 1 && Mer.MerNo.StartsWith("M900"))
+                                {
+                                    BrandId = 3;
+                                }
+                                if (BrandId == 4 && Mer.SeoTitle == "200")
+                                { 
+                                    BrandId = 5;
+                                }
+                                PxcModels.PosMerchantInfo add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
+                                {
+                                    CreateDate = Mer.CreateTime,
+                                    UpdateDate = Mer.UpdateTime,
+                                    TopUserId = TopUserId,
+                                    MerUserType = user.MerchantType,
+                                    BrandId = BrandId,
+                                    SnStoreId = pos.StoreId,
+                                    SnType = pos.PosSnType,
+                                    UserId = pos.UserId,
+                                    MgrName = Mer.AgentName,
+                                    MerStatus = 1,
+                                    KqSnNo = Mer.SnNo,
+                                    KqMerNo = Mer.MerNo,
+                                    MerIdcardNo = Mer.MerIdcardNo,
+                                    MerRealName = Mer.MerRealName,
+                                    MerchantMobile = Mer.MerMobile,
+                                    MerchantName = Mer.MerName,
+                                    MerchantNo = Mer.MerNo,
+                                }).Entity;
+                                db.SaveChanges();
+                                pos.BindMerchantId = add.Id;
+                                Merchants edit = spdb.Merchants.FirstOrDefault(m => m.Id == Mer.Id);
+                                if (edit != null)
+                                {
+                                    edit.Status = 2;
+                                    spdb.SaveChanges();
+                                }
+                                tran.Commit();
+                            }
                         }
-                        int BrandId = int.Parse(Mer.ProductType);
-                        if (Mer.MerNo.StartsWith("M900"))
-                        {
-                            BrandId = 3;
-                        }
-                        PxcModels.PosMerchantInfo add = db.PosMerchantInfo.Add(new PxcModels.PosMerchantInfo()
-                        {
-                            CreateDate = Mer.CreateTime,
-                            UpdateDate = Mer.UpdateTime,
-                            TopUserId = TopUserId,
-                            MerUserType = user.MerchantType,
-                            BrandId = BrandId,
-                            SnStoreId = pos.StoreId,
-                            SnType = pos.PosSnType,
-                            UserId = pos.UserId,
-                            MgrName = Mer.AgentName,
-                            MerStatus = 1,
-                            KqSnNo = Mer.SnNo,
-                            KqMerNo = Mer.MerNo,
-                            MerIdcardNo = Mer.MerIdcardNo,
-                            MerRealName = Mer.MerRealName,
-                            MerchantMobile = Mer.MerMobile,
-                            MerchantName = Mer.MerName,
-                            MerchantNo = Mer.MerNo,
-                        }).Entity;
-                        db.SaveChanges();
-                        pos.BindMerchantId = add.Id;
-                        Merchants edit = spdb.Merchants.FirstOrDefault(m => m.Id == Mer.Id);
-                        if (edit != null)
+                        catch (Exception ex)
                         {
-                            edit.Status = 2;
-                            spdb.SaveChanges();
+                            tran.Rollback();
+                            function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Mer.Id, "同步SP商户数据到MAIN异常");
                         }
-                        tran.Commit();
+                        tran.Dispose();
                     }
+                    spdb.SaveChanges();
+                    spdb.Dispose();
+                    db.SaveChanges();
+                    db.Dispose();
                 }
                 catch (Exception ex)
                 {
-                    tran.Rollback();
-                    function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n" + Mer.Id, "同步SP商户数据到MAIN异常");
+                    function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP商户数据到MAIN异常");
                 }
-                tran.Dispose();
+                Thread.Sleep(1000);
             }
-            spdb.SaveChanges();
-            spdb.Dispose();
-            db.SaveChanges();
-            db.Dispose();
         }
     }
 }

+ 16 - 16
AppStart/Helper/SycnSpServer/SycnSpService.cs

@@ -35,22 +35,22 @@ namespace MySystem
 
         public void dosomething(string Kind)
         { 
-            if (Kind == "bind")
-            {
-                SycnSpBindService.Instance.Start();
-            }
-            else if (Kind == "active")
-            { 
-                SycnSpActiveService.Instance.Start();
-            }
-            else if (Kind == "trade")
-            { 
-                SycnSpTradeService.Instance.Start();
-            }
-            else if (Kind == "merchant")
-            { 
-                SycnSpMerchantService.Instance.Start();
-            }
+            // if (Kind == "bind")
+            // {
+            //     SycnSpBindService.Instance.Start();
+            // }
+            // else if (Kind == "active")
+            // { 
+            //     SycnSpActiveService.Instance.Start();
+            // }
+            // else if (Kind == "trade")
+            // { 
+            //     SycnSpTradeService.Instance.Start();
+            // }
+            // else if (Kind == "merchant")
+            // { 
+            //     SycnSpMerchantService.Instance.Start();
+            // }
         }
     }
 }

+ 161 - 126
AppStart/Helper/SycnSpServer/SycnSpTradeService.cs

@@ -4,6 +4,7 @@ using System.Linq;
 using MySystem.SpModels;
 using Library;
 using LitJson;
+using System.Threading;
 
 namespace MySystem
 {
@@ -13,156 +14,190 @@ namespace MySystem
         private SycnSpTradeService()
         { }
 
-        public void Start(int Id = 0)
+        public void Start()
         {
-            WebCMSEntities spdb = new WebCMSEntities();
-            PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
-            DateTime start = DateTime.Now.AddDays(-2);
-            IQueryable<TradeRecord> trades = spdb.TradeRecord;
-            if (Id > 0)
-            {
-                trades = trades.Where(m => m.Id == Id && m.Status == 1);
-            }
-            else
-            { 
-                trades = trades.Where(m => m.CreateDate >= start && m.Status == 1);
-            }
-            trades = trades.OrderByDescending(m => m.Id);
-            // DateTime start = DateTime.Parse("2022-04-03 00:00:00");
-            // DateTime end = DateTime.Parse("2022-04-04 00:00:00");
-            // trades = trades.Where(m => m.CreateDate >= start && m.CreateDate < end);
-            trades = trades.OrderBy(m => m.Id);
-            foreach (TradeRecord trade in trades.ToList())
+            Thread th = new Thread(StartDo);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        public void StartDo()
+        {
+            while (true)
             {
-                bool op = true;
-                if (trade.SerEntryMode == "N")
+                try
                 {
-                    if (trade.TradeAmount == 9900 || trade.TradeAmount == 19900 || trade.TradeAmount == 29900)
+                    WebCMSEntities spdb = new WebCMSEntities();
+                    PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities();
+                    DateTime start = DateTime.Now.AddDays(-5);
+                    IQueryable<TradeRecord> trades = spdb.TradeRecord;
+                    trades = trades.Where(m => m.CreateDate >= start && m.Status == 1);
+                    trades = trades.OrderByDescending(m => m.Id);
+                    // DateTime start = DateTime.Parse("2022-04-03 00:00:00");
+                    // DateTime end = DateTime.Parse("2022-04-04 00:00:00");
+                    // trades = trades.Where(m => m.CreateDate >= start && m.CreateDate < end);
+                    trades = trades.OrderBy(m => m.Id);
+                    foreach (TradeRecord trade in trades.ToList())
                     {
-                        op = false;
-                        PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo();
-                        PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
-                        if (pos != null)
+                        bool op = true;
+                        if (trade.SerEntryMode == "N")
                         {
-                            if (trade.SerEntryMode == "N" && trade.ProductType == "1")
+                            if (trade.TradeAmount == 9900 || trade.TradeAmount == 19900 || trade.TradeAmount == 29900)
                             {
-                                pos.SeoKeyword = trade.TradeAmount.ToString("f2");
-                                db.SaveChanges();
+                                op = false;
+                                PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo();
+                                PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
+                                if (pos != null)
+                                {
+                                    if (trade.SerEntryMode == "N" && trade.ProductType == "1")
+                                    {
+                                        pos.SeoKeyword = trade.TradeAmount.ToString("f2");
+                                        db.SaveChanges();
+                                    }
+                                }
+                                TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
+                                if (edit != null)
+                                {
+                                    edit.Status = 2;
+                                }
+                                spdb.SaveChanges();
                             }
                         }
-                        TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
-                        if (edit != null)
-                        {
-                            edit.Status = 2;
-                        }
-                        spdb.SaveChanges();
-                    }
-                }
-                if (op)
-                {
-                    PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo();
-                    PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
-                    if (pos != null)
-                    {
-                        if (pos.BindMerchantId > 0)
-                        {
-                            PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
-                            int TopUserId = 0;
-                            if (!string.IsNullOrEmpty(user.ParentNav))
+                        if (trade.DiscountRateFlag == "True")
+                        { 
+                            op = false;
+                            TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
+                            if (edit != null)
                             {
-                                TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
+                                edit.Status = 2;
                             }
-                            bool check = db.TradeRecord.Any(m => m.RecordNo == trade.TradeSerialNo);
-                            if (!check)
+                            spdb.SaveChanges();
+                        }
+                        if (op)
+                        {
+                            PxcModels.MachineForMerNo posFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == trade.MerNo) ?? new PxcModels.MachineForMerNo();
+                            PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posFor.SnId);
+                            if (pos != null)
                             {
-                                decimal TradeAmount = trade.TradeAmount;
-                                int BankCardType = -1;
-                                int QrPayFlag = 0;
-                                if (pos.BrandId == 1 || pos.BrandId == 3)
-                                {
-                                    TradeAmount = TradeAmount / 100;
-                                    BankCardType = int.Parse(trade.BankCardType);
-                                    if(trade.TradeType == "02") QrPayFlag = 1;
-                                }
-                                else if (pos.BrandId == 2)
+                                if (pos.BindMerchantId > 0)
                                 {
-                                    if (trade.TradeType == "CREDIT_BY_CARD")
+                                    PxcModels.Users user = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new PxcModels.Users();
+                                    int TopUserId = 0;
+                                    if (!string.IsNullOrEmpty(user.ParentNav))
                                     {
-                                        BankCardType = 1;
+                                        TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
                                     }
-                                    else if (trade.TradeType == "DEBIT_BY_CARD")
+                                    bool check = db.TradeRecord.Any(m => m.RecordNo == trade.TradeSerialNo);
+                                    if (!check)
                                     {
-                                        BankCardType = 0;
+                                        decimal TradeAmount = trade.TradeAmount;
+                                        int BankCardType = -1;
+                                        int QrPayFlag = 0;
+                                        if (pos.BrandId == 1 || pos.BrandId == 3)
+                                        {
+                                            TradeAmount = TradeAmount / 100;
+                                            BankCardType = int.Parse(trade.BankCardType);
+                                            if (trade.TradeType == "02") QrPayFlag = 1;
+                                        }
+                                        else if (pos.BrandId == 2)
+                                        {
+                                            if (trade.TradeType == "CREDIT_BY_CARD")
+                                            {
+                                                BankCardType = 1;
+                                            }
+                                            else if (trade.TradeType == "DEBIT_BY_CARD")
+                                            {
+                                                BankCardType = 0;
+                                            }
+                                            if (trade.TradeType == "CLOUD_PAY") QrPayFlag = 1;
+                                        }
+                                        else if (pos.BrandId == 4 || pos.BrandId == 5)
+                                        {
+                                            TradeAmount = TradeAmount / 100;
+                                            if (trade.BankCardType == "100")
+                                            {
+                                                BankCardType = 1;
+                                            }
+                                            else if (trade.BankCardType == "200")
+                                            {
+                                                BankCardType = 0;
+                                            }
+                                            if (trade.TradeType == "200") QrPayFlag = 1;
+                                        }
+                                        int BrandId = int.Parse(trade.ProductType);
+                                        if (trade.MerNo.StartsWith("M900"))
+                                        {
+                                            BrandId = 3;
+                                        }
+                                        db.TradeRecord.Add(new PxcModels.TradeRecord()
+                                        {
+                                            CreateDate = trade.CreateDate,
+                                            UpdateDate = trade.UpdateDate,
+                                            RecordNo = trade.TradeSerialNo, //单号
+                                            UserId = pos.UserId, //创客
+                                            MerchantId = pos.BindMerchantId, //商户
+                                            MerNo = trade.MerNo, //渠道商户编号
+                                            MerHelpFlag = 0, //是否属于扶持周期内商户
+                                            HelpMonthCount = 0, //扶持第几个月
+                                            MerBuddyType = user.MerchantType, //商户创客类型
+                                            SnNo = trade.TradeSnNo, //渠道SN号
+                                                                    // TradeDate = DateTime.Parse(trade.TradeTime), //交易日期
+                                            TradeSerialNo = trade.ChannelSerial, //交易流水号
+                                            TradeAmount = TradeAmount, //交易金额
+                                            BankCardType = BankCardType, //银行卡类型
+                                            QrPayFlag = QrPayFlag, //云闪付标识
+                                            BrandId = BrandId, //品牌
+                                            Remark = trade.Remark, //备注
+                                            TopUserId = TopUserId, //顶级创客
+                                            MerUserId = pos.UserId, //商户直属创客
+                                        });
+                                        if (BankCardType == 1)
+                                        {
+                                            pos.CreditTrade += TradeAmount;
+                                        }
+                                        else if (BankCardType == 0)
+                                        {
+                                            pos.DebitCardTrade += TradeAmount;
+                                        }
+                                        if (pos.CreditTrade < 1000)
+                                        {
+                                            pos.IsPurchase = 99;
+                                        }
+                                        else if (pos.CreditTrade >= 1000 && pos.ActivationState == 0 && pos.BindingTime > DateTime.Now.AddDays(-20))
+                                        {
+                                            pos.IsPurchase = 0;
+                                            pos.ActivationState = 1;
+                                            pos.ActivationTime = DateTime.Now;
+                                            PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
+                                            if (merchant != null)
+                                            {
+                                                merchant.ActiveStatus = 1;
+                                                merchant.MerStandardDate = DateTime.Now;
+                                                db.SaveChanges();
+                                                RedisDbconn.Instance.Set("PosMerchantInfo:" + merchant.Id, merchant);
+                                            }
+                                        }
+                                        db.SaveChanges();
                                     }
-                                    if(trade.TradeType == "CLOUD_PAY") QrPayFlag = 1;
-                                }
-                                int BrandId = int.Parse(trade.ProductType);
-                                if (trade.MerNo.StartsWith("M900"))
-                                {
-                                    BrandId = 3;
-                                }
-                                db.TradeRecord.Add(new PxcModels.TradeRecord()
-                                {
-                                    CreateDate = trade.CreateDate,
-                                    UpdateDate = trade.UpdateDate,
-                                    RecordNo = trade.TradeSerialNo, //单号
-                                    UserId = pos.UserId, //创客
-                                    MerchantId = pos.BindMerchantId, //商户
-                                    MerNo = trade.MerNo, //渠道商户编号
-                                    MerHelpFlag = 0, //是否属于扶持周期内商户
-                                    HelpMonthCount = 0, //扶持第几个月
-                                    MerBuddyType = user.MerchantType, //商户创客类型
-                                    SnNo = trade.TradeSnNo, //渠道SN号
-                                    // TradeDate = DateTime.Parse(trade.TradeTime), //交易日期
-                                    TradeSerialNo = trade.ChannelSerial, //交易流水号
-                                    TradeAmount = TradeAmount, //交易金额
-                                    BankCardType = BankCardType, //银行卡类型
-                                    QrPayFlag = QrPayFlag, //云闪付标识
-                                    BrandId = BrandId, //品牌
-                                    Remark = trade.Remark, //备注
-                                    TopUserId = TopUserId, //顶级创客
-                                    MerUserId = pos.UserId, //商户直属创客
-                                });
-                                if (BankCardType == 1)
-                                {
-                                    pos.CreditTrade += TradeAmount;
-                                }
-                                else if (BankCardType == 0)
-                                {
-                                    pos.DebitCardTrade += TradeAmount;
-                                }
-                                if (pos.CreditTrade < 1000)
-                                {
-                                    pos.IsPurchase = 99;
-                                }
-                                else if (pos.CreditTrade >= 1000 && pos.ActivationState == 0 && pos.BindingTime > DateTime.Now.AddDays(-20))
-                                {
-                                    pos.IsPurchase = 0;
-                                    pos.ActivationState = 1;
-                                    pos.ActivationTime = DateTime.Now;
-                                    PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
-                                    if (merchant != null)
+                                    TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
+                                    if (edit != null)
                                     {
-                                        merchant.ActiveStatus = 1;
-                                        merchant.MerStandardDate = DateTime.Now;
-                                        db.SaveChanges();
-                                        RedisDbconn.Instance.Set("PosMerchantInfo:" + merchant.Id, merchant);
+                                        edit.Status = 2;
                                     }
+                                    spdb.SaveChanges();
                                 }
-                                db.SaveChanges();
-                            }
-                            TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
-                            if (edit != null)
-                            {
-                                edit.Status = 2;
                             }
-                            spdb.SaveChanges();
                         }
                     }
+                    spdb.Dispose();
+                    db.Dispose();
+                }
+                catch (Exception ex)
+                {
+                    function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "同步SP交易数据到MAIN异常");
                 }
+                Thread.Sleep(1000);
             }
-            spdb.Dispose();
-            db.Dispose();
         }
     }
 }

+ 1 - 1
AppStart/Timer/AlipayPayBack2Timer.cs

@@ -15,7 +15,7 @@ public class AlipayPayBack2Timer : BackgroundService
     {
         while (!stoppingToken.IsCancellationRequested)
         {
-            int timespan = 10000;
+            int timespan = 1000;
             await Task.Delay(timespan).ContinueWith(tsk =>
             {
                 DoWorks();

+ 87 - 13
AppStart/Timer/TestHelper.cs

@@ -23,6 +23,7 @@ public class TestHelper
 
     private void DoWorks()
     {
+        WebCMSEntities db = new WebCMSEntities();
         // bool op = true;
         // while (op)
         // {
@@ -55,20 +56,93 @@ public class TestHelper
         //     Thread.Sleep(10);
         // }
 
-        WebCMSEntities db = new WebCMSEntities();
-        IQueryable<Users> users = db.Users.Where(m => m.AuthFlag == 1).OrderBy(m => m.Id);
-        foreach (Users user in users.ToList())
+        // IQueryable<Users> users = db.Users.Where(m => m.AuthFlag == 1).OrderBy(m => m.Id);
+        // foreach (Users user in users.ToList())
+        // {
+        //     string path = function.CreateQRCode2(ConfigurationManager.AppSettings["SourceHost"].ToString() + "p/user-inviteregist-1?Id=" + user.Id, function.MD5_16(user.Id.ToString() + "8745"), "/bsserver_com/static/ReferenceQrCode/");
+        //     path = path.Replace("//", "/");
+        //     string resultpath = "/bsserver_com/static/ReferenceQrCode/" + function.MD5_16(user.Id.ToString() + "8745") + "Pic.png";
+        //     MakeReferenceQrCodeService.Instance.MakeQRCode(function.getPath("/static/QrCodeBg.png"), function.getPath(path), function.getPath(resultpath), user);
+        //     resultpath = resultpath.Replace("bsserver_com/", "");
+        //     user.ReferenceQrCode = resultpath;
+        //     db.SaveChanges();
+        //     RedisDbconn.Instance.Set("Users:" + user.Id, user);
+        //     function.WriteLog(user.Id.ToString(), "生成邀请二维码");
+        // }
+        // function.WriteLog("finish", "生成邀请二维码");
+
+        
+        bool op = true;
+        while (op)
+        {
+            int startId = RedisDbconn.Instance.Get<int>("RemoveUserId");
+            List<int> uids = db.Users.Select(m => m.Id).Where(m => m > startId && m > 1).OrderBy(m => m).Take(100).ToList();
+            if (uids.Count > 0)
+            {
+                foreach (int uid in uids)
+                {
+                    DoUsers(db, uid);
+                    RedisDbconn.Instance.Set("RemoveUserId", uid);
+                }
+                Thread.Sleep(200);
+            }
+            else
+            {
+                op = false;
+            }
+        }
+
+        db.Dispose();
+    }
+
+    public void DoUsers(WebCMSEntities db, int uid)
+    { 
+        Users user = db.Users.FirstOrDefault(m => m.Id == uid);
+        if (user != null)
         {
-            string path = function.CreateQRCode2(ConfigurationManager.AppSettings["SourceHost"].ToString() + "p/user-inviteregist-1?Id=" + user.Id, function.MD5_16(user.Id.ToString() + "8745"), "/bsserver_com/static/ReferenceQrCode/");
-            path = path.Replace("//", "/");
-            string resultpath = "/bsserver_com/static/ReferenceQrCode/" + function.MD5_16(user.Id.ToString() + "8745") + "Pic.png";
-            MakeReferenceQrCodeService.Instance.MakeQRCode(function.getPath("/static/QrCodeBg.png"), function.getPath(path), function.getPath(resultpath), user);
-            resultpath = resultpath.Replace("bsserver_com/", "");
-            user.ReferenceQrCode = resultpath;
-            db.SaveChanges();
-            RedisDbconn.Instance.Set("Users:" + user.Id, user);
-            function.WriteLog(user.Id.ToString(), "生成邀请二维码");
+            string Mobile = function.CheckNull(user.Mobile);
+            if (!Mobile.Contains("*") && Mobile.Substring(0, 1) == "1" && Mobile.Length == 11)
+            {
+                string ParentNav = user.ParentNav;
+                if (!string.IsNullOrEmpty(ParentNav))
+                {
+                    string NewParentNav = "";
+                    int NewParentUserId = 1;
+                    string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
+                    Array.Reverse(ParentNavList);
+                    int i = 0;
+                    foreach (string ParentId in ParentNavList)
+                    {
+                        int puid = int.Parse(ParentId);
+                        Users puser = db.Users.FirstOrDefault(m => m.Id == puid);
+                        if (puser != null)
+                        {
+                            Mobile = function.CheckNull(puser.Mobile);
+                            if (!Mobile.Contains("*") && Mobile.Substring(0, 1) == "1" && Mobile.Length == 11)
+                            {
+                                i += 1;
+                                NewParentNav = "," + ParentId + "," + NewParentNav;
+                                if (i == 1)
+                                {
+                                    NewParentUserId = puid;
+                                }
+                            }
+                        }
+                    }
+                    if (string.IsNullOrEmpty(NewParentNav))
+                    {
+                        NewParentNav = ",1,";
+                    }
+                    user.ParentNav = NewParentNav;
+                    user.ParentUserId = NewParentUserId;
+                }
+                else
+                {
+                    user.ParentNav = ",1,";
+                    user.ParentUserId = 1;
+                }
+                db.SaveChanges();
+            }
         }
-        function.WriteLog("finish", "生成邀请二维码");
     }
 }

+ 1 - 1
AppStart/Timer/TradeStatTimer.cs

@@ -179,7 +179,7 @@ public class TradeStatTimer
             }
             else
             {
-                Thread.Sleep(3600000);
+                Thread.Sleep(900000);
             }
         }
     }

+ 8 - 18
Controllers/HomeController.cs

@@ -125,23 +125,6 @@ namespace MySystem.Controllers
             db.Dispose();
         }
 
-        public string chkact(int Id = 0)
-        {
-            if (Id > 0)
-            {
-                SycnSpActiveService.Instance.Start(Id);
-            }
-            return "ok";
-        }
-        public string chktrade(int Id = 0)
-        {
-            if (Id > 0)
-            {
-                SycnSpTradeService.Instance.Start(Id);
-            }
-            return "ok";
-        }
-
         // 补激活奖励
         public string setmeruser(string date)
         {
@@ -663,9 +646,16 @@ namespace MySystem.Controllers
             return function.MD532(pwd);
         }
 
+        //重置本月团队交易额
+        public string resetMonthTrade()
+        {
+            
+            return "";
+        }
+
         public string test()
         {
-            StatService.Instance.testStatTrade("2022-04-04");
+            TestHelper.Instance.DoUsers(new WebCMSEntities(), 483);
             return "ok";
         }
     }

+ 15 - 10
Startup.cs

@@ -88,11 +88,11 @@ namespace MySystem
             // services.AddHostedService<TradeService>();
             // services.AddHostedService<TeamTopService>();
             // services.AddHostedService<PopService>();
-            
-            // services.AddHostedService<TimerStatTimer>(); //实时统计创客、激活商户数
-            // services.AddHostedService<PosTradeStatTimer>(); // 统计头天的交易额、商户型创客、激活奖励、开机奖励
             // services.AddHostedService<SycnSpTimer>(); //同步SP数据
-            // services.AddHostedService<AlipayPayBack2Timer>(); //支付宝回调处理
+            
+            services.AddHostedService<TimerStatTimer>(); //实时统计创客、激活商户数
+            services.AddHostedService<PosTradeStatTimer>(); // 统计头天的交易额、商户型创客、激活奖励、开机奖励
+            services.AddHostedService<AlipayPayBack2Timer>(); //支付宝回调处理
 
             //services.AddHttpContextAccessor();
 
@@ -216,15 +216,20 @@ namespace MySystem
 
             // app.UseMiddleware<GraphQLMiddleware>();
 
-            
+
             // TradeStatTimer2.Instance.Start(); //交易统计
-            // ProfitHelper.Instance.StatProfit("202203");
 
             //必须打开的
-            // ActiveRewardTimer.Instance.Start(); //实时处理激活记录
-            // TradeStatTimer.Instance.Start(); //交易统计
-            // ChangePosTimer.Instance.Start(); //售后换新执行机具数据转移
-            // RabbitMQClient.Instance.StartReceive("MakeReferenceQrCode");
+            ActiveRewardTimer.Instance.Start(); //实时处理激活记录
+            TradeStatTimer.Instance.Start(); //交易统计
+            ChangePosTimer.Instance.Start(); //售后换新执行机具数据转移
+            RabbitMQClient.Instance.StartReceive("MakeReferenceQrCode");
+            SycnSpBindService.Instance.Start(); //同步SP绑定数据
+            SycnSpMerchantService.Instance.Start(); //同步SP商户数据
+            SycnSpActiveService.Instance.Start(); //同步SP激活数据
+            SycnSpTradeService.Instance.Start(); //同步SP交易数据
+            // ProfitHelper.Instance.StatProfit("202203"); //统计分润
+            // TestHelper.Instance.Start();
             //必须打开的
 
             // RabbitMQClient.Instance.StartReceive("MerchantConfirmList");

二進制
bin/Debug/netcoreapp3.0/MySystem.dll


二進制
bin/Debug/netcoreapp3.0/MySystem.pdb


二進制
bin/release/netcoreapp3.0/MySystem.dll


二進制
bin/release/netcoreapp3.0/MySystem.pdb


二進制
obj/Debug/netcoreapp3.0/MySystem.dll


二進制
obj/Debug/netcoreapp3.0/MySystem.pdb


二進制
obj/release/netcoreapp3.0/MySystem.dll


二進制
obj/release/netcoreapp3.0/MySystem.pdb