StatisticsController.cs 224 KB

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