浏览代码

Merge branch 'release' into develop

lichunlei 2 年之前
父节点
当前提交
368558776d

+ 2 - 2
AppStart/Helper/AlipayPayBack2Service.cs

@@ -273,8 +273,8 @@ namespace MySystem
                                 while(ParentUserId > 0)
                                 {
                                     Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
-                                    int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
-                                    int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
+                                    int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
+                                    int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
                                     int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
                                     function.WriteLog("MakerCode:" + puser.MakerCode, "推荐下单奖励监控日志");
                                     function.WriteLog("machineCount:" + machineCount, "推荐下单奖励监控日志");

+ 51 - 4
AppStart/Helper/StatService.cs

@@ -256,7 +256,7 @@ namespace MySystem
                 // PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId && !string.IsNullOrEmpty(m.MerIdcardNo));
                 // PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId && m.Sort == 1);
                 PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
-                if (merchant != null)
+                if (merchant != null && pos.ActivationTime.Value <= pos.BindingTime.Value.AddDays(30))
                 {
                     // PosMerchantOtherInfo otherInfo = db.PosMerchantOtherInfo.FirstOrDefault(m => m.CertId == merchant.MerIdcardNo && m.PrizeFlag1 == 0);
                     // if (otherInfo != null)
@@ -850,8 +850,8 @@ namespace MySystem
                                     Users puser = db.Users.FirstOrDefault(m => m.Id == UserId && m.AuthFlag == 1);
                                     if (puser != null && Prize > 0)
                                     {
-                                        int machineCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
-                                        int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
+                                        int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
+                                        int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
                                         int couponCount = db.PosCoupons.Count(m => m.UserId == puser.Id && m.IsUse == 0); //判断是否拥有3张券
                                         // int BigCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.BrandId == 3); //判断是否拥有2台大机
                                         // int BigActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1 && m.BrandId == 3); //判断是否拥有2台激活大机(不限购买或赠送)
@@ -1722,6 +1722,7 @@ namespace MySystem
             WebCMSEntities db = new WebCMSEntities();
             try
             {
+                OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
                 function.WriteLog(DateTime.Now.ToString(), "创客升级日志");
                 DateTime start = DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01 00:00:00");
                 DateTime end = start.AddDays(1);
@@ -1753,7 +1754,29 @@ namespace MySystem
                                 {
                                     AfterLevel = set.Id;
                                 }
-                                if (AfterLevel > BeforeLevel && AfterLevel > 1)
+
+                                // K6以上计算小市场是否达标
+                                // 升级逻辑
+                                bool upFlag = true;
+                                if(AfterLevel > 5)
+                                {
+                                    DataTable dt = OtherMySqlConn.dtable("select UserId,sum(HelpNonDirectTradeAmt+NotHelpNonDirectTradeAmt+HelpNonDirectDebitTradeAmt+NotHelpNonDirectDebitTradeAmt) from TradeDaySummary where UserId in (select Id from Users where ParentUserId=" + user.Id + ") and TradeMonth='" + TradeMonth + "' and SeoTitle='team' group by UserId order by sum(HelpNonDirectTradeAmt+NotHelpNonDirectTradeAmt+HelpNonDirectDebitTradeAmt+NotHelpNonDirectDebitTradeAmt) desc");
+                                    int index = 0;
+                                    decimal TradeAmt = 0;
+                                    foreach(DataRow dr in dt.Rows)
+                                    {
+                                        index += 1;
+                                        if(index > 1)
+                                        {
+                                            TradeAmt += decimal.Parse(dr[1].ToString());
+                                        }
+                                    }
+                                    if(TradeAmt < 12000000)
+                                    {
+                                        upFlag = false;
+                                    }
+                                }
+                                if (AfterLevel > BeforeLevel && AfterLevel > 1 && upFlag)
                                 {
                                     function.WriteLog("升级:" + user.Id.ToString() + BeforeLevel + "->" + AfterLevel, "创客升级日志");
                                     user.UserLevel = AfterLevel;
@@ -1772,6 +1795,30 @@ namespace MySystem
                                     });
                                     db.SaveChanges();
                                 }
+                                // 降级逻辑
+                                // if(!upFlag && AfterLevel > 5)
+                                // {
+                                //     AfterLevel = 5;
+                                // }
+                                // if (AfterLevel < BeforeLevel && BeforeLevel > 1)
+                                // {
+                                //     function.WriteLog("降级:" + user.Id.ToString() + AfterLevel + "->" + BeforeLevel, "创客升级日志");
+                                //     user.UserLevel = AfterLevel;
+                                //     db.UserRank.Add(new UserRank()
+                                //     {
+                                //         CreateDate = DateTime.Now,
+                                //         UpdateDate = DateTime.Now,
+                                //         UserId = user.Id, //创客
+                                //         WhiteRank = BeforeLevel,
+                                //         Rank = AfterLevel, //当前等级
+                                //         StatYear = DateTime.Now.Year, //统计年份
+                                //         StatMonth = DateTime.Now.Month, //统计月份
+                                //         TradeAmt = TradeAmount, //团队交易总额
+                                //         UpgradeFlag = 0, //升级标识
+                                //         OperateDate = DateTime.Now, //操作时间
+                                //     });
+                                //     db.SaveChanges();
+                                // }
                             }
                             startid = subuser.Id;
                         }

+ 93 - 38
AppStart/Helper/SycnSpServer/SycnSpBindService.cs

@@ -30,58 +30,113 @@ namespace MySystem
                     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();
+                    var Binds = spdb.BindRecord.Select(m => new { m.Id, m.CreateTime, m.Status, m.MerNo, m.MerSnNo, m.ProductType, m.Field1 }).Where(m => m.CreateTime >= start && m.Status == 1).OrderByDescending(m => m.Id).ToList();
                     foreach (var Bind in Binds)
                     {
                         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)
+                            if(Bind.Field1 == "解绑" && Bind.ProductType == "1")
                             {
-                                pos.BindingState = 1;
-                                pos.BindingTime = Bind.CreateTime;
-                                pos.Status = 0;
-                                PxcModels.MachineForMerNo merFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.MerNo);
-                                if (merFor == null)
+                                // string PosSn = Bind.MerSnNo;
+                                // string MerNo = Bind.MerNo;
+                                // PxcModels.MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn);
+                                // PxcModels.MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
+                                // PxcModels.PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
+                                // if (pos.ActivationState == 0 && pos.BuyUserId > 0 && pos.BindingState == 0)
+                                // {
+                                //     if (forMerNo != null)
+                                //     {
+                                //         db.MachineForMerNo.Remove(forMerNo);
+                                //         db.SaveChanges();
+                                //     }
+                                //     db.MachineUnBind.Add(new PxcModels.MachineUnBind()
+                                //     {
+                                //         CreateDate = DateTime.Now,
+                                //         MerchantId = pos.BindMerchantId,
+                                //         AuditDate = DateTime.Now,
+                                //         AuditDesc = "金控推送解绑",
+                                //         AuditStatus = 1,
+                                //         SnNo = pos.PosSn,
+                                //         BrandId = pos.BrandId,
+                                //         UserId = pos.BuyUserId,
+                                //         ApplyNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
+                                //     });
+                                //     pos.BindMerchantId = 0;
+                                //     pos.BindingState = 0;
+                                //     pos.BindingTime = DateTime.Parse("1900-01-01");
+                                //     pos.UserId = pos.BuyUserId;
+                                //     string IdBrand = pos.BuyUserId + "_" + pos.BrandId;
+                                //     PxcModels.UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
+                                //     if (userData == null)
+                                //     {
+                                //         userData = db.UserMachineData.Add(new PxcModels.UserMachineData()
+                                //         {
+                                //             IdBrand = IdBrand,
+                                //         }).Entity;
+                                //         db.SaveChanges();
+                                //     }
+                                //     userData.BindCount -= 1;
+                                //     userData.UnBindCount += 1;
+                                //     db.SaveChanges();
+
+                                //     BindRecord edit = spdb.BindRecord.FirstOrDefault(m => m.Id == Bind.Id);
+                                //     if (edit != null)
+                                //     {
+                                //         edit.Status = 2;
+                                //         spdb.SaveChanges();
+                                //     }
+                                // }
+                            }
+                            else
+                            {
+                                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)
                                 {
-                                    merFor = db.MachineForMerNo.Add(new PxcModels.MachineForMerNo()
+                                    pos.BindingState = 1;
+                                    pos.BindingTime = Bind.CreateTime;
+                                    pos.Status = 0;
+                                    PxcModels.MachineForMerNo merFor = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Bind.MerNo);
+                                    if (merFor == null)
                                     {
-                                        MerNo = Bind.MerNo,
-                                        SnId = pos.Id,
-                                    }).Entity;
-                                }
-                                else
-                                {
-                                    merFor.SnId = pos.Id;
-                                }
-                                db.SaveChanges();
-                                RedisDbconn.Instance.Set("PosMachinesTwo", pos);
+                                        merFor = db.MachineForMerNo.Add(new PxcModels.MachineForMerNo()
+                                        {
+                                            MerNo = Bind.MerNo,
+                                            SnId = pos.Id,
+                                        }).Entity;
+                                    }
+                                    else
+                                    {
+                                        merFor.SnId = pos.Id;
+                                    }
+                                    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)
-                                {
-                                    MachineData = db.UserMachineData.Add(new PxcModels.UserMachineData()
+                                    string IdBrand = pos.UserId + "_" + pos.BrandId;
+                                    PxcModels.UserMachineData MachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
+                                    if (MachineData == null)
                                     {
-                                        IdBrand = IdBrand,
-                                    }).Entity;
+                                        MachineData = db.UserMachineData.Add(new PxcModels.UserMachineData()
+                                        {
+                                            IdBrand = IdBrand,
+                                        }).Entity;
+                                        db.SaveChanges();
+                                    }
+                                    MachineData.BindCount += 1;
+                                    MachineData.UnBindCount -= 1;
                                     db.SaveChanges();
+                                    RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, MachineData);
                                 }
-                                MachineData.BindCount += 1;
-                                MachineData.UnBindCount -= 1;
-                                db.SaveChanges();
-                                tran.Commit();
-                                RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, MachineData);
                             }
+                            tran.Commit();
                         }
                         catch (Exception ex)
                         {

+ 452 - 0
AppStart/Timer/RedPackageV2Helper.cs

@@ -0,0 +1,452 @@
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Linq;
+using System.Data;
+using MySystem;
+using MySystem.PxcModels;
+using Library;
+
+public class RedPackageV2Helper
+{
+    public readonly static RedPackageV2Helper Instance = new RedPackageV2Helper();
+    private RedPackageV2Helper()
+    {
+    }
+
+    public void Start()
+    {
+        Thread th = new Thread(DoWorks);
+        th.IsBackground = true;
+        th.Start();
+    }
+
+    private void DoWorks()
+    {
+        while (true)
+        {
+            if (DateTime.Now.Hour >= 3)
+            {
+                string ActivityDate = DateTime.Now.AddDays(-1).ToString("yyyyMMdd");
+                string check = function.ReadInstance("/Activity/RedPackage/" + ActivityDate + ".txt");
+                if (string.IsNullOrEmpty(check))
+                {
+                    function.WritePage("/Activity/RedPackage/", ActivityDate + ".txt", DateTime.Now.ToString());
+                    function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "生成指定未领取红包日志");
+                    WebCMSEntities db = new WebCMSEntities();
+                    try
+                    {
+                        // decimal TotalPrize = 888.88M;
+                        // DateTime start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 07:50:00");
+                        // DateTime today = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
+                        // string PreDate = DateTime.Now.AddDays(-2).ToString("yyyyMMdd");
+                        List<decimal> list = new List<decimal>();
+                        list.Add(88.88M);
+                        list.Add(40.76M);
+                        list.Add(38.88M);
+                        list.Add(18.88M);
+                        list.Add(15.88M);
+                        list.Add(11.88M);
+                        list.Add(8.88M);
+                        list.Add(8.88M);
+                        list.Add(8.88M);
+                        list.Add(8.88M);
+                        list.Add(8.88M);
+                        list.Add(8.88M);
+                        list.Add(8.88M);
+                        list.Add(8.88M);
+                        list.Add(8.88M);
+                        list.Add(8.88M);
+                        list.Add(8.88M);
+                        list.Add(8.88M);
+                        list.Add(8.88M);
+                        list.Add(8.88M);
+                        list.Add(8.88M);
+                        list.Add(8.88M);
+                        list.Add(8.88M);
+                        list.Add(8.88M);
+                        list.Add(8.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(5.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(3.88M);
+                        list.Add(1.88M);
+                        list.Add(1.88M);
+                        list.Add(1.88M);
+                        list.Add(1.88M);
+                        list.Add(1.88M);
+                        list.Add(1.88M);
+                        list.Add(1.88M);
+                        list.Add(1.88M);
+                        list.Add(1.88M);
+                        list.Add(1.88M);
+                        list.Add(1.88M);
+                        list.Add(1.88M);
+                        list.Add(1.88M);
+                        list.Add(1.88M);
+                        list.Add(1.88M);
+                        list.Add(1.88M);
+                        list.Add(1.88M);
+                        list.Add(1.88M);
+                        list.Add(1.88M);
+                        list.Add(1.88M);
+                        // TotalPrize -= 88.88M;
+                        // for (int i = 1; i < 150; i++)
+                        // {
+                        //     list.Add(0.88M);
+                        //     TotalPrize -= 0.88M;
+                        // }
+                        // for (int i = 0; i < 150; i++)
+                        // {
+                        //     if (TotalPrize > 0)
+                        //     {
+                        //         int BigPrize = function.get_Random(1, 150);
+                        //         decimal PrizeAmt = (decimal)function.get_Random(88, 1000) / 100M;
+                        //         if (TotalPrize > PrizeAmt)
+                        //         {
+                        //             list[BigPrize] += PrizeAmt;
+                        //             TotalPrize -= PrizeAmt;
+                        //         }
+                        //         else
+                        //         {
+                        //             list[BigPrize] += TotalPrize;
+                        //             TotalPrize = 0;
+                        //         }
+                        //     }
+                        //     else
+                        //     {
+                        //         break;
+                        //     }
+                        // }
+                        foreach (decimal PrizeAmt in list)
+                        {
+                            db.ActivityRedPackageStock.Add(new ActivityRedPackageStock()
+                            {
+                                CreateDate = DateTime.Now,
+                                PrizeAmt = PrizeAmt,
+                                ActivityDate = ActivityDate,
+                                SeoTitle = function.get_Random(20),
+                            });
+                        }
+                        db.SaveChanges();
+                    }
+                    catch (Exception ex)
+                    {
+                        function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "生成指定未领取红包异常");
+                    }
+                    db.Dispose();
+                    function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "生成指定未领取红包日志");
+                }
+                redisStock();
+            }
+            Thread.Sleep(60000);
+        }
+    }
+
+    // 将红包加入缓存
+    public void redisStock()
+    {
+        string ActivityDate = DateTime.Now.AddDays(-1).ToString("yyyyMMdd");
+        string check = function.ReadInstance("/Activity/RedPackageRedis/" + ActivityDate + ".txt");
+        if (!string.IsNullOrEmpty(check))
+        {
+            return;
+        }
+        function.WritePage("/Activity/RedPackageRedis/", ActivityDate + ".txt", DateTime.Now.ToString());
+        WebCMSEntities db = new WebCMSEntities();
+        List<ActivityRedPackageStock> list = db.ActivityRedPackageStock.Where(m => m.ActivityDate == ActivityDate && m.PrizeAmt != 88.88M).OrderBy(m => m.SeoTitle).ToList();
+        int i = 0;
+        foreach(ActivityRedPackageStock sub in list)
+        {
+            i += 1;
+            if(i == 18)
+            {
+                ActivityRedPackageStock best = db.ActivityRedPackageStock.FirstOrDefault(m => m.ActivityDate == ActivityDate && m.PrizeAmt == 88.88M);
+                if(best != null)
+                {
+                    RedisDbconn.Instance.AddList("RedPackageList:" + ActivityDate, best);
+                }
+            }
+            RedisDbconn.Instance.AddList("RedPackageList:" + ActivityDate, sub);
+        }
+
+        string PreDate = DateTime.Now.AddDays(-2).ToString("yyyyMMdd");
+        string PreMakerCode = "";
+        string PreRealName = "";
+        decimal PrePrizeAmt = 0;
+        bool checkPre = db.ActivityRedPackageStock.Any(m => m.ActivityDate == PreDate);
+        if (checkPre)
+        {
+            ActivityRedPackageStock preInfo = db.ActivityRedPackageStock.Where(m => m.ActivityDate == PreDate).OrderByDescending(m => m.PrizeAmt).FirstOrDefault();
+            if (preInfo != null)
+            {
+                Users user = db.Users.FirstOrDefault(m => m.Id == preInfo.UserId) ?? new Users();
+                PreMakerCode = user.MakerCode;
+                PreRealName = user.RealName;
+                PrePrizeAmt = preInfo.PrizeAmt;
+                RedisDbconn.Instance.Set("PreInfoString:" + PreDate, PreMakerCode + "|" + PreRealName + "|" + PrePrizeAmt);
+                RedisDbconn.Instance.SetExpire("PreInfoString:" + PreDate, 7200);
+            }
+        }
+        db.Dispose();
+    }
+
+
+
+
+
+    public void StartStatTop10()
+    {
+        Thread th = new Thread(StartStatTop10Do);
+        th.IsBackground = true;
+        th.Start();
+    }
+
+    private void StartStatTop10Do()
+    {
+        while (true)
+        {
+            if(DateTime.Now.Hour >= 7 && DateTime.Now.Hour <= 10)
+            {
+                OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
+                OtherMySqlConn.op("delete from ActivityRedPackageTop10");
+                using (WebCMSEntities db = new WebCMSEntities())
+                {
+                    DataTable dt = OtherMySqlConn.dtable("select UserId,sum(PrizeAmt) from ActivityRedPackageJoins group by UserId order by sum(PrizeAmt) desc");
+                    int index = 0;
+                    foreach (DataRow dr in dt.Rows)
+                    {
+                        index += 1;
+                        int UserId = int.Parse(dr["UserId"].ToString());
+                        decimal PrizeAmt = decimal.Parse(dr[1].ToString());
+                        db.ActivityRedPackageTop10.Add(new ActivityRedPackageTop10()
+                        {
+                            Sort = index,
+                            UserId = UserId,
+                            PrizeAmt = PrizeAmt,
+                            Kind = 1,
+                        });
+                    }
+                    dt = OtherMySqlConn.dtable("select UserId,count(Id) from ActivityRedPackageJoins group by UserId order by count(Id) desc");
+                    index = 0;
+                    foreach (DataRow dr in dt.Rows)
+                    {
+                        index += 1;
+                        int UserId = int.Parse(dr["UserId"].ToString());
+                        int PrizeCount = int.Parse(dr[1].ToString());
+                        db.ActivityRedPackageTop10.Add(new ActivityRedPackageTop10()
+                        {
+                            Sort = index,
+                            UserId = UserId,
+                            TimeNum = PrizeCount,
+                            Kind = 2,
+                        });
+                    }
+                    db.SaveChanges();
+                }
+            }
+            Thread.Sleep(300000);
+        }
+    }
+
+
+    public void StartSendPrize()
+    {
+        Thread th = new Thread(StartSendPrizeNewDo);
+        th.IsBackground = true;
+        th.Start();
+    }
+
+    private void StartSendPrizeNewDo()
+    {
+        while (true)
+        {
+            string content = RedisDbconn.Instance.RPop<string>("RedPrizeQueue");
+            if (!string.IsNullOrEmpty(content))
+            {
+                try
+                {
+                    string[] data = content.Split(':');
+                    int Id = int.Parse(function.CheckInt(data[0]));
+                    int UserId = int.Parse(function.CheckInt(data[1]));
+                    string ActivityDate = data[2];
+                    using (WebCMSEntities db = new WebCMSEntities())
+                    {
+                        ActivityRedPackageStock edit = db.ActivityRedPackageStock.FirstOrDefault(m => m.Id == Id);
+                        if(edit != null)
+                        {
+                            edit.UserId = UserId;
+                            edit.UpdateDate = DateTime.Now;
+                            ActivityRedPackageJoins query = db.ActivityRedPackageJoins.Add(new ActivityRedPackageJoins()
+                            {
+                                CreateDate = DateTime.Now, //创建时间
+                                Status = 1,
+                                UserId = UserId, //创客
+                                ActivityDate = ActivityDate, //期数
+                                PrizeAmt = edit.PrizeAmt,
+                            }).Entity;
+                            db.SaveChanges();
+                            StartGetAccount(db, UserId, query.Id, edit.PrizeAmt);
+                        }
+                    }
+                }
+                catch (Exception ex)
+                {
+                    function.WriteLog(ex.ToString(), "发放红包奖励异常");
+                }
+                Thread.Sleep(200);
+            }
+            else
+            {
+                Thread.Sleep(500);
+            }
+        }
+    }
+    
+    private void StartGetAccount(WebCMSEntities db, int UserId, int Id, decimal PrizeAmt)
+    {
+        try
+        {
+            UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
+            if (account == null)
+            {
+                account = db.UserAccount.Add(new UserAccount()
+                {
+                    Id = UserId,
+                    UserId = UserId,
+                }).Entity;
+                db.SaveChanges();
+            }
+            decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
+            decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
+            decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
+            account.BalanceAmount += PrizeAmt;
+            account.TotalAmount += PrizeAmt;
+            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 = UserId, //创客
+                ChangeType = 31, //变动类型
+                ChangeAmount = PrizeAmt, //变更金额
+                BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
+                AfterTotalAmount = AfterTotalAmount, //变更后总金额
+                BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
+                AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
+                BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
+                AfterBalanceAmount = AfterBalanceAmount, //变更后余额
+                QueryCount = Id,
+                Remark = "开机抢红包活动",
+            }).Entity;
+            db.SaveChanges();
+        }
+        catch (Exception ex)
+        {
+            function.WriteLog(ex.ToString(), "领取红包奖励异常");
+        }
+    }    
+}

+ 4 - 4
Controllers/HomeController.cs

@@ -1035,8 +1035,8 @@ namespace MySystem.Controllers
                                 while (ParentUserId > 0)
                                 {
                                     Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
-                                    int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
-                                    int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
+                                    int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
+                                    int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
                                     int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
                                     if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
                                     {
@@ -1178,8 +1178,8 @@ namespace MySystem.Controllers
                                 while(ParentUserId > 0)
                                 {
                                     Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
-                                    int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
-                                    int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
+                                    int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.PosSnType == 0 && m.ActivationState == 0); //判断是否拥有3台购买机
+                                    int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
                                     int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
                                     if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
                                     {

+ 4 - 4
Startup.cs

@@ -200,9 +200,9 @@ namespace MySystem
             SycnSpTradeService.Instance.Start(); //同步SP交易数据
             SycnSpChangeBindService.Instance.Start(); //同步SP换绑数据
             SycnSpUnBindService.Instance.Start(); //同步SP解绑数据
-            RedPackageHelper.Instance.Start(); //每天生成300个红包
-            RedPackageHelper.Instance.StartStatTop10(); //红包活动统计排行
-            RedPackageHelper.Instance.StartSendPrize(); //红包活动发奖
+            RedPackageV2Helper.Instance.Start(); //每天生成红包
+            RedPackageV2Helper.Instance.StartStatTop10(); //红包活动统计排行
+            RedPackageV2Helper.Instance.StartSendPrize(); //红包活动发奖
             BalancePayBackService.Instance.Start(); //余额支付队列
             ReservePayBackService.Instance.Start(); //储备金支付队列
             LeaderPrizeService.Instance.Start(); //大盟主奖励发奖
@@ -210,7 +210,7 @@ namespace MySystem
             RecommendActStatService.Instance.Start(); //推荐王奖励数据统计
             //必须打开的
 
-            StoreApplyHelper.Instance.Start();
+            StoreApplyHelper.Instance.Start(); // 每月1号重置仓库额度
             StoreApplyHelper.Instance.StartEverTime();
             // StatService.Instance.StartPosActNum(); //实时统计激活数
             // StatService.Instance.StartNewUserNum(); //实时统计新增创客数