|
@@ -0,0 +1,376 @@
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Data;
|
|
|
+using System.Threading;
|
|
|
+using MySystem.Models.Main;
|
|
|
+using Library;
|
|
|
+using LitJson;
|
|
|
+using System.Net;
|
|
|
+using System.IO;
|
|
|
+using AppConfig;
|
|
|
+
|
|
|
+namespace MySystem
|
|
|
+{
|
|
|
+ /// <summary>
|
|
|
+ /// 获取好哒ftp数据
|
|
|
+ /// </summary>
|
|
|
+ public class GetHaoDaFTPInfoService
|
|
|
+ {
|
|
|
+ public readonly static GetHaoDaFTPInfoService Instance = new GetHaoDaFTPInfoService();
|
|
|
+ private GetHaoDaFTPInfoService()
|
|
|
+ { }
|
|
|
+
|
|
|
+
|
|
|
+ public void Start()
|
|
|
+ {
|
|
|
+ //半小时执行获取好哒FTP交易数据
|
|
|
+ Thread th = new Thread(GetFTPDataInfoHalfHour);
|
|
|
+ th.IsBackground = true;
|
|
|
+ th.Start();
|
|
|
+
|
|
|
+ //每天凌晨执行获取好哒FTP今日交易数据
|
|
|
+ Thread th1 = new Thread(GetFTPDataInfoToday);
|
|
|
+ th1.IsBackground = true;
|
|
|
+ th1.Start();
|
|
|
+
|
|
|
+ //每天凌晨执行获取好哒FTP昨日交易数据
|
|
|
+ Thread th2 = new Thread(GetFTPDataInfoYesterday);
|
|
|
+ th2.IsBackground = true;
|
|
|
+ th2.Start();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 没半小时获取好哒FTP今日交易数据
|
|
|
+ /// </summary>
|
|
|
+ public static void GetFTPDataInfoHalfHour()
|
|
|
+ {
|
|
|
+ // 47.108.253.46
|
|
|
+ // 用户名:hdftp
|
|
|
+ // 密:haodatradeftp2024
|
|
|
+ // 目录:/haoda-trade
|
|
|
+
|
|
|
+ // FTP服务器的地址
|
|
|
+ string ftpServerAddress = Base.HaoDaFtpHost;
|
|
|
+ // FTP登录凭证
|
|
|
+ string ftpUser = Base.HaoDaFtpLoginName;
|
|
|
+ string ftpPassword = Base.HaoDaFtpLoginPwd;
|
|
|
+ // 要下载的文件路径
|
|
|
+ string filePath = "/haoda-trade/" + DateTime.Now.ToString("yyyyMMdd") + ".csv";
|
|
|
+
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ 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();
|
|
|
+ using (StreamReader reader = new StreamReader(responseStream))
|
|
|
+ {
|
|
|
+ WebCMSEntities db = new WebCMSEntities();
|
|
|
+ // 读取数据
|
|
|
+ string fileContents = reader.ReadToEnd();
|
|
|
+ if (!string.IsNullOrEmpty(fileContents))
|
|
|
+ {
|
|
|
+ var DataInfo = fileContents.TrimEnd('\n').Split('\n', 2);
|
|
|
+ var DataList = DataInfo[1].Split('\n');
|
|
|
+ foreach (var DataListItem in DataList)
|
|
|
+ {
|
|
|
+ var DataListInfo = DataListItem.Split(',');
|
|
|
+
|
|
|
+ var MerchantNo = ""; // 商户号
|
|
|
+ var BaseNo = ""; // 设备号
|
|
|
+ var OrderNo = ""; // 订单号
|
|
|
+ var PayWay = ""; // 支付方式(微信 支付宝)
|
|
|
+ var TradeType = ""; // 交易类型
|
|
|
+ var TradeAmount = ""; // 交易金额
|
|
|
+ var TradeFee = ""; // 交易手续费
|
|
|
+ var TradeDate = ""; // 交易时间
|
|
|
+ var TradeCycle = ""; // 结算周期
|
|
|
+
|
|
|
+ MerchantNo = DataListInfo[0];
|
|
|
+ BaseNo = DataListInfo[1];
|
|
|
+ OrderNo = DataListInfo[2];
|
|
|
+ PayWay = DataListInfo[3];
|
|
|
+ TradeType = DataListInfo[4];
|
|
|
+ TradeAmount = DataListInfo[5];
|
|
|
+ TradeFee = DataListInfo[6];
|
|
|
+ TradeDate = DataListInfo[7];
|
|
|
+ TradeCycle = DataListInfo[8];
|
|
|
+
|
|
|
+ var PayMode = 0;
|
|
|
+ if (PayWay.Contains("支付宝")) PayMode = 1;
|
|
|
+ if (PayWay.Contains("微信")) PayMode = 2;
|
|
|
+
|
|
|
+ var merchantAddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.MchtNo == MerchantNo) ?? new MerchantAddInfo();
|
|
|
+ if (merchantAddInfo.Id > 0)
|
|
|
+ {
|
|
|
+ var merchantInfo = db.MerchantInfo.FirstOrDefault(m => m.Id == merchantAddInfo.Id) ?? new MerchantInfo();
|
|
|
+ var orders = db.ConsumerOrders.FirstOrDefault(m => m.SeoTitle == OrderNo && OrderNo == OrderNo) ?? new ConsumerOrders();
|
|
|
+ if (orders.Id == 0)
|
|
|
+ {
|
|
|
+ ConsumerOrders consumerOrders = new ConsumerOrders
|
|
|
+ {
|
|
|
+ Status = 1,
|
|
|
+ CreateDate = DateTime.Parse(TradeDate),
|
|
|
+ UpdateDate = DateTime.Parse(TradeDate),
|
|
|
+ SnNo = BaseNo,
|
|
|
+ PayMoney = decimal.Parse(TradeAmount),
|
|
|
+ PayMode = PayMode,
|
|
|
+ SeoTitle = OrderNo,
|
|
|
+ OrderNo = OrderNo,
|
|
|
+ MerchantId = merchantAddInfo.Id,
|
|
|
+ UserId = merchantInfo.UserId
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ db.SaveChanges();
|
|
|
+ db.Dispose();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关闭响应
|
|
|
+ response.Close();
|
|
|
+ Thread.Sleep(1800000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (WebException ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine("获取好哒FTP文件数据异常: " + ex.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取好哒FTP今日交易数据
|
|
|
+ /// </summary>
|
|
|
+ public static void GetFTPDataInfoToday()
|
|
|
+ {
|
|
|
+ // 47.108.253.46
|
|
|
+ // 用户名:hdftp
|
|
|
+ // 密:haodatradeftp2024
|
|
|
+ // 目录:/haoda-trade
|
|
|
+
|
|
|
+ // FTP服务器的地址
|
|
|
+ string ftpServerAddress = Base.HaoDaFtpHost;
|
|
|
+ // FTP登录凭证
|
|
|
+ string ftpUser = Base.HaoDaFtpLoginName;
|
|
|
+ string ftpPassword = Base.HaoDaFtpLoginPwd;
|
|
|
+ // 要下载的文件路径
|
|
|
+ string filePath = "/haoda-trade/" + DateTime.Now.ToString("yyyyMMdd") + ".csv";
|
|
|
+
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ if (DateTime.Now.Hour > 0 && DateTime.Now.Hour < 9)
|
|
|
+ {
|
|
|
+ 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();
|
|
|
+ using (StreamReader reader = new StreamReader(responseStream))
|
|
|
+ {
|
|
|
+ WebCMSEntities db = new WebCMSEntities();
|
|
|
+ // 读取数据
|
|
|
+ string fileContents = reader.ReadToEnd();
|
|
|
+ if (!string.IsNullOrEmpty(fileContents))
|
|
|
+ {
|
|
|
+ var DataInfo = fileContents.TrimEnd('\n').Split('\n', 2);
|
|
|
+ var DataList = DataInfo[1].Split('\n');
|
|
|
+ foreach (var DataListItem in DataList)
|
|
|
+ {
|
|
|
+ var DataListInfo = DataListItem.Split(',');
|
|
|
+
|
|
|
+ var MerchantNo = ""; // 商户号
|
|
|
+ var BaseNo = ""; // 设备号
|
|
|
+ var OrderNo = ""; // 订单号
|
|
|
+ var PayWay = ""; // 支付方式(微信 支付宝)
|
|
|
+ var TradeType = ""; // 交易类型
|
|
|
+ var TradeAmount = ""; // 交易金额
|
|
|
+ var TradeFee = ""; // 交易手续费
|
|
|
+ var TradeDate = ""; // 交易时间
|
|
|
+ var TradeCycle = ""; // 结算周期
|
|
|
+
|
|
|
+ MerchantNo = DataListInfo[0];
|
|
|
+ BaseNo = DataListInfo[1];
|
|
|
+ OrderNo = DataListInfo[2];
|
|
|
+ PayWay = DataListInfo[3];
|
|
|
+ TradeType = DataListInfo[4];
|
|
|
+ TradeAmount = DataListInfo[5];
|
|
|
+ TradeFee = DataListInfo[6];
|
|
|
+ TradeDate = DataListInfo[7];
|
|
|
+ TradeCycle = DataListInfo[8];
|
|
|
+
|
|
|
+ var PayMode = 0;
|
|
|
+ if (PayWay.Contains("支付宝")) PayMode = 1;
|
|
|
+ if (PayWay.Contains("微信")) PayMode = 2;
|
|
|
+
|
|
|
+ var merchantAddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.MchtNo == MerchantNo) ?? new MerchantAddInfo();
|
|
|
+ if (merchantAddInfo.Id > 0)
|
|
|
+ {
|
|
|
+ var merchantInfo = db.MerchantInfo.FirstOrDefault(m => m.Id == merchantAddInfo.Id) ?? new MerchantInfo();
|
|
|
+ var orders = db.ConsumerOrders.FirstOrDefault(m => m.SeoTitle == OrderNo && OrderNo == OrderNo) ?? new ConsumerOrders();
|
|
|
+ if (orders.Id == 0)
|
|
|
+ {
|
|
|
+ ConsumerOrders consumerOrders = new ConsumerOrders
|
|
|
+ {
|
|
|
+ Status = 1,
|
|
|
+ CreateDate = DateTime.Parse(TradeDate),
|
|
|
+ UpdateDate = DateTime.Parse(TradeDate),
|
|
|
+ SnNo = BaseNo,
|
|
|
+ PayMoney = decimal.Parse(TradeAmount),
|
|
|
+ PayMode = PayMode,
|
|
|
+ SeoTitle = OrderNo,
|
|
|
+ OrderNo = OrderNo,
|
|
|
+ MerchantId = merchantAddInfo.Id,
|
|
|
+ UserId = merchantInfo.UserId
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ db.SaveChanges();
|
|
|
+ db.Dispose();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关闭响应
|
|
|
+ response.Close();
|
|
|
+ Thread.Sleep(1800000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (WebException ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine("获取好哒FTP文件数据异常: " + ex.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取好哒FTP昨日交易数据
|
|
|
+ /// </summary>
|
|
|
+ public static void GetFTPDataInfoYesterday()
|
|
|
+ {
|
|
|
+ // 47.108.253.46
|
|
|
+ // 用户名:hdftp
|
|
|
+ // 密:haodatradeftp2024
|
|
|
+ // 目录:/haoda-trade
|
|
|
+
|
|
|
+ // FTP服务器的地址
|
|
|
+ string ftpServerAddress = Base.HaoDaFtpHost;
|
|
|
+ // FTP登录凭证
|
|
|
+ string ftpUser = Base.HaoDaFtpLoginName;
|
|
|
+ string ftpPassword = Base.HaoDaFtpLoginPwd;
|
|
|
+ // 要下载的文件路径
|
|
|
+ string filePath = "/haoda-trade/" + DateTime.Now.AddDays(-1).ToString("yyyyMMdd") + ".csv";
|
|
|
+
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ if (DateTime.Now.Hour > 0 && DateTime.Now.Hour < 9)
|
|
|
+ {
|
|
|
+ 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();
|
|
|
+ using (StreamReader reader = new StreamReader(responseStream))
|
|
|
+ {
|
|
|
+ WebCMSEntities db = new WebCMSEntities();
|
|
|
+ // 读取数据
|
|
|
+ string fileContents = reader.ReadToEnd();
|
|
|
+ if (!string.IsNullOrEmpty(fileContents))
|
|
|
+ {
|
|
|
+ var DataInfo = fileContents.TrimEnd('\n').Split('\n', 2);
|
|
|
+ var DataList = DataInfo[1].Split('\n');
|
|
|
+ foreach (var DataListItem in DataList)
|
|
|
+ {
|
|
|
+ var DataListInfo = DataListItem.Split(',');
|
|
|
+
|
|
|
+ var MerchantNo = ""; // 商户号
|
|
|
+ var BaseNo = ""; // 设备号
|
|
|
+ var OrderNo = ""; // 订单号
|
|
|
+ var PayWay = ""; // 支付方式(微信 支付宝)
|
|
|
+ var TradeType = ""; // 交易类型
|
|
|
+ var TradeAmount = ""; // 交易金额
|
|
|
+ var TradeFee = ""; // 交易手续费
|
|
|
+ var TradeDate = ""; // 交易时间
|
|
|
+ var TradeCycle = ""; // 结算周期
|
|
|
+
|
|
|
+ MerchantNo = DataListInfo[0];
|
|
|
+ BaseNo = DataListInfo[1];
|
|
|
+ OrderNo = DataListInfo[2];
|
|
|
+ PayWay = DataListInfo[3];
|
|
|
+ TradeType = DataListInfo[4];
|
|
|
+ TradeAmount = DataListInfo[5];
|
|
|
+ TradeFee = DataListInfo[6];
|
|
|
+ TradeDate = DataListInfo[7];
|
|
|
+ TradeCycle = DataListInfo[8];
|
|
|
+
|
|
|
+ var PayMode = 0;
|
|
|
+ if (PayWay.Contains("支付宝")) PayMode = 1;
|
|
|
+ if (PayWay.Contains("微信")) PayMode = 2;
|
|
|
+
|
|
|
+ var merchantAddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.MchtNo == MerchantNo) ?? new MerchantAddInfo();
|
|
|
+ if (merchantAddInfo.Id > 0)
|
|
|
+ {
|
|
|
+ var merchantInfo = db.MerchantInfo.FirstOrDefault(m => m.Id == merchantAddInfo.Id) ?? new MerchantInfo();
|
|
|
+ var orders = db.ConsumerOrders.FirstOrDefault(m => m.SeoTitle == OrderNo && OrderNo == OrderNo) ?? new ConsumerOrders();
|
|
|
+ if (orders.Id == 0)
|
|
|
+ {
|
|
|
+ ConsumerOrders consumerOrders = new ConsumerOrders
|
|
|
+ {
|
|
|
+ Status = 1,
|
|
|
+ CreateDate = DateTime.Parse(TradeDate),
|
|
|
+ UpdateDate = DateTime.Parse(TradeDate),
|
|
|
+ SnNo = BaseNo,
|
|
|
+ PayMoney = decimal.Parse(TradeAmount),
|
|
|
+ PayMode = PayMode,
|
|
|
+ SeoTitle = OrderNo,
|
|
|
+ OrderNo = OrderNo,
|
|
|
+ MerchantId = merchantAddInfo.Id,
|
|
|
+ UserId = merchantInfo.UserId
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ db.SaveChanges();
|
|
|
+ db.Dispose();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关闭响应
|
|
|
+ response.Close();
|
|
|
+ Thread.Sleep(1800000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (WebException ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine("获取好哒FTP文件数据异常: " + ex.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|