FinancialController.cs 227 KB

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