GetHaoDaFTPInfoService.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using System.Threading;
  6. using Library;
  7. using LitJson;
  8. using System.Net;
  9. using System.IO;
  10. using MySystem.SpModels;
  11. namespace MySystem
  12. {
  13. /// <summary>
  14. /// 获取好哒ftp数据
  15. /// </summary>
  16. public class GetHaoDaFTPInfoService
  17. {
  18. public readonly static GetHaoDaFTPInfoService Instance = new GetHaoDaFTPInfoService();
  19. private GetHaoDaFTPInfoService()
  20. { }
  21. // 47.108.253.46
  22. // 用户名:hdftp
  23. // 密:haodatradeftp2024
  24. // 目录:/haoda-trade
  25. public string ftpServerAddress = "ftp://47.108.253.46";
  26. public string ftpUser = "hdftp";
  27. public string ftpPassword = "haodatradeftp2024";
  28. public void Start()
  29. {
  30. //每天凌晨执行获取好哒FTP昨日交易数据
  31. Thread th2 = new Thread(GetDepositDataReady);
  32. th2.IsBackground = true;
  33. th2.Start();
  34. }
  35. /// <summary>
  36. /// 获取好哒FTP昨日交易数据
  37. /// </summary>
  38. public void GetDepositDataReady()
  39. {
  40. while (true)
  41. {
  42. if (DateTime.Now.Hour > 10 && DateTime.Now.Hour < 22)
  43. {
  44. string check = function.ReadInstance("/GetFTPDepositYesterday/check" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + ".txt");
  45. if (string.IsNullOrEmpty(check))
  46. {
  47. function.WritePage("/GetFTPDepositYesterday/", "check" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + ".txt", DateTime.Now.ToString());
  48. GetDepositData(DateTime.Now.AddDays(-1).ToString("yyyyMMdd"));
  49. Thread.Sleep(60000);
  50. GetTradeData(DateTime.Now.AddDays(-1).ToString("yyyyMMdd"));
  51. }
  52. }
  53. Thread.Sleep(7200000);
  54. }
  55. }
  56. public void Start2()
  57. {
  58. //每天凌晨执行获取好哒FTP昨日交易数据
  59. Thread th2 = new Thread(GetDepositDataReady2);
  60. th2.IsBackground = true;
  61. th2.Start();
  62. }
  63. /// <summary>
  64. /// 获取好哒FTP昨日交易数据
  65. /// </summary>
  66. public void GetDepositDataReady2()
  67. {
  68. while (true)
  69. {
  70. if (DateTime.Now > DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 10:05:00"))
  71. {
  72. GetDepositData("d_" + DateTime.Now.ToString("yyyyMMdd"));
  73. }
  74. GetTradeData(DateTime.Now.ToString("yyyyMMdd"));
  75. Thread.Sleep(1800000);
  76. }
  77. }
  78. public void StartListen()
  79. {
  80. //每天凌晨执行获取好哒FTP昨日交易数据
  81. Thread th2 = new Thread(ListenDepositDataReady);
  82. th2.IsBackground = true;
  83. th2.Start();
  84. }
  85. /// <summary>
  86. /// 获取好哒FTP昨日交易数据
  87. /// </summary>
  88. public void ListenDepositDataReady()
  89. {
  90. while (true)
  91. {
  92. string content = RedisDbconn.Instance.RPop<string>("ListenDepositDataQueue2");
  93. if (!string.IsNullOrEmpty(content))
  94. {
  95. GetDepositData2(content);
  96. Thread.Sleep(2000);
  97. }
  98. else
  99. {
  100. Thread.Sleep(60000);
  101. }
  102. }
  103. }
  104. public void StartListenOne()
  105. {
  106. //每天凌晨执行获取好哒FTP昨日交易数据
  107. Thread th = new Thread(ListenDepositOne);
  108. th.IsBackground = true;
  109. th.Start();
  110. }
  111. /// <summary>
  112. /// 获取好哒FTP昨日交易数据
  113. /// </summary>
  114. public void ListenDepositOne()
  115. {
  116. while (true)
  117. {
  118. string content = RedisDbconn.Instance.RPop<string>("ListenDepositOneQueue");
  119. if (!string.IsNullOrEmpty(content))
  120. {
  121. string[] data = content.Split('|');
  122. WebCMSEntities db = new WebCMSEntities();
  123. MpMainModels2.WebCMSEntities mpdb2 = new MpMainModels2.WebCMSEntities();
  124. DataInDatabase(db, mpdb2, data[0], data[1]);
  125. db.Dispose();
  126. mpdb2.Dispose();
  127. Thread.Sleep(2000);
  128. }
  129. else
  130. {
  131. Thread.Sleep(60000);
  132. }
  133. }
  134. }
  135. public void GetDepositData(string Date)
  136. {
  137. // 要下载的文件路径
  138. string filePath = "/haoda-deposit/deposit_" + Date + ".csv";
  139. try
  140. {
  141. // 创建FtpWebRequest对象
  142. FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpServerAddress + filePath);
  143. request.Method = WebRequestMethods.Ftp.DownloadFile;
  144. request.Credentials = new NetworkCredential(ftpUser, ftpPassword);
  145. // 使用WebResponse获取响应
  146. FtpWebResponse response = (FtpWebResponse)request.GetResponse();
  147. // 打开数据流
  148. Stream responseStream = response.GetResponseStream();
  149. StreamReader reader = new StreamReader(responseStream);
  150. // 读取数据
  151. string fileContents = reader.ReadToEnd();
  152. if (!string.IsNullOrEmpty(fileContents))
  153. {
  154. WebCMSEntities db = new WebCMSEntities();
  155. MpMainModels2.WebCMSEntities mpdb2 = new MpMainModels2.WebCMSEntities();
  156. var DataInfo = fileContents.TrimEnd('\n').Split('\n', 2);
  157. if(DataInfo.Length > 1)
  158. {
  159. var DataList = DataInfo[1].Split('\n');
  160. foreach (var DataListItem in DataList)
  161. {
  162. DataInDatabase(db, mpdb2, DataListItem, Date);
  163. }
  164. }
  165. db.Dispose();
  166. mpdb2.Dispose();
  167. }
  168. // 关闭响应
  169. reader.Dispose();
  170. responseStream.Dispose();
  171. response.Close();
  172. }
  173. catch (WebException ex)
  174. {
  175. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP文件数据异常");
  176. }
  177. }
  178. public void DataInDatabase(WebCMSEntities db, MpMainModels2.WebCMSEntities mpdb2, string DataListItem, string Date)
  179. {
  180. var DataListInfo = DataListItem.Split(',');
  181. string SnNo = DataListInfo[0]; //sn
  182. string MerNo = DataListInfo[1]; //商户编号
  183. string PosKind = DataListInfo[2]; //机具型号
  184. string ActDate = DataListInfo[3]; //激活时间
  185. string Deposit = DataListInfo[4]; //押金金额
  186. string PrizeAmt = "0"; //奖励金额
  187. string PrizeDate = "None"; //奖励发放时间
  188. string Name = ""; //发放人姓名
  189. string MerName = ""; //商户名称
  190. string PassDate = ""; //审核通过时期
  191. string MerKind = ""; //商户类型
  192. if(Date.StartsWith("d_"))
  193. {
  194. MerName = DataListInfo[5]; //商户名称
  195. PassDate = DataListInfo[6]; //审核通过时期
  196. MerKind = DataListInfo[7]; //商户类型
  197. }
  198. else
  199. {
  200. PrizeAmt = DataListInfo[5]; //奖励金额
  201. PrizeDate = DataListInfo[6]; //奖励发放时间
  202. Name = DataListInfo[7]; //发放人姓名
  203. MerName = DataListInfo[8]; //商户名称
  204. PassDate = DataListInfo[9]; //审核通过时期
  205. if(DataListInfo.Length > 10) MerKind = DataListInfo[10]; //商户类型
  206. }
  207. string ActDateString = ActDate.Substring(0, 4) + "-" + ActDate.Substring(4, 2) + "-" + ActDate.Substring(6, 2);
  208. if(DateTime.Parse(ActDateString) >= DateTime.Parse(DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd")))
  209. {
  210. string PrizeDateString = "";
  211. if(PrizeDate == "None")
  212. {
  213. PrizeDate = Date.Replace("d_", "");
  214. }
  215. else
  216. {
  217. PrizeDateString = PrizeDate.Substring(0, 4) + "-" + PrizeDate.Substring(4, 2) + "-" + PrizeDate.Substring(6, 2);
  218. }
  219. if(!db.BindRecord.Any(m => m.MerSnNo == SnNo))
  220. {
  221. string ProductType = "0";
  222. if(PosKind == "好哒语音王Y512") ProductType = "18";
  223. if(PosKind == "4G收款王M820") ProductType = "19";
  224. if(PosKind == "4G收款王M826") ProductType = "20";
  225. if(PosKind == "好哒S312") ProductType = "21";
  226. if(PosKind == "好哒扫码通M837") ProductType = "29";
  227. BindRecord mer = db.BindRecord.Add(new BindRecord()
  228. {
  229. CreateDate = DateTime.Now,
  230. UpdateTime = DateTime.Now, //机具绑定、解绑时间
  231. CreateTime = DateTime.Now, //商户操作时间
  232. MerSnNo = SnNo, //序列号
  233. MerNo = MerNo, //商户编号
  234. MerName = MerName,
  235. SeoTitle = PrizeAmt,
  236. SeoKeyword = ActDateString,
  237. ProductType = ProductType,
  238. Field1 = Deposit,
  239. Field2 = PrizeDate,
  240. Field3 = Name,
  241. Field4 = PassDate,
  242. Field5 = MerKind,
  243. Status = 1,
  244. }).Entity;
  245. db.Merchants.Add(new Merchants()
  246. {
  247. SnNo = SnNo,
  248. CreateTime = DateTime.Now,
  249. UpdateTime = DateTime.Now,
  250. AgentName = Name,
  251. MerRealName = Name,
  252. MerNo = MerNo,
  253. MerName = Name,
  254. ProductType = ProductType,
  255. Status = 1,
  256. });
  257. db.SaveChanges();
  258. Thread.Sleep(1000);
  259. ActivateRecord act = db.ActivateRecord.Add(new ActivateRecord()
  260. {
  261. SnNo = SnNo,
  262. CreateDate = DateTime.Now,
  263. SeoTitle = Deposit,
  264. ActivateDate = DateTime.Now,
  265. AgentNo = MerNo,
  266. MerRealName = Name,
  267. MerNo = MerNo,
  268. MerName = Name,
  269. ProductType = ProductType,
  270. ChannelSerial = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  271. Status = 1,
  272. Field1 = PassDate,
  273. Field2 = MerKind,
  274. }).Entity;
  275. db.SaveChanges();
  276. //推送MQ给创业帮
  277. var merchantAddInfo = mpdb2.MerchantAddInfo.FirstOrDefault(m => m.MchtNo == MerNo) ?? new MpMainModels2.MerchantAddInfo();
  278. if (merchantAddInfo.BrandId == 1 && !string.IsNullOrEmpty(merchantAddInfo.CybMakerCode))
  279. {
  280. SortedList<string, string> obj = new SortedList<string, string>();
  281. obj.Add("create_time", ActDateString);
  282. obj.Add("sn", SnNo);
  283. obj.Add("deposit", Deposit);
  284. obj.Add("subject_type", merchantAddInfo.SubjectType);
  285. obj.Add("merch_no", merchantAddInfo.MchtNo);
  286. obj.Add("maker_code", merchantAddInfo.CybMakerCode);
  287. PushHelper.Instance.Do(obj, "cashNotify");
  288. PosPushDataNewHelper.Bind(mer);
  289. PosPushDataNewHelper.Deposit(act);
  290. }
  291. }
  292. }
  293. }
  294. public void GetDepositData2(string Date)
  295. {
  296. // 要下载的文件路径
  297. string filePath = "/haoda-deposit/deposit_" + Date + ".csv";
  298. try
  299. {
  300. // 创建FtpWebRequest对象
  301. FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpServerAddress + filePath);
  302. request.Method = WebRequestMethods.Ftp.DownloadFile;
  303. request.Credentials = new NetworkCredential(ftpUser, ftpPassword);
  304. // 使用WebResponse获取响应
  305. FtpWebResponse response = (FtpWebResponse)request.GetResponse();
  306. // 打开数据流
  307. Stream responseStream = response.GetResponseStream();
  308. StreamReader reader = new StreamReader(responseStream);
  309. // 读取数据
  310. string fileContents = reader.ReadToEnd();
  311. if (!string.IsNullOrEmpty(fileContents))
  312. {
  313. WebCMSEntities db = new WebCMSEntities();
  314. MpMainModels2.WebCMSEntities mpdb2 = new MpMainModels2.WebCMSEntities();
  315. var DataInfo = fileContents.TrimEnd('\n').Split('\n', 2);
  316. if(DataInfo.Length > 1)
  317. {
  318. var DataList = DataInfo[1].Split('\n');
  319. foreach (var DataListItem in DataList)
  320. {
  321. var DataListInfo = DataListItem.Split(',');
  322. string SnNo = DataListInfo[0]; //sn
  323. string MerNo = DataListInfo[1]; //商户编号
  324. string PosKind = DataListInfo[2]; //机具型号
  325. string ActDate = DataListInfo[3]; //激活时间
  326. string Deposit = DataListInfo[4]; //押金金额
  327. string PrizeAmt = DataListInfo[5]; //奖励金额
  328. string PrizeDate = DataListInfo[6]; //奖励发放时间
  329. string Name = DataListInfo[7]; //发放人姓名
  330. string ActDateString = ActDate.Substring(0, 4) + "-" + ActDate.Substring(4, 2) + "-" + ActDate.Substring(6, 2);
  331. string PrizeDateString = "";
  332. if(PrizeDate == "None")
  333. {
  334. PrizeDate = Date;
  335. }
  336. else
  337. {
  338. PrizeDateString = PrizeDate.Substring(0, 4) + "-" + PrizeDate.Substring(4, 2) + "-" + PrizeDate.Substring(6, 2);
  339. }
  340. string ProductType = "0";
  341. if(PosKind == "好哒语音王Y512") ProductType = "18";
  342. if(PosKind == "4G收款王M820") ProductType = "19";
  343. if(PosKind == "4G收款王M826") ProductType = "20";
  344. if(PosKind == "好哒S312") ProductType = "21";
  345. db.BindRecord.Add(new BindRecord()
  346. {
  347. CreateDate = DateTime.Now,
  348. UpdateTime = DateTime.Now, //机具绑定、解绑时间
  349. CreateTime = DateTime.Now, //商户操作时间
  350. MerSnNo = SnNo, //序列号
  351. MerNo = MerNo, //商户编号
  352. MerName = Name,
  353. SeoTitle = PrizeAmt,
  354. SeoKeyword = ActDateString,
  355. ProductType = ProductType,
  356. Field1 = Deposit,
  357. Field2 = PrizeDate,
  358. Status = 1,
  359. });
  360. db.Merchants.Add(new Merchants()
  361. {
  362. SnNo = SnNo,
  363. CreateTime = DateTime.Now,
  364. UpdateTime = DateTime.Now,
  365. AgentName = Name,
  366. MerRealName = Name,
  367. MerNo = MerNo,
  368. MerName = Name,
  369. ProductType = ProductType,
  370. Status = 1,
  371. });
  372. db.SaveChanges();
  373. Thread.Sleep(1000);
  374. db.ActivateRecord.Add(new ActivateRecord()
  375. {
  376. SnNo = SnNo,
  377. CreateDate = DateTime.Now,
  378. SeoTitle = Deposit,
  379. ActivateDate = DateTime.Now,
  380. AgentNo = MerNo,
  381. MerRealName = Name,
  382. MerNo = MerNo,
  383. MerName = Name,
  384. ProductType = ProductType,
  385. ChannelSerial = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  386. Status = 1,
  387. });
  388. db.SaveChanges();
  389. //推送MQ给创业帮
  390. var merchantAddInfo = mpdb2.MerchantAddInfo.FirstOrDefault(m => m.MchtNo == MerNo) ?? new MpMainModels2.MerchantAddInfo();
  391. if (merchantAddInfo.BrandId == 1 && !string.IsNullOrEmpty(merchantAddInfo.CybMakerCode))
  392. {
  393. SortedList<string, string> obj = new SortedList<string, string>();
  394. obj.Add("create_time", ActDateString);
  395. obj.Add("sn", SnNo);
  396. obj.Add("deposit", Deposit);
  397. obj.Add("subject_type", merchantAddInfo.SubjectType);
  398. obj.Add("merch_no", merchantAddInfo.MchtNo);
  399. obj.Add("maker_code", merchantAddInfo.CybMakerCode);
  400. PushHelper.Instance.Do(obj, "cashNotify");
  401. }
  402. }
  403. }
  404. db.Dispose();
  405. mpdb2.Dispose();
  406. }
  407. // 关闭响应
  408. reader.Dispose();
  409. responseStream.Dispose();
  410. response.Close();
  411. }
  412. catch (WebException ex)
  413. {
  414. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP文件数据异常");
  415. }
  416. }
  417. public void StartTrade()
  418. {
  419. //每天凌晨执行获取好哒FTP昨日交易数据
  420. Thread th2 = new Thread(GetTradeDataReady);
  421. th2.IsBackground = true;
  422. th2.Start();
  423. }
  424. /// <summary>
  425. /// 获取好哒FTP昨日交易数据
  426. /// </summary>
  427. public void GetTradeDataReady()
  428. {
  429. while (true)
  430. {
  431. if (DateTime.Now.Hour > 10 && DateTime.Now.Hour < 22)
  432. {
  433. string check = function.ReadInstance("/GetFTPTradeYesterday/check" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + ".txt");
  434. if (string.IsNullOrEmpty(check))
  435. {
  436. function.WritePage("/GetFTPTradeYesterday/", "check" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + ".txt", DateTime.Now.ToString());
  437. GetTradeData(DateTime.Now.AddDays(-1).ToString("yyyyMMdd"));
  438. Thread.Sleep(600000);
  439. }
  440. }
  441. else
  442. {
  443. Thread.Sleep(1800000);
  444. }
  445. }
  446. }
  447. public void StartTradeListen()
  448. {
  449. //每天凌晨执行获取好哒FTP昨日交易数据
  450. Thread th2 = new Thread(ListenTradeDataReady);
  451. th2.IsBackground = true;
  452. th2.Start();
  453. }
  454. /// <summary>
  455. /// 获取好哒FTP昨日交易数据
  456. /// </summary>
  457. public void ListenTradeDataReady()
  458. {
  459. while (true)
  460. {
  461. string content = RedisDbconn.Instance.RPop<string>("ListenTradeDataQueue");
  462. if (!string.IsNullOrEmpty(content))
  463. {
  464. GetTradeData(content, true);
  465. Thread.Sleep(2000);
  466. }
  467. else
  468. {
  469. Thread.Sleep(60000);
  470. }
  471. }
  472. }
  473. public void GetTradeData(string Date, bool IsAll = false)
  474. {
  475. // 要下载的文件路径
  476. string filePath = "/haoda-trade/" + Date + ".csv";
  477. function.WriteLog(DateTime.Now.ToString() + ":" + filePath, "获取好哒FTP文件交易数据");
  478. try
  479. {
  480. // 创建FtpWebRequest对象
  481. FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpServerAddress + filePath);
  482. request.Method = WebRequestMethods.Ftp.DownloadFile;
  483. request.Credentials = new NetworkCredential(ftpUser, ftpPassword);
  484. // 使用WebResponse获取响应
  485. FtpWebResponse response = (FtpWebResponse)request.GetResponse();
  486. // 打开数据流
  487. Stream responseStream = response.GetResponseStream();
  488. StreamReader reader = new StreamReader(responseStream);
  489. // 读取数据
  490. string fileContents = reader.ReadToEnd();
  491. function.WriteLog("fileContents:" + fileContents, "获取好哒FTP文件交易数据");
  492. if (!string.IsNullOrEmpty(fileContents))
  493. {
  494. MpMainModels2.WebCMSEntities db = new MpMainModels2.WebCMSEntities();
  495. var DataInfo = fileContents.TrimEnd('\n').Split('\n', 2);
  496. if(DataInfo.Length > 1)
  497. {
  498. var DataList = DataInfo[1].Split('\n');
  499. foreach (var DataListItem in DataList)
  500. {
  501. var DataListInfo = DataListItem.Split(',');
  502. var MerchantNo = ""; // 商户号
  503. var BaseNo = ""; // 设备号
  504. var DeviceKind = ""; // 终端类型
  505. var OrderNo = ""; // 订单号
  506. var PayWay = ""; // 支付方式(微信 支付宝)
  507. var TradeType = ""; // 交易类型
  508. var TradeAmount = ""; // 交易金额
  509. var TradeFee = ""; // 交易手续费
  510. var TradeDate = ""; // 交易时间
  511. var TradeCycle = ""; // 结算周期
  512. MerchantNo = DataListInfo[0];
  513. BaseNo = DataListInfo[1];
  514. DeviceKind = DataListInfo[2];
  515. OrderNo = DataListInfo[3];
  516. PayWay = DataListInfo[4];
  517. TradeType = DataListInfo[5];
  518. TradeAmount = DataListInfo[6];
  519. TradeFee = DataListInfo[7];
  520. TradeDate = DataListInfo[8];
  521. TradeCycle = DataListInfo[9];
  522. 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);
  523. if(DateTime.Parse(TradeDate) > DateTime.Parse(DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd") + " 00:00:00") || IsAll)
  524. {
  525. function.WriteLog("OrderNo:" + OrderNo, "获取好哒FTP文件交易数据");
  526. function.WriteLog("MerchantNo:" + MerchantNo, "获取好哒FTP文件交易数据");
  527. var PayMode = 0;
  528. if (PayWay.Contains("支付宝")) PayMode = 1;
  529. if (PayWay.Contains("微信")) PayMode = 2;
  530. var merchantAddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.MchtNo == MerchantNo) ?? new MpMainModels2.MerchantAddInfo();
  531. if (merchantAddInfo.Id > 0)
  532. {
  533. function.WriteLog("找到商户", "获取好哒FTP文件交易数据");
  534. var merchantInfo = db.MerchantInfo.FirstOrDefault(m => m.Id == merchantAddInfo.Id) ?? new MpMainModels2.MerchantInfo();
  535. if(merchantInfo.IsAct == 0)
  536. {
  537. merchantInfo.IsAct = 1;
  538. }
  539. var orders = db.ConsumerOrders.FirstOrDefault(m => m.SeoTitle == OrderNo && m.OrderNo == OrderNo) ?? new MpMainModels2.ConsumerOrders();
  540. if (orders.Id == 0)
  541. {
  542. function.WriteLog("订单号不存在,开始入库", "获取好哒FTP文件交易数据");
  543. decimal FeeRate = decimal.Parse(function.CheckNum(merchantAddInfo.FeeRate)) * 100;
  544. var query = db.ConsumerOrders.Add(new MpMainModels2.ConsumerOrders()
  545. {
  546. Status = 1,
  547. CreateDate = DateTime.Parse(TradeDate),
  548. UpdateDate = DateTime.Parse(TradeDate),
  549. SnNo = BaseNo,
  550. PayMoney = decimal.Parse(TradeAmount),
  551. PayMode = PayMode,
  552. SeoTitle = OrderNo,
  553. OrderNo = OrderNo,
  554. MerchantId = merchantAddInfo.Id,
  555. UserId = merchantInfo.UserId,
  556. SeoKeyword = merchantAddInfo.CybMakerCode,
  557. Sort = (int)FeeRate,
  558. TradePayNo = MerchantNo,
  559. }).Entity;
  560. db.SaveChanges();
  561. function.WriteLog("入库完毕", "获取好哒FTP文件交易数据");
  562. //推送MQ给创业帮
  563. if (merchantAddInfo.BrandId == 1)
  564. {
  565. if(!string.IsNullOrEmpty(merchantAddInfo.CybMakerCode))
  566. {
  567. SortedList<string, string> obj = new SortedList<string, string>();
  568. obj.Add("create_time", TradeDate);
  569. obj.Add("sn", BaseNo);
  570. obj.Add("pay_money", TradeAmount);
  571. obj.Add("pay_mode", PayMode.ToString());
  572. obj.Add("order_no", OrderNo);
  573. obj.Add("merch_no", merchantAddInfo.MchtNo);
  574. obj.Add("maker_code", merchantAddInfo.CybMakerCode);
  575. PushHelper.Instance.Do(obj);
  576. }
  577. OrderMessageHelper.SendOrderMsg(query);
  578. // PosPushDataNewHelper.Trade(query, DeviceKind);
  579. }
  580. }
  581. }
  582. }
  583. }
  584. }
  585. db.Dispose();
  586. }
  587. // 关闭响应
  588. reader.Dispose();
  589. responseStream.Dispose();
  590. response.Close();
  591. function.WriteLog("结束\n\n\n", "获取好哒FTP文件数据异常");
  592. }
  593. catch (WebException ex)
  594. {
  595. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP文件交易数据异常");
  596. }
  597. }
  598. }
  599. }