TestHaoDaService.cs 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using MySystem.Models.Main;
  6. using Library;
  7. using LitJson;
  8. using System.Threading;
  9. using System.Net;
  10. using System.IO;
  11. namespace MySystem
  12. {
  13. /// <summary>
  14. /// 好哒测试服务
  15. /// </summary>
  16. public class TestHaoDaService
  17. {
  18. public readonly static TestHaoDaService Instance = new TestHaoDaService();
  19. private TestHaoDaService()
  20. { }
  21. public void Start()
  22. {
  23. while (true)
  24. {
  25. Thread th = new Thread(StartListen);
  26. th.IsBackground = true;
  27. th.Start();
  28. Thread.Sleep(10000);
  29. }
  30. }
  31. public void StartListen()
  32. {
  33. // GetFTPListInfo(); // 获取好哒FTPInfo
  34. // GetFTPDataInfo(); //获取好哒FTPDataInfo
  35. //开户意愿申请
  36. // RedisDbconn.Instance.AddList("AlipayForHaoDaQueue",824);
  37. // RedisDbconn.Instance.AddList("WeChatForHaoDaQueue",824);
  38. // AlipayAddInfo(826);//提交支付宝开户意愿申请单
  39. // AlipayAddInfo(828,"202309011037906510");//查询支付宝开户意愿申请状态
  40. // WeChatAddInfo(826);//提交微信开户意愿申请单
  41. // WeChatAddInfo(825,"2000002424428809");//查询微信开户意愿申请状态
  42. // ConfiemMer(1833);//新建商户
  43. QueryMerchantStatus(3197);//新建商户查询状态
  44. // GetTencentAddressInfo(112); //获取商户经纬坐标
  45. // ChangeMerchantCard(1);//商户修改银行卡
  46. // QueryChangeCardStatus(1874);//商户修改银行卡状态
  47. // AddOpenDivideAccounts(832); //添加分账方
  48. // QueryAuthStatus(1845);//查询实名认证状态
  49. // WeChatFunctionForHD.Instance.QueryAuthMerchant("600955391");
  50. // AlipayFunctionForHD.Instance.AuthOrderAuthQuery("2088820718243322");
  51. // StartProfitShareListen();
  52. // HaoDaHelper.Instance.BindWeChatAppId("1490230", "21622558", AppConfig.Haoda.SubAppId);
  53. // HaoDaHelper.Instance.OrderDivideAccountsQuery("FZ2023110315225748140470708", "1492500"); //查询分账结果
  54. // WebCMSEntities db = new WebCMSEntities();
  55. // List<int> ids = new List<int>();
  56. // foreach(int id in ids)
  57. // {
  58. // ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == id) ?? new ConsumerOrders();
  59. // MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
  60. // string applyNo = "FZ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //批次号
  61. // string mchtNo = merchantAdd.OutMchtNo; //慧掌柜商户号
  62. // string orderNo = order.SeoTitle; //交易订单号(好哒平台订单号,G开头)
  63. // string acctNo = AppConfig.Haoda.AcctNo; //账户号,分账接收方账户号
  64. // string sacctNo = merchantAdd.MchtNo; //账户号,收款商户号
  65. // string acctType = "0"; //账户类型(0:商户收款账户(大B),1:分账接收方账户(小B))
  66. // // decimal hdfee = 0.0038M * order.PayMoney;
  67. // // hdfee = decimal.Parse(hdfee.ToString("f2"));
  68. // // decimal servicefee = 0.01M * order.PayMoney;
  69. // // servicefee = decimal.Parse(servicefee.ToString("f2"));
  70. // // decimal amount = order.PayMoney - hdfee - servicefee;
  71. // // amount = amount * 100; //金额(分)
  72. // // servicefee = servicefee * 100;
  73. // // string seviceAmount = servicefee.ToString("f0"); //服务费
  74. // string result = HaoDaHelper.Instance.OrderDivideAccounts(OrderDivideAccountsUtil.AddValue(applyNo, mchtNo, orderNo, acctNo, sacctNo, acctType, "1", "0"));
  75. // }
  76. // string content = function.ReadInstance("content.txt");
  77. // string[] list = content.Split('\n');
  78. // foreach(string sub in list)
  79. // {
  80. // JsonData jsonObj = JsonMapper.ToObject(sub);
  81. // string orderNo = jsonObj["orderNo"].ToString();
  82. // JsonData detail = jsonObj["detail"];
  83. // string me = detail[0]["amount"].ToString();
  84. // string mer = detail[1]["amount"].ToString();
  85. // ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.SeoTitle == orderNo) ?? new ConsumerOrders();
  86. // if(order.SettleAmount > 0)
  87. // {
  88. // MerchantParamSet set = Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantParamSet>(order.SeoDescription);
  89. // MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
  90. // string applyNo = "FZ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //批次号
  91. // string mchtNo = merchantAdd.OutMchtNo; //慧掌柜商户号
  92. // string acctNo = AppConfig.Haoda.AcctNo; //账户号,分账接收方账户号
  93. // string sacctNo = merchantAdd.MchtNo; //账户号,收款商户号
  94. // decimal settleAmount = (decimal)order.SettleAmount / 100M;
  95. // decimal divideAmt = (1 - 0.0038M) * order.PayMoney;
  96. // divideAmt = decimal.Parse(divideAmt.ToString("f2"));
  97. // decimal hdfee = 0.0038M * order.PayMoney * (1 - set.GetPercent / 100 - 0.01M);
  98. // hdfee = decimal.Parse(hdfee.ToString("f2"));
  99. // decimal servicefee = 0.01M * order.PayMoney - hdfee;
  100. // servicefee = decimal.Parse(servicefee.ToString("f2"));
  101. // decimal amount = order.PayMoney*(1-0.0038M) - servicefee;
  102. // amount = decimal.Parse(amount.ToString("f2"));
  103. // decimal otherAmt = settleAmount - servicefee - amount;
  104. // if(otherAmt != 0)
  105. // {
  106. // amount += otherAmt;
  107. // }
  108. // amount -= decimal.Parse(mer) / 100M;
  109. // servicefee -= decimal.Parse(me) / 100M;
  110. // if(amount > 0)
  111. // {
  112. // if(servicefee < 0) servicefee = 0;
  113. // amount = amount * 100 - 1; //金额(分)
  114. // servicefee = servicefee * 100;
  115. // string seviceAmount = servicefee.ToString("f0"); //服务费
  116. // string amountAmount = amount.ToString("f0");
  117. // string result = HaoDaHelper.Instance.OrderDivideAccounts(OrderDivideAccountsUtil.AddValue(applyNo, mchtNo, orderNo, acctNo, sacctNo, "0", amountAmount, seviceAmount));
  118. // }
  119. // }
  120. // }
  121. // List<string> list = new List<string>();
  122. // list.Add("{\"orderNo\":\"G2231124C02180937731\",\"settle\":\"29687\",\"part\":\"29575\"}");
  123. // foreach(string sub in list)
  124. // {
  125. // JsonData jsonObj = JsonMapper.ToObject(sub);
  126. // string orderNo = jsonObj["orderNo"].ToString();
  127. // string settle = jsonObj["settle"].ToString();
  128. // string part = jsonObj["part"].ToString();
  129. // ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.SeoTitle == orderNo) ?? new ConsumerOrders();
  130. // if(order.SettleAmount > 0)
  131. // {
  132. // MerchantParamSet set = Newtonsoft.Json.JsonConvert.DeserializeObject<MerchantParamSet>(order.SeoDescription);
  133. // MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
  134. // string applyNo = "FZ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //批次号
  135. // string mchtNo = merchantAdd.OutMchtNo; //慧掌柜商户号
  136. // string acctNo = AppConfig.Haoda.AcctNo; //账户号,分账接收方账户号
  137. // string sacctNo = merchantAdd.MchtNo; //账户号,收款商户号
  138. // decimal settleamount = decimal.Parse(settle);
  139. // decimal partamount = decimal.Parse(part);
  140. // decimal amount = settleamount - partamount;
  141. // if(amount > 0)
  142. // {
  143. // decimal servicefee = amount / 100M;
  144. // servicefee = decimal.Parse(servicefee.ToString("f0"));
  145. // amount -= servicefee;
  146. // string seviceAmount = servicefee.ToString("f0"); //服务费
  147. // string amountAmount = amount.ToString("f0");
  148. // string result = HaoDaHelper.Instance.OrderDivideAccounts(OrderDivideAccountsUtil.AddValue(applyNo, mchtNo, orderNo, acctNo, sacctNo, "0", amountAmount, seviceAmount));
  149. // }
  150. // }
  151. // }
  152. // db.Dispose();
  153. }
  154. /// <summary>
  155. /// 从ftp服务器上获得文件列表
  156. /// </summary>
  157. /// <param name="RequedstPath">服务器下的相对路径</param>
  158. /// <returns></returns>
  159. public static List<string> GetFTPListInfo(string RequedstPath = "/haoda-trade")
  160. {
  161. // 47.108.253.46
  162. // 用户名:hdftp
  163. // 密:haodatradeftp2024
  164. // 目录:/haoda-trade
  165. List<string> strs = new List<string>();
  166. try
  167. {
  168. string uri = "ftp://47.108.253.46" + RequedstPath; //目标路径 path为服务器地址        ②
  169. FtpWebRequest reqFTP = (FtpWebRequest)WebRequest.Create(new Uri(uri));
  170. // ftp用户名和密码
  171. reqFTP.Credentials = new NetworkCredential("hdftp", "haodatradeftp2024");
  172. reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
  173. WebResponse response = reqFTP.GetResponse();
  174. StreamReader reader = new StreamReader(response.GetResponseStream());//中文文件名
  175. string line = reader.ReadLine();
  176. while (line != null)
  177. {
  178. if (!line.Contains("<DIR>"))
  179. {
  180. string msg = line.Substring(0).Trim();
  181. msg = msg.Substring(msg.Length - 24, 24);
  182. strs.Add(msg);
  183. }
  184. line = reader.ReadLine();
  185. }
  186. reader.Close();
  187. response.Close();
  188. return strs;
  189. }
  190. catch (Exception ex)
  191. {
  192. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP文件数据异常");
  193. }
  194. return strs;
  195. }
  196. public static void GetFTPDataInfo()
  197. {
  198. // 47.108.253.46
  199. // 用户名:hdftp
  200. // 密:haodatradeftp2024
  201. // 目录:/haoda-trade
  202. // FTP服务器的地址
  203. string ftpServerAddress = "ftp://47.108.253.46";
  204. // FTP登录凭证
  205. string ftpUser = "hdftp";
  206. string ftpPassword = "haodatradeftp2024";
  207. // 要下载的文件路径
  208. string filePath = "/haoda-trade/20240513.csv";
  209. try
  210. {
  211. // 创建FtpWebRequest对象
  212. FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpServerAddress + filePath);
  213. request.Method = WebRequestMethods.Ftp.DownloadFile;
  214. request.Credentials = new NetworkCredential(ftpUser, ftpPassword);
  215. // 使用WebResponse获取响应
  216. FtpWebResponse response = (FtpWebResponse)request.GetResponse();
  217. // 打开数据流
  218. Stream responseStream = response.GetResponseStream();
  219. using (StreamReader reader = new StreamReader(responseStream))
  220. {
  221. WebCMSEntities db = new WebCMSEntities();
  222. // 读取数据
  223. string fileContents = reader.ReadToEnd();
  224. if (!string.IsNullOrEmpty(fileContents))
  225. {
  226. var DataInfo = fileContents.TrimEnd('\n').Split('\n', 2);
  227. var DataList = DataInfo[1].Split('\n');
  228. foreach (var DataListItem in DataList)
  229. {
  230. var DataListInfo = DataListItem.Split(',');
  231. var MerchantNo = ""; // 商户号
  232. var BaseNo = ""; // 设备号
  233. var OrderNo = ""; // 订单号
  234. var PayWay = ""; // 支付方式(微信 支付宝)
  235. var TradeType = ""; // 交易类型
  236. var TradeAmount = ""; // 交易金额
  237. var TradeFee = ""; // 交易手续费
  238. var TradeDate = ""; // 交易时间
  239. var TradeCycle = ""; // 结算周期
  240. MerchantNo = DataListInfo[0];
  241. BaseNo = DataListInfo[1];
  242. OrderNo = DataListInfo[2];
  243. PayWay = DataListInfo[3];
  244. TradeType = DataListInfo[4];
  245. TradeAmount = DataListInfo[5];
  246. TradeFee = DataListInfo[6];
  247. TradeDate = DataListInfo[7];
  248. TradeCycle = DataListInfo[8];
  249. 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);
  250. var PayMode = 0;
  251. if (PayWay.Contains("支付宝")) PayMode = 1;
  252. if (PayWay.Contains("微信")) PayMode = 2;
  253. var merchantAddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.MchtNo == MerchantNo) ?? new MerchantAddInfo();
  254. if (merchantAddInfo.Id > 0)
  255. {
  256. var merchantInfo = db.MerchantInfo.FirstOrDefault(m => m.Id == merchantAddInfo.Id) ?? new MerchantInfo();
  257. var orders = db.ConsumerOrders.FirstOrDefault(m => m.SeoTitle == OrderNo && OrderNo == OrderNo) ?? new ConsumerOrders();
  258. if (orders.Id == 0)
  259. {
  260. var query = db.ConsumerOrders.Add(new ConsumerOrders()
  261. {
  262. Status = 1,
  263. CreateDate = DateTime.Parse(TradeDate),
  264. UpdateDate = DateTime.Parse(TradeDate),
  265. SnNo = BaseNo,
  266. PayMoney = decimal.Parse(TradeAmount),
  267. PayMode = PayMode,
  268. SeoTitle = OrderNo,
  269. OrderNo = OrderNo,
  270. MerchantId = merchantAddInfo.Id,
  271. UserId = merchantInfo.UserId
  272. }).Entity;
  273. }
  274. }
  275. }
  276. db.SaveChanges();
  277. db.Dispose();
  278. }
  279. // 关闭响应
  280. response.Close();
  281. }
  282. // 关闭响应
  283. response.Close();
  284. }
  285. catch (WebException ex)
  286. {
  287. // 如果抛出WebException,则可能是文件不存在
  288. // 根据响应状态码判断是否文件不存在
  289. if (((FtpWebResponse)ex.Response).StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
  290. {
  291. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString() + "文件" + filePath + "不存在", "获取好哒FTP文件数据异常"); // 文件不存在,返回false
  292. }
  293. else
  294. {
  295. // 其他错误
  296. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "获取好哒FTP文件数据异常");
  297. }
  298. }
  299. }
  300. public void StartProfitShareListen()
  301. {
  302. bool op = true;
  303. while (op)
  304. {
  305. try
  306. {
  307. WebCMSEntities db = new WebCMSEntities();
  308. var list = db.ConsumerOrders.Where(m => m.Status == 1 && m.IsAct == 0).OrderByDescending(m => m.Id).ToList();
  309. foreach (var sub in list)
  310. {
  311. ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == sub.Id);
  312. if (order != null)
  313. {
  314. int Status = 2;
  315. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantInfo();
  316. MerchantParamSet set = db.MerchantParamSet.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantParamSet();
  317. MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
  318. //发起分账
  319. string applyNo = "FZ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //批次号
  320. string mchtNo = merchantAdd.OutMchtNo; //慧掌柜商户号
  321. string orderNo = order.SeoTitle; //交易订单号(好哒平台订单号,G开头)
  322. string acctNo = AppConfig.Haoda.AcctNo; //账户号,分账接收方账户号
  323. string sacctNo = merchantAdd.MchtNo; //账户号,收款商户号
  324. string acctType = "0"; //账户类型(0:商户收款账户(大B),1:分账接收方账户(小B))
  325. decimal amount = order.PayMoney * (1M - 0.0038M) * 100;
  326. string result = HaoDaHelper.Instance.OrderDivideAccounts(OrderDivideAccountsUtil.AddValue(applyNo, mchtNo, orderNo, acctNo, sacctNo, acctType, amount.ToString().Split('.')[0], "0"));
  327. if (result.Contains("\"resultCode\":\"0\"") && result.Contains("分账金额不足"))
  328. {
  329. Status = 1;
  330. }
  331. order.Status = Status;
  332. }
  333. }
  334. db.SaveChanges();
  335. db.Dispose();
  336. }
  337. catch (Exception ex)
  338. {
  339. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "好哒分账队列异常");
  340. }
  341. Thread.Sleep(2000);
  342. }
  343. }
  344. //新建商户查询状态
  345. public void QueryMerchantStatus(int MerchantId)
  346. {
  347. WebCMSEntities db = new WebCMSEntities();
  348. MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  349. var BrhCode = HaodaUnionParam.BrhCode;
  350. if (merchantadd.BrandId == 1) BrhCode = HaodaParam.BrhCode;
  351. //查询商户审核状态
  352. var returnInfo = HaoDaHelper.Instance.QueryMerchantStatus(BrhCode, merchantadd.MchtNo, merchantadd.BrandId);
  353. JsonData dic = JsonMapper.ToObject(returnInfo);
  354. //审核成功(1- 待审核 2 -审核中 3 -审核被拒绝 4 -审核通过 6 -待复核)
  355. if (dic["data"]["code"].ToString() == "4" && !string.IsNullOrEmpty(dic["data"]["storeNo"].ToString()) && !string.IsNullOrEmpty(dic["data"]["outMchtNo"].ToString()))
  356. {
  357. //查询商户是否存在
  358. if (merchantadd != null)
  359. {
  360. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId);
  361. merchantadd.StoreNo = dic["data"]["storeNo"].ToString();
  362. merchantadd.HdStatus = 1; //0 待审核 1 已通过 2 已开通分账 3 已添加接收方
  363. merchantadd.OutMchtNo = dic["data"]["outMchtNo"].ToString();
  364. if (merchantadd.BrandId == 1)
  365. {
  366. merchantadd.Status = 2;
  367. merchantadd.QueryCount = 2;
  368. merchant.Status = 2;
  369. merchant.QueryCount = 2;
  370. }
  371. else
  372. {
  373. if (merchant != null)
  374. {
  375. merchant.Status = 1;
  376. }
  377. //商户开通分账
  378. JsonData Info = JsonMapper.ToObject(HaoDaHelper.Instance.OpenDivideAccounts(merchantadd.OutMchtNo, merchantadd.StoreNo, merchantadd.BrandId));
  379. //开通失败
  380. if (Info["resultCode"].ToString() == "0")
  381. {
  382. merchantadd.Status = -1;
  383. merchantadd.WeChatRemark = Info["errorDesc"].ToString();
  384. }
  385. //开通成功
  386. if (Info["resultCode"].ToString() == "1")
  387. {
  388. merchantadd.OpenAct = 1;//是否开通分账(1 是 0 否)
  389. merchantadd.HdStatus = 2; //0 待审核 1 已通过 2 已开通分账 3 已添加接收方
  390. //分账接收方签约
  391. JsonData Infos = JsonMapper.ToObject(HaoDaHelper.Instance.DivideAccountsSign(AppConfig.Haoda.AcctNo, merchantadd.OutMchtNo, merchantadd.StoreNo, merchantadd.BrandId));
  392. //失败
  393. if (Infos["resultCode"].ToString() == "0")
  394. {
  395. merchantadd.WeChatRemark = Infos["errorDesc"].ToString();
  396. }
  397. //成功
  398. else
  399. {
  400. merchantadd.HdStatus = 3; //0 待审核 1 已通过 2 已开通分账 3 已添加接收方
  401. if (!string.IsNullOrEmpty(merchantadd.ToAcctNo))
  402. {
  403. if (!merchantadd.ToAcctNo.Contains("," + AppConfig.Haoda.AcctNo + ","))
  404. {
  405. merchantadd.ToAcctNo += "," + AppConfig.Haoda.AcctNo + ",";
  406. }
  407. }
  408. else
  409. {
  410. merchantadd.ToAcctNo += "," + AppConfig.Haoda.AcctNo + ",";
  411. }
  412. merchantadd.HdPassDate = DateTime.Now;
  413. }
  414. }
  415. //开户意愿申请
  416. RedisDbconn.Instance.AddList("AlipayForHaoDaQueue", MerchantId);
  417. RedisDbconn.Instance.AddList("WeChatForHaoDaQueue", MerchantId);
  418. }
  419. db.SaveChanges();
  420. //创客账号
  421. Models.Main1.WebCMSEntities db1 = new Models.Main1.WebCMSEntities();
  422. string pwd = merchantadd.MobilePhone.Substring(5);
  423. merchant.LoginPwd = function.MD532(pwd);
  424. Models.Main1.MerchantLoginInfo info = db1.MerchantLoginInfo.FirstOrDefault(m => m.LoginMobile == merchantadd.MobilePhone);
  425. if (info == null)
  426. {
  427. info = db1.MerchantLoginInfo.Add(new Models.Main1.MerchantLoginInfo()
  428. {
  429. LoginMobile = merchantadd.MobilePhone,
  430. }).Entity;
  431. db1.SaveChanges();
  432. }
  433. info.LoginPwd = function.MD532(pwd);
  434. db1.SaveChanges();
  435. Models.Main1.MerchantAccountLinkInfo infolink = db1.MerchantAccountLinkInfo.FirstOrDefault(m => m.LoginId == info.Id && m.MerchantId == merchantadd.Id && m.Kind == 2);
  436. if (infolink == null)
  437. {
  438. infolink = db1.MerchantAccountLinkInfo.Add(new Models.Main1.MerchantAccountLinkInfo()
  439. {
  440. LoginId = info.Id,
  441. MerchantId = merchantadd.Id,
  442. Kind = 2,
  443. }).Entity;
  444. db1.SaveChanges();
  445. }
  446. db1.Dispose();
  447. }
  448. }
  449. //审核被拒绝
  450. else if (dic["data"]["code"].ToString() == "3")
  451. {
  452. if (merchantadd != null)
  453. {
  454. string WeChatRemark = dic["data"]["option"].ToString();
  455. if (WeChatRemark.Contains("租赁协议") && WeChatRemark.Contains("水电煤") && WeChatRemark.Contains("门头合影") && WeChatRemark.Contains("下载地址"))
  456. {
  457. WeChatRemark = "门头不一致需补充 “名称不一致说明函”";
  458. }
  459. if (WeChatRemark.Contains("盒伙人在门头合影"))
  460. {
  461. WeChatRemark = "门头不一致需补充 “名称不一致说明函”";
  462. }
  463. if (WeChatRemark.Contains("不支持跨商户进件"))
  464. {
  465. WeChatRemark = "该商户已注册,错误指令【404】";
  466. }
  467. merchantadd.WeChatRemark = WeChatRemark;
  468. merchantadd.Status = -1;
  469. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId);
  470. if (merchant != null)
  471. {
  472. merchant.Status = -1;
  473. }
  474. db.SaveChanges();
  475. }
  476. db.Dispose();
  477. }
  478. }
  479. //提交支付宝开户意愿申请单
  480. public void AlipayAddInfo(int Id)
  481. {
  482. try
  483. {
  484. WebCMSEntities db = new WebCMSEntities();
  485. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  486. string result = AlipayFunctionForHD.Instance.AuthOrderCreate(info, info.AlipayAuthToken);
  487. JsonData jsonObj = JsonMapper.ToObject(result);
  488. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  489. reqdic.Add("Id", Id); // 商户Id
  490. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  491. LogHelper.Instance.WriteLog(req, "提交支付宝商户意愿申请单");
  492. Dictionary<string, string> headdic = HaoDaHelper.Instance.GetHeader(req);
  493. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  494. LogHelper.Instance.WriteLog("请求参数\n" + req, "提交支付宝商户意愿申请单");
  495. LogHelper.Instance.WriteLog(result, "提交支付宝商户意愿申请单");
  496. if (jsonObj["alipay_merchant_indirect_authorder_create_response"]["code"].ToString() == "10000")
  497. {
  498. LogHelper.Instance.WriteLog("success", "提交支付宝商户意愿申请单");
  499. string order_no = jsonObj["alipay_merchant_indirect_authorder_create_response"]["order_no"].ToString();
  500. // RedisDbconn.Instance.AddList("AlipayResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"order_no\":\"" + order_no + "\"}");
  501. LogHelper.Instance.WriteLog("end", "提交支付宝商户意愿申请单");
  502. }
  503. else
  504. {
  505. LogHelper.Instance.WriteLog("false", "提交支付宝商户意愿申请单");
  506. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  507. info.QueryCount = -1;
  508. merchant.QueryCount = -1;
  509. info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_create_response"]["msg"].ToString();
  510. LogHelper.Instance.WriteLog("end", "提交支付宝商户意愿申请单");
  511. db.SaveChanges();
  512. }
  513. db.Dispose();
  514. }
  515. catch (Exception ex)
  516. {
  517. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "支付宝开户意愿申请异常");
  518. }
  519. }
  520. //查询支付宝开户意愿申请状态
  521. public void AlipayAddInfo(int Id, string OrderNo)
  522. {
  523. try
  524. {
  525. LogHelper.Instance.WriteLog("start", "查询支付宝商户意愿申请状态");
  526. WebCMSEntities db = new WebCMSEntities();
  527. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  528. string result = AlipayFunctionForHD.Instance.AuthOrderQuery(OrderNo);
  529. JsonData jsonObj = JsonMapper.ToObject(result);
  530. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  531. reqdic.Add("Id", Id); // 商户Id
  532. reqdic.Add("OrderNo", OrderNo); // 商户Id
  533. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  534. LogHelper.Instance.WriteLog(req, "查询支付宝商户意愿申请状态");
  535. Dictionary<string, string> headdic = HaoDaHelper.Instance.GetHeader(req);
  536. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  537. LogHelper.Instance.WriteLog("请求参数\n" + req, "查询支付宝商户意愿申请状态");
  538. LogHelper.Instance.WriteLog(result, "查询支付宝商户意愿申请状态");
  539. if (jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["code"].ToString() == "10000")
  540. {
  541. LogHelper.Instance.WriteLog("start1", "查询支付宝商户意愿申请状态");
  542. string order_status = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["order_status"].ToString();
  543. if (order_status == "CONTACT_CONFIRM")
  544. {
  545. LogHelper.Instance.WriteLog("start1", "查询支付宝商户意愿申请状态");
  546. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  547. info.QueryCount = 1;
  548. merchant.QueryCount = 1;
  549. info.AlipayRemark = "";
  550. info.AlipaySignUrl = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["qr_code"].ToString();
  551. db.SaveChanges();
  552. // RedisDbconn.Instance.AddList("HaoDaAuthQueryHelper", "{\"MerchantId\":\"" + Id + "\",\"MchtNo\":\"" + info.MchtNo + "\",\"StoreNo\":\"" + info.StoreNo + "\"}");
  553. LogHelper.Instance.WriteLog("start1end", "查询支付宝商户意愿申请状态");
  554. }
  555. else if (order_status == "AUDIT_REJECT" || order_status == "AUDIT_FREEZE")
  556. {
  557. LogHelper.Instance.WriteLog("start2", "查询支付宝商户意愿申请状态");
  558. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  559. info.QueryCount = -1;
  560. merchant.QueryCount = -1;
  561. info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["msg"].ToString();
  562. LogHelper.Instance.WriteLog("start2end", "查询支付宝商户意愿申请状态");
  563. db.SaveChanges();
  564. }
  565. else if (order_status == "AUDIT_PASS")
  566. {
  567. LogHelper.Instance.WriteLog("start2", "查询支付宝商户意愿申请状态");
  568. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  569. info.QueryCount = 2;
  570. merchant.QueryCount = 2;
  571. info.AlipayRemark = "";
  572. LogHelper.Instance.WriteLog("start2end", "查询支付宝商户意愿申请状态");
  573. if (merchant.Latitude == 0)
  574. {
  575. //签约成功调用腾讯地图接口获取地址
  576. RedisDbconn.Instance.AddList("GetTencentAddressInfoQueueHd", "{\"MerChantId\":\"" + merchant.Id + "\",\"Address\":\"" + merchant.Areas + merchant.Address + "\"}");
  577. }
  578. db.SaveChanges();
  579. }
  580. // else
  581. // {
  582. // RedisDbconn.Instance.AddList("AlipayResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"order_no\":\"" + OrderNo + "\"}");
  583. // }
  584. }
  585. else
  586. {
  587. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  588. info.QueryCount = -1;
  589. merchant.QueryCount = -1;
  590. info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["msg"].ToString();
  591. db.SaveChanges();
  592. }
  593. db.Dispose();
  594. }
  595. catch (Exception ex)
  596. {
  597. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "支付宝开户意愿申请异常");
  598. }
  599. }
  600. //提交微信开户意愿申请单
  601. public void WeChatAddInfo(int Id)
  602. {
  603. try
  604. {
  605. WebCMSEntities db = new WebCMSEntities();
  606. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  607. string result = WeChatFunctionForHD.Instance.MerchantApply(info);
  608. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  609. reqdic.Add("Id", Id); // 商户Id
  610. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  611. LogHelper.Instance.WriteLog(req, "提交微信商户意愿申请单");
  612. Dictionary<string, string> headdic = HaoDaHelper.Instance.GetHeader(req);
  613. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  614. LogHelper.Instance.WriteLog("请求参数\n" + req, "提交微信商户意愿申请单");
  615. LogHelper.Instance.WriteLog(result, "提交微信商户意愿申请单");
  616. if (result.Contains("\"applyment_id\":"))
  617. {
  618. LogHelper.Instance.WriteLog("success", "提交微信商户意愿申请单");
  619. JsonData json = JsonMapper.ToObject(result);
  620. string applyment_id = json["applyment_id"].ToString();
  621. // RedisDbconn.Instance.AddList("WeChatResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"ApplymentId\":\"" + applyment_id + "\"}");
  622. LogHelper.Instance.WriteLog("end", "提交微信商户意愿申请单");
  623. }
  624. else if (result.Contains("\"message\":"))
  625. {
  626. LogHelper.Instance.WriteLog("false", "提交微信商户意愿申请单");
  627. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  628. JsonData jsonObj = JsonMapper.ToObject(result);
  629. info.Status = -1;
  630. merchant.Status = -1;
  631. info.WeChatRemark = jsonObj["message"].ToString();
  632. LogHelper.Instance.WriteLog("end", "提交微信商户意愿申请单");
  633. db.SaveChanges();
  634. }
  635. db.Dispose();
  636. }
  637. catch (Exception ex)
  638. {
  639. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "微信开户意愿申请异常");
  640. }
  641. }
  642. //查询微信开户意愿申请状态
  643. public void WeChatAddInfo(int Id, string ApplymentId)
  644. {
  645. try
  646. {
  647. WebCMSEntities db = new WebCMSEntities();
  648. MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  649. string result = WeChatFunctionForHD.Instance.QueryMerchant(ApplymentId);
  650. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  651. reqdic.Add("Id", Id); // 商户Id
  652. reqdic.Add("ApplymentId", ApplymentId); // 商户Id
  653. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  654. LogHelper.Instance.WriteLog(req, "提交微信商户意愿申请单");
  655. Dictionary<string, string> headdic = HaoDaHelper.Instance.GetHeader(req);
  656. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  657. LogHelper.Instance.WriteLog("请求参数\n" + req, "提交微信商户意愿申请单");
  658. JsonData jsonObj = JsonMapper.ToObject(result);
  659. if (jsonObj["applyment_state"].ToString() == "APPLYMENT_STATE_WAITTING_FOR_CONFIRM_CONTACT")
  660. {
  661. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  662. info.Status = 1;
  663. merchant.Status = 1;
  664. info.WeChatRemark = "";
  665. info.WeChatSignUrl = jsonObj["qrcode_data"].ToString();
  666. db.SaveChanges();
  667. // RedisDbconn.Instance.AddList("HaoDaAuthQueryHelper", "{\"MerchantId\":\"" + Id + "\",\"MchtNo\":\"" + info.MchtNo + "\",\"StoreNo\":\"" + info.StoreNo + "\"}");
  668. }
  669. else if (jsonObj["applyment_state"].ToString() == "APPLYMENT_STATE_REJECTED")
  670. {
  671. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  672. info.Status = -1;
  673. merchant.Status = -1;
  674. info.WeChatRemark = jsonObj["reject_reason"].ToString();
  675. db.SaveChanges();
  676. }
  677. // else
  678. // {
  679. // RedisDbconn.Instance.AddList("WeChatResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"ApplymentId\":\"" + ApplymentId + "\"}");
  680. // }
  681. db.Dispose();
  682. }
  683. catch (Exception ex)
  684. {
  685. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "微信开户意愿申请异常");
  686. }
  687. }
  688. //添加分账接收方账户
  689. public void AddOpenDivideAccounts(int MerchantId)
  690. {
  691. WebCMSEntities db = new WebCMSEntities();
  692. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  693. string result = HaoDaHelper.Instance.AddOpenDivideAccounts(AddOpenDivideAccountsUtil.AddValue(AddInfo));
  694. db.Dispose();
  695. }
  696. public void ConfiemMer(int MerchantId)
  697. {
  698. WebCMSEntities db = new WebCMSEntities();
  699. Models.Main1.WebCMSEntities db1 = new Models.Main1.WebCMSEntities();
  700. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  701. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId);
  702. if (AddInfo != null && merchant != null)
  703. {
  704. string BusinessCode = AddInfo.BusinessCode;
  705. if (string.IsNullOrEmpty(BusinessCode))
  706. {
  707. BusinessCode = "LKB" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(5);
  708. AddInfo.BusinessCode = BusinessCode;
  709. }
  710. string pwd = AddInfo.MobilePhone.Substring(5);
  711. merchant.LoginPwd = function.MD532(pwd);
  712. MerchantParamSet query = db.MerchantParamSet.FirstOrDefault(m => m.Id == MerchantId);
  713. if (query == null)
  714. {
  715. query = new MerchantParamSet();
  716. query.IsAll = 1;
  717. db.MerchantParamSet.Add(query);
  718. db.SaveChanges();
  719. }
  720. MerchantForMobile merchantForMobile = db.MerchantForMobile.FirstOrDefault(m => m.Mobile == AddInfo.MobilePhone);
  721. if (merchantForMobile == null)
  722. {
  723. merchantForMobile = db.MerchantForMobile.Add(new MerchantForMobile()
  724. {
  725. Mobile = AddInfo.MobilePhone,
  726. }).Entity;
  727. db.SaveChanges();
  728. }
  729. merchantForMobile.MerchantId = MerchantId;
  730. db.SaveChanges();
  731. Models.Main1.MerchantLoginInfo info = db1.MerchantLoginInfo.FirstOrDefault(m => m.LoginMobile == AddInfo.MobilePhone);
  732. if (info == null)
  733. {
  734. info = db1.MerchantLoginInfo.Add(new Models.Main1.MerchantLoginInfo()
  735. {
  736. LoginMobile = AddInfo.MobilePhone,
  737. }).Entity;
  738. db1.SaveChanges();
  739. }
  740. info.LoginPwd = function.MD532(pwd);
  741. db1.SaveChanges();
  742. Models.Main1.MerchantAccountLinkInfo infolink = db1.MerchantAccountLinkInfo.FirstOrDefault(m => m.LoginId == info.Id && m.MerchantId == MerchantId && m.Kind == 2);
  743. if (infolink == null)
  744. {
  745. infolink = db1.MerchantAccountLinkInfo.Add(new Models.Main1.MerchantAccountLinkInfo()
  746. {
  747. LoginId = info.Id,
  748. MerchantId = MerchantId,
  749. Kind = 2,
  750. }).Entity;
  751. db1.SaveChanges();
  752. }
  753. if (AddInfo.Status <= 0)
  754. {
  755. //好哒新建商户
  756. string result = HaoDaHelper.Instance.AddNewMerchant(AddNewMerchantSetUtil.SetValue(AddInfo));
  757. JsonData jsonObj = JsonMapper.ToObject(result);
  758. //创建成功
  759. if (jsonObj["resultCode"].ToString() == "1")
  760. {
  761. AddInfo.WeChatRemark = "";
  762. if (string.IsNullOrEmpty(AddInfo.MchtNo))
  763. {
  764. AddInfo.MchtNo = jsonObj["data"]["mchtNo"].ToString();
  765. }
  766. AddInfo.Status = 0;
  767. merchant.Status = 0;
  768. db.SaveChanges();
  769. QueryMerchantStatus queryMerchantStatus = new QueryMerchantStatus();
  770. queryMerchantStatus.MerchantId = MerchantId.ToString();
  771. queryMerchantStatus.MerchantNo = AddInfo.MchtNo;
  772. // RedisDbconn.Instance.AddList("WeChatSignHdQueue", queryMerchantStatus);
  773. }
  774. //创建失败
  775. else
  776. {
  777. AddInfo.Status = -1;
  778. merchant.Status = -1;
  779. AddInfo.WeChatRemark = jsonObj["errorDesc"].ToString();
  780. // if (string.IsNullOrEmpty(AddInfo.MchtNo))
  781. // {
  782. // if (jsonObj.ToJson().Contains("mchtNo"))
  783. // {
  784. // AddInfo.MchtNo = jsonObj["data"]["mchtNo"].ToString();
  785. // }
  786. // }
  787. db.SaveChanges();
  788. }
  789. }
  790. }
  791. db.Dispose();
  792. db1.Dispose();
  793. }
  794. //商户开通分账
  795. public void OpenDivideAccounts(int MerchantId)
  796. {
  797. WebCMSEntities db = new WebCMSEntities();
  798. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  799. string result = HaoDaHelper.Instance.OpenDivideAccounts(AddInfo.OutMchtNo, AddInfo.StoreNo);
  800. db.Dispose();
  801. }
  802. //分账接收方签约
  803. public void DivideAccountsSign(int MerchantId)
  804. {
  805. WebCMSEntities db = new WebCMSEntities();
  806. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  807. string result = HaoDaHelper.Instance.DivideAccountsSign("230817000000000278", AddInfo.OutMchtNo, AddInfo.StoreNo);
  808. db.Dispose();
  809. }
  810. //查询实名认证状态
  811. public void QueryAuthStatus(int MerchantId)
  812. {
  813. WebCMSEntities db = new WebCMSEntities();
  814. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  815. string result = HaoDaHelper.Instance.QueryAuthStatus(AddInfo.OutMchtNo, AddInfo.StoreNo);
  816. db.Dispose();
  817. }
  818. //商户修改银行卡
  819. public void ChangeMerchantCard(int MerchantId)
  820. {
  821. WebCMSEntities db = new WebCMSEntities();
  822. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  823. var request = TestChangeMerchantCardSetUtil.SetValue(AddInfo);
  824. JsonData Infos = JsonMapper.ToObject(HaoDaHelper.Instance.ChangeMerchantCard(request));
  825. JsonData results = JsonMapper.ToObject(HaoDaHelper.Instance.QueryChangeCardStatus(AddInfo.MchtNo, Infos["data"]["taskId"].ToString()));
  826. //TODO:修改结算卡变更商户相关信息
  827. // AccountNumber
  828. // BankName
  829. // BankBranchId
  830. // BankAddressCode
  831. // BankAccountType
  832. // OpenUnionNo
  833. // OpenCollectBankCode
  834. // OpenBankRegionCode
  835. // OpenBankAccout
  836. // OpenBankAccName
  837. // ZbankRegionCode
  838. // ZBankNo
  839. db.Dispose();
  840. }
  841. //获取商户经纬坐标
  842. public void GetTencentAddressInfo(int Id)
  843. {
  844. WebCMSEntities db = new WebCMSEntities();
  845. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id);
  846. string Address = merchant.Areas + merchant.Address;
  847. string Key = Library.ConfigurationManager.AppSettings["TencentKey"].ToString();
  848. LogHelper.Instance.WriteLog("商户Id\n" + Id + "\n\n", "获取商户经纬坐标");
  849. LogHelper.Instance.WriteLog("请求参数\n" + Address + "\n\n", "获取商户经纬坐标");
  850. var info = function.GetWebRequest("https://apis.map.qq.com/ws/geocoder/v1/?address=" + Address + "&key=" + Key);
  851. JsonData result = JsonMapper.ToObject(info);
  852. //创建成功
  853. if (result["status"].ToString() == "0")
  854. {
  855. var merInfo = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
  856. if (merInfo.Id > 0)
  857. {
  858. merInfo.Longitude = decimal.Parse(result["result"]["location"]["lng"].ToString());
  859. merInfo.Latitude = decimal.Parse(result["result"]["location"]["lat"].ToString());
  860. db.SaveChanges();
  861. db.Dispose();
  862. }
  863. }
  864. LogHelper.Instance.WriteLog("返回\n" + info + "\n\n", "获取商户经纬坐标");
  865. db.Dispose();
  866. }
  867. public void QueryChangeCardStatus(int MerchantId)
  868. {
  869. WebCMSEntities db = new WebCMSEntities();
  870. MerchantAddInfo AddInfo = db.MerchantAddInfo.FirstOrDefault(m => m.Id == MerchantId);
  871. // JsonData results = JsonMapper.ToObject(HaoDaHelper.Instance.QueryChangeCardStatus(AddInfo.MchtNo, Infos["data"]["taskId"].ToString()));
  872. JsonData results = JsonMapper.ToObject(HaoDaHelper.Instance.QueryChangeCardStatus(AddInfo.MchtNo, "16592654"));
  873. }
  874. public void refund()
  875. {
  876. Thread th = new Thread(refunddo);
  877. th.IsBackground = true;
  878. th.Start();
  879. }
  880. public void refunddo()
  881. {
  882. for (int month = 10; month <= 11; month++)
  883. {
  884. for (int day = 1; day <= 31; day++)
  885. {
  886. string content = function.ReadInstance("/log/好哒聚合支付退款/2023/" + month + "/" + day + "/content.log");
  887. if (!string.IsNullOrEmpty(content))
  888. {
  889. content = content.Replace("\n\n\n", "####");
  890. content = content.Replace("\n", "");
  891. content = content.Replace("####", "\n");
  892. MatchCollection mc = Regex.Matches(content, "请求参数.*?退款次数超出限制");
  893. foreach (Match m in mc)
  894. {
  895. string mchtNo = Regex.Match(m.Value, "\"mchtNo\":\".*?\"").Value.Replace("\"mchtNo\":\"", "").Replace("\"", "");
  896. string storeNo = Regex.Match(m.Value, "\"storeNo\":\".*?\"").Value.Replace("\"storeNo\":\"", "").Replace("\"", "");
  897. string outOrderNo = Regex.Match(m.Value, "\"outOrderNo\":\".*?\"").Value.Replace("\"outOrderNo\":\"", "").Replace("\"", "");
  898. string refundAmount = Regex.Match(m.Value, "\"refundAmount\":\".*?\"").Value.Replace("\"refundAmount\":\"", "").Replace("\"", "");
  899. function.WriteLog("mchtNo:" + mchtNo + ";storeNo:" + storeNo + ";outOrderNo:" + outOrderNo + ";refundAmount:" + refundAmount + ";", "补充退款日志");
  900. var info = HaoDaHelper.Instance.AggregatedPayRefund(mchtNo, storeNo, "HDTK" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), outOrderNo, refundAmount);
  901. function.WriteLog(info + "\n\n", "补充退款日志");
  902. Thread.Sleep(1000);
  903. }
  904. }
  905. }
  906. }
  907. }
  908. }
  909. }