Ver Fonte

发放推荐奖励排除已注销人员

lcl há 9 meses atrás
pai
commit
601a4e9d05
1 ficheiros alterados com 133 adições e 130 exclusões
  1. 133 130
      AppStart/Helper/PosCouponPrize/PosCouponPrizeService.cs

+ 133 - 130
AppStart/Helper/PosCouponPrize/PosCouponPrizeService.cs

@@ -105,71 +105,155 @@ namespace MySystem
                     foreach(string ParentId in ParentNavList)
                     {
                         UserRankItem parentUser = GetUserLevel(int.Parse(ParentId));
-                        Utils.Instance.PrizeRecord(2, order.OrderNo, "创客编号:" + parentUser.MakerCode + ";创客姓名:" + parentUser.RealName + ";");
-                        index += 1;
-                        if(index == 1)
-                        {
-                            Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:下单人是盟主;下单人盟主等级:" + orderUser.LeaderLevel + "");
-                            Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:下单人是运营中心或合伙人;下单人合伙人等级:" + orderUser.OperateLevel + "");
-                            Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:推荐奖励是否已发放;当前状态:" + DirectPrizeFlag + "");
-                        }
-                        if(index == 1 && (orderUser.LeaderLevel > 0 || orderUser.OperateLevel > 0) && !DirectPrizeFlag)
+                        if(parentUser.Id > 0)
                         {
-                            Utils.Instance.PrizeRecord(2, order.OrderNo, "满足条件,发放推荐奖励给下单人");
-                            DirectPrize(db, order.Id, order.UserId, order.BuyCount);
-                            DirectPrizeFlag = true;
-                        }
-                        if(index > 1)
-                        {
-                            bool IsStandardUser = Utils.Instance.IsStandardUser(parentUser.Id);
-                            Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:上级是有效创客;是否有效创客:" + IsStandardUser + "");
-                            Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:推荐奖励是否已发放;当前状态:" + DirectPrizeFlag + "");
-                            if(IsStandardUser && !DirectPrizeFlag)
+                            Utils.Instance.PrizeRecord(2, order.OrderNo, "创客编号:" + parentUser.MakerCode + ";创客姓名:" + parentUser.RealName + ";");
+                            index += 1;
+                            if(index == 1)
+                            {
+                                Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:下单人是盟主;下单人盟主等级:" + orderUser.LeaderLevel + "");
+                                Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:下单人是运营中心或合伙人;下单人合伙人等级:" + orderUser.OperateLevel + "");
+                                Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:推荐奖励是否已发放;当前状态:" + DirectPrizeFlag + "");
+                            }
+                            if(index == 1 && (orderUser.LeaderLevel > 0 || orderUser.OperateLevel > 0) && !DirectPrizeFlag)
                             {
-                                Utils.Instance.PrizeRecord(2, order.OrderNo, "满足条件,发放推荐奖励给上级");
-                                DirectPrize(db, order.Id, parentUser.Id, order.BuyCount);
+                                Utils.Instance.PrizeRecord(2, order.OrderNo, "满足条件,发放推荐奖励给下单人");
+                                DirectPrize(db, order.Id, order.UserId, order.BuyCount);
                                 DirectPrizeFlag = true;
                             }
-                        }
-                        Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:创客是盟主;创客盟主等级:" + parentUser.AgoLeaderLevel + "");
-                        Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:盟主储备金是否充足;");
-                        Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:创客是运营中心或合伙人;合伙人等级:" + parentUser.AgoLeaderLevel + "");
-                        Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:合伙人未使用额度是否充足;");
-                        if(parentUser.AgoLeaderLevel > 0 && CheckLeaderReserve(db, order.BuyCount, parentUser.Id))
-                        {
-                            Utils.Instance.PrizeRecord(2, order.OrderNo, "满足条件,发放购机奖");
-                            //购机奖
-                            if(parentUser.LeaderLevel > 0)
+                            if(index > 1)
                             {
-                                decimal CurBuyPrize = GetBuyPrize(parentUser, order.UserId);
-                                decimal GetPrize = CurBuyPrize - BuyPrize;
-                                Utils.Instance.PrizeRecord(2, order.OrderNo, "发放金额:" + GetPrize);
-                                if(GetPrize > 0 && BuyPrizeFlag < 2)
+                                bool IsStandardUser = Utils.Instance.IsStandardUser(parentUser.Id);
+                                Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:上级是有效创客;是否有效创客:" + IsStandardUser + "");
+                                Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:推荐奖励是否已发放;当前状态:" + DirectPrizeFlag + "");
+                                if(IsStandardUser && !DirectPrizeFlag)
                                 {
-                                    bool PrizeFlag = true;
-                                    int ChangeType = 118;
-                                    if(parentUser.OperateLevel == 1)
-                                    {
-                                        ChangeType = 120;
-                                    }
-                                    if(parentUser.OperateLevel > 1)
+                                    Utils.Instance.PrizeRecord(2, order.OrderNo, "满足条件,发放推荐奖励给上级");
+                                    DirectPrize(db, order.Id, parentUser.Id, order.BuyCount);
+                                    DirectPrizeFlag = true;
+                                }
+                            }
+                            Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:创客是盟主;创客盟主等级:" + parentUser.AgoLeaderLevel + "");
+                            Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:盟主储备金是否充足;");
+                            Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:创客是运营中心或合伙人;合伙人等级:" + parentUser.AgoLeaderLevel + "");
+                            Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:合伙人未使用额度是否充足;");
+                            if(parentUser.AgoLeaderLevel > 0 && CheckLeaderReserve(db, order.BuyCount, parentUser.Id))
+                            {
+                                Utils.Instance.PrizeRecord(2, order.OrderNo, "满足条件,发放购机奖");
+                                //购机奖
+                                if(parentUser.LeaderLevel > 0)
+                                {
+                                    decimal CurBuyPrize = GetBuyPrize(parentUser, order.UserId);
+                                    decimal GetPrize = CurBuyPrize - BuyPrize;
+                                    Utils.Instance.PrizeRecord(2, order.OrderNo, "发放金额:" + GetPrize);
+                                    if(GetPrize > 0 && BuyPrizeFlag < 2)
                                     {
-                                        ChangeType = 128;
-                                        if(function.CheckNull(RedisDbconn.Instance.Get<string>("YingXunUser")).Contains("," + orderUser.Id + ","))
+                                        bool PrizeFlag = true;
+                                        int ChangeType = 118;
+                                        if(parentUser.OperateLevel == 1)
                                         {
-                                            PrizeFlag = false;
+                                            ChangeType = 120;
+                                        }
+                                        if(parentUser.OperateLevel > 1)
+                                        {
+                                            ChangeType = 128;
+                                            if(function.CheckNull(RedisDbconn.Instance.Get<string>("YingXunUser")).Contains("," + orderUser.Id + ","))
+                                            {
+                                                PrizeFlag = false;
+                                            }
+                                        }
+                                        if(PrizeFlag)
+                                        {
+                                            OpAccount(db, order.Id, parentUser.Id, CurBuyPrize - BuyPrize, order.BuyCount, ChangeType);
+                                            if(GetPrize == 160) BuyPrizeFlag = 2;
+                                            else if(GetPrize == 60) BuyPrizeFlag = 2;
+                                            else BuyPrizeFlag = 1;
                                         }
+                                        BuyPrize = CurBuyPrize;
                                     }
-                                    if(PrizeFlag)
+                                    if(parentUser.OperateLevel == 2 && CurBuyPrize == 100) BuyPrizeFlag = 2;
+                                }
+                                else if(parentUser.OperateLevel > 0 && CheckOpReserve(opdb, order.BuyCount, parentUser.Id) && BuyPrizeFlag < 2)
+                                {
+                                    Utils.Instance.PrizeRecord(2, order.OrderNo, "满足条件,发放购机奖");
+                                    //购机奖
+                                    decimal CurBuyPrize = GetBuyPrize(parentUser, order.UserId);
+                                    decimal GetPrize = CurBuyPrize - BuyPrize;
+                                    Utils.Instance.PrizeRecord(2, order.OrderNo, "发放金额:" + GetPrize);
+                                    if(GetPrize > 0)
                                     {
-                                        OpAccount(db, order.Id, parentUser.Id, CurBuyPrize - BuyPrize, order.BuyCount, ChangeType);
+                                        int ChangeType = 120;
+                                        if(parentUser.OperateLevel > 1)
+                                        {
+                                            ChangeType = 128;
+                                        }
+                                        OpAccount(db, order.Id, parentUser.Id, GetPrize, order.BuyCount, ChangeType);
+                                        BuyPrize = CurBuyPrize;
                                         if(GetPrize == 160) BuyPrizeFlag = 2;
                                         else if(GetPrize == 60) BuyPrizeFlag = 2;
                                         else BuyPrizeFlag = 1;
                                     }
-                                    BuyPrize = CurBuyPrize;
+                                    if(parentUser.OperateLevel == 2 && CurBuyPrize == 100) BuyPrizeFlag = 2; 
+
+                                    if(!BackAccountFlag)
+                                    {
+                                        BackAccountFlag = true;
+                                        decimal GetAmount = GetWithdrawMoney(parentUser) * order.BuyCount;
+                                        //扣减备用金
+                                        // OperateAmountChange(opdb, parentUser.Id, GetAmount, 2, 1, "商城购机", true, order.Id);
+                                        // //返回到余额
+                                        // OperateAmountChange(opdb, parentUser.Id, GetAmount, 1, 2, "商城购机", true, order.Id);
+
+                                        OpAmountItem item = new OpAmountItem()
+                                        {
+                                            UserId = parentUser.Id,
+                                            OperateType = 0,
+                                            ChangeType = 5,
+                                            Remark = "商城购机",
+                                            UseAmount = GetAmount,
+                                            UseValidForGetAmount = GetAmount,
+                                            UseTotalAmt = GetAmount,
+                                            DataType = 1,
+                                            DataId = order.Id,
+                                        };
+                                        RedisDbconn.Instance.AddList("OperateAmountRecordServiceQueue", item);
+                                    }
+                                }
+
+                                if(!BackAccountFlag)
+                                {
+                                    BackAccountFlag = true;
+                                    //扣减备用金
+                                    int ReserveRecordId = OpReserve(db, order.Id, parentUser.Id, GetWithdrawMoney(parentUser) * order.BuyCount, 2, order.UserId, "购机奖励");
+                                    //返回到余额
+                                    OpLeaderAccount(db, order, parentUser.Id, GetWithdrawMoney(parentUser), order.BuyCount, ReserveRecordId);
+                                }
+
+                                //给券打大盟主标记
+                                Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:创客是盟主;创客盟主等级:" + parentUser.LeaderLevel + "");
+                                Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:盟主储备金是否充足;");
+                                if(parentUser.LeaderLevel == 1 && CheckLeaderReserve(db, order.BuyCount, parentUser.Id) && !BigLeaderFlag)
+                                {
+                                    Utils.Instance.PrizeRecord(2, order.OrderNo, "满足小盟主条件,开始检查大盟主关联的额度");
+                                    int LeaderId = CheckPosCouponLeaderFlag(db, parentUser.Id, order.BuyCount, codes);
+                                    if(LeaderId > 0)
+                                    {
+                                        BigLeaderFlag = true;
+                                        Utils.Instance.PrizeRecord(2, order.OrderNo, "满足条件,大盟主标记打给" + LeaderId);
+                                    }
+                                }
+                                else if(parentUser.LeaderLevel == 2 && !BigLeaderFlag)
+                                {
+                                    Utils.Instance.PrizeRecord(2, order.OrderNo, "满足大盟主条件,大盟主标记打给" + parentUser.Id + ",对应机具券:" + order.SnNos);
+                                    BigLeaderFlag = true;
+                                    if(!string.IsNullOrEmpty(order.SnNos))
+                                    {
+                                        List<int> couponIds = db.PosCoupons.Where(m => codes.Contains(m.ExchangeCode)).OrderBy(m => m.Id).Take(CouponCount).ToList().Select(m => m.Id).ToList();
+                                        Utils.Instance.PrizeRecord(2, order.OrderNo, "开始打标记,数量:" + couponIds.Count);
+                                        SetPosCouponLeaderFlag(db, parentUser.Id, order.BuyCount, couponIds);
+                                        Utils.Instance.PrizeRecord(2, order.OrderNo, "结束打标记");
+                                    }
                                 }
-                                if(parentUser.OperateLevel == 2 && CurBuyPrize == 100) BuyPrizeFlag = 2;
                             }
                             else if(parentUser.OperateLevel > 0 && CheckOpReserve(opdb, order.BuyCount, parentUser.Id) && BuyPrizeFlag < 2)
                             {
@@ -217,87 +301,6 @@ namespace MySystem
                                     RedisDbconn.Instance.AddList("OperateAmountRecordServiceQueue", item);
                                 }
                             }
-
-                            if(!BackAccountFlag)
-                            {
-                                BackAccountFlag = true;
-                                //扣减备用金
-                                int ReserveRecordId = OpReserve(db, order.Id, parentUser.Id, GetWithdrawMoney(parentUser) * order.BuyCount, 2, order.UserId, "购机奖励");
-                                //返回到余额
-                                OpLeaderAccount(db, order, parentUser.Id, GetWithdrawMoney(parentUser), order.BuyCount, ReserveRecordId);
-                            }
-
-                            //给券打大盟主标记
-                            Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:创客是盟主;创客盟主等级:" + parentUser.LeaderLevel + "");
-                            Utils.Instance.PrizeRecord(2, order.OrderNo, "条件:盟主储备金是否充足;");
-                            if(parentUser.LeaderLevel == 1 && CheckLeaderReserve(db, order.BuyCount, parentUser.Id) && !BigLeaderFlag)
-                            {
-                                Utils.Instance.PrizeRecord(2, order.OrderNo, "满足小盟主条件,开始检查大盟主关联的额度");
-                                int LeaderId = CheckPosCouponLeaderFlag(db, parentUser.Id, order.BuyCount, codes);
-                                if(LeaderId > 0)
-                                {
-                                    BigLeaderFlag = true;
-                                    Utils.Instance.PrizeRecord(2, order.OrderNo, "满足条件,大盟主标记打给" + LeaderId);
-                                }
-                            }
-                            else if(parentUser.LeaderLevel == 2 && !BigLeaderFlag)
-                            {
-                                Utils.Instance.PrizeRecord(2, order.OrderNo, "满足大盟主条件,大盟主标记打给" + parentUser.Id + ",对应机具券:" + order.SnNos);
-                                BigLeaderFlag = true;
-                                if(!string.IsNullOrEmpty(order.SnNos))
-                                {
-                                    List<int> couponIds = db.PosCoupons.Where(m => codes.Contains(m.ExchangeCode)).OrderBy(m => m.Id).Take(CouponCount).ToList().Select(m => m.Id).ToList();
-                                    Utils.Instance.PrizeRecord(2, order.OrderNo, "开始打标记,数量:" + couponIds.Count);
-                                    SetPosCouponLeaderFlag(db, parentUser.Id, order.BuyCount, couponIds);
-                                    Utils.Instance.PrizeRecord(2, order.OrderNo, "结束打标记");
-                                }
-                            }
-                        }
-                        else if(parentUser.OperateLevel > 0 && CheckOpReserve(opdb, order.BuyCount, parentUser.Id) && BuyPrizeFlag < 2)
-                        {
-                            Utils.Instance.PrizeRecord(2, order.OrderNo, "满足条件,发放购机奖");
-                            //购机奖
-                            decimal CurBuyPrize = GetBuyPrize(parentUser, order.UserId);
-                            decimal GetPrize = CurBuyPrize - BuyPrize;
-                            Utils.Instance.PrizeRecord(2, order.OrderNo, "发放金额:" + GetPrize);
-                            if(GetPrize > 0)
-                            {
-                                int ChangeType = 120;
-                                if(parentUser.OperateLevel > 1)
-                                {
-                                    ChangeType = 128;
-                                }
-                                OpAccount(db, order.Id, parentUser.Id, GetPrize, order.BuyCount, ChangeType);
-                                BuyPrize = CurBuyPrize;
-                                if(GetPrize == 160) BuyPrizeFlag = 2;
-                                else if(GetPrize == 60) BuyPrizeFlag = 2;
-                                else BuyPrizeFlag = 1;
-                            }
-                            if(parentUser.OperateLevel == 2 && CurBuyPrize == 100) BuyPrizeFlag = 2; 
-
-                            if(!BackAccountFlag)
-                            {
-                                BackAccountFlag = true;
-                                decimal GetAmount = GetWithdrawMoney(parentUser) * order.BuyCount;
-                                //扣减备用金
-                                // OperateAmountChange(opdb, parentUser.Id, GetAmount, 2, 1, "商城购机", true, order.Id);
-                                // //返回到余额
-                                // OperateAmountChange(opdb, parentUser.Id, GetAmount, 1, 2, "商城购机", true, order.Id);
-
-                                OpAmountItem item = new OpAmountItem()
-                                {
-                                    UserId = parentUser.Id,
-                                    OperateType = 0,
-                                    ChangeType = 5,
-                                    Remark = "商城购机",
-                                    UseAmount = GetAmount,
-                                    UseValidForGetAmount = GetAmount,
-                                    UseTotalAmt = GetAmount,
-                                    DataType = 1,
-                                    DataId = order.Id,
-                                };
-                                RedisDbconn.Instance.AddList("OperateAmountRecordServiceQueue", item);
-                            }
                         }
                     }
                 }