AirTicketResRepository.cs 57 KB

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