AirTicketResRepository.cs 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  1. using AutoMapper;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using OASystem.Domain;
  5. using OASystem.Domain.AesEncryption;
  6. using OASystem.Domain.Dtos.Groups;
  7. using OASystem.Domain.Entities.Customer;
  8. using OASystem.Domain.Entities.Financial;
  9. using OASystem.Domain.Entities.Groups;
  10. using OASystem.Domain.Entities.Resource;
  11. using OASystem.Domain.ViewModels.Groups;
  12. using System.Security.Cryptography;
  13. namespace OASystem.Infrastructure.Repositories.Groups
  14. {
  15. public class AirTicketResRepository : BaseRepository<Grp_AirTicketReservations, Grp_AirTicketReservations>
  16. {
  17. private readonly IMapper _mapper;
  18. public AirTicketResRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  19. {
  20. _mapper = mapper;
  21. }
  22. public async Task<Result> AirTicketResById(AirTicketResByIdDto dto)
  23. {
  24. var result = new Result() { Code = -2, Msg = "未知错误" };
  25. try
  26. {
  27. Grp_AirTicketReservations grp_AirTicket = _sqlSugar.Queryable<Grp_AirTicketReservations>().First(a => a.Id == dto.Id && a.IsDel == 0);
  28. if (grp_AirTicket == null)
  29. {
  30. return result = new Result() { Code = -1, Msg = "暂无数据" };
  31. }
  32. else
  33. {
  34. Grp_CreditCardPayment grp_CreditCard = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == grp_AirTicket.Id && a.IsDel == 0 && a.CTable == 85);
  35. if (grp_CreditCard == null) { return result = new Result() { Code = -1, Msg = "暂无数据" }; }
  36. return result = new Result()
  37. {
  38. Code = 0,
  39. Msg = "查询成功!",
  40. Data = new
  41. {
  42. AirTicket = grp_AirTicket,
  43. CreditCard = grp_CreditCard,
  44. }
  45. };
  46. }
  47. }
  48. catch (Exception)
  49. {
  50. return result = new Result() { Code = -2, Msg = "未知错误" };
  51. throw;
  52. }
  53. }
  54. public async Task<Result> AirTicketResList(AirTicketResDto dto)
  55. {
  56. var result = new Result() { Code = -2, Msg = "未知错误" };
  57. Grp_DelegationInfo _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().First(it => it.Id == dto.DiId);
  58. if (_DelegationInfo != null)
  59. {
  60. string UserId = "";
  61. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 85).ToList();
  62. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  63. UserId += gta.UId + ",";
  64. if (!string.IsNullOrWhiteSpace(UserId))
  65. {
  66. UserId = UserId[..^1];
  67. }
  68. else
  69. {
  70. UserId = "0";
  71. }
  72. string sqlWhere = "";
  73. if (dto.IsPaySign != -1)
  74. {
  75. sqlWhere += string.Format(@" And ccp.IsPay = {0} ", dto.IsPaySign);
  76. }
  77. string sql = string.Format(@"Select atr.*,ccp.IsAuditGM,sd1.Name As CTypeName,sd2.Name As PreCurrencyStr,sd3.Name As CurrencyStr,ccp.IsPay
  78. From Grp_AirTicketReservations atr
  79. Left Join Grp_CreditCardPayment ccp On atr.Id = ccp.CId And atr.DIId = ccp.DIId And ccp.IsDel = 0
  80. Left Join Sys_SetData sd1 On sd1.Id = atr.ctype
  81. Left Join Sys_SetData sd2 On sd2.Id = atr.PreCurrency
  82. Left Join Sys_SetData sd3 On sd3.Id = atr.Currency
  83. Where atr.IsDel = 0 And atr.DIId={0} {1}
  84. Order By atr.FlightsDate Asc", dto.DiId, sqlWhere);
  85. List<AirTicketReservationsView> _AirTicketReservations = _sqlSugar.SqlQueryable<AirTicketReservationsView>(sql).ToList();
  86. foreach (var item in _AirTicketReservations)
  87. {
  88. if (item.FlightsDescription.Contains("\n"))
  89. {
  90. var spilitArr = Regex.Split(item.FlightsDescription, "\n");
  91. int rowindex = 1;
  92. foreach (var spilitItem in spilitArr)
  93. {
  94. try
  95. {
  96. var spDotandEmpty = spilitItem.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  97. var depCode = spDotandEmpty[3].Substring(0, 3);
  98. var arrCode = spDotandEmpty[3].Substring(3, 3);
  99. Res_ThreeCode depData = _sqlSugar.Queryable<Res_ThreeCode>().First(it => it.IsDel == 0 && it.Three == depCode);
  100. Res_ThreeCode arrData = _sqlSugar.Queryable<Res_ThreeCode>().First(it => it.IsDel == 0 && it.Three == arrCode);
  101. string day = spDotandEmpty[2].Substring(2, 2);//日
  102. string monthAbbreviations = spDotandEmpty[2].Substring(4, 3).ToUpper();//月份
  103. switch (monthAbbreviations)
  104. {
  105. case "JAN":
  106. monthAbbreviations = "1";
  107. break;
  108. case "FEB":
  109. monthAbbreviations = "2";
  110. break;
  111. case "MAR":
  112. monthAbbreviations = "3";
  113. break;
  114. case "APR":
  115. monthAbbreviations = "4";
  116. break;
  117. case "MAY":
  118. monthAbbreviations = "5";
  119. break;
  120. case "JUN":
  121. monthAbbreviations = "6";
  122. break;
  123. case "JUL":
  124. monthAbbreviations = "7";
  125. break;
  126. case "AUG":
  127. monthAbbreviations = "8";
  128. break;
  129. case "SEP":
  130. monthAbbreviations = "9";
  131. break;
  132. case "OCT":
  133. monthAbbreviations = "10";
  134. break;
  135. case "NOV":
  136. monthAbbreviations = "11";
  137. break;
  138. case "DEC":
  139. monthAbbreviations = "12";
  140. break;
  141. }
  142. string tate = $"{monthAbbreviations}月{day}日";
  143. item.FlightDescription += rowindex + ". " + depData.AirPort + " " + arrData.AirPort + " (" + tate + ")\r\n";
  144. }
  145. catch (Exception ex)
  146. {
  147. item.FlightDescription = "录入数据不规范!请检查";
  148. break;
  149. }
  150. rowindex++;
  151. }
  152. }
  153. else
  154. {
  155. try
  156. {
  157. var spDotandEmpty = item.FlightsDescription.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  158. var depCode = spDotandEmpty[3].Substring(0, 3);
  159. var arrCode = spDotandEmpty[3].Substring(3, 3);
  160. Res_ThreeCode depData = _sqlSugar.Queryable<Res_ThreeCode>().First(it => it.IsDel == 0 && it.Three == depCode);
  161. Res_ThreeCode arrData = _sqlSugar.Queryable<Res_ThreeCode>().First(it => it.IsDel == 0 && it.Three == arrCode);
  162. string day = spDotandEmpty[2].Substring(2, 2);//日
  163. string monthAbbreviations = spDotandEmpty[2].Substring(4, 3).ToUpper();//月份
  164. switch (monthAbbreviations)
  165. {
  166. case "JAN":
  167. monthAbbreviations = "1";
  168. break;
  169. case "FEB":
  170. monthAbbreviations = "2";
  171. break;
  172. case "MAR":
  173. monthAbbreviations = "3";
  174. break;
  175. case "APR":
  176. monthAbbreviations = "4";
  177. break;
  178. case "MAY":
  179. monthAbbreviations = "5";
  180. break;
  181. case "JUN":
  182. monthAbbreviations = "6";
  183. break;
  184. case "JUL":
  185. monthAbbreviations = "7";
  186. break;
  187. case "AUG":
  188. monthAbbreviations = "8";
  189. break;
  190. case "SEP":
  191. monthAbbreviations = "9";
  192. break;
  193. case "OCT":
  194. monthAbbreviations = "10";
  195. break;
  196. case "NOV":
  197. monthAbbreviations = "11";
  198. break;
  199. case "DEC":
  200. monthAbbreviations = "12";
  201. break;
  202. }
  203. string tate = $"{monthAbbreviations}月{day}日";
  204. item.FlightDescription += depData.AirPort + " " + arrData.AirPort + " (" + tate + ")\r\n";
  205. }
  206. catch (Exception)
  207. {
  208. item.FlightDescription = "录入数据不规范!请检查";
  209. }
  210. }
  211. }
  212. //团组成本预算表查询
  213. Grp_GroupCostParameter _GroupCostParameter = _sqlSugar.Queryable<Grp_GroupCostParameter>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CostType == "A" && a.IsShare == 1);
  214. AirGroupCostParameterView _AirgroupCostParameter = _mapper.Map<AirGroupCostParameterView>(_GroupCostParameter);
  215. for (int i = 0; i < _AirTicketReservations.Count; i++)
  216. {
  217. string[] ClientArr = _AirTicketReservations[i].ClientName.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  218. foreach (var item in ClientArr)
  219. {
  220. bool isNumeric = int.TryParse(item, out _);
  221. if (isNumeric)
  222. {
  223. if (item == "-1")
  224. {
  225. _AirTicketReservations[i].ClientNameStr += "行程单,";
  226. }
  227. else
  228. {
  229. Crm_DeleClient DeleClient = _sqlSugar.Queryable<Crm_DeleClient>().Where(a => a.IsDel == 0 && a.Id == int.Parse(item)).First();
  230. EncryptionProcessor.DecryptProperties(DeleClient);
  231. _AirTicketReservations[i].ClientNameStr += DeleClient.Pinyin + ',';
  232. }
  233. }
  234. else
  235. {
  236. _AirTicketReservations[i].ClientNameStr += item;
  237. }
  238. }
  239. if (_AirTicketReservations[i].ClientNameStr is not null)
  240. {
  241. _AirTicketReservations[i].ClientNameStr = _AirTicketReservations[i].ClientNameStr.Substring(0, _AirTicketReservations[i].ClientNameStr.Length - 1);
  242. }
  243. }
  244. if (dto.PortType == 1)
  245. {
  246. var data = new
  247. {
  248. DelegationInfo = _DelegationInfo,
  249. AirTicketReservations = _AirTicketReservations,
  250. AirGroupCostParameter = _AirgroupCostParameter
  251. };
  252. return result = new Result() { Code = 0, Msg = "查询成功!", Data = data };
  253. }
  254. else if (dto.PortType == 2 || dto.PortType == 3)
  255. {
  256. int count = _AirTicketReservations.Count;
  257. float totalPage = (float)count / dto.PageSize;//总页数
  258. if (totalPage == 0) totalPage = 1;
  259. else totalPage = (int)Math.Ceiling((double)totalPage);
  260. var grp_AirTickets = new List<AirTicketReservationsView>();
  261. for (int i = 0; i < dto.PageSize; i++)
  262. {
  263. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  264. if (RowIndex < _AirTicketReservations.Count)
  265. {
  266. grp_AirTickets.Add(_AirTicketReservations[RowIndex]);
  267. }
  268. else
  269. {
  270. break;
  271. }
  272. }
  273. var rst = new ListViewBase<AirTicketReservationsView>
  274. {
  275. DataList = grp_AirTickets,
  276. DataCount = count,
  277. CurrPageIndex = dto.PageIndex,
  278. CurrPageSize = dto.PageSize
  279. };
  280. var data = new
  281. {
  282. AirData = rst,
  283. AirGroupCostParameter = _AirgroupCostParameter
  284. };
  285. return new Result() { Code = 0, Msg = "查询成功!", Data = data };
  286. }
  287. else
  288. {
  289. return new Result() { Code = -1, Msg = "请传入PortType参数!1:Web,2:Android,3:IOS!" };
  290. }
  291. }
  292. else
  293. {
  294. return new Result() { Code = -1, Msg = "暂无团组数据!" };
  295. }
  296. }
  297. public async Task<Result> AirTicketResSelect(AirTicketResDto dto)
  298. {
  299. var result = new Result() { Code = -2, Msg = "未知错误" };
  300. try
  301. {
  302. if (dto.DiId < 1)
  303. {
  304. dto.DiId = -1;
  305. }
  306. #region 团组下拉框
  307. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == 85).ToList();
  308. var grp_NameView = new List<GroupNameView>();
  309. string DiId = "";
  310. foreach (var item in grp_GroupsTaskAssignment)
  311. {
  312. DiId += item.DIId + ",";
  313. }
  314. if (DiId.Length > 1)
  315. {
  316. DiId = DiId.Substring(0, DiId.Length - 1);
  317. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1} Order By Id Desc", DiId, 0);
  318. List<Grp_DelegationInfo> grp_Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  319. if (grp_Delegations.Count == 0)
  320. {
  321. return result = new Result() { Code = -1, Msg = "查询失败!" };
  322. }
  323. foreach (var item in grp_Delegations)
  324. {
  325. var groupNameView = new GroupNameView
  326. {
  327. Id = item.Id,
  328. GroupName = item.TeamName
  329. };
  330. grp_NameView.Add(groupNameView);
  331. }
  332. }
  333. #endregion
  334. #region 其他下拉框查询
  335. //舱位类型
  336. List<Sys_SetData> TicketClass = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 44 && a.IsDel == 0).ToList();
  337. List<SetDataInfoView> _TicketClassa = _mapper.Map<List<SetDataInfoView>>(TicketClass);
  338. //支付方式
  339. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  340. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  341. //卡类型
  342. List<Sys_SetData> CardType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
  343. List<SetDataInfoView> _CardType = _mapper.Map<List<SetDataInfoView>>(CardType);
  344. //合作方资料
  345. List<Res_AirTicketAgent> _AirTicketAgents = _sqlSugar.Queryable<Res_AirTicketAgent>().Where(a => a.IsDel == 0).ToList();
  346. foreach (var item in _AirTicketAgents)
  347. {
  348. EncryptionProcessor.DecryptProperties(item);
  349. }
  350. #endregion
  351. #region 客人名单下拉框
  352. if (dto.DiId == -1)
  353. {
  354. var dele = _AirTicketAgents.FirstOrDefault();
  355. dto.DiId = dele != null ? dele.Id : dto.DiId;
  356. }
  357. string sqlClient = string.Format("select b.Id,b.Pinyin,b.lastName,b.firstName,b.phone from Grp_TourClientList a, Crm_DeleClient b where a.clientid = b.id and a.isdel = 0 and a.diid = {0}", dto.DiId);
  358. var clientArr = _sqlSugar.SqlQueryable<SimplClientInfo>(sqlClient).ToList();
  359. foreach (var item in clientArr) { EncryptionProcessor.DecryptProperties(item); }
  360. #endregion
  361. var data = new
  362. {
  363. TicketClass = _TicketClassa,
  364. Payment = _Payment,
  365. CardType = _CardType,
  366. GroupName = grp_NameView,
  367. AirTicketAgents = _AirTicketAgents,
  368. clientArr
  369. };
  370. return result = new Result() { Code = 0, Msg = "查询成功!", Data = data };
  371. }
  372. catch (Exception ex)
  373. {
  374. return result = new Result() { Code = -2, Msg = "程序错误" };
  375. }
  376. }
  377. public async Task<Result> OpAirTicketRes(AirTicketResOpDto dto, Func<int, int, int, Task<Result>> fn)
  378. {
  379. var result = new Result() { Code = -2, Msg = "未知错误" };
  380. try
  381. {
  382. BeginTran();
  383. int id = 0;
  384. var grp_AirTicket = _mapper.Map<Grp_AirTicketReservations>(dto.AirTicketResOpData);
  385. if (dto.Status == 1)
  386. {
  387. //string selectSql = string.Format(@"select * from Grp_AirTicketReservations where CONVERT(nvarchar,ClientName)= '{0}' and IsDel={1} and FlightsCode='{2}'"
  388. // , dto.AirTicketResOpData.ClientName, 0,dto.AirTicketResOpData.FlightsCode);
  389. //var DeleClient = await _sqlSugar.SqlQueryable<Grp_AirTicketReservations>(selectSql).FirstAsync();//查询是否存在
  390. //if (DeleClient != null)
  391. //{
  392. // return result = new Result() { Code = -1, Msg = "该机票信息已存在,请勿重复添加!" };
  393. //}
  394. //else//不存在,可添加
  395. //{
  396. //grp_AirTicket.ArrivedTime = "";
  397. //grp_AirTicket.LeaveDescription = "";
  398. //grp_AirTicket.FlightsDescription = "";
  399. //grp_AirTicket.DeleteUserId = 0;
  400. //grp_AirTicket.DeleteTime = "";
  401. //grp_AirTicket.ReturnDescription = "";
  402. grp_AirTicket.FlightsDate = DateTime.Parse(grp_AirTicket.FlightsDate).ToString("yyyy-MM-dd");
  403. id = await AddAsyncReturnId(grp_AirTicket);
  404. if (id == 0)
  405. {
  406. result = new Result() { Code = -1, Msg = "添加失败!" };
  407. }
  408. else
  409. {
  410. result = new Result() { Code = 0, Msg = "添加成功!" };
  411. }
  412. // }
  413. if (result.Code == 0)
  414. {
  415. Grp_CreditCardPayment grp_CreditCard = _mapper.Map<Grp_CreditCardPayment>(dto.CardPaymentOpData);
  416. //PayDId == 刷卡 IsPay == 1
  417. if (dto.CardPaymentOpData.PayDId == 72) grp_CreditCard.IsPay = 1;
  418. else grp_CreditCard.IsPay = 0;
  419. //获取新汇率 int diId,int CId, int currencyId
  420. var rate = await fn(dto.AirTicketResOpData.DiId, 85, dto.AirTicketResOpData.Currency);
  421. if (rate.Code == 0)
  422. {
  423. var rateInfo = (rate.Data as CurrencyInfo);
  424. if (rateInfo is not null)
  425. {
  426. grp_CreditCard.DayRate = rateInfo.Rate;
  427. grp_CreditCard.RMBPrice = rateInfo.Rate * grp_CreditCard.PayMoney;
  428. }
  429. else
  430. {
  431. grp_CreditCard.DayRate = 1;
  432. grp_CreditCard.RMBPrice = grp_CreditCard.PayMoney;
  433. }
  434. }
  435. //换算
  436. #region 老汇率处理方式
  437. //Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == grp_AirTicket.DIId && a.IsDel == 0 && a.CTable == 85);
  438. //if (_TeamRate != null)
  439. //{
  440. // if (grp_CreditCard.PaymentCurrency == 49)
  441. // {
  442. // grp_CreditCard.DayRate = _TeamRate.RateU;
  443. // grp_CreditCard.RMBPrice = grp_CreditCard.PayMoney * Convert.ToDecimal(_TeamRate.RateU);
  444. // //ccp.PayMoney = ccp.PayMoney * float.Parse(tr.RateU);
  445. // }
  446. // else if (grp_CreditCard.PaymentCurrency == 51)
  447. // {
  448. // grp_CreditCard.DayRate = _TeamRate.RateE;
  449. // grp_CreditCard.RMBPrice = grp_CreditCard.PayMoney * Convert.ToDecimal(_TeamRate.RateE);
  450. // //ccp.PayMoney = ccp.PayMoney * float.Parse(tr.RateE);
  451. // }
  452. // else
  453. // {
  454. // grp_CreditCard.DayRate = 1M;
  455. // grp_CreditCard.RMBPrice = grp_CreditCard.PayMoney;
  456. // }
  457. //}
  458. //else
  459. //{
  460. // grp_CreditCard.DayRate = 1M;
  461. // grp_CreditCard.RMBPrice = grp_CreditCard.PayMoney;
  462. //}
  463. #endregion
  464. //判断是否超出成本
  465. #region 自动审核(暂时屏蔽)
  466. //Grp_GroupCostParameter _GroupCostParameter = _sqlSugar.Queryable<Grp_GroupCostParameter>().First(a => a.DiId == grp_AirTicket.DIId && a.IsDel == 0);
  467. //if (grp_AirTicket.CType == 460)//经济舱
  468. //{
  469. // if (_GroupCostParameter != null)
  470. // {
  471. // if (Convert.ToDecimal(_GroupCostParameter.JJCCB) * Convert.ToDecimal(grp_AirTicket.ClientNum) > grp_CreditCard.RMBPrice)
  472. // {
  473. // grp_CreditCard.ExceedBudget = 0;// 超出预算比例 换算
  474. // grp_CreditCard.IsAuditGM = 3;//3 为自动审核
  475. // grp_CreditCard.AuditGMOperate = 0;
  476. // grp_CreditCard.AuditGMDate = "";
  477. // grp_CreditCard.IsPay = 0;
  478. // }
  479. // else
  480. // {
  481. // var a = grp_CreditCard.RMBPrice - Convert.ToDecimal(_GroupCostParameter.JJCCB);
  482. // var b = a / Convert.ToDecimal(_GroupCostParameter.JJCCB) * Convert.ToDecimal(grp_AirTicket.ClientNum);
  483. // grp_CreditCard.ExceedBudget = b;// 超出预算比例 换算
  484. // grp_CreditCard.IsAuditGM = 0;//3 为自动审核
  485. // grp_CreditCard.AuditGMOperate = 21;
  486. // grp_CreditCard.AuditGMDate = "";
  487. // grp_CreditCard.IsPay = 0;
  488. // }
  489. // }
  490. // else
  491. // {
  492. // grp_CreditCard.ExceedBudget = 0.00M;// 超出预算比例 换算
  493. // grp_CreditCard.IsAuditGM = 0;//3 为自动审核
  494. // grp_CreditCard.AuditGMOperate = 0;
  495. // grp_CreditCard.AuditGMDate = "";
  496. // grp_CreditCard.IsPay = 0;
  497. // }
  498. //}
  499. //else if (grp_AirTicket.CType == 458)
  500. //{
  501. // if (_GroupCostParameter != null)
  502. // {
  503. // if (Convert.ToDecimal(_GroupCostParameter.GWCB) * Convert.ToDecimal(grp_AirTicket.ClientNum) > grp_CreditCard.RMBPrice)
  504. // {
  505. // grp_CreditCard.ExceedBudget = 0;// 超出预算比例 换算
  506. // grp_CreditCard.IsAuditGM = 3;//3 为自动审核
  507. // grp_CreditCard.AuditGMOperate = 21;
  508. // grp_CreditCard.AuditGMDate = "";
  509. // grp_CreditCard.IsPay = 0;
  510. // }
  511. // else
  512. // {
  513. // var a = grp_CreditCard.RMBPrice - Convert.ToDecimal(_GroupCostParameter.GWCB);
  514. // var b = a / Convert.ToDecimal(_GroupCostParameter.GWCB) * Convert.ToDecimal(grp_AirTicket.ClientNum);
  515. // grp_CreditCard.ExceedBudget = b;// 超出预算比例 换算
  516. // grp_CreditCard.IsAuditGM = 0;//3 为自动审核
  517. // grp_CreditCard.AuditGMOperate = 21;
  518. // grp_CreditCard.AuditGMDate = "";
  519. // grp_CreditCard.IsPay = 0;
  520. // }
  521. // }
  522. // else
  523. // {
  524. // grp_CreditCard.ExceedBudget = 0.00M;// 超出预算比例 换算
  525. // grp_CreditCard.IsAuditGM = 0;//3 为自动审核
  526. // grp_CreditCard.AuditGMOperate = 21;
  527. // grp_CreditCard.AuditGMDate = "";
  528. // grp_CreditCard.IsPay = 0;
  529. // }
  530. //}
  531. //else
  532. //{
  533. // grp_CreditCard.ExceedBudget = 0.00M;// 超出预算比例 换算
  534. // grp_CreditCard.IsAuditGM = 0;//3 为自动审核
  535. // grp_CreditCard.AuditGMOperate = 0;
  536. // grp_CreditCard.AuditGMDate = "";
  537. // grp_CreditCard.IsPay = 0;
  538. //}
  539. #endregion
  540. grp_CreditCard.CId = id;
  541. grp_CreditCard.CTable = 85;
  542. grp_CreditCard.PayPercentage = 100;
  543. #region 查询上一次付款(注释)
  544. ////查询上一次付款信息
  545. //Grp_CreditCardPayment _CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().OrderByDescending(x => x.CreateUserId).First(a => a.DIId == grp_AirTicket.DIId && a.IsDel == 0 && a.IsPay == 1);
  546. //if (_CreditCardPayment != null)
  547. //{
  548. // grp_CreditCard.PayPercentageOld = _CreditCardPayment.PayPercentageOld;// 上次付款百分比 查询并计算最近一次
  549. // grp_CreditCard.PayThenMoneyOld = _CreditCardPayment.PayMoney;// 上次付款金额 查询上一次
  550. // grp_CreditCard.UpdateDate = _CreditCardPayment.UpdateDate;// 上次付款时间 查询上一次
  551. //}
  552. //else
  553. //{
  554. // grp_CreditCard.PayPercentageOld = 0;// 上次付款百分比 查询并计算最近一次
  555. // grp_CreditCard.PayThenMoneyOld = 0;// 上次付款金额 查询上一次
  556. // grp_CreditCard.UpdateDate = "";// 上次付款时间 查询上一次
  557. //}
  558. #endregion
  559. id = await _sqlSugar.Insertable(grp_CreditCard).ExecuteReturnIdentityAsync();
  560. if (id == 0)
  561. {
  562. RollbackTran();
  563. return result = new Result() { Code = -1, Msg = "添加失败!" };
  564. }
  565. await UpdateAsync(a => a.Id == id, a => new Grp_AirTicketReservations
  566. {
  567. FlightsDescription = dto.AirTicketResOpData.FlightsDescription,
  568. });
  569. CommitTran();
  570. var data = new { ccpId = id, sign = 1 };
  571. return result = new Result() { Code = 0, Msg = "添加成功!", Data = data };
  572. }
  573. else
  574. {
  575. RollbackTran();
  576. return result = new Result() { Code = -1, Msg = "添加失败!" };
  577. }
  578. }
  579. else if (dto.Status == 2)
  580. {
  581. id = dto.AirTicketResOpData.Id;
  582. bool res = await UpdateAsync(a => a.Id == dto.AirTicketResOpData.Id, a => new Grp_AirTicketReservations
  583. {
  584. CType = dto.AirTicketResOpData.CType,
  585. PrePrice = dto.AirTicketResOpData.PrePrice,
  586. PreCurrency = dto.AirTicketResOpData.PreCurrency,
  587. Price = dto.AirTicketResOpData.Price,
  588. Currency = dto.AirTicketResOpData.Currency,
  589. ClientNum = dto.AirTicketResOpData.ClientNum,
  590. ClientName = dto.AirTicketResOpData.ClientName,
  591. IsCheckIn = dto.AirTicketResOpData.IsCheckIn,
  592. IsSetSeat = dto.AirTicketResOpData.IsSetSeat,
  593. IsPackage = dto.AirTicketResOpData.IsPackage,
  594. IsBagHandle = dto.AirTicketResOpData.IsBagHandle,
  595. IsTrain = dto.AirTicketResOpData.IsTrain,
  596. FlightsCode = dto.AirTicketResOpData.FlightsCode,
  597. FlightsCity = dto.AirTicketResOpData.FlightsCity,
  598. FlightsDescription = dto.AirTicketResOpData.FlightsDescription,
  599. PriceDescription = dto.AirTicketResOpData.PriceDescription,
  600. TicketNumber = dto.AirTicketResOpData.TicketNumber,
  601. TicketCode = dto.AirTicketResOpData.TicketCode,
  602. Remark = dto.AirTicketResOpData.Remark,
  603. });
  604. if (!res) { result = new Result() { Code = -1, Msg = "修改失败!" }; }
  605. else { result = new Result() { Code = 0, Msg = "修改成功!" }; }
  606. if (result.Code == 0)
  607. {
  608. //C表操作
  609. Grp_CreditCardPayment grp_CreditCard = _mapper.Map<Grp_CreditCardPayment>(dto.CardPaymentOpData);
  610. //PayDId == 刷卡 IsPay == 1
  611. if (grp_CreditCard.PayDId == 72) grp_CreditCard.IsPay = 1;
  612. else grp_CreditCard.IsPay = 0;
  613. //获取新汇率 int diId,int CId, int currencyId
  614. var rate = await fn(dto.AirTicketResOpData.DiId, 85, dto.AirTicketResOpData.Currency);
  615. if (rate.Code == 0)
  616. {
  617. var rateInfo = (rate.Data as CurrencyInfo);
  618. if (rateInfo is not null)
  619. {
  620. grp_CreditCard.DayRate = rateInfo.Rate;
  621. grp_CreditCard.RMBPrice = rateInfo.Rate * grp_CreditCard.PayMoney;
  622. }
  623. else
  624. {
  625. grp_CreditCard.DayRate = 1;
  626. grp_CreditCard.RMBPrice = grp_CreditCard.PayMoney;
  627. }
  628. }
  629. #region 老汇率修改(注释)
  630. //换算
  631. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == grp_AirTicket.DIId && a.IsDel == 0 && a.CTable == 85);
  632. //if (_TeamRate != null)
  633. //{
  634. // if (grp_CreditCard.PaymentCurrency == 49)
  635. // {
  636. // grp_CreditCard.DayRate = _TeamRate.RateU;
  637. // grp_CreditCard.RMBPrice = grp_CreditCard.PayMoney * Convert.ToDecimal(_TeamRate.RateU);
  638. // //ccp.PayMoney = ccp.PayMoney * float.Parse(tr.RateU);
  639. // }
  640. // else if (grp_CreditCard.PaymentCurrency == 51)
  641. // {
  642. // grp_CreditCard.DayRate = _TeamRate.RateE;
  643. // grp_CreditCard.RMBPrice = grp_CreditCard.PayMoney * Convert.ToDecimal(_TeamRate.RateE);
  644. // //ccp.PayMoney = ccp.PayMoney * float.Parse(tr.RateE);
  645. // }
  646. // else
  647. // {
  648. // grp_CreditCard.DayRate = 1M;
  649. // grp_CreditCard.RMBPrice = grp_CreditCard.PayMoney;
  650. // }
  651. //}
  652. //else
  653. //{
  654. // grp_CreditCard.DayRate = 1M;
  655. // grp_CreditCard.RMBPrice = grp_CreditCard.PayMoney;
  656. //}
  657. #endregion
  658. #region 自动审核(注释)
  659. //Grp_GroupCostParameter _GroupCostParameter = _sqlSugar.Queryable<Grp_GroupCostParameter>().First(a => a.DiId == grp_AirTicket.DIId && a.IsDel == 0);
  660. //if (grp_AirTicket.CType == 460)//经济舱
  661. //{
  662. // if (_GroupCostParameter != null)
  663. // {
  664. // if (Convert.ToDecimal(_GroupCostParameter.JJCCB) * Convert.ToDecimal(grp_AirTicket.ClientNum) > grp_CreditCard.RMBPrice)
  665. // {
  666. // grp_CreditCard.ExceedBudget = 0;// 超出预算比例 换算
  667. // grp_CreditCard.IsAuditGM = 3;//3 为自动审核
  668. // grp_CreditCard.AuditGMOperate = 0;
  669. // grp_CreditCard.AuditGMDate = "";
  670. // grp_CreditCard.IsPay = 1;
  671. // }
  672. // else
  673. // {
  674. // var a = grp_CreditCard.RMBPrice - Convert.ToDecimal(_GroupCostParameter.JJCCB);
  675. // var b = a / Convert.ToDecimal(_GroupCostParameter.JJCCB) * Convert.ToDecimal(grp_AirTicket.ClientNum);
  676. // grp_CreditCard.ExceedBudget = b;// 超出预算比例 换算
  677. // grp_CreditCard.IsAuditGM = 0;//3 为自动审核
  678. // grp_CreditCard.AuditGMOperate = 21;
  679. // grp_CreditCard.AuditGMDate = "";
  680. // grp_CreditCard.IsPay = 1;
  681. // }
  682. // }
  683. // else
  684. // {
  685. // grp_CreditCard.ExceedBudget = 0.00M;// 超出预算比例 换算
  686. // grp_CreditCard.IsAuditGM = 0;//3 为自动审核
  687. // grp_CreditCard.AuditGMOperate = 21;
  688. // grp_CreditCard.AuditGMDate = "";
  689. // grp_CreditCard.IsPay = 0;
  690. // }
  691. //}
  692. //else if (grp_AirTicket.CType == 458)
  693. //{
  694. // if (_GroupCostParameter != null)
  695. // {
  696. // if ((_GroupCostParameter != null ? _GroupCostParameter.GWCB : 0) * Convert.ToDecimal(grp_AirTicket.ClientNum) > grp_CreditCard.RMBPrice)
  697. // {
  698. // grp_CreditCard.ExceedBudget = 0;// 超出预算比例 换算
  699. // grp_CreditCard.IsAuditGM = 3;//3 为自动审核
  700. // grp_CreditCard.AuditGMOperate = 21;
  701. // grp_CreditCard.AuditGMDate = "";
  702. // grp_CreditCard.IsPay = 1;
  703. // }
  704. // else
  705. // {
  706. // var a = grp_CreditCard.RMBPrice - Convert.ToDecimal(_GroupCostParameter.GWCB);
  707. // var b = a / Convert.ToDecimal(_GroupCostParameter.GWCB) * Convert.ToDecimal(grp_AirTicket.ClientNum);
  708. // grp_CreditCard.ExceedBudget = b;// 超出预算比例 换算
  709. // grp_CreditCard.IsAuditGM = 0;//3 为自动审核
  710. // grp_CreditCard.AuditGMOperate = 21;
  711. // grp_CreditCard.AuditGMDate = "";
  712. // grp_CreditCard.IsPay = 1;
  713. // }
  714. // }
  715. // else
  716. // {
  717. // grp_CreditCard.ExceedBudget = 0.00M;// 超出预算比例 换算
  718. // grp_CreditCard.IsAuditGM = 0;//3 为自动审核
  719. // grp_CreditCard.AuditGMOperate = 21;
  720. // grp_CreditCard.AuditGMDate = "";
  721. // grp_CreditCard.IsPay = 0;
  722. // }
  723. //}
  724. #endregion
  725. grp_CreditCard.CId = id;
  726. grp_CreditCard.CTable = 85;
  727. grp_CreditCard.PayPercentage = 100;
  728. #region 查询上一次付款信息(注释)
  729. ////查询上一次付款信息
  730. //Grp_CreditCardPayment _CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().OrderByDescending(x => x.CreateUserId).First(a => a.DIId == grp_AirTicket.DIId && a.IsDel == 0 && a.IsPay == 1);
  731. //if (_CreditCardPayment != null)
  732. //{
  733. // grp_CreditCard.PayPercentageOld = _CreditCardPayment.PayPercentageOld;// 上次付款百分比 查询并计算最近一次
  734. // grp_CreditCard.PayThenMoneyOld = _CreditCardPayment.PayMoney;// 上次付款金额 查询上一次
  735. // grp_CreditCard.UpdateDate = _CreditCardPayment.UpdateDate;// 上次付款时间 查询上一次
  736. //}
  737. //else
  738. //{
  739. // grp_CreditCard.PayPercentageOld = 0;// 上次付款百分比 查询并计算最近一次
  740. // grp_CreditCard.PayThenMoneyOld = 0;// 上次付款金额 查询上一次
  741. // grp_CreditCard.UpdateDate = "";// 上次付款时间 查询上一次
  742. //}
  743. #endregion
  744. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.Id == dto.CardPaymentOpData.Id).SetColumns(a => new Grp_CreditCardPayment
  745. {
  746. PayDId = grp_CreditCard.PayDId,
  747. ConsumptionPatterns = grp_CreditCard.ConsumptionPatterns,
  748. ConsumptionDate = grp_CreditCard.ConsumptionDate,
  749. CTDId = grp_CreditCard.CTDId,
  750. BankNo = grp_CreditCard.BankNo,
  751. CardholderName = grp_CreditCard.CardholderName,
  752. PayMoney = grp_CreditCard.PayMoney,
  753. PaymentCurrency = grp_CreditCard.PaymentCurrency,
  754. DayRate = grp_CreditCard.DayRate,
  755. CompanyBankNo = grp_CreditCard.CompanyBankNo,
  756. OtherBankName = grp_CreditCard.OtherBankName,
  757. OtherSideNo = grp_CreditCard.OtherSideNo,
  758. OtherSideName = grp_CreditCard.OtherSideName,
  759. IsAuditGM = grp_CreditCard.IsAuditGM,
  760. AuditGMOperate = grp_CreditCard.AuditGMOperate,
  761. AuditGMDate = grp_CreditCard.AuditGMDate,
  762. IsPay = grp_CreditCard.IsPay,
  763. PayPercentage = grp_CreditCard.PayPercentage,
  764. PayThenMoney = grp_CreditCard.PayThenMoney,
  765. PayPercentageOld = grp_CreditCard.PayPercentageOld,
  766. PayThenMoneyOld = grp_CreditCard.PayThenMoneyOld,
  767. UpdateDate = grp_CreditCard.UpdateDate,
  768. Payee = grp_CreditCard.Payee,
  769. RMBPrice = grp_CreditCard.RMBPrice,
  770. OrbitalPrivateTransfer = grp_CreditCard.OrbitalPrivateTransfer,
  771. ExceedBudget = grp_CreditCard.ExceedBudget,
  772. Remark = grp_CreditCard.Remark,
  773. }).ExecuteCommandAsync();
  774. if (CTable == 0)
  775. {
  776. RollbackTran();
  777. return result = new Result() { Code = -1, Msg = "修改失败!" };
  778. }
  779. else
  780. {
  781. Grp_CreditCardPayment ccp = Query<Grp_CreditCardPayment>(a => a.Id == dto.CardPaymentOpData.Id).First();
  782. var data = new { ccpId = ccp.Id, sign = 2 };
  783. result = new Result() { Code = 0, Msg = "修改成功!", Data = data };
  784. }
  785. }
  786. else
  787. {
  788. result = new Result() { Code = -1, Msg = "修改失败!" };
  789. RollbackTran();
  790. }
  791. }
  792. CommitTran();
  793. }
  794. catch (Exception ex)
  795. {
  796. RollbackTran();
  797. return result = new Result() { Code = -2, Msg = "程序错误" };
  798. throw;
  799. }
  800. return result;
  801. }
  802. /// <summary>
  803. /// 导出机票费用报表
  804. /// </summary>
  805. /// <param name="dto"></param>
  806. /// <returns></returns>
  807. /// <exception cref="NotImplementedException"></exception>
  808. public async Task<Result> DeriveAirTicketRes(AirTicketResDto dto)
  809. {
  810. var result = new Result() { Code = -2, Msg = "未知错误" };
  811. try
  812. {
  813. string sql = string.Format(@"Select atr.*,ccp.IsAuditGM,sd1.Name As 'CTypeName',sd2.Name As 'PreCurrencyStr',sd3.Name As CurrencyStr
  814. From Grp_AirTicketReservations atr
  815. Left Join Grp_CreditCardPayment ccp On atr.Id = ccp.CId And atr.DIId = ccp.DIId And ccp.IsDel = 0
  816. Left Join Sys_SetData sd1 On sd1.Id = atr.ctype
  817. Left Join Sys_SetData sd2 On sd2.Id = atr.PreCurrency
  818. Left Join Sys_SetData sd3 On sd3.Id = atr.Currency
  819. Where atr.IsDel = 0 And atr.DIId={0}
  820. Order By atr.FlightsDate Asc", dto.DiId);
  821. List<AirTicketReservationsPayView> _AirTicketReservations = _sqlSugar.SqlQueryable<AirTicketReservationsPayView>(sql).ToList();
  822. if (_AirTicketReservations.Count != 0)
  823. {
  824. Grp_DelegationInfo grp_Delegation = _sqlSugar.Queryable<Grp_DelegationInfo>().First(a => a.Id == dto.DiId && a.IsDel == 0);
  825. Sys_Users _Users = _sqlSugar.Queryable<Sys_Users>().First(a => a.Id == dto.UserId && a.IsDel == 0);
  826. return result = new Result() { Code = 0, Msg = "成功", Data = new { Delegation = grp_Delegation, AirTicketRes = _AirTicketReservations, Users = _Users } };
  827. }
  828. else
  829. {
  830. return result = new Result() { Code = -1, Msg = "暂无数据", Data = null };
  831. }
  832. }
  833. catch (Exception)
  834. {
  835. return result = new Result() { Code = -2, Msg = "未知错误" };
  836. }
  837. }
  838. public async Task<Result> ItineraryAirTicketRes(ItineraryAirTicketResDto dto)
  839. {
  840. try
  841. {
  842. string sql = string.Format(@"select a.*,c.IsAuditGM,(select Name from Sys_SetData where Id=a.cType) as 'CTypeName',(select Name from
  843. Sys_SetData where Id=a.PreCurrency) as 'PreCurrencyStr',(select Name from Sys_SetData where Id=a.Currency)
  844. as 'CurrencyStr' from Grp_AirTicketReservations a,Grp_CreditCardPayment c where a.id=c.CId and a.isdel={1}
  845. and a.DIId={0} Order By a.CreateTime desc", dto.DiId, 0);
  846. List<AirTicketReservationsView> _AirTicketReservations = _sqlSugar.SqlQueryable<AirTicketReservationsView>(sql).ToList();
  847. if (_AirTicketReservations.Count == 0)
  848. {
  849. return new Result() { Code = -1, Msg = "暂无数据", Data = null };
  850. }
  851. else
  852. {
  853. return new Result() { Code = 0, Msg = "查询成功", Data = _AirTicketReservations };
  854. }
  855. }
  856. catch (Exception)
  857. {
  858. return new Result() { Code = -2, Msg = "未知错误" };
  859. }
  860. }
  861. public async Task<List<TranslateResult>> ReTransBatch(List<string> list, string aimlanguage)
  862. {
  863. var reultStr = new List<TranslateResult>();
  864. if (list.Count < 0)
  865. {
  866. return reultStr;
  867. }
  868. //待翻译内容,必须是UTF-8编码
  869. string q = "";
  870. string Qtext = "";
  871. foreach (var item in list)
  872. {
  873. q += item;
  874. Qtext += "q=" + item + "&";
  875. }
  876. if (Qtext.Length > 0)
  877. {
  878. Qtext = Qtext[..^1];
  879. }
  880. var dic = new Dictionary<string, string>();
  881. string url = "https://openapi.youdao.com/v2/api";
  882. //应用ID
  883. string appKey = "0fe3bc01e109ed36";
  884. //应用应用密钥
  885. string appSecret = "1f2x9TrqJfSBEJ8iH9GEFGgTyaYGjEry";
  886. //UUID
  887. string salt = DateTime.Now.Millisecond.ToString();
  888. //源语言
  889. dic.Add("from", "zh-CHS");
  890. //目标语言
  891. dic.Add("to", aimlanguage);
  892. //签名类型
  893. dic.Add("signType", "v3");
  894. //时间戳
  895. string curtime = ((GetBeijingTime().ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString();
  896. dic.Add("curtime", curtime);
  897. string signStr = appKey + Truncate(q) + salt + curtime + appSecret; ;
  898. string sign = ComputeHash(signStr, SHA256.Create());
  899. dic.Add("q", Qtext);
  900. dic.Add("appKey", appKey);
  901. dic.Add("salt", salt);
  902. dic.Add("sign", sign);
  903. try
  904. {
  905. //Thread.Sleep(500);
  906. string jsonStr = await TransSync(url, dic);
  907. JObject trans = (JObject)JsonConvert.DeserializeObject(jsonStr);
  908. string errorCode = trans["errorCode"].ToString();
  909. if (errorCode == "0")
  910. {
  911. reultStr = JsonConvert.DeserializeObject<List<TranslateResult>>(trans["translateResults"].ToString());
  912. }
  913. return reultStr;
  914. }
  915. catch (Exception)
  916. {
  917. return reultStr;
  918. }
  919. }
  920. public string Processing(string str)//处理这段英文的方法
  921. {
  922. if (string.IsNullOrEmpty(str)) { return ""; }
  923. string[] strArray;
  924. if (str.Contains(" ")) strArray = str.Split(" ".ToCharArray());
  925. else if (str.Contains(",")) strArray = str.Split(",".ToCharArray());
  926. else if (str.Contains(" ") && str.Contains(",")) strArray = str.Split(",".ToCharArray());
  927. else strArray = new string[] { str };
  928. string result = string.Empty;//定义一个空字符串
  929. foreach (string s in strArray)//循环处理数组里面每一个字符串
  930. {
  931. //result += System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(s) + " ";
  932. result += string.Concat(s[..1].ToUpper(), s.AsSpan(1), " ");
  933. //.Substring(0, 1).ToUpper()把循环到的字符串第一个字母截取并转换为大写,并用s.Substring(1)得到循环到的字符串除第一个字符后的所有字符拼装到首字母后面。
  934. }
  935. return result;
  936. }
  937. protected static async Task<string> TransSync(string url, Dictionary<string, string> dic)
  938. {
  939. string result = "";
  940. using (var client = new HttpClient())
  941. {
  942. var content = new FormUrlEncodedContent(dic);
  943. HttpResponseMessage response = await client.PostAsync(url, content);
  944. response.EnsureSuccessStatusCode();
  945. if (response.Content.Headers.ContentType.MediaType.ToLower().Equals("audio/mp3"))
  946. {
  947. await SaveBinaryFile(response, "合成的音频存储路径");
  948. }
  949. else
  950. {
  951. result = await response.Content.ReadAsStringAsync();
  952. }
  953. }
  954. return result;
  955. }
  956. private static async Task<bool> SaveBinaryFile(HttpResponseMessage response, string FileName)
  957. {
  958. string FilePath = FileName + DateTime.Now.Millisecond.ToString() + ".mp3";
  959. bool Value = true;
  960. byte[] buffer = new byte[1024];
  961. try
  962. {
  963. if (File.Exists(FilePath))
  964. File.Delete(FilePath);
  965. using Stream outStream = File.Create(FilePath);
  966. using Stream inStream = await response.Content.ReadAsStreamAsync();
  967. int l;
  968. do
  969. {
  970. l = await inStream.ReadAsync(buffer);
  971. if (l > 0)
  972. await outStream.WriteAsync(buffer.AsMemory(0, l));
  973. }
  974. while (l > 0);
  975. }
  976. catch
  977. {
  978. Value = false;
  979. }
  980. return Value;
  981. }
  982. protected static string ComputeHash(string input, HashAlgorithm algorithm)
  983. {
  984. byte[] inputBytes = Encoding.UTF8.GetBytes(input);
  985. byte[] hashedBytes = algorithm.ComputeHash(inputBytes);
  986. return BitConverter.ToString(hashedBytes).Replace("-", "");
  987. }
  988. protected static string Truncate(string q)
  989. {
  990. if (q == null)
  991. {
  992. return null;
  993. }
  994. int len = q.Length;
  995. return len <= 20 ? q : q.Substring(0, 10) + len + q.Substring(len - 10, 10);
  996. }
  997. public static DateTime GetBeijingTime()
  998. {
  999. string datetime = string.Empty;
  1000. try
  1001. {
  1002. using (var client = new HttpClient())
  1003. {
  1004. client.Timeout = TimeSpan.FromSeconds(3);
  1005. HttpResponseMessage response = client.GetAsync("https://www.baidu.com").Result;
  1006. response.EnsureSuccessStatusCode();
  1007. datetime = response.Headers.Date?.ToString() ?? DateTime.Now.ToString();
  1008. }
  1009. return Convert.ToDateTime(datetime);
  1010. }
  1011. catch (Exception)
  1012. {
  1013. return DateTime.Now;
  1014. }
  1015. }
  1016. public class TranslateResult
  1017. {
  1018. public string Query { get; set; }
  1019. public string Translation { get; set; }
  1020. public string Type { get; set; }
  1021. public string VerifyResult { get; set; }
  1022. }
  1023. }
  1024. }