StatisticsController.cs 182 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738
  1. using Microsoft.AspNetCore.Mvc;
  2. using NPOI.POIFS.Properties;
  3. using NPOI.SS.Formula.Functions;
  4. using OASystem.API.OAMethodLib;
  5. using OASystem.Domain.Dtos.Groups;
  6. using OASystem.Domain.Dtos.Statistics;
  7. using OASystem.Domain.Entities.Financial;
  8. using OASystem.Domain.ViewModels.Financial;
  9. using OASystem.Domain.ViewModels.Groups;
  10. using OASystem.Domain.ViewModels.Statistics;
  11. using OASystem.Infrastructure.Repositories.Groups;
  12. using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
  13. using System;
  14. using OASystem.Domain.Entities.Customer;
  15. using System.Collections.Generic;
  16. using Microsoft.AspNetCore.Mvc.RazorPages;
  17. using Microsoft.VisualBasic;
  18. using OASystem.Domain.Entities.Groups;
  19. using Microsoft.Extensions.DependencyInjection;
  20. using Aspose.Words.Lists;
  21. using static OASystem.API.OAMethodLib.GeneralMethod;
  22. using TypeInfo = OASystem.Domain.ViewModels.Statistics.TypeInfo;
  23. using System.Net.NetworkInformation;
  24. using System.ComponentModel.Design;
  25. using NetTaste;
  26. using OASystem.Domain.ViewModels.QiYeWeChat;
  27. using NPOI.POIFS.Crypt.Dsig;
  28. using EyeSoft.SequentialIdentity;
  29. using Microsoft.Extensions.Configuration;
  30. using System.Text.Json;
  31. using OASystem.RedisRepository;
  32. using OASystem.RedisRepository.RedisAsyncHelper;
  33. using System.Data;
  34. using OfficeOpenXml.Export.ToDataTable;
  35. using Aspose.Cells;
  36. using NPOI.OpenXmlFormats.Wordprocessing;
  37. namespace OASystem.API.Controllers
  38. {
  39. /// <summary>
  40. /// 统计模块
  41. /// </summary>
  42. [Route("api/[controller]")]
  43. [ApiController]
  44. public class StatisticsController : ControllerBase
  45. {
  46. private readonly int _decimalPlaces;
  47. private readonly IConfiguration _config;
  48. private readonly IMapper _mapper;
  49. private readonly SqlSugarClient _sqlSugar;
  50. private readonly DelegationInfoRepository _groupRep;
  51. private readonly SetDataRepository _setDataRep;
  52. private readonly TeamRateRepository _teamRateRep;
  53. private readonly VisitingClientsRepository _visitingClientsRep;
  54. /// <summary>
  55. /// Init
  56. /// </summary>
  57. /// <param name="mapper"></param>
  58. /// <param name="sqlSugar"></param>
  59. /// <param name="groupRep"></param>
  60. /// <param name="setDataRep"></param>
  61. public StatisticsController(IMapper mapper, IConfiguration config, SqlSugarClient sqlSugar, DelegationInfoRepository groupRep, SetDataRepository setDataRep, TeamRateRepository teamRate, VisitingClientsRepository visitingClientsRep)
  62. {
  63. _mapper = mapper;
  64. _config = config;
  65. _groupRep = groupRep;
  66. _setDataRep = setDataRep;
  67. _sqlSugar = sqlSugar;
  68. _teamRateRep = teamRate;
  69. _visitingClientsRep = visitingClientsRep;
  70. }
  71. #region 团组报表
  72. /// <summary>
  73. /// 团组报表
  74. /// Items
  75. /// </summary>
  76. /// <param name="_dto">团组列表请求dto</param>
  77. /// <returns></returns>
  78. [HttpPost("PostGroupStatementItems")]
  79. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  80. public async Task<IActionResult> PostGroupStatementItems(GroupStatementItemsDto _dto)
  81. {
  82. #region 参数验证
  83. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  84. if (_dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  85. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  86. #region 页面操作权限验证
  87. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  88. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  89. #endregion
  90. #endregion
  91. if (_dto.PortType == 1 || _dto.PortType == 2 || _dto.PortType == 3) // web/Android/IOS
  92. {
  93. string sqlWhere = string.Empty;
  94. if (_dto.IsSure == 0) //未完成
  95. {
  96. sqlWhere += string.Format(@" And IsSure = 0");
  97. }
  98. else if (_dto.IsSure == 1) //已完成
  99. {
  100. sqlWhere += string.Format(@" And IsSure = 1");
  101. }
  102. if (!string.IsNullOrEmpty(_dto.SearchCriteria))
  103. {
  104. string tj = _dto.SearchCriteria;
  105. 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}%')",
  106. tj, tj, tj, tj, tj);
  107. }
  108. string sql = string.Format(@"Select row_number() over(order by gdi.VisitDate Desc) as Row_Number,
  109. gdi.Id,TourCode,ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,
  110. ClientName,ClientUnit,VisitDate,ssd.Id TeamTypeId, ssd.Name TeamType,
  111. VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure,gdi.CreateTime,
  112. pr.LastCollectionTime
  113. From Grp_DelegationInfo gdi
  114. Left Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  115. Left Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  116. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  117. Left Join (
  118. SELECT Diid, MAX(CreateTime) LastCollectionTime
  119. FROM Fin_ProceedsReceived
  120. Where IsDel = 0
  121. GROUP BY Diid
  122. ) pr On gdi.Id = pr.Diid
  123. Where gdi.IsDel = 0 {0} ", sqlWhere);
  124. RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
  125. var _DelegationList = await _sqlSugar.SqlQueryable<GroupStatementItemView>(sql).ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);//ToPageAsync
  126. var _view = new
  127. {
  128. PageFuncAuth = pageFunAuthView,
  129. Data = _DelegationList
  130. };
  131. return Ok(JsonView(true, "查询成功!", _view, total));
  132. }
  133. else
  134. {
  135. return Ok(JsonView(false, "查询失败"));
  136. }
  137. }
  138. /// <summary>
  139. /// 团组报表
  140. /// Details
  141. /// </summary>
  142. /// <param name="_dto">团组列表请求dto</param>
  143. /// <returns></returns>
  144. [HttpPost("PostGroupStatementDetails")]
  145. //[JsonConverter(typeof(DecimalConverter), 2)]
  146. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  147. public async Task<IActionResult> PostGroupStatementDetails(GroupStatementDetailsDto _dto)
  148. {
  149. /*
  150. * 团组报表计算方式
  151. * 当前总支出 = 团组支出.Sum() + 超支费用.Sum()
  152. * 应收金额 = 应收表.Sum()
  153. * 已收金额 = 已收表.Sum()
  154. * 应收利润(应收-支出) = 应收金额 - 收款退还 - 当前总支出
  155. * 已收利润(已收-支出) = 已收金额 - 收款退还 - 当前总支出
  156. *
  157. */
  158. #region 参数验证
  159. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  160. if (_dto.PageId < 1) _dto.PageId = 38; //团组报表页面Id
  161. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  162. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  163. #region 页面操作权限验证
  164. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  165. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  166. #endregion
  167. #endregion
  168. if (_dto.PortType == 1 || _dto.PortType == 2 || _dto.PortType == 3) // web/Android/IOS
  169. {
  170. GroupStatementDetailsView _view = new GroupStatementDetailsView();
  171. #region 费用类型 币种,转账,客户信息
  172. List<Sys_SetData> _setDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToListAsync();
  173. var _clientDatas = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync();
  174. #endregion
  175. #region 团组收入
  176. GroupIncomeView _giView = new GroupIncomeView();
  177. /*
  178. * 应收报表
  179. * 增加方式=实际报价时 费用必须审核才能进入团组报表
  180. */
  181. decimal frTotalAmount = 0.00M;//应收总金额
  182. 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,
  183. sd.Name As CurrencyCode,sd.Remark As CurrencyName,fr.Rate,fr.ItemSumPrice,fr.CreateTime
  184. From Fin_ForeignReceivables fr
  185. Left Join Sys_SetData sd On fr.Currency = sd.Id
  186. Left Join Sys_Users u On fr.Auditor = u.Id
  187. Where fr.IsDel = 0 And fr.Diid = {0} Order By CreateTime", _dto.DiId);
  188. List<Gsd_ForeignReceivablesView> _frViews = await _sqlSugar.SqlQueryable<Gsd_ForeignReceivablesView>(_frSql).ToListAsync();
  189. //List<Gsd_ForeignReceivablesView> _frViews = new List<Gsd_ForeignReceivablesView>();
  190. //if (_frViews1.Count > 0)
  191. //{
  192. // _frViews.AddRange(_frViews1.Where(x => x.AddingWay != 2).ToList());
  193. // _frViews.AddRange(_frViews1.Where(x => x.AddingWay == 2 && x.Status == 1).ToList());
  194. //}
  195. _frViews.ForEach(x =>
  196. {
  197. string namePrefix = string.Empty;
  198. if (x.AddingWay == 0) namePrefix = $"账单模块-";
  199. else if (x.AddingWay == 1) namePrefix = $"成本预算模块-";
  200. else if (x.AddingWay == 2) namePrefix = $"实际报价-";
  201. x.PriceName = $"{namePrefix}{x.PriceName}";
  202. });
  203. frTotalAmount = _frViews.Sum(it => it.ItemSumPrice);
  204. _giView.Receivables = _frViews;
  205. _giView.ReceivableStr = string.Format(@"应收款合计:{0} CNY(人民币)", frTotalAmount.ConvertToDecimal1().ToString("#0.00"));
  206. /*
  207. * 已收报表
  208. */
  209. decimal prTotalAmount = 0.00M;//已收总金额
  210. string _prSql = string.Format(@"Select pr.Id,pr.Diid,pr.SectionTime As SectionTimeDt,pr.Price,pr.Currency,
  211. sd1.Name As CurrencyCode,sd1.Remark As CurrencyName,pr.Client,
  212. pr.ReceivablesType,sd2.Name As ReceivablesTypeName,pr.Remark,pr.CreateTime
  213. From Fin_ProceedsReceived pr
  214. Left Join Sys_SetData sd1 On pr.Currency = sd1.Id
  215. Left Join Sys_SetData sd2 On pr.ReceivablesType = sd2.Id
  216. Where pr.IsDel = 0 and pr.Diid = {0} Order By CreateTime", _dto.DiId);
  217. List<Gsd_ProceedsReceivedView> _prViews = await _sqlSugar.SqlQueryable<Gsd_ProceedsReceivedView>(_prSql).ToListAsync();
  218. prTotalAmount = _prViews.Sum(it => it.Price);
  219. _giView.ProceedsReceivedViews = _prViews;
  220. _giView.ProceedsReceivedStr = string.Format(@$"应收合计:{frTotalAmount.ToString("#0.00")} CNY 已收款合计:{prTotalAmount.ConvertToDecimal1().ToString("#0.00")} CNY");
  221. /*
  222. * 超支费用
  223. */
  224. decimal exTotalAmount = 0.00M;
  225. 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,
  226. (gec.PriceSum * gec.Coefficient * ccp.DayRate) As CNYPrice,ccp.DayRate,ccp.Payee,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  227. sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant,gec.CreateTime
  228. From OA2023DB.dbo.Fin_GroupExtraCost gec
  229. Left Join Grp_CreditCardPayment ccp On gec.Id = ccp.CId
  230. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  231. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  232. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  233. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  234. Where ccp.IsDel = 0 And ccp.CTable = 1015 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ccp.DiId = {0} Order By CreateTime", _dto.DiId);
  235. List<Gsd_ExtraCostsView> _ExtraCostsViews = await _sqlSugar.SqlQueryable<Gsd_ExtraCostsView>(_ecSql).ToListAsync();
  236. #region 超支费用 - 模拟数据
  237. //if (_ExtraCostsViews.Count < 1)
  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. // _ExtraCostsViews.Add(new Gsd_ExtraCostsView()
  256. // {
  257. // GECId = 0,
  258. // GECDiId = 2334,
  259. // PriceName = "模拟数据-超支费用名称",
  260. // PayMoney = 1000.00M,
  261. // PaymentCurrency = "CNY",
  262. // DayRate = 1.0000M,
  263. // CNYPrice = 1000.00M,
  264. // Payee = "模拟数据-超支费用收款方",
  265. // OrbitalPrivateTransfer = 1,
  266. // PayWay = "刷卡",
  267. // CardType = "招行卡",
  268. // IsPay = 1,
  269. // Applicant = "刘华举"
  270. // });
  271. //}
  272. #endregion
  273. exTotalAmount = _ExtraCostsViews.Sum(it => it.CNYPrice);
  274. _giView.ExtraCostsViews = _ExtraCostsViews;
  275. _giView.ExtraCostsStr = string.Format(@"人民币总费用:{0} CNY", exTotalAmount.ConvertToDecimal1().ToString("#0.00"));
  276. /*
  277. * 收款退还
  278. */
  279. decimal promTotalAmount = 0.00M;// 收款退还总金额
  280. List<Gsd_PaymentRefundAndOtherMoneyView> _promView = new List<Gsd_PaymentRefundAndOtherMoneyView>();
  281. //删除了 And prom.PriceType = 1
  282. string _ropSql = string.Format(@"Select u.CnName As Appliction,prom.Id As PrId,prom.DiId As PrDiId,prom.Price As PrPrice,
  283. prom.PriceName AS PrPriceName,prom.CurrencyId As PrCurrencyId,
  284. prom.PayType As PrPayType,prom.PriceType As PrPriceType,ccp.*,prom.CreateTime As PrCreateTime
  285. From Fin_PaymentRefundAndOtherMoney prom
  286. Left Join Grp_CreditCardPayment ccp On prom.DiId = ccp.DIId And prom.Id = ccp.CId
  287. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  288. Where prom.IsDel = 0 And prom.PayType = 1 And ccp.CTable = 285
  289. And ccp.IsAuditGM = 1 And ccp.IsPay = 1
  290. And prom.DiId = {0} Order By PrCreateTime", _dto.DiId);
  291. var _promDatas = await _sqlSugar.SqlQueryable<Gsd_PaymentRefundAndOtherMoneyDataSource1View>(_ropSql).ToListAsync();
  292. foreach (var ropItem in _promDatas)
  293. {
  294. string thisCueencyCode = "Unknown";
  295. string thisCueencyName = "Unknown";
  296. var currency = _setDatas.Where(it => it.Id == ropItem.PaymentCurrency).FirstOrDefault();
  297. if (currency != null)
  298. {
  299. thisCueencyCode = currency.Name;
  300. thisCueencyName = currency.Remark;
  301. }
  302. string orbitalPrivateTransferStr = "Unknown";
  303. var orbitalPrivateTransfer = _setDatas.Where(it => it.Id == ropItem.OrbitalPrivateTransfer).FirstOrDefault();
  304. if (orbitalPrivateTransfer != null)
  305. {
  306. orbitalPrivateTransferStr = orbitalPrivateTransfer.Name;
  307. }
  308. string payStr = "Unknown";
  309. var pay = _setDatas.Where(it => it.Id == ropItem.PayDId).FirstOrDefault();
  310. if (pay != null)
  311. {
  312. payStr = pay.Name;
  313. }
  314. Gsd_PaymentRefundAndOtherMoneyView gsd_PaymentRefund = new Gsd_PaymentRefundAndOtherMoneyView()
  315. {
  316. Id = ropItem.Id,
  317. DiId = ropItem.DIId,
  318. PriceName = ropItem.PrPriceName,
  319. PayCurrencyCode = thisCueencyCode,
  320. PayCurrencyName = thisCueencyName,
  321. Price = ropItem.PrPrice,
  322. CNYPrice = ropItem.RMBPrice,
  323. ThisRate = ropItem.DayRate,
  324. Payee = ropItem.Payee,
  325. PayTime = ropItem.AuditGMDate,
  326. OrbitalPrivateTransfer = ropItem.OrbitalPrivateTransfer,
  327. PayType = payStr,
  328. IsPay = ropItem.IsPay,
  329. Applicant = ropItem.Appliction
  330. };
  331. _promView.Add(gsd_PaymentRefund);
  332. }
  333. #region 收款退还 - 模拟数据
  334. //if (_promView.Count < 1)
  335. //{
  336. // _promView.Add(new Gsd_PaymentRefundAndOtherMoneyView()
  337. // {
  338. // Id = 0,
  339. // DiId = 2334,
  340. // PriceName = "模拟数据-费用名称",
  341. // PayCurrencyCode = "CNY",
  342. // PayCurrencyName = "人民币",
  343. // Price = 1000.00M,
  344. // CNYPrice = 1000.00M,
  345. // ThisRate = 1.00M,
  346. // Payee = "模拟数据-收款方",
  347. // PayTime = "2023-01-01 15:20:01",
  348. // OrbitalPrivateTransfer = 1,
  349. // PayType = "刷卡",
  350. // IsPay = 1,
  351. // Applicant = "刘华举"
  352. // });
  353. // _promView.Add(new Gsd_PaymentRefundAndOtherMoneyView()
  354. // {
  355. // Id = 0,
  356. // DiId = 2334,
  357. // PriceName = "模拟数据-费用名称",
  358. // PayCurrencyCode = "CNY",
  359. // PayCurrencyName = "人民币",
  360. // Price = 1000.00M,
  361. // CNYPrice = 1000.00M,
  362. // ThisRate = 1.00M,
  363. // Payee = "模拟数据-收款方",
  364. // PayTime = "2023-01-01 15:20:01",
  365. // OrbitalPrivateTransfer = 1,
  366. // PayType = "刷卡",
  367. // IsPay = 1,
  368. // Applicant = "刘华举"
  369. // });
  370. //}
  371. #endregion
  372. promTotalAmount = _promView.Sum(it => it.CNYPrice);
  373. _giView.PaymentRefundAndOtherMoneyViews = _promView;
  374. _giView.PaymentRefundAndOtherMoneyStr = string.Format(@"人民币总费用:{0} CNY", promTotalAmount.ConvertToDecimal1().ToString("#0.00"));
  375. decimal BalancePayment = frTotalAmount - prTotalAmount + promTotalAmount;
  376. _view.GroupIncome = _giView;
  377. _view.GroupIncomeStr = string.Format(@"<span style='color:red;'>剩余尾款:{0} CNY(包含了收款退还费用数据)</span>", BalancePayment.ConvertToDecimal1().ToString("#0.00"));
  378. #endregion
  379. #region 团组支出
  380. GroupExpenditureView _geView = new GroupExpenditureView();
  381. #region 酒店预定费用
  382. List<GroupHotelFeeView> groupHotelFeeViews = new List<GroupHotelFeeView>();
  383. //ccp.RMBPrice As CNYPrice
  384. //(((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice
  385. string hotelFeeSql = string.Format(@"Select hr.Id As HrId,hr.DiId As HrDiId,hr.City,hr.HotelName,hr.CheckInDate,hr.CheckOutDate,hr.CardPrice As RoomPrice,
  386. sd1.Name As PaymentCurrency,hr.SingleRoomPrice,hr.SingleRoomCount,hr.DoubleRoomPrice,
  387. hr.DoubleRoomCount,hr.SuiteRoomPrice,hr.SuiteRoomCount,hr.OtherRoomPrice,hr.OtherRoomCount,
  388. hr.BreakfastPrice,sd4.Name As BreakfastCurrency,hr.Isoppay,hr.GovernmentRent,
  389. sd5.Name As GovernmentRentCurrency,hr.CityTax,sd6.Name As CityTaxCurrency,
  390. ccp.PayMoney,(((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice,ccp.DayRate,ccp.Payee,ccp.OrbitalPrivateTransfer,
  391. sd2.Name As PayWay,sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant
  392. From Grp_HotelReservations hr
  393. Left Join Grp_CreditCardPayment ccp On hr.Id = ccp.CId
  394. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  395. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  396. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  397. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  398. Left Join Sys_SetData sd4 On hr.BreakfastCurrency = sd4.Id
  399. Left Join Sys_SetData sd5 On hr.GovernmentRentCurrency = sd5.Id
  400. Left Join Sys_SetData sd6 On hr.CityTaxCurrency = sd6.Id
  401. Where hr.IsDel = 0 And ccp.IsDel = 0 And ccp.CTable = 76 And ccp.IsAuditGM = 1 And ccp.PayMoney<> 0 And hr.DiId = {0}
  402. Order By CheckInDate Asc", _dto.DiId);
  403. groupHotelFeeViews = await _sqlSugar.SqlQueryable<GroupHotelFeeView>(hotelFeeSql).ToListAsync();
  404. List<int> hotelSubIds = groupHotelFeeViews.Select(it => it.HrId).ToList();
  405. List<Grp_HotelReservationsContent> groupHotelContentFeeViews = new List<Grp_HotelReservationsContent>();
  406. groupHotelContentFeeViews = await _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => hotelSubIds.Contains(it.HrId)).ToListAsync();
  407. decimal HotelCNYTotalPrice = 0.00M;
  408. var teamRateData = await _teamRateRep.PostGroupRateInfoByDiId(_dto.DiId);
  409. foreach (var item in groupHotelFeeViews)
  410. {
  411. if (groupHotelContentFeeViews.Count > 0)
  412. {
  413. string paymentStr = string.Empty;
  414. var roomData = groupHotelContentFeeViews.Find(it => it.HrId == item.HrId && it.PriceType == 1); //房费
  415. item.RoomPrice = roomData?.Price ?? 0.00M;
  416. if (item.RoomPrice != 0)
  417. {
  418. if (roomData.IsPay == 0) paymentStr += $"房费:未付款<br/>";
  419. item.RoomPriceCurrency = _setDatas.Find(it => it.Id == roomData?.Currency)?.Name;
  420. string feeMark1 = roomData?.OrbitalPrivateTransfer == 0 ? "公转" : "私转";
  421. string isFeeMark1 = roomData?.IsOppay == 1 ? "是" : "否";
  422. item.RoomInfoTips = @$"当时汇率:{roomData?.Rate.ToString("#0.0000")} <br/>
  423. 收款方:{roomData?.Payee}<br/>
  424. 费用标识:{feeMark1} <br/>
  425. 支付方式:{_setDatas.Find(it => it.Id == roomData?.PayDId)?.Name} <br/>
  426. 卡类型:{_setDatas.Find(it => it.Id == roomData?.CTDId)?.Name}<br/>
  427. 是否由地接支付:{isFeeMark1} <br/>";
  428. }
  429. var breakfastData = groupHotelContentFeeViews.Find(it => it.HrId == item.HrId && it.PriceType == 2); //早餐
  430. item.BreakfastPrice = breakfastData?.Price ?? 0.00M;
  431. if (item.BreakfastPrice != 0)
  432. {
  433. if (breakfastData.IsPay == 0) paymentStr += $"早餐:未付款<br/>";
  434. item.BreakfastCurrency = _setDatas.Find(it => it.Id == breakfastData?.Currency)?.Name;
  435. string feeMark2 = breakfastData?.OrbitalPrivateTransfer == 0 ? "公转" : "私转";
  436. string isFeeMark2 = breakfastData?.IsOppay == 1 ? "是" : "否";
  437. item.BreakfastInfoTips = @$"当时汇率:{breakfastData?.Rate.ToString("#0.0000")} <br/>
  438. 收款方:{breakfastData?.Payee}<br/>
  439. 费用标识:{feeMark2} <br/>
  440. 支付方式:{_setDatas.Find(it => it.Id == roomData?.PayDId)?.Name} <br/>
  441. 卡类型:{_setDatas.Find(it => it.Id == roomData?.CTDId)?.Name} <br/>
  442. 是否由地接支付:{isFeeMark2} <br/>";
  443. }
  444. var landTaxData = groupHotelContentFeeViews.Find(it => it.HrId == item.HrId && it.PriceType == 3); //地税
  445. item.GovernmentRent = landTaxData?.Price ?? 0.00M;
  446. if (item.GovernmentRent != 0)
  447. {
  448. if (landTaxData.IsPay == 0) paymentStr += $"地税:未付款<br/>";
  449. item.GovernmentRentCurrency = _setDatas.Find(it => it.Id == landTaxData?.Currency)?.Name;
  450. string feeMark3 = landTaxData?.OrbitalPrivateTransfer == 0 ? "公转" : "私转";
  451. string isFeeMark3 = landTaxData?.IsOppay == 1 ? "是" : "否";
  452. item.GovernmentRentTips = @$"当时汇率:{landTaxData?.Rate.ToString("#0.0000")} <br/>
  453. 收款方:{landTaxData?.Payee}<br/>
  454. 费用标识:{feeMark3} <br/>
  455. 支付方式:{_setDatas.Find(it => it.Id == landTaxData?.PayDId)?.Name} <br/>
  456. 卡类型:{_setDatas.Find(it => it.Id == landTaxData?.CTDId)?.Name} <br/>
  457. 是否由地接支付:{isFeeMark3} <br/>";
  458. }
  459. var cityTaxData = groupHotelContentFeeViews.Find(it => it.HrId == item.HrId && it.PriceType == 4); //城市税
  460. item.CityTax = cityTaxData?.Price ?? 0.00M;
  461. if (item.CityTax != 0)
  462. {
  463. if (cityTaxData.IsPay == 0) paymentStr += $"城市税:未付款<br/>";
  464. item.CityTaxCurrency = _setDatas.Find(it => it.Id == cityTaxData?.Currency)?.Name;
  465. string feeMark4 = cityTaxData?.OrbitalPrivateTransfer == 0 ? "公转" : "私转";
  466. string isFeeMark4 = landTaxData?.IsOppay == 1 ? "是" : "否";
  467. item.CityTaxTips = @$"当时汇率:{cityTaxData?.Rate.ToString("#0.0000")} <br/>
  468. 收款方:{cityTaxData?.Payee}<br/>
  469. 费用标识:{feeMark4} <br/>
  470. 支付方式:{_setDatas.Find(it => it.Id == cityTaxData?.PayDId)?.Name} <br/>
  471. 卡类型:{_setDatas.Find(it => it.Id == cityTaxData?.CTDId)?.Name} <br/>
  472. 是否由地接支付:{isFeeMark4} <br/>";
  473. }
  474. if (!string.IsNullOrEmpty(paymentStr))
  475. {
  476. item.IsPay = 2;
  477. item.PayTips = paymentStr;
  478. }
  479. }
  480. else
  481. {
  482. decimal roomPrice = (item.SingleRoomCount * item.SingleRoomPrice) +
  483. (item.DoubleRoomCount * item.DoubleRoomPrice) +
  484. (item.SuiteRoomCount * item.SuiteRoomPrice) +
  485. (item.OtherRoomCount * item.OtherRoomPrice);
  486. //item.RoomPrice = item.CardPrice;
  487. item.RoomPriceCurrency = item.PaymentCurrency;
  488. }
  489. HotelCNYTotalPrice += item.CNYPrice;
  490. item.PayMoney = item.PayMoney.ConvertToDecimal1();
  491. item.CNYPrice = item.CNYPrice.ConvertToDecimal1();
  492. }
  493. _geView.GroupHotelFeeViews = groupHotelFeeViews;
  494. _geView.GroupHotelFeeStr = string.Format(@"人民币总费用:{0} CNY", HotelCNYTotalPrice.ToString("#0.00"));
  495. #endregion
  496. #region 地接费用
  497. List<GroupCTGGRFeeView> groupCTGGRFeeViews = new List<GroupCTGGRFeeView>();
  498. //string CTGGRFeeSql = string.Format(@"Select ctggr.Id As CTGGRId,ctggr.DiId As CTGGRDiId,ctggr.PriceName As Area,ctggrc.*,ctggrc.Price As PayMoney,
  499. // sd2.name As PaymentCurrency,ccp.PayPercentage,
  500. // (ctggrc.Price / (ccp.PayPercentage / 100)) As AmountPaid,
  501. // (ctggrc.Price / (ccp.PayPercentage / 100) - ctggrc.Price) As BalancePayment,
  502. // ccp.DayRate,(ctggrc.Price * ccp.DayRate) As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  503. // ccp.OrbitalPrivateTransfer,sd1.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ctggr.CreateTime
  504. // From Grp_CarTouristGuideGroundReservations ctggr
  505. // Left Join ( Select cggrc.CTGGRId,sd1.Name As PriceName,cggrc.Price,sd2.Name As PriceCurrency,
  506. // cggrc.DatePrice,cggrc.PriceContent
  507. // From Grp_CarTouristGuideGroundReservationsContent cggrc
  508. // Left Join Sys_SetData sd1 On cggrc.SId = sd1.Id
  509. // Left Join Sys_SetData sd2 On cggrc.Currency = sd2.Id
  510. // Where cggrc.ISdel = 0 And cggrc.Price != 0.00
  511. // ) ctggrc On ctggr.Id = ctggrc.CTGGRId
  512. // Left Join Grp_CreditCardPayment ccp On ccp.IsDel = 0 And ccp.CTable = 79 And ctggr.Id = ccp.CId
  513. // Left Join Sys_SetData sd1 On ccp.PayDId = sd1.Id
  514. // Left Join Sys_SetData sd2 On ccp.PaymentCurrency = sd2.Id
  515. // Left Join Sys_Users u On ccp.CreateUserId = u.Id
  516. // Where ctggr.IsDel = 0 And ccp.IsAuditGM = 1 And ctggr.DiId = {0}
  517. // Order By CreateTime", _dto.DiId);
  518. string CTGGRFeeSql = string.Format(@"Select ctggr.Id As CTGGRId,ctggr.DiId As CTGGRDiId,ctggr.PriceName As Area,ctggrc.*,ctggrc.Price As PayMoney,
  519. sd2.name As PaymentCurrency,ccp.PayPercentage,
  520. (ctggrc.Price * (ccp.PayPercentage / 100)) As AmountPaid,
  521. (ctggrc.Price - ctggrc.Price * (ccp.PayPercentage / 100)) As BalancePayment,
  522. ccp.DayRate,(ctggrc.Price * (ccp.PayPercentage / 100) * ccp.DayRate) As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  523. ccp.OrbitalPrivateTransfer,sd1.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ctggr.CreateTime
  524. From Grp_CarTouristGuideGroundReservations ctggr
  525. Left Join ( Select cggrc.CTGGRId,sd1.Name As PriceName,cggrc.Price*cggrc.Count As Price,sd2.Name As PriceCurrency,
  526. cggrc.DatePrice,cggrc.PriceContent
  527. From Grp_CarTouristGuideGroundReservationsContent cggrc
  528. Left Join Sys_SetData sd1 On cggrc.SId = sd1.Id
  529. Left Join Sys_SetData sd2 On cggrc.Currency = sd2.Id
  530. Where cggrc.ISdel = 0 And cggrc.Price != 0.00
  531. ) ctggrc On ctggr.Id = ctggrc.CTGGRId
  532. Left Join Grp_CreditCardPayment ccp On ccp.IsDel = 0 And ccp.CTable = 79 And ctggr.Id = ccp.CId
  533. Left Join Sys_SetData sd1 On ccp.PayDId = sd1.Id
  534. Left Join Sys_SetData sd2 On ccp.PaymentCurrency = sd2.Id
  535. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  536. Where ctggr.IsDel = 0 And ccp.IsAuditGM = 1 And ctggr.DiId = {0}
  537. Order By CreateTime", _dto.DiId);
  538. groupCTGGRFeeViews = await _sqlSugar.SqlQueryable<GroupCTGGRFeeView>(CTGGRFeeSql).ToListAsync();
  539. string CTGGRFeeStr = "";
  540. decimal CTGGRCNYTotalPrice = 0.00M;
  541. //按1 地区,2 币种,3 汇率 分组计算
  542. var groupCTGGRFeeDatas = groupCTGGRFeeViews.GroupBy(it => it.Area);
  543. foreach (var ctggfr in groupCTGGRFeeDatas)
  544. {
  545. var ctggfr_curr = ctggfr.GroupBy(it => it.PaymentCurrency);
  546. if (ctggfr_curr.Count() > 0)
  547. {
  548. foreach (var curr in ctggfr_curr)
  549. {
  550. var ctggfr_rate = curr.GroupBy(it => it.DayRate);
  551. if (ctggfr_rate.Count() > 0)
  552. {
  553. foreach (var rate in ctggfr_rate)
  554. {
  555. CTGGRFeeStr += string.Format(@$"{ctggfr.Key} 总费用:{rate.Sum(it => it.AmountPaid).ToString("#0.00")}
  556. {rate.FirstOrDefault()?.PaymentCurrency}(人民币:
  557. {rate.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00"))).ToString("#0.00")} CNY 当时支付汇率:
  558. {rate.FirstOrDefault()?.DayRate.ToString("#0.0000")})\r\n");
  559. CTGGRCNYTotalPrice += rate.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  560. }
  561. }
  562. else
  563. {
  564. CTGGRFeeStr += string.Format(@$"{ctggfr.Key} 总费用:{curr.Sum(it => it.AmountPaid).ToString("#0.00")}
  565. {curr.FirstOrDefault()?.PaymentCurrency}(人民币:
  566. {curr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00"))).ToString("#0.00")} CNY 当时支付汇率:
  567. {curr.FirstOrDefault()?.DayRate.ToString("#0.0000")})\r\n");
  568. CTGGRCNYTotalPrice += curr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  569. }
  570. }
  571. }
  572. else
  573. {
  574. CTGGRFeeStr += string.Format(@$"{ctggfr.Key} 总费用:{ctggfr.Sum(it => it.AmountPaid).ToString("#0.00")}
  575. {ctggfr.FirstOrDefault()?.PaymentCurrency}(人民币:
  576. {ctggfr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00"))).ToString("#0.00")} CNY 当时支付汇率:
  577. {ctggfr.FirstOrDefault()?.DayRate.ToString("#0.0000")})\r\n");
  578. CTGGRCNYTotalPrice += ctggfr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  579. }
  580. }
  581. foreach (var item in groupCTGGRFeeViews)
  582. {
  583. if (!string.IsNullOrEmpty(item.AuditGMDate))
  584. {
  585. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  586. }
  587. if (item.DatePrice != null)
  588. {
  589. item.PriceName = $"{item.PriceName}({Convert.ToDateTime(item.DatePrice).ToString("yyyy-MM-dd")})";
  590. }
  591. //CTGGRFeeStr += string.Format(@"{0} 总费用:{1} {2}(人民币:{3} CNY 当时支付汇率:{4})\r\n",
  592. // item.Area, item.AmountPaid.ConvertToDecimal1().ToString("#0.00"), item.PaymentCurrency, item.CNYPrice.ToString("#0.0000"), item.DayRate.ToString("#0.0000"));
  593. //CTGGRCNYTotalPrice += item.CNYPrice;
  594. }
  595. _geView.GroupCTGGRFeeViews = groupCTGGRFeeViews;
  596. _geView.GroupCTGGRFeeStr = string.Format(@"{0}人民币总费用:{1} CNY", CTGGRFeeStr, CTGGRCNYTotalPrice.ToString("#0.00"));
  597. #endregion
  598. #region 机票预订费用
  599. //(((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice
  600. //ccp.RMBPrice As CNYPrice
  601. List<GroupAirFeeView> groupAirFeeViews = new List<GroupAirFeeView>();
  602. string groupAirFeeSql = string.Format(@"Select atr.Id As AirId,atr.DIId As AirDiId,atr.FlightsCode,atr.FlightsCity,sd4.Name As AirTypeName,
  603. atr.FlightsDate,atr.FlightsTime,atr.ClientName,atr.ClientNum,ccp.PayMoney,
  604. sd1.Name As PayMoneyCurrency,(((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice,ccp.DayRate,ccp.Payee,ccp.AuditGMDate,
  605. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant,atr.CreateTime,
  606. atr.CType
  607. From Grp_AirTicketReservations atr
  608. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 85 And atr.Id = ccp.CId
  609. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  610. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  611. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  612. Left Join Sys_SetData sd4 On atr.CType = sd4.Id
  613. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  614. Where atr.IsDel = 0 And ccp.IsAuditGM = 1 And atr.DiId = {0} Order By CreateTime", _dto.DiId);
  615. groupAirFeeViews = await _sqlSugar.SqlQueryable<GroupAirFeeView>(groupAirFeeSql).ToListAsync();
  616. string str = "";
  617. List<dynamic> airClientPris = new List<dynamic>();
  618. decimal AirCNYTotalPrice = 0.00M;
  619. decimal JJCCNYTotalPrice = 0.00M, JJCPeopleNum = 0.00M, JJCAveragePrice = 0.00M;
  620. decimal GWCCNYTotalPrice = 0.00M, GWCPeopleNum = 0.00M, GWCAveragePrice = 0.00M;
  621. //if (groupAirFeeViews.Count > 0)
  622. //{
  623. // JJCCNYTotalPrice = groupAirFeeViews.Where(it => it.AirTypeName.Equals("经济舱")).Sum(it => it.CNYPrice);
  624. // JJCPeopleNum = groupAirFeeViews.Where(it => it.AirTypeName.Equals("经济舱")).Sum(it => it.ClientNum);
  625. // JJCAveragePrice = (JJCCNYTotalPrice / JJCPeopleNum).ConvertToDecimal1();
  626. // GWCCNYTotalPrice = groupAirFeeViews.Where(it => it.AirTypeName.Equals("公务舱")).Sum(it => it.CNYPrice);
  627. // GWCPeopleNum = groupAirFeeViews.Where(it => it.AirTypeName.Equals("公务舱")).Sum(it => it.ClientNum);
  628. // GWCAveragePrice = (GWCCNYTotalPrice / GWCPeopleNum).ConvertToDecimal1();
  629. //}
  630. int Index = 0;
  631. foreach (var item in groupAirFeeViews)
  632. {
  633. if (item.AirId > 2924)
  634. {
  635. string itemClientName = "";
  636. if (!string.IsNullOrEmpty(item.ClientName))
  637. {
  638. System.Text.RegularExpressions.Match m_EnName = Regex.Match(item.ClientName, @"[A-Za-z]+");
  639. System.Text.RegularExpressions.Match m_ZHName = Regex.Match(item.ClientName, @"[\u4e00-\u9fa5]");
  640. if (m_EnName.Success || m_ZHName.Success)
  641. {
  642. itemClientName = item.ClientName;
  643. decimal unitCost = 0.00M;
  644. AirCNYTotalPrice += item.CNYPrice;
  645. continue;
  646. }
  647. string[] clientIds = new string[] { };
  648. if (item.ClientName.Contains(','))
  649. {
  650. clientIds = item.ClientName.Split(',');
  651. }
  652. else
  653. {
  654. clientIds = new string[] { item.ClientName };
  655. }
  656. if (clientIds.Length > 0)
  657. {
  658. int[] output = Array.ConvertAll<string, int>(clientIds, delegate (string s) { return int.Parse(s); });
  659. if (output.Contains(-1))
  660. {
  661. itemClientName += $@"行程单";
  662. output = output.Where(val => val != -1).ToArray();
  663. }
  664. var clients = _clientDatas.Where(it => output.Contains(it.Id)).ToList();
  665. decimal unitCost = 0.00M;
  666. unitCost = (item.PayMoney / item.ClientNum).ConvertToDecimal1();
  667. int clienIndex = 1;
  668. foreach (var client in clients)
  669. {
  670. airClientPris.Add(new
  671. {
  672. CnName = client.LastName + client.FirstName,
  673. EnName = client.Pinyin,
  674. Price = unitCost,
  675. AirType = item.AirTypeName
  676. });
  677. string six = "";
  678. if (client.Sex == 0) six = "Mr";
  679. else if (client.Sex == 1) six = "Ms";
  680. itemClientName += string.Format(@"{0}.{1} {2};", clienIndex, client.LastName + client.FirstName, six);
  681. clienIndex++;
  682. }
  683. }
  684. }
  685. item.ClientName = itemClientName;
  686. }
  687. else
  688. {
  689. string clientPinYinName = "";
  690. decimal unitCost = 0.00M;
  691. int cNum = item.ClientNum == 0 ? 1 : item.ClientNum;
  692. unitCost = (item.PayMoney / cNum).ConvertToDecimal1();
  693. Regex r = new Regex("[0-9]");
  694. string name1 = item.ClientName;
  695. name1 = r.Replace(name1, "");
  696. string[] clientNames = name1.Split('.');
  697. for (int i = 0; i < item.ClientNum; i++)
  698. {
  699. string name = "";
  700. if (clientNames.Length > 0)
  701. {
  702. int index = i + 1;
  703. if (index < clientNames.Length)
  704. {
  705. name = clientNames[index].Replace("MR", "").Replace("MS", "").Trim();
  706. if (!string.IsNullOrEmpty(name))
  707. {
  708. airClientPris.Add(new
  709. {
  710. CnName = name,
  711. EnName = name,
  712. Price = unitCost,
  713. AirType = item.AirTypeName
  714. });
  715. }
  716. //if (name.Length > 0)
  717. //{
  718. // string nameLastStr = name[name.Length - 1].ToString();
  719. // if (nameLastStr.IsNumeric())
  720. // {
  721. // name = name.Substring(0, name.Length - 1).Trim();
  722. // }
  723. //}
  724. }
  725. }
  726. clientPinYinName += string.Format(@"{0}.{1}出票价为:{2} CNY;", Index + 1, name, unitCost.ToString("#0.00"));
  727. }
  728. }
  729. if (!string.IsNullOrEmpty(item.AuditGMDate))
  730. {
  731. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  732. }
  733. AirCNYTotalPrice += item.CNYPrice;
  734. }
  735. _geView.GroupAirFeeViews = groupAirFeeViews;
  736. if (airClientPris.Count > 0)
  737. {
  738. var peoplePriStr = "";
  739. var airClientPris1 = airClientPris.GroupBy(item => item.CnName)
  740. .Select(group => group.First())
  741. .ToList();
  742. int airClientPrisIndex = 1;
  743. foreach (var item in airClientPris1)
  744. {
  745. decimal price = 0.00M;
  746. var prices = airClientPris.Where(it => it.CnName == item.CnName).ToList();
  747. foreach (var pri in prices)
  748. {
  749. price += pri.Price;
  750. }
  751. peoplePriStr += $@"{airClientPrisIndex}.{item.EnName}出票价为: {price.ToString("#0.00")} CNY;";
  752. airClientPrisIndex++;
  753. }
  754. if (!string.IsNullOrEmpty(peoplePriStr))
  755. {
  756. str = $@"其中:{peoplePriStr}";
  757. }
  758. //经济舱均价
  759. var airJJCPris = airClientPris.Where(it => it.AirType == "经济舱").ToList();
  760. if (airJJCPris.Count > 0)
  761. {
  762. decimal jjcTotalPrice = 0.00M;
  763. foreach (var item in airJJCPris)
  764. {
  765. jjcTotalPrice += item.Price;
  766. }
  767. decimal jjcPeopleNum = airJJCPris.GroupBy(item => item.CnName)
  768. .Select(group => group.First())
  769. .ToList().Count(); ;
  770. JJCAveragePrice = jjcTotalPrice / jjcPeopleNum;
  771. }
  772. //公务舱均价
  773. var airGWCPris = airClientPris.Where(it => it.AirType == "公务舱").ToList();
  774. if (airGWCPris.Count > 0)
  775. {
  776. decimal gwcTotalPrice = 0.00M;
  777. foreach (var item in airGWCPris)
  778. {
  779. gwcTotalPrice += item.Price;
  780. }
  781. decimal gwcPeopleNum = airGWCPris.GroupBy(item => item.CnName)
  782. .Select(group => group.First())
  783. .ToList().Count();
  784. GWCAveragePrice = gwcTotalPrice / gwcPeopleNum;
  785. }
  786. }
  787. _geView.GroupAirFeeStr = $@"人民币总费用:{AirCNYTotalPrice.ToString("#0.00")} CNY\r\n{str}\r\n经济舱均价为:{JJCAveragePrice.ToString("#0.00")}CNY/人;公务舱均价为:{GWCAveragePrice.ToString("#0.00")}CNY/人;";
  788. #endregion
  789. #region 签证费用
  790. List<GroupVisaFeeView> groupVisaFeeViews = new List<GroupVisaFeeView>();
  791. string groupVisaFeeSql = string.Format(@"Select vi.Id As VisaId,vi.DIId As VisaDiId,vi.VisaClient,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  792. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  793. sd3.Name As CardTypeName,ccp.IsPay,u.CnName As Applicant,vi.CreateTime,
  794. (((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice
  795. From Grp_VisaInfo vi
  796. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 80 And vi.Id = ccp.CId
  797. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  798. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  799. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  800. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  801. Where vi.IsDel = 0 And ccp.IsAuditGM = 1 And vi.DIId = {0} Order By CreateTime", _dto.DiId);
  802. groupVisaFeeViews = await _sqlSugar.SqlQueryable<GroupVisaFeeView>(groupVisaFeeSql).ToListAsync();
  803. decimal VisaCNYTotalPirce = 0.00M;
  804. foreach (var item in groupVisaFeeViews)
  805. {
  806. string itemClientName = "";
  807. string visaClients = item.VisaClient;
  808. if (!string.IsNullOrEmpty(visaClients))
  809. {
  810. string[] clientIds = new string[] { };
  811. if (visaClients.Contains(','))
  812. {
  813. clientIds = visaClients.Split(',');
  814. }
  815. else
  816. {
  817. clientIds = new string[] { visaClients };
  818. }
  819. if (clientIds.Length > 0)
  820. {
  821. List<int> clientIds1 = new List<int>() { };
  822. foreach (var clientIdStr in clientIds)
  823. {
  824. if (clientIdStr.IsNumeric())
  825. {
  826. clientIds1.Add(int.Parse(clientIdStr));
  827. }
  828. }
  829. if (clientIds1.Count > 0)
  830. {
  831. var clients = _clientDatas.Where(it => clientIds1.Contains(it.Id)).ToList();
  832. foreach (var client in clients)
  833. {
  834. itemClientName += $"{client.LastName + client.FirstName},";
  835. }
  836. }
  837. else
  838. {
  839. itemClientName = visaClients;
  840. }
  841. }
  842. }
  843. if (itemClientName.Length > 0)
  844. {
  845. itemClientName = itemClientName.Substring(0, itemClientName.Length - 1);
  846. }
  847. item.VisaClient = itemClientName;
  848. VisaCNYTotalPirce += item.CNYPrice;
  849. if (!string.IsNullOrEmpty(item.AuditGMDate))
  850. {
  851. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  852. }
  853. }
  854. _geView.GroupVisaFeeViews = groupVisaFeeViews;
  855. _geView.GroupVisaFeeStr = string.Format(@"人民币总费用:{0} CNY", VisaCNYTotalPirce.ConvertToDecimal1().ToString("#.00"));
  856. #endregion
  857. #region 邀请/公务活动 CTable = 81
  858. List<GroupInvitationalFeeView> groupInvitationalFeeViews = new List<GroupInvitationalFeeView>();
  859. string groupInvitationalFeeSql = string.Format(@"Select ioa.Id As IOAId,ioa.DiId As IOADiId,ioa.InviterArea,ioa.Inviter,ioa.InviteTime,
  860. ioa.InviteCost,sd3.Name As InviteCurrency,ioa.SendCost,sd4.Name As SendCurrency,ioa.EventsCost,
  861. sd5.Name As EventsCurrency,ioa.TranslateCost,sd6.Name As TranslateCurrency,ccp.PayMoney,
  862. sd7.Name As PaymentCurrency,ccp.RMBPrice As CNYPrice,(((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice2,ccp.Payee,ccp.AuditGMDate,
  863. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ioa.CreateTime
  864. From Grp_InvitationOfficialActivities ioa
  865. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 81 And ioa.Id = ccp.CId
  866. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  867. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  868. Left Join Sys_SetData sd3 On ioa.InviteCurrency = sd3.Id
  869. Left Join Sys_SetData sd4 On ioa.SendCurrency = sd4.Id
  870. Left Join Sys_SetData sd5 On ioa.EventsCurrency = sd5.Id
  871. Left Join Sys_SetData sd6 On ioa.TranslateCurrency = sd6.Id
  872. Left Join Sys_SetData sd7 On ccp.PaymentCurrency = sd7.Id
  873. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  874. Where ioa.IsDel = 0 And ccp.IsAuditGM = 1 And ioa.Diid = {0} Order By CreateTime", _dto.DiId);
  875. groupInvitationalFeeViews = await _sqlSugar.SqlQueryable<GroupInvitationalFeeView>(groupInvitationalFeeSql).ToListAsync();
  876. #region 邀请/公务活动 - 模拟数据
  877. //if (groupInvitationalFeeViews.Count < 1)
  878. //{
  879. // groupInvitationalFeeViews.Add(new GroupInvitationalFeeView()
  880. // {
  881. // IOAId = 0,
  882. // IOADiId = 2334,
  883. // InviterArea = "模拟数据-邀请方地区",
  884. // Inviter = "模拟数据-邀请方",
  885. // InviteTime = "2023-10-10",
  886. // InviteCost = 100.00M,
  887. // InviteCurrency = "EUR",
  888. // SendCost = 100.00M,
  889. // SendCurrency = "EUR",
  890. // EventsCost = 10000.00M,
  891. // EventsCurrency = "EUR",
  892. // TranslateCost = 300.00M,
  893. // TranslateCurrency = "EUR",
  894. // PayMoney = 10500.00M,
  895. // PaymentCurrency = "EUR",
  896. // CNYPrice = 76765.50M,
  897. // Payee = "模拟数据-收款方",
  898. // AuditGMDate = "2023-12-05",
  899. // OrbitalPrivateTransfer = 1,
  900. // PayWay = "刷卡",
  901. // IsPay = 1,
  902. // Applicant = "刘华举"
  903. // });
  904. // groupInvitationalFeeViews.Add(new GroupInvitationalFeeView()
  905. // {
  906. // IOAId = 0,
  907. // IOADiId = 2334,
  908. // InviterArea = "模拟数据-邀请方地区",
  909. // Inviter = "模拟数据-邀请方",
  910. // InviteTime = "2023-10-10",
  911. // InviteCost = 100.00M,
  912. // InviteCurrency = "EUR",
  913. // SendCost = 100.00M,
  914. // SendCurrency = "EUR",
  915. // EventsCost = 10000.00M,
  916. // EventsCurrency = "EUR",
  917. // TranslateCost = 300.00M,
  918. // TranslateCurrency = "EUR",
  919. // PayMoney = 10500.00M,
  920. // PaymentCurrency = "EUR",
  921. // CNYPrice = 76765.50M,
  922. // Payee = "模拟数据-收款方",
  923. // AuditGMDate = "2023-12-05",
  924. // OrbitalPrivateTransfer = 1,
  925. // PayWay = "刷卡",
  926. // IsPay = 1,
  927. // Applicant = "刘华举"
  928. // });
  929. //}
  930. #endregion
  931. decimal InvitationalCNYTotalPrice = 0.00M;
  932. foreach (var item in groupInvitationalFeeViews)
  933. {
  934. InvitationalCNYTotalPrice += item.CNYPrice2;
  935. if (!string.IsNullOrEmpty(item.AuditGMDate))
  936. {
  937. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  938. }
  939. string currencyRateStr = "";
  940. List<string> currencys = new List<string>();
  941. if (!string.IsNullOrEmpty(item.InviteCurrency)) currencys.Add(item.InviteCurrency);
  942. if (!string.IsNullOrEmpty(item.SendCurrency)) currencys.Add(item.SendCurrency);
  943. if (!string.IsNullOrEmpty(item.EventsCurrency)) currencys.Add(item.EventsCurrency);
  944. if (!string.IsNullOrEmpty(item.TranslateCurrency)) currencys.Add(item.TranslateCurrency);
  945. if (!string.IsNullOrEmpty(item.PaymentCurrency)) currencys.Add(item.PaymentCurrency);
  946. currencyRateStr = await GeneralMethod.PostGroupRateByCTableAndCurrency(teamRateData, 81, currencys);
  947. item.CurrencyRateStr = currencyRateStr;
  948. }
  949. _geView.GroupInvitationalFeeViews = groupInvitationalFeeViews;
  950. _geView.GroupInvitationalFeeStr = string.Format(@"人民币总费用:{0} CNY", InvitationalCNYTotalPrice.ToString("#.00"));
  951. #endregion
  952. #region 保险费用
  953. List<GroupInsuranceFeeView> groupInsuranceFeeViews = new List<GroupInsuranceFeeView>();
  954. string groupInsuranceFeeSql = string.Format(@"Select ic.Id As InsuranceId,ic.Diid As InsuranceDiId,ClientName,ccp.PayMoney,ccp.RMBPrice As CNYPrice,
  955. sd1.Name As PayMoneyCurrency,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  956. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ic.CreateTime
  957. From Grp_Customers ic
  958. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 82 And ic.Id = ccp.CId
  959. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  960. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  961. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  962. Where ic.IsDel = 0 And ccp.IsAuditGM = 1 And ic.DiId = {0} Order By CreateTime", _dto.DiId);
  963. groupInsuranceFeeViews = await _sqlSugar.SqlQueryable<GroupInsuranceFeeView>(groupInsuranceFeeSql).ToListAsync();
  964. decimal InsuranceCNYTotalPrice = 0.00M;
  965. foreach (var item in groupInsuranceFeeViews)
  966. {
  967. InsuranceCNYTotalPrice += item.CNYPrice;
  968. string itemClientName = "";
  969. string insClients = item.ClientName;
  970. if (!string.IsNullOrEmpty(insClients))
  971. {
  972. //System.Text.RegularExpressions.Match m_EnName = Regex.Match(item.ClientName, @"[A-Za-z]+");
  973. //System.Text.RegularExpressions.Match m_ZHName = Regex.Match(item.ClientName, @"[\u4e00-\u9fa5]");
  974. //if (m_EnName.Success || m_ZHName.Success)
  975. //{
  976. // itemClientName = insClients;
  977. // continue;
  978. //}
  979. string[] clientIds = new string[] { };
  980. if (insClients.Contains(','))
  981. {
  982. clientIds = insClients.Split(',');
  983. }
  984. else
  985. {
  986. clientIds = new string[] { insClients };
  987. }
  988. if (clientIds.Length > 0)
  989. {
  990. List<int> output = new List<int>();
  991. foreach (var clientId in clientIds)
  992. {
  993. if (clientId.IsNumeric())
  994. {
  995. output.Add(int.Parse(clientId));
  996. }
  997. }
  998. if (output.Count > 0)
  999. {
  1000. var clients = _clientDatas.Where(it => output.Contains(it.Id)).ToList();
  1001. foreach (var client in clients)
  1002. {
  1003. itemClientName += $"{client.LastName + client.FirstName},";
  1004. }
  1005. if (itemClientName.Length > 0)
  1006. {
  1007. itemClientName = itemClientName.Substring(0, itemClientName.Length - 1);
  1008. }
  1009. }
  1010. else
  1011. {
  1012. itemClientName = insClients;
  1013. }
  1014. }
  1015. }
  1016. item.ClientName = itemClientName;
  1017. if (!string.IsNullOrEmpty(item.AuditGMDate))
  1018. {
  1019. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  1020. }
  1021. }
  1022. _geView.GroupInsuranceFeeViews = groupInsuranceFeeViews;
  1023. _geView.GroupInsuranceFeeStr = string.Format(@"人民币总费用:{0} CNY", InsuranceCNYTotalPrice.ToString("#0.00"));
  1024. #endregion
  1025. #region 其他款项费用 98
  1026. List<GroupDecreaseFeeView> groupDecreaseFeeViews = new List<GroupDecreaseFeeView>();
  1027. string groupDecreaseFeeSql = string.Format(@"Select dp.Id As DPId,dp.DiId As DPDiId,dp.PriceName,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  1028. (((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice,
  1029. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  1030. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,dp.CreateTime
  1031. From Grp_DecreasePayments dp
  1032. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 98 And dp.Id = ccp.CId
  1033. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1034. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1035. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1036. Where dp.IsDel = 0 And ccp.Ctable = 98 And ccp.IsAuditGM = 1 And dp.Diid = {0}
  1037. Order By CreateTime", _dto.DiId);
  1038. groupDecreaseFeeViews = await _sqlSugar.SqlQueryable<GroupDecreaseFeeView>(groupDecreaseFeeSql).ToListAsync();
  1039. #region 保险费用 - 模拟数据
  1040. //if (groupDecreaseFeeViews.Count < 1)
  1041. //{
  1042. // groupDecreaseFeeViews.Add(new GroupDecreaseFeeView()
  1043. // {
  1044. // DPId = 0,
  1045. // DPDiId = 2334,
  1046. // PriceName = "模拟数据-费用名称",
  1047. // PayMoney = 1000.00M,
  1048. // PayMoneyCurrency = "CNY",
  1049. // DayRate = 1.0000M,
  1050. // CNYPrice = 1.0000M,
  1051. // AuditGMDate = "2023-12-10 12:13:00",
  1052. // Payee = "模拟数据-付款方",
  1053. // OrbitalPrivateTransfer = 1,
  1054. // PayWay = "现金",
  1055. // IsPay = 1,
  1056. // Applicant = "刘华举"
  1057. // });
  1058. // groupDecreaseFeeViews.Add(new GroupDecreaseFeeView()
  1059. // {
  1060. // DPId = 0,
  1061. // DPDiId = 2334,
  1062. // PriceName = "模拟数据-费用名称",
  1063. // PayMoney = 1000.00M,
  1064. // PayMoneyCurrency = "CNY",
  1065. // DayRate = 1.0000M,
  1066. // CNYPrice = 1.0000M,
  1067. // AuditGMDate = "2023-12-10 12:13:00",
  1068. // Payee = "模拟数据-付款方",
  1069. // OrbitalPrivateTransfer = 1,
  1070. // PayWay = "现金",
  1071. // IsPay = 1,
  1072. // Applicant = "刘华举"
  1073. // });
  1074. //}
  1075. #endregion
  1076. decimal DecreaseCNYTotalPrice = 0.00M;
  1077. foreach (var item in groupDecreaseFeeViews)
  1078. {
  1079. item.CNYPrice = Convert.ToDecimal(item.CNYPrice.ToString("#0.00"));
  1080. DecreaseCNYTotalPrice += item.CNYPrice;
  1081. if (!string.IsNullOrEmpty(item.AuditGMDate))
  1082. {
  1083. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  1084. }
  1085. }
  1086. _geView.GroupDecreaseFeeViews = groupDecreaseFeeViews;
  1087. _geView.GroupDecreaseFeeStr = string.Format(@"人民币总费用:{0} CNY", DecreaseCNYTotalPrice.ToString("#0.00"));
  1088. #endregion
  1089. _view.GroupExpenditure = _geView;
  1090. #endregion
  1091. /*
  1092. * 团组报表计算方式
  1093. * 当前总支出 = 团组支出.Sum() + 超支费用.Sum()
  1094. * 应收金额 = 应收表.Sum()
  1095. * 已收金额 = 已收表.Sum()
  1096. * 应收利润(应收-支出) = 应收金额 - 收款退还 - 当前总支出
  1097. * 已收利润(已收-支出) = 已收金额 - 收款退还 - 当前总支出
  1098. *
  1099. */
  1100. decimal _totalExpenditure = 0.00M; //总支出
  1101. decimal _amountReceivable = 0.00M; //应收金额
  1102. decimal _amountReceived = 0.00M; //已收金额
  1103. decimal _receivableProfit = 0.00M; //应收利润
  1104. decimal _receivedProfit = 0.00M; //已收利润
  1105. _totalExpenditure = HotelCNYTotalPrice + CTGGRCNYTotalPrice + AirCNYTotalPrice + VisaCNYTotalPirce + InvitationalCNYTotalPrice +
  1106. InsuranceCNYTotalPrice + DecreaseCNYTotalPrice + exTotalAmount;
  1107. _amountReceivable = frTotalAmount;
  1108. _amountReceived = prTotalAmount;
  1109. _receivableProfit = _amountReceivable - promTotalAmount - _totalExpenditure;
  1110. _receivedProfit = _amountReceived - promTotalAmount - _totalExpenditure;
  1111. _view.FeeTotalStr = string.Format(@$"<span>
  1112. <span>当前总支出:{_totalExpenditure.ToString("#0.00")} CNY</span>
  1113. <span style='padding-left:10px;color: Green;'>应收金额:{_amountReceivable.ToString("#0.00")} CNY</span>
  1114. <span style='padding-left:10px;color: Green;'>已收金额:{_amountReceived.ToString("#0.00")} CNY</span>
  1115. <span style='padding-left:10px;color: Green;'>应收利润(应收-支出):{_receivableProfit.ToString("#0.00")} CNY</span>
  1116. <span style='padding-left:10px;color: Green;'>已收利润(已收-支出):{_receivedProfit.ToString("#0.00")} CNY</span>
  1117. </span>");
  1118. return Ok(JsonView(true, "查询成功!", _view));
  1119. }
  1120. else
  1121. {
  1122. return Ok(JsonView(false, "查询成功"));
  1123. }
  1124. }
  1125. #endregion
  1126. #region 报表/折线图统计
  1127. //企业利润-团组利润
  1128. //企业利润-会务利润
  1129. /// <summary>
  1130. /// 企业利润
  1131. /// Details
  1132. /// 待添加权限验证
  1133. /// </summary>
  1134. /// <param name="_dto">团组列表请求dto</param>
  1135. /// <returns></returns>
  1136. [HttpPost("PostCorporateProfit")]
  1137. //[JsonConverter(typeof(DecimalConverter), 2)]
  1138. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1139. public async Task<IActionResult> PostCorporateProfit(PostCorporateProfitDto _dto)
  1140. {
  1141. #region 参数验证
  1142. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  1143. if (_dto.PageId < 1) _dto.PageId = 38; //团组报表页面Id
  1144. if (_dto.Year < 1) return Ok(JsonView(false, "请输入有效的Year参数!"));
  1145. if (_dto.StatisticsType > 2 && _dto.StatisticsType < 1) return Ok(JsonView(false, "请输入有效的StatisticsType参数,1 月份 2 季度"));
  1146. if (_dto.BusinessType > 3 && _dto.BusinessType < 1) return Ok(JsonView(false, "请输入有效的BusinessType参数,1 所有 2 团组 3 会务"));
  1147. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1148. #region 页面操作权限验证
  1149. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  1150. //if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  1151. #endregion
  1152. string sqlWhere = string.Empty;
  1153. //起止时间
  1154. DateTime beginDt = Convert.ToDateTime($"{_dto.Year}-01-01 00:00:00");
  1155. DateTime endDt = Convert.ToDateTime($"{_dto.Year}-12-31 23:59:59");
  1156. sqlWhere = string.Format(@$" Where Isdel = 0 ");
  1157. //业务类型
  1158. List<int> groupTypeId = new List<int>();
  1159. if (_dto.BusinessType == 2) //团组
  1160. {
  1161. groupTypeId.AddRange(new List<int>() {
  1162. 38, // 政府团
  1163. 39, // 企业团
  1164. 40, // 散客团
  1165. 1048 // 高校团
  1166. });
  1167. }
  1168. else if (_dto.BusinessType == 3) //会务
  1169. {
  1170. groupTypeId.AddRange(new List<int>() {
  1171. 102, // 未知
  1172. 248, // 非团组
  1173. 302, // 成都-会务活动
  1174. 691, // 四川-会务活动
  1175. 762, // 四川-赛事项目收入
  1176. 1047 // 成都-赛事项目收入
  1177. });
  1178. }
  1179. if (groupTypeId.Count > 0)
  1180. {
  1181. sqlWhere += string.Format(@$" And TeamDid In ({string.Join(',', groupTypeId)})");
  1182. }
  1183. string sql = string.Format(@$"Select * From Grp_DelegationInfo {sqlWhere}");
  1184. var groupInfos = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).Where(it => it.CreateTime >= beginDt && it.CreateTime <= endDt).ToListAsync();
  1185. if (groupInfos.Count < 1) return Ok(JsonView(false, "暂无相关团组!"));
  1186. List<int> diIds = groupInfos.Select(it => it.Id).ToList();
  1187. List<CorporateProfit> corporateProfits = await CorporateProfit(diIds);
  1188. List<MonthInfo> months = new List<MonthInfo>();
  1189. if (_dto.StatisticsType == 1) //月份
  1190. {
  1191. months = GeneralMethod.GetMonthInfos(Convert.ToInt32(_dto.Year));
  1192. }
  1193. else if (_dto.StatisticsType == 1) //季度
  1194. {
  1195. months = GeneralMethod.GetQuarter(Convert.ToInt32(_dto.Year));
  1196. }
  1197. List<CorporateProfitMonthView> _view = new List<CorporateProfitMonthView>();
  1198. foreach (var item in months)
  1199. {
  1200. DateTime monthBeginDt = Convert.ToDateTime($"{_dto.Year}-{item.Month}-{item.Days.BeginDays} 00:00:00");
  1201. DateTime monthEndDt = Convert.ToDateTime($"{_dto.Year}-{item.Month}-{item.Days.EndDays} 23:59:59");
  1202. var corporateProfit = corporateProfits.Where(it => it.CreateDt >= monthBeginDt && it.CreateDt <= monthEndDt).ToList();
  1203. _view.Add(new CorporateProfitMonthView()
  1204. {
  1205. Month = item.Month,
  1206. Profit = corporateProfit.Sum(it => it.ReceivedProfit),
  1207. GroupInfos = corporateProfit.OrderBy(it => it.CreateDt).ToList()
  1208. });
  1209. }
  1210. return Ok(JsonView(true, "操作成功!", _view));
  1211. #endregion
  1212. }
  1213. /// <summary>
  1214. /// 计算团组利润
  1215. /// </summary>
  1216. /// <param name="diIds"></param>
  1217. /// <returns></returns>
  1218. private async Task<List<CorporateProfit>> CorporateProfit(List<int> diIds)
  1219. {
  1220. List<CorporateProfit> corporateProfits = new List<CorporateProfit>();
  1221. if (diIds.Count < 1)
  1222. {
  1223. return corporateProfits;
  1224. }
  1225. #region 计算团组利润
  1226. /*
  1227. * 团组报表计算方式
  1228. * 当前总支出 = 团组支出.Sum() + 超支费用.Sum()
  1229. * 应收金额 = 应收表.Sum()
  1230. * 已收金额 = 已收表.Sum()
  1231. * 应收利润(应收-支出) = 应收金额 - 收款退还 - 当前总支出
  1232. * 已收利润(已收-支出) = 已收金额 - 收款退还 - 当前总支出
  1233. *
  1234. */
  1235. string diIdStr = string.Join(",", diIds);
  1236. string sql = string.Format(@$"Select * From Grp_DelegationInfo Where Isdel = 0 And Id In ({diIdStr})");
  1237. var groupInfos = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToListAsync();
  1238. #region 费用类型 币种,转账,客户信息
  1239. List<Sys_SetData> _setDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToListAsync();
  1240. var _clientDatas = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync();
  1241. #endregion
  1242. foreach (var _diId in diIds)
  1243. {
  1244. List<ExpenditureInfo> expenditureInfos = new List<ExpenditureInfo>();
  1245. #region 团组收入
  1246. /*
  1247. * 应收报表
  1248. */
  1249. decimal frTotalAmount = 0.00M;//应收总金额
  1250. string _frSql = string.Format(@"Select fr.Id,fr.Diid,fr.PriceName,fr.Price,fr.Count,fr.Unit,fr.Currency,
  1251. sd.Name As CurrencyCode,sd.Remark As CurrencyName,fr.Rate,fr.ItemSumPrice,fr.CreateTime
  1252. From Fin_ForeignReceivables fr
  1253. Left Join Sys_SetData sd On fr.Currency = sd.Id
  1254. Where fr.IsDel = 0 And fr.Diid = {0} Order By CreateTime", _diId);
  1255. List<Gsd_ForeignReceivablesView> _frViews = await _sqlSugar.SqlQueryable<Gsd_ForeignReceivablesView>(_frSql).ToListAsync();
  1256. frTotalAmount = _frViews.Sum(it => it.ItemSumPrice);
  1257. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "应收项", Amount = frTotalAmount });
  1258. /*
  1259. * 已收报表
  1260. */
  1261. decimal prTotalAmount = 0.00M;//已收总金额
  1262. string _prSql = string.Format(@"Select pr.Id,pr.Diid,pr.SectionTime As SectionTimeDt,pr.Price,pr.Currency,
  1263. sd1.Name As CurrencyCode,sd1.Remark As CurrencyName,pr.Client,
  1264. pr.ReceivablesType,sd2.Name As ReceivablesTypeName,pr.Remark,pr.CreateTime
  1265. From Fin_ProceedsReceived pr
  1266. Left Join Sys_SetData sd1 On pr.Currency = sd1.Id
  1267. Left Join Sys_SetData sd2 On pr.ReceivablesType = sd2.Id
  1268. Where pr.IsDel = 0 and pr.Diid = {0} Order By CreateTime", _diId);
  1269. List<Gsd_ProceedsReceivedView> _prViews = await _sqlSugar.SqlQueryable<Gsd_ProceedsReceivedView>(_prSql).ToListAsync();
  1270. prTotalAmount = _prViews.Sum(it => it.Price);
  1271. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "已收项", Amount = prTotalAmount });
  1272. /*
  1273. * 超支费用
  1274. */
  1275. decimal exTotalAmount = 0.00M;
  1276. string _ecSql = string.Format(@"Select gec.Id As GECId,gec.DiId As GECDiId,gec.PriceName,ccp.PayMoney,sd1.Name As PaymentCurrency,
  1277. ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  1278. sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant,gec.CreateTime
  1279. From OA2023DB.dbo.Fin_GroupExtraCost gec
  1280. Left Join Grp_CreditCardPayment ccp On gec.Id = ccp.CId
  1281. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1282. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1283. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  1284. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1285. Where ccp.IsDel = 0 And ccp.CTable = 1015 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ccp.DiId = {0} Order By CreateTime", _diId);
  1286. List<Gsd_ExtraCostsView> _ExtraCostsViews = await _sqlSugar.SqlQueryable<Gsd_ExtraCostsView>(_ecSql).ToListAsync();
  1287. exTotalAmount = _ExtraCostsViews.Sum(it => it.CNYPrice);
  1288. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "超支费用", Amount = exTotalAmount });
  1289. /*
  1290. * 收款退还
  1291. */
  1292. decimal promTotalAmount = 0.00M;// 收款退还总金额
  1293. List<Gsd_PaymentRefundAndOtherMoneyView> _promView = new List<Gsd_PaymentRefundAndOtherMoneyView>();
  1294. //删除了 And prom.PriceType = 1
  1295. string _ropSql = string.Format(@"Select u.CnName As Appliction,prom.Id As PrId,prom.DiId As PrDiId,prom.Price As PrPrice,
  1296. prom.PriceName AS PrPriceName,prom.CurrencyId As PrCurrencyId,
  1297. prom.PayType As PrPayType,prom.PriceType As PrPriceType,ccp.*,prom.CreateTime As PrCreateTime
  1298. From Fin_PaymentRefundAndOtherMoney prom
  1299. Left Join Grp_CreditCardPayment ccp On prom.DiId = ccp.DIId And prom.Id = ccp.CId
  1300. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1301. Where prom.IsDel = 0 And prom.PayType = 1 And ccp.CTable = 285
  1302. And ccp.IsAuditGM = 1 And ccp.IsPay = 1
  1303. And prom.DiId = {0} Order By PrCreateTime", _diId);
  1304. var _promDatas = await _sqlSugar.SqlQueryable<Gsd_PaymentRefundAndOtherMoneyDataSource1View>(_ropSql).ToListAsync();
  1305. foreach (var ropItem in _promDatas)
  1306. {
  1307. string thisCueencyCode = "Unknown";
  1308. string thisCueencyName = "Unknown";
  1309. var currency = _setDatas.Where(it => it.Id == ropItem.PaymentCurrency).FirstOrDefault();
  1310. if (currency != null)
  1311. {
  1312. thisCueencyCode = currency.Name;
  1313. thisCueencyName = currency.Remark;
  1314. }
  1315. string orbitalPrivateTransferStr = "Unknown";
  1316. var orbitalPrivateTransfer = _setDatas.Where(it => it.Id == ropItem.OrbitalPrivateTransfer).FirstOrDefault();
  1317. if (orbitalPrivateTransfer != null)
  1318. {
  1319. orbitalPrivateTransferStr = orbitalPrivateTransfer.Name;
  1320. }
  1321. string payStr = "Unknown";
  1322. var pay = _setDatas.Where(it => it.Id == ropItem.PayDId).FirstOrDefault();
  1323. if (pay != null)
  1324. {
  1325. payStr = pay.Name;
  1326. }
  1327. Gsd_PaymentRefundAndOtherMoneyView gsd_PaymentRefund = new Gsd_PaymentRefundAndOtherMoneyView()
  1328. {
  1329. Id = ropItem.Id,
  1330. DiId = ropItem.DIId,
  1331. PriceName = ropItem.PrPriceName,
  1332. PayCurrencyCode = thisCueencyCode,
  1333. PayCurrencyName = thisCueencyName,
  1334. Price = ropItem.PrPrice,
  1335. CNYPrice = ropItem.RMBPrice,
  1336. ThisRate = ropItem.DayRate,
  1337. Payee = ropItem.Payee,
  1338. PayTime = ropItem.AuditGMDate,
  1339. OrbitalPrivateTransfer = ropItem.OrbitalPrivateTransfer,
  1340. PayType = payStr,
  1341. IsPay = ropItem.IsPay,
  1342. Applicant = ropItem.Appliction
  1343. };
  1344. _promView.Add(gsd_PaymentRefund);
  1345. }
  1346. promTotalAmount = _promView.Sum(it => it.CNYPrice);
  1347. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "收款退还", Amount = promTotalAmount });
  1348. #endregion
  1349. #region 团组支出
  1350. GroupExpenditureView _geView = new GroupExpenditureView();
  1351. #region 酒店预定费用
  1352. List<GroupHotelFeeView> groupHotelFeeViews = new List<GroupHotelFeeView>();
  1353. string hotelFeeSql = string.Format(@"Select hr.Id As HrId,hr.DiId As HrDiId,hr.City,hr.HotelName,hr.CheckInDate,hr.CheckOutDate,
  1354. sd1.Name As PaymentCurrency,hr.SingleRoomPrice,hr.SingleRoomCount,hr.DoubleRoomPrice,
  1355. hr.DoubleRoomCount,hr.SuiteRoomPrice,hr.SuiteRoomCount,hr.OtherRoomPrice,hr.OtherRoomCount,
  1356. hr.BreakfastPrice,sd4.Name As BreakfastCurrency,hr.Isoppay,hr.GovernmentRent,
  1357. sd5.Name As GovernmentRentCurrency,hr.CityTax,sd6.Name As CityTaxCurrency,
  1358. ccp.PayMoney,ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.OrbitalPrivateTransfer,
  1359. sd2.Name As PayWay,sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant
  1360. From Grp_HotelReservations hr
  1361. Left Join Grp_CreditCardPayment ccp On hr.Id = ccp.CId
  1362. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1363. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1364. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  1365. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1366. Left Join Sys_SetData sd4 On hr.BreakfastCurrency = sd4.Id
  1367. Left Join Sys_SetData sd5 On hr.GovernmentRentCurrency = sd5.Id
  1368. Left Join Sys_SetData sd6 On hr.CityTaxCurrency = sd6.Id
  1369. Where hr.IsDel = 0 And ccp.IsDel = 0 And ccp.CTable = 76 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And hr.DiId = {0}
  1370. Order By CheckInDate Asc", _diId);
  1371. groupHotelFeeViews = await _sqlSugar.SqlQueryable<GroupHotelFeeView>(hotelFeeSql).ToListAsync();
  1372. decimal HotelCNYTotalPrice = groupHotelFeeViews.Sum(it => it.CNYPrice);
  1373. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "酒店预定", Amount = HotelCNYTotalPrice });
  1374. #endregion
  1375. #region 地接费用
  1376. List<GroupCTGGRFeeView> groupCTGGRFeeViews = new List<GroupCTGGRFeeView>();
  1377. string CTGGRFeeSql = string.Format(@"Select ctggr.Id As CTGGRId,ctggr.DiId As CTGGRDiId,ctggr.Area,ctggrc.*,ctggrc.Price As PayMoney,
  1378. sd2.name As PaymentCurrency,ccp.PayPercentage,
  1379. (ctggrc.Price / (ccp.PayPercentage / 100)) As AmountPaid,
  1380. (ctggrc.Price / (ccp.PayPercentage / 100) - ctggrc.Price) As BalancePayment,
  1381. ccp.DayRate,(ctggrc.Price * ccp.DayRate) As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  1382. ccp.OrbitalPrivateTransfer,sd1.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ctggr.CreateTime
  1383. From Grp_CarTouristGuideGroundReservations ctggr
  1384. Left Join ( Select cggrc.CTGGRId,sd1.Name As PriceName,cggrc.Price,sd2.Name As PriceCurrency,
  1385. cggrc.PriceContent
  1386. From Grp_CarTouristGuideGroundReservationsContent cggrc
  1387. Left Join Sys_SetData sd1 On cggrc.SId = sd1.Id
  1388. Left Join Sys_SetData sd2 On cggrc.Currency = sd2.Id
  1389. Where cggrc.ISdel = 0 And cggrc.Price != 0.00
  1390. ) ctggrc On ctggr.Id = ctggrc.CTGGRId
  1391. Left Join Grp_CreditCardPayment ccp On ccp.IsDel = 0 And ccp.CTable = 79 And ctggr.Id = ccp.CId
  1392. Left Join Sys_SetData sd1 On ccp.PayDId = sd1.Id
  1393. Left Join Sys_SetData sd2 On ccp.PaymentCurrency = sd2.Id
  1394. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1395. Where ctggr.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ctggr.DiId = {0}
  1396. Order By CreateTime", _diId);
  1397. groupCTGGRFeeViews = await _sqlSugar.SqlQueryable<GroupCTGGRFeeView>(CTGGRFeeSql).ToListAsync();
  1398. decimal CTGGRCNYTotalPrice = groupCTGGRFeeViews.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  1399. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "地接", Amount = CTGGRCNYTotalPrice });
  1400. #endregion
  1401. #region 机票预订费用
  1402. List<GroupAirFeeView> groupAirFeeViews = new List<GroupAirFeeView>();
  1403. string groupAirFeeSql = string.Format(@"Select atr.Id As AirId,atr.DIId As AirDiId,atr.FlightsCode,atr.FlightsCity,sd4.Name As AirTypeName,
  1404. atr.FlightsDate,atr.FlightsTime,atr.ClientName,atr.ClientNum,ccp.PayMoney,
  1405. sd1.Name As PayMoneyCurrency,ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.AuditGMDate,
  1406. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant,atr.CreateTime
  1407. From Grp_AirTicketReservations atr
  1408. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 85 And atr.Id = ccp.CId
  1409. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1410. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1411. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  1412. Left Join Sys_SetData sd4 On atr.CType = sd4.Id
  1413. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1414. Where atr.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And atr.DiId = {0} Order By CreateTime", _diId);
  1415. groupAirFeeViews = await _sqlSugar.SqlQueryable<GroupAirFeeView>(groupAirFeeSql).ToListAsync();
  1416. decimal AirCNYTotalPrice = groupAirFeeViews.Sum(it => it.CNYPrice);
  1417. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "机票预订", Amount = AirCNYTotalPrice });
  1418. #endregion
  1419. #region 签证费用
  1420. List<GroupVisaFeeView> groupVisaFeeViews = new List<GroupVisaFeeView>();
  1421. string groupVisaFeeSql = string.Format(@"Select vi.Id As VisaId,vi.DIId As VisaDiId,vi.VisaClient,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  1422. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  1423. sd3.Name As CardTypeName,ccp.IsPay,u.CnName As Applicant,vi.CreateTime
  1424. From Grp_VisaInfo vi
  1425. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 80 And vi.Id = ccp.CId
  1426. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1427. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1428. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  1429. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1430. Where vi.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And vi.DIId = {0} Order By CreateTime", _diId);
  1431. groupVisaFeeViews = await _sqlSugar.SqlQueryable<GroupVisaFeeView>(groupVisaFeeSql).ToListAsync();
  1432. decimal VisaCNYTotalPirce = groupVisaFeeViews.Sum(it => it.PayMoney);
  1433. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "签证", Amount = VisaCNYTotalPirce });
  1434. #endregion
  1435. #region 邀请/公务活动 CTable = 81
  1436. List<GroupInvitationalFeeView> groupInvitationalFeeViews = new List<GroupInvitationalFeeView>();
  1437. string groupInvitationalFeeSql = string.Format(@"Select ioa.Id As IOAId,ioa.DiId As IOADiId,ioa.InviterArea,ioa.Inviter,ioa.InviteTime,
  1438. ioa.InviteCost,sd3.Name As InviteCurrency,ioa.SendCost,sd4.Name As SendCurrency,ioa.EventsCost,
  1439. sd5.Name As EventsCurrency,ioa.TranslateCost,sd6.Name As TranslateCurrency,ccp.PayMoney,
  1440. sd7.Name As PaymentCurrency,ccp.RMBPrice As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  1441. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ioa.CreateTime
  1442. From Grp_InvitationOfficialActivities ioa
  1443. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 81 And ioa.Id = ccp.CId
  1444. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1445. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1446. Left Join Sys_SetData sd3 On ioa.InviteCurrency = sd3.Id
  1447. Left Join Sys_SetData sd4 On ioa.SendCurrency = sd4.Id
  1448. Left Join Sys_SetData sd5 On ioa.EventsCurrency = sd5.Id
  1449. Left Join Sys_SetData sd6 On ioa.TranslateCurrency = sd6.Id
  1450. Left Join Sys_SetData sd7 On ccp.PaymentCurrency = sd7.Id
  1451. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1452. Where ioa.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ioa.Diid = {0} Order By CreateTime", _diId);
  1453. groupInvitationalFeeViews = await _sqlSugar.SqlQueryable<GroupInvitationalFeeView>(groupInvitationalFeeSql).ToListAsync();
  1454. decimal InvitationalCNYTotalPrice = groupInvitationalFeeViews.Sum(it => it.CNYPrice);
  1455. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "邀请/公务活动", Amount = InvitationalCNYTotalPrice });
  1456. #endregion
  1457. #region 保险费用
  1458. List<GroupInsuranceFeeView> groupInsuranceFeeViews = new List<GroupInsuranceFeeView>();
  1459. string groupInsuranceFeeSql = string.Format(@"Select ic.Id As InsuranceId,ic.Diid As InsuranceDiId,ClientName,ccp.PayMoney,ccp.RMBPrice As CNYPrice,
  1460. sd1.Name As PayMoneyCurrency,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  1461. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ic.CreateTime
  1462. From Grp_Customers ic
  1463. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 82 And ic.Id = ccp.CId
  1464. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1465. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1466. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1467. Where ic.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ic.DiId = {0} Order By CreateTime", _diId);
  1468. groupInsuranceFeeViews = await _sqlSugar.SqlQueryable<GroupInsuranceFeeView>(groupInsuranceFeeSql).ToListAsync();
  1469. decimal InsuranceCNYTotalPrice = groupInsuranceFeeViews.Sum(it => it.CNYPrice);
  1470. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "保险费用", Amount = InsuranceCNYTotalPrice });
  1471. #endregion
  1472. #region 其他款项费用 98
  1473. List<GroupDecreaseFeeView> groupDecreaseFeeViews = new List<GroupDecreaseFeeView>();
  1474. string groupDecreaseFeeSql = string.Format(@"Select dp.Id As DPId,dp.DiId As DPDiId,dp.PriceName,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  1475. (((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice,
  1476. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  1477. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,dp.CreateTime
  1478. From Grp_DecreasePayments dp
  1479. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 98 And dp.Id = ccp.CId
  1480. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1481. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1482. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1483. Where dp.IsDel = 0 And ccp.Ctable = 98 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And dp.Diid = {0}
  1484. Order By CreateTime", _diId);
  1485. groupDecreaseFeeViews = await _sqlSugar.SqlQueryable<GroupDecreaseFeeView>(groupDecreaseFeeSql).ToListAsync();
  1486. decimal DecreaseCNYTotalPrice = groupDecreaseFeeViews.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  1487. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "其他款项", Amount = DecreaseCNYTotalPrice });
  1488. #endregion
  1489. #endregion
  1490. /*
  1491. * 团组报表计算方式
  1492. * 当前总支出 = 团组支出.Sum() + 超支费用.Sum()
  1493. * 应收金额 = 应收表.Sum()
  1494. * 已收金额 = 已收表.Sum()
  1495. * 应收利润(应收-支出) = 应收金额 - 收款退还 - 当前总支出
  1496. * 已收利润(已收-支出) = 已收金额 - 收款退还 - 当前总支出
  1497. *
  1498. */
  1499. decimal _totalExpenditure = 0.00M; //总支出
  1500. decimal _amountReceivable = 0.00M; //应收金额
  1501. decimal _amountReceived = 0.00M; //已收金额
  1502. decimal _receivableProfit = 0.00M; //应收利润
  1503. decimal _receivedProfit = 0.00M; //已收利润
  1504. _totalExpenditure = HotelCNYTotalPrice + CTGGRCNYTotalPrice + AirCNYTotalPrice + VisaCNYTotalPirce + InvitationalCNYTotalPrice +
  1505. InsuranceCNYTotalPrice + DecreaseCNYTotalPrice + exTotalAmount;
  1506. _amountReceivable = frTotalAmount;
  1507. _amountReceived = prTotalAmount;
  1508. _receivableProfit = _amountReceivable - promTotalAmount - _totalExpenditure;
  1509. _receivedProfit = _amountReceived - promTotalAmount - _totalExpenditure;
  1510. var groupInfo = groupInfos.Find(it => it.Id == _diId);
  1511. corporateProfits.Add(new CorporateProfit()
  1512. {
  1513. DiId = _diId,
  1514. TeamName = groupInfo?.TeamName ?? "Unkwnon",
  1515. CreateDt = Convert.ToDateTime(groupInfo?.CreateTime),
  1516. TotalExpenditure = _totalExpenditure,
  1517. ExpenditureItem = expenditureInfos,
  1518. AmountReceivable = _amountReceivable,
  1519. AmountReceived = _amountReceived,
  1520. ReceivableProfit = _receivableProfit,
  1521. ReceivedProfit = _receivedProfit,
  1522. });
  1523. }
  1524. #endregion
  1525. return corporateProfits;
  1526. }
  1527. //未来预测-地区接团/出团量
  1528. //未来预测-地区酒店预订量
  1529. //未来预测-地区机票预订量
  1530. //未来预测-地区车辆预订量
  1531. /// <summary>
  1532. /// (国家/城市)地区预订数量(团,酒店,机票,车辆)
  1533. /// Details
  1534. /// 待添加权限验证
  1535. /// </summary>
  1536. /// <param name="_dto">团组列表请求dto</param>
  1537. /// <returns></returns>
  1538. [HttpPost("PostRegionalBookingsNumber")]
  1539. //[JsonConverter(typeof(DecimalConverter), 2)]
  1540. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1541. public async Task<IActionResult> PostRegionalBookingsNumber(PostRegionalBookingsNumberDto _dto)
  1542. {
  1543. #region 参数验证
  1544. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  1545. //if (_dto.PageId < 1) _dto.PageId = 38; //团组报表页面Id
  1546. if (_dto.Type > 1 && _dto.Type > 5) return Ok(JsonView(false, "请输入有效的Type参数,1 团 2 酒店 3 机票 4 车辆"));
  1547. if (_dto.Year < 1) return Ok(JsonView(false, "请输入有效的Year参数!"));
  1548. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1549. #region 页面操作权限验证
  1550. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  1551. //if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  1552. #endregion
  1553. string sqlWhere = string.Empty;
  1554. //起止时间
  1555. DateTime beginDt = Convert.ToDateTime($"{_dto.Year}-01-01 00:00:00");
  1556. DateTime endDt = Convert.ToDateTime($"{_dto.Year}-12-31 23:59:59");
  1557. sqlWhere = string.Format(@$" Where Isdel = 0 ");
  1558. string sql = string.Format(@$"Select * From Grp_DelegationInfo {sqlWhere}");
  1559. var groupInfos = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).Where(it => it.CreateTime >= beginDt && it.CreateTime <= endDt).ToListAsync();
  1560. if (groupInfos.Count < 1) return Ok(JsonView(false, "暂无相关团组!"));
  1561. List<GroupTypeNumberInfo> datas = new List<GroupTypeNumberInfo>();
  1562. foreach (var item in groupInfos)
  1563. {
  1564. var data = await GroupBookingsNumber(_dto.Type, item);
  1565. if (data.TypeItem.Count > 0)
  1566. {
  1567. datas.Add(data);
  1568. }
  1569. }
  1570. //类型处理
  1571. if (_dto.Type == 1)//接团
  1572. {
  1573. List<GroupBookingNumberView> views = new List<GroupBookingNumberView>();
  1574. dynamic groupData = null;
  1575. foreach (var item in datas)
  1576. {
  1577. if (item.TypeItem.Count > 0)
  1578. {
  1579. foreach (var item1 in item.TypeItem)
  1580. {
  1581. if (item1.RegionItem.Count > 0)
  1582. {
  1583. GroupInfo groupInfo = new GroupInfo()
  1584. {
  1585. DiId = item.DiId,
  1586. TeamName = item.GroupName,
  1587. CreateTime = groupInfos.Find(it => it.Id == item.DiId)?.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") ?? "Unknown",
  1588. ClientUnit = groupInfos.Find(it => it.Id == item.DiId)?.ClientUnit ?? "Unknown",
  1589. Principal = groupInfos.Find(it => it.Id == item.DiId)?.ClientName ?? "Unknown",
  1590. };
  1591. views.Add(new GroupBookingNumberView() { Name = item1.RegionItem[0].Name, Number = item1.RegionItem[0].Number, GroupItem = new List<GroupInfo>() { groupInfo } });
  1592. }
  1593. }
  1594. }
  1595. }
  1596. var viewsGroup = views.GroupBy(it => it.Name);
  1597. List<GroupBookingNumberView> _view = new List<GroupBookingNumberView>();
  1598. foreach (var item in viewsGroup)
  1599. {
  1600. List<GroupInfo> infos = new List<GroupInfo>();
  1601. foreach (var item1 in item)
  1602. {
  1603. infos.AddRange(item1.GroupItem);
  1604. }
  1605. infos = infos.OrderByDescending(it => it.CreateTime).ToList(); //
  1606. _view.Add(new GroupBookingNumberView() { Name = item.Key, Number = item.Count(), GroupItem = infos });
  1607. }
  1608. _view = _view.OrderByDescending(it => it.Number).Take(10).ToList();
  1609. return Ok(JsonView(true, "操作成功!", _view, _view.Count));
  1610. }
  1611. else if (_dto.Type == 2)
  1612. {
  1613. List<HotelBookingNumberView> views = new List<HotelBookingNumberView>();
  1614. foreach (var item in datas)
  1615. {
  1616. if (item.TypeItem.Count > 0)
  1617. {
  1618. foreach (var item1 in item.TypeItem)
  1619. {
  1620. if (item1.RegionItem.Count > 0)
  1621. {
  1622. foreach (var item2 in item1.RegionItem)
  1623. {
  1624. GroupInfo groupInfo = new GroupInfo()
  1625. {
  1626. DiId = item.DiId,
  1627. TeamName = item.GroupName,
  1628. CreateTime = groupInfos.Find(it => it.Id == item.DiId)?.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") ?? "Unknown",
  1629. ClientUnit = groupInfos.Find(it => it.Id == item.DiId)?.ClientUnit ?? "Unknown",
  1630. Principal = groupInfos.Find(it => it.Id == item.DiId)?.ClientName ?? "Unknown",
  1631. };
  1632. List<HotelInfo> hotels = new List<HotelInfo>();
  1633. foreach (var item3 in item2.Data)
  1634. {
  1635. StatisticsHotelInfo statisticsHotelInfos = JsonConvert.DeserializeObject<StatisticsHotelInfo>(JsonConvert.SerializeObject(item3));
  1636. HotelInfo hotelInfo = new HotelInfo()
  1637. {
  1638. HotelName = statisticsHotelInfos.HotelName,
  1639. SingleRoomNum = statisticsHotelInfos.SingleRoomNum,
  1640. DoubleRoomNum = statisticsHotelInfos.DoubleRoomNum,
  1641. SuiteRoomNum = statisticsHotelInfos.SuiteRoomNum,
  1642. OtherRoomNum = statisticsHotelInfos.OtherRoomNum,
  1643. GroupInfo = groupInfo
  1644. };
  1645. hotels.Add(hotelInfo);
  1646. }
  1647. views.Add(new HotelBookingNumberView() { Name = item1.RegionItem[0].Name, Number = item1.RegionItem[0].Number, HotelItem = hotels });
  1648. }
  1649. }
  1650. }
  1651. }
  1652. }
  1653. var viewsGroup = views.GroupBy(it => it.Name);
  1654. List<HotelBookingNumberView> _view = new List<HotelBookingNumberView>();
  1655. foreach (var item in viewsGroup)
  1656. {
  1657. List<HotelInfo> infos = new List<HotelInfo>();
  1658. foreach (var item1 in item)
  1659. {
  1660. infos.AddRange(item1.HotelItem);
  1661. }
  1662. _view.Add(new HotelBookingNumberView() { Name = item.Key, Number = item.Count(), HotelItem = infos });
  1663. }
  1664. _view = _view.OrderByDescending(it => it.Number).Take(10).ToList();
  1665. return Ok(JsonView(true, "操作成功!", views, views.Count));
  1666. }
  1667. return Ok(JsonView(false, "操作失败!"));
  1668. #endregion
  1669. }
  1670. /// <summary>
  1671. /// 计算团组ALLType预订数量
  1672. /// </summary>
  1673. /// <param name="diIds"></param>
  1674. /// <returns></returns>
  1675. private async Task<GroupTypeNumberInfo> GroupBookingsNumber(int type, Grp_DelegationInfo info)
  1676. {
  1677. GroupTypeNumberInfo _view = new GroupTypeNumberInfo();
  1678. if (info == null)
  1679. {
  1680. return _view;
  1681. }
  1682. _view.DiId = info.Id;
  1683. _view.GroupName = info.TeamName;
  1684. List<TypeInfo> _types = new List<TypeInfo>();
  1685. #region 计算团组ALLType预订数量
  1686. if (type == 1)
  1687. {
  1688. //接团 客户集团所在地区
  1689. string group_region = string.Empty;
  1690. int group_number = 0;
  1691. if (!string.IsNullOrEmpty(info.ClientUnit))
  1692. {
  1693. var _NewClientData = await _sqlSugar.Queryable<Crm_NewClientData>().Where(it => it.IsDel == 0 && it.Client.Equals(info.ClientUnit)).FirstAsync();
  1694. if (_NewClientData != null)
  1695. {
  1696. var regionInfo = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == _NewClientData.Lvlid).FirstAsync();
  1697. if (regionInfo != null)
  1698. {
  1699. group_region = regionInfo.Name.Replace("级", "");
  1700. group_number++;
  1701. }
  1702. }
  1703. }
  1704. if (group_number > 0)
  1705. {
  1706. _types.Add(new TypeInfo() { Id = 1, RegionItem = new List<RegionInfo>() { new RegionInfo() { Name = group_region, Number = group_number } } });
  1707. }
  1708. }
  1709. else if (type == 2)
  1710. {
  1711. //酒店
  1712. var hotelInfos = await _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && it.DiId == info.Id).ToListAsync();
  1713. if (hotelInfos.Count > 0)
  1714. {
  1715. List<RegionInfo> hotelRegions = new List<RegionInfo>();
  1716. foreach (var item in hotelInfos)
  1717. {
  1718. var hotelNumberInfo = new StatisticsHotelInfo()
  1719. {
  1720. HotelName = item.HotelName,
  1721. SingleRoomNum = item.SingleRoomCount,
  1722. DoubleRoomNum = item.DoubleRoomCount,
  1723. SuiteRoomNum = item.SuiteRoomCount,
  1724. OtherRoomNum = item.OtherRoomCount,
  1725. };
  1726. int hotelRoomTotal = item.SingleRoomCount + item.DoubleRoomCount + item.SuiteRoomCount + item.OtherRoomCount;
  1727. if (hotelRegions.Select(it => it.Name).ToList().Contains(item.City))
  1728. {
  1729. RegionInfo hotelRegion = hotelRegions.Find(it => it.Name.Equals(item.City));
  1730. if (hotelRegion != null)
  1731. {
  1732. hotelRegions.Remove(hotelRegion);
  1733. if (hotelRegion.Data.Count > 0)
  1734. {
  1735. hotelRegion.Data.Add(hotelNumberInfo);
  1736. }
  1737. hotelRegion.Number += hotelRoomTotal;
  1738. hotelRegions.Add(hotelRegion);
  1739. }
  1740. }
  1741. else
  1742. {
  1743. hotelRegions.Add(new RegionInfo() { Name = item.City, Number = hotelRoomTotal, Data = new List<dynamic>() { hotelNumberInfo } });
  1744. }
  1745. }
  1746. _types.Add(new TypeInfo() { Id = 2, RegionItem = hotelRegions });
  1747. }
  1748. }
  1749. else if (type == 3)
  1750. {
  1751. //机票
  1752. var airTicketInfos = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  1753. .LeftJoin<Grp_CreditCardPayment>((atr, ccp) => atr.Id == ccp.CId && ccp.IsPay == 1)
  1754. .LeftJoin<Sys_SetData>((atr, ccp, sd) => atr.CType == sd.Id)
  1755. .Where((atr, ccp, sd) => atr.IsDel == 0 && atr.DIId == info.Id)
  1756. .Select((atr, ccp, sd) => new { atr.ClientNum, atr.CType, ccp.Payee, AirType = sd.Name })
  1757. .ToListAsync();
  1758. if (airTicketInfos.Count > 0)
  1759. {
  1760. List<RegionInfo> airTicketRegions = new List<RegionInfo>();
  1761. foreach (var item in airTicketInfos)
  1762. {
  1763. var ticketClass = new
  1764. {
  1765. TiketClass = item.AirType,
  1766. Number = item.ClientNum
  1767. };
  1768. if (airTicketRegions.Select(it => it.Name).ToList().Contains(item.Payee))
  1769. {
  1770. RegionInfo airTicketRegion = airTicketRegions.Find(it => it.Name.Equals(item.Payee));
  1771. if (airTicketRegion != null)
  1772. {
  1773. airTicketRegions.Remove(airTicketRegion);
  1774. if (airTicketRegion.Data.Count > 0)
  1775. {
  1776. airTicketRegion.Data.Add(ticketClass);
  1777. }
  1778. airTicketRegion.Number += item.ClientNum;
  1779. airTicketRegions.Add(airTicketRegion);
  1780. }
  1781. }
  1782. else
  1783. {
  1784. airTicketRegions.Add(new RegionInfo() { Name = item.Payee, Number = item.ClientNum, Data = new List<dynamic>() { ticketClass } });
  1785. }
  1786. }
  1787. _types.Add(new TypeInfo() { Id = 3, RegionItem = airTicketRegions });
  1788. }
  1789. }
  1790. else if (type == 4)
  1791. {
  1792. //车辆
  1793. var opInfos = await _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(it => it.IsDel == 0 && it.DiId == info.Id).ToListAsync();
  1794. var opContentInfos = await _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(it => it.IsDel == 0 && it.DiId == info.Id).ToListAsync();
  1795. if (opInfos.Count > 0)
  1796. {
  1797. List<RegionInfo> opRegions = new List<RegionInfo>();
  1798. foreach (var item in opInfos)
  1799. {
  1800. int carNum = 0;
  1801. var opContentInfo = opContentInfos.Where(it => it.CTGGRId == item.Id && it.SId == 91).ToList();
  1802. if (opContentInfo.Count > 0)
  1803. {
  1804. foreach (var item1 in opContentInfo)
  1805. {
  1806. if (item1.Price > 0 && item1.Count > 0)
  1807. {
  1808. carNum += item1.Count;
  1809. }
  1810. }
  1811. }
  1812. if (carNum > 0)
  1813. {
  1814. var opData = new
  1815. {
  1816. ServiceCompany = item.ServiceCompany,
  1817. BusName = item.BusName,
  1818. Numbuer = carNum
  1819. };
  1820. if (opRegions.Select(it => it.Name).ToList().Contains(item.Area))
  1821. {
  1822. RegionInfo opRegion = opRegions.Find(it => it.Name.Equals(item.Area));
  1823. if (opRegion != null)
  1824. {
  1825. opRegions.Remove(opRegion);
  1826. if (opRegion.Data.Count > 0)
  1827. {
  1828. opRegion.Data.Add(opData);
  1829. }
  1830. opRegion.Number += carNum;
  1831. opRegions.Add(opRegion);
  1832. }
  1833. }
  1834. else
  1835. {
  1836. opRegions.Add(new RegionInfo() { Name = item.Area, Number = carNum, Data = new List<dynamic>() { opData } });
  1837. }
  1838. }
  1839. }
  1840. _types.Add(new TypeInfo() { Id = 4, RegionItem = opRegions });
  1841. }
  1842. }
  1843. #endregion
  1844. _view.TypeItem = _types;
  1845. return _view;
  1846. }
  1847. #endregion
  1848. #region 市场部销售额
  1849. /// <summary>
  1850. /// 市场部销售额
  1851. /// Init 基础数据(公司/人员/年份/季度/月份)
  1852. /// </summary>
  1853. /// <param name="_dto">市场部销售额请求dto</param>
  1854. /// <returns></returns>
  1855. [HttpPost("PostMarketingSalesInitData")]
  1856. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1857. public async Task<IActionResult> PostMarketingSalesInitData(MarketingSalesInitDataDto _dto)
  1858. {
  1859. #region 参数验证
  1860. MarketingSalesInitDataDtoFoalidator validationRules = new MarketingSalesInitDataDtoFoalidator();
  1861. var validResult = await validationRules.ValidateAsync(_dto);
  1862. if (!validResult.IsValid)
  1863. {
  1864. var errors = new StringBuilder();
  1865. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  1866. return Ok(JsonView(false, errors.ToString()));
  1867. }
  1868. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1869. #region 页面操作权限验证
  1870. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  1871. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  1872. #endregion
  1873. var companyData = _sqlSugar.Queryable<Sys_Company>().Where(it => it.IsDel == 0)
  1874. .Select(it => new { id = it.Id, name = it.CompanyName })
  1875. .ToList();
  1876. List<int> companyIds = companyData.Select(it => it.id).ToList();
  1877. List<int> pickGroupUserIds = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0)
  1878. .Select(it => it.JietuanOperator )
  1879. .ToList();
  1880. //var jobData = _sqlSugar.Queryable<Sys_JobPost>().Where(it => it.IsDel == 0 && companyIds.Contains(it.CompanyId) && (it.JobName.Contains("经理") || it.JobName.Contains("主管")))
  1881. // .Select(it => new { it.Id, it.CompanyId, it.DepId, it.JobName })
  1882. // .ToList();
  1883. //List<int> jobIds = jobData.Select(it => it.Id).ToList();
  1884. //(depIds.Contains(it.DepId) || jobIds.Contains(it.JobPostId)
  1885. //userId = 21
  1886. var userData = _sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && (pickGroupUserIds.Contains(it.Id) || it.Id == 21))
  1887. .Select(it => new { id = it.Id, companyId = it.CompanyId, name = it.CnName })
  1888. .ToList();
  1889. companyData.Insert(0, new { id = -1, name = "全部" });
  1890. userData.Insert(0, new { id = -1, companyId = -1, name = "全部" });
  1891. #region 年份
  1892. var dtData = new List<dynamic>();
  1893. int dt = DateTime.Now.Year;
  1894. for (int y = dt; y >= dt-4; y--)
  1895. {
  1896. //季度
  1897. var quarterDatas = new List<dynamic>();
  1898. quarterDatas.Add(new { name = "全部", beginDt = $"{y}-01-01", endDt = $"{y}-12-31" });
  1899. for (int q = 0; q < 4; q++)
  1900. {
  1901. dynamic quarterData = null;
  1902. if (q == 0)
  1903. {
  1904. var monthDatas = new List<dynamic>();
  1905. monthDatas.Add(new { name = $"全部", beginDt = $"{y}-01-01", endDt = $" {y}-03-31" });
  1906. for (int m = 1; m < 4; m++)
  1907. {
  1908. MonthlyTimeSegment timeSegment = new MonthlyTimeSegment(y, m);
  1909. monthDatas.Add(new { name = $"{ConvertToChinese(m)}", beginDt = timeSegment.Start.ToString("yyyy-MM-dd"), endDt = timeSegment.End.ToString("yyyy-MM-dd") });
  1910. }
  1911. //quarterData = new { name = "第一季度", beginDt = $"{y}-01-01", endDt = $" {y}-03-31", monthData = monthDatas };
  1912. quarterData = new { name = "第一季度", monthData = monthDatas };
  1913. }
  1914. else if (q == 1)
  1915. {
  1916. var monthDatas = new List<dynamic>();
  1917. monthDatas.Add(new { name = $"全部", beginDt = $"{y}-04-01", endDt = $"{y}-06-30" });
  1918. for (int m = 4; m < 7; m++)
  1919. {
  1920. MonthlyTimeSegment timeSegment = new MonthlyTimeSegment(y, m);
  1921. monthDatas.Add(new { name = $"{ConvertToChinese(m)}", beginDt = timeSegment.Start.ToString("yyyy-MM-dd"), endDt = timeSegment.End.ToString("yyyy-MM-dd") });
  1922. }
  1923. //quarterData = new { name = "第二季度", beginDt = $"{y}-04-01", endDt = $"{y}-06-30", monthData = monthDatas };
  1924. quarterData = new { name = "第二季度", monthData = monthDatas };
  1925. }
  1926. else if (q == 2)
  1927. {
  1928. var monthDatas = new List<dynamic>();
  1929. monthDatas.Add(new { name = $"全部", beginDt = $"{y}-07-01", endDt = $"{y}-09-30" });
  1930. for (int m = 7; m < 10; m++)
  1931. {
  1932. MonthlyTimeSegment timeSegment = new MonthlyTimeSegment(y, m);
  1933. monthDatas.Add(new { name = $"{ConvertToChinese(m)}", beginDt = timeSegment.Start.ToString("yyyy-MM-dd"), endDt = timeSegment.End.ToString("yyyy-MM-dd") });
  1934. }
  1935. //quarterData = new { name = "第三季度", beginDt = $"{y}-07-01", endDt = $"{y}-09-30", monthData = monthDatas };
  1936. quarterData = new { name = "第三季度", monthData = monthDatas };
  1937. }
  1938. else if (q == 3)
  1939. {
  1940. var monthDatas = new List<dynamic>();
  1941. monthDatas.Add(new { name = $"全部", beginDt = $"{y}-10-01", endDt = $"{y}-12-31" });
  1942. for (int m = 10; m < 13; m++)
  1943. {
  1944. MonthlyTimeSegment timeSegment = new MonthlyTimeSegment(y, m);
  1945. monthDatas.Add(new { name = $"{ConvertToChinese(m)}", beginDt = timeSegment.Start.ToString("yyyy-MM-dd"), endDt = timeSegment.End.ToString("yyyy-MM-dd") });
  1946. }
  1947. //quarterData = new { name = "第四季度", beginDt = $"{y}-10-01", endDt = $"{y}-12-31", monthData = monthDatas };
  1948. quarterData = new { name = "第四季度", monthData = monthDatas };
  1949. }
  1950. quarterDatas.Add(quarterData);
  1951. }
  1952. dtData.Add(new
  1953. {
  1954. year = y,
  1955. //yearData = new { beginDt = $"{y}-01-01", endDt = $"{y}-12-31" },
  1956. quarterData = quarterDatas,
  1957. });
  1958. }
  1959. #endregion
  1960. return Ok(JsonView(true, "操作成功!", new { companyData = companyData, userData = userData, dtData = dtData }));
  1961. #endregion
  1962. }
  1963. private static string ConvertToChinese(int month)
  1964. {
  1965. if (month < 1 || month > 12)
  1966. throw new ArgumentOutOfRangeException(nameof(month), "月份必须在1到12之间。");
  1967. var cultureInfo = new System.Globalization.CultureInfo("zh-CN");
  1968. var dateTimeFormat = cultureInfo.DateTimeFormat;
  1969. return dateTimeFormat.GetMonthName(month);
  1970. }
  1971. /// <summary>
  1972. /// 市场部销售额
  1973. /// 年度/季度/月度 报表(同比)
  1974. /// (增加团组查询条件 IsSure=1)
  1975. /// </summary>
  1976. /// <param name="_dto">市场部销售额请求dto</param>
  1977. /// <returns></returns>
  1978. [HttpPost("PostMarketingSalesStatistics")]
  1979. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1980. public async Task<IActionResult> PostMarketingSalesStatistics_Year(MarketingSalesStatisticsDto _dto)
  1981. {
  1982. #region 参数验证
  1983. MarketingSalesStatisticsDtoFoalidator validationRules = new MarketingSalesStatisticsDtoFoalidator();
  1984. var validResult = await validationRules.ValidateAsync(_dto);
  1985. if (!validResult.IsValid)
  1986. {
  1987. var errors = new StringBuilder();
  1988. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  1989. return Ok(JsonView(false, errors.ToString()));
  1990. }
  1991. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1992. #region 页面操作权限验证
  1993. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  1994. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  1995. #endregion
  1996. #endregion
  1997. string beginDt = $"{_dto.BeginDt} 00:00:00",endDt = $"{_dto.EndDt} 23:59:59";
  1998. return Ok(JsonView(true, "操作成功!", await GroupSales(_dto.CompanyId, _dto.GroupPickupUserId, beginDt, endDt)));
  1999. }
  2000. private async Task<List<int>> GetUserIds(int companyId, int groupPickupUserId)
  2001. {
  2002. //全部人员Id
  2003. //查询所有公司的市场部
  2004. List<int> pickGroupIds = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0).Select(it => it.JietuanOperator).Distinct().ToList();
  2005. List<int> userIds = new List<int>();
  2006. var userDatas = await _sqlSugar.Queryable<Sys_Users>()
  2007. .InnerJoin<Sys_Company>((u, c) => u.CompanyId == c.Id)
  2008. .Where((u, c) => u.IsDel == 0 && pickGroupIds.Contains( u.Id))
  2009. .Select((u, c) => new { u.Id, u.CompanyId, u.CnName })
  2010. .ToListAsync();
  2011. userIds = userDatas.Select(it => it.Id).ToList();
  2012. if (companyId > 0)
  2013. {
  2014. userIds = userDatas.Where(it => it.CompanyId == companyId).Select(it => it.Id).ToList();
  2015. }
  2016. if (groupPickupUserId > 0)
  2017. {
  2018. userIds = userDatas.Where(it => it.Id == groupPickupUserId).Select(it => it.Id).ToList();
  2019. }
  2020. return userIds;
  2021. }
  2022. /// <summary>
  2023. /// 计算团组销售额
  2024. /// </summary>
  2025. /// <param name="companyId"></param>
  2026. /// <param name="groupPickupUserId"></param>
  2027. /// <param name="beginDt"></param>
  2028. /// <param name="endDt"></param>
  2029. /// <returns></returns>
  2030. private async Task<SalesYOYView> GroupSales(int companyId, int groupPickupUserId,string beginDt, string endDt)
  2031. {
  2032. decimal thisSales = 0.00M, lastSales = 0.00M, yoy = 1.00M;
  2033. var _view = new SalesYOYView();
  2034. List<int> userIds = new List<int>();
  2035. userIds = await GetUserIds(companyId, groupPickupUserId);
  2036. string userSqlWhere = "";
  2037. if (userIds.Count > 0)
  2038. {
  2039. userSqlWhere = string.Format($" And Id IN ({string.Join(',', userIds)})");
  2040. }
  2041. else
  2042. {
  2043. _view = new SalesYOYView
  2044. {
  2045. thisYearSales = "0.00",
  2046. lastYearSales = "0.00",
  2047. };
  2048. return _view;
  2049. }
  2050. string lastBeginDt = Convert.ToDateTime(beginDt).AddYears(-1).ToString("yyyy-MM-dd HH:mm:ss"),
  2051. lastEndDt = Convert.ToDateTime(endDt).AddYears(-1).ToString("yyyy-MM-dd HH:mm:ss");
  2052. string salesSql = string.Format(@"
  2053. SELECT
  2054. 'ThisSales' As [Name],
  2055. CAST(SUM(Sales) AS decimal(12,2)) As Sales
  2056. FROM
  2057. (
  2058. SELECT di.VisitDate,
  2059. (SELECT CAST(SUM(ItemSumPrice * Rate) AS decimal(12,2)) FROM Fin_ForeignReceivables
  2060. WHERE IsDel = 0 AND AddingWay IN (0, 1, 2)AND di.Id = Diid
  2061. ) AS Sales
  2062. FROM
  2063. Grp_DelegationInfo di
  2064. WHERE di.IsDel = 0 AND di.IsSure = 1
  2065. AND di.JietuanOperator IN (SELECT Id FROM Sys_Users WITH (NoLock) WHERE IsDel = 0 {0})
  2066. AND di.VisitDate BETWEEN '{1}' AND '{2}'
  2067. ) temp
  2068. Union ALL
  2069. SELECT
  2070. 'LastSales' As [Name],
  2071. CAST(SUM(Sales) AS decimal(12,2)) As Sales
  2072. FROM
  2073. (
  2074. SELECT di.VisitDate,
  2075. (SELECT CAST(SUM(ItemSumPrice * Rate) AS decimal(12,2)) FROM Fin_ForeignReceivables
  2076. WHERE IsDel = 0 AND AddingWay IN (0, 1, 2)AND di.Id = Diid
  2077. ) AS Sales
  2078. FROM
  2079. Grp_DelegationInfo di
  2080. WHERE di.IsDel = 0 AND di.IsSure = 1
  2081. AND di.JietuanOperator IN (SELECT Id FROM Sys_Users WITH (NoLock) WHERE IsDel = 0 {3})
  2082. AND di.VisitDate BETWEEN '{4}' AND '{5}'
  2083. ) temp", userSqlWhere, beginDt, endDt, userSqlWhere, lastBeginDt, lastEndDt);
  2084. var salesData = await _sqlSugar.SqlQueryable<SalesView>(salesSql).ToListAsync();
  2085. thisSales = salesData.Where(x => x.Name.Equals("ThisSales")).First()?.Sales ?? 0;
  2086. lastSales = salesData.Where(x => x.Name.Equals("LastSales")).First()?.Sales ?? 0;
  2087. if (lastSales != 0 && thisSales != 0) yoy = (thisSales - lastSales) / lastSales;
  2088. return new SalesYOYView() {
  2089. thisYearSales = thisSales.ToString("#0.00"),
  2090. lastYearSales = lastSales.ToString("#0.00"),
  2091. yoy = yoy.ToString("#0.00")
  2092. };
  2093. }
  2094. private class SalesView
  2095. {
  2096. public string Name { get; set; }
  2097. public decimal Sales { get; set; }
  2098. }
  2099. private class SalesYOYView
  2100. {
  2101. public string thisYearSales { get; set; }
  2102. public string lastYearSales { get; set; }
  2103. public string yoy { get; set; } = "1.00";
  2104. }
  2105. /// <summary>
  2106. /// 市场部销售额
  2107. /// 团组列表
  2108. /// (增加团组查询条件 IsSure=1)
  2109. /// </summary>
  2110. /// <param name="_dto">市场部销售额请求dto</param>
  2111. /// <returns></returns>
  2112. [HttpPost("PostMarketingSalesGroupList")]
  2113. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2114. public async Task<IActionResult> PostMarketingSalesGroupList(MarketingSalesGroupListDto _dto)
  2115. {
  2116. #region 参数验证
  2117. MarketingSalesStatisticsDtoFoalidator validationRules = new MarketingSalesStatisticsDtoFoalidator();
  2118. var validResult = await validationRules.ValidateAsync(_dto);
  2119. if (!validResult.IsValid)
  2120. {
  2121. var errors = new StringBuilder();
  2122. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2123. return Ok(JsonView(false, errors.ToString()));
  2124. }
  2125. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2126. #region 页面操作权限验证
  2127. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2128. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2129. #endregion
  2130. #endregion
  2131. string userSql = "";
  2132. List<int> userIds = new List<int>();
  2133. userIds = await GetUserIds(_dto.CompanyId, _dto.GroupPickupUserId);
  2134. if (userIds.Count <= 0)
  2135. {
  2136. return Ok(JsonView(true, "操作成功!", new List<object> { }, 0));
  2137. }
  2138. else userSql = @$" And di.JietuanOperator In ({string.Join(",", userIds)})";
  2139. if (!string.IsNullOrEmpty(_dto.SearchCriteria))
  2140. {
  2141. userSql += string.Format(@$" AND di.TeamName Like '%{_dto.SearchCriteria}%'");
  2142. }
  2143. string beginDt = $"{_dto.BeginDt} 00:00:00", endDt = $"{_dto.EndDt} 23:59:59";
  2144. string sql = string.Format(@$"SELECT
  2145. ROW_NUMBER() OVER (
  2146. ORDER BY
  2147. CollectionDays
  2148. ) AS RowNumber,
  2149. *
  2150. FROM
  2151. (
  2152. SELECT
  2153. di.Id,
  2154. di.TeamName,
  2155. di.ClientUnit,
  2156. di.ClientName,
  2157. di.VisitDate,
  2158. di.VisitPNumber,
  2159. di.JietuanOperator,
  2160. di.VisitEndDate,
  2161. (
  2162. SELECT
  2163. CAST(
  2164. COALESCE(SUM(ItemSumPrice * Rate), 0) AS DECIMAL(12, 2)
  2165. ) AS GroupSales
  2166. FROM
  2167. Fin_ForeignReceivables
  2168. WHERE
  2169. IsDel = 0
  2170. AND di.Id = Diid
  2171. AND AddingWay IN (0, 1, 2)
  2172. ) AS GroupSales,
  2173. u.CnName AS GroupPickupUser,
  2174. DATEADD(DAY, 7, di.VisitEndDate) AS CollectionDays
  2175. FROM
  2176. Grp_DelegationInfo di
  2177. WITH
  2178. (NoLock)
  2179. LEFT JOIN Sys_Users u ON di.JietuanOperator = u.Id
  2180. WHERE
  2181. di.Isdel = 0
  2182. AND di.IsSure = 1 {userSql}
  2183. AND VisitDate Between '{beginDt}' And '{endDt}'
  2184. ) Temp ");
  2185. RefAsync<int> total = 0;
  2186. var groupData = await _sqlSugar.SqlQueryable<MarketingSalesGroupList>(sql).ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);
  2187. return Ok(JsonView(true, "操作成功!", groupData, total));
  2188. }
  2189. /// <summary>
  2190. /// 市场部销售额
  2191. /// 客户类型、客户等级 统计
  2192. /// </summary>
  2193. /// <param name="_dto">市场部销售额请求dto</param>
  2194. /// <returns></returns>
  2195. [HttpPost("PostMarketingSalesGroupStatistics")]
  2196. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2197. public async Task<IActionResult> PostMarketingSalesGroupStatistics(MarketingSalesGroupStatisticsDto _dto)
  2198. {
  2199. #region 参数验证
  2200. MarketingSalesStatisticsDtoFoalidator validationRules = new MarketingSalesStatisticsDtoFoalidator();
  2201. var validResult = await validationRules.ValidateAsync(_dto);
  2202. if (!validResult.IsValid)
  2203. {
  2204. var errors = new StringBuilder();
  2205. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2206. return Ok(JsonView(false, errors.ToString()));
  2207. }
  2208. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2209. #region 页面操作权限验证
  2210. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2211. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2212. #endregion
  2213. #endregion
  2214. string beginDt = $"{_dto.BeginDt} 00:00:00", endDt = $"{_dto.EndDt} 23:59:59";
  2215. List<int> userIds = await GetUserIds(_dto.CompanyId, _dto.GroupPickupUserId);
  2216. string userSql = "";
  2217. if (userIds.Count > 0)
  2218. {
  2219. userSql = string.Format(@$" AND JietuanOperator IN ({string.Join(",",userIds)})");
  2220. }
  2221. else
  2222. {
  2223. if (_dto.PortType == 2 || _dto.PortType == 3)
  2224. {
  2225. return Ok(JsonView(true, "操作成功!", new List<object> { }));
  2226. }
  2227. else
  2228. {
  2229. return Ok(JsonView(true, "操作成功!", new
  2230. {
  2231. customerTypeData = new List<object> { },
  2232. clientGradeData = new List<object> { }
  2233. }));
  2234. }
  2235. }
  2236. string sql = "";
  2237. if (_dto.StatisticsType == 1 )
  2238. {
  2239. sql = string.Format(@$"Select
  2240. sd.[Name],
  2241. Count(*) As [Count]
  2242. From Grp_DelegationInfo di
  2243. Left Join Sys_SetData sd On di.TeamDid = sd.Id
  2244. Where di.Isdel = 0
  2245. And IsSure = 1 {userSql}
  2246. And VisitDate Between '{beginDt}' And '{endDt}'
  2247. Group By [Name]
  2248. Order By Count Desc");
  2249. }
  2250. else if (_dto.StatisticsType == 2)
  2251. {
  2252. sql = string.Format(@$"Select
  2253. sd.[Name],
  2254. Count(*) As [Count]
  2255. From Grp_DelegationInfo di
  2256. Left Join Sys_SetData sd On di.TeamLevSId = sd.Id
  2257. Where di.Isdel = 0
  2258. And IsSure = 1 {userSql}
  2259. And VisitDate Between '{beginDt}' And '{endDt}'
  2260. Group By [Name]
  2261. Order By Count Desc");
  2262. }
  2263. else return Ok(JsonView(false, "StatisticsType不在可取范围!"));
  2264. if (_dto.PortType == 1)
  2265. {
  2266. string sql1 = string.Format(@$"Select
  2267. sd.[Name],
  2268. Count(*) As [Count]
  2269. From Grp_DelegationInfo di
  2270. Left Join Sys_SetData sd On di.TeamDid = sd.Id
  2271. Where di.Isdel = 0
  2272. And IsSure = 1 {userSql}
  2273. And VisitDate Between '{beginDt}' And '{endDt}'
  2274. Group By [Name]
  2275. Order By Count Desc");
  2276. var customerTypeData = await _sqlSugar.SqlQueryable<MarketingSalesGroupStatisticsView>(sql1).ToListAsync();
  2277. string sql2 = string.Format(@$"Select
  2278. sd.[Name],
  2279. Count(*) As [Count]
  2280. From Grp_DelegationInfo di
  2281. Left Join Sys_SetData sd On di.TeamLevSId = sd.Id
  2282. Where di.Isdel = 0
  2283. And IsSure = 1 {userSql}
  2284. And VisitDate Between '{beginDt}' And '{endDt}'
  2285. Group By [Name]
  2286. Order By Count Desc");
  2287. var clientGradeData = await _sqlSugar.SqlQueryable<MarketingSalesGroupStatisticsView>(sql2).ToListAsync();
  2288. return Ok(JsonView(true, "操作成功!", new {
  2289. customerTypeData= customerTypeData,
  2290. clientGradeData = clientGradeData
  2291. }));
  2292. }
  2293. else if (_dto.PortType == 2 || _dto.PortType == 3)
  2294. {
  2295. var data = await _sqlSugar.SqlQueryable<MarketingSalesGroupStatisticsView>(sql).ToListAsync();
  2296. return Ok(JsonView(true, "操作成功!", data, data.Count));
  2297. }
  2298. else return Ok(JsonView(false, MsgTips.Port));
  2299. }
  2300. /// <summary>
  2301. /// 市场部销售额
  2302. /// 接单排名
  2303. /// </summary>
  2304. /// <param name="_dto">市场部销售额请求dto</param>
  2305. /// <returns></returns>
  2306. [HttpPost("PostMarketingSalesOrderRanking")]
  2307. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2308. public async Task<IActionResult> PostMarketingSalesOrderRanking(MarketingSalesOrderRankingDto _dto)
  2309. {
  2310. #region 参数验证
  2311. MarketingSalesStatisticsDtoFoalidator validationRules = new MarketingSalesStatisticsDtoFoalidator();
  2312. var validResult = await validationRules.ValidateAsync(_dto);
  2313. if (!validResult.IsValid)
  2314. {
  2315. var errors = new StringBuilder();
  2316. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2317. return Ok(JsonView(false, errors.ToString()));
  2318. }
  2319. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2320. #region 页面操作权限验证
  2321. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2322. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2323. #endregion
  2324. #endregion
  2325. string beginDt = $"{_dto.BeginDt} 00:00:00", endDt = $"{_dto.EndDt} 23:59:59";
  2326. List<int> userIds = await GetUserIds(_dto.CompanyId, _dto.GroupPickupUserId);
  2327. string userSql = "";
  2328. if (userIds.Count > 0)
  2329. {
  2330. userSql = string.Format(@$" AND JietuanOperator IN ({string.Join(",", userIds)})");
  2331. }else return Ok(JsonView(true, "操作成功!", new List<object> { }, 0));
  2332. string sql = string.Format(@$"Select
  2333. ROW_NUMBER() Over(Order By Count(*) Desc) As RowNumber,
  2334. u.CnName As UserName,
  2335. Count(*) As [Count]
  2336. From Grp_DelegationInfo di
  2337. Left Join Sys_Users u On di.JietuanOperator = u.Id
  2338. Where di.Isdel = 0
  2339. AND IsSure = 1 {userSql}
  2340. And VisitDate Between '{beginDt}' And '{endDt}'
  2341. Group By CnName");
  2342. RefAsync<int> total = 0;
  2343. var rankingData = await _sqlSugar.SqlQueryable<MarketingSalesOrderRankingView>(sql).ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);
  2344. return Ok(JsonView(true, "操作成功!", rankingData, total));
  2345. }
  2346. /// <summary>
  2347. /// 市场部销售额
  2348. /// 团组列表、客户类型、客户等级、接单排名
  2349. /// (增加团组查询条件 IsSure=1)
  2350. /// </summary>
  2351. /// <param name="_dto">市场部销售额请求dto</param>
  2352. /// <returns></returns>
  2353. [HttpPost("PostMarketingSalesGroupItem")]
  2354. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2355. public async Task<IActionResult> PostMarketingSalesGroupItem(MarketingSalesGroupListDto _dto)
  2356. {
  2357. #region 参数验证
  2358. MarketingSalesStatisticsDtoFoalidator validationRules = new MarketingSalesStatisticsDtoFoalidator();
  2359. var validResult = await validationRules.ValidateAsync(_dto);
  2360. if (!validResult.IsValid)
  2361. {
  2362. var errors = new StringBuilder();
  2363. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2364. return Ok(JsonView(false, errors.ToString()));
  2365. }
  2366. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2367. #region 页面操作权限验证
  2368. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2369. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2370. #endregion
  2371. #endregion
  2372. string userSql = "";
  2373. List<int> userIds = new List<int>();
  2374. userIds = await GetUserIds(_dto.CompanyId, _dto.GroupPickupUserId);
  2375. if (userIds.Count <= 0)
  2376. {
  2377. return Ok(JsonView(true, "操作成功!", new List<object> { }, 0));
  2378. }
  2379. else userSql = @$" And di.JietuanOperator In ({string.Join(",", userIds)})";
  2380. if (!string.IsNullOrEmpty(_dto.SearchCriteria))
  2381. {
  2382. userSql += string.Format(@$" AND di.TeamName Like '%{_dto.SearchCriteria}%'");
  2383. }
  2384. string beginDt = $"{_dto.BeginDt} 00:00:00", endDt = $"{_dto.EndDt} 23:59:59";
  2385. #region 团组List
  2386. string sql = string.Format(@$"SELECT
  2387. ROW_NUMBER() OVER (
  2388. ORDER BY
  2389. CollectionDays
  2390. ) AS RowNumber,
  2391. *
  2392. FROM
  2393. (
  2394. SELECT
  2395. di.Id,
  2396. di.TeamName,
  2397. di.ClientUnit,
  2398. di.ClientName,
  2399. di.VisitDate,
  2400. di.VisitPNumber,
  2401. di.JietuanOperator,
  2402. di.VisitEndDate,
  2403. (
  2404. SELECT
  2405. CAST(
  2406. COALESCE(SUM(ItemSumPrice * Rate), 0) AS DECIMAL(12, 2)
  2407. ) AS GroupSales
  2408. FROM
  2409. Fin_ForeignReceivables
  2410. WHERE
  2411. IsDel = 0
  2412. AND di.Id = Diid
  2413. AND AddingWay IN (0, 1, 2)
  2414. ) AS GroupSales,
  2415. u.CnName AS GroupPickupUser,
  2416. DATEADD(DAY, 7, di.VisitEndDate) AS CollectionDays
  2417. FROM
  2418. Grp_DelegationInfo di
  2419. WITH
  2420. (NoLock)
  2421. LEFT JOIN Sys_Users u ON di.JietuanOperator = u.Id
  2422. WHERE
  2423. di.Isdel = 0
  2424. AND di.IsSure = 1 {userSql}
  2425. AND VisitDate Between '{beginDt}' And '{endDt}'
  2426. ) Temp ");
  2427. RefAsync<int> total = 0;
  2428. var groupData = await _sqlSugar.SqlQueryable<MarketingSalesGroupList>(sql).ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);
  2429. #endregion
  2430. #region 客户类型、客户等级 统计
  2431. string sql1 = string.Format(@$"Select
  2432. sd.[Name],
  2433. Count(*) As [Count]
  2434. From Grp_DelegationInfo di
  2435. Left Join Sys_SetData sd On di.TeamDid = sd.Id
  2436. Where di.Isdel = 0
  2437. And IsSure = 1 {userSql}
  2438. And VisitDate Between '{beginDt}' And '{endDt}'
  2439. Group By [Name]
  2440. Order By Count Desc");
  2441. var customerTypeData = await _sqlSugar.SqlQueryable<MarketingSalesGroupStatisticsView>(sql1).ToListAsync();
  2442. string sql2 = string.Format(@$"Select
  2443. sd.[Name],
  2444. Count(*) As [Count]
  2445. From Grp_DelegationInfo di
  2446. Left Join Sys_SetData sd On di.TeamLevSId = sd.Id
  2447. Where di.Isdel = 0
  2448. And IsSure = 1 {userSql}
  2449. And VisitDate Between '{beginDt}' And '{endDt}'
  2450. Group By [Name]
  2451. Order By Count Desc");
  2452. var clientGradeData = await _sqlSugar.SqlQueryable<MarketingSalesGroupStatisticsView>(sql2).ToListAsync();
  2453. #endregion
  2454. #region 接单排名
  2455. string sql4 = string.Format(@$"Select
  2456. ROW_NUMBER() Over(Order By Count(*) Desc) As RowNumber,
  2457. u.CnName As UserName,
  2458. Count(*) As [Count]
  2459. From Grp_DelegationInfo di
  2460. Left Join Sys_Users u On di.JietuanOperator = u.Id
  2461. Where di.Isdel = 0
  2462. AND IsSure = 1 {userSql}
  2463. And VisitDate Between '{beginDt}' And '{endDt}'
  2464. Group By CnName");
  2465. var rankingData = await _sqlSugar.SqlQueryable<MarketingSalesOrderRankingView>(sql4).ToListAsync();
  2466. #endregion
  2467. var viewData = new {
  2468. groupData = groupData,
  2469. groupTotal = total,
  2470. customerTypeData = customerTypeData,
  2471. clientGradeData = clientGradeData,
  2472. rankingData = rankingData
  2473. };
  2474. return Ok(JsonView(true, "操作成功!", viewData, total));
  2475. }
  2476. /// <summary>
  2477. /// 市场部销售额
  2478. /// 客户拜访列表
  2479. /// </summary>
  2480. /// <param name="_dto">市场部销售额请求dto</param>
  2481. /// <returns></returns>
  2482. [HttpPost("PostMarketingSalesVCList")]
  2483. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2484. public async Task<IActionResult> PostMarketingSalesVCList(MarketingSalesVCListDto _dto)
  2485. {
  2486. #region 参数验证
  2487. MarketingSalesUserPageFuncDtoBaseFoalidator validationRules = new MarketingSalesUserPageFuncDtoBaseFoalidator();
  2488. var validResult = await validationRules.ValidateAsync(_dto);
  2489. if (!validResult.IsValid)
  2490. {
  2491. var errors = new StringBuilder();
  2492. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2493. return Ok(JsonView(false, errors.ToString()));
  2494. }
  2495. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2496. #region 页面操作权限验证
  2497. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2498. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2499. #endregion
  2500. #endregion
  2501. return Ok(await _visitingClientsRep._List(_dto.PortType,_dto.PageIndex,_dto.PageSize,_dto.DiId,_dto.Search));
  2502. }
  2503. /// <summary>
  2504. /// 市场部销售额
  2505. /// 客户拜访 操作(添加 Or 编辑)
  2506. /// </summary>
  2507. /// <param name="_dto">市场部销售额请求dto</param>
  2508. /// <returns></returns>
  2509. [HttpPost("PostMarketingSalesVCOperate")]
  2510. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2511. public async Task<IActionResult> PostMarketingSalesVCOperate(MarketingSalesVCOperrateDto _dto)
  2512. {
  2513. #region 参数验证
  2514. MarketingSalesUserPageFuncDtoBaseFoalidator validationRules = new MarketingSalesUserPageFuncDtoBaseFoalidator();
  2515. var validResult = await validationRules.ValidateAsync(_dto);
  2516. if (!validResult.IsValid)
  2517. {
  2518. var errors = new StringBuilder();
  2519. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2520. return Ok(JsonView(false, errors.ToString()));
  2521. }
  2522. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2523. #region 页面操作权限验证
  2524. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2525. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2526. #endregion
  2527. #endregion
  2528. return Ok(await _visitingClientsRep._AddOrEdit(_dto));
  2529. }
  2530. /// <summary>
  2531. /// 市场部销售额
  2532. /// 客户拜访 Del
  2533. /// </summary>
  2534. /// <param name="_dto">市场部销售额请求dto</param>
  2535. /// <returns></returns>
  2536. [HttpPost("PostMarketingSalesVCDel")]
  2537. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2538. public async Task<IActionResult> PostMarketingSalesVCDel(MarketingSalesVCDelDto _dto)
  2539. {
  2540. return Ok(await _visitingClientsRep._Del(_dto.Id,_dto.UserId));
  2541. }
  2542. /// <summary>
  2543. /// 市场部销售额
  2544. /// 客户拜访 操作 save
  2545. /// </summary>
  2546. /// <param name="_dto">市场部销售额请求dto</param>
  2547. /// <returns></returns>
  2548. [HttpPost("PostMarketingSalesVCSave")]
  2549. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2550. public async Task<IActionResult> PostMarketingSalesVCSave(MarketingSalesVCSaveDto _dto)
  2551. {
  2552. #region 参数验证
  2553. MarketingSalesUserPageFuncDtoBaseFoalidator validationRules = new MarketingSalesUserPageFuncDtoBaseFoalidator();
  2554. var validResult = await validationRules.ValidateAsync(_dto);
  2555. if (!validResult.IsValid)
  2556. {
  2557. var errors = new StringBuilder();
  2558. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2559. return Ok(JsonView(false, errors.ToString()));
  2560. }
  2561. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2562. #region 页面操作权限验证
  2563. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2564. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2565. #endregion
  2566. #endregion
  2567. return Ok(await _visitingClientsRep._Save(_dto));
  2568. }
  2569. #endregion
  2570. #region 日付报表
  2571. /// <summary>
  2572. /// 日付类型数据
  2573. /// </summary>
  2574. /// <param name="_dto"></param>
  2575. /// <returns></returns>
  2576. [HttpPost("DailypaymentTypeInit")]
  2577. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2578. public async Task<IActionResult> DailypaymentTypeInit(DailypaymentTypeInitDto _dto)
  2579. {
  2580. #region 参数验证
  2581. if (_dto.PortType < 1 || _dto.PortType > 3) return Ok(JsonView(false, msg:MsgTips.Port));
  2582. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2583. #region 页面操作权限验证
  2584. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2585. //if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  2586. #endregion
  2587. #endregion
  2588. if (_dto.PortType == 1 || _dto.PortType == 2 || _dto.PortType == 3) // web/Android/IOS
  2589. {
  2590. var defaultParentIds = new List<int>() {
  2591. 48,// 人员费用
  2592. 49,// 办公费用
  2593. 50,// 销售费用
  2594. 51,// 其他费用
  2595. 55,// 大运会
  2596. };
  2597. var dailypaymentTypeData = await RedisRepository.RedisFactory
  2598. .CreateRedisRepository()
  2599. .StringGetAsync<List<int>>("DailypaymentTypeData") ?? new List<int>();
  2600. var dailyTypeData = await _sqlSugar.Queryable<DailypaymentParentTypeView>()
  2601. .Includes(x => x.SubData)
  2602. .Where(x => defaultParentIds.Contains(x.Id))
  2603. .ToListAsync();
  2604. dailyTypeData.ForEach(x =>
  2605. {
  2606. x.SubData.ForEach(y =>
  2607. {
  2608. int currId = dailypaymentTypeData.Find(z => z == y.Id);
  2609. y.IsChecked = currId == 0 ? false : true;
  2610. });
  2611. });
  2612. var companyData = await _sqlSugar.Queryable<Sys_Company>()
  2613. .Where(x => x.IsDel == 0)
  2614. .Select(x => new { id = x.Id, name = x.CompanyName })
  2615. .ToListAsync();
  2616. return Ok(JsonView(true, "查询成功!", new { dailyTypeData = dailyTypeData, companyData = companyData }));
  2617. }
  2618. else
  2619. {
  2620. return Ok(JsonView(false, "查询失败"));
  2621. }
  2622. }
  2623. /// <summary>
  2624. /// 日付类型数据 Save
  2625. /// </summary>
  2626. /// <param name="_dto"></param>
  2627. /// <returns></returns>
  2628. [HttpPost("DailypaymentTypeDataSave")]
  2629. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2630. public async Task<IActionResult> DailypaymentTypeDataSave(DailypaymentTypeDataSaveDto _dto)
  2631. {
  2632. #region 参数验证
  2633. if (_dto.PortType < 1 || _dto.PortType > 3) return Ok(JsonView(false, msg: MsgTips.Port));
  2634. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2635. #region 页面操作权限验证
  2636. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2637. //if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  2638. #endregion
  2639. #endregion
  2640. if (_dto.PortType == 1 || _dto.PortType == 2 || _dto.PortType == 3) // web/Android/IOS
  2641. {
  2642. if (_dto.TypeIds.Count < 1) return Ok(JsonView(false, "请传入需要保存的TypeIds"));
  2643. var res = await RedisRepository.RedisFactory
  2644. .CreateRedisRepository()
  2645. .StringSetAsync(
  2646. key:"DailypaymentTypeData",
  2647. _dto.TypeIds,
  2648. timeout:null );
  2649. if (!res) return Ok(JsonView(false, "操作失败"));
  2650. return Ok(JsonView(true, "操作成功!"));
  2651. }
  2652. else return Ok(JsonView(false, "操作失败"));
  2653. }
  2654. /// <summary>
  2655. /// 日付数据列表
  2656. /// </summary>
  2657. /// <param name="_dto"></param>
  2658. /// <returns></returns>
  2659. [HttpPost("DailypaymentRange")]
  2660. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2661. public async Task<IActionResult> DailypaymentRange(DailypaymentRangeDto _dto)
  2662. {
  2663. #region 参数验证
  2664. var validator = new DailypaymentRangeDtoValidator();
  2665. var validationRes = validator.Validate(_dto);
  2666. if (!validationRes.IsValid)
  2667. {
  2668. StringBuilder sb = new StringBuilder();
  2669. foreach (var item in validationRes.Errors)
  2670. {
  2671. sb.AppendLine(item.ErrorMessage);
  2672. }
  2673. return Ok(JsonView(false, sb.ToString()));
  2674. }
  2675. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2676. #region 页面操作权限验证
  2677. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2678. //if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  2679. #endregion
  2680. #endregion
  2681. if (_dto.PortType == 1 || _dto.PortType == 2 || _dto.PortType == 3) // web/Android/IOS
  2682. {
  2683. DateTime _beginDt = Convert.ToDateTime($"{_dto.BeginDt} 00:00:00"),
  2684. _endDt = Convert.ToDateTime($"{_dto.EndDt} 23:59:59");
  2685. string sqlWhere = string.Format(@" And dfp.CreateTime Between '{0}' And '{1}'",_beginDt,_endDt);
  2686. var dailypaymentTypeData = await RedisRepository.RedisFactory
  2687. .CreateRedisRepository()
  2688. .StringGetAsync<List<int>>("DailypaymentTypeData") ?? new List<int>();
  2689. string sql = string.Format(@"
  2690. Select
  2691. dfp.Id,
  2692. dfp.Instructions,
  2693. dfp.PriceTypeId,
  2694. sd1.Name As FeeType,
  2695. dfp.TransferTypeId,
  2696. sd2.Name As TransferType,
  2697. dfp.SumPrice,
  2698. dfp.FAuditDate,
  2699. dfp.MAuditDate,
  2700. dfp.CompanyId,
  2701. c.CompanyName,
  2702. dfp.CreateUserId As ApplicantId,
  2703. u.CnName As Applicant,
  2704. dfp.CreateTime As ApplicantDt,
  2705. dfp.Instructions+u.CnName As ViewStr
  2706. From Fin_DailyFeePayment dfp
  2707. Left Join Sys_Users u On dfp.CreateUserId = u.Id
  2708. Left Join Sys_SetData sd1 On dfp.TransferTypeId = sd1.Id
  2709. Left Join Sys_Company c On dfp.CompanyId = c.Id
  2710. Left Join Sys_SetData sd2 On dfp.PriceTypeId = sd2.Id
  2711. Where dfp.IsDel = 0 And dfp.IsPay = 1
  2712. ", sqlWhere);//--Order By dfp.CreateTime Desc
  2713. if (_dto.Type == 1) //data
  2714. {
  2715. RefAsync<int> total = 0;
  2716. var _view = await _sqlSugar.SqlQueryable<DailyFeePaymentRangeView>(sql)
  2717. .Where(x => x.ApplicantDt >= _beginDt && x.ApplicantDt <= _endDt)
  2718. .WhereIF(dailypaymentTypeData.Count > 0,
  2719. x => dailypaymentTypeData.Contains(x.PriceTypeId))
  2720. .WhereIF(_dto.CompanyIds.Count > 0, x => _dto.CompanyIds.Contains(x.CompanyId))
  2721. .WhereIF(!string.IsNullOrEmpty(_dto.Filter), x => x.ViewStr.Contains(_dto.Filter))
  2722. .OrderByDescending(x => x.ApplicantDt)
  2723. .ToPageListAsync(
  2724. pageNumber: _dto.PageIndex,
  2725. pageSize: _dto.PageSize,
  2726. totalNumber: total
  2727. );
  2728. _sqlSugar.ThenMapper(_view, x =>
  2729. {
  2730. x.Contents = _sqlSugar.Queryable<DailyFeePaymentContentView>()
  2731. .SetContext(x1 => x1.DFPId, () => x.Id, x)
  2732. .ToList();
  2733. });
  2734. //单独处理
  2735. return Ok(JsonView(true, "操作成功!", new { data = _view, total = _view.Sum(x => x.SumPrice) }, total));
  2736. }
  2737. else if (_dto.Type == 2) //view
  2738. {
  2739. var _view = await _sqlSugar.SqlQueryable<ExcelView>(sql)
  2740. .Where(x => x.ApplicantDt >= _beginDt && x.ApplicantDt <= _endDt)
  2741. .WhereIF(dailypaymentTypeData.Count > 0,
  2742. x => dailypaymentTypeData.Contains(x.PriceTypeId))
  2743. .WhereIF(_dto.CompanyIds.Count > 0, x => _dto.CompanyIds.Contains(x.CompanyId))
  2744. .WhereIF(!string.IsNullOrEmpty(_dto.Filter), x => x.ViewStr.Contains(_dto.Filter))
  2745. .OrderByDescending(x => x.ApplicantDt)
  2746. .ToPageListAsync(
  2747. pageNumber: 1,
  2748. pageSize: 99999
  2749. ) ;
  2750. _sqlSugar.ThenMapper(_view, x =>
  2751. {
  2752. x.Contents = _sqlSugar.Queryable<DailyFeePaymentContentView>()
  2753. .SetContext(x1 => x1.DFPId, () => x.Id, x)
  2754. .ToList();
  2755. string str = "";
  2756. int index = 1;
  2757. foreach (var item in x.Contents)
  2758. {
  2759. string str1 = $"{index}、费用名称:[{item.PriceName}] 单价:[{item.Price.ToString("#0.00")}] 数量:[{item.Quantity.ToString("#0.00")}] 小计:[{item.ItemTotal.ToString("#0.00")}] 备注:[{item.Remark}]";
  2760. if (index == x.Contents.Count) str += str1;
  2761. else str += str1 + "\r\n";
  2762. index++;
  2763. }
  2764. x.ContentStr = str;
  2765. });
  2766. if (_view.Count > 0 )
  2767. {
  2768. //DataTable dt = GeneralMethod.
  2769. DataTable dt = CommonFun.GetDataTableFromIList(_view );
  2770. dt.TableName = $"_view";
  2771. decimal total = _view.Sum(x => x.SumPrice);
  2772. WorkbookDesigner designer = new WorkbookDesigner();
  2773. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/日付报表模板.xls");
  2774. designer.SetDataSource(dt);
  2775. designer.SetDataSource("Total", total);
  2776. designer.Workbook.Worksheets[0].Name = "日付报表";
  2777. designer.Process();
  2778. string fileName = $"DailyPayment/日付报表{ DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx";
  2779. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  2780. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  2781. return Ok(JsonView(true, "操作成功", new { url = rst })) ;
  2782. }
  2783. return Ok(JsonView(true, ",暂无数据"));
  2784. }
  2785. return Ok(JsonView(false, "操作失败"));
  2786. }
  2787. else return Ok(JsonView(false, "操作失败"));
  2788. }
  2789. #endregion
  2790. #region 统计模块
  2791. /*
  2792. * 1、营业额(今年和去年的)、成本支出(今年和去年的)、毛利润(今年和去年的)
  2793. 2、国交数据统计(1、机票票数、2、机票到达地 3、酒店预订地区TOP10排序、酒店房型地区间数、商邀邀请国家数量TOP10排序)
  2794. 3、会务数据统计(1、会务城市TOP10排序
  2795. *
  2796. */
  2797. /// <summary>
  2798. /// 同比
  2799. /// 营业额(今年和去年的)、成本支出(今年和去年的)、毛利润(今年和去年的)
  2800. /// </summary>
  2801. /// <param name="_dto">市场部销售额请求dto</param>
  2802. /// <returns></returns>
  2803. [HttpPost("StatisticsYOY")]
  2804. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2805. public async Task<IActionResult> StatisticsYOY(YOYDto _dto)
  2806. {
  2807. //同比增长率 = (本期 - 同期) / 同期 * 100%;
  2808. if (_dto.Year < 1) return Ok(JsonView(false,"操作失败"));
  2809. string beginDt = $"{_dto.Year-1}-01-01 00:00:00",
  2810. endDt = $"{_dto.Year}-12-31 23:59:59";
  2811. string sql = string.Format(@"
  2812. SELECT
  2813. di.Id,
  2814. di.TeamName,
  2815. di.VisitDate,
  2816. YEAR(di.VisitDate) AS YEAR,
  2817. MONTH(di.VisitDate) AS MONTH,
  2818. (
  2819. SELECT
  2820. CAST(SUM(ItemSumPrice * Rate) AS DECIMAL(12, 2))
  2821. FROM
  2822. Fin_ForeignReceivables
  2823. WHERE
  2824. IsDel = 0
  2825. AND AddingWay IN (0, 1, 2)
  2826. AND di.Id = Diid
  2827. ) AS SaleAmount,
  2828. (
  2829. SELECT
  2830. CAST(
  2831. SUM(
  2832. (
  2833. ((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100
  2834. )
  2835. ) AS DECIMAL(12, 2)
  2836. )
  2837. FROM
  2838. Grp_AirTicketReservations atr
  2839. INNER JOIN Grp_CreditCardPayment ccp ON ccp.isdel = 0
  2840. AND ccp.CTable = 85
  2841. AND atr.Id = ccp.CId
  2842. WHERE
  2843. atr.IsDel = 0
  2844. AND ccp.IsAuditGM = 1
  2845. AND ccp.IsPay = 1
  2846. AND di.Id = atr.DiId
  2847. ) AirTicketAmount,
  2848. (
  2849. SELECT
  2850. CAST(
  2851. SUM(
  2852. (
  2853. ctggr.ServiceQuotedPrice * (ccp.PayPercentage / 100) * ccp.DayRate
  2854. )
  2855. ) AS DECIMAL(12, 2)
  2856. )
  2857. FROM
  2858. Grp_CarTouristGuideGroundReservations ctggr
  2859. INNER JOIN Grp_CreditCardPayment ccp ON ccp.IsDel = 0
  2860. AND ccp.CTable = 79
  2861. AND ctggr.Id = ccp.CId
  2862. WHERE
  2863. ctggr.IsDel = 0
  2864. AND ccp.IsAuditGM = 1
  2865. AND ccp.IsPay = 1
  2866. AND di.Id = ctggr.DiId
  2867. ) AS OPAmount,
  2868. (
  2869. SELECT
  2870. CAST(SUM((ccp.PayMoney * ccp.DayRate)) AS DECIMAL(12, 2))
  2871. FROM
  2872. Grp_DecreasePayments dp
  2873. INNER JOIN Grp_CreditCardPayment ccp ON ccp.isdel = 0
  2874. AND ccp.CTable = 98
  2875. AND dp.Id = ccp.CId
  2876. WHERE
  2877. dp.IsDel = 0
  2878. AND ccp.Ctable = 98
  2879. AND ccp.IsAuditGM = 1
  2880. AND ccp.IsPay = 1
  2881. AND di.Id = dp.Diid
  2882. ) AS OtherCostAmount,
  2883. (
  2884. SELECT
  2885. CAST(
  2886. SUM(
  2887. (
  2888. ((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100
  2889. )
  2890. ) AS DECIMAL(12, 2)
  2891. )
  2892. FROM
  2893. Grp_VisaInfo vi
  2894. INNER JOIN Grp_CreditCardPayment ccp ON ccp.isdel = 0
  2895. AND ccp.CTable = 80
  2896. AND vi.Id = ccp.CId
  2897. WHERE
  2898. vi.IsDel = 0
  2899. AND ccp.IsAuditGM = 1
  2900. AND ccp.IsPay = 1
  2901. AND di.Id = vi.DIId
  2902. ) AS VisaAmount,
  2903. (
  2904. SELECT
  2905. CAST(
  2906. SUM(
  2907. ((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100
  2908. ) AS DECIMAL(12, 2)
  2909. )
  2910. FROM
  2911. Grp_InvitationOfficialActivities ioa
  2912. INNER JOIN Grp_CreditCardPayment ccp ON ccp.isdel = 0
  2913. AND ccp.CTable = 81
  2914. AND ioa.Id = ccp.CId
  2915. WHERE
  2916. ioa.IsDel = 0
  2917. AND ccp.IsAuditGM = 1
  2918. AND ccp.IsPay = 1
  2919. AND di.Id = ioa.Diid
  2920. ) AS OAAmount,
  2921. (
  2922. SELECT
  2923. CAST(
  2924. SUM(
  2925. ((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100
  2926. ) AS DECIMAL(12, 2)
  2927. )
  2928. FROM
  2929. Grp_Customers ic
  2930. INNER JOIN Grp_CreditCardPayment ccp ON ccp.isdel = 0
  2931. AND ccp.CTable = 82
  2932. AND ic.Id = ccp.CId
  2933. WHERE
  2934. ic.IsDel = 0
  2935. AND ccp.IsAuditGM = 1And ccp.IsPay = 1
  2936. AND di.Id = ic.DiId
  2937. ) AS InsureAmount,
  2938. (
  2939. SELECT
  2940. CAST(
  2941. SUM(
  2942. ((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100
  2943. ) AS DECIMAL(12, 2)
  2944. )
  2945. FROM
  2946. Grp_HotelReservations hr
  2947. INNER JOIN Grp_CreditCardPayment ccp ON hr.Id = ccp.CId
  2948. WHERE
  2949. hr.IsDel = 0
  2950. AND ccp.IsDel = 0
  2951. AND ccp.CTable = 76
  2952. AND ccp.IsAuditGM = 1
  2953. AND ccp.PayMoney <> 0
  2954. AND ccp.IsPay = 0
  2955. AND di.Id = hr.DiId
  2956. ) AS HotelAmount,
  2957. (
  2958. SELECT
  2959. CAST(
  2960. SUM((gec.PriceSum * gec.Coefficient * ccp.DayRate)) AS DECIMAL(12, 2)
  2961. )
  2962. FROM
  2963. OA2023DB.dbo.Fin_GroupExtraCost gec
  2964. INNER JOIN Grp_CreditCardPayment ccp ON gec.Id = ccp.CId
  2965. WHERE
  2966. ccp.IsDel = 0
  2967. AND ccp.CTable = 1015
  2968. AND ccp.IsAuditGM = 1
  2969. AND ccp.IsPay = 1
  2970. AND di.Id = gec.DiId
  2971. ) AS ExcessAmount,
  2972. (
  2973. SELECT
  2974. CAST(
  2975. SUM(
  2976. ((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100
  2977. ) AS DECIMAL(12, 2)
  2978. )
  2979. FROM
  2980. Fin_PaymentRefundAndOtherMoney prom
  2981. INNER JOIN Grp_CreditCardPayment ccp ON prom.DiId = ccp.DIId
  2982. AND prom.Id = ccp.CId
  2983. WHERE
  2984. prom.IsDel = 0
  2985. AND prom.PayType = 1
  2986. AND ccp.CTable = 285
  2987. AND ccp.IsAuditGM = 1
  2988. AND ccp.IsPay = 1
  2989. AND di.Id = prom.DiId
  2990. ) AS SKTHAmount
  2991. FROM
  2992. Grp_DelegationInfo di
  2993. WHERE
  2994. di.IsDel = 0
  2995. AND di.IsSure = 1
  2996. AND di.VisitDate BETWEEN '{0}' AND '{1}'
  2997. ORDER BY
  2998. di.VisitDate
  2999. ", beginDt,endDt);
  3000. var data = await _sqlSugar.SqlQueryable<StatisticsYOYView>(sql).ToListAsync();
  3001. var thisYearData = data.Where(x => x.Year == _dto.Year).ToList();
  3002. var lastYearData = data.Where(x => x.Year == (_dto.Year - 1)).ToList();
  3003. List<YOYReturnView> salesYOYData = new List<YOYReturnView>();
  3004. List<YOYReturnView> costYOYData = new List<YOYReturnView>();
  3005. List<YOYReturnView> grossProfitYOYData = new List<YOYReturnView>();
  3006. int monthIndex = 1;
  3007. while (monthIndex < 13)
  3008. {
  3009. var thisMonthData = thisYearData.Where(x => x.Month == monthIndex).ToList();
  3010. var lastMonthData = lastYearData.Where(x => x.Month == monthIndex).ToList();
  3011. var thisGroupIds = thisMonthData.Select(x => x.Id).ToList();
  3012. var lastGroupIds = lastMonthData.Select(x => x.Id).ToList();
  3013. decimal thisSalesAmount = thisMonthData.Sum(x => x?.SaleAmount ?? 0.00M),
  3014. lastSalesAmount = lastMonthData.Sum(x => x?.SaleAmount ?? 0.00M),
  3015. thisCostAmount = thisMonthData.Sum(x => x?.CostAmount ?? 0.00M),
  3016. lastCostAmount = lastMonthData.Sum(x => x?.CostAmount ?? 0.00M),
  3017. thisgrossProfitAmount = thisMonthData.Sum(x => x?.GrossProfitAmount ?? 0.00M),
  3018. lastgrossProfitAmount = lastMonthData.Sum(x => x?.GrossProfitAmount ?? 0.00M);
  3019. salesYOYData.Add(new YOYReturnView(_dto.Year, monthIndex, thisSalesAmount, lastSalesAmount, thisGroupIds, lastGroupIds));
  3020. costYOYData.Add(new YOYReturnView(_dto.Year, monthIndex, thisCostAmount, lastCostAmount, thisGroupIds, lastGroupIds));
  3021. grossProfitYOYData.Add(new YOYReturnView(_dto.Year, monthIndex, thisgrossProfitAmount, lastgrossProfitAmount, thisGroupIds, lastGroupIds));
  3022. monthIndex++;
  3023. }
  3024. salesYOYData = salesYOYData.OrderBy(x => x.Month).ToList();
  3025. costYOYData = costYOYData.OrderBy(x => x.Month).ToList();
  3026. grossProfitYOYData = grossProfitYOYData.OrderBy(x => x.Month).ToList();
  3027. return Ok(JsonView(true,"操作成功!", new { salesYOYData = salesYOYData, costYOYData = costYOYData, grossProfitYOYData = grossProfitYOYData }));
  3028. }
  3029. /// <summary>
  3030. /// 国交数据统计-机票相关
  3031. /// 1、机票票数、2、机票到达地
  3032. /// </summary>
  3033. /// <param name="_dto"></param>
  3034. /// <returns></returns>
  3035. [HttpPost("StatisticsAirTicket")]
  3036. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3037. public async Task<IActionResult> StatisticsAirTicket(YOYDto _dto)
  3038. {
  3039. if (_dto.Year < 1) return Ok(JsonView(false, "操作失败"));
  3040. string beginDt = $"{_dto.Year}-01-01 00:00:00",
  3041. endDt = $"{_dto.Year}-12-31 23:59:59";
  3042. string sql = string.Format(@"
  3043. SELECT
  3044. atr.DIId,
  3045. atr.FlightsDate,
  3046. YEAR(atr.FlightsDate) AS YEAR,
  3047. MONTH(atr.FlightsDate) AS MONTH,
  3048. atr.CType,
  3049. sd.Name As CTypeName,
  3050. atr.FlightsCity,
  3051. atr.ClientNum,
  3052. atr.ClientName
  3053. FROM
  3054. Grp_AirTicketReservations atr
  3055. INNER JOIN Grp_CreditCardPayment ccp ON atr.Id = ccp.CId
  3056. AND ccp.IsDel = 0
  3057. AND CTable = 85
  3058. Left Join Sys_SetData sd On atr.CType = sd.Id
  3059. WHERE
  3060. atr.IsDel = 0
  3061. And atr.CType IN(457,458,459,460,574,575)
  3062. AND CHARINDEX('行程单',atr.ClientName) = 0
  3063. AND CHARINDEX('返点',atr.ClientName) = 0
  3064. AND CHARINDEX('-1',atr.ClientName) = 0
  3065. AND ccp.IsPay = 1
  3066. AND atr.FlightsDate BETWEEN '{0}' AND '{1}'
  3067. ORDER BY atr.FlightsDate
  3068. ", beginDt, endDt);
  3069. var data = await _sqlSugar.SqlQueryable<StatisticsAirTicketView>(sql).ToListAsync();
  3070. var groupIds = data.Select(x => x.DIId).ToList();
  3071. //处理城市数据
  3072. var threeCodeData = await _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.IsDel == 0).ToListAsync();
  3073. //处理团组名称
  3074. var groupNames = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => groupIds.Contains(x.Id)).Select(x => new { Id = x.Id, GroupName = x.TeamName }).ToListAsync();
  3075. data.ForEach(x => {
  3076. string cityName = "";
  3077. if (!string.IsNullOrEmpty(x.FlightsCity))
  3078. {
  3079. string cityCode = x.FlightsCity.Replace("-", "").Replace("/", "");
  3080. int cityNum = cityCode.Length / 3;
  3081. if (cityCode.Length % 3 == 0)
  3082. {
  3083. for (int i = 0; i < cityNum; i++)
  3084. {
  3085. string code = "";
  3086. if (i == 0) code = cityCode.Substring(0, 3);
  3087. else code = cityCode.Substring(i * 3, 3);
  3088. if (!string.IsNullOrEmpty(code))
  3089. {
  3090. if (i == cityNum-1)
  3091. {
  3092. cityName += threeCodeData.Find(x => x.Three.Equals(code))?.City ?? "";
  3093. }
  3094. else
  3095. {
  3096. string str1 = threeCodeData.Find(x => x.Three.Equals(code))?.City ?? "";
  3097. cityName += str1 + "、";
  3098. }
  3099. }
  3100. }
  3101. }
  3102. }
  3103. x.FlightsCityName = cityName;
  3104. });
  3105. var airTicketNumData = new List<AirTicketReturnView>();
  3106. var airTicketAreaData = new List<AirTicketCityReturnView>();
  3107. int monthIndex = 1;
  3108. while (monthIndex < 13)
  3109. {
  3110. var monthData = data.Where(x => x.Month == monthIndex).ToList();
  3111. //机票票数处理
  3112. int airticket_quantity = monthData.Sum(x => x.ClientNum);
  3113. var linkGroupIds = monthData.Select(x => x.DIId).ToList();
  3114. List<AitTicketInfo> aitTicketInfos = new List<AitTicketInfo>();
  3115. foreach (var item in monthData)
  3116. {
  3117. string groupName = groupNames.Find(x => item.DIId == x.Id)?.GroupName ?? "";
  3118. aitTicketInfos.Add(new AitTicketInfo(item.DIId,groupName,item.ClientNum));
  3119. }
  3120. var aitTicketInfosGroupBy = aitTicketInfos.GroupBy(x => x.Id);
  3121. List<AitTicketInfo> aitTicketInfos1 = new List<AitTicketInfo>();
  3122. foreach (var item in aitTicketInfosGroupBy)
  3123. {
  3124. aitTicketInfos1.Add(new AitTicketInfo(item.Key, item.First().GroupName, item.Sum(x => x.Quantity)));
  3125. }
  3126. aitTicketInfos1 = aitTicketInfos1.OrderBy(x => x.Quantity).ToList();
  3127. linkGroupIds = linkGroupIds.Distinct().ToList();
  3128. airTicketNumData.Add(new AirTicketReturnView(_dto.Year, monthIndex, airticket_quantity, aitTicketInfos1,linkGroupIds));
  3129. //机票城市处理
  3130. //城市处理
  3131. List<string> airTicketCityInfos = new List<string>();
  3132. foreach (var item in monthData)
  3133. {
  3134. if (!string.IsNullOrEmpty(item.FlightsCityName))
  3135. {
  3136. if (item.FlightsCityName.Contains("、"))
  3137. {
  3138. var cityArray = item.FlightsCityName.Split("、").ToList();
  3139. foreach (var item1 in cityArray)
  3140. {
  3141. if (!string.IsNullOrEmpty(item.FlightsCityName))
  3142. {
  3143. airTicketCityInfos.Add(item1);
  3144. }
  3145. }
  3146. }
  3147. else
  3148. {
  3149. airTicketCityInfos.Add(item.FlightsCityName);
  3150. }
  3151. }
  3152. }
  3153. //int quantity1 = airTicketCityInfos.Count;
  3154. int city_totalquantity = 0;
  3155. var airTicketCityInfosGroupby = airTicketCityInfos.GroupBy(x => x);
  3156. var airTicketCityInfos1 = new List<AirTicketCityInfo>();
  3157. foreach (var item in airTicketCityInfosGroupby)
  3158. {
  3159. var city_quantity = item.ToList().Count;
  3160. city_totalquantity += city_quantity;
  3161. airTicketCityInfos1.Add(new AirTicketCityInfo(item.Key, city_quantity));
  3162. }
  3163. airTicketCityInfos1 = airTicketCityInfos1.OrderByDescending(x => x.Quantity).ToList();
  3164. airTicketAreaData.Add(new AirTicketCityReturnView(_dto.Year, monthIndex, city_totalquantity, airTicketCityInfos1, linkGroupIds));
  3165. monthIndex++;
  3166. }
  3167. return Ok(JsonView(true, "操作成功!", new { airTicketNumData = airTicketNumData, airTicketAreaData = airTicketAreaData }));
  3168. }
  3169. /// <summary>
  3170. /// 国交数据统计-酒店相关、商要邀请
  3171. /// 酒店预订地区TOP10排序、酒店房型地区间数、商邀邀请国家数量TOP10
  3172. /// </summary>
  3173. /// <param name="_dto"></param>
  3174. /// <returns></returns>
  3175. [HttpPost("StatisticsHotel")]
  3176. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3177. public async Task<IActionResult> StatisticsHotel()
  3178. {
  3179. string sql = string.Format(@"
  3180. SELECT
  3181. hr.DIId,
  3182. hr.City,
  3183. hr.HotelName,
  3184. sd.Name AS BookinSite,
  3185. hr.CheckInDate,
  3186. YEAR(hr.CheckInDate) AS YEAR,
  3187. MONTH(hr.CheckInDate) AS MONTH,
  3188. hr.CheckOutDate,
  3189. hr.SingleRoomCount,
  3190. hr.DoubleRoomCount,
  3191. hr.SuiteRoomCount,
  3192. hr.OtherRoomCount
  3193. FROM
  3194. Grp_HotelReservations hr
  3195. INNER JOIN Grp_CreditCardPayment ccp ON hr.Id = ccp.CId
  3196. AND ccp.IsDel = 0
  3197. AND CTable = 85
  3198. LEFT JOIN Sys_SetData sd ON hr.ReservationsWebsite = sd.Id
  3199. WHERE
  3200. hr.IsDel = 0
  3201. AND ccp.IsPay = 1
  3202. ORDER BY
  3203. hr.CheckInDate
  3204. ");
  3205. var data = await _sqlSugar.SqlQueryable<StatisticsHotelView>(sql).ToListAsync();
  3206. var hotelData = data.OrderBy(x => x.CityStr).ToList();
  3207. var airTicketNumData = new List<AirTicketReturnView>();
  3208. var airTicketAreaData = new List<AirTicketCityReturnView>();
  3209. int monthIndex = 1;
  3210. while (monthIndex < 13)
  3211. {
  3212. monthIndex++;
  3213. }
  3214. return Ok(JsonView(true, "操作成功!", new { hotelData = hotelData, airTicketAreaData = airTicketAreaData }));
  3215. }
  3216. #endregion
  3217. }
  3218. }