Browse Source

手动补订单奖励

lcl 10 months ago
parent
commit
62e04a1afb
3 changed files with 235 additions and 65 deletions
  1. 232 65
      AppStart/Helper/PosCouponPrize/PosCouponPrizeService.cs
  2. 2 0
      Startup.cs
  3. 1 0
      appsettings.json

+ 232 - 65
AppStart/Helper/PosCouponPrize/PosCouponPrizeService.cs

@@ -313,86 +313,253 @@ namespace MySystem
         }
 
 
-        public void StartTmp()
-        {
-            Thread th = new Thread(tmpuse);
-            th.IsBackground = true;
-            th.Start();
-        }
 
-        public void tmpuse()
+        public void AddPrize(int OrderId)
         { 
-            List<string> OrderNos = new List<string>();
-            // OrderNos.Add("BM2024060113545453402672795");
-
-            List<int> ChkIds = new List<int>(); //机具券商品Id集合
-            ChkIds.Add(10);
-            ChkIds.Add(11);
-            ChkIds.Add(77);
-            ChkIds.Add(78);
-            ChkIds.Add(79);
-            ChkIds.Add(92);
-            DateTime chkDate = DateTime.Parse("2024-06-01 00:00:00");
             WebCMSEntities db = new WebCMSEntities();
             OpModels.WebCMSEntities opdb = new OpModels.WebCMSEntities();
-            List<Orders> orders = db.Orders.Where(m => m.CreateDate >= chkDate && OrderNos.Contains(m.OrderNo) && ChkIds.Contains(m.ProductId) && m.Status > 0).ToList();
-            foreach(Orders order in orders)
+            Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId);
+            if(order != null)
             {
-                int Kind = 0;
-                if (order.ProductId == 10)
-                {
-                    Kind = 1;
-                }
-                else if (order.ProductId == 11)
-                {
-                    Kind = 2;
-                }
-                int CouponCount = 0;
-                if(Kind == 1)
-                {
-                    CouponCount = 3 * order.BuyCount;
-                }
-                else if(Kind == 2)
+                List<int> ChkIds = new List<int>(); //机具券商品Id集合
+                ChkIds.Add(10);
+                ChkIds.Add(11);
+                ChkIds.Add(77);
+                ChkIds.Add(78);
+                ChkIds.Add(79);
+                ChkIds.Add(92);
+                
+                //判断是否是指定商品
+                if(ChkIds.Contains(order.ProductId))
                 {
-                    CouponCount = 2 * order.BuyCount;
-                }
+                    
+                    int Kind = 0;
+                    if (order.ProductId == 10)
+                    {
+                        Kind = 1;
+                    }
+                    else if (order.ProductId == 11)
+                    {
+                        Kind = 2;
+                    }
+                    int CouponCount = 0;
+                    if(Kind == 1)
+                    {
+                        CouponCount = 3 * order.BuyCount;
+                    }
+                    else if(Kind == 2)
+                    {
+                        CouponCount = 2 * order.BuyCount;
+                    }
 
-                UserAccountRecord record = db.UserAccountRecord.FirstOrDefault(m => m.Id >= 4579675 && m.QueryCount == order.Id && m.ChangeType == 112) ?? new UserAccountRecord();
 
-                UserRankItem orderUser = GetUserLevel2(order.UserId, order.PayDate.Value, false);
-                if(orderUser.UserLevel == 0) 
-                {
-                    PreUserLevel(db, order.UserId, 1, DateTime.Parse("2025-01-01 00:00:00"));
-                }
-                string ParentNav = orderUser.ParentNav + "," + orderUser.Id + ",";
-                string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
-                Array.Reverse(ParentNavList);
-                int index = 0;
-                bool DirectPrizeFlag = false; //推荐奖励发放标识
-                foreach(string ParentId in ParentNavList)
-                {
-                    UserRankItem parentUser = GetUserLevel2(int.Parse(ParentId), order.PayDate.Value, index > 0);
-                    index += 1;
-                    if(index == 1 && (orderUser.LeaderLevel > 0 || orderUser.OperateLevel > 0) && !DirectPrizeFlag)
+                    UserRankItem orderUser = GetUserLevel(order.UserId, false);
+                    if(orderUser.UserLevel == 0) 
                     {
-                        // DirectPrize(db, order.Id, order.UserId, order.BuyCount);
-                        if(record.UserId != order.UserId) function.WriteLog("下单人--订单号:" + order.OrderNo + ";应发对象:" + order.UserId + ";实发对象:" + record.UserId + ";发放金额:" + order.BuyCount + "00;", "推荐奖励计算");
-                        DirectPrizeFlag = true;
+                        PreUserLevel(db, order.UserId, 1, DateTime.Parse("2025-01-01 00:00:00"));
                     }
-                    if(index > 1)
+                    List<string> codes = function.CheckNull(order.SnNos).Split(',').ToList();
+                    string ParentNav = orderUser.ParentNav + "," + orderUser.Id + ",";
+                    string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
+                    Array.Reverse(ParentNavList);
+                    int index = 0;
+                    bool DirectPrizeFlag = false; //推荐奖励发放标识
+                    int BuyPrizeFlag = 0; //购机奖励发放标识
+                    bool BackAccountFlag = false; //备用金返余额标识
+                    bool BigLeaderFlag = false; //大盟主标记
+                    decimal BuyPrize = 0; //购机奖励
+                    
+                    foreach(string ParentId in ParentNavList)
                     {
-                        if(Utils.Instance.IsStandardUser2(parentUser.Id, order.PayDate.Value) && !DirectPrizeFlag)
+                        UserRankItem parentUser = GetUserLevel(int.Parse(ParentId), index > 0);
+                        if(parentUser.Id > 0)
                         {
-                            // DirectPrize(db, order.Id, parentUser.Id, order.BuyCount);
-                            if(record.UserId != parentUser.Id) function.WriteLog("上级--订单号:" + order.OrderNo + ";应发对象:" + parentUser.Id + ";实发对象:" + record.UserId + ";发放金额:" + order.BuyCount + "00;", "推荐奖励计算");
-                            DirectPrizeFlag = true;
+                            
+                            index += 1;
+                            if(index == 1)
+                            {
+                                
+                                
+                                
+                            }
+                            if(index == 1 && (orderUser.LeaderLevel > 0 || orderUser.OperateLevel > 0) && !DirectPrizeFlag)
+                            {
+                                
+                                DirectPrize(db, order.Id, order.UserId, order.BuyCount);
+                                DirectPrizeFlag = true;
+                            }
+                            if(index > 1)
+                            {
+                                bool IsStandardUser = Utils.Instance.IsStandardUser(parentUser.Id);
+                                
+                                
+                                if(IsStandardUser && !DirectPrizeFlag)
+                                {
+                                    
+                                    DirectPrize(db, order.Id, parentUser.Id, order.BuyCount);
+                                    DirectPrizeFlag = true;
+                                }
+                            }
+                            
+                            
+                            
+                            
+                            if(parentUser.AgoLeaderLevel > 0 && CheckLeaderReserve(db, order.BuyCount, parentUser.Id))
+                            {
+                                
+                                //购机奖
+                                if(parentUser.LeaderLevel > 0)
+                                {
+                                    decimal CurBuyPrize = GetBuyPrize(parentUser, order);
+                                    decimal GetPrize = CurBuyPrize - BuyPrize;
+                                    
+                                    if(GetPrize > 0 && BuyPrizeFlag < 2)
+                                    {
+                                        bool PrizeFlag = true;
+                                        int ChangeType = 118;
+                                        if(parentUser.OperateLevel == 1)
+                                        {
+                                            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(parentUser.OperateLevel == 2 && CurBuyPrize == 100) BuyPrizeFlag = 2;
+                                }
+                                else if(parentUser.OperateLevel > 0 && CheckOpReserve(opdb, order.BuyCount, parentUser.Id) && BuyPrizeFlag < 2)
+                                {
+                                    
+                                    //购机奖
+                                    decimal CurBuyPrize = GetBuyPrize(parentUser, order);
+                                    decimal GetPrize = CurBuyPrize - BuyPrize;
+                                    
+                                    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;
+                                        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);
+                                }
+
+                                //给券打大盟主标记
+                                // if(parentUser.LeaderLevel == 1 && CheckLeaderReserve(db, order.BuyCount, parentUser.Id) && !BigLeaderFlag)
+                                // {
+                                    
+                                //     int LeaderId = CheckPosCouponLeaderFlag(db, parentUser.Id, order.BuyCount, codes);
+                                //     if(LeaderId > 0)
+                                //     {
+                                //         BigLeaderFlag = true;
+                                        
+                                //     }
+                                // }
+                                // else if(parentUser.LeaderLevel == 2 && !BigLeaderFlag)
+                                // {
+                                    
+                                //     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();
+                                        
+                                //         SetPosCouponLeaderFlag(db, parentUser.Id, order.BuyCount, couponIds);
+                                        
+                                //     }
+                                // }
+                            }
+                            else if(parentUser.OperateLevel > 0 && CheckOpReserve(opdb, order.BuyCount, parentUser.Id) && BuyPrizeFlag < 2)
+                            {
+                                
+                                //购机奖
+                                decimal CurBuyPrize = GetBuyPrize(parentUser, order);
+                                decimal GetPrize = CurBuyPrize - BuyPrize;
+                                
+                                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;
+
+                                    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(!DirectPrizeFlag && record.Id == 0)
-                {
-                    function.WriteLog("没发--订单号:" + order.OrderNo + ";发放金额:" + order.BuyCount + "00;", "推荐奖励计算");
-                }
             }
             db.Dispose();
             opdb.Dispose();

+ 2 - 0
Startup.cs

@@ -255,6 +255,8 @@ namespace MySystem
                 TradeFilterService.Instance.Start(); //营训奖励拦截
                 WifiTradeHelper.Instance.Start(); //每月1号统计上月wifi交易 
 
+                // PosCouponPrizeService.Instance.AddPrize(595246);
+
                 
                 // RabbitMQClientV2.Instance.CreateConn("KXS_WIFI_TRADE_QUEUE"); //推送wifi每月交易额
 

+ 1 - 0
appsettings.json

@@ -26,6 +26,7 @@
     "MpSqlConnStr": "server=rm-2vc27k81v217qs1t55o.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=QrCodePlateMainServer;password=ll4DFaALMu9YIooM;database=QrCodePlateMainServer;charset=utf8;",
     "MpSqlConnStr2": "server=rm-2vc27k81v217qs1t55o.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=QrCodePlateMainServer;password=ll4DFaALMu9YIooM;database=QrCodePlateMainServer2;charset=utf8;",
     "RdsStatSqlConnStr": "server=rm-2vc27k81v217qs1t55o.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=KxsStatServer;password=mzeqjriUWore0dwT;database=KxsStatServer;charset=utf8;",
+    "JavaSqlConnStr": "server=47.109.61.191;port=3306;user=root;password=HDlNs1ZpG5iR9D9I;database=kxs_sys;charset=utf8;",
     "RedisConnStr": "r-2vc7uglenfmzmlvrnopd.redis.cn-chengdu.rds.aliyuncs.com:6379,password=AZp2ns01w07YW9K0,DefaultDatabase=0,poolsize=500,preheat=50,asyncPipeline=true",
     "IOSAppVersion": "1.0.0",
     "AndroidAppVersion": "1.0.0",