StatisticsController.cs 224 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758
  1. using Aspose.Cells;
  2. using OASystem.API.OAMethodLib;
  3. using OASystem.Domain.Dtos.Statistics;
  4. using OASystem.Domain.Entities.Customer;
  5. using OASystem.Domain.Entities.Groups;
  6. using OASystem.Domain.ViewModels.Financial;
  7. using OASystem.Domain.ViewModels.QiYeWeChat;
  8. using OASystem.Domain.ViewModels.Statistics;
  9. using OASystem.Infrastructure.Repositories.Groups;
  10. using System.Data;
  11. using static OASystem.API.OAMethodLib.GeneralMethod;
  12. using TypeInfo = OASystem.Domain.ViewModels.Statistics.TypeInfo;
  13. namespace OASystem.API.Controllers
  14. {
  15. /// <summary>
  16. /// 统计模块
  17. /// </summary>
  18. [Route("api/[controller]")]
  19. [ApiController]
  20. public class StatisticsController : ControllerBase
  21. {
  22. private readonly int _decimalPlaces;
  23. private readonly IConfiguration _config;
  24. private readonly IMapper _mapper;
  25. private readonly SqlSugarClient _sqlSugar;
  26. private readonly DelegationInfoRepository _groupRep;
  27. private readonly SetDataRepository _setDataRep;
  28. private readonly TeamRateRepository _teamRateRep;
  29. private readonly VisitingClientsRepository _visitingClientsRep;
  30. /// <summary>
  31. /// Init
  32. /// </summary>
  33. /// <param name="mapper"></param>
  34. /// <param name="sqlSugar"></param>
  35. /// <param name="groupRep"></param>
  36. /// <param name="setDataRep"></param>
  37. public StatisticsController(IMapper mapper, IConfiguration config, SqlSugarClient sqlSugar, DelegationInfoRepository groupRep, SetDataRepository setDataRep, TeamRateRepository teamRate, VisitingClientsRepository visitingClientsRep)
  38. {
  39. _mapper = mapper;
  40. _config = config;
  41. _groupRep = groupRep;
  42. _setDataRep = setDataRep;
  43. _sqlSugar = sqlSugar;
  44. _teamRateRep = teamRate;
  45. _visitingClientsRep = visitingClientsRep;
  46. }
  47. #region 团组报表
  48. /// <summary>
  49. /// 团组报表
  50. /// Items
  51. /// </summary>
  52. /// <param name="_dto">团组列表请求dto</param>
  53. /// <returns></returns>
  54. [HttpPost("PostGroupStatementItems")]
  55. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  56. public async Task<IActionResult> PostGroupStatementItems(GroupStatementItemsDto _dto)
  57. {
  58. #region 参数验证
  59. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  60. if (_dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  61. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  62. #region 页面操作权限验证
  63. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  64. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  65. #endregion
  66. #endregion
  67. if (_dto.PortType == 1 || _dto.PortType == 2 || _dto.PortType == 3) // web/Android/IOS
  68. {
  69. string sqlWhere = string.Empty;
  70. if (_dto.IsSure == 0) //未完成
  71. {
  72. sqlWhere += string.Format(@" And IsSure = 0");
  73. }
  74. else if (_dto.IsSure == 1) //已完成
  75. {
  76. sqlWhere += string.Format(@" And IsSure = 1");
  77. }
  78. if (!string.IsNullOrEmpty(_dto.SearchCriteria))
  79. {
  80. string tj = _dto.SearchCriteria;
  81. sqlWhere += string.Format(@"And (ssd.Name Like '%{0}%' Or TeamName Like '%{1}%' Or ClientName Like '%{2}%' Or ClientName Like '%{3}%' Or su.CnName Like '%{4}%')",
  82. tj, tj, tj, tj, tj);
  83. }
  84. string sql = string.Format(@"Select row_number() over(order by gdi.VisitDate Desc) as Row_Number,
  85. gdi.Id,TourCode,ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,
  86. ClientName,ClientUnit,VisitDate,ssd.Id TeamTypeId, ssd.Name TeamType,
  87. VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure,gdi.CreateTime,
  88. pr.LastCollectionTime
  89. From Grp_DelegationInfo gdi
  90. Left Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  91. Left Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  92. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  93. Left Join (
  94. SELECT Diid, MAX(CreateTime) LastCollectionTime
  95. FROM Fin_ProceedsReceived
  96. Where IsDel = 0
  97. GROUP BY Diid
  98. ) pr On gdi.Id = pr.Diid
  99. Where gdi.IsDel = 0 {0} ", sqlWhere);
  100. RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
  101. var _DelegationList = await _sqlSugar.SqlQueryable<GroupStatementItemView>(sql).ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);//ToPageAsync
  102. var _view = new
  103. {
  104. PageFuncAuth = pageFunAuthView,
  105. Data = _DelegationList
  106. };
  107. return Ok(JsonView(true, "查询成功!", _view, total));
  108. }
  109. else
  110. {
  111. return Ok(JsonView(false, "查询失败"));
  112. }
  113. }
  114. /// <summary>
  115. /// 团组报表
  116. /// Details
  117. /// </summary>
  118. /// <param name="_dto">团组列表请求dto</param>
  119. /// <returns></returns>
  120. [HttpPost("PostGroupStatementDetails")]
  121. //[JsonConverter(typeof(DecimalConverter), 2)]
  122. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  123. public async Task<IActionResult> PostGroupStatementDetails(GroupStatementDetailsDto _dto)
  124. {
  125. /*
  126. * 团组报表计算方式
  127. * 当前总支出 = 团组支出.Sum() + 超支费用.Sum()
  128. * 应收金额 = 应收表.Sum()
  129. * 已收金额 = 已收表.Sum()
  130. * 应收利润(应收-支出) = 应收金额 - 收款退还 - 当前总支出
  131. * 已收利润(已收-支出) = 已收金额 - 收款退还 - 当前总支出
  132. *
  133. */
  134. #region 参数验证
  135. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  136. if (_dto.PageId < 1) _dto.PageId = 38; //团组报表页面Id
  137. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  138. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  139. #region 页面操作权限验证
  140. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  141. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  142. #endregion
  143. #endregion
  144. if (_dto.PortType == 1 || _dto.PortType == 2 || _dto.PortType == 3) // web/Android/IOS
  145. {
  146. GroupStatementDetailsView _view = new GroupStatementDetailsView();
  147. #region 费用类型 币种,转账,客户信息
  148. List<Sys_SetData> _setDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToListAsync();
  149. var _clientDatas = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync();
  150. #endregion
  151. #region 团组收入
  152. GroupIncomeView _giView = new GroupIncomeView();
  153. /*
  154. * 应收报表
  155. * 增加方式=实际报价时 费用必须审核才能进入团组报表
  156. */
  157. decimal frTotalAmount = 0.00M;//应收总金额
  158. string _frSql = string.Format(@" Select fr.Id,fr.AddingWay,fr.Status,u.CnName As Auditor,fr.AuditTime,fr.Diid,fr.PriceName,fr.Price,fr.Count,fr.Unit,fr.Currency,
  159. sd.Name As CurrencyCode,sd.Remark As CurrencyName,fr.Rate,fr.ItemSumPrice,fr.CreateTime
  160. From Fin_ForeignReceivables fr
  161. Left Join Sys_SetData sd On fr.Currency = sd.Id
  162. Left Join Sys_Users u On fr.Auditor = u.Id
  163. Where fr.IsDel = 0 And fr.Diid = {0} Order By CreateTime", _dto.DiId);
  164. List<Gsd_ForeignReceivablesView> _frViews = await _sqlSugar.SqlQueryable<Gsd_ForeignReceivablesView>(_frSql).ToListAsync();
  165. //List<Gsd_ForeignReceivablesView> _frViews = new List<Gsd_ForeignReceivablesView>();
  166. //if (_frViews1.Count > 0)
  167. //{
  168. // _frViews.AddRange(_frViews1.Where(x => x.AddingWay != 2).ToList());
  169. // _frViews.AddRange(_frViews1.Where(x => x.AddingWay == 2 && x.Status == 1).ToList());
  170. //}
  171. _frViews.ForEach(x =>
  172. {
  173. string namePrefix = string.Empty;
  174. if (x.AddingWay == 0) namePrefix = $"账单模块-";
  175. else if (x.AddingWay == 1) namePrefix = $"成本预算模块-";
  176. else if (x.AddingWay == 2) namePrefix = $"实际报价-";
  177. x.PriceName = $"{namePrefix}{x.PriceName}";
  178. });
  179. frTotalAmount = _frViews.Sum(it => it.ItemSumPrice);
  180. _giView.Receivables = _frViews;
  181. _giView.ReceivableStr = string.Format(@"应收款合计:{0} CNY(人民币)", frTotalAmount.ConvertToDecimal1().ToString("#0.00"));
  182. /*
  183. * 已收报表
  184. */
  185. decimal prTotalAmount = 0.00M;//已收总金额
  186. string _prSql = string.Format(@"Select pr.Id,pr.Diid,pr.SectionTime As SectionTimeDt,pr.Price,pr.Currency,
  187. sd1.Name As CurrencyCode,sd1.Remark As CurrencyName,pr.Client,
  188. pr.ReceivablesType,sd2.Name As ReceivablesTypeName,pr.Remark,pr.CreateTime
  189. From Fin_ProceedsReceived pr
  190. Left Join Sys_SetData sd1 On pr.Currency = sd1.Id
  191. Left Join Sys_SetData sd2 On pr.ReceivablesType = sd2.Id
  192. Where pr.IsDel = 0 and pr.Diid = {0} Order By CreateTime", _dto.DiId);
  193. List<Gsd_ProceedsReceivedView> _prViews = await _sqlSugar.SqlQueryable<Gsd_ProceedsReceivedView>(_prSql).ToListAsync();
  194. prTotalAmount = _prViews.Sum(it => it.Price);
  195. _giView.ProceedsReceivedViews = _prViews;
  196. _giView.ProceedsReceivedStr = string.Format(@$"应收合计:{frTotalAmount:#0.00} CNY 已收款合计:{prTotalAmount.ConvertToDecimal1():#0.00} CNY");
  197. /*
  198. * 超支费用
  199. */
  200. decimal exTotalAmount = 0.00M;
  201. // string ecSql = string.Format(@"Select gec.Id As GECId,gec.DiId As GECDiId,gec.PriceName,(gec.PriceSum * gec.Coefficient) As PayMoney,sd1.Name As PaymentCurrency,
  202. // (gec.PriceSum * gec.Coefficient * ccp.DayRate) As CNYPrice,ccp.DayRate,ccp.Payee,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  203. // sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant,gec.CreateTime
  204. //From OA2023DB.dbo.Fin_GroupExtraCost gec
  205. //Left Join Grp_CreditCardPayment ccp On gec.Id = ccp.CId
  206. // Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  207. // Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  208. // Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  209. // Left Join Sys_Users u On ccp.CreateUserId = u.Id
  210. //Where ccp.IsDel = 0 And ccp.CTable = 1015 {1} And ccp.DiId = {0} Order By CreateTime", _dto.DiId, _dto.isAudit ? "And ccp.IsAuditGM = 1 And ccp.IsPay = 1 " : " ");
  211. // List<Gsd_ExtraCostsView> _ExtraCostsViews = await _sqlSugar.SqlQueryable<Gsd_ExtraCostsView>(ecSql).ToListAsync();
  212. // #region 超支费用 - 模拟数据
  213. // //if (_ExtraCostsViews.Count < 1)
  214. // //{
  215. // // _ExtraCostsViews.Add(new Gsd_ExtraCostsView()
  216. // // {
  217. // // GECId = 0,
  218. // // GECDiId = 2334,
  219. // // PriceName = "模拟数据-超支费用名称",
  220. // // PayMoney = 1000.00M,
  221. // // PaymentCurrency = "CNY",
  222. // // DayRate = 1.0000M,
  223. // // CNYPrice = 1000.00M,
  224. // // Payee = "模拟数据-超支费用收款方",
  225. // // OrbitalPrivateTransfer = 1,
  226. // // PayWay = "刷卡",
  227. // // CardType = "招行卡",
  228. // // IsPay = 1,
  229. // // Applicant = "刘华举"
  230. // // });
  231. // // _ExtraCostsViews.Add(new Gsd_ExtraCostsView()
  232. // // {
  233. // // GECId = 0,
  234. // // GECDiId = 2334,
  235. // // PriceName = "模拟数据-超支费用名称",
  236. // // PayMoney = 1000.00M,
  237. // // PaymentCurrency = "CNY",
  238. // // DayRate = 1.0000M,
  239. // // CNYPrice = 1000.00M,
  240. // // Payee = "模拟数据-超支费用收款方",
  241. // // OrbitalPrivateTransfer = 1,
  242. // // PayWay = "刷卡",
  243. // // CardType = "招行卡",
  244. // // IsPay = 1,
  245. // // Applicant = "刘华举"
  246. // // });
  247. // //}
  248. // #endregion
  249. // exTotalAmount = _ExtraCostsViews.Sum(it => it.CNYPrice);
  250. // _giView.ExtraCostsViews = _ExtraCostsViews;
  251. // _giView.ExtraCostsStr = string.Format(@"人民币总费用:{0} CNY", exTotalAmount.ConvertToDecimal1().ToString("#0.00"));
  252. /*
  253. * 收款退还
  254. */
  255. decimal promTotalAmount = 0.00M;// 收款退还总金额
  256. List<Gsd_PaymentRefundAndOtherMoneyView> _promView = new List<Gsd_PaymentRefundAndOtherMoneyView>();
  257. //删除了 And prom.PriceType = 1
  258. string _ropSql = string.Format(@"Select u.CnName As Appliction,prom.Id As PrId,prom.DiId As PrDiId,prom.Price As PrPrice,
  259. prom.PriceName AS PrPriceName,prom.CurrencyId As PrCurrencyId,
  260. prom.PayType As PrPayType,prom.PriceType As PrPriceType,
  261. ccp.RMBPrice * ccp.DayRate As RMBPrice,ccp.*,prom.CreateTime As PrCreateTime
  262. From Fin_PaymentRefundAndOtherMoney prom
  263. Left Join Grp_CreditCardPayment ccp On prom.DiId = ccp.DIId And prom.Id = ccp.CId
  264. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  265. Where prom.IsDel = 0
  266. And prom.PayType = 1
  267. And ccp.CTable = 285
  268. {1}
  269. And prom.DiId = {0} Order By PrCreateTime", _dto.DiId, _dto.isAudit ? "And ccp.IsAuditGM = 1" : " ");
  270. var _promDatas = await _sqlSugar.SqlQueryable<Gsd_PaymentRefundAndOtherMoneyDataSource1View>(_ropSql).ToListAsync();
  271. foreach (var ropItem in _promDatas)
  272. {
  273. string thisCueencyCode = "Unknown";
  274. string thisCueencyName = "Unknown";
  275. var currency = _setDatas.Where(it => it.Id == ropItem.PaymentCurrency).FirstOrDefault();
  276. if (currency != null)
  277. {
  278. thisCueencyCode = currency.Name;
  279. thisCueencyName = currency.Remark;
  280. }
  281. string orbitalPrivateTransferStr = "Unknown";
  282. var orbitalPrivateTransfer = _setDatas.Where(it => it.Id == ropItem.OrbitalPrivateTransfer).FirstOrDefault();
  283. if (orbitalPrivateTransfer != null)
  284. {
  285. orbitalPrivateTransferStr = orbitalPrivateTransfer.Name;
  286. }
  287. string payStr = "Unknown";
  288. var pay = _setDatas.Where(it => it.Id == ropItem.PayDId).FirstOrDefault();
  289. if (pay != null)
  290. {
  291. payStr = pay.Name;
  292. }
  293. Gsd_PaymentRefundAndOtherMoneyView gsd_PaymentRefund = new Gsd_PaymentRefundAndOtherMoneyView()
  294. {
  295. Id = ropItem.Id,
  296. DiId = ropItem.DIId,
  297. PriceName = ropItem.PrPriceName,
  298. PayCurrencyCode = thisCueencyCode,
  299. PayCurrencyName = thisCueencyName,
  300. Price = ropItem.PrPrice,
  301. CNYPrice = ropItem.PayMoney * ropItem.DayRate,
  302. ThisRate = ropItem.DayRate,
  303. Payee = ropItem.Payee,
  304. PayTime = ropItem.AuditGMDate,
  305. OrbitalPrivateTransfer = ropItem.OrbitalPrivateTransfer,
  306. PayType = payStr,
  307. IsPay = ropItem.IsPay,
  308. Applicant = ropItem.Appliction
  309. };
  310. _promView.Add(gsd_PaymentRefund);
  311. }
  312. #region 收款退还 - 模拟数据
  313. //if (_promView.Count < 1)
  314. //{
  315. // _promView.Add(new Gsd_PaymentRefundAndOtherMoneyView()
  316. // {
  317. // Id = 0,
  318. // DiId = 2334,
  319. // PriceName = "模拟数据-费用名称",
  320. // PayCurrencyCode = "CNY",
  321. // PayCurrencyName = "人民币",
  322. // Price = 1000.00M,
  323. // CNYPrice = 1000.00M,
  324. // ThisRate = 1.00M,
  325. // Payee = "模拟数据-收款方",
  326. // PayTime = "2023-01-01 15:20:01",
  327. // OrbitalPrivateTransfer = 1,
  328. // PayType = "刷卡",
  329. // IsPay = 1,
  330. // Applicant = "刘华举"
  331. // });
  332. // _promView.Add(new Gsd_PaymentRefundAndOtherMoneyView()
  333. // {
  334. // Id = 0,
  335. // DiId = 2334,
  336. // PriceName = "模拟数据-费用名称",
  337. // PayCurrencyCode = "CNY",
  338. // PayCurrencyName = "人民币",
  339. // Price = 1000.00M,
  340. // CNYPrice = 1000.00M,
  341. // ThisRate = 1.00M,
  342. // Payee = "模拟数据-收款方",
  343. // PayTime = "2023-01-01 15:20:01",
  344. // OrbitalPrivateTransfer = 1,
  345. // PayType = "刷卡",
  346. // IsPay = 1,
  347. // Applicant = "刘华举"
  348. // });
  349. //}
  350. #endregion
  351. promTotalAmount = _promView.Sum(it => it.CNYPrice);
  352. _giView.PaymentRefundAndOtherMoneyViews = _promView;
  353. _giView.PaymentRefundAndOtherMoneyStr = string.Format(@"人民币总费用:{0} CNY", promTotalAmount.ConvertToDecimal1().ToString("#0.00"));
  354. decimal BalancePayment = frTotalAmount - prTotalAmount + promTotalAmount;
  355. _view.GroupIncome = _giView;
  356. _view.GroupIncomeStr = string.Format(@"<span style='color:red;'>剩余尾款:{0} CNY(包含了收款退还费用数据)</span>", BalancePayment.ConvertToDecimal1().ToString("#0.00"));
  357. #endregion
  358. #region 团组支出
  359. GroupExpenditureView _geView = new GroupExpenditureView();
  360. #region 酒店预定费用
  361. List<GroupHotelFeeView> groupHotelFeeViews = new List<GroupHotelFeeView>();
  362. //ccp.RMBPrice As CNYPrice
  363. //(((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice
  364. string hotelFeeSql = string.Format(@"
  365. SELECT
  366. hr.Id AS HrId,
  367. hr.DiId AS HrDiId,
  368. hr.City,
  369. hr.HotelName,
  370. hr.CheckInDate,
  371. hr.CheckOutDate,
  372. hr.CardPrice AS RoomPrice,
  373. sd1.Name AS PaymentCurrency,
  374. hr.SingleRoomPrice,
  375. hr.SingleRoomCount,
  376. hr.DoubleRoomPrice,
  377. hr.DoubleRoomCount,
  378. hr.SuiteRoomPrice,
  379. hr.SuiteRoomCount,
  380. hr.OtherRoomPrice,
  381. hr.OtherRoomCount,
  382. hr.BreakfastPrice,
  383. sd4.Name AS BreakfastCurrency,
  384. hr.Isoppay,
  385. hr.GovernmentRent,
  386. sd5.Name AS GovernmentRentCurrency,
  387. hr.CityTax,
  388. sd6.Name AS CityTaxCurrency,
  389. ccp.PayMoney,
  390. (
  391. ((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100
  392. ) AS CNYPrice,
  393. ccp.PayPercentage,
  394. ccp.DayRate,
  395. ccp.Payee,
  396. ccp.OrbitalPrivateTransfer,
  397. sd2.Name AS PayWay,
  398. sd3.Name AS CardType,
  399. ccp.IsPay,
  400. u.CnName AS Applicant
  401. FROM
  402. Grp_HotelReservations hr
  403. INNER JOIN Grp_CreditCardPayment ccp ON hr.Id = ccp.CId
  404. LEFT JOIN Sys_SetData sd1 ON ccp.PaymentCurrency = sd1.Id
  405. LEFT JOIN Sys_SetData sd2 ON ccp.PayDId = sd2.Id
  406. LEFT JOIN Sys_SetData sd3 ON ccp.CTDId = sd3.Id
  407. LEFT JOIN Sys_Users u ON ccp.CreateUserId = u.Id
  408. LEFT JOIN Sys_SetData sd4 ON hr.BreakfastCurrency = sd4.Id
  409. LEFT JOIN Sys_SetData sd5 ON hr.GovernmentRentCurrency = sd5.Id
  410. LEFT JOIN Sys_SetData sd6 ON hr.CityTaxCurrency = sd6.Id
  411. WHERE
  412. hr.IsDel = 0
  413. AND ccp.IsDel = 0
  414. AND ccp.CTable = 76 {1}
  415. AND ccp.PayMoney <> 0
  416. AND hr.DiId = {0}
  417. ORDER BY
  418. CheckInDate Asc", _dto.DiId, _dto.isAudit ? "AND (ccp.IsAuditGM = 1 Or ccp.IsAuditGM = 3)" : " ");
  419. groupHotelFeeViews = await _sqlSugar.SqlQueryable<GroupHotelFeeView>(hotelFeeSql).ToListAsync();
  420. List<int> hotelSubIds = groupHotelFeeViews.Select(it => it.HrId).ToList();
  421. List<Grp_HotelReservationsContent> groupHotelContentFeeViews = new List<Grp_HotelReservationsContent>();
  422. groupHotelContentFeeViews = await _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => hotelSubIds.Contains(it.HrId)).ToListAsync();
  423. decimal HotelCNYTotalPrice = 0.00M;
  424. var teamRateData = await _teamRateRep.PostGroupRateInfoByDiId(_dto.DiId);
  425. foreach (var item in groupHotelFeeViews)
  426. {
  427. if (groupHotelContentFeeViews.Count > 0)
  428. {
  429. string paymentStr = string.Empty;
  430. var roomData = groupHotelContentFeeViews.Find(it => it.HrId == item.HrId && it.PriceType == 1); //房费
  431. item.RoomPrice = roomData?.Price ?? 0.00M;
  432. if (item.RoomPrice != 0)
  433. {
  434. if (roomData.IsPay == 0) paymentStr += $"房费:未付款<br/>";
  435. item.RoomPriceCurrency = _setDatas.Find(it => it.Id == roomData?.Currency)?.Name;
  436. string feeMark1 = roomData?.OrbitalPrivateTransfer == 0 ? "公转" : "私转";
  437. string isFeeMark1 = roomData?.IsOppay == 1 ? "是" : "否";
  438. item.RoomInfoTips = @$"当时汇率:{roomData?.Rate.ToString("#0.0000")} <br/>
  439. 收款方:{roomData?.Payee}<br/>
  440. 费用标识:{feeMark1} <br/>
  441. 支付方式:{_setDatas.Find(it => it.Id == roomData?.PayDId)?.Name} <br/>
  442. 卡类型:{_setDatas.Find(it => it.Id == roomData?.CTDId)?.Name}<br/>
  443. 是否由地接支付:{isFeeMark1} <br/>";
  444. }
  445. var breakfastData = groupHotelContentFeeViews.Find(it => it.HrId == item.HrId && it.PriceType == 2); //早餐
  446. item.BreakfastPrice = breakfastData?.Price ?? 0.00M;
  447. if (item.BreakfastPrice != 0)
  448. {
  449. if (breakfastData.IsPay == 0) paymentStr += $"早餐:未付款<br/>";
  450. item.BreakfastCurrency = _setDatas.Find(it => it.Id == breakfastData?.Currency)?.Name;
  451. string feeMark2 = breakfastData?.OrbitalPrivateTransfer == 0 ? "公转" : "私转";
  452. string isFeeMark2 = breakfastData?.IsOppay == 1 ? "是" : "否";
  453. item.BreakfastInfoTips = @$"当时汇率:{breakfastData?.Rate.ToString("#0.0000")} <br/>
  454. 收款方:{breakfastData?.Payee}<br/>
  455. 费用标识:{feeMark2} <br/>
  456. 支付方式:{_setDatas.Find(it => it.Id == roomData?.PayDId)?.Name} <br/>
  457. 卡类型:{_setDatas.Find(it => it.Id == roomData?.CTDId)?.Name} <br/>
  458. 是否由地接支付:{isFeeMark2} <br/>";
  459. }
  460. var landTaxData = groupHotelContentFeeViews.Find(it => it.HrId == item.HrId && it.PriceType == 3); //地税
  461. item.GovernmentRent = landTaxData?.Price ?? 0.00M;
  462. if (item.GovernmentRent != 0)
  463. {
  464. if (landTaxData.IsPay == 0) paymentStr += $"地税:未付款<br/>";
  465. item.GovernmentRentCurrency = _setDatas.Find(it => it.Id == landTaxData?.Currency)?.Name;
  466. string feeMark3 = landTaxData?.OrbitalPrivateTransfer == 0 ? "公转" : "私转";
  467. string isFeeMark3 = landTaxData?.IsOppay == 1 ? "是" : "否";
  468. item.GovernmentRentTips = @$"当时汇率:{landTaxData?.Rate.ToString("#0.0000")} <br/>
  469. 收款方:{landTaxData?.Payee}<br/>
  470. 费用标识:{feeMark3} <br/>
  471. 支付方式:{_setDatas.Find(it => it.Id == landTaxData?.PayDId)?.Name} <br/>
  472. 卡类型:{_setDatas.Find(it => it.Id == landTaxData?.CTDId)?.Name} <br/>
  473. 是否由地接支付:{isFeeMark3} <br/>";
  474. }
  475. var cityTaxData = groupHotelContentFeeViews.Find(it => it.HrId == item.HrId && it.PriceType == 4); //城市税
  476. item.CityTax = cityTaxData?.Price ?? 0.00M;
  477. if (item.CityTax != 0)
  478. {
  479. if (cityTaxData.IsPay == 0) paymentStr += $"城市税:未付款<br/>";
  480. item.CityTaxCurrency = _setDatas.Find(it => it.Id == cityTaxData?.Currency)?.Name;
  481. string feeMark4 = cityTaxData?.OrbitalPrivateTransfer == 0 ? "公转" : "私转";
  482. string isFeeMark4 = landTaxData?.IsOppay == 1 ? "是" : "否";
  483. item.CityTaxTips = @$"当时汇率:{cityTaxData?.Rate.ToString("#0.0000")} <br/>
  484. 收款方:{cityTaxData?.Payee}<br/>
  485. 费用标识:{feeMark4} <br/>
  486. 支付方式:{_setDatas.Find(it => it.Id == cityTaxData?.PayDId)?.Name} <br/>
  487. 卡类型:{_setDatas.Find(it => it.Id == cityTaxData?.CTDId)?.Name} <br/>
  488. 是否由地接支付:{isFeeMark4} <br/>";
  489. }
  490. if (!string.IsNullOrEmpty(paymentStr))
  491. {
  492. item.IsPay = 2;
  493. item.PayTips = paymentStr;
  494. }
  495. }
  496. else
  497. {
  498. decimal roomPrice = (item.SingleRoomCount * item.SingleRoomPrice) +
  499. (item.DoubleRoomCount * item.DoubleRoomPrice) +
  500. (item.SuiteRoomCount * item.SuiteRoomPrice) +
  501. (item.OtherRoomCount * item.OtherRoomPrice);
  502. //item.RoomPrice = item.CardPrice;
  503. item.RoomPriceCurrency = item.PaymentCurrency;
  504. }
  505. HotelCNYTotalPrice += item.CNYPrice;
  506. item.PayMoney = item.PayMoney.ConvertToDecimal1();
  507. item.CNYPrice = item.CNYPrice.ConvertToDecimal1();
  508. }
  509. _geView.GroupHotelFeeViews = groupHotelFeeViews;
  510. _geView.GroupHotelFeeStr = string.Format(@"人民币总费用:{0} CNY", HotelCNYTotalPrice.ToString("#0.00"));
  511. #endregion
  512. #region 地接费用
  513. List<GroupCTGGRFeeView> groupCTGGRFeeViews = new List<GroupCTGGRFeeView>();
  514. string CTGGRFeeSql = string.Format(@"Select ctggr.Id As CTGGRId,ctggr.DiId As CTGGRDiId,ctggr.PriceName As Area,ctggrc.*,ctggrc.Price As PayMoney,
  515. sd2.name As PaymentCurrency,ccp.PayPercentage,
  516. (ctggrc.Price * (ccp.PayPercentage / 100)) As AmountPaid,
  517. (ctggrc.Price - ctggrc.Price * (ccp.PayPercentage / 100)) As BalancePayment,
  518. ccp.DayRate,(ctggrc.Price * (ccp.PayPercentage / 100) * ccp.DayRate) As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  519. ccp.OrbitalPrivateTransfer,sd1.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ctggr.CreateTime
  520. From Grp_CarTouristGuideGroundReservations ctggr
  521. Left Join ( Select cggrc.CTGGRId,sd1.Name As PriceName,cggrc.Price*cggrc.Count As Price,sd2.Name As PriceCurrency,
  522. cggrc.DatePrice,cggrc.PriceContent
  523. From Grp_CarTouristGuideGroundReservationsContent cggrc
  524. Left Join Sys_SetData sd1 On cggrc.SId = sd1.Id
  525. Left Join Sys_SetData sd2 On cggrc.Currency = sd2.Id
  526. Where cggrc.ISdel = 0 And cggrc.Price != 0.00
  527. ) ctggrc On ctggr.Id = ctggrc.CTGGRId
  528. Left Join Grp_CreditCardPayment ccp On ccp.IsDel = 0 And ccp.CTable = 79 And ctggr.Id = ccp.CId
  529. Left Join Sys_SetData sd1 On ccp.PayDId = sd1.Id
  530. Left Join Sys_SetData sd2 On ccp.PaymentCurrency = sd2.Id
  531. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  532. Where ctggr.IsDel = 0 {1} And ctggr.DiId = {0}
  533. Order By CreateTime", _dto.DiId, _dto.isAudit ? "And (ccp.IsAuditGM = 1 OR ccp.IsAuditGM = 3)" : " ");
  534. groupCTGGRFeeViews = await _sqlSugar.SqlQueryable<GroupCTGGRFeeView>(CTGGRFeeSql).ToListAsync();
  535. string CTGGRFeeStr = "";
  536. decimal CTGGRCNYTotalPrice = 0.00M;
  537. //按1 地区,2 币种,3 汇率 分组计算
  538. var groupCTGGRFeeDatas = groupCTGGRFeeViews.GroupBy(it => it.Area);
  539. foreach (var ctggfr in groupCTGGRFeeDatas)
  540. {
  541. var ctggfr_curr = ctggfr.GroupBy(it => it.PaymentCurrency);
  542. if (ctggfr_curr.Count() > 0)
  543. {
  544. foreach (var curr in ctggfr_curr)
  545. {
  546. var ctggfr_rate = curr.GroupBy(it => it.DayRate);
  547. if (ctggfr_rate.Count() > 0)
  548. {
  549. foreach (var rate in ctggfr_rate)
  550. {
  551. CTGGRFeeStr += string.Format(@$"{ctggfr.Key} 总费用:{rate.Sum(it => it.AmountPaid).ToString("#0.00")}
  552. {rate.FirstOrDefault()?.PaymentCurrency}(人民币:
  553. {rate.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00"))).ToString("#0.00")} CNY 当时支付汇率:
  554. {rate.FirstOrDefault()?.DayRate.ToString("#0.0000")})\r\n");
  555. CTGGRCNYTotalPrice += rate.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  556. }
  557. }
  558. else
  559. {
  560. CTGGRFeeStr += string.Format(@$"{ctggfr.Key} 总费用:{curr.Sum(it => it.AmountPaid).ToString("#0.00")}
  561. {curr.FirstOrDefault()?.PaymentCurrency}(人民币:
  562. {curr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00"))).ToString("#0.00")} CNY 当时支付汇率:
  563. {curr.FirstOrDefault()?.DayRate.ToString("#0.0000")})\r\n");
  564. CTGGRCNYTotalPrice += curr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  565. }
  566. }
  567. }
  568. else
  569. {
  570. CTGGRFeeStr += string.Format(@$"{ctggfr.Key} 总费用:{ctggfr.Sum(it => it.AmountPaid).ToString("#0.00")}
  571. {ctggfr.FirstOrDefault()?.PaymentCurrency}(人民币:
  572. {ctggfr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00"))).ToString("#0.00")} CNY 当时支付汇率:
  573. {ctggfr.FirstOrDefault()?.DayRate.ToString("#0.0000")})\r\n");
  574. CTGGRCNYTotalPrice += ctggfr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  575. }
  576. }
  577. foreach (var item in groupCTGGRFeeViews)
  578. {
  579. if (!string.IsNullOrEmpty(item.AuditGMDate))
  580. {
  581. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  582. }
  583. if (item.DatePrice != null)
  584. {
  585. item.PriceName = $"{item.PriceName}({Convert.ToDateTime(item.DatePrice).ToString("yyyy-MM-dd")})";
  586. }
  587. //CTGGRFeeStr += string.Format(@"{0} 总费用:{1} {2}(人民币:{3} CNY 当时支付汇率:{4})\r\n",
  588. // item.Area, item.AmountPaid.ConvertToDecimal1().ToString("#0.00"), item.PaymentCurrency, item.CNYPrice.ToString("#0.0000"), item.DayRate.ToString("#0.0000"));
  589. //CTGGRCNYTotalPrice += item.CNYPrice;
  590. }
  591. _geView.GroupCTGGRFeeViews = groupCTGGRFeeViews;
  592. _geView.GroupCTGGRFeeStr = string.Format(@"{0}人民币总费用:{1} CNY", CTGGRFeeStr, CTGGRCNYTotalPrice.ToString("#0.00"));
  593. #endregion
  594. #region 机票预订费用
  595. //(((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice
  596. //ccp.RMBPrice As CNYPrice
  597. List<GroupAirFeeView> groupAirFeeViews = new List<GroupAirFeeView>();
  598. string groupAirFeeSql = string.Format(@"Select atr.Id As AirId,atr.DIId As AirDiId,atr.FlightsCode,atr.FlightsCity,sd4.Name As AirTypeName,
  599. atr.FlightsDate,atr.FlightsTime,atr.ClientName,atr.ClientNum,ccp.PayMoney,
  600. sd1.Name As PayMoneyCurrency,(((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice,ccp.DayRate,ccp.Payee,ccp.AuditGMDate,
  601. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant,atr.CreateTime,
  602. atr.CType
  603. From Grp_AirTicketReservations atr
  604. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 85 And atr.Id = ccp.CId
  605. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  606. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  607. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  608. Left Join Sys_SetData sd4 On atr.CType = sd4.Id
  609. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  610. Where atr.IsDel = 0 {1} And atr.DiId = {0} Order By CreateTime", _dto.DiId, _dto.isAudit ? "And ccp.IsAuditGM = 1" : " ");
  611. groupAirFeeViews = await _sqlSugar.SqlQueryable<GroupAirFeeView>(groupAirFeeSql).ToListAsync();
  612. string str = "";
  613. List<dynamic> airClientPris = new List<dynamic>();
  614. decimal AirCNYTotalPrice = 0.00M;
  615. decimal JJCCNYTotalPrice = 0.00M, JJCPeopleNum = 0.00M, JJCAveragePrice = 0.00M;
  616. decimal GWCCNYTotalPrice = 0.00M, GWCPeopleNum = 0.00M, GWCAveragePrice = 0.00M;
  617. //if (groupAirFeeViews.Count > 0)
  618. //{
  619. // JJCCNYTotalPrice = groupAirFeeViews.Where(it => it.AirTypeName.Equals("经济舱")).Sum(it => it.CNYPrice);
  620. // JJCPeopleNum = groupAirFeeViews.Where(it => it.AirTypeName.Equals("经济舱")).Sum(it => it.ClientNum);
  621. // JJCAveragePrice = (JJCCNYTotalPrice / JJCPeopleNum).ConvertToDecimal1();
  622. // GWCCNYTotalPrice = groupAirFeeViews.Where(it => it.AirTypeName.Equals("公务舱")).Sum(it => it.CNYPrice);
  623. // GWCPeopleNum = groupAirFeeViews.Where(it => it.AirTypeName.Equals("公务舱")).Sum(it => it.ClientNum);
  624. // GWCAveragePrice = (GWCCNYTotalPrice / GWCPeopleNum).ConvertToDecimal1();
  625. //}
  626. int Index = 0;
  627. foreach (var item in groupAirFeeViews)
  628. {
  629. if (item.AirId > 2924)
  630. {
  631. string itemClientName = "";
  632. if (!string.IsNullOrEmpty(item.ClientName))
  633. {
  634. System.Text.RegularExpressions.Match m_EnName = Regex.Match(item.ClientName, @"[A-Za-z]+");
  635. System.Text.RegularExpressions.Match m_ZHName = Regex.Match(item.ClientName, @"[\u4e00-\u9fa5]");
  636. if (m_EnName.Success || m_ZHName.Success)
  637. {
  638. itemClientName = item.ClientName;
  639. decimal unitCost = 0.00M;
  640. AirCNYTotalPrice += item.CNYPrice;
  641. continue;
  642. }
  643. string[] clientIds = new string[] { };
  644. if (item.ClientName.Contains(','))
  645. {
  646. clientIds = item.ClientName.Split(',');
  647. }
  648. else
  649. {
  650. clientIds = new string[] { item.ClientName };
  651. }
  652. if (clientIds.Length > 0)
  653. {
  654. int[] output = Array.ConvertAll<string, int>(clientIds, delegate (string s) { return int.Parse(s); });
  655. if (output.Contains(-1))
  656. {
  657. itemClientName += $@"行程单";
  658. output = output.Where(val => val != -1).ToArray();
  659. }
  660. var clients = _clientDatas.Where(it => output.Contains(it.Id)).ToList();
  661. decimal unitCost = 0.00M;
  662. unitCost = (item.PayMoney / item.ClientNum).ConvertToDecimal1();
  663. int clienIndex = 1;
  664. foreach (var client in clients)
  665. {
  666. airClientPris.Add(new
  667. {
  668. CnName = client.LastName + client.FirstName,
  669. EnName = client.Pinyin,
  670. Price = unitCost,
  671. AirType = item.AirTypeName
  672. });
  673. string six = "";
  674. if (client.Sex == 0) six = "Mr";
  675. else if (client.Sex == 1) six = "Ms";
  676. itemClientName += string.Format(@"{0}.{1} {2};", clienIndex, client.LastName + client.FirstName, six);
  677. clienIndex++;
  678. }
  679. }
  680. }
  681. item.ClientName = itemClientName;
  682. }
  683. else
  684. {
  685. string clientPinYinName = "";
  686. decimal unitCost = 0.00M;
  687. int cNum = item.ClientNum == 0 ? 1 : item.ClientNum;
  688. unitCost = (item.PayMoney / cNum).ConvertToDecimal1();
  689. Regex r = new Regex("[0-9]");
  690. string name1 = item.ClientName;
  691. name1 = r.Replace(name1, "");
  692. string[] clientNames = name1.Split('.');
  693. for (int i = 0; i < item.ClientNum; i++)
  694. {
  695. string name = "";
  696. if (clientNames.Length > 0)
  697. {
  698. int index = i + 1;
  699. if (index < clientNames.Length)
  700. {
  701. name = clientNames[index].Replace("MR", "").Replace("MS", "").Trim();
  702. if (!string.IsNullOrEmpty(name))
  703. {
  704. airClientPris.Add(new
  705. {
  706. CnName = name,
  707. EnName = name,
  708. Price = unitCost,
  709. AirType = item.AirTypeName
  710. });
  711. }
  712. //if (name.Length > 0)
  713. //{
  714. // string nameLastStr = name[name.Length - 1].ToString();
  715. // if (nameLastStr.IsNumeric())
  716. // {
  717. // name = name.Substring(0, name.Length - 1).Trim();
  718. // }
  719. //}
  720. }
  721. }
  722. clientPinYinName += string.Format(@"{0}.{1}出票价为:{2} CNY;", Index + 1, name, unitCost.ToString("#0.00"));
  723. }
  724. }
  725. if (!string.IsNullOrEmpty(item.AuditGMDate))
  726. {
  727. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  728. }
  729. AirCNYTotalPrice += item.CNYPrice;
  730. }
  731. _geView.GroupAirFeeViews = groupAirFeeViews;
  732. if (airClientPris.Count > 0)
  733. {
  734. var peoplePriStr = "";
  735. var airClientPris1 = airClientPris.GroupBy(item => item.CnName)
  736. .Select(group => group.First())
  737. .ToList();
  738. int airClientPrisIndex = 1;
  739. foreach (var item in airClientPris1)
  740. {
  741. decimal price = 0.00M;
  742. var prices = airClientPris.Where(it => it.CnName == item.CnName).ToList();
  743. foreach (var pri in prices)
  744. {
  745. price += pri.Price;
  746. }
  747. peoplePriStr += $@"{airClientPrisIndex}.{item.EnName}出票价为: {price.ToString("#0.00")} CNY;";
  748. airClientPrisIndex++;
  749. }
  750. if (!string.IsNullOrEmpty(peoplePriStr))
  751. {
  752. str = $@"其中:{peoplePriStr}";
  753. }
  754. //经济舱均价
  755. var airJJCPris = airClientPris.Where(it => it.AirType == "经济舱").ToList();
  756. if (airJJCPris.Count > 0)
  757. {
  758. decimal jjcTotalPrice = 0.00M;
  759. foreach (var item in airJJCPris)
  760. {
  761. jjcTotalPrice += item.Price;
  762. }
  763. decimal jjcPeopleNum = airJJCPris.GroupBy(item => item.CnName)
  764. .Select(group => group.First())
  765. .ToList().Count;
  766. JJCAveragePrice = jjcTotalPrice / jjcPeopleNum;
  767. }
  768. //公务舱均价
  769. var airGWCPris = airClientPris.Where(it => it.AirType == "公务舱").ToList();
  770. if (airGWCPris.Count > 0)
  771. {
  772. decimal gwcTotalPrice = 0.00M;
  773. foreach (var item in airGWCPris)
  774. {
  775. gwcTotalPrice += item.Price;
  776. }
  777. decimal gwcPeopleNum = airGWCPris.GroupBy(item => item.CnName)
  778. .Select(group => group.First())
  779. .ToList().Count;
  780. GWCAveragePrice = gwcTotalPrice / gwcPeopleNum;
  781. }
  782. }
  783. _geView.GroupAirFeeStr = $@"人民币总费用:{AirCNYTotalPrice.ToString("#0.00")} CNY\r\n{str}\r\n经济舱均价为:{JJCAveragePrice.ToString("#0.00")}CNY/人;公务舱均价为:{GWCAveragePrice.ToString("#0.00")}CNY/人;";
  784. #endregion
  785. #region 签证费用
  786. List<GroupVisaFeeView> groupVisaFeeViews = new List<GroupVisaFeeView>();
  787. string groupVisaFeeSql = string.Format(@"Select vi.Id As VisaId,vi.DIId As VisaDiId,vi.VisaClient,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  788. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  789. sd3.Name As CardTypeName,ccp.IsPay,u.CnName As Applicant,vi.CreateTime,
  790. (((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice
  791. From Grp_VisaInfo vi
  792. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 80 And vi.Id = ccp.CId
  793. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  794. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  795. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  796. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  797. Where vi.IsDel = 0 {1} And vi.DIId = {0} Order By CreateTime", _dto.DiId, _dto.isAudit ? "And ccp.IsAuditGM = 1" : " ");
  798. groupVisaFeeViews = await _sqlSugar.SqlQueryable<GroupVisaFeeView>(groupVisaFeeSql).ToListAsync();
  799. decimal VisaCNYTotalPirce = 0.00M;
  800. foreach (var item in groupVisaFeeViews)
  801. {
  802. string itemClientName = "";
  803. string visaClients = item.VisaClient;
  804. if (!string.IsNullOrEmpty(visaClients))
  805. {
  806. string[] clientIds = new string[] { };
  807. if (visaClients.Contains(','))
  808. {
  809. clientIds = visaClients.Split(',');
  810. }
  811. else
  812. {
  813. clientIds = new string[] { visaClients };
  814. }
  815. if (clientIds.Length > 0)
  816. {
  817. List<int> clientIds1 = new List<int>() { };
  818. foreach (var clientIdStr in clientIds)
  819. {
  820. if (clientIdStr.IsNumeric())
  821. {
  822. clientIds1.Add(int.Parse(clientIdStr));
  823. }
  824. }
  825. if (clientIds1.Count > 0)
  826. {
  827. var clients = _clientDatas.Where(it => clientIds1.Contains(it.Id)).ToList();
  828. foreach (var client in clients)
  829. {
  830. itemClientName += $"{client.LastName + client.FirstName},";
  831. }
  832. }
  833. else
  834. {
  835. itemClientName = visaClients;
  836. }
  837. }
  838. }
  839. if (itemClientName.Length > 0)
  840. {
  841. itemClientName = itemClientName.Substring(0, itemClientName.Length - 1);
  842. }
  843. item.VisaClient = itemClientName;
  844. VisaCNYTotalPirce += item.CNYPrice;
  845. if (!string.IsNullOrEmpty(item.AuditGMDate))
  846. {
  847. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  848. }
  849. }
  850. _geView.GroupVisaFeeViews = groupVisaFeeViews;
  851. _geView.GroupVisaFeeStr = string.Format(@"人民币总费用:{0} CNY", VisaCNYTotalPirce.ConvertToDecimal1().ToString("#.00"));
  852. #endregion
  853. #region 邀请/公务活动 CTable = 81
  854. List<GroupInvitationalFeeView> groupInvitationalFeeViews = new List<GroupInvitationalFeeView>();
  855. string groupInvitationalFeeSql = string.Format(@"Select ioa.Id As IOAId,ioa.DiId As IOADiId,ioa.InviterArea,ioa.Inviter,ioa.InviteTime,
  856. ioa.InviteCost,sd3.Name As InviteCurrency,ioa.SendCost,sd4.Name As SendCurrency,ioa.EventsCost,
  857. sd5.Name As EventsCurrency,ioa.TranslateCost,sd6.Name As TranslateCurrency,ccp.PayMoney,
  858. sd7.Name As PaymentCurrency,ccp.RMBPrice As CNYPrice,
  859. (((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice2,ccp.Payee,ccp.AuditGMDate,
  860. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ioa.CreateTime
  861. From Grp_InvitationOfficialActivities ioa
  862. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 81 And ioa.Id = ccp.CId
  863. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  864. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  865. Left Join Sys_SetData sd3 On ioa.InviteCurrency = sd3.Id
  866. Left Join Sys_SetData sd4 On ioa.SendCurrency = sd4.Id
  867. Left Join Sys_SetData sd5 On ioa.EventsCurrency = sd5.Id
  868. Left Join Sys_SetData sd6 On ioa.TranslateCurrency = sd6.Id
  869. Left Join Sys_SetData sd7 On ccp.PaymentCurrency = sd7.Id
  870. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  871. Where ioa.IsDel = 0 {1} And ioa.Diid = {0} Order By CreateTime", _dto.DiId, _dto.isAudit ? "And ccp.IsAuditGM = 1" : " ");
  872. groupInvitationalFeeViews = await _sqlSugar.SqlQueryable<GroupInvitationalFeeView>(groupInvitationalFeeSql).ToListAsync();
  873. #region 邀请/公务活动 - 模拟数据
  874. //if (groupInvitationalFeeViews.Count < 1)
  875. //{
  876. // groupInvitationalFeeViews.Add(new GroupInvitationalFeeView()
  877. // {
  878. // IOAId = 0,
  879. // IOADiId = 2334,
  880. // InviterArea = "模拟数据-邀请方地区",
  881. // Inviter = "模拟数据-邀请方",
  882. // InviteTime = "2023-10-10",
  883. // InviteCost = 100.00M,
  884. // InviteCurrency = "EUR",
  885. // SendCost = 100.00M,
  886. // SendCurrency = "EUR",
  887. // EventsCost = 10000.00M,
  888. // EventsCurrency = "EUR",
  889. // TranslateCost = 300.00M,
  890. // TranslateCurrency = "EUR",
  891. // PayMoney = 10500.00M,
  892. // PaymentCurrency = "EUR",
  893. // CNYPrice = 76765.50M,
  894. // Payee = "模拟数据-收款方",
  895. // AuditGMDate = "2023-12-05",
  896. // OrbitalPrivateTransfer = 1,
  897. // PayWay = "刷卡",
  898. // IsPay = 1,
  899. // Applicant = "刘华举"
  900. // });
  901. // groupInvitationalFeeViews.Add(new GroupInvitationalFeeView()
  902. // {
  903. // IOAId = 0,
  904. // IOADiId = 2334,
  905. // InviterArea = "模拟数据-邀请方地区",
  906. // Inviter = "模拟数据-邀请方",
  907. // InviteTime = "2023-10-10",
  908. // InviteCost = 100.00M,
  909. // InviteCurrency = "EUR",
  910. // SendCost = 100.00M,
  911. // SendCurrency = "EUR",
  912. // EventsCost = 10000.00M,
  913. // EventsCurrency = "EUR",
  914. // TranslateCost = 300.00M,
  915. // TranslateCurrency = "EUR",
  916. // PayMoney = 10500.00M,
  917. // PaymentCurrency = "EUR",
  918. // CNYPrice = 76765.50M,
  919. // Payee = "模拟数据-收款方",
  920. // AuditGMDate = "2023-12-05",
  921. // OrbitalPrivateTransfer = 1,
  922. // PayWay = "刷卡",
  923. // IsPay = 1,
  924. // Applicant = "刘华举"
  925. // });
  926. //}
  927. #endregion
  928. decimal InvitationalCNYTotalPrice = 0.00M;
  929. foreach (var item in groupInvitationalFeeViews)
  930. {
  931. InvitationalCNYTotalPrice += item.CNYPrice2;
  932. if (!string.IsNullOrEmpty(item.AuditGMDate))
  933. {
  934. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  935. }
  936. string currencyRateStr = "";
  937. List<string> currencys = new List<string>();
  938. if (!string.IsNullOrEmpty(item.InviteCurrency)) currencys.Add(item.InviteCurrency);
  939. if (!string.IsNullOrEmpty(item.SendCurrency)) currencys.Add(item.SendCurrency);
  940. if (!string.IsNullOrEmpty(item.EventsCurrency)) currencys.Add(item.EventsCurrency);
  941. if (!string.IsNullOrEmpty(item.TranslateCurrency)) currencys.Add(item.TranslateCurrency);
  942. if (!string.IsNullOrEmpty(item.PaymentCurrency)) currencys.Add(item.PaymentCurrency);
  943. currencyRateStr = await GeneralMethod.PostGroupRateByCTableAndCurrency(teamRateData, 81, currencys);
  944. item.CurrencyRateStr = currencyRateStr;
  945. }
  946. _geView.GroupInvitationalFeeViews = groupInvitationalFeeViews;
  947. _geView.GroupInvitationalFeeStr = string.Format(@"人民币总费用:{0} CNY", InvitationalCNYTotalPrice.ToString("#.00"));
  948. #endregion
  949. #region 保险费用
  950. List<GroupInsuranceFeeView> groupInsuranceFeeViews = new List<GroupInsuranceFeeView>();
  951. string groupInsuranceFeeSql = string.Format(@"Select ic.Id As InsuranceId,ic.Diid As InsuranceDiId,ClientName,ccp.PayMoney,ccp.PayMoney * ccp.DayRate As CNYPrice,
  952. sd1.Name As PayMoneyCurrency,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  953. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ic.CreateTime
  954. From Grp_Customers ic
  955. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 82 And ic.Id = ccp.CId
  956. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  957. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  958. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  959. Where ic.IsDel = 0 {1} And ic.DiId = {0} Order By CreateTime", _dto.DiId, _dto.isAudit ? "And ccp.IsAuditGM = 1" : " ");
  960. groupInsuranceFeeViews = await _sqlSugar.SqlQueryable<GroupInsuranceFeeView>(groupInsuranceFeeSql).ToListAsync();
  961. decimal InsuranceCNYTotalPrice = 0.00M;
  962. foreach (var item in groupInsuranceFeeViews)
  963. {
  964. InsuranceCNYTotalPrice += item.CNYPrice;
  965. string itemClientName = "";
  966. string insClients = item.ClientName;
  967. if (!string.IsNullOrEmpty(insClients))
  968. {
  969. //System.Text.RegularExpressions.Match m_EnName = Regex.Match(item.ClientName, @"[A-Za-z]+");
  970. //System.Text.RegularExpressions.Match m_ZHName = Regex.Match(item.ClientName, @"[\u4e00-\u9fa5]");
  971. //if (m_EnName.Success || m_ZHName.Success)
  972. //{
  973. // itemClientName = insClients;
  974. // continue;
  975. //}
  976. string[] clientIds = new string[] { };
  977. if (insClients.Contains(','))
  978. {
  979. clientIds = insClients.Split(',');
  980. }
  981. else
  982. {
  983. clientIds = new string[] { insClients };
  984. }
  985. if (clientIds.Length > 0)
  986. {
  987. List<int> output = new List<int>();
  988. foreach (var clientId in clientIds)
  989. {
  990. if (clientId.IsNumeric())
  991. {
  992. output.Add(int.Parse(clientId));
  993. }
  994. }
  995. if (output.Count > 0)
  996. {
  997. var clients = _clientDatas.Where(it => output.Contains(it.Id)).ToList();
  998. foreach (var client in clients)
  999. {
  1000. itemClientName += $"{client.LastName + client.FirstName},";
  1001. }
  1002. if (itemClientName.Length > 0)
  1003. {
  1004. itemClientName = itemClientName.Substring(0, itemClientName.Length - 1);
  1005. }
  1006. }
  1007. else
  1008. {
  1009. itemClientName = insClients;
  1010. }
  1011. }
  1012. }
  1013. item.ClientName = itemClientName;
  1014. if (!string.IsNullOrEmpty(item.AuditGMDate))
  1015. {
  1016. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  1017. }
  1018. }
  1019. _geView.GroupInsuranceFeeViews = groupInsuranceFeeViews;
  1020. _geView.GroupInsuranceFeeStr = string.Format(@"人民币总费用:{0} CNY", InsuranceCNYTotalPrice.ToString("#0.00"));
  1021. #endregion
  1022. #region 其他款项费用 98
  1023. List<GroupDecreaseFeeView> groupDecreaseFeeViews = new List<GroupDecreaseFeeView>();
  1024. string groupDecreaseFeeSql = string.Format(@"Select dp.Id As DPId,dp.DiId As DPDiId,dp.PriceName,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  1025. (((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice,
  1026. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  1027. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,dp.CreateTime
  1028. From Grp_DecreasePayments dp
  1029. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 98 And dp.Id = ccp.CId
  1030. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1031. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1032. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1033. Where dp.IsDel = 0 And ccp.Ctable = 98 {1} And dp.Diid = {0}
  1034. Order By CreateTime", _dto.DiId, _dto.isAudit ? "And ccp.IsAuditGM = 1" : " ");
  1035. groupDecreaseFeeViews = await _sqlSugar.SqlQueryable<GroupDecreaseFeeView>(groupDecreaseFeeSql).ToListAsync();
  1036. #region 保险费用 - 模拟数据
  1037. //if (groupDecreaseFeeViews.Count < 1)
  1038. //{
  1039. // groupDecreaseFeeViews.Add(new GroupDecreaseFeeView()
  1040. // {
  1041. // DPId = 0,
  1042. // DPDiId = 2334,
  1043. // PriceName = "模拟数据-费用名称",
  1044. // PayMoney = 1000.00M,
  1045. // PayMoneyCurrency = "CNY",
  1046. // DayRate = 1.0000M,
  1047. // CNYPrice = 1.0000M,
  1048. // AuditGMDate = "2023-12-10 12:13:00",
  1049. // Payee = "模拟数据-付款方",
  1050. // OrbitalPrivateTransfer = 1,
  1051. // PayWay = "现金",
  1052. // IsPay = 1,
  1053. // Applicant = "刘华举"
  1054. // });
  1055. // groupDecreaseFeeViews.Add(new GroupDecreaseFeeView()
  1056. // {
  1057. // DPId = 0,
  1058. // DPDiId = 2334,
  1059. // PriceName = "模拟数据-费用名称",
  1060. // PayMoney = 1000.00M,
  1061. // PayMoneyCurrency = "CNY",
  1062. // DayRate = 1.0000M,
  1063. // CNYPrice = 1.0000M,
  1064. // AuditGMDate = "2023-12-10 12:13:00",
  1065. // Payee = "模拟数据-付款方",
  1066. // OrbitalPrivateTransfer = 1,
  1067. // PayWay = "现金",
  1068. // IsPay = 1,
  1069. // Applicant = "刘华举"
  1070. // });
  1071. //}
  1072. #endregion
  1073. decimal DecreaseCNYTotalPrice = 0.00M;
  1074. foreach (var item in groupDecreaseFeeViews)
  1075. {
  1076. item.CNYPrice = Convert.ToDecimal(item.CNYPrice.ToString("#0.00"));
  1077. DecreaseCNYTotalPrice += item.CNYPrice;
  1078. if (!string.IsNullOrEmpty(item.AuditGMDate))
  1079. {
  1080. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  1081. }
  1082. }
  1083. _geView.GroupDecreaseFeeViews = groupDecreaseFeeViews;
  1084. _geView.GroupDecreaseFeeStr = string.Format(@"人民币总费用:{0} CNY", DecreaseCNYTotalPrice.ToString("#0.00"));
  1085. #endregion
  1086. _view.GroupExpenditure = _geView;
  1087. #endregion
  1088. /*
  1089. * 团组报表计算方式
  1090. * 当前总支出 = 团组支出.Sum() + 超支费用.Sum()
  1091. * 应收金额 = 应收表.Sum()
  1092. * 已收金额 = 已收表.Sum()
  1093. * 应收利润(应收-支出) = 应收金额 - 收款退还 - 当前总支出
  1094. * 已收利润(已收-支出) = 已收金额 - 收款退还 - 当前总支出
  1095. *
  1096. */
  1097. decimal _totalExpenditure = 0.00M; //总支出
  1098. decimal _amountReceivable = 0.00M; //应收金额
  1099. decimal _amountReceived = 0.00M; //已收金额
  1100. decimal _receivableProfit = 0.00M; //应收利润
  1101. decimal _receivedProfit = 0.00M; //已收利润
  1102. _totalExpenditure = HotelCNYTotalPrice + CTGGRCNYTotalPrice + AirCNYTotalPrice + VisaCNYTotalPirce + InvitationalCNYTotalPrice +
  1103. InsuranceCNYTotalPrice + DecreaseCNYTotalPrice + exTotalAmount;
  1104. _amountReceivable = frTotalAmount;
  1105. _amountReceived = prTotalAmount;
  1106. _receivableProfit = _amountReceivable - promTotalAmount - _totalExpenditure;
  1107. _receivedProfit = _amountReceived - promTotalAmount - _totalExpenditure;
  1108. _view.FeeTotalStr = string.Format(@$"<span>
  1109. <span>当前总支出:{_totalExpenditure.ToString("#0.00")} CNY</span>
  1110. <span style='padding-left:10px;color: Green;'>应收金额:{_amountReceivable.ToString("#0.00")} CNY</span>
  1111. <span style='padding-left:10px;color: Green;'>已收金额:{_amountReceived.ToString("#0.00")} CNY</span>
  1112. <span style='padding-left:10px;color: Green;'>应收利润(应收-支出):{_receivableProfit.ToString("#0.00")} CNY</span>
  1113. <span style='padding-left:10px;color: Green;'>已收利润(已收-支出):{_receivedProfit.ToString("#0.00")} CNY</span>
  1114. </span>");
  1115. return Ok(JsonView(true, "查询成功!", _view));
  1116. }
  1117. else
  1118. {
  1119. return Ok(JsonView(false, "查询成功"));
  1120. }
  1121. }
  1122. #endregion
  1123. #region 报表/折线图统计
  1124. //企业利润-团组利润
  1125. //企业利润-会务利润
  1126. /// <summary>
  1127. /// 企业利润
  1128. /// Details
  1129. /// 待添加权限验证
  1130. /// </summary>
  1131. /// <param name="_dto">团组列表请求dto</param>
  1132. /// <returns></returns>
  1133. [HttpPost("PostCorporateProfit")]
  1134. //[JsonConverter(typeof(DecimalConverter), 2)]
  1135. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1136. public async Task<IActionResult> PostCorporateProfit(PostCorporateProfitDto _dto)
  1137. {
  1138. #region 参数验证
  1139. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  1140. if (_dto.PageId < 1) _dto.PageId = 38; //团组报表页面Id
  1141. if (_dto.Year < 1) return Ok(JsonView(false, "请输入有效的Year参数!"));
  1142. if (_dto.StatisticsType > 2 && _dto.StatisticsType < 1) return Ok(JsonView(false, "请输入有效的StatisticsType参数,1 月份 2 季度"));
  1143. if (_dto.BusinessType > 3 && _dto.BusinessType < 1) return Ok(JsonView(false, "请输入有效的BusinessType参数,1 所有 2 团组 3 会务"));
  1144. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1145. #region 页面操作权限验证
  1146. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  1147. //if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  1148. #endregion
  1149. string sqlWhere = string.Empty;
  1150. //起止时间
  1151. DateTime beginDt = Convert.ToDateTime($"{_dto.Year}-01-01 00:00:00");
  1152. DateTime endDt = Convert.ToDateTime($"{_dto.Year}-12-31 23:59:59");
  1153. sqlWhere = string.Format(@$" Where Isdel = 0 ");
  1154. //业务类型
  1155. List<int> groupTypeId = new List<int>();
  1156. if (_dto.BusinessType == 2) //团组
  1157. {
  1158. groupTypeId.AddRange(new List<int>() {
  1159. 38, // 政府团
  1160. 39, // 企业团
  1161. 40, // 散客团
  1162. 1048 // 高校团
  1163. });
  1164. }
  1165. else if (_dto.BusinessType == 3) //会务
  1166. {
  1167. groupTypeId.AddRange(new List<int>() {
  1168. 102, // 未知
  1169. 248, // 非团组
  1170. 302, // 成都-会务活动
  1171. 691, // 四川-会务活动
  1172. 762, // 四川-赛事项目收入
  1173. 1047 // 成都-赛事项目收入
  1174. });
  1175. }
  1176. if (groupTypeId.Count > 0)
  1177. {
  1178. sqlWhere += string.Format(@$" And TeamDid In ({string.Join(',', groupTypeId)})");
  1179. }
  1180. string sql = string.Format(@$"Select * From Grp_DelegationInfo {sqlWhere}");
  1181. var groupInfos = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).Where(it => it.CreateTime >= beginDt && it.CreateTime <= endDt).ToListAsync();
  1182. if (groupInfos.Count < 1) return Ok(JsonView(false, "暂无相关团组!"));
  1183. List<int> diIds = groupInfos.Select(it => it.Id).ToList();
  1184. List<CorporateProfit> corporateProfits = await CorporateProfit(diIds);
  1185. List<MonthInfo> months = new List<MonthInfo>();
  1186. if (_dto.StatisticsType == 1) //月份
  1187. {
  1188. months = GeneralMethod.GetMonthInfos(Convert.ToInt32(_dto.Year));
  1189. }
  1190. else if (_dto.StatisticsType == 1) //季度
  1191. {
  1192. months = GeneralMethod.GetQuarter(Convert.ToInt32(_dto.Year));
  1193. }
  1194. List<CorporateProfitMonthView> _view = new List<CorporateProfitMonthView>();
  1195. foreach (var item in months)
  1196. {
  1197. DateTime monthBeginDt = Convert.ToDateTime($"{_dto.Year}-{item.Month}-{item.Days.BeginDays} 00:00:00");
  1198. DateTime monthEndDt = Convert.ToDateTime($"{_dto.Year}-{item.Month}-{item.Days.EndDays} 23:59:59");
  1199. var corporateProfit = corporateProfits.Where(it => it.CreateDt >= monthBeginDt && it.CreateDt <= monthEndDt).ToList();
  1200. _view.Add(new CorporateProfitMonthView()
  1201. {
  1202. Month = item.Month,
  1203. Profit = corporateProfit.Sum(it => it.ReceivedProfit),
  1204. GroupInfos = corporateProfit.OrderBy(it => it.CreateDt).ToList()
  1205. });
  1206. }
  1207. return Ok(JsonView(true, "操作成功!", _view));
  1208. #endregion
  1209. }
  1210. /// <summary>
  1211. /// 计算团组利润
  1212. /// </summary>
  1213. /// <param name="diIds"></param>
  1214. /// <returns></returns>
  1215. private async Task<List<CorporateProfit>> CorporateProfit(List<int> diIds)
  1216. {
  1217. List<CorporateProfit> corporateProfits = new List<CorporateProfit>();
  1218. if (diIds.Count < 1)
  1219. {
  1220. return corporateProfits;
  1221. }
  1222. #region 计算团组利润
  1223. /*
  1224. * 团组报表计算方式
  1225. * 当前总支出 = 团组支出.Sum() + 超支费用.Sum()
  1226. * 应收金额 = 应收表.Sum()
  1227. * 已收金额 = 已收表.Sum()
  1228. * 应收利润(应收-支出) = 应收金额 - 收款退还 - 当前总支出
  1229. * 已收利润(已收-支出) = 已收金额 - 收款退还 - 当前总支出
  1230. *
  1231. */
  1232. string diIdStr = string.Join(",", diIds);
  1233. string sql = string.Format(@$"Select * From Grp_DelegationInfo Where Isdel = 0 And Id In ({diIdStr})");
  1234. var groupInfos = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToListAsync();
  1235. #region 费用类型 币种,转账,客户信息
  1236. List<Sys_SetData> _setDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToListAsync();
  1237. var _clientDatas = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync();
  1238. #endregion
  1239. foreach (var _diId in diIds)
  1240. {
  1241. List<ExpenditureInfo> expenditureInfos = new List<ExpenditureInfo>();
  1242. #region 团组收入
  1243. /*
  1244. * 应收报表
  1245. */
  1246. decimal frTotalAmount = 0.00M;//应收总金额
  1247. string _frSql = string.Format(@"Select fr.Id,fr.Diid,fr.PriceName,fr.Price,fr.Count,fr.Unit,fr.Currency,
  1248. sd.Name As CurrencyCode,sd.Remark As CurrencyName,fr.Rate,fr.ItemSumPrice,fr.CreateTime
  1249. From Fin_ForeignReceivables fr
  1250. Left Join Sys_SetData sd On fr.Currency = sd.Id
  1251. Where fr.IsDel = 0 And fr.Diid = {0} Order By CreateTime", _diId);
  1252. List<Gsd_ForeignReceivablesView> _frViews = await _sqlSugar.SqlQueryable<Gsd_ForeignReceivablesView>(_frSql).ToListAsync();
  1253. frTotalAmount = _frViews.Sum(it => it.ItemSumPrice);
  1254. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "应收项", Amount = frTotalAmount });
  1255. /*
  1256. * 已收报表
  1257. */
  1258. decimal prTotalAmount = 0.00M;//已收总金额
  1259. string _prSql = string.Format(@"Select pr.Id,pr.Diid,pr.SectionTime As SectionTimeDt,pr.Price,pr.Currency,
  1260. sd1.Name As CurrencyCode,sd1.Remark As CurrencyName,pr.Client,
  1261. pr.ReceivablesType,sd2.Name As ReceivablesTypeName,pr.Remark,pr.CreateTime
  1262. From Fin_ProceedsReceived pr
  1263. Left Join Sys_SetData sd1 On pr.Currency = sd1.Id
  1264. Left Join Sys_SetData sd2 On pr.ReceivablesType = sd2.Id
  1265. Where pr.IsDel = 0 and pr.Diid = {0} Order By CreateTime", _diId);
  1266. List<Gsd_ProceedsReceivedView> _prViews = await _sqlSugar.SqlQueryable<Gsd_ProceedsReceivedView>(_prSql).ToListAsync();
  1267. prTotalAmount = _prViews.Sum(it => it.Price);
  1268. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "已收项", Amount = prTotalAmount });
  1269. /*
  1270. * 超支费用
  1271. */
  1272. decimal exTotalAmount = 0.00M;
  1273. string _ecSql = string.Format(@"Select gec.Id As GECId,gec.DiId As GECDiId,gec.PriceName,ccp.PayMoney,sd1.Name As PaymentCurrency,
  1274. ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  1275. sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant,gec.CreateTime
  1276. From OA2023DB.dbo.Fin_GroupExtraCost gec
  1277. Left Join Grp_CreditCardPayment ccp On gec.Id = ccp.CId
  1278. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1279. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1280. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  1281. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1282. Where ccp.IsDel = 0 And ccp.CTable = 1015 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ccp.DiId = {0} Order By CreateTime", _diId);
  1283. List<Gsd_ExtraCostsView> _ExtraCostsViews = await _sqlSugar.SqlQueryable<Gsd_ExtraCostsView>(_ecSql).ToListAsync();
  1284. exTotalAmount = _ExtraCostsViews.Sum(it => it.CNYPrice);
  1285. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "超支费用", Amount = exTotalAmount });
  1286. /*
  1287. * 收款退还
  1288. */
  1289. decimal promTotalAmount = 0.00M;// 收款退还总金额
  1290. List<Gsd_PaymentRefundAndOtherMoneyView> _promView = new List<Gsd_PaymentRefundAndOtherMoneyView>();
  1291. //删除了 And prom.PriceType = 1
  1292. string _ropSql = string.Format(@"Select u.CnName As Appliction,prom.Id As PrId,prom.DiId As PrDiId,prom.Price As PrPrice,
  1293. prom.PriceName AS PrPriceName,prom.CurrencyId As PrCurrencyId,
  1294. prom.PayType As PrPayType,prom.PriceType As PrPriceType,ccp.*,prom.CreateTime As PrCreateTime
  1295. From Fin_PaymentRefundAndOtherMoney prom
  1296. Left Join Grp_CreditCardPayment ccp On prom.DiId = ccp.DIId And prom.Id = ccp.CId
  1297. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1298. Where prom.IsDel = 0 And prom.PayType = 1 And ccp.CTable = 285
  1299. And ccp.IsAuditGM = 1 And ccp.IsPay = 1
  1300. And prom.DiId = {0} Order By PrCreateTime", _diId);
  1301. var _promDatas = await _sqlSugar.SqlQueryable<Gsd_PaymentRefundAndOtherMoneyDataSource1View>(_ropSql).ToListAsync();
  1302. foreach (var ropItem in _promDatas)
  1303. {
  1304. string thisCueencyCode = "Unknown";
  1305. string thisCueencyName = "Unknown";
  1306. var currency = _setDatas.Where(it => it.Id == ropItem.PaymentCurrency).FirstOrDefault();
  1307. if (currency != null)
  1308. {
  1309. thisCueencyCode = currency.Name;
  1310. thisCueencyName = currency.Remark;
  1311. }
  1312. string orbitalPrivateTransferStr = "Unknown";
  1313. var orbitalPrivateTransfer = _setDatas.Where(it => it.Id == ropItem.OrbitalPrivateTransfer).FirstOrDefault();
  1314. if (orbitalPrivateTransfer != null)
  1315. {
  1316. orbitalPrivateTransferStr = orbitalPrivateTransfer.Name;
  1317. }
  1318. string payStr = "Unknown";
  1319. var pay = _setDatas.Where(it => it.Id == ropItem.PayDId).FirstOrDefault();
  1320. if (pay != null)
  1321. {
  1322. payStr = pay.Name;
  1323. }
  1324. Gsd_PaymentRefundAndOtherMoneyView gsd_PaymentRefund = new Gsd_PaymentRefundAndOtherMoneyView()
  1325. {
  1326. Id = ropItem.Id,
  1327. DiId = ropItem.DIId,
  1328. PriceName = ropItem.PrPriceName,
  1329. PayCurrencyCode = thisCueencyCode,
  1330. PayCurrencyName = thisCueencyName,
  1331. Price = ropItem.PrPrice,
  1332. CNYPrice = ropItem.RMBPrice,
  1333. ThisRate = ropItem.DayRate,
  1334. Payee = ropItem.Payee,
  1335. PayTime = ropItem.AuditGMDate,
  1336. OrbitalPrivateTransfer = ropItem.OrbitalPrivateTransfer,
  1337. PayType = payStr,
  1338. IsPay = ropItem.IsPay,
  1339. Applicant = ropItem.Appliction
  1340. };
  1341. _promView.Add(gsd_PaymentRefund);
  1342. }
  1343. promTotalAmount = _promView.Sum(it => it.CNYPrice);
  1344. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "收款退还", Amount = promTotalAmount });
  1345. #endregion
  1346. #region 团组支出
  1347. GroupExpenditureView _geView = new GroupExpenditureView();
  1348. #region 酒店预定费用
  1349. List<GroupHotelFeeView> groupHotelFeeViews = new List<GroupHotelFeeView>();
  1350. string hotelFeeSql = string.Format(@"Select hr.Id As HrId,hr.DiId As HrDiId,hr.City,hr.HotelName,hr.CheckInDate,hr.CheckOutDate,
  1351. sd1.Name As PaymentCurrency,hr.SingleRoomPrice,hr.SingleRoomCount,hr.DoubleRoomPrice,
  1352. hr.DoubleRoomCount,hr.SuiteRoomPrice,hr.SuiteRoomCount,hr.OtherRoomPrice,hr.OtherRoomCount,
  1353. hr.BreakfastPrice,sd4.Name As BreakfastCurrency,hr.Isoppay,hr.GovernmentRent,
  1354. sd5.Name As GovernmentRentCurrency,hr.CityTax,sd6.Name As CityTaxCurrency,
  1355. ccp.PayMoney,ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.OrbitalPrivateTransfer,
  1356. sd2.Name As PayWay,sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant
  1357. From Grp_HotelReservations hr
  1358. Left Join Grp_CreditCardPayment ccp On hr.Id = ccp.CId
  1359. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1360. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1361. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  1362. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1363. Left Join Sys_SetData sd4 On hr.BreakfastCurrency = sd4.Id
  1364. Left Join Sys_SetData sd5 On hr.GovernmentRentCurrency = sd5.Id
  1365. Left Join Sys_SetData sd6 On hr.CityTaxCurrency = sd6.Id
  1366. Where hr.IsDel = 0 And ccp.IsDel = 0 And ccp.CTable = 76 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And hr.DiId = {0}
  1367. Order By CheckInDate Asc", _diId);
  1368. groupHotelFeeViews = await _sqlSugar.SqlQueryable<GroupHotelFeeView>(hotelFeeSql).ToListAsync();
  1369. decimal HotelCNYTotalPrice = groupHotelFeeViews.Sum(it => it.CNYPrice);
  1370. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "酒店预定", Amount = HotelCNYTotalPrice });
  1371. #endregion
  1372. #region 地接费用
  1373. List<GroupCTGGRFeeView> groupCTGGRFeeViews = new List<GroupCTGGRFeeView>();
  1374. string CTGGRFeeSql = string.Format(@"Select ctggr.Id As CTGGRId,ctggr.DiId As CTGGRDiId,ctggr.Area,ctggrc.*,ctggrc.Price As PayMoney,
  1375. sd2.name As PaymentCurrency,ccp.PayPercentage,
  1376. (ctggrc.Price / (ccp.PayPercentage / 100)) As AmountPaid,
  1377. (ctggrc.Price / (ccp.PayPercentage / 100) - ctggrc.Price) As BalancePayment,
  1378. ccp.DayRate,(ctggrc.Price * ccp.DayRate) As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  1379. ccp.OrbitalPrivateTransfer,sd1.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ctggr.CreateTime
  1380. From Grp_CarTouristGuideGroundReservations ctggr
  1381. Left Join ( Select cggrc.CTGGRId,sd1.Name As PriceName,cggrc.Price,sd2.Name As PriceCurrency,
  1382. cggrc.PriceContent
  1383. From Grp_CarTouristGuideGroundReservationsContent cggrc
  1384. Left Join Sys_SetData sd1 On cggrc.SId = sd1.Id
  1385. Left Join Sys_SetData sd2 On cggrc.Currency = sd2.Id
  1386. Where cggrc.ISdel = 0 And cggrc.Price != 0.00
  1387. ) ctggrc On ctggr.Id = ctggrc.CTGGRId
  1388. Left Join Grp_CreditCardPayment ccp On ccp.IsDel = 0 And ccp.CTable = 79 And ctggr.Id = ccp.CId
  1389. Left Join Sys_SetData sd1 On ccp.PayDId = sd1.Id
  1390. Left Join Sys_SetData sd2 On ccp.PaymentCurrency = sd2.Id
  1391. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1392. Where ctggr.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ctggr.DiId = {0}
  1393. Order By CreateTime", _diId);
  1394. groupCTGGRFeeViews = await _sqlSugar.SqlQueryable<GroupCTGGRFeeView>(CTGGRFeeSql).ToListAsync();
  1395. decimal CTGGRCNYTotalPrice = groupCTGGRFeeViews.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  1396. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "地接", Amount = CTGGRCNYTotalPrice });
  1397. #endregion
  1398. #region 机票预订费用
  1399. List<GroupAirFeeView> groupAirFeeViews = new List<GroupAirFeeView>();
  1400. string groupAirFeeSql = string.Format(@"Select atr.Id As AirId,atr.DIId As AirDiId,atr.FlightsCode,atr.FlightsCity,sd4.Name As AirTypeName,
  1401. atr.FlightsDate,atr.FlightsTime,atr.ClientName,atr.ClientNum,ccp.PayMoney,
  1402. sd1.Name As PayMoneyCurrency,ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.AuditGMDate,
  1403. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant,atr.CreateTime
  1404. From Grp_AirTicketReservations atr
  1405. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 85 And atr.Id = ccp.CId
  1406. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1407. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1408. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  1409. Left Join Sys_SetData sd4 On atr.CType = sd4.Id
  1410. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1411. Where atr.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And atr.DiId = {0} Order By CreateTime", _diId);
  1412. groupAirFeeViews = await _sqlSugar.SqlQueryable<GroupAirFeeView>(groupAirFeeSql).ToListAsync();
  1413. decimal AirCNYTotalPrice = groupAirFeeViews.Sum(it => it.CNYPrice);
  1414. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "机票预订", Amount = AirCNYTotalPrice });
  1415. #endregion
  1416. #region 签证费用
  1417. List<GroupVisaFeeView> groupVisaFeeViews = new List<GroupVisaFeeView>();
  1418. string groupVisaFeeSql = string.Format(@"Select vi.Id As VisaId,vi.DIId As VisaDiId,vi.VisaClient,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  1419. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  1420. sd3.Name As CardTypeName,ccp.IsPay,u.CnName As Applicant,vi.CreateTime
  1421. From Grp_VisaInfo vi
  1422. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 80 And vi.Id = ccp.CId
  1423. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1424. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1425. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  1426. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1427. Where vi.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And vi.DIId = {0} Order By CreateTime", _diId);
  1428. groupVisaFeeViews = await _sqlSugar.SqlQueryable<GroupVisaFeeView>(groupVisaFeeSql).ToListAsync();
  1429. decimal VisaCNYTotalPirce = groupVisaFeeViews.Sum(it => it.PayMoney);
  1430. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "签证", Amount = VisaCNYTotalPirce });
  1431. #endregion
  1432. #region 邀请/公务活动 CTable = 81
  1433. List<GroupInvitationalFeeView> groupInvitationalFeeViews = new List<GroupInvitationalFeeView>();
  1434. string groupInvitationalFeeSql = string.Format(@"Select ioa.Id As IOAId,ioa.DiId As IOADiId,ioa.InviterArea,ioa.Inviter,ioa.InviteTime,
  1435. ioa.InviteCost,sd3.Name As InviteCurrency,ioa.SendCost,sd4.Name As SendCurrency,ioa.EventsCost,
  1436. sd5.Name As EventsCurrency,ioa.TranslateCost,sd6.Name As TranslateCurrency,ccp.PayMoney,
  1437. sd7.Name As PaymentCurrency,ccp.RMBPrice As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  1438. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ioa.CreateTime
  1439. From Grp_InvitationOfficialActivities ioa
  1440. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 81 And ioa.Id = ccp.CId
  1441. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1442. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1443. Left Join Sys_SetData sd3 On ioa.InviteCurrency = sd3.Id
  1444. Left Join Sys_SetData sd4 On ioa.SendCurrency = sd4.Id
  1445. Left Join Sys_SetData sd5 On ioa.EventsCurrency = sd5.Id
  1446. Left Join Sys_SetData sd6 On ioa.TranslateCurrency = sd6.Id
  1447. Left Join Sys_SetData sd7 On ccp.PaymentCurrency = sd7.Id
  1448. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1449. Where ioa.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ioa.Diid = {0} Order By CreateTime", _diId);
  1450. groupInvitationalFeeViews = await _sqlSugar.SqlQueryable<GroupInvitationalFeeView>(groupInvitationalFeeSql).ToListAsync();
  1451. decimal InvitationalCNYTotalPrice = groupInvitationalFeeViews.Sum(it => it.CNYPrice);
  1452. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "邀请/公务活动", Amount = InvitationalCNYTotalPrice });
  1453. #endregion
  1454. #region 保险费用
  1455. List<GroupInsuranceFeeView> groupInsuranceFeeViews = new List<GroupInsuranceFeeView>();
  1456. string groupInsuranceFeeSql = string.Format(@"Select ic.Id As InsuranceId,ic.Diid As InsuranceDiId,ClientName,ccp.PayMoney,ccp.RMBPrice As CNYPrice,
  1457. sd1.Name As PayMoneyCurrency,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  1458. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ic.CreateTime
  1459. From Grp_Customers ic
  1460. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 82 And ic.Id = ccp.CId
  1461. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1462. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1463. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1464. Where ic.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ic.DiId = {0} Order By CreateTime", _diId);
  1465. groupInsuranceFeeViews = await _sqlSugar.SqlQueryable<GroupInsuranceFeeView>(groupInsuranceFeeSql).ToListAsync();
  1466. decimal InsuranceCNYTotalPrice = groupInsuranceFeeViews.Sum(it => it.CNYPrice);
  1467. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "保险费用", Amount = InsuranceCNYTotalPrice });
  1468. #endregion
  1469. #region 其他款项费用 98
  1470. List<GroupDecreaseFeeView> groupDecreaseFeeViews = new List<GroupDecreaseFeeView>();
  1471. string groupDecreaseFeeSql = string.Format(@"Select dp.Id As DPId,dp.DiId As DPDiId,dp.PriceName,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  1472. (((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice,
  1473. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  1474. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,dp.CreateTime
  1475. From Grp_DecreasePayments dp
  1476. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 98 And dp.Id = ccp.CId
  1477. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1478. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1479. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1480. Where dp.IsDel = 0 And ccp.Ctable = 98 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And dp.Diid = {0}
  1481. Order By CreateTime", _diId);
  1482. groupDecreaseFeeViews = await _sqlSugar.SqlQueryable<GroupDecreaseFeeView>(groupDecreaseFeeSql).ToListAsync();
  1483. decimal DecreaseCNYTotalPrice = groupDecreaseFeeViews.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  1484. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "其他款项", Amount = DecreaseCNYTotalPrice });
  1485. #endregion
  1486. #endregion
  1487. /*
  1488. * 团组报表计算方式
  1489. * 当前总支出 = 团组支出.Sum() + 超支费用.Sum()
  1490. * 应收金额 = 应收表.Sum()
  1491. * 已收金额 = 已收表.Sum()
  1492. * 应收利润(应收-支出) = 应收金额 - 收款退还 - 当前总支出
  1493. * 已收利润(已收-支出) = 已收金额 - 收款退还 - 当前总支出
  1494. *
  1495. */
  1496. decimal _totalExpenditure = 0.00M; //总支出
  1497. decimal _amountReceivable = 0.00M; //应收金额
  1498. decimal _amountReceived = 0.00M; //已收金额
  1499. decimal _receivableProfit = 0.00M; //应收利润
  1500. decimal _receivedProfit = 0.00M; //已收利润
  1501. _totalExpenditure = HotelCNYTotalPrice + CTGGRCNYTotalPrice + AirCNYTotalPrice + VisaCNYTotalPirce + InvitationalCNYTotalPrice +
  1502. InsuranceCNYTotalPrice + DecreaseCNYTotalPrice + exTotalAmount;
  1503. _amountReceivable = frTotalAmount;
  1504. _amountReceived = prTotalAmount;
  1505. _receivableProfit = _amountReceivable - promTotalAmount - _totalExpenditure;
  1506. _receivedProfit = _amountReceived - promTotalAmount - _totalExpenditure;
  1507. var groupInfo = groupInfos.Find(it => it.Id == _diId);
  1508. corporateProfits.Add(new CorporateProfit()
  1509. {
  1510. DiId = _diId,
  1511. TeamName = groupInfo?.TeamName ?? "Unkwnon",
  1512. CreateDt = Convert.ToDateTime(groupInfo?.CreateTime),
  1513. TotalExpenditure = _totalExpenditure,
  1514. ExpenditureItem = expenditureInfos,
  1515. AmountReceivable = _amountReceivable,
  1516. AmountReceived = _amountReceived,
  1517. ReceivableProfit = _receivableProfit,
  1518. ReceivedProfit = _receivedProfit,
  1519. });
  1520. }
  1521. #endregion
  1522. return corporateProfits;
  1523. }
  1524. //未来预测-地区接团/出团量
  1525. //未来预测-地区酒店预订量
  1526. //未来预测-地区机票预订量
  1527. //未来预测-地区车辆预订量
  1528. /// <summary>
  1529. /// (国家/城市)地区预订数量(团,酒店,机票,车辆)
  1530. /// Details
  1531. /// 待添加权限验证
  1532. /// </summary>
  1533. /// <param name="_dto">团组列表请求dto</param>
  1534. /// <returns></returns>
  1535. [HttpPost("PostRegionalBookingsNumber")]
  1536. //[JsonConverter(typeof(DecimalConverter), 2)]
  1537. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1538. public async Task<IActionResult> PostRegionalBookingsNumber(PostRegionalBookingsNumberDto _dto)
  1539. {
  1540. #region 参数验证
  1541. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  1542. //if (_dto.PageId < 1) _dto.PageId = 38; //团组报表页面Id
  1543. if (_dto.Type > 1 && _dto.Type > 5) return Ok(JsonView(false, "请输入有效的Type参数,1 团 2 酒店 3 机票 4 车辆"));
  1544. if (_dto.Year < 1) return Ok(JsonView(false, "请输入有效的Year参数!"));
  1545. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1546. #region 页面操作权限验证
  1547. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  1548. //if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  1549. #endregion
  1550. string sqlWhere = string.Empty;
  1551. //起止时间
  1552. DateTime beginDt = Convert.ToDateTime($"{_dto.Year}-01-01 00:00:00");
  1553. DateTime endDt = Convert.ToDateTime($"{_dto.Year}-12-31 23:59:59");
  1554. sqlWhere = string.Format(@$" Where Isdel = 0 ");
  1555. string sql = string.Format(@$"Select * From Grp_DelegationInfo {sqlWhere}");
  1556. var groupInfos = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).Where(it => it.CreateTime >= beginDt && it.CreateTime <= endDt).ToListAsync();
  1557. if (groupInfos.Count < 1) return Ok(JsonView(false, "暂无相关团组!"));
  1558. List<GroupTypeNumberInfo> datas = new List<GroupTypeNumberInfo>();
  1559. foreach (var item in groupInfos)
  1560. {
  1561. var data = await GroupBookingsNumber(_dto.Type, item);
  1562. if (data.TypeItem.Count > 0)
  1563. {
  1564. datas.Add(data);
  1565. }
  1566. }
  1567. //类型处理
  1568. if (_dto.Type == 1)//接团
  1569. {
  1570. List<GroupBookingNumberView> views = new List<GroupBookingNumberView>();
  1571. dynamic groupData = null;
  1572. foreach (var item in datas)
  1573. {
  1574. if (item.TypeItem.Count > 0)
  1575. {
  1576. foreach (var item1 in item.TypeItem)
  1577. {
  1578. if (item1.RegionItem.Count > 0)
  1579. {
  1580. GroupInfo groupInfo = new GroupInfo()
  1581. {
  1582. DiId = item.DiId,
  1583. TeamName = item.GroupName,
  1584. CreateTime = groupInfos.Find(it => it.Id == item.DiId)?.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") ?? "Unknown",
  1585. ClientUnit = groupInfos.Find(it => it.Id == item.DiId)?.ClientUnit ?? "Unknown",
  1586. Principal = groupInfos.Find(it => it.Id == item.DiId)?.ClientName ?? "Unknown",
  1587. };
  1588. views.Add(new GroupBookingNumberView() { Name = item1.RegionItem[0].Name, Number = item1.RegionItem[0].Number, GroupItem = new List<GroupInfo>() { groupInfo } });
  1589. }
  1590. }
  1591. }
  1592. }
  1593. var viewsGroup = views.GroupBy(it => it.Name);
  1594. List<GroupBookingNumberView> _view = new List<GroupBookingNumberView>();
  1595. foreach (var item in viewsGroup)
  1596. {
  1597. List<GroupInfo> infos = new List<GroupInfo>();
  1598. foreach (var item1 in item)
  1599. {
  1600. infos.AddRange(item1.GroupItem);
  1601. }
  1602. infos = infos.OrderByDescending(it => it.CreateTime).ToList(); //
  1603. _view.Add(new GroupBookingNumberView() { Name = item.Key, Number = item.Count(), GroupItem = infos });
  1604. }
  1605. _view = _view.OrderByDescending(it => it.Number).Take(10).ToList();
  1606. return Ok(JsonView(true, "操作成功!", _view, _view.Count));
  1607. }
  1608. else if (_dto.Type == 2)
  1609. {
  1610. List<HotelBookingNumberView> views = new List<HotelBookingNumberView>();
  1611. foreach (var item in datas)
  1612. {
  1613. if (item.TypeItem.Count > 0)
  1614. {
  1615. foreach (var item1 in item.TypeItem)
  1616. {
  1617. if (item1.RegionItem.Count > 0)
  1618. {
  1619. foreach (var item2 in item1.RegionItem)
  1620. {
  1621. GroupInfo groupInfo = new GroupInfo()
  1622. {
  1623. DiId = item.DiId,
  1624. TeamName = item.GroupName,
  1625. CreateTime = groupInfos.Find(it => it.Id == item.DiId)?.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") ?? "Unknown",
  1626. ClientUnit = groupInfos.Find(it => it.Id == item.DiId)?.ClientUnit ?? "Unknown",
  1627. Principal = groupInfos.Find(it => it.Id == item.DiId)?.ClientName ?? "Unknown",
  1628. };
  1629. List<HotelInfo> hotels = new List<HotelInfo>();
  1630. foreach (var item3 in item2.Data)
  1631. {
  1632. StatisticsHotelInfo statisticsHotelInfos = JsonConvert.DeserializeObject<StatisticsHotelInfo>(JsonConvert.SerializeObject(item3));
  1633. HotelInfo hotelInfo = new HotelInfo()
  1634. {
  1635. HotelName = statisticsHotelInfos.HotelName,
  1636. SingleRoomNum = statisticsHotelInfos.SingleRoomNum,
  1637. DoubleRoomNum = statisticsHotelInfos.DoubleRoomNum,
  1638. SuiteRoomNum = statisticsHotelInfos.SuiteRoomNum,
  1639. OtherRoomNum = statisticsHotelInfos.OtherRoomNum,
  1640. GroupInfo = groupInfo
  1641. };
  1642. hotels.Add(hotelInfo);
  1643. }
  1644. views.Add(new HotelBookingNumberView() { Name = item1.RegionItem[0].Name, Number = item1.RegionItem[0].Number, HotelItem = hotels });
  1645. }
  1646. }
  1647. }
  1648. }
  1649. }
  1650. var viewsGroup = views.GroupBy(it => it.Name);
  1651. List<HotelBookingNumberView> _view = new List<HotelBookingNumberView>();
  1652. foreach (var item in viewsGroup)
  1653. {
  1654. List<HotelInfo> infos = new List<HotelInfo>();
  1655. foreach (var item1 in item)
  1656. {
  1657. infos.AddRange(item1.HotelItem);
  1658. }
  1659. _view.Add(new HotelBookingNumberView() { Name = item.Key, Number = item.Count(), HotelItem = infos });
  1660. }
  1661. _view = _view.OrderByDescending(it => it.Number).Take(10).ToList();
  1662. return Ok(JsonView(true, "操作成功!", views, views.Count));
  1663. }
  1664. return Ok(JsonView(false, "操作失败!"));
  1665. #endregion
  1666. }
  1667. /// <summary>
  1668. /// 计算团组ALLType预订数量
  1669. /// </summary>
  1670. /// <param name="diIds"></param>
  1671. /// <returns></returns>
  1672. private async Task<GroupTypeNumberInfo> GroupBookingsNumber(int type, Grp_DelegationInfo info)
  1673. {
  1674. GroupTypeNumberInfo _view = new GroupTypeNumberInfo();
  1675. if (info == null)
  1676. {
  1677. return _view;
  1678. }
  1679. _view.DiId = info.Id;
  1680. _view.GroupName = info.TeamName;
  1681. List<TypeInfo> _types = new List<TypeInfo>();
  1682. #region 计算团组ALLType预订数量
  1683. if (type == 1)
  1684. {
  1685. //接团 客户集团所在地区
  1686. string group_region = string.Empty;
  1687. int group_number = 0;
  1688. if (!string.IsNullOrEmpty(info.ClientUnit))
  1689. {
  1690. var _NewClientData = await _sqlSugar.Queryable<Crm_NewClientData>().Where(it => it.IsDel == 0 && it.Client.Equals(info.ClientUnit)).FirstAsync();
  1691. if (_NewClientData != null)
  1692. {
  1693. var regionInfo = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == _NewClientData.Lvlid).FirstAsync();
  1694. if (regionInfo != null)
  1695. {
  1696. group_region = regionInfo.Name.Replace("级", "");
  1697. group_number++;
  1698. }
  1699. }
  1700. }
  1701. if (group_number > 0)
  1702. {
  1703. _types.Add(new TypeInfo() { Id = 1, RegionItem = new List<RegionInfo>() { new RegionInfo() { Name = group_region, Number = group_number } } });
  1704. }
  1705. }
  1706. else if (type == 2)
  1707. {
  1708. //酒店
  1709. var hotelInfos = await _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && it.DiId == info.Id).ToListAsync();
  1710. if (hotelInfos.Count > 0)
  1711. {
  1712. List<RegionInfo> hotelRegions = new List<RegionInfo>();
  1713. foreach (var item in hotelInfos)
  1714. {
  1715. var hotelNumberInfo = new StatisticsHotelInfo()
  1716. {
  1717. HotelName = item.HotelName,
  1718. SingleRoomNum = item.SingleRoomCount,
  1719. DoubleRoomNum = item.DoubleRoomCount,
  1720. SuiteRoomNum = item.SuiteRoomCount,
  1721. OtherRoomNum = item.OtherRoomCount,
  1722. };
  1723. int hotelRoomTotal = item.SingleRoomCount + item.DoubleRoomCount + item.SuiteRoomCount + item.OtherRoomCount;
  1724. if (hotelRegions.Select(it => it.Name).ToList().Contains(item.City))
  1725. {
  1726. RegionInfo hotelRegion = hotelRegions.Find(it => it.Name.Equals(item.City));
  1727. if (hotelRegion != null)
  1728. {
  1729. hotelRegions.Remove(hotelRegion);
  1730. if (hotelRegion.Data.Count > 0)
  1731. {
  1732. hotelRegion.Data.Add(hotelNumberInfo);
  1733. }
  1734. hotelRegion.Number += hotelRoomTotal;
  1735. hotelRegions.Add(hotelRegion);
  1736. }
  1737. }
  1738. else
  1739. {
  1740. hotelRegions.Add(new RegionInfo() { Name = item.City, Number = hotelRoomTotal, Data = new List<dynamic>() { hotelNumberInfo } });
  1741. }
  1742. }
  1743. _types.Add(new TypeInfo() { Id = 2, RegionItem = hotelRegions });
  1744. }
  1745. }
  1746. else if (type == 3)
  1747. {
  1748. //机票
  1749. var airTicketInfos = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  1750. .LeftJoin<Grp_CreditCardPayment>((atr, ccp) => atr.Id == ccp.CId && ccp.IsPay == 1)
  1751. .LeftJoin<Sys_SetData>((atr, ccp, sd) => atr.CType == sd.Id)
  1752. .Where((atr, ccp, sd) => atr.IsDel == 0 && atr.DIId == info.Id)
  1753. .Select((atr, ccp, sd) => new { atr.ClientNum, atr.CType, ccp.Payee, AirType = sd.Name })
  1754. .ToListAsync();
  1755. if (airTicketInfos.Count > 0)
  1756. {
  1757. List<RegionInfo> airTicketRegions = new List<RegionInfo>();
  1758. foreach (var item in airTicketInfos)
  1759. {
  1760. var ticketClass = new
  1761. {
  1762. TiketClass = item.AirType,
  1763. Number = item.ClientNum
  1764. };
  1765. if (airTicketRegions.Select(it => it.Name).ToList().Contains(item.Payee))
  1766. {
  1767. RegionInfo airTicketRegion = airTicketRegions.Find(it => it.Name.Equals(item.Payee));
  1768. if (airTicketRegion != null)
  1769. {
  1770. airTicketRegions.Remove(airTicketRegion);
  1771. if (airTicketRegion.Data.Count > 0)
  1772. {
  1773. airTicketRegion.Data.Add(ticketClass);
  1774. }
  1775. airTicketRegion.Number += item.ClientNum;
  1776. airTicketRegions.Add(airTicketRegion);
  1777. }
  1778. }
  1779. else
  1780. {
  1781. airTicketRegions.Add(new RegionInfo() { Name = item.Payee, Number = item.ClientNum, Data = new List<dynamic>() { ticketClass } });
  1782. }
  1783. }
  1784. _types.Add(new TypeInfo() { Id = 3, RegionItem = airTicketRegions });
  1785. }
  1786. }
  1787. else if (type == 4)
  1788. {
  1789. //车辆
  1790. var opInfos = await _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(it => it.IsDel == 0 && it.DiId == info.Id).ToListAsync();
  1791. var opContentInfos = await _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(it => it.IsDel == 0 && it.DiId == info.Id).ToListAsync();
  1792. if (opInfos.Count > 0)
  1793. {
  1794. List<RegionInfo> opRegions = new List<RegionInfo>();
  1795. foreach (var item in opInfos)
  1796. {
  1797. int carNum = 0;
  1798. var opContentInfo = opContentInfos.Where(it => it.CTGGRId == item.Id && it.SId == 91).ToList();
  1799. if (opContentInfo.Count > 0)
  1800. {
  1801. foreach (var item1 in opContentInfo)
  1802. {
  1803. if (item1.Price > 0 && item1.Count > 0)
  1804. {
  1805. carNum += item1.Count;
  1806. }
  1807. }
  1808. }
  1809. if (carNum > 0)
  1810. {
  1811. var opData = new
  1812. {
  1813. ServiceCompany = item.ServiceCompany,
  1814. BusName = item.BusName,
  1815. Numbuer = carNum
  1816. };
  1817. if (opRegions.Select(it => it.Name).ToList().Contains(item.Area))
  1818. {
  1819. RegionInfo opRegion = opRegions.Find(it => it.Name.Equals(item.Area));
  1820. if (opRegion != null)
  1821. {
  1822. opRegions.Remove(opRegion);
  1823. if (opRegion.Data.Count > 0)
  1824. {
  1825. opRegion.Data.Add(opData);
  1826. }
  1827. opRegion.Number += carNum;
  1828. opRegions.Add(opRegion);
  1829. }
  1830. }
  1831. else
  1832. {
  1833. opRegions.Add(new RegionInfo() { Name = item.Area, Number = carNum, Data = new List<dynamic>() { opData } });
  1834. }
  1835. }
  1836. }
  1837. _types.Add(new TypeInfo() { Id = 4, RegionItem = opRegions });
  1838. }
  1839. }
  1840. #endregion
  1841. _view.TypeItem = _types;
  1842. return _view;
  1843. }
  1844. #endregion
  1845. #region 市场部销售额
  1846. /// <summary>
  1847. /// 市场部销售额
  1848. /// Init 基础数据(公司/人员/年份/季度/月份)
  1849. /// </summary>
  1850. /// <param name="_dto">市场部销售额请求dto</param>
  1851. /// <returns></returns>
  1852. [HttpPost("PostMarketingSalesInitData")]
  1853. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1854. public async Task<IActionResult> PostMarketingSalesInitData(MarketingSalesInitDataDto _dto)
  1855. {
  1856. #region 参数验证
  1857. MarketingSalesInitDataDtoFoalidator validationRules = new MarketingSalesInitDataDtoFoalidator();
  1858. var validResult = await validationRules.ValidateAsync(_dto);
  1859. if (!validResult.IsValid)
  1860. {
  1861. var errors = new StringBuilder();
  1862. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  1863. return Ok(JsonView(false, errors.ToString()));
  1864. }
  1865. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1866. #region 页面操作权限验证
  1867. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  1868. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  1869. #endregion
  1870. var companyData = _sqlSugar.Queryable<Sys_Company>().Where(it => it.IsDel == 0)
  1871. .Select(it => new { id = it.Id, name = it.CompanyName })
  1872. .ToList();
  1873. List<int> companyIds = companyData.Select(it => it.id).ToList();
  1874. List<int> pickGroupUserIds = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0)
  1875. .Select(it => it.JietuanOperator)
  1876. .ToList();
  1877. var userData = _sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && (pickGroupUserIds.Contains(it.Id) || it.Id == 21))
  1878. .Select(it => new { id = it.Id, companyId = it.CompanyId, name = it.CnName })
  1879. .ToList();
  1880. companyData.Insert(0, new { id = -1, name = "全部" });
  1881. userData.Insert(0, new { id = -1, companyId = -1, name = "全部" });
  1882. #region 年份
  1883. var dtData = new List<dynamic>();
  1884. int dt = DateTime.Now.Year;
  1885. for (int y = dt; y >= dt - 4; y--)
  1886. {
  1887. //季度
  1888. var quarterDatas = new List<dynamic>();
  1889. quarterDatas.Add(new { name = "全部", beginDt = $"{y}-01-01", endDt = $"{y}-12-31" });
  1890. for (int q = 0; q < 4; q++)
  1891. {
  1892. dynamic quarterData = null;
  1893. if (q == 0)
  1894. {
  1895. var monthDatas = new List<dynamic>();
  1896. monthDatas.Add(new { name = $"全部", beginDt = $"{y}-01-01", endDt = $" {y}-03-31" });
  1897. for (int m = 1; m < 4; m++)
  1898. {
  1899. MonthlyTimeSegment timeSegment = new MonthlyTimeSegment(y, m);
  1900. monthDatas.Add(new { name = $"{ConvertToChinese(m)}", beginDt = timeSegment.Start.ToString("yyyy-MM-dd"), endDt = timeSegment.End.ToString("yyyy-MM-dd") });
  1901. }
  1902. //quarterData = new { name = "第一季度", beginDt = $"{y}-01-01", endDt = $" {y}-03-31", monthData = monthDatas };
  1903. quarterData = new { name = "第一季度", monthData = monthDatas };
  1904. }
  1905. else if (q == 1)
  1906. {
  1907. var monthDatas = new List<dynamic>();
  1908. monthDatas.Add(new { name = $"全部", beginDt = $"{y}-04-01", endDt = $"{y}-06-30" });
  1909. for (int m = 4; m < 7; m++)
  1910. {
  1911. MonthlyTimeSegment timeSegment = new MonthlyTimeSegment(y, m);
  1912. monthDatas.Add(new { name = $"{ConvertToChinese(m)}", beginDt = timeSegment.Start.ToString("yyyy-MM-dd"), endDt = timeSegment.End.ToString("yyyy-MM-dd") });
  1913. }
  1914. //quarterData = new { name = "第二季度", beginDt = $"{y}-04-01", endDt = $"{y}-06-30", monthData = monthDatas };
  1915. quarterData = new { name = "第二季度", monthData = monthDatas };
  1916. }
  1917. else if (q == 2)
  1918. {
  1919. var monthDatas = new List<dynamic>();
  1920. monthDatas.Add(new { name = $"全部", beginDt = $"{y}-07-01", endDt = $"{y}-09-30" });
  1921. for (int m = 7; m < 10; m++)
  1922. {
  1923. MonthlyTimeSegment timeSegment = new MonthlyTimeSegment(y, m);
  1924. monthDatas.Add(new { name = $"{ConvertToChinese(m)}", beginDt = timeSegment.Start.ToString("yyyy-MM-dd"), endDt = timeSegment.End.ToString("yyyy-MM-dd") });
  1925. }
  1926. //quarterData = new { name = "第三季度", beginDt = $"{y}-07-01", endDt = $"{y}-09-30", monthData = monthDatas };
  1927. quarterData = new { name = "第三季度", monthData = monthDatas };
  1928. }
  1929. else if (q == 3)
  1930. {
  1931. var monthDatas = new List<dynamic>();
  1932. monthDatas.Add(new { name = $"全部", beginDt = $"{y}-10-01", endDt = $"{y}-12-31" });
  1933. for (int m = 10; m < 13; m++)
  1934. {
  1935. MonthlyTimeSegment timeSegment = new MonthlyTimeSegment(y, m);
  1936. monthDatas.Add(new { name = $"{ConvertToChinese(m)}", beginDt = timeSegment.Start.ToString("yyyy-MM-dd"), endDt = timeSegment.End.ToString("yyyy-MM-dd") });
  1937. }
  1938. //quarterData = new { name = "第四季度", beginDt = $"{y}-10-01", endDt = $"{y}-12-31", monthData = monthDatas };
  1939. quarterData = new { name = "第四季度", monthData = monthDatas };
  1940. }
  1941. quarterDatas.Add(quarterData);
  1942. }
  1943. dtData.Add(new
  1944. {
  1945. year = y,
  1946. //yearData = new { beginDt = $"{y}-01-01", endDt = $"{y}-12-31" },
  1947. quarterData = quarterDatas,
  1948. });
  1949. }
  1950. #endregion
  1951. return Ok(JsonView(true, "操作成功!", new { companyData = companyData, userData = userData, dtData = dtData }));
  1952. #endregion
  1953. }
  1954. private static string ConvertToChinese(int month)
  1955. {
  1956. if (month < 1 || month > 12)
  1957. throw new ArgumentOutOfRangeException(nameof(month), "月份必须在1到12之间。");
  1958. var cultureInfo = new System.Globalization.CultureInfo("zh-CN");
  1959. var dateTimeFormat = cultureInfo.DateTimeFormat;
  1960. return dateTimeFormat.GetMonthName(month);
  1961. }
  1962. /// <summary>
  1963. /// 市场部销售额
  1964. /// 年度/季度/月度 报表(同比)
  1965. /// </summary>
  1966. /// <param name="_dto">市场部销售额请求dto</param>
  1967. /// <returns></returns>
  1968. [HttpPost("PostMarketingSalesStatistics")]
  1969. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1970. public async Task<IActionResult> PostMarketingSalesStatistics_Year(MarketingSalesStatisticsDto _dto)
  1971. {
  1972. #region 参数验证
  1973. MarketingSalesStatisticsDtoFoalidator validationRules = new MarketingSalesStatisticsDtoFoalidator();
  1974. var validResult = await validationRules.ValidateAsync(_dto);
  1975. if (!validResult.IsValid)
  1976. {
  1977. var errors = new StringBuilder();
  1978. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  1979. return Ok(JsonView(false, errors.ToString()));
  1980. }
  1981. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1982. #region 页面操作权限验证
  1983. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  1984. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  1985. #endregion
  1986. #endregion
  1987. string beginDt = $"{_dto.BeginDt} 00:00:00", endDt = $"{_dto.EndDt} 23:59:59";
  1988. return Ok(JsonView(true, "操作成功!", await GroupSales(_dto.CompanyId, _dto.GroupPickupUserId, beginDt, endDt)));
  1989. }
  1990. private async Task<List<int>> GetUserIds(int companyId, int groupPickupUserId)
  1991. {
  1992. //全部人员Id
  1993. //查询所有公司的市场部
  1994. var pickGroupIds = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0).Select(it => it.JietuanOperator).Distinct().ToList();
  1995. var userIds = new List<int>();
  1996. var userDatas = await _sqlSugar.Queryable<Sys_Users>()
  1997. .InnerJoin<Sys_Company>((u, c) => u.CompanyId == c.Id)
  1998. .Where((u, c) => u.IsDel == 0 && pickGroupIds.Contains(u.Id))
  1999. .Select((u, c) => new { u.Id, u.CompanyId, u.CnName })
  2000. .ToListAsync();
  2001. userIds = userDatas.Select(it => it.Id).ToList();
  2002. if (companyId > 0)
  2003. {
  2004. userIds = userDatas.Where(it => it.CompanyId == companyId).Select(it => it.Id).ToList();
  2005. }
  2006. if (groupPickupUserId > 0)
  2007. {
  2008. userIds = userDatas.Where(it => it.Id == groupPickupUserId).Select(it => it.Id).ToList();
  2009. }
  2010. return userIds;
  2011. }
  2012. /// <summary>
  2013. /// 计算团组销售额
  2014. /// </summary>
  2015. /// <param name="companyId"></param>
  2016. /// <param name="groupPickupUserId"></param>
  2017. /// <param name="beginDt"></param>
  2018. /// <param name="endDt"></param>
  2019. /// <returns></returns>
  2020. private async Task<SalesYOYView> GroupSales(int companyId, int groupPickupUserId, string beginDt, string endDt)
  2021. {
  2022. decimal thisSales = 0.00M, lastSales = 0.00M, yoy = 1.00M;
  2023. var _view = new SalesYOYView();
  2024. List<int> userIds = new List<int>();
  2025. userIds = await GetUserIds(companyId, groupPickupUserId);
  2026. string userSqlWhere = "";
  2027. if (userIds.Count > 0)
  2028. {
  2029. userSqlWhere = string.Format($" And Id IN ({string.Join(',', userIds)})");
  2030. }
  2031. else
  2032. {
  2033. _view = new SalesYOYView
  2034. {
  2035. thisYearSales = "0.00",
  2036. lastYearSales = "0.00",
  2037. };
  2038. return _view;
  2039. }
  2040. string lastBeginDt = Convert.ToDateTime(beginDt).AddYears(-1).ToString("yyyy-MM-dd HH:mm:ss"),
  2041. lastEndDt = Convert.ToDateTime(endDt).AddYears(-1).ToString("yyyy-MM-dd HH:mm:ss");
  2042. // string salesSql = string.Format(@"
  2043. //SELECT
  2044. // 'ThisSales' As [Name],
  2045. // CAST(SUM(Sales) AS decimal(12,2)) As Sales
  2046. //FROM
  2047. // (
  2048. // SELECT di.VisitDate,
  2049. // (SELECT CAST(SUM(ItemSumPrice * Rate) AS decimal(12,2)) FROM Fin_ForeignReceivables
  2050. // WHERE IsDel = 0 AND AddingWay IN (0, 1, 2)AND di.Id = Diid
  2051. // ) AS Sales
  2052. // FROM
  2053. // Grp_DelegationInfo di
  2054. // WHERE di.IsDel = 0 AND di.IsSure = 1
  2055. // AND di.JietuanOperator IN (SELECT Id FROM Sys_Users WITH (NoLock) WHERE IsDel = 0 {0})
  2056. // AND di.VisitDate BETWEEN '{1}' AND '{2}'
  2057. // ) temp
  2058. //Union ALL
  2059. //SELECT
  2060. // 'LastSales' As [Name],
  2061. // CAST(SUM(Sales) AS decimal(12,2)) As Sales
  2062. //FROM
  2063. // (
  2064. // SELECT di.VisitDate,
  2065. // (SELECT CAST(SUM(ItemSumPrice * Rate) AS decimal(12,2)) FROM Fin_ForeignReceivables
  2066. // WHERE IsDel = 0 AND AddingWay IN (0, 1, 2)AND di.Id = Diid
  2067. // ) AS Sales
  2068. // FROM
  2069. // Grp_DelegationInfo di
  2070. // WHERE di.IsDel = 0 AND di.IsSure = 1
  2071. // AND di.JietuanOperator IN (SELECT Id FROM Sys_Users WITH (NoLock) WHERE IsDel = 0 {3})
  2072. // AND di.VisitDate BETWEEN '{4}' AND '{5}'
  2073. // ) temp", userSqlWhere, beginDt, endDt, userSqlWhere, lastBeginDt, lastEndDt);
  2074. string salesSql = string.Format(@"
  2075. SELECT
  2076. 'ThisSales' As [Name],
  2077. CAST(SUM(Sales) AS decimal(12,2)) As Sales
  2078. FROM
  2079. (
  2080. SELECT di.VisitDate,
  2081. (SELECT CAST(SUM(ItemSumPrice * Rate) AS decimal(12,2)) FROM Fin_ForeignReceivables
  2082. WHERE IsDel = 0 AND AddingWay IN (0, 1, 2)AND di.Id = Diid
  2083. ) AS Sales
  2084. FROM
  2085. Grp_DelegationInfo di
  2086. WHERE di.IsDel = 0
  2087. AND di.JietuanOperator IN (SELECT Id FROM Sys_Users WITH (NoLock) WHERE IsDel = 0 {0})
  2088. AND di.VisitDate BETWEEN '{1}' AND '{2}'
  2089. ) temp
  2090. Union ALL
  2091. SELECT
  2092. 'LastSales' As [Name],
  2093. CAST(SUM(Sales) AS decimal(12,2)) As Sales
  2094. FROM
  2095. (
  2096. SELECT di.VisitDate,
  2097. (SELECT CAST(SUM(ItemSumPrice * Rate) AS decimal(12,2)) FROM Fin_ForeignReceivables
  2098. WHERE IsDel = 0 AND AddingWay IN (0, 1, 2)AND di.Id = Diid
  2099. ) AS Sales
  2100. FROM
  2101. Grp_DelegationInfo di
  2102. WHERE di.IsDel = 0
  2103. AND di.JietuanOperator IN (SELECT Id FROM Sys_Users WITH (NoLock) WHERE IsDel = 0 {3})
  2104. AND di.VisitDate BETWEEN '{4}' AND '{5}'
  2105. ) temp", userSqlWhere, beginDt, endDt, userSqlWhere, lastBeginDt, lastEndDt);
  2106. var salesData = await _sqlSugar.SqlQueryable<SalesView>(salesSql).ToListAsync();
  2107. thisSales = salesData.Where(x => x.Name.Equals("ThisSales")).First()?.Sales ?? 0;
  2108. lastSales = salesData.Where(x => x.Name.Equals("LastSales")).First()?.Sales ?? 0;
  2109. if (lastSales != 0 && thisSales != 0) yoy = (thisSales - lastSales) / lastSales;
  2110. return new SalesYOYView()
  2111. {
  2112. thisYearSales = thisSales.ToString("#0.00"),
  2113. lastYearSales = lastSales.ToString("#0.00"),
  2114. yoy = yoy.ToString("#0.00")
  2115. };
  2116. }
  2117. private class SalesView
  2118. {
  2119. public string Name { get; set; }
  2120. public decimal Sales { get; set; }
  2121. }
  2122. private class SalesYOYView
  2123. {
  2124. public string thisYearSales { get; set; }
  2125. public string lastYearSales { get; set; }
  2126. public string yoy { get; set; } = "1.00";
  2127. }
  2128. /// <summary>
  2129. /// 市场部销售额
  2130. /// 团组列表
  2131. /// </summary>
  2132. /// <param name="_dto">市场部销售额请求dto</param>
  2133. /// <returns></returns>
  2134. [HttpPost("PostMarketingSalesGroupList")]
  2135. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2136. public async Task<IActionResult> PostMarketingSalesGroupList(MarketingSalesGroupListDto _dto)
  2137. {
  2138. #region 参数验证
  2139. MarketingSalesStatisticsDtoFoalidator validationRules = new MarketingSalesStatisticsDtoFoalidator();
  2140. var validResult = await validationRules.ValidateAsync(_dto);
  2141. if (!validResult.IsValid)
  2142. {
  2143. var errors = new StringBuilder();
  2144. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2145. return Ok(JsonView(false, errors.ToString()));
  2146. }
  2147. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2148. #region 页面操作权限验证
  2149. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2150. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2151. #endregion
  2152. #endregion
  2153. string userSql = "";
  2154. List<int> userIds = new List<int>();
  2155. userIds = await GetUserIds(_dto.CompanyId, _dto.GroupPickupUserId);
  2156. if (userIds.Count <= 0)
  2157. {
  2158. return Ok(JsonView(true, "操作成功!", new List<object> { }, 0));
  2159. }
  2160. else userSql = @$" And di.JietuanOperator In ({string.Join(",", userIds)})";
  2161. if (!string.IsNullOrEmpty(_dto.SearchCriteria))
  2162. {
  2163. userSql += string.Format(@$" AND di.TeamName Like '%{_dto.SearchCriteria}%'");
  2164. }
  2165. string beginDt = $"{_dto.BeginDt} 00:00:00", endDt = $"{_dto.EndDt} 23:59:59";
  2166. // string sql = string.Format(@$"SELECT
  2167. // ROW_NUMBER() OVER (
  2168. // ORDER BY
  2169. // CollectionDays
  2170. // ) AS RowNumber,
  2171. // *
  2172. //FROM
  2173. // (
  2174. // SELECT
  2175. // di.Id,
  2176. // di.TeamName,
  2177. // di.ClientUnit,
  2178. // di.ClientName,
  2179. // di.VisitDate,
  2180. // di.VisitPNumber,
  2181. // di.JietuanOperator,
  2182. // di.VisitEndDate,
  2183. // (
  2184. // SELECT
  2185. // CAST(
  2186. // COALESCE(SUM(ItemSumPrice * Rate), 0) AS DECIMAL(12, 2)
  2187. // ) AS GroupSales
  2188. // FROM
  2189. // Fin_ForeignReceivables
  2190. // WHERE
  2191. // IsDel = 0
  2192. // AND di.Id = Diid
  2193. // AND AddingWay IN (0, 1, 2)
  2194. // ) AS GroupSales,
  2195. // u.CnName AS GroupPickupUser,
  2196. // DATEADD(DAY, 7, di.VisitEndDate) AS CollectionDays
  2197. // FROM
  2198. // Grp_DelegationInfo di
  2199. // WITH
  2200. // (NoLock)
  2201. // LEFT JOIN Sys_Users u ON di.JietuanOperator = u.Id
  2202. // WHERE
  2203. // di.Isdel = 0
  2204. // AND di.IsSure = 1 {userSql}
  2205. // AND VisitDate Between '{beginDt}' And '{endDt}'
  2206. // ) Temp ");
  2207. string sql = string.Format(@$"SELECT
  2208. ROW_NUMBER() OVER (
  2209. ORDER BY
  2210. CollectionDays
  2211. ) AS RowNumber,
  2212. *
  2213. FROM
  2214. (
  2215. SELECT
  2216. di.Id,
  2217. di.TeamName,
  2218. di.ClientUnit,
  2219. di.ClientName,
  2220. di.VisitDate,
  2221. di.VisitPNumber,
  2222. di.JietuanOperator,
  2223. di.VisitEndDate,
  2224. (
  2225. SELECT
  2226. CAST(
  2227. COALESCE(SUM(ItemSumPrice * Rate), 0) AS DECIMAL(12, 2)
  2228. ) AS GroupSales
  2229. FROM
  2230. Fin_ForeignReceivables
  2231. WHERE
  2232. IsDel = 0
  2233. AND di.Id = Diid
  2234. AND AddingWay IN (0, 1, 2)
  2235. ) AS GroupSales,
  2236. u.CnName AS GroupPickupUser,
  2237. DATEADD(DAY, 7, di.VisitEndDate) AS CollectionDays
  2238. FROM
  2239. Grp_DelegationInfo di
  2240. WITH
  2241. (NoLock)
  2242. LEFT JOIN Sys_Users u ON di.JietuanOperator = u.Id
  2243. WHERE
  2244. di.Isdel = 0
  2245. AND (
  2246. SELECT
  2247. CAST(
  2248. COALESCE(SUM(ItemSumPrice * Rate), 0) AS DECIMAL(12, 2)
  2249. ) AS GroupSales
  2250. FROM
  2251. Fin_ForeignReceivables
  2252. WHERE
  2253. IsDel = 0
  2254. AND di.Id = Diid
  2255. AND AddingWay IN (0, 1, 2)
  2256. ) > 0
  2257. {userSql}
  2258. AND VisitDate Between '{beginDt}' And '{endDt}'
  2259. ) Temp ");
  2260. RefAsync<int> total = 0;
  2261. var groupData = await _sqlSugar.SqlQueryable<MarketingSalesGroupList>(sql).ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);
  2262. return Ok(JsonView(true, "操作成功!", groupData, total));
  2263. }
  2264. /// <summary>
  2265. /// 市场部销售额
  2266. /// 团组列表Excel下载
  2267. /// </summary>
  2268. /// <param name="_dto">市场部销售额请求dto</param>
  2269. /// <returns></returns>
  2270. [HttpPost("PostMarketingSalesGroupExcel")]
  2271. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2272. public async Task<IActionResult> PostMarketingSalesGroupExcel(MarketingSalesGroupListDto _dto)
  2273. {
  2274. #region 参数验证
  2275. MarketingSalesStatisticsDtoFoalidator validationRules = new MarketingSalesStatisticsDtoFoalidator();
  2276. var validResult = await validationRules.ValidateAsync(_dto);
  2277. if (!validResult.IsValid)
  2278. {
  2279. var errors = new StringBuilder();
  2280. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2281. return Ok(JsonView(false, errors.ToString()));
  2282. }
  2283. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2284. #region 页面操作权限验证
  2285. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2286. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2287. #endregion
  2288. #endregion
  2289. string userSql = "";
  2290. var userIds = new List<int>();
  2291. userIds = await GetUserIds(_dto.CompanyId, _dto.GroupPickupUserId);
  2292. if (userIds.Count <= 0)
  2293. {
  2294. return Ok(JsonView(false));
  2295. }
  2296. else userSql = @$" And di.JietuanOperator In ({string.Join(",", userIds)})";
  2297. if (!string.IsNullOrEmpty(_dto.SearchCriteria))
  2298. {
  2299. userSql += string.Format(@$" AND di.TeamName Like '%{_dto.SearchCriteria}%'");
  2300. }
  2301. string beginDt = $"{_dto.BeginDt} 00:00:00",
  2302. endDt = $"{_dto.EndDt} 23:59:59";
  2303. string sql = string.Format(@$"SELECT
  2304. ROW_NUMBER() OVER (
  2305. ORDER BY
  2306. CollectionDays
  2307. ) AS RowNumber,
  2308. *
  2309. FROM
  2310. (
  2311. SELECT
  2312. di.Id,
  2313. di.TeamName,
  2314. di.ClientUnit,
  2315. di.ClientName,
  2316. di.VisitDate,
  2317. di.VisitPNumber,
  2318. di.JietuanOperator,
  2319. di.VisitEndDate,
  2320. (
  2321. SELECT
  2322. CAST(
  2323. COALESCE(SUM(ItemSumPrice * Rate), 0) AS DECIMAL(12, 2)
  2324. ) AS GroupSales
  2325. FROM
  2326. Fin_ForeignReceivables
  2327. WHERE
  2328. IsDel = 0
  2329. AND di.Id = Diid
  2330. AND AddingWay IN (0, 1, 2)
  2331. ) AS GroupSales,
  2332. u.CnName AS GroupPickupUser,
  2333. DATEADD(DAY, 7, di.VisitEndDate) AS CollectionDays
  2334. FROM
  2335. Grp_DelegationInfo di
  2336. WITH
  2337. (NoLock)
  2338. LEFT JOIN Sys_Users u ON di.JietuanOperator = u.Id
  2339. WHERE
  2340. di.Isdel = 0
  2341. AND (
  2342. SELECT
  2343. CAST(
  2344. COALESCE(SUM(ItemSumPrice * Rate), 0) AS DECIMAL(12, 2)
  2345. ) AS GroupSales
  2346. FROM
  2347. Fin_ForeignReceivables
  2348. WHERE
  2349. IsDel = 0
  2350. AND di.Id = Diid
  2351. AND AddingWay IN (0, 1, 2)
  2352. ) > 0
  2353. {userSql}
  2354. AND VisitDate Between '{beginDt}' And '{endDt}'
  2355. ) Temp ");
  2356. var view = await _sqlSugar.SqlQueryable<MarketingSalesGroupList>(sql).ToListAsync();
  2357. if (view.Count < 1 ) return Ok(JsonView(false, "暂无数据!"));
  2358. //DataTable dt = GeneralMethod.
  2359. DataTable dt = CommonFun.GetDataTableFromIList(view);
  2360. dt.TableName = $"_view";
  2361. WorkbookDesigner designer = new WorkbookDesigner();
  2362. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/营业额团组报表模板.xls");
  2363. designer.SetDataSource(dt);
  2364. designer.SetDataSource("Total", view.Sum(x => x.GroupSales));
  2365. designer.Workbook.Worksheets[0].Name = "营业额团组报表";
  2366. designer.Process();
  2367. string fileName = $"MarketingSales/{_dto.BeginDt}{_dto.EndDt}营业额团组报表{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx";
  2368. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  2369. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  2370. return Ok(JsonView(true, "操作成功", new { url = rst }));
  2371. }
  2372. /// <summary>
  2373. /// 市场部销售额
  2374. /// 客户类型、客户等级 统计
  2375. /// </summary>
  2376. /// <param name="_dto">市场部销售额请求dto</param>
  2377. /// <returns></returns>
  2378. [HttpPost("PostMarketingSalesGroupStatistics")]
  2379. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2380. public async Task<IActionResult> PostMarketingSalesGroupStatistics(MarketingSalesGroupStatisticsDto _dto)
  2381. {
  2382. #region 参数验证
  2383. MarketingSalesStatisticsDtoFoalidator validationRules = new MarketingSalesStatisticsDtoFoalidator();
  2384. var validResult = await validationRules.ValidateAsync(_dto);
  2385. if (!validResult.IsValid)
  2386. {
  2387. var errors = new StringBuilder();
  2388. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2389. return Ok(JsonView(false, errors.ToString()));
  2390. }
  2391. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2392. #region 页面操作权限验证
  2393. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2394. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2395. #endregion
  2396. #endregion
  2397. string beginDt = $"{_dto.BeginDt} 00:00:00", endDt = $"{_dto.EndDt} 23:59:59";
  2398. List<int> userIds = await GetUserIds(_dto.CompanyId, _dto.GroupPickupUserId);
  2399. string userSql = "";
  2400. if (userIds.Count > 0)
  2401. {
  2402. userSql = string.Format(@$" AND JietuanOperator IN ({string.Join(",", userIds)})");
  2403. }
  2404. else
  2405. {
  2406. if (_dto.PortType == 2 || _dto.PortType == 3)
  2407. {
  2408. return Ok(JsonView(true, "操作成功!", new List<object> { }));
  2409. }
  2410. else
  2411. {
  2412. return Ok(JsonView(true, "操作成功!", new
  2413. {
  2414. customerTypeData = new List<object> { },
  2415. clientGradeData = new List<object> { }
  2416. }));
  2417. }
  2418. }
  2419. string sql = "";
  2420. if (_dto.StatisticsType == 1)
  2421. {
  2422. sql = string.Format(@$"Select
  2423. sd.[Name],
  2424. Count(*) As [Count]
  2425. From Grp_DelegationInfo di
  2426. Left Join Sys_SetData sd On di.TeamDid = sd.Id
  2427. Where di.Isdel = 0
  2428. And (
  2429. SELECT
  2430. CAST(
  2431. COALESCE(SUM(ItemSumPrice * Rate), 0) AS DECIMAL(12, 2)
  2432. ) AS GroupSales
  2433. FROM
  2434. Fin_ForeignReceivables fr
  2435. WHERE
  2436. fr.IsDel = 0
  2437. AND di.Id = fr.Diid
  2438. AND AddingWay IN (0, 1, 2)
  2439. ) > 0
  2440. {userSql}
  2441. And VisitDate Between '{beginDt}' And '{endDt}'
  2442. Group By [Name]
  2443. Order By Count Desc");
  2444. }
  2445. else if (_dto.StatisticsType == 2)
  2446. {
  2447. sql = string.Format(@$"Select
  2448. sd.[Name],
  2449. Count(*) As [Count]
  2450. From Grp_DelegationInfo di
  2451. Left Join Sys_SetData sd On di.TeamLevSId = sd.Id
  2452. Where di.Isdel = 0
  2453. And (
  2454. SELECT
  2455. CAST(
  2456. COALESCE(SUM(ItemSumPrice * Rate), 0) AS DECIMAL(12, 2)
  2457. ) AS GroupSales
  2458. FROM
  2459. Fin_ForeignReceivables fr
  2460. WHERE
  2461. fr.IsDel = 0
  2462. AND di.Id = fr.Diid
  2463. AND AddingWay IN (0, 1, 2)
  2464. ) > 0
  2465. {userSql}
  2466. And VisitDate Between '{beginDt}' And '{endDt}'
  2467. Group By [Name]
  2468. Order By Count Desc");
  2469. }
  2470. else return Ok(JsonView(false, "StatisticsType不在可取范围!"));
  2471. if (_dto.PortType == 1)
  2472. {
  2473. string sql1 = string.Format(@$"Select
  2474. sd.[Name],
  2475. Count(*) As [Count]
  2476. From Grp_DelegationInfo di
  2477. Left Join Sys_SetData sd On di.TeamDid = sd.Id
  2478. Where di.Isdel = 0
  2479. And (
  2480. SELECT
  2481. CAST(
  2482. COALESCE(SUM(ItemSumPrice * Rate), 0) AS DECIMAL(12, 2)
  2483. ) AS GroupSales
  2484. FROM
  2485. Fin_ForeignReceivables fr
  2486. WHERE
  2487. fr.IsDel = 0
  2488. AND di.Id = fr.Diid
  2489. AND AddingWay IN (0, 1, 2)
  2490. ) > 0
  2491. {userSql}
  2492. And VisitDate Between '{beginDt}' And '{endDt}'
  2493. Group By [Name]
  2494. Order By Count Desc");
  2495. var customerTypeData = await _sqlSugar.SqlQueryable<MarketingSalesGroupStatisticsView>(sql1).ToListAsync();
  2496. string sql2 = string.Format(@$"Select
  2497. sd.[Name],
  2498. Count(*) As [Count]
  2499. From Grp_DelegationInfo di
  2500. Left Join Sys_SetData sd On di.TeamLevSId = sd.Id
  2501. Where di.Isdel = 0
  2502. And (
  2503. SELECT
  2504. CAST(
  2505. COALESCE(SUM(ItemSumPrice * Rate), 0) AS DECIMAL(12, 2)
  2506. ) AS GroupSales
  2507. FROM
  2508. Fin_ForeignReceivables fr
  2509. WHERE
  2510. fr.IsDel = 0
  2511. AND di.Id = fr.Diid
  2512. AND AddingWay IN (0, 1, 2)
  2513. ) > 0
  2514. {userSql}
  2515. And VisitDate Between '{beginDt}' And '{endDt}'
  2516. Group By [Name]
  2517. Order By Count Desc");
  2518. var clientGradeData = await _sqlSugar.SqlQueryable<MarketingSalesGroupStatisticsView>(sql2).ToListAsync();
  2519. return Ok(JsonView(true, "操作成功!", new
  2520. {
  2521. customerTypeData = customerTypeData,
  2522. clientGradeData = clientGradeData
  2523. }));
  2524. }
  2525. else if (_dto.PortType == 2 || _dto.PortType == 3)
  2526. {
  2527. var data = await _sqlSugar.SqlQueryable<MarketingSalesGroupStatisticsView>(sql).ToListAsync();
  2528. return Ok(JsonView(true, "操作成功!", data, data.Count));
  2529. }
  2530. else return Ok(JsonView(false, MsgTips.Port));
  2531. }
  2532. /// <summary>
  2533. /// 市场部销售额
  2534. /// 接单排名
  2535. /// </summary>
  2536. /// <param name="_dto">市场部销售额请求dto</param>
  2537. /// <returns></returns>
  2538. [HttpPost("PostMarketingSalesOrderRanking")]
  2539. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2540. public async Task<IActionResult> PostMarketingSalesOrderRanking(MarketingSalesOrderRankingDto _dto)
  2541. {
  2542. #region 参数验证
  2543. MarketingSalesStatisticsDtoFoalidator validationRules = new MarketingSalesStatisticsDtoFoalidator();
  2544. var validResult = await validationRules.ValidateAsync(_dto);
  2545. if (!validResult.IsValid)
  2546. {
  2547. var errors = new StringBuilder();
  2548. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2549. return Ok(JsonView(false, errors.ToString()));
  2550. }
  2551. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2552. #region 页面操作权限验证
  2553. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2554. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2555. #endregion
  2556. #endregion
  2557. string beginDt = $"{_dto.BeginDt} 00:00:00", endDt = $"{_dto.EndDt} 23:59:59";
  2558. List<int> userIds = await GetUserIds(_dto.CompanyId, _dto.GroupPickupUserId);
  2559. string userSql = "";
  2560. if (userIds.Count > 0)
  2561. {
  2562. userSql = string.Format(@$" AND JietuanOperator IN ({string.Join(",", userIds)})");
  2563. }
  2564. else return Ok(JsonView(true, "操作成功!", new List<object> { }, 0));
  2565. string sql = string.Format(@$"Select
  2566. ROW_NUMBER() Over(Order By Count(*) Desc) As RowNumber,
  2567. u.CnName As UserName,
  2568. Count(*) As [Count]
  2569. From Grp_DelegationInfo di
  2570. Left Join Sys_Users u On di.JietuanOperator = u.Id
  2571. Where di.Isdel = 0
  2572. And (
  2573. SELECT
  2574. CAST(
  2575. COALESCE(SUM(ItemSumPrice * Rate), 0) AS DECIMAL(12, 2)
  2576. ) AS GroupSales
  2577. FROM
  2578. Fin_ForeignReceivables fr
  2579. WHERE
  2580. fr.IsDel = 0
  2581. AND di.Id = fr.Diid
  2582. AND AddingWay IN (0, 1, 2)
  2583. ) > 0
  2584. {userSql}
  2585. And VisitDate Between '{beginDt}' And '{endDt}'
  2586. Group By CnName");
  2587. RefAsync<int> total = 0;
  2588. var rankingData = await _sqlSugar.SqlQueryable<MarketingSalesOrderRankingView>(sql).ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);
  2589. return Ok(JsonView(true, "操作成功!", rankingData, total));
  2590. }
  2591. /// <summary>
  2592. /// 市场部销售额
  2593. /// 团组列表、客户类型、客户等级、接单排名
  2594. /// </summary>
  2595. /// <param name="_dto">市场部销售额请求dto</param>
  2596. /// <returns></returns>
  2597. [HttpPost("PostMarketingSalesGroupItem")]
  2598. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2599. public async Task<IActionResult> PostMarketingSalesGroupItem(MarketingSalesGroupListDto _dto)
  2600. {
  2601. #region 参数验证
  2602. MarketingSalesStatisticsDtoFoalidator validationRules = new MarketingSalesStatisticsDtoFoalidator();
  2603. var validResult = await validationRules.ValidateAsync(_dto);
  2604. if (!validResult.IsValid)
  2605. {
  2606. var errors = new StringBuilder();
  2607. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2608. return Ok(JsonView(false, errors.ToString()));
  2609. }
  2610. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2611. #region 页面操作权限验证
  2612. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2613. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2614. #endregion
  2615. #endregion
  2616. string userSql = "";
  2617. List<int> userIds = new List<int>();
  2618. userIds = await GetUserIds(_dto.CompanyId, _dto.GroupPickupUserId);
  2619. if (userIds.Count <= 0)
  2620. {
  2621. return Ok(JsonView(true, "操作成功!", new List<object> { }, 0));
  2622. }
  2623. else userSql = @$" And di.JietuanOperator In ({string.Join(",", userIds)})";
  2624. if (!string.IsNullOrEmpty(_dto.SearchCriteria))
  2625. {
  2626. userSql += string.Format(@$" AND di.TeamName Like '%{_dto.SearchCriteria}%'");
  2627. }
  2628. string beginDt = $"{_dto.BeginDt} 00:00:00", endDt = $"{_dto.EndDt} 23:59:59";
  2629. #region 团组List
  2630. string sql = string.Format(@$"SELECT
  2631. ROW_NUMBER() OVER (
  2632. ORDER BY
  2633. CollectionDays
  2634. ) AS RowNumber,
  2635. *
  2636. FROM
  2637. (
  2638. SELECT
  2639. di.Id,
  2640. di.TeamName,
  2641. di.ClientUnit,
  2642. di.ClientName,
  2643. di.VisitDate,
  2644. di.VisitPNumber,
  2645. di.JietuanOperator,
  2646. di.VisitEndDate,
  2647. (
  2648. SELECT
  2649. CAST(
  2650. COALESCE(SUM(ItemSumPrice * Rate), 0) AS DECIMAL(12, 2)
  2651. ) AS GroupSales
  2652. FROM
  2653. Fin_ForeignReceivables
  2654. WHERE
  2655. IsDel = 0
  2656. AND di.Id = Diid
  2657. AND AddingWay IN (0, 1, 2)
  2658. ) AS GroupSales,
  2659. u.CnName AS GroupPickupUser,
  2660. DATEADD(DAY, 7, di.VisitEndDate) AS CollectionDays
  2661. FROM
  2662. Grp_DelegationInfo di
  2663. WITH
  2664. (NoLock)
  2665. LEFT JOIN Sys_Users u ON di.JietuanOperator = u.Id
  2666. WHERE
  2667. di.Isdel = 0
  2668. AND (
  2669. SELECT
  2670. CAST(
  2671. COALESCE(SUM(ItemSumPrice * Rate), 0) AS DECIMAL(12, 2)
  2672. ) AS GroupSales
  2673. FROM
  2674. Fin_ForeignReceivables fr
  2675. WHERE
  2676. fr.IsDel = 0
  2677. AND di.Id = fr.Diid
  2678. AND AddingWay IN (0, 1, 2)
  2679. ) > 0
  2680. {userSql}
  2681. AND VisitDate Between '{beginDt}' And '{endDt}'
  2682. ) Temp ");
  2683. RefAsync<int> total = 0;
  2684. var groupData = await _sqlSugar.SqlQueryable<MarketingSalesGroupList>(sql).ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);
  2685. #endregion
  2686. #region 客户类型、客户等级 统计
  2687. string sql1 = string.Format(@$"Select
  2688. sd.[Name],
  2689. Count(*) As [Count]
  2690. From Grp_DelegationInfo di
  2691. Left Join Sys_SetData sd On di.TeamDid = sd.Id
  2692. Where di.Isdel = 0
  2693. And (
  2694. SELECT
  2695. CAST(
  2696. COALESCE(SUM(ItemSumPrice * Rate), 0) AS DECIMAL(12, 2)
  2697. ) AS GroupSales
  2698. FROM
  2699. Fin_ForeignReceivables fr
  2700. WHERE
  2701. fr.IsDel = 0
  2702. AND di.Id = fr.Diid
  2703. AND AddingWay IN (0, 1, 2)
  2704. ) > 0
  2705. {userSql}
  2706. And VisitDate Between '{beginDt}' And '{endDt}'
  2707. Group By [Name]
  2708. Order By Count Desc");
  2709. var customerTypeData = await _sqlSugar.SqlQueryable<MarketingSalesGroupStatisticsView>(sql1).ToListAsync();
  2710. string sql2 = string.Format(@$"Select
  2711. sd.[Name],
  2712. Count(*) As [Count]
  2713. From Grp_DelegationInfo di
  2714. Left Join Sys_SetData sd On di.TeamLevSId = sd.Id
  2715. Where di.Isdel = 0
  2716. And (
  2717. SELECT
  2718. CAST(
  2719. COALESCE(SUM(ItemSumPrice * Rate), 0) AS DECIMAL(12, 2)
  2720. ) AS GroupSales
  2721. FROM
  2722. Fin_ForeignReceivables fr
  2723. WHERE
  2724. fr.IsDel = 0
  2725. AND di.Id = fr.Diid
  2726. AND AddingWay IN (0, 1, 2)
  2727. ) > 0
  2728. {userSql}
  2729. And VisitDate Between '{beginDt}' And '{endDt}'
  2730. Group By [Name]
  2731. Order By Count Desc");
  2732. var clientGradeData = await _sqlSugar.SqlQueryable<MarketingSalesGroupStatisticsView>(sql2).ToListAsync();
  2733. #endregion
  2734. #region 接单排名
  2735. string sql4 = string.Format(@$"Select
  2736. ROW_NUMBER() Over(Order By Count(*) Desc) As RowNumber,
  2737. u.CnName As UserName,
  2738. Count(*) As [Count]
  2739. From Grp_DelegationInfo di
  2740. Left Join Sys_Users u On di.JietuanOperator = u.Id
  2741. Where di.Isdel = 0
  2742. And (
  2743. SELECT
  2744. CAST(
  2745. COALESCE(SUM(ItemSumPrice * Rate), 0) AS DECIMAL(12, 2)
  2746. ) AS GroupSales
  2747. FROM
  2748. Fin_ForeignReceivables fr
  2749. WHERE
  2750. fr.IsDel = 0
  2751. AND di.Id = fr.Diid
  2752. AND AddingWay IN (0, 1, 2)
  2753. ) > 0
  2754. {userSql}
  2755. And VisitDate Between '{beginDt}' And '{endDt}'
  2756. Group By CnName");
  2757. var rankingData = await _sqlSugar.SqlQueryable<MarketingSalesOrderRankingView>(sql4).ToListAsync();
  2758. #endregion
  2759. var viewData = new
  2760. {
  2761. groupData = groupData,
  2762. groupTotal = total,
  2763. customerTypeData = customerTypeData,
  2764. clientGradeData = clientGradeData,
  2765. rankingData = rankingData
  2766. };
  2767. return Ok(JsonView(true, "操作成功!", viewData, total));
  2768. }
  2769. /// <summary>
  2770. /// 市场部销售额
  2771. /// 客户拜访列表
  2772. /// </summary>
  2773. /// <param name="_dto">市场部销售额请求dto</param>
  2774. /// <returns></returns>
  2775. [HttpPost("PostMarketingSalesVCList")]
  2776. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2777. public async Task<IActionResult> PostMarketingSalesVCList(MarketingSalesVCListDto _dto)
  2778. {
  2779. #region 参数验证
  2780. MarketingSalesUserPageFuncDtoBaseFoalidator validationRules = new MarketingSalesUserPageFuncDtoBaseFoalidator();
  2781. var validResult = await validationRules.ValidateAsync(_dto);
  2782. if (!validResult.IsValid)
  2783. {
  2784. var errors = new StringBuilder();
  2785. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2786. return Ok(JsonView(false, errors.ToString()));
  2787. }
  2788. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2789. #region 页面操作权限验证
  2790. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2791. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2792. #endregion
  2793. #endregion
  2794. return Ok(await _visitingClientsRep._List(_dto.PortType, _dto.PageIndex, _dto.PageSize, _dto.DiId, _dto.Search));
  2795. }
  2796. /// <summary>
  2797. /// 市场部销售额
  2798. /// 客户拜访 操作(添加 Or 编辑)
  2799. /// </summary>
  2800. /// <param name="_dto">市场部销售额请求dto</param>
  2801. /// <returns></returns>
  2802. [HttpPost("PostMarketingSalesVCOperate")]
  2803. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2804. public async Task<IActionResult> PostMarketingSalesVCOperate(MarketingSalesVCOperrateDto _dto)
  2805. {
  2806. #region 参数验证
  2807. MarketingSalesUserPageFuncDtoBaseFoalidator validationRules = new MarketingSalesUserPageFuncDtoBaseFoalidator();
  2808. var validResult = await validationRules.ValidateAsync(_dto);
  2809. if (!validResult.IsValid)
  2810. {
  2811. var errors = new StringBuilder();
  2812. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2813. return Ok(JsonView(false, errors.ToString()));
  2814. }
  2815. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2816. #region 页面操作权限验证
  2817. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2818. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2819. #endregion
  2820. #endregion
  2821. return Ok(await _visitingClientsRep._AddOrEdit(_dto));
  2822. }
  2823. /// <summary>
  2824. /// 市场部销售额
  2825. /// 客户拜访 Del
  2826. /// </summary>
  2827. /// <param name="_dto">市场部销售额请求dto</param>
  2828. /// <returns></returns>
  2829. [HttpPost("PostMarketingSalesVCDel")]
  2830. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2831. public async Task<IActionResult> PostMarketingSalesVCDel(MarketingSalesVCDelDto _dto)
  2832. {
  2833. return Ok(await _visitingClientsRep._Del(_dto.Id, _dto.UserId));
  2834. }
  2835. /// <summary>
  2836. /// 市场部销售额
  2837. /// 客户拜访 操作 save
  2838. /// </summary>
  2839. /// <param name="_dto">市场部销售额请求dto</param>
  2840. /// <returns></returns>
  2841. [HttpPost("PostMarketingSalesVCSave")]
  2842. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2843. public async Task<IActionResult> PostMarketingSalesVCSave(MarketingSalesVCSaveDto _dto)
  2844. {
  2845. #region 参数验证
  2846. MarketingSalesUserPageFuncDtoBaseFoalidator validationRules = new MarketingSalesUserPageFuncDtoBaseFoalidator();
  2847. var validResult = await validationRules.ValidateAsync(_dto);
  2848. if (!validResult.IsValid)
  2849. {
  2850. var errors = new StringBuilder();
  2851. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2852. return Ok(JsonView(false, errors.ToString()));
  2853. }
  2854. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2855. #region 页面操作权限验证
  2856. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2857. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2858. #endregion
  2859. #endregion
  2860. return Ok(await _visitingClientsRep._Save(_dto));
  2861. }
  2862. #endregion
  2863. #region 日付报表
  2864. /// <summary>
  2865. /// 日付类型数据
  2866. /// </summary>
  2867. /// <param name="_dto"></param>
  2868. /// <returns></returns>
  2869. [HttpPost("DailypaymentTypeInit")]
  2870. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2871. public async Task<IActionResult> DailypaymentTypeInit(DailypaymentTypeInitDto _dto)
  2872. {
  2873. #region 参数验证
  2874. if (_dto.PortType < 1 || _dto.PortType > 3) return Ok(JsonView(false, msg: MsgTips.Port));
  2875. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2876. #region 页面操作权限验证
  2877. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2878. //if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  2879. #endregion
  2880. #endregion
  2881. if (_dto.PortType == 1 || _dto.PortType == 2 || _dto.PortType == 3) // web/Android/IOS
  2882. {
  2883. var defaultParentIds = new List<int>() {
  2884. 48,// 人员费用
  2885. 49,// 办公费用
  2886. 50,// 销售费用
  2887. 51,// 其他费用
  2888. 55,// 大运会
  2889. };
  2890. var dailypaymentTypeData = await RedisRepository.RedisFactory
  2891. .CreateRedisRepository()
  2892. .StringGetAsync<List<int>>("DailypaymentTypeData") ?? new List<int>();
  2893. var dailyTypeData = await _sqlSugar.Queryable<DailypaymentParentTypeView>()
  2894. .Includes(x => x.SubData)
  2895. .Where(x => defaultParentIds.Contains(x.Id))
  2896. .ToListAsync();
  2897. dailyTypeData.ForEach(x =>
  2898. {
  2899. x.SubData.ForEach(y =>
  2900. {
  2901. int currId = dailypaymentTypeData.Find(z => z == y.Id);
  2902. y.IsChecked = currId == 0 ? false : true;
  2903. });
  2904. });
  2905. var companyData = await _sqlSugar.Queryable<Sys_Company>()
  2906. .Where(x => x.IsDel == 0)
  2907. .Select(x => new { id = x.Id, name = x.CompanyName })
  2908. .ToListAsync();
  2909. return Ok(JsonView(true, "查询成功!", new { dailyTypeData = dailyTypeData, companyData = companyData }));
  2910. }
  2911. else
  2912. {
  2913. return Ok(JsonView(false, "查询失败"));
  2914. }
  2915. }
  2916. /// <summary>
  2917. /// 日付类型数据 Save
  2918. /// </summary>
  2919. /// <param name="_dto"></param>
  2920. /// <returns></returns>
  2921. [HttpPost("DailypaymentTypeDataSave")]
  2922. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2923. public async Task<IActionResult> DailypaymentTypeDataSave(DailypaymentTypeDataSaveDto _dto)
  2924. {
  2925. #region 参数验证
  2926. if (_dto.PortType < 1 || _dto.PortType > 3) return Ok(JsonView(false, msg: MsgTips.Port));
  2927. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2928. #region 页面操作权限验证
  2929. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2930. //if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  2931. #endregion
  2932. #endregion
  2933. if (_dto.PortType == 1 || _dto.PortType == 2 || _dto.PortType == 3) // web/Android/IOS
  2934. {
  2935. if (_dto.TypeIds.Count < 1) return Ok(JsonView(false, "请传入需要保存的TypeIds"));
  2936. var res = await RedisRepository.RedisFactory
  2937. .CreateRedisRepository()
  2938. .StringSetAsync(
  2939. key: "DailypaymentTypeData",
  2940. _dto.TypeIds,
  2941. timeout: null);
  2942. if (!res) return Ok(JsonView(false, "操作失败"));
  2943. return Ok(JsonView(true, "操作成功!"));
  2944. }
  2945. else return Ok(JsonView(false, "操作失败"));
  2946. }
  2947. /// <summary>
  2948. /// 日付数据列表
  2949. /// </summary>
  2950. /// <param name="_dto"></param>
  2951. /// <returns></returns>
  2952. [HttpPost("DailypaymentRange")]
  2953. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2954. public async Task<IActionResult> DailypaymentRange(DailypaymentRangeDto _dto)
  2955. {
  2956. #region 参数验证
  2957. var validator = new DailypaymentRangeDtoValidator();
  2958. var validationRes = validator.Validate(_dto);
  2959. if (!validationRes.IsValid)
  2960. {
  2961. StringBuilder sb = new StringBuilder();
  2962. foreach (var item in validationRes.Errors)
  2963. {
  2964. sb.AppendLine(item.ErrorMessage);
  2965. }
  2966. return Ok(JsonView(false, sb.ToString()));
  2967. }
  2968. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2969. #region 页面操作权限验证
  2970. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2971. //if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  2972. #endregion
  2973. #endregion
  2974. if (_dto.PortType == 1 || _dto.PortType == 2 || _dto.PortType == 3) // web/Android/IOS
  2975. {
  2976. DateTime _beginDt = Convert.ToDateTime($"{_dto.BeginDt} 00:00:00"),
  2977. _endDt = Convert.ToDateTime($"{_dto.EndDt} 23:59:59");
  2978. var sqlWhere = string.Format(@" And dfp.CreateTime Between '{0}' And '{1}'", _beginDt, _endDt);
  2979. var dailypaymentTypeData = await RedisRepository.RedisFactory
  2980. .CreateRedisRepository()
  2981. .StringGetAsync<List<int>>("DailypaymentTypeData") ?? new List<int>();
  2982. var sql = string.Format(@"
  2983. Select
  2984. dfp.Id,
  2985. dfp.Instructions,
  2986. dfp.PriceTypeId,
  2987. sd1.Name As FeeType,
  2988. dfp.TransferTypeId,
  2989. sd2.Name As TransferType,
  2990. dfp.SumPrice,
  2991. dfp.FAuditDate,
  2992. dfp.MAuditDate,
  2993. dfp.CompanyId,
  2994. c.CompanyName,
  2995. dfp.CreateUserId As ApplicantId,
  2996. u.CnName As Applicant,
  2997. dfp.CreateTime As ApplicantDt,
  2998. dfp.Instructions+u.CnName As ViewStr
  2999. From Fin_DailyFeePayment dfp
  3000. Left Join Sys_Users u On dfp.CreateUserId = u.Id
  3001. Left Join Sys_SetData sd1 On dfp.TransferTypeId = sd1.Id
  3002. Left Join Sys_Company c On dfp.CompanyId = c.Id
  3003. Left Join Sys_SetData sd2 On dfp.PriceTypeId = sd2.Id
  3004. Where dfp.IsDel = 0 And dfp.IsPay = 1
  3005. ");//--Order By dfp.CreateTime Desc
  3006. if (_dto.Type == 1) //data
  3007. {
  3008. RefAsync<int> total = 0;
  3009. var _view = await _sqlSugar.SqlQueryable<DailyFeePaymentRangeView>(sql)
  3010. .Where(x => x.ApplicantDt >= _beginDt && x.ApplicantDt <= _endDt)
  3011. .WhereIF(dailypaymentTypeData.Count > 0,
  3012. x => dailypaymentTypeData.Contains(x.PriceTypeId))
  3013. .WhereIF(_dto.CompanyIds.Count > 0, x => _dto.CompanyIds.Contains(x.CompanyId))
  3014. .WhereIF(!string.IsNullOrEmpty(_dto.Filter), x => x.ViewStr.Contains(_dto.Filter))
  3015. .OrderByDescending(x => x.ApplicantDt)
  3016. .ToPageListAsync(
  3017. pageNumber: _dto.PageIndex,
  3018. pageSize: _dto.PageSize,
  3019. totalNumber: total
  3020. );
  3021. _sqlSugar.ThenMapper(_view, x =>
  3022. {
  3023. x.Contents = _sqlSugar.Queryable<DailyFeePaymentContentView>()
  3024. .SetContext(x1 => x1.DFPId, () => x.Id, x)
  3025. .ToList();
  3026. });
  3027. //单独处理
  3028. return Ok(JsonView(true, "操作成功!", new { data = _view, total = _view.Sum(x => x.SumPrice) }, total));
  3029. }
  3030. else if (_dto.Type == 2) //view
  3031. {
  3032. var _view = await _sqlSugar.SqlQueryable<ExcelView>(sql)
  3033. .Where(x => x.ApplicantDt >= _beginDt && x.ApplicantDt <= _endDt)
  3034. .WhereIF(dailypaymentTypeData.Count > 0,
  3035. x => dailypaymentTypeData.Contains(x.PriceTypeId))
  3036. .WhereIF(_dto.CompanyIds.Count > 0, x => _dto.CompanyIds.Contains(x.CompanyId))
  3037. .WhereIF(!string.IsNullOrEmpty(_dto.Filter), x => x.ViewStr.Contains(_dto.Filter))
  3038. .OrderByDescending(x => x.ApplicantDt)
  3039. .ToPageListAsync(
  3040. pageNumber: 1,
  3041. pageSize: 99999
  3042. );
  3043. _sqlSugar.ThenMapper(_view, x =>
  3044. {
  3045. x.Contents = _sqlSugar.Queryable<DailyFeePaymentContentView>()
  3046. .SetContext(x1 => x1.DFPId, () => x.Id, x)
  3047. .ToList();
  3048. string str = "";
  3049. int index = 1;
  3050. foreach (var item in x.Contents)
  3051. {
  3052. string str1 = $"{index}、费用名称:[{item.PriceName}] 单价:[{item.Price:#0.00}] 数量:[{item.Quantity:#0.00}] 小计:[{item.ItemTotal:#0.00}] 备注:[{item.Remark}]";
  3053. if (index == x.Contents.Count) str += str1;
  3054. else str += str1 + "\r\n";
  3055. index++;
  3056. }
  3057. x.ContentStr = str;
  3058. });
  3059. if (_view.Count > 0)
  3060. {
  3061. //DataTable dt = GeneralMethod.
  3062. DataTable dt = CommonFun.GetDataTableFromIList(_view);
  3063. dt.TableName = $"_view";
  3064. decimal total = _view.Sum(x => x.SumPrice);
  3065. WorkbookDesigner designer = new WorkbookDesigner();
  3066. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/日付报表模板.xls");
  3067. designer.SetDataSource(dt);
  3068. designer.SetDataSource("Total", total);
  3069. designer.Workbook.Worksheets[0].Name = "日付报表";
  3070. designer.Process();
  3071. string fileName = $"DailyPayment/日付报表{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx";
  3072. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  3073. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  3074. return Ok(JsonView(true, "操作成功", new { url = rst }));
  3075. }
  3076. return Ok(JsonView(true, ",暂无数据"));
  3077. }
  3078. return Ok(JsonView(false, "操作失败"));
  3079. }
  3080. else return Ok(JsonView(false, "操作失败"));
  3081. }
  3082. #endregion
  3083. #region 统计模块
  3084. /// <summary>
  3085. /// 同比
  3086. /// 营业额(今年和去年的)、成本支出(今年和去年的)、毛利润(今年和去年的)
  3087. /// </summary>
  3088. /// <param name="_dto">市场部销售额请求dto</param>
  3089. /// <returns></returns>
  3090. [HttpPost("StatisticsYOY")]
  3091. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3092. public async Task<IActionResult> StatisticsYOY(YOYDto _dto)
  3093. {
  3094. //同比增长率 = (本期 - 同期) / 同期 * 100%;
  3095. if (_dto.Year < 1) return Ok(JsonView(false, "操作失败"));
  3096. string beginDt = $"{_dto.Year - 1}-01-01 00:00:00",
  3097. endDt = $"{_dto.Year}-12-31 23:59:59";
  3098. string sql = string.Format(@"
  3099. SELECT
  3100. di.Id,
  3101. di.TeamName,
  3102. di.VisitDate,
  3103. YEAR(di.VisitDate) AS YEAR,
  3104. MONTH(di.VisitDate) AS MONTH,
  3105. (
  3106. SELECT
  3107. CAST(SUM(ItemSumPrice * Rate) AS DECIMAL(12, 2))
  3108. FROM
  3109. Fin_ForeignReceivables
  3110. WHERE
  3111. IsDel = 0
  3112. AND AddingWay IN (0, 1, 2)
  3113. AND di.Id = Diid
  3114. ) AS SaleAmount,
  3115. (
  3116. SELECT
  3117. CAST(
  3118. SUM(
  3119. (
  3120. ((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100
  3121. )
  3122. ) AS DECIMAL(12, 2)
  3123. )
  3124. FROM
  3125. Grp_AirTicketReservations atr
  3126. INNER JOIN Grp_CreditCardPayment ccp ON ccp.isdel = 0
  3127. AND ccp.CTable = 85
  3128. AND atr.Id = ccp.CId
  3129. WHERE
  3130. atr.IsDel = 0
  3131. AND ccp.IsAuditGM = 1
  3132. AND ccp.IsPay = 1
  3133. AND di.Id = atr.DiId
  3134. ) AirTicketAmount,
  3135. (
  3136. SELECT
  3137. CAST(
  3138. SUM(
  3139. (
  3140. ctggr.ServiceQuotedPrice * (ccp.PayPercentage / 100) * ccp.DayRate
  3141. )
  3142. ) AS DECIMAL(12, 2)
  3143. )
  3144. FROM
  3145. Grp_CarTouristGuideGroundReservations ctggr
  3146. INNER JOIN Grp_CreditCardPayment ccp ON ccp.IsDel = 0
  3147. AND ccp.CTable = 79
  3148. AND ctggr.Id = ccp.CId
  3149. WHERE
  3150. ctggr.IsDel = 0
  3151. AND ccp.IsAuditGM = 1
  3152. AND ccp.IsPay = 1
  3153. AND di.Id = ctggr.DiId
  3154. ) AS OPAmount,
  3155. (
  3156. SELECT
  3157. CAST(SUM((ccp.PayMoney * ccp.DayRate)) AS DECIMAL(12, 2))
  3158. FROM
  3159. Grp_DecreasePayments dp
  3160. INNER JOIN Grp_CreditCardPayment ccp ON ccp.isdel = 0
  3161. AND ccp.CTable = 98
  3162. AND dp.Id = ccp.CId
  3163. WHERE
  3164. dp.IsDel = 0
  3165. AND ccp.Ctable = 98
  3166. AND ccp.IsAuditGM = 1
  3167. AND ccp.IsPay = 1
  3168. AND di.Id = dp.Diid
  3169. ) AS OtherCostAmount,
  3170. (
  3171. SELECT
  3172. CAST(
  3173. SUM(
  3174. (
  3175. ((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100
  3176. )
  3177. ) AS DECIMAL(12, 2)
  3178. )
  3179. FROM
  3180. Grp_VisaInfo vi
  3181. INNER JOIN Grp_CreditCardPayment ccp ON ccp.isdel = 0
  3182. AND ccp.CTable = 80
  3183. AND vi.Id = ccp.CId
  3184. WHERE
  3185. vi.IsDel = 0
  3186. AND ccp.IsAuditGM = 1
  3187. AND ccp.IsPay = 1
  3188. AND di.Id = vi.DIId
  3189. ) AS VisaAmount,
  3190. (
  3191. SELECT
  3192. CAST(
  3193. SUM(
  3194. ((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100
  3195. ) AS DECIMAL(12, 2)
  3196. )
  3197. FROM
  3198. Grp_InvitationOfficialActivities ioa
  3199. INNER JOIN Grp_CreditCardPayment ccp ON ccp.isdel = 0
  3200. AND ccp.CTable = 81
  3201. AND ioa.Id = ccp.CId
  3202. WHERE
  3203. ioa.IsDel = 0
  3204. AND ccp.IsAuditGM = 1
  3205. AND ccp.IsPay = 1
  3206. AND di.Id = ioa.Diid
  3207. ) AS OAAmount,
  3208. (
  3209. SELECT
  3210. CAST(
  3211. SUM(
  3212. ((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100
  3213. ) AS DECIMAL(12, 2)
  3214. )
  3215. FROM
  3216. Grp_Customers ic
  3217. INNER JOIN Grp_CreditCardPayment ccp ON ccp.isdel = 0
  3218. AND ccp.CTable = 82
  3219. AND ic.Id = ccp.CId
  3220. WHERE
  3221. ic.IsDel = 0
  3222. AND ccp.IsAuditGM = 1And ccp.IsPay = 1
  3223. AND di.Id = ic.DiId
  3224. ) AS InsureAmount,
  3225. (
  3226. SELECT
  3227. CAST(
  3228. SUM(
  3229. ((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100
  3230. ) AS DECIMAL(12, 2)
  3231. )
  3232. FROM
  3233. Grp_HotelReservations hr
  3234. INNER JOIN Grp_CreditCardPayment ccp ON hr.Id = ccp.CId
  3235. WHERE
  3236. hr.IsDel = 0
  3237. AND ccp.IsDel = 0
  3238. AND ccp.CTable = 76
  3239. AND ccp.IsAuditGM = 1
  3240. AND ccp.PayMoney <> 0
  3241. AND ccp.IsPay = 0
  3242. AND di.Id = hr.DiId
  3243. ) AS HotelAmount,
  3244. (
  3245. SELECT
  3246. CAST(
  3247. SUM((gec.PriceSum * gec.Coefficient * ccp.DayRate)) AS DECIMAL(12, 2)
  3248. )
  3249. FROM
  3250. OA2023DB.dbo.Fin_GroupExtraCost gec
  3251. INNER JOIN Grp_CreditCardPayment ccp ON gec.Id = ccp.CId
  3252. WHERE
  3253. ccp.IsDel = 0
  3254. AND ccp.CTable = 1015
  3255. AND ccp.IsAuditGM = 1
  3256. AND ccp.IsPay = 1
  3257. AND di.Id = gec.DiId
  3258. ) AS ExcessAmount,
  3259. (
  3260. SELECT
  3261. CAST(
  3262. SUM(
  3263. ((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100
  3264. ) AS DECIMAL(12, 2)
  3265. )
  3266. FROM
  3267. Fin_PaymentRefundAndOtherMoney prom
  3268. INNER JOIN Grp_CreditCardPayment ccp ON prom.DiId = ccp.DIId
  3269. AND prom.Id = ccp.CId
  3270. WHERE
  3271. prom.IsDel = 0
  3272. AND prom.PayType = 1
  3273. AND ccp.CTable = 285
  3274. AND ccp.IsAuditGM = 1
  3275. AND ccp.IsPay = 1
  3276. AND di.Id = prom.DiId
  3277. ) AS SKTHAmount
  3278. FROM
  3279. Grp_DelegationInfo di
  3280. WHERE
  3281. di.IsDel = 0
  3282. AND di.TeamDid IN (38,39,40,1048)
  3283. AND di.VisitDate BETWEEN '{0}' AND '{1}'
  3284. ORDER BY
  3285. di.VisitDate
  3286. ", beginDt, endDt);
  3287. var data = await _sqlSugar.SqlQueryable<StatisticsYOYView>(sql).ToListAsync();
  3288. var thisYearData = data.Where(x => x.Year == _dto.Year).ToList();
  3289. var lastYearData = data.Where(x => x.Year == (_dto.Year - 1)).ToList();
  3290. List<YOYReturnView> salesYOYData = new List<YOYReturnView>();
  3291. List<YOYReturnView> costYOYData = new List<YOYReturnView>();
  3292. List<YOYReturnView> grossProfitYOYData = new List<YOYReturnView>();
  3293. int monthIndex = 1;
  3294. while (monthIndex < 13)
  3295. {
  3296. var thisMonthData = thisYearData.Where(x => x.Month == monthIndex).ToList();
  3297. var lastMonthData = lastYearData.Where(x => x.Month == monthIndex).ToList();
  3298. var thisGroupIds = thisMonthData.Select(x => x.Id).ToList();
  3299. var lastGroupIds = lastMonthData.Select(x => x.Id).ToList();
  3300. decimal thisSalesAmount = thisMonthData.Sum(x => x?.SaleAmount ?? 0.00M),
  3301. lastSalesAmount = lastMonthData.Sum(x => x?.SaleAmount ?? 0.00M),
  3302. thisCostAmount = thisMonthData.Sum(x => x?.CostAmount ?? 0.00M),
  3303. lastCostAmount = lastMonthData.Sum(x => x?.CostAmount ?? 0.00M),
  3304. thisgrossProfitAmount = thisMonthData.Sum(x => x?.GrossProfitAmount ?? 0.00M),
  3305. lastgrossProfitAmount = lastMonthData.Sum(x => x?.GrossProfitAmount ?? 0.00M);
  3306. salesYOYData.Add(new YOYReturnView(_dto.Year, monthIndex, thisSalesAmount, lastSalesAmount, thisGroupIds, lastGroupIds));
  3307. costYOYData.Add(new YOYReturnView(_dto.Year, monthIndex, thisCostAmount, lastCostAmount, thisGroupIds, lastGroupIds));
  3308. grossProfitYOYData.Add(new YOYReturnView(_dto.Year, monthIndex, thisgrossProfitAmount, lastgrossProfitAmount, thisGroupIds, lastGroupIds));
  3309. monthIndex++;
  3310. }
  3311. salesYOYData = salesYOYData.OrderBy(x => x.Month).ToList();
  3312. costYOYData = costYOYData.OrderBy(x => x.Month).ToList();
  3313. grossProfitYOYData = grossProfitYOYData.OrderBy(x => x.Month).ToList();
  3314. return Ok(JsonView(true, "操作成功!", new { salesYOYData = salesYOYData, costYOYData = costYOYData, grossProfitYOYData = grossProfitYOYData }));
  3315. }
  3316. /// <summary>
  3317. /// 国交数据统计-机票相关
  3318. /// 机票票数、机票到达地、预订平台
  3319. /// </summary>
  3320. /// <param name="_dto"></param>
  3321. /// <returns></returns>
  3322. [HttpPost("StatisticsAirTicket")]
  3323. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3324. public async Task<IActionResult> StatisticsAirTicket(YOYDto _dto)
  3325. {
  3326. if (_dto.Year < 1) return Ok(JsonView(false, "操作失败"));
  3327. string beginDt = $"{_dto.Year}-01-01 00:00:00",
  3328. endDt = $"{_dto.Year}-12-31 23:59:59";
  3329. string sql = string.Format(@"
  3330. SELECT
  3331. atr.DIId,
  3332. atr.FlightsDate,
  3333. YEAR(atr.FlightsDate) AS YEAR,
  3334. MONTH(atr.FlightsDate) AS MONTH,
  3335. atr.CType,
  3336. sd.Name As CTypeName,
  3337. atr.FlightsCity,
  3338. atr.ClientNum,
  3339. atr.ClientName,
  3340. di.TeamName As 'GroupName',
  3341. CASE
  3342. WHEN ccp.Payee = '' OR ccp.Payee IS NULL THEN '未知'
  3343. ELSE ccp.Payee
  3344. END AS 'Platform'
  3345. FROM
  3346. Grp_AirTicketReservations atr
  3347. INNER JOIN Grp_CreditCardPayment ccp ON atr.Id = ccp.CId
  3348. AND ccp.IsDel = 0
  3349. AND CTable = 85
  3350. INNER JOIN Grp_DelegationInfo di ON atr.DIId = di.Id
  3351. LEFT JOIN Sys_SetData sd On atr.CType = sd.Id
  3352. WHERE
  3353. atr.IsDel = 0
  3354. AND di.TeamDid IN (38,39,40,1048)
  3355. AND atr.CType IN(457,458,459,460,574,575)
  3356. AND CHARINDEX('行程单',atr.ClientName) = 0
  3357. AND CHARINDEX('返点',atr.ClientName) = 0
  3358. AND CHARINDEX('-1',atr.ClientName) = 0
  3359. AND ccp.IsPay = 1
  3360. AND atr.FlightsDate BETWEEN '{0}' AND '{1}'
  3361. ORDER BY atr.FlightsDate
  3362. ", beginDt, endDt);
  3363. var data = await _sqlSugar.SqlQueryable<StatisticsAirTicketView>(sql).ToListAsync();
  3364. var groupIds = data.Select(x => x.DIId).ToList();
  3365. //处理城市数据
  3366. var threeCodeData = await _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.IsDel == 0).ToListAsync();
  3367. //处理团组名称
  3368. var groupNames = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => groupIds.Contains(x.Id)).Select(x => new { Id = x.Id, GroupName = x.TeamName }).ToListAsync();
  3369. data.ForEach(x =>
  3370. {
  3371. string cityName = "";
  3372. if (!string.IsNullOrEmpty(x.FlightsCity))
  3373. {
  3374. string cityCode = x.FlightsCity.Replace("-", "").Replace("/", "");
  3375. int cityNum = cityCode.Length / 3;
  3376. if (cityCode.Length % 3 == 0)
  3377. {
  3378. for (int i = 0; i < cityNum; i++)
  3379. {
  3380. string code = "";
  3381. if (i == 0) code = cityCode.Substring(0, 3);
  3382. else code = cityCode.Substring(i * 3, 3);
  3383. if (!string.IsNullOrEmpty(code))
  3384. {
  3385. if (i == cityNum - 1)
  3386. {
  3387. cityName += threeCodeData.Find(x1 => x1.Three.Equals(code))?.City ?? "";
  3388. }
  3389. else
  3390. {
  3391. var str1 = threeCodeData.Find(x1 => x1.Three.Equals(code))?.City ?? "";
  3392. cityName += str1 + "、";
  3393. }
  3394. }
  3395. }
  3396. }
  3397. }
  3398. x.FlightsCityName = cityName;
  3399. });
  3400. var airTicketNumData = new List<AirTicketReturnView>();
  3401. var airTicketAreaData = new List<AirTicketCityReturnView>();
  3402. int monthIndex = 1;
  3403. while (monthIndex < 13)
  3404. {
  3405. var monthData = data.Where(x => x.Month == monthIndex).ToList();
  3406. //机票票数处理
  3407. int airticket_quantity = monthData.Sum(x => x.ClientNum);
  3408. var linkGroupIds = monthData.Select(x => x.DIId).ToList();
  3409. List<AitTicketInfo> aitTicketInfos = new List<AitTicketInfo>();
  3410. foreach (var item in monthData)
  3411. {
  3412. string groupName = groupNames.Find(x => item.DIId == x.Id)?.GroupName ?? "";
  3413. aitTicketInfos.Add(new AitTicketInfo(item.DIId, groupName, item.ClientNum));
  3414. }
  3415. var aitTicketInfosGroupBy = aitTicketInfos.GroupBy(x => x.Id);
  3416. List<AitTicketInfo> aitTicketInfos1 = new List<AitTicketInfo>();
  3417. foreach (var item in aitTicketInfosGroupBy)
  3418. {
  3419. aitTicketInfos1.Add(new AitTicketInfo(item.Key, item.First().GroupName, item.Sum(x => x.Quantity)));
  3420. }
  3421. aitTicketInfos1 = aitTicketInfos1.OrderBy(x => x.Quantity).ToList();
  3422. linkGroupIds = linkGroupIds.Distinct().ToList();
  3423. airTicketNumData.Add(new AirTicketReturnView(_dto.Year, monthIndex, airticket_quantity, aitTicketInfos1, linkGroupIds));
  3424. //机票城市处理
  3425. //城市处理
  3426. var airTicketCityInfos = new List<string>();
  3427. foreach (var item in monthData)
  3428. {
  3429. if (!string.IsNullOrEmpty(item.FlightsCityName))
  3430. {
  3431. if (item.FlightsCityName.Contains("、"))
  3432. {
  3433. var cityArray = item.FlightsCityName.Split("、").ToList();
  3434. foreach (var item1 in cityArray)
  3435. {
  3436. if (!string.IsNullOrEmpty(item1))
  3437. {
  3438. airTicketCityInfos.Add(item1);
  3439. }
  3440. }
  3441. }
  3442. else
  3443. {
  3444. airTicketCityInfos.Add(item.FlightsCityName);
  3445. }
  3446. }
  3447. }
  3448. //int quantity1 = airTicketCityInfos.Count;
  3449. int city_totalquantity = 0;
  3450. var airTicketCityInfosGroupby = airTicketCityInfos.GroupBy(x => x);
  3451. var airTicketCityInfos1 = new List<AirTicketCityInfo>();
  3452. foreach (var item in airTicketCityInfosGroupby)
  3453. {
  3454. var city_quantity = item.ToList().Count;
  3455. city_totalquantity += city_quantity;
  3456. airTicketCityInfos1.Add(new AirTicketCityInfo(item.Key, city_quantity));
  3457. }
  3458. airTicketCityInfos1 = airTicketCityInfos1.OrderByDescending(x => x.Quantity).ToList();
  3459. airTicketAreaData.Add(new AirTicketCityReturnView(_dto.Year, monthIndex, city_totalquantity, airTicketCityInfos1, linkGroupIds));
  3460. monthIndex++;
  3461. }
  3462. var airTicketPlatformData = data.GroupBy(g => g.Platform)
  3463. .Select(g => new
  3464. {
  3465. platform = g.Key,
  3466. total = g.Sum(x => x.ClientNum),
  3467. children = g.GroupBy(g1 => g1.DIId)
  3468. .Select(g1 => new {
  3469. diId = g1.Key,
  3470. groupName = g1.FirstOrDefault()?.GroupName ?? "-",
  3471. total = g1.Sum(x1 => x1.ClientNum),
  3472. children = g1.Select(x1 => new {
  3473. //diId = x1.DIId,
  3474. //groupName = x1.GroupName,
  3475. flightsCityName=x1.FlightsCityName,
  3476. total = x1.ClientNum
  3477. })
  3478. .ToList()
  3479. })
  3480. .OrderByDescending(x1 => x1.total)
  3481. .ToList()
  3482. })
  3483. .OrderByDescending(x => x.total)
  3484. .ToList();
  3485. return Ok(JsonView(true, "操作成功!", new
  3486. {
  3487. airTicketNumData = airTicketNumData,
  3488. airTicketAreaData = airTicketAreaData,
  3489. airTicketPlatformData = airTicketPlatformData
  3490. }));
  3491. }
  3492. /// <summary>
  3493. /// 国交数据统计-酒店
  3494. /// 地区TOP10、预订平台
  3495. /// </summary>
  3496. /// <param name="_dto"></param>
  3497. /// <returns></returns>
  3498. [HttpPost("StatisticsHotel")]
  3499. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3500. public async Task<IActionResult> StatisticsHotel(YOYDto _dto)
  3501. {
  3502. if (_dto.Year < 1) return Ok(JsonView(false, "操作失败"));
  3503. string beginDt = $"{_dto.Year}-01-01 00:00:00",
  3504. endDt = $"{_dto.Year}-12-31 23:59:59";
  3505. string sql = string.Format(@"
  3506. SELECT
  3507. hr.DIId,
  3508. hr.City,
  3509. hr.HotelName,
  3510. sd.Name AS BookinSite,
  3511. hr.CheckInDate,
  3512. YEAR(hr.CheckInDate) AS YEAR,
  3513. MONTH(hr.CheckInDate) AS MONTH,
  3514. hr.CheckOutDate,
  3515. hr.SingleRoomCount,
  3516. hr.DoubleRoomCount,
  3517. hr.SuiteRoomCount,
  3518. hr.OtherRoomCount
  3519. FROM
  3520. Grp_HotelReservations hr
  3521. INNER JOIN Grp_CreditCardPayment ccp ON hr.Id = ccp.CId
  3522. AND ccp.IsDel = 0
  3523. AND CTable = 76
  3524. INNER JOIN Grp_DelegationInfo di ON hr.DiId = di.Id
  3525. LEFT JOIN Sys_SetData sd ON hr.ReservationsWebsite = sd.Id
  3526. WHERE
  3527. hr.IsDel = 0
  3528. AND di.TeamDid IN (38,39,40,1048)
  3529. AND ccp.IsPay = 1
  3530. AND (
  3531. hr.SingleRoomCount > 0
  3532. OR hr.DoubleRoomCount > 0
  3533. OR hr.SuiteRoomCount > 0
  3534. OR hr.OtherRoomCount > 0
  3535. )
  3536. AND CHARINDEX('早餐',hr.HotelName) = 0
  3537. AND CHARINDEX('晚餐',hr.HotelName) = 0
  3538. AND CHARINDEX('升级',hr.HotelName) = 0
  3539. AND CHARINDEX('饮料茶水费',hr.HotelName) = 0
  3540. AND CHARINDEX('城市税',hr.HotelName) = 0
  3541. AND CHARINDEX('退款',hr.HotelName) = 0
  3542. AND CHARINDEX('返现',hr.HotelName) = 0
  3543. AND CHARINDEX('会议室',hr.HotelName) = 0
  3544. AND CHARINDEX('迷你吧消费',hr.HotelName) = 0
  3545. AND CHARINDEX('运费',hr.HotelName) = 0
  3546. AND CHARINDEX('地接',hr.HotelName) = 0
  3547. AND CHARINDEX('损失',hr.HotelName) = 0
  3548. AND CHARINDEX('补差',hr.HotelName) = 0
  3549. AND hr.CheckInDate BETWEEN CONVERT(datetime,'{0}') AND CONVERT(datetime,'{1}')
  3550. ORDER BY
  3551. hr.CheckInDate
  3552. ", beginDt, endDt);
  3553. var data = await _sqlSugar.SqlQueryable<StatisticsHotelView>(sql).ToListAsync();
  3554. var hotelData = data.OrderBy(x => x.CityStr).ToList();
  3555. var hotelCityGroupByData = data.GroupBy(x => x.CityStr)
  3556. .Select(g => new
  3557. {
  3558. city = g.Key,
  3559. BookingRoomNum = g.Sum(x => x.RoomTotal),
  3560. hotelData = g.GroupBy(x => x.HotelName)
  3561. .Select(g1 => new
  3562. {
  3563. hotelName = g1.Key,
  3564. roomNights = g1.Sum(x => x.RoomNights),
  3565. roomTotal = g1.Sum(x => x.RoomTotal),
  3566. singleRoomCount = g1.Sum(x => x.SingleRoomCount),
  3567. doubleRoomCount = g1.Sum(x => x.DoubleRoomCount),
  3568. suiteRoomCount = g1.Sum(x => x.SuiteRoomCount),
  3569. otherRoomCount = g1.Sum(x => x.OtherRoomCount),
  3570. })
  3571. .ToList(),
  3572. linkGroupIds = g.Select(x => x.DIId).Distinct().ToList()
  3573. })
  3574. .OrderByDescending(x => x.BookingRoomNum)
  3575. .Take(10)
  3576. .ToList();
  3577. var hotelPlatformGroupByData = data.GroupBy(x => x.BookinSite)
  3578. .Select(g => new
  3579. {
  3580. Platform = g.Key,
  3581. BookingRoomNum = g.Sum(x => x.RoomTotal),
  3582. hotelData = g.GroupBy(x => x.HotelName)
  3583. .Select(g1 => new
  3584. {
  3585. hotelName = g1.Key,
  3586. roomNights = g1.Sum(x => x.RoomNights),
  3587. roomTotal = g1.Sum(x => x.RoomTotal),
  3588. singleRoomCount = g1.Sum(x => x.SingleRoomCount),
  3589. doubleRoomCount = g1.Sum(x => x.DoubleRoomCount),
  3590. suiteRoomCount = g1.Sum(x => x.SuiteRoomCount),
  3591. otherRoomCount = g1.Sum(x => x.OtherRoomCount),
  3592. })
  3593. .ToList(),
  3594. linkGroupIds = g.Select(x => x.DIId).Distinct().ToList()
  3595. })
  3596. .OrderByDescending(x => x.BookingRoomNum)
  3597. .ToList();
  3598. return Ok(JsonView(true, "操作成功!", new { hotelCityData = hotelCityGroupByData , hotelPlatformData = hotelPlatformGroupByData }));
  3599. }
  3600. /// <summary>
  3601. /// 国交数据统计
  3602. /// 商邀邀请国家数量TOP10
  3603. /// </summary>
  3604. /// <param name="_dto"></param>
  3605. /// <returns></returns>
  3606. [HttpPost("StatisticsInvitation")]
  3607. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3608. public async Task<IActionResult> StatisticsInvitation(YOYDto _dto)
  3609. {
  3610. if (_dto.Year < 1) return Ok(JsonView(false, "操作失败"));
  3611. string beginDt = $"{_dto.Year}-01-01 00:00:00",
  3612. endDt = $"{_dto.Year}-12-31 23:59:59";
  3613. string sql = string.Format(@"
  3614. SELECT
  3615. ioa.DiId,
  3616. ioa.InviterArea AS Country
  3617. FROM
  3618. Grp_InvitationOfficialActivities ioa
  3619. INNER JOIN Grp_CreditCardPayment ccp ON ioa.Id = ccp.CId
  3620. AND ccp.IsDel = 0
  3621. AND ccp.CTable = 81
  3622. INNER JOIN Grp_DelegationInfo di ON ioa.DiId = di.Id
  3623. WHERE
  3624. ioa.IsDel = 0
  3625. AND di.TeamDid IN (38,39,40,1048)
  3626. AND ccp.IsPay = 1
  3627. AND ioa.CreateTime BETWEEN '{0}' AND '{1}'
  3628. ", beginDt, endDt);
  3629. var data = await _sqlSugar.SqlQueryable<StatisticsInvitation>(sql).ToListAsync();
  3630. var groupByData = data.GroupBy(x => x.Country)
  3631. .Select(g => new
  3632. {
  3633. Country = g.Key,
  3634. TimeNum = g.Count(),
  3635. LinkGroupIds = g.Select(x => x.DIId).ToList()
  3636. })
  3637. .OrderByDescending(x => x.TimeNum)
  3638. .Take(10)
  3639. .ToList();
  3640. return Ok(JsonView(true, "操作成功!", groupByData));
  3641. }
  3642. /// <summary>
  3643. /// 会务数据统计
  3644. /// 会务城市TOP10排序
  3645. /// </summary>
  3646. /// <param name="_dto"></param>
  3647. /// <returns></returns>
  3648. [HttpPost("StatisticsConferenceCity")]
  3649. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3650. public async Task<IActionResult> StatisticsConferenceCity(YOYDto _dto)
  3651. {
  3652. if (_dto.Year < 1) return Ok(JsonView(false, "操作失败"));
  3653. string beginDt = $"{_dto.Year}-01-01 00:00:00",
  3654. endDt = $"{_dto.Year}-12-31 23:59:59";
  3655. string sql = string.Format(@"
  3656. SELECT
  3657. ioa.DiId,
  3658. ioa.InviterArea AS Country
  3659. FROM
  3660. Grp_InvitationOfficialActivities ioa
  3661. INNER JOIN Grp_CreditCardPayment ccp ON ioa.Id = ccp.CId
  3662. AND ccp.IsDel = 0
  3663. AND ccp.CTable = 81
  3664. INNER JOIN Grp_DelegationInfo di ON ioa.DiId = di.Id
  3665. WHERE
  3666. ioa.IsDel = 0
  3667. AND di.TeamDid IN (102,248,302,691,762,1047)
  3668. AND ccp.IsPay = 1
  3669. AND ioa.CreateTime BETWEEN '{0}' AND '{1}'
  3670. ", beginDt, endDt);
  3671. var data = await _sqlSugar.SqlQueryable<StatisticsInvitation>(sql).ToListAsync();
  3672. var groupByData = data.GroupBy(x => x.Country)
  3673. .Select(g => new
  3674. {
  3675. Country = g.Key,
  3676. TimeNum = g.Count(),
  3677. LinkGroupIds = g.Select(x => x.DIId).ToList()
  3678. })
  3679. .OrderByDescending(x => x.TimeNum)
  3680. .Take(10)
  3681. .ToList();
  3682. return Ok(JsonView(true, "操作成功!", groupByData));
  3683. }
  3684. /// <summary>
  3685. /// 团组数据统计
  3686. /// 团组合作前十的客户TOP10排序
  3687. /// </summary>
  3688. /// <param name="_dto"></param>
  3689. /// <returns></returns>
  3690. [HttpPost("StatisticsCooperativeCustomer")]
  3691. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3692. public async Task<IActionResult> StatisticsCooperativeCustomer(YOYDto _dto)
  3693. {
  3694. if (_dto.Year < 1) return Ok(JsonView(false, "操作失败"));
  3695. string beginDt = $"{_dto.Year}-01-01 00:00:00",
  3696. endDt = $"{_dto.Year}-12-31 23:59:59";
  3697. DateTime _beginDt = Convert.ToDateTime(beginDt),
  3698. _endDt = Convert.ToDateTime(endDt);
  3699. var groupInfos = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  3700. .Where(x => x.IsDel == 0)
  3701. //.Where(x => x.IsSure == 1)
  3702. .Where(x => x.VisitDate >= _beginDt && x.VisitDate <= _endDt)
  3703. .ToListAsync();
  3704. var groupInfos1 = groupInfos.GroupBy(x => x.ClientName);
  3705. var view = groupInfos1.Select(x =>
  3706. new
  3707. {
  3708. clienName = x.Key,
  3709. clientUnit = x.FirstOrDefault()?.ClientUnit ?? "",
  3710. visitsNum = x.Count()
  3711. }
  3712. )
  3713. .OrderByDescending(x => x.visitsNum)
  3714. .Take(10)
  3715. .ToList();
  3716. return Ok(JsonView(true, "操作成功!", view));
  3717. }
  3718. /// <summary>
  3719. /// 团组数据统计
  3720. /// 已出团客户单位的类型比例图(饼状图-政府团、企业团等)
  3721. /// </summary>
  3722. /// <param name="_dto"></param>
  3723. /// <returns></returns>
  3724. [HttpPost("StatisticsCooperativeCustomerType")]
  3725. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3726. public async Task<IActionResult> StatisticsCooperativeCustomerType(YOYDto _dto)
  3727. {
  3728. if (_dto.Year < 1) return Ok(JsonView(false, "操作失败"));
  3729. string beginDt = $"{_dto.Year}-01-01 00:00:00",
  3730. endDt = $"{_dto.Year}-12-31 23:59:59";
  3731. DateTime _beginDt = Convert.ToDateTime(beginDt),
  3732. _endDt = Convert.ToDateTime(endDt);
  3733. var groupInfos = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  3734. .LeftJoin<Sys_SetData>((di, sd) => di.TeamDid == sd.Id)
  3735. .Where((di, sd) => di.IsDel == 0)
  3736. .Where((di, sd) => di.VisitDate >= _beginDt && di.VisitDate <= _endDt)
  3737. .Select((di, sd) => new
  3738. {
  3739. Id = di.Id,
  3740. GroupTypeId = di.TeamDid,
  3741. GroupTypeName = sd.Name,
  3742. })
  3743. .ToListAsync();
  3744. var groupInfos1 = groupInfos.GroupBy(x => x.GroupTypeName);
  3745. var view = groupInfos1.Select(x =>
  3746. new
  3747. {
  3748. groupTypeName = x.Key,
  3749. groupNum = x.Count(),
  3750. linkGroupId = x.Select(x1 => x1.Id).ToList()
  3751. }
  3752. )
  3753. .OrderByDescending(x => x.groupNum)
  3754. .ToList();
  3755. return Ok(JsonView(true, "操作成功!", view));
  3756. }
  3757. /// <summary>
  3758. /// 团组数据统计
  3759. /// 团组数量
  3760. /// </summary>
  3761. /// <param name="_dto"></param>
  3762. /// <returns></returns>
  3763. [HttpPost("StatisticsGroupNum")]
  3764. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3765. public async Task<IActionResult> StatisticsGroupNum(YOYDto _dto)
  3766. {
  3767. if (_dto.Year < 1) return Ok(JsonView(false, "操作失败"));
  3768. string beginDt = $"{_dto.Year}-01-01 00:00:00",
  3769. endDt = $"{_dto.Year}-12-31 23:59:59";
  3770. DateTime _beginDt = Convert.ToDateTime(beginDt),
  3771. _endDt = Convert.ToDateTime(endDt);
  3772. var groupInfos = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  3773. .Where(x => x.IsDel == 0)
  3774. .Where(x => x.VisitDate >= _beginDt && x.VisitDate <= _endDt)
  3775. .Select(x => new StatisticsGroupInfoEntity
  3776. {
  3777. Id = x.Id,
  3778. VisitDate = x.VisitDate,
  3779. Month = x.VisitDate.Month,
  3780. //MonthName = x.VisitDate.ToString("MMM", CultureInfo.GetCultureInfo("zh-CN")),
  3781. VisitPNumber = x.VisitPNumber
  3782. })
  3783. .MergeTable()
  3784. .OrderBy(x => new { x.Month })
  3785. .ToListAsync();
  3786. string groupNumStr = $"年度出访量:{groupInfos.Count}\r\n";
  3787. var groupNumYearData = new
  3788. {
  3789. year = _dto.Year,
  3790. yearName = _dto.Year + "年",
  3791. num = groupInfos.Count,
  3792. linkGroupIds = groupInfos.Select(x => x.Id).ToList()
  3793. };
  3794. var groupNumData = groupInfos.GroupBy(x => x.Quarter)
  3795. .Select(x => new
  3796. {
  3797. Quarter = x.Key,
  3798. QuarterName = x.FirstOrDefault()?.QuarterName ?? "-",
  3799. Num = x.Count(),
  3800. LinkGroupIds = x.Select(x1 => x1.Id).ToList()
  3801. })
  3802. .OrderBy(x => x.Quarter)
  3803. .ToList();
  3804. groupNumData.ForEach(x =>
  3805. {
  3806. groupNumStr += $"{x.QuarterName}出访量:{x.Num};";
  3807. });
  3808. var groupNumMonthData = groupInfos.GroupBy(x => x.Month)
  3809. .Select(x => new
  3810. {
  3811. Month = x.Key,
  3812. MonthName = x.FirstOrDefault()?.MonthName ?? "-",
  3813. Num = x.Count(),
  3814. LinkGroupIds = x.Select(x1 => x1.Id).ToList()
  3815. })
  3816. .OrderBy(x => x.Month)
  3817. .ToList();
  3818. return Ok(JsonView(true, "操作成功!", new
  3819. {
  3820. yearData = groupNumYearData,
  3821. quarterData = groupNumData,
  3822. monthData = groupNumMonthData,
  3823. remark = groupNumStr
  3824. }));
  3825. }
  3826. /// <summary>
  3827. /// 团组数据统计
  3828. /// 团组人数
  3829. /// </summary>
  3830. /// <param name="_dto"></param>
  3831. /// <returns></returns>
  3832. [HttpPost("StatisticsGroupPeopleNum")]
  3833. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3834. public async Task<IActionResult> StatisticsGroupPeopleNum(YOYDto _dto)
  3835. {
  3836. if (_dto.Year < 1) return Ok(JsonView(false, "操作失败"));
  3837. string beginDt = $"{_dto.Year}-01-01 00:00:00",
  3838. endDt = $"{_dto.Year}-12-31 23:59:59";
  3839. DateTime _beginDt = Convert.ToDateTime(beginDt),
  3840. _endDt = Convert.ToDateTime(endDt);
  3841. var groupInfos = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  3842. .Where(x => x.IsDel == 0)
  3843. .Where(x => x.VisitDate >= _beginDt && x.VisitDate <= _endDt)
  3844. .Select(x => new StatisticsGroupInfoEntity
  3845. {
  3846. Id = x.Id,
  3847. VisitDate = x.VisitDate,
  3848. Month = x.VisitDate.Month,
  3849. VisitPNumber = x.VisitPNumber
  3850. })
  3851. .MergeTable()
  3852. .OrderBy(x => new { x.Month })
  3853. .ToListAsync();
  3854. string groupPeopleNumStr = $"年度出访人数:{groupInfos.Sum(x => x.VisitPNumber)}\r\n";
  3855. var groupPeopleNumYearData = new
  3856. {
  3857. year = _dto.Year,
  3858. yearName = _dto.Year + "年",
  3859. num = groupInfos.Sum(x => x.VisitPNumber),
  3860. linkGroupIds = groupInfos.Select(x => x.Id).ToList()
  3861. };
  3862. var groupPeopleNumData = groupInfos.GroupBy(x => x.Quarter)
  3863. .Select(x => new
  3864. {
  3865. Quarter = x.Key,
  3866. QuarterName = x.FirstOrDefault()?.QuarterName ?? "-",
  3867. Num = x.Sum(x1 => x1.VisitPNumber),
  3868. LinkGroupIds = x.Select(x1 => x1.Id).ToList()
  3869. })
  3870. .OrderBy(x => x.Quarter)
  3871. .ToList();
  3872. groupPeopleNumData.ForEach(x =>
  3873. {
  3874. groupPeopleNumStr += $"{x.QuarterName}出访人数:{x.Num};";
  3875. });
  3876. var groupPeopleNumMonthData = groupInfos.GroupBy(x => x.Month)
  3877. .Select(x => new
  3878. {
  3879. Month = x.Key,
  3880. MonthName = x.FirstOrDefault()?.MonthName ?? "-",
  3881. Num = x.Sum(x1 => x1.VisitPNumber),
  3882. LinkGroupIds = x.Select(x1 => x1.Id).ToList()
  3883. })
  3884. .OrderBy(x => x.Month)
  3885. .ToList();
  3886. return Ok(JsonView(true, "操作成功!", new
  3887. {
  3888. yearData = groupPeopleNumYearData,
  3889. quarterData = groupPeopleNumData,
  3890. monthData = groupPeopleNumMonthData,
  3891. remark = groupPeopleNumStr
  3892. }));
  3893. }
  3894. /// <summary>
  3895. /// 团组数据统计
  3896. /// OP 成本
  3897. /// </summary>
  3898. /// <param name="_dto"></param>
  3899. /// <returns></returns>
  3900. [HttpPost("StatisticsOP")]
  3901. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3902. public async Task<IActionResult> StatisticsOP(StatisticsOPDto _dto)
  3903. {
  3904. if (_dto.Year < 1) return Ok(JsonView(false, "Year参数错误!"));
  3905. if (_dto.Type < 1 || _dto.Type > 2) return Ok(JsonView(false, "Type参数错误!"));
  3906. int thisYear = _dto.Year, lastYear = _dto.Year - 1;
  3907. string beginDt = $"{lastYear}-01-01 00:00:00",
  3908. endDt = $"{thisYear}-12-31 23:59:59";
  3909. string sql = string.Format(@"
  3910. SELECT
  3911. temp.Id,
  3912. DiId,
  3913. PaymentTime,
  3914. [Year],
  3915. [Quarter],
  3916. [Month],
  3917. Area,
  3918. FeeType,
  3919. sd1.Name AS FeeTypeName,
  3920. FeeSubType,
  3921. sd2.Name AS FeeSubTypeName,
  3922. CONVERT(DECIMAL(12, 2), Price * Qauntity * ExchangeRate) AS Price
  3923. FROM
  3924. (
  3925. SELECT
  3926. ctggr.Id,
  3927. ctggr.DiId,
  3928. ctggr.Area,
  3929. CASE
  3930. WHEN ctggr.PriceType IS NULL THEN 1069
  3931. ELSE ctggr.PriceType
  3932. END AS FeeType,
  3933. ctggrc.SId AS FeeSubType,
  3934. ctggrc.Price,
  3935. CASE
  3936. WHEN ctggrc.Count IS NULL THEN 1
  3937. ELSE ctggrc.Count
  3938. END AS Qauntity,
  3939. ccp.DayRate AS ExchangeRate,
  3940. ctggrc.CreateTime AS PaymentTime,
  3941. YEAR(ctggrc.CreateTime) AS [Year],
  3942. CONVERT(INT,DATENAME(QUARTER, ctggrc.CreateTime)) AS [Quarter],
  3943. MONTH(ctggrc.CreateTime) AS [Month]
  3944. FROM
  3945. Grp_CarTouristGuideGroundReservations ctggr
  3946. INNER JOIN Grp_CarTouristGuideGroundReservationsContent ctggrc ON ctggr.Id = ctggrc.CTGGRId
  3947. AND ctggrc.IsDel = 0
  3948. INNER JOIN Grp_CreditCardPayment ccp ON ctggr.Id = ccp.CId
  3949. AND ccp.CTable = 79
  3950. AND ccp.IsDel = 0
  3951. WHERE
  3952. ctggr.IsDel = 0
  3953. AND ctggrc.SId != 1070 --费用子项筛掉尾款
  3954. AND ctggrc.Price > 0 --筛选真实存在的数据
  3955. AND ccp.IsPay = 1
  3956. ) temp
  3957. LEFT JOIN Sys_SetData sd1 ON FeeType = sd1.Id
  3958. LEFT JOIN Sys_SetData sd2 ON FeeSubType = sd2.Id
  3959. WHERE
  3960. temp.Area NOT LIKE '%尾款%' -- 筛选掉尾款相关信息
  3961. AND temp.FeeType != 1062 --费用类型筛选掉全款和首付款数据
  3962. AND temp.PaymentTime BETWEEN CONVERT(datetime,'{0}') AND CONVERT(datetime,'{1}')
  3963. ORDER BY
  3964. temp.[Year],
  3965. temp.[Quarter],
  3966. temp.[Month]
  3967. ", beginDt, endDt);
  3968. var opInfos = await _sqlSugar.SqlQueryable<StatisticsOP>(sql).ToListAsync();
  3969. //处理地区相关信息
  3970. var countrys = await _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x => x.IsDel == 0).ToListAsync();
  3971. for (int i = 0; i < opInfos.Count; i++)
  3972. {
  3973. string country = string.Empty, city = string.Empty;
  3974. int dataId = 0;
  3975. bool isCountryId = int.TryParse(opInfos[i].Area, out dataId);
  3976. string[] citySelecter = new string[] { "其他城市", "所有城市" };
  3977. if (isCountryId)
  3978. {
  3979. var countryInfo = countrys.Find(x => x.Id == dataId);
  3980. country = countryInfo?.Country ?? "";
  3981. if (citySelecter.Contains(countryInfo?.City)) city = country;
  3982. else city = countryInfo?.City ?? "";
  3983. }
  3984. else
  3985. {
  3986. var countryInfo1 = countrys.Find(x => opInfos[i].Area.Contains(x.Country));
  3987. if (countryInfo1 != null)
  3988. {
  3989. country = countryInfo1?.Country ?? "";
  3990. city = countryInfo1?.City ?? country;
  3991. var countryInfo2 = countrys.Find(x => opInfos[i].Area.Contains(x.City));
  3992. if (citySelecter.Contains(countryInfo2?.City)) city = country;
  3993. else city = countryInfo2?.City ?? country;
  3994. }
  3995. else
  3996. {
  3997. var countryInfo2 = countrys.Find(x => opInfos[i].Area.Contains(x.City));
  3998. if (countryInfo2 != null)
  3999. {
  4000. country = countryInfo2?.Country ?? "";
  4001. city = countryInfo2?.City ?? "";
  4002. if (citySelecter.Contains(countryInfo2?.City)) city = country;
  4003. }
  4004. }
  4005. }
  4006. opInfos[i].Country = country;
  4007. opInfos[i].City = city;
  4008. }
  4009. var opParentFeeData = new StatisticsOP()._OPParentFeeInfo;
  4010. if (_dto.Type == 1)
  4011. {
  4012. //同比增长率=(本期数-同期数)/ 同期数
  4013. var yearData = opInfos.GroupBy(x => x.ParentFeeName)
  4014. .Select(x => new StatisticsOPYOY(
  4015. feeId: x.FirstOrDefault()?.ParentFeeId ?? 0,
  4016. feeName: x.Key,
  4017. currPeriodFee: x.Where(x => x.Year == thisYear).Sum(x => x.Price),
  4018. samePeriodFee: x.Where(x => x.Year == lastYear).Sum(x => x.Price),
  4019. currPeriodGroupTotal: x.Where(x => x.Year == thisYear).Select(x => x.DiId).Distinct().Count(),
  4020. samePeriodGroupTotal: x.Where(x => x.Year == lastYear).Select(x => x.DiId).Distinct().Count(),
  4021. subFeeData: x.GroupBy(x1 => x1.FeeSubType)
  4022. .Select(x1 => new StatisticsOPSubFeeYOY(
  4023. feeId: x1.Key,
  4024. feeName: x1.FirstOrDefault()?.FeeSubTypeName ?? "",
  4025. currPeriodFee: x1.Where(x1 => x1.Year == thisYear).Sum(x1 => x1.Price),
  4026. samePeriodFee: x1.Where(x1 => x1.Year == lastYear).Sum(x1 => x1.Price),
  4027. currPeriodGroupTotal: x1.Where(x1 => x1.Year == thisYear).Select(x1 => x1.DiId).Distinct().Count(),
  4028. samePeriodGroupTotal: x1.Where(x1 => x1.Year == lastYear).Select(x1 => x1.DiId).Distinct().Count(),
  4029. cityData: x1.GroupBy(x2 => x2.City)
  4030. .Select(x2 => new StatisticsOPCityYOY(
  4031. cityName: x2.Key,
  4032. currPeriodGroupTotal: x2.Where(x2 => x2.Year == thisYear).Select(x2 => x2.DiId).Distinct().Count(),
  4033. samePeriodGroupTotal: x2.Where(x2 => x2.Year == lastYear).Select(x2 => x2.DiId).Distinct().Count(),
  4034. currPeriodFee: x2.Where(x2 => x2.Year == thisYear).Sum(x2 => x2.Price),
  4035. samePeriodFee: x2.Where(x2 => x2.Year == lastYear).Sum(x2 => x2.Price)
  4036. ))
  4037. .ToArray()
  4038. ))
  4039. .ToArray()
  4040. ))
  4041. .OrderBy(x => x.FeeId)
  4042. .ToList();
  4043. var opParentYearIds = yearData.Select(x => x.FeeId).ToList();
  4044. var opParentYearDataSelector = opParentFeeData.Where(x => !opParentYearIds.Contains(x.Id)).ToList();
  4045. if (opParentYearDataSelector.Count > 0)
  4046. {
  4047. foreach (var item in opParentYearDataSelector)
  4048. {
  4049. yearData.Add(
  4050. new StatisticsOPYOY(feeId: item.Id,
  4051. feeName: item.Name,
  4052. currPeriodFee: 0.00M,
  4053. samePeriodFee: 0.00M,
  4054. currPeriodGroupTotal: 0,
  4055. samePeriodGroupTotal: 0,
  4056. subFeeData: new StatisticsOPSubFeeYOY[] { }
  4057. ));
  4058. }
  4059. yearData = yearData.OrderBy(x => x.FeeId).ToList();
  4060. }
  4061. return Ok(JsonView(true, "操作成功!", yearData));
  4062. }
  4063. else if (_dto.Type == 2)
  4064. {
  4065. var monthData = opInfos.GroupBy(x => x.Month)
  4066. .Select(x => new StatisticsOPMonthYOY(
  4067. monthId: x.Key,
  4068. monthName: Enum.IsDefined(typeof(MonthEnum), (int)x.Key) ? ((MonthEnum)(int)x.Key).GetEnumDescription() : "",
  4069. feeDatas: x.GroupBy(x1 => x1.ParentFeeId)
  4070. .Select(x1 => new StatisticsOPYOY(
  4071. feeId: x1.Key,
  4072. feeName: x1.FirstOrDefault()?.ParentFeeName ?? "",
  4073. currPeriodFee: x1.Where(x1 => x1.Year == thisYear).Sum(x1 => x1.Price),
  4074. samePeriodFee: x1.Where(x1 => x1.Year == lastYear).Sum(x1 => x1.Price),
  4075. currPeriodGroupTotal: x1.Where(x1 => x1.Year == thisYear).Select(x1 => x1.DiId).Distinct().Count(),
  4076. samePeriodGroupTotal: x1.Where(x1 => x1.Year == lastYear).Select(x1 => x1.DiId).Distinct().Count(),
  4077. subFeeData: x1.GroupBy(x2 => x2.FeeSubType)
  4078. .Select(x2 => new StatisticsOPSubFeeYOY(
  4079. feeId: x2.Key,
  4080. feeName: x2.FirstOrDefault()?.FeeSubTypeName ?? "",
  4081. currPeriodFee: x2.Where(x2 => x2.Year == thisYear).Sum(x2 => x2.Price),
  4082. samePeriodFee: x2.Where(x2 => x2.Year == lastYear).Sum(x2 => x2.Price),
  4083. currPeriodGroupTotal: x2.Where(x2 => x2.Year == thisYear).Select(x2 => x2.DiId).Distinct().Count(),
  4084. samePeriodGroupTotal: x2.Where(x2 => x2.Year == lastYear).Select(x2 => x2.DiId).Distinct().Count(),
  4085. cityData: x2.GroupBy(x3 => x3.City)
  4086. .Select(x3 => new StatisticsOPCityYOY(
  4087. cityName: x3.Key,
  4088. currPeriodFee: x3.Where(x3 => x3.Year == thisYear).Sum(x3 => x3.Price),
  4089. samePeriodFee: x3.Where(x3 => x3.Year == lastYear).Sum(x3 => x3.Price),
  4090. currPeriodGroupTotal: x3.Where(x3 => x3.Year == thisYear).Select(x3 => x3.DiId).Distinct().Count(),
  4091. samePeriodGroupTotal: x3.Where(x3 => x3.Year == lastYear).Select(x3 => x3.DiId).Distinct().Count()
  4092. ))
  4093. .ToArray()
  4094. ))
  4095. .ToArray()
  4096. ))
  4097. .ToArray()
  4098. ))
  4099. //.OrderBy(x => x.MonthId)
  4100. .ToList();
  4101. //1、月份是否足够十二月
  4102. var monthIds = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
  4103. var monthDataIds = monthData.Select(x => x.MonthId).ToArray();
  4104. var newMonthIds = monthIds.Where(x => !monthDataIds.Contains(x)).ToList();
  4105. if (newMonthIds.Count > 0)
  4106. {
  4107. foreach (var item in newMonthIds)
  4108. {
  4109. monthData.Add(new StatisticsOPMonthYOY(
  4110. monthId: item,
  4111. monthName: Enum.IsDefined(typeof(MonthEnum), (int)item) ? ((MonthEnum)(int)item).GetEnumDescription() : "",
  4112. feeDatas: Array.Empty<StatisticsOPYOY>()
  4113. ));
  4114. }
  4115. monthData = monthData.OrderBy(x => x.MonthId).ToList();
  4116. }
  4117. //2、费用父类是否足够
  4118. for (int i = 0; i < monthData.Count; i++)
  4119. {
  4120. var month = monthData[i];
  4121. var opParentFeeIds = month.FeeDatas.Select(x => x.FeeId).ToList();
  4122. var opParentFeeDataSelector = opParentFeeData.Where(x => !opParentFeeIds.Contains(x.Id)).ToList();
  4123. if (opParentFeeDataSelector.Count > 0)
  4124. {
  4125. var feeDatas = month.FeeDatas.ToList();
  4126. foreach (var item in opParentFeeDataSelector)
  4127. {
  4128. feeDatas.Add(new StatisticsOPYOY(
  4129. feeId: item.Id,
  4130. feeName: item.Name,
  4131. currPeriodFee: 0.00M,
  4132. samePeriodFee: 0.00M,
  4133. currPeriodGroupTotal: 0,
  4134. samePeriodGroupTotal: 0,
  4135. subFeeData: Array.Empty<StatisticsOPSubFeeYOY>()
  4136. ));
  4137. }
  4138. feeDatas = feeDatas.OrderBy(x => x.FeeId).ToList();
  4139. monthData[i].FeeDatas = feeDatas.ToArray();
  4140. }
  4141. }
  4142. //3、费用子类是否足够
  4143. return Ok(JsonView(true, "操作成功!", monthData));
  4144. }
  4145. return Ok(JsonView(false, "操作失败!"));
  4146. }
  4147. #endregion
  4148. }
  4149. }