Prechádzať zdrojové kódy

Merge branch 'DuGuYang'

lcl 6 mesiacov pred
rodič
commit
00b7e8bc5f

+ 6 - 0
Config/Base.cs

@@ -12,6 +12,12 @@ namespace AppConfig
         public static string defaultImage = Library.ConfigurationManager.AppSettings["Host"].ToString() + "/skin/app/default/static/images/default.jpg";
         public static string SqlConnStr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
 
+        //好哒FTP
+        public static string HaoDaFtpHost = Library.ConfigurationManager.AppSettings["HaoDaFtpHost"].ToString();
+        public static string HaoDaFtpLoginName = Library.ConfigurationManager.AppSettings["HaoDaFtpLoginName"].ToString();
+        public static string HaoDaFtpLoginPwd = Library.ConfigurationManager.AppSettings["HaoDaFtpLoginPwd"].ToString();
+
+
 
         #region 数据库结构
         public static Dictionary<string, Dictionary<string, string>> mainTables = new Dictionary<string, Dictionary<string, string>>();

+ 1 - 1
Entity/HaoDa/HaodaParam.cs

@@ -11,6 +11,6 @@ namespace MySystem
         public static string BoxAppId = "AP8322645764893728768";
         public static string BoxAppSecret = "je1TElprp3jzWETsG3FcWqtmpreEHqZS";
         public static string BoxPublicKey = "";
-        public static string BrhCode = "";
+        public static string BrhCode = "015001";
     }
 }

+ 4 - 3
Startup.cs

@@ -135,13 +135,14 @@ namespace MySystem
             });
 
             initMainServer();
-            if(Library.ConfigurationManager.EnvironmentFlag == 1)
+            if (Library.ConfigurationManager.EnvironmentFlag == 1)
             {
                 TestHaoDaService.Instance.Start(); //好哒测试
                 // MerchantStandardService.Instance.Start();
             }
