Эх сурвалжийг харах

互斥,判断是否第一台机具,否则不发奖励

lichunlei 3 жил өмнө
parent
commit
61f21b95db

+ 101 - 98
AppStart/Helper/StatService.cs

@@ -248,7 +248,7 @@ namespace MySystem
             foreach (PosMachinesTwo pos in posList.ToList())
             {
                 // PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId && !string.IsNullOrEmpty(m.MerIdcardNo));
-                PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
+                PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId && m.Sort == 1);
                 if (merchant != null)
                 {
                     // PosMerchantOtherInfo otherInfo = db.PosMerchantOtherInfo.FirstOrDefault(m => m.CertId == merchant.MerIdcardNo && m.PrizeFlag1 == 0);
@@ -599,7 +599,7 @@ namespace MySystem
                     if (ActPrize > 0)
                     {
                         // PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId && !string.IsNullOrEmpty(m.MerIdcardNo));
-                        PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
+                        PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId && m.Sort == 1);
                         if (merchant != null)
                         {
                             // PosMerchantOtherInfo otherInfo = db.PosMerchantOtherInfo.FirstOrDefault(m => m.CertId == merchant.MerIdcardNo && m.PrizeFlag2 == 0);
@@ -983,121 +983,124 @@ namespace MySystem
                     {
                         MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == TradeSnNo) ?? new MachineForSnNo();
                         PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId) ?? new PosMachinesTwo();
-                        PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
-                        bool checkExist = db.FluxProfitDetail.Any(m => m.MerNo == merchant.KqMerNo);
-                        if (!checkExist)
+                        PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId && m.Sort == 1);
+                        if(merchant != null)
                         {
-                            Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
-                            int GetUserId = user.Id;
-                            int TopUserId = 0;
-                            string ParentNav = user.ParentNav;
-                            if (!string.IsNullOrEmpty(ParentNav))
+                            bool checkExist = db.FluxProfitDetail.Any(m => m.MerNo == merchant.KqMerNo);
+                            if (!checkExist)
                             {
-                                string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
-                                if (ParentNavList.Length > 1)
+                                Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
+                                int GetUserId = user.Id;
+                                int TopUserId = 0;
+                                string ParentNav = user.ParentNav;
+                                if (!string.IsNullOrEmpty(ParentNav))
                                 {
-                                    TopUserId = int.Parse(ParentNavList[1]);
+                                    string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
+                                    if (ParentNavList.Length > 1)
+                                    {
+                                        TopUserId = int.Parse(ParentNavList[1]);
+                                    }
+                                    else if (ParentNavList.Length == 1)
+                                    {
+                                        TopUserId = int.Parse(ParentNavList[0]);
+                                    }
                                 }
-                                else if (ParentNavList.Length == 1)
+                                FluxProfitSummary fluxProfit = db.FluxProfitSummary.FirstOrDefault(m => m.UserId == GetUserId && m.BrandId == pos.BrandId && m.TradeMonth == TradeMonth);
+                                if (fluxProfit == null)
                                 {
-                                    TopUserId = int.Parse(ParentNavList[0]);
+                                    fluxProfit = db.FluxProfitSummary.Add(new FluxProfitSummary()
+                                    {
+                                        CreateDate = DateTime.Now,
+                                        UpdateDate = DateTime.Now,
+                                        UserId = GetUserId, //创客
+                                        BrandId = pos.BrandId,
+                                        TopUserId = TopUserId, //顶级创客
+                                        TradeMonth = TradeMonth, //交易月
+                                        MerUserType = user.MerchantType, //商户创客类型
+                                        Remark = "流量卡分佣", //备注
+                                    }).Entity;
+                                    db.SaveChanges();
                                 }
-                            }
-                            FluxProfitSummary fluxProfit = db.FluxProfitSummary.FirstOrDefault(m => m.UserId == GetUserId && m.BrandId == pos.BrandId && m.TradeMonth == TradeMonth);
-                            if (fluxProfit == null)
-                            {
-                                fluxProfit = db.FluxProfitSummary.Add(new FluxProfitSummary()
+                                fluxProfit.FluxProfitAmt += FluxProfit; //流量分润总金额
+                                db.FluxProfitDetail.Add(new FluxProfitDetail()
                                 {
                                     CreateDate = DateTime.Now,
                                     UpdateDate = DateTime.Now,
+                                    RecordNo = OrderNo, //单号
+                                    TradeDate = TradeDate.ToString("yyyyMMdd"), //交易日期
+                                    TradeTime = TradeDate.ToString("HHmmss"), //交易时间
+                                    TradeMonth = TradeMonth, //交易月
                                     UserId = GetUserId, //创客
-                                    BrandId = pos.BrandId,
+                                    MerchantId = pos.BindMerchantId, //商户
+                                    MerchantUserId = pos.UserId, //商户直属人
+                                    MerNo = merchant.KqMerNo, //渠道商户编号
+                                    SnNo = pos.PosSn, //渠道SN号
+                                    FluxOrderNo = OrderNo, //流量扣费单号
+                                    TradeOrderNo = OrderNo, //交易流水号
+                                    TradeAmt = trade.TradeAmount, //商户交易额
+                                    FluxFeeAmt = FeeAmount, //流量费
+                                    FluxProfitAmt = FluxProfit, //流量分润总金额
+                                    PosType = pos.PosSnType.ToString(), //POS类型
+                                    Remark = "流量卡分佣", //备注
+                                    BrandId = pos.BrandId, //品牌
                                     TopUserId = TopUserId, //顶级创客
-                                    TradeMonth = TradeMonth, //交易月
                                     MerUserType = user.MerchantType, //商户创客类型
-                                    Remark = "流量卡分佣", //备注
-                                }).Entity;
-                                db.SaveChanges();
-                            }
-                            fluxProfit.FluxProfitAmt += FluxProfit; //流量分润总金额
-                            db.FluxProfitDetail.Add(new FluxProfitDetail()
-                            {
-                                CreateDate = DateTime.Now,
-                                UpdateDate = DateTime.Now,
-                                RecordNo = OrderNo, //单号
-                                TradeDate = TradeDate.ToString("yyyyMMdd"), //交易日期
-                                TradeTime = TradeDate.ToString("HHmmss"), //交易时间
-                                TradeMonth = TradeMonth, //交易月
-                                UserId = GetUserId, //创客
-                                MerchantId = pos.BindMerchantId, //商户
-                                MerchantUserId = pos.UserId, //商户直属人
-                                MerNo = merchant.KqMerNo, //渠道商户编号
-                                SnNo = pos.PosSn, //渠道SN号
-                                FluxOrderNo = OrderNo, //流量扣费单号
-                                TradeOrderNo = OrderNo, //交易流水号
-                                TradeAmt = trade.TradeAmount, //商户交易额
-                                FluxFeeAmt = FeeAmount, //流量费
-                                FluxProfitAmt = FluxProfit, //流量分润总金额
-                                PosType = pos.PosSnType.ToString(), //POS类型
-                                Remark = "流量卡分佣", //备注
-                                BrandId = pos.BrandId, //品牌
-                                TopUserId = TopUserId, //顶级创客
-                                MerUserType = user.MerchantType, //商户创客类型
-                            });
-                            string IdBrand = user.Id + "_" + pos.BrandId;
-                            UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
-                            if (userData == null)
-                            {
-                                userData = db.UserMachineData.Add(new UserMachineData()
+                                });
+                                string IdBrand = user.Id + "_" + pos.BrandId;
+                                UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
+                                if (userData == null)
                                 {
-                                    IdBrand = IdBrand,
-                                }).Entity;
+                                    userData = db.UserMachineData.Add(new UserMachineData()
+                                    {
+                                        IdBrand = IdBrand,
+                                    }).Entity;
+                                    db.SaveChanges();
+                                }
+                                userData.FluxProfit += FluxProfit;
                                 db.SaveChanges();
-                            }
-                            userData.FluxProfit += FluxProfit;
-                            db.SaveChanges();
-                            RedisDbconn.Instance.Clear("UserMachineData:" + IdBrand);
-                            UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
-                            if (account == null)
-                            {
-                                account = db.UserAccount.Add(new UserAccount()
+                                RedisDbconn.Instance.Clear("UserMachineData:" + IdBrand);
+                                UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
+                                if (account == null)
                                 {
-                                    Id = GetUserId,
-                                    UserId = GetUserId,
+                                    account = db.UserAccount.Add(new UserAccount()
+                                    {
+                                        Id = GetUserId,
+                                        UserId = GetUserId,
+                                    }).Entity;
+                                    db.SaveChanges();
+                                }
+                                decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
+                                decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
+                                decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
+                                account.BalanceAmount += FluxProfit;
+                                account.TotalAmount += FluxProfit;
+                                decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
+                                decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
+                                decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
+                                UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
+                                {
+                                    CreateDate = DateTime.Now,
+                                    UpdateDate = DateTime.Now,
+                                    UserId = GetUserId, //创客
+                                    ChangeType = 60, //变动类型
+                                    ProductType = pos.BrandId, //产品类型
+                                    ChangeAmount = FluxProfit, //变更金额
+                                    BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
+                                    AfterTotalAmount = AfterTotalAmount, //变更后总金额
+                                    BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
+                                    AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
+                                    BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
+                                    AfterBalanceAmount = AfterBalanceAmount, //变更后余额
                                 }).Entity;
                                 db.SaveChanges();
+                                RedisDbconn.Instance.Clear("UserAccount:" + GetUserId);
                             }
-                            decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
-                            decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
-                            decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
-                            account.BalanceAmount += FluxProfit;
-                            account.TotalAmount += FluxProfit;
-                            decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
-                            decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
-                            decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
-                            UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
+                            SpModels.TradeFluxRecord edit = spdb.TradeFluxRecord.FirstOrDefault(m => m.Id == trade.Id);
+                            if (edit != null)
                             {
-                                CreateDate = DateTime.Now,
-                                UpdateDate = DateTime.Now,
-                                UserId = GetUserId, //创客
-                                ChangeType = 60, //变动类型
-                                ProductType = pos.BrandId, //产品类型
-                                ChangeAmount = FluxProfit, //变更金额
-                                BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
-                                AfterTotalAmount = AfterTotalAmount, //变更后总金额
-                                BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
-                                AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
-                                BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
-                                AfterBalanceAmount = AfterBalanceAmount, //变更后余额
-                            }).Entity;
-                            db.SaveChanges();
-                            RedisDbconn.Instance.Clear("UserAccount:" + GetUserId);
-                        }
-                        SpModels.TradeFluxRecord edit = spdb.TradeFluxRecord.FirstOrDefault(m => m.Id == trade.Id);
-                        if (edit != null)
-                        {
-                            edit.Status = 2;
-                            spdb.SaveChanges();
+                                edit.Status = 2;
+                                spdb.SaveChanges();
+                            }
                         }
                     }
                 }

+ 16 - 13
AppStart/Helper/SycnSpServer/SycnSpTradeService.cs

@@ -236,23 +236,26 @@ namespace MySystem
                                         // 立刷60天内刷满10000,再返40
                                         if (pos.BrandId == 6 && pos.ActivationState == 1 && pos.CreditTrade >= 10000 && pos.BindingTime > DateTime.Now.AddDays(-60))
                                         {
-                                            PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PxcModels.PosMerchantInfo();
-                                            PxcModels.Users getUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new PxcModels.Users();
-                                            int BuyTopUserId = 0;
-                                            string ParentNav = getUser.ParentNav;
-                                            if (!string.IsNullOrEmpty(ParentNav))
+                                            PxcModels.PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId && m.Sort == 1);
+                                            if(merchant != null)
                                             {
-                                                string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
-                                                if (ParentNavList.Length > 1)
+                                                PxcModels.Users getUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new PxcModels.Users();
+                                                int BuyTopUserId = 0;
+                                                string ParentNav = getUser.ParentNav;
+                                                if (!string.IsNullOrEmpty(ParentNav))
                                                 {
-                                                    BuyTopUserId = int.Parse(ParentNavList[1]);
-                                                }
-                                                else if (ParentNavList.Length == 1)
-                                                {
-                                                    BuyTopUserId = int.Parse(ParentNavList[0]);
+                                                    string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
+                                                    if (ParentNavList.Length > 1)
+                                                    {
+                                                        BuyTopUserId = int.Parse(ParentNavList[1]);
+                                                    }
+                                                    else if (ParentNavList.Length == 1)
+                                                    {
+                                                        BuyTopUserId = int.Parse(ParentNavList[0]);
+                                                    }
                                                 }
+                                                StatService.Instance.doActiveReward(db, merchant, pos, getUser.Id, getUser.ParentNav, BuyTopUserId, 40, 12);
                                             }
-                                            StatService.Instance.doActiveReward(db, merchant, pos, getUser.Id, getUser.ParentNav, BuyTopUserId, 40, 12);
                                         }
                                         db.SaveChanges();
                                     }