FinancialController.cs 229 KB

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