FinancialController.cs 303 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495
  1. using Aspose.Cells;
  2. using Aspose.Words;
  3. using Aspose.Words.Drawing;
  4. using EyeSoft.Extensions;
  5. using EyeSoft.IO;
  6. using EyeSoft.Runtime.InteropServices;
  7. using FluentValidation;
  8. using MathNet.Numerics.Distributions;
  9. using Microsoft.EntityFrameworkCore.Query.Internal;
  10. using Microsoft.OpenApi.Expressions;
  11. using NPOI.HPSF;
  12. using NPOI.HSSF.UserModel;
  13. using NPOI.SS.Formula.Functions;
  14. using NPOI.SS.Formula.PTG;
  15. using NPOI.SS.UserModel;
  16. using NPOI.Util;
  17. using NPOI.XSSF.UserModel;
  18. using OASystem.API.OAMethodLib;
  19. using OASystem.API.OAMethodLib.File;
  20. using OASystem.API.OAMethodLib.QiYeWeChatAPI.AppNotice;
  21. using OASystem.Domain.Dtos.Financial;
  22. using OASystem.Domain.Dtos.Groups;
  23. using OASystem.Domain.Entities.Customer;
  24. using OASystem.Domain.Entities.Financial;
  25. using OASystem.Domain.Entities.Groups;
  26. using OASystem.Domain.ViewModels.Financial;
  27. using OASystem.Domain.ViewModels.Groups;
  28. using OASystem.Infrastructure.Repositories.Financial;
  29. using OASystem.Infrastructure.Repositories.Groups;
  30. using OfficeOpenXml;
  31. using Org.BouncyCastle.Math;
  32. using SqlSugar.Extensions;
  33. using System.Collections;
  34. using System.ComponentModel.Design;
  35. using System.Data;
  36. using System.Data.OleDb;
  37. using System.Diagnostics;
  38. using System.Globalization;
  39. using System.IO.Compression;
  40. using System.IO.Pipelines;
  41. using System.Linq.Expressions;
  42. namespace OASystem.API.Controllers
  43. {
  44. /// <summary>
  45. /// 财务模块
  46. /// </summary>
  47. [Route("api/[controller]/[action]")]
  48. [ApiController]
  49. public class FinancialController : ControllerBase
  50. {
  51. private readonly IMapper _mapper;
  52. private readonly IConfiguration _config;
  53. private readonly SqlSugarClient _sqlSugar;
  54. private readonly HttpClient _httpClient;
  55. private readonly SetDataTypeRepository _setDataTypeRep;
  56. private readonly SetDataRepository _setDataRep;
  57. private readonly DailyFeePaymentRepository _daiRep; //日付申请仓库
  58. private readonly TeamRateRepository _teamRateRep; //团组汇率仓库
  59. private readonly ForeignReceivablesRepository _ForForeignReceivablesRep; //对外收款账单仓库
  60. private readonly ProceedsReceivedRepository _proceedsReceivedRep; //已收款项仓库
  61. private readonly PaymentRefundAndOtherMoneyRepository _paymentRefundAndOtherMoneyRep; //收款退还与其他款项 仓库
  62. private readonly DelegationInfoRepository _delegationInfoRep; //团组信息 仓库
  63. /// <summary>
  64. /// 初始化
  65. /// </summary>
  66. public FinancialController(IMapper mapper, IConfiguration configuration, DailyFeePaymentRepository daiRep, SqlSugarClient sqlSugar, SetDataTypeRepository setDataTypeRep,
  67. TeamRateRepository teamRateRep, ForeignReceivablesRepository ForForeignReceivablesRep, ProceedsReceivedRepository proceedsReceivedRep,
  68. PaymentRefundAndOtherMoneyRepository paymentRefundAndOtherMoneyRep, HttpClient httpClient, DelegationInfoRepository delegationInfoRep, SetDataRepository setDataRep)
  69. {
  70. _mapper = mapper;
  71. _config = configuration;
  72. _daiRep = daiRep;
  73. _sqlSugar = sqlSugar;
  74. _setDataTypeRep = setDataTypeRep;
  75. _teamRateRep = teamRateRep;
  76. _ForForeignReceivablesRep = ForForeignReceivablesRep;
  77. _proceedsReceivedRep = proceedsReceivedRep;
  78. _paymentRefundAndOtherMoneyRep = paymentRefundAndOtherMoneyRep;
  79. _httpClient = httpClient;
  80. _delegationInfoRep = delegationInfoRep;
  81. _setDataRep = setDataRep;
  82. }
  83. #region 日付申请
  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> PostPageSearchDailyPaymentPriceTypeData(PortDtoBase dto)
  92. {
  93. var result = await _daiRep.GetPagePriceTypeData(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. /// 获取日付申请 基础数据源 - 转账表识
  103. /// </summary>
  104. /// <param name="dto"> 日付申请 分页 dto</param>
  105. /// <returns></returns>
  106. [HttpPost]
  107. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  108. public async Task<IActionResult> GetSearchDailyPaymentPriceTypeAddData(PortDtoBase dto)
  109. {
  110. var result = await _daiRep.GetPriceTypeAddData(dto);
  111. if (result == null || result.Code != 0)
  112. {
  113. return Ok(JsonView(false, result.Msg));
  114. }
  115. var data = result.Data;
  116. return Ok(JsonView(data));
  117. }
  118. /// <summary>
  119. /// 日付申请 Page Search
  120. /// </summary>
  121. /// <param name="dto"> 日付申请 分页 dto</param>
  122. /// <returns></returns>
  123. [HttpPost]
  124. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  125. public async Task<IActionResult> PostPageSearchDailyPaymentList(PageDailyFeePaymentDto dto)
  126. {
  127. var result = await _daiRep.GetPageSearchAll(dto);
  128. if (result == null || result.Code != 0)
  129. {
  130. return Ok(JsonView(false, result.Msg));
  131. }
  132. var data = result.Data;
  133. if (data == null)
  134. {
  135. return Ok(JsonView(false, result.Msg));
  136. }
  137. return Ok(JsonView(data));
  138. }
  139. /// <summary>
  140. /// 日付申请 Single Search By Id
  141. /// </summary>
  142. /// <param name="dto"></param>
  143. /// <returns></returns>
  144. [HttpPost]
  145. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  146. public async Task<IActionResult> PostSearchDailyPaymentInfo(SearchDailyFeePaymentDto dto)
  147. {
  148. var result = await _daiRep.GetSearchById(dto);
  149. if (result == null || result.Code != 0)
  150. {
  151. return Ok(JsonView(false, result.Msg));
  152. }
  153. return Ok(JsonView(result.Data));
  154. }
  155. /// <summary>
  156. /// 日付申请 添加
  157. /// </summary>
  158. /// <param name="dto"> 日付申请 添加 dto</param>
  159. /// <returns></returns>
  160. [HttpPost]
  161. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  162. public async Task<IActionResult> PostAddDailyPayment(AddDailyFeePaymentDto dto)
  163. {
  164. var result = await _daiRep.Add(dto);
  165. if (result == null || result.Code != 0)
  166. {
  167. return Ok(JsonView(false, result.Msg));
  168. }
  169. #region 应用推送
  170. try
  171. {
  172. int dailyId = result.Data.GetType().GetProperty("dailyId").GetValue(result.Data, null);
  173. int sign = result.Data.GetType().GetProperty("sign").GetValue(result.Data, null);
  174. await AppNoticeLibrary.DailyPayReminders_Create_ToCaiwuChat(dailyId, sign, QiyeWeChatEnum.CaiWuChat);
  175. }
  176. catch (Exception ex)
  177. {
  178. }
  179. #endregion
  180. return Ok(JsonView(true));
  181. }
  182. /// <summary>
  183. /// 日付申请 Update
  184. /// </summary>
  185. /// <param name="dto"> 日付申请 修改 dto</param>
  186. /// <returns></returns>
  187. [HttpPost]
  188. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  189. public async Task<IActionResult> PostEditDailyPayment(EditDailyFeePaymentDto dto)
  190. {
  191. var result = await _daiRep.Edit(dto);
  192. if (result == null || result.Code != 0)
  193. {
  194. return Ok(JsonView(false, result.Msg));
  195. }
  196. #region 应用推送
  197. try
  198. {
  199. int dailyId = result.Data.GetType().GetProperty("dailyId").GetValue(result.Data, null);
  200. int sign = result.Data.GetType().GetProperty("sign").GetValue(result.Data, null);
  201. await AppNoticeLibrary.DailyPayReminders_Create_ToCaiwuChat(dailyId, sign, QiyeWeChatEnum.CaiWuChat);
  202. }
  203. catch (Exception ex)
  204. {
  205. }
  206. #endregion
  207. return Ok(JsonView(true));
  208. }
  209. /// <summary>
  210. /// 日付申请 Del
  211. /// </summary>
  212. /// <param name="dto"> 日付申请 删除 dto</param>
  213. /// <returns></returns>
  214. [HttpPost]
  215. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  216. public async Task<IActionResult> PostDelDailyPayment(DelDailyFeePaymentDto dto)
  217. {
  218. _sqlSugar.BeginTran();
  219. var result = await _daiRep.Del(dto);
  220. //删除日付关联表
  221. var delCount = _sqlSugar.Updateable<Fin_RoyaltyForm>()
  222. .Where(x => x.IsDel == 0 && x.DayOverhead == dto.Id)
  223. .SetColumns(x => new Fin_RoyaltyForm
  224. {
  225. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  226. DeleteUserId = dto.UserId,
  227. IsDel = 1
  228. }).ExecuteCommand();
  229. _sqlSugar.CommitTran();
  230. if (result == null || result.Code != 0)
  231. {
  232. return Ok(JsonView(false, result.Msg));
  233. }
  234. return Ok(JsonView(true));
  235. }
  236. /// <summary>
  237. /// 日付申请 财务审核
  238. /// </summary>
  239. /// <param name="dto"> dto </param>
  240. /// <returns></returns>
  241. [HttpPost]
  242. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  243. public async Task<IActionResult> PostDelDailyPaymentAudit(DP_AuditStatusDto dto)
  244. {
  245. var result = await _daiRep.DailyPaymentAudit(dto);
  246. if (result == null || result.Code != 0)
  247. {
  248. return Ok(JsonView(false, result.Msg));
  249. }
  250. return Ok(JsonView(true));
  251. }
  252. /// <summary>
  253. /// 日付申请 Single Excel Download
  254. /// </summary>
  255. /// <param name="dto"> dto </param>
  256. /// <returns></returns>
  257. [HttpPost]
  258. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  259. public async Task<IActionResult> PostExcelDailyPaymentDownload(SearchDailyFeePaymentDto dto)
  260. {
  261. if (dto.PortType == 1 || dto.PortType == 2)
  262. {
  263. Fin_DailyFeePaymentInfolView feeData = new Fin_DailyFeePaymentInfolView();
  264. string feeSql = string.Format(@"Select * From Fin_DailyFeePayment
  265. Where IsDel=0 And Id = {0} ", dto.Id);
  266. feeData = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentInfolView>(feeSql).FirstAsync();
  267. if (feeData == null)
  268. {
  269. return Ok(JsonView(false, "暂无数据!"));
  270. }
  271. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  272. Where IsDel=0 And DFPId = {0} ", dto.Id);
  273. feeData.FeeContents = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToListAsync();
  274. if (feeData != null)
  275. {
  276. string userName = string.Empty;
  277. string userSql = string.Format("Select * From Sys_Users Where Id={0} And Isdel = {1}", feeData.CreateUserId, 0);
  278. Sys_Users user = await _sqlSugar.SqlQueryable<Sys_Users>(userSql).FirstAsync();
  279. if (user != null) { userName = user.CnName; }
  280. var setData = _setDataTypeRep.QueryDto<Sys_SetData, Fin_DailyFeePaymentPagePriceSubTypeView>().ToList();
  281. //48人员费用 49办公费用 50 销售费用 51 其他费用 55 大运会
  282. var priceSubTypeData = setData.Where(s => s.STid == 55).ToList();
  283. Dictionary<string, object> pairs = new Dictionary<string, object>();
  284. List<DataTable> datas = new List<DataTable>();
  285. //if (priceSubTypeData.Where(s => s.Id == feeData.PriceTypeId).ToList().Count() > 0)//大运会专属模板
  286. //{
  287. // //AsposeHelper.ExpertExcelToModel("日常费用付款申请模板-大运会数据.xls", "DailyPayment", "大运会所有日常费用付款申请.xls",
  288. // // pairs, datas);
  289. //}
  290. //else //日付常规模板
  291. //{
  292. pairs.Clear();
  293. pairs.Add("Opertor", userName);
  294. pairs.Add("DateTime", feeData.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"));
  295. pairs.Add("FAuditStatus", feeData.FAuditDesc);
  296. pairs.Add("MAuditStatus", feeData.MAuditDesc);
  297. pairs.Add("SumPrice", feeData.SumPrice);
  298. DataTable data = AsposeHelper.ListToDataTable("DailyFeePayment", feeData.FeeContents);
  299. datas.Clear();
  300. datas.Add(data);
  301. string fileName = string.Format("{0}-日常费用付款申请.xlsx", feeData.Instructions);
  302. string msg = AsposeHelper.ExpertExcelToModel("日常费用付款申请模板.xlsx", "DailyPayment", fileName, pairs, datas);
  303. return Ok(JsonView(true, msg));
  304. //}
  305. }
  306. else
  307. {
  308. return Ok(JsonView(false, "暂无数据!"));
  309. }
  310. }
  311. return Ok(JsonView(true));
  312. }
  313. /// <summary>
  314. /// 日付申请
  315. /// 总经理未审核 日付信息
  316. /// </summary>
  317. /// <param name="dto"> dto </param>
  318. /// <returns></returns>
  319. [HttpGet]
  320. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  321. public async Task<IActionResult> DailyPaymentGMUnAudited()
  322. {
  323. var dailyInfos = await _sqlSugar.Queryable<Fin_DailyFeePayment>()
  324. .LeftJoin<Sys_Users>((dfp, u) => dfp.CreateUserId == u.Id)
  325. .Where(dfp => dfp.IsDel == 0 &&
  326. //dfp.FAudit == 1 &&
  327. //dfp.IsPay == 0 &&
  328. dfp.MAudit == 0
  329. )
  330. .OrderBy(dfp => dfp.CreateTime, OrderByType.Desc)
  331. //.OrderBy(dfp => dfp.FAudit, OrderByType.Desc)
  332. .Select((dfp, u) => new
  333. {
  334. id = dfp.Id,
  335. amountName = dfp.Instructions,
  336. amount = dfp.SumPrice,
  337. fAuditStatus = dfp.FAudit == 1 ? "审核通过" :
  338. dfp.FAudit == 2 ? "审核未通过" : "未审核",
  339. fAuditDate = dfp.FAuditDate,
  340. applicant = u.CnName,
  341. applicantDate = dfp.CreateTime
  342. })
  343. //.ToListAsync();
  344. .CountAsync();
  345. //int count = dailyInfos.Count;
  346. return Ok(JsonView(true,"查询成功", dailyInfos));
  347. }
  348. #endregion
  349. #region 团组提成
  350. /// <summary>
  351. /// 提成 Page Search
  352. /// </summary>
  353. /// <param name="dto"> 提成 分页 dto</param>
  354. /// <returns></returns>
  355. [HttpPost]
  356. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  357. public async Task<IActionResult> PostPageSearchCommissionList(GroupCommissionDto dto)
  358. {
  359. var data = await GroupCommission.GetCommissionPageList(dto);
  360. return Ok(JsonView(data.Data));
  361. }
  362. #endregion
  363. #region 团组汇率
  364. /// <summary>
  365. /// 团组汇率 Select数据源(团组列,汇率列)
  366. /// </summary>
  367. /// <param name="dto"></param>
  368. /// <returns></returns>
  369. [HttpPost]
  370. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  371. public async Task<IActionResult> GetGroupRateDataSources(TeamRateDto dto)
  372. {
  373. try
  374. {
  375. //迁移数据更新团组汇率
  376. //Result teamRateData1 = await _teamRateRep.GetGroupRateChangeData();
  377. //var data = await _teamRateRep.PostGroupTeamRateHot();
  378. Stopwatch stopwatch = Stopwatch.StartNew();
  379. GroupNameDto groupNameDto = new GroupNameDto() { PortType = dto.PortType };
  380. var groups = await _delegationInfoRep.GetGroupNameList(groupNameDto);
  381. List<CurrencyHot> _currData = new List<CurrencyHot>();
  382. string currData = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("GroupTeamCurrencyData");//string 取
  383. if (!string.IsNullOrEmpty(currData))
  384. {
  385. _currData = JsonConvert.DeserializeObject<List<CurrencyHot>>(currData);
  386. }
  387. else
  388. {
  389. _currData = await _teamRateRep.PostGroupTeamRateHot();
  390. //过期时间 25 Hours
  391. TimeSpan ts = DateTime.Now.AddHours(25).TimeOfDay;
  392. await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync("GroupTeamCurrencyData", JsonConvert.SerializeObject(_currData), ts);
  393. }
  394. var _data = new { GroupData = groups.Data, TeamRateData = _currData };
  395. stopwatch.Stop();
  396. return Ok(JsonView(true, $"查询成功!耗时:{stopwatch.ElapsedMilliseconds / 1000}s", _data));
  397. }
  398. catch (Exception ex)
  399. {
  400. return Ok(JsonView(false, ex.Message));
  401. }
  402. }
  403. ///// <summary>
  404. ///// 团组汇率 changge
  405. ///// </summary>
  406. ///// <returns></returns>
  407. //[HttpPost]
  408. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  409. //public async Task<IActionResult> ChangeGroupRateInfo()
  410. //{
  411. // try
  412. // {
  413. // Result teamRateData = await _teamRateRep.GetGroupRateChangeData();
  414. // if (teamRateData.Code != 0)
  415. // {
  416. // return Ok(JsonView(false, teamRateData.Msg));
  417. // }
  418. // return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  419. // }
  420. // catch (Exception ex)
  421. // {
  422. // return Ok(JsonView(false, ex.Message));
  423. // throw;
  424. // }
  425. //}
  426. /// <summary>
  427. /// 团组汇率 Select汇率详情
  428. /// </summary>
  429. /// <param name="dto"></param>
  430. /// <returns></returns>
  431. [HttpPost]
  432. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  433. public async Task<IActionResult> GetGroupRateInfo(TeamRateInfoDto dto)
  434. {
  435. try
  436. {
  437. Result teamRateData = await _teamRateRep.GetGroupRateInfoByDiid(dto);
  438. if (teamRateData.Code != 0)
  439. {
  440. return Ok(JsonView(false, teamRateData.Msg));
  441. }
  442. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  443. }
  444. catch (Exception ex)
  445. {
  446. return Ok(JsonView(false, ex.Message));
  447. throw;
  448. }
  449. }
  450. /// <summary>
  451. /// 团组汇率 添加 or 更新
  452. /// </summary>
  453. /// <param name="dto"></param>
  454. /// <returns></returns>
  455. [HttpPost]
  456. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  457. public async Task<IActionResult> PostGroupRateUpdate(TeamRateUpdateDto dto)
  458. {
  459. try
  460. {
  461. Result teamRateData = await _teamRateRep.PostGroupRateUpdate(dto);
  462. if (teamRateData.Code != 0)
  463. {
  464. return Ok(JsonView(false, teamRateData.Msg));
  465. }
  466. return Ok(JsonView(true, teamRateData.Msg, teamRateData.Data));
  467. }
  468. catch (Exception ex)
  469. {
  470. return Ok(JsonView(false, ex.Message));
  471. throw;
  472. }
  473. }
  474. #endregion
  475. #region 对外收款账单 关联已收款项
  476. /// <summary>
  477. /// 对外收款账单 Select数据源(团组名,币种,汇款方式)
  478. /// 关联已收款项
  479. /// </summary>
  480. /// <param name="dto"></param>
  481. /// <returns></returns>
  482. [HttpPost]
  483. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  484. public async Task<IActionResult> GetForeignReceivablesDataSources(ForeignReceivablesDataSourcesDto dto)
  485. {
  486. return Ok(await _ForForeignReceivablesRep.GetDataSource(dto));
  487. }
  488. /// <summary>
  489. /// 对外收款账单
  490. /// 账单详情
  491. /// 关联已收款项
  492. /// </summary>
  493. /// <param name="dto"></param>
  494. /// <returns></returns>
  495. [HttpPost]
  496. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  497. public async Task<IActionResult> GetGroupReceivablesInfoByDiId(ForForeignReceivablesInfoDto dto)
  498. {
  499. try
  500. {
  501. Result ffrData = await _ForForeignReceivablesRep.GetGroupReceivablesInfoByDiId(dto);
  502. if (ffrData.Code != 0)
  503. {
  504. return Ok(JsonView(false, ffrData.Msg));
  505. }
  506. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  507. }
  508. catch (Exception ex)
  509. {
  510. return Ok(JsonView(false, ex.Message));
  511. throw;
  512. }
  513. }
  514. /// <summary>
  515. /// 对外收款账单
  516. /// 账单 删除
  517. /// 关联已收款项
  518. /// </summary>
  519. /// <param name="dto"></param>
  520. /// <returns></returns>
  521. [HttpPost]
  522. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  523. public async Task<IActionResult> PostGroupReceivablesDel(DelForForeignReceivablesInfoDto dto)
  524. {
  525. try
  526. {
  527. Result ffrData = await _ForForeignReceivablesRep._Del(dto);
  528. if (ffrData.Code != 0)
  529. {
  530. return Ok(JsonView(false, ffrData.Msg));
  531. }
  532. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  533. }
  534. catch (Exception ex)
  535. {
  536. return Ok(JsonView(false, ex.Message));
  537. throw;
  538. }
  539. }
  540. /// <summary>
  541. /// 对外收款账单
  542. /// 添加 And 更新
  543. /// 关联已收款项
  544. /// </summary>
  545. /// <param name="dto"></param>
  546. /// <returns></returns>
  547. [HttpPost]
  548. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  549. public async Task<IActionResult> PostReceivablesOperate(ForeignReceivablesAddAndUpdateDto dto)
  550. {
  551. try
  552. {
  553. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesOperate(dto);
  554. if (ffrData.Code != 0)
  555. {
  556. return Ok(JsonView(false, ffrData.Msg));
  557. }
  558. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  559. }
  560. catch (Exception ex)
  561. {
  562. return Ok(JsonView(false, ex.Message));
  563. throw;
  564. }
  565. }
  566. /// <summary>
  567. /// 已收款项
  568. /// 账单 删除
  569. /// 关联已收款项
  570. /// </summary>
  571. /// <param name="dto"></param>
  572. /// <returns></returns>
  573. [HttpPost]
  574. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  575. public async Task<IActionResult> PostAmountReceivedDel(ProceedsReceivedDelDto dto)
  576. {
  577. try
  578. {
  579. Result ffrData = await _proceedsReceivedRep._Del(dto);
  580. if (ffrData.Code != 0)
  581. {
  582. return Ok(JsonView(false, ffrData.Msg));
  583. }
  584. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  585. }
  586. catch (Exception ex)
  587. {
  588. return Ok(JsonView(false, ex.Message));
  589. throw;
  590. }
  591. }
  592. /// <summary>
  593. /// 已收款项
  594. /// 添加 And 更新
  595. /// 关联已收款项
  596. /// </summary>
  597. /// <param name="dto"></param>
  598. /// <returns></returns>
  599. [HttpPost]
  600. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  601. public async Task<IActionResult> PostAmountReceivedOperate(ProceedsReceivedDto dto)
  602. {
  603. try
  604. {
  605. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedOperate(dto);
  606. if (ffrData.Code != 0)
  607. {
  608. return Ok(JsonView(false, ffrData.Msg));
  609. }
  610. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  611. }
  612. catch (Exception ex)
  613. {
  614. return Ok(JsonView(false, ex.Message));
  615. throw;
  616. }
  617. }
  618. /// <summary>
  619. /// 财务 已收款项
  620. /// 分配已收款项至 应收项下
  621. /// 关联已收款项
  622. /// </summary>
  623. /// <param name="dto"></param>
  624. /// <returns></returns>
  625. [HttpPost]
  626. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  627. public async Task<IActionResult> PostAllocateAmountReceived(AllocateAmountReceivedDto dto)
  628. {
  629. try
  630. {
  631. Result ffrData = await _proceedsReceivedRep.PostAllocateAmountReceived(dto);
  632. if (ffrData.Code != 0)
  633. {
  634. return Ok(JsonView(false, ffrData.Msg));
  635. }
  636. return Ok(JsonView(true));
  637. }
  638. catch (Exception ex)
  639. {
  640. return Ok(JsonView(false, ex.Message));
  641. throw;
  642. }
  643. }
  644. ///// <summary>
  645. ///// 财务 收款账单
  646. ///// 导出Word(北京,四川)
  647. ///// </summary>
  648. ///// <param name="dto"></param>
  649. ///// <returns></returns>
  650. //[HttpPost]
  651. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  652. //public async Task<IActionResult> PostAccountReceivableWordExport(AccountReceivableWordExportDto dto)
  653. //{
  654. // try
  655. // {
  656. // //模板处理
  657. // string typeName = string.Empty;
  658. // if (dto.TemplateType == 1) //四川
  659. // {
  660. // typeName = "四川";
  661. // }
  662. // else if (dto.TemplateType == 2) //北京
  663. // {
  664. // typeName = "北京";
  665. // }
  666. // else return Ok(JsonView(false,"请选择正确的模板类型!"));
  667. // string wordTempName = string.Format("收款账单({0})模板.doc", typeName);
  668. // }
  669. // catch (Exception ex)
  670. // {
  671. // return Ok(JsonView(false, ex.Message));
  672. // }
  673. //}
  674. #endregion
  675. #region 对外收款账单
  676. /// <summary>
  677. /// 对外收款账单
  678. /// 数据源
  679. /// </summary>
  680. /// <param name="dto"></param>
  681. /// <returns></returns>
  682. [HttpPost]
  683. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  684. public async Task<IActionResult> PostGroupReceivablesDataSource(ForeignReceivablesDataSourcesDto dto)
  685. {
  686. return Ok(await _ForForeignReceivablesRep.PostDataSource(dto));
  687. }
  688. /// <summary>
  689. /// 对外收款账单
  690. /// 账单详情
  691. /// </summary>
  692. /// <param name="dto"></param>
  693. /// <returns></returns>
  694. [HttpPost]
  695. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  696. public async Task<IActionResult> PostGroupReceivablesInfoByDiId(ForForeignReceivablesNewDto dto)
  697. {
  698. return Ok(await _ForForeignReceivablesRep.PostGroupReceivablesInfoByDiId(dto));
  699. }
  700. /// <summary>
  701. /// 对外收款账单
  702. /// 添加 And 更新
  703. /// </summary>
  704. /// <param name="dto"></param>
  705. /// <returns></returns>
  706. [HttpPost]
  707. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  708. public async Task<IActionResult> PostReceivablesSave(ForeignReceivablesSaveDto dto)
  709. {
  710. return Ok(await _ForForeignReceivablesRep.PostReceivablesSave(dto));
  711. }
  712. /// <summary>
  713. /// 对外收款账单
  714. /// 审核
  715. /// </summary>
  716. /// <param name="dto"></param>
  717. /// <returns></returns>
  718. [HttpPost]
  719. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  720. public async Task<IActionResult> PostReceivablesAudit(FeeAuditDto dto)
  721. {
  722. return Ok(await _ForForeignReceivablesRep.FeeAudit(dto));
  723. }
  724. /// <summary>
  725. /// 已收账单
  726. /// 删除
  727. /// </summary>
  728. /// <param name="dto"></param>
  729. /// <returns></returns>
  730. [HttpPost]
  731. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  732. public async Task<IActionResult> PostReceivablesDel(ForeignReceivablesDelDto dto)
  733. {
  734. try
  735. {
  736. Result ffrData = await _ForForeignReceivablesRep.PostReceivablesDel(dto);
  737. if (ffrData.Code != 0)
  738. {
  739. return Ok(JsonView(false, ffrData.Msg));
  740. }
  741. return Ok(JsonView(true, ffrData.Msg, ffrData.Data));
  742. }
  743. catch (Exception ex)
  744. {
  745. return Ok(JsonView(false, ex.Message));
  746. throw;
  747. }
  748. }
  749. /// <summary>
  750. /// 已收账单
  751. /// File Downloasd
  752. /// Init
  753. /// </summary>
  754. /// <param name="dto"></param>
  755. /// <returns></returns>
  756. [HttpPost]
  757. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  758. public async Task<IActionResult> PostReceivablesFeilDownloadInit()
  759. {
  760. return Ok(JsonView(true, "操作成功!", new List<dynamic> {
  761. new { Id = 1, Name = "生成收款单(四川)" },
  762. new { Id = 2, Name = "生成收款单(北京)" },
  763. new { Id = 3, Name = "汇款账单" }
  764. }
  765. ));
  766. }
  767. /// <summary>
  768. /// 已收账单
  769. /// File Downloasd
  770. /// </summary>
  771. /// <param name="dto"></param>
  772. /// <returns></returns>
  773. [HttpPost]
  774. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  775. public async Task<IActionResult> PostReceivablesFeilDownload(ForeignReceivablesFeilDownloadDto dto)
  776. {
  777. try
  778. {
  779. if (dto.DiId < 1)
  780. {
  781. return Ok(JsonView(false, "请传入有效DiId参数!"));
  782. }
  783. if (dto.FileType < 1 || dto.FileType > 3)
  784. {
  785. return Ok(JsonView(false, "请传入有效FileType参数! 1 生成收款单(四川) 2 生成收款单(北京) 3 汇款账单"));
  786. }
  787. var _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == dto.DiId).First();
  788. if (_DelegationInfo == null)
  789. {
  790. return Ok(JsonView(false, "暂无团组信息!!"));
  791. }
  792. if (dto.FileType == 1 || dto.FileType == 2)
  793. {
  794. var _ForeignReceivables = _sqlSugar.Queryable<Fin_ForeignReceivables>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
  795. if (_ForeignReceivables.Count < 1)
  796. {
  797. return Ok(JsonView(false, "暂无收款信息!!"));
  798. }
  799. string tempName = "";
  800. if (dto.FileType == 1) tempName = $"收款账单(四川)模板.docx";
  801. else if (dto.FileType == 2) tempName = $"收款账单(北京)模板.docx";
  802. string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/{tempName}";
  803. //载入模板
  804. Document doc = new Document(tempPath);
  805. DocumentBuilder builder = new DocumentBuilder(doc);
  806. #region 替换Word模板书签内容
  807. //这里可以创建个DataTable循环添加书签的值,这里提示一下就不多做修改了
  808. //付款方
  809. if (doc.Range.Bookmarks["To"] != null)
  810. {
  811. Bookmark mark = doc.Range.Bookmarks["To"];
  812. mark.Text = _ForeignReceivables[0].To == null ? "" : _ForeignReceivables[0].To.ToString();
  813. }
  814. //付款方电话
  815. if (doc.Range.Bookmarks["ToTel"] != null)
  816. {
  817. Bookmark mark = doc.Range.Bookmarks["ToTel"];
  818. mark.Text = _ForeignReceivables[0].ToTel == null ? "" : _ForeignReceivables[0].ToTel.ToString();
  819. }
  820. //导出时间
  821. if (doc.Range.Bookmarks["Date"] != null)
  822. {
  823. Bookmark mark = doc.Range.Bookmarks["Date"];
  824. mark.Text = DateTime.Now.ToString("yyyy-MM-dd");
  825. }
  826. //注
  827. if (doc.Range.Bookmarks["Attention"] != null)
  828. {
  829. Bookmark mark = doc.Range.Bookmarks["Attention"];
  830. mark.Text = _ForeignReceivables[0].Attention == null ? "" : _ForeignReceivables[0].Attention.ToString();
  831. }
  832. //团队名称
  833. if (doc.Range.Bookmarks["Team"] != null)
  834. {
  835. Bookmark mark = doc.Range.Bookmarks["Team"];
  836. mark.Text = _DelegationInfo.VisitCountry == null ? "" : _DelegationInfo.VisitCountry.Replace("|", "、").ToString();
  837. }
  838. //付款日期
  839. if (doc.Range.Bookmarks["PayDate"] != null)
  840. {
  841. Bookmark mark = doc.Range.Bookmarks["PayDate"];
  842. mark.Text = _ForeignReceivables[0].PayDate == null ? "" : Convert.ToDateTime(_ForeignReceivables[0].PayDate).ToString("yyyy年MM月dd日");
  843. }
  844. decimal sumPrice = 0;
  845. //各项费用
  846. if (doc.Range.Bookmarks["PayItemContent"] != null)
  847. {
  848. string items = "";
  849. foreach (var fr in _ForeignReceivables)
  850. {
  851. var currInfo = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == fr.Currency).First();
  852. items += $"{fr.PriceName} {currInfo?.Name} {fr.Price.ToString("#0.00")} * {fr.Count} {fr.Unit} * {fr.Rate}.................. RMB {fr.ItemSumPrice.ToString("#0.00")}\n";
  853. sumPrice += fr.ItemSumPrice;
  854. }
  855. Bookmark mark = doc.Range.Bookmarks["PayItemContent"];
  856. mark.Text = items;
  857. }
  858. //合计
  859. if (doc.Range.Bookmarks["Total"] != null)
  860. {
  861. Bookmark mark = doc.Range.Bookmarks["Total"];
  862. mark.Text = sumPrice.ToString("#0.00");
  863. }
  864. #endregion
  865. //文件名
  866. string strFileName = _DelegationInfo.TeamName + "-收款账单.docx";
  867. //去水印
  868. new Aspose.Words.License().SetLicense(new MemoryStream(Convert.FromBase64String(AsposeHelper.asposeKey)));
  869. doc.Save(AppSettingsHelper.Get("WordBasePath") + "ForeignReceivables/File/" + strFileName);
  870. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/ForeignReceivables/File/" + strFileName;
  871. return Ok(JsonView(true, "成功", new { Url = url }));
  872. }
  873. else if (dto.FileType == 3) //汇款通知
  874. {
  875. var _EnterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  876. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId && it.NationalTravelFeeId > 0).ToList();
  877. if (_EnterExitCosts == null)
  878. {
  879. return Ok(JsonView(false, "该团组未填写出入境费用;"));
  880. }
  881. var _cityFee = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  882. foreach (var item in _DayAndCosts)
  883. {
  884. var cityInfo = _cityFee.Where(it => it.Id == item.NationalTravelFeeId).FirstOrDefault();
  885. if (cityInfo != null)
  886. {
  887. if (cityInfo.City.Contains("全部城市") || cityInfo.City.Contains("其他城市") || cityInfo.City.Contains("所有城市"))
  888. {
  889. item.Place = cityInfo.Country;
  890. }
  891. else item.Place = cityInfo.City;
  892. }
  893. }
  894. //数据源
  895. List<Grp_DayAndCost> dac1 = _DayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  896. List<Grp_DayAndCost> dac2 = _DayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  897. List<Grp_DayAndCost> dac3 = _DayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  898. List<Grp_DayAndCost> dac4 = _DayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  899. //币种Data
  900. var currData = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  901. var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  902. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  903. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  904. .Where((tcl, dc, cc) => tcl.IsDel == 0 && tcl.DiId == dto.DiId)
  905. .Select((tcl, dc, cc) => new
  906. {
  907. Name = dc.LastName + dc.FirstName,
  908. Sex = dc.Sex,
  909. Birthday = dc.BirthDay,
  910. Company = cc.CompanyFullName.Replace("\n",""),
  911. Job = dc.Job,
  912. AirType = tcl.ShippingSpaceTypeId
  913. })
  914. .ToList();
  915. if (DeleClientList.Count < 1)
  916. {
  917. return Ok(JsonView(false, "暂无团组成员,请先填写团组成员!!!"));
  918. }
  919. var _ClientNames = DeleClientList.Select(x => x.Name).ToList();
  920. var _GroupClient = DeleClientList.GroupBy(x => x.Company).ToList();
  921. Dictionary<string, string> bookmarkArr = null;
  922. string tempPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/Temp/汇款通知.docx";
  923. //载入模板
  924. Document doc = new Document(tempPath);
  925. DocumentBuilder builder = null;
  926. List<string> filesToZip = new List<string>();
  927. foreach (var ClientItem in _GroupClient) //遍历单位
  928. {
  929. doc = new Document(tempPath);
  930. builder = new DocumentBuilder(doc);
  931. Paragraph paragraph = new Paragraph(doc);
  932. bookmarkArr = new Dictionary<string, string>();
  933. bookmarkArr.Add("titleClientUnit", ClientItem.Key); //title单位
  934. bookmarkArr.Add("ClientUnit", ClientItem.Key); //单位
  935. bookmarkArr.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));//出发日期
  936. bookmarkArr.Add("name", string.Join(",", ClientItem.Select(x => x.Name).ToArray()).TrimEnd(','));//全部人员信息
  937. bookmarkArr.Add("VisitCountry", _DelegationInfo.VisitCountry.Replace("|", "、"));//出访国家
  938. bookmarkArr.Add("dayTime", DateTime.Now.ToString("yyyy年MM月dd日"));//今天日期
  939. var ClientItemList = ClientItem.ToList();
  940. string UsersTop = string.Empty;//word中人员以及金额
  941. decimal WordAllPrice = 0.00M;
  942. //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(),
  943. // 6, 3 + dac1.Where(x=>!string.IsNullOrWhiteSpace(x.Place)).Select(x=>(Convert.ToDecimal(x.SubTotal) / Convert.ToDecimal(x.Cost)).ToString().Length).Max() };
  944. //遍历人员
  945. for (int i = 0; i < ClientItemList.Count(); i++)
  946. {
  947. Dictionary<string, string> TeableBookmarkArr = new Dictionary<string, string>();
  948. var client = ClientItemList[i]; //每个人员
  949. var firstName = ClientItemList[i].Name;
  950. /*
  951. * 457 头等舱
  952. * 458 公务舱
  953. * 460 经济舱
  954. */
  955. decimal airPrice = 0.00M;
  956. string airName = string.Empty;
  957. if (client.AirType == 457)
  958. {
  959. airName = $"头等舱";
  960. airPrice = _EnterExitCosts.AirTD;
  961. }else if (client.AirType == 458)
  962. {
  963. airName = $"公务舱";
  964. airPrice = _EnterExitCosts.AirGW;
  965. }else if (client.AirType == 460)
  966. {
  967. airName = $"经济舱";
  968. airPrice = _EnterExitCosts.AirJJ;
  969. }
  970. //计算费用总和
  971. decimal AllPrice = airPrice + _EnterExitCosts.CityTranffic + dac1.Sum(x => x.SubTotal) + dac2.Sum(x => x.SubTotal) +
  972. dac3.Sum(x => x.SubTotal) + dac4.Sum(x => x.SubTotal) + _EnterExitCosts.Visa + _EnterExitCosts.Safe +
  973. +_EnterExitCosts.YiMiao + _EnterExitCosts.YiMiao + _EnterExitCosts.Ticket + _EnterExitCosts.Service;
  974. WordAllPrice += AllPrice;
  975. UsersTop += firstName + "出访费用为¥" + AllPrice.ToString("#0.00") + "元、";
  976. TeableBookmarkArr.Add("jp", airPrice.ToString("#0.00") + " 元"); //机票金额
  977. TeableBookmarkArr.Add("cs", _EnterExitCosts.CityTranffic.ToString("#0.00") + " 元"); //城市交通费用
  978. TeableBookmarkArr.Add("zs", dac1.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //住宿费
  979. string zsinfo = string.Empty;
  980. string hsinfo = string.Empty;
  981. string gzinfo = string.Empty;
  982. List<string> placeArr = new List<string>();
  983. Aspose.Words.Tables.Table FirstTable = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
  984. Aspose.Words.Tables.Table ChildTable = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 0, true);
  985. Aspose.Words.Tables.Table ChildTable1 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 1, true);
  986. Aspose.Words.Tables.Table ChildTable2 = (Aspose.Words.Tables.Table)FirstTable.GetChild(NodeType.Table, 2, true);
  987. int rowIndex = 0;
  988. foreach (var item in dac1)
  989. {
  990. if (string.IsNullOrWhiteSpace(item.Place))
  991. {
  992. continue;
  993. }
  994. if (placeArr.Contains(item.Place))
  995. {
  996. continue;
  997. }
  998. else
  999. {
  1000. placeArr.Add(item.Place);
  1001. }
  1002. if (!string.IsNullOrWhiteSpace(item.Place))
  1003. {
  1004. if (rowIndex > ChildTable.Rows.Count - 1)
  1005. {
  1006. var chitableRow = ChildTable.LastRow.Clone(true);
  1007. ChildTable.AppendChild(chitableRow);
  1008. }
  1009. int days = dac1.FindAll(x => x.Place == item.Place).Count();
  1010. SetCells(ChildTable, doc, rowIndex, 0, item.Place);
  1011. SetCells(ChildTable, doc, rowIndex, 1, days + "晚");
  1012. string currencyCode = currData.Find(it => it.Id == item.Currency)?.Remark ?? "Unknown";
  1013. SetCells(ChildTable, doc, rowIndex, 2, item.Cost.ToString("#0.00") + currencyCode + "/晚");
  1014. SetCells(ChildTable, doc, rowIndex, 3, "汇率" + (item.SubTotal / item.Cost).ToString("#0.0000"));
  1015. SetCells(ChildTable, doc, rowIndex, 4, "CNY " + item.SubTotal + "\r\n");
  1016. rowIndex++;
  1017. zsinfo += item.Place + " " + days + "晚 " + item.Cost.ToString("#0.00") + currencyCode + "/晚" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.0000") + " CNY " + item.SubTotal * days + "\r\n";
  1018. }
  1019. }
  1020. placeArr.Clear();
  1021. rowIndex = 0;
  1022. foreach (var item in dac2)
  1023. {
  1024. if (string.IsNullOrWhiteSpace(item.Place))
  1025. {
  1026. continue;
  1027. }
  1028. if (placeArr.Contains(item.Place))
  1029. {
  1030. continue;
  1031. }
  1032. else
  1033. {
  1034. placeArr.Add(item.Place);
  1035. }
  1036. if (!string.IsNullOrWhiteSpace(item.Place))
  1037. {
  1038. if (rowIndex > ChildTable1.Rows.Count - 1)
  1039. {
  1040. var chitableRow = ChildTable1.LastRow.Clone(true);
  1041. ChildTable1.AppendChild(chitableRow);
  1042. }
  1043. int days = dac2.FindAll(x => x.Place == item.Place).Count();
  1044. SetCells(ChildTable1, doc, rowIndex, 0, item.Place);
  1045. SetCells(ChildTable1, doc, rowIndex, 1, days + "天");
  1046. string currencyCode = currData.Find(it => it.Id == item.Currency)?.Remark ?? "Unknown";
  1047. SetCells(ChildTable1, doc, rowIndex, 2, item.Cost.ToString("#0.00") + currencyCode + "/天");
  1048. SetCells(ChildTable1, doc, rowIndex, 3, "汇率" + (item.SubTotal / item.Cost).ToString("#0.0000"));
  1049. SetCells(ChildTable1, doc, rowIndex, 4, "CNY " + item.SubTotal);
  1050. rowIndex++;
  1051. hsinfo += item.Place + " " + days + "天 " + item.Cost.ToString("#0.00") + currencyCode + "/天" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.0000") + " CNY " + item.SubTotal * days + "\r\n";
  1052. }
  1053. }
  1054. placeArr.Clear();
  1055. rowIndex = 0;
  1056. foreach (var item in dac3)
  1057. {
  1058. if (string.IsNullOrWhiteSpace(item.Place))
  1059. {
  1060. continue;
  1061. }
  1062. if (placeArr.Contains(item.Place))
  1063. {
  1064. continue;
  1065. }
  1066. else
  1067. {
  1068. placeArr.Add(item.Place);
  1069. }
  1070. if (!string.IsNullOrWhiteSpace(item.Place))
  1071. {
  1072. if (rowIndex > ChildTable2.Rows.Count - 1)
  1073. {
  1074. var chitableRow = ChildTable2.LastRow.Clone(true);
  1075. ChildTable2.AppendChild(chitableRow);
  1076. }
  1077. int days = dac3.FindAll(x => x.Place == item.Place).Count();
  1078. SetCells(ChildTable2, doc, rowIndex, 0, item.Place);
  1079. SetCells(ChildTable2, doc, rowIndex, 1, days + "天");
  1080. string currencyCode = currData.Find(it => it.Id == item.Currency)?.Remark ?? "Unknown";
  1081. SetCells(ChildTable2, doc, rowIndex, 2, item.Cost.ToString("#0.00") + currencyCode + "/天");
  1082. SetCells(ChildTable2, doc, rowIndex, 3, "汇率" + (item.SubTotal / item.Cost).ToString("#0.0000"));
  1083. SetCells(ChildTable2, doc, rowIndex, 4, "CNY " + item.SubTotal + "\r\n");
  1084. rowIndex++;
  1085. gzinfo += item.Place + " " + days + "天 " + item.Cost.ToString("#0.00") + currencyCode + "/天" + " 汇率" + (item.SubTotal / item.Cost).ToString("#0.00") + " CNY " + item.SubTotal * days + "\r\n";
  1086. }
  1087. }
  1088. placeArr.Clear();
  1089. TeableBookmarkArr.Add("zsinfo", zsinfo); //住宿费详情
  1090. TeableBookmarkArr.Add("hs", dac2.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //伙食费
  1091. TeableBookmarkArr.Add("hsinfo", hsinfo); //伙食费详情
  1092. TeableBookmarkArr.Add("gz", dac3.Sum(x => Convert.ToDecimal(x.SubTotal)).ToString("#0.00") + " 元"); //公杂费
  1093. TeableBookmarkArr.Add("gzinfo", gzinfo); //公杂费详情
  1094. string otherFeestr = "";
  1095. decimal otherFee = 0.00M;
  1096. if (_EnterExitCosts.Visa > 0.00M)
  1097. {
  1098. otherFee += _EnterExitCosts.Visa;
  1099. otherFeestr += $"签证费{_EnterExitCosts.Visa.ToString("#0.00")}元、";
  1100. }
  1101. if (_EnterExitCosts.YiMiao > 0.00M)
  1102. {
  1103. otherFee += _EnterExitCosts.YiMiao;
  1104. otherFeestr += $"疫苗费{_EnterExitCosts.YiMiao.ToString("#0.00")}元、";
  1105. }
  1106. if (_EnterExitCosts.HeSuan > 0.00M)
  1107. {
  1108. otherFee += _EnterExitCosts.HeSuan;
  1109. otherFeestr += $"核酸检测费{_EnterExitCosts.HeSuan.ToString("#0.00")}元、";
  1110. }
  1111. if (_EnterExitCosts.Safe > 0.00M)
  1112. {
  1113. otherFee += _EnterExitCosts.Safe;
  1114. otherFeestr += $"保险费{_EnterExitCosts.Safe.ToString("#0.00")}元、";
  1115. }
  1116. if (_EnterExitCosts.Ticket > 0.00M)
  1117. {
  1118. otherFee += _EnterExitCosts.Ticket;
  1119. otherFeestr += $"参展门票费{_EnterExitCosts.Ticket.ToString("#0.00")}元、";
  1120. }
  1121. if (otherFeestr.Length > 0)
  1122. {
  1123. otherFeestr = otherFeestr.Substring(0, otherFeestr.Length - 1);
  1124. otherFeestr += "等费用";
  1125. }
  1126. TeableBookmarkArr.Add("qt", otherFee.ToString("#0.00") + " 元");//其他费用
  1127. TeableBookmarkArr.Add("qtinfo", otherFeestr);//其他费用第二列
  1128. TeableBookmarkArr.Add("fw", _EnterExitCosts.Service.ToString("#0.00") + "元/人");//服务费
  1129. TeableBookmarkArr.Add("AllPrice", AllPrice.ToString("#0.00") + "元/人");//表格合计费用
  1130. TeableBookmarkArr.Add("title", $"费用清单-{airName}({firstName})");
  1131. foreach (var book in TeableBookmarkArr.Keys)
  1132. {
  1133. if (doc.Range.Bookmarks[book] != null)
  1134. {
  1135. Bookmark mark = doc.Range.Bookmarks[book];
  1136. mark.Text = TeableBookmarkArr[book];
  1137. }
  1138. }
  1139. if (i != ClientItemList.Count - 1)
  1140. {
  1141. builder.PageSetup.Orientation = Aspose.Words.Orientation.Portrait;
  1142. Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
  1143. table.ParentNode.InsertAfter(paragraph, table);
  1144. var CloneTable = (Aspose.Words.Tables.Table)table.Clone(true);
  1145. table.ParentNode.InsertAfter(CloneTable, paragraph);
  1146. }
  1147. TeableBookmarkArr.Clear();
  1148. }
  1149. bookmarkArr.Add("VisitPrice", WordAllPrice.ToString());//出访费用总额
  1150. bookmarkArr.Add("CnAllPrice", WordAllPrice.ConvertCNYUpper());//出访费用总额中文
  1151. bookmarkArr.Add("namesPrice", UsersTop.TrimEnd('、'));//各人员出访费用 付辰同志出访费用为¥73,604.8元
  1152. foreach (var book in bookmarkArr.Keys)
  1153. {
  1154. if (doc.Range.Bookmarks[book] != null)
  1155. {
  1156. Bookmark mark = doc.Range.Bookmarks[book];
  1157. mark.Text = bookmarkArr[book];
  1158. }
  1159. }
  1160. //MemoryStream outSteam = new MemoryStream();
  1161. string filsPath = AppSettingsHelper.Get("WordBasePath") + $"ForeignReceivables/File/{ClientItem.Key.Replace("\n", "")}.docx";
  1162. //去水印
  1163. new Aspose.Words.License().SetLicense(new MemoryStream(Convert.FromBase64String(AsposeHelper.asposeKey)));
  1164. doc.Save(filsPath);
  1165. filesToZip.Add(filsPath);
  1166. //streams.Add(ClientItem.Key + ".docx", outSteam.ToArray());
  1167. }
  1168. //文件名
  1169. string zipFileName = _DelegationInfo.TeamName + "-收款账单.zip";
  1170. string zipPath = $"ForeignReceivables/File/{_DelegationInfo.TeamName}-收款账单{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
  1171. try
  1172. {
  1173. using (var zip = ZipFile.Open(AppSettingsHelper.Get("WordBasePath") + zipPath, ZipArchiveMode.Create))
  1174. {
  1175. foreach (var file in filesToZip)
  1176. {
  1177. zip.CreateEntryFromFile(file, Path.GetFileName(file));
  1178. }
  1179. }
  1180. }
  1181. catch (Exception ex)
  1182. {
  1183. return Ok(JsonView(false, ex.Message));
  1184. }
  1185. string url = AppSettingsHelper.Get("WordBaseUrl") + $"Office/Word/{zipPath}";
  1186. return Ok(JsonView(true, "成功", new { Url = url }));
  1187. }
  1188. return Ok(JsonView(false, "操作失败!"));
  1189. }
  1190. catch (Exception ex)
  1191. {
  1192. return Ok(JsonView(false, ex.Message));
  1193. }
  1194. }
  1195. private void SetCells(Aspose.Words.Tables.Table table, Document doc, int rows, int cells, string val)
  1196. {
  1197. //获取table中的某个单元格,从0开始
  1198. Aspose.Words.Tables.Cell lshCell = table.Rows[rows].Cells[cells];
  1199. //将单元格中的第一个段落移除
  1200. lshCell.FirstParagraph.Remove();
  1201. //if (cells == 0) lshCell.CellFormat.Width = 120;
  1202. //else if (cells == 1) lshCell.CellFormat.Width = 50;
  1203. //else if (cells == 2) lshCell.CellFormat.Width = 120;
  1204. //else if (cells == 3) lshCell.CellFormat.Width = 100;
  1205. //else if (cells == 4) lshCell.CellFormat.Width = 120;
  1206. //新建一个段落
  1207. Paragraph p = new Paragraph(doc);
  1208. var r = new Run(doc, val);
  1209. r.Font.Size = 8;
  1210. //把设置的值赋给之前新建的段落
  1211. p.AppendChild(r);
  1212. //将此段落加到单元格内
  1213. lshCell.AppendChild(p);
  1214. }
  1215. /// <summary>
  1216. /// 已收账单
  1217. /// 提示导入出入境报价费用
  1218. /// </summary>
  1219. /// <param name="groupId"></param>
  1220. /// <returns></returns>
  1221. [HttpPost]
  1222. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1223. public async Task<IActionResult> PostReceivablesImportFee(int groupId)
  1224. {
  1225. if (groupId < 1) return Ok(JsonView(false, "请传入有效的GroupId参数!"));
  1226. var _EnterExitCosts =await _sqlSugar.Queryable<Grp_EnterExitCost>()
  1227. .Where(it => it.IsDel == 0 && it.DiId == groupId)
  1228. .FirstAsync();
  1229. var _DayAndCosts =await _sqlSugar.Queryable<Grp_DayAndCost>()
  1230. .Where(it => it.IsDel == 0 && it.DiId == groupId)
  1231. .ToListAsync();
  1232. if (_EnterExitCosts == null) return Ok(JsonView(false, "该团组未填写出入境费用;"));
  1233. //数据源
  1234. var stayDatas = _DayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  1235. var mealDatas = _DayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  1236. var miscellaneousDatas = _DayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  1237. var tainDatas = _DayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  1238. //筛选 陪同人员 = 1
  1239. var groupClientList = await _sqlSugar.Queryable<Grp_TourClientList>()
  1240. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id)
  1241. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id)
  1242. .LeftJoin<Sys_SetData>((tcl, dc, cc, sd) => tcl.ShippingSpaceTypeId == sd.Id)
  1243. .Where(tcl => tcl.IsDel == 0 &&
  1244. tcl.DiId == groupId &&
  1245. tcl.IsAccompany == 1
  1246. )
  1247. .Select((tcl, dc, cc, sd) => new
  1248. {
  1249. DiId = tcl.DiId,
  1250. CompanyId = cc.Id,
  1251. CompanyName = cc.CompanyFullName,
  1252. ClienId = dc.Id,
  1253. ClientName = dc.FirstName + dc.LastName,
  1254. SpaceId = tcl.ShippingSpaceTypeId,
  1255. SpaceName = sd.Name
  1256. })
  1257. .ToListAsync();
  1258. if (groupClientList.Count < 1) return Ok(JsonView(false, "该团组未填写接团客户名单;"));
  1259. decimal domesticFeeTotal =0.00M, //境内费用
  1260. economyClassFeeTotal = 0.00M, //经济舱费用
  1261. businessClassFeeTotal = 0.00M, //公务舱费用
  1262. firstClassFeeTotal = 0.00M, //头等舱费用
  1263. stayFeeTotal = 0.00M, //住宿费
  1264. mealsFeeTotal = 0.00M, //餐食费
  1265. miscellaneousFeeTotal = 0.00M, //公杂费
  1266. tainFeeTotal = 0.00M; //培训费
  1267. //境内费用(其他费用)
  1268. if (_EnterExitCosts.ChoiceOne == 1) domesticFeeTotal = _EnterExitCosts.InsidePay;
  1269. //住宿费
  1270. if (_EnterExitCosts.ChoiceThree == 1) stayFeeTotal = stayDatas.Sum(x => x.SubTotal);
  1271. //伙食费
  1272. if (_EnterExitCosts.ChoiceFour == 1) mealsFeeTotal = mealDatas.Sum(x => x.SubTotal);
  1273. //公杂费
  1274. if (_EnterExitCosts.ChoiceFive == 1) miscellaneousFeeTotal = miscellaneousDatas.Sum(x => x.SubTotal);
  1275. //培训费
  1276. if (_EnterExitCosts.ChoiceSix == 1) tainFeeTotal = tainDatas.Sum(x => x.SubTotal);
  1277. decimal otherFeeTotal = domesticFeeTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal;
  1278. //国际旅费合计
  1279. //经济舱
  1280. if (_EnterExitCosts.SumJJC == 1) economyClassFeeTotal = _EnterExitCosts.OutsideJJPay + otherFeeTotal;
  1281. //公务舱
  1282. if (_EnterExitCosts.SumGWC == 1) businessClassFeeTotal = _EnterExitCosts.OutsideGWPay + otherFeeTotal;
  1283. //头等舱
  1284. if (_EnterExitCosts.SumTDC == 1) firstClassFeeTotal = _EnterExitCosts.OutsideTDPay + otherFeeTotal;
  1285. var groupClientListGroup = groupClientList.GroupBy(x => x.CompanyId);
  1286. var _view = new List<ProceedsReceivedNewView>();
  1287. foreach (var item in groupClientListGroup)
  1288. {
  1289. string companyName = item.FirstOrDefault().CompanyName;
  1290. var airTicketGroup = item.GroupBy(x => x.SpaceId);
  1291. foreach (var airTicket in airTicketGroup)
  1292. {
  1293. int quantity = airTicket.Count();
  1294. if (quantity > 0)
  1295. {
  1296. decimal price = 0.00M;
  1297. string spaceName = airTicket.FirstOrDefault()?.SpaceName ?? string.Empty;
  1298. if (spaceName.Equals("经济舱")) price = economyClassFeeTotal;
  1299. else if (spaceName.Equals("公务舱")) price = businessClassFeeTotal;
  1300. else if (spaceName.Equals("头等舱")) price = firstClassFeeTotal;
  1301. if (price > 0)
  1302. {
  1303. decimal itemTotal = price * quantity;
  1304. _view.Add(new ProceedsReceivedNewView()
  1305. {
  1306. Id = 0,
  1307. CreateTime = DateTime.Now,
  1308. Diid = groupId,
  1309. PriceName = $"{companyName}-{spaceName}",
  1310. Price = price,
  1311. Count = quantity,
  1312. Unit = "人",
  1313. ItemSumPrice = itemTotal,
  1314. Currency = 836,
  1315. Rate = 1.0000M,
  1316. AddingWay = 2,
  1317. Remark = "由出入境费用导入费用",
  1318. });
  1319. }
  1320. }
  1321. }
  1322. }
  1323. return Ok(JsonView(true, "操作成功", _view));
  1324. }
  1325. #endregion
  1326. #region 已收款项
  1327. /// <summary>
  1328. /// 已收款项
  1329. /// 查询
  1330. /// </summary>
  1331. /// <param name="dto"></param>
  1332. /// <returns></returns>
  1333. [HttpPost]
  1334. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1335. public async Task<IActionResult> PostAmountReceived(AmountReceivedDto dto)
  1336. {
  1337. try
  1338. {
  1339. if (dto == null)
  1340. {
  1341. return Ok(JsonView(false, "参数不能为空!"));
  1342. }
  1343. Result ffrData = await _proceedsReceivedRep.PostAmountReceived(dto.DiId);
  1344. dynamic data = null;
  1345. if (dto.PortType == 1)
  1346. {
  1347. if (ffrData.Code != 0)
  1348. {
  1349. return Ok(JsonView(false, ffrData.Msg));
  1350. }
  1351. data = ffrData.Data;
  1352. }
  1353. else if (dto.PortType == 2)
  1354. {
  1355. if (ffrData.Code != 0)
  1356. {
  1357. return Ok(JsonView(false, ffrData.Msg));
  1358. }
  1359. data = ffrData.Data;
  1360. }
  1361. else if (dto.PortType == 2)
  1362. {
  1363. if (ffrData.Code != 0)
  1364. {
  1365. return Ok(JsonView(false, ffrData.Msg));
  1366. }
  1367. data = ffrData.Data;
  1368. }
  1369. else
  1370. {
  1371. return Ok(JsonView(false, "请选择正确的端口号!"));
  1372. }
  1373. return Ok(JsonView(true, "操作成功!", data));
  1374. }
  1375. catch (Exception ex)
  1376. {
  1377. return Ok(JsonView(false, ex.Message));
  1378. }
  1379. }
  1380. /// <summary>
  1381. /// 已收款项
  1382. /// Add Or Edit
  1383. /// </summary>
  1384. /// <param name="dto"></param>
  1385. /// <returns></returns>
  1386. [HttpPost]
  1387. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1388. public async Task<IActionResult> PostAmountReceivedAddOrEdit(AmountReceivedAddOrEditDto dto)
  1389. {
  1390. try
  1391. {
  1392. if (dto == null)
  1393. {
  1394. return Ok(JsonView(false, "参数不能为空!"));
  1395. }
  1396. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedAddOrEditDto(dto);
  1397. if (dto.PortType == 1)
  1398. {
  1399. if (ffrData.Code != 0)
  1400. {
  1401. return Ok(JsonView(false, ffrData.Msg));
  1402. }
  1403. }
  1404. else if (dto.PortType == 2)
  1405. {
  1406. if (ffrData.Code != 0)
  1407. {
  1408. return Ok(JsonView(false, ffrData.Msg));
  1409. }
  1410. }
  1411. else if (dto.PortType == 2)
  1412. {
  1413. if (ffrData.Code != 0)
  1414. {
  1415. return Ok(JsonView(false, ffrData.Msg));
  1416. }
  1417. }
  1418. else
  1419. {
  1420. return Ok(JsonView(false, "请选择正确的端口号!"));
  1421. }
  1422. return Ok(JsonView(true, "操作成功!"));
  1423. }
  1424. catch (Exception ex)
  1425. {
  1426. return Ok(JsonView(false, ex.Message));
  1427. }
  1428. }
  1429. /// <summary>
  1430. /// 已收款项
  1431. /// Del
  1432. /// </summary>
  1433. /// <param name="dto"></param>
  1434. /// <returns></returns>
  1435. [HttpPost]
  1436. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1437. public async Task<IActionResult> PostAmountReceived_Del(AmountReceivedDelDto dto)
  1438. {
  1439. try
  1440. {
  1441. if (dto == null)
  1442. {
  1443. return Ok(JsonView(false, "参数不能为空!"));
  1444. }
  1445. Result ffrData = await _proceedsReceivedRep.PostAmountReceivedDel(dto);
  1446. if (ffrData.Code != 0)
  1447. {
  1448. return Ok(JsonView(false, ffrData.Msg));
  1449. }
  1450. return Ok(JsonView(true, "操作成功!"));
  1451. }
  1452. catch (Exception ex)
  1453. {
  1454. return Ok(JsonView(false, ex.Message));
  1455. }
  1456. }
  1457. #endregion
  1458. #region 收款退还与其他款项 --> 收款退还
  1459. /// <summary>
  1460. /// 收款退还与其他款项
  1461. /// 查询 根据团组Id
  1462. /// </summary>
  1463. /// <param name="dto"></param>
  1464. /// <returns></returns>
  1465. [HttpPost]
  1466. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1467. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyItemByDiId(PaymentRefundAndOtherMoneyItemByDiIdDto dto)
  1468. {
  1469. try
  1470. {
  1471. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1472. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1473. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1474. #region 页面功能权限处理
  1475. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1476. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1477. if (pageFunAuth.CheckAuth == 0)
  1478. {
  1479. return Ok(JsonView(false, "您没有当前页面查询权限!"));
  1480. }
  1481. #endregion
  1482. Result _result = await _paymentRefundAndOtherMoneyRep._ItemByDiId(dto.DiId);
  1483. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //1 Web 2 Android 3 Ios
  1484. {
  1485. if (_result.Code != 0)
  1486. {
  1487. return Ok(JsonView(false, _result.Msg));
  1488. }
  1489. var data = new
  1490. {
  1491. PageFuncAuth = pageFunAuth,
  1492. Data = _result.Data
  1493. };
  1494. return Ok(JsonView(true, "操作成功!", data));
  1495. }
  1496. else
  1497. {
  1498. return Ok(JsonView(false, "请输入正确的端口号! 1 Web 2 Android 3 Ios;"));
  1499. }
  1500. }
  1501. catch (Exception ex)
  1502. {
  1503. return Ok(JsonView(false, ex.Message));
  1504. }
  1505. }
  1506. /// <summary>
  1507. /// 收款退还与其他款项
  1508. /// 删除
  1509. /// </summary>
  1510. /// <param name="dto"></param>
  1511. /// <returns></returns>
  1512. [HttpPost]
  1513. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1514. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyDel(PaymentRefundAndOtherMoneyDelDto dto)
  1515. {
  1516. try
  1517. {
  1518. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1519. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1520. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1521. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1522. #region 页面功能权限处理
  1523. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1524. #endregion
  1525. if (pageFunAuth.DeleteAuth == 0)
  1526. {
  1527. return Ok(JsonView(false, "您没有当前页面删除权限!"));
  1528. }
  1529. Result _result = await _paymentRefundAndOtherMoneyRep._Del(dto);
  1530. if (_result.Code != 0)
  1531. {
  1532. return Ok(JsonView(false, _result.Msg));
  1533. }
  1534. return Ok(JsonView(true, "操作成功!"));
  1535. }
  1536. catch (Exception ex)
  1537. {
  1538. return Ok(JsonView(false, ex.Message));
  1539. }
  1540. }
  1541. /// <summary>
  1542. /// 收款退还与其他款项
  1543. /// Info Data Source
  1544. /// </summary>
  1545. /// <param name="dto"></param>
  1546. /// <returns></returns>
  1547. [HttpPost]
  1548. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1549. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyInfoDataSource(PortDtoBase dto)
  1550. {
  1551. try
  1552. {
  1553. Result _result = await _paymentRefundAndOtherMoneyRep._InfoDataSource(dto);
  1554. if (_result.Code != 0)
  1555. {
  1556. return Ok(JsonView(false, _result.Msg));
  1557. }
  1558. return Ok(JsonView(true, "查询成功!", _result.Data));
  1559. }
  1560. catch (Exception ex)
  1561. {
  1562. return Ok(JsonView(false, ex.Message));
  1563. }
  1564. }
  1565. /// <summary>
  1566. /// 收款退还与其他款项
  1567. /// Info
  1568. /// </summary>
  1569. /// <param name="dto"></param>
  1570. /// <returns></returns>
  1571. [HttpPost]
  1572. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1573. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyInfo(PaymentRefundAndOtherMoneyInfoDto dto)
  1574. {
  1575. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1576. var view = await _paymentRefundAndOtherMoneyRep._Info(dto);
  1577. return Ok(view);
  1578. }
  1579. /// <summary>
  1580. /// 收款退还与其他款项 --> 收款退还(只保留人名币)
  1581. /// 操作(Add Or Edit)
  1582. /// </summary>
  1583. /// <param name="dto"></param>
  1584. /// <returns></returns>
  1585. [HttpPost]
  1586. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1587. public async Task<IActionResult> PostPaymentRefundAndOtherMoneyAddOrEdit(PaymentRefundAndOtherMoneyAddOrEditDto dto)
  1588. {
  1589. if (dto == null) return Ok(JsonView(false, "参数不能为空!"));
  1590. if (dto.PageId <= 0) return Ok(JsonView(false, "请传入正确的的页面Id!"));
  1591. if (dto.UserId <= 0) return Ok(JsonView(false, "请传入正确的的员工Id!"));
  1592. #region 页面功能权限处理
  1593. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  1594. pageFunAuth = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1595. #endregion
  1596. if (dto.Status == 1) //add
  1597. {
  1598. if (pageFunAuth.AddAuth == 0) return Ok(JsonView(false, "您没有当前页面添加权限!"));
  1599. }
  1600. else if (dto.Status == 2) //edit
  1601. {
  1602. if (pageFunAuth.EditAuth == 0) return Ok(JsonView(false, "您没有当前页面编辑权限!"));
  1603. }
  1604. else return Ok(JsonView(false, "请输入正确的操作状态! 1 添加 2 修改!"));
  1605. return Ok(await _paymentRefundAndOtherMoneyRep._AddOrEdit(dto));
  1606. }
  1607. #endregion
  1608. #region 应收报表
  1609. /// <summary>
  1610. /// 应收报表
  1611. /// 查询 根据日期范围
  1612. /// </summary>
  1613. /// <param name="dto"></param>
  1614. /// <returns></returns>
  1615. [HttpPost]
  1616. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1617. public async Task<IActionResult> PostSyntheticalReceivableByDateRange(PostSyntheticalReceivableByDateRangeDto dto)
  1618. {
  1619. string sqlWhere = " Where di.IsDel=0 ";
  1620. #region 验证
  1621. if (string.IsNullOrEmpty(dto.beginDt) && string.IsNullOrEmpty(dto.endDt))
  1622. {
  1623. return Ok(JsonView(false, "日期参数至少填写一个!"));
  1624. }
  1625. if (!string.IsNullOrEmpty(dto.beginDt))
  1626. {
  1627. if (Regex.Match(dto.beginDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
  1628. {
  1629. return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
  1630. }
  1631. else
  1632. {
  1633. sqlWhere += string.Format(@" And di.VisitDate >= '{0} 00:00:00' ", dto.beginDt);
  1634. }
  1635. }
  1636. if (!string.IsNullOrEmpty(dto.endDt))
  1637. {
  1638. if (Regex.Match(dto.endDt, @"^\d{4}-\d{2}-\d{2}$").Value.Length < 1)
  1639. {
  1640. return Ok(JsonView(false, "日期参数格式错误,应为yyyy-MM-dd!"));
  1641. }
  1642. else
  1643. {
  1644. sqlWhere += string.Format(@" And di.VisitDate <= '{0} 23:59:59' ", dto.endDt);
  1645. }
  1646. }
  1647. #endregion
  1648. //已收款项 判断如果是市场部的人员进来的话 只显示自己的 其他的都显示全部的
  1649. string userSqlWhere = "";
  1650. var userInfos = await _sqlSugar.Queryable<Sys_Users>()
  1651. .InnerJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  1652. .Where((u, d) => u.IsDel == 0 && d.DepName.Contains("市场部") && u.Id == dto.CurrUserId)
  1653. .ToListAsync();
  1654. if (userInfos.Count > 0) userSqlWhere = string.Format(@$" And JietuanOperator={dto.CurrUserId} ");
  1655. //排序倒序
  1656. 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");
  1657. List<PostSyntheticalReceivableByDateRangeView> list_rst = _sqlSugar.SqlQueryable<PostSyntheticalReceivableByDateRangeView>(sql).ToList();
  1658. var setData = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToList();
  1659. decimal sumAll_fr = 0M; //应收
  1660. decimal sumAll_pr = 0M; //已收
  1661. decimal sumAll_balance = 0M; //尾款
  1662. if (list_rst.Count > 0)
  1663. {
  1664. int rowNumber = 1;
  1665. foreach (var item_rst in list_rst)
  1666. {
  1667. DateTime dtTemp;
  1668. bool b = DateTime.TryParse(item_rst.visitDate, out dtTemp);
  1669. if (b)
  1670. {
  1671. item_rst.visitDate = dtTemp.ToString("yyyy-MM-dd");
  1672. }
  1673. item_rst.No = rowNumber;
  1674. rowNumber++;
  1675. int diId = item_rst.diid;
  1676. decimal sum_fr = 0M;
  1677. decimal sum_pr = 0M;
  1678. string str_client = string.Empty;
  1679. decimal sum_refund = 0M; //收款退还
  1680. decimal sum_extra = 0M; //超支费用
  1681. decimal balance = 0M;
  1682. string str_schedule = string.Empty;
  1683. //1.应收
  1684. string sql_fr = string.Format(@" Select * From Fin_ForeignReceivables Where IsDel=0 And Diid={0} ", diId);
  1685. List<Fin_ForeignReceivables> list_fr = _sqlSugar.SqlQueryable<Fin_ForeignReceivables>(sql_fr).ToList();
  1686. sum_fr = list_fr.Sum(s => s.ItemSumPrice);
  1687. //2.已收
  1688. string sql_pr = string.Format(@" Select * From Fin_ProceedsReceived Where IsDel=0 And Diid={0} ", diId);
  1689. List<Fin_ProceedsReceived> list_pr = _sqlSugar.SqlQueryable<Fin_ProceedsReceived>(sql_pr).ToList();
  1690. foreach (var item_pr in list_pr)
  1691. {
  1692. sum_pr += item_pr.Price;
  1693. str_client += string.Format(@"{0};", item_pr.Client);
  1694. str_schedule += string.Format(@"{0};", item_pr.Remark);
  1695. }
  1696. if (str_schedule.Length > 0)
  1697. {
  1698. str_schedule = str_schedule.TrimEnd(';');
  1699. }
  1700. if (str_client.Length > 0)
  1701. {
  1702. str_client = str_client.TrimEnd(';');
  1703. }
  1704. //3.收款退还
  1705. string sql_other = string.Format(@"Select * From Fin_PaymentRefundAndOtherMoney prao
  1706. Inner Join Grp_CreditCardPayment ccp On prao.Id = ccp.CId
  1707. Where ccp.CTable = 285 And ccp.IsPay = 1 And prao.IsDel = 0 And ccp.IsDel = 0 And prao.DiId = {0}", diId);
  1708. List<Grp_CreditCardPayment> list_other = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_other).ToList();
  1709. sum_refund = list_other.Sum(s => s.PayMoney * s.DayRate);
  1710. //4.超支
  1711. string sql_extra = string.Format(@" Select c.* From Fin_GroupExtraCost f
  1712. Inner join Grp_CreditCardPayment c On f.Id = c.CId
  1713. Where c.CTable = 1015 And c.IsPay = 1 And f.IsDel = 0 And c.IsDel = 0 And f.DiId = {0} ", diId);
  1714. List<Grp_CreditCardPayment> list_extra = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_extra).ToList();
  1715. sum_extra = list_extra.Sum(s => s.PayMoney * s.DayRate);
  1716. item_rst.frPrice = sum_fr.ToString("#0.00");
  1717. item_rst.extraPrice = sum_extra.ToString("#0.00");
  1718. item_rst.receivableTotal = (sum_fr + sum_extra).ToString("#0.00");
  1719. item_rst.prPrice = sum_pr.ToString("#0.00");
  1720. item_rst.refundAmount = sum_refund.ToString("#0.00");
  1721. item_rst.receivedTotal = (sum_pr - sum_refund).ToString("#0.00");
  1722. item_rst.balPrice = ((sum_fr + sum_extra) - (sum_pr - sum_refund)).ToString("#0.00");
  1723. item_rst.prClient = str_client;
  1724. item_rst.schedule = str_schedule;
  1725. string tempVisitDate = Convert.ToDateTime(item_rst.visitDate).ToString("yyyy-MM-dd");
  1726. sumAll_fr += (sum_fr + sum_extra);
  1727. sumAll_pr += (sum_pr - sum_refund);
  1728. sumAll_balance += ((sum_fr + sum_extra) - (sum_pr - sum_refund));
  1729. #region 单位应收已收细项(以应收费用名称为主去(已收费用)匹配) 新增 雷怡 2024-5-08 16:35:28
  1730. List<ClientFeeInfoView> feeDatas = new List<ClientFeeInfoView>();
  1731. //匹配上的数据
  1732. foreach (var item in list_fr)
  1733. {
  1734. var prInfo = list_pr.Find(it => item.PriceName.Contains(it.Client) || item.PriceName.Equals(it.Client));
  1735. decimal _balancePayment = 0.00M;
  1736. if (item.Currency == prInfo?.Currency)
  1737. {
  1738. _balancePayment = item.ItemSumPrice - prInfo?.Price ?? 0.00M;
  1739. }
  1740. feeDatas.Add(new ClientFeeInfoView
  1741. {
  1742. client = item.PriceName,
  1743. frMoney = item.ItemSumPrice.ToString("#0.00"),
  1744. frCurrency = setData.Find(it => it.Id == item.Currency)?.Name ?? "-",
  1745. frRate = item.Rate.ToString("#0.0000"),
  1746. prReceivablesType = setData.Find(it => it.Id == prInfo?.ReceivablesType)?.Name ?? "",
  1747. prTime = prInfo?.SectionTime ?? "-",
  1748. prMoney = prInfo?.Price.ToString("#0.00") ?? "-",
  1749. prCurrency = setData.Find(it => it.Id == prInfo?.Currency)?.Name ?? "",
  1750. balPayment = _balancePayment.ToString("#0.00")
  1751. });
  1752. }
  1753. //未匹配上的数据
  1754. foreach (var item in list_pr)
  1755. {
  1756. var frInfo = list_fr.Find(it => it.PriceName.Contains(item.Client) || it.PriceName.Equals(item.Client));
  1757. if (frInfo == null)
  1758. {
  1759. feeDatas.Add(new ClientFeeInfoView
  1760. {
  1761. client = item.Client + "[未匹配上的已收数据(应收已收公司名称不一致)]",
  1762. frMoney = "0.00",
  1763. frCurrency = "-",
  1764. frRate = "0.0000",
  1765. prReceivablesType = setData.Find(it => it.Id == item?.ReceivablesType)?.Name ?? "",
  1766. prTime = item?.SectionTime ?? "-",
  1767. prMoney = item?.Price.ToString("#0.00") ?? "0.00",
  1768. prCurrency = setData.Find(it => it.Id == item?.Currency)?.Name ?? "",
  1769. balPayment = "0.00"
  1770. });
  1771. }
  1772. }
  1773. item_rst.feeItem = feeDatas;
  1774. #endregion
  1775. }
  1776. PostSyntheticalReceivableByDateRangeResultView result = new PostSyntheticalReceivableByDateRangeResultView();
  1777. result.total_fr = sumAll_fr.ToString("#0.00");
  1778. result.total_pr = sumAll_pr.ToString("#0.00");
  1779. result.total_balance = sumAll_balance.ToString("#0.00");
  1780. result.dataList = new List<PostSyntheticalReceivableByDateRangeView>(list_rst);
  1781. if (dto.requestType == 1)
  1782. {
  1783. return Ok(JsonView(true, "请求成功", result, list_rst.Count));
  1784. }
  1785. else
  1786. {
  1787. //----------------------------
  1788. List<Excel_SyntheticalReceivableByDateRange> list_Ex = new List<Excel_SyntheticalReceivableByDateRange>();
  1789. WorkbookDesigner designer = new WorkbookDesigner();
  1790. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/应收款项模板 - 副本.xls");
  1791. int excNo = 1;
  1792. foreach (var item in list_rst)
  1793. {
  1794. Excel_SyntheticalReceivableByDateRange exc = new Excel_SyntheticalReceivableByDateRange();
  1795. exc.No = excNo.ToString();
  1796. excNo++;
  1797. exc.TeamName = item.teamName;
  1798. exc.ClientUnit = item.clientUnit;
  1799. exc.VisitDate = item.visitDate;
  1800. exc.Accounts = item.frPrice;
  1801. exc.Extra = item.extraPrice;
  1802. exc.ReceivableTotal = item.receivableTotal;
  1803. exc.Received = item.prPrice;
  1804. exc.RefundAmount = item.refundAmount;
  1805. exc.ReceivedTotal = item.receivedTotal;
  1806. exc.Balance = item.balPrice;
  1807. exc.Collection = item.schedule;
  1808. DateTime time = Convert.ToDateTime(item.visitDate);
  1809. TimeSpan ts = DateTime.Now - time;
  1810. float SY = float.Parse(item.balPrice);
  1811. if (ts.Days >= 365 && SY > 0)
  1812. {
  1813. exc.Sign = "需收款";
  1814. }
  1815. else
  1816. {
  1817. exc.Sign = "";
  1818. }
  1819. list_Ex.Add(exc);
  1820. }
  1821. var dt = CommonFun.GetDataTableFromIList(list_Ex);
  1822. dt.TableName = "Excel_SyntheticalReceivableByDateRange";
  1823. if (dt != null)
  1824. {
  1825. designer.SetDataSource("SumPrice", "应收合计:" + result.total_fr + "RMB 已收合计:" + result.total_pr + "RMB 余款合计:" + result.total_balance + "RMB");
  1826. //数据源
  1827. designer.SetDataSource(dt);
  1828. //根据数据源处理生成报表内容
  1829. designer.Process();
  1830. string fileName = ("Receivable/应收款项(" + dto.beginDt + "~" + dto.endDt + ").xlsx");
  1831. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  1832. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  1833. return Ok(JsonView(true, "成功", new { url = rst }));
  1834. }
  1835. }
  1836. }
  1837. return Ok(JsonView(true, "获取成功", "", list_rst.Count));
  1838. }
  1839. #endregion
  1840. #region 付款申请
  1841. /// <summary>
  1842. /// 付款申请
  1843. /// 基础数据
  1844. /// </summary>
  1845. /// <param name="dto"></param>
  1846. /// <returns></returns>
  1847. [HttpPost]
  1848. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1849. public async Task<IActionResult> PostPayRequestInit()
  1850. {
  1851. try
  1852. {
  1853. var conpanyDatas = _sqlSugar.Queryable<Sys_Company>()
  1854. .Where(it => it.IsDel == 0)
  1855. .Select(it => new
  1856. {
  1857. Id = it.Id,
  1858. ConpamyName = it.CompanyName
  1859. }).ToList();
  1860. return Ok(JsonView(true, "操作成功!", new { ConpanyData = conpanyDatas }));
  1861. }
  1862. catch (Exception ex)
  1863. {
  1864. return Ok(JsonView(false, ex.Message));
  1865. }
  1866. }
  1867. /// <summary>
  1868. /// 付款申请 (PageId=51)
  1869. /// 查询 根据日期范围
  1870. /// </summary>
  1871. /// <param name="dto"></param>
  1872. /// <returns></returns>
  1873. [HttpPost]
  1874. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1875. public async Task<IActionResult> PostPayRequest_Center(PostPayRequestByDateRangeDto dto)
  1876. {
  1877. Stopwatch stopwatch = Stopwatch.StartNew();
  1878. #region 验证
  1879. DateTime beginDt, endDt;
  1880. string format = "yyyy-MM-dd";
  1881. if (!DateTime.TryParseExact(dto.beginDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out beginDt))
  1882. {
  1883. return Ok(JsonView(false, "开始日期格式不正确!正确格式:yyyy-MM-dd"));
  1884. }
  1885. if (!DateTime.TryParseExact(dto.endDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt))
  1886. {
  1887. return Ok(JsonView(false, "结束日期格式不正确!正确格式:yyyy-MM-dd"));
  1888. }
  1889. #region 页面操作权限验证
  1890. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1891. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1892. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  1893. #endregion
  1894. #endregion
  1895. try
  1896. {
  1897. PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
  1898. var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
  1899. if (checkedStr != null)
  1900. {
  1901. checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
  1902. if (checkedView.GroupIds.Count > 0)
  1903. {
  1904. checkedView.GroupIds = checkedView.GroupIds.OrderBy(x => x).ToList();
  1905. }
  1906. }
  1907. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(dto.Status, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
  1908. tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(dto.Status, checkedView.GroupIds, checkedView.HotelSubIds, dto.beginDt, dto.endDt);
  1909. stopwatch.Stop();
  1910. return Ok(JsonView(true, $"查询成功!耗时{stopwatch.ElapsedMilliseconds / 1000}s", new { daily = dailyResult, group = groupResult }));
  1911. }
  1912. catch (Exception ex)
  1913. {
  1914. return Ok(JsonView(false, ex.Message));
  1915. }
  1916. }
  1917. /// <summary>
  1918. /// 根据团组类型类型处理团组费用所属公司
  1919. /// </summary>
  1920. /// <param name="teamId"></param>
  1921. /// <returns></returns>
  1922. private CompanyInfo ExpenseCompanyByTeamId(int teamId)
  1923. {
  1924. CompanyInfo _companyInfo = new CompanyInfo();
  1925. List<int> _SiChuan = new List<int>() {
  1926. 38 , // 政府团
  1927. 39 , // 企业团
  1928. 40 , // 散客团
  1929. 102, // 未知
  1930. 248, // 非团组
  1931. 691, // 四川-会务活动
  1932. 762, // 四川-赛事项目收入
  1933. 1048,//高校团
  1934. };
  1935. List<int> _ChengDu = new List<int>() {
  1936. 302, // 成都-会务活动
  1937. 1047, // 成都-赛事项目收入
  1938. };
  1939. if (_SiChuan.Contains(teamId))
  1940. {
  1941. _companyInfo.Id = 2;
  1942. _companyInfo.ConpanyName = "四川泛美交流有限公司";
  1943. }
  1944. if (_ChengDu.Contains(teamId))
  1945. {
  1946. _companyInfo.Id = 1;
  1947. _companyInfo.ConpanyName = "成都泛美商务有限公司";
  1948. }
  1949. return _companyInfo;
  1950. }
  1951. /// <summary>
  1952. /// 付款申请(团组费用申请相关)
  1953. /// 查询 根据日期范围
  1954. /// </summary>
  1955. /// <param name="_groupIds"></param>
  1956. /// <param name="beginDt"></param>
  1957. /// <param name="endDt"></param>
  1958. /// <returns></returns>
  1959. private tree_Group_DailyFeePaymentResult PayRequest_GroupPaymentByDateRange(int status, List<int> _groupIds,List<int> _hotelSubIds, string beginDt, string endDt)
  1960. {
  1961. tree_Group_DailyFeePaymentResult _DailyFeePaymentResult = new tree_Group_DailyFeePaymentResult();
  1962. List<tree_Group_DailyFeePaymentPageListView> dataList = new List<tree_Group_DailyFeePaymentPageListView>();
  1963. #region sql条件处理
  1964. string sqlWhere = string.Format(@" And (AuditGMDate Between '{0} 00:00:00' And '{1} 23:59:59') ", beginDt, endDt);
  1965. if (status == 2)
  1966. {
  1967. if (_hotelSubIds.Count > 1)
  1968. {
  1969. var hrIds = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => _hotelSubIds.Contains(it.Id) && it.Price != 0).Select(it => it.HrId).Distinct().ToList();
  1970. var hrIds1 = _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(it => it.CTable == 76 && hrIds.Contains(it.CId)).Select(it => it.Id).ToList();
  1971. if (hrIds1.Count > 1)
  1972. {
  1973. _groupIds.AddRange(hrIds1);
  1974. }
  1975. }
  1976. if (_groupIds.Count < 1)
  1977. {
  1978. _DailyFeePaymentResult.dataList = new List<tree_Group_DailyFeePaymentPageListView>();
  1979. return _DailyFeePaymentResult;
  1980. }
  1981. sqlWhere += string.Format(@" And Id In ({0})", string.Join(",", _groupIds));
  1982. }
  1983. string sql_1 = string.Format(@"Select * From Grp_CreditCardPayment Where IsDel = 0 And IsPay = 0 And (IsAuditGM = 1 Or IsAuditGM = 3 ){0}", sqlWhere);
  1984. #endregion
  1985. var _paymentDatas = _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql_1).ToList();//付款信息
  1986. _DailyFeePaymentResult.gz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 0).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); //公转
  1987. _DailyFeePaymentResult.sz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 1).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); ; //私转
  1988. List<int> groupIds = _paymentDatas.Select(it => it.DIId).Distinct().ToList();
  1989. var _groupDatas = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Id)).ToList();
  1990. //_groupDatas = (List<Grp_DelegationInfo>)_groupDatas.GroupBy(it => it.TeamDid);
  1991. #region 相关基础数据源
  1992. var userDatas = _sqlSugar.Queryable<Sys_Users>().ToList();
  1993. var setDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToList();
  1994. var countryFeeDatas = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  1995. var hotelDatas = _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1996. var hotelContentDatas = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => it.IsDel == 0 && it.IsPay == 0 && it.Price != 0 && groupIds.Contains(it.DiId)).ToList();
  1997. var opDatas = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  1998. var visaDatas = _sqlSugar.Queryable<Grp_VisaInfo>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DIId)).ToList();
  1999. var ioaDatas = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  2000. var insureDatas = _sqlSugar.Queryable<Grp_Customers>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  2001. var airDatas = _sqlSugar.Queryable<Grp_AirTicketReservations>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DIId)).ToList();
  2002. //var otherMoneyDatas = _sqlSugar.Queryable<Fin_OtherPrice>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Diid)).ToList();
  2003. var otherMoneyDatas = _sqlSugar.Queryable<Grp_DecreasePayments>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  2004. var refundPaymentDatas = _sqlSugar.Queryable<Fin_PaymentRefundAndOtherMoney>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  2005. var ExtraCostDatas = _sqlSugar.Queryable<Fin_GroupExtraCost>().Where(it => it.IsDel == 0 && groupIds.Contains(it.DiId)).ToList();
  2006. #endregion
  2007. //Expense company
  2008. foreach (var groupInfo in _groupDatas)
  2009. {
  2010. List<Group_DailyFeePaymentContentInfolView> childList = new List<Group_DailyFeePaymentContentInfolView>();
  2011. var groupPaymentDatas = _paymentDatas.Where(it => groupInfo.Id == it.DIId).ToList();
  2012. int rouNumber = 1;
  2013. foreach (var payInfo in groupPaymentDatas)
  2014. {
  2015. string priName = "-";
  2016. string orbitalPrivateTransfer = payInfo.OrbitalPrivateTransfer == 0 ? "公转" : payInfo.OrbitalPrivateTransfer == 1 ? "私转" : "-";
  2017. switch (payInfo.CTable)
  2018. {
  2019. case 76: //76 酒店预订
  2020. priName = $"[费用名称:{hotelDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.HotelName ?? ""}]";
  2021. break;
  2022. case 79: //79 车/导游地接
  2023. var opData = opDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id);
  2024. if (opData != null)
  2025. {
  2026. string area = "";
  2027. bool b = int.TryParse(opData.Area, out int areaId);
  2028. if (b)
  2029. {
  2030. string area1 = countryFeeDatas.Find(it => it.Id == areaId)?.Country ?? "-";
  2031. area = $"{area1}({setDatas.Find(it => it.Id == opData.PriceType)?.Name ?? "-"})";
  2032. }
  2033. else area = opData.Area;
  2034. string opPriName = "-";
  2035. if (!string.IsNullOrEmpty(opData.PriceName)) opPriName = opData.PriceName;
  2036. area += $"({opPriName})";
  2037. if (payInfo.OrbitalPrivateTransfer == 0) //公转
  2038. {
  2039. priName = $"【{orbitalPrivateTransfer}】【导游: {opData.ServiceGuide} 】[费用名称:{area}]";
  2040. }
  2041. else if (payInfo.OrbitalPrivateTransfer == 1) //私转
  2042. {
  2043. priName = $"【{orbitalPrivateTransfer}】【导游:{opData.ServiceGuide}】[费用名称:{area}]";
  2044. }
  2045. }
  2046. break;
  2047. case 80: // 80 签证
  2048. 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);
  2049. List<SimplClientInfo> arr = _sqlSugar.SqlQueryable<SimplClientInfo>(sql).ToList();
  2050. string visaClientName = visaDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.VisaClient ?? "";
  2051. string clientName = "-";
  2052. if (Regex.Match(visaClientName, @"\d+,?").Value.Length > 0)
  2053. {
  2054. string[] temparr = visaClientName.Split(',');
  2055. string fistrStr = temparr[0];
  2056. int count = temparr.Count();
  2057. int tempId;
  2058. bool success = int.TryParse(fistrStr, out tempId);
  2059. if (success)
  2060. {
  2061. SimplClientInfo tempInfo = arr.FirstOrDefault(s => s.Id == tempId);
  2062. if (tempInfo != null)
  2063. {
  2064. if (count > 1)
  2065. {
  2066. clientName = string.Format(@"{0}{1}等{2}人", tempInfo.LastName, tempInfo.FirstName, count);
  2067. }
  2068. else
  2069. {
  2070. clientName = string.Format(@"{0}{1}", tempInfo.LastName, tempInfo.FirstName);
  2071. }
  2072. }
  2073. }
  2074. else
  2075. {
  2076. clientName = fistrStr;
  2077. }
  2078. }
  2079. priName = $"[费用名称:{clientName}]";
  2080. break;
  2081. case 81: // 81 邀请/公务活动
  2082. priName = $"[费用名称:{ioaDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.Inviter ?? " -"}]";
  2083. break;
  2084. case 82: // 82 团组客户保险
  2085. string bx_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);
  2086. List<SimplClientInfo> bx_arr = _sqlSugar.SqlQueryable<SimplClientInfo>(bx_sql).ToList();
  2087. string bx_ClientName = insureDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.ClientName ?? "";
  2088. string bx_clientName = "-";
  2089. if (Regex.Match(bx_ClientName, @"\d+,?").Value.Length > 0)
  2090. {
  2091. string[] temparr = bx_ClientName.Split(',');
  2092. string fistrStr = temparr[0];
  2093. int count = temparr.Count();
  2094. int tempId;
  2095. bool success = int.TryParse(fistrStr, out tempId);
  2096. if (success)
  2097. {
  2098. SimplClientInfo tempInfo = bx_arr.FirstOrDefault(s => s.Id == tempId);
  2099. if (tempInfo != null)
  2100. {
  2101. if (count > 1)
  2102. {
  2103. bx_clientName = string.Format(@"{0}{1}等{2}人", tempInfo.LastName, tempInfo.FirstName, count);
  2104. }
  2105. else
  2106. {
  2107. bx_clientName = string.Format(@"{0}{1}", tempInfo.LastName, tempInfo.FirstName);
  2108. }
  2109. }
  2110. }
  2111. else
  2112. {
  2113. bx_clientName = fistrStr;
  2114. }
  2115. }
  2116. //priName = $"[费用名称:{insureDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.ClientName ?? " -"}]";
  2117. priName = $"[费用名称:{bx_clientName}]";
  2118. break;
  2119. case 85: // 85 机票预订
  2120. string flightsCode = airDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.FlightsCode ?? "-";
  2121. string airPayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "-";
  2122. priName = $"{flightsCode}【{airPayType}】";
  2123. break;
  2124. case 98: // 98 其他款项
  2125. priName = $"[费用名称:{otherMoneyDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? " -"}]";
  2126. break;
  2127. case 285: // 285 收款退还
  2128. priName = $"[费用名称:{refundPaymentDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? " -"}]";
  2129. break;
  2130. case 1015: // 1015 超支费用
  2131. priName = $"[费用名称:{ExtraCostDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? " -"}]";
  2132. break;
  2133. default:
  2134. priName = "";
  2135. break;
  2136. }
  2137. bool status1 = false;
  2138. if (_groupIds != null)
  2139. {
  2140. status1 = _groupIds.Contains(payInfo.Id);
  2141. }
  2142. if (payInfo.CTable == 76) //酒店单独处理
  2143. {
  2144. var hotelContents = hotelContentDatas.Where(it => it.HrId == payInfo.CId);
  2145. List<Group_DailyFeePaymentContentInfolView> childInfos = new List<Group_DailyFeePaymentContentInfolView>();
  2146. foreach (var hotelContent in hotelContents)
  2147. {
  2148. string subPriceName = "";
  2149. if (hotelContent.PriceType == 1) subPriceName = "房费";
  2150. else if (hotelContent.PriceType == 2) subPriceName = "早餐";
  2151. else if (hotelContent.PriceType == 3) subPriceName = "地税";
  2152. else if (hotelContent.PriceType == 4) subPriceName = "城市税";
  2153. if (string.IsNullOrEmpty(subPriceName)) subPriceName = priName;
  2154. else subPriceName = $"{priName.Replace("]","")}-{subPriceName}]";
  2155. string payeeStr1 = string.Format(@" {0},开户行:{1},银行卡号:{2} ",
  2156. string.IsNullOrEmpty(hotelContent.Payee) ? "-" : hotelContent.Payee,
  2157. string.IsNullOrEmpty(hotelContent.OtherBankName) ? "-" : hotelContent.OtherBankName,
  2158. string.IsNullOrEmpty(hotelContent.OtherSideNo) ? "-" : hotelContent.OtherSideNo);
  2159. decimal _PaymentAmount1 = hotelContent.Price;//此次付款金额
  2160. decimal _CNYSubTotalAmount1 = _PaymentAmount1 * hotelContent.Rate;//此次付款金额
  2161. _CNYSubTotalAmount1 = Convert.ToDecimal(_CNYSubTotalAmount1.ToString("#0.00"));
  2162. //酒店子项Id选中状态更改
  2163. if (_hotelSubIds != null) status1 = _hotelSubIds.Contains(hotelContent.Id);
  2164. var childInfo1 = new Group_DailyFeePaymentContentInfolView()
  2165. {
  2166. IsChecked = status1,
  2167. Id = payInfo.Id,
  2168. HotelSubId = hotelContent.Id,
  2169. Payee = payeeStr1,
  2170. RowNumber = rouNumber,
  2171. Applicant = userDatas.Find(it => it.Id == payInfo.CreateUserId)?.CnName ?? "",
  2172. ApplicantDt = payInfo.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
  2173. PayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "",
  2174. TransferMark = orbitalPrivateTransfer,
  2175. PriceName = subPriceName,
  2176. ModuleName = setDatas.Find(it => it.Id == payInfo.CTable)?.Name ?? "",
  2177. PayCurrCode = setDatas.Find(it => it.Id == hotelContent.Currency)?.Name ?? "",
  2178. PaymentAmount = _PaymentAmount1,
  2179. PayRate = hotelContent.Rate,
  2180. CNYSubTotalAmount = _CNYSubTotalAmount1,
  2181. AuditStatus = payInfo.IsAuditGM
  2182. };
  2183. 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})";
  2184. childInfo1.RemaksDescription = remaksDescription1;
  2185. if (status == 2)
  2186. {
  2187. if (status1)
  2188. {
  2189. childInfos.Add(childInfo1);
  2190. }
  2191. }
  2192. else childInfos.Add(childInfo1);
  2193. rouNumber++;
  2194. }
  2195. childList.AddRange(childInfos);
  2196. }
  2197. else
  2198. {
  2199. string payeeStr = string.Format(@" {0},开户行:{1},银行卡号:{2} ",
  2200. string.IsNullOrEmpty(payInfo.Payee) ? "-" : payInfo.Payee,
  2201. string.IsNullOrEmpty(payInfo.OtherBankName) ? "-" : payInfo.OtherBankName,
  2202. string.IsNullOrEmpty(payInfo.OtherSideNo) ? "-" : payInfo.OtherSideNo);
  2203. decimal _PaymentAmount = (payInfo.PayMoney / 100) * payInfo.PayPercentage;//此次付款金额
  2204. decimal _CNYSubTotalAmount = _PaymentAmount * payInfo.DayRate;//此次付款金额
  2205. _CNYSubTotalAmount = Convert.ToDecimal(_CNYSubTotalAmount.ToString("#0.00"));
  2206. var childInfo = new Group_DailyFeePaymentContentInfolView()
  2207. {
  2208. IsChecked = status1,
  2209. Id = payInfo.Id,
  2210. Payee = payeeStr,
  2211. RowNumber = rouNumber,
  2212. Applicant = userDatas.Find(it => it.Id == payInfo.CreateUserId)?.CnName ?? "",
  2213. ApplicantDt = payInfo.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
  2214. PayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "",
  2215. TransferMark = orbitalPrivateTransfer,
  2216. PriceName = priName,
  2217. ModuleName = setDatas.Find(it => it.Id == payInfo.CTable)?.Name ?? "",
  2218. PayCurrCode = setDatas.Find(it => it.Id == payInfo.PaymentCurrency)?.Name ?? "",
  2219. PaymentAmount = _PaymentAmount,
  2220. PayRate = payInfo.DayRate,
  2221. CNYSubTotalAmount = _CNYSubTotalAmount,
  2222. AuditStatus = payInfo.IsAuditGM
  2223. };
  2224. 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})";
  2225. childInfo.RemaksDescription = remaksDescription;
  2226. childList.Add(childInfo);
  2227. rouNumber++;
  2228. }
  2229. }
  2230. CompanyInfo companyInfo = new CompanyInfo();
  2231. companyInfo = ExpenseCompanyByTeamId(groupInfo.TeamDid);
  2232. dataList.Add(new tree_Group_DailyFeePaymentPageListView()
  2233. {
  2234. Id = Guid.NewGuid().ToString("N"),
  2235. GroupName = groupInfo.TeamName,
  2236. CompanyId = companyInfo.Id,
  2237. ConpanyName = companyInfo.ConpanyName,
  2238. CNYTotalAmount = childList.Sum(it => it.CNYSubTotalAmount),
  2239. ChildList = childList,
  2240. });
  2241. }
  2242. _DailyFeePaymentResult.dataList = dataList;
  2243. return _DailyFeePaymentResult;
  2244. }
  2245. /// <summary>
  2246. /// 付款申请(日付申请相关)
  2247. /// 查询 根据日期范围
  2248. /// </summary>
  2249. /// <param name="_dailyIds"></param>
  2250. /// <param name="beginDt"></param>
  2251. /// <param name="endDt"></param>
  2252. /// <returns></returns>
  2253. private tree_Fin_DailyFeePaymentResult PayRequest_DailyByDateRange(int status, List<int> _dailyIds, string beginDt, string endDt)
  2254. {
  2255. #region sql条件处理
  2256. string sqlWhere = string.Format(@" And dfp.CreateTime between '{0} 00:00:00' And '{1} 23:59:59' ", beginDt, endDt);
  2257. if (status == 2)
  2258. {
  2259. if (_dailyIds.Count < 1)
  2260. {
  2261. return new tree_Fin_DailyFeePaymentResult() { childList = new List<Fin_DailyFeePaymentContentInfolView>() };
  2262. }
  2263. sqlWhere += string.Format(@" And dfp.Id In({0}) ", string.Join(",", _dailyIds));
  2264. }
  2265. string sql_1 = string.Format(@"Select * From (
  2266. Select row_number() over (order by dfp.Id Desc) as RowNumber,
  2267. dfp.Id,dfp.CompanyId,c.CompanyName,dfp.Instructions,dfp.SumPrice,
  2268. dfp.CreateUserId,u.CnName CreateUser,dfp.CreateTime,dfp.FAudit,dfp.MAudit,
  2269. dfp.PriceTypeId,dfp.TransferTypeId
  2270. From Fin_DailyFeePayment dfp
  2271. Inner Join Sys_Company c On dfp.CompanyId = c.Id
  2272. Left Join Sys_Users u On dfp.CreateUserId = u.Id
  2273. Where dfp.IsDel=0 {0} And dfp.FAudit = 1 And dfp.MAudit = 1 And dfp.IsPay = 0
  2274. ) temp ", sqlWhere);
  2275. #endregion
  2276. List<tree_Fin_DailyFeePaymentPageListView> DailyFeePaymentData = _sqlSugar.SqlQueryable<tree_Fin_DailyFeePaymentPageListView>(sql_1).ToList();
  2277. Dictionary<int, string> dic_setData = new Dictionary<int, string>();
  2278. Sys_SetDataType stGZ = _daiRep.Query<Sys_SetDataType>(s => s.Name == "公转").First();
  2279. Sys_SetDataType stSZ = _daiRep.Query<Sys_SetDataType>(s => s.Name == "私转").First();
  2280. foreach (var item in DailyFeePaymentData)
  2281. {
  2282. if (_dailyIds != null)
  2283. {
  2284. item.IsChecked = _dailyIds.Contains(item.Id);
  2285. }
  2286. if (dic_setData.ContainsKey(item.PriceTypeId))
  2287. {
  2288. item.priceTypeStr = dic_setData[item.PriceTypeId];
  2289. }
  2290. else
  2291. {
  2292. Sys_SetData sd_priceType = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceTypeId).First();
  2293. if (sd_priceType != null)
  2294. {
  2295. item.priceTypeStr = sd_priceType.Name;
  2296. dic_setData.Add(item.PriceTypeId, sd_priceType.Name);
  2297. }
  2298. }
  2299. if (dic_setData.ContainsKey(item.transferTypeId))
  2300. {
  2301. item.transferTypeIdStr = dic_setData[item.transferTypeId];
  2302. Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
  2303. if (sd_transfer != null)
  2304. {
  2305. item.transferParentId = sd_transfer.STid;
  2306. item.transferParentIdStr = sd_transfer.STid == stGZ.Id ? "公转" : sd_transfer.STid == stSZ.Id ? "私转" : "";
  2307. }
  2308. }
  2309. else
  2310. {
  2311. Sys_SetData sd_transfer = _daiRep.Query<Sys_SetData>(s => s.Id == item.transferTypeId).First();
  2312. if (sd_transfer != null)
  2313. {
  2314. item.transferTypeIdStr = sd_transfer.Name;
  2315. item.transferParentId = sd_transfer.STid;
  2316. item.transferParentIdStr = sd_transfer.STid == stGZ.Id ? "公转" : sd_transfer.STid == stSZ.Id ? "私转" : "";
  2317. dic_setData.Add(item.transferTypeId, sd_transfer.Name);
  2318. }
  2319. }
  2320. string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent
  2321. Where IsDel=0 And DFPId = {0} ", item.Id);
  2322. item.childList = _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToList();
  2323. int rowNumber = 1;
  2324. foreach (var subItem in item.childList)
  2325. {
  2326. string remaksDescription = $"{rowNumber}、【{item.priceTypeStr}】{item.Instructions}({subItem.PriceName}) CNY:{subItem.ItemTotal.ToString("#0.00")}(单价:{subItem.Price.ToString("#0.00")} * {subItem.Quantity})";
  2327. subItem.RemaksDescription = remaksDescription;
  2328. 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")}】";
  2329. subItem.ExcelRemaksDescription = excelRemaksDescription;
  2330. rowNumber++;
  2331. }
  2332. }
  2333. decimal total_gz = DailyFeePaymentData.Where(s => s.transferParentId == stGZ.Id).Sum(d => d.SumPrice ?? 0M);
  2334. decimal total_sz = DailyFeePaymentData.Where(s => s.transferParentId == stSZ.Id).Sum(d => d.SumPrice ?? 0M);
  2335. var result = new tree_Fin_DailyFeePaymentResult() { gz = total_gz, sz = total_sz, dataList = DailyFeePaymentData };
  2336. return result;
  2337. }
  2338. /// <summary>
  2339. /// 付款申请 (PageId=51)
  2340. /// 团组,日付相关费用 选中状态变更
  2341. /// </summary>
  2342. /// <param name="dto"></param>
  2343. /// <returns></returns>
  2344. [HttpPost]
  2345. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2346. public async Task<IActionResult> PostPayRequestCheckedChange(PayRequestCheckedChangeDto dto)
  2347. {
  2348. #region 验证
  2349. if (dto.Type < 1 || dto.Type > 2)
  2350. {
  2351. return Ok(JsonView(false, "请传入有效的Type参数! 1 checked 2 清除上次勾选"));
  2352. }
  2353. #endregion
  2354. PaymentRequestCheckedView requestCheckedView = new PaymentRequestCheckedView();
  2355. List<int> groupIds = new List<int>();
  2356. List<int> dailyPaymentIds = new List<int>();
  2357. List<int> hotelIds = new List<int>();
  2358. #region 参数处理
  2359. if (!string.IsNullOrEmpty(dto.GroupIds))
  2360. {
  2361. if (dto.GroupIds.Contains(","))
  2362. {
  2363. groupIds = dto.GroupIds.Split(',').Select(int.Parse).ToList();
  2364. }
  2365. else
  2366. {
  2367. groupIds.Add(int.Parse(dto.GroupIds));
  2368. }
  2369. }
  2370. if (!string.IsNullOrEmpty(dto.HotelSubIds))
  2371. {
  2372. if (dto.HotelSubIds.Contains(","))
  2373. {
  2374. hotelIds = dto.HotelSubIds.Split(',').Select(int.Parse).ToList();
  2375. }
  2376. else
  2377. {
  2378. hotelIds.Add(int.Parse(dto.HotelSubIds));
  2379. }
  2380. }
  2381. if (!string.IsNullOrEmpty(dto.DailyPaymentIds))
  2382. {
  2383. if (dto.DailyPaymentIds.Contains(","))
  2384. {
  2385. dailyPaymentIds = dto.DailyPaymentIds.Split(',').Select(int.Parse).ToList();
  2386. }
  2387. else
  2388. {
  2389. dailyPaymentIds.Add(int.Parse(dto.DailyPaymentIds));
  2390. }
  2391. }
  2392. #endregion
  2393. requestCheckedView.GroupIds = groupIds;
  2394. requestCheckedView.HotelSubIds = hotelIds;
  2395. requestCheckedView.DailyPaymentIds = dailyPaymentIds;
  2396. if (dto.Type == 1)
  2397. {
  2398. TimeSpan ts = DateTime.Now.AddDays(180) - DateTime.Now; //设置redis 过期时间 半年(180)
  2399. var status = await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>("paymentRequestCheckedData", JsonConvert.SerializeObject(requestCheckedView), ts);
  2400. if (status)
  2401. {
  2402. return Ok(JsonView(true, "操作成功!"));
  2403. }
  2404. }
  2405. else if (dto.Type == 2)
  2406. {
  2407. var status = await RedisRepository.RedisFactory.CreateRedisRepository().KeyDeleteAsync("paymentRequestCheckedData");
  2408. if (status)
  2409. {
  2410. return Ok(JsonView(true, "操作成功!"));
  2411. }
  2412. }
  2413. return Ok(JsonView(false, "操作失败!"));
  2414. }
  2415. /// <summary>
  2416. /// 付款申请 (PageId=51)
  2417. /// 团组,日付相关费用 汇率变更
  2418. /// </summary>
  2419. /// <param name="dto"></param>
  2420. /// <returns></returns>
  2421. [HttpPost]
  2422. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2423. public async Task<IActionResult> PostPayRequestRateChange(PayRequestRateChangeDto dto)
  2424. {
  2425. #region 验证
  2426. DateTime beginDt, endDt;
  2427. string format = "yyyy-MM-dd";
  2428. if (!DateTime.TryParseExact(dto.beginDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out beginDt))
  2429. {
  2430. return Ok(JsonView(false, "开始日期格式不正确!正确格式:yyyy-MM-dd"));
  2431. }
  2432. if (!DateTime.TryParseExact(dto.endDt, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt))
  2433. {
  2434. return Ok(JsonView(false, "结束日期格式不正确!正确格式:yyyy-MM-dd"));
  2435. }
  2436. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  2437. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数!"));
  2438. if (dto.Rate <= 0) return Ok(JsonView(false, "请传入有效的Rate参数!"));
  2439. #endregion
  2440. int hotelSubStatus = 0,status = 0;
  2441. int diid = 0, cTable = 0, currId = 0;
  2442. if (dto.HotelSubId > 0)
  2443. {
  2444. //更改酒店子表汇率
  2445. hotelSubStatus = _sqlSugar.Updateable<Grp_HotelReservationsContent>()
  2446. .SetColumns(it => it.Rate == dto.Rate)
  2447. .Where(it => it.Id == dto.HotelSubId)
  2448. .ExecuteCommand();
  2449. if (hotelSubStatus > 0)
  2450. {
  2451. var hotelSubInfo = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => it.Id == dto.HotelSubId).First();
  2452. if (hotelSubInfo != null)
  2453. {
  2454. diid = hotelSubInfo.DiId;
  2455. currId = hotelSubInfo.Currency;
  2456. }
  2457. //付款申请汇率更改成功;更改团组汇率对应币种
  2458. string currCode = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == currId).First()?.Name ?? "";
  2459. await _teamRateRep.UpdateGroupRateByDiIdAndCTableId(diid, 76, currCode, dto.Rate);
  2460. }
  2461. }
  2462. if (dto.Id > 0)
  2463. {
  2464. var ccpInfo = _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(it => it.Id == dto.Id).First();
  2465. decimal cnyMoney = 0.00M;
  2466. if (ccpInfo != null) {
  2467. cnyMoney = ccpInfo.PayMoney * dto.Rate;
  2468. diid = ccpInfo.DIId;
  2469. cTable = ccpInfo.CTable;
  2470. currId = ccpInfo.PaymentCurrency;
  2471. }
  2472. status = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  2473. .SetColumns(it => it.DayRate == dto.Rate)
  2474. .SetColumns(it => it.RMBPrice == cnyMoney)
  2475. .Where(it => it.Id == dto.Id)
  2476. .ExecuteCommand();
  2477. if (status > 0)
  2478. {
  2479. //付款申请汇率更改成功;更改团组汇率对应币种
  2480. if (cTable != 76)
  2481. {
  2482. string currCode = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == currId).First()?.Name ?? "";
  2483. await _teamRateRep.UpdateGroupRateByDiIdAndCTableId(diid, cTable, currCode, dto.Rate);
  2484. }
  2485. }
  2486. }
  2487. if (hotelSubStatus > 0 || status > 0)
  2488. {
  2489. PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
  2490. var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
  2491. if (checkedStr != null)
  2492. {
  2493. checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
  2494. }
  2495. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(1, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
  2496. tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(1, checkedView.GroupIds, checkedView.HotelSubIds, dto.beginDt, dto.endDt);
  2497. decimal _gz = dailyResult.gz + groupResult.gz;
  2498. decimal _sz = dailyResult.sz + groupResult.sz;
  2499. return Ok(JsonView(true, "操作成功!", new { gz = dailyResult, sz = groupResult }));
  2500. }
  2501. return Ok(JsonView(false, "该项汇率修改失败!"));
  2502. }
  2503. /// <summary>
  2504. /// 付款申请 (PageId=51)
  2505. /// 团组,日付相关费用 付款状态变更
  2506. /// </summary>
  2507. /// <param name="dto"></param>
  2508. /// <returns></returns>
  2509. [HttpPost]
  2510. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2511. public async Task<IActionResult> PostPayRequestPayChange(PayRequestPayChangeDto dto)
  2512. {
  2513. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  2514. //if (string.IsNullOrEmpty(dto.GroupIds))
  2515. //{
  2516. // return Ok(JsonView(false, "请传入有效的GroupIds参数!"));
  2517. //}
  2518. //if (string.IsNullOrEmpty(dto.DailyPaymentIds))
  2519. //{
  2520. // return Ok(JsonView(false, "请传入有效的DailyPaymentIds参数!"));
  2521. //}
  2522. List<int> groupIds = new List<int>();
  2523. List<int> dailyPaymentIds = new List<int>();
  2524. List<int> hotelSubIds = new List<int>();
  2525. #region 参数处理
  2526. if (!string.IsNullOrEmpty(dto.GroupIds))
  2527. {
  2528. if (dto.GroupIds.Contains(",")) groupIds = dto.GroupIds.Split(',').Select(int.Parse).ToList();
  2529. else groupIds.Add(int.Parse(dto.GroupIds));
  2530. }
  2531. if (!string.IsNullOrEmpty(dto.HotelSubIds))
  2532. {
  2533. if (dto.HotelSubIds.Contains(",")) hotelSubIds = dto.HotelSubIds.Split(',').Select(int.Parse).ToList();
  2534. else hotelSubIds.Add(int.Parse(dto.HotelSubIds));
  2535. if (hotelSubIds.Count > 0)
  2536. {
  2537. foreach (var item in hotelSubIds)
  2538. {
  2539. if (item < 1)
  2540. {
  2541. hotelSubIds.Remove(item);
  2542. }
  2543. }
  2544. }
  2545. }
  2546. if (!string.IsNullOrEmpty(dto.DailyPaymentIds))
  2547. {
  2548. if (dto.DailyPaymentIds.Contains(",")) dailyPaymentIds = dto.DailyPaymentIds.Split(',').Select(int.Parse).ToList();
  2549. else dailyPaymentIds.Add(int.Parse(dto.DailyPaymentIds));
  2550. }
  2551. #endregion
  2552. bool changeStatus = false;
  2553. _sqlSugar.BeginTran();
  2554. if (groupIds.Count > 0)
  2555. {
  2556. var ccpInfos = _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(it => it.IsDel == 0 && groupIds.Contains(it.Id)).ToList();
  2557. var otherTypeCcpIds = ccpInfos.Where(it => it.CTable != 76).Select(it => it.Id).ToList();
  2558. var hotelTyprCcpIds = ccpInfos.Where(it => it.CTable == 76).Select(it => it.Id).ToList();
  2559. int groupStatus = 0;
  2560. if (otherTypeCcpIds.Count > 0) //其他费用类型 正常付款
  2561. {
  2562. groupStatus = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  2563. .SetColumns(it => it.IsPay == 1)
  2564. .Where(it => otherTypeCcpIds.Contains(it.Id))
  2565. .ExecuteCommand();
  2566. changeStatus = true;
  2567. }
  2568. if (hotelTyprCcpIds.Count > 0) //酒店费用子项逻辑付款,酒店子项费用全部付完款,c表ispay=1
  2569. {
  2570. if (hotelSubIds.Count > 0)
  2571. {
  2572. List<int> hrPayIds = new List<int>();
  2573. var hrIspayStatus = _sqlSugar.Updateable<Grp_HotelReservationsContent>()
  2574. .SetColumns(it => it.IsPay == 1)
  2575. .Where(it => hotelSubIds.Contains(it.Id))
  2576. .ExecuteCommand();
  2577. changeStatus = true;
  2578. //酒店子项是否全部付完款
  2579. List<int> hrIds = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => it.IsDel == 0 && hotelSubIds.Contains(it.Id)).Select(it => it.HrId).Distinct().ToList();
  2580. if (hrIds.Count > 0 )
  2581. {
  2582. var hotelSubFeeData = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => it.IsDel == 0 && hrIds.Contains(it.HrId)).ToList();
  2583. var hotelSubFeeGroupData = hotelSubFeeData.GroupBy(it => it.HrId).ToList();
  2584. foreach (var item in hotelSubFeeGroupData)
  2585. {
  2586. var allTotal = item.Where(it => it.Price > 0).ToList().Count;
  2587. var paymentTotal = item.Where(it => it.Price > 0 && it.IsPay == 1).ToList().Count;
  2588. if (allTotal == paymentTotal)
  2589. {
  2590. hrPayIds.Add(item.Key);
  2591. }
  2592. }
  2593. }
  2594. if (hrPayIds.Count > 0)
  2595. {
  2596. //c表更改全部付款的酒店费用
  2597. groupStatus = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  2598. .SetColumns(it => it.IsPay == 1)
  2599. .Where(it => it.CTable == 76 && hrPayIds.Contains(it.CId))
  2600. .ExecuteCommand();
  2601. }
  2602. }
  2603. }
  2604. }
  2605. //if (hotelSubIds.Count > 0)
  2606. //{
  2607. // var groupStatus = _sqlSugar.Updateable<Grp_HotelReservationsContent>()
  2608. // .SetColumns(it => it.IsPay == 1)
  2609. // .Where(it => hotelSubIds.Contains(it.Id))
  2610. // .ExecuteCommand();
  2611. // if (groupStatus > 0)
  2612. // {
  2613. // changeStatus = true;
  2614. // }
  2615. //}
  2616. if (dailyPaymentIds.Count > 0)
  2617. {
  2618. var dailyPaymentStatus = _sqlSugar.Updateable<Fin_DailyFeePayment>()
  2619. .SetColumns(it => it.IsPay == 1)
  2620. .Where(it => dailyPaymentIds.Contains(it.Id))
  2621. .ExecuteCommand();
  2622. if (dailyPaymentStatus > 0)
  2623. {
  2624. changeStatus = true;
  2625. }
  2626. }
  2627. if (changeStatus)
  2628. {
  2629. _sqlSugar.CommitTran();
  2630. #region 应用推送
  2631. try
  2632. {
  2633. foreach (int ccpId in groupIds)
  2634. {
  2635. List<string> tempList = new List<string>() { ccpId.ToString() };
  2636. await AppNoticeLibrary.SendUserMsg_GroupStatus_PayResult(ccpId, tempList);
  2637. }
  2638. foreach (int dailyId in dailyPaymentIds)
  2639. {
  2640. List<string> tempList = new List<string>() { dailyId.ToString() };
  2641. await AppNoticeLibrary.DailyPayReminder_Pay_ToUser(dailyId, tempList);
  2642. }
  2643. }
  2644. catch (Exception ex)
  2645. {
  2646. }
  2647. #endregion
  2648. return Ok(JsonView(true, "操作成功!"));
  2649. }
  2650. _sqlSugar.RollbackTran();
  2651. return Ok(JsonView(false, "付款状态修改失败!"));
  2652. }
  2653. /// <summary>
  2654. /// 付款申请 (PageId=51)
  2655. /// File Download
  2656. /// </summary>
  2657. /// <param name="dto"></param>
  2658. /// <returns></returns>
  2659. [HttpPost]
  2660. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2661. public async Task<IActionResult> PostPayRequestFileDownload(PayRequestFileDownloadDto dto)
  2662. {
  2663. Stopwatch stopwatch = Stopwatch.StartNew();
  2664. #region 参数,权限 验证
  2665. if (dto.PortType < 1)
  2666. {
  2667. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  2668. }
  2669. if (dto.UserId < 1)
  2670. {
  2671. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  2672. }
  2673. if (dto.PageId < 1)
  2674. {
  2675. dto.PageId = 51;
  2676. return Ok(JsonView(false, "请传入有效的PageId参数!"));
  2677. }
  2678. if (dto.ConpanyId < 1 || dto.ConpanyId > 4)
  2679. {
  2680. return Ok(JsonView(false, "请传入有效的ConpanyId参数!"));
  2681. }
  2682. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2683. #region 页面操作权限验证
  2684. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  2685. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  2686. #endregion
  2687. #endregion
  2688. try
  2689. {
  2690. PaymentRequestCheckedView checkedView = new PaymentRequestCheckedView();
  2691. var checkedStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("paymentRequestCheckedData");
  2692. if (checkedStr != null)
  2693. {
  2694. checkedView = JsonConvert.DeserializeObject<PaymentRequestCheckedView>(checkedStr.ToString());
  2695. }
  2696. if (checkedView == null)
  2697. {
  2698. return Ok(JsonView(false, "没有选中的数据!"));
  2699. }
  2700. if (checkedView.GroupIds == null && checkedView.DailyPaymentIds == null)
  2701. {
  2702. return Ok(JsonView(false, "没有选中的数据!"));
  2703. }
  2704. tree_Fin_DailyFeePaymentResult dailyResult = PayRequest_DailyByDateRange(2, checkedView.DailyPaymentIds, dto.beginDt, dto.endDt);
  2705. tree_Group_DailyFeePaymentResult groupResult = PayRequest_GroupPaymentByDateRange(2, checkedView.GroupIds, checkedView.HotelSubIds, dto.beginDt, dto.endDt);
  2706. if (dailyResult.childList == null)
  2707. {
  2708. dailyResult.childList = new List<Fin_DailyFeePaymentContentInfolView>();
  2709. }
  2710. List<tree_Group_DailyFeePaymentPageListView> _GroupData = new List<tree_Group_DailyFeePaymentPageListView>();
  2711. List<tree_Fin_DailyFeePaymentPageListView> _DailyData = new List<tree_Fin_DailyFeePaymentPageListView>();
  2712. //1 成都泛美商务有限公司
  2713. if (dto.ConpanyId == 1)
  2714. {
  2715. if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 1).ToList();
  2716. if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 1).ToList();
  2717. }
  2718. //2 四川泛美交流有限公司
  2719. else if (dto.ConpanyId == 2)
  2720. {
  2721. if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 2).ToList();
  2722. if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 2).ToList();
  2723. }
  2724. //3 成都纽茵教育科技有限公司
  2725. else if (dto.ConpanyId == 3)
  2726. {
  2727. if (groupResult.dataList != null && groupResult.dataList.Count > 0) _GroupData = groupResult.dataList.Where(it => it.CompanyId == 3).ToList();
  2728. if (dailyResult.dataList != null && dailyResult.dataList.Count > 0) _DailyData = dailyResult.dataList.Where(it => it.CompanyId == 3).ToList();
  2729. }
  2730. //4 成都鸿企中元科技有限公司
  2731. else if (dto.ConpanyId == 4)
  2732. {
  2733. return Ok(JsonView(false, "暂未开放该类型!"));
  2734. }
  2735. else
  2736. {
  2737. return Ok(JsonView(false, "参数ConpanyId不可使用!"));
  2738. }
  2739. string _requestPaymentDt = DateTime.Now.ToString("yyyy-MM-dd"),//申请付款日期
  2740. _appliedAmount = "", //申请付款金额
  2741. _GZStr = "", //公转价格描述
  2742. _SZStr = ""; //私转价格描述
  2743. decimal groupGZAmout = 0.00M, groupSZAmout = 0.00M;
  2744. decimal dailyGZAmout = 0.00M, dailySZAmout = 0.00M;
  2745. string dailyGZStr = "", dailySZStr = "", groupGZStr = "", groupSZStr = "";
  2746. #region 数据处理
  2747. //团组费用相关
  2748. foreach (var item in _GroupData)
  2749. {
  2750. string groupGZSubStr = "";
  2751. string groupSZSubStr = "";
  2752. foreach (var subItem in item.ChildList)
  2753. {
  2754. if (subItem.TransferMark.Equals("公转"))
  2755. {
  2756. groupGZAmout += subItem.CNYSubTotalAmount;
  2757. groupGZSubStr += $"{subItem.RemaksDescription}\r\n";
  2758. }
  2759. else if (subItem.TransferMark.Equals("私转"))
  2760. {
  2761. groupSZAmout += subItem.CNYSubTotalAmount;
  2762. groupSZSubStr += $"{subItem.RemaksDescription}\r\n";
  2763. }
  2764. //groupGZSubStr += $"\t";
  2765. }
  2766. //if (!string.IsNullOrEmpty(groupGZSubStr)) groupGZStr += $"团组:{item.GroupName}\r\n{groupGZSubStr}\r\n";
  2767. //if (!string.IsNullOrEmpty(groupSZSubStr)) groupSZStr += $"团组:{item.GroupName}\r\n{groupSZSubStr}\r\n";
  2768. if (!string.IsNullOrEmpty(groupGZSubStr)) groupGZStr += $"{groupGZSubStr}\r\n";
  2769. if (!string.IsNullOrEmpty(groupSZSubStr)) groupSZStr += $"{groupSZSubStr}\r\n";
  2770. }
  2771. //日常费用相关
  2772. foreach (var item in _DailyData)
  2773. {
  2774. foreach (var subItem in item.childList)
  2775. {
  2776. if (item.transferParentId == 62) //公转
  2777. {
  2778. dailyGZAmout += item.SumPrice ?? 0.00M;
  2779. dailyGZStr += $"{item.RowNumber}、【{item.CompanyName}】{subItem.ExcelRemaksDescription}\r\n";
  2780. }
  2781. else if (item.transferParentId == 63) //私转
  2782. {
  2783. dailySZAmout += item.SumPrice ?? 0.00M;
  2784. dailySZStr += $"{item.RowNumber}、【{item.CompanyName}】{subItem.ExcelRemaksDescription}\r\n";
  2785. }
  2786. }
  2787. }
  2788. _GZStr = $"【公转】团组相关费用(合计:CNY {groupGZAmout.ToString("#0.00")}):\r\n{groupGZStr}【公转】日常付款费用(合计:CNY {dailyGZAmout.ToString("#0.00")}):\r\n{dailyGZStr}";
  2789. _SZStr = $"【私转】团组相关费用(合计:CNY {groupSZAmout.ToString("#0.00")}):\r\n{groupSZStr}【私转】日常付款费用(合计:CNY {dailySZAmout.ToString("#0.00")}):\r\n{dailySZStr}";
  2790. _appliedAmount = $"公转:CNY {(groupGZAmout + dailyGZAmout).ToString("#0.00")}\r\n私转:CNY {(groupSZAmout + dailySZAmout).ToString("#0.00")}";
  2791. #endregion
  2792. WorkbookDesigner designer = new WorkbookDesigner();
  2793. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/付款申请书.xls");
  2794. designer.SetDataSource("Date", _requestPaymentDt);
  2795. designer.SetDataSource("Price", _appliedAmount);
  2796. designer.SetDataSource("Content", _GZStr);
  2797. designer.SetDataSource("Content1", _SZStr);
  2798. //根据数据源处理生成报表内容
  2799. designer.Process();
  2800. string fileName = ("PayRequest/付款申请(" + dto.beginDt + "~" + dto.endDt + ").xlsx");
  2801. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  2802. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  2803. stopwatch.Stop();
  2804. return Ok(JsonView(true, $"操作成功!{stopwatch.ElapsedMilliseconds / 1000}s", new { url = rst }));
  2805. }
  2806. catch (Exception ex)
  2807. {
  2808. return Ok(JsonView(false, ex.Message));
  2809. }
  2810. }
  2811. #endregion
  2812. #region 超支费用
  2813. /// <summary>
  2814. /// 超支费用
  2815. /// 1增、2改、3删
  2816. /// </summary>
  2817. /// <param name="dto"></param>
  2818. /// <returns></returns>
  2819. [HttpPost]
  2820. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2821. public async Task<IActionResult> PostGroupExtraCost_Operator(Fin_GroupExtraCostDto_OP dto)
  2822. {
  2823. #region 验证
  2824. #endregion
  2825. Fin_GroupExtraCost _entity = new Fin_GroupExtraCost();
  2826. _entity.DiId = dto.diId;
  2827. _entity.PriceName = dto.priceName;
  2828. _entity.Price = dto.price;
  2829. _entity.PriceCurrency = dto.currency;
  2830. _entity.PriceType = dto.priceType;
  2831. _entity.Coefficient = dto.coefficient;
  2832. _entity.PriceDetailType = dto.priceDetailType;
  2833. _entity.FilePath = dto.filePath;
  2834. _entity.Remark = dto.remark;
  2835. _entity.PriceCount = dto.PriceCount;
  2836. _entity.Area = dto.Area;
  2837. DateTime dt_PriceDt;
  2838. bool b_PriceDt = DateTime.TryParse(dto.PriceDt, out dt_PriceDt);
  2839. if (b_PriceDt)
  2840. {
  2841. _entity.PriceDt = dt_PriceDt;
  2842. }
  2843. else
  2844. {
  2845. _entity.PriceDt = DateTime.MinValue;
  2846. }
  2847. _entity.PriceSum = dto.price * dto.PriceCount;
  2848. _daiRep.BeginTran();
  2849. if (dto.editType == 1)
  2850. {
  2851. _entity.CreateUserId = dto.createUser;
  2852. _entity.CreateTime = DateTime.Now;
  2853. _entity.IsDel = 0;
  2854. int returnId = await _daiRep.AddAsyncReturnId<Fin_GroupExtraCost>(_entity);
  2855. if (returnId > 0)
  2856. {
  2857. dto.Id = returnId;
  2858. }
  2859. }
  2860. else if (dto.editType == 2)
  2861. {
  2862. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  2863. {
  2864. PriceName = dto.priceName,
  2865. Price = dto.price,
  2866. PriceCurrency = dto.currency,
  2867. PriceType = dto.priceType,
  2868. PriceDetailType = dto.priceDetailType,
  2869. Coefficient = dto.coefficient,
  2870. FilePath = dto.filePath,
  2871. Remark = dto.remark,
  2872. PriceCount = dto.PriceCount,
  2873. PriceDt = _entity.PriceDt,
  2874. PriceSum = _entity.PriceSum,
  2875. Area = _entity.Area,
  2876. });
  2877. if (!res)
  2878. {
  2879. _daiRep.RollbackTran();
  2880. return Ok(JsonView(false, "2操作失败!"));
  2881. }
  2882. }
  2883. else if (dto.editType == 3)
  2884. {
  2885. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  2886. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  2887. {
  2888. IsDel = 1,
  2889. DeleteTime = delTime,
  2890. DeleteUserId = dto.createUser
  2891. });
  2892. if (!res)
  2893. {
  2894. _daiRep.RollbackTran();
  2895. return Ok(JsonView(false, "3操作失败!"));
  2896. }
  2897. }
  2898. else
  2899. {
  2900. _daiRep.RollbackTran();
  2901. return Ok(JsonView(false, "未知的editType"));
  2902. }
  2903. if (!extraCost_editCreditCardPayment(dto))
  2904. {
  2905. return Ok(JsonView(false, "ccp操作失败"));
  2906. }
  2907. _daiRep.CommitTran();
  2908. return Ok(JsonView(true, "操作成功"));
  2909. }
  2910. private Result PostCurrencyByDiid_Sync(int diId, int CId, int currencyId)
  2911. {
  2912. if (diId == 0)
  2913. {
  2914. return new Result() { Code = -1, Msg = "请传入团组Id!" };
  2915. }
  2916. if (CId == 0)
  2917. {
  2918. return new Result() { Code = -1, Msg = "请传入类型Id!" };
  2919. }
  2920. if (currencyId == 0)
  2921. {
  2922. return new Result() { Code = -1, Msg = "请传入币种Id!" };
  2923. }
  2924. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == diId && a.IsDel == 0 && a.CTable == CId);
  2925. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  2926. CurrencyInfo CurrencyRate = new CurrencyInfo();
  2927. try
  2928. {
  2929. if (_TeamRate != null)
  2930. {
  2931. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == currencyId);
  2932. if (_SetData != null)
  2933. {
  2934. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  2935. CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  2936. if (CurrencyRate != null)
  2937. {
  2938. return new Result() { Code = 0, Msg = "查询成功!", Data = CurrencyRate };
  2939. }
  2940. else
  2941. {
  2942. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  2943. }
  2944. }
  2945. else
  2946. {
  2947. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  2948. }
  2949. }
  2950. else
  2951. {
  2952. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  2953. }
  2954. }
  2955. catch (Exception)
  2956. {
  2957. return new Result() { Code = -1, Msg = "查询异常!", Data = CurrencyRate };
  2958. }
  2959. }
  2960. private bool extraCost_editCreditCardPayment(Fin_GroupExtraCostDto_OP costDto)
  2961. {
  2962. //设置团组汇率
  2963. decimal dcm_dayrate = 1M;
  2964. decimal dcm_rmbPrice = costDto.price;
  2965. int ispay = costDto.payType == 72 ? 1 : 0;
  2966. if (costDto.costSign != 3)
  2967. {
  2968. //获取新汇率 int diId,int CId, int currencyId
  2969. Result rate = this.PostCurrencyByDiid_Sync(costDto.diId, 1015, costDto.currency);
  2970. if (rate.Code == 0)
  2971. {
  2972. var rateInfo = (rate.Data as CurrencyInfo);
  2973. if (rateInfo is not null)
  2974. {
  2975. dcm_dayrate = rateInfo.Rate;
  2976. dcm_rmbPrice = rateInfo.Rate * dcm_rmbPrice;
  2977. }
  2978. else
  2979. {
  2980. dcm_dayrate = 1;
  2981. }
  2982. }
  2983. }
  2984. Grp_CreditCardPayment ccp = _daiRep.Query<Grp_CreditCardPayment>(s => s.CId == costDto.Id && s.CTable == 1015).First();
  2985. if (ccp == null)
  2986. {
  2987. ccp = new Grp_CreditCardPayment();
  2988. ccp.PayDId = costDto.payType;// dto
  2989. ccp.ConsumptionPatterns = "";
  2990. ccp.ConsumptionDate = "";
  2991. ccp.CTDId = costDto.payCardId;// dto
  2992. ccp.BankNo = "";
  2993. ccp.CardholderName = "";
  2994. ccp.PayMoney = costDto.price;// dto
  2995. ccp.PaymentCurrency = costDto.currency;// dto
  2996. ccp.CompanyBankNo = "";
  2997. ccp.OtherBankName = "";
  2998. ccp.OtherSideNo = "";
  2999. ccp.OtherSideName = "";
  3000. ccp.Remark = "";
  3001. ccp.CreateUserId = costDto.createUser;
  3002. ccp.CreateTime = DateTime.Now;
  3003. ccp.MFOperator = 0;
  3004. ccp.MFOperatorDate = "";
  3005. ccp.IsAuditDM = 0;
  3006. ccp.AuditDMOperate = 0;
  3007. ccp.AuditDMDate = "";
  3008. ccp.IsAuditMF = 0;
  3009. ccp.AuditMFOperate = 0;
  3010. ccp.AuditMFDate = "";
  3011. ccp.IsAuditGM = 0;
  3012. ccp.AuditGMOperate = 0;
  3013. ccp.AuditGMDate = "";
  3014. ccp.IsPay = ispay; // upd
  3015. ccp.DIId = costDto.diId;// dto
  3016. ccp.CId = costDto.Id;// dto
  3017. ccp.CTable = 1015; //超支费用指向id
  3018. ccp.IsDel = 0;
  3019. ccp.PayPercentage = 100M;
  3020. ccp.PayThenMoney = 0M;
  3021. ccp.PayPercentageOld = 100M;
  3022. ccp.PayThenMoneyOld = 0M;
  3023. ccp.UpdateDate = "";
  3024. ccp.Payee = costDto.payee;// dto
  3025. ccp.OrbitalPrivateTransfer = costDto.costSign;// dto
  3026. ccp.ExceedBudget = 0;
  3027. ccp.DayRate = dcm_dayrate; //upd
  3028. ccp.RMBPrice = dcm_rmbPrice; //upd
  3029. int ccpInsertId = _daiRep.AddReturnId<Grp_CreditCardPayment>(ccp);
  3030. if (ccpInsertId > 0)
  3031. {
  3032. return true;
  3033. }
  3034. }
  3035. else
  3036. {
  3037. if (costDto.editType == 2)
  3038. {
  3039. bool res = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  3040. {
  3041. PayDId = costDto.payType,
  3042. CTDId = costDto.payCardId,
  3043. PayMoney = costDto.price,
  3044. PaymentCurrency = costDto.currency,
  3045. IsPay = ispay,
  3046. Payee = costDto.payee,
  3047. OrbitalPrivateTransfer = costDto.costSign,
  3048. DayRate = dcm_dayrate,
  3049. RMBPrice = dcm_rmbPrice
  3050. });
  3051. return res;
  3052. }
  3053. else if (costDto.editType == 3)
  3054. {
  3055. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  3056. bool res2 = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  3057. {
  3058. IsDel = 1,
  3059. DeleteTime = delTime,
  3060. DeleteUserId = costDto.createUser
  3061. });
  3062. return res2;
  3063. }
  3064. }
  3065. return false;
  3066. }
  3067. /// <summary>
  3068. /// 超支费用
  3069. /// 详情查询
  3070. /// </summary>
  3071. /// <param name="dto"></param>
  3072. /// <returns></returns>
  3073. [HttpPost]
  3074. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3075. public async Task<IActionResult> PostGroupExtraCost_Detail(Fin_GroupExtraCostDto_Detail dto)
  3076. {
  3077. if (dto.Id < 1)
  3078. {
  3079. return Ok(JsonView(false, "查询失败"));
  3080. }
  3081. string sql = string.Format(@" Select
  3082. f.Id,f.DiId,
  3083. f.PriceName,f.Price,f.PriceCurrency,c.Payee,c.OrbitalPrivateTransfer,c.PayDId,f.area,
  3084. c.CTDId,f.PriceType,f.PriceDetailType,f.Coefficient,f.Remark,f.PriceCount,f.PriceDt
  3085. From Fin_GroupExtraCost f
  3086. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  3087. Left Join Sys_Users u On f.CreateUserId = u.Id
  3088. Where f.IsDel=0 And c.CTable = 1015
  3089. And f.Id = {0} ", dto.Id);
  3090. Fin_GroupExtraCostDetailView detailView = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostDetailView>(sql).FirstAsync();
  3091. if (detailView == null)
  3092. {
  3093. return Ok(JsonView(false, "查询失败"));
  3094. }
  3095. return Ok(JsonView(true, "查询成功", detailView));
  3096. }
  3097. /// <summary>
  3098. /// 超支费用
  3099. /// 列表查询
  3100. /// </summary>
  3101. /// <param name="dto"></param>
  3102. /// <returns></returns>
  3103. [HttpPost]
  3104. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3105. public async Task<IActionResult> PostGroupExtraCost_Search(Fin_GroupExtraCostDto_Search dto)
  3106. {
  3107. string sqlWhere = string.Format(@" And f.DiId = {0} ", dto.diId);
  3108. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  3109. int endIndex = startIndex + dto.PageSize - 1;
  3110. string sql_data = string.Format(@"Select * From (
  3111. Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
  3112. 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,
  3113. f.CreateUserId,f.PriceDt,c.IsAuditGM
  3114. From Fin_GroupExtraCost f
  3115. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  3116. Inner Join Sys_SetData s On f.PriceCurrency = s.Id
  3117. Left Join Sys_Users u On f.CreateUserId = u.Id
  3118. Where f.IsDel=0 And c.CTable = 1015 {0}
  3119. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  3120. string sql_count = string.Format(@"Select Count(1) as DataCount From (
  3121. Select row_number() over (order by f.Id Desc) as RowNumber,f.Id,f.DiId,
  3122. f.PriceName,f.PriceType,f.Price,f.FilePath,f.CreateUserId,f.CreateTime,c.IsAuditGM
  3123. From Fin_GroupExtraCost f
  3124. Inner Join Grp_CreditCardPayment c On f.Id = c.CId
  3125. Inner Join Sys_SetData s On f.PriceCurrency = s.Id
  3126. Left Join Sys_Users u On f.CreateUserId = u.Id
  3127. Where f.IsDel=0 And c.CTable = 1015 {0}
  3128. ) temp ", sqlWhere);
  3129. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  3130. {
  3131. //Fin_DailyFeePaymentPageCount
  3132. var count = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostViewDataCount>(sql_count).FirstAsync();
  3133. List<Fin_GroupExtraCostView> dataList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCostView>(sql_data).ToListAsync();
  3134. Dictionary<int, string> dic_setData = new Dictionary<int, string>();
  3135. Dictionary<int, string> dic_user = new Dictionary<int, string>();
  3136. foreach (var item in dataList)
  3137. {
  3138. DateTime dtTemp_PriceDt;
  3139. bool b_ct = DateTime.TryParse(item.PriceDt, out dtTemp_PriceDt);
  3140. if (b_ct)
  3141. {
  3142. item.PriceDt = dtTemp_PriceDt.ToString("yyyy-MM-dd");
  3143. }
  3144. //费用类型
  3145. if (dic_setData.ContainsKey(item.PriceType))
  3146. {
  3147. item.PriceTypeStr = dic_setData[item.PriceType];
  3148. }
  3149. else
  3150. {
  3151. Sys_SetData sd_priceTypeDetail = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceType).First();
  3152. if (sd_priceTypeDetail != null)
  3153. {
  3154. string tempName = sd_priceTypeDetail.Name.Replace("n", "");
  3155. item.PriceTypeStr = tempName;
  3156. dic_setData.Add(item.PriceType, tempName);
  3157. }
  3158. }
  3159. if (item.PriceDetailType > 0)
  3160. {
  3161. if (dic_setData.ContainsKey(item.PriceDetailType))
  3162. {
  3163. item.PriceTypeStr = item.PriceTypeStr + " - " + dic_setData[item.PriceDetailType];
  3164. }
  3165. else
  3166. {
  3167. Sys_SetData sd_priceTypeDetail = _daiRep.Query<Sys_SetData>(s => s.Id == item.PriceDetailType).First();
  3168. if (sd_priceTypeDetail != null)
  3169. {
  3170. string tempName = sd_priceTypeDetail.Name.Replace("n", "");
  3171. item.PriceTypeStr = item.PriceTypeStr + " - " + tempName;
  3172. dic_setData.Add(item.PriceDetailType, tempName);
  3173. }
  3174. }
  3175. }
  3176. //系统用户
  3177. if (dic_user.ContainsKey(item.CreateUserId))
  3178. {
  3179. item.CreateUserIdStr = dic_user[item.CreateUserId];
  3180. }
  3181. else
  3182. {
  3183. Sys_Users users = _daiRep.Query<Sys_Users>(s => s.Id == item.CreateUserId).First();
  3184. if (users != null)
  3185. {
  3186. item.CreateUserIdStr = users.CnName;
  3187. dic_user.Add(item.CreateUserId, users.CnName);
  3188. }
  3189. }
  3190. switch (item.IsAuditGM)
  3191. {
  3192. case 0: item.IsAuditGMStr = "未审核"; break;
  3193. case 1: item.IsAuditGMStr = "已通过"; break;
  3194. case 2: item.IsAuditGMStr = "未通过"; break;
  3195. default: item.IsAuditGMStr = "未知状态"; break;
  3196. }
  3197. }
  3198. var result = new ListViewBase<Fin_GroupExtraCostView>
  3199. {
  3200. CurrPageIndex = dto.PageIndex,
  3201. CurrPageSize = dto.PageSize,
  3202. DataCount = count.DataCount,
  3203. DataList = dataList
  3204. };
  3205. return Ok(JsonView(true, "查询成功", result));
  3206. }
  3207. return Ok(JsonView(false, "查询失败"));
  3208. }
  3209. /// <summary>
  3210. /// 超支费用
  3211. /// 数据集合配置
  3212. /// </summary>
  3213. /// <param name="dto"></param>
  3214. /// <returns></returns>
  3215. [HttpPost]
  3216. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3217. public async Task<IActionResult> PostGroupExtraCost_ListDataInit(Fin_GroupExtraCostDto_DataListInit dto)
  3218. {
  3219. //支付方式
  3220. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  3221. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  3222. //信用卡类型
  3223. List<Sys_SetData> Card = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
  3224. List<SetDataInfoView> _Card = _mapper.Map<List<SetDataInfoView>>(Card);
  3225. //超支费用类型
  3226. List<Sys_SetData> PriceType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 79 && a.IsDel == 0).ToList();
  3227. List<SetDataInfoView> _PriceType = _mapper.Map<List<SetDataInfoView>>(PriceType);
  3228. //超支费用详细类型
  3229. List<Sys_SetData> PriceDetailType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 80 && a.IsDel == 0).ToList();
  3230. PriceDetailType.ForEach(a => { a.Name = a.Name.Replace("n", ""); });
  3231. List<SetDataInfoView> _PriceDetailType = _mapper.Map<List<SetDataInfoView>>(PriceDetailType);
  3232. var data = new
  3233. {
  3234. Payment = _Payment,
  3235. Card = _Card,
  3236. PriceType = _PriceType,
  3237. PriceDetailType = _PriceDetailType
  3238. };
  3239. return Ok(JsonView(true, "", data));
  3240. }
  3241. /// <summary>
  3242. /// 超支费用
  3243. /// 导出团组超支费用Excel
  3244. /// </summary>
  3245. /// <param name="dto"></param>
  3246. /// <returns></returns>
  3247. [HttpPost]
  3248. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3249. public async Task<IActionResult> PostGroupExtraCost_OutputExcel(Fin_GroupExtraCostExcelDto dto)
  3250. {
  3251. string sqlGroup = string.Format(@" Select * From Grp_DelegationInfo WIth(Nolock) where Id = {0} ", dto.diId);
  3252. Grp_DelegationInfo grp_DelegationInfo = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sqlGroup).FirstAsync();
  3253. if (grp_DelegationInfo == null)
  3254. {
  3255. return Ok(JsonView(false, "导出失败,未查询到团组"));
  3256. }
  3257. Workbook workbook = new Workbook();
  3258. Worksheet sheet = workbook.Worksheets[0];
  3259. Cells cells = sheet.Cells;
  3260. //sheet.Protect(Aspose.Cells.ProtectionType.All, "123123", "");//保护工作表
  3261. //sheet.Protection.IsSelectingLockedCellsAllowed = true;//设置只能选择解锁单元格
  3262. //sheet.Protection.IsFormattingColumnsAllowed = true;//设置可以调整列
  3263. //sheet.Protection.IsFormattingRowsAllowed = true;//设置可以调整行
  3264. #region 数据源
  3265. string sqlData = string.Format(@" Select f.PriceType,REPLACE(s2.[Name],'超支费用','') as PriceTypeStr,'('+REPLACE(s3.[Name],'n','')+')' as PriceDetailTypeStr, PriceDt,PriceName,
  3266. Price,PriceCount,s.[Name] as Currency,PriceSum,f.Remark
  3267. From Fin_GroupExtraCost as f With(Nolock)
  3268. Inner Join Grp_CreditCardPayment as c With(Nolock) On f.Id = c.CId
  3269. Inner Join Sys_SetData as s With(Nolock) On f.PriceCurrency = s.Id
  3270. Inner Join Sys_SetData as s2 With(Nolock) On f.PriceType = s2.Id
  3271. Inner Join Sys_SetData as s3 With(Nolock) On f.PriceDetailType = s3.Id
  3272. Where f.DiId = {0} And f.IsDel=0 And c.CTable=1015
  3273. Order by PriceType ASC,PriceDt ASC ", dto.diId);
  3274. string sqlDataCount = string.Format(@" Select f.PriceType,COUNT(f.PriceType) as DataCount
  3275. From Fin_GroupExtraCost as f With(Nolock)
  3276. Inner Join Grp_CreditCardPayment as c With(Nolock) On f.Id = c.CId
  3277. Where f.DiId = {0} And f.IsDel=0 And c.CTable=1015
  3278. Group by PriceType ", dto.diId);
  3279. List<Fin_GroupExtraCost_ExcelView> dataList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCost_ExcelView>(sqlData).ToListAsync();
  3280. List<Fin_GroupExtraCost_ExcelCountView> countList = await _sqlSugar.SqlQueryable<Fin_GroupExtraCost_ExcelCountView>(sqlDataCount).ToListAsync();
  3281. if (dataList.Count < 1 || countList.Count < 1)
  3282. {
  3283. return Ok(JsonView(false, "导出失败,未查询到数据"));
  3284. }
  3285. #endregion
  3286. #region 标题
  3287. string cellValue_Header = grp_DelegationInfo.TeamName;
  3288. //Aspose.Cells.Style style1 = workbook.Styles[workbook.Styles.Add()];//新增样式
  3289. Aspose.Cells.Style style_Header = workbook.CreateStyle();
  3290. style_Header.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  3291. style_Header.VerticalAlignment = TextAlignmentType.Center;
  3292. style_Header.Font.Name = "微软雅黑";//文字字体
  3293. style_Header.Font.Size = 18;//文字大小
  3294. style_Header.IsLocked = false;//单元格解锁
  3295. style_Header.Font.IsBold = false;//粗体
  3296. style_Header.Font.Color = Color.FromArgb(255, 0, 0);
  3297. //style1.ForegroundColor = Color.FromArgb(0x99, 0xcc, 0xff);//设置背景色
  3298. //style1.Pattern = BackgroundType.Solid; //设置背景样式
  3299. //style1.IsTextWrapped = true;//单元格内容自动换行
  3300. style_Header.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  3301. style_Header.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  3302. style_Header.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  3303. style_Header.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  3304. cells.Merge(1, 1, 1, 10);
  3305. Aspose.Cells.Range range_header = cells.CreateRange(1, 1, 1, 10);
  3306. range_header.PutValue(cellValue_Header, false, false);
  3307. range_header.SetStyle(style_Header);
  3308. cells.SetRowHeight(1, 35);
  3309. #endregion
  3310. #region 列名
  3311. Aspose.Cells.Style style_colName = workbook.CreateStyle();
  3312. style_colName.Name = "colName";
  3313. style_colName.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  3314. style_colName.VerticalAlignment = TextAlignmentType.Center;
  3315. style_colName.Font.Name = "微软雅黑";//文字字体
  3316. style_colName.Font.Size = 12;//文字大小
  3317. style_colName.IsLocked = false;//单元格解锁
  3318. style_colName.Font.IsBold = true;//粗体
  3319. style_colName.Font.Color = Color.FromArgb(0, 0, 0);
  3320. style_colName.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  3321. style_colName.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  3322. style_colName.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  3323. style_colName.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  3324. List<Fin_GroupExtraCostExcelColumnSetting> colNameSettingList = new List<Fin_GroupExtraCostExcelColumnSetting>()
  3325. {
  3326. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 1, columnName="类型", columnWidth= 25},
  3327. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 2, columnName="时间", columnWidth= 16},
  3328. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 3, columnName="内容", columnWidth= 35},
  3329. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 4, columnName="单价", columnWidth= 12},
  3330. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 5, columnName="数量", columnWidth= 12},
  3331. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 6, columnName="货币", columnWidth= 12},
  3332. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 7, columnName="费用", columnWidth= 12},
  3333. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 8, columnName="汇率", columnWidth= 12},
  3334. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 9, columnName="人民币", columnWidth= 12},
  3335. new Fin_GroupExtraCostExcelColumnSetting(){ columnIndex = 10, columnName="备注信息", columnWidth= 24}
  3336. };
  3337. foreach (var col in colNameSettingList)
  3338. {
  3339. cells[2, col.columnIndex].PutValue(col.columnName);
  3340. cells[2, col.columnIndex].SetStyle(style_colName);
  3341. cells.SetColumnWidth(col.columnIndex, col.columnWidth);
  3342. }
  3343. cells.SetRowHeight(2, 25);
  3344. #endregion
  3345. #region 数据填充
  3346. Aspose.Cells.Style style_dataCol = workbook.GetNamedStyle("colName");
  3347. style_dataCol.Font.IsBold = false;
  3348. style_dataCol.Name = "dataCol";
  3349. Aspose.Cells.Style style_dataBlue = workbook.CreateStyle();
  3350. style_dataBlue.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  3351. style_dataBlue.VerticalAlignment = TextAlignmentType.Center;
  3352. style_dataBlue.Font.Name = "微软雅黑";//文字字体
  3353. style_dataBlue.Font.Size = 12;//文字大小
  3354. style_dataBlue.IsLocked = false;//单元格解锁
  3355. style_dataBlue.Font.IsBold = false;//粗体
  3356. style_dataBlue.ForegroundColor = Color.FromArgb(189, 215, 238);
  3357. style_dataBlue.Pattern = BackgroundType.Solid;
  3358. style_dataBlue.Font.Color = Color.FromArgb(0, 0, 0);
  3359. style_dataBlue.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  3360. style_dataBlue.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  3361. style_dataBlue.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  3362. style_dataBlue.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  3363. Aspose.Cells.Style style_dataYellow = workbook.CreateStyle();
  3364. style_dataYellow.HorizontalAlignment = TextAlignmentType.Center;//文字居中
  3365. style_dataYellow.VerticalAlignment = TextAlignmentType.Center;
  3366. style_dataYellow.Font.Name = "微软雅黑";//文字字体
  3367. style_dataYellow.Font.Size = 12;//文字大小
  3368. style_dataYellow.IsLocked = false;//单元格解锁
  3369. style_dataYellow.Font.IsBold = false;//粗体
  3370. style_dataYellow.ForegroundColor = Color.FromArgb(255, 242, 204);
  3371. style_dataYellow.Pattern = BackgroundType.Solid;
  3372. style_dataYellow.Font.Color = Color.FromArgb(0, 0, 0);
  3373. style_dataYellow.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
  3374. style_dataYellow.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
  3375. style_dataYellow.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
  3376. style_dataYellow.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
  3377. int rowIndex = 4;
  3378. foreach (var d in dataList)
  3379. {
  3380. //内容
  3381. string typeStr = d.PriceDetailTypeStr + d.PriceName;
  3382. cells["B" + rowIndex.ToString()].PutValue(d.PriceTypeStr);
  3383. cells["C" + rowIndex.ToString()].PutValue(d.PriceDtStr);
  3384. cells["D" + rowIndex.ToString()].PutValue(typeStr);
  3385. cells["E" + rowIndex.ToString()].PutValue(d.Price.ToString("#0.00"));
  3386. cells["F" + rowIndex.ToString()].PutValue(d.PriceCount);
  3387. cells["G" + rowIndex.ToString()].PutValue(d.Currency);
  3388. cells["H" + rowIndex.ToString()].PutValue(d.PriceSum.ToString("#0.00"));
  3389. cells["K" + rowIndex.ToString()].PutValue(d.Remark);
  3390. //样式
  3391. cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
  3392. cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
  3393. cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
  3394. cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3395. cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3396. cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3397. cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3398. cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3399. cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3400. cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
  3401. //公式
  3402. cells["H" + rowIndex.ToString()].Formula = string.Format(@"E{0}*F{0}", rowIndex);
  3403. cells["J" + rowIndex.ToString()].Formula = string.Format(@"H{0}*I{0}", rowIndex);
  3404. cells.SetRowHeight(rowIndex - 1, 25);
  3405. rowIndex++;
  3406. }
  3407. cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
  3408. cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
  3409. cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
  3410. cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3411. cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3412. cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3413. cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3414. cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3415. cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3416. cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
  3417. rowIndex++;
  3418. cells["B" + rowIndex.ToString()].SetStyle(style_dataCol);
  3419. cells["C" + rowIndex.ToString()].SetStyle(style_dataCol);
  3420. cells["D" + rowIndex.ToString()].SetStyle(style_dataCol);
  3421. cells["E" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3422. cells["F" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3423. cells["G" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3424. cells["H" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3425. cells["I" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3426. cells["J" + rowIndex.ToString()].SetStyle(style_dataBlue);
  3427. cells["K" + rowIndex.ToString()].SetStyle(style_dataYellow);
  3428. rowIndex = 3;
  3429. int tempPriceType = 0;
  3430. foreach (var c in dataList)
  3431. {
  3432. if (tempPriceType == c.PriceType)
  3433. {
  3434. continue;
  3435. }
  3436. tempPriceType = c.PriceType;
  3437. int _rowCount = countList.First(s => s.PriceType == tempPriceType).DataCount;
  3438. cells.Merge(rowIndex, 1, _rowCount, 1);
  3439. Aspose.Cells.Range tempRange = cells.CreateRange(rowIndex, 1, _rowCount, 1);
  3440. rowIndex += _rowCount;
  3441. }
  3442. rowIndex = 4 + dataList.Count;
  3443. cells["D" + rowIndex.ToString()].PutValue("合计");
  3444. cells["J" + rowIndex.ToString()].Formula = string.Format(@"SUM(J4,J{0})", rowIndex - 1);
  3445. cells.SetRowHeight(rowIndex - 1, 25);
  3446. rowIndex++;
  3447. cells["D" + rowIndex.ToString()].PutValue("服务费10%开票税金8%");
  3448. cells["J" + rowIndex.ToString()].Formula = string.Format(@"J{0}*1.1*1.08", rowIndex - 1);
  3449. cells.SetRowHeight(rowIndex - 1, 25);
  3450. #endregion
  3451. #region IO
  3452. System.IO.MemoryStream ms = workbook.SaveToStream();//生成数据流
  3453. string fileName = ("GroupExtraCost/超支费用(" + cellValue_Header + ").xlsx");
  3454. byte[] bt = ms.ToArray();
  3455. workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  3456. #endregion
  3457. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  3458. return Ok(JsonView(true, "成功", new { url = rst }));
  3459. }
  3460. /// <summary>
  3461. /// 超支费用Excel导出
  3462. /// </summary>
  3463. /// <param name="dto"></param>
  3464. /// <returns></returns>
  3465. [HttpPost]
  3466. public IActionResult ExportOverspendExcel(Fin_GroupExtraCostExcelDto dto)
  3467. {
  3468. var jw = JsonView(false);
  3469. var grp_DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.diId && x.IsDel == 0);
  3470. if (grp_DelegationInfo == null)
  3471. {
  3472. return Ok(JsonView(false, "团组信息有误!"));
  3473. }
  3474. Dictionary<int, int> dicSoure = new Dictionary<int, int>()
  3475. {
  3476. {1077,1074 },
  3477. {1078,1075 },
  3478. {1079,1076 }
  3479. };
  3480. Dictionary<int, int> mealsDic = new Dictionary<int, int>()
  3481. {
  3482. {988,1074},
  3483. {93,1075},
  3484. {989,1076},
  3485. };
  3486. var checkBoxDataArr = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 17).ToList();
  3487. var CurrDataArr = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToList();
  3488. var joinTable = _sqlSugar.Queryable<Fin_GroupExtraCost, Grp_CreditCardPayment, Sys_SetData, Grp_NationalTravelFee ,
  3489. Fin_LocalGuideRelevancyOverspend , Grp_CarTouristGuideGroundReservations, Sys_SetData,Grp_DelegationInfo>(
  3490. (f, c, s, g, r ,l, s1,i) => new JoinQueryInfos(
  3491. JoinType.Left, f.Id == c.CId && c.CTable == 1015 && c.IsDel == 0,
  3492. JoinType.Left, c.PaymentCurrency == s.Id && s.IsDel == 0,
  3493. JoinType.Left, g.IsDel == 0 && g.Id == f.Area,
  3494. JoinType.Left, f.Id == r.OverspendId && r.IsDel == 0,
  3495. JoinType.Left, l.Id == r.LocalGuideId && l.IsDel == 0,
  3496. JoinType.Left, s1.Id == l.toCurr && s1.IsDel == 0,
  3497. JoinType.Left, i.Id == l.DiId && i.IsDel == 0
  3498. ))
  3499. .Where((f, c, s, g) => f.IsDel == 0 && f.DiId == dto.diId)
  3500. .Select((f, c, s, g, r, l,s1,i) => new
  3501. {
  3502. c.PaymentCurrency,
  3503. c.DayRate,
  3504. PaymentCurrencyStr = s.Name,
  3505. f.PriceName,
  3506. f.Remark,
  3507. f.PriceCount,
  3508. Price = f.Price * f.Coefficient,
  3509. c.PayMoney,
  3510. RMBPrice = c.RMBPrice * f.Coefficient,
  3511. Offer = c.RMBPrice * f.PriceCount * f.Coefficient,
  3512. c.CTable,
  3513. f.PriceDetailType,
  3514. Area = g.Country ?? "未选择地区!",
  3515. l.toCurr,
  3516. l.Rate,
  3517. toCurrStr = s1.Name,
  3518. g.FoodCost,
  3519. CarParentId = l.Id,
  3520. f.PriceDt,
  3521. i.VisitPNumber,
  3522. f.DiId,
  3523. f.PriceCurrency
  3524. })
  3525. .ToList()
  3526. .Select(x =>
  3527. {
  3528. var costPirce = x.Price;
  3529. decimal costRMBPrice = x.RMBPrice;
  3530. decimal costDayRate = x.DayRate;
  3531. string remake = x.Remark;
  3532. if (x.VisitPNumber > 0 && x.PriceDetailType != 1088)
  3533. {
  3534. decimal.TryParse(x.FoodCost, out decimal cost);
  3535. cost /= 2;
  3536. decimal oldPrice = costPirce;
  3537. costPirce *= x.Rate; //转换币种
  3538. if (x.toCurr != x.PaymentCurrency)
  3539. {
  3540. var rate = _setDataRep.PostCurrencyByDiid(x.DiId, 1015, x.toCurr).Result;
  3541. if (rate.Code == 0)
  3542. {
  3543. var rateData = rate.Data as CurrencyInfo;
  3544. if (rateData != null)
  3545. {
  3546. costDayRate = rateData.Rate;
  3547. }
  3548. }
  3549. }
  3550. if (dicSoure.Keys.Contains(x.PriceDetailType))
  3551. {
  3552. var CarCenter = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(x1 => x1.CTGGRId == x.CarParentId && x1.IsDel == 0
  3553. && x1.SId == mealsDic.First(x2 => x2.Value == dicSoure[x.PriceDetailType]).Key ).ToList().First(x1=> (DateTime.Compare(x1.DatePrice.ObjToDate(), x.PriceDt) == 0));
  3554. costPirce += (CarCenter.Price * CarCenter.Count * x.Rate);
  3555. oldPrice += (CarCenter.Price * CarCenter.Count);
  3556. var costResultPirce = costPirce - x.VisitPNumber * cost;
  3557. costResultPirce = Convert.ToInt32(Math.Round(costResultPirce));
  3558. var findCheck = checkBoxDataArr.Find(s => s.Id == CarCenter.SId);
  3559. if (x.toCurr != x.PaymentCurrency)
  3560. {
  3561. remake += $"{x.PriceDt.ToString("M/d")} {findCheck?.Name} {x.PaymentCurrencyStr} {(int)Math.Round(oldPrice)}( 折算{x.toCurrStr} {(int)Math.Round(costPirce)}) - 财政{cost} * {x.VisitPNumber} = {x.toCurrStr}{costResultPirce}";
  3562. }
  3563. else
  3564. {
  3565. remake += $"{x.PriceDt.ToString("M/d")} {findCheck?.Name}{x.PaymentCurrencyStr} {(int)Math.Round(costPirce)} - 财政{cost} * {x.VisitPNumber} = {x.PaymentCurrencyStr}{costResultPirce}";
  3566. }
  3567. costPirce = costResultPirce;
  3568. }
  3569. else
  3570. {
  3571. costPirce = Convert.ToInt32(Math.Round(costPirce));
  3572. }
  3573. costRMBPrice = Convert.ToInt32(Math.Round(costPirce * costDayRate));
  3574. }
  3575. return new
  3576. {
  3577. x.PaymentCurrency,
  3578. DayRate = costDayRate,
  3579. x.PaymentCurrencyStr,
  3580. x.PriceName,
  3581. Remark = remake,
  3582. x.PriceCount,
  3583. Price = costPirce,
  3584. x.PayMoney,
  3585. RMBPrice = costRMBPrice,
  3586. Offer = costRMBPrice * x.PriceCount,
  3587. x.CTable,
  3588. x.PriceDetailType,
  3589. x.Area,
  3590. x.toCurr,
  3591. x.toCurrStr,
  3592. ItemPrice = costPirce * x.PriceCount,
  3593. };
  3594. })
  3595. .ToList();
  3596. var PriceDetailTypeArr = new int[] { 1088 , 1074, 1075, 1076 };
  3597. var whereArr = joinTable.Where(x => PriceDetailTypeArr.Contains(x.PriceDetailType)).ToList();
  3598. _ = joinTable.RemoveAll(x => PriceDetailTypeArr.Contains(x.PriceDetailType));
  3599. foreach (var item in whereArr)
  3600. {
  3601. joinTable.Insert(0, item);
  3602. }
  3603. var dicClounm = new Dictionary<int, string>()
  3604. {
  3605. { 0,"Area" },
  3606. { 1,"PriceName" },
  3607. { 2,"Remark" },
  3608. { 3,"PriceCount" },
  3609. { 4,"Price" },
  3610. { 5,"ItemPrice" },
  3611. { 6,"DayRate" },
  3612. { 7,"Offer" },
  3613. };
  3614. var rowStartIndex = 2;
  3615. string filePath = AppSettingsHelper.Get("ExcelBasePath") + "\\Template\\超支费用表.xlsx";
  3616. IWorkbook workbook = new XSSFWorkbook(new FileStream(filePath, FileMode.Open, FileAccess.Read));
  3617. ISheet sheet = workbook.GetSheetAt(0);
  3618. var initStyleRow = sheet.GetRow(2);
  3619. var clounmCount = dicClounm.Count;
  3620. Action cloneRowFn = () =>
  3621. {
  3622. rowStartIndex++;
  3623. var cloneRow = sheet.CreateRow(rowStartIndex);
  3624. // 复制样式
  3625. for (int i = initStyleRow.FirstCellNum; i < initStyleRow.LastCellNum; i++)
  3626. {
  3627. ICell sourceCell = initStyleRow.GetCell(i);
  3628. ICell targetCell = cloneRow.GetCell(i) ?? cloneRow.CreateCell(i);
  3629. // 确保单元格存在样式
  3630. if (sourceCell.CellStyle != null)
  3631. {
  3632. targetCell.CellStyle = sourceCell.CellStyle;
  3633. }
  3634. }
  3635. };
  3636. sheet.GetRow(0).GetCell(0).SetCellValue($"{grp_DelegationInfo.TeamName}—超支费用");
  3637. foreach (var item in joinTable)
  3638. {
  3639. for (int i = 0; i < clounmCount; i++)
  3640. {
  3641. string property = dicClounm[i];
  3642. string value = item.GetType()!.GetProperty(property)!.GetValue(item)?.ToString() ?? "";
  3643. sheet.GetRow(rowStartIndex).GetCell(i).SetCellValue(value);
  3644. }
  3645. cloneRowFn();
  3646. }
  3647. sheet.GetRow(rowStartIndex).GetCell(2).SetCellValue($"小计:");
  3648. sheet.GetRow(rowStartIndex).GetCell(3).SetCellValue($"{joinTable.Sum(x=>x.RMBPrice)}元");
  3649. var path = $"GroupExtraCost/{grp_DelegationInfo.TeamName}_超支费用.xlsx";
  3650. using (var stream = new MemoryStream())
  3651. {
  3652. workbook.Write(stream, true);
  3653. stream.Flush();
  3654. stream.Seek(0, SeekOrigin.Begin);
  3655. var pathinfo = AppSettingsHelper.Get("ExcelBasePath") + path;
  3656. if (System.IO.File.Exists(pathinfo))
  3657. {
  3658. System.IO.File.Delete(pathinfo);
  3659. }
  3660. stream.SaveToFile(AppSettingsHelper.Get("ExcelBasePath") + path);
  3661. }
  3662. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + path;
  3663. jw = JsonView(true, "成功", new { url = rst });
  3664. return Ok(jw);
  3665. }
  3666. /// <summary>
  3667. /// 获取超支系数配置
  3668. /// </summary>
  3669. /// <returns></returns>
  3670. [HttpPost]
  3671. public IActionResult QueryCoefficientConfig()
  3672. {
  3673. var arr = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.STid == 80 && x.IsDel == 0).ToList();
  3674. var carCoefficient = new int[] { 1050 }; //2.4
  3675. var menpiaoCoefficient = new int[] { 1086 }; // 1.2
  3676. var airCoefficient = new int[] { 1035, 1036 }; // 2.0
  3677. var HotelCoefficient = new int[] { 1044, 1045, 1046, 1041, 1042, 1043, 1038 }; // 1.5
  3678. var fanyiCoefficient = new int[] { 1087 }; // 1.5
  3679. var resultArr = new
  3680. ArrayList();
  3681. foreach (var item in arr)
  3682. {
  3683. var a = new { coefficient = 1M, id = 0 };
  3684. if (carCoefficient.Contains(item.Id))
  3685. {
  3686. a = a with
  3687. {
  3688. coefficient = 2.4M,
  3689. id = item.Id
  3690. };
  3691. }
  3692. else if (menpiaoCoefficient.Contains(item.Id))
  3693. {
  3694. a = a with
  3695. {
  3696. coefficient = 1.2M,
  3697. id = item.Id
  3698. };
  3699. }
  3700. else if (airCoefficient.Contains(item.Id))
  3701. {
  3702. a = a with
  3703. {
  3704. coefficient = 2.0M,
  3705. id = item.Id
  3706. };
  3707. }
  3708. else if (HotelCoefficient.Contains(item.Id))
  3709. {
  3710. a = a with
  3711. {
  3712. coefficient = 1.5M,
  3713. id = item.Id
  3714. };
  3715. }
  3716. else if (fanyiCoefficient.Contains(item.Id))
  3717. {
  3718. a = a with
  3719. {
  3720. coefficient = 1.5M,
  3721. id = item.Id
  3722. };
  3723. }
  3724. else
  3725. {
  3726. a = a with
  3727. {
  3728. coefficient = 1M,
  3729. id = item.Id
  3730. };
  3731. }
  3732. resultArr.Add(a);
  3733. }
  3734. return Ok(JsonView(true, "获取成功!", resultArr));
  3735. }
  3736. #endregion
  3737. #region 信用卡对账
  3738. /// <summary>
  3739. ///将指定的Excel的文件转换成DataTable (Excel的第一个sheet)
  3740. /// </summary>
  3741. /// <param name="fullFielPath">文件的绝对路径</param>
  3742. /// <returns></returns>
  3743. private DataTable WorksheetToTable(string fullFielPath, string sheetName = null)
  3744. {
  3745. //如果是“EPPlus”,需要指定LicenseContext。
  3746. //EPPlus.Core 不需要指定。
  3747. ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
  3748. FileInfo existingFile = new FileInfo(fullFielPath);
  3749. ExcelPackage package = new ExcelPackage(existingFile);
  3750. ExcelWorksheet worksheet = null;
  3751. if (string.IsNullOrEmpty(sheetName))
  3752. {
  3753. //不传入 sheetName 默认取第1个sheet。
  3754. //EPPlus 索引是0
  3755. //EPPlus.Core 索引是1
  3756. worksheet = package.Workbook.Worksheets[0];
  3757. }
  3758. else
  3759. {
  3760. worksheet = package.Workbook.Worksheets[sheetName];
  3761. }
  3762. if (worksheet == null)
  3763. throw new Exception("指定的sheetName不存在");
  3764. return WorksheetToTable(worksheet);
  3765. }
  3766. /// <summary>
  3767. /// 将worksheet转成datatable
  3768. /// </summary>
  3769. /// <param name="worksheet">待处理的worksheet</param>
  3770. /// <returns>返回处理后的datatable</returns>
  3771. private DataTable WorksheetToTable(ExcelWorksheet worksheet)
  3772. {
  3773. //获取worksheet的行数
  3774. int rows = worksheet.Dimension.End.Row;
  3775. //获取worksheet的列数
  3776. int cols = worksheet.Dimension.End.Column;
  3777. DataTable dt = new DataTable(worksheet.Name);
  3778. DataRow dr = null;
  3779. for (int i = 1; i <= rows; i++)
  3780. {
  3781. if (i > 1)
  3782. dr = dt.Rows.Add();
  3783. for (int j = 1; j <= cols; j++)
  3784. {
  3785. //默认将第一行设置为datatable的标题
  3786. if (i == 1)
  3787. dt.Columns.Add(GetString(worksheet.Cells[i, j].Value));
  3788. //剩下的写入datatable
  3789. else
  3790. dr[j - 1] = GetString(worksheet.Cells[i, j].Value);
  3791. }
  3792. }
  3793. return dt;
  3794. }
  3795. private string GetString(object obj)
  3796. {
  3797. if (obj == null)
  3798. return "";
  3799. return obj.ToString();
  3800. }
  3801. private DataTable ExcelFileToDataTable(IFormFile file)
  3802. {
  3803. DataTable dtTest = null;
  3804. using (var stream = new MemoryStream())
  3805. {
  3806. file.CopyTo(stream);
  3807. using (var package = new ExcelPackage(stream))
  3808. {
  3809. ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
  3810. ExcelWorksheet worksheet = package.Workbook.Worksheets[0];
  3811. dtTest = WorksheetToTable(worksheet);
  3812. }
  3813. }
  3814. return dtTest;
  3815. }
  3816. /// <summary>
  3817. /// 信用卡对账
  3818. /// </summary>
  3819. /// <param name="file"></param>
  3820. /// <param name="cardType"></param>
  3821. /// <param name="beginDt"></param>
  3822. /// <param name="endDt"></param>
  3823. /// <returns></returns>
  3824. [HttpPost]
  3825. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3826. public async Task<IActionResult> PostCreditCardBill(IFormFile file, int cardType, string beginDt, string endDt)
  3827. {
  3828. if (file == null || file.Length < 1)
  3829. {
  3830. return Ok(JsonView(false, "请上传文件!"));
  3831. }
  3832. string fileName = file.FileName;
  3833. if (!fileName.EndsWith(".xlsx") && !fileName.EndsWith(".xls"))
  3834. {
  3835. return Ok(JsonView(false, "请上传Excel文件!"));
  3836. }
  3837. if (cardType < 1) return Ok(JsonView(false, "请传入有效的卡类型!"));
  3838. if (string.IsNullOrEmpty(beginDt) || string.IsNullOrEmpty(endDt)) return Ok(JsonView(false, "请输入开始/结束日期!"));
  3839. var beginValid = DateTime.TryParse(beginDt, out _);
  3840. var endValid = DateTime.TryParse(endDt, out _);
  3841. if (!beginValid || !endValid) return Ok(JsonView(false, "请输入正确的日期格式"));
  3842. //读取ExcelFile
  3843. DataTable dt = ExcelFileToDataTable(file);
  3844. dt.TableName = "TB";
  3845. if (dt == null)
  3846. {
  3847. return Ok(JsonView(false, $"您上传的Excel工作表没有内容,请检查!!!"));
  3848. }
  3849. //信用卡信息
  3850. string sql = string.Format($"Select * From Grp_CreditCardPayment Where Isdel = 0 And CTDId = {cardType} And ConsumptionDate between '{beginDt}' and '{endDt}' ");
  3851. var List_ccp = await _sqlSugar.SqlQueryable<Grp_CreditCardPayment>(sql).ToListAsync();
  3852. if (List_ccp.Count < 1)
  3853. {
  3854. return Ok(JsonView(false, $"未查询到 {beginDt} 至 {endDt} 信用卡账单信息!!!!"));
  3855. }
  3856. //资源信息
  3857. var delegationInfos = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0).ToList();
  3858. var users = _sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0).ToList();
  3859. string url = string.Empty;
  3860. try
  3861. {
  3862. /*
  3863. * 卡类型
  3864. * 74 美元卡 1
  3865. * 75 欧元卡 1
  3866. * 86 招行卡 1
  3867. * 346 中信卡 1
  3868. * 363 交行卡 1
  3869. *
  3870. */
  3871. var ids = new List<int>();
  3872. if (cardType == 74) //美元卡
  3873. {
  3874. var AirGroupReuslt = List_ccp.Where(x => x.CTable == 85).GroupBy(x => x.DIId).ToList();
  3875. if (AirGroupReuslt != null && AirGroupReuslt.Count > 0)
  3876. {
  3877. foreach (var item in AirGroupReuslt)
  3878. {
  3879. if (item.Count() > 1)
  3880. {
  3881. var obj = item.FirstOrDefault();
  3882. obj.RMBPrice = item.Sum(x => x.PayMoney);//合计币种金额
  3883. obj.Remark = "团组机票总价(虚拟)";
  3884. List_ccp.Add(obj);
  3885. }
  3886. }
  3887. }
  3888. //dt.AcceptChanges(); //提交
  3889. //修改table列名
  3890. dt.Columns[0].ColumnName = "accountType"; // 账户类型
  3891. dt.Columns[1].ColumnName = "tradeDate"; //交易日期
  3892. dt.Columns[2].ColumnName = "BillingDate"; // 记账日期
  3893. dt.Columns[3].ColumnName = "CardNo"; // 卡号
  3894. dt.Columns[4].ColumnName = "deposit"; // 存入金额
  3895. dt.Columns[5].ColumnName = "SpendingAmount"; // 支出金额
  3896. dt.Columns[6].ColumnName = "TransactionDescription"; // 交易描述
  3897. dt.Columns[7].ColumnName = "TeamRemark"; // 团组备注描述
  3898. dt.Columns[8].ColumnName = "Handlers"; // 经手人
  3899. dt.Columns[9].ColumnName = "State"; // 状态
  3900. //删除第一行数据
  3901. if (dt.Rows.Count > 0)
  3902. {
  3903. string accountType = dt.Rows[0]["accountType"].ToString();
  3904. if (dt.Rows[0]["accountType"].ToString().Equals("账户类型"))
  3905. {
  3906. dt.Rows[0].Delete();
  3907. dt.AcceptChanges(); //提交
  3908. }
  3909. }
  3910. foreach (DataRow item in dt.Rows)
  3911. {
  3912. #region 匹配的金额
  3913. decimal ExcelAmount = 0.00M;
  3914. decimal deposit = 0.00M;
  3915. if (!string.IsNullOrEmpty(item["SpendingAmount"].ToString()))
  3916. {
  3917. var isParase = decimal.TryParse(item["SpendingAmount"].ToString(), out ExcelAmount);
  3918. if (isParase)
  3919. {
  3920. var CList = List_ccp.FindAll(x => x.PayMoney == ExcelAmount);
  3921. if (CList != null && CList.Count > 0)
  3922. {
  3923. item["TeamRemark"] = delegationInfos.Find(it => it.Id == CList.First().DIId)?.TeamName;
  3924. item["Handlers"] = users.Find(it => it.Id == CList.First().CreateUserId)?.CnName;
  3925. item["State"] = 1;
  3926. }
  3927. }
  3928. }
  3929. if (!string.IsNullOrEmpty(item["deposit"].ToString()))
  3930. {
  3931. var isParse = decimal.TryParse(item["deposit"].ToString(), out deposit);
  3932. if (isParse)
  3933. {
  3934. var CList = List_ccp.FindAll(x => x.PayMoney == deposit);
  3935. if (CList != null && CList.Count > 0)
  3936. {
  3937. item["TeamRemark"] = delegationInfos.Find(it => it.Id == CList.First().DIId)?.TeamName;
  3938. item["Handlers"] = users.Find(it => it.Id == CList.First().CreateUserId)?.CnName;
  3939. item["State"] = 1;
  3940. }
  3941. }
  3942. }
  3943. #endregion
  3944. //交易描述
  3945. if (!string.IsNullOrEmpty(item["TransactionDescription"].ToString()))
  3946. {
  3947. string TransactionDescription = item["TransactionDescription"].ToString();
  3948. var startIndex = TransactionDescription.LastIndexOf("[");
  3949. var endIndex = TransactionDescription.LastIndexOf("]");
  3950. if (startIndex != -1 && endIndex != -1)
  3951. {
  3952. var moenyList = TransactionDescription.Substring(startIndex + 1, endIndex - startIndex - 1).Split(' ').
  3953. Where(x => !string.IsNullOrEmpty(x)).ToList();
  3954. decimal money = 0.00M;
  3955. foreach (var itemMoeny in moenyList)
  3956. {
  3957. if (itemMoeny.Contains('.'))
  3958. {
  3959. string itemMoenyStr = itemMoeny.Replace(",", string.Empty);
  3960. bool istrue = decimal.TryParse(itemMoenyStr, out money);
  3961. if (istrue)
  3962. {
  3963. var CList = List_ccp.FindAll(x => x.PayMoney == money);
  3964. if (CList != null && CList.Count > 0)
  3965. {
  3966. item["TeamRemark"] = delegationInfos.Find(it => it.Id == CList.First().DIId)?.TeamName;
  3967. item["Handlers"] = users.Find(it => it.Id == CList.First().CreateUserId)?.CnName;
  3968. item["State"] = 1;
  3969. }
  3970. }
  3971. }
  3972. }
  3973. }
  3974. }
  3975. }
  3976. string fileName1 = $"信用卡账单(美元卡){DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  3977. Dictionary<string, object> pairs = new Dictionary<string, object>();
  3978. List<DataTable> datas = new List<DataTable>();
  3979. datas.Add(dt);
  3980. url = AsposeHelper.ExpertExcelToModel("信用卡对账模板-美元卡.xls", $"CreditCardBill", fileName1, pairs, datas);
  3981. }
  3982. else if (cardType == 75) //欧元卡
  3983. {
  3984. if (dt.Rows.Count > 0)
  3985. {
  3986. string accountType = dt.Rows[0][0].ToString();
  3987. if (accountType.Equals("账户类型"))
  3988. {
  3989. dt.Rows[0].Delete();
  3990. dt.AcceptChanges(); //提交
  3991. }
  3992. }
  3993. //dt.Columns[0].ColumnName = "All";
  3994. DataTable dt1 = new DataTable();
  3995. dt1.TableName = "TB";
  3996. dt1.Columns.Add("TradingDate", Type.GetType("System.String"));//交易日期
  3997. dt1.Columns.Add("TallyDate", Type.GetType("System.String")); //记账日期
  3998. dt1.Columns.Add("TradindDesc", Type.GetType("System.String"));//交易描述
  3999. dt1.Columns.Add("TradindMoney", Type.GetType("System.String"));//交易币种/金额
  4000. dt1.Columns.Add("ClearindMoney", Type.GetType("System.String"));// 清算币种/金额
  4001. dt1.Columns.Add("TeamRemark", Type.GetType("System.String")); //团组备注描述
  4002. dt1.Columns.Add("Handlers", Type.GetType("System.String")); //经手人
  4003. dt1.Columns.Add("State", Type.GetType("System.String")); //状态
  4004. for (int i = 0; i < dt.Rows.Count; i++)
  4005. {
  4006. string[] str = dt.Rows[i]["All"].ToString().Split(' ');
  4007. //string[] str = dt.Rows[i];
  4008. DataRow dr = dt1.NewRow();
  4009. dr["TradingDate"] = str[0].ToString();
  4010. dr["TallyDate"] = str[1].ToString();
  4011. dr["TradindDesc"] = str[2].ToString() + " " + str[3].ToString();
  4012. dr["TradindMoney"] = str[4].ToString() + " " + str[5].ToString();
  4013. dr["ClearindMoney"] = str[6].ToString() + " " + str[7].ToString();
  4014. dt1.Rows.Add(dr);
  4015. }
  4016. foreach (DataRow item in dt1.Rows)
  4017. {
  4018. for (int i = 0; i < List_ccp.Count; i++)
  4019. {
  4020. DateTime dtTime1 = Convert.ToDateTime(item["TradingDate"].ToString() == "" ? DateTime.Now.ToString("MM/dd") : item["TradingDate"].ToString()); //交易日期
  4021. string USDPrice = item["TradindMoney"].ToString(); //支出金额
  4022. USDPrice = USDPrice.Split(' ')[1].Trim(); //替换掉非数字
  4023. //USDPrice = USDPrice.Split('/')[1];
  4024. // 经手人 and excel行状态
  4025. if (!string.IsNullOrEmpty(List_ccp[i].ConsumptionDate) && !string.IsNullOrEmpty(USDPrice))
  4026. {
  4027. DateTime dtTime2 = Convert.ToDateTime(List_ccp[i].ConsumptionDate.ToString() == "" ? DateTime.Now.ToString("MM/dd") : List_ccp[i].ConsumptionDate.ToString());
  4028. float price1 = float.Parse(USDPrice);
  4029. float price2 = float.Parse(List_ccp[i].PayMoney.ToString("F2"));
  4030. if (dtTime1 == dtTime2 && price1 == price2)
  4031. {
  4032. item["TeamRemark"] = delegationInfos.Find(it => it.Id == List_ccp[i].DIId)?.TeamName;
  4033. item["Handlers"] = users.Find(it => it.Id == List_ccp[i].CreateUserId)?.CnName;
  4034. item["State"] = "1";
  4035. i = List_ccp.Count - 1;
  4036. }
  4037. else item["State"] = "0";
  4038. }
  4039. else item["State"] = "0";
  4040. }
  4041. if (item["TradindDesc"].ToString().Contains("财付通"))
  4042. item["State"] = "2";
  4043. else if (item["TradindDesc"].ToString().Contains("京东"))
  4044. item["State"] = "2";
  4045. else if (item["TradindDesc"].ToString().Contains("微信支付"))
  4046. item["State"] = "2";
  4047. else if (item["TradindDesc"].ToString().Contains("淘宝"))
  4048. item["State"] = "2";
  4049. }
  4050. string fileName1 = $"信用卡账单(欧元卡){DateTime.Now.ToString("yyyy.MM.dd")}.xls";
  4051. Dictionary<string, object> pairs = new Dictionary<string, object>();
  4052. List<DataTable> datas = new List<DataTable>();
  4053. datas.Add(dt);
  4054. url = AsposeHelper.ExpertExcelToModel("信用卡对账模板-欧元卡.xls", "TB", fileName1, pairs, datas);
  4055. }
  4056. else if (cardType == 86) //招行卡
  4057. {
  4058. var AirGroupReuslt1 = List_ccp.Where(x => x.CTable == 85).GroupBy(x => x.DIId).ToList();
  4059. if (AirGroupReuslt1 != null && AirGroupReuslt1.Count > 0)
  4060. {
  4061. foreach (var item in AirGroupReuslt1)
  4062. {
  4063. if (item.Count() > 1)
  4064. {
  4065. var di = delegationInfos.Find(it => it.Id == item.Key);
  4066. var obj = item.FirstOrDefault();
  4067. obj.Remark = "团组机票总价";
  4068. if (di != null)
  4069. {
  4070. obj.Remark = "团组机票总价(" + di.TeamName + ")";
  4071. }
  4072. obj.RMBPrice = item.Sum(x => x.RMBPrice);//合计人民币
  4073. List_ccp.Add(obj);
  4074. }
  4075. }
  4076. }
  4077. //查询所有刷卡的团组
  4078. //将刷卡团组内刷卡金额的金额存入ccp_list
  4079. //将excel作比较
  4080. //机票刷卡记录
  4081. var AirListAndPayID = List_ccp.Where(x => x.CTable == 85 && x.PayDId == 72).Select(x => x.DIId).Distinct().ToList();
  4082. var AirData = _sqlSugar.Queryable<Grp_AirTicketReservations>().Where(it => AirListAndPayID.Contains(it.DIId) && it.PrePrice != it.Price).ToList();
  4083. foreach (var item in AirData)
  4084. {
  4085. var DBwhere = List_ccp.Find(x => x.PayMoney == item.PrePrice);
  4086. if (DBwhere == null)
  4087. {
  4088. List_ccp.Add(new Grp_CreditCardPayment
  4089. {
  4090. PayMoney = item.PrePrice,
  4091. DIId = item.DIId,
  4092. CreateUserId = item.CreateUserId,
  4093. Remark = "(机票单价价格)",
  4094. });
  4095. }
  4096. }
  4097. var HotelGroupReuslt = List_ccp.Where(x => x.CTable == 76).GroupBy(x => x.DIId).ToList();
  4098. if (HotelGroupReuslt != null && HotelGroupReuslt.Count > 0)
  4099. {
  4100. foreach (var item in HotelGroupReuslt)
  4101. {
  4102. if (item.Count() > 1)
  4103. {
  4104. var di = delegationInfos.Find(it => it.Id == item.Key);
  4105. var obj = item.FirstOrDefault();
  4106. obj.Remark = "团组酒店总价";
  4107. if (di != null)
  4108. {
  4109. obj.Remark = "团组酒店总价(" + di.TeamName + ")";
  4110. }
  4111. obj.RMBPrice = item.Sum(x => x.RMBPrice);//合计人民币
  4112. List_ccp.Add(obj);
  4113. }
  4114. }
  4115. }
  4116. #region
  4117. dt.Rows[0].Delete();//删除列名行
  4118. dt.AcceptChanges();
  4119. DataTable dt1 = new DataTable();
  4120. dt1.TableName = "TB";
  4121. dt1.Columns.Add("TradingDay", Type.GetType("System.String")); // 交易日
  4122. dt1.Columns.Add("TallyDay", Type.GetType("System.String")); // 记账日
  4123. dt1.Columns.Add("TransactionDesc", Type.GetType("System.String")); // 交易描述
  4124. dt1.Columns.Add("RMBMoney", Type.GetType("System.String")); // 人名币金额
  4125. dt1.Columns.Add("CardNo", Type.GetType("System.String")); // 卡号
  4126. dt1.Columns.Add("TradingMoney", Type.GetType("System.String")); // 交易地金额
  4127. dt1.Columns.Add("Currency", Type.GetType("System.String")); // 币种
  4128. dt1.Columns.Add("TeamRemark", Type.GetType("System.String")); //团组备注描述
  4129. dt1.Columns.Add("Handlers", Type.GetType("System.String")); //经手人
  4130. dt1.Columns.Add("State", Type.GetType("System.String")); //状态
  4131. for (int j = 0; j < dt.Rows.Count; j++)//遍历行
  4132. {
  4133. DataRow dr = dt1.NewRow(); //获取每一行的数据
  4134. dr["TradingDay"] = dt.Rows[j][0].ToString();
  4135. dr["TallyDay"] = dt.Rows[j][1].ToString();
  4136. dr["TransactionDesc"] = dt.Rows[j][2].ToString();
  4137. dr["RMBMoney"] = dt.Rows[j][3].ToString();
  4138. dr["CardNo"] = dt.Rows[j][4].ToString();
  4139. string currency = "CN";
  4140. string money = dt.Rows[j][5].ToString();
  4141. if (money.Contains('('))
  4142. {
  4143. string[] strs = money.Split('(');
  4144. money = strs[0];
  4145. currency = strs[1].Replace(")", "");
  4146. }
  4147. dr["TradingMoney"] = money;
  4148. dr["Currency"] = currency;
  4149. if (string.IsNullOrEmpty(money))
  4150. {
  4151. continue;
  4152. }
  4153. dt1.Rows.Add(dr);
  4154. }
  4155. //datatable 排序
  4156. dt1.DefaultView.Sort = "TradingDay asc";
  4157. dt1 = dt1.DefaultView.ToTable();
  4158. foreach (DataRow item in dt1.Rows)
  4159. {
  4160. if (item["TradingDay"] == "" && item["RMBMoney"] == "")
  4161. {
  4162. continue;
  4163. }
  4164. //excel获取交易日期
  4165. string ExcelDt = string.Empty;
  4166. //C表交易日期
  4167. string DBDt = string.Empty;
  4168. //excel交易的金额
  4169. decimal TradingMoney = decimal.Parse(item["TradingMoney"].ToString());
  4170. if (item["TradingDay"] != null)
  4171. {
  4172. ExcelDt = DateTime.Parse(item["TradingDay"].ToString()).ToString("MMdd");
  4173. }
  4174. //加一获取金额区间
  4175. decimal MaxTradingMoney = TradingMoney + 1;
  4176. decimal MinTradingMoney = TradingMoney - 1;
  4177. //匹配C表金额相等的值
  4178. var CList = List_ccp.FindAll(x => x.PayMoney < MaxTradingMoney && x.PayMoney > MinTradingMoney);
  4179. if (CList != null && CList.Count > 0)
  4180. {
  4181. #region 日期匹配
  4182. foreach (var Citem in CList)
  4183. {
  4184. if (!string.IsNullOrWhiteSpace(Citem.ConsumptionDate))
  4185. {
  4186. DBDt = DateTime.Parse(Citem.ConsumptionDate).ToString("MMdd");
  4187. if (DBDt == ExcelDt)
  4188. {
  4189. item["TeamRemark"] = delegationInfos.Find(it => it.Id == Citem.DIId)?.TeamName;
  4190. item["Handlers"] = users.Find(it => it.Id == Citem.CreateUserId)?.CnName;
  4191. ids.Add(Citem.Id);
  4192. }
  4193. }
  4194. }
  4195. #endregion
  4196. }
  4197. if (item["TransactionDesc"].ToString().Contains("财付通"))
  4198. item["State"] = "2";
  4199. else if (item["TransactionDesc"].ToString().Contains("京东支付"))
  4200. item["State"] = "2";
  4201. else if (item["TransactionDesc"].ToString().Contains("微信支付"))
  4202. item["State"] = "2";
  4203. else if (item["TransactionDesc"].ToString().Contains("淘宝"))
  4204. item["State"] = "2";
  4205. else if (item["TransactionDesc"].ToString().Contains("支付宝"))
  4206. item["State"] = "2";
  4207. else if (item["TransactionDesc"].ToString().Contains("拼多多"))
  4208. item["State"] = "2";
  4209. else
  4210. item["State"] = "0";
  4211. if (!string.IsNullOrEmpty(item["TeamRemark"].ToString()) && !string.IsNullOrEmpty(item["Handlers"].ToString()))
  4212. item["State"] = "1";
  4213. }
  4214. //更改匹配项状态
  4215. if (ids.Count > 0)
  4216. {
  4217. var _CreditCardPayments = new List<Grp_CreditCardPayment>();
  4218. foreach (var item in ids)
  4219. {
  4220. _CreditCardPayments.Add(new Grp_CreditCardPayment() { Id = item, IsMatchCreditCard = 1.00M });
  4221. }
  4222. var updateStatus = _sqlSugar.Updateable<Grp_CreditCardPayment>(_CreditCardPayments)
  4223. .UpdateColumns(it => new { it.IsMatchCreditCard })
  4224. .Where(it => ids.Contains(it.Id))
  4225. .ExecuteCommand();
  4226. }
  4227. string fileName1 = $"信用卡账单(招行卡){DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  4228. Dictionary<string, object> pairs = new Dictionary<string, object>();
  4229. List<DataTable> datas = new List<DataTable>();
  4230. datas.Add(dt1);
  4231. url = AsposeHelper.ExpertExcelToModel("信用卡对账模板-招行卡.xls", "CreditCardBill", fileName1, pairs, datas);
  4232. #endregion
  4233. }
  4234. else if (cardType == 346) //中信卡
  4235. {
  4236. dt.Columns.Add("TeamRemark", Type.GetType("System.String")); //团组备注描述
  4237. dt.Columns.Add("Handlers", Type.GetType("System.String")); //经手人
  4238. dt.Columns.Add("State", Type.GetType("System.String")); //状态
  4239. //修改table列名
  4240. dt.Columns[0].ColumnName = "TransactionDesc"; // 交易描述
  4241. dt.Columns[1].ColumnName = "TradingCurrencyAndMoney"; // 交易币种和金额
  4242. dt.Columns[2].ColumnName = "TransactionDate"; // 交易日期
  4243. dt.Columns[3].ColumnName = "SettlementCurrencyAndMoney";// 结算币种和金额
  4244. dt.Columns[4].ColumnName = "BookedDate"; // 入账日期
  4245. foreach (DataRow item in dt.Rows)
  4246. {
  4247. for (int i = 0; i < List_ccp.Count; i++)
  4248. {
  4249. if (string.IsNullOrEmpty(item["TransactionDate"].ToString()))
  4250. break;
  4251. DateTime dtTime1 = Convert.ToDateTime(item["TransactionDate"].ToString()); //交易日期
  4252. string USDPrice = item["TradingCurrencyAndMoney"].ToString(); //支出金额
  4253. USDPrice = USDPrice.Split('/')[1];
  4254. //string USDPrice1 = USDPrice.ToString("0.00");
  4255. // 经手人 and excel行状态
  4256. if (!string.IsNullOrEmpty(List_ccp[i].ConsumptionDate) && !string.IsNullOrEmpty(USDPrice))
  4257. {
  4258. DateTime dtTime2 = Convert.ToDateTime(List_ccp[i].ConsumptionDate);
  4259. float price1 = float.Parse(USDPrice);
  4260. float price2 = float.Parse(List_ccp[i].PayMoney.ToString("F2"));
  4261. if (dtTime1 == dtTime2 && price1 == price2)
  4262. {
  4263. item["TeamRemark"] = delegationInfos.Find(it => it.Id == List_ccp[i].DIId)?.TeamName;
  4264. item["Handlers"] = users.Find(it => it.Id == List_ccp[i].CreateUserId)?.CnName;
  4265. item["State"] = "1";
  4266. i = List_ccp.Count - 1;
  4267. }
  4268. else
  4269. item["State"] = "0";
  4270. }
  4271. else
  4272. item["State"] = "0";
  4273. }
  4274. //判断是否是数字
  4275. //if (IsNumber(item["TradingCurrencyAndMoney"].ToString().Split('/')[1]) == false)
  4276. // item["State"] = "0";
  4277. if (item["TransactionDesc"].ToString().Contains("财付通"))
  4278. item["State"] = "2";
  4279. else if (item["TransactionDesc"].ToString().Contains("京东"))
  4280. item["State"] = "2";
  4281. else if (item["TransactionDesc"].ToString().Contains("微信支付"))
  4282. item["State"] = "2";
  4283. else if (item["TransactionDesc"].ToString().Contains("淘宝"))
  4284. item["State"] = "2";
  4285. }
  4286. #region DownExcel
  4287. string fileName1 = $"信用卡账单(中信卡){DateTime.Now.ToString("yyyy.MM.dd")}.xls";
  4288. Dictionary<string, object> pairs = new Dictionary<string, object>();
  4289. List<DataTable> datas = new List<DataTable>();
  4290. datas.Add(dt);
  4291. url = AsposeHelper.ExpertExcelToModel("信用卡对账模板-中信卡.xls", "TB", fileName1, pairs, datas);
  4292. #endregion
  4293. }
  4294. else if (cardType == 363) //交行卡
  4295. {
  4296. dt.Columns[0].ColumnName = "All";
  4297. DataTable dt1 = new DataTable();
  4298. dt1.Columns.Add("TradingDate", Type.GetType("System.String"));//交易日期
  4299. dt1.Columns.Add("TallyDate", Type.GetType("System.String")); //记账日期
  4300. dt1.Columns.Add("TradindDesc", Type.GetType("System.String"));//交易描述
  4301. dt1.Columns.Add("TradindMoney", Type.GetType("System.String"));//交易币种/金额
  4302. dt1.Columns.Add("ClearindMoney", Type.GetType("System.String"));// 清算币种/金额
  4303. dt1.Columns.Add("TeamRemark", Type.GetType("System.String")); //团组备注描述
  4304. dt1.Columns.Add("Handlers", Type.GetType("System.String")); //经手人
  4305. dt1.Columns.Add("State", Type.GetType("System.String")); //状态
  4306. for (int i = 0; i < dt.Rows.Count; i++)
  4307. {
  4308. string[] str = dt.Rows[i]["All"].ToString().Split(' ');
  4309. DataRow dr = dt1.NewRow();
  4310. dr["TradingDate"] = str[0].ToString();
  4311. dr["TallyDate"] = str[1].ToString();
  4312. dr["TradindDesc"] = str[2].ToString() + " " + str[3].ToString();
  4313. dr["TradindMoney"] = str[4].ToString() + " " + str[5].ToString();
  4314. dr["ClearindMoney"] = str[6].ToString() + " " + str[7].ToString();
  4315. dt1.Rows.Add(dr);
  4316. }
  4317. foreach (DataRow item in dt1.Rows)
  4318. {
  4319. for (int i = 0; i < List_ccp.Count; i++)
  4320. {
  4321. DateTime dtTime1 = Convert.ToDateTime(item["TradingDate"].ToString() == "" ? DateTime.Now.ToString("MM/dd") : item["TradingDate"].ToString()); //交易日期
  4322. string USDPrice = item["TradindMoney"].ToString(); //支出金额
  4323. USDPrice = USDPrice.Split(' ')[1].Trim(); //替换掉非数字
  4324. //USDPrice = USDPrice.Split('/')[1];
  4325. // 经手人 and excel行状态
  4326. if (!string.IsNullOrEmpty(List_ccp[i].ConsumptionDate) && !string.IsNullOrEmpty(USDPrice))
  4327. {
  4328. DateTime dtTime2 = Convert.ToDateTime(List_ccp[i].ConsumptionDate.ToString() == "" ? DateTime.Now.ToString("MM/dd") : List_ccp[i].ConsumptionDate.ToString());
  4329. float price1 = float.Parse(USDPrice);
  4330. float price2 = float.Parse(List_ccp[i].PayMoney.ToString("F2"));
  4331. if (dtTime1 == dtTime2 && price1 == price2)
  4332. {
  4333. item["TeamRemark"] = delegationInfos.Find(it => it.Id == List_ccp[i].DIId)?.TeamName;
  4334. item["Handlers"] = users.Find(it => it.Id == List_ccp[i].CreateUserId)?.CnName;
  4335. item["State"] = "1";
  4336. i = List_ccp.Count - 1;
  4337. }
  4338. else
  4339. item["State"] = "0";
  4340. }
  4341. else
  4342. item["State"] = "0";
  4343. }
  4344. if (item["TradindDesc"].ToString().Contains("财付通"))
  4345. item["State"] = "2";
  4346. else if (item["TradindDesc"].ToString().Contains("京东"))
  4347. item["State"] = "2";
  4348. else if (item["TradindDesc"].ToString().Contains("微信支付"))
  4349. item["State"] = "2";
  4350. else if (item["TradindDesc"].ToString().Contains("淘宝"))
  4351. item["State"] = "2";
  4352. }
  4353. string fileName1 = $"信用卡账单(交行卡){DateTime.Now.ToString("yyyy.MM.dd")}.xls";
  4354. Dictionary<string, object> pairs = new Dictionary<string, object>();
  4355. List<DataTable> datas = new List<DataTable>();
  4356. datas.Add(dt);
  4357. url = AsposeHelper.ExpertExcelToModel("信用卡对账模板-交行卡.xls", "TB", fileName1, pairs, datas);
  4358. }
  4359. }
  4360. catch (Exception ex)
  4361. {
  4362. return Ok(JsonView(false, $"匹配失败,{ex.Message}!"));
  4363. }
  4364. return Ok(JsonView(true, "操作成功", new { url = url }));
  4365. }
  4366. /// <summary>
  4367. /// 把数据从Excel装载到DataTable
  4368. /// </summary>
  4369. /// <param name="pathName">带路径的Excel文件名</param>
  4370. /// <param name="sheetName">工作表名</param>
  4371. /// <param name="tbContainer">将数据存入的DataTable</param>
  4372. /// <returns></returns>
  4373. public static DataTable ExcelToDataTable(string pathName, string sheetName)
  4374. {
  4375. DataTable tbContainer = new DataTable();
  4376. string strConn = string.Empty;
  4377. if (string.IsNullOrEmpty(sheetName)) { sheetName = "Sheet1"; }
  4378. FileInfo file = new FileInfo(pathName);
  4379. if (!file.Exists) { throw new Exception("文件不存在"); }
  4380. string extension = file.Extension;
  4381. switch (extension)
  4382. {
  4383. case ".xls":
  4384. strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathName + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
  4385. break;
  4386. case ".xlsx":
  4387. strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pathName + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1;'";
  4388. break;
  4389. default:
  4390. strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathName + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
  4391. break;
  4392. }
  4393. //链接Excel
  4394. OleDbConnection cnnxls = new OleDbConnection(strConn);
  4395. //读取Excel里面有 表Sheet1
  4396. System.Data.OleDb.OleDbDataAdapter oda = new System.Data.OleDb.OleDbDataAdapter(string.Format("select * from [{0}$]", sheetName), cnnxls);
  4397. DataSet ds = new DataSet();
  4398. //将Excel里面有表内容装载到内存表中!
  4399. oda.Fill(tbContainer);
  4400. return tbContainer;
  4401. }
  4402. #endregion
  4403. #region 提成计算
  4404. /// <summary>
  4405. /// 提成计算
  4406. /// </summary>
  4407. /// <param name="dto"></param>
  4408. /// <returns></returns>
  4409. [HttpPost]
  4410. public IActionResult ComputeRoyalties(ComputeRoyaltiesDto dto)
  4411. {
  4412. var jw = JsonView(false);
  4413. var userId = dto.UserId;
  4414. var user = _sqlSugar.Queryable<Sys_Users>().First(x=>x.Id == userId);
  4415. //jw.Data = System.Array.Empty<string>();
  4416. if (user == null)
  4417. {
  4418. jw.Msg = "暂无该用户!";
  4419. return Ok(jw);
  4420. }
  4421. if (!DateTime.TryParse(dto.StartDate,out DateTime StartDateTime))
  4422. {
  4423. jw.Msg = "开始时间格式有误!";
  4424. return Ok(jw);
  4425. }
  4426. if (!DateTime.TryParse(dto.EndDate, out DateTime EndDateTime))
  4427. {
  4428. jw.Msg = "结束时间格式有误!";
  4429. return Ok(jw);
  4430. }
  4431. if (DateTime.Compare(StartDateTime,EndDateTime) > 0)
  4432. {
  4433. jw.Msg = "开始时间大于结束时间!";
  4434. return Ok(jw);
  4435. }
  4436. //机票 职位表id 24
  4437. int[] AirTicket = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.JobPostId == 24).Select(x => x.Id).ToArray();
  4438. //酒店 职位表id 25
  4439. int[] Hotel = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.JobPostId == 25).Select(x => x.Id).ToArray();
  4440. //OP 职位表id 28
  4441. int [] OP = _sqlSugar.Queryable<Sys_Users>().Where(x=>x.IsDel == 0 && x.JobPostId == 28).Select(x=>x.Id).ToArray();
  4442. //商邀 职位表id 27
  4443. int [] Invitation = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.JobPostId == 27).Select(x => x.Id).ToArray();
  4444. //签证 职位表id 26
  4445. int[] Visa = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.JobPostId == 26 ).Select(x => x.Id).ToArray();
  4446. //主管职位
  4447. //string[] Manager = { "149", "283" };
  4448. List<ComputeRoyaltiesView> resultArr = new List<ComputeRoyaltiesView>();
  4449. var teamLv = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.STid == 56 && x.IsDel == 0).ToList();
  4450. var auditState = new int[] { 1 , 3 };
  4451. if (AirTicket.Contains(userId))
  4452. {
  4453. //提成方式:¥10/人×人数×段数(每个组团涉及的换机次数)
  4454. var listAir = _sqlSugar.Queryable<Grp_AirTicketReservations, Grp_DelegationInfo, Grp_CreditCardPayment>((x, a, b) => new
  4455. JoinQueryInfos(
  4456. JoinType.Left, a.Id == x.DIId ,
  4457. JoinType.Left, b.CTable == 85 && b.CId == x.Id )
  4458. ).Where((x, a, b) => x.IsDel == 0 && x.CreateUserId == userId && (b.IsAuditGM == 1 || b.IsAuditGM == 3)
  4459. && a.IsDel == 0 && a.VisitDate >= StartDateTime && a.VisitDate <= EndDateTime && b.IsDel == 0 && a.IsSure == 1 && auditState.Contains(b.IsAuditGM) )
  4460. .Select((x, a, b) => new
  4461. {
  4462. x.FlightsDescription,
  4463. a.Id,
  4464. a.TeamName,
  4465. a.VisitDate,
  4466. a.TeamLevSId,
  4467. a.VisitPNumber,
  4468. x.Price,
  4469. x.ClientName,
  4470. x.ClientNum,
  4471. x.FlightsCode,
  4472. }).ToList();
  4473. var groupByid = listAir.GroupBy(x => x.Id);
  4474. foreach (var airArr in groupByid)
  4475. {
  4476. var groupAirCount = 0; //团组航段数量
  4477. var infos = new List<string>();
  4478. foreach (var air in airArr)
  4479. {
  4480. var airCount = 0; // 单条航段数量
  4481. if (air.FlightsDescription.IsNullOrWhiteSpace())
  4482. {
  4483. continue;
  4484. }
  4485. if (air.ClientName.Contains("-1") || air.ClientName.Contains("行程单") || air.FlightsCode.Contains("行程单"))
  4486. {
  4487. continue;
  4488. }
  4489. string errMsg = string.Empty;
  4490. if (air.FlightsDescription.Contains("\r\n"))
  4491. {
  4492. var rowCode = Regex.Split(air.FlightsDescription, "\\d+\\.", RegexOptions.IgnoreCase).Where(x=>!string.IsNullOrWhiteSpace(x)).ToArray();
  4493. for (int i = 0; i < rowCode.Length; i++)
  4494. {
  4495. if (i != 0)
  4496. {
  4497. try
  4498. {
  4499. var columnValue = rowCode[i].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  4500. string day = columnValue[2].Substring(2, 2);//日
  4501. string monthAbbreviations = columnValue[2].Substring(4, 3).ToUpper();//月份
  4502. monthAbbreviations = GeneralMethod.GetLonger(monthAbbreviations);
  4503. string EndHHmm = columnValue[5].Substring(0, 2) + ":" + columnValue[5].Substring(2, 2);
  4504. DateTime EndData = DateTime.Parse($"{DateTime.Now.Year}-{monthAbbreviations}-{day} {EndHHmm}");//当前班次
  4505. var spDotandEmpty1 = rowCode[i - 1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  4506. string day1 = spDotandEmpty1[2].Substring(2, 2);//日
  4507. string monthAbbreviations1 = spDotandEmpty1[2].Substring(4, 3).ToUpper();//月份
  4508. monthAbbreviations1 = GeneralMethod.GetLonger(monthAbbreviations1);
  4509. string HHmm = spDotandEmpty1[6].Substring(0, 2) + ":" + spDotandEmpty1[6].Substring(2, 2);
  4510. DateTime data = DateTime.Parse($"{DateTime.Now.Year}-{monthAbbreviations1}-{day1} {HHmm}");//上个班次
  4511. TimeSpan t3 = EndData - data; //两个时间相减 。默认得到的是 两个时间之间的天数 得到:365.00:00:00
  4512. double getHour = t3.TotalHours;
  4513. if (getHour >= 6)
  4514. {
  4515. if (air.Price > 0)
  4516. {
  4517. airCount += 1;
  4518. }
  4519. else
  4520. {
  4521. airCount -= 1;
  4522. }
  4523. }
  4524. }
  4525. catch (Exception ex)
  4526. {
  4527. errMsg = "机票行程代码格式有误!解析失败!" + $"({ex.Message})";
  4528. break;
  4529. }
  4530. }
  4531. else
  4532. {
  4533. if (air.Price > 0)
  4534. {
  4535. airCount += 1;
  4536. }
  4537. else
  4538. {
  4539. airCount -= 1;
  4540. }
  4541. }
  4542. }
  4543. }
  4544. else
  4545. {
  4546. if (air.Price > 0)
  4547. {
  4548. airCount++;
  4549. }
  4550. else
  4551. {
  4552. airCount--;
  4553. }
  4554. }
  4555. string info = $"航班{air.FlightsCode} {(air.Price > 0 ? "" : "此笔为退费!")} 人数为{air.ClientNum} 有效段数为{airCount} 总段数为{airCount * air.ClientNum}";
  4556. if (!string.IsNullOrWhiteSpace(errMsg))
  4557. {
  4558. info = $"航班{air.FlightsCode} " + errMsg ;
  4559. }
  4560. infos.Add(info);
  4561. groupAirCount += airCount * air.ClientNum;
  4562. }
  4563. var groupinfo = listAir.First(x => x.Id == airArr.Key);
  4564. string temp = "本团人数" + Convert.ToInt32(groupinfo.VisitPNumber) + ",该人员" + user.CnName + "共订航段数" + groupAirCount.ToString() + ",每程航班提成为10元," + user.CnName + "提成共" + (groupAirCount * 10).ToString("#0.00");
  4565. resultArr.Add(new ComputeRoyaltiesView
  4566. {
  4567. TeamName = groupinfo.TeamName,
  4568. TeamId = groupinfo.Id,
  4569. ChiArr = infos,
  4570. TeamLvStr = teamLv.Find(x=>x.Id == groupinfo.TeamLevSId)?.Name,
  4571. VisitDate = groupinfo.VisitDate,
  4572. Temp = temp,
  4573. Price = (groupAirCount * 10),
  4574. }) ;
  4575. }
  4576. }
  4577. else if (Hotel.Contains(userId))
  4578. {
  4579. //标准团组:¥10/间/晚 * 实际订房间数 * 实际订房晚数; setdata id 1001 客人房
  4580. var listHotel = _sqlSugar.Queryable<Grp_HotelReservations, Grp_DelegationInfo, Grp_CreditCardPayment>((x, a, b) => new JoinQueryInfos(
  4581. JoinType.Left,x.DiId == a.Id,
  4582. JoinType.Left,b.CTable == 76 && b.CId == x.Id ))
  4583. .Where((x, a, b) => x.IsDel == 0 && x.CreateUserId == userId && a.VisitDate >= StartDateTime
  4584. && a.VisitDate <= EndDateTime && a.IsDel == 0 && b.IsDel == 0 && x.CardPrice > 0 && a.IsSure == 1 && auditState.Contains(b.IsAuditGM) && x.CheckType == 1001).Select((x,a,b)=> new
  4585. {
  4586. a.Id,
  4587. a.TeamName,
  4588. a.VisitDate,
  4589. a.TeamLevSId,
  4590. a.VisitPNumber,
  4591. x.SingleRoomCount,
  4592. x.SuiteRoomCount,
  4593. x.DoubleRoomCount,
  4594. x.OtherRoomCount,
  4595. x.CheckInDate,
  4596. x.CheckOutDate,
  4597. x.HotelName
  4598. }).ToList();
  4599. var groupByid = listHotel.GroupBy(x => x.Id);
  4600. var propertys = new string[] { "SingleRoomCount", "SuiteRoomCount", "DoubleRoomCount", "OtherRoomCount" };
  4601. foreach (var group in groupByid)
  4602. {
  4603. var infos = new List<string>();
  4604. var totalPrice = 0.00M;
  4605. foreach (var item in group)
  4606. {
  4607. var hotelCount = 0;
  4608. foreach (var property in propertys)
  4609. {
  4610. var value = item.GetType().GetProperty(property).GetValue(item).ObjToInt();
  4611. if (value > 0)
  4612. {
  4613. hotelCount += value;
  4614. }
  4615. }
  4616. if (hotelCount > 0)
  4617. {
  4618. if (DateTime.TryParse(item.CheckInDate, out DateTime checkin) && DateTime.TryParse(item.CheckOutDate, out DateTime checkout))
  4619. {
  4620. var day = checkout - checkin;
  4621. infos.Add($"{item.HotelName} 共有 {hotelCount} 间房 , 入住时间{item.CheckInDate} - {item.CheckOutDate} 共 { day.TotalDays }晚 提成数量:{hotelCount * day.TotalDays} 提成金额:{hotelCount * day.TotalDays * 10}");
  4622. totalPrice += (decimal)(hotelCount * day.TotalDays * 10);
  4623. }
  4624. else
  4625. {
  4626. infos.Add(item.HotelName + " 时间有误!请检查 。");
  4627. }
  4628. }
  4629. }
  4630. var groupinfo = listHotel.First(x => x.Id == group.Key);
  4631. var temp = "本团人数" + groupinfo.VisitPNumber + ",该人员" + user.CnName + "共操作酒店晚数" + totalPrice / 10 + ",每间每晚提成10元," + user.CnName + "提成共" + totalPrice.ToString("#0.00") + "元";
  4632. resultArr.Add(new ComputeRoyaltiesView
  4633. {
  4634. TeamName = groupinfo.TeamName,
  4635. TeamId = groupinfo.Id,
  4636. ChiArr = infos,
  4637. TeamLvStr = teamLv.Find(x => x.Id == groupinfo.TeamLevSId)?.Name,
  4638. VisitDate = groupinfo.VisitDate,
  4639. Temp = temp,
  4640. Price = totalPrice,
  4641. });
  4642. }
  4643. }
  4644. else if (OP.Contains(userId))
  4645. {
  4646. var OPList = _sqlSugar.Queryable<Grp_DelegationInfo>().Where((a) => a.IsDel == 0
  4647. && a.VisitDate >= StartDateTime && a.VisitDate <= EndDateTime && a.IsSure == 1
  4648. ).ToList();
  4649. var LvArr = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.STid == 70 && x.IsDel == 0).ToList();
  4650. foreach (var groupinfo in OPList)
  4651. {
  4652. var price = LvArr.Find(x => x.Id == groupinfo.OpRoyaltyLv)?.Name.ObjToInt() ?? 0;
  4653. string temp = $"本团等级为{teamLv.Find(x => x.Id == groupinfo.TeamLevSId)?.Name} 提成金额为{price} {(string.IsNullOrWhiteSpace(groupinfo.OpRoyaltyRemark) ? "" : "提成说明:" + groupinfo.OpRoyaltyRemark )}";
  4654. if (price == 0)
  4655. {
  4656. temp = $"本团等级为{teamLv.Find(x => x.Id == groupinfo.TeamLevSId)?.Name} op提成选项未选择!" ;
  4657. }
  4658. resultArr.Add(new ComputeRoyaltiesView
  4659. {
  4660. TeamName = groupinfo.TeamName,
  4661. TeamId = groupinfo.Id,
  4662. ChiArr = new List<string>() { temp },
  4663. TeamLvStr = teamLv.Find(x => x.Id == groupinfo.TeamLevSId)?.Name,
  4664. VisitDate = groupinfo.VisitDate,
  4665. Temp = temp,
  4666. Price = price
  4667. });
  4668. }
  4669. }
  4670. else if (Invitation.Contains(userId))
  4671. {
  4672. //2)付费公务活动部分:¥50 / 团;
  4673. //4)不付费公务活动部分(自己联络)额外奖励:¥200 / 团(若公务活动方与邀请方为同一机构,奖励金额为¥100 / 团);
  4674. //5)只发邀请的团组不付费邀请额外奖励:¥100 / 团;
  4675. //邀请方已授权我司签发的邀请仍按照:¥100 / 团,无额外奖励。
  4676. var officialList = _sqlSugar.Queryable<Res_OfficialActivities, Grp_DelegationInfo>((x,a)=>
  4677. new JoinQueryInfos(JoinType.Left,a.Id == x.DiId)
  4678. ).Where((x,a) => x.IsSubmitApproval == 0 && x.IsDel == 0 && a.IsDel == 0
  4679. && a.VisitDate >= StartDateTime && a.VisitDate <= EndDateTime && a.IsSure == 1
  4680. )
  4681. .Select((x, a) => new
  4682. {
  4683. a.Id,
  4684. a.TeamName,
  4685. a.VisitDate,
  4686. x.CreateUserId,
  4687. x.Type,
  4688. a.TeamLevSId,
  4689. x.Country,
  4690. x.Area,
  4691. x.Date,
  4692. x.Client
  4693. })
  4694. .ToList();
  4695. var groups = officialList.GroupBy(x => x.Id);
  4696. foreach (var group in groups)
  4697. {
  4698. var groupinfo = officialList.First(x => x.Id == group.Key);
  4699. var officialGroupList = group.GroupBy(d => d.CreateUserId);
  4700. int operUserMax = 0, operMaxCount = 0;
  4701. foreach (var item in officialGroupList)
  4702. {
  4703. if (item.Count() > operMaxCount)
  4704. {
  4705. operUserMax = item.Key;
  4706. operMaxCount = item.Count();
  4707. }
  4708. }
  4709. string temp = string.Empty;
  4710. bool isBasics = operUserMax == userId;
  4711. var money = 0;
  4712. var infos = new List<string>();
  4713. foreach (var item in group)
  4714. {
  4715. if (item.CreateUserId != user.Id)
  4716. {
  4717. continue;
  4718. }
  4719. string info = string.Empty;
  4720. if (item.Type == 0)
  4721. {
  4722. money += (100 + 300);
  4723. info = $"{item.Country} - {item.Area} - {item.Client} - {item.Date} 提成金额为 400";
  4724. }
  4725. else if (item.Type == 1)
  4726. {
  4727. money += 300;
  4728. info = $"{item.Country} - {item.Area} - {item.Client} - {item.Date} 提成金额为 300";
  4729. }
  4730. else if (item.Type == 2)
  4731. {
  4732. money += 200;
  4733. info = $"{item.Country} - {item.Area} - {item.Client} - {item.Date} 提成金额为 200";
  4734. }
  4735. infos.Add(info);
  4736. }
  4737. if (isBasics)
  4738. {
  4739. infos.Add($"{groupinfo.TeamName} 该人员{user.CnName}操作场数最多,基本提成为{150}");
  4740. }
  4741. else
  4742. {
  4743. infos.Add($"{groupinfo.TeamName} 操作场数不是最多人员,所以无基本提成");
  4744. }
  4745. resultArr.Add(new ComputeRoyaltiesView
  4746. {
  4747. TeamName = groupinfo.TeamName,
  4748. TeamId = groupinfo.Id,
  4749. ChiArr = infos,
  4750. TeamLvStr = teamLv.Find(x => x.Id == groupinfo.TeamLevSId)?.Name,
  4751. VisitDate = groupinfo.VisitDate,
  4752. Temp = temp,
  4753. Price = money,
  4754. });
  4755. }
  4756. }
  4757. else if (Visa.Contains(userId)) //签证
  4758. {
  4759. // 1)办理英国、加拿大、美国签证¥50元 / 人 / 团;
  4760. // 申根国家及其他所有国家¥30元 / 人 / 团;
  4761. // setdata id 974 客人
  4762. var existsCountry = new string[] { "英国", "加拿大", "美国" };
  4763. var whereExpression = Expressionable.Create<Grp_VisaInfo, Grp_DelegationInfo, Grp_CreditCardPayment>()
  4764. .And(
  4765. (x, a, b) => x.IsDel == 0 && x.CreateUserId == userId && (b.IsAuditGM == 1 || b.IsAuditGM == 3)
  4766. && a.IsDel == 0 && a.VisitDate >= StartDateTime && a.VisitDate <= EndDateTime && b.IsDel == 0 && x.IsThird == 0 && x.PassengerType == 974
  4767. && a.IsSure == 1 && auditState.Contains(b.IsAuditGM)
  4768. );
  4769. var listVisa = _sqlSugar.Queryable<Grp_VisaInfo, Grp_DelegationInfo, Grp_CreditCardPayment>((x, a, b) => new
  4770. JoinQueryInfos(
  4771. JoinType.Left, a.Id == x.DIId,
  4772. JoinType.Left, b.CTable == 80 && b.CId == x.Id)
  4773. )
  4774. .Where(whereExpression.ToExpression())
  4775. .Select((x, a, b) => new
  4776. {
  4777. a.Id,
  4778. a.TeamName,
  4779. a.VisitDate,
  4780. a.TeamLevSId,
  4781. a.VisitPNumber,
  4782. a.VisitCountry,
  4783. x.VisaDescription,
  4784. x.VisaFreeNumber,
  4785. x.VisaNumber,
  4786. x.VisaPrice
  4787. })
  4788. .ToList();
  4789. var groupByid = listVisa.GroupBy(x => x.Id);
  4790. foreach (var visaArr in groupByid)
  4791. {
  4792. var groupinfo = listVisa.First(x => x.Id == visaArr.Key);
  4793. var singlePrice = existsCountry.Where(x => groupinfo.VisitCountry.Contains(x)).Count() > 0 ? 50 : 30;
  4794. int count = 0, money = 0;
  4795. var arr = new List<string>();
  4796. foreach (var visa in visaArr)
  4797. {
  4798. if (visa.VisaPrice > 0)
  4799. {
  4800. count += visa.VisaFreeNumber + visa.VisaNumber;
  4801. money += singlePrice * (visa.VisaFreeNumber + visa.VisaNumber);
  4802. }
  4803. else
  4804. {
  4805. count -= visa.VisaFreeNumber + visa.VisaNumber;
  4806. money -= singlePrice * (visa.VisaFreeNumber + visa.VisaNumber);
  4807. }
  4808. string info = $"签证 {visa.VisaDescription} {(visa.VisaPrice > 0 ? "" : "此笔为退费!")} 人数为{visa.VisaFreeNumber + visa.VisaNumber} 单价为{singlePrice} 金额为{singlePrice * (visa.VisaFreeNumber + visa.VisaNumber)}";
  4809. arr.Add(info);
  4810. }
  4811. string temp = "本团人数" + groupinfo.VisitPNumber + ",该人员" + user.CnName + "共办理英国、加拿大、美国签证" + (singlePrice == 50 ? count : 0).ToString() + "本护照(包含免签人员),申根国家及其他所有国家" + (singlePrice == 30 ? count : 0).ToString() + "本。" + user.CnName + "提成共" + money.ToString("#0.00") + "元";
  4812. resultArr.Add(new ComputeRoyaltiesView
  4813. {
  4814. TeamName = groupinfo.TeamName,
  4815. TeamId = groupinfo.Id,
  4816. ChiArr = arr,
  4817. TeamLvStr = teamLv.Find(x => x.Id == groupinfo.TeamLevSId)?.Name,
  4818. VisitDate = groupinfo.VisitDate,
  4819. Temp = temp,
  4820. Price = money,
  4821. });
  4822. }
  4823. }
  4824. if (resultArr.Count > 0)
  4825. {
  4826. jw.Code = 200;
  4827. jw.Msg = "success!";
  4828. decimal total = 0;
  4829. foreach (var item in resultArr)
  4830. {
  4831. //var number = item.GetType().GetProperty("price")?.GetValue(item)?.ToString();
  4832. //total += decimal.TryParse(number,out decimal numberInt) ? numberInt : 0.00M;
  4833. total += item.Price;
  4834. }
  4835. jw.Data = new
  4836. {
  4837. resultArr,
  4838. totalPrice = total,
  4839. };
  4840. }
  4841. else
  4842. {
  4843. jw.Msg = "暂无数据!";
  4844. }
  4845. return Ok(jw);
  4846. }
  4847. /// <summary>
  4848. /// 导出提成表格
  4849. /// </summary>
  4850. /// <returns></returns>
  4851. [HttpPost]
  4852. public IActionResult ExportRoyaltyExcel(ExportRoyaltyExcelDto dto)
  4853. {
  4854. var jw = JsonView(false);
  4855. var apiResult = ComputeRoyalties(new
  4856. ComputeRoyaltiesDto
  4857. {
  4858. EndDate = dto.EndDate,
  4859. StartDate = dto.StartDate,
  4860. UserId = dto.UserId,
  4861. });
  4862. var parseApiResult = ((apiResult as OkObjectResult)?.Value) as OASystem.Domain.ViewModels.JsonView;
  4863. if (parseApiResult != null && parseApiResult.Code == 200)
  4864. {
  4865. var apiArr = (parseApiResult.Data?.GetType().GetProperty("resultArr")?.GetValue(parseApiResult.Data)) as List<ComputeRoyaltiesView>;
  4866. var user = _sqlSugar.Queryable<Sys_Users>().First(x => x.Id == dto.UserId);
  4867. if (apiArr != null && apiArr.Count > 0)
  4868. {
  4869. Dictionary<string, string> dic = new Dictionary<string, string>();
  4870. //dic.Add("Name", "人员:" + user.CnName);
  4871. dic.Add("startTime", dto.StartDate);
  4872. dic.Add("endTime", dto.EndDate);
  4873. dic.Add("operName", user.CnName);
  4874. dic.Add("timeNow", DateTime.Now.ToString("yyyy年MM月dd日"));
  4875. //dic.Add("DowntimeNow", DateTime.Now.ToString("yyyy年MM月dd日"));
  4876. dic.Add("totalPrice",( "总金额:" + parseApiResult.Data?.GetType().GetProperty("totalPrice")?.GetValue(parseApiResult.Data).ObjToDecimal().ToString() ?? "0") +" 元");
  4877. ArrayList ToTableArr = new ArrayList();
  4878. int No = 1;
  4879. //打开excel模板
  4880. foreach (var item in apiArr)
  4881. {
  4882. //载入数据
  4883. ToTableArr.Add(new
  4884. {
  4885. No,
  4886. item.TeamName,
  4887. item.VisitDate,
  4888. item.TeamLvStr,
  4889. item.Temp,
  4890. infos = string.Join("\r\n",item.ChiArr),
  4891. price = item.Price + "元",
  4892. });
  4893. No++;
  4894. }
  4895. DataTable TbData =CommonFun.ToDataTableArray(ToTableArr);
  4896. TbData.TableName = "TbData";
  4897. WorkbookDesigner designer = new WorkbookDesigner();
  4898. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/提成结算template.xlsx");
  4899. foreach (var key in dic.Keys)
  4900. {
  4901. designer.SetDataSource(key, dic[key]);
  4902. }
  4903. //数据源
  4904. designer.SetDataSource(TbData);
  4905. designer.Process();
  4906. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + "RoyaltyExcel/" + user.CnName + "_提成结算.xlsx" );
  4907. jw = JsonView(true, "success!", new
  4908. {
  4909. Url = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath")+ "RoyaltyExcel/" + user.CnName + "_提成结算.xlsx",
  4910. });
  4911. }
  4912. }
  4913. else
  4914. {
  4915. jw.Msg = "获取提成信息error " + jw.Msg;
  4916. }
  4917. return Ok(jw);
  4918. }
  4919. /// <summary>
  4920. /// 提成财务确认通知
  4921. /// </summary>
  4922. /// <returns></returns>
  4923. [HttpPost]
  4924. public async Task<IActionResult> RoyaltyConfirmByFin(RoyaltyConfirmDto dto)
  4925. {
  4926. var jw = JsonView(false);
  4927. if (!DateTime.TryParse(dto.StartData, out DateTime StartDateTime))
  4928. {
  4929. jw.Msg = "开始时间格式有误!";
  4930. return Ok(jw);
  4931. }
  4932. if (!DateTime.TryParse(dto.EndData, out DateTime EndDateTime))
  4933. {
  4934. jw.Msg = "结束时间格式有误!";
  4935. return Ok(jw);
  4936. }
  4937. if (DateTime.Compare(StartDateTime, EndDateTime) > 0)
  4938. {
  4939. jw.Msg = "开始时间大于结束时间!";
  4940. return Ok(jw);
  4941. }
  4942. if (dto.ComputeRoyaltiesList.Count != 0)
  4943. {
  4944. var user = _sqlSugar.Queryable<Sys_Users>().First(x => x.Id == dto.UserId);
  4945. if (user == null) { return Ok(JsonView(false, "通知失败! 人员信息有误!")); }
  4946. //保存提成信息
  4947. //消息通知对应人员(公司 部门 人员 时间段 团组id 是否确定 )
  4948. List<Fin_RoyaltyConfirm> entitys = dto.ComputeRoyaltiesList.Select(x => new Fin_RoyaltyConfirm
  4949. {
  4950. UserId = dto.UserId,
  4951. ChiArr = JsonConvert.SerializeObject(x.ChiArr),
  4952. CreateTime = DateTime.Now,
  4953. CreateUserId = dto.UserId,
  4954. IsConfirm = 0,
  4955. TeamId = x.TeamId,
  4956. TeamLvStr = x.TeamLvStr,
  4957. Price = x.Price,
  4958. VisitDate = x.VisitDate,
  4959. TeamName = x.TeamName,
  4960. Temp = x.Temp,
  4961. IsSeed = 0
  4962. }).ToList();
  4963. var expressionSoftDeleteWhere = Expressionable.Create<Fin_RoyaltyConfirm>()
  4964. .And(it => it.VisitDate >= StartDateTime)
  4965. .And(it => it.VisitDate <= EndDateTime)
  4966. .And(it => it.IsDel == 0)
  4967. .And(it => it.UserId == dto.UserId)
  4968. .And(it => it.IsSeed == 0)
  4969. .ToExpression();
  4970. var expressionSelectWhere = Expressionable.Create<Fin_RoyaltyConfirm>()
  4971. .And(it => it.VisitDate >= StartDateTime)
  4972. .And(it => it.VisitDate <= EndDateTime)
  4973. .And(it => it.IsDel == 0)
  4974. .And(it => it.UserId == dto.UserId)
  4975. .And(it => it.IsSeed == 1)
  4976. .ToExpression();
  4977. _sqlSugar.BeginTran();
  4978. try
  4979. {
  4980. _ = _sqlSugar.Updateable<Fin_RoyaltyConfirm>().SetColumns(it => new Fin_RoyaltyConfirm() { IsDel = 1, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"), DeleteUserId = dto.UserId })
  4981. .Where(expressionSoftDeleteWhere)
  4982. .ExecuteCommand();
  4983. var confirmYes = _sqlSugar.Queryable<Fin_RoyaltyConfirm>().Where(expressionSelectWhere).Select(x => x.TeamId).ToList();
  4984. entitys = entitys.Where(x => !confirmYes.Contains(x.TeamId)).ToList();
  4985. _ = _sqlSugar.Insertable<Fin_RoyaltyConfirm>(entitys).ExecuteCommand();
  4986. _sqlSugar.CommitTran();
  4987. //调用通知
  4988. var title = "提成确认";
  4989. var center = $"【{dto.StartData}】 - 【{dto.EndData}】提成财务已确认,请尽快查看!";
  4990. //【{dto.StartData}-{dto.EndData}-{dto.CompanyId}-{dto.DeparId}-{dto.UserId}】";
  4991. var ids = new List<int> { 235 , 233 }; //dto.UserId
  4992. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations,title, center, ids);
  4993. jw = JsonView(true, $"人员:{user.CnName} {dto.StartData}-{dto.EndData} 通知成功!");
  4994. }
  4995. catch (Exception ex)
  4996. {
  4997. _sqlSugar.RollbackTran();
  4998. jw = JsonView(false, "保存失败!" + ex.Message);
  4999. }
  5000. }
  5001. else
  5002. {
  5003. jw = JsonView(false,"保存失败! 无提成信息");
  5004. }
  5005. return Ok(jw);
  5006. }
  5007. /// <summary>
  5008. /// 查询提成信息
  5009. /// </summary>
  5010. /// <param name="dto"></param>
  5011. /// <returns></returns>
  5012. [HttpPost]
  5013. public IActionResult QueryRoyaltyInfo(QueryRoyaltyInfoDto dto)
  5014. {
  5015. var jw = JsonView(false);
  5016. var stateArr = new int[] { -1, 0, 1 };
  5017. if (!DateTime.TryParse(dto.StartDate, out DateTime StartDateTime))
  5018. {
  5019. jw.Msg = "开始时间格式有误!";
  5020. return Ok(jw);
  5021. }
  5022. if (!DateTime.TryParse(dto.EndDate, out DateTime EndDateTime))
  5023. {
  5024. jw.Msg = "结束时间格式有误!";
  5025. return Ok(jw);
  5026. }
  5027. if (DateTime.Compare(StartDateTime, EndDateTime) > 0)
  5028. {
  5029. jw.Msg = "开始时间大于结束时间!";
  5030. return Ok(jw);
  5031. }
  5032. if (!stateArr.Contains(dto.Send) || !stateArr.Contains(dto.Confirm))
  5033. {
  5034. jw.Msg = "状态标识有误!";
  5035. return Ok(jw);
  5036. }
  5037. var expressionSelectWhere = Expressionable.Create<Fin_RoyaltyConfirm>()
  5038. .And(it => it.VisitDate >= StartDateTime)
  5039. .And(it => it.VisitDate <= EndDateTime)
  5040. .And(it => it.IsDel == 0)
  5041. .And(it => it.UserId == dto.UserId)
  5042. .AndIF(dto.Confirm != -1,it => it.IsConfirm == dto.Confirm)
  5043. .AndIF(dto.Send != -1, it => it.IsSeed == dto.Send)
  5044. .ToExpression();
  5045. try
  5046. {
  5047. var query = _sqlSugar.Queryable<Fin_RoyaltyConfirm>().Where(expressionSelectWhere).ToList().Select(x => new
  5048. {
  5049. x.Price,
  5050. ChiArr = JsonConvert.DeserializeObject<List<string>>(x.ChiArr),
  5051. x.IsConfirm,
  5052. x.Id,
  5053. x.TeamId,
  5054. x.TeamName,
  5055. x.TeamLvStr,
  5056. x.Temp,
  5057. x.VisitDate,
  5058. x.IsSeed
  5059. });
  5060. jw = JsonView(true, "获取成功!", new
  5061. {
  5062. List = query,
  5063. CostPrice = query.Sum(x=>x.Price),
  5064. ConfirmPrice = query.Where(x=>x.IsConfirm == 1).Sum(x=>x.Price),
  5065. NoConfirmPrice = query.Where(x => x.IsConfirm == 0).Sum(x => x.Price),
  5066. SeedPrice = query.Where(x => x.IsSeed == 1).Sum(x => x.Price),
  5067. NoSeedPrice = query.Where(x => x.IsSeed == 0).Sum(x => x.Price),
  5068. });
  5069. }
  5070. catch (Exception ex)
  5071. {
  5072. jw = JsonView(true, "获取失败!" + ex.Message);
  5073. }
  5074. return Ok(jw);
  5075. }
  5076. /// <summary>
  5077. /// 个人提成确认
  5078. /// </summary>
  5079. /// <param name="dto"></param>
  5080. /// <returns></returns>
  5081. [HttpPost]
  5082. public IActionResult RoyaltyConfirmByUser(RoyaltyConfirmByUserDto dto)
  5083. {
  5084. var jw = JsonView(false);
  5085. var stateArr = new int[] {0 , 1};
  5086. if (!stateArr.Contains(dto.State))
  5087. {
  5088. return Ok(JsonView(false,"状态标识有误!"));
  5089. }
  5090. if (dto.Data != null && dto.Data.Count != 0)
  5091. {
  5092. var expressionUpdateWhere = Expressionable.Create<Fin_RoyaltyConfirm>()
  5093. .And(it => dto.Data.Contains (it.Id))
  5094. .And(it => it.IsDel == 0)
  5095. .ToExpression();
  5096. var count = _sqlSugar.Updateable<Fin_RoyaltyConfirm>().SetColumns(x => new Fin_RoyaltyConfirm
  5097. {
  5098. IsConfirm = dto.State,
  5099. })
  5100. .Where(expressionUpdateWhere).ExecuteCommand();
  5101. jw.Msg = $"{count}个团组确认成功!";
  5102. jw.Code = 200;
  5103. }
  5104. else
  5105. {
  5106. jw.Msg = "Data为空!";
  5107. }
  5108. return Ok(jw);
  5109. }
  5110. /// <summary>
  5111. /// 提成发放
  5112. /// </summary>
  5113. /// <param name="dto"></param>
  5114. /// <returns></returns>
  5115. [HttpPost]
  5116. public IActionResult RoyaltySeed(RoyaltySeedDto dto)
  5117. {
  5118. var jw = JsonView(false);
  5119. if (dto.Data != null && dto.Data.Count > 0)
  5120. {
  5121. var updateCount = _sqlSugar.Updateable<Fin_RoyaltyConfirm>().SetColumns(x => new Fin_RoyaltyConfirm
  5122. { IsSeed = 1 }).Where(x => dto.Data.Contains(x.Id) && x.IsDel == 0 && x.IsConfirm == 1).ExecuteCommand();
  5123. var info = $"{updateCount}个团组提成发放成功!";
  5124. if (dto.Data.Count > updateCount)
  5125. {
  5126. info += $"/r/n{dto.Data.Count - updateCount}个团组未确认!";
  5127. }
  5128. jw = JsonView(true, info);
  5129. }
  5130. else
  5131. {
  5132. jw.Msg = "发放的数据为空!";
  5133. }
  5134. return Ok(jw);
  5135. }
  5136. /// <summary>
  5137. /// 提成确认信息
  5138. /// </summary>
  5139. /// <returns></returns>
  5140. [HttpPost]
  5141. public IActionResult RoyaltyConfirmInfo()
  5142. {
  5143. var jw = JsonView(false);
  5144. var queryExpression = Expressionable.Create<Fin_RoyaltyConfirm>()
  5145. .And(r => r.IsDel == 0)
  5146. .And(r => r.IsConfirm == 1)
  5147. .And(r => r.IsSeed == 0)
  5148. .ToExpression();
  5149. var DbQueryConfirmInfo = _sqlSugar.Queryable<Fin_RoyaltyConfirm>()
  5150. .LeftJoin<Sys_Users>((r,s) => s.IsDel == 0 && s.Id == r.UserId)
  5151. .LeftJoin<Sys_JobPost>((r, s , p) => p.IsDel == 0 && p.Id == s.JobPostId)
  5152. .LeftJoin<Sys_Department>((r, s, p , d) => d.IsDel == 0 && d.Id == p.DepId)
  5153. .LeftJoin<Sys_Company>((r, s, p, d, c) => c.IsDel == 0 && c.Id == d.CompanyId)
  5154. .Where(queryExpression)
  5155. .Select((r, s, p, d, c) => new
  5156. {
  5157. r.UserId,
  5158. r.TeamId,
  5159. r.Id,
  5160. r.TeamName,
  5161. r.Price,
  5162. s.CnName,
  5163. p.JobName,
  5164. d.DepName,
  5165. c.CompanyName
  5166. })
  5167. .ToList();
  5168. var groupConfirmInfoByUser = DbQueryConfirmInfo.GroupBy(x => x.UserId);
  5169. ArrayList returnData = new ArrayList();
  5170. foreach (var item in groupConfirmInfoByUser)
  5171. {
  5172. var first = item.First();
  5173. returnData.Add(new
  5174. {
  5175. UserId = item.Key,
  5176. Count = item.Count(),
  5177. first.CompanyName,
  5178. first.DepName,
  5179. first.JobName,
  5180. first.CnName,
  5181. SumPrice = item.Sum(x=>x.Price),
  5182. RoyaltyIdArr = item.Select(x=>x.Id)
  5183. });
  5184. }
  5185. jw = JsonView(true,"获取成功!",returnData);
  5186. return Ok(jw);
  5187. }
  5188. /// <summary>
  5189. /// 提交到日付申请
  5190. /// </summary>
  5191. /// <returns></returns>
  5192. [HttpPost]
  5193. public async Task<IActionResult> RoyaltyFormPrice(RoyaltyFromPriceDto dto)
  5194. {
  5195. var jw = JsonView(false,"用户ID为空!");
  5196. var User = _sqlSugar.Queryable<Sys_Users>().First(x => x.Id
  5197. == dto.CreateId && x.IsDel == 0);
  5198. if (User == null)
  5199. {
  5200. JsonView(false, "createid 不存在!");
  5201. }
  5202. if (dto.Items.Count > 0)
  5203. {
  5204. var queryExpression = Expressionable.Create<Fin_RoyaltyConfirm>()
  5205. .And(r => r.IsDel == 0)
  5206. .And(r => r.IsConfirm == 1)
  5207. .And(r => dto.Items.Select(x=>x.UserId).Contains(r.UserId))
  5208. .ToExpression();
  5209. var DbQueryConfirmInfo = _sqlSugar.Queryable<Fin_RoyaltyConfirm>()
  5210. .LeftJoin<Sys_Users>((r, s) => s.IsDel == 0 && s.Id == r.UserId)
  5211. .LeftJoin<Sys_JobPost>((r, s, p) => p.IsDel == 0 && p.Id == s.JobPostId)
  5212. .LeftJoin<Sys_Department>((r, s, p, d) => d.IsDel == 0 && d.Id == p.DepId)
  5213. .LeftJoin<Sys_Company>((r, s, p, d, c) => c.IsDel == 0 && c.Id == d.CompanyId)
  5214. .Where(queryExpression)
  5215. .Select((r, s, p, d, c) => new
  5216. {
  5217. r.UserId,
  5218. r.TeamId,
  5219. r.Id,
  5220. r.TeamName,
  5221. r.Price,
  5222. s.CnName,
  5223. p.JobName,
  5224. d.DepName,
  5225. c.CompanyName,
  5226. CompanyId = c.Id,
  5227. UserName = s.CnName,
  5228. })
  5229. .ToList();
  5230. //已经提交到日付的用户提成信息
  5231. var existsDb = _sqlSugar.Queryable<Fin_RoyaltyForm>()
  5232. .Where(x => dto.Items
  5233. .Select(x => x.UserId).Contains(x.UserId) && x.IsDel == 0 )
  5234. .ToList();
  5235. var GroupByConfirmInfo = DbQueryConfirmInfo.GroupBy(x => x.UserId ).ToList();
  5236. //关联信息
  5237. List<Fin_RoyaltyForm> relevanceSoure = new List<Fin_RoyaltyForm>();
  5238. AddDailyFeePaymentDto dayPrice = new AddDailyFeePaymentDto()
  5239. {
  5240. UserId = dto.CreateId,
  5241. Instructions = DateTime.Now.ToString("yyyy-MM-dd HH:mm") + " 提成导入日付!",
  5242. PortType = 1,
  5243. CompanyId = 2,
  5244. PriceTypeId = 668,
  5245. TransferTypeId = 798,
  5246. };
  5247. List<AddDailyFeePaymentContentDto> ChiDayPrice = new List<AddDailyFeePaymentContentDto>();
  5248. _sqlSugar.BeginTran();
  5249. try
  5250. {
  5251. string message = string.Empty;
  5252. foreach (var item in GroupByConfirmInfo)
  5253. {
  5254. var first = item.First();
  5255. var reqBody = dto.Items.Find(x => x.UserId == item.Key);
  5256. var exists = item.Where(x => reqBody!.ChiArr.Contains(x.Id));
  5257. var existsDbByUser = existsDb.Where(x => x.UserId == item.Key);
  5258. var idsByUser = string.Join(',',existsDbByUser.Select(x=>x.ConfirmIdArr));
  5259. var idsByUserList = idsByUser.Split(',')
  5260. .Select(x=>
  5261. {
  5262. if (!string.IsNullOrWhiteSpace(x) && int.TryParse(x, out int intx))
  5263. {
  5264. return intx;
  5265. }
  5266. return 0;
  5267. })
  5268. .Where(x => x != 0)
  5269. .ToList();
  5270. var saveArr = exists.Where(x => !idsByUserList.Contains(x.Id));
  5271. var existsYes = exists.Where(x => idsByUserList.Contains(x.Id));
  5272. var yesPrice = existsYes.Sum(x => x.Price);
  5273. var savePrice = saveArr.Sum(x => x.Price);
  5274. if (saveArr.Count() > 0) {
  5275. ChiDayPrice.Add(new
  5276. AddDailyFeePaymentContentDto
  5277. {
  5278. ItemTotal = savePrice,
  5279. Price = savePrice,
  5280. Quantity = 1,
  5281. PriceName = first.CnName + "提成金额!",
  5282. });
  5283. relevanceSoure.Add(new
  5284. Fin_RoyaltyForm
  5285. {
  5286. CreateUserId = dto.CreateId,
  5287. ConfirmIdArr = string.Join(',', saveArr.Select(x => x.Id)),
  5288. CreateTime = DateTime.Now,
  5289. IsDel = 0,
  5290. UserId = item.Key,
  5291. });
  5292. }
  5293. if (yesPrice > 0 ) {
  5294. message += $"{first.CnName} 提成 {savePrice}元已导入日付申请 , {yesPrice} 元已经存在 ! \r\n";
  5295. }
  5296. else {
  5297. message += $"{first.CnName} 提成 {savePrice}元已导入日付申请 ! \r\n";
  5298. }
  5299. }
  5300. dayPrice.FeeContents = ChiDayPrice;
  5301. dayPrice.SumPrice = ChiDayPrice.Sum(x => x.ItemTotal);
  5302. if (dayPrice.SumPrice != 0)
  5303. {
  5304. var ApiResult = await _daiRep.Add(dayPrice);
  5305. int dailyId = Convert.ToInt32(ApiResult?.Data?.GetType().GetProperty("dailyId").GetValue(ApiResult.Data));
  5306. int sign = Convert.ToInt32(ApiResult?.Data?.GetType().GetProperty("sign").GetValue(ApiResult.Data));
  5307. relevanceSoure.ForEach(x => x.DayOverhead = dailyId);
  5308. var addCount = _sqlSugar.Insertable<Fin_RoyaltyForm>(relevanceSoure).ExecuteCommand();
  5309. }
  5310. _sqlSugar.CommitTran();
  5311. //消息通知
  5312. //await AppNoticeLibrary.DailyPayReminders_Create_ToCaiwuChat(dailyId, sign, QiyeWeChatEnum.CaiWuChat);
  5313. jw = JsonView(true, message);
  5314. }
  5315. catch (Exception ex)
  5316. {
  5317. _sqlSugar.RollbackTran();
  5318. jw = JsonView(false, $" Api Error ({ex.Message})");
  5319. }
  5320. }
  5321. return Ok(jw);
  5322. }
  5323. #endregion
  5324. #region 团组未审核数据
  5325. /// <summary>
  5326. /// 团组未审核费用数据
  5327. /// </summary>
  5328. /// <param name="beginDt"></param>
  5329. /// <param name="endDt"></param>
  5330. /// <returns></returns>
  5331. [HttpGet]
  5332. public async Task<IActionResult> GroupUnAuditFeeList(string beginDt,string endDt,string teamName)
  5333. {
  5334. var jw = JsonView(false);
  5335. bool beginDtBool = DateTime.TryParse(beginDt, out DateTime _beginDt),
  5336. endDtBool = DateTime.TryParse(endDt, out DateTime _endDt);
  5337. if (!beginDtBool && !endDtBool)
  5338. {
  5339. jw.Msg = $"开始或者结束时间格式不正确!";
  5340. return Ok(jw);
  5341. }
  5342. var _groupDatas = _sqlSugar.Queryable<Grp_DelegationInfo>()
  5343. .Where(x => x.IsDel == 0 &&
  5344. x.VisitDate >= _beginDt &&
  5345. x.VisitDate <= _endDt
  5346. )
  5347. .WhereIF(!string.IsNullOrEmpty(teamName), x => x.TeamName.Contains(teamName))
  5348. .ToList();
  5349. var _groupIds = _groupDatas.Select(x => x.Id).ToList();
  5350. if (_groupIds.Count < 1)
  5351. {
  5352. jw.Msg = $"该时间段暂无出访的团组!";
  5353. return Ok(jw);
  5354. }
  5355. var _DailyFeePaymentResult = new tree_Group_DailyFeePaymentResult();
  5356. var dataList = new List<tree_Group_DailyFeePaymentPageListView>();
  5357. var _paymentDatas = _sqlSugar.Queryable<Grp_CreditCardPayment>()
  5358. .Where(x => x.IsDel == 0 &&
  5359. _groupIds.Contains(x.DIId) &&
  5360. x.IsAuditGM == 0
  5361. )
  5362. .ToList();
  5363. _DailyFeePaymentResult.gz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 0).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); //公转
  5364. _DailyFeePaymentResult.sz = _paymentDatas.Where(it => it.OrbitalPrivateTransfer == 1).Sum(it => ((it.PayMoney * it.DayRate) / 100) * it.PayPercentage); ; //私转
  5365. #region 相关基础数据源
  5366. var userDatas = _sqlSugar.Queryable<Sys_Users>().ToList();
  5367. var setDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToList();
  5368. var countryFeeDatas = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  5369. //76 酒店预订
  5370. var hotelDatas = _sqlSugar.Queryable<Grp_HotelReservations>()
  5371. .InnerJoin<Grp_CreditCardPayment>((hr,ccp) => hr.Id == ccp.CId &&
  5372. ccp.CTable == 76 &&
  5373. ccp.IsDel == 0
  5374. )
  5375. .Where((hr, ccp) => hr.IsDel == 0 && _groupIds.Contains(hr.DiId) && ccp.IsAuditGM == 0)
  5376. .ToList();
  5377. var hotelContentDatas = _sqlSugar.Queryable<Grp_HotelReservationsContent>()
  5378. .Where(it => it.IsDel == 0 &&
  5379. it.IsPay == 0 &&
  5380. it.Price != 0 &&
  5381. _groupIds.Contains(it.DiId)
  5382. )
  5383. .ToList();
  5384. //79 车/导游地接
  5385. var opDatas = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
  5386. .InnerJoin<Grp_CreditCardPayment>((ctggr, ccp) => ctggr.Id == ccp.CId &&
  5387. ccp.CTable == 79 &&
  5388. ccp.IsDel == 0
  5389. )
  5390. .Where((ctggr, ccp) => ctggr.IsDel == 0 && _groupIds.Contains(ctggr.DiId) && ccp.IsAuditGM == 0)
  5391. .ToList();
  5392. // 80 签证
  5393. var visaDatas = _sqlSugar.Queryable<Grp_VisaInfo>()
  5394. .InnerJoin<Grp_CreditCardPayment>((vi, ccp) => vi.Id == ccp.CId &&
  5395. ccp.CTable == 80 &&
  5396. ccp.IsDel == 0
  5397. )
  5398. .Where((vi, ccp) => vi.IsDel == 0 && _groupIds.Contains(vi.DIId) && ccp.IsAuditGM == 0)
  5399. .ToList();
  5400. // 81 邀请/公务活动
  5401. var ioaDatas = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>()
  5402. .InnerJoin<Grp_CreditCardPayment>((ioa, ccp) => ioa.Id == ccp.CId &&
  5403. ccp.CTable == 81 &&
  5404. ccp.IsDel == 0
  5405. )
  5406. .Where((ioa, ccp) => ioa.IsDel == 0 && _groupIds.Contains(ioa.DiId) && ccp.IsAuditGM == 0)
  5407. .ToList();
  5408. // 82 团组客户保险
  5409. var insureDatas = _sqlSugar.Queryable<Grp_Customers>()
  5410. .InnerJoin<Grp_CreditCardPayment>((c, ccp) => c.Id == ccp.CId &&
  5411. ccp.CTable == 82 &&
  5412. ccp.IsDel == 0
  5413. )
  5414. .Where((c, ccp) => c.IsDel == 0 && _groupIds.Contains(c.DiId) && ccp.IsAuditGM == 0)
  5415. .ToList();
  5416. // 85 机票预订
  5417. var airDatas = _sqlSugar.Queryable<Grp_AirTicketReservations>()
  5418. .InnerJoin<Grp_CreditCardPayment>((atr, ccp) => atr.Id == ccp.CId &&
  5419. ccp.CTable == 85 &&
  5420. ccp.IsDel == 0
  5421. )
  5422. .Where((atr, ccp) => atr.IsDel == 0 && _groupIds.Contains(atr.DIId) && ccp.IsAuditGM == 0)
  5423. .ToList();
  5424. // 98 其他款项
  5425. var otherMoneyDatas = _sqlSugar.Queryable<Grp_DecreasePayments>()
  5426. .InnerJoin<Grp_CreditCardPayment>((dp, ccp) => dp.Id == ccp.CId &&
  5427. ccp.CTable == 98 &&
  5428. ccp.IsDel == 0
  5429. )
  5430. .Where((dp, ccp) => dp.IsDel == 0 && _groupIds.Contains(dp.DiId) && ccp.IsAuditGM == 0)
  5431. .ToList();
  5432. // 285 收款退还
  5433. var refundPaymentDatas = _sqlSugar.Queryable<Fin_PaymentRefundAndOtherMoney>()
  5434. .InnerJoin<Grp_CreditCardPayment>((prom, ccp) => prom.Id == ccp.CId &&
  5435. ccp.CTable == 285 &&
  5436. ccp.IsDel == 0
  5437. )
  5438. .Where((prom, ccp) => prom.IsDel == 0 && _groupIds.Contains(prom.DiId) && ccp.IsAuditGM == 0)
  5439. .ToList();
  5440. // 1015 超支费用
  5441. var extraCostDatas = _sqlSugar.Queryable<Fin_GroupExtraCost>()
  5442. .InnerJoin<Grp_CreditCardPayment>((gec, ccp) => gec.Id == ccp.CId &&
  5443. ccp.CTable == 1015 &&
  5444. ccp.IsDel == 0
  5445. )
  5446. .Where((gec, ccp) => gec.IsDel == 0 && _groupIds.Contains(gec.DiId) && ccp.IsAuditGM == 0)
  5447. .ToList();
  5448. #endregion
  5449. //Expense company
  5450. foreach (var groupInfo in _groupDatas)
  5451. {
  5452. var childList = new List<Group_DailyFeePaymentContentInfolView>();
  5453. var groupPaymentDatas = _paymentDatas.Where(it => groupInfo.Id == it.DIId).ToList();
  5454. if (groupPaymentDatas.Count > 0)
  5455. {
  5456. int rouNumber = 1;
  5457. foreach (var payInfo in groupPaymentDatas)
  5458. {
  5459. string priName = "-";
  5460. string orbitalPrivateTransfer = payInfo.OrbitalPrivateTransfer == 0 ? "公转" : payInfo.OrbitalPrivateTransfer == 1 ? "私转" : "-";
  5461. switch (payInfo.CTable)
  5462. {
  5463. case 76: //76 酒店预订
  5464. priName = $"[费用名称:{hotelDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.HotelName ?? ""}]";
  5465. break;
  5466. case 79: //79 车/导游地接
  5467. var opData = opDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id);
  5468. if (opData != null)
  5469. {
  5470. string area = "";
  5471. bool b = int.TryParse(opData.Area, out int areaId);
  5472. if (b)
  5473. {
  5474. string area1 = countryFeeDatas.Find(it => it.Id == areaId)?.Country ?? "-";
  5475. area = $"{area1}({setDatas.Find(it => it.Id == opData.PriceType)?.Name ?? "-"})";
  5476. }
  5477. else area = opData.Area;
  5478. string opPriName = "-";
  5479. if (!string.IsNullOrEmpty(opData.PriceName)) opPriName = opData.PriceName;
  5480. area += $"({opPriName})";
  5481. if (payInfo.OrbitalPrivateTransfer == 0) //公转
  5482. {
  5483. priName = $"【{orbitalPrivateTransfer}】【导游: {opData.ServiceGuide} 】[费用名称:{area}]";
  5484. }
  5485. else if (payInfo.OrbitalPrivateTransfer == 1) //私转
  5486. {
  5487. priName = $"【{orbitalPrivateTransfer}】【导游:{opData.ServiceGuide}】[费用名称:{area}]";
  5488. }
  5489. }
  5490. break;
  5491. case 80: // 80 签证
  5492. 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);
  5493. List<SimplClientInfo> arr = _sqlSugar.SqlQueryable<SimplClientInfo>(sql).ToList();
  5494. string visaClientName = visaDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.VisaClient ?? "";
  5495. string clientName = "-";
  5496. if (Regex.Match(visaClientName, @"\d+,?").Value.Length > 0)
  5497. {
  5498. string[] temparr = visaClientName.Split(',');
  5499. string fistrStr = temparr[0];
  5500. int count = temparr.Count();
  5501. int tempId;
  5502. bool success = int.TryParse(fistrStr, out tempId);
  5503. if (success)
  5504. {
  5505. SimplClientInfo tempInfo = arr.FirstOrDefault(s => s.Id == tempId);
  5506. if (tempInfo != null)
  5507. {
  5508. if (count > 1)
  5509. {
  5510. clientName = string.Format(@"{0}{1}等{2}人", tempInfo.LastName, tempInfo.FirstName, count);
  5511. }
  5512. else
  5513. {
  5514. clientName = string.Format(@"{0}{1}", tempInfo.LastName, tempInfo.FirstName);
  5515. }
  5516. }
  5517. }
  5518. else
  5519. {
  5520. clientName = fistrStr;
  5521. }
  5522. }
  5523. priName = $"[费用名称:{clientName}]";
  5524. break;
  5525. case 81: // 81 邀请/公务活动
  5526. priName = $"[费用名称:{ioaDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.Inviter ?? " -"}]";
  5527. break;
  5528. case 82: // 82 团组客户保险
  5529. string bx_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);
  5530. List<SimplClientInfo> bx_arr = _sqlSugar.SqlQueryable<SimplClientInfo>(bx_sql).ToList();
  5531. string bx_ClientName = insureDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.ClientName ?? "";
  5532. string bx_clientName = "-";
  5533. if (Regex.Match(bx_ClientName, @"\d+,?").Value.Length > 0)
  5534. {
  5535. string[] temparr = bx_ClientName.Split(',');
  5536. string fistrStr = temparr[0];
  5537. int count = temparr.Count();
  5538. int tempId;
  5539. bool success = int.TryParse(fistrStr, out tempId);
  5540. if (success)
  5541. {
  5542. SimplClientInfo tempInfo = bx_arr.FirstOrDefault(s => s.Id == tempId);
  5543. if (tempInfo != null)
  5544. {
  5545. if (count > 1)
  5546. {
  5547. bx_clientName = string.Format(@"{0}{1}等{2}人", tempInfo.LastName, tempInfo.FirstName, count);
  5548. }
  5549. else
  5550. {
  5551. bx_clientName = string.Format(@"{0}{1}", tempInfo.LastName, tempInfo.FirstName);
  5552. }
  5553. }
  5554. }
  5555. else
  5556. {
  5557. bx_clientName = fistrStr;
  5558. }
  5559. }
  5560. //priName = $"[费用名称:{insureDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.ClientName ?? " -"}]";
  5561. priName = $"[费用名称:{bx_clientName}]";
  5562. break;
  5563. case 85: // 85 机票预订
  5564. string flightsCode = airDatas.Find(it => payInfo.DIId == it.DIId && payInfo.CId == it.Id)?.FlightsCode ?? "-";
  5565. string airPayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "-";
  5566. priName = $"{flightsCode}【{airPayType}】";
  5567. break;
  5568. case 98: // 98 其他款项
  5569. priName = $"[费用名称:{otherMoneyDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? " -"}]";
  5570. break;
  5571. case 285: // 285 收款退还
  5572. priName = $"[费用名称:{refundPaymentDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? " -"}]";
  5573. break;
  5574. case 1015: // 1015 超支费用
  5575. priName = $"[费用名称:{extraCostDatas.Find(it => payInfo.DIId == it.DiId && payInfo.CId == it.Id)?.PriceName ?? " -"}]";
  5576. break;
  5577. default:
  5578. priName = "";
  5579. break;
  5580. }
  5581. if (payInfo.CTable == 76) //酒店单独处理
  5582. {
  5583. var hotelContents = hotelContentDatas.Where(it => it.HrId == payInfo.CId);
  5584. List<Group_DailyFeePaymentContentInfolView> childInfos = new List<Group_DailyFeePaymentContentInfolView>();
  5585. foreach (var hotelContent in hotelContents)
  5586. {
  5587. string subPriceName = "";
  5588. if (hotelContent.PriceType == 1) subPriceName = "房费";
  5589. else if (hotelContent.PriceType == 2) subPriceName = "早餐";
  5590. else if (hotelContent.PriceType == 3) subPriceName = "地税";
  5591. else if (hotelContent.PriceType == 4) subPriceName = "城市税";
  5592. if (string.IsNullOrEmpty(subPriceName)) subPriceName = priName;
  5593. else subPriceName = $"{priName.Replace("]", "")}-{subPriceName}]";
  5594. string payeeStr1 = string.Format(@" {0},开户行:{1},银行卡号:{2} ",
  5595. string.IsNullOrEmpty(hotelContent.Payee) ? "-" : hotelContent.Payee,
  5596. string.IsNullOrEmpty(hotelContent.OtherBankName) ? "-" : hotelContent.OtherBankName,
  5597. string.IsNullOrEmpty(hotelContent.OtherSideNo) ? "-" : hotelContent.OtherSideNo);
  5598. decimal _PaymentAmount1 = hotelContent.Price;//此次付款金额
  5599. decimal _CNYSubTotalAmount1 = _PaymentAmount1 * hotelContent.Rate;//此次付款金额
  5600. _CNYSubTotalAmount1 = Convert.ToDecimal(_CNYSubTotalAmount1.ToString("#0.00"));
  5601. var childInfo1 = new Group_DailyFeePaymentContentInfolView()
  5602. {
  5603. Id = payInfo.Id,
  5604. HotelSubId = hotelContent.Id,
  5605. Payee = payeeStr1,
  5606. RowNumber = rouNumber,
  5607. Applicant = userDatas.Find(it => it.Id == payInfo.CreateUserId)?.CnName ?? "",
  5608. ApplicantDt = payInfo.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
  5609. PayType = setDatas.Find(it => it.Id == hotelContent.PayDId)?.Name ?? "",
  5610. TransferMark = orbitalPrivateTransfer,
  5611. PriceName = subPriceName,
  5612. ModuleName = setDatas.Find(it => it.Id == payInfo.CTable)?.Name ?? "",
  5613. PayCurrCode = setDatas.Find(it => it.Id == hotelContent.Currency)?.Name ?? "",
  5614. PaymentAmount = _PaymentAmount1,
  5615. PayRate = hotelContent.Rate,
  5616. CNYSubTotalAmount = _CNYSubTotalAmount1,
  5617. AuditStatus = payInfo.IsAuditGM
  5618. };
  5619. 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})";
  5620. childInfo1.RemaksDescription = remaksDescription1;
  5621. childInfos.Add(childInfo1);
  5622. rouNumber++;
  5623. }
  5624. childList.AddRange(childInfos);
  5625. }
  5626. else
  5627. {
  5628. string payeeStr = string.Format(@" {0},开户行:{1},银行卡号:{2} ",
  5629. string.IsNullOrEmpty(payInfo.Payee) ? "-" : payInfo.Payee,
  5630. string.IsNullOrEmpty(payInfo.OtherBankName) ? "-" : payInfo.OtherBankName,
  5631. string.IsNullOrEmpty(payInfo.OtherSideNo) ? "-" : payInfo.OtherSideNo);
  5632. decimal _PaymentAmount = (payInfo.PayMoney / 100) * payInfo.PayPercentage;//此次付款金额
  5633. decimal _CNYSubTotalAmount = _PaymentAmount * payInfo.DayRate;//此次付款金额
  5634. _CNYSubTotalAmount = Convert.ToDecimal(_CNYSubTotalAmount.ToString("#0.00"));
  5635. var childInfo = new Group_DailyFeePaymentContentInfolView()
  5636. {
  5637. Id = payInfo.Id,
  5638. Payee = payeeStr,
  5639. RowNumber = rouNumber,
  5640. Applicant = userDatas.Find(it => it.Id == payInfo.CreateUserId)?.CnName ?? "",
  5641. ApplicantDt = payInfo.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
  5642. PayType = setDatas.Find(it => it.Id == payInfo.PayDId)?.Name ?? "",
  5643. TransferMark = orbitalPrivateTransfer,
  5644. PriceName = priName,
  5645. ModuleName = setDatas.Find(it => it.Id == payInfo.CTable)?.Name ?? "",
  5646. PayCurrCode = setDatas.Find(it => it.Id == payInfo.PaymentCurrency)?.Name ?? "",
  5647. PaymentAmount = _PaymentAmount,
  5648. PayRate = payInfo.DayRate,
  5649. CNYSubTotalAmount = _CNYSubTotalAmount,
  5650. AuditStatus = payInfo.IsAuditGM
  5651. };
  5652. 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})";
  5653. childInfo.RemaksDescription = remaksDescription;
  5654. childList.Add(childInfo);
  5655. rouNumber++;
  5656. }
  5657. }
  5658. CompanyInfo companyInfo = new CompanyInfo();
  5659. companyInfo = ExpenseCompanyByTeamId(groupInfo.TeamDid);
  5660. dataList.Add(new tree_Group_DailyFeePaymentPageListView()
  5661. {
  5662. Id = Guid.NewGuid().ToString("N"),
  5663. GroupName = groupInfo.TeamName,
  5664. CompanyId = companyInfo.Id,
  5665. ConpanyName = companyInfo.ConpanyName,
  5666. CNYTotalAmount = childList.Sum(it => it.CNYSubTotalAmount),
  5667. ChildList = childList,
  5668. });
  5669. }
  5670. }
  5671. var dataList1 = new List<tree_Group_DailyFeePaymentPageListView>();
  5672. //移除没有数据的团
  5673. foreach (var item in dataList)
  5674. {
  5675. if (item.CNYTotalAmount > 0 && item.ChildList.Count >0)
  5676. {
  5677. dataList1.Add(item);
  5678. }
  5679. }
  5680. _DailyFeePaymentResult.dataList = dataList1;
  5681. jw.Code = StatusCodes.Status200OK;
  5682. jw.Msg = $"操作成功!";
  5683. jw.Data = _DailyFeePaymentResult;
  5684. return Ok(jw);
  5685. }
  5686. #endregion
  5687. }
  5688. }