FinancialController.cs 205 KB

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