AirTicketResRepository.cs 57 KB

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