Browse Source

押金数据队列和交易数据队列分开

lcl 1 year ago
parent
commit
de23f08a96
2 changed files with 167 additions and 51 deletions
  1. 166 51
      AppStart/GetHaoDaFTPInfoService.cs
  2. 1 0
      Startup.cs

+ 166 - 51
AppStart/GetHaoDaFTPInfoService.cs

@@ -20,11 +20,20 @@ namespace MySystem
         private GetHaoDaFTPInfoService()
         { }
 
+        // 47.108.253.46
+        // 用户名:hdftp
+        // 密:haodatradeftp2024
+        // 目录:/haoda-trade
+
+        public string ftpServerAddress = "ftp://47.108.253.46";
+        public string ftpUser = "hdftp";
+        public string ftpPassword = "haodatradeftp2024";
+
 
         public void Start()
         {
             //每天凌晨执行获取好哒FTP昨日交易数据
-            Thread th2 = new Thread(GetFTPDataInfoYesterdayReady);
+            Thread th2 = new Thread(GetDepositDataReady);
             th2.IsBackground = true;
             th2.Start();
         }
@@ -33,40 +42,30 @@ namespace MySystem
         /// <summary>
         /// 获取好哒FTP昨日交易数据
         /// </summary>
-        public void GetFTPDataInfoYesterdayReady()
+        public void GetDepositDataReady()
         {
             while (true)
             {
-                if (DateTime.Now.Hour > 12 && DateTime.Now.Hour < 22)
-                {
-                    // string check = function.ReadInstance("/GetFTPDepositYesterday/check" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + ".txt");
-                    // if (string.IsNullOrEmpty(check))
-                    // {
-                    //     function.WritePage("/GetFTPDepositYesterday/", "check" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + ".txt", DateTime.Now.ToString());
-                        GetFTPDataInfoYesterday();
+                // if (DateTime.Now.Hour > 10 && DateTime.Now.Hour < 22)
+                // {
+                //     string check = function.ReadInstance("/GetFTPDepositYesterday/check" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + ".txt");
+                //     if (string.IsNullOrEmpty(check))
+                //     {
+                //         function.WritePage("/GetFTPDepositYesterday/", "check" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + ".txt", DateTime.Now.ToString());
+                        GetDepositData();
                         Thread.Sleep(600000);
-                    // }
-                }
-                else
-                {
-                    Thread.Sleep(1800000);
-                }
+                //     }
+                // }
+                // else
+                // {
+                //     Thread.Sleep(1800000);
+                // }
             }
         }
-        public void GetFTPDataInfoYesterday()
+        public void GetDepositData()
         {
-            // 47.108.253.46
-            // 用户名:hdftp
-            // 密:haodatradeftp2024
-            // 目录:/haoda-trade
-
-            // FTP服务器的地址
-            string ftpServerAddress = "ftp://47.108.253.46";
-            // FTP登录凭证
-            string ftpUser = "hdftp";
-            string ftpPassword = "haodatradeftp2024";
             // 要下载的文件路径
-            string filePath = "/haoda-trade/test_deposit_" + DateTime.Now.AddDays(-1).ToString("yyyyMMdd") + ".csv";
+            string filePath = "/haoda-deposit/deposit_" + DateTime.Now.AddDays(-1).ToString("yyyyMMdd") + ".csv";
             
             try
             {
@@ -92,40 +91,34 @@ namespace MySystem
                     {
                         var DataListInfo = DataListItem.Split(',');
 
-                        string SnNo = ""; //sn
-                        string MerNo = ""; //商户编号
-                        string ActDate = ""; //激活时间
-                        string Deposit = ""; //押金金额
-                        string PrizeAmt = ""; //奖励金额
-                        string PrizeDate = ""; //奖励发放时间
-                        string Name = ""; //发放人姓名
-                        string PosKind = ""; //机具型号
-
-                        SnNo = DataListInfo[0];
-                        MerNo = DataListInfo[1];
-                        ActDate = DataListInfo[2];
-                        Deposit = DataListInfo[3];
-                        PrizeAmt = DataListInfo[4];
-                        PrizeDate = DataListInfo[5];
-                        Name = DataListInfo[6];
-                        PosKind = DataListInfo[7];
+                        string SnNo = DataListInfo[0]; //sn
+                        string MerNo = DataListInfo[1]; //商户编号
+                        string ActDate = DataListInfo[2]; //激活时间
+                        string Deposit = DataListInfo[3]; //押金金额
+                        string PrizeAmt = DataListInfo[4]; //奖励金额
+                        string PrizeDate = DataListInfo[5]; //奖励发放时间
+                        string Name = DataListInfo[6]; //发放人姓名
+                        string PosKind = DataListInfo[7]; //机具型号
+
+                        string ActDateString = ActDate.Substring(0, 4) + "-" + ActDate.Substring(4, 2) + "-" + ActDate.Substring(6, 2);
+                        string PrizeDateString = PrizeDate.Substring(0, 4) + "-" + PrizeDate.Substring(4, 2) + "-" + PrizeDate.Substring(6, 2);
 
                         string ProductType = "0";
                         if(PosKind == "1") ProductType = "18";
-                        if(PosKind == "2") ProductType = "19";
-                        if(PosKind == "3") ProductType = "20";
+                        if(PosKind == "4G收款王M820") ProductType = "19";
+                        if(PosKind == "4G收款王M826") ProductType = "20";
                         if(PosKind == "4") ProductType = "21";
 
                         db.BindRecord.Add(new BindRecord()
                         {
                             CreateDate = DateTime.Now,
-                            UpdateTime = DateTime.Parse(ActDate), //机具绑定、解绑时间
-                            CreateTime = DateTime.Parse(ActDate), //商户操作时间
+                            UpdateTime = DateTime.Parse(ActDateString), //机具绑定、解绑时间
+                            CreateTime = DateTime.Parse(ActDateString), //商户操作时间
                             MerSnNo = SnNo, //序列号
                             MerNo = MerNo, //商户编号
                             MerName = Name,
                             SeoTitle = PrizeAmt,
-                            SeoKeyword = ActDate,
+                            SeoKeyword = ActDateString,
                             ProductType = ProductType,
                             Field1 = Deposit,
                             Field2 = PrizeDate,
@@ -136,7 +129,7 @@ namespace MySystem
                         {
                             SnNo = SnNo,
                             CreateTime = DateTime.Now,
-                            UpdateTime = DateTime.Parse(ActDate),
+                            UpdateTime = DateTime.Parse(ActDateString),
                             AgentName = Name,
                             MerRealName = Name,
                             MerNo = MerNo,
@@ -151,7 +144,7 @@ namespace MySystem
                             SnNo = SnNo,
                             CreateDate = DateTime.Now,
                             SeoTitle = Deposit,
-                            ActivateDate = DateTime.Parse(ActDate),
+                            ActivateDate = DateTime.Parse(ActDateString),
                             AgentNo = MerNo,
                             MerRealName = Name,
                             MerNo = MerNo,
@@ -176,5 +169,127 @@ namespace MySystem
             }
         }
 
+
+
+
+
+
+
+
+
+        public void StartTrade()
+        {
+            //每天凌晨执行获取好哒FTP昨日交易数据
+            Thread th2 = new Thread(GetTradeDataReady);
+            th2.IsBackground = true;
+            th2.Start();
+        }
+
+
+        /// <summary>
+        /// 获取好哒FTP昨日交易数据
+        /// </summary>
+        public void GetTradeDataReady()
+        {
+            while (true)
+            {
+                // if (DateTime.Now.Hour > 10 && DateTime.Now.Hour < 22)
+                // {
+                //     string check = function.ReadInstance("/GetFTPTradeYesterday/check" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + ".txt");
+                //     if (string.IsNullOrEmpty(check))
+                //     {
+                //         function.WritePage("/GetFTPTradeYesterday/", "check" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + ".txt", DateTime.Now.ToString());
+                        GetTradeData();
+                        Thread.Sleep(600000);
+                //     }
+                // }
+                // else
+                // {
+                //     Thread.Sleep(1800000);
+                // }
+            }
+        }
+        public void GetTradeData()
+        {
+            // 要下载的文件路径
+            string filePath = "/haoda-trade/" + DateTime.Now.AddDays(-1).ToString("yyyyMMdd") + ".csv";
+            
+            try
+            {
+                // 创建FtpWebRequest对象
+                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpServerAddress + filePath);
+                request.Method = WebRequestMethods.Ftp.DownloadFile;
+                request.Credentials = new NetworkCredential(ftpUser, ftpPassword);
+
+                // 使用WebResponse获取响应
+                FtpWebResponse response = (FtpWebResponse)request.GetResponse();
+
+                // 打开数据流
+                Stream responseStream = response.GetResponseStream();
+                StreamReader reader = new StreamReader(responseStream);
+                // 读取数据
+                string fileContents = reader.ReadToEnd();
+                if (!string.IsNullOrEmpty(fileContents))
+                {
+                    WebCMSEntities db = new WebCMSEntities();
+                    var DataInfo = fileContents.TrimEnd('\n').Split('\n', 2);
+                    var DataList = DataInfo[1].Split('\n');
+                    foreach (var DataListItem in DataList)
+                    {
+                        var DataListInfo = DataListItem.Split(',');
+
+                        string MerNo = DataListInfo[0]; // 商户号
+                        string SnNo = DataListInfo[1]; // 设备号
+                        string OrderNo = DataListInfo[2]; // 订单号
+                        string PayMode = DataListInfo[3]; // 支付方式(微信 支付宝)
+                        string TradeType = DataListInfo[4]; // 交易类型
+                        string TradeAmount = DataListInfo[5]; // 交易金额
+                        string TradeFee = DataListInfo[6]; // 交易手续费
+                        string TradeDate = DataListInfo[7]; // 交易时间
+                        string TradeCycle = DataListInfo[8]; // 结算周期
+                        string PosKind = DataListInfo[9];
+
+                        string TradeDateString = TradeDate.Substring(0, 4) + "-" + TradeDate.Substring(4, 2) + "-" + TradeDate.Substring(6, 2) + " " + TradeDate.Substring(8, 2) + ":" + TradeDate.Substring(10, 2) + ":" + TradeDate.Substring(12, 2);
+
+                        string ProductType = "0";
+                        if(PosKind == "1") ProductType = "18";
+                        if(PosKind == "4G收款王M820") ProductType = "19";
+                        if(PosKind == "4G收款王M826") ProductType = "20";
+                        if(PosKind == "4") ProductType = "21";
+
+                        db.TradeRecord.Add(new TradeRecord()
+                        {
+                            CreateDate = DateTime.Now,
+                            UpdateDate = DateTime.Parse(TradeDateString),
+                            TradeSnNo = SnNo, //序列号
+                            MerNo = MerNo, //商户编号
+                            Remark = "交易成功",
+                            SettleFee = decimal.Parse(function.CheckNum(TradeFee)),
+                            BankCardType = "02",
+                            TradeType = TradeType,
+                            TradeStatus = "00",
+                            TradeAmount = decimal.Parse(function.CheckNum(TradeAmount)),
+                            TradeSerialNo = OrderNo,
+                            ProductType = ProductType,
+                            Field1 = PayMode,
+                            Field2 = TradeCycle,
+                            Status = 1,
+                        });
+                        db.SaveChanges();
+                    }
+                    db.Dispose();
+                }
+
+                // 关闭响应
+                reader.Dispose();
+                responseStream.Dispose();
+                response.Close();
+            }
+            catch (WebException ex)
+            {
+                function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP文件数据异常");
+            }
+        }
+
     }
 }

+ 1 - 0
Startup.cs

@@ -153,6 +153,7 @@ namespace MySystem
 
             //必须打开的
             GetHaoDaFTPInfoService.Instance.Start();
+            GetHaoDaFTPInfoService.Instance.StartTrade();
         }
 
         private void InitMain()