FinancialController.cs 221 KB

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