123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Data;
- using System.Threading;
- using Library;
- using LitJson;
- using System.Net;
- using System.IO;
- using MySystem.SpModels;
- namespace MySystem
- {
- /// <summary>
- /// 获取好哒ftp数据
- /// </summary>
- public class GetHaoDaFTPInfoService
- {
- public readonly static GetHaoDaFTPInfoService Instance = new GetHaoDaFTPInfoService();
- private GetHaoDaFTPInfoService()
- { }
- public void Start()
- {
- //每天凌晨执行获取好哒FTP昨日交易数据
- Thread th2 = new Thread(GetFTPDataInfoYesterdayReady);
- th2.IsBackground = true;
- th2.Start();
- }
- /// <summary>
- /// 获取好哒FTP昨日交易数据
- /// </summary>
- public void GetFTPDataInfoYesterdayReady()
- {
- 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();
- Thread.Sleep(600000);
- // }
- }
- else
- {
- Thread.Sleep(1800000);
- }
- }
- }
- public void GetFTPDataInfoYesterday()
- {
- // 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";
-
- 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 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 ProductType = "0";
- if(PosKind == "1") ProductType = "18";
- if(PosKind == "2") ProductType = "19";
- if(PosKind == "3") ProductType = "20";
- if(PosKind == "4") ProductType = "21";
- db.BindRecord.Add(new BindRecord()
- {
- CreateDate = DateTime.Now,
- UpdateTime = DateTime.Parse(ActDate), //机具绑定、解绑时间
- CreateTime = DateTime.Parse(ActDate), //商户操作时间
- MerSnNo = SnNo, //序列号
- MerNo = MerNo, //商户编号
- MerName = Name,
- SeoTitle = PrizeAmt,
- SeoKeyword = ActDate,
- ProductType = ProductType,
- Field1 = Deposit,
- Field2 = PrizeDate,
- Status = 1,
- });
- db.Merchants.Add(new Merchants()
- {
- SnNo = SnNo,
- CreateTime = DateTime.Now,
- UpdateTime = DateTime.Parse(ActDate),
- AgentName = Name,
- MerRealName = Name,
- MerNo = MerNo,
- MerName = Name,
- ProductType = ProductType,
- Status = 1,
- });
- db.SaveChanges();
- db.ActivateRecord.Add(new ActivateRecord()
- {
- SnNo = SnNo,
- CreateDate = DateTime.Now,
- SeoTitle = Deposit,
- ActivateDate = DateTime.Parse(ActDate),
- AgentNo = MerNo,
- MerRealName = Name,
- MerNo = MerNo,
- MerName = Name,
- ProductType = ProductType,
- ChannelSerial = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
- Status = 1,
- });
- db.SaveChanges();
- }
- db.Dispose();
- }
- // 关闭响应
- reader.Dispose();
- responseStream.Dispose();
- response.Close();
- }
- catch (WebException ex)
- {
- function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP文件数据异常");
- }
- }
- }
- }
|