FinancialController.cs 207 KB

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