Переглянути джерело

初步完成流程代码的开发,待核对流程

lichunlei 2 роки тому
батько
коміт
9cde75d9da
1 змінених файлів з 177 додано та 31 видалено
  1. 177 31
      AppStart/Helper/AlipayPayBack2Service.cs

+ 177 - 31
AppStart/Helper/AlipayPayBack2Service.cs

@@ -225,11 +225,13 @@ namespace MySystem
                             {
                                 bool directPrize = false; //直推奖标记
                                 bool bigLeaderPrize = false; //大盟主券标记
+                                bool operateFlag = false; //运营中心标记
                                 bool buyPrize = false; //返100购机奖励标记
+                                bool operatePrize = false; //返100购机奖励标记-运营中心
                                 int leaderFlag = 0; //返600备用金标记
                                 if(user.LeaderLevel > 0 || user.UserType == 1) //盟主或运营中心
                                 {
-                                    if(user.LeaderLevel > 0)
+                                    if(user.LeaderLevel == 1)
                                     {
                                         UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId) ?? new UserAccount();
                                         if(acccount.LeaderReserve >= order.TotalPrice)
@@ -265,7 +267,60 @@ namespace MySystem
                                         }
                                     }
                                     db.SaveChanges();
-                                    if(user.LeaderLevel == 2 || user.UserType == 1)
+                                    if(order.PayMode == 4 && user.LeaderLevel == 2) //使用盟主储蓄金,并且是大盟主
+                                    {
+                                        if(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.LeaderUserId = user.Id;
+                                                        coupon.OpId = user.Id;
+                                                    }
+                                                }
+                                            }
+                                            db.SaveChanges();
+                                        }
+                                        else
+                                        {
+                                            //寻找最近运营中心额度大于0的运营中心
+                                            int PUserId = user.Id;
+                                            bool OperateFlag = 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)
+                                                        {
+                                                            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;
+                                                }
+                                            }
+                                        }
+                                    }
+                                    else if(order.PayMode == 4 && user.UserType == 1) //使用盟主储蓄金,并且是运营中心
                                     {
                                         if(couponIds.Count > 0)
                                         {
@@ -274,43 +329,110 @@ namespace MySystem
                                                 PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
                                                 if(coupon != null)
                                                 {
-                                                    if(user.LeaderLevel == 2)
+                                                    coupon.OpId = user.Id;
+                                                }
+                                            }
+                                        }
+                                        db.SaveChanges();
+                                        //寻找最近储蓄金充足的大盟主
+                                        int PUserId = user.Id;
+                                        bool LeaderFlag = 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)
                                                     {
-                                                        coupon.LeaderUserId = user.Id;
+                                                        foreach(int couponId in couponIds)
+                                                        {
+                                                            PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
+                                                            if(coupon != null)
+                                                            {
+                                                                coupon.LeaderUserId = puser.Id;
+                                                            }
+                                                        }
+                                                        db.SaveChanges();
+                                                        UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId) ?? new UserAccount();
+                                                        if(acccount.LeaderReserve >= order.TotalPrice)
+                                                        {
+                                                            //扣减备用金
+                                                            OpReserve(db, order, order.UserId, order.TotalPrice, 2, 0, "商城购机");
+                                                            //返回到余额
+                                                            OpLeaderAccount(db, order, order.UserId, order.TotalPrice / pro.ProductCount, pro.ProductCount);
+                                                        }
+                                                        LeaderFlag = false;
+                                                    }
+                                                }
+                                                PUserId = puser.ParentUserId;
+                                            }
+                                            else
+                                            {
+                                                PUserId = 0;
+                                            }
+                                        }
+                                    }
+                                    else
+                                    {
+                                        //寻找最近储蓄金充足的大盟主及最近运营中心额度大于0的运营中心(含自身)
+                                        int PUserId = user.Id;
+                                        bool LeaderFlag = true;
+                                        bool OperateFlag = 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)
+                                                    {
+                                                        foreach(int couponId in couponIds)
+                                                        {
+                                                            PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.Id == couponId);
+                                                            if(coupon != null)
+                                                            {
+                                                                coupon.LeaderUserId = puser.Id;
+                                                            }
+                                                        }
+                                                        db.SaveChanges();
+                                                        UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId) ?? new UserAccount();
+                                                        if(acccount.LeaderReserve >= order.TotalPrice)
+                                                        {
+                                                            //扣减备用金
+                                                            OpReserve(db, order, order.UserId, order.TotalPrice, 2, 0, "商城购机");
+                                                            //返回到余额
+                                                            OpLeaderAccount(db, order, order.UserId, order.TotalPrice / pro.ProductCount, pro.ProductCount);
+                                                        }
+                                                        LeaderFlag = false;
                                                     }
-                                                    if(user.UserType == 1)
+                                                }
+                                                if(puser.UserType == 1 && OperateFlag == true) //运营中心
+                                                {
+                                                    if(couponIds.Count > 0)
                                                     {
-                                                        coupon.OpId = user.Id;
+                                                        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;
                                             }
-                                            db.SaveChanges();
                                         }
                                     }
-                                    // else
-                                    // {
-                                    //     int PUserId = user.ParentUserId;
-                                    //     while(PUserId > 0)
-                                    //     {
-                                    //         Users puser = db.Users.FirstOrDefault(m => m.Id == PUserId) ?? new Users();
-                                    //         if(puser.LeaderLevel == 2)
-                                    //         {
-                                    //             UserAccount acc = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
-                                    //             if(acc.LeaderReserve >= order.TotalPrice)
-                                    //             {
-                                    //                 //扣减备用金
-                                    //                 OpReserve(db, order, puser.Id, order.TotalPrice, 2, order.UserId, "购机奖励");
-                                    //                 //返回到余额
-                                    //                 OpLeaderAccount(db, order, puser.Id, order.TotalPrice / pro.ProductCount, pro.ProductCount);
-                                    //             }
-                                    //             PUserId = 0;
-                                    //         }
-                                    //         else
-                                    //         {
-                                    //             PUserId = puser.ParentUserId;
-                                    //         }
-                                    //     }
-                                    // }
                                     return;
                                 }
                                 int ParentUserId = user.ParentUserId;
@@ -395,6 +517,30 @@ namespace MySystem
                                             bigLeaderPrize = true;
                                         }
                                     }
+                                    if(puser.UserType == 1)
+                                    {
+                                        UserAccount acccount = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id) ?? new UserAccount();
+                                        if(acccount.LeaderReserve >= order.TotalPrice && !operatePrize)
+                                        {
+                                            //购机奖励
+                                            OpAccount(db, order, puser.Id, 100, pro.ProductCount);
+                                            operatePrize = 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;
                                 }
                             }