Pārlūkot izejas kodu

流量卡分佣算法
二维码生成队列换成redis
集成立刷逻辑

lichunlei 3 gadi atpakaļ
vecāks
revīzija
dd3a25a4fd

+ 25 - 0
AppStart/Helper/MakeReferenceQrCodeService.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Threading;
 using MySystem.PxcModels;
 using Library;
 using LitJson;
@@ -15,6 +16,30 @@ namespace MySystem
         private MakeReferenceQrCodeService()
         { }
 
+        public void StartListen()
+        {
+            Thread th = new Thread(Loop);
+            th.IsBackground = true;
+            th.Start();
+        }
+
+        private void Loop()
+        { 
+            bool op = true;
+            while (op)
+            {
+                string content = RedisDbconn.Instance.RPop<string>("MakeReferenceQrCode");
+                if (!string.IsNullOrEmpty(content))
+                {
+                    Start(content);
+                }
+                else
+                {
+                    Thread.Sleep(5000);
+                }
+            }
+        }
+
         public void Start(string uid)
         {
             try

+ 219 - 0
AppStart/Helper/StatService.cs

@@ -30,6 +30,7 @@ namespace MySystem
                     // dosomething2(doDate);
                     StartEverDay(doDate);
                     dosomething4(doDate);
+                    ListenFluxRecord(doDate);
                 }
                 string Msg = "success";
                 jobInfo.Status = Msg == "success" ? 1 : 0;
@@ -957,6 +958,224 @@ namespace MySystem
         }
 
 
+        // 4. 前一天的流量卡记录和匹配
+        public void ListenFluxRecord(string date)
+        { 
+            Thread th = new Thread(CheckFluxForTrade);
+            th.IsBackground = true;
+            th.Start(date);
+        }
+        public void doFluxRecord(string date)
+        {
+            function.WriteLog(DateTime.Now.ToString(), "执行流量费返佣");
+            SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
+            WebCMSEntities db = new WebCMSEntities();
+            DateTime yesterday = DateTime.Parse(date + " 00:00:00");
+            DateTime today = DateTime.Parse(DateTime.Parse(date).AddDays(1).ToString("yyyy-MM-dd") + " 00:00:00");
+            List<SpModels.TradeFluxRecord> trades = spdb.TradeFluxRecord.Where(m => m.CreateDate >= yesterday && m.CreateDate < today && m.Status == 1).ToList();
+            foreach (SpModels.TradeFluxRecord trade in trades)
+            {
+                try
+                {
+                    string OrderNo = trade.TradeSerialNo; //单号
+                    DateTime TradeDate = trade.CreateDate.Value;
+                    string TradeMonth = TradeDate.ToString("yyyyMM");
+                    decimal FeeAmount = trade.FeeAmount; //流量费
+                    if (trade.ProductType == "1" || trade.ProductType == "4")
+                    {
+                        FeeAmount = FeeAmount / 100;
+                    }
+                    string TradeSnNo = trade.TradeSnNo; //机具SN
+                    decimal FluxProfit = 0;
+                    if (trade.ProductType == "1" && FeeAmount == 60)
+                    {
+                        FluxProfit = 24;
+                    }
+                    else if (trade.ProductType != "1" && FeeAmount == 48)
+                    {
+                        FluxProfit = 12;
+                    }
+                    if (FluxProfit > 0)
+                    {
+                        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)
+                        {
+                            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))
+                            {
+                                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]);
+                                }
+                            }
+                            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()
+                                {
+                                    CreateDate = DateTime.Now,
+                                    UpdateDate = DateTime.Now,
+                                    UserId = GetUserId, //创客
+                                    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()
+                                {
+                                    IdBrand = IdBrand,
+                                }).Entity;
+                                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()
+                                {
+                                    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);
+                        }
+                        SpModels.TradeFluxRecord edit = spdb.TradeFluxRecord.FirstOrDefault(m => m.Id == trade.Id);
+                        if (edit != null)
+                        {
+                            edit.Status = 2;
+                            spdb.SaveChanges();
+                        }
+                    }
+                }
+                catch (Exception ex)
+                {
+                    function.WriteLog(DateTime.Now.ToString() + "\n$" + trade.Id + "$\n" + ex.ToString(), "流量卡分佣异常");
+                }
+            }
+            spdb.Dispose();
+            db.Dispose();
+            function.WriteLog(DateTime.Now.ToString() + "\n", "执行流量费返佣");
+        }
+        public void CheckFluxForTrade(object sender)
+        {
+            string date = sender.ToString();
+            function.WriteLog(DateTime.Now.ToString(), "扫描金控交易记录中的流量费");
+            SpModels.WebCMSEntities spdb = new SpModels.WebCMSEntities();
+            DateTime start = DateTime.Parse(date + " 00:00:00");
+            DateTime end = start.AddDays(1);
+            var list = spdb.TradeRecord.Select(m => new { m.Id, m.CreateDate, m.ProductType }).Where(m => m.CreateDate > start && m.CreateDate < end && m.ProductType == "1").OrderBy(m => m.CreateDate);
+            foreach (var sub in list.ToList())
+            {
+                try
+                {
+                    SpModels.TradeRecord trade = spdb.TradeRecord.FirstOrDefault(m => m.Id == sub.Id);
+                    if (trade != null)
+                    {
+                        string content = trade.SeoDescription;
+                        if (!string.IsNullOrEmpty(content))
+                        {
+                            content = System.Web.HttpUtility.UrlDecode(content);
+                            JsonData jsonObj = JsonMapper.ToObject(content);
+                            decimal terminalDataFlowFee = decimal.Parse(function.CheckNum(jsonObj["terminalDataFlowFee"].ToString()));
+                            if (terminalDataFlowFee > 0)
+                            {
+                                spdb.TradeFluxRecord.Add(new SpModels.TradeFluxRecord()
+                                {
+                                    SeoDescription = trade.TradeSerialNo,
+                                    FeeAmount = terminalDataFlowFee,
+                                    TradeSerialNo = function.MD5_16(trade.TradeSerialNo),
+                                    CreateDate = trade.CreateDate,
+                                    TradeSnNo = trade.TradeSnNo,
+                                    ProductType = trade.ProductType,
+                                    Status = 1,
+                                });
+                                spdb.SaveChanges();
+                            }
+                        }
+                    }
+                }
+                catch (Exception ex)
+                {
+                    function.WriteLog(DateTime.Now.ToString() + "\n$" + sub.Id + "$\n" + ex.ToString(), "扫描金控交易记录中的流量费异常");
+                }
+            }
+            spdb.Dispose();
+            function.WriteLog(DateTime.Now.ToString() + "\n", "扫描金控交易记录中的流量费");
+
+            doFluxRecord(date);
+        }
+
+
 
 
 

+ 2 - 2
AppStart/Helper/SycnSpServer/SycnSpActiveService.cs

@@ -42,7 +42,7 @@ namespace MySystem
                         {
                             op = true;
                         }
-                        else if (act.ProductType == "2" || act.ProductType == "4")
+                        else if (act.ProductType == "2" || act.ProductType == "4" || act.ProductType == "6")
                         {
                             op = true;
                         }
@@ -54,7 +54,7 @@ namespace MySystem
                             {
                                 // pos.ActivationState = 1;
                                 // pos.ActivationTime = DateTime.Now;
-                                if (pos.BrandId == 2 || pos.BrandId == 4 || pos.BrandId == 5)
+                                if (pos.BrandId == 2 || pos.BrandId == 4 || pos.BrandId == 5 || pos.BrandId == 6)
                                 {
                                     pos.SeoKeyword = act.SeoTitle;
                                     db.SaveChanges();

+ 38 - 19
AppStart/Helper/SycnSpServer/SycnSpTradeService.cs

@@ -120,6 +120,18 @@ namespace MySystem
                                             }
                                             if (trade.TradeType == "200") QrPayFlag = 1;
                                         }
+                                        else if (pos.BrandId == 6)
+                                        {
+                                            TradeAmount = TradeAmount / 100;
+                                            if (trade.BankCardType == "01" || trade.BankCardType == "11")
+                                            {
+                                                BankCardType = 0;
+                                            }
+                                            else
+                                            {
+                                                BankCardType = 1;
+                                            }
+                                        }
                                         int BrandId = int.Parse(trade.ProductType);
                                         if (trade.MerNo.StartsWith("M900"))
                                         {
@@ -147,6 +159,13 @@ namespace MySystem
                                             TopUserId = TopUserId, //顶级创客
                                             MerUserId = pos.UserId, //商户直属创客
                                         });
+                                        decimal CheckMoney = 1000;
+                                        int CheckDays = 20;
+                                        if (pos.BrandId == 6)
+                                        { 
+                                            CheckMoney = 5000;
+                                            CheckDays = 30;
+                                        }
                                         if (BankCardType == 1)
                                         {
                                             pos.CreditTrade += TradeAmount;
@@ -155,11 +174,11 @@ namespace MySystem
                                         {
                                             pos.DebitCardTrade += TradeAmount;
                                         }
-                                        if (pos.CreditTrade < 1000)
+                                        if (pos.CreditTrade < CheckMoney)
                                         {
                                             pos.IsPurchase = 99;
                                         }
-                                        else if (pos.CreditTrade >= 1000 && pos.ActivationState == 0 && pos.BindingTime > DateTime.Now.AddDays(-20))
+                                        else if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0 && pos.BindingTime > DateTime.Now.AddDays(-CheckDays))
                                         {
                                             pos.IsPurchase = 0;
                                             pos.ActivationState = 1;
@@ -231,23 +250,23 @@ namespace MySystem
                         if (trade.TradeAmount == 9900 || trade.TradeAmount == 19900 || trade.TradeAmount == 29900)
                         {
                             op = false;
-                            // TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
-                            // if (edit != null)
-                            // {
-                            //     edit.Status = 2;
-                            // }
-                            // spdb.SaveChanges();
+                            TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
+                            if (edit != null)
+                            {
+                                edit.Status = 2;
+                            }
+                            spdb.SaveChanges();
                         }
                     }
                     if (trade.DiscountRateFlag == "True")
                     { 
                         op = false;
-                        // TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
-                        // if (edit != null)
-                        // {
-                        //     edit.Status = 2;
-                        // }
-                        // spdb.SaveChanges();
+                        TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
+                        if (edit != null)
+                        {
+                            edit.Status = 2;
+                        }
+                        spdb.SaveChanges();
                     }
                     if (op)
                     {
@@ -329,11 +348,11 @@ namespace MySystem
                                     });
                                     db.SaveChanges();
                                 }
-                                // TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
-                                // if (edit != null)
-                                // {
-                                //     edit.Status = 2;
-                                // }
+                                TradeRecord edit = spdb.TradeRecord.FirstOrDefault(m => m.Id == trade.Id);
+                                if (edit != null)
+                                {
+                                    edit.Status = 2;
+                                }
                                 spdb.SaveChanges();
                             }
                         }

+ 0 - 4
AppStart/RabbitMQClient.cs

@@ -209,10 +209,6 @@ namespace MySystem
                 {
                     MerchantConfirmService.Instance.Start(MsgContent);
                 }
-                else if (QueueName == "MakeReferenceQrCode")
-                {
-                    MakeReferenceQrCodeService.Instance.Start(MsgContent);
-                }
                 else if (QueueName == "DeleteMySqlData")
                 {
                     DeleteMySqlDataService.Instance.Start(MsgContent);

+ 3 - 1
Startup.cs

@@ -223,13 +223,15 @@ namespace MySystem
             ActiveRewardTimer.Instance.Start(); //实时处理激活记录
             TradeStatTimer.Instance.Start(); //交易统计
             ChangePosTimer.Instance.Start(); //售后换新执行机具数据转移
-            RabbitMQClient.Instance.StartReceive("MakeReferenceQrCode");
+            MakeReferenceQrCodeService.Instance.StartListen(); //生成创客邀请二维码
             SycnSpBindService.Instance.Start(); //同步SP绑定数据
             SycnSpMerchantService.Instance.Start(); //同步SP商户数据
             SycnSpActiveService.Instance.Start(); //同步SP激活数据
             SycnSpTradeService.Instance.Start(); //同步SP交易数据
             //必须打开的
 
+
+            // StatService.Instance.ListenFluxRecord();
             // StatService.Instance.StartEverDay2();
             // ProfitHelper.Instance.StatProfit("202203"); //统计分润
             // TestHelper.Instance.Start();

BIN
bin/Debug/netcoreapp3.0/MySystem.dll


BIN
bin/Debug/netcoreapp3.0/MySystem.pdb


BIN
bin/release/netcoreapp3.0/MySystem.dll


BIN
bin/release/netcoreapp3.0/MySystem.pdb


BIN
obj/Debug/netcoreapp3.0/MySystem.dll


BIN
obj/Debug/netcoreapp3.0/MySystem.pdb


BIN
obj/release/netcoreapp3.0/MySystem.dll


BIN
obj/release/netcoreapp3.0/MySystem.pdb