GetHaoDaFTPInfoService.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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. }
  206. string ActDateString = ActDate.Substring(0, 4) + "-" + ActDate.Substring(4, 2) + "-" + ActDate.Substring(6, 2);
  207. if(DateTime.Parse(ActDateString) >= DateTime.Parse(DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd")))
  208. {
  209. string PrizeDateString = "";
  210. if(PrizeDate == "None")
  211. {
  212. PrizeDate = Date.Replace("d_", "");
  213. }
  214. else
  215. {
  216. PrizeDateString = PrizeDate.Substring(0, 4) + "-" + PrizeDate.Substring(4, 2) + "-" + PrizeDate.Substring(6, 2);
  217. }
  218. if(!db.BindRecord.Any(m => m.MerSnNo == SnNo))
  219. {
  220. string ProductType = "0";
  221. if(PosKind == "好哒语音王Y512") ProductType = "18";
  222. if(PosKind == "4G收款王M820") ProductType = "19";
  223. if(PosKind == "4G收款王M826") ProductType = "20";
  224. if(PosKind == "好哒S312") ProductType = "21";
  225. if(PosKind == "好哒扫码通M837") ProductType = "29";
  226. BindRecord mer = db.BindRecord.Add(new BindRecord()
  227. {
  228. CreateDate = DateTime.Now,
  229. UpdateTime = DateTime.Now, //机具绑定、解绑时间
  230. CreateTime = DateTime.Now, //商户操作时间
  231. MerSnNo = SnNo, //序列号
  232. MerNo = MerNo, //商户编号
  233. MerName = MerName,
  234. SeoTitle = PrizeAmt,
  235. SeoKeyword = ActDateString,
  236. ProductType = ProductType,
  237. Field1 = Deposit,
  238. Field2 = PrizeDate,
  239. Field3 = Name,
  240. Field4 = PassDate,
  241. Field5 = MerKind,
  242. Status = 1,
  243. }).Entity;
  244. db.Merchants.Add(new Merchants()
  245. {
  246. SnNo = SnNo,
  247. CreateTime = DateTime.Now,
  248. UpdateTime = DateTime.Now,
  249. AgentName = Name,
  250. MerRealName = Name,
  251. MerNo = MerNo,
  252. MerName = Name,
  253. ProductType = ProductType,
  254. Status = 1,
  255. });
  256. db.SaveChanges();
  257. Thread.Sleep(1000);
  258. ActivateRecord act = db.ActivateRecord.Add(new ActivateRecord()
  259. {
  260. SnNo = SnNo,
  261. CreateDate = DateTime.Now,
  262. SeoTitle = Deposit,
  263. ActivateDate = DateTime.Now,
  264. AgentNo = MerNo,
  265. MerRealName = Name,
  266. MerNo = MerNo,
  267. MerName = Name,
  268. ProductType = ProductType,
  269. ChannelSerial = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  270. Status = 1,
  271. Field1 = PassDate,
  272. Field2 = MerKind,
  273. }).Entity;
  274. db.SaveChanges();
  275. //推送MQ给创业帮
  276. var merchantAddInfo = mpdb2.MerchantAddInfo.FirstOrDefault(m => m.MchtNo == MerNo) ?? new MpMainModels2.MerchantAddInfo();
  277. if (merchantAddInfo.BrandId == 1 && !string.IsNullOrEmpty(merchantAddInfo.CybMakerCode))
  278. {
  279. SortedList<string, string> obj = new SortedList<string, string>();
  280. obj.Add("create_time", ActDateString);
  281. obj.Add("sn", SnNo);
  282. obj.Add("deposit", Deposit);
  283. obj.Add("subject_type", merchantAddInfo.SubjectType);
  284. obj.Add("merch_no", merchantAddInfo.MchtNo);
  285. obj.Add("maker_code", merchantAddInfo.CybMakerCode);
  286. PushHelper.Instance.Do(obj, "cashNotify");
  287. PosPushDataNewHelper.Bind(mer);
  288. PosPushDataNewHelper.Deposit(act);
  289. }
  290. }
  291. }
  292. }
  293. public void GetDepositData2(string Date)
  294. {
  295. // 要下载的文件路径
  296. string filePath = "/haoda-deposit/deposit_" + Date + ".csv";
  297. try
  298. {
  299. // 创建FtpWebRequest对象
  300. FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpServerAddress + filePath);
  301. request.Method = WebRequestMethods.Ftp.DownloadFile;
  302. request.Credentials = new NetworkCredential(ftpUser, ftpPassword);
  303. // 使用WebResponse获取响应
  304. FtpWebResponse response = (FtpWebResponse)request.GetResponse();
  305. // 打开数据流
  306. Stream responseStream = response.GetResponseStream();
  307. StreamReader reader = new StreamReader(responseStream);
  308. // 读取数据
  309. string fileContents = reader.ReadToEnd();
  310. if (!string.IsNullOrEmpty(fileContents))
  311. {
  312. WebCMSEntities db = new WebCMSEntities();
  313. MpMainModels2.WebCMSEntities mpdb2 = new MpMainModels2.WebCMSEntities();
  314. var DataInfo = fileContents.TrimEnd('\n').Split('\n', 2);
  315. if(DataInfo.Length > 1)
  316. {
  317. var DataList = DataInfo[1].Split('\n');
  318. foreach (var DataListItem in DataList)
  319. {
  320. var DataListInfo = DataListItem.Split(',');
  321. string SnNo = DataListInfo[0]; //sn
  322. string MerNo = DataListInfo[1]; //商户编号
  323. string PosKind = DataListInfo[2]; //机具型号
  324. string ActDate = DataListInfo[3]; //激活时间
  325. string Deposit = DataListInfo[4]; //押金金额
  326. string PrizeAmt = DataListInfo[5]; //奖励金额
  327. string PrizeDate = DataListInfo[6]; //奖励发放时间
  328. string Name = DataListInfo[7]; //发放人姓名
  329. string ActDateString = ActDate.Substring(0, 4) + "-" + ActDate.Substring(4, 2) + "-" + ActDate.Substring(6, 2);
  330. string PrizeDateString = "";
  331. if(PrizeDate == "None")
  332. {
  333. PrizeDate = Date;
  334. }
  335. else
  336. {
  337. PrizeDateString = PrizeDate.Substring(0, 4) + "-" + PrizeDate.Substring(4, 2) + "-" + PrizeDate.Substring(6, 2);
  338. }
  339. string ProductType = "0";
  340. if(PosKind == "好哒语音王Y512") ProductType = "18";
  341. if(PosKind == "4G收款王M820") ProductType = "19";
  342. if(PosKind == "4G收款王M826") ProductType = "20";
  343. if(PosKind == "好哒S312") ProductType = "21";
  344. db.BindRecord.Add(new BindRecord()
  345. {
  346. CreateDate = DateTime.Now,
  347. UpdateTime = DateTime.Now, //机具绑定、解绑时间
  348. CreateTime = DateTime.Now, //商户操作时间
  349. MerSnNo = SnNo, //序列号
  350. MerNo = MerNo, //商户编号
  351. MerName = Name,
  352. SeoTitle = PrizeAmt,
  353. SeoKeyword = ActDateString,
  354. ProductType = ProductType,
  355. Field1 = Deposit,
  356. Field2 = PrizeDate,
  357. Status = 1,
  358. });
  359. db.Merchants.Add(new Merchants()
  360. {
  361. SnNo = SnNo,
  362. CreateTime = DateTime.Now,
  363. UpdateTime = DateTime.Now,
  364. AgentName = Name,
  365. MerRealName = Name,
  366. MerNo = MerNo,
  367. MerName = Name,
  368. ProductType = ProductType,
  369. Status = 1,
  370. });
  371. db.SaveChanges();
  372. Thread.Sleep(1000);
  373. db.ActivateRecord.Add(new ActivateRecord()
  374. {
  375. SnNo = SnNo,
  376. CreateDate = DateTime.Now,
  377. SeoTitle = Deposit,
  378. ActivateDate = DateTime.Now,
  379. AgentNo = MerNo,
  380. MerRealName = Name,
  381. MerNo = MerNo,
  382. MerName = Name,
  383. ProductType = ProductType,
  384. ChannelSerial = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  385. Status = 1,
  386. });
  387. db.SaveChanges();
  388. //推送MQ给创业帮
  389. var merchantAddInfo = mpdb2.MerchantAddInfo.FirstOrDefault(m => m.MchtNo == MerNo) ?? new MpMainModels2.MerchantAddInfo();
  390. if (merchantAddInfo.BrandId == 1 && !string.IsNullOrEmpty(merchantAddInfo.CybMakerCode))
  391. {
  392. SortedList<string, string> obj = new SortedList<string, string>();
  393. obj.Add("create_time", ActDateString);
  394. obj.Add("sn", SnNo);
  395. obj.Add("deposit", Deposit);
  396. obj.Add("subject_type", merchantAddInfo.SubjectType);
  397. obj.Add("merch_no", merchantAddInfo.MchtNo);
  398. obj.Add("maker_code", merchantAddInfo.CybMakerCode);
  399. PushHelper.Instance.Do(obj, "cashNotify");
  400. }
  401. }
  402. }
  403. db.Dispose();
  404. mpdb2.Dispose();
  405. }
  406. // 关闭响应
  407. reader.Dispose();
  408. responseStream.Dispose();
  409. response.Close();
  410. }
  411. catch (WebException ex)
  412. {
  413. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP文件数据异常");
  414. }
  415. }
  416. public void StartTrade()
  417. {
  418. //每天凌晨执行获取好哒FTP昨日交易数据
  419. Thread th2 = new Thread(GetTradeDataReady);
  420. th2.IsBackground = true;
  421. th2.Start();
  422. }
  423. /// <summary>
  424. /// 获取好哒FTP昨日交易数据
  425. /// </summary>
  426. public void GetTradeDataReady()
  427. {
  428. while (true)
  429. {
  430. if (DateTime.Now.Hour > 10 && DateTime.Now.Hour < 22)
  431. {
  432. string check = function.ReadInstance("/GetFTPTradeYesterday/check" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + ".txt");
  433. if (string.IsNullOrEmpty(check))
  434. {
  435. function.WritePage("/GetFTPTradeYesterday/", "check" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + ".txt", DateTime.Now.ToString());
  436. GetTradeData(DateTime.Now.AddDays(-1).ToString("yyyyMMdd"));
  437. Thread.Sleep(600000);
  438. }
  439. }
  440. else
  441. {
  442. Thread.Sleep(1800000);
  443. }
  444. }
  445. }
  446. public void StartTradeListen()
  447. {
  448. //每天凌晨执行获取好哒FTP昨日交易数据
  449. Thread th2 = new Thread(ListenTradeDataReady);
  450. th2.IsBackground = true;
  451. th2.Start();
  452. }
  453. /// <summary>
  454. /// 获取好哒FTP昨日交易数据
  455. /// </summary>
  456. public void ListenTradeDataReady()
  457. {
  458. while (true)
  459. {
  460. string content = RedisDbconn.Instance.RPop<string>("ListenTradeDataQueue");
  461. if (!string.IsNullOrEmpty(content))
  462. {
  463. GetTradeData(content, true);
  464. Thread.Sleep(2000);
  465. }
  466. else
  467. {
  468. Thread.Sleep(60000);
  469. }
  470. }
  471. }
  472. public void GetTradeData(string Date, bool IsAll = false)
  473. {
  474. // 要下载的文件路径
  475. string filePath = "/haoda-trade/" + Date + ".csv";
  476. function.WriteLog(DateTime.Now.ToString() + ":" + filePath, "获取好哒FTP文件交易数据");
  477. try
  478. {
  479. // 创建FtpWebRequest对象
  480. FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpServerAddress + filePath);
  481. request.Method = WebRequestMethods.Ftp.DownloadFile;
  482. request.Credentials = new NetworkCredential(ftpUser, ftpPassword);
  483. // 使用WebResponse获取响应
  484. FtpWebResponse response = (FtpWebResponse)request.GetResponse();
  485. // 打开数据流
  486. Stream responseStream = response.GetResponseStream();
  487. StreamReader reader = new StreamReader(responseStream);
  488. // 读取数据
  489. string fileContents = reader.ReadToEnd();
  490. function.WriteLog("fileContents:" + fileContents, "获取好哒FTP文件交易数据");
  491. if (!string.IsNullOrEmpty(fileContents))
  492. {
  493. MpMainModels2.WebCMSEntities db = new MpMainModels2.WebCMSEntities();
  494. var DataInfo = fileContents.TrimEnd('\n').Split('\n', 2);
  495. if(DataInfo.Length > 1)
  496. {
  497. var DataList = DataInfo[1].Split('\n');
  498. foreach (var DataListItem in DataList)
  499. {
  500. var DataListInfo = DataListItem.Split(',');
  501. var MerchantNo = ""; // 商户号
  502. var BaseNo = ""; // 设备号
  503. var DeviceKind = ""; // 终端类型
  504. var OrderNo = ""; // 订单号
  505. var PayWay = ""; // 支付方式(微信 支付宝)
  506. var TradeType = ""; // 交易类型
  507. var TradeAmount = ""; // 交易金额
  508. var TradeFee = ""; // 交易手续费
  509. var TradeDate = ""; // 交易时间
  510. var TradeCycle = ""; // 结算周期
  511. MerchantNo = DataListInfo[0];
  512. BaseNo = DataListInfo[1];
  513. DeviceKind = DataListInfo[2];
  514. OrderNo = DataListInfo[3];
  515. PayWay = DataListInfo[4];
  516. TradeType = DataListInfo[5];
  517. TradeAmount = DataListInfo[6];
  518. TradeFee = DataListInfo[7];
  519. TradeDate = DataListInfo[8];
  520. TradeCycle = DataListInfo[9];
  521. 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);
  522. if(DateTime.Parse(TradeDate) > DateTime.Parse(DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd") + " 00:00:00") || IsAll)
  523. {
  524. function.WriteLog("OrderNo:" + OrderNo, "获取好哒FTP文件交易数据");
  525. function.WriteLog("MerchantNo:" + MerchantNo, "获取好哒FTP文件交易数据");
  526. var PayMode = 0;
  527. if (PayWay.Contains("支付宝")) PayMode = 1;
  528. if (PayWay.Contains("微信")) PayMode = 2;
  529. var merchantAddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.MchtNo == MerchantNo) ?? new MpMainModels2.MerchantAddInfo();
  530. if (merchantAddInfo.Id > 0)
  531. {
  532. function.WriteLog("找到商户", "获取好哒FTP文件交易数据");
  533. var merchantInfo = db.MerchantInfo.FirstOrDefault(m => m.Id == merchantAddInfo.Id) ?? new MpMainModels2.MerchantInfo();
  534. if(merchantInfo.IsAct == 0)
  535. {
  536. merchantInfo.IsAct = 1;
  537. }
  538. var orders = db.ConsumerOrders.FirstOrDefault(m => m.SeoTitle == OrderNo && m.OrderNo == OrderNo) ?? new MpMainModels2.ConsumerOrders();
  539. if (orders.Id == 0)
  540. {
  541. function.WriteLog("订单号不存在,开始入库", "获取好哒FTP文件交易数据");
  542. decimal FeeRate = decimal.Parse(function.CheckNum(merchantAddInfo.FeeRate)) * 100;
  543. var query = db.ConsumerOrders.Add(new MpMainModels2.ConsumerOrders()
  544. {
  545. Status = 1,
  546. CreateDate = DateTime.Parse(TradeDate),
  547. UpdateDate = DateTime.Parse(TradeDate),
  548. SnNo = BaseNo,
  549. PayMoney = decimal.Parse(TradeAmount),
  550. PayMode = PayMode,
  551. SeoTitle = OrderNo,
  552. OrderNo = OrderNo,
  553. MerchantId = merchantAddInfo.Id,
  554. UserId = merchantInfo.UserId,
  555. SeoKeyword = merchantAddInfo.CybMakerCode,
  556. Sort = (int)FeeRate,
  557. TradePayNo = MerchantNo,
  558. }).Entity;
  559. db.SaveChanges();
  560. function.WriteLog("入库完毕", "获取好哒FTP文件交易数据");
  561. //推送MQ给创业帮
  562. if (merchantAddInfo.BrandId == 1)
  563. {
  564. if(!string.IsNullOrEmpty(merchantAddInfo.CybMakerCode))
  565. {
  566. SortedList<string, string> obj = new SortedList<string, string>();
  567. obj.Add("create_time", TradeDate);
  568. obj.Add("sn", BaseNo);
  569. obj.Add("pay_money", TradeAmount);
  570. obj.Add("pay_mode", PayMode.ToString());
  571. obj.Add("order_no", OrderNo);
  572. obj.Add("merch_no", merchantAddInfo.MchtNo);
  573. obj.Add("maker_code", merchantAddInfo.CybMakerCode);
  574. PushHelper.Instance.Do(obj);
  575. }
  576. OrderMessageHelper.SendOrderMsg(query);
  577. // PosPushDataNewHelper.Trade(query, DeviceKind);
  578. }
  579. }
  580. }
  581. }
  582. }
  583. }
  584. db.Dispose();
  585. }
  586. // 关闭响应
  587. reader.Dispose();
  588. responseStream.Dispose();
  589. response.Close();
  590. function.WriteLog("结束\n\n\n", "获取好哒FTP文件数据异常");
  591. }
  592. catch (WebException ex)
  593. {
  594. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP文件交易数据异常");
  595. }
  596. }
  597. }
  598. }