FinancialController.cs 218 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737
  1. using Aspose.Cells;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.AspNetCore.Mvc;
  4. using OASystem.API.OAMethodLib;
  5. using OASystem.API.OAMethodLib.File;
  6. using OASystem.Domain;
  7. using OASystem.Domain.Dtos.Financial;
  8. using OASystem.Domain.Dtos.Groups;
  9. using OASystem.Domain.Entities.Financial;
  10. using OASystem.Domain.Entities.Groups;
  11. using OASystem.Domain.ViewModels.Financial;
  12. using OASystem.Domain.ViewModels.Groups;
  13. using OASystem.Domain.ViewModels.SmallFun;
  14. using OASystem.Infrastructure.Repositories.Financial;
  15. using OASystem.Infrastructure.Repositories.Groups;
  16. using SqlSugar;
  17. using StackExchange.Redis;
  18. using System.Data;
  19. using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
  20. using System.Web;
  21. using Aspose.Words;
  22. using NPOI.HSSF.Util;
  23. using OASystem.Domain.Entities.Customer;
  24. using System.IO.Compression;
  25. using NPOI.SS.UserModel;
  26. using System.Net.Http;
  27. using Google.Protobuf;
  28. using NPOI.SS.Formula.Functions;
  29. using System.Globalization;
  30. using NPOI.POIFS.Properties;
  31. using SixLabors.ImageSharp.ColorSpaces;
  32. using OASystem.Domain.ViewModels.QiYeWeChat;
  33. using System.Diagnostics;
  34. using System.Security.Cryptography;
  35. using NPOI.POIFS.Crypt.Dsig;
  36. using OASystem.API.OAMethodLib.QiYeWeChatAPI.AppNotice;
  37. using Org.BouncyCastle.Asn1.Ocsp;
  38. using FluentValidation;
  39. using AutoMapper;
  40. using NetTaste;
  41. using EyeSoft.Runtime.InteropServices;
  42. using NPOI.HPSF;
  43. using System.Data.OleDb;
  44. using Org.BouncyCastle.Crypto;
  45. using OfficeOpenXml;
  46. using Org.BouncyCastle.Asn1.Crmf;
  47. using EyeSoft.Extensions;
  48. using System.Collections;
  49. namespace OASystem.API.Controllers
  50. {
  51. /// <summary>
  52. /// 财务模块
  53. /// </summary>
  54. [Route("api/[controller]/[action]")]
  55. [ApiController]
  56. public class FinancialController : ControllerBase
  57. {
  58. private readonly IMapper _mapper;
  59. private readonly IConfiguration _config;
  60. private readonly SqlSugarClient _sqlSugar;
  61. private readonly HttpClient _httpClient;
  62. private readonly SetDataTypeRepository _setDataTypeRep;
  63. private readonly SetDataRepository _setDataRep;
  64. private readonly DailyFeePaymentRepository _daiRep; //日付申请仓库
  65. private readonly TeamRateRepository _teamRateRep; //团组汇率仓库
  66. private readonly ForeignReceivablesRepository _ForForeignReceivablesRep; //对外收款账单仓库
  67. private readonly ProceedsReceivedRepository _proceedsReceivedRep; //已收款项仓库
  68. private readonly PaymentRefundAndOtherMoneyRepository _paymentRefundAndOtherMoneyRep; //收款退还与其他款项 仓库
  69. private readonly DelegationInfoRepository _delegationInfoRep; //团组信息 仓库
  70. /// <summary>
  71. /// 初始化
  72. /// </summary>
  73. public FinancialController(IMapper mapper, IConfiguration configuration, DailyFeePaymentRepository daiRep, SqlSugarClient sqlSugar, SetDataTypeRepository setDataTypeRep,
  74. TeamRateRepository teamRateRep, ForeignReceivablesRepository ForForeignReceivablesRep, ProceedsReceivedRepository proceedsReceivedRep,
  75. PaymentRefundAndOtherMoneyRepository paymentRefundAndOtherMoneyRep, HttpClient httpClient, DelegationInfoRepository delegationInfoRep)
  76. {
  77. _mapper = mapper;
  78. _config = configuration;
  79. _daiRep = daiRep;
  80. _sqlSugar = sqlSugar;
  81. _setDataTypeRep = setDataTypeRep;
  82. _teamRateRep = teamRateRep;
  83. _ForForeignReceivablesRep = ForForeignReceivablesRep;
  84. _proceedsReceivedRep = proceedsReceivedRep;
  85. _paymentRefundAndOtherMoneyRep = paymentRefundAndOtherMoneyRep;
  86. _httpClient = httpClient;
  87. _delegationInfoRep = delegationInfoRep;
  88. }
  89. #region 日付申请
  90. /// <summary>
  91. /// 获取日付申请 基础数据源
  92. /// </summary>
  93. /// <param name="dto"> 日付申请 分页 dto</param>
  94. /// <returns></returns>
  95. [HttpPost]
  96. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  97. public async Task<IActionResult> PostPageSearchDailyPaymentPriceTypeData(PortDtoBase dto)
  98. {
  99. var result = await _daiRep.GetPagePriceTypeData(dto);
  100. if (result == null || result.Code != 0)
  101. {
  102. return Ok(JsonView(false, result.Msg));
  103. }
  104. var data = result.Data;
  105. return Ok(JsonView(data));
  106. }
  107. /// <summary>
  108. /// 获取日付申请 基础数据源 - 转账表识
  109. /// </summary>
  110. /// <param name="dto"> 日付申请 分页 dto</param>
  111. /// <returns></returns>
  112. [HttpPost]
  113. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  114. public async Task<IActionResult> GetSearchDailyPaymentPriceTypeAddData(PortDtoBase dto)
  115. {
  116. var result = await _daiRep.GetPriceTypeAddData(dto);
  117. if (result == null || result.Code != 0)
  118. {
  119. return Ok(JsonView(false, result.Msg));
  120. }
  121. var data = result.Data;
  122. return Ok(JsonView(data));
  123. }
  124. /// <summary>
  125. /// 日付申请 Page Search
  126. /// </summary>
  127. /// <param name="dto"> 日付申请 分页 dto</param>
  128. /// <returns></returns>
  129. [HttpPost]
  130. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  131. public async Task<IActionResult> PostPageSearchDailyPaymentList(PageDailyFeePaymentDto dto)
  132. {
  133. var result = await _daiRep.GetPageSearchAll(dto);
  134. if (result == null || result.Code != 0)
  135. {
  136. return Ok(JsonView(false, result.Msg));
  137. }
  138. var data = result.Data;
  139. if (data == null)
  140. {
  141. return Ok(JsonView(false, result.Msg));
  142. }
  143. return Ok(JsonView(data));
  144. }
  145. /// <summary>
  146. /// 日付申请 Single Search By Id
  147. /// </summary>
  148. /// <param name="dto"></param>
  149. /// <returns></returns>
  150. [HttpPost]
  151. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  152. public async Task<IActionResult> PostSearchDailyPaymentInfo(SearchDailyFeePaymentDto dto)
  153. {
  154. var result = await _daiRep.GetSearchById(dto);
  155. if (result == null || result.Code != 0)
  156. {
  157. return Ok(JsonView(false, result.Msg));
  158. }
  159. return Ok(JsonView(result.Data));
  160. }
  161. /// <summary>
  162. /// 日付申请 添加
  163. /// </summary>
  164. /// <param name="dto"> 日付申请 添加 dto</param>
  165. /// <returns></returns>
  166. [HttpPost]
  167. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  168. public async Task<IActionResult> PostAddDailyPayment(AddDailyFeePaymentDto dto)
  169. {
  170. var result = await _daiRep.Add(dto);
  171. if (result == null || result.Code != 0)
  172. {
  173. return Ok(JsonView(false, result.Msg));
  174. }
  175. #region 应用推送
  176. try
  177. {
  178. int dailyId = result.Data.GetType().GetProperty("dailyId").GetValue(result.Data, null);
  179. int sign = result.Data.GetType().GetProperty("sign").GetValue(result.Data, null);
  180. await AppNoticeLibrary.DailyPayReminders_Create_ToCaiwuChat(dailyId, sign, QiyeWeChatEnum.CaiWuChat);
  181. }
  182. catch (Exception ex)
  183. {
  184. }
  185. #endregion
  186. return Ok(JsonView(true));
  187. }
  188. /// <summary>
  189. /// 日付申请 Update
  190. /// </summary>
  191. /// <param name="dto"> 日付申请 修改 dto</param>
  192. /// <returns></returns>
  193. [HttpPost]
  194. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  195. public async Task<IActionResult> PostEditDailyPayment(EditDailyFeePaymentDto dto)
  196. {
  197. var result = await _daiRep.Edit(dto);
  198. if (result == null || result.Code != 0)
  199. {
  200. return Ok(JsonView(false, result.Msg));
  201. }
  202. #region 应用推送
  203. try
  204. {
  205. int dailyId = result.Data.GetType().GetProperty("dailyId").GetValue(result.Data, null);
  206. int sign = result.Data.GetType().GetProperty("sign").GetValue(result.Data, null);
  207. await AppNoticeLibrary.DailyPayReminders_Create_ToCaiwuChat(dailyId, sign, QiyeWeChatEnum.CaiWuChat);
  208. }
  209. catch (Exception ex)
  210. {
  211. }
  212. #endregion
  213. return Ok(JsonView(true));
  214. }
  215. /// <summary>
  216. /// 日付申请 Del
  217. /// </summary>
  218. /// <param name="dto"> 日付申请 删除 dto</param>
  219. /// <returns></returns>
  220. [HttpPost]
  221. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  222. public async Task<IActionResult> PostDelDailyPayment(DelDailyFeePaymentDto dto)
  223. {
  224. var result = await _daiRep.Del(dto);
  225. if (result == null || result.Code != 0)
  226. {
  227. return Ok(JsonView(false, result.Msg));
  228. }
  229. return Ok(JsonView(true));
  230. }
  231. /// <summary>
  232. /// 日付申请 财务审核
  233. /// </summary>
  234. /// <param name="dto"> dto </param>
  235. /// <returns></returns>
  236. [HttpPost]
  237. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  238. public async Task<IActionResult> PostDelDailyPaymentAudit(DP_AuditStatusDto dto)
  239. {
  240. var result = await _daiRep.DailyPaymentAudit(dto);
  241. if (result == null || result.Code != 0)
  242. {
  243. return Ok(JsonView(false, result.Msg));
  244. }
  245. return Ok(JsonView(true));
  246. }
  247. /// <summary>
  248. /// 日付申请 Single Excel Download
  249. /// </summary>
  250. /// <param name="dto"> dto </param>
  251. /// <returns></returns>
  252. [HttpPost]
  253. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  254. public async Task<IActionResult> PostExcelDailyPaymentDownload(SearchDailyFeePaymentDto dto)
  255. {
  256. if (dto.PortType == 1 || dto.PortType == 2)
  257. {
  258. Fin_DailyFeePaymentInfolView feeData = new Fin_DailyFeePaymentInfolView();
  259. string feeSql = string.Format(@"Select * From Fin_DailyFeePayment
  260. Where IsDel=0 And Id = {0} ", dto.Id);
  261. feeData = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentInfolView>(feeSql).FirstAsync();
  262. if (feeData == null)
  263. {
  264. return Ok(JsonView(false, "暂无数据!"));
  265. }
  266. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  267. Where IsDel=0 And DFPId = {0} ", dto.Id);
  268. feeData.FeeContents = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToListAsync();
  269. if (feeData != null)
  270. {
  271. string userName = string.Empty;
  272. string userSql = string.Format("Select * From Sys_Users Where Id={0} And Isdel = {1}", feeData.CreateUserId, 0);
  273. Sys_Users user = await _sqlSugar.SqlQueryable<Sys_Users>(userSql).FirstAsync();
  274. if (user != null) { userName = user.CnName; }
  275. var setData = _setDataTypeRep.QueryDto<Sys_SetData, Fin_DailyFeePaymentPagePriceSubTypeView>().ToList();
  276. //48人员费用 49办公费用 50 销售费用 51 其他费用 55 大运会
  277. var priceSubTypeData = setData.Where(s => s.STid == 55).ToList();
  278. Dictionary<string, object> pairs = new Dictionary<string, object>();
  279. List<DataTable> datas = new List<DataTable>();
  280. //if (priceSubTypeData.Where(s => s.Id == feeData.PriceTypeId).ToList().Count() > 0)//大运会专属模板
  281. //{
  282. // //AsposeHelper.ExpertExcelToModel("日常费用付款申请模板-大运会数据.xls", "DailyPayment", "大运会所有日常费用付款申请.xls",
  283. // // pairs, datas);
  284. //}
  285. //else //日付常规模板
  286. //{
  287. pairs.Clear();
  288. pairs.Add("Opertor", userName);
  289. pairs.Add("DateTime", feeData.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"));
  290. pairs.Add("FAuditStatus", feeData.FAuditDesc);
  291. pairs.Add("MAuditStatus", feeData.MAuditDesc);
  292. pairs.Add("SumPrice", feeData.SumPrice);
  293. DataTable data = AsposeHelper.ListToDataTable("DailyFeePayment", feeData.FeeContents);
  294. datas.Clear();
  295. datas.Add(data);
  296. string fileName = string.Format("{0}-日常费用付款申请.xlsx", feeData.Instructions);
  297. string msg = AsposeHelper.ExpertExcelToModel("日常费用付款申请模板.xlsx", "DailyPayment", fileName, pairs, datas);
  298. return Ok(JsonView(true, msg));
  299. //}
  300. }
  301. else
  302. {
  303. return Ok(JsonView(false, "暂无数据!"));
  304. }
  305. }
  306. return Ok(JsonView(true));
  307. }
  308. #endregion
  309. #region 团组提成
  310. /// <summary>
  311. /// 提成 Page Search
  312. /// </summary>
  313. /// <param name="dto"> 提成 分页 dto</param>
  314. /// <returns></returns>
  315. [HttpPost]
  316. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  317. public async Task<IActionResult> PostPageSearchCommissionList(GroupCommissionDto dto)
  318. {
  319. var data = await GroupCommission.GetCommissionPageList(dto);
  320. return Ok(JsonView(data.Data));
  321. }
  322. #endregion
  323. #region 团组汇率
  324. /// <summary>
  325. /// 团组汇率 Select数据源(团组列,汇率列)
  326. /// </summary>
  327. /// <param name="dto"></param>
  328. /// <returns></returns>
  329. [HttpPost]
  330. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  331. public async Task<IActionResult> GetGroupRateDataSources(TeamRateDto dto)
  332. {
  333. try
  334. {
  335. //迁移数据更新团组汇率
  336. //Result teamRateData1 = await _teamRateRep.GetGroupRateChangeData();
  337. //var data = await _teamRateRep.PostGroupTeamRateHot();
  338. Stopwatch stopwatch = Stopwatch.StartNew();
  339. GroupNameDto groupNameDto = new GroupNameDto() { PortType = dto.PortType };
  340. var groups = await _delegationInfoRep.GetGroupNameList(groupNameDto);
  341. List<CurrencyHot> _currData = new List<CurrencyHot>();
  342. string currData = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("GroupTeamCurrencyData");//string 取
  343. if (!string.IsNullOrEmpty(currData))
  344. {
  345. _currData = JsonConvert.DeserializeObject<List<CurrencyHot>>(currData);
  346. }
  347. else
  348. {
  349. _currData = await _teamRateRep.PostGroupTeamRateHot();
  350. //过期时间 25 Hours
  351. TimeSpan ts = DateTime.Now.AddHours(25).TimeOfDay;
  352. await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync("GroupTeamCurrencyData", JsonConvert.SerializeObject(_currData), ts);
  353. }
  354. var _data = new { GroupData = groups.Data, TeamRateData = _currData };
  355. stopwatch.Stop();
  356. return Ok(JsonView(true, $"查询成功!耗时:{stopwatch.ElapsedMilliseconds / 1000}s", _data));
  357. }
  358. catch (Exception ex)
  359. {
  360. return Ok(JsonView(false, ex.Message));
  361. }
  362. }
  363. ///// <summary>
  364. ///// 团组汇率 changge
  365. ///// </summary>
  366. ///// <returns></returns>
  367. //[HttpPost]
  368. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  369. //public async Task<IActionResult> ChangeGroupRateInfo()
  370. //{
  371. // try
  372. // {
  373. // Result teamRateData = await _teamRateRep.GetGroupRateChangeData();
  374. // if (teamRateData.Code != 0)
  375. // {
  376. // return Ok(JsonView(false, teamRateData.Msg));
  377. // }
  378. // return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  379. // }
  380. // catch (Exception ex)
  381. // {
  382. // return Ok(JsonView(false, ex.Message));
  383. // throw;
  384. // }
  385. //}
  386. /// <summary>
  387. /// 团组汇率 Select汇率详情
  388. /// </summary>
  389. /// <param name="dto"></param>
  390. /// <returns></returns>
  391. [HttpPost]
  392. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  393. public async Task<IActionResult> GetGroupRateInfo(TeamRateInfoDto dto)
  394. {
  395. try
  396. {
  397. Result teamRateData = await _teamRateRep.GetGroupRateInfoByDiid(dto);
  398. if (teamRateData.Code != 0)
  399. {
  400. return Ok(JsonView(false, teamRateData.Msg));
  401. }
  402. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  403. }
  404. catch (Exception ex)
  405. {
  406. return Ok(JsonView(false, ex.Message));
  407. throw;
  408. }
  409. }
  410. /// <summary>
  411. /// 团组汇率 添加 or 更新
  412. /// </summary>
  413. /// <param name="dto"></param>
  414. /// <returns></returns>
  415. [HttpPost]
  416. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  417. public async Task<IActionResult> PostGroupRateUpdate(TeamRateUpdateDto dto)
  418. {
  419. try
  420. {
  421. Result teamRateData = await _teamRateRep.PostGroupRateUpdate(dto);
  422. if (teamRateData.Code != 0)
  423. {
  424. return Ok(JsonView(false, teamRateData.Msg));
  425. }
  426. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  427. }
  428. catch (Exception ex)
  429. {
  430. return Ok(JsonView(false, ex.Message));
  431. throw;
  432. }
  433. }
  434. #endregion
  435. #region 对外收款账单 关联已收款项
  436. /// <summary>
  437. /// 对外收款账单 Select数据源(团组名,币种,汇款方式)
  438. /// 关联已收款项
  439. /// </summary>
  440. /// <param name="dto"></param>
  441. /// <returns></returns>
  442. [HttpPost]
  443. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  444. public async Task<IActionResult> GetForeignReceivablesDataSources(ForeignReceivablesDataSourcesDto dto)
  445. {
  446. return Ok(await _ForForeignReceivablesRep.GetDataSource(dto));
  447. }
  448. /// <summary>
  449. /// 对外收款账单
  450. /// 账单详情
  451. /// 关联已收款项
  452. /// </summary>
  453. /// <param name="dto"></param>
  454. /// <returns></returns>
  455. [HttpPost]
  456. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  457. public async Task<IActionResult> GetGroupReceivablesInfoByDiId(ForForeignReceivablesInfoDto dto)
  458. {
  459. try
  460. {
  461. Result ffrData = await _ForForeignReceivablesRep.GetGroupReceivablesInfoByDiId(dto);
  462. if (ffrData.Code != 0)
  463. {
  464. return Ok(JsonView(false, ffrData.Msg));
  465. }
  466. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  467. }
  468. catch (Exception ex)
  469. {
  470. return Ok(JsonView(false, ex.Message));
  471. throw;
  472. }
  473. }
  474. /// <summary>
  475. /// 对外收款账单
  476. /// 账单 删除
  477. /// 关联已收款项
  478. /// </summary>
  479. /// <param name="dto"></param>
  480. /// <returns></returns>
  481. [HttpPost]
  482. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  483. public async Task<IActionResult> PostGroupReceivablesDel(DelForForeignReceivablesInfoDto dto)
  484. {
  485. try
  486. {
  487. Result ffrData = await _ForForeignReceivablesRep._Del(dto);
  488. if (ffrData.Code != 0)
  489. {
  490. return Ok(JsonView(false, ffrData.Msg));
  491. }
  492. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  493. }
  494. catch (Exception ex)
  495. {
  496. return Ok(JsonView(false, ex.Message));
  497. throw;
  498. }
  499. }
  500. /// <summary>
  501. /// 对外收款账单
  502. /// 添加 And 更新
  503. /// 关联已收款项
  504. /// </summary>
  505. /// <param name="dto"></param>
  506. /// <returns></returns>
  507. [HttpPost]
  508. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  509. public async Task<IActionResult> PostReceivablesOperate(ForeignReceivablesAddAndUpdateDto dto)
  510. {
  511. try
  512. {
  513. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesOperate(dto);
  514. if (ffrData.Code != 0)
  515. {
  516. return Ok(JsonView(false, ffrData.Msg));
  517. }
  518. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  519. }
  520. catch (Exception ex)
  521. {
  522. return Ok(JsonView(false, ex.Message));
  523. throw;
  524. }
  525. }
  526. /// <summary>
  527. /// 已收款项
  528. /// 账单 删除
  529. /// 关联已收款项
  530. /// </summary>
  531. /// <param name="dto"></param>
  532. /// <returns></returns>
  533. [HttpPost]
  534. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  535. public async Task<IActionResult> PostAmountReceivedDel(ProceedsReceivedDelDto dto)
  536. {
  537. try
  538. {
  539. Result ffrData = await _proceedsReceivedRep._Del(dto);
  540. if (ffrData.Code != 0)
  541. {
  542. return Ok(JsonView(false, ffrData.Msg));
  543. }
  544. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  545. }
  546. catch (Exception ex)
  547. {
  548. return Ok(JsonView(false, ex.Message));
  549. throw;
  550. }
  551. }
  552. /// <summary>
  553. /// 已收款项
  554. /// 添加 And 更新
  555. /// 关联已收款项
  556. /// </summary>
  557. /// <param name="dto"></param>
  558. /// <returns></returns>
  559. [HttpPost]
  560. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  561. public async Task<IActionResult> PostAmountReceivedOperate(ProceedsReceivedDto dto)
  562. {
  563. try
  564. {
  565. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedOperate(dto);
  566. if (ffrData.Code != 0)
  567. {
  568. return Ok(JsonView(false, ffrData.Msg));
  569. }
  570. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  571. }
  572. catch (Exception ex)
  573. {
  574. return Ok(JsonView(false, ex.Message));
  575. throw;
  576. }
  577. }
  578. /// <summary>
  579. /// 财务 已收款项
  580. /// 分配已收款项至 应收项下
  581. /// 关联已收款项
  582. /// </summary>
  583. /// <param name="dto"></param>
  584. /// <returns></returns>
  585. [HttpPost]
  586. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  587. public async Task<IActionResult> PostAllocateAmountReceived(AllocateAmountReceivedDto dto)
  588. {
  589. try
  590. {
  591. Result ffrData = await _proceedsReceivedRep.PostAllocateAmountReceived(dto);
  592. if (ffrData.Code != 0)
  593. {
  594. return Ok(JsonView(false, ffrData.Msg));
  595. }
  596. return Ok(JsonView(true));
  597. }
  598. catch (Exception ex)
  599. {
  600. return Ok(JsonView(false, ex.Message));
  601. throw;
  602. }
  603. }
  604. ///// <summary>
  605. ///// 财务 收款账单
  606. ///// 导出Word(北京,四川)
  607. ///// </summary>
  608. ///// <param name="dto"></param>
  609. ///// <returns></returns>
  610. //[HttpPost]
  611. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  612. //public async Task<IActionResult> PostAccountReceivableWordExport(AccountReceivableWordExportDto dto)
  613. //{
  614. // try
  615. // {
  616. // //模板处理
  617. // string typeName = string.Empty;
  618. // if (dto.TemplateType == 1) //四川
  619. // {
  620. // typeName = "四川";
  621. // }
  622. // else if (dto.TemplateType == 2) //北京
  623. // {
  624. // typeName = "北京";
  625. // }
  626. // else return Ok(JsonView(false,"请选择正确的模板类型!"));
  627. // string wordTempName = string.Format("收款账单({0})模板.doc", typeName);
  628. // }
  629. // catch (Exception ex)
  630. // {
  631. // return Ok(JsonView(false, ex.Message));
  632. // }
  633. //}
  634. #endregion
  635. #region 对外收款账单
  636. /// <summary>
  637. /// 对外收款账单
  638. /// 数据源
  639. /// </summary>
  640. /// <param name="dto"></param>
  641. /// <returns></returns>
  642. [HttpPost]
  643. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  644. public async Task<IActionResult> PostGroupReceivablesDataSource(ForeignReceivablesDataSourcesDto dto)
  645. {
  646. return Ok(await _ForForeignReceivablesRep.PostDataSource(dto));
  647. }
  648. /// <summary>
  649. /// 对外收款账单
  650. /// 账单详情
  651. /// </summary>
  652. /// <param name="dto"></param>
  653. /// <returns></returns>
  654. [HttpPost]
  655. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  656. public async Task<IActionResult> PostGroupReceivablesInfoByDiId(ForForeignReceivablesNewDto dto)
  657. {
  658. try
  659. {
  660. Result ffrData = await _ForForeignReceivablesRep.PostGroupReceivablesInfoByDiId(dto);
  661. if (ffrData.Code != 0)
  662. {
  663. return Ok(JsonView(false, ffrData.Msg));
  664. }
  665. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  666. }
  667. catch (Exception ex)
  668. {
  669. return Ok(JsonView(false, ex.Message));
  670. }
  671. }
  672. /// <summary>
  673. /// 对外收款账单
  674. /// 添加 And 更新
  675. /// </summary>
  676. /// <param name="dto"></param>
  677. /// <returns></returns>
  678. [HttpPost]
  679. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  680. public async Task<IActionResult> PostReceivablesSave(ForeignReceivablesSaveDto dto)
  681. {
  682. try
  683. {
  684. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesSave(dto);
  685. if (ffrData.Code != 0)
  686. {
  687. return Ok(JsonView(false, ffrData.Msg));
  688. }
  689. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  690. }
  691. catch (Exception ex)
  692. {
  693. return Ok(JsonView(false, ex.Message));
  694. throw;
  695. }
  696. }
  697. /// <summary>
  698. /// 已收账单
  699. /// 删除
  700. /// </summary>
  701. /// <param name="dto"></param>
  702. /// <returns></returns>
  703. [HttpPost]
  704. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  705. public async Task<IActionResult> PostReceivablesDel(ForeignReceivablesDelDto dto)
  706. {
  707. try
  708. {
  709. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesDel(dto);
  710. if (ffrData.Code != 0)
  711. {
  712. return Ok(JsonView(false, ffrData.Msg));
  713. }
  714. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  715. }
  716. catch (Exception ex)
  717. {
  718. return Ok(JsonView(false, ex.Message));
  719. throw;
  720. }
  721. }
  722. /// <summary>
  723. /// 已收账单
  724. /// File Downloasd
  725. /// Init
  726. /// </summary>
  727. /// <param name="dto"></param>
  728. /// <returns></returns>
  729. [HttpPost]
  730. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  731. public async Task<IActionResult> PostReceivablesFeilDownloadInit()
  732. {
  733. return Ok(JsonView(true, "操作成功!", new List<dynamic> {
  734. new { Id = 1, Name = "生成收款单(四川)" },
  735. new { Id = 2, Name = "生成收款单(北京)" },
  736. new { Id = 3, Name = "汇款账单" }
  737. }
  738. ));
  739. }
  740. /// <summary>
  741. /// 已收账单
  742. /// File Downloasd
  743. /// </summary>
  744. /// <param name="dto"></param>
  745. /// <returns></returns>
  746. [HttpPost]
  747. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  748. public async Task<IActionResult> PostReceivablesFeilDownload(ForeignReceivablesFeilDownloadDto dto)
  749. {
  750. try
  751. {
  752. if (dto.DiId < 1)
  753. {
  754. return Ok(JsonView(false, "请传入有效DiId参数!"));
  755. }
  756. if (dto.FileType < 1 || dto.FileType > 3)
  757. {
  758. return Ok(JsonView(false, "请传入有效FileType参数! 1 生成收款单(四川) 2 生成收款单(北京) 3 汇款账单"));
  759. }
  760. var _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == dto.DiId).First();
  761. if (_DelegationInfo == null)
  762. {
  763. return Ok(JsonView(false, "暂无团组信息!!"));
  764. }
  765. if (dto.FileType == 1 || dto.FileType == 2)
  766. {
  767. var _ForeignReceivables = _sqlSugar.Queryable<Fin_ForeignReceivables>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
  768. if (_ForeignReceivables.Count < 1)
  769. {
  770. return Ok(JsonView(false, "暂无收款信息!!"));
  771. }
  772. string tempName = "";
  773. if (dto.FileType == 1) tempName = $"收款账单(四川)模板.docx";
  774. else if (dto.FileType == 2) tempName = $"收款账单(北京)模板.docx";
  775. string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/{tempName}";
  776. //载入模板
  777. Document doc = new Document(tempPath);
  778. DocumentBuilder builder = new DocumentBuilder(doc);
  779. #region 替换Word模板书签内容
  780. //这里可以创建个DataTable循环添加书签的值,这里提示一下就不多做修改了
  781. //付款方
  782. if (doc.Range.Bookmarks["To"] != null)
  783. {
  784. Bookmark mark = doc.Range.Bookmarks["To"];
  785. mark.Text = _ForeignReceivables[0].To == null ? "" : _ForeignReceivables[0].To.ToString();
  786. }
  787. //付款方电话
  788. if (doc.Range.Bookmarks["ToTel"] != null)
  789. {
  790. Bookmark mark = doc.Range.Bookmarks["ToTel"];
  791. mark.Text = _ForeignReceivables[0].ToTel == null ? "" : _ForeignReceivables[0].ToTel.ToString();
  792. }
  793. //导出时间
  794. if (doc.Range.Bookmarks["Date"] != null)
  795. {
  796. Bookmark mark = doc.Range.Bookmarks["Date"];
  797. mark.Text = DateTime.Now.ToString("yyyy-MM-dd");
  798. }
  799. //注
  800. if (doc.Range.Bookmarks["Attention"] != null)
  801. {
  802. Bookmark mark = doc.Range.Bookmarks["Attention"];
  803. mark.Text = _ForeignReceivables[0].Attention == null ? "" : _ForeignReceivables[0].Attention.ToString();
  804. }
  805. //团队名称
  806. if (doc.Range.Bookmarks["Team"] != null)
  807. {
  808. Bookmark mark = doc.Range.Bookmarks["Team"];
  809. mark.Text = _DelegationInfo.VisitCountry == null ? "" : _DelegationInfo.VisitCountry.Replace("|", "、").ToString();
  810. }
  811. //付款日期
  812. if (doc.Range.Bookmarks["PayDate"] != null)
  813. {
  814. Bookmark mark = doc.Range.Bookmarks["PayDate"];
  815. mark.Text = _ForeignReceivables[0].PayDate == null ? "" : Convert.ToDateTime(_ForeignReceivables[0].PayDate).ToString("yyyy年MM月dd日");
  816. }
  817. decimal sumPrice = 0;
  818. //各项费用
  819. if (doc.Range.Bookmarks["PayItemContent"] != null)
  820. {
  821. string items = "";
  822. foreach (var fr in _ForeignReceivables)
  823. {
  824. var currInfo = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == fr.Currency).First();
  825. items += $"{fr.PriceName} {currInfo?.Name} {fr.Price.ToString("#0.00")} * {fr.Count} {fr.Unit} * {fr.Rate}.................. RMB {fr.ItemSumPrice.ToString("#0.00")}\n";
  826. sumPrice += fr.ItemSumPrice;
  827. }
  828. Bookmark mark = doc.Range.Bookmarks["PayItemContent"];
  829. mark.Text = items;
  830. }
  831. //合计
  832. if (doc.Range.Bookmarks["Total"] != null)
  833. {
  834. Bookmark mark = doc.Range.Bookmarks["Total"];
  835. mark.Text = sumPrice.ToString("#0.00");
  836. }
  837. #endregion
  838. //文件名
  839. string strFileName = _DelegationInfo.TeamName + "-收款账单.docx";
  840. //去水印
  841. new Aspose.Words.License().SetLicense(new MemoryStream(Convert.FromBase64String(AsposeHelper.asposeKey)));
  842. doc.Save(AppSettingsHelper.Get("WordBasePath") + "ForeignReceivables/File/" + strFileName);
  843. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/ForeignReceivables/File/" + strFileName;
  844. return Ok(JsonView(true, "成功", new { Url = url }));
  845. }
  846. else if (dto.FileType == 3) //汇款通知
  847. {
  848. var _EnterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  849. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId && it.NationalTravelFeeId > 0).ToList();
  850. if (_EnterExitCosts == null)
  851. {
  852. return Ok(JsonView(false, "该团组未填写出入境费用;"));
  853. }
  854. var _cityFee = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  855. foreach (var item in _DayAndCosts)
  856. {
  857. var cityInfo = _cityFee.Where(it => it.Id == item.NationalTravelFeeId).FirstOrDefault();
  858. if (cityInfo != null)
  859. {
  860. if (cityInfo.City.Contains("全部城市") || cityInfo.City.Contains("其他城市"))
  861. {
  862. item.Place = cityInfo.Country;
  863. }
  864. else item.Place = cityInfo.City;
  865. }
  866. }
  867. //数据源
  868. List<Grp_DayAndCost> dac1 = _DayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  869. List<Grp_DayAndCost> dac2 = _DayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  870. List<Grp_DayAndCost> dac3 = _DayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  871. List<Grp_DayAndCost> dac4 = _DayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  872. //币种Data
  873. var currData = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  874. var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  875. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  876. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  877. .Where((tcl, dc, cc) => tcl.IsDel == 0 && tcl.DiId == dto.DiId)
  878. .Select((tcl, dc, cc) => new
  879. {
  880. Name = dc.LastName + dc.FirstName,
  881. Sex = dc.Sex,
  882. Birthday = dc.BirthDay,
  883. Company = cc.CompanyFullName,
  884. Job = dc.Job,
  885. AirType = tcl.ShippingSpaceTypeId
  886. })
  887. .ToList();
  888. if (DeleClientList.Count < 1)
  889. {
  890. return Ok(JsonView(false, "暂无团组成员,请先填写团组成员!!!"));
  891. }
  892. var _ClientNames = DeleClientList.Select(x => x.Name).ToList();
  893. var _GroupClient = DeleClientList.GroupBy(x => x.Company).ToList();
  894. Dictionary<string, string> bookmarkArr = null;
  895. string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/汇款通知.docx";
  896. //载入模板
  897. Document doc = new Document(tempPath);
  898. DocumentBuilder builder = null;
  899. List<string> filesToZip = new List<string>();
  900. foreach (var ClientItem in _GroupClient) //遍历单位
  901. {
  902. doc = new Document(tempPath);
  903. builder = new DocumentBuilder(doc);
  904. Paragraph paragraph = new Paragraph(doc);
  905. bookmarkArr = new Dictionary<string, string>();
  906. bookmarkArr.Add("titleClientUnit", ClientItem.Key); //title单位
  907. bookmarkArr.Add("ClientUnit", ClientItem.Key); //单位
  908. bookmarkArr.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));//出发日期
  909. bookmarkArr.Add("name", string.Join(",", ClientItem.Select(x => x.Name).ToArray()).TrimEnd(','));//全部人员信息
  910. bookmarkArr.Add("VisitCountry", _DelegationInfo.VisitCountry.Replace("|", "、"));//出访国家
  911. bookmarkArr.Add("dayTime", DateTime.Now.ToString("yyyy年MM月dd日"));//今天日期
  912. var ClientItemList = ClientItem.ToList();
  913. string UsersTop = string.Empty;//word中人员以及金额
  914. decimal WordAllPrice = 0.00M;
  915. //int[] infoColumn = new int[5] {dac1.Select(x=>x.Place.Length).ToList().Max(),2, dac1.Select(x => x.Cost.Length).Max() + dac1.Select(x => x.Currency.Length).Max(),
  916. // 6, 3 + dac1.Where(x=>!string.IsNullOrWhiteSpace(x.Place)).Select(x=>(Convert.ToDecimal(x.SubTotal) / Convert.ToDecimal(x.Cost)).ToString().Length).Max() };
  917. //遍历人员
  918. for (int i = 0; i < ClientItemList.Count(); i++)
  919. {
  920. Dictionary<string, string> TeableBookmarkArr = new Dictionary<string, string>();
  921. var client = ClientItemList[i]; //每个人员
  922. var firstName = ClientItemList[i].Name;
  923. //计算费用总和
  924. decimal airPrice = client.AirType == 460 ? _EnterExitCosts.AirJJ : _EnterExitCosts.AirGW;
  925. decimal AllPrice = airPrice + _EnterExitCosts.CityTranffic + dac1.Sum(x => x.SubTotal) + dac2.Sum(x => x.SubTotal) +
  926. dac3.Sum(x => x.SubTotal) + dac4.Sum(x => x.SubTotal) + _EnterExitCosts.Visa + _EnterExitCosts.Safe +
  927. +_EnterExitCosts.YiMiao + _EnterExitCosts.YiMiao + _EnterExitCosts.Ticket + _EnterExitCosts.Service;
  928. WordAllPrice += AllPrice;
  929. UsersTop += firstName + "出访费用为¥" + AllPrice.ToString("#0.00") + "元、";
  930. TeableBookmarkArr.Add("jp", (client.AirType == 460 ? _EnterExitCosts.AirJJ : _EnterExitCosts.AirGW).ToString("#0.00") + " 元"); //机票金额
  931. TeableBookmarkArr.Add("cs", _EnterExitCosts.CityTranffic.ToString("#0.00") + " 元"); //城市交通费用
  932. TeableBookmarkArr.Add("zs", dac1.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //住宿费
  933. string zsinfo = string.Empty;
  934. string hsinfo = string.Empty;
  935. string gzinfo = string.Empty;
  936. List<string> placeArr = new List<string>();
  937. Aspose.Words.Tables.Table FirstTable = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
  938. Aspose.Words.Tables.Table ChildTable = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 0, true);
  939. Aspose.Words.Tables.Table ChildTable1 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 1, true);
  940. Aspose.Words.Tables.Table ChildTable2 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 2, true);
  941. int rowIndex = 0;
  942. foreach (var item in dac1)
  943. {
  944. if (string.IsNullOrWhiteSpace(item.Place))
  945. {
  946. continue;
  947. }
  948. if (placeArr.Contains(item.Place))
  949. {
  950. continue;
  951. }
  952. else
  953. {
  954. placeArr.Add(item.Place);
  955. }
  956. if (!string.IsNullOrWhiteSpace(item.Place))
  957. {
  958. if (rowIndex > ChildTable.Rows.Count - 1)
  959. {
  960. var chitableRow = ChildTable.LastRow.Clone(true);
  961. ChildTable.AppendChild(chitableRow);
  962. }
  963. int days = dac1.FindAll(x => x.Place == item.Place).Count();
  964. SetCells(ChildTable, doc, rowIndex, 0, item.Place);
  965. SetCells(ChildTable, doc, rowIndex, 1, days + "晚");
  966. string currencyCode = currData.Find(it => it.Id == item.Currency)?.Remark ?? "Unknown";
  967. SetCells(ChildTable, doc, rowIndex, 2, item.Cost.ToString("#0.00") + currencyCode + "/晚");
  968. SetCells(ChildTable, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  969. SetCells(ChildTable, doc, rowIndex, 4, "CNY" + item.SubTotal + "\r\n");
  970. rowIndex++;
  971. zsinfo += item.Place + " " + days + "晚 " + item.Cost.ToString("#0.00") + currencyCode + "/晚" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.0000") + " CNY" + item.SubTotal * days + "\r\n";
  972. }
  973. }
  974. placeArr.Clear();
  975. rowIndex = 0;
  976. foreach (var item in dac2)
  977. {
  978. if (string.IsNullOrWhiteSpace(item.Place))
  979. {
  980. continue;
  981. }
  982. if (placeArr.Contains(item.Place))
  983. {
  984. continue;
  985. }
  986. else
  987. {
  988. placeArr.Add(item.Place);
  989. }
  990. if (!string.IsNullOrWhiteSpace(item.Place))
  991. {
  992. if (rowIndex > ChildTable1.Rows.Count - 1)
  993. {
  994. var chitableRow = ChildTable1.LastRow.Clone(true);
  995. ChildTable1.AppendChild(chitableRow);
  996. }
  997. int days = dac2.FindAll(x => x.Place == item.Place).Count();
  998. SetCells(ChildTable1, doc, rowIndex, 0, item.Place);
  999. SetCells(ChildTable1, doc, rowIndex, 1, days + "天");
  1000. string currencyCode = currData.Find(it => it.Id == item.Currency)?.Remark ?? "Unknown";
  1001. SetCells(ChildTable1, doc, rowIndex, 2, item.Cost.ToString("#0.00") + currencyCode + "/天");
  1002. SetCells(ChildTable1, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  1003. SetCells(ChildTable1, doc, rowIndex, 4, "CNY" + item.SubTotal);
  1004. rowIndex++;
  1005. hsinfo += item.Place + " " + days + "天 " + item.Cost.ToString("#0.00") + currencyCode + "/天" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.0000") + " CNY" + item.SubTotal * days + "\r\n";
  1006. }
  1007. }
  1008. placeArr.Clear();
  1009. rowIndex = 0;
  1010. foreach (var item in dac3)
  1011. {
  1012. if (string.IsNullOrWhiteSpace(item.Place))
  1013. {
  1014. continue;
  1015. }
  1016. if (placeArr.Contains(item.Place))
  1017. {
  1018. continue;
  1019. }
  1020. else
  1021. {
  1022. placeArr.Add(item.Place);
  1023. }
  1024. if (!string.IsNullOrWhiteSpace(item.Place))
  1025. {
  1026. if (rowIndex > ChildTable2.Rows.Count - 1)
  1027. {
  1028. var chitableRow = ChildTable2.LastRow.Clone(true);
  1029. ChildTable2.AppendChild(chitableRow);
  1030. }
  1031. int days = dac3.FindAll(x => x.Place == item.Place).Count();
  1032. SetCells(ChildTable2, doc, rowIndex, 0, item.Place);
  1033. SetCells(ChildTable2, doc, rowIndex, 1, days + "天");
  1034. string currencyCode = currData.Find(it => it.Id == item.Currency)?.Remark ?? "Unknown";
  1035. SetCells(ChildTable2, doc, rowIndex, 2, item.Cost.ToString("#0.00") + currencyCode + "/天");
  1036. SetCells(ChildTable2, doc, rowIndex, 3, " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00"));
  1037. SetCells(ChildTable2, doc, rowIndex, 4, "CNY" + item.SubTotal + "\r\n");
  1038. rowIndex++;
  1039. gzinfo += item.Place + " " + days + "天 " + item.Cost.ToString("#0.00") + currencyCode + "/天" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00") + " CNY" + item.SubTotal * days + "\r\n";
  1040. }
  1041. }
  1042. placeArr.Clear();
  1043. TeableBookmarkArr.Add("zsinfo", zsinfo); //住宿费详情
  1044. TeableBookmarkArr.Add("hs", dac2.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //伙食费
  1045. TeableBookmarkArr.Add("hsinfo", hsinfo); //伙食费详情
  1046. TeableBookmarkArr.Add("gz", dac3.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //公杂费
  1047. TeableBookmarkArr.Add("gzinfo", gzinfo); //公杂费详情
  1048. string otherFeestr = "";
  1049. decimal otherFee = 0.00M;
  1050. if (_EnterExitCosts.Visa > 0.00M)
  1051. {
  1052. otherFee += _EnterExitCosts.Visa;
  1053. otherFeestr += $"签证费{_EnterExitCosts.Visa.ToString("#0.00")}元、";
  1054. }
  1055. if (_EnterExitCosts.YiMiao > 0.00M)
  1056. {
  1057. otherFee += _EnterExitCosts.YiMiao;
  1058. otherFeestr += $"疫苗费{_EnterExitCosts.YiMiao.ToString("#0.00")}元、";
  1059. }
  1060. if (_EnterExitCosts.HeSuan > 0.00M)
  1061. {
  1062. otherFee += _EnterExitCosts.HeSuan;
  1063. otherFeestr += $"核酸检测费{_EnterExitCosts.HeSuan.ToString("#0.00")}元、";
  1064. }
  1065. if (_EnterExitCosts.Safe > 0.00M)
  1066. {
  1067. otherFee += _EnterExitCosts.Safe;
  1068. otherFeestr += $"保险费{_EnterExitCosts.Safe.ToString("#0.00")}元、";
  1069. }
  1070. if (_EnterExitCosts.Ticket > 0.00M)
  1071. {
  1072. otherFee += _EnterExitCosts.Ticket;
  1073. otherFeestr += $"参展门票费{_EnterExitCosts.Ticket.ToString("#0.00")}元、";
  1074. }
  1075. if (otherFeestr.Length > 0)
  1076. {
  1077. otherFeestr = otherFeestr.Substring(0, otherFeestr.Length - 1);
  1078. otherFeestr += "等费用";
  1079. }
  1080. TeableBookmarkArr.Add("qt", otherFee.ToString("#0.00") + " 元");//其他费用
  1081. TeableBookmarkArr.Add("qtinfo", otherFeestr);//其他费用第二列
  1082. TeableBookmarkArr.Add("fw", _EnterExitCosts.Service.ToString("#0.00") + "元/人");//服务费
  1083. TeableBookmarkArr.Add("AllPrice", AllPrice.ToString("#0.00") + "元/人");//表格合计费用
  1084. string airStr = client.AirType == 460 ? "经济舱" : client.AirType == 458 ? "公务舱" : "";
  1085. TeableBookmarkArr.Add("title", $"费用清单-{airStr}({firstName})");
  1086. foreach (var book in TeableBookmarkArr.Keys)
  1087. {
  1088. if (doc.Range.Bookmarks[book] != null)
  1089. {
  1090. Bookmark mark = doc.Range.Bookmarks[book];
  1091. mark.Text = TeableBookmarkArr[book];
  1092. }
  1093. }
  1094. if (i != ClientItemList.Count - 1)
  1095. {
  1096. builder.PageSetup.Orientation = Aspose.Words.Orientation.Portrait;
  1097. Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
  1098. table.ParentNode.InsertAfter(paragraph, table);
  1099. var CloneTable = (Aspose.Words.Tables.Table)table.Clone(true);
  1100. table.ParentNode.InsertAfter(CloneTable, paragraph);
  1101. }
  1102. TeableBookmarkArr.Clear();
  1103. }
  1104. bookmarkArr.Add("VisitPrice", WordAllPrice.ToString());//出访费用总额
  1105. bookmarkArr.Add("CnAllPrice", WordAllPrice.ConvertCNYUpper());//出访费用总额中文
  1106. bookmarkArr.Add("namesPrice", UsersTop.TrimEnd('、'));//各人员出访费用 付辰同志出访费用为¥73,604.8元
  1107. foreach (var book in bookmarkArr.Keys)
  1108. {
  1109. if (doc.Range.Bookmarks[book] != null)
  1110. {
  1111. Bookmark mark = doc.Range.Bookmarks[book];
  1112. mark.Text = bookmarkArr[book];
  1113. }
  1114. }
  1115. //MemoryStream outSteam = new MemoryStream();
  1116. string filsPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/File/{ClientItem.Key.Replace("\n", "")}.docx";
  1117. //去水印
  1118. new Aspose.Words.License().SetLicense(new MemoryStream(Convert.FromBase64String(AsposeHelper.asposeKey)));
  1119. doc.Save(filsPath);
  1120. filesToZip.Add(filsPath);
  1121. //streams.Add(ClientItem.Key + ".docx", outSteam.ToArray());
  1122. }
  1123. //文件名
  1124. string zipFileName = _DelegationInfo.TeamName + "-收款账单.zip";
  1125. string zipPath = $"ForeignReceivables/File/{_DelegationInfo.TeamName}-收款账单{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
  1126. try
  1127. {
  1128. using (var zip = ZipFile.Open(AppSettingsHelper.Get("WordBasePath") + zipPath, ZipArchiveMode.Create))
  1129. {
  1130. foreach (var file in filesToZip)
  1131. {
  1132. zip.CreateEntryFromFile(file, Path.GetFileName(file));
  1133. }
  1134. }
  1135. }
  1136. catch (Exception ex)
  1137. {
  1138. return Ok(JsonView(false, ex.Message));
  1139. }
  1140. string url = AppSettingsHelper.Get("WordBaseUrl") + $"Office/Word/{zipPath}";
  1141. return Ok(JsonView(true, "成功", new { Url = url }));
  1142. }
  1143. return Ok(JsonView(false, "操作失败!"));
  1144. }
  1145. catch (Exception ex)
  1146. {
  1147. return Ok(JsonView(false, ex.Message));
  1148. }
  1149. }
  1150. private void SetCells(Aspose.Words.Tables.Table table, Document doc, int rows, int cells, string val)
  1151. {
  1152. //获取table中的某个单元格,从0开始
  1153. Aspose.Words.Tables.Cell lshCell = table.Rows[rows].Cells[cells];
  1154. //将单元格中的第一个段落移除
  1155. lshCell.FirstParagraph.Remove();
  1156. //新建一个段落
  1157. Paragraph p = new Paragraph(doc);
  1158. var r = new Run(doc, val);
  1159. r.Font.Size = 8;
  1160. //把设置的值赋给之前新建的段落
  1161. p.AppendChild(r);
  1162. //将此段落加到单元格内
  1163. lshCell.AppendChild(p);
  1164. }
  1165. #endregion
  1166. #region 已收款项
  1167. /// <summary>
  1168. /// 已收款项
  1169. /// 查询
  1170. /// </summary>
  1171. /// <param name="dto"></param>
  1172. /// <returns></returns>
  1173. [HttpPost]
  1174. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1175. public async Task<IActionResult> PostAmountReceived(AmountReceivedDto dto)
  1176. {
  1177. try
  1178. {
  1179. if (dto == null)
  1180. {
  1181. return Ok(JsonView(false, "参数不能为空!"));
  1182. }
  1183. Result ffrData = await _proceedsReceivedRep.PostAmountReceived(dto.DiId);
  1184. dynamic data = null;
  1185. if (dto.PortType == 1)
  1186. {
  1187. if (ffrData.Code != 0)
  1188. {
  1189. return Ok(JsonView(false, ffrData.Msg));
  1190. }
  1191. data = ffrData.Data;
  1192. }
  1193. else if (dto.PortType == 2)
  1194. {
  1195. if (ffrData.Code != 0)
  1196. {
  1197. return Ok(JsonView(false, ffrData.Msg));
  1198. }
  1199. data = ffrData.Data;
  1200. }
  1201. else if (dto.PortType == 2)
  1202. {
  1203. if (ffrData.Code != 0)
  1204. {
  1205. return Ok(JsonView(false, ffrData.Msg));
  1206. }
  1207. data = ffrData.Data;
  1208. }
  1209. else
  1210. {
  1211. return Ok(JsonView(false, "请选择正确的端口号!"));
  1212. }
  1213. return Ok(JsonView(true, "操作成功!", data));
  1214. }
  1215. catch (Exception ex)
  1216. {
  1217. return Ok(JsonView(false, ex.Message));
  1218. }
  1219. }
  1220. /// <summary>
  1221. /// 已收款项
  1222. /// Add Or Edit
  1223. /// </summary>
  1224. /// <param name="dto"></param>
  1225. /// <returns></returns>
  1226. [HttpPost]
  1227. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1228. public async Task<IActionResult> PostAmountReceivedAddOrEdit(AmountReceivedAddOrEditDto dto)
  1229. {
  1230. try
  1231. {
  1232. if (dto == null)
  1233. {
  1234. return Ok(JsonView(false, "参数不能为空!"));
  1235. }
  1236. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedAddOrEditDto(dto);
  1237. if (dto.PortType == 1)
  1238. {
  1239. if (ffrData.Code != 0)
  1240. {
  1241. return Ok(JsonView(false, ffrData.Msg));
  1242. }
  1243. }
  1244. else if (dto.PortType == 2)
  1245. {
  1246. if (ffrData.Code != 0)
  1247. {
  1248. return Ok(JsonView(false, ffrData.Msg));
  1249. }
  1250. }
  1251. else if (dto.PortType == 2)
  1252. {
  1253. if (ffrData.Code != 0)
  1254. {
  1255. return Ok(JsonView(false, ffrData.Msg));
  1256. }
  1257. }
  1258. else
  1259. {
  1260. return Ok(JsonView(false, "请选择正确的端口号!"));
  1261. }
  1262. return Ok(JsonView(true, "操作成功!"));
  1263. }
  1264. catch (Exception ex)
  1265. {
  1266. return Ok(JsonView(false, ex.Message));
  1267. }
  1268. }
  1269. /// <summary>
  1270. /// 已收款项
  1271. /// Del
  1272. /// </summary>
  1273. /// <param name="dto"></param>
  1274. /// <returns></returns>
  1275. [HttpPost]
  1276. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1277. public async Task<IActionResult> PostAmountReceived_Del(AmountReceivedDelDto dto)
  1278. {
  1279. try
  1280. {
  1281. if (dto == null)
  1282. {
  1283. return Ok(JsonView(false, "参数不能为空!"));
  1284. }
  1285. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedDel(dto);
  1286. if (ffrData.Code != 0)
  1287. {
  1288. return Ok(JsonView(false, ffrData.Msg));
  1289. }
  1290. return Ok(JsonView(true, "操作成功!"));
  1291. }
  1292. catch (Exception ex)
  1293. {
  1294. return Ok(JsonView(false, ex.Message));
  1295. }
  1296. }
  1297. #endregion
  1298. #region 收款退还与其他款项 --> 收款退还
  1299. /// <summary>
  1300. /// 收款退还与其他款项
  1301. /// 查询 根据团组Id
  1302. /// </summary>
  1303. /// <param name="dto"></param>
  1304. /// <returns></returns>
  1305. [HttpPost]
  1306. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1307. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyItemByDiId(PaymentRefundAndOtherMoneyItemByDiIdDto dto)
  1308. {
  1309. try
  1310. {
  1311. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1312. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1313. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1314. #region 页面功能权限处理
  1315. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1316. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1317. if (pageFunAuth.CheckAuth == 0)
  1318. {
  1319. return Ok(JsonView(false, "您没有当前页面查询权限!"));
  1320. }
  1321. #endregion
  1322. Result _result = await _paymentRefundAndOtherMoneyRep._ItemByDiId(dto.DiId);
  1323. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //1 Web 2 Android 3 Ios
  1324. {
  1325. if (_result.Code != 0)
  1326. {
  1327. return Ok(JsonView(false, _result.Msg));
  1328. }
  1329. var data = new
  1330. {
  1331. PageFuncAuth = pageFunAuth,
  1332. Data = _result.Data
  1333. };
  1334. return Ok(JsonView(true, "操作成功!", data));
  1335. }
  1336. else
  1337. {
  1338. return Ok(JsonView(false, "请输入正确的端口号! 1 Web 2 Android 3 Ios;"));
  1339. }
  1340. }
  1341. catch (Exception ex)
  1342. {
  1343. return Ok(JsonView(false, ex.Message));
  1344. }
  1345. }
  1346. /// <summary>
  1347. /// 收款退还与其他款项
  1348. /// 删除
  1349. /// </summary>
  1350. /// <param name="dto"></param>
  1351. /// <returns></returns>
  1352. [HttpPost]
  1353. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1354. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyDel(PaymentRefundAndOtherMoneyDelDto dto)
  1355. {
  1356. try
  1357. {
  1358. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1359. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1360. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1361. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1362. #region 页面功能权限处理
  1363. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1364. #endregion
  1365. if (pageFunAuth.DeleteAuth == 0)
  1366. {
  1367. return Ok(JsonView(false, "您没有当前页面删除权限!"));
  1368. }
  1369. Result _result = await _paymentRefundAndOtherMoneyRep._Del(dto);
  1370. if (_result.Code != 0)
  1371. {
  1372. return Ok(JsonView(false, _result.Msg));
  1373. }
  1374. return Ok(JsonView(true, "操作成功!"));
  1375. }
  1376. catch (Exception ex)
  1377. {
  1378. return Ok(JsonView(false, ex.Message));
  1379. }
  1380. }
  1381. /// <summary>
  1382. /// 收款退还与其他款项
  1383. /// Info Data Source
  1384. /// </summary>
  1385. /// <param name="dto"></param>
  1386. /// <returns></returns>
  1387. [HttpPost]
  1388. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1389. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyInfoDataSource(PortDtoBase dto)
  1390. {
  1391. try
  1392. {
  1393. Result _result = await _paymentRefundAndOtherMoneyRep._InfoDataSource(dto);
  1394. if (_result.Code != 0)
  1395. {
  1396. return Ok(JsonView(false, _result.Msg));
  1397. }
  1398. return Ok(JsonView(true, "查询成功!", _result.Data));
  1399. }
  1400. catch (Exception ex)
  1401. {
  1402. return Ok(JsonView(false, ex.Message));
  1403. }
  1404. }
  1405. /// <summary>
  1406. /// 收款退还与其他款项
  1407. /// Info
  1408. /// </summary>
  1409. /// <param name="dto"></param>
  1410. /// <returns></returns>
  1411. [HttpPost]
  1412. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1413. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyInfo(PaymentRefundAndOtherMoneyInfoDto dto)
  1414. {
  1415. try
  1416. {
  1417. if (dto == null)
  1418. {
  1419. return Ok(JsonView(false, "参数不能为空!"));
  1420. }
  1421. Result _result = await _paymentRefundAndOtherMoneyRep._Info(dto);
  1422. if (_result.Code != 0)
  1423. {
  1424. return Ok(JsonView(false, _result.Msg));
  1425. }
  1426. return Ok(JsonView(true, "查询成功!", _result.Data));
  1427. }
  1428. catch (Exception ex)
  1429. {
  1430. return Ok(JsonView(false, ex.Message));
  1431. }
  1432. }
  1433. /// <summary>
  1434. /// 收款退还与其他款项 --> 收款退还(只保留人名币)
  1435. /// 操作(Add Or Edit)
  1436. /// </summary>
  1437. /// <param name="dto"></param>
  1438. /// <returns></returns>
  1439. [HttpPost]
  1440. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1441. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyAddOrEdit(PaymentRefundAndOtherMoneyAddOrEditDto dto)
  1442. {
  1443. try
  1444. {
  1445. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1446. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1447. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1448. #region 页面功能权限处理
  1449. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1450. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1451. #endregion
  1452. if (dto.Status == 1) //add
  1453. {
  1454. if (pageFunAuth.AddAuth == 0)
  1455. {
  1456. return Ok(JsonView(false, "您没有当前页面添加权限!"));
  1457. }
  1458. }
  1459. else if (dto.Status == 2) //edit
  1460. {
  1461. if (pageFunAuth.EditAuth == 0)
  1462. {
  1463. return Ok(JsonView(false, "您没有当前页面编辑权限!"));
  1464. }
  1465. }
  1466. else
  1467. {
  1468. return Ok(JsonView(false, "请输入正确的操作状态! 1 添加 2 修改!"));
  1469. }
  1470. Result _result = await _paymentRefundAndOtherMoneyRep._AddOrEdit(dto);
  1471. if (_result.Code != 0)
  1472. {
  1473. return Ok(JsonView(false, _result.Msg));
  1474. }
  1475. return Ok(JsonView(true, "操作成功!"));
  1476. }
  1477. catch (Exception ex)
  1478. {
  1479. return Ok(JsonView(false, ex.Message));
  1480. }
  1481. }
  1482. #endregion
  1483. #region 应收报表
  1484. /// <summary>
  1485. /// 应收报表
  1486. /// 查询 根据日期范围
  1487. /// </summary>
  1488. /// <param name="dto"></param>
  1489. /// <returns></returns>
  1490. [HttpPost]
  1491. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1492. public async Task<IActionResult> PostSyntheticalReceivableByDateRange(PostSyntheticalReceivableByDateRangeDto dto)
  1493. {
  1494. string sqlWhere = " Where di.IsDel=0 ";
  1495. #region 验证
  1496. if (string.IsNullOrEmpty(dto.beginDt) && string.IsNullOrEmpty(dto.endDt))
  1497. {
  1498. return Ok(JsonView(false, "日期参数至少填写一个!"));
  1499. }
  1500. if (!string.IsNullOrEmpty(dto.beginDt))
  1501. {
  1502. if (Regex.Match(dto.beginDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
  1503. {
  1504. return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
  1505. }
  1506. else
  1507. {
  1508. sqlWhere += string.Format(@" And di.VisitDate >= '{0} 00:00:00' ", dto.beginDt);
  1509. }
  1510. }
  1511. if (!string.IsNullOrEmpty(dto.endDt))
  1512. {
  1513. if (Regex.Match(dto.endDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
  1514. {
  1515. return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
  1516. }
  1517. else
  1518. {
  1519. sqlWhere += string.Format(@" And di.VisitDate <= '{0} 23:59:59' ", dto.endDt);
  1520. }
  1521. }
  1522. #endregion
  1523. //已收款项 判断如果是市场部的人员进来的话 只显示自己的 其他的都显示全部的
  1524. string userSqlWhere = "";
  1525. var userInfos = await _sqlSugar.Queryable<Sys_Users>()
  1526. .InnerJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  1527. .Where((u, d) => u.IsDel == 0 && d.DepName.Contains("市场部") && u.Id == dto.CurrUserId)
  1528. .ToListAsync();
  1529. if (userInfos.Count > 0) userSqlWhere = string.Format(@$" And JietuanOperator={dto.CurrUserId} ");
  1530. //排序倒序
  1531. string sql = string.Format(@$"select distinct fr.diid,di.TeamName,di.ClientUnit,di.VisitDate,di.CreateTime from Fin_ForeignReceivables fr join Grp_DelegationInfo di on fr.DIID = di.id {sqlWhere} {userSqlWhere} Order By di.VisitDate Desc");
  1532. List<PostSyntheticalReceivableByDateRangeView> list_rst = _sqlSugar.SqlQueryable<PostSyntheticalReceivableByDateRangeView>(sql).ToList();
  1533. var setData = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToList();
  1534. decimal sumAll_fr = 0M; //应收
  1535. decimal sumAll_pr = 0M; //已收
  1536. decimal sumAll_balance = 0M; //尾款
  1537. if (list_rst.Count > 0)
  1538. {
  1539. int rowNumber = 1;
  1540. foreach (var item_rst in list_rst)
  1541. {
  1542. DateTime dtTemp;
  1543. bool b = DateTime.TryParse(item_rst.visitDate, out dtTemp);
  1544. if (b)
  1545. {
  1546. item_rst.visitDate = dtTemp.ToString("yyyy-MM-dd");
  1547. }
  1548. item_rst.No = rowNumber;
  1549. rowNumber++;
  1550. int diId = item_rst.diid;
  1551. decimal sum_fr = 0M;
  1552. decimal sum_pr = 0M;
  1553. string str_client = string.Empty;
  1554. decimal sum_refund = 0M; //收款退还
  1555. decimal sum_extra = 0M; //超支费用
  1556. decimal balance = 0M;
  1557. string str_schedule = string.Empty;
  1558. //1.应收
  1559. string sql_fr = string.Format(@" Select * From Fin_ForeignReceivables Where IsDel=0 And Diid={0} ", diId);
  1560. List<Fin_ForeignReceivables> list_fr = _sqlSugar.SqlQueryable<Fin_ForeignReceivables>(sql_fr).ToList();
  1561. sum_fr = list_fr.Sum(s => s.ItemSumPrice);
  1562. //2.已收
  1563. string sql_pr = string.Format(@" Select * From Fin_ProceedsReceived Where IsDel=0 And Diid={0} ", diId);
  1564. List<Fin_ProceedsReceived> list_pr = _sqlSugar.SqlQueryable<Fin_ProceedsReceived>(sql_pr).ToList();
  1565. foreach (var item_pr in list_pr)
  1566. {
  1567. sum_pr += item_pr.Price;
  1568. str_client += string.Format(@"{0};", item_pr.Client);
  1569. str_schedule += string.Format(@"{0};", item_pr.Remark);
  1570. }
  1571. if (str_schedule.Length > 0)
  1572. {
  1573. str_schedule = str_schedule.TrimEnd(';');
  1574. }
  1575. if (str_client.Length > 0)
  1576. {
  1577. str_client = str_client.TrimEnd(';');
  1578. }
  1579. //3.收款退还
  1580. string sql_other = string.Format(@"Select * From Fin_PaymentRefundAndOtherMoney prao
  1581. Inner Join Grp_CreditCardPayment ccp On prao.Id = ccp.CId
  1582. Where ccp.CTable = 285 And ccp.IsPay = 1 And prao.IsDel = 0 And ccp.IsDel = 0 And prao.DiId = {0}", diId);
  1583. List<Grp_CreditCardPayment> list_other = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_other).ToList();
  1584. sum_refund = list_other.Sum(s => s.RMBPrice);
  1585. //4.超支
  1586. string sql_extra = string.Format(@" Select c.* From Fin_GroupExtraCost f
  1587. Inner join Grp_CreditCardPayment c On f.Id = c.CId
  1588. Where c.CTable = 1015 And c.IsPay = 1 And f.IsDel = 0 And c.IsDel = 0 And f.DiId = {0} ", diId);
  1589. List<Grp_CreditCardPayment> list_extra = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_extra).ToList();
  1590. sum_extra = list_extra.Sum(s => s.RMBPrice);
  1591. item_rst.frPrice = sum_fr.ToString("#0.00");
  1592. item_rst.extraPrice = sum_extra.ToString("#0.00");
  1593. item_rst.receivableTotal = (sum_fr + sum_extra).ToString("#0.00");
  1594. item_rst.prPrice = sum_pr.ToString("#0.00");
  1595. item_rst.refundAmount = sum_refund.ToString("#0.00");
  1596. item_rst.receivedTotal = (sum_pr - sum_refund).ToString("#0.00");
  1597. item_rst.balPrice = ((sum_fr + sum_extra) - (sum_pr - sum_refund)).ToString("#0.00");
  1598. item_rst.prClient = str_client;
  1599. item_rst.schedule = str_schedule;
  1600. string tempVisitDate = Convert.ToDateTime(item_rst.visitDate).ToString("yyyy-MM-dd");
  1601. sumAll_fr += (sum_fr + sum_extra);
  1602. sumAll_pr += (sum_pr - sum_refund);
  1603. sumAll_balance += ((sum_fr + sum_extra) - (sum_pr - sum_refund));
  1604. #region 单位应收已收细项(以应收费用名称为主去(已收费用)匹配) 新增 雷怡 2024-35-08 16:35:28
  1605. List<ClientFeeInfoView> feeDatas = new List<ClientFeeInfoView>();
  1606. //匹配上的数据
  1607. foreach (var item in list_fr)
  1608. {
  1609. var prInfo = list_pr.Find(it => item.PriceName.Contains(it.Client) || item.PriceName.Equals(it.Client));
  1610. decimal _balancePayment = 0.00M;
  1611. if (item.Currency == prInfo?.Currency)
  1612. {
  1613. _balancePayment = item.ItemSumPrice - prInfo?.Price ?? 0.00M;
  1614. }
  1615. feeDatas.Add(new ClientFeeInfoView
  1616. {
  1617. client = item.PriceName,
  1618. frMoney = item.ItemSumPrice.ToString("#0.00"),
  1619. frCurrency = setData.Find(it => it.Id == item.Currency)?.Name ?? "-",
  1620. frRate = item.Rate.ToString("#0.0000"),
  1621. prReceivablesType = setData.Find(it => it.Id == prInfo?.ReceivablesType)?.Name ?? "",
  1622. prTime = prInfo?.SectionTime ?? "-",
  1623. prMoney = prInfo?.Price.ToString("#0.00") ?? "-",
  1624. prCurrency = setData.Find(it => it.Id == prInfo?.Currency)?.Name ?? "",
  1625. balPayment = _balancePayment.ToString("#0.00")
  1626. });
  1627. }
  1628. //未匹配上的数据
  1629. foreach (var item in list_pr)
  1630. {
  1631. var frInfo = list_fr.Find(it => it.PriceName.Contains(item.Client) || it.PriceName.Equals(item.Client));
  1632. if (frInfo == null)
  1633. {
  1634. feeDatas.Add(new ClientFeeInfoView
  1635. {
  1636. client = item.Client + "[未匹配上的已收数据(应收已收公司名称不一致)]",
  1637. frMoney = "0.00",
  1638. frCurrency = "-",
  1639. frRate = "0.0000",
  1640. prReceivablesType = setData.Find(it => it.Id == item?.ReceivablesType)?.Name ?? "",
  1641. prTime = item?.SectionTime ?? "-",
  1642. prMoney = item?.Price.ToString("#0.00") ?? "0.00",
  1643. prCurrency = setData.Find(it => it.Id == item?.Currency)?.Name ?? "",
  1644. balPayment = "0.00"
  1645. });
  1646. }
  1647. }
  1648. item_rst.feeItem = feeDatas;
  1649. #endregion
  1650. }
  1651. PostSyntheticalReceivableByDateRangeResultView result = new PostSyntheticalReceivableByDateRangeResultView();
  1652. result.total_fr = sumAll_fr.ToString("#0.00");
  1653. result.total_pr = sumAll_pr.ToString("#0.00");
  1654. result.total_balance = sumAll_balance.ToString("#0.00");
  1655. result.dataList = new List<PostSyntheticalReceivableByDateRangeView>(list_rst);
  1656. if (dto.requestType == 1)
  1657. {
  1658. return Ok(JsonView(true, "请求成功", result, list_rst.Count));
  1659. }
  1660. else
  1661. {
  1662. //----------------------------
  1663. List<Excel_SyntheticalReceivableByDateRange> list_Ex = new List<Excel_SyntheticalReceivableByDateRange>();
  1664. WorkbookDesigner designer = new WorkbookDesigner();
  1665. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/应收款项模板 - 副本.xls");
  1666. int excNo = 1;
  1667. foreach (var item in list_rst)
  1668. {
  1669. Excel_SyntheticalReceivableByDateRange exc = new Excel_SyntheticalReceivableByDateRange();
  1670. exc.No = excNo.ToString();
  1671. excNo++;
  1672. exc.TeamName = item.teamName;
  1673. exc.ClientUnit = item.clientUnit;
  1674. exc.VisitDate = item.visitDate;
  1675. exc.Accounts = item.frPrice;
  1676. exc.Extra = item.extraPrice;
  1677. exc.ReceivableTotal = item.receivableTotal;
  1678. exc.Received = item.prPrice;
  1679. exc.RefundAmount = item.refundAmount;
  1680. exc.ReceivedTotal = item.receivedTotal;
  1681. exc.Balance = item.balPrice;
  1682. exc.Collection = item.schedule;
  1683. DateTime time = Convert.ToDateTime(item.visitDate);
  1684. TimeSpan ts = DateTime.Now - time;
  1685. float SY = float.Parse(item.balPrice);
  1686. if (ts.Days >= 365 && SY > 0)
  1687. {
  1688. exc.Sign = "需收款";
  1689. }
  1690. else
  1691. {
  1692. exc.Sign = "";
  1693. }
  1694. list_Ex.Add(exc);
  1695. }
  1696. var dt = CommonFun.GetDataTableFromIList(list_Ex);
  1697. dt.TableName = "Excel_SyntheticalReceivableByDateRange";
  1698. if (dt != null)
  1699. {
  1700. designer.SetDataSource("SumPrice", "应收合计:" + result.total_fr + "RMB 已收合计:" + result.total_pr + "RMB 余款合计:" + result.total_balance + "RMB");
  1701. //数据源
  1702. designer.SetDataSource(dt);
  1703. //根据数据源处理生成报表内容
  1704. designer.Process();
  1705. string fileName = ("Receivable/应收款项(" + dto.beginDt + "~" + dto.endDt + ").xlsx");
  1706. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  1707. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  1708. return Ok(JsonView(true, "成功", new { url = rst }));
  1709. }
  1710. }
  1711. }
  1712. return Ok(JsonView(true, "获取成功", "", list_rst.Count));
  1713. }
  1714. #endregion
  1715. #region 付款申请
  1716. /// <summary>
  1717. /// 付款申请
  1718. /// 基础数据
  1719. /// </summary>
  1720. /// <param name="dto"></param>
  1721. /// <returns></returns>
  1722. [HttpPost]
  1723. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1724. public async Task<IActionResult> PostPayRequestInit()
  1725. {
  1726. try
  1727. {
  1728. var conpanyDatas = _sqlSugar.Queryable<Sys_Company>()
  1729. .Where(it => it.IsDel == 0)
  1730. .Select(it => new
  1731. {
  1732. Id = it.Id,
  1733. ConpamyName = it.CompanyName
  1734. }).ToList();
  1735. return Ok(JsonView(true, "操作成功!", new { ConpanyData = conpanyDatas }));
  1736. }
  1737. catch (Exception ex)
  1738. {
  1739. return Ok(JsonView(false, ex.Message));
  1740. }
  1741. }
  1742. /// <summary>
  1743. /// 付款申请 (PageId=51)
  1744. /// 查询 根据日期范围
  1745. /// </summary>
  1746. /// <param name="dto"></param>
  1747. /// <returns></returns>
  1748. [HttpPost]
  1749. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1750. public async Task<IActionResult> PostPayRequest_Center(PostPayRequestByDateRangeDto dto)
  1751. {
  1752. Stopwatch stopwatch = Stopwatch.StartNew();
  1753. #region 验证
  1754. DateTime beginDt, endDt;
  1755. string format = "yyyy-MM-dd";
  1756. if (!DateTime.TryParseExact(dto.beginDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out beginDt))
  1757. {
  1758. return Ok(JsonView(false, "开始日期格式不正确!正确格式:yyyy-MM-dd"));
  1759. }
  1760. if (!DateTime.TryParseExact(dto.endDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt))
  1761. {
  1762. return Ok(JsonView(false, "结束日期格式不正确!正确格式:yyyy-MM-dd"));
  1763. }
  1764. #region 页面操作权限验证
  1765. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1766. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1767. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  1768. #endregion
  1769. #endregion
  1770. try
  1771. {
  1772. PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
  1773. var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
  1774. if (checkedStr != null)
  1775. {
  1776. checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
  1777. }
  1778. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(dto.Status, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
  1779. tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(dto.Status, checkedView.GroupIds, checkedView.HotelSubIds, dto.beginDt, dto.endDt);
  1780. stopwatch.Stop();
  1781. return Ok(JsonView(true, $"查询成功!耗时{stopwatch.ElapsedMilliseconds / 1000}s", new { daily = dailyResult, group = groupResult }));
  1782. }
  1783. catch (Exception ex)
  1784. {
  1785. return Ok(JsonView(false, ex.Message));
  1786. }
  1787. }
  1788. /// <summary>
  1789. /// 根据团组类型类型处理团组费用所属公司
  1790. /// </summary>
  1791. /// <param name="teamId"></param>
  1792. /// <returns></returns>
  1793. private CompanyInfo ExpenseCompanyByTeamId(int teamId)
  1794. {
  1795. CompanyInfo _companyInfo = new CompanyInfo();
  1796. List<int> _SiChuan = new List<int>() {
  1797. 38 , // 政府团
  1798. 39 , // 企业团
  1799. 40 , // 散客团
  1800. 102, // 未知
  1801. 248, // 非团组
  1802. 691, // 四川-会务活动
  1803. 762, // 四川-赛事项目收入
  1804. };
  1805. List<int> _ChengDu = new List<int>() {
  1806. 302, // 成都-会务活动
  1807. 1047, // 成都-赛事项目收入
  1808. };
  1809. if (_SiChuan.Contains(teamId))
  1810. {
  1811. _companyInfo.Id = 2;
  1812. _companyInfo.ConpanyName = "四川泛美交流有限公司";
  1813. }
  1814. if (_ChengDu.Contains(teamId))
  1815. {
  1816. _companyInfo.Id = 1;
  1817. _companyInfo.ConpanyName = "成都泛美商务有限公司";
  1818. }
  1819. return _companyInfo;
  1820. }
  1821. /// <summary>
  1822. /// 付款申请(团组费用申请相关)
  1823. /// 查询 根据日期范围
  1824. /// </summary>
  1825. /// <param name="_groupIds"></param>
  1826. /// <param name="beginDt"></param>
  1827. /// <param name="endDt"></param>
  1828. /// <returns></returns>
  1829. private tree_Group_DailyFeePaymentResult PayRequest_GroupPaymentByDateRange(int status, List<int> _groupIds,List<int> _hotelSubIds, string beginDt, string endDt)
  1830. {
  1831. tree_Group_DailyFeePaymentResult _DailyFeePaymentResult = new tree_Group_DailyFeePaymentResult();
  1832. List<tree_Group_DailyFeePaymentPageListView> dataList = new List<tree_Group_DailyFeePaymentPageListView>();
  1833. #region sql条件处理
  1834. string sqlWhere = string.Format(@" And (AuditGMDate Between '{0} 00:00:00' And '{1} 23:59:59') ", beginDt, endDt);
  1835. if (status == 2)
  1836. {
  1837. if (_hotelSubIds.Count > 1)
  1838. {
  1839. var hrIds = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => _hotelSubIds.Contains(it.Id)).Select(it => it.HrId).Distinct().ToList();
  1840. _groupIds = _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(it => it.CTable == 76 && hrIds.Contains(it.CId)).Select(it => it.Id).ToList();
  1841. }
  1842. if (_groupIds.Count < 1)
  1843. {
  1844. _DailyFeePaymentResult.dataList = new List<tree_Group_DailyFeePaymentPageListView>();
  1845. return _DailyFeePaymentResult;
  1846. }
  1847. sqlWhere += string.Format(@" And Id In ({0})", string.Join(",", _groupIds));
  1848. }
  1849. string sql_1 = string.Format(@"Select * From Grp_CreditCardPayment Where IsDel = 0 And IsPay = 0 And (IsAuditGM = 1 Or IsAuditGM = 3 ){0}", sqlWhere);
  1850. #endregion
  1851. var _paymentDatas = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_1).ToList();//付款信息
  1852. _DailyFeePaymentResult.gz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 0).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); //公转
  1853. _DailyFeePaymentResult.sz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 1).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); ; //私转
  1854. List<int> groupIds = _paymentDatas.Select(it => it.DIId).Distinct().ToList();
  1855. var _groupDatas = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Id)).ToList();
  1856. //_groupDatas = (List<Grp_DelegationInfo>)_groupDatas.GroupBy(it => it.TeamDid);
  1857. #region 相关基础数据源
  1858. var userDatas = _sqlSugar.Queryable<Sys_Users>().ToList();
  1859. var setDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToList();
  1860. var countryFeeDatas = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  1861. var hotelDatas = _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1862. var hotelContentDatas = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => it.IsDel == 0 && it.IsPay == 0 && groupIds.Contains(it.DiId)).ToList();
  1863. var opDatas = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1864. var visaDatas = _sqlSugar.Queryable<Grp_VisaInfo>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DIId)).ToList();
  1865. var ioaDatas = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1866. var insureDatas = _sqlSugar.Queryable<Grp_Customers>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1867. var airDatas = _sqlSugar.Queryable<Grp_AirTicketReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DIId)).ToList();
  1868. //var otherMoneyDatas = _sqlSugar.Queryable<Fin_OtherPrice>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Diid)).ToList();
  1869. var otherMoneyDatas = _sqlSugar.Queryable<Grp_DecreasePayments>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1870. var refundPaymentDatas = _sqlSugar.Queryable<Fin_PaymentRefundAndOtherMoney>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1871. var ExtraCostDatas = _sqlSugar.Queryable<Fin_GroupExtraCost>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1872. #endregion
  1873. //Expense company
  1874. foreach (var groupInfo in _groupDatas)
  1875. {
  1876. List<Group_DailyFeePaymentContentInfolView> childList = new List<Group_DailyFeePaymentContentInfolView>();
  1877. var groupPaymentDatas = _paymentDatas.Where(it => groupInfo.Id == it.DIId).ToList();
  1878. int rouNumber = 1;
  1879. foreach (var payInfo in groupPaymentDatas)
  1880. {
  1881. string priName = "-";
  1882. string orbitalPrivateTransfer = payInfo.OrbitalPrivateTransfer == 0 ? "公转" : payInfo.OrbitalPrivateTransfer == 1 ? "私转" : "-";
  1883. switch (payInfo.CTable)
  1884. {
  1885. case 76: //76 酒店预订
  1886. priName = $"[费用名称:{hotelDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.HotelName ?? ""}]";
  1887. break;
  1888. case 79: //79 车/导游地接
  1889. var opData = opDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id);
  1890. if (opData != null)
  1891. {
  1892. string area = "";
  1893. bool b = int.TryParse(opData.Area, out int areaId);
  1894. if (b)
  1895. {
  1896. string area1 = countryFeeDatas.Find(it => it.Id == areaId)?.Country ?? "-";
  1897. area = $"{area1}({setDatas.Find(it => it.Id == opData.PriceType)?.Name ?? "-"})";
  1898. }
  1899. else area = opData.Area;
  1900. string opPriName = "-";
  1901. if (!string.IsNullOrEmpty(opData.PriceName)) opPriName = opData.PriceName;
  1902. area += $"({opPriName})";
  1903. if (payInfo.OrbitalPrivateTransfer == 0) //公转
  1904. {
  1905. priName = $"【{orbitalPrivateTransfer}】【导游: {opData.ServiceGuide} 】[费用名称:{area}]";
  1906. }
  1907. else if (payInfo.OrbitalPrivateTransfer == 1) //私转
  1908. {
  1909. priName = $"【{orbitalPrivateTransfer}】【导游:{opData.ServiceGuide}】[费用名称:{area}]";
  1910. }
  1911. }
  1912. break;
  1913. case 80: // 80 签证
  1914. string sql = 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}", groupInfo.Id);
  1915. List<SimplClientInfo> arr = _sqlSugar.SqlQueryable<SimplClientInfo>(sql).ToList();
  1916. string visaClientName = visaDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.VisaClient ?? "";
  1917. string clientName = "-";
  1918. if (Regex.Match(visaClientName, @"\d+,?").Value.Length > 0)
  1919. {
  1920. string[] temparr = visaClientName.Split(',');
  1921. string fistrStr = temparr[0];
  1922. int count = temparr.Count();
  1923. int tempId;
  1924. bool success = int.TryParse(fistrStr, out tempId);
  1925. if (success)
  1926. {
  1927. SimplClientInfo tempInfo = arr.FirstOrDefault(s => s.Id == tempId);
  1928. if (tempInfo != null)
  1929. {
  1930. if (count > 1)
  1931. {
  1932. clientName = string.Format(@"{0}{1}等{2}人", tempInfo.LastName, tempInfo.FirstName, count);
  1933. }
  1934. else
  1935. {
  1936. clientName = string.Format(@"{0}{1}", tempInfo.LastName, tempInfo.FirstName);
  1937. }
  1938. }
  1939. }
  1940. else
  1941. {
  1942. clientName = fistrStr;
  1943. }
  1944. }
  1945. priName = $"[费用名称:{clientName}]";
  1946. break;
  1947. case 81: // 81 邀请/公务活动
  1948. priName = $"[费用名称:{ioaDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.Inviter ?? " -"}]";
  1949. break;
  1950. case 82: // 82 团组客户保险
  1951. priName = $"[费用名称:{insureDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.ClientName ?? " -"}]";
  1952. break;
  1953. case 85: // 85 机票预订
  1954. string flightsCode = airDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.FlightsCode ?? "-";
  1955. string airPayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "-";
  1956. priName = $"{flightsCode}【{airPayType}】";
  1957. break;
  1958. case 98: // 98 其他款项
  1959. priName = $"[费用名称:{otherMoneyDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? " -"}]";
  1960. break;
  1961. case 285: // 285 收款退还
  1962. priName = $"[费用名称:{refundPaymentDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? " -"}]";
  1963. break;
  1964. case 1015: // 1015 超支费用
  1965. priName = $"[费用名称:{ExtraCostDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? " -"}]";
  1966. break;
  1967. default:
  1968. priName = "";
  1969. break;
  1970. }
  1971. bool status1 = false;
  1972. if (_groupIds != null)
  1973. {
  1974. status1 = _groupIds.Contains(payInfo.Id);
  1975. }
  1976. if (payInfo.CTable == 76) //酒店单独处理
  1977. {
  1978. var hotelContents = hotelContentDatas.Where(it => it.HrId == payInfo.CId);
  1979. List<Group_DailyFeePaymentContentInfolView> childInfos = new List<Group_DailyFeePaymentContentInfolView>();
  1980. foreach (var hotelContent in hotelContents)
  1981. {
  1982. string subPriceName = "";
  1983. if (hotelContent.PriceType == 1) subPriceName = "房费";
  1984. else if (hotelContent.PriceType == 2) subPriceName = "早餐";
  1985. else if (hotelContent.PriceType == 3) subPriceName = "地税";
  1986. else if (hotelContent.PriceType == 4) subPriceName = "城市税";
  1987. if (string.IsNullOrEmpty(subPriceName)) subPriceName = priName;
  1988. else subPriceName = $"{priName.Replace("]","")}-{subPriceName}]";
  1989. string payeeStr1 = string.Format(@" {0},开户行:{1},银行卡号:{2} ",
  1990. string.IsNullOrEmpty(hotelContent.Payee) ? "-" : hotelContent.Payee,
  1991. string.IsNullOrEmpty(hotelContent.OtherBankName) ? "-" : hotelContent.OtherBankName,
  1992. string.IsNullOrEmpty(hotelContent.OtherSideNo) ? "-" : hotelContent.OtherSideNo);
  1993. decimal _PaymentAmount1 = hotelContent.Price;//此次付款金额
  1994. decimal _CNYSubTotalAmount1 = _PaymentAmount1 * hotelContent.Rate;//此次付款金额
  1995. _CNYSubTotalAmount1 = Convert.ToDecimal(_CNYSubTotalAmount1.ToString("#0.00"));
  1996. //酒店子项Id选中状态更改
  1997. if (_hotelSubIds != null) status1 = _hotelSubIds.Contains(hotelContent.Id);
  1998. var childInfo1 = new Group_DailyFeePaymentContentInfolView()
  1999. {
  2000. IsChecked = status1,
  2001. Id = payInfo.Id,
  2002. HotelSubId = hotelContent.Id,
  2003. Payee = payeeStr1,
  2004. RowNumber = rouNumber,
  2005. Applicant = userDatas.Find(it => it.Id == payInfo.CreateUserId)?.CnName ?? "",
  2006. ApplicantDt = payInfo.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
  2007. PayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "",
  2008. TransferMark = orbitalPrivateTransfer,
  2009. PriceName = subPriceName,
  2010. ModuleName = setDatas.Find(it => it.Id == payInfo.CTable)?.Name ?? "",
  2011. PayCurrCode = setDatas.Find(it => it.Id == hotelContent.Currency)?.Name ?? "",
  2012. PaymentAmount = _PaymentAmount1,
  2013. PayRate = hotelContent.Rate,
  2014. CNYSubTotalAmount = _CNYSubTotalAmount1,
  2015. AuditStatus = payInfo.IsAuditGM
  2016. };
  2017. string remaksDescription1 = $"【{childInfo1.PayType}】【{childInfo1.ModuleName}】{rouNumber}、[申请人:{childInfo1.Applicant}]{subPriceName}[收款方:{childInfo1.Payee}] {childInfo1.PayCurrCode} {_PaymentAmount1.ToString("#0.00")}、CNY:{childInfo1.CNYSubTotalAmount.ToString("#0.00")}(团组:{groupInfo.TeamName})";
  2018. childInfo1.RemaksDescription = remaksDescription1;
  2019. childInfos.Add(childInfo1);
  2020. rouNumber++;
  2021. }
  2022. childList.AddRange(childInfos);
  2023. }
  2024. else
  2025. {
  2026. string payeeStr = string.Format(@" {0},开户行:{1},银行卡号:{2} ",
  2027. string.IsNullOrEmpty(payInfo.Payee) ? "-" : payInfo.Payee,
  2028. string.IsNullOrEmpty(payInfo.OtherBankName) ? "-" : payInfo.OtherBankName,
  2029. string.IsNullOrEmpty(payInfo.OtherSideNo) ? "-" : payInfo.OtherSideNo);
  2030. decimal _PaymentAmount = (payInfo.PayMoney / 100) * payInfo.PayPercentage;//此次付款金额
  2031. decimal _CNYSubTotalAmount = _PaymentAmount * payInfo.DayRate;//此次付款金额
  2032. _CNYSubTotalAmount = Convert.ToDecimal(_CNYSubTotalAmount.ToString("#0.00"));
  2033. var childInfo = new Group_DailyFeePaymentContentInfolView()
  2034. {
  2035. IsChecked = status1,
  2036. Id = payInfo.Id,
  2037. Payee = payeeStr,
  2038. RowNumber = rouNumber,
  2039. Applicant = userDatas.Find(it => it.Id == payInfo.CreateUserId)?.CnName ?? "",
  2040. ApplicantDt = payInfo.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
  2041. PayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "",
  2042. TransferMark = orbitalPrivateTransfer,
  2043. PriceName = priName,
  2044. ModuleName = setDatas.Find(it => it.Id == payInfo.CTable)?.Name ?? "",
  2045. PayCurrCode = setDatas.Find(it => it.Id == payInfo.PaymentCurrency)?.Name ?? "",
  2046. PaymentAmount = _PaymentAmount,
  2047. PayRate = payInfo.DayRate,
  2048. CNYSubTotalAmount = _CNYSubTotalAmount,
  2049. AuditStatus = payInfo.IsAuditGM
  2050. };
  2051. string remaksDescription = $"【{childInfo.PayType}】【{childInfo.ModuleName}】{rouNumber}、[申请人:{childInfo.Applicant}]{priName}[收款方:{childInfo.Payee}] {childInfo.PayCurrCode} {_PaymentAmount.ToString("#0.00")}、CNY:{childInfo.CNYSubTotalAmount.ToString("#0.00")}(团组:{groupInfo.TeamName})";
  2052. childInfo.RemaksDescription = remaksDescription;
  2053. childList.Add(childInfo);
  2054. rouNumber++;
  2055. }
  2056. }
  2057. CompanyInfo companyInfo = new CompanyInfo();
  2058. companyInfo = ExpenseCompanyByTeamId(groupInfo.TeamDid);
  2059. dataList.Add(new tree_Group_DailyFeePaymentPageListView()
  2060. {
  2061. Id = Guid.NewGuid().ToString("N"),
  2062. GroupName = groupInfo.TeamName,
  2063. CompanyId = companyInfo.Id,
  2064. ConpanyName = companyInfo.ConpanyName,
  2065. CNYTotalAmount = childList.Sum(it => it.CNYSubTotalAmount),
  2066. ChildList = childList,
  2067. });
  2068. }
  2069. _DailyFeePaymentResult.dataList = dataList;
  2070. return _DailyFeePaymentResult;
  2071. }
  2072. /// <summary>
  2073. /// 付款申请(日付申请相关)
  2074. /// 查询 根据日期范围
  2075. /// </summary>
  2076. /// <param name="_dailyIds"></param>
  2077. /// <param name="beginDt"></param>
  2078. /// <param name="endDt"></param>
  2079. /// <returns></returns>
  2080. private tree_Fin_DailyFeePaymentResult PayRequest_DailyByDateRange(int status, List<int> _dailyIds, string beginDt, string endDt)
  2081. {
  2082. #region sql条件处理
  2083. string sqlWhere = string.Format(@" And dfp.CreateTime between '{0} 00:00:00' And '{1} 23:59:59' ", beginDt, endDt);
  2084. if (status == 2)
  2085. {
  2086. if (_dailyIds.Count < 1)
  2087. {
  2088. return new tree_Fin_DailyFeePaymentResult() { childList = new List<Fin_DailyFeePaymentContentInfolView>() };
  2089. }
  2090. sqlWhere += string.Format(@" And dfp.Id In({0}) ", string.Join(",", _dailyIds));
  2091. }
  2092. string sql_1 = string.Format(@"Select * From (
  2093. Select row_number() over (order by dfp.Id Desc) as RowNumber,
  2094. dfp.Id,dfp.CompanyId,c.CompanyName,dfp.Instructions,dfp.SumPrice,
  2095. dfp.CreateUserId,u.CnName CreateUser,dfp.CreateTime,dfp.FAudit,dfp.MAudit,
  2096. dfp.PriceTypeId,dfp.TransferTypeId
  2097. From Fin_DailyFeePayment dfp
  2098. Inner Join Sys_Company c On dfp.CompanyId = c.Id
  2099. Left Join Sys_Users u On dfp.CreateUserId = u.Id
  2100. Where dfp.IsDel=0 {0} And dfp.FAudit = 1 And dfp.MAudit = 1 And dfp.IsPay = 0
  2101. ) temp ", sqlWhere);
  2102. #endregion
  2103. List<tree_Fin_DailyFeePaymentPageListView> DailyFeePaymentData = _sqlSugar.SqlQueryable<tree_Fin_DailyFeePaymentPageListView>(sql_1).ToList();
  2104. Dictionary<int, string> dic_setData = new Dictionary<int, string>();
  2105. Sys_SetDataType stGZ = _daiRep.Query<Sys_SetDataType>(s => s.Name == "公转").First();
  2106. Sys_SetDataType stSZ = _daiRep.Query<Sys_SetDataType>(s => s.Name == "私转").First();
  2107. foreach (var item in DailyFeePaymentData)
  2108. {
  2109. if (_dailyIds != null)
  2110. {
  2111. item.IsChecked = _dailyIds.Contains(item.Id);
  2112. }
  2113. if (dic_setData.ContainsKey(item.PriceTypeId))
  2114. {
  2115. item.priceTypeStr = dic_setData[item.PriceTypeId];
  2116. }
  2117. else
  2118. {
  2119. Sys_SetData sd_priceType = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceTypeId).First();
  2120. if (sd_priceType != null)
  2121. {
  2122. item.priceTypeStr = sd_priceType.Name;
  2123. dic_setData.Add(item.PriceTypeId, sd_priceType.Name);
  2124. }
  2125. }
  2126. if (dic_setData.ContainsKey(item.transferTypeId))
  2127. {
  2128. item.transferTypeIdStr = dic_setData[item.transferTypeId];
  2129. Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
  2130. if (sd_transfer != null)
  2131. {
  2132. item.transferParentId = sd_transfer.STid;
  2133. item.transferParentIdStr = sd_transfer.STid == stGZ.Id ? "公转" : sd_transfer.STid == stSZ.Id ? "私转" : "";
  2134. }
  2135. }
  2136. else
  2137. {
  2138. Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
  2139. if (sd_transfer != null)
  2140. {
  2141. item.transferTypeIdStr = sd_transfer.Name;
  2142. item.transferParentId = sd_transfer.STid;
  2143. item.transferParentIdStr = sd_transfer.STid == stGZ.Id ? "公转" : sd_transfer.STid == stSZ.Id ? "私转" : "";
  2144. dic_setData.Add(item.transferTypeId, sd_transfer.Name);
  2145. }
  2146. }
  2147. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  2148. Where IsDel=0 And DFPId = {0} ", item.Id);
  2149. item.childList = _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToList();
  2150. int rowNumber = 1;
  2151. foreach (var subItem in item.childList)
  2152. {
  2153. string remaksDescription = $"{rowNumber}、【{item.priceTypeStr}】{item.Instructions}({subItem.PriceName}) CNY:{subItem.ItemTotal.ToString("#0.00")}(单价:{subItem.Price.ToString("#0.00")} * {subItem.Quantity})";
  2154. subItem.RemaksDescription = remaksDescription;
  2155. string excelRemaksDescription = $"【{item.priceTypeStr}】{item.Instructions}({subItem.PriceName}) CNY:{subItem.ItemTotal.ToString("#0.00")}(单价:{subItem.Price.ToString("#0.00")} * {subItem.Quantity})【申请人:{item.CreateUser} 申请时间:{item.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")}】";
  2156. subItem.ExcelRemaksDescription = excelRemaksDescription;
  2157. rowNumber++;
  2158. }
  2159. }
  2160. decimal total_gz = DailyFeePaymentData.Where(s => s.transferParentId == stGZ.Id).Sum(d => d.SumPrice ?? 0M);
  2161. decimal total_sz = DailyFeePaymentData.Where(s => s.transferParentId == stSZ.Id).Sum(d => d.SumPrice ?? 0M);
  2162. var result = new tree_Fin_DailyFeePaymentResult() { gz = total_gz, sz = total_sz, dataList = DailyFeePaymentData };
  2163. return result;
  2164. }
  2165. /// <summary>
  2166. /// 付款申请 (PageId=51)
  2167. /// 团组,日付相关费用 选中状态变更
  2168. /// </summary>
  2169. /// <param name="dto"></param>
  2170. /// <returns></returns>
  2171. [HttpPost]
  2172. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2173. public async Task<IActionResult> PostPayRequestCheckedChange(PayRequestCheckedChangeDto dto)
  2174. {
  2175. #region 验证
  2176. if (dto.Type < 1 || dto.Type > 2)
  2177. {
  2178. return Ok(JsonView(false, "请传入有效的Type参数! 1 checked 2 清除上次勾选"));
  2179. }
  2180. #endregion
  2181. PaymentRequestCheckedView requestCheckedView = new PaymentRequestCheckedView();
  2182. List<int> groupIds = new List<int>();
  2183. List<int> dailyPaymentIds = new List<int>();
  2184. List<int> hotelIds = new List<int>();
  2185. #region 参数处理
  2186. if (!string.IsNullOrEmpty(dto.GroupIds))
  2187. {
  2188. if (dto.GroupIds.Contains(","))
  2189. {
  2190. groupIds = dto.GroupIds.Split(',').Select(int.Parse).ToList();
  2191. }
  2192. else
  2193. {
  2194. groupIds.Add(int.Parse(dto.GroupIds));
  2195. }
  2196. }
  2197. if (!string.IsNullOrEmpty(dto.HotelSubIds))
  2198. {
  2199. if (dto.HotelSubIds.Contains(","))
  2200. {
  2201. hotelIds = dto.HotelSubIds.Split(',').Select(int.Parse).ToList();
  2202. }
  2203. else
  2204. {
  2205. hotelIds.Add(int.Parse(dto.HotelSubIds));
  2206. }
  2207. }
  2208. if (!string.IsNullOrEmpty(dto.DailyPaymentIds))
  2209. {
  2210. if (dto.DailyPaymentIds.Contains(","))
  2211. {
  2212. dailyPaymentIds = dto.DailyPaymentIds.Split(',').Select(int.Parse).ToList();
  2213. }
  2214. else
  2215. {
  2216. dailyPaymentIds.Add(int.Parse(dto.DailyPaymentIds));
  2217. }
  2218. }
  2219. #endregion
  2220. requestCheckedView.GroupIds = groupIds;
  2221. requestCheckedView.HotelSubIds = hotelIds;
  2222. requestCheckedView.DailyPaymentIds = dailyPaymentIds;
  2223. if (dto.Type == 1)
  2224. {
  2225. TimeSpan ts = DateTime.Now.AddDays(180) - DateTime.Now; //设置redis 过期时间 半年(180)
  2226. var status = await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>("paymentRequestCheckedData", JsonConvert.SerializeObject(requestCheckedView), ts);
  2227. if (status)
  2228. {
  2229. return Ok(JsonView(true, "操作成功!"));
  2230. }
  2231. }
  2232. else if (dto.Type == 2)
  2233. {
  2234. var status = await RedisRepository.RedisFactory.CreateRedisRepository().KeyDeleteAsync("paymentRequestCheckedData");
  2235. if (status)
  2236. {
  2237. return Ok(JsonView(true, "操作成功!"));
  2238. }
  2239. }
  2240. return Ok(JsonView(false, "操作失败!"));
  2241. }
  2242. /// <summary>
  2243. /// 付款申请 (PageId=51)
  2244. /// 团组,日付相关费用 汇率变更
  2245. /// </summary>
  2246. /// <param name="dto"></param>
  2247. /// <returns></returns>
  2248. [HttpPost]
  2249. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2250. public async Task<IActionResult> PostPayRequestRateChange(PayRequestRateChangeDto dto)
  2251. {
  2252. #region 验证
  2253. DateTime beginDt, endDt;
  2254. string format = "yyyy-MM-dd";
  2255. if (!DateTime.TryParseExact(dto.beginDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out beginDt))
  2256. {
  2257. return Ok(JsonView(false, "开始日期格式不正确!正确格式:yyyy-MM-dd"));
  2258. }
  2259. if (!DateTime.TryParseExact(dto.endDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt))
  2260. {
  2261. return Ok(JsonView(false, "结束日期格式不正确!正确格式:yyyy-MM-dd"));
  2262. }
  2263. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  2264. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数!"));
  2265. if (dto.Rate <= 0) return Ok(JsonView(false, "请传入有效的Rate参数!"));
  2266. #endregion
  2267. int hotelSubStatus = 0,status = 0;
  2268. int diid = 0, cTable = 0, currId = 0;
  2269. if (dto.HotelSubId > 0)
  2270. {
  2271. //更改酒店子表汇率
  2272. hotelSubStatus = _sqlSugar.Updateable<Grp_HotelReservationsContent>()
  2273. .SetColumns(it => it.Rate == dto.Rate)
  2274. .Where(it => it.Id == dto.HotelSubId)
  2275. .ExecuteCommand();
  2276. if (hotelSubStatus > 0)
  2277. {
  2278. var hotelSubInfo = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => it.Id == dto.HotelSubId).First();
  2279. if (hotelSubInfo != null)
  2280. {
  2281. diid = hotelSubInfo.DiId;
  2282. currId = hotelSubInfo.Currency;
  2283. }
  2284. //付款申请汇率更改成功;更改团组汇率对应币种
  2285. string currCode = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == currId).First()?.Name ?? "";
  2286. await _teamRateRep.UpdateGroupRateByDiIdAndCTableId(diid, 76, currCode, dto.Rate);
  2287. }
  2288. }
  2289. if (dto.Id > 0)
  2290. {
  2291. var ccpInfo = _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(it => it.Id == dto.Id).First();
  2292. decimal cnyMoney = 0.00M;
  2293. if (ccpInfo != null) {
  2294. cnyMoney = ccpInfo.PayMoney * dto.Rate;
  2295. diid = ccpInfo.DIId;
  2296. cTable = ccpInfo.CTable;
  2297. currId = ccpInfo.PaymentCurrency;
  2298. }
  2299. status = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  2300. .SetColumns(it => it.DayRate == dto.Rate)
  2301. .SetColumns(it => it.RMBPrice == cnyMoney)
  2302. .Where(it => it.Id == dto.Id)
  2303. .ExecuteCommand();
  2304. if (status > 0)
  2305. {
  2306. //付款申请汇率更改成功;更改团组汇率对应币种
  2307. if (cTable != 76)
  2308. {
  2309. string currCode = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == currId).First()?.Name ?? "";
  2310. await _teamRateRep.UpdateGroupRateByDiIdAndCTableId(diid, cTable, currCode, dto.Rate);
  2311. }
  2312. }
  2313. }
  2314. if (hotelSubStatus > 0 || status > 0)
  2315. {
  2316. PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
  2317. var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
  2318. if (checkedStr != null)
  2319. {
  2320. checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
  2321. }
  2322. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(1, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
  2323. tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(1, checkedView.GroupIds, checkedView.HotelSubIds, dto.beginDt, dto.endDt);
  2324. decimal _gz = dailyResult.gz + groupResult.gz;
  2325. decimal _sz = dailyResult.sz + groupResult.sz;
  2326. return Ok(JsonView(true, "操作成功!", new { gz = dailyResult, sz = groupResult }));
  2327. }
  2328. return Ok(JsonView(false, "该项汇率修改失败!"));
  2329. }
  2330. /// <summary>
  2331. /// 付款申请 (PageId=51)
  2332. /// 团组,日付相关费用 付款状态变更
  2333. /// </summary>
  2334. /// <param name="dto"></param>
  2335. /// <returns></returns>
  2336. [HttpPost]
  2337. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2338. public async Task<IActionResult> PostPayRequestPayChange(PayRequestPayChangeDto dto)
  2339. {
  2340. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  2341. //if (string.IsNullOrEmpty(dto.GroupIds))
  2342. //{
  2343. // return Ok(JsonView(false, "请传入有效的GroupIds参数!"));
  2344. //}
  2345. //if (string.IsNullOrEmpty(dto.DailyPaymentIds))
  2346. //{
  2347. // return Ok(JsonView(false, "请传入有效的DailyPaymentIds参数!"));
  2348. //}
  2349. List<int> groupIds = new List<int>();
  2350. List<int> dailyPaymentIds = new List<int>();
  2351. List<int> hotelSubIds = new List<int>();
  2352. #region 参数处理
  2353. if (!string.IsNullOrEmpty(dto.GroupIds))
  2354. {
  2355. if (dto.GroupIds.Contains(",")) groupIds = dto.GroupIds.Split(',').Select(int.Parse).ToList();
  2356. else groupIds.Add(int.Parse(dto.GroupIds));
  2357. }
  2358. if (!string.IsNullOrEmpty(dto.HotelSubIds))
  2359. {
  2360. if (dto.HotelSubIds.Contains(",")) hotelSubIds = dto.HotelSubIds.Split(',').Select(int.Parse).ToList();
  2361. else hotelSubIds.Add(int.Parse(dto.HotelSubIds));
  2362. if (hotelSubIds.Count > 0)
  2363. {
  2364. foreach (var item in hotelSubIds)
  2365. {
  2366. if (item < 1)
  2367. {
  2368. hotelSubIds.Remove(item);
  2369. }
  2370. }
  2371. }
  2372. }
  2373. if (!string.IsNullOrEmpty(dto.DailyPaymentIds))
  2374. {
  2375. if (dto.DailyPaymentIds.Contains(",")) dailyPaymentIds = dto.DailyPaymentIds.Split(',').Select(int.Parse).ToList();
  2376. else dailyPaymentIds.Add(int.Parse(dto.DailyPaymentIds));
  2377. }
  2378. #endregion
  2379. bool changeStatus = false;
  2380. _sqlSugar.BeginTran();
  2381. if (groupIds.Count > 0)
  2382. {
  2383. var ccpInfos = _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Id)).ToList();
  2384. var otherTypeCcpIds = ccpInfos.Where(it => it.CTable != 76).Select(it => it.Id).ToList();
  2385. var hotelTyprCcpIds = ccpInfos.Where(it => it.CTable == 76).Select(it => it.Id).ToList();
  2386. int groupStatus = 0;
  2387. if (otherTypeCcpIds.Count > 0) //其他费用类型 正常付款
  2388. {
  2389. groupStatus = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  2390. .SetColumns(it => it.IsPay == 1)
  2391. .Where(it => otherTypeCcpIds.Contains(it.Id))
  2392. .ExecuteCommand();
  2393. changeStatus = true;
  2394. }
  2395. if (hotelTyprCcpIds.Count > 0) //酒店费用子项逻辑付款,酒店子项费用全部付完款,c表ispay=1
  2396. {
  2397. if (hotelSubIds.Count > 0)
  2398. {
  2399. List<int> hrPayIds = new List<int>();
  2400. var hrIspayStatus = _sqlSugar.Updateable<Grp_HotelReservationsContent>()
  2401. .SetColumns(it => it.IsPay == 1)
  2402. .Where(it => hotelSubIds.Contains(it.Id))
  2403. .ExecuteCommand();
  2404. changeStatus = true;
  2405. //酒店子项是否全部付完款
  2406. List<int> hrIds = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => it.IsDel == 0 && hotelSubIds.Contains(it.Id)).Select(it => it.HrId).Distinct().ToList();
  2407. if (hrIds.Count > 0 )
  2408. {
  2409. var hotelSubFeeData = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => it.IsDel == 0 && hrIds.Contains(it.HrId)).ToList();
  2410. var hotelSubFeeGroupData = hotelSubFeeData.GroupBy(it => it.HrId).ToList();
  2411. foreach (var item in hotelSubFeeGroupData)
  2412. {
  2413. var allTotal = item.Where(it => it.Price > 0).ToList().Count;
  2414. var paymentTotal = item.Where(it => it.Price > 0 && it.IsPay == 1).ToList().Count;
  2415. if (allTotal == paymentTotal)
  2416. {
  2417. hrPayIds.Add(item.Key);
  2418. }
  2419. }
  2420. }
  2421. if (hrPayIds.Count > 0)
  2422. {
  2423. //c表更改全部付款的酒店费用
  2424. groupStatus = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  2425. .SetColumns(it => it.IsPay == 1)
  2426. .Where(it => it.CTable == 76 && hrPayIds.Contains(it.CId))
  2427. .ExecuteCommand();
  2428. }
  2429. }
  2430. }
  2431. }
  2432. //if (hotelSubIds.Count > 0)
  2433. //{
  2434. // var groupStatus = _sqlSugar.Updateable<Grp_HotelReservationsContent>()
  2435. // .SetColumns(it => it.IsPay == 1)
  2436. // .Where(it => hotelSubIds.Contains(it.Id))
  2437. // .ExecuteCommand();
  2438. // if (groupStatus > 0)
  2439. // {
  2440. // changeStatus = true;
  2441. // }
  2442. //}
  2443. if (dailyPaymentIds.Count > 0)
  2444. {
  2445. var dailyPaymentStatus = _sqlSugar.Updateable<Fin_DailyFeePayment>()
  2446. .SetColumns(it => it.IsPay == 1)
  2447. .Where(it => dailyPaymentIds.Contains(it.Id))
  2448. .ExecuteCommand();
  2449. if (dailyPaymentStatus > 0)
  2450. {
  2451. changeStatus = true;
  2452. }
  2453. }
  2454. if (changeStatus)
  2455. {
  2456. _sqlSugar.CommitTran();
  2457. #region 应用推送
  2458. try
  2459. {
  2460. foreach (int ccpId in groupIds)
  2461. {
  2462. List<string> tempList = new List<string>() { ccpId.ToString() };
  2463. await AppNoticeLibrary.SendUserMsg_GroupStatus_PayResult(ccpId, tempList);
  2464. }
  2465. foreach (int dailyId in dailyPaymentIds)
  2466. {
  2467. List<string> tempList = new List<string>() { dailyId.ToString() };
  2468. await AppNoticeLibrary.DailyPayReminder_Pay_ToUser(dailyId, tempList);
  2469. }
  2470. }
  2471. catch (Exception ex)
  2472. {
  2473. }
  2474. #endregion
  2475. return Ok(JsonView(true, "操作成功!"));
  2476. }
  2477. _sqlSugar.RollbackTran();
  2478. return Ok(JsonView(false, "付款状态修改失败!"));
  2479. }
  2480. /// <summary>
  2481. /// 付款申请 (PageId=51)
  2482. /// File Download
  2483. /// </summary>
  2484. /// <param name="dto"></param>
  2485. /// <returns></returns>
  2486. [HttpPost]
  2487. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2488. public async Task<IActionResult> PostPayRequestFileDownload(PayRequestFileDownloadDto dto)
  2489. {
  2490. Stopwatch stopwatch = Stopwatch.StartNew();
  2491. #region 参数,权限 验证
  2492. if (dto.PortType < 1)
  2493. {
  2494. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  2495. }
  2496. if (dto.UserId < 1)
  2497. {
  2498. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  2499. }
  2500. if (dto.PageId < 1)
  2501. {
  2502. dto.PageId = 51;
  2503. return Ok(JsonView(false, "请传入有效的PageId参数!"));
  2504. }
  2505. if (dto.ConpanyId < 1 || dto.ConpanyId > 4)
  2506. {
  2507. return Ok(JsonView(false, "请传入有效的ConpanyId参数!"));
  2508. }
  2509. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2510. #region 页面操作权限验证
  2511. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  2512. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  2513. #endregion
  2514. #endregion
  2515. try
  2516. {
  2517. PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
  2518. var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
  2519. if (checkedStr != null)
  2520. {
  2521. checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
  2522. }
  2523. if (checkedView == null)
  2524. {
  2525. return Ok(JsonView(false, "没有选中的数据!"));
  2526. }
  2527. if (checkedView.GroupIds == null && checkedView.DailyPaymentIds == null)
  2528. {
  2529. return Ok(JsonView(false, "没有选中的数据!"));
  2530. }
  2531. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(2, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
  2532. tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(2, checkedView.GroupIds, checkedView.HotelSubIds, dto.beginDt, dto.endDt);
  2533. if (dailyResult.childList == null)
  2534. {
  2535. dailyResult.childList = new List<Fin_DailyFeePaymentContentInfolView>();
  2536. }
  2537. List<tree_Group_DailyFeePaymentPageListView> _GroupData = new List<tree_Group_DailyFeePaymentPageListView>();
  2538. List<tree_Fin_DailyFeePaymentPageListView> _DailyData = new List<tree_Fin_DailyFeePaymentPageListView>();
  2539. //1 成都泛美商务有限公司
  2540. if (dto.ConpanyId == 1)
  2541. {
  2542. if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 1).ToList();
  2543. if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 1).ToList();
  2544. }
  2545. //2 四川泛美交流有限公司
  2546. else if (dto.ConpanyId == 2)
  2547. {
  2548. if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 2).ToList();
  2549. if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 2).ToList();
  2550. }
  2551. //3 成都纽茵教育科技有限公司
  2552. else if (dto.ConpanyId == 3)
  2553. {
  2554. if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 3).ToList();
  2555. if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 3).ToList();
  2556. }
  2557. //4 成都鸿企中元科技有限公司
  2558. else if (dto.ConpanyId == 4)
  2559. {
  2560. return Ok(JsonView(false, "暂未开放该类型!"));
  2561. }
  2562. else
  2563. {
  2564. return Ok(JsonView(false, "参数ConpanyId不可使用!"));
  2565. }
  2566. string _requestPaymentDt = DateTime.Now.ToString("yyyy-MM-dd"),//申请付款日期
  2567. _appliedAmount = "", //申请付款金额
  2568. _GZStr = "", //公转价格描述
  2569. _SZStr = ""; //私转价格描述
  2570. decimal groupGZAmout = 0.00M, groupSZAmout = 0.00M;
  2571. decimal dailyGZAmout = 0.00M, dailySZAmout = 0.00M;
  2572. string dailyGZStr = "", dailySZStr = "", groupGZStr = "", groupSZStr = "";
  2573. #region 数据处理
  2574. //团组费用相关
  2575. foreach (var item in _GroupData)
  2576. {
  2577. string groupGZSubStr = "";
  2578. string groupSZSubStr = "";
  2579. foreach (var subItem in item.ChildList)
  2580. {
  2581. if (subItem.TransferMark.Equals("公转"))
  2582. {
  2583. groupGZAmout += subItem.CNYSubTotalAmount;
  2584. groupGZSubStr += $"{subItem.RemaksDescription}\r\n";
  2585. }
  2586. else if (subItem.TransferMark.Equals("私转"))
  2587. {
  2588. groupSZAmout += subItem.CNYSubTotalAmount;
  2589. groupSZSubStr += $"{subItem.RemaksDescription}\r\n";
  2590. }
  2591. //groupGZSubStr += $"\t";
  2592. }
  2593. //if (!string.IsNullOrEmpty(groupGZSubStr)) groupGZStr += $"团组:{item.GroupName}\r\n{groupGZSubStr}\r\n";
  2594. //if (!string.IsNullOrEmpty(groupSZSubStr)) groupSZStr += $"团组:{item.GroupName}\r\n{groupSZSubStr}\r\n";
  2595. if (!string.IsNullOrEmpty(groupGZSubStr)) groupGZStr += $"{groupGZSubStr}\r\n";
  2596. if (!string.IsNullOrEmpty(groupSZSubStr)) groupSZStr += $"{groupSZSubStr}\r\n";
  2597. }
  2598. //日常费用相关
  2599. foreach (var item in _DailyData)
  2600. {
  2601. foreach (var subItem in item.childList)
  2602. {
  2603. if (item.transferParentId == 62) //公转
  2604. {
  2605. dailyGZAmout += item.SumPrice ?? 0.00M;
  2606. dailyGZStr += $"{item.RowNumber}、【{item.CompanyName}】{subItem.ExcelRemaksDescription}\r\n";
  2607. }
  2608. else if (item.transferParentId == 63) //私转
  2609. {
  2610. dailySZAmout += item.SumPrice ?? 0.00M;
  2611. dailySZStr += $"{item.RowNumber}、【{item.CompanyName}】{subItem.ExcelRemaksDescription}\r\n";
  2612. }
  2613. }
  2614. }
  2615. _GZStr = $"【公转】团组相关费用(合计:CNY {groupGZAmout.ToString("#0.00")}):\r\n{groupGZStr}【公转】日常付款费用(合计:CNY {dailyGZAmout.ToString("#0.00")}):\r\n{dailyGZStr}";
  2616. _SZStr = $"【私转】团组相关费用(合计:CNY {groupSZAmout.ToString("#0.00")}):\r\n{groupSZStr}【私转】日常付款费用(合计:CNY {dailySZAmout.ToString("#0.00")}):\r\n{dailySZStr}";
  2617. _appliedAmount = $"公转:CNY {(groupGZAmout + dailyGZAmout).ToString("#0.00")}\r\n私转:CNY {(groupSZAmout + dailySZAmout).ToString("#0.00")}";
  2618. #endregion
  2619. WorkbookDesigner designer = new WorkbookDesigner();
  2620. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/付款申请书.xls");
  2621. designer.SetDataSource("Date", _requestPaymentDt);
  2622. designer.SetDataSource("Price", _appliedAmount);
  2623. designer.SetDataSource("Content", _GZStr);
  2624. designer.SetDataSource("Content1", _SZStr);
  2625. //根据数据源处理生成报表内容
  2626. designer.Process();
  2627. string fileName = ("PayRequest/付款申请(" + dto.beginDt + "~" + dto.endDt + ").xlsx");
  2628. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  2629. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  2630. stopwatch.Stop();
  2631. return Ok(JsonView(true, $"操作成功!{stopwatch.ElapsedMilliseconds / 1000}s", new { url = rst }));
  2632. }
  2633. catch (Exception ex)
  2634. {
  2635. return Ok(JsonView(false, ex.Message));
  2636. }
  2637. }
  2638. #endregion
  2639. #region 超支费用
  2640. /// <summary>
  2641. /// 超支费用
  2642. /// 1增、2改、3删
  2643. /// </summary>
  2644. /// <param name="dto"></param>
  2645. /// <returns></returns>
  2646. [HttpPost]
  2647. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2648. public async Task<IActionResult> PostGroupExtraCost_Operator(Fin_GroupExtraCostDto_OP dto)
  2649. {
  2650. #region 验证
  2651. #endregion
  2652. Fin_GroupExtraCost _entity = new Fin_GroupExtraCost();
  2653. _entity.DiId = dto.diId;
  2654. _entity.PriceName = dto.priceName;
  2655. _entity.Price = dto.price;
  2656. _entity.PriceCurrency = dto.currency;
  2657. _entity.PriceType = dto.priceType;
  2658. _entity.Coefficient = dto.coefficient;
  2659. _entity.PriceDetailType = dto.priceDetailType;
  2660. _entity.FilePath = dto.filePath;
  2661. _entity.Remark = dto.remark;
  2662. _entity.PriceCount = dto.PriceCount;
  2663. DateTime dt_PriceDt;
  2664. bool b_PriceDt = DateTime.TryParse(dto.PriceDt, out dt_PriceDt);
  2665. if (b_PriceDt)
  2666. {
  2667. _entity.PriceDt = dt_PriceDt;
  2668. }
  2669. else
  2670. {
  2671. _entity.PriceDt = DateTime.MinValue;
  2672. }
  2673. _entity.PriceSum = dto.price * dto.PriceCount;
  2674. _daiRep.BeginTran();
  2675. if (dto.editType == 1)
  2676. {
  2677. _entity.CreateUserId = dto.createUser;
  2678. _entity.CreateTime = DateTime.Now;
  2679. _entity.IsDel = 0;
  2680. int returnId = await _daiRep.AddAsyncReturnId<Fin_GroupExtraCost>(_entity);
  2681. if (returnId > 0)
  2682. {
  2683. dto.Id = returnId;
  2684. }
  2685. }
  2686. else if (dto.editType == 2)
  2687. {
  2688. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  2689. {
  2690. PriceName = dto.priceName,
  2691. Price = dto.price,
  2692. PriceCurrency = dto.currency,
  2693. PriceType = dto.priceType,
  2694. PriceDetailType = dto.priceDetailType,
  2695. Coefficient = dto.coefficient,
  2696. FilePath = dto.filePath,
  2697. Remark = dto.remark,
  2698. PriceCount = dto.PriceCount,
  2699. PriceDt = _entity.PriceDt,
  2700. PriceSum = _entity.PriceSum
  2701. });
  2702. if (!res)
  2703. {
  2704. _daiRep.RollbackTran();
  2705. return Ok(JsonView(false, "2操作失败!"));
  2706. }
  2707. }
  2708. else if (dto.editType == 3)
  2709. {
  2710. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  2711. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  2712. {
  2713. IsDel = 1,
  2714. DeleteTime = delTime,
  2715. DeleteUserId = dto.createUser
  2716. });
  2717. if (!res)
  2718. {
  2719. _daiRep.RollbackTran();
  2720. return Ok(JsonView(false, "3操作失败!"));
  2721. }
  2722. }
  2723. else
  2724. {
  2725. _daiRep.RollbackTran();
  2726. return Ok(JsonView(false, "未知的editType"));
  2727. }
  2728. if (!extraCost_editCreditCardPayment(dto))
  2729. {
  2730. return Ok(JsonView(false, "ccp操作失败"));
  2731. }
  2732. _daiRep.CommitTran();
  2733. return Ok(JsonView(true, "操作成功"));
  2734. }
  2735. private Result PostCurrencyByDiid_Sync(int diId, int CId, int currencyId)
  2736. {
  2737. if (diId == 0)
  2738. {
  2739. return new Result() { Code = -1, Msg = "请传入团组Id!" };
  2740. }
  2741. if (CId == 0)
  2742. {
  2743. return new Result() { Code = -1, Msg = "请传入类型Id!" };
  2744. }
  2745. if (currencyId == 0)
  2746. {
  2747. return new Result() { Code = -1, Msg = "请传入币种Id!" };
  2748. }
  2749. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == diId && a.IsDel == 0 && a.CTable == CId);
  2750. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  2751. CurrencyInfo CurrencyRate = new CurrencyInfo();
  2752. try
  2753. {
  2754. if (_TeamRate != null)
  2755. {
  2756. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == currencyId);
  2757. if (_SetData != null)
  2758. {
  2759. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  2760. CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  2761. if (CurrencyRate != null)
  2762. {
  2763. return new Result() { Code = 0, Msg = "查询成功!", Data = CurrencyRate };
  2764. }
  2765. else
  2766. {
  2767. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  2768. }
  2769. }
  2770. else
  2771. {
  2772. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  2773. }
  2774. }
  2775. else
  2776. {
  2777. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  2778. }
  2779. }
  2780. catch (Exception)
  2781. {
  2782. return new Result() { Code = -1, Msg = "查询异常!", Data = CurrencyRate };
  2783. }
  2784. }
  2785. private bool extraCost_editCreditCardPayment(Fin_GroupExtraCostDto_OP costDto)
  2786. {
  2787. //设置团组汇率
  2788. decimal dcm_dayrate = 1M;
  2789. decimal dcm_rmbPrice = costDto.price;
  2790. int ispay = costDto.payType == 72 ? 1 : 0;
  2791. if (costDto.costSign != 3)
  2792. {
  2793. //获取新汇率 int diId,int CId, int currencyId
  2794. Result rate = this.PostCurrencyByDiid_Sync(costDto.diId, 1015, costDto.currency);
  2795. if (rate.Code == 0)
  2796. {
  2797. var rateInfo = (rate.Data as CurrencyInfo);
  2798. if (rateInfo is not null)
  2799. {
  2800. dcm_dayrate = rateInfo.Rate;
  2801. dcm_rmbPrice = rateInfo.Rate * dcm_rmbPrice;
  2802. }
  2803. else
  2804. {
  2805. dcm_dayrate = 1;
  2806. }
  2807. }
  2808. }
  2809. Grp_CreditCardPayment ccp = _daiRep.Query<Grp_CreditCardPayment>(s => s.CId == costDto.Id && s.CTable == 1015).First();
  2810. if (ccp == null)
  2811. {
  2812. ccp = new Grp_CreditCardPayment();
  2813. ccp.PayDId = costDto.payType;// dto
  2814. ccp.ConsumptionPatterns = "";
  2815. ccp.ConsumptionDate = "";
  2816. ccp.CTDId = costDto.payCardId;// dto
  2817. ccp.BankNo = "";
  2818. ccp.CardholderName = "";
  2819. ccp.PayMoney = costDto.price;// dto
  2820. ccp.PaymentCurrency = costDto.currency;// dto
  2821. ccp.CompanyBankNo = "";
  2822. ccp.OtherBankName = "";
  2823. ccp.OtherSideNo = "";
  2824. ccp.OtherSideName = "";
  2825. ccp.Remark = "";
  2826. ccp.CreateUserId = costDto.createUser;
  2827. ccp.CreateTime = DateTime.Now;
  2828. ccp.MFOperator = 0;
  2829. ccp.MFOperatorDate = "";
  2830. ccp.IsAuditDM = 0;
  2831. ccp.AuditDMOperate = 0;
  2832. ccp.AuditDMDate = "";
  2833. ccp.IsAuditMF = 0;
  2834. ccp.AuditMFOperate = 0;
  2835. ccp.AuditMFDate = "";
  2836. ccp.IsAuditGM = 0;
  2837. ccp.AuditGMOperate = 0;
  2838. ccp.AuditGMDate = "";
  2839. ccp.IsPay = ispay; // upd
  2840. ccp.DIId = costDto.diId;// dto
  2841. ccp.CId = costDto.Id;// dto
  2842. ccp.CTable = 1015; //超支费用指向id
  2843. ccp.IsDel = 0;
  2844. ccp.PayPercentage = 100M;
  2845. ccp.PayThenMoney = 0M;
  2846. ccp.PayPercentageOld = 100M;
  2847. ccp.PayThenMoneyOld = 0M;
  2848. ccp.UpdateDate = "";
  2849. ccp.Payee = costDto.payee;// dto
  2850. ccp.OrbitalPrivateTransfer = costDto.costSign;// dto
  2851. ccp.ExceedBudget = 0;
  2852. ccp.DayRate = dcm_dayrate; //upd
  2853. ccp.RMBPrice = dcm_rmbPrice; //upd
  2854. int ccpInsertId = _daiRep.AddReturnId<Grp_CreditCardPayment>(ccp);
  2855. if (ccpInsertId > 0)
  2856. {
  2857. return true;
  2858. }
  2859. }
  2860. else
  2861. {
  2862. if (costDto.editType == 2)
  2863. {
  2864. bool res = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  2865. {
  2866. PayDId = costDto.payType,
  2867. CTDId = costDto.payCardId,
  2868. PayMoney = costDto.price,
  2869. PaymentCurrency = costDto.currency,
  2870. IsPay = ispay,
  2871. Payee = costDto.payee,
  2872. OrbitalPrivateTransfer = costDto.costSign,
  2873. DayRate = dcm_dayrate,
  2874. RMBPrice = dcm_rmbPrice
  2875. });
  2876. return res;
  2877. }
  2878. else if (costDto.editType == 3)
  2879. {
  2880. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  2881. bool res2 = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  2882. {
  2883. IsDel = 1,
  2884. DeleteTime = delTime,
  2885. DeleteUserId = costDto.createUser
  2886. });
  2887. return res2;
  2888. }
  2889. }
  2890. return false;
  2891. }
  2892. /// <summary>
  2893. /// 超支费用
  2894. /// 详情查询
  2895. /// </summary>
  2896. /// <param name="dto"></param>
  2897. /// <returns></returns>
  2898. [HttpPost]
  2899. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2900. public async Task<IActionResult> PostGroupExtraCost_Detail(Fin_GroupExtraCostDto_Detail dto)
  2901. {
  2902. if (dto.Id < 1)
  2903. {
  2904. return Ok(JsonView(false, "查询失败"));
  2905. }
  2906. string sql = string.Format(@" Select
  2907. f.Id,f.DiId,
  2908. f.PriceName,f.Price,f.PriceCurrency,c.Payee,c.OrbitalPrivateTransfer,c.PayDId,
  2909. c.CTDId,f.PriceType,f.PriceDetailType,f.Coefficient,f.Remark,f.PriceCount,f.PriceDt
  2910. From Fin_GroupExtraCost f
  2911. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  2912. Left Join Sys_Users u On f.CreateUserId = u.Id
  2913. Where f.IsDel=0 And c.CTable = 1015
  2914. And f.Id = {0} ", dto.Id);
  2915. Fin_GroupExtraCostDetailView detailView = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostDetailView>(sql).FirstAsync();
  2916. if (detailView == null)
  2917. {
  2918. return Ok(JsonView(false, "查询失败"));
  2919. }
  2920. return Ok(JsonView(true, "查询成功", detailView));
  2921. }
  2922. /// <summary>
  2923. /// 超支费用
  2924. /// 列表查询
  2925. /// </summary>
  2926. /// <param name="dto"></param>
  2927. /// <returns></returns>
  2928. [HttpPost]
  2929. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2930. public async Task<IActionResult> PostGroupExtraCost_Search(Fin_GroupExtraCostDto_Search dto)
  2931. {
  2932. string sqlWhere = string.Format(@" And f.DiId = {0} ", dto.diId);
  2933. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  2934. int endIndex = startIndex + dto.PageSize - 1;
  2935. string sql_data = string.Format(@"Select * From (
  2936. Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
  2937. f.PriceName,f.PriceType,f.PriceDetailType,CAST(f.Price as varchar)+' '+s.[Name] as PriceStr,f.PriceCount,CAST(f.PriceSum as varchar)+' '+s.[Name] as PriceSumStr,
  2938. f.CreateUserId,f.PriceDt,c.IsAuditGM
  2939. From Fin_GroupExtraCost f
  2940. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  2941. Inner Join Sys_SetData s On f.PriceCurrency = s.Id
  2942. Left Join Sys_Users u On f.CreateUserId = u.Id
  2943. Where f.IsDel=0 And c.CTable = 1015 {0}
  2944. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  2945. string sql_count = string.Format(@"Select Count(1) as DataCount From (
  2946. Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
  2947. f.PriceName,f.PriceType,f.Price,f.FilePath,f.CreateUserId,f.CreateTime,c.IsAuditGM
  2948. From Fin_GroupExtraCost f
  2949. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  2950. Inner Join Sys_SetData s On f.PriceCurrency = s.Id
  2951. Left Join Sys_Users u On f.CreateUserId = u.Id
  2952. Where f.IsDel=0 And c.CTable = 1015 {0}
  2953. ) temp ", sqlWhere);
  2954. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  2955. {
  2956. //Fin_DailyFeePaymentPageCount
  2957. var count = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostViewDataCount>(sql_count).FirstAsync();
  2958. List<Fin_GroupExtraCostView> dataList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostView>(sql_data).ToListAsync();
  2959. Dictionary<int, string> dic_setData = new Dictionary<int, string>();
  2960. Dictionary<int, string> dic_user = new Dictionary<int, string>();
  2961. foreach (var item in dataList)
  2962. {
  2963. DateTime dtTemp_PriceDt;
  2964. bool b_ct = DateTime.TryParse(item.PriceDt, out dtTemp_PriceDt);
  2965. if (b_ct)
  2966. {
  2967. item.PriceDt = dtTemp_PriceDt.ToString("yyyy-MM-dd");
  2968. }
  2969. //费用类型
  2970. if (dic_setData.ContainsKey(item.PriceType))
  2971. {
  2972. item.PriceTypeStr = dic_setData[item.PriceType];
  2973. }
  2974. else
  2975. {
  2976. Sys_SetData sd_priceTypeDetail = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceType).First();
  2977. if (sd_priceTypeDetail != null)
  2978. {
  2979. string tempName = sd_priceTypeDetail.Name.Replace("n", "");
  2980. item.PriceTypeStr = tempName;
  2981. dic_setData.Add(item.PriceType, tempName);
  2982. }
  2983. }
  2984. if (item.PriceDetailType > 0)
  2985. {
  2986. if (dic_setData.ContainsKey(item.PriceDetailType))
  2987. {
  2988. item.PriceTypeStr = item.PriceTypeStr + " - " + dic_setData[item.PriceDetailType];
  2989. }
  2990. else
  2991. {
  2992. Sys_SetData sd_priceTypeDetail = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceDetailType).First();
  2993. if (sd_priceTypeDetail != null)
  2994. {
  2995. string tempName = sd_priceTypeDetail.Name.Replace("n", "");
  2996. item.PriceTypeStr = item.PriceTypeStr + " - " + tempName;
  2997. dic_setData.Add(item.PriceDetailType, tempName);
  2998. }
  2999. }
  3000. }
  3001. //系统用户
  3002. if (dic_user.ContainsKey(item.CreateUserId))
  3003. {
  3004. item.CreateUserIdStr = dic_user[item.CreateUserId];
  3005. }
  3006. else
  3007. {
  3008. Sys_Users users = _daiRep.Query<Sys_Users>(s => s.Id == item.CreateUserId).First();
  3009. if (users != null)
  3010. {
  3011. item.CreateUserIdStr = users.CnName;
  3012. dic_user.Add(item.CreateUserId, users.CnName);
  3013. }
  3014. }
  3015. switch (item.IsAuditGM)
  3016. {
  3017. case 0: item.IsAuditGMStr = "未审核"; break;
  3018. case 1: item.IsAuditGMStr = "已通过"; break;
  3019. case 2: item.IsAuditGMStr = "未通过"; break;
  3020. default: item.IsAuditGMStr = "未知状态"; break;
  3021. }
  3022. }
  3023. var result = new ListViewBase<Fin_GroupExtraCostView>
  3024. {
  3025. CurrPageIndex = dto.PageIndex,
  3026. CurrPageSize = dto.PageSize,
  3027. DataCount = count.DataCount,
  3028. DataList = dataList
  3029. };
  3030. return Ok(JsonView(true, "查询成功", result));
  3031. }
  3032. return Ok(JsonView(false, "查询失败"));
  3033. }
  3034. /// <summary>
  3035. /// 超支费用
  3036. /// 数据集合配置
  3037. /// </summary>
  3038. /// <param name="dto"></param>
  3039. /// <returns></returns>
  3040. [HttpPost]
  3041. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3042. public async Task<IActionResult> PostGroupExtraCost_ListDataInit(Fin_GroupExtraCostDto_DataListInit dto)
  3043. {
  3044. //支付方式
  3045. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  3046. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  3047. //信用卡类型
  3048. List<Sys_SetData> Card = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
  3049. List<SetDataInfoView> _Card = _mapper.Map<List<SetDataInfoView>>(Card);
  3050. //超支费用类型
  3051. List<Sys_SetData> PriceType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 79 && a.IsDel == 0).ToList();
  3052. List<SetDataInfoView> _PriceType = _mapper.Map<List<SetDataInfoView>>(PriceType);
  3053. //超支费用详细类型
  3054. List<Sys_SetData> PriceDetailType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 80 && a.IsDel == 0).ToList();
  3055. PriceDetailType.ForEach(a => { a.Name = a.Name.Replace("n", ""); });
  3056. List<SetDataInfoView> _PriceDetailType = _mapper.Map<List<SetDataInfoView>>(PriceDetailType);
  3057. var data = new
  3058. {
  3059. Payment = _Payment,
  3060. Card = _Card,
  3061. PriceType = _PriceType,
  3062. PriceDetailType = _PriceDetailType
  3063. };
  3064. return Ok(JsonView(true, "", data));
  3065. }
  3066. /// <summary>
  3067. /// 超支费用
  3068. /// 导出团组超支费用Excel
  3069. /// </summary>
  3070. /// <param name="dto"></param>
  3071. /// <returns></returns>
  3072. [HttpPost]
  3073. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3074. public async Task<IActionResult> PostGroupExtraCost_OutputExcel(Fin_GroupExtraCostExcelDto dto)
  3075. {
  3076. string sqlGroup = string.Format(@" Select * From Grp_DelegationInfo WIth(Nolock) where Id = {0} ", dto.diId);
  3077. Grp_DelegationInfo grp_DelegationInfo = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sqlGroup).FirstAsync();
  3078. if (grp_DelegationInfo == null)
  3079. {
  3080. return Ok(JsonView(false, "导出失败,未查询到团组"));
  3081. }
  3082. Workbook workbook = new Workbook();
  3083. Worksheet sheet = workbook.Worksheets[0];
  3084. Cells cells = sheet.Cells;
  3085. //sheet.Protect(Aspose.Cells.ProtectionType.All, "123123", "");//保护工作表
  3086. //sheet.Protection.IsSelectingLockedCellsAllowed = true;//设置只能选择解锁单元格
  3087. //sheet.Protection.IsFormattingColumnsAllowed = true;//设置可以调整列
  3088. //sheet.Protection.IsFormattingRowsAllowed = true;//设置可以调整行
  3089. #region 数据源
  3090. string sqlData = string.Format(@" Select f.PriceType,REPLACE(s2.[Name],'超支费用','') as PriceTypeStr,'('+REPLACE(s3.[Name],'n','')+')' as PriceDetailTypeStr, PriceDt,PriceName,
  3091. Price,PriceCount,s.[Name] as Currency,PriceSum,f.Remark
  3092. From Fin_GroupExtraCost as f With(Nolock)
  3093. Inner Join Grp_CreditCardPayment as c With(Nolock) On f.Id = c.CId
  3094. Inner Join Sys_SetData as s With(Nolock) On f.PriceCurrency = s.Id
  3095. Inner Join Sys_SetData as s2 With(Nolock) On f.PriceType = s2.Id
  3096. Inner Join Sys_SetData as s3 With(Nolock) On f.PriceDetailType = s3.Id
  3097. Where f.DiId = {0} And f.IsDel=0 And c.CTable=1015
  3098. Order by PriceType ASC,PriceDt ASC ", dto.diId);
  3099. string sqlDataCount = string.Format(@" Select f.PriceType,COUNT(f.PriceType) as DataCount
  3100. From Fin_GroupExtraCost as f With(Nolock)
  3101. Inner Join Grp_CreditCardPayment as c With(Nolock) On f.Id = c.CId
  3102. Where f.DiId = {0} And f.IsDel=0 And c.CTable=1015
  3103. Group by PriceType ", dto.diId);
  3104. List<Fin_GroupExtraCost_ExcelView> dataList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCost_ExcelView>(sqlData).ToListAsync();
  3105. List<Fin_GroupExtraCost_ExcelCountView> countList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCost_ExcelCountView>(sqlDataCount).ToListAsync();
  3106. if (dataList.Count < 1 || countList.Count < 1)
  3107. {
  3108. return Ok(JsonView(false, "导出失败,未查询到数据"));
  3109. }
  3110. #endregion
  3111. #region 标题
  3112. string cellValue_Header = grp_DelegationInfo.TeamName;
  3113. //Aspose.Cells.Style style1 = workbook.Styles[workbook.Styles.Add()];//新增样式
  3114. Aspose.Cells.Style style_Header = workbook.CreateStyle();
  3115. style_Header.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  3116. style_Header.VerticalAlignment = TextAlignmentType.Center;
  3117. style_Header.Font.Name = "微软雅黑";//文字字体
  3118. style_Header.Font.Size = 18;//文字大小
  3119. style_Header.IsLocked = false;//单元格解锁
  3120. style_Header.Font.IsBold = false;//粗体
  3121. style_Header.Font.Color = Color.FromArgb(255, 0, 0);
  3122. //style1.ForegroundColor = Color.FromArgb(0x99, 0xcc, 0xff);//设置背景色
  3123. //style1.Pattern = BackgroundType.Solid; //设置背景样式
  3124. //style1.IsTextWrapped = true;//单元格内容自动换行
  3125. style_Header.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  3126. style_Header.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  3127. style_Header.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  3128. style_Header.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  3129. cells.Merge(1, 1, 1, 10);
  3130. Aspose.Cells.Range range_header = cells.CreateRange(1, 1, 1, 10);
  3131. range_header.PutValue(cellValue_Header, false, false);
  3132. range_header.SetStyle(style_Header);
  3133. cells.SetRowHeight(1, 35);
  3134. #endregion
  3135. #region 列名
  3136. Aspose.Cells.Style style_colName = workbook.CreateStyle();
  3137. style_colName.Name = "colName";
  3138. style_colName.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  3139. style_colName.VerticalAlignment = TextAlignmentType.Center;
  3140. style_colName.Font.Name = "微软雅黑";//文字字体
  3141. style_colName.Font.Size = 12;//文字大小
  3142. style_colName.IsLocked = false;//单元格解锁
  3143. style_colName.Font.IsBold = true;//粗体
  3144. style_colName.Font.Color = Color.FromArgb(0, 0, 0);
  3145. style_colName.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  3146. style_colName.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  3147. style_colName.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  3148. style_colName.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  3149. List<Fin_GroupExtraCostExcelColumnSetting> colNameSettingList = new List<Fin_GroupExtraCostExcelColumnSetting>()
  3150. {
  3151. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 1, columnName="类型", columnWidth= 25},
  3152. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 2, columnName="时间", columnWidth= 16},
  3153. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 3, columnName="内容", columnWidth= 35},
  3154. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 4, columnName="单价", columnWidth= 12},
  3155. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 5, columnName="数量", columnWidth= 12},
  3156. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 6, columnName="货币", columnWidth= 12},
  3157. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 7, columnName="费用", columnWidth= 12},
  3158. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 8, columnName="汇率", columnWidth= 12},
  3159. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 9, columnName="人民币", columnWidth= 12},
  3160. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 10, columnName="备注信息", columnWidth= 24}
  3161. };
  3162. foreach (var col in colNameSettingList)
  3163. {
  3164. cells[2, col.columnIndex].PutValue(col.columnName);
  3165. cells[2, col.columnIndex].SetStyle(style_colName);
  3166. cells.SetColumnWidth(col.columnIndex, col.columnWidth);
  3167. }
  3168. cells.SetRowHeight(2, 25);
  3169. #endregion
  3170. #region 数据填充
  3171. Aspose.Cells.Style style_dataCol = workbook.GetNamedStyle("colName");
  3172. style_dataCol.Font.IsBold = false;
  3173. style_dataCol.Name = "dataCol";
  3174. Aspose.Cells.Style style_dataBlue = workbook.CreateStyle();
  3175. style_dataBlue.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  3176. style_dataBlue.VerticalAlignment = TextAlignmentType.Center;
  3177. style_dataBlue.Font.Name = "微软雅黑";//文字字体
  3178. style_dataBlue.Font.Size = 12;//文字大小
  3179. style_dataBlue.IsLocked = false;//单元格解锁
  3180. style_dataBlue.Font.IsBold = false;//粗体
  3181. style_dataBlue.ForegroundColor = Color.FromArgb(189, 215, 238);
  3182. style_dataBlue.Pattern = BackgroundType.Solid;
  3183. style_dataBlue.Font.Color = Color.FromArgb(0, 0, 0);
  3184. style_dataBlue.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  3185. style_dataBlue.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  3186. style_dataBlue.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  3187. style_dataBlue.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  3188. Aspose.Cells.Style style_dataYellow = workbook.CreateStyle();
  3189. style_dataYellow.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  3190. style_dataYellow.VerticalAlignment = TextAlignmentType.Center;
  3191. style_dataYellow.Font.Name = "微软雅黑";//文字字体
  3192. style_dataYellow.Font.Size = 12;//文字大小
  3193. style_dataYellow.IsLocked = false;//单元格解锁
  3194. style_dataYellow.Font.IsBold = false;//粗体
  3195. style_dataYellow.ForegroundColor = Color.FromArgb(255, 242, 204);
  3196. style_dataYellow.Pattern = BackgroundType.Solid;
  3197. style_dataYellow.Font.Color = Color.FromArgb(0, 0, 0);
  3198. style_dataYellow.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  3199. style_dataYellow.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  3200. style_dataYellow.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  3201. style_dataYellow.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  3202. int rowIndex = 4;
  3203. foreach (var d in dataList)
  3204. {
  3205. //内容
  3206. string typeStr = d.PriceDetailTypeStr + d.PriceName;
  3207. cells["B" + rowIndex.ToString()].PutValue(d.PriceTypeStr);
  3208. cells["C" + rowIndex.ToString()].PutValue(d.PriceDtStr);
  3209. cells["D" + rowIndex.ToString()].PutValue(typeStr);
  3210. cells["E" + rowIndex.ToString()].PutValue(d.Price.ToString("#0.00"));
  3211. cells["F" + rowIndex.ToString()].PutValue(d.PriceCount);
  3212. cells["G" + rowIndex.ToString()].PutValue(d.Currency);
  3213. cells["H" + rowIndex.ToString()].PutValue(d.PriceSum.ToString("#0.00"));
  3214. cells["K" + rowIndex.ToString()].PutValue(d.Remark);
  3215. //样式
  3216. cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
  3217. cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
  3218. cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
  3219. cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3220. cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3221. cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3222. cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3223. cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3224. cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3225. cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
  3226. //公式
  3227. cells["H" + rowIndex.ToString()].Formula = string.Format(@"E{0}*F{0}", rowIndex);
  3228. cells["J" + rowIndex.ToString()].Formula = string.Format(@"H{0}*I{0}", rowIndex);
  3229. cells.SetRowHeight(rowIndex - 1, 25);
  3230. rowIndex++;
  3231. }
  3232. cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
  3233. cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
  3234. cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
  3235. cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3236. cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3237. cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3238. cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3239. cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3240. cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3241. cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
  3242. rowIndex++;
  3243. cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
  3244. cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
  3245. cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
  3246. cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3247. cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3248. cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3249. cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3250. cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3251. cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3252. cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
  3253. rowIndex = 3;
  3254. int tempPriceType = 0;
  3255. foreach (var c in dataList)
  3256. {
  3257. if (tempPriceType == c.PriceType)
  3258. {
  3259. continue;
  3260. }
  3261. tempPriceType = c.PriceType;
  3262. int _rowCount = countList.First(s => s.PriceType == tempPriceType).DataCount;
  3263. cells.Merge(rowIndex, 1, _rowCount, 1);
  3264. Aspose.Cells.Range tempRange = cells.CreateRange(rowIndex, 1, _rowCount, 1);
  3265. rowIndex += _rowCount;
  3266. }
  3267. rowIndex = 4 + dataList.Count;
  3268. cells["D" + rowIndex.ToString()].PutValue("合计");
  3269. cells["J" + rowIndex.ToString()].Formula = string.Format(@"SUM(J4,J{0})", rowIndex - 1);
  3270. cells.SetRowHeight(rowIndex - 1, 25);
  3271. rowIndex++;
  3272. cells["D" + rowIndex.ToString()].PutValue("服务费10%开票税金8%");
  3273. cells["J" + rowIndex.ToString()].Formula = string.Format(@"J{0}*1.1*1.08", rowIndex - 1);
  3274. cells.SetRowHeight(rowIndex - 1, 25);
  3275. #endregion
  3276. #region IO
  3277. System.IO.MemoryStream ms = workbook.SaveToStream();//生成数据流
  3278. string fileName = ("GroupExtraCost/超支费用(" + cellValue_Header + ").xlsx");
  3279. byte[] bt = ms.ToArray();
  3280. workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  3281. #endregion
  3282. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  3283. return Ok(JsonView(true, "成功", new { url = rst }));
  3284. }
  3285. #endregion
  3286. #region 信用卡对账
  3287. /// <summary>
  3288. ///将指定的Excel的文件转换成DataTable (Excel的第一个sheet)
  3289. /// </summary>
  3290. /// <param name="fullFielPath">文件的绝对路径</param>
  3291. /// <returns></returns>
  3292. private DataTable WorksheetToTable(string fullFielPath, string sheetName = null)
  3293. {
  3294. //如果是“EPPlus”,需要指定LicenseContext。
  3295. //EPPlus.Core 不需要指定。
  3296. ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
  3297. FileInfo existingFile = new FileInfo(fullFielPath);
  3298. ExcelPackage package = new ExcelPackage(existingFile);
  3299. ExcelWorksheet worksheet = null;
  3300. if (string.IsNullOrEmpty(sheetName))
  3301. {
  3302. //不传入 sheetName 默认取第1个sheet。
  3303. //EPPlus 索引是0
  3304. //EPPlus.Core 索引是1
  3305. worksheet = package.Workbook.Worksheets[0];
  3306. }
  3307. else
  3308. {
  3309. worksheet = package.Workbook.Worksheets[sheetName];
  3310. }
  3311. if (worksheet == null)
  3312. throw new Exception("指定的sheetName不存在");
  3313. return WorksheetToTable(worksheet);
  3314. }
  3315. /// <summary>
  3316. /// 将worksheet转成datatable
  3317. /// </summary>
  3318. /// <param name="worksheet">待处理的worksheet</param>
  3319. /// <returns>返回处理后的datatable</returns>
  3320. private DataTable WorksheetToTable(ExcelWorksheet worksheet)
  3321. {
  3322. //获取worksheet的行数
  3323. int rows = worksheet.Dimension.End.Row;
  3324. //获取worksheet的列数
  3325. int cols = worksheet.Dimension.End.Column;
  3326. DataTable dt = new DataTable(worksheet.Name);
  3327. DataRow dr = null;
  3328. for (int i = 1; i <= rows; i++)
  3329. {
  3330. if (i > 1)
  3331. dr = dt.Rows.Add();
  3332. for (int j = 1; j <= cols; j++)
  3333. {
  3334. //默认将第一行设置为datatable的标题
  3335. if (i == 1)
  3336. dt.Columns.Add(GetString(worksheet.Cells[i, j].Value));
  3337. //剩下的写入datatable
  3338. else
  3339. dr[j - 1] = GetString(worksheet.Cells[i, j].Value);
  3340. }
  3341. }
  3342. return dt;
  3343. }
  3344. private string GetString(object obj)
  3345. {
  3346. if (obj == null)
  3347. return "";
  3348. return obj.ToString();
  3349. }
  3350. private DataTable ExcelFileToDataTable(IFormFile file)
  3351. {
  3352. DataTable dtTest = null;
  3353. using (var stream = new MemoryStream())
  3354. {
  3355. file.CopyTo(stream);
  3356. using (var package = new ExcelPackage(stream))
  3357. {
  3358. ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
  3359. ExcelWorksheet worksheet = package.Workbook.Worksheets[0];
  3360. dtTest = WorksheetToTable(worksheet);
  3361. }
  3362. }
  3363. return dtTest;
  3364. }
  3365. /// <summary>
  3366. /// 信用卡对账
  3367. /// </summary>
  3368. /// <param name="file"></param>
  3369. /// <param name="cardType"></param>
  3370. /// <param name="beginDt"></param>
  3371. /// <param name="endDt"></param>
  3372. /// <returns></returns>
  3373. [HttpPost]
  3374. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3375. public async Task<IActionResult> PostCreditCardBill(IFormFile file, int cardType, string beginDt, string endDt)
  3376. {
  3377. if (file == null || file.Length < 1)
  3378. {
  3379. return Ok(JsonView(false, "请上传文件!"));
  3380. }
  3381. string fileName = file.FileName;
  3382. if (!fileName.EndsWith(".xlsx") && !fileName.EndsWith(".xls"))
  3383. {
  3384. return Ok(JsonView(false, "请上传Excel文件!"));
  3385. }
  3386. if (cardType < 1) return Ok(JsonView(false, "请传入有效的卡类型!"));
  3387. if (string.IsNullOrEmpty(beginDt) || string.IsNullOrEmpty(endDt)) return Ok(JsonView(false, "请输入开始/结束日期!"));
  3388. var beginValid = DateTime.TryParse(beginDt, out _);
  3389. var endValid = DateTime.TryParse(endDt, out _);
  3390. if (!beginValid || !endValid) return Ok(JsonView(false, "请输入正确的日期格式"));
  3391. //读取ExcelFile
  3392. DataTable dt = ExcelFileToDataTable(file);
  3393. dt.TableName = "TB";
  3394. if (dt == null)
  3395. {
  3396. return Ok(JsonView(false, $"您上传的Excel工作表没有内容,请检查!!!"));
  3397. }
  3398. //信用卡信息
  3399. string sql = string.Format($"Select * From Grp_CreditCardPayment Where Isdel = 0 And CTDId = {cardType} And ConsumptionDate between '{beginDt}' and '{endDt}' ");
  3400. var List_ccp = await _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql).ToListAsync();
  3401. if (List_ccp.Count < 1)
  3402. {
  3403. return Ok(JsonView(false, $"未查询到 {beginDt} 至 {endDt} 信用卡账单信息!!!!"));
  3404. }
  3405. //资源信息
  3406. var delegationInfos = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0).ToList();
  3407. var users = _sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0).ToList();
  3408. string url = string.Empty;
  3409. try
  3410. {
  3411. /*
  3412. * 卡类型
  3413. * 74 美元卡 1
  3414. * 75 欧元卡 1
  3415. * 86 招行卡 1
  3416. * 346 中信卡 1
  3417. * 363 交行卡 1
  3418. *
  3419. */
  3420. var ids = new List<int>();
  3421. if (cardType == 74) //美元卡
  3422. {
  3423. var AirGroupReuslt = List_ccp.Where(x => x.CTable == 85).GroupBy(x => x.DIId).ToList();
  3424. if (AirGroupReuslt != null && AirGroupReuslt.Count > 0)
  3425. {
  3426. foreach (var item in AirGroupReuslt)
  3427. {
  3428. if (item.Count() > 1)
  3429. {
  3430. var obj = item.FirstOrDefault();
  3431. obj.RMBPrice = item.Sum(x => x.PayMoney);//合计币种金额
  3432. obj.Remark = "团组机票总价(虚拟)";
  3433. List_ccp.Add(obj);
  3434. }
  3435. }
  3436. }
  3437. //dt.AcceptChanges(); //提交
  3438. //修改table列名
  3439. dt.Columns[0].ColumnName = "accountType"; // 账户类型
  3440. dt.Columns[1].ColumnName = "tradeDate"; //交易日期
  3441. dt.Columns[2].ColumnName = "BillingDate"; // 记账日期
  3442. dt.Columns[3].ColumnName = "CardNo"; // 卡号
  3443. dt.Columns[4].ColumnName = "deposit"; // 存入金额
  3444. dt.Columns[5].ColumnName = "SpendingAmount"; // 支出金额
  3445. dt.Columns[6].ColumnName = "TransactionDescription"; // 交易描述
  3446. dt.Columns[7].ColumnName = "TeamRemark"; // 团组备注描述
  3447. dt.Columns[8].ColumnName = "Handlers"; // 经手人
  3448. dt.Columns[9].ColumnName = "State"; // 状态
  3449. //删除第一行数据
  3450. if (dt.Rows.Count > 0)
  3451. {
  3452. string accountType = dt.Rows[0]["accountType"].ToString();
  3453. if (dt.Rows[0]["accountType"].ToString().Equals("账户类型"))
  3454. {
  3455. dt.Rows[0].Delete();
  3456. dt.AcceptChanges(); //提交
  3457. }
  3458. }
  3459. foreach (DataRow item in dt.Rows)
  3460. {
  3461. #region 匹配的金额
  3462. decimal ExcelAmount = 0.00M;
  3463. decimal deposit = 0.00M;
  3464. if (!string.IsNullOrEmpty(item["SpendingAmount"].ToString()))
  3465. {
  3466. var isParase = decimal.TryParse(item["SpendingAmount"].ToString(), out ExcelAmount);
  3467. if (isParase)
  3468. {
  3469. var CList = List_ccp.FindAll(x => x.PayMoney == ExcelAmount);
  3470. if (CList != null && CList.Count > 0)
  3471. {
  3472. item["TeamRemark"] = delegationInfos.Find(it => it.Id == CList.First().DIId)?.TeamName;
  3473. item["Handlers"] = users.Find(it => it.Id == CList.First().CreateUserId)?.CnName;
  3474. item["State"] = 1;
  3475. }
  3476. }
  3477. }
  3478. if (!string.IsNullOrEmpty(item["deposit"].ToString()))
  3479. {
  3480. var isParse = decimal.TryParse(item["deposit"].ToString(), out deposit);
  3481. if (isParse)
  3482. {
  3483. var CList = List_ccp.FindAll(x => x.PayMoney == deposit);
  3484. if (CList != null && CList.Count > 0)
  3485. {
  3486. item["TeamRemark"] = delegationInfos.Find(it => it.Id == CList.First().DIId)?.TeamName;
  3487. item["Handlers"] = users.Find(it => it.Id == CList.First().CreateUserId)?.CnName;
  3488. item["State"] = 1;
  3489. }
  3490. }
  3491. }
  3492. #endregion
  3493. //交易描述
  3494. if (!string.IsNullOrEmpty(item["TransactionDescription"].ToString()))
  3495. {
  3496. string TransactionDescription = item["TransactionDescription"].ToString();
  3497. var startIndex = TransactionDescription.LastIndexOf("[");
  3498. var endIndex = TransactionDescription.LastIndexOf("]");
  3499. if (startIndex != -1 && endIndex != -1)
  3500. {
  3501. var moenyList = TransactionDescription.Substring(startIndex + 1, endIndex - startIndex - 1).Split(' ').
  3502. Where(x => !string.IsNullOrEmpty(x)).ToList();
  3503. decimal money = 0.00M;
  3504. foreach (var itemMoeny in moenyList)
  3505. {
  3506. if (itemMoeny.Contains('.'))
  3507. {
  3508. string itemMoenyStr = itemMoeny.Replace(",", string.Empty);
  3509. bool istrue = decimal.TryParse(itemMoenyStr, out money);
  3510. if (istrue)
  3511. {
  3512. var CList = List_ccp.FindAll(x => x.PayMoney == money);
  3513. if (CList != null && CList.Count > 0)
  3514. {
  3515. item["TeamRemark"] = delegationInfos.Find(it => it.Id == CList.First().DIId)?.TeamName;
  3516. item["Handlers"] = users.Find(it => it.Id == CList.First().CreateUserId)?.CnName;
  3517. item["State"] = 1;
  3518. }
  3519. }
  3520. }
  3521. }
  3522. }
  3523. }
  3524. }
  3525. string fileName1 = $"信用卡账单(美元卡){DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  3526. Dictionary<string, object> pairs = new Dictionary<string, object>();
  3527. List<DataTable> datas = new List<DataTable>();
  3528. datas.Add(dt);
  3529. url = AsposeHelper.ExpertExcelToModel("信用卡对账模板-美元卡.xls", $"CreditCardBill", fileName1, pairs, datas);
  3530. }
  3531. else if (cardType == 75) //欧元卡
  3532. {
  3533. if (dt.Rows.Count > 0)
  3534. {
  3535. string accountType = dt.Rows[0][0].ToString();
  3536. if (accountType.Equals("账户类型"))
  3537. {
  3538. dt.Rows[0].Delete();
  3539. dt.AcceptChanges(); //提交
  3540. }
  3541. }
  3542. //dt.Columns[0].ColumnName = "All";
  3543. DataTable dt1 = new DataTable();
  3544. dt1.TableName = "TB";
  3545. dt1.Columns.Add("TradingDate", Type.GetType("System.String"));//交易日期
  3546. dt1.Columns.Add("TallyDate", Type.GetType("System.String")); //记账日期
  3547. dt1.Columns.Add("TradindDesc", Type.GetType("System.String"));//交易描述
  3548. dt1.Columns.Add("TradindMoney", Type.GetType("System.String"));//交易币种/金额
  3549. dt1.Columns.Add("ClearindMoney", Type.GetType("System.String"));// 清算币种/金额
  3550. dt1.Columns.Add("TeamRemark", Type.GetType("System.String")); //团组备注描述
  3551. dt1.Columns.Add("Handlers", Type.GetType("System.String")); //经手人
  3552. dt1.Columns.Add("State", Type.GetType("System.String")); //状态
  3553. for (int i = 0; i < dt.Rows.Count; i++)
  3554. {
  3555. string[] str = dt.Rows[i]["All"].ToString().Split(' ');
  3556. //string[] str = dt.Rows[i];
  3557. DataRow dr = dt1.NewRow();
  3558. dr["TradingDate"] = str[0].ToString();
  3559. dr["TallyDate"] = str[1].ToString();
  3560. dr["TradindDesc"] = str[2].ToString() + " " + str[3].ToString();
  3561. dr["TradindMoney"] = str[4].ToString() + " " + str[5].ToString();
  3562. dr["ClearindMoney"] = str[6].ToString() + " " + str[7].ToString();
  3563. dt1.Rows.Add(dr);
  3564. }
  3565. foreach (DataRow item in dt1.Rows)
  3566. {
  3567. for (int i = 0; i < List_ccp.Count; i++)
  3568. {
  3569. DateTime dtTime1 = Convert.ToDateTime(item["TradingDate"].ToString() == "" ? DateTime.Now.ToString("MM/dd") : item["TradingDate"].ToString()); //交易日期
  3570. string USDPrice = item["TradindMoney"].ToString(); //支出金额
  3571. USDPrice = USDPrice.Split(' ')[1].Trim(); //替换掉非数字
  3572. //USDPrice = USDPrice.Split('/')[1];
  3573. // 经手人 and excel行状态
  3574. if (!string.IsNullOrEmpty(List_ccp[i].ConsumptionDate) && !string.IsNullOrEmpty(USDPrice))
  3575. {
  3576. DateTime dtTime2 = Convert.ToDateTime(List_ccp[i].ConsumptionDate.ToString() == "" ? DateTime.Now.ToString("MM/dd") : List_ccp[i].ConsumptionDate.ToString());
  3577. float price1 = float.Parse(USDPrice);
  3578. float price2 = float.Parse(List_ccp[i].PayMoney.ToString("F2"));
  3579. if (dtTime1 == dtTime2 && price1 == price2)
  3580. {
  3581. item["TeamRemark"] = delegationInfos.Find(it => it.Id == List_ccp[i].DIId)?.TeamName;
  3582. item["Handlers"] = users.Find(it => it.Id == List_ccp[i].CreateUserId)?.CnName;
  3583. item["State"] = "1";
  3584. i = List_ccp.Count - 1;
  3585. }
  3586. else item["State"] = "0";
  3587. }
  3588. else item["State"] = "0";
  3589. }
  3590. if (item["TradindDesc"].ToString().Contains("财付通"))
  3591. item["State"] = "2";
  3592. else if (item["TradindDesc"].ToString().Contains("京东"))
  3593. item["State"] = "2";
  3594. else if (item["TradindDesc"].ToString().Contains("微信支付"))
  3595. item["State"] = "2";
  3596. else if (item["TradindDesc"].ToString().Contains("淘宝"))
  3597. item["State"] = "2";
  3598. }
  3599. string fileName1 = $"信用卡账单(欧元卡){DateTime.Now.ToString("yyyy.MM.dd")}.xls";
  3600. Dictionary<string, object> pairs = new Dictionary<string, object>();
  3601. List<DataTable> datas = new List<DataTable>();
  3602. datas.Add(dt);
  3603. url = AsposeHelper.ExpertExcelToModel("信用卡对账模板-欧元卡.xls", "TB", fileName1, pairs, datas);
  3604. }
  3605. else if (cardType == 86) //招行卡
  3606. {
  3607. var AirGroupReuslt1 = List_ccp.Where(x => x.CTable == 85).GroupBy(x => x.DIId).ToList();
  3608. if (AirGroupReuslt1 != null && AirGroupReuslt1.Count > 0)
  3609. {
  3610. foreach (var item in AirGroupReuslt1)
  3611. {
  3612. if (item.Count() > 1)
  3613. {
  3614. var di = delegationInfos.Find(it => it.Id == item.Key);
  3615. var obj = item.FirstOrDefault();
  3616. obj.Remark = "团组机票总价";
  3617. if (di != null)
  3618. {
  3619. obj.Remark = "团组机票总价(" + di.TeamName + ")";
  3620. }
  3621. obj.RMBPrice = item.Sum(x => x.RMBPrice);//合计人民币
  3622. List_ccp.Add(obj);
  3623. }
  3624. }
  3625. }
  3626. //查询所有刷卡的团组
  3627. //将刷卡团组内刷卡金额的金额存入ccp_list
  3628. //将excel作比较
  3629. //机票刷卡记录
  3630. var AirListAndPayID = List_ccp.Where(x => x.CTable == 85 && x.PayDId == 72).Select(x => x.DIId).Distinct().ToList();
  3631. var AirData = _sqlSugar.Queryable<Grp_AirTicketReservations>().Where(it => AirListAndPayID.Contains(it.DIId) && it.PrePrice != it.Price).ToList();
  3632. foreach (var item in AirData)
  3633. {
  3634. var DBwhere = List_ccp.Find(x => x.PayMoney == item.PrePrice);
  3635. if (DBwhere == null)
  3636. {
  3637. List_ccp.Add(new Grp_CreditCardPayment
  3638. {
  3639. PayMoney = item.PrePrice,
  3640. DIId = item.DIId,
  3641. CreateUserId = item.CreateUserId,
  3642. Remark = "(机票单价价格)",
  3643. });
  3644. }
  3645. }
  3646. var HotelGroupReuslt = List_ccp.Where(x => x.CTable == 76).GroupBy(x => x.DIId).ToList();
  3647. if (HotelGroupReuslt != null && HotelGroupReuslt.Count > 0)
  3648. {
  3649. foreach (var item in HotelGroupReuslt)
  3650. {
  3651. if (item.Count() > 1)
  3652. {
  3653. var di = delegationInfos.Find(it => it.Id == item.Key);
  3654. var obj = item.FirstOrDefault();
  3655. obj.Remark = "团组酒店总价";
  3656. if (di != null)
  3657. {
  3658. obj.Remark = "团组酒店总价(" + di.TeamName + ")";
  3659. }
  3660. obj.RMBPrice = item.Sum(x => x.RMBPrice);//合计人民币
  3661. List_ccp.Add(obj);
  3662. }
  3663. }
  3664. }
  3665. #region
  3666. dt.Rows[0].Delete();//删除列名行
  3667. dt.AcceptChanges();
  3668. DataTable dt1 = new DataTable();
  3669. dt1.TableName = "TB";
  3670. dt1.Columns.Add("TradingDay", Type.GetType("System.String")); // 交易日
  3671. dt1.Columns.Add("TallyDay", Type.GetType("System.String")); // 记账日
  3672. dt1.Columns.Add("TransactionDesc", Type.GetType("System.String")); // 交易描述
  3673. dt1.Columns.Add("RMBMoney", Type.GetType("System.String")); // 人名币金额
  3674. dt1.Columns.Add("CardNo", Type.GetType("System.String")); // 卡号
  3675. dt1.Columns.Add("TradingMoney", Type.GetType("System.String")); // 交易地金额
  3676. dt1.Columns.Add("Currency", Type.GetType("System.String")); // 币种
  3677. dt1.Columns.Add("TeamRemark", Type.GetType("System.String")); //团组备注描述
  3678. dt1.Columns.Add("Handlers", Type.GetType("System.String")); //经手人
  3679. dt1.Columns.Add("State", Type.GetType("System.String")); //状态
  3680. for (int j = 0; j < dt.Rows.Count; j++)//遍历行
  3681. {
  3682. DataRow dr = dt1.NewRow(); //获取每一行的数据
  3683. dr["TradingDay"] = dt.Rows[j][0].ToString();
  3684. dr["TallyDay"] = dt.Rows[j][1].ToString();
  3685. dr["TransactionDesc"] = dt.Rows[j][2].ToString();
  3686. dr["RMBMoney"] = dt.Rows[j][3].ToString();
  3687. dr["CardNo"] = dt.Rows[j][4].ToString();
  3688. string currency = "CN";
  3689. string money = dt.Rows[j][5].ToString();
  3690. if (money.Contains('('))
  3691. {
  3692. string[] strs = money.Split('(');
  3693. money = strs[0];
  3694. currency = strs[1].Replace(")", "");
  3695. }
  3696. dr["TradingMoney"] = money;
  3697. dr["Currency"] = currency;
  3698. if (string.IsNullOrEmpty(money))
  3699. {
  3700. continue;
  3701. }
  3702. dt1.Rows.Add(dr);
  3703. }
  3704. //datatable 排序
  3705. dt1.DefaultView.Sort = "TradingDay asc";
  3706. dt1 = dt1.DefaultView.ToTable();
  3707. foreach (DataRow item in dt1.Rows)
  3708. {
  3709. if (item["TradingDay"] == "" && item["RMBMoney"] == "")
  3710. {
  3711. continue;
  3712. }
  3713. //excel获取交易日期
  3714. string ExcelDt = string.Empty;
  3715. //C表交易日期
  3716. string DBDt = string.Empty;
  3717. //excel交易的金额
  3718. decimal TradingMoney = decimal.Parse(item["TradingMoney"].ToString());
  3719. if (item["TradingDay"] != null)
  3720. {
  3721. ExcelDt = DateTime.Parse(item["TradingDay"].ToString()).ToString("MMdd");
  3722. }
  3723. //加一获取金额区间
  3724. decimal MaxTradingMoney = TradingMoney + 1;
  3725. decimal MinTradingMoney = TradingMoney - 1;
  3726. //匹配C表金额相等的值
  3727. var CList = List_ccp.FindAll(x => x.PayMoney < MaxTradingMoney && x.PayMoney > MinTradingMoney);
  3728. if (CList != null && CList.Count > 0)
  3729. {
  3730. #region 日期匹配
  3731. foreach (var Citem in CList)
  3732. {
  3733. if (!string.IsNullOrWhiteSpace(Citem.ConsumptionDate))
  3734. {
  3735. DBDt = DateTime.Parse(Citem.ConsumptionDate).ToString("MMdd");
  3736. if (DBDt == ExcelDt)
  3737. {
  3738. item["TeamRemark"] = delegationInfos.Find(it => it.Id == Citem.DIId)?.TeamName;
  3739. item["Handlers"] = users.Find(it => it.Id == Citem.CreateUserId)?.CnName;
  3740. ids.Add(Citem.Id);
  3741. }
  3742. }
  3743. }
  3744. #endregion
  3745. }
  3746. if (item["TransactionDesc"].ToString().Contains("财付通"))
  3747. item["State"] = "2";
  3748. else if (item["TransactionDesc"].ToString().Contains("京东支付"))
  3749. item["State"] = "2";
  3750. else if (item["TransactionDesc"].ToString().Contains("微信支付"))
  3751. item["State"] = "2";
  3752. else if (item["TransactionDesc"].ToString().Contains("淘宝"))
  3753. item["State"] = "2";
  3754. else if (item["TransactionDesc"].ToString().Contains("支付宝"))
  3755. item["State"] = "2";
  3756. else if (item["TransactionDesc"].ToString().Contains("拼多多"))
  3757. item["State"] = "2";
  3758. else
  3759. item["State"] = "0";
  3760. if (!string.IsNullOrEmpty(item["TeamRemark"].ToString()) && !string.IsNullOrEmpty(item["Handlers"].ToString()))
  3761. item["State"] = "1";
  3762. }
  3763. //更改匹配项状态
  3764. if (ids.Count > 0)
  3765. {
  3766. var _CreditCardPayments = new List<Grp_CreditCardPayment>();
  3767. foreach (var item in ids)
  3768. {
  3769. _CreditCardPayments.Add(new Grp_CreditCardPayment() { Id = item, IsMatchCreditCard = 1.00M });
  3770. }
  3771. var updateStatus = _sqlSugar.Updateable<Grp_CreditCardPayment>(_CreditCardPayments)
  3772. .UpdateColumns(it => new { it.IsMatchCreditCard })
  3773. .Where(it => ids.Contains(it.Id))
  3774. .ExecuteCommand();
  3775. }
  3776. string fileName1 = $"信用卡账单(招行卡){DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  3777. Dictionary<string, object> pairs = new Dictionary<string, object>();
  3778. List<DataTable> datas = new List<DataTable>();
  3779. datas.Add(dt1);
  3780. url = AsposeHelper.ExpertExcelToModel("信用卡对账模板-招行卡.xls", "CreditCardBill", fileName1, pairs, datas);
  3781. #endregion
  3782. }
  3783. else if (cardType == 346) //中信卡
  3784. {
  3785. dt.Columns.Add("TeamRemark", Type.GetType("System.String")); //团组备注描述
  3786. dt.Columns.Add("Handlers", Type.GetType("System.String")); //经手人
  3787. dt.Columns.Add("State", Type.GetType("System.String")); //状态
  3788. //修改table列名
  3789. dt.Columns[0].ColumnName = "TransactionDesc"; // 交易描述
  3790. dt.Columns[1].ColumnName = "TradingCurrencyAndMoney"; // 交易币种和金额
  3791. dt.Columns[2].ColumnName = "TransactionDate"; // 交易日期
  3792. dt.Columns[3].ColumnName = "SettlementCurrencyAndMoney";// 结算币种和金额
  3793. dt.Columns[4].ColumnName = "BookedDate"; // 入账日期
  3794. foreach (DataRow item in dt.Rows)
  3795. {
  3796. for (int i = 0; i < List_ccp.Count; i++)
  3797. {
  3798. if (string.IsNullOrEmpty(item["TransactionDate"].ToString()))
  3799. break;
  3800. DateTime dtTime1 = Convert.ToDateTime(item["TransactionDate"].ToString()); //交易日期
  3801. string USDPrice = item["TradingCurrencyAndMoney"].ToString(); //支出金额
  3802. USDPrice = USDPrice.Split('/')[1];
  3803. //string USDPrice1 = USDPrice.ToString("0.00");
  3804. // 经手人 and excel行状态
  3805. if (!string.IsNullOrEmpty(List_ccp[i].ConsumptionDate) && !string.IsNullOrEmpty(USDPrice))
  3806. {
  3807. DateTime dtTime2 = Convert.ToDateTime(List_ccp[i].ConsumptionDate);
  3808. float price1 = float.Parse(USDPrice);
  3809. float price2 = float.Parse(List_ccp[i].PayMoney.ToString("F2"));
  3810. if (dtTime1 == dtTime2 && price1 == price2)
  3811. {
  3812. item["TeamRemark"] = delegationInfos.Find(it => it.Id == List_ccp[i].DIId)?.TeamName;
  3813. item["Handlers"] = users.Find(it => it.Id == List_ccp[i].CreateUserId)?.CnName;
  3814. item["State"] = "1";
  3815. i = List_ccp.Count - 1;
  3816. }
  3817. else
  3818. item["State"] = "0";
  3819. }
  3820. else
  3821. item["State"] = "0";
  3822. }
  3823. //判断是否是数字
  3824. //if (IsNumber(item["TradingCurrencyAndMoney"].ToString().Split('/')[1]) == false)
  3825. // item["State"] = "0";
  3826. if (item["TransactionDesc"].ToString().Contains("财付通"))
  3827. item["State"] = "2";
  3828. else if (item["TransactionDesc"].ToString().Contains("京东"))
  3829. item["State"] = "2";
  3830. else if (item["TransactionDesc"].ToString().Contains("微信支付"))
  3831. item["State"] = "2";
  3832. else if (item["TransactionDesc"].ToString().Contains("淘宝"))
  3833. item["State"] = "2";
  3834. }
  3835. #region DownExcel
  3836. string fileName1 = $"信用卡账单(中信卡){DateTime.Now.ToString("yyyy.MM.dd")}.xls";
  3837. Dictionary<string, object> pairs = new Dictionary<string, object>();
  3838. List<DataTable> datas = new List<DataTable>();
  3839. datas.Add(dt);
  3840. url = AsposeHelper.ExpertExcelToModel("信用卡对账模板-中信卡.xls", "TB", fileName1, pairs, datas);
  3841. #endregion
  3842. }
  3843. else if (cardType == 363) //交行卡
  3844. {
  3845. dt.Columns[0].ColumnName = "All";
  3846. DataTable dt1 = new DataTable();
  3847. dt1.Columns.Add("TradingDate", Type.GetType("System.String"));//交易日期
  3848. dt1.Columns.Add("TallyDate", Type.GetType("System.String")); //记账日期
  3849. dt1.Columns.Add("TradindDesc", Type.GetType("System.String"));//交易描述
  3850. dt1.Columns.Add("TradindMoney", Type.GetType("System.String"));//交易币种/金额
  3851. dt1.Columns.Add("ClearindMoney", Type.GetType("System.String"));// 清算币种/金额
  3852. dt1.Columns.Add("TeamRemark", Type.GetType("System.String")); //团组备注描述
  3853. dt1.Columns.Add("Handlers", Type.GetType("System.String")); //经手人
  3854. dt1.Columns.Add("State", Type.GetType("System.String")); //状态
  3855. for (int i = 0; i < dt.Rows.Count; i++)
  3856. {
  3857. string[] str = dt.Rows[i]["All"].ToString().Split(' ');
  3858. DataRow dr = dt1.NewRow();
  3859. dr["TradingDate"] = str[0].ToString();
  3860. dr["TallyDate"] = str[1].ToString();
  3861. dr["TradindDesc"] = str[2].ToString() + " " + str[3].ToString();
  3862. dr["TradindMoney"] = str[4].ToString() + " " + str[5].ToString();
  3863. dr["ClearindMoney"] = str[6].ToString() + " " + str[7].ToString();
  3864. dt1.Rows.Add(dr);
  3865. }
  3866. foreach (DataRow item in dt1.Rows)
  3867. {
  3868. for (int i = 0; i < List_ccp.Count; i++)
  3869. {
  3870. DateTime dtTime1 = Convert.ToDateTime(item["TradingDate"].ToString() == "" ? DateTime.Now.ToString("MM/dd") : item["TradingDate"].ToString()); //交易日期
  3871. string USDPrice = item["TradindMoney"].ToString(); //支出金额
  3872. USDPrice = USDPrice.Split(' ')[1].Trim(); //替换掉非数字
  3873. //USDPrice = USDPrice.Split('/')[1];
  3874. // 经手人 and excel行状态
  3875. if (!string.IsNullOrEmpty(List_ccp[i].ConsumptionDate) && !string.IsNullOrEmpty(USDPrice))
  3876. {
  3877. DateTime dtTime2 = Convert.ToDateTime(List_ccp[i].ConsumptionDate.ToString() == "" ? DateTime.Now.ToString("MM/dd") : List_ccp[i].ConsumptionDate.ToString());
  3878. float price1 = float.Parse(USDPrice);
  3879. float price2 = float.Parse(List_ccp[i].PayMoney.ToString("F2"));
  3880. if (dtTime1 == dtTime2 && price1 == price2)
  3881. {
  3882. item["TeamRemark"] = delegationInfos.Find(it => it.Id == List_ccp[i].DIId)?.TeamName;
  3883. item["Handlers"] = users.Find(it => it.Id == List_ccp[i].CreateUserId)?.CnName;
  3884. item["State"] = "1";
  3885. i = List_ccp.Count - 1;
  3886. }
  3887. else
  3888. item["State"] = "0";
  3889. }
  3890. else
  3891. item["State"] = "0";
  3892. }
  3893. if (item["TradindDesc"].ToString().Contains("财付通"))
  3894. item["State"] = "2";
  3895. else if (item["TradindDesc"].ToString().Contains("京东"))
  3896. item["State"] = "2";
  3897. else if (item["TradindDesc"].ToString().Contains("微信支付"))
  3898. item["State"] = "2";
  3899. else if (item["TradindDesc"].ToString().Contains("淘宝"))
  3900. item["State"] = "2";
  3901. }
  3902. string fileName1 = $"信用卡账单(交行卡){DateTime.Now.ToString("yyyy.MM.dd")}.xls";
  3903. Dictionary<string, object> pairs = new Dictionary<string, object>();
  3904. List<DataTable> datas = new List<DataTable>();
  3905. datas.Add(dt);
  3906. url = AsposeHelper.ExpertExcelToModel("信用卡对账模板-交行卡.xls", "TB", fileName1, pairs, datas);
  3907. }
  3908. }
  3909. catch (Exception ex)
  3910. {
  3911. return Ok(JsonView(false, $"匹配失败,{ex.Message}!"));
  3912. }
  3913. return Ok(JsonView(true, "操作成功", new { url = url }));
  3914. }
  3915. /// <summary>
  3916. /// 把数据从Excel装载到DataTable
  3917. /// </summary>
  3918. /// <param name="pathName">带路径的Excel文件名</param>
  3919. /// <param name="sheetName">工作表名</param>
  3920. /// <param name="tbContainer">将数据存入的DataTable</param>
  3921. /// <returns></returns>
  3922. public static DataTable ExcelToDataTable(string pathName, string sheetName)
  3923. {
  3924. DataTable tbContainer = new DataTable();
  3925. string strConn = string.Empty;
  3926. if (string.IsNullOrEmpty(sheetName)) { sheetName = "Sheet1"; }
  3927. FileInfo file = new FileInfo(pathName);
  3928. if (!file.Exists) { throw new Exception("文件不存在"); }
  3929. string extension = file.Extension;
  3930. switch (extension)
  3931. {
  3932. case ".xls":
  3933. strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathName + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
  3934. break;
  3935. case ".xlsx":
  3936. strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pathName + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1;'";
  3937. break;
  3938. default:
  3939. strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathName + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
  3940. break;
  3941. }
  3942. //链接Excel
  3943. OleDbConnection cnnxls = new OleDbConnection(strConn);
  3944. //读取Excel里面有 表Sheet1
  3945. System.Data.OleDb.OleDbDataAdapter oda = new System.Data.OleDb.OleDbDataAdapter(string.Format("select * from [{0}$]", sheetName), cnnxls);
  3946. DataSet ds = new DataSet();
  3947. //将Excel里面有表内容装载到内存表中!
  3948. oda.Fill(tbContainer);
  3949. return tbContainer;
  3950. }
  3951. #endregion
  3952. #region 提成计算
  3953. /// <summary>
  3954. /// 提成计算
  3955. /// </summary>
  3956. /// <param name="dto"></param>
  3957. /// <returns></returns>
  3958. [HttpPost]
  3959. public IActionResult ComputeRoyalties(ComputeRoyaltiesDto dto)
  3960. {
  3961. var jw = JsonView(false);
  3962. var userId = dto.UserId;
  3963. var user = _sqlSugar.Queryable<Sys_Users>().First(x=>x.Id == userId);
  3964. if (user == null)
  3965. {
  3966. jw.Msg = "暂无该用户!";
  3967. return Ok(jw);
  3968. }
  3969. if (!DateTime.TryParse(dto.StartDate,out DateTime StartDateTime))
  3970. {
  3971. jw.Msg = "开始时间格式有误!";
  3972. return Ok(jw);
  3973. }
  3974. if (!DateTime.TryParse(dto.EndDate, out DateTime EndDateTime))
  3975. {
  3976. jw.Msg = "结束时间格式有误!";
  3977. return Ok(jw);
  3978. }
  3979. if (DateTime.Compare(StartDateTime,EndDateTime) > 0)
  3980. {
  3981. jw.Msg = "开始时间大于结束时间!";
  3982. return Ok(jw);
  3983. }
  3984. //机票 职位表id 24
  3985. int[] AirTicket = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.JobPostId == 24).Select(x => x.Id).ToArray();
  3986. //酒店 职位表id 25
  3987. int[] Hotel = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.JobPostId == 25).Select(x => x.Id).ToArray();
  3988. //OP 职位表id 28
  3989. int [] OP = _sqlSugar.Queryable<Sys_Users>().Where(x=>x.IsDel == 0 && x.JobPostId == 28).Select(x=>x.Id).ToArray();
  3990. //商邀 职位表id 27
  3991. int [] Invitation = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.JobPostId == 27).Select(x => x.Id).ToArray();
  3992. //签证 职位表id 26
  3993. int[] Visa = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.JobPostId == 26 ).Select(x => x.Id).ToArray();
  3994. //主管职位
  3995. //string[] Manager = { "149", "283" };
  3996. ArrayList resultArr = new ArrayList();
  3997. var teamLv = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.STid == 56 && x.IsDel == 0).ToList();
  3998. if (AirTicket.Contains(userId))
  3999. {
  4000. var listAir = _sqlSugar.Queryable<Grp_AirTicketReservations, Grp_DelegationInfo, Grp_CreditCardPayment>((x, a, b) => new
  4001. JoinQueryInfos(
  4002. JoinType.Left, a.Id == x.DIId ,
  4003. JoinType.Left, b.CTable == 85 && b.CId == x.Id )
  4004. ).Where((x, a, b) => x.IsDel == 0 && x.CreateUserId == userId && (b.IsAuditGM == 1 || b.IsAuditGM == 3)
  4005. && a.IsDel == 0 && a.VisitDate > StartDateTime && a.VisitDate < EndDateTime && b.IsDel == 0)
  4006. .Select((x, a, b) => new
  4007. {
  4008. x.FlightsDescription,
  4009. a.Id,
  4010. a.TeamName,
  4011. a.VisitDate,
  4012. a.TeamLevSId,
  4013. a.VisitPNumber,
  4014. x.Price,
  4015. x.ClientName,
  4016. x.ClientNum,
  4017. x.FlightsCode,
  4018. }).ToList();
  4019. var groupByid = listAir.GroupBy(x => x.Id);
  4020. foreach (var airArr in groupByid)
  4021. {
  4022. var groupAirCount = 0; //团组航段数量
  4023. var infos = new ArrayList();
  4024. foreach (var air in airArr)
  4025. {
  4026. var airCount = 0; // 单条航段数量
  4027. if (air.FlightsDescription.IsNullOrWhiteSpace())
  4028. {
  4029. continue;
  4030. }
  4031. if (air.ClientName.Contains("-1") || air.ClientName.Contains("行程单") || air.FlightsCode.Contains("行程单"))
  4032. {
  4033. continue;
  4034. }
  4035. string errMsg = string.Empty;
  4036. if (air.FlightsDescription.Contains("\r\n"))
  4037. {
  4038. var rowCode = Regex.Split(air.FlightsDescription, "\\d+\\.", RegexOptions.IgnoreCase).Where(x=>!string.IsNullOrWhiteSpace(x)).ToArray();
  4039. for (int i = 0; i < rowCode.Length; i++)
  4040. {
  4041. if (i != 0)
  4042. {
  4043. try
  4044. {
  4045. var columnValue = rowCode[i].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  4046. string day = columnValue[2].Substring(2, 2);//日
  4047. string monthAbbreviations = columnValue[2].Substring(4, 3).ToUpper();//月份
  4048. monthAbbreviations = GeneralMethod.GetLonger(monthAbbreviations);
  4049. string EndHHmm = columnValue[5].Substring(0, 2) + ":" + columnValue[5].Substring(2, 2);
  4050. DateTime EndData = DateTime.Parse($"{DateTime.Now.Year}-{monthAbbreviations}-{day} {EndHHmm}");//当前班次
  4051. var spDotandEmpty1 = rowCode[i - 1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  4052. string day1 = spDotandEmpty1[2].Substring(2, 2);//日
  4053. string monthAbbreviations1 = spDotandEmpty1[2].Substring(4, 3).ToUpper();//月份
  4054. monthAbbreviations1 = GeneralMethod.GetLonger(monthAbbreviations1);
  4055. string HHmm = spDotandEmpty1[6].Substring(0, 2) + ":" + spDotandEmpty1[6].Substring(2, 2);
  4056. DateTime data = DateTime.Parse($"{DateTime.Now.Year}-{monthAbbreviations1}-{day1} {HHmm}");//上个班次
  4057. TimeSpan t3 = EndData - data; //两个时间相减 。默认得到的是 两个时间之间的天数 得到:365.00:00:00
  4058. double getHour = t3.TotalHours;
  4059. if (getHour >= 6)
  4060. {
  4061. if (air.Price > 0)
  4062. {
  4063. airCount += 1;
  4064. }
  4065. else
  4066. {
  4067. airCount -= 1;
  4068. }
  4069. }
  4070. }
  4071. catch (Exception ex)
  4072. {
  4073. errMsg = "机票行程代码格式有误!解析失败!" + $"({ex.Message})";
  4074. break;
  4075. }
  4076. }
  4077. else
  4078. {
  4079. if (air.Price > 0)
  4080. {
  4081. airCount += 1;
  4082. }
  4083. else
  4084. {
  4085. airCount -= 1;
  4086. }
  4087. }
  4088. }
  4089. }
  4090. else
  4091. {
  4092. if (air.Price > 0)
  4093. {
  4094. airCount++;
  4095. }
  4096. else
  4097. {
  4098. airCount--;
  4099. }
  4100. }
  4101. string info = $"航班{air.FlightsCode} {(air.Price > 0 ? "" : "此笔为退费!")} 人数为{air.ClientNum} 有效段数为{airCount} 总段数为{airCount * air.ClientNum}";
  4102. if (!string.IsNullOrWhiteSpace(errMsg))
  4103. {
  4104. info = $"航班{air.FlightsCode} " + errMsg ;
  4105. }
  4106. infos.Add(info);
  4107. groupAirCount += airCount * air.ClientNum;
  4108. }
  4109. var groupinfo = listAir.First(x => x.Id == airArr.Key);
  4110. string temp = "本团人数" + Convert.ToInt32(groupinfo.VisitPNumber) + ",该人员" + user.CnName + "共订航段数" + groupAirCount.ToString() + ",每程航班提成为10元," + user.CnName + "提成共" + (groupAirCount * 10).ToString("#0.00");
  4111. resultArr.Add(new
  4112. {
  4113. groupinfo.TeamName,
  4114. groupinfo.Id,
  4115. chiArr = infos,
  4116. teamLvStr = teamLv.Find(x=>x.Id == groupinfo.TeamLevSId)?.Name,
  4117. groupinfo.VisitDate,
  4118. temp,
  4119. price = (groupAirCount * 10),
  4120. }) ;
  4121. }
  4122. }
  4123. else if (Hotel.Contains(userId))
  4124. {
  4125. var listHotel = _sqlSugar.Queryable<Grp_HotelReservations, Grp_DelegationInfo>((x, a) => x.DiId == a.Id)
  4126. .Where((x, a) => x.IsDel == 0 && x.CreateUserId == userId && a.VisitDate > StartDateTime && a.VisitDate < EndDateTime && a.IsDel == 0).ToList();
  4127. }
  4128. else if (OP.Contains(userId))
  4129. {
  4130. }
  4131. jw.Data = resultArr;
  4132. if (resultArr.Count > 0)
  4133. {
  4134. jw.Code = 200;
  4135. jw.Msg = "success!";
  4136. }
  4137. else
  4138. {
  4139. jw.Msg = "暂无数据!";
  4140. }
  4141. return Ok(jw);
  4142. }
  4143. #endregion
  4144. }
  4145. }