FinancialController.cs 253 KB

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