ソースを参照

合伙人逻辑写完

lcl 1 年間 前
コミット
48f19808ba

+ 2 - 460
AppStart/Helper/AlipayPayBack2Service.cs

@@ -245,7 +245,7 @@ namespace MySystem
                             Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
                             //自留券数量清除
                             CancelStayCoupon(db, order.UserId, 5);
-                            // if (check) OperateReserveBackFor(db, user.Id, 10000);
+                            if (check) OperateReserveBackFor(db, user.Id, 10000);
                             //预设小盟主职级
                             LeaderPreUserLevel(db, order.UserId, 1);
                             AddLeader(db, order.UserId, 1);
@@ -282,465 +282,7 @@ namespace MySystem
                     }
 
                     //推荐下单奖励
-                    List<int> LkbIds = new List<int>(); //来客吧组合包
-                    LkbIds.Add(77);
-                    LkbIds.Add(78);
-                    LkbIds.Add(79);
-                    if (pro.ProductId == 10 || pro.ProductId == 11 || LkbIds.Contains(pro.ProductId))
-                    {
-                        bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
-                        function.WriteLog("OrderId:" + OrderId, "推荐下单奖励监控日志");
-                        function.WriteLog("checkPrize:" + checkPrize, "推荐下单奖励监控日志");
-                        if (checkPrize)
-                        {
-                            Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
-                            if (user != null)
-                            {
-                                if(user.LeaderLevel > 0 || user.UserType == 1) //盟主或运营中心
-                                {
-                                    //获得100元奖励
-                                    OpAccount(db, order, order.UserId, 100, pro.ProductCount);
-                                }
-                            }
-                        }
-                        else
-                        {
-                            Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
-                            if (user != null)
-                            {
-                                bool directPrize = false; //直推奖标记
-                                bool bigLeaderPrize = false; //大盟主券标记
-                                bool operateFlag = false; //运营中心标记
-                                bool buyPrize = false; //返100购机奖励标记或返100购机奖励标记-运营中心
-                                int leaderFlag = 0; //返600备用金标记
-                                if(user.LeaderLevel > 0 || user.UserType == 1) //盟主或运营中心
-                                {
-                                    if(user.LeaderLevel > 0)
-                                    {
-                                        UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId) ?? new UserAccount();
-                                        if(acccount.LeaderReserve >= order.TotalPrice)
-                                        {
-                                            if(order.PayMode == 4)
-                                            {
-                                                //扣减备用金
-                                                OpReserve(db, order, order.UserId, order.TotalPrice, 0, 0, "商城购机(储备金支付)");
-                                            }
-                                        }
-                                        string parentString = user.ParentNav + "," + order.UserId + ",";
-                                        string[] puids = parentString.Replace(",,", ",").Trim(',').Split(',');
-                                        Array.Reverse(puids);
-                                        bool getFlag = true;
-                                        foreach(string puid in puids)
-                                        {
-                                            int puidNum = int.Parse(function.CheckInt(puid));
-                                            Users puser = db.Users.FirstOrDefault(m => m.Id == puidNum) ?? new Users();
-                                            if(puser.LeaderLevel > 0 && getFlag)
-                                            {
-                                                UserAccount pacccount = db.UserAccount.FirstOrDefault(m => m.Id == puidNum) ?? new UserAccount();
-                                                if(pacccount.LeaderReserve >= 400 * pro.ProductCount)
-                                                {
-                                                    //获得100元奖励
-                                                    OpAccount(db, order, puidNum, 100, pro.ProductCount);
-                                                    getFlag = false;
-                                                    break;
-                                                }
-                                            }
-                                        }
-
-                                        //小盟主在有效期内购券后预设职级,仍为K5,但增加一条预设为K1的预设记录
-                                        if(user.LeaderLevel == 1)
-                                        {
-                                            DateTime now = DateTime.Now;
-                                            bool checkLeader = db.Leaders.Any(m => m.Id == user.Id && m.ExpiredDate > now);
-                                            if(checkLeader)
-                                            {
-                                                PreUserLevel(db, user.Id, 1, DateTime.Parse("2025-01-01 00:00:00"));
-                                            }
-                                        }
-                                    }
-                                    else if(user.UserType == 1)
-                                    {
-                                        //获得100元奖励
-                                        OpAccount(db, order, order.UserId, 100, pro.ProductCount);
-                                    }
-                                    //推荐奖励
-                                    DirectPrize(db, order.Id, order.UserId, pro.ProductCount);
-                                    //推荐下单上级获得30天的机具循环天数(盟主自己得)
-                                    var posList = db.PosMachinesTwo.Select(m => new { m.Id, m.UserId, m.BindingState, m.RecycEndDate }).Where(m => m.UserId == order.UserId && m.BindingState == 0 && m.RecycEndDate != null).ToList();
-                                    foreach (var subPos in posList)
-                                    {
-                                        PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
-                                        if (pos != null)
-                                        {
-                                            pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
-                                        }
-                                    }
-                                    db.SaveChanges();
-                                    if(order.PayMode == 4 && user.LeaderLevel > 0) //使用盟主储蓄金,并且是盟主
-                                    {
-                                        if(user.UserType == 1)
-                                        {
-                                            if(couponIds.Count > 0)
-                                            {
-                                                UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == user.Id) ?? new UserAccount();
-                                                foreach(int couponId in couponIds)
-                                                {
-                                                    PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
-                                                    if(coupon != null)
-                                                    {
-                                                        if(acccount.LeaderReserve >= 400 * pro.ProductCount)
-                                                        {
-                                                            coupon.LeaderUserId = user.Id;
-                                                        }
-                                                        coupon.OpId = user.Id;
-                                                    }
-                                                }
-                                            }
-                                            db.SaveChanges();
-                                        }
-                                        else
-                                        {
-                                            //寻找最近运营中心额度大于0的运营中心
-                                            int PUserId = user.Id;
-                                            bool OperateFlag = true;
-                                            bool OncePrizeFlag1 = true;
-                                            while(PUserId > 0)
-                                            {
-                                                Users puser = db.Users.FirstOrDefault(m => m.Id == PUserId);
-                                                if(puser != null)
-                                                {
-                                                    if(puser.UserType == 1 && OperateFlag == true) //运营中心
-                                                    {
-                                                        if(couponIds.Count > 0)
-                                                        {
-                                                            UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId) ?? new UserAccount();
-                                                            foreach(int couponId in couponIds)
-                                                            {
-                                                                PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
-                                                                if(coupon != null)
-                                                                {
-                                                                    if(acccount.LeaderReserve >= 400 * pro.ProductCount)
-                                                                    {
-                                                                        coupon.LeaderUserId = user.Id;
-                                                                    }
-                                                                    coupon.OpId = puser.Id;
-                                                                }
-                                                            }
-                                                            db.SaveChanges();
-                                                            if(acccount.LeaderReserve >= 400 * pro.ProductCount && OncePrizeFlag1)
-                                                            {
-                                                                //扣减备用金
-                                                                OpReserve(db, order, order.UserId, 400 * pro.ProductCount, 2, 0, "商城购机");
-                                                                //返回到余额
-                                                                OpLeaderAccount(db, order, order.UserId, 400, pro.ProductCount);
-                                                                OncePrizeFlag1 = false;
-                                                            }
-                                                            OperateFlag = false;
-                                                        }
-                                                        else if(LkbIds.Contains(pro.ProductId)) //来客吧组合包
-                                                        {
-                                                            UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId) ?? new UserAccount();
-                                                            if(acccount.LeaderReserve >= 400 * pro.ProductCount && OncePrizeFlag1)
-                                                            {
-                                                                //扣减备用金
-                                                                OpReserve(db, order, order.UserId, 400 * pro.ProductCount, 2, 0, "商城购机");
-                                                                //返回到余额
-                                                                OpLeaderAccount(db, order, order.UserId, 400, pro.ProductCount);
-                                                                OncePrizeFlag1 = false;
-                                                            }
-                                                            OperateFlag = false;
-                                                        }
-                                                    }
-                                                    PUserId = puser.ParentUserId;
-                                                }
-                                                else
-                                                {
-                                                    PUserId = 0;
-                                                }
-                                            }
-                                        }
-                                    }
-                                    else if(order.PayMode == 4 && user.UserType == 1) //使用盟主储蓄金,并且是运营中心
-                                    {
-                                        if(couponIds.Count > 0)
-                                        {
-                                            foreach(int couponId in couponIds)
-                                            {
-                                                PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
-                                                if(coupon != null)
-                                                {
-                                                    coupon.OpId = user.Id;
-                                                }
-                                            }
-                                        } 
-                                        db.SaveChanges();
-                                        //寻找最近储蓄金充足的大盟主
-                                        int PUserId = user.Id;
-                                        bool LeaderFlag = true;
-                                        bool OncePrizeFlag2 = true;
-                                        while(PUserId > 0)
-                                        {
-                                            Users puser = db.Users.FirstOrDefault(m => m.Id == PUserId);
-                                            if(puser != null)
-                                            {
-                                                if(puser.LeaderLevel == 2 && LeaderFlag == true) //大盟主
-                                                {
-                                                    if(couponIds.Count > 0)
-                                                    {
-                                                        UserAccount pacccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
-                                                        foreach(int couponId in couponIds)
-                                                        {
-                                                            PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
-                                                            if(coupon != null && pacccount.LeaderReserve >= 400 * pro.ProductCount)
-                                                            {
-                                                                coupon.LeaderUserId = puser.Id;
-                                                            }
-                                                        }
-                                                        db.SaveChanges();
-                                                        UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId) ?? new UserAccount();
-                                                        if(acccount.LeaderReserve >= 400 * pro.ProductCount && OncePrizeFlag2)
-                                                        {
-                                                            //扣减备用金
-                                                            OpReserve(db, order, order.UserId, 400 * pro.ProductCount, 2, 0, "商城购机");
-                                                            //返回到余额
-                                                            OpLeaderAccount(db, order, order.UserId, 400, pro.ProductCount);
-                                                            OncePrizeFlag2 = false;
-                                                        }
-                                                        LeaderFlag = false;
-                                                    }
-                                                    else if(LkbIds.Contains(pro.ProductId))
-                                                    {
-                                                        UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId) ?? new UserAccount();
-                                                        if(acccount.LeaderReserve >= 400 * pro.ProductCount && OncePrizeFlag2)
-                                                        {
-                                                            //扣减备用金
-                                                            OpReserve(db, order, order.UserId, 400 * pro.ProductCount, 2, 0, "商城购机");
-                                                            //返回到余额
-                                                            OpLeaderAccount(db, order, order.UserId, 400, pro.ProductCount);
-                                                            OncePrizeFlag2 = false;
-                                                        }
-                                                        LeaderFlag = false;
-                                                    }
-                                                }
-                                                PUserId = puser.ParentUserId;
-                                            }
-                                            else
-                                            {
-                                                PUserId = 0;
-                                            }
-                                        }
-                                    }
-                                    else
-                                    {
-                                        //寻找最近储蓄金充足的大盟主及最近运营中心额度大于0的运营中心(含自身)
-                                        int PUserId = user.Id;
-                                        int LeaderFlag = 0;
-                                        bool OperateFlag = true;
-                                        bool OncePrizeFlag3 = true;
-                                        while(PUserId > 0)
-                                        {
-                                            Users puser = db.Users.FirstOrDefault(m => m.Id == PUserId);
-                                            if(puser != null)
-                                            {
-                                                if(puser.LeaderLevel > 0 && puser.LeaderLevel > LeaderFlag && LeaderFlag < 2) //大盟主
-                                                {
-                                                    if(couponIds.Count > 0)
-                                                    {
-                                                        if(puser.LeaderLevel == 2)
-                                                        {
-                                                            UserAccount pacccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
-                                                            foreach(int couponId in couponIds)
-                                                            {
-                                                                PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
-                                                                if(coupon != null && pacccount.LeaderReserve >= 400 * pro.ProductCount)
-                                                                {
-                                                                    coupon.LeaderUserId = puser.Id;
-                                                                }
-                                                            }
-                                                            db.SaveChanges();
-                                                        }
-                                                        UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
-                                                        if(acccount.LeaderReserve >= 400 * pro.ProductCount && OncePrizeFlag3)
-                                                        {
-                                                            //扣减备用金
-                                                            OpReserve(db, order, puser.Id, 400 * pro.ProductCount, 2, 0, "商城购机");
-                                                            //返回到余额
-                                                            OpLeaderAccount(db, order, puser.Id, 400, pro.ProductCount);
-                                                            LeaderFlag = puser.LeaderLevel;
-                                                            OncePrizeFlag3 = false;
-                                                        }
-                                                    }
-                                                    else if(LkbIds.Contains(pro.ProductId))
-                                                    {
-                                                        UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
-                                                        if(acccount.LeaderReserve >= 400 * pro.ProductCount && OncePrizeFlag3)
-                                                        {
-                                                            //扣减备用金
-                                                            OpReserve(db, order, puser.Id, 400 * pro.ProductCount, 2, 0, "商城购机");
-                                                            //返回到余额
-                                                            OpLeaderAccount(db, order, puser.Id, 400, pro.ProductCount);
-                                                            LeaderFlag = puser.LeaderLevel;
-                                                            OncePrizeFlag3 = false;
-                                                        }
-                                                    }
-                                                }
-                                                if(puser.UserType == 1 && OperateFlag == true) //运营中心
-                                                {
-                                                    if(couponIds.Count > 0)
-                                                    {
-                                                        foreach(int couponId in couponIds)
-                                                        {
-                                                            PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
-                                                            if(coupon != null)
-                                                            {
-                                                                coupon.OpId = puser.Id;
-                                                            }
-                                                        }
-                                                        db.SaveChanges();
-                                                        OperateFlag = false;
-                                                    }
-                                                }
-                                                PUserId = puser.ParentUserId;
-                                            }
-                                            else
-                                            {
-                                                PUserId = 0;
-                                            }
-                                        }
-                                        //运营中心返额度(下单人自己是运营中心)
-                                        // OperateReserveBackFor(db, order.UserId, order.TotalPrice);
-                                    }
-                                    return;
-                                }
-                                int ParentUserId = user.ParentUserId;
-                                LeaderRankWhite rank = db.LeaderRankWhite.FirstOrDefault(m => m.Id == order.UserId);
-                                if(rank == null)
-                                {
-                                    PreUserLevel(db, order.UserId, 1, DateTime.Now.AddYears(1));
-                                }
-                                // List<int> proids = new List<int>();
-                                // proids.Add(10);
-                                // proids.Add(11);
-                                // 普通创客购买600一组的机具券
-                                bool OncePrizeFlag4 = true;
-                                while(ParentUserId > 0)
-                                {
-                                    Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
-                                    bool valid = Utils.Instance.IsStandardUser(ParentUserId);
-                                    function.WriteLog("是否有效创客:" + valid, "推荐下单奖励监控日志");
-                                    if (valid)
-                                    {
-                                        // 盟主直推奖励,可以每次下单获得
-                                        if(!directPrize)
-                                        {
-                                            DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
-                                            directPrize = true;
-                                        }
-
-                                        //推荐下单上级获得30天的机具循环天数
-                                        var posList = db.PosMachinesTwo.Select(m => new { m.Id, m.UserId, m.BindingState, m.RecycEndDate }).Where(m => m.UserId == ParentUserId && m.BindingState == 0 && m.RecycEndDate != null).ToList();
-                                        foreach (var subPos in posList)
-                                        {
-                                            PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
-                                            if (pos != null)
-                                            {
-                                                pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
-                                            }
-                                        }
-                                        db.SaveChanges();
-                                    }
-                                    if(puser.LeaderLevel > 0)
-                                    {
-                                        function.WriteLog("OrderId:" + order.Id, "监控大盟主购机奖励");
-                                        function.WriteLog("UserId:" + puser.Id, "监控大盟主购机奖励");
-                                        UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
-                                        function.WriteLog("LeaderReserve:" + acccount.LeaderReserve, "监控大盟主购机奖励");
-                                        function.WriteLog("buyPrize:" + buyPrize, "监控大盟主购机奖励");
-                                        if(acccount.LeaderReserve >= 400 * pro.ProductCount && !buyPrize)
-                                        {
-                                            //购机奖励
-                                            OpAccount(db, order, puser.Id, 100, pro.ProductCount);
-                                            buyPrize = true;
-                                        }
-                                        function.WriteLog("LeaderReserve:" + acccount.LeaderReserve, "监控大盟主购机奖励");
-                                        function.WriteLog("leaderFlag:" + leaderFlag, "监控大盟主购机奖励");
-                                        function.WriteLog("OncePrizeFlag4:" + OncePrizeFlag4, "监控大盟主购机奖励");
-                                        function.WriteLog("-----------------------------", "监控大盟主购机奖励");
-                                        if(acccount.LeaderReserve >= 400 * pro.ProductCount && puser.LeaderLevel > leaderFlag && leaderFlag < 2 && OncePrizeFlag4)
-                                        {
-                                            //扣减备用金
-                                            OpReserve(db, order, puser.Id, 400 * pro.ProductCount, 2, order.UserId, "购机奖励");
-                                            //返回到余额
-                                            OpLeaderAccount(db, order, puser.Id, 400, pro.ProductCount);
-                                            leaderFlag = puser.LeaderLevel;
-                                            OncePrizeFlag4 = false;
-                                        }
-                                        //如果是小盟主,则查找该小盟主关联的大盟主储蓄金是否充足,是则给券打上关联大盟主标记
-                                        if(couponIds.Count > 0 && puser.LeaderLevel == 1 && !bigLeaderPrize)
-                                        {
-                                            LeaderAccountRecord leaderItem = db.LeaderAccountRecord.FirstOrDefault(m => m.Sort == puser.Id && m.LeaderId > 0 && m.LeaderReserve >= 400 * pro.ProductCount);
-                                            if(leaderItem != null)
-                                            {
-                                                leaderItem.LeaderReserve -= 400 * pro.ProductCount;
-                                                foreach(int couponId in couponIds)
-                                                {
-                                                    PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
-                                                    if(coupon != null)
-                                                    {
-                                                        coupon.LeaderUserId = leaderItem.LeaderId;
-                                                    }
-                                                }
-                                                db.SaveChanges();
-                                                bigLeaderPrize = true;
-                                            }
-                                        }
-                                        //如果是大盟主,则标记大盟主标签
-                                        if(couponIds.Count > 0 && puser.LeaderLevel == 2 && acccount.LeaderReserve >= 400 * pro.ProductCount && !bigLeaderPrize)
-                                        {
-                                            foreach(int couponId in couponIds)
-                                            {
-                                                PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
-                                                if(coupon != null)
-                                                {
-                                                    coupon.LeaderUserId = puser.Id;
-                                                }
-                                            }
-                                            db.SaveChanges();
-                                            bigLeaderPrize = true;
-                                        }
-                                    }
-                                    if(puser.UserType == 1)
-                                    {
-                                        UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
-                                        if(!buyPrize)
-                                        {
-                                            //购机奖励
-                                            ChangeAccount(db, order, puser.Id, 100 * pro.ProductCount, 120);
-                                            buyPrize = true;
-                                        }
-                                        //标记标签
-                                        if(couponIds.Count > 0 && !operateFlag)
-                                        {
-                                            foreach(int couponId in couponIds)
-                                            {
-                                                PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
-                                                if(coupon != null)
-                                                {
-                                                    coupon.OpId= puser.Id;
-                                                }
-                                            }
-                                            db.SaveChanges();
-                                            operateFlag = true;
-                                        }
-                                    }
-                                    ParentUserId = puser.ParentUserId;
-                                }
-                                //运营中心返额度
-                                // OperateReserveBackFor(db, order.UserId, order.TotalPrice);
-                            }
-                        }
-                        function.WriteLog("\r\n\r\n", "推荐下单奖励监控日志");
-                    }
+                    RedisDbconn.Instance.AddList("PosCouponPrizeQueue", order.Id.ToString());
 
                     //推荐王
                     if(pro.ProductId == 29)

+ 144 - 92
AppStart/Helper/LeaderApplyCouponsHelper.cs

@@ -3,7 +3,7 @@ using System.Threading;
 using System.Linq;
 using System.Data;
 using Library;
-using MySystem.Models;
+using MySystem.PxcModels;
 using LitJson;
 using System.Collections.Generic;
 
@@ -33,99 +33,82 @@ namespace MySystem
                     try
                     {
                         var Id = int.Parse(content);
-                        WebCMSEntities db = new WebCMSEntities();
-                        var LeaderUserId = 0;
-                        var queryList = db.LeaderReserveRecord.FirstOrDefault(m => m.Id == Id) ?? new LeaderReserveRecord();
-                        var userInfo = db.Users.FirstOrDefault(m => m.Id == queryList.UserId) ?? new Users();
-                        if (userInfo.LeaderLevel == 2)
-                        {
-                            LeaderUserId = queryList.UserId;
-                        }
-                        else
-                        {
-                            string[] ParentNavList = userInfo.ParentNav.Trim(',').Replace(",,", ",").Split(',');
-                            for (int j = ParentNavList.Length; j > 0; j--)
-                            {
-                                int userId = int.Parse(ParentNavList[j - 1]);
-                                var user = db.Users.FirstOrDefault(m => m.Id == userId) ?? new Users();
-                                //如果是小盟主,则查找该小盟主关联的大盟主储蓄金是否充足,是则给券打上关联大盟主标记
-                                if(user.LeaderLevel == 1)
-                                {
-                                    // LeaderAccountRecord leaderItem = db.LeaderAccountRecord.FirstOrDefault(m => m.Sort == user.Id && m.LeaderId > 0 && m.LeaderReserve >= 400 * pro.ProductCount);
-                                    // if(leaderItem != null)
-                                    // {
-                                    //     leaderItem.LeaderReserve -= 400 * pro.ProductCount;
-                                    //     foreach(int couponId in couponIds)
-                                    //     {
-                                    //         PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
-                                    //         if(coupon != null)
-                                    //         {
-                                    //             coupon.LeaderUserId = leaderItem.LeaderId;
-                                    //         }
-                                    //     }
-                                    //     db.SaveChanges();
-                                    //     bigLeaderPrize = true;
-                                    // }
-                                }
-                                if (user.LeaderLevel == 2)
-                                {
-                                    LeaderUserId = userId;
-                                    break;
-                                }
-                                else
-                                {
-                                    continue;
-                                }
-                            }
+                        dosomething(Id);
+                        // WebCMSEntities db = new WebCMSEntities();
+                        // var LeaderUserId = 0;
+                        // var queryList = db.LeaderReserveRecord.FirstOrDefault(m => m.Id == Id) ?? new LeaderReserveRecord();
+                        // var userInfo = db.Users.FirstOrDefault(m => m.Id == queryList.UserId) ?? new Users();
+                        // if (userInfo.LeaderLevel == 2)
+                        // {
+                        //     LeaderUserId = queryList.UserId;
+                        // }
+                        // else
+                        // {
+                        //     string[] ParentNavList = userInfo.ParentNav.Trim(',').Replace(",,", ",").Split(',');
+                        //     for (int j = ParentNavList.Length; j > 0; j--)
+                        //     {
+                        //         int userId = int.Parse(ParentNavList[j - 1]);
+                        //         var user = db.Users.FirstOrDefault(m => m.Id == userId) ?? new Users();
+                        //         //如果是小盟主,则查找该小盟主关联的大盟主储蓄金是否充足,是则给券打上关联大盟主标记
+                        //         if (user.LeaderLevel == 2)
+                        //         {
+                        //             LeaderUserId = userId;
+                        //             break;
+                        //         }
+                        //         else
+                        //         {
+                        //             continue;
+                        //         }
+                        //     }
 
-                        }
+                        // }
 
-                        JsonData ApplyList = JsonMapper.ToObject(queryList.SeoTitle);
-                        var SnList = "";
-                        for (int i = 0; i < ApplyList.Count; i++)
-                        {
-                            int num = Convert.ToInt32(ApplyList[i]["Num"].ToString());
-                            int type = Convert.ToInt32(ApplyList[i]["Type"].ToString());
-                            //电签
-                            if (type == 1)
-                            {
-                                var dposCoupons = db.PosCoupons.Where(m => m.QueryCount == 1 && m.UserId == 0 && m.LeaderUserId == 0 && m.IsUse == 0 && m.IsLock == 0 && m.OpId == 0).Take(num).ToList();//电签券
-                                foreach (var item in dposCoupons)
-                                {
-                                    var posCoupon = db.PosCoupons.FirstOrDefault(m => m.Id == item.Id) ?? new PosCoupons();
-                                    posCoupon.UserId = queryList.UserId;
-                                    posCoupon.LeaderUserId = LeaderUserId;
-                                    // SnList += posCoupon.ExchangeCode + ",";
-                                    db.UserSnDelayChange.Add(new UserSnDelayChange()
-                                    {
-                                        CreateDate = DateTime.Now,
-                                        QueryCount = Id,
-                                        SnNo = posCoupon.ExchangeCode,
-                                    });
-                                }
-                            }
-                            //大机
-                            if (type == 2)
-                            {
-                                var bposCoupons = db.PosCoupons.Where(m => m.QueryCount == 2 && m.UserId == 0 && m.LeaderUserId == 0 && m.IsUse == 0 && m.IsLock == 0 && m.OpId == 0).Take(num).ToList();//大机券
-                                foreach (var items in bposCoupons)
-                                {
-                                    var posCoupon = db.PosCoupons.FirstOrDefault(m => m.Id == items.Id) ?? new PosCoupons();
-                                    posCoupon.UserId = queryList.UserId;
-                                    posCoupon.LeaderUserId = LeaderUserId;
-                                    // SnList += posCoupon.ExchangeCode + ",";
-                                    db.UserSnDelayChange.Add(new UserSnDelayChange()
-                                    {
-                                        CreateDate = DateTime.Now,
-                                        QueryCount = Id,
-                                        SnNo = posCoupon.ExchangeCode,
-                                    });
-                                }
-                            }
-                            db.SaveChanges();
-                        }
-                        // queryList.SeoDescription = SnList.TrimEnd(',');
-                        db.SaveChanges();
+                        // JsonData ApplyList = JsonMapper.ToObject(queryList.SeoTitle);
+                        // var SnList = "";
+                        // for (int i = 0; i < ApplyList.Count; i++)
+                        // {
+                        //     int num = Convert.ToInt32(ApplyList[i]["Num"].ToString());
+                        //     int type = Convert.ToInt32(ApplyList[i]["Type"].ToString());
+                        //     //电签
+                        //     if (type == 1)
+                        //     {
+                        //         var dposCoupons = db.PosCoupons.Where(m => m.QueryCount == 1 && m.UserId == 0 && m.LeaderUserId == 0 && m.IsUse == 0 && m.IsLock == 0 && m.OpId == 0).Take(num).ToList();//电签券
+                        //         foreach (var item in dposCoupons)
+                        //         {
+                        //             var posCoupon = db.PosCoupons.FirstOrDefault(m => m.Id == item.Id) ?? new PosCoupons();
+                        //             posCoupon.UserId = queryList.UserId;
+                        //             posCoupon.LeaderUserId = LeaderUserId;
+                        //             // SnList += posCoupon.ExchangeCode + ",";
+                        //             db.UserSnDelayChange.Add(new UserSnDelayChange()
+                        //             {
+                        //                 CreateDate = DateTime.Now,
+                        //                 QueryCount = Id,
+                        //                 SnNo = posCoupon.ExchangeCode,
+                        //             });
+                        //         }
+                        //     }
+                        //     //大机
+                        //     if (type == 2)
+                        //     {
+                        //         var bposCoupons = db.PosCoupons.Where(m => m.QueryCount == 2 && m.UserId == 0 && m.LeaderUserId == 0 && m.IsUse == 0 && m.IsLock == 0 && m.OpId == 0).Take(num).ToList();//大机券
+                        //         foreach (var items in bposCoupons)
+                        //         {
+                        //             var posCoupon = db.PosCoupons.FirstOrDefault(m => m.Id == items.Id) ?? new PosCoupons();
+                        //             posCoupon.UserId = queryList.UserId;
+                        //             posCoupon.LeaderUserId = LeaderUserId;
+                        //             // SnList += posCoupon.ExchangeCode + ",";
+                        //             db.UserSnDelayChange.Add(new UserSnDelayChange()
+                        //             {
+                        //                 CreateDate = DateTime.Now,
+                        //                 QueryCount = Id,
+                        //                 SnNo = posCoupon.ExchangeCode,
+                        //             });
+                        //         }
+                        //     }
+                        //     db.SaveChanges();
+                        // }
+                        // // queryList.SeoDescription = SnList.TrimEnd(',');
+                        // db.SaveChanges();
                     }
                     catch (Exception ex)
                     {
@@ -138,5 +121,74 @@ namespace MySystem
                 }
             }
         }
+
+        private void dosomething(int Id)
+        { 
+            WebCMSEntities db = new WebCMSEntities();
+            OpModels.WebCMSEntities opdb = new OpModels.WebCMSEntities();
+            var query = db.LeaderReserveRecord.FirstOrDefault(m => m.Id == Id && m.Remark == "兑换机具券");
+            if(query != null)
+            {
+                JsonData ApplyList = JsonMapper.ToObject(query.SeoTitle);
+                UserRankItem orderUser = PosCouponPrizeService.Instance.GetUserLevel(db, query.UserId);
+                string ParentNav = orderUser.ParentNav + "," + orderUser.Id + ",";
+                string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
+                Array.Reverse(ParentNavList);
+                int index = 0;
+                bool BuyPrizeFlag = false; //购机奖励发放标识
+                decimal BuyPrize = 0; //购机奖励
+                foreach(string ParentId in ParentNavList)
+                {
+                    UserRankItem parentUser = PosCouponPrizeService.Instance.GetUserLevel(db, int.Parse(ParentId));
+                    index += 1;
+
+                    //给券打大盟主标记
+                    if(parentUser.LeaderLevel == 2 && index == 1)
+                    {
+                        for (int i = 0; i < ApplyList.Count; i++)
+                        {
+                            int num = Convert.ToInt32(ApplyList[i]["Num"].ToString());
+                            int Kind = Convert.ToInt32(ApplyList[i]["Type"].ToString());
+                            List<int> couponIds = db.PosCoupons.Where(m => m.IsLock == 0 && m.IsUse == 0 && m.UserId == 0 && m.QueryCount == Kind).OrderBy(m => m.Id).Take(num).ToList().Select(m => m.Id).ToList();
+                            PosCouponPrizeService.Instance.SetPosCouponLeaderFlag(db, parentUser.Id, num / 3, couponIds);
+                        }
+                    }
+
+                    if(parentUser.OperateLevel > 0 && !BuyPrizeFlag)
+                    {
+                        int groupCount = 0;
+                        for (int i = 0; i < ApplyList.Count; i++)
+                        {
+                            int num = Convert.ToInt32(ApplyList[i]["Num"].ToString());
+                            int Kind = Convert.ToInt32(ApplyList[i]["Type"].ToString());
+                            groupCount += num / 3;
+                        }
+                        if(PosCouponPrizeService.Instance.CheckOpReserve(opdb, groupCount, parentUser.Id))
+                        {
+                        //购机奖
+                            decimal CurBuyPrize = GetBuyPrize(parentUser);
+                            PosCouponPrizeService.Instance.OpAccount(db, 0, parentUser.Id, CurBuyPrize - BuyPrize, groupCount);
+                            BuyPrizeFlag = true;
+                            BuyPrize = CurBuyPrize;
+                        }
+                    }
+                }
+            }
+            db.Dispose();
+            opdb.Dispose();
+        }
+
+        /// <summary>
+        /// 获取购机奖金额
+        /// </summary>
+        /// <param name="user"></param>
+        /// <returns></returns>
+        public decimal GetBuyPrize(UserRankItem user)
+        {
+            if(user.OperateLevel == 2) return 60;
+            if(user.OperateLevel == 3) return 80;
+            if(user.OperateLevel == 4) return 100;
+            return 0;
+        }
     }
 }

+ 86 - 0
AppStart/Helper/PosCouponPrize/OperateAddService.cs

@@ -0,0 +1,86 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Data;
+using System.Threading;
+using MySystem.PxcModels;
+using Library;
+using LitJson;
+
+namespace MySystem
+{
+    public class OperateAddService
+    {
+        public readonly static OperateAddService Instance = new OperateAddService();
+        private OperateAddService()
+        { }
+
+
+        public void Start()
+        {
+            Thread th = new Thread(ready);
+            th.IsBackground = true;
+            th.Start();
+        }
+        
+        private void ready()
+        { 
+            bool op = true;
+            while (op)
+            {
+                string content = RedisDbconn.Instance.RPop<string>("OperateAddServiceQueue");
+                if (!string.IsNullOrEmpty(content))
+                {
+                    try
+                    {
+                        dosomething(int.Parse(function.CheckInt(content)));
+                    }
+                    catch(Exception ex)
+                    {
+                        function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "添加运营中心合伙人异常");
+                    }
+                }
+                else
+                {
+                    Thread.Sleep(2000);
+                }
+            }
+        }
+
+        private void dosomething(int Id)
+        { 
+            WebCMSEntities db = new WebCMSEntities();
+            OpModels.WebCMSEntities opdb = new OpModels.WebCMSEntities();
+            OpModels.SysAdmin edit = opdb.SysAdmin.FirstOrDefault(m => m.Id == Id);
+            if (edit != null)
+            {                
+                UserRankItem orderUser = PosCouponPrizeService.Instance.GetUserLevel(db, edit.UserId);
+                string ParentNav = orderUser.ParentNav + "," + orderUser.Id + ",";
+                string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
+                Array.Reverse(ParentNavList);
+                int index = 0;
+                bool PrizeFlag = false; //奖励发放标识
+                foreach(string ParentId in ParentNavList)
+                {
+                    UserRankItem parentUser = PosCouponPrizeService.Instance.GetUserLevel(db, int.Parse(ParentId));
+                    index += 1;
+
+                    if(parentUser.OperateLevel > 1 && PosCouponPrizeService.Instance.CheckOpReserve(opdb, 16000, parentUser.Id) && !PrizeFlag)
+                    {
+                        //扣减备用金
+                        PosCouponPrizeService.Instance.OperateAmountChange(opdb, parentUser.Id, 16000, 2, 1, "购买运营中心");
+                        //返回到余额
+                        PosCouponPrizeService.Instance.OperateAmountChange(opdb, parentUser.Id, 16000, 1, 2, "购买运营中心");
+
+                        //发放5888推荐奖励
+                        PosCouponPrizeService.Instance.OpAccount(db, parentUser.Id, parentUser.Id, 5888, 1);
+
+                        PrizeFlag = true;
+                    }
+                }
+            }
+            db.Dispose();
+            opdb.Dispose();
+        }
+    }
+}

+ 9 - 0
AppStart/Helper/PosCouponPrize/PosCouponPrizeService.cs

@@ -247,6 +247,15 @@ namespace MySystem
             }
             return false;
         }
+        public bool CheckOpReserve(OpModels.WebCMSEntities db, decimal Amt, int UserId)
+        {
+            OpModels.UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId) ?? new OpModels.UserAccount();
+            if(account.TotalAmt >= Amt)
+            {
+                return true;
+            }
+            return false;
+        }
 
         /// <summary>
         /// 扣减/增加盟主储蓄金

+ 1 - 0
Startup.cs

@@ -196,6 +196,7 @@ namespace MySystem
                 // LeaderTimeoutSendMessageService.Instance.Start(); //盟主过期消息提醒
 
                 // AlipayPayBack2Service.Instance.Start(); //支付宝回调处理
+                // PosCouponPrizeService.Instance.Start(); //购券奖励队列
                 // BalancePayBackService.Instance.Start(); //余额支付队列
                 // ReservePayBackService.Instance.Start(); //储备金支付队列
                 // OrderRefundService.Instance.Start(); //商城订单退款