FinancialController.cs 198 KB

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