AirTicketResRepository.cs 113 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669
  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. public class AirTicketResRepository : BaseRepository<Grp_AirTicketReservations, Grp_AirTicketReservations>
  15. {
  16. private readonly IMapper _mapper;
  17. private readonly DelegationInfoRepository _groupInfoRep;
  18. private readonly TeamRateRepository _groupRateRep;
  19. public AirTicketResRepository(SqlSugarClient sqlSugar, DelegationInfoRepository groupInfoRep, TeamRateRepository groupRateRep, IMapper mapper) : base(sqlSugar)
  20. {
  21. _mapper = mapper;
  22. _groupInfoRep = groupInfoRep;
  23. _groupRateRep = groupRateRep;
  24. }
  25. #region 旧版
  26. public async Task<Result> AirTicketResById(AirTicketResByIdDto dto)
  27. {
  28. var result = new Result() { Code = -2, Msg = "未知错误" };
  29. try
  30. {
  31. Grp_AirTicketReservations grp_AirTicket = _sqlSugar.Queryable<Grp_AirTicketReservations>().First(a => a.Id == dto.Id && a.IsDel == 0);
  32. if (grp_AirTicket == null)
  33. {
  34. return result = new Result() { Code = -1, Msg = "暂无数据" };
  35. }
  36. else
  37. {
  38. Grp_CreditCardPayment grp_CreditCard = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == grp_AirTicket.Id && a.IsDel == 0 && a.CTable == 85);
  39. if (grp_CreditCard == null) { return result = new Result() { Code = -1, Msg = "暂无数据" }; }
  40. return result = new Result()
  41. {
  42. Code = 0,
  43. Msg = "查询成功!",
  44. Data = new
  45. {
  46. AirTicket = grp_AirTicket,
  47. CreditCard = grp_CreditCard,
  48. }
  49. };
  50. }
  51. }
  52. catch (Exception)
  53. {
  54. return result = new Result() { Code = -2, Msg = "未知错误" };
  55. }
  56. }
  57. public async Task<Result> AirTicketResList(AirTicketResDto dto)
  58. {
  59. var result = new Result() { Code = -2, Msg = "未知错误" };
  60. Grp_DelegationInfo _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().First(it => it.Id == dto.DiId);
  61. if (_DelegationInfo != null)
  62. {
  63. string UserId = "";
  64. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 85).ToList();
  65. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  66. UserId += gta.UId + ",";
  67. if (!string.IsNullOrWhiteSpace(UserId))
  68. {
  69. UserId = UserId[..^1];
  70. }
  71. else
  72. {
  73. UserId = "0";
  74. }
  75. string sqlWhere = "";
  76. if (dto.IsPaySign != -1)
  77. {
  78. sqlWhere += string.Format(@" And ccp.IsPay = {0} ", dto.IsPaySign);
  79. }
  80. string sql = string.Format(@"Select atr.*,ccp.IsAuditGM,sd1.Name As CTypeName,sd2.Name As PreCurrencyStr,sd3.Name As CurrencyStr,ccp.IsPay
  81. From Grp_AirTicketReservations atr
  82. Left Join Grp_CreditCardPayment ccp On atr.Id = ccp.CId And atr.DIId = ccp.DIId And ccp.IsDel = 0
  83. Left Join Sys_SetData sd1 On sd1.Id = atr.ctype
  84. Left Join Sys_SetData sd2 On sd2.Id = atr.PreCurrency
  85. Left Join Sys_SetData sd3 On sd3.Id = atr.Currency
  86. Where atr.IsDel = 0 And atr.DIId={0} {1}
  87. Order By atr.FlightsDate Asc", dto.DiId, sqlWhere);
  88. List<AirTicketReservationsView> _AirTicketReservations = _sqlSugar.SqlQueryable<AirTicketReservationsView>(sql).ToList();
  89. foreach (var item in _AirTicketReservations)
  90. {
  91. if (item.FlightsDescription.Contains("\n"))
  92. {
  93. var spilitArr = Regex.Split(item.FlightsDescription, "\n");
  94. int rowindex = 1;
  95. foreach (var spilitItem in spilitArr)
  96. {
  97. try
  98. {
  99. var spDotandEmpty = spilitItem.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  100. var depCode = spDotandEmpty[3].Substring(0, 3);
  101. var arrCode = spDotandEmpty[3].Substring(3, 3);
  102. Res_ThreeCode depData = _sqlSugar.Queryable<Res_ThreeCode>().First(it => it.IsDel == 0 && it.Three == depCode);
  103. Res_ThreeCode arrData = _sqlSugar.Queryable<Res_ThreeCode>().First(it => it.IsDel == 0 && it.Three == arrCode);
  104. string day = spDotandEmpty[2].Substring(2, 2);//日
  105. string monthAbbreviations = spDotandEmpty[2].Substring(4, 3).ToUpper();//月份
  106. switch (monthAbbreviations)
  107. {
  108. case "JAN":
  109. monthAbbreviations = "1";
  110. break;
  111. case "FEB":
  112. monthAbbreviations = "2";
  113. break;
  114. case "MAR":
  115. monthAbbreviations = "3";
  116. break;
  117. case "APR":
  118. monthAbbreviations = "4";
  119. break;
  120. case "MAY":
  121. monthAbbreviations = "5";
  122. break;
  123. case "JUN":
  124. monthAbbreviations = "6";
  125. break;
  126. case "JUL":
  127. monthAbbreviations = "7";
  128. break;
  129. case "AUG":
  130. monthAbbreviations = "8";
  131. break;
  132. case "SEP":
  133. monthAbbreviations = "9";
  134. break;
  135. case "OCT":
  136. monthAbbreviations = "10";
  137. break;
  138. case "NOV":
  139. monthAbbreviations = "11";
  140. break;
  141. case "DEC":
  142. monthAbbreviations = "12";
  143. break;
  144. }
  145. string tate = $"{monthAbbreviations}月{day}日";
  146. item.FlightDescription += rowindex + ". " + depData.AirPort + " " + arrData.AirPort + " (" + tate + ")\r\n";
  147. }
  148. catch (Exception ex)
  149. {
  150. item.FlightDescription = "录入数据不规范!请检查";
  151. break;
  152. }
  153. rowindex++;
  154. }
  155. }
  156. else
  157. {
  158. try
  159. {
  160. var spDotandEmpty = item.FlightsDescription.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  161. var depCode = spDotandEmpty[3].Substring(0, 3);
  162. var arrCode = spDotandEmpty[3].Substring(3, 3);
  163. Res_ThreeCode depData = _sqlSugar.Queryable<Res_ThreeCode>().First(it => it.IsDel == 0 && it.Three == depCode);
  164. Res_ThreeCode arrData = _sqlSugar.Queryable<Res_ThreeCode>().First(it => it.IsDel == 0 && it.Three == arrCode);
  165. string day = spDotandEmpty[2].Substring(2, 2);//日
  166. string monthAbbreviations = spDotandEmpty[2].Substring(4, 3).ToUpper();//月份
  167. switch (monthAbbreviations)
  168. {
  169. case "JAN":
  170. monthAbbreviations = "1";
  171. break;
  172. case "FEB":
  173. monthAbbreviations = "2";
  174. break;
  175. case "MAR":
  176. monthAbbreviations = "3";
  177. break;
  178. case "APR":
  179. monthAbbreviations = "4";
  180. break;
  181. case "MAY":
  182. monthAbbreviations = "5";
  183. break;
  184. case "JUN":
  185. monthAbbreviations = "6";
  186. break;
  187. case "JUL":
  188. monthAbbreviations = "7";
  189. break;
  190. case "AUG":
  191. monthAbbreviations = "8";
  192. break;
  193. case "SEP":
  194. monthAbbreviations = "9";
  195. break;
  196. case "OCT":
  197. monthAbbreviations = "10";
  198. break;
  199. case "NOV":
  200. monthAbbreviations = "11";
  201. break;
  202. case "DEC":
  203. monthAbbreviations = "12";
  204. break;
  205. }
  206. string tate = $"{monthAbbreviations}月{day}日";
  207. item.FlightDescription += depData.AirPort + " " + arrData.AirPort + " (" + tate + ")\r\n";
  208. }
  209. catch (Exception)
  210. {
  211. item.FlightDescription = "录入数据不规范!请检查";
  212. }
  213. }
  214. }
  215. //团组成本预算表查询
  216. Grp_GroupCostParameter _GroupCostParameter = _sqlSugar.Queryable<Grp_GroupCostParameter>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CostType == "A" && a.IsShare == 1);
  217. AirGroupCostParameterView _AirgroupCostParameter = _mapper.Map<AirGroupCostParameterView>(_GroupCostParameter);
  218. for (int i = 0; i < _AirTicketReservations.Count; i++)
  219. {
  220. string[] ClientArr = _AirTicketReservations[i].ClientName.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  221. foreach (var item in ClientArr)
  222. {
  223. bool isNumeric = int.TryParse(item, out _);
  224. if (isNumeric)
  225. {
  226. if (item == "-1")
  227. {
  228. _AirTicketReservations[i].ClientNameStr += "行程单,";
  229. }
  230. else
  231. {
  232. Crm_DeleClient DeleClient = _sqlSugar.Queryable<Crm_DeleClient>().Where(a => a.IsDel == 0 && a.Id == int.Parse(item)).First();
  233. EncryptionProcessor.DecryptProperties(DeleClient);
  234. _AirTicketReservations[i].ClientNameStr += DeleClient.Pinyin + ',';
  235. }
  236. }
  237. else
  238. {
  239. _AirTicketReservations[i].ClientNameStr += item;
  240. }
  241. }
  242. if (_AirTicketReservations[i].ClientNameStr is not null)
  243. {
  244. _AirTicketReservations[i].ClientNameStr = _AirTicketReservations[i].ClientNameStr.Substring(0, _AirTicketReservations[i].ClientNameStr.Length - 1);
  245. }
  246. }
  247. if (dto.PortType == 1)
  248. {
  249. var data = new
  250. {
  251. DelegationInfo = _DelegationInfo,
  252. AirTicketReservations = _AirTicketReservations,
  253. AirGroupCostParameter = _AirgroupCostParameter
  254. };
  255. return result = new Result() { Code = 0, Msg = "查询成功!", Data = data };
  256. }
  257. else if (dto.PortType == 2 || dto.PortType == 3)
  258. {
  259. int count = _AirTicketReservations.Count;
  260. float totalPage = (float)count / dto.PageSize;//总页数
  261. if (totalPage == 0) totalPage = 1;
  262. else totalPage = (int)Math.Ceiling((double)totalPage);
  263. var grp_AirTickets = new List<AirTicketReservationsView>();
  264. for (int i = 0; i < dto.PageSize; i++)
  265. {
  266. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  267. if (RowIndex < _AirTicketReservations.Count)
  268. {
  269. grp_AirTickets.Add(_AirTicketReservations[RowIndex]);
  270. }
  271. else
  272. {
  273. break;
  274. }
  275. }
  276. var rst = new ListViewBase<AirTicketReservationsView>
  277. {
  278. DataList = grp_AirTickets,
  279. DataCount = count,
  280. CurrPageIndex = dto.PageIndex,
  281. CurrPageSize = dto.PageSize
  282. };
  283. var data = new
  284. {
  285. AirData = rst,
  286. AirGroupCostParameter = _AirgroupCostParameter
  287. };
  288. return new Result() { Code = 0, Msg = "查询成功!", Data = data };
  289. }
  290. else
  291. {
  292. return new Result() { Code = -1, Msg = "请传入PortType参数!1:Web,2:Android,3:IOS!" };
  293. }
  294. }
  295. else
  296. {
  297. return new Result() { Code = -1, Msg = "暂无团组数据!" };
  298. }
  299. }
  300. public async Task<Result> AirTicketResSelect(AirTicketResDto dto)
  301. {
  302. var result = new Result() { Code = -2, Msg = "未知错误" };
  303. try
  304. {
  305. if (dto.DiId < 1)
  306. {
  307. dto.DiId = -1;
  308. }
  309. #region 团组下拉框
  310. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == 85).ToList();
  311. var grp_NameView = new List<dynamic>();
  312. string DiId = "";
  313. foreach (var item in grp_GroupsTaskAssignment)
  314. {
  315. DiId += item.DIId + ",";
  316. }
  317. if (DiId.Length > 1)
  318. {
  319. DiId = DiId.Substring(0, DiId.Length - 1);
  320. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1} Order By VisitStartDate Desc", DiId, 0);
  321. List<Grp_DelegationInfo> grp_Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  322. if (grp_Delegations.Count == 0)
  323. {
  324. return result = new Result() { Code = -1, Msg = "查询失败!" };
  325. }
  326. foreach (var item in grp_Delegations)
  327. {
  328. var groupNameView = new
  329. {
  330. item.Id,
  331. item.TeamName
  332. };
  333. grp_NameView.Add(groupNameView);
  334. }
  335. }
  336. #endregion
  337. #region 其他下拉框查询
  338. //舱位类型
  339. List<Sys_SetData> TicketClass = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 44 && a.IsDel == 0).ToList();
  340. List<SetDataInfoView> _TicketClassa = _mapper.Map<List<SetDataInfoView>>(TicketClass);
  341. //支付方式
  342. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  343. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  344. //卡类型
  345. List<Sys_SetData> CardType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
  346. List<SetDataInfoView> _CardType = _mapper.Map<List<SetDataInfoView>>(CardType);
  347. //合作方资料
  348. List<Res_AirTicketAgent> _AirTicketAgents = _sqlSugar.Queryable<Res_AirTicketAgent>().Where(a => a.IsDel == 0).ToList();
  349. foreach (var item in _AirTicketAgents)
  350. {
  351. EncryptionProcessor.DecryptProperties(item);
  352. }
  353. #endregion
  354. #region 客人名单下拉框
  355. if (dto.DiId == -1)
  356. {
  357. var dele = _AirTicketAgents.FirstOrDefault();
  358. dto.DiId = dele != null ? dele.Id : dto.DiId;
  359. }
  360. 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);
  361. var clientArr = _sqlSugar.SqlQueryable<SimplClientInfo>(sqlClient).ToList();
  362. foreach (var item in clientArr) { EncryptionProcessor.DecryptProperties(item); }
  363. #endregion
  364. var data = new
  365. {
  366. TicketClass = _TicketClassa,
  367. Payment = _Payment,
  368. CardType = _CardType,
  369. GroupName = grp_NameView,
  370. AirTicketAgents = _AirTicketAgents,
  371. clientArr
  372. };
  373. return result = new Result() { Code = 0, Msg = "查询成功!", Data = data };
  374. }
  375. catch (Exception ex)
  376. {
  377. return result = new Result() { Code = -2, Msg = "程序错误" };
  378. }
  379. }
  380. public async Task<Result> OpAirTicketRes(AirTicketResOpDto dto, Func<int, int, int, Task<Result>> fn)
  381. {
  382. var result = new Result() { Code = -2, Msg = "未知错误" };
  383. try
  384. {
  385. BeginTran();
  386. int id = 0;
  387. var grp_AirTicket = _mapper.Map<Grp_AirTicketReservations>(dto.AirTicketResOpData);
  388. var clientName = string.Join(",", dto.AirTicketResOpData.ClientName);
  389. if (dto.Status == 1)
  390. {
  391. grp_AirTicket.FlightsDate = DateTime.Parse(grp_AirTicket.FlightsDate).ToString("yyyy-MM-dd");
  392. grp_AirTicket.ClientName = clientName;
  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. // 2025-04-07 第四次更改 PayDId == 72(刷卡) IsPay == 1
  407. if (grp_CreditCard.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, dataId = grp_CreditCard.CId };
  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 = 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. //2025-04-07 第四次更改 PayDId == 72(刷卡) 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, dataId = grp_CreditCard.CId };
  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. var result = new Result() { Code = -2, Msg = "未知错误" };
  801. try
  802. {
  803. string sql = string.Format(@"Select atr.*,ccp.Payee,ccp.BankNo, sd4.Name as PayType ,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. left join Sys_SetData sd4 On sd4.Id = ccp.PayDId
  810. Where atr.IsDel = 0 And atr.DIId={0}
  811. Order By atr.FlightsDate Asc", dto.DiId);
  812. List<AirTicketReservationsPayView> _AirTicketReservations = _sqlSugar.SqlQueryable<AirTicketReservationsPayView>(sql).ToList();
  813. if (_AirTicketReservations.Count != 0)
  814. {
  815. Grp_DelegationInfo grp_Delegation = _sqlSugar.Queryable<Grp_DelegationInfo>().First(a => a.Id == dto.DiId && a.IsDel == 0);
  816. Sys_Users _Users = _sqlSugar.Queryable<Sys_Users>().First(a => a.Id == dto.UserId && a.IsDel == 0);
  817. return result = new Result() { Code = 0, Msg = "成功", Data = new { Delegation = grp_Delegation, AirTicketRes = _AirTicketReservations, Users = _Users } };
  818. }
  819. else
  820. {
  821. return result = new Result() { Code = -1, Msg = "暂无数据", Data = null };
  822. }
  823. }
  824. catch (Exception)
  825. {
  826. return result = new Result() { Code = -2, Msg = "未知错误" };
  827. }
  828. }
  829. public async Task<Result> ItineraryAirTicketRes(ItineraryAirTicketResDto dto)
  830. {
  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 new Result() { Code = -1, Msg = "暂无数据", Data = null };
  841. }
  842. else
  843. {
  844. return new Result() { Code = 0, Msg = "查询成功", Data = _AirTicketReservations };
  845. }
  846. }
  847. catch (Exception)
  848. {
  849. return new Result() { Code = -2, Msg = "未知错误" };
  850. }
  851. }
  852. public async Task<List<TranslateResult>> ReTransBatch(List<string> list, string aimlanguage)
  853. {
  854. var reultStr = new List<TranslateResult>();
  855. if (list.Count < 0)
  856. {
  857. return reultStr;
  858. }
  859. //待翻译内容,必须是UTF-8编码
  860. string q = "";
  861. string Qtext = "";
  862. foreach (var item in list)
  863. {
  864. q += item;
  865. Qtext += "q=" + item + "&";
  866. }
  867. if (Qtext.Length > 0)
  868. {
  869. Qtext = Qtext[..^1];
  870. }
  871. var dic = new Dictionary<string, string>();
  872. string url = "https://openapi.youdao.com/v2/api";
  873. //应用ID
  874. string appKey = "0fe3bc01e109ed36";
  875. //应用应用密钥
  876. string appSecret = "1f2x9TrqJfSBEJ8iH9GEFGgTyaYGjEry";
  877. //UUID
  878. string salt = DateTime.Now.Millisecond.ToString();
  879. //源语言
  880. dic.Add("from", "zh-CHS");
  881. //目标语言
  882. dic.Add("to", aimlanguage);
  883. //签名类型
  884. dic.Add("signType", "v3");
  885. //时间戳
  886. string curtime = ((GetBeijingTime().ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString();
  887. dic.Add("curtime", curtime);
  888. string signStr = appKey + Truncate(q) + salt + curtime + appSecret; ;
  889. string sign = ComputeHash(signStr, SHA256.Create());
  890. dic.Add("q", Qtext);
  891. dic.Add("appKey", appKey);
  892. dic.Add("salt", salt);
  893. dic.Add("sign", sign);
  894. try
  895. {
  896. //Thread.Sleep(500);
  897. string jsonStr = await TransSync(url, dic);
  898. JObject trans = (JObject)JsonConvert.DeserializeObject(jsonStr);
  899. string errorCode = trans["errorCode"].ToString();
  900. if (errorCode == "0")
  901. {
  902. reultStr = JsonConvert.DeserializeObject<List<TranslateResult>>(trans["translateResults"].ToString());
  903. }
  904. return reultStr;
  905. }
  906. catch (Exception)
  907. {
  908. return reultStr;
  909. }
  910. }
  911. public string Processing(string str)//处理这段英文的方法
  912. {
  913. if (string.IsNullOrEmpty(str)) { return ""; }
  914. string[] strArray;
  915. if (str.Contains(" ")) strArray = str.Split(" ".ToCharArray());
  916. else if (str.Contains(",")) strArray = str.Split(",".ToCharArray());
  917. else if (str.Contains(" ") && str.Contains(",")) strArray = str.Split(",".ToCharArray());
  918. else strArray = new string[] { str };
  919. string result = string.Empty;//定义一个空字符串
  920. foreach (string s in strArray)//循环处理数组里面每一个字符串
  921. {
  922. //result += System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(s) + " ";
  923. result += string.Concat(s[..1].ToUpper(), s.AsSpan(1), " ");
  924. //.Substring(0, 1).ToUpper()把循环到的字符串第一个字母截取并转换为大写,并用s.Substring(1)得到循环到的字符串除第一个字符后的所有字符拼装到首字母后面。
  925. }
  926. return result;
  927. }
  928. protected static async Task<string> TransSync(string url, Dictionary<string, string> dic)
  929. {
  930. string result = "";
  931. using (var client = new HttpClient())
  932. {
  933. var content = new FormUrlEncodedContent(dic);
  934. HttpResponseMessage response = await client.PostAsync(url, content);
  935. response.EnsureSuccessStatusCode();
  936. if (response.Content.Headers.ContentType.MediaType.ToLower().Equals("audio/mp3"))
  937. {
  938. await SaveBinaryFile(response, "合成的音频存储路径");
  939. }
  940. else
  941. {
  942. result = await response.Content.ReadAsStringAsync();
  943. }
  944. }
  945. return result;
  946. }
  947. private static async Task<bool> SaveBinaryFile(HttpResponseMessage response, string FileName)
  948. {
  949. string FilePath = FileName + DateTime.Now.Millisecond.ToString() + ".mp3";
  950. bool Value = true;
  951. byte[] buffer = new byte[1024];
  952. try
  953. {
  954. if (File.Exists(FilePath))
  955. File.Delete(FilePath);
  956. using Stream outStream = File.Create(FilePath);
  957. using Stream inStream = await response.Content.ReadAsStreamAsync();
  958. int l;
  959. do
  960. {
  961. l = await inStream.ReadAsync(buffer);
  962. if (l > 0)
  963. await outStream.WriteAsync(buffer.AsMemory(0, l));
  964. }
  965. while (l > 0);
  966. }
  967. catch
  968. {
  969. Value = false;
  970. }
  971. return Value;
  972. }
  973. protected static string ComputeHash(string input, HashAlgorithm algorithm)
  974. {
  975. byte[] inputBytes = Encoding.UTF8.GetBytes(input);
  976. byte[] hashedBytes = algorithm.ComputeHash(inputBytes);
  977. return BitConverter.ToString(hashedBytes).Replace("-", "");
  978. }
  979. protected static string Truncate(string q)
  980. {
  981. if (q == null)
  982. {
  983. return null;
  984. }
  985. int len = q.Length;
  986. return len <= 20 ? q : q.Substring(0, 10) + len + q.Substring(len - 10, 10);
  987. }
  988. public static DateTime GetBeijingTime()
  989. {
  990. string datetime = string.Empty;
  991. try
  992. {
  993. using (var client = new HttpClient())
  994. {
  995. client.Timeout = TimeSpan.FromSeconds(3);
  996. HttpResponseMessage response = client.GetAsync("https://www.baidu.com").Result;
  997. response.EnsureSuccessStatusCode();
  998. datetime = response.Headers.Date?.ToString() ?? DateTime.Now.ToString();
  999. }
  1000. return Convert.ToDateTime(datetime);
  1001. }
  1002. catch (Exception)
  1003. {
  1004. return DateTime.Now;
  1005. }
  1006. }
  1007. public class TranslateResult
  1008. {
  1009. public string Query { get; set; }
  1010. public string Translation { get; set; }
  1011. public string Type { get; set; }
  1012. public string VerifyResult { get; set; }
  1013. }
  1014. #endregion
  1015. #region 2026版
  1016. /// <summary>
  1017. /// list 2026版
  1018. /// </summary>
  1019. /// <param name="dto">查询参数</param>
  1020. /// <returns>机票费用列表</returns>
  1021. public async Task<JsonView> ListAsync(AirTicketFeeListDto dto)
  1022. {
  1023. // 1. 参数校验
  1024. if (!SharingStaticData.PortTypes.Contains(dto.PortType))
  1025. return JsonView.Fail(MsgTips.Port);
  1026. if (dto.DiId <= 0)
  1027. return JsonView.Fail("团组ID无效");
  1028. // 2. 获取团组信息
  1029. var groupInfo = await _groupInfoRep.GetGroupAirInfo(dto.DiId);
  1030. if (groupInfo == null)
  1031. return JsonView.Fail("暂无团组数据!");
  1032. // 3. 查询机票费用列表
  1033. var airTicketFeeList = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  1034. .InnerJoin<Grp_CreditCardPayment>((x, y) => x.Id == y.CId && x.DIId == y.DIId)
  1035. .LeftJoin<Sys_SetData>((x, y, z) => x.CType == z.Id)
  1036. .LeftJoin<Sys_SetData>((x, y, z, z1) => x.Currency == z1.Id)
  1037. .LeftJoin<Sys_Users>((x, y, z, z1, u) => x.CreateUserId == u.Id)
  1038. .Where((x, y, z, z1, u) => x.IsDel == 0 && y.IsDel == 0 && x.DIId == dto.DiId)
  1039. .WhereIF(dto.IsPaySign != -1, (x, y, z, z1, u) => y.IsPay == dto.IsPaySign)
  1040. .Select((x, y, z, z1, u) => new AirTicketFeeListView()
  1041. {
  1042. Id = x.Id,
  1043. No = x.RecordType,
  1044. CabinName = z.Name,
  1045. FlightDesc = x.FlightsDescription,
  1046. ClientNameList = x.ClientName,
  1047. ClientCount = x.ClientNum,
  1048. TotalTicketPrice = x.Price,
  1049. Currency = z1.Name,
  1050. AuditStatus = y.IsAuditGM.ToString(),
  1051. Remark = y.Remark,
  1052. Applicant = u.CnName,
  1053. ApplyTime = x.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
  1054. })
  1055. .ToListAsync();
  1056. // 4. 获取黑屏代码(三字码映射)
  1057. var threeCodeList = await _sqlSugar.Queryable<Res_ThreeCode>()
  1058. .Where(x => x.IsDel == 0)
  1059. .Select(x => new { x.Three, x.AirPort })
  1060. .ToListAsync();
  1061. // 保留第一个遇到的
  1062. var threeCodes = threeCodeList
  1063. .GroupBy(x => x.Three)
  1064. .ToDictionary(g => g.Key, g => g.First().AirPort);
  1065. // 5. 获取团组成本预算
  1066. var groupCostParameter = await _sqlSugar.Queryable<Grp_GroupCostParameter>()
  1067. .FirstAsync(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CostType == "A" && a.IsShare == 1);
  1068. var airgroupCostParameter = _mapper.Map<AirGroupCostParameterView>(groupCostParameter);
  1069. // 6. 获取客户信息映射
  1070. var groupClientIds = await _sqlSugar.Queryable<Grp_TourClientList>()
  1071. .Where(a => a.DiId == dto.DiId && a.IsDel == 0)
  1072. .Select(x => x.ClientId)
  1073. .ToListAsync();
  1074. var clientInfoMap = new Dictionary<int, (string FirstName, string LastName, string Pinyin)>();
  1075. if (groupClientIds.Any())
  1076. {
  1077. var encryptedClients = await _sqlSugar.Queryable<Crm_DeleClient>()
  1078. .Where(a => a.IsDel == 0 && groupClientIds.Contains(a.Id))
  1079. .Select(x => new { x.Id, x.FirstName, x.LastName, x.Pinyin })
  1080. .ToListAsync();
  1081. foreach (var client in encryptedClients)
  1082. {
  1083. clientInfoMap[client.Id] = (
  1084. AesEncryptionHelper.Decrypt(client.FirstName),
  1085. AesEncryptionHelper.Decrypt(client.LastName),
  1086. AesEncryptionHelper.Decrypt(client.Pinyin)
  1087. );
  1088. }
  1089. }
  1090. // 7. 处理航班描述和客户名称
  1091. foreach (var item in airTicketFeeList)
  1092. {
  1093. // 退票退票标识
  1094. if (item.No == 1)
  1095. {
  1096. item.CabinName += "(退票)";
  1097. }
  1098. // 7.1 处理航班描述
  1099. if (!string.IsNullOrWhiteSpace(item.FlightDesc))
  1100. {
  1101. var flightInfos = FlightParser.ParseFlights(item.FlightDesc);
  1102. var flightDescBuilder = new StringBuilder();
  1103. foreach (var flightInfo in flightInfos)
  1104. {
  1105. string departAirport = threeCodes.ContainsKey(flightInfo.DepartureAirport)
  1106. ? threeCodes[flightInfo.DepartureAirport]?.ToString() ?? flightInfo.DepartureAirport
  1107. : flightInfo.DepartureAirport;
  1108. string arrivalAirport = threeCodes.ContainsKey(flightInfo.ArrivalAirport)
  1109. ? threeCodes[flightInfo.ArrivalAirport]?.ToString() ?? flightInfo.ArrivalAirport
  1110. : flightInfo.ArrivalAirport;
  1111. string desc = $"{flightInfo.SequenceNo}.{departAirport} → {arrivalAirport}({flightInfo.DepartureDate:yyyy-MM-dd})";
  1112. flightDescBuilder.AppendLine(desc);
  1113. }
  1114. item.FlightDesc = flightDescBuilder.ToString().TrimEnd();
  1115. }
  1116. else item.FlightDesc = "录入数据不规范!请检查";
  1117. // 7.2 处理客户名称
  1118. if (!string.IsNullOrWhiteSpace(item.ClientNameList))
  1119. {
  1120. var clientArr = item.ClientNameList.Split(',')
  1121. .Where(x => !string.IsNullOrWhiteSpace(x))
  1122. .ToArray();
  1123. var clientNames = new List<string>();
  1124. foreach (var clientItem in clientArr)
  1125. {
  1126. if (int.TryParse(clientItem, out int clientId))
  1127. {
  1128. if (clientId == -1)
  1129. {
  1130. clientNames.Add("行程单");
  1131. }
  1132. else if (clientInfoMap.TryGetValue(clientId, out var clientInfo))
  1133. {
  1134. clientNames.Add(clientInfo.Pinyin);
  1135. }
  1136. }
  1137. else
  1138. {
  1139. clientNames.Add(clientItem);
  1140. }
  1141. }
  1142. item.ClientNameList = clientNames.Any() ? string.Join(",", clientNames) : string.Empty;
  1143. }
  1144. }
  1145. // 8. 根据端口类型返回数据
  1146. if (dto.PortType == 1)
  1147. {
  1148. var data = new
  1149. {
  1150. DelegationInfo = groupInfo,
  1151. AirTicketReservations = airTicketFeeList,
  1152. AirGroupCostParameter = airgroupCostParameter
  1153. };
  1154. return JsonView.Success(data);
  1155. }
  1156. else if (dto.PortType == 2 || dto.PortType == 3)
  1157. {
  1158. int totalCount = airTicketFeeList.Count;
  1159. int totalPages = (int)Math.Ceiling((double)totalCount / dto.PageSize);
  1160. if (totalPages == 0) totalPages = 1;
  1161. // 分页数据
  1162. var pagedData = airTicketFeeList
  1163. .Skip((dto.PageIndex - 1) * dto.PageSize)
  1164. .Take(dto.PageSize)
  1165. .ToList();
  1166. var rst = new ListViewBase<AirTicketFeeListView>
  1167. {
  1168. DataList = pagedData,
  1169. DataCount = totalCount,
  1170. CurrPageIndex = dto.PageIndex,
  1171. CurrPageSize = dto.PageSize
  1172. };
  1173. var data = new
  1174. {
  1175. AirData = rst,
  1176. AirGroupCostParameter = airgroupCostParameter
  1177. };
  1178. return JsonView.Success(data);
  1179. }
  1180. return JsonView.Fail("暂无团组数据!");
  1181. }
  1182. /// <summary>
  1183. /// 机票费用基础数据 2026版
  1184. /// </summary>
  1185. /// <returns></returns>
  1186. public async Task<JsonView> BasicDataAsync(int userId)
  1187. {
  1188. var setDatas = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.IsDel == 0).ToList();
  1189. // 附加服务类型
  1190. var additionalServiceTypes = setDatas
  1191. .Where(a => a.STid == 139 && a.IsDel == 0)
  1192. .Select(a => _mapper.Map<SetDataInfoView>(a))
  1193. .OrderBy(x => x.RemarkSort)
  1194. .ToList();
  1195. // 舱位类型
  1196. var ticketClass = setDatas
  1197. .Where(a => a.STid == 44 && a.IsDel == 0)
  1198. .Select(a => _mapper.Map<SetDataInfoView>(a))
  1199. .ToList();
  1200. // 支付方式
  1201. var payments = setDatas
  1202. .Where(a => a.STid == 14 && a.IsDel == 0)
  1203. .Select(a => _mapper.Map<SetDataInfoView>(a))
  1204. .ToList();
  1205. // 卡类型
  1206. var cardTypes = setDatas
  1207. .Where(a => a.STid == 15 && a.IsDel == 0)
  1208. .Select(a => _mapper.Map<SetDataInfoView>(a))
  1209. .ToList();
  1210. // 合作方资料
  1211. var airTicketAgents = _sqlSugar.Queryable<Res_AirTicketAgent>().Where(a => a.IsDel == 0).ToList();
  1212. foreach (var item in airTicketAgents)
  1213. {
  1214. EncryptionProcessor.DecryptProperties(item);
  1215. }
  1216. var airTicketAgentsView = airTicketAgents.Select(x => new
  1217. {
  1218. x.Id,
  1219. x.Name,
  1220. x.Account,
  1221. x.Bank
  1222. }).ToList();
  1223. #region 团组下拉框
  1224. var permGroupIds = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == userId && a.CTId == 85).Select(a => a.DIId).ToList();
  1225. var teamNames = _sqlSugar.Queryable<Grp_DelegationInfo>()
  1226. .Where(x => x.IsDel == 0 && permGroupIds.Contains(x.Id))
  1227. .OrderByDescending(x => x.VisitDate)
  1228. .Select(x => new
  1229. {
  1230. x.Id,
  1231. x.TeamName
  1232. })
  1233. .ToList();
  1234. #endregion
  1235. // 获取第一个团组的基本信息
  1236. var firstGroupInfo = await _groupInfoRep.GetGroupAirInfo(teamNames.FirstOrDefault()?.Id ?? 0);
  1237. return JsonView.Success(new
  1238. {
  1239. additionalServiceTypes,
  1240. ticketClass,
  1241. payment = payments,
  1242. cardType = cardTypes,
  1243. airTicketAgents = airTicketAgentsView,
  1244. firstGroupInfo,
  1245. groupName = teamNames
  1246. });
  1247. }
  1248. /// <summary>
  1249. /// 详情 2026版
  1250. /// </summary>
  1251. /// <returns></returns>
  1252. public async Task<JsonView> InfoAsync(int userId, int groupId)
  1253. {
  1254. var view = new AirTicketFeeInfoView()
  1255. {
  1256. CurrUserId = userId,
  1257. GroupAirInfo = new GroupAirTicketInfo(),
  1258. AirTicketFeeInfos = new List<AirTicketFeeInfo>()
  1259. };
  1260. if (userId < 1) return JsonView.Fail<AirTicketFeeInfoView>("用户ID无效");
  1261. if (groupId < 1) return JsonView.Fail<AirTicketFeeInfoView>("团组ID无效");
  1262. var groupVaild = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == userId && a.CTId == 85 && a.DIId == groupId).Any();
  1263. if (!groupVaild) return JsonView.Fail<AirTicketFeeInfoView>("没有查看权限");
  1264. // 获取第一个团组的基本信息
  1265. var firstGroupInfo = await _groupInfoRep.GetGroupAirInfo(groupId);
  1266. if (firstGroupInfo == null)
  1267. return JsonView.Fail<AirTicketFeeInfoView>("团组信息不存在");
  1268. // 团组公共信息
  1269. var groupInfo = _mapper.Map<GroupAirTicketInfo>(firstGroupInfo);
  1270. // 机票信息集合
  1271. var airTicketFeeInfos = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  1272. .InnerJoin<Grp_CreditCardPayment>((x, y) => x.Id == y.CId && x.DIId == y.DIId && y.CTable == 85)
  1273. .Where((x, y) => x.IsDel == 0 && y.IsDel == 0 && x.DIId == groupId && x.RecordType == 0)
  1274. .Select((x, y) => new AirTicketFeeInfo
  1275. {
  1276. // 机票信息
  1277. Id = x.Id,
  1278. FlightsDescription = x.FlightsDescription,
  1279. AirTicketBasicInfos = x.AirTicketBasicInfos,
  1280. ClientName = x.ClientName,
  1281. CustTicketInfos = x.CustTicketInfos,
  1282. PriceDescription = x.PriceDescription,
  1283. // 支付信息
  1284. PayDId = y.PayDId,
  1285. ConsumptionPatterns = y.ConsumptionPatterns,
  1286. ConsumptionDate = y.ConsumptionDate,
  1287. PayMoney = y.PayMoney,
  1288. PaymentCurrency = y.PaymentCurrency,
  1289. CTDId = y.CTDId,
  1290. BankNo = y.BankNo,
  1291. CardholderName = y.CardholderName,
  1292. DayRate = y.DayRate,
  1293. CompanyBankNo = y.CompanyBankNo,
  1294. OtherSideNo = y.OtherSideNo,
  1295. OtherSideName = y.OtherSideName,
  1296. Payee = y.Payee,
  1297. OrbitalPrivateTransfer = y.OrbitalPrivateTransfer,
  1298. Remark = y.Remark,
  1299. IsAuditGM = y.IsAuditGM,
  1300. AuditGMOperate = y.AuditGMOperate,
  1301. AuditGMDate = y.AuditGMDate
  1302. })
  1303. .ToListAsync();
  1304. // 如果没有数据,返回空结果
  1305. if (!airTicketFeeInfos.Any())
  1306. {
  1307. groupInfo.FlightsDescription = string.Empty;
  1308. return JsonView.Success(new AirTicketFeeInfoView()
  1309. {
  1310. CurrUserId = userId,
  1311. GroupAirInfo = groupInfo,
  1312. AirTicketFeeInfos = new List<AirTicketFeeInfo>()
  1313. });
  1314. }
  1315. // 航班舱位类型
  1316. var cabinTypes = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 44).ToListAsync();
  1317. // 分组统计一个航班行程的信息
  1318. var groupedByFlights = airTicketFeeInfos
  1319. .GroupBy(x => x.FlightsDescription)
  1320. .Select(g =>
  1321. {
  1322. var first = g.First();
  1323. // 合并客户名称(去重)
  1324. var clientNames = string.Join(",", g.Select(x => x.ClientName).ToList());
  1325. var clientNameIds = ParseToIntListSafe(clientNames);
  1326. // 处理审核状态
  1327. var auditsStr = new StringBuilder();
  1328. foreach (var item in g)
  1329. {
  1330. var auditStatus = item.IsAuditGM switch
  1331. {
  1332. 0 => "未审核",
  1333. 1 => "审核通过",
  1334. 2 => "审核驳回",
  1335. 3 => "自动审核",
  1336. _ => "未知状态"
  1337. };
  1338. var cabinTypeName = cabinTypes.FirstOrDefault(c => c.Id == item.CustTicketInfos.FirstOrDefault()?.CType)?.Name ?? "未知舱位";
  1339. auditsStr.Append($"{cabinTypeName}:{auditStatus};");
  1340. }
  1341. // 合并所有客户的机票信息
  1342. var custTicketInfos = g.SelectMany(x => x.CustTicketInfos ?? new List<CustTicketInfo>()).ToList();
  1343. // 累计退票金额
  1344. decimal refundAmount = custTicketInfos.Where(x => x.IsRefund).Sum(x => (x.RefundRecord?.RefundAmount ?? 0m) + (x.RefundRecord?.NonRefundableTax ?? 0m));
  1345. // 付款金额
  1346. decimal payMoney = g.Sum(x => x.PayMoney) + refundAmount;
  1347. // 处理多舱位审核描述
  1348. var newFlight = new AirTicketFeeInfo
  1349. {
  1350. Id = first.Id,
  1351. FlightsDescription = g.Key,
  1352. AirTicketBasicInfos = g.FirstOrDefault()?.AirTicketBasicInfos ?? new List<AirTicketBasicInfo>(),
  1353. // 合并客户人员
  1354. ClientName = clientNames,
  1355. ClientNameIds = clientNameIds,
  1356. // 合并所有客户的机票信息
  1357. CustTicketInfos = custTicketInfos,
  1358. PriceDescription = first.PriceDescription,
  1359. // 付款信息
  1360. PayDId = first.PayDId,
  1361. ConsumptionPatterns = first.ConsumptionPatterns,
  1362. ConsumptionDate = first.ConsumptionDate,
  1363. PayMoney = payMoney,
  1364. PaymentCurrency = first.PaymentCurrency,
  1365. CTDId = first.CTDId,
  1366. BankNo = first.BankNo,
  1367. CardholderName = first.CardholderName,
  1368. DayRate = first.DayRate,
  1369. CompanyBankNo = first.CompanyBankNo,
  1370. OtherSideNo = first.OtherSideNo,
  1371. OtherSideName = first.OtherSideName,
  1372. Payee = first.Payee,
  1373. OrbitalPrivateTransfer = first.OrbitalPrivateTransfer,
  1374. Remark = first.Remark,
  1375. IsAuditGM = first.IsAuditGM,
  1376. AuditGMOperate = first.AuditGMOperate,
  1377. AuditGMDate = first.AuditGMDate,
  1378. AuditStr = auditsStr.ToString().Trim()
  1379. };
  1380. return newFlight;
  1381. })
  1382. .ToList();
  1383. // 按序号排序
  1384. groupedByFlights = groupedByFlights
  1385. .OrderBy(x => ExtractSequenceNo(x.FlightsDescription))
  1386. .ToList();
  1387. // 提取完整的航班行程信息
  1388. var flightsDescAll = new StringBuilder();
  1389. foreach (var item in groupedByFlights)
  1390. {
  1391. flightsDescAll.Append(item.FlightsDescription);
  1392. }
  1393. groupInfo.FlightsDescription = flightsDescAll.ToString();
  1394. return JsonView.Success(new AirTicketFeeInfoView()
  1395. {
  1396. CurrUserId = userId,
  1397. GroupAirInfo = groupInfo,
  1398. AirTicketFeeInfos = groupedByFlights
  1399. });
  1400. }
  1401. #region info 辅助方法
  1402. /// <summary>
  1403. /// 将逗号分隔的字符串解析为 List<int>(带错误处理)
  1404. /// </summary>
  1405. public static List<int> ParseToIntListSafe(string input)
  1406. {
  1407. if (string.IsNullOrWhiteSpace(input))
  1408. return new List<int>();
  1409. var result = new List<int>();
  1410. var parts = input.Split(',');
  1411. foreach (var part in parts)
  1412. {
  1413. if (int.TryParse(part.Trim(), out int value))
  1414. {
  1415. result.Add(value);
  1416. }
  1417. // 可选:记录解析失败的值
  1418. }
  1419. return result;
  1420. }
  1421. /// <summary>
  1422. /// 提取序号辅助方法
  1423. /// </summary>
  1424. private static int ExtractSequenceNo(string flightsDescription)
  1425. {
  1426. if (string.IsNullOrWhiteSpace(flightsDescription))
  1427. return int.MaxValue;
  1428. var match = Regex.Match(flightsDescription, @"^(\d+)\.");
  1429. return match.Success ? int.Parse(match.Groups[1].Value) : int.MaxValue;
  1430. }
  1431. /// <summary>
  1432. /// 获取测试数据
  1433. /// </summary>
  1434. private static List<CustTicketInfo> GetTestCustomerData()
  1435. {
  1436. var testData = new CustTicketInfo()
  1437. {
  1438. ClientId = 1081,
  1439. CType = 460,
  1440. ActualPrice = 1000,
  1441. TicketCode = "9991234567890",
  1442. TicketNumber = "ABC123",
  1443. SelectedServiceIds = new List<int> { 1561, 1563 },
  1444. AdditionalServices = new List<AdditionalService>()
  1445. {
  1446. new AdditionalService() { ServiceTypeId = 1561, Amount = 100 },
  1447. new AdditionalService() { ServiceTypeId = 1563, Amount = 50 }
  1448. },
  1449. TotalTicketPrice = 1150,
  1450. IsRefund = true,
  1451. RefundRecord = new RefundRecord()
  1452. {
  1453. RefundAmount = -200,
  1454. NonRefundableTax = -100,
  1455. RefundReason = "航班取消",
  1456. RefundTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  1457. RefundAccount = 0,
  1458. }
  1459. };
  1460. return new List<CustTicketInfo>
  1461. {
  1462. testData,
  1463. new CustTicketInfo
  1464. {
  1465. ClientId = 1720,
  1466. CType = 460,
  1467. ActualPrice = 1000,
  1468. TicketCode = "9991234567890",
  1469. TicketNumber = "ABC123"
  1470. },
  1471. new CustTicketInfo
  1472. {
  1473. ClientId = 163,
  1474. CType = 460,
  1475. ActualPrice = 1000,
  1476. TicketCode = "9991234567890",
  1477. TicketNumber = "ABC123"
  1478. }
  1479. };
  1480. }
  1481. #endregion
  1482. /// <summary>
  1483. /// 保存 2026版
  1484. /// </summary>
  1485. /// <returns></returns>
  1486. /// <summary>
  1487. /// 保存 2026版(无ID,通过业务字段定位)
  1488. /// </summary>
  1489. public async Task<JsonView<AppPushBodyView>> SaveAsync(AirTicketFeeSaveDto dto)
  1490. {
  1491. // 1. 基础字段设置
  1492. var currUserId = dto.CurrUserId;
  1493. var groupId = dto.GroupAirInfo?.Id ?? 0;
  1494. var appPushBodyInfos = new List<AppPushBodyInfo>();
  1495. var index = 1;
  1496. // 2. 整理数据
  1497. var airFeeRecords = await OrganizeAirTicketDataAsync(dto.AirTicketFeeInfos, groupId);
  1498. if (airFeeRecords == null || !airFeeRecords.Any())
  1499. {
  1500. return JsonView<AppPushBodyView>.Success("没有需要保存的数据");
  1501. }
  1502. // 3. 开启事务
  1503. BeginTran();
  1504. try
  1505. {
  1506. foreach (var airInfo in airFeeRecords)
  1507. {
  1508. var airFeeInfo = _mapper.Map<Grp_AirTicketReservations>(airInfo);
  1509. var cardPaymentInfo = _mapper.Map<Grp_CreditCardPayment>(airInfo);
  1510. // 设置公共字段
  1511. airFeeInfo.CreateUserId = currUserId;
  1512. airFeeInfo.IsDel = 0;
  1513. cardPaymentInfo.DIId = groupId;
  1514. cardPaymentInfo.CTable = 85;
  1515. cardPaymentInfo.AuditGMDate = string.Empty;
  1516. cardPaymentInfo.UpdateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1517. cardPaymentInfo.IsPay = cardPaymentInfo.PayDId == 72 ? 1 : 0;
  1518. cardPaymentInfo.PayThenMoney = cardPaymentInfo.PayMoney;
  1519. cardPaymentInfo.RMBPrice = cardPaymentInfo.PayMoney * cardPaymentInfo.DayRate;
  1520. cardPaymentInfo.CreateUserId = currUserId;
  1521. cardPaymentInfo.IsDel = 0;
  1522. // ========== 通过业务字段查找现有记录 ==========
  1523. var existingAir = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  1524. .FirstAsync(x => x.DIId == groupId
  1525. && x.FlightsDescription == airFeeInfo.FlightsDescription
  1526. && x.CType == airFeeInfo.CType
  1527. && x.RecordType == airFeeInfo.RecordType
  1528. && x.IsDel == 0);
  1529. int airId = 0;
  1530. int cardId = 0;
  1531. if (existingAir == null)
  1532. {
  1533. // ========== 新增 ==========
  1534. var (Success, ErrorMessage, AirId, CardId) = await InsertNewRecord(airFeeInfo, cardPaymentInfo, index);
  1535. if (!Success)
  1536. {
  1537. RollbackTran();
  1538. return JsonView<AppPushBodyView>.Fail(ErrorMessage);
  1539. }
  1540. airId = AirId;
  1541. cardId = CardId;
  1542. appPushBodyInfos.Add(new AppPushBodyInfo()
  1543. {
  1544. OperationType = 1,
  1545. AirTicketId = airId,
  1546. CardId = cardId,
  1547. CardCNYAmount = cardPaymentInfo.RMBPrice
  1548. });
  1549. }
  1550. else
  1551. {
  1552. // ========== 修改 ==========
  1553. var result = await UpdateExistingRecord(airFeeInfo, cardPaymentInfo, existingAir, groupId, index);
  1554. if (!result.Success)
  1555. {
  1556. RollbackTran();
  1557. return JsonView<AppPushBodyView>.Fail(result.ErrorMessage);
  1558. }
  1559. airId = result.AirId;
  1560. cardId = result.CardId;
  1561. appPushBodyInfos.Add(new AppPushBodyInfo()
  1562. {
  1563. OperationType = 2,
  1564. AirTicketId = airId,
  1565. CardId = cardId,
  1566. CardCNYAmount = cardPaymentInfo.RMBPrice
  1567. });
  1568. }
  1569. index++;
  1570. }
  1571. CommitTran();
  1572. var view = new AppPushBodyView()
  1573. {
  1574. GroupName = dto.GroupAirInfo.TeamName,
  1575. AppPushBodyInfos = appPushBodyInfos
  1576. };
  1577. return JsonView<AppPushBodyView>.Success("保存成功", view);
  1578. }
  1579. catch (Exception ex)
  1580. {
  1581. RollbackTran();
  1582. return JsonView<AppPushBodyView>.Fail($"保存失败:{ex.Message}");
  1583. }
  1584. }
  1585. #region 保存 辅助方法
  1586. /// <summary>
  1587. /// 整理数据(按舱位类型分组,分离退票和正常记录)
  1588. /// </summary>
  1589. /// <param name="airTicketFeeInfos"></param>
  1590. /// <param name="groupId"></param>
  1591. /// <returns></returns>
  1592. private Task<List<AirTicketFeeOpInfo>> OrganizeAirTicketDataAsync(List<AirTicketFeeInfo> airTicketFeeInfos, int groupId)
  1593. {
  1594. var result = new List<AirTicketFeeOpInfo>();
  1595. foreach (var airInfo in airTicketFeeInfos)
  1596. {
  1597. if (airInfo.CustTicketInfos == null || !airInfo.CustTicketInfos.Any())
  1598. continue;
  1599. // 按舱位类型分组
  1600. var groupByCabinType = airInfo.CustTicketInfos
  1601. .GroupBy(x => x.CType)
  1602. .ToList();
  1603. foreach (var cabinGroup in groupByCabinType)
  1604. {
  1605. var customers = cabinGroup.ToList();
  1606. // 1. 正常记录(非退票客户)- 按舱位类型合并成一条数据
  1607. var normalCustomers = customers.ToList();
  1608. if (normalCustomers.Any())
  1609. {
  1610. var custRecord = _mapper.Map<AirTicketFeeOpInfo>(airInfo);
  1611. custRecord.ClientNum = normalCustomers.Count;
  1612. custRecord.ClientName = string.Join(",", normalCustomers.Select(x => x.ClientId));
  1613. custRecord.CustTicketInfos = normalCustomers;
  1614. var totalTicketPrice = normalCustomers.Sum(x => x.ActualPrice + x.AdditionalServices?.Sum(x1 => x1.Amount) ?? 0.00m);
  1615. custRecord.Price = totalTicketPrice;
  1616. custRecord.Currency = airInfo.PaymentCurrency;
  1617. custRecord.PayMoney = totalTicketPrice;
  1618. custRecord.RecordType = 0; // 正常记录
  1619. custRecord.DIId = groupId;
  1620. custRecord.CType = normalCustomers.FirstOrDefault()?.CType ?? 0;
  1621. result.Add(custRecord);
  1622. }
  1623. // 2. 退票记录 - 按舱位类型 + 退款卡类型 分组
  1624. var refundCustomers = customers.Where(x => x.IsRefund).ToList();
  1625. if (refundCustomers.Any())
  1626. {
  1627. // 按退款卡类型分组
  1628. var groupByRefundAccount = refundCustomers
  1629. .GroupBy(x => x.RefundRecord?.RefundAccount ?? 0)
  1630. .ToList();
  1631. foreach (var refundGroup in groupByRefundAccount)
  1632. {
  1633. var refundCustomersInGroup = refundGroup.ToList();
  1634. var refundAccount = refundGroup.Key;
  1635. var custRecord = _mapper.Map<AirTicketFeeOpInfo>(airInfo);
  1636. custRecord.DIId = groupId;
  1637. custRecord.RecordType = 1; // 退票记录
  1638. custRecord.CType = normalCustomers.FirstOrDefault()?.CType ?? 0;
  1639. custRecord.OriginalReservationId = custRecord.Id; // 关联原始记录
  1640. custRecord.ClientNum = refundCustomersInGroup.Count;
  1641. custRecord.ClientName = string.Join(",", refundCustomersInGroup.Select(x => x.ClientId));
  1642. custRecord.CustTicketInfos = refundCustomersInGroup;
  1643. // 计算退款金额(负数)
  1644. decimal totalRefundAmount = refundCustomersInGroup.Sum(x =>
  1645. (x.RefundRecord?.RefundAmount ?? 0) + (x.RefundRecord?.NonRefundableTax ?? 0));
  1646. custRecord.Price = totalRefundAmount;
  1647. custRecord.Currency = airInfo.PaymentCurrency;
  1648. custRecord.PayMoney = totalRefundAmount;
  1649. custRecord.CTDId = refundAccount; // 退款账户
  1650. result.Add(custRecord);
  1651. }
  1652. }
  1653. }
  1654. }
  1655. return Task.FromResult(result.OrderBy(x => x.RecordType).ToList());
  1656. }
  1657. /// <summary>
  1658. /// 新增记录
  1659. /// </summary>
  1660. /// <param name="airFeeInfo"></param>
  1661. /// <param name="cardPaymentInfo"></param>
  1662. /// <param name="index"></param>
  1663. /// <returns></returns>
  1664. private async Task<(bool Success, string ErrorMessage, int AirId, int CardId)> InsertNewRecord(
  1665. Grp_AirTicketReservations airFeeInfo,
  1666. Grp_CreditCardPayment cardPaymentInfo,
  1667. int index)
  1668. {
  1669. // 如果是退票记录,需要先获取关联的正常机票ID
  1670. if (airFeeInfo.RecordType == 1)
  1671. {
  1672. // 根据唯一键查找关联的正常机票记录
  1673. var normalAir = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  1674. .FirstAsync(x => x.DIId == airFeeInfo.DIId
  1675. && x.FlightsDescription == airFeeInfo.FlightsDescription
  1676. && x.CType == airFeeInfo.CType
  1677. && x.RecordType == 0
  1678. && x.IsDel == 0);
  1679. // 设置关联的正常机票ID
  1680. airFeeInfo.OriginalReservationId = normalAir?.Id ?? 0;
  1681. }
  1682. // 插入机票信息
  1683. var airIdLong = await _sqlSugar.Insertable(airFeeInfo).ExecuteReturnIdentityAsync();
  1684. var airId = (int)airIdLong;
  1685. if (airId < 1)
  1686. {
  1687. return (false, $"第{index}条,机票信息添加失败", 0, 0);
  1688. }
  1689. // 插入付款信息
  1690. cardPaymentInfo.CId = airId;
  1691. var cardIdLong = await _sqlSugar.Insertable(cardPaymentInfo).ExecuteReturnIdentityAsync();
  1692. var cardId = (int)cardIdLong;
  1693. if (cardId < 1)
  1694. {
  1695. return (false, $"第{index}条,机票付款信息添加失败", 0, 0);
  1696. }
  1697. return (true, string.Empty, airId, cardId);
  1698. }
  1699. /// <summary>
  1700. /// 更新记录
  1701. /// </summary>
  1702. /// <param name="airFeeInfo"></param>
  1703. /// <param name="cardPaymentInfo"></param>
  1704. /// <param name="existingAir"></param>
  1705. /// <param name="groupId"></param>
  1706. /// <param name="index"></param>
  1707. /// <returns></returns>
  1708. /// <summary>
  1709. /// 更新记录(支持舱位变更:当前舱位无人员时删除,新舱位新增或合并)
  1710. /// </summary>
  1711. /// <summary>
  1712. /// 更新记录(在修改时处理舱位变更)
  1713. /// </summary>
  1714. private async Task<(bool Success, bool IsSkip, string ErrorMessage, int AirId, int CardId)> UpdateExistingRecord(
  1715. Grp_AirTicketReservations airFeeInfo,
  1716. Grp_CreditCardPayment cardPaymentInfo,
  1717. Grp_AirTicketReservations existingAir,
  1718. int groupId,
  1719. int index)
  1720. {
  1721. var existingAirId = existingAir.Id;
  1722. var oldCabinType = existingAir.CType;
  1723. var newCabinType = airFeeInfo.CType;
  1724. // 1. 验证费用状态
  1725. var existingCard = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  1726. .FirstAsync(x => x.DIId == groupId && x.CTable == 85 && x.CId == existingAirId && x.IsDel == 0);
  1727. if (existingCard != null)
  1728. {
  1729. if (existingCard.IsAuditGM == 1 || existingCard.IsAuditGM == 3)
  1730. {
  1731. return (false, true, $"第{index}条,机票费用已审核,不可操作!", 0, 0);
  1732. }
  1733. if (existingCard.IsPay == 1)
  1734. {
  1735. return (false, true, $"第{index}条,机票费用已付款,不可操作!", 0, 0);
  1736. }
  1737. }
  1738. // 2. 如果是退票记录,处理关联
  1739. if (airFeeInfo.RecordType == 1 && airFeeInfo.OriginalReservationId <= 0)
  1740. {
  1741. var normalAir = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  1742. .FirstAsync(x => x.DIId == groupId
  1743. && x.FlightsDescription == airFeeInfo.FlightsDescription
  1744. && x.CType == airFeeInfo.CType
  1745. && x.RecordType == 0
  1746. && x.IsDel == 0);
  1747. if (normalAir == null)
  1748. {
  1749. return (false, true, $"第{index}条,退票记录关联的正常机票不存在,请先添加正常机票", 0, 0);
  1750. }
  1751. airFeeInfo.OriginalReservationId = normalAir.Id;
  1752. }
  1753. // ========== 3. 处理舱位变更 ==========
  1754. if (oldCabinType != newCabinType)
  1755. {
  1756. // 3.1 检查原舱位是否有退票记录
  1757. var hasRefund = existingAir.CustTicketInfos?.Any(x => x.IsRefund) == true;
  1758. if (hasRefund)
  1759. {
  1760. return (false, true, $"第{index}条,原舱位下存在退票记录,不可变更舱位!请先处理退票", 0, 0);
  1761. }
  1762. // 3.2 获取原舱位的人员列表
  1763. var movingClients = existingAir.CustTicketInfos ?? new List<CustTicketInfo>();
  1764. if (!movingClients.Any())
  1765. {
  1766. // 没有人员,直接更新舱位类型
  1767. airFeeInfo.Id = existingAirId;
  1768. var airUpdateCount = await _sqlSugar.Updateable(airFeeInfo)
  1769. .IgnoreColumns(ignoreAllNullColumns: true)
  1770. .Where(x => x.Id == existingAirId)
  1771. .ExecuteCommandAsync();
  1772. if (airUpdateCount < 1)
  1773. {
  1774. return (false, false, $"第{index}条,更新舱位类型失败", 0, 0);
  1775. }
  1776. return (true, false, string.Empty, existingAirId, existingCard?.Id ?? 0);
  1777. }
  1778. // 3.3 查找目标舱位是否已存在记录
  1779. var targetRecord = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  1780. .FirstAsync(x => x.DIId == groupId
  1781. && x.FlightsDescription == airFeeInfo.FlightsDescription
  1782. && x.CType == newCabinType
  1783. && x.RecordType == airFeeInfo.RecordType
  1784. && x.IsDel == 0);
  1785. if (targetRecord != null)
  1786. {
  1787. // ========== 目标舱位已存在:合并人员 ==========
  1788. // 3.3.1 获取目标舱位的人员列表
  1789. var targetClients = targetRecord.CustTicketInfos ?? new List<CustTicketInfo>();
  1790. var existingClientIds = targetClients.Select(x => x.ClientId).ToHashSet();
  1791. // 3.3.2 合并人员(去重,保留原舱位的人员信息)
  1792. foreach (var movingClient in movingClients)
  1793. {
  1794. if (!existingClientIds.Contains(movingClient.ClientId))
  1795. {
  1796. targetClients.Add(movingClient);
  1797. }
  1798. }
  1799. // 3.3.3 重新计算目标舱位的总金额
  1800. var totalTicketPrice = targetClients.Sum(x =>
  1801. x.ActualPrice + (x.AdditionalServices?.Sum(x1 => x1.Amount) ?? 0.00m));
  1802. // 3.3.4 更新目标舱位记录
  1803. targetRecord.CustTicketInfos = targetClients;
  1804. targetRecord.ClientNum = targetClients.Count;
  1805. targetRecord.ClientName = string.Join(",", targetClients.Select(x => x.ClientId));
  1806. targetRecord.Price = totalTicketPrice;
  1807. var targetUpdateCount = await _sqlSugar.Updateable(targetRecord)
  1808. .IgnoreColumns(ignoreAllNullColumns: true)
  1809. .Where(x => x.Id == targetRecord.Id)
  1810. .ExecuteCommandAsync();
  1811. if (targetUpdateCount < 1)
  1812. {
  1813. return (false, false, $"第{index}条,合并到目标舱位失败", 0, 0);
  1814. }
  1815. // 3.3.5 更新目标舱位的费用记录
  1816. var targetCard = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  1817. .FirstAsync(x => x.DIId == groupId && x.CTable == 85 && x.CId == targetRecord.Id && x.IsDel == 0);
  1818. if (targetCard != null)
  1819. {
  1820. targetCard.PayMoney = totalTicketPrice;
  1821. targetCard.RMBPrice = totalTicketPrice * (targetCard?.DayRate ?? 1);
  1822. targetCard.UpdateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1823. await _sqlSugar.Updateable(targetCard)
  1824. .IgnoreColumns(ignoreAllNullColumns: true)
  1825. .Where(x => x.Id == targetCard.Id)
  1826. .ExecuteCommandAsync();
  1827. }
  1828. // 3.3.6 删除原舱位记录(软删除)
  1829. existingAir.IsDel = 1;
  1830. existingAir.DeleteUserId = airFeeInfo.CreateUserId;
  1831. existingAir.DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1832. await _sqlSugar.Updateable(existingAir)
  1833. .UpdateColumns(x => new { x.IsDel, x.DeleteUserId, x.DeleteTime })
  1834. .Where(x => x.Id == existingAirId)
  1835. .ExecuteCommandAsync();
  1836. // 3.3.7 删除原舱位费用记录
  1837. if (existingCard != null)
  1838. {
  1839. existingCard.IsDel = 1;
  1840. existingCard.DeleteUserId = airFeeInfo.CreateUserId;
  1841. existingCard.DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1842. await _sqlSugar.Updateable(existingCard)
  1843. .UpdateColumns(x => new { x.IsDel, x.DeleteUserId, x.DeleteTime })
  1844. .Where(x => x.Id == existingCard.Id)
  1845. .ExecuteCommandAsync();
  1846. }
  1847. return (true, false, string.Empty, targetRecord.Id, targetCard?.Id ?? 0);
  1848. }
  1849. else
  1850. {
  1851. // ========== 目标舱位不存在:直接修改原记录的舱位类型 ==========
  1852. airFeeInfo.Id = existingAirId;
  1853. airFeeInfo.CreateUserId = existingAir.CreateUserId;
  1854. airFeeInfo.CreateTime = existingAir.CreateTime;
  1855. var airUpdateCount = await _sqlSugar.Updateable(airFeeInfo)
  1856. .IgnoreColumns(ignoreAllNullColumns: true)
  1857. .Where(x => x.Id == existingAirId)
  1858. .ExecuteCommandAsync();
  1859. if (airUpdateCount < 1)
  1860. {
  1861. return (false, false, $"第{index}条,更新舱位类型失败", 0, 0);
  1862. }
  1863. return (true, false, string.Empty, existingAirId, existingCard?.Id ?? 0);
  1864. }
  1865. }
  1866. // ========== 4. 舱位未变,正常更新 ==========
  1867. // 4.1 保留创建信息
  1868. airFeeInfo.Id = existingAirId;
  1869. airFeeInfo.CreateUserId = existingAir.CreateUserId;
  1870. airFeeInfo.CreateTime = existingAir.CreateTime;
  1871. airFeeInfo.IsDel = 0;
  1872. // 4.2 更新机票信息
  1873. var updateCount = await _sqlSugar.Updateable(airFeeInfo)
  1874. .IgnoreColumns(ignoreAllNullColumns: true)
  1875. .Where(x => x.Id == existingAirId)
  1876. .ExecuteCommandAsync();
  1877. if (updateCount < 1)
  1878. {
  1879. return (false, false, $"第{index}条,机票信息保存失败", 0, 0);
  1880. }
  1881. // 4.3 更新或新增付款信息
  1882. int cardId = 0;
  1883. cardPaymentInfo.CId = existingAirId;
  1884. if (existingCard != null)
  1885. {
  1886. cardPaymentInfo.Id = existingCard.Id;
  1887. cardPaymentInfo.CreateUserId = existingCard.CreateUserId;
  1888. cardPaymentInfo.CreateTime = existingCard.CreateTime;
  1889. var cardUpdateCount = await _sqlSugar.Updateable(cardPaymentInfo)
  1890. .IgnoreColumns(ignoreAllNullColumns: true)
  1891. .Where(x => x.Id == existingCard.Id)
  1892. .ExecuteCommandAsync();
  1893. if (cardUpdateCount < 1)
  1894. {
  1895. return (false, false, $"第{index}条,机票费用信息保存失败", 0, 0);
  1896. }
  1897. cardId = existingCard.Id;
  1898. }
  1899. else
  1900. {
  1901. var cardIdLong = await _sqlSugar.Insertable(cardPaymentInfo).ExecuteReturnIdentityAsync();
  1902. if (cardIdLong < 1)
  1903. {
  1904. return (false, false, $"第{index}条,机票费用信息保存失败", 0, 0);
  1905. }
  1906. cardId = (int)cardIdLong;
  1907. }
  1908. return (true, false, string.Empty, existingAirId, cardId);
  1909. }
  1910. #endregion
  1911. /// <summary>
  1912. /// 行程内删除用户信息
  1913. /// </summary>
  1914. /// <param name="dto"></param>
  1915. /// <returns></returns>
  1916. public async Task<JsonView> TripUserDeleteAsync(AirTicketCostTripUserDelDto dto)
  1917. {
  1918. // 基础数据查询(舱位类型)
  1919. var cabinDatas = await _sqlSugar
  1920. .Queryable<Sys_SetData>()
  1921. .Where(x => x.IsDel == 0 && x.STid == 44)
  1922. .Select(x => new { x.Id, x.Name })
  1923. .ToListAsync();
  1924. // 人员信息查询
  1925. var clientInfo = await _sqlSugar.Queryable<Crm_DeleClient>()
  1926. .Where(x => x.IsDel == 0 && x.Id == dto.ClientId)
  1927. .Select(x => new { x.Id, x.FirstName, x.LastName, x.Pinyin })
  1928. .FirstAsync();
  1929. // 客户名称
  1930. var clientName = clientInfo != null
  1931. ? $"{AesEncryptionHelper.Decrypt(clientInfo.FirstName)}{AesEncryptionHelper.Decrypt(clientInfo.LastName)}"
  1932. : $"ID:{dto.ClientId}";
  1933. BeginTran();
  1934. try
  1935. {
  1936. // 1. 查询对应的机票记录(按团组+航段+舱位+正常记录)
  1937. var airTicket = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  1938. .Where(x => x.DIId == dto.GroupId
  1939. && x.FlightsDescription == dto.FlightsDescription
  1940. && x.CType == dto.CType
  1941. && x.RecordType == 0 // 正常记录
  1942. && x.IsDel == 0)
  1943. .FirstAsync();
  1944. var cabinName = cabinDatas.FirstOrDefault(x => x.Id == dto.CType)?.Name ?? "未知舱位";
  1945. if (airTicket == null)
  1946. {
  1947. RollbackTran();
  1948. return JsonView.Fail($"未找到对应记录!(航段:{dto.FlightsDescription}, 舱位:{cabinName})");
  1949. }
  1950. // 1.1 检查人员是否在记录中
  1951. var hasClient = airTicket.CustTicketInfos?.Any(ct => ct.ClientId == dto.ClientId) == true;
  1952. if (!hasClient)
  1953. {
  1954. RollbackTran();
  1955. return JsonView.Fail($"人员【{clientName}(ID:{dto.ClientId})】不存在于该记录中!(航段:{dto.FlightsDescription}, 舱位:{cabinName})");
  1956. }
  1957. // 2. 查询对应的费用记录并验证状态
  1958. var cardPayment = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  1959. .Where(x => x.DIId == dto.GroupId && x.CId == airTicket.Id && x.CTable == 85 && x.IsDel == 0)
  1960. .FirstAsync();
  1961. if (cardPayment != null)
  1962. {
  1963. // 费用状态验证
  1964. if (cardPayment.IsAuditGM == 1)
  1965. {
  1966. RollbackTran();
  1967. return JsonView.Fail($"删除失败:当前费用已审核,不可删除人员!(航段:{dto.FlightsDescription}, 舱位:{cabinName}, 客户:{clientName})");
  1968. }
  1969. if (cardPayment.IsAuditGM == 3)
  1970. {
  1971. RollbackTran();
  1972. return JsonView.Fail($"删除失败:当前费用已自动审核,不可删除人员!(航段:{dto.FlightsDescription}, 舱位:{cabinName}, 客户:{clientName})");
  1973. }
  1974. if (cardPayment.IsPay == 1)
  1975. {
  1976. RollbackTran();
  1977. return JsonView.Fail($"删除失败:当前费用已付款,不可删除人员!(航段:{dto.FlightsDescription}, 舱位:{cabinName}, 客户:{clientName})");
  1978. }
  1979. }
  1980. // 3. 检查该人员是否有退票记录
  1981. var targetClientInfo = airTicket.CustTicketInfos?.FirstOrDefault(x => x.ClientId == dto.ClientId);
  1982. var hasRefund = targetClientInfo?.IsRefund == true;
  1983. if (hasRefund)
  1984. {
  1985. RollbackTran();
  1986. return JsonView.Fail($"删除失败:人员【{clientName}(ID:{dto.ClientId})】存在退票记录,不可删除!请先处理退票信息。");
  1987. }
  1988. // 4. 获取剩余人员列表
  1989. var remainingClients = airTicket.CustTicketInfos?
  1990. .Where(ct => ct.ClientId != dto.ClientId)
  1991. .ToList() ?? new List<CustTicketInfo>();
  1992. // 5. 计算总金额(包含机票价格 + 附加服务费用)
  1993. decimal totalPrice = remainingClients.Sum(x =>
  1994. (x?.ActualPrice ?? 0) + (x.AdditionalServices?.Sum(x1 => x1.Amount) ?? 0));
  1995. // 6. 更新或删除记录
  1996. if (remainingClients.Any())
  1997. {
  1998. // 6.1 更新机票记录
  1999. airTicket.Price = totalPrice;
  2000. airTicket.ClientNum = remainingClients.Count;
  2001. airTicket.ClientName = string.Join(",", remainingClients.Select(x => x.ClientId));
  2002. airTicket.CustTicketInfos = remainingClients;
  2003. var airUpdateCount = await _sqlSugar.Updateable(airTicket)
  2004. .UpdateColumns(x => new { x.ClientNum, x.ClientName, x.Price, x.CustTicketInfos })
  2005. .Where(x => x.Id == airTicket.Id)
  2006. .ExecuteCommandAsync();
  2007. if (airUpdateCount < 1)
  2008. {
  2009. RollbackTran();
  2010. return JsonView.Fail("删除失败:更新机票记录失败!");
  2011. }
  2012. // 6.2 更新费用记录
  2013. if (cardPayment != null)
  2014. {
  2015. cardPayment.PayMoney = totalPrice;
  2016. cardPayment.UpdateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2017. cardPayment.PayThenMoney = totalPrice;
  2018. cardPayment.RMBPrice = totalPrice * (cardPayment?.DayRate ?? 1);
  2019. var cardUpdateCount = await _sqlSugar.Updateable(cardPayment)
  2020. .IgnoreColumns(ignoreAllNullColumns: true)
  2021. .Where(x => x.Id == cardPayment.Id)
  2022. .ExecuteCommandAsync();
  2023. if (cardUpdateCount < 1)
  2024. {
  2025. RollbackTran();
  2026. return JsonView.Fail("删除失败:更新费用记录失败!");
  2027. }
  2028. }
  2029. }
  2030. else
  2031. {
  2032. // 7. 没有剩余人员,删除整条记录
  2033. var now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2034. // 7.1 软删除机票记录
  2035. airTicket.IsDel = 1;
  2036. airTicket.DeleteUserId = dto.CurrUserId;
  2037. airTicket.DeleteTime = now;
  2038. var airUpdateCount = await _sqlSugar.Updateable(airTicket)
  2039. .UpdateColumns(x => new { x.IsDel, x.DeleteUserId, x.DeleteTime })
  2040. .Where(x => x.Id == airTicket.Id)
  2041. .ExecuteCommandAsync();
  2042. if (airUpdateCount < 1)
  2043. {
  2044. RollbackTran();
  2045. return JsonView.Fail("删除失败:删除机票记录失败!");
  2046. }
  2047. // 7.2 软删除费用记录
  2048. if (cardPayment != null)
  2049. {
  2050. cardPayment.IsDel = 1;
  2051. cardPayment.DeleteUserId = dto.CurrUserId;
  2052. cardPayment.DeleteTime = now;
  2053. var cardUpdateCount = await _sqlSugar.Updateable(cardPayment)
  2054. .UpdateColumns(x => new { x.IsDel, x.DeleteUserId, x.DeleteTime })
  2055. .Where(x => x.Id == cardPayment.Id)
  2056. .ExecuteCommandAsync();
  2057. if (cardUpdateCount < 1)
  2058. {
  2059. RollbackTran();
  2060. return JsonView.Fail("删除失败:删除费用记录失败!");
  2061. }
  2062. }
  2063. }
  2064. CommitTran();
  2065. return JsonView.Success($"删除成功!已从航段【{dto.FlightsDescription}】舱位【{cabinName}】中移除人员【{clientName}(ID:{dto.ClientId})】");
  2066. }
  2067. catch (Exception ex)
  2068. {
  2069. RollbackTran();
  2070. // 记录异常日志
  2071. // _logger.LogError(ex, "行程内删除用户信息失败,参数:{@dto}", dto);
  2072. return JsonView.Fail($"删除失败:{ex.Message}");
  2073. }
  2074. }
  2075. /// <summary>
  2076. /// 取消指定客户的退票
  2077. /// </summary>
  2078. /// <param name="dto">取消退票参数</param>
  2079. /// <returns></returns>
  2080. public async Task<JsonView> CancelClientRefundAsync(CancelClientRefundDto dto)
  2081. {
  2082. // 人员信息查询
  2083. var clientInfo = await _sqlSugar.Queryable<Crm_DeleClient>()
  2084. .Where(x => x.IsDel == 0 && x.Id == dto.ClientId)
  2085. .Select(x => new { x.Id, x.FirstName, x.LastName, x.Pinyin })
  2086. .FirstAsync();
  2087. // 客户名称
  2088. var clientName = clientInfo != null
  2089. ? $"{AesEncryptionHelper.Decrypt(clientInfo.FirstName)}{AesEncryptionHelper.Decrypt(clientInfo.LastName)}"
  2090. : $"ID:{dto.ClientId}";
  2091. BeginTran();
  2092. try
  2093. {
  2094. // 1. 查询退票记录
  2095. var refundRecord = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  2096. .Where(x => x.DIId == dto.GroupId
  2097. && x.FlightsDescription == dto.FlightsDescription
  2098. && x.CType == dto.CType
  2099. && x.RecordType == 1 // 退票记录
  2100. && x.IsDel == 0)
  2101. .FirstAsync();
  2102. if (refundRecord == null)
  2103. {
  2104. RollbackTran();
  2105. return JsonView.Fail("未找到退票记录!");
  2106. }
  2107. // 2. 查询退票费用记录并验证状态
  2108. var refundPayment = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  2109. .Where(x => x.DIId == dto.GroupId
  2110. && x.CId == refundRecord.Id
  2111. && x.CTable == 85
  2112. && x.IsDel == 0)
  2113. .FirstAsync();
  2114. if (refundPayment != null)
  2115. {
  2116. if (refundPayment.IsAuditGM == 1 || refundPayment.IsAuditGM == 3)
  2117. {
  2118. RollbackTran();
  2119. return JsonView.Fail("取消失败:退票费用已审核,不可取消!");
  2120. }
  2121. if (refundPayment.IsPay == 1)
  2122. {
  2123. RollbackTran();
  2124. return JsonView.Fail("取消失败:退票费用已付款,不可取消!");
  2125. }
  2126. }
  2127. // 3. 解析退票人员列表
  2128. var refundClientIds = refundRecord.CustTicketInfos?
  2129. .Where(x => x.IsRefund)
  2130. .Select(x => x.ClientId)
  2131. .ToList() ?? new List<int>();
  2132. if (!refundClientIds.Contains(dto.ClientId))
  2133. {
  2134. RollbackTran();
  2135. return JsonView.Fail($"人员【{clientName}】不存在于该退票记录中!");
  2136. }
  2137. // 4. 查询关联的正常机票记录
  2138. var normalTicket = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  2139. .Where(x => x.Id == refundRecord.OriginalReservationId
  2140. && x.RecordType == 0
  2141. && x.IsDel == 0)
  2142. .FirstAsync();
  2143. if (normalTicket == null)
  2144. {
  2145. RollbackTran();
  2146. return JsonView.Fail("取消失败:关联的正常机票记录不存在!");
  2147. }
  2148. // 5. 更新正常机票中该客户的 IsRefund 标志
  2149. var normalTicketClients = normalTicket.CustTicketInfos ?? new List<CustTicketInfo>();
  2150. var targetClient = normalTicketClients.FirstOrDefault(x => x.ClientId == dto.ClientId);
  2151. if (targetClient != null)
  2152. {
  2153. targetClient.IsRefund = false;
  2154. targetClient.RefundRecord = new RefundRecord();
  2155. }
  2156. // 6. 保存正常机票记录
  2157. normalTicket.CustTicketInfos = normalTicketClients;
  2158. var airNormalCount = await _sqlSugar.Updateable(normalTicket)
  2159. .UpdateColumns(x => new { x.CustTicketInfos })
  2160. .Where(x => x.Id == normalTicket.Id)
  2161. .ExecuteCommandAsync();
  2162. if (airNormalCount < 1)
  2163. {
  2164. RollbackTran();
  2165. return JsonView.Fail("取消失败:更新正常机票记录失败!");
  2166. }
  2167. // 7. 从退票记录中移除该客户(同时更新 CustTicketInfos)
  2168. var remainingRefundClients = refundRecord.CustTicketInfos?
  2169. .Where(x => x.ClientId != dto.ClientId)
  2170. .ToList() ?? new List<CustTicketInfo>();
  2171. if (remainingRefundClients.Any())
  2172. {
  2173. // 7.1 更新退票记录中的 CustTicketInfos
  2174. refundRecord.CustTicketInfos = remainingRefundClients;
  2175. refundRecord.ClientNum = remainingRefundClients.Count;
  2176. refundRecord.ClientName = string.Join(",", remainingRefundClients.Select(x => x.ClientId));
  2177. // 重新计算退款金额
  2178. decimal totalRefundAmount = remainingRefundClients.Sum(x =>
  2179. (x.RefundRecord?.RefundAmount ?? 0) + (x.RefundRecord?.NonRefundableTax ?? 0));
  2180. refundRecord.Price = totalRefundAmount;
  2181. var refundRecordCount = await _sqlSugar.Updateable(refundRecord)
  2182. .UpdateColumns(x => new { x.CustTicketInfos, x.ClientNum, x.ClientName, x.Price })
  2183. .Where(x => x.Id == refundRecord.Id)
  2184. .ExecuteCommandAsync();
  2185. if (refundRecordCount < 1)
  2186. {
  2187. RollbackTran();
  2188. return JsonView.Fail("取消退票失败:退票信息更新失败!");
  2189. }
  2190. // 7.2 更新退票费用记录
  2191. if (refundPayment != null)
  2192. {
  2193. refundPayment.PayMoney = totalRefundAmount;
  2194. refundPayment.RMBPrice = totalRefundAmount * (refundPayment?.DayRate ?? 1);
  2195. refundPayment.UpdateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2196. var refundPaymentCount = await _sqlSugar.Updateable(refundPayment)
  2197. .UpdateColumns(x => new { x.PayMoney, x.RMBPrice, x.UpdateDate })
  2198. .Where(x => x.Id == refundPayment.Id)
  2199. .ExecuteCommandAsync();
  2200. if (refundPaymentCount < 1)
  2201. {
  2202. RollbackTran();
  2203. return JsonView.Fail("取消退票失败:退票费用信息更新失败!");
  2204. }
  2205. }
  2206. }
  2207. else
  2208. {
  2209. // 8. 退票记录中没有客户了,删除整条退票记录
  2210. var now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2211. refundRecord.IsDel = 1;
  2212. refundRecord.DeleteUserId = dto.CurrUserId;
  2213. refundRecord.DeleteTime = now;
  2214. var refundRecordCount = await _sqlSugar.Updateable(refundRecord)
  2215. .UpdateColumns(x => new { x.IsDel, x.DeleteUserId, x.DeleteTime })
  2216. .Where(x => x.Id == refundRecord.Id)
  2217. .ExecuteCommandAsync();
  2218. if (refundRecordCount < 1)
  2219. {
  2220. RollbackTran();
  2221. return JsonView.Fail("取消退票失败:删除退票记录失败!");
  2222. }
  2223. if (refundPayment != null)
  2224. {
  2225. refundPayment.IsDel = 1;
  2226. refundPayment.DeleteUserId = dto.CurrUserId;
  2227. refundPayment.DeleteTime = now;
  2228. var refundPaymentCount = await _sqlSugar.Updateable(refundPayment)
  2229. .UpdateColumns(x => new { x.IsDel, x.DeleteUserId, x.DeleteTime })
  2230. .Where(x => x.Id == refundPayment.Id)
  2231. .ExecuteCommandAsync();
  2232. if (refundPaymentCount < 1)
  2233. {
  2234. RollbackTran();
  2235. return JsonView.Fail("取消退票失败:删除退票费用记录失败!");
  2236. }
  2237. }
  2238. }
  2239. CommitTran();
  2240. return JsonView.Success($"取消退票成功!已将客户【{clientName}】的退票状态恢复正常");
  2241. }
  2242. catch (Exception ex)
  2243. {
  2244. RollbackTran();
  2245. return JsonView.Fail($"取消退票失败:{ex.Message}");
  2246. }
  2247. }
  2248. /// <summary>
  2249. /// 按ID删除机票记录 2026版
  2250. /// 验证费用状态和退票记录
  2251. /// </summary>
  2252. /// <param name="userId">操作用户ID</param>
  2253. /// <param name="airTicketId">机票记录ID</param>
  2254. /// <returns></returns>
  2255. public async Task<JsonView> DeleteByIdAsync(int userId, int airTicketId)
  2256. {
  2257. BeginTran();
  2258. try
  2259. {
  2260. // 1. 查询机票记录
  2261. var airTicket = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  2262. .Where(x => x.Id == airTicketId && x.IsDel == 0)
  2263. .FirstAsync();
  2264. if (airTicket == null)
  2265. {
  2266. RollbackTran();
  2267. return JsonView.Fail("机票费用记录不存在或已被删除!");
  2268. }
  2269. // 2. 验证费用状态
  2270. var cardPayment = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  2271. .Where(x => x.CId == airTicketId && x.CTable == 85 && x.IsDel == 0)
  2272. .FirstAsync();
  2273. if (cardPayment != null)
  2274. {
  2275. if (cardPayment.IsAuditGM == 1)
  2276. {
  2277. RollbackTran();
  2278. return JsonView.Fail($"删除失败:当前费用已审核,不可删除!(记录ID:{airTicketId})");
  2279. }
  2280. if (cardPayment.IsAuditGM == 3)
  2281. {
  2282. RollbackTran();
  2283. return JsonView.Fail($"删除失败:当前费用已自动审核,不可删除!(记录ID:{airTicketId})");
  2284. }
  2285. if (cardPayment.IsPay == 1)
  2286. {
  2287. RollbackTran();
  2288. return JsonView.Fail($"删除失败:当前费用已付款,不可删除!(记录ID:{airTicketId})");
  2289. }
  2290. }
  2291. // 3. 验证退票记录关联
  2292. if (airTicket.RecordType == 0) // 正常记录
  2293. {
  2294. // 检查是否有退票记录关联
  2295. var refundRecords = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  2296. .Where(x => x.OriginalReservationId == airTicketId
  2297. && x.RecordType == 1
  2298. && x.IsDel == 0)
  2299. .ToListAsync();
  2300. if (refundRecords.Any())
  2301. {
  2302. var refundIds = string.Join(",", refundRecords.Select(x => x.Id));
  2303. var refundNames = string.Join(",", refundRecords.Select(x => x.ClientName));
  2304. RollbackTran();
  2305. return JsonView.Fail($"删除失败:该记录存在关联的退票记录!请先删除以下退票记录ID:[{refundIds}],关联人员:[{refundNames}]");
  2306. }
  2307. }
  2308. else if (airTicket.RecordType == 1) // 退票记录
  2309. {
  2310. // 检查关联的正常机票是否存在
  2311. if (airTicket.OriginalReservationId > 0)
  2312. {
  2313. var normalTicket = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  2314. .Where(x => x.Id == airTicket.OriginalReservationId && x.IsDel == 0)
  2315. .FirstAsync();
  2316. if (normalTicket == null)
  2317. {
  2318. RollbackTran();
  2319. return JsonView.Fail($"删除失败:退票记录关联的正常机票不存在或已被删除!(关联ID:{airTicket.OriginalReservationId})");
  2320. }
  2321. }
  2322. }
  2323. // 4. 执行软删除
  2324. // 4.1 软删除机票记录
  2325. airTicket.IsDel = 1;
  2326. airTicket.DeleteUserId = userId;
  2327. airTicket.DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2328. var airUpdateCount = await _sqlSugar.Updateable(airTicket)
  2329. .UpdateColumns(x => new { x.IsDel, x.DeleteUserId, x.DeleteTime })
  2330. .Where(x => x.Id == airTicketId)
  2331. .ExecuteCommandAsync();
  2332. if (airUpdateCount < 1)
  2333. {
  2334. RollbackTran();
  2335. return JsonView.Fail("删除失败:机票记录删除失败!");
  2336. }
  2337. // 4.2 软删除对应的费用记录
  2338. if (cardPayment != null)
  2339. {
  2340. cardPayment.IsDel = 1;
  2341. cardPayment.DeleteUserId = userId;
  2342. cardPayment.DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2343. var cardUpdateCount = await _sqlSugar.Updateable(cardPayment)
  2344. .UpdateColumns(x => new { x.IsDel, x.DeleteUserId, x.DeleteTime })
  2345. .Where(x => x.Id == cardPayment.Id)
  2346. .ExecuteCommandAsync();
  2347. if (cardUpdateCount < 1)
  2348. {
  2349. RollbackTran();
  2350. return JsonView.Fail("删除失败:费用记录删除失败!");
  2351. }
  2352. }
  2353. CommitTran();
  2354. var recordTypeName = airTicket.RecordType == 0 ? "正常记录" : "退票记录";
  2355. return JsonView.Success($"删除成功!已删除{recordTypeName},ID:{airTicketId}");
  2356. }
  2357. catch (Exception ex)
  2358. {
  2359. RollbackTran();
  2360. return JsonView.Fail($"删除失败:{ex.Message}");
  2361. }
  2362. }
  2363. #endregion
  2364. }