FinancialController.cs 207 KB

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