-            if(Library.ConfigurationManager.EnvironmentFlag == 2)
+            if (Library.ConfigurationManager.EnvironmentFlag == 2)
             {
+                // GetHaoDaFTPInfoService.Instance.Start(); // 获取好哒FTP交易数据
                 GetTencentAddressInfoService.Instance.Start(); // 获取腾讯地图地址
                 GetStoreNoHelper.Instance.Start(); //获取商户门店号、微信支付宝商户号
                 MerchantConfirmService.Instance.Start(); //提交商户进件
@@ -170,7 +171,7 @@ namespace MySystem
                 ActiveRewardService.Instance.StartOpenReward();
                 ActiveRewardService.Instance.StartLeaderReward();
                 ActiveRewardService.Instance.StartOperateReward();
-                
+
                 MerchantStandardService.Instance.Start(); //商户缴纳服务费次月活动交易额大于等于1W,奖励进件创客50元
                 MerchantStandardService.Instance.StartThree(); //商户缴纳服务费次月起连续不间断三个月,每月活动交易额大于1W,奖励进件创客100元
                 MerchantStandardService.Instance.StartActive();

+ 1 - 1
Util/HaoDa/CheckWeChatBindService.cs

@@ -28,7 +28,7 @@ namespace MySystem
             while (true)
             {
                 string CheckDate = DateTime.Now.AddMinutes(-15).ToString("yyyy-MM-dd HH:mm:ss");
-                DataTable dt = CustomerSqlConn.dtable("select Id from MerchantAddInfo where HdStatus=3 and HdBindWeChat=0 and HdPassDate<'" + CheckDate + "' and OutMchtNo!='' and OutMchtNo is not null", AppConfig.Base.SqlConnStr);
+                DataTable dt = CustomerSqlConn.dtable("select Id from MerchantAddInfo where HdStatus=3 and HdBindWeChat=0 and BrandId=0 and HdPassDate<'" + CheckDate + "' and OutMchtNo!='' and OutMchtNo is not null", AppConfig.Base.SqlConnStr);
                 foreach (DataRow dr in dt.Rows)
                 {
                     StartDo(int.Parse(function.CheckInt(dr["Id"].ToString())));

+ 45 - 36
Util/HaoDa/CheckWeChatSignService.cs

@@ -84,52 +84,66 @@ namespace MySystem
                     //查询商户是否存在
                     if (merchantadd != null)
                     {
-                        // merchantadd.Status = 1;
+                        MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == mId);
                         merchantadd.StoreNo = dic["data"]["storeNo"].ToString();
                         merchantadd.HdStatus = 1; //0 待审核 1 已通过 2 已开通分账 3 已添加接收方
                         merchantadd.OutMchtNo = dic["data"]["outMchtNo"].ToString();
-                        MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == mId);
-                        if (merchant != null)
-                        {
-                            merchant.Status = 1;
-                        }
-                        //商户开通分账
-                        JsonData Info = JsonMapper.ToObject(HaoDaHelper.Instance.OpenDivideAccounts(merchantadd.OutMchtNo, merchantadd.StoreNo, merchantadd.BrandId));
-                        //开通失败
-                        if (Info["resultCode"].ToString() == "0")
+                        if (merchantadd.BrandId == 1)
                         {
-                            merchantadd.Status = -1;
-                            merchantadd.WeChatRemark = Info["errorDesc"].ToString();
+                            merchantadd.Status = 2;
+                            merchantadd.QueryCount = 2;
+
+                            merchant.Status = 2;
+                            merchant.QueryCount = 2;
                         }
-                        //开通成功
-                        if (Info["resultCode"].ToString() == "1")
+                        else
                         {
-                            merchantadd.OpenAct = 1;//是否开通分账(1 是 0 否)
-                            merchantadd.HdStatus = 2; //0 待审核 1 已通过 2 已开通分账 3 已添加接收方
-                            //分账接收方签约
-                            JsonData Infos = JsonMapper.ToObject(HaoDaHelper.Instance.DivideAccountsSign(AppConfig.Haoda.AcctNo, merchantadd.OutMchtNo, merchantadd.StoreNo, merchantadd.BrandId));
-                            //失败
-                            if (Infos["resultCode"].ToString() == "0")
+                            if (merchant != null)
+                            {
+                                merchant.Status = 1;
+                            }
+                            //商户开通分账
+                            JsonData Info = JsonMapper.ToObject(HaoDaHelper.Instance.OpenDivideAccounts(merchantadd.OutMchtNo, merchantadd.StoreNo, merchantadd.BrandId));
+                            //开通失败
+                            if (Info["resultCode"].ToString() == "0")
                             {
-                                merchantadd.WeChatRemark = Infos["errorDesc"].ToString();
+                                merchantadd.Status = -1;
+                                merchantadd.WeChatRemark = Info["errorDesc"].ToString();
                             }
-                            //成功
-                            else
+                            //开通成功
+                            if (Info["resultCode"].ToString() == "1")
                             {
-                                merchantadd.HdStatus = 3; //0 待审核 1 已通过 2 已开通分账 3 已添加接收方
-                                if (!string.IsNullOrEmpty(merchantadd.ToAcctNo))
+                                merchantadd.OpenAct = 1;//是否开通分账(1 是 0 否)
+                                merchantadd.HdStatus = 2; //0 待审核 1 已通过 2 已开通分账 3 已添加接收方
+                                                          //分账接收方签约
+                                JsonData Infos = JsonMapper.ToObject(HaoDaHelper.Instance.DivideAccountsSign(AppConfig.Haoda.AcctNo, merchantadd.OutMchtNo, merchantadd.StoreNo, merchantadd.BrandId));
+                                //失败
+                                if (Infos["resultCode"].ToString() == "0")
                                 {
-                                    if (!merchantadd.ToAcctNo.Contains("," + AppConfig.Haoda.AcctNo + ","))
-                                    {
-                                        merchantadd.ToAcctNo += "," + AppConfig.Haoda.AcctNo + ",";
-                                    }
+                                    merchantadd.WeChatRemark = Infos["errorDesc"].ToString();
                                 }
+                                //成功
                                 else
                                 {
-                                    merchantadd.ToAcctNo += "," + AppConfig.Haoda.AcctNo + ",";
+                                    merchantadd.HdStatus = 3; //0 待审核 1 已通过 2 已开通分账 3 已添加接收方
+                                    if (!string.IsNullOrEmpty(merchantadd.ToAcctNo))
+                                    {
+                                        if (!merchantadd.ToAcctNo.Contains("," + AppConfig.Haoda.AcctNo + ","))
+                                        {
+                                            merchantadd.ToAcctNo += "," + AppConfig.Haoda.AcctNo + ",";
+                                        }
+                                    }
+                                    else
+                                    {
+                                        merchantadd.ToAcctNo += "," + AppConfig.Haoda.AcctNo + ",";
+                                    }
+                                    merchantadd.HdPassDate = DateTime.Now;
                                 }
-                                merchantadd.HdPassDate = DateTime.Now;
                             }
+
+                            //开户意愿申请
+                            RedisDbconn.Instance.AddList("AlipayForHaoDaQueue", mId);
+                            RedisDbconn.Instance.AddList("WeChatForHaoDaQueue", mId);
                         }
                         db.SaveChanges();
 
@@ -160,11 +174,6 @@ namespace MySystem
                             db1.SaveChanges();
                         }
                         db1.Dispose();
-
-                        //开户意愿申请
-                        RedisDbconn.Instance.AddList("AlipayForHaoDaQueue", mId);
-                        RedisDbconn.Instance.AddList("WeChatForHaoDaQueue", mId);
-
                     }
                 }
                 //审核被拒绝

+ 396 - 0
Util/HaoDa/GetHaoDaFTPInfoService.cs

@@ -0,0 +1,396 @@
+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];
+
+                                TradeDate = TradeDate.Substring(0, 4) + "-" + TradeDate.Substring(4, 2) + "-" + TradeDate.Substring(6, 2) + " " + TradeDate.Substring(8, 2) + ":" + TradeDate.Substring(10, 2) + ":" + TradeDate.Substring(12, 2);
+
+                                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)
+                                    {
+                                        var query = db.ConsumerOrders.Add(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
+                                        }).Entity;
+                                    }
+                                }
+                            }
+                            db.SaveChanges();
+                            db.Dispose();
+                        }
+
+                        // 关闭响应
+                        response.Close();
+                        Thread.Sleep(1800000);
+                    }
+                }
+                catch (WebException ex)
+                {
+                    // 如果抛出WebException,则可能是文件不存在
+                    // 根据响应状态码判断是否文件不存在
+                    if (((FtpWebResponse)ex.Response).StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
+                    {
+                        function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString() + "文件" + filePath + "不存在", "获取好哒FTP文件数据异常"); // 文件不存在,返回false
+                    }
+                    else
+                    {
+                        // 其他错误
+                        function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP文件数据异常");
+                    }
+                }
+            }
+        }
+
+
+        /// <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];
+
+                                    TradeDate = TradeDate.Substring(0, 4) + "-" + TradeDate.Substring(4, 2) + "-" + TradeDate.Substring(6, 2) + " " + TradeDate.Substring(8, 2) + ":" + TradeDate.Substring(10, 2) + ":" + TradeDate.Substring(12, 2);
+
+                                    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)
+                                        {
+                                            var query = db.ConsumerOrders.Add(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
+                                            }).Entity;
+                                        }
+                                    }
+                                }
+                                db.SaveChanges();
+                                db.Dispose();
+                            }
+
+                            // 关闭响应
+                            response.Close();
+                            Thread.Sleep(1800000);
+                        }
+                    }
+                    catch (WebException ex)
+                    {
+                        function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP文件数据异常");
+                    }
+                }
+            }
+        }
+
+        /// <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)
+            {
+                string check = function.ReadInstance("/GetFTPDataInfoYesterday/check" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + ".txt");
+                if (string.IsNullOrEmpty(check))
+                {
+                    if (DateTime.Now.Hour > 11 && DateTime.Now.Hour < 24)
+                    {
+                        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];
+
+                                        TradeDate = TradeDate.Substring(0, 4) + "-" + TradeDate.Substring(4, 2) + "-" + TradeDate.Substring(6, 2) + " " + TradeDate.Substring(8, 2) + ":" + TradeDate.Substring(10, 2) + ":" + TradeDate.Substring(12, 2);
+
+                                        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)
+                                            {
+                                                var query = db.ConsumerOrders.Add(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
+                                                }).Entity;
+                                            }
+                                        }
+                                    }
+                                    db.SaveChanges();
+                                    db.Dispose();
+                                }
+
+                                // 关闭响应
+                                response.Close();
+                                Thread.Sleep(1800000);
+                            }
+                        }
+                        catch (WebException ex)
+                        {
+                            function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP文件数据异常");
+                        }
+                    }
+                }
+            }
+        }
+
+    }
+}

+ 1 - 1
Util/HaoDa/HaoDaAuthQueryHelper.cs

@@ -29,7 +29,7 @@ public class HaoDaAuthQueryHelper
     {
         while (true)
         {
-            DataTable dt = CustomerSqlConn.dtable("select Id,OutMchtNo,StoreNo from MerchantAddInfo where HdStatus=3 and OutMchtNo is not null and StoreNo is not null and ((`Status`=1 and WeChatMerchantId is null) or (`QueryCount`=1 and AliMerchantId is null)) order by Id desc", AppConfig.Base.SqlConnStr);
+            DataTable dt = CustomerSqlConn.dtable("select Id,OutMchtNo,StoreNo from MerchantAddInfo where HdStatus=3 and BrandId=0 and OutMchtNo is not null and StoreNo is not null and ((`Status`=1 and WeChatMerchantId is null) or (`QueryCount`=1 and AliMerchantId is null)) order by Id desc", AppConfig.Base.SqlConnStr);
             foreach (DataRow dr in dt.Rows)
             {
                 QueryAuthStatus(dr["Id"].ToString(), dr["OutMchtNo"].ToString(), dr["StoreNo"].ToString());

+ 2 - 2
Util/HaoDa/HaoDaExtQueryAuthHelper.cs

@@ -39,7 +39,7 @@ public class HaoDaExtQueryAuthHelper
             // {
             //     Thread.Sleep(10000);
             // }
-            DataTable dt = CustomerSqlConn.dtable("select Id from MerchantAddInfo where HdStatus=3 and `Status`=1 and WeChatMerchantId!='' and WeChatMerchantId is not null", AppConfig.Base.SqlConnStr);
+            DataTable dt = CustomerSqlConn.dtable("select Id from MerchantAddInfo where HdStatus=3 and BrandId=0 and `Status`=1 and WeChatMerchantId!='' and WeChatMerchantId is not null", AppConfig.Base.SqlConnStr);
             foreach (DataRow dr in dt.Rows)
             {
                 WeChatAddInfo(int.Parse(dr["Id"].ToString()));
@@ -114,7 +114,7 @@ public class HaoDaExtQueryAuthHelper
             // {
             //     Thread.Sleep(10000);
             // }
-            DataTable dt = CustomerSqlConn.dtable("select Id from MerchantAddInfo where HdStatus=3 and `QueryCount`=1 and AliMerchantId!='' and AliMerchantId is not null", AppConfig.Base.SqlConnStr);
+            DataTable dt = CustomerSqlConn.dtable("select Id from MerchantAddInfo where HdStatus=3 and BrandId=0 and `QueryCount`=1 and AliMerchantId!='' and AliMerchantId is not null", AppConfig.Base.SqlConnStr);
             foreach (DataRow dr in dt.Rows)
             {
                 AlipayAddInfo(int.Parse(dr["Id"].ToString()));

+ 2 - 2
Util/HaoDa/HaoDaExtQueryHelper.cs

@@ -39,7 +39,7 @@ public class HaoDaExtQueryHelper
             // {
             //     Thread.Sleep(10000);
             // }
-            DataTable dt = CustomerSqlConn.dtable("select Id,ApplymentId from MerchantAddInfo where HdStatus=3 and `Status`=0 and ApplymentId!='' and ApplymentId is not null", AppConfig.Base.SqlConnStr);
+            DataTable dt = CustomerSqlConn.dtable("select Id,ApplymentId from MerchantAddInfo where HdStatus=3 and BrandId=0 and `Status`=0 and ApplymentId!='' and ApplymentId is not null", AppConfig.Base.SqlConnStr);
             foreach (DataRow dr in dt.Rows)
             {
                 WeChatAddInfo(int.Parse(dr["Id"].ToString()), dr["ApplymentId"].ToString());
@@ -133,7 +133,7 @@ public class HaoDaExtQueryHelper
             // {
             //     Thread.Sleep(10000);
             // }
-            DataTable dt = CustomerSqlConn.dtable("select Id,SeoTitle from MerchantAddInfo where HdStatus=3 and `QueryCount`=0 and SeoTitle!='' and SeoTitle is not null", AppConfig.Base.SqlConnStr);
+            DataTable dt = CustomerSqlConn.dtable("select Id,SeoTitle from MerchantAddInfo where HdStatus=3 and BrandId=0 and `QueryCount`=0 and SeoTitle!='' and SeoTitle is not null", AppConfig.Base.SqlConnStr);
             foreach (DataRow dr in dt.Rows)
             {
                 AlipayAddInfo(int.Parse(dr["Id"].ToString()), dr["SeoTitle"].ToString());

+ 164 - 0
Util/HaoDa/TestHaoDaService.cs

@@ -6,6 +6,8 @@ using MySystem.Models.Main;
 using Library;
 using LitJson;
 using System.Threading;
+using System.Net;
+using System.IO;
 
 namespace MySystem
 {
@@ -27,6 +29,8 @@ namespace MySystem
 
         public void StartListen()
         {
+            // GetFTPListInfo(); // 获取好哒FTPInfo
+            GetFTPDataInfo(); //获取好哒FTPDataInfo
             //开户意愿申请
             // RedisDbconn.Instance.AddList("AlipayForHaoDaQueue",824);
             // RedisDbconn.Instance.AddList("WeChatForHaoDaQueue",824);
@@ -160,6 +164,166 @@ namespace MySystem
             // db.Dispose();
         }
 
+        /// <summary>
+        /// 从ftp服务器上获得文件列表
+        /// </summary>
+        /// <param name="RequedstPath">服务器下的相对路径</param>
+        /// <returns></returns>
+        public static List<string> GetFTPListInfo(string RequedstPath = "/haoda-trade")
+        {
+            // 47.108.253.46
+            // 用户名:hdftp
+            // 密:haodatradeftp2024
+            // 目录:/haoda-trade
+            List<string> strs = new List<string>();
+            try
+            {
+                string uri = "ftp://47.108.253.46" + RequedstPath;   //目标路径 path为服务器地址        ②
+                FtpWebRequest reqFTP = (FtpWebRequest)WebRequest.Create(new Uri(uri));
+                // ftp用户名和密码
+                reqFTP.Credentials = new NetworkCredential("hdftp", "haodatradeftp2024");
+                reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
+                WebResponse response = reqFTP.GetResponse();
+                StreamReader reader = new StreamReader(response.GetResponseStream());//中文文件名
+
+                string line = reader.ReadLine();
+                while (line != null)
+                {
+                    if (!line.Contains("<DIR>"))
+                    {
+                        string msg = line.Substring(0).Trim();
+                        msg = msg.Substring(msg.Length - 24, 24);
+                        strs.Add(msg);
+                    }
+                    line = reader.ReadLine();
+                }
+                reader.Close();
+                response.Close();
+                return strs;
+            }
+            catch (Exception ex)
+            {
+                function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP文件数据异常");
+            }
+            return strs;
+        }
+
+        public static void GetFTPDataInfo()
+        {
+            // 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/20240513.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();
+                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];
+
+                            TradeDate = TradeDate.Substring(0, 4) + "-" + TradeDate.Substring(4, 2) + "-" + TradeDate.Substring(6, 2) + " " + TradeDate.Substring(8, 2) + ":" + TradeDate.Substring(10, 2) + ":" + TradeDate.Substring(12, 2);
+
+                            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)
+                                {
+                                    var query = db.ConsumerOrders.Add(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
+                                    }).Entity;
+                                }
+                            }
+                        }
+                        db.SaveChanges();
+                        db.Dispose();
+                    }
+
+                    // 关闭响应
+                    response.Close();
+                }
+
+                // 关闭响应
+                response.Close();
+            }
+            catch (WebException ex)
+            {
+                // 如果抛出WebException,则可能是文件不存在
+                // 根据响应状态码判断是否文件不存在
+                if (((FtpWebResponse)ex.Response).StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
+                {
+                    function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString() + "文件" + filePath + "不存在", "获取好哒FTP文件数据异常"); // 文件不存在,返回false
+                }
+                else
+                {
+                    // 其他错误
+                    function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP文件数据异常");
+                }
+            }
+        }
+
         public void StartProfitShareListen()
         {
             bool op = true;

+ 6 - 3
appsettings.Development.json

@@ -22,10 +22,13 @@
     "OSSSecret": "Q6P2vSNEY2LBNdygO8gUCkBZQpiswZ",
     "OSSEndpoint": "oss-cn-hangzhou.aliyuncs.com",
     "OSSBucketName": "yunmuit",
-    "TencentKey":"GU3BZ-JYL6Q-ETG5Y-BGPXM-QFQV6-PZBLW",
+    "TencentKey": "GU3BZ-JYL6Q-ETG5Y-BGPXM-QFQV6-PZBLW",
     "AppSource": "/skin/app/default/",
     "JwtSecret": "JvDHuowbOnWiyxMIFc9gG5rw1LSSc0xx68L31oRfxS0",
     "JwtIss": "TpAdminServer",
-    "JwtAud": "api"
+    "JwtAud": "api",
+    "HaoDaFtpHost": "ftp://47.108.253.46",
+    "HaoDaFtpLoginName": "hdftp",
+    "HaoDaFtpLoginPwd": "haodatradeftp2024"
   }
-}
+}