StatisticsController.cs 142 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757
  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. namespace OASystem.API.Controllers
  29. {
  30. /// <summary>
  31. /// 统计模块
  32. /// </summary>
  33. [Route("api/[controller]")]
  34. [ApiController]
  35. public class StatisticsController : ControllerBase
  36. {
  37. private readonly int _decimalPlaces;
  38. private readonly IMapper _mapper;
  39. private readonly SqlSugarClient _sqlSugar;
  40. private readonly DelegationInfoRepository _groupRep;
  41. private readonly SetDataRepository _setDataRep;
  42. private readonly TeamRateRepository _teamRateRep;
  43. private readonly VisitingClientsRepository _visitingClientsRep;
  44. /// <summary>
  45. /// Init
  46. /// </summary>
  47. /// <param name="mapper"></param>
  48. /// <param name="sqlSugar"></param>
  49. /// <param name="groupRep"></param>
  50. /// <param name="setDataRep"></param>
  51. public StatisticsController(IMapper mapper, SqlSugarClient sqlSugar, DelegationInfoRepository groupRep, SetDataRepository setDataRep, TeamRateRepository teamRate, VisitingClientsRepository visitingClientsRep)
  52. {
  53. _mapper = mapper;
  54. _groupRep = groupRep;
  55. _setDataRep = setDataRep;
  56. _sqlSugar = sqlSugar;
  57. _teamRateRep = teamRate;
  58. _visitingClientsRep = visitingClientsRep;
  59. }
  60. #region 团组报表
  61. /// <summary>
  62. /// 团组报表
  63. /// Items
  64. /// </summary>
  65. /// <param name="_dto">团组列表请求dto</param>
  66. /// <returns></returns>
  67. [HttpPost("PostGroupStatementItems")]
  68. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  69. public async Task<IActionResult> PostGroupStatementItems(GroupStatementItemsDto _dto)
  70. {
  71. #region 参数验证
  72. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  73. if (_dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  74. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  75. #region 页面操作权限验证
  76. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  77. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  78. #endregion
  79. #endregion
  80. if (_dto.PortType == 1 || _dto.PortType == 2 || _dto.PortType == 3) // web/Android/IOS
  81. {
  82. string sqlWhere = string.Empty;
  83. if (_dto.IsSure == 0) //未完成
  84. {
  85. sqlWhere += string.Format(@" And IsSure = 0");
  86. }
  87. else if (_dto.IsSure == 1) //已完成
  88. {
  89. sqlWhere += string.Format(@" And IsSure = 1");
  90. }
  91. if (!string.IsNullOrEmpty(_dto.SearchCriteria))
  92. {
  93. string tj = _dto.SearchCriteria;
  94. 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}%')",
  95. tj, tj, tj, tj, tj);
  96. }
  97. string sql = string.Format(@"Select row_number() over(order by gdi.VisitDate Desc) as Row_Number,
  98. gdi.Id,TourCode,ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,
  99. ClientName,ClientUnit,VisitDate,ssd.Id TeamTypeId, ssd.Name TeamType,
  100. VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure,gdi.CreateTime,
  101. pr.LastCollectionTime
  102. From Grp_DelegationInfo gdi
  103. Left Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  104. Left Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  105. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  106. Left Join (
  107. SELECT Diid, MAX(CreateTime) LastCollectionTime
  108. FROM Fin_ProceedsReceived
  109. Where IsDel = 0
  110. GROUP BY Diid
  111. ) pr On gdi.Id = pr.Diid
  112. Where gdi.IsDel = 0 {0} ", sqlWhere);
  113. RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
  114. var _DelegationList = await _sqlSugar.SqlQueryable<GroupStatementItemView>(sql).ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);//ToPageAsync
  115. var _view = new
  116. {
  117. PageFuncAuth = pageFunAuthView,
  118. Data = _DelegationList
  119. };
  120. return Ok(JsonView(true, "查询成功!", _view, total));
  121. }
  122. else
  123. {
  124. return Ok(JsonView(false, "查询失败"));
  125. }
  126. }
  127. /// <summary>
  128. /// 团组报表
  129. /// Details
  130. /// </summary>
  131. /// <param name="_dto">团组列表请求dto</param>
  132. /// <returns></returns>
  133. [HttpPost("PostGroupStatementDetails")]
  134. //[JsonConverter(typeof(DecimalConverter), 2)]
  135. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  136. public async Task<IActionResult> PostGroupStatementDetails(GroupStatementDetailsDto _dto)
  137. {
  138. /*
  139. * 团组报表计算方式
  140. * 当前总支出 = 团组支出.Sum() + 超支费用.Sum()
  141. * 应收金额 = 应收表.Sum()
  142. * 已收金额 = 已收表.Sum()
  143. * 应收利润(应收-支出) = 应收金额 - 收款退还 - 当前总支出
  144. * 已收利润(已收-支出) = 已收金额 - 收款退还 - 当前总支出
  145. *
  146. */
  147. #region 参数验证
  148. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  149. if (_dto.PageId < 1) _dto.PageId = 38; //团组报表页面Id
  150. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  151. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  152. #region 页面操作权限验证
  153. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  154. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  155. #endregion
  156. #endregion
  157. if (_dto.PortType == 1 || _dto.PortType == 2 || _dto.PortType == 3) // web/Android/IOS
  158. {
  159. GroupStatementDetailsView _view = new GroupStatementDetailsView();
  160. #region 费用类型 币种,转账,客户信息
  161. List<Sys_SetData> _setDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToListAsync();
  162. var _clientDatas = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync();
  163. #endregion
  164. #region 团组收入
  165. GroupIncomeView _giView = new GroupIncomeView();
  166. /*
  167. * 应收报表
  168. */
  169. decimal frTotalAmount = 0.00M;//应收总金额
  170. string _frSql = string.Format(@"Select fr.Id,fr.Diid,fr.PriceName,fr.Price,fr.Count,fr.Unit,fr.Currency,
  171. sd.Name As CurrencyCode,sd.Remark As CurrencyName,fr.Rate,fr.ItemSumPrice,fr.CreateTime
  172. From Fin_ForeignReceivables fr
  173. Left Join Sys_SetData sd On fr.Currency = sd.Id
  174. Where fr.IsDel = 0 And fr.Diid = {0} Order By CreateTime", _dto.DiId);
  175. List<Gsd_ForeignReceivablesView> _frViews = await _sqlSugar.SqlQueryable<Gsd_ForeignReceivablesView>(_frSql).ToListAsync();
  176. frTotalAmount = _frViews.Sum(it => it.ItemSumPrice);
  177. _giView.Receivables = _frViews;
  178. _giView.ReceivableStr = string.Format(@"应收款合计:{0} CNY(人民币)", frTotalAmount.ConvertToDecimal1().ToString("#0.00"));
  179. /*
  180. * 已收报表
  181. */
  182. decimal prTotalAmount = 0.00M;//已收总金额
  183. string _prSql = string.Format(@"Select pr.Id,pr.Diid,pr.SectionTime As SectionTimeDt,pr.Price,pr.Currency,
  184. sd1.Name As CurrencyCode,sd1.Remark As CurrencyName,pr.Client,
  185. pr.ReceivablesType,sd2.Name As ReceivablesTypeName,pr.Remark,pr.CreateTime
  186. From Fin_ProceedsReceived pr
  187. Left Join Sys_SetData sd1 On pr.Currency = sd1.Id
  188. Left Join Sys_SetData sd2 On pr.ReceivablesType = sd2.Id
  189. Where pr.IsDel = 0 and pr.Diid = {0} Order By CreateTime", _dto.DiId);
  190. List<Gsd_ProceedsReceivedView> _prViews = await _sqlSugar.SqlQueryable<Gsd_ProceedsReceivedView>(_prSql).ToListAsync();
  191. prTotalAmount = _prViews.Sum(it => it.Price);
  192. _giView.ProceedsReceivedViews = _prViews;
  193. _giView.ProceedsReceivedStr = string.Format(@$"应收合计:{frTotalAmount.ToString("#0.00")} CNY 已收款合计:{prTotalAmount.ConvertToDecimal1().ToString("#0.00")} CNY");
  194. /*
  195. * 超支费用
  196. */
  197. decimal exTotalAmount = 0.00M;
  198. 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,
  199. (gec.PriceSum * gec.Coefficient * ccp.DayRate) As CNYPrice,ccp.DayRate,ccp.Payee,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  200. sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant,gec.CreateTime
  201. From OA2023DB.dbo.Fin_GroupExtraCost gec
  202. Left Join Grp_CreditCardPayment ccp On gec.Id = ccp.CId
  203. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  204. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  205. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  206. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  207. 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);
  208. List<Gsd_ExtraCostsView> _ExtraCostsViews = await _sqlSugar.SqlQueryable<Gsd_ExtraCostsView>(_ecSql).ToListAsync();
  209. #region 超支费用 - 模拟数据
  210. //if (_ExtraCostsViews.Count < 1)
  211. //{
  212. // _ExtraCostsViews.Add(new Gsd_ExtraCostsView()
  213. // {
  214. // GECId = 0,
  215. // GECDiId = 2334,
  216. // PriceName = "模拟数据-超支费用名称",
  217. // PayMoney = 1000.00M,
  218. // PaymentCurrency = "CNY",
  219. // DayRate = 1.0000M,
  220. // CNYPrice = 1000.00M,
  221. // Payee = "模拟数据-超支费用收款方",
  222. // OrbitalPrivateTransfer = 1,
  223. // PayWay = "刷卡",
  224. // CardType = "招行卡",
  225. // IsPay = 1,
  226. // Applicant = "刘华举"
  227. // });
  228. // _ExtraCostsViews.Add(new Gsd_ExtraCostsView()
  229. // {
  230. // GECId = 0,
  231. // GECDiId = 2334,
  232. // PriceName = "模拟数据-超支费用名称",
  233. // PayMoney = 1000.00M,
  234. // PaymentCurrency = "CNY",
  235. // DayRate = 1.0000M,
  236. // CNYPrice = 1000.00M,
  237. // Payee = "模拟数据-超支费用收款方",
  238. // OrbitalPrivateTransfer = 1,
  239. // PayWay = "刷卡",
  240. // CardType = "招行卡",
  241. // IsPay = 1,
  242. // Applicant = "刘华举"
  243. // });
  244. //}
  245. #endregion
  246. exTotalAmount = _ExtraCostsViews.Sum(it => it.CNYPrice);
  247. _giView.ExtraCostsViews = _ExtraCostsViews;
  248. _giView.ExtraCostsStr = string.Format(@"人民币总费用:{0} CNY", exTotalAmount.ConvertToDecimal1().ToString("#0.00"));
  249. /*
  250. * 收款退还
  251. */
  252. decimal promTotalAmount = 0.00M;// 收款退还总金额
  253. List<Gsd_PaymentRefundAndOtherMoneyView> _promView = new List<Gsd_PaymentRefundAndOtherMoneyView>();
  254. //删除了 And prom.PriceType = 1
  255. string _ropSql = string.Format(@"Select u.CnName As Appliction,prom.Id As PrId,prom.DiId As PrDiId,prom.Price As PrPrice,
  256. prom.PriceName AS PrPriceName,prom.CurrencyId As PrCurrencyId,
  257. prom.PayType As PrPayType,prom.PriceType As PrPriceType,ccp.*,prom.CreateTime As PrCreateTime
  258. From Fin_PaymentRefundAndOtherMoney prom
  259. Left Join Grp_CreditCardPayment ccp On prom.DiId = ccp.DIId And prom.Id = ccp.CId
  260. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  261. Where prom.IsDel = 0 And prom.PayType = 1 And ccp.CTable = 285
  262. And ccp.IsAuditGM = 1 And ccp.IsPay = 1
  263. And prom.DiId = {0} Order By PrCreateTime", _dto.DiId);
  264. var _promDatas = await _sqlSugar.SqlQueryable<Gsd_PaymentRefundAndOtherMoneyDataSource1View>(_ropSql).ToListAsync();
  265. foreach (var ropItem in _promDatas)
  266. {
  267. string thisCueencyCode = "Unknown";
  268. string thisCueencyName = "Unknown";
  269. var currency = _setDatas.Where(it => it.Id == ropItem.PaymentCurrency).FirstOrDefault();
  270. if (currency != null)
  271. {
  272. thisCueencyCode = currency.Name;
  273. thisCueencyName = currency.Remark;
  274. }
  275. string orbitalPrivateTransferStr = "Unknown";
  276. var orbitalPrivateTransfer = _setDatas.Where(it => it.Id == ropItem.OrbitalPrivateTransfer).FirstOrDefault();
  277. if (orbitalPrivateTransfer != null)
  278. {
  279. orbitalPrivateTransferStr = orbitalPrivateTransfer.Name;
  280. }
  281. string payStr = "Unknown";
  282. var pay = _setDatas.Where(it => it.Id == ropItem.PayDId).FirstOrDefault();
  283. if (pay != null)
  284. {
  285. payStr = pay.Name;
  286. }
  287. Gsd_PaymentRefundAndOtherMoneyView gsd_PaymentRefund = new Gsd_PaymentRefundAndOtherMoneyView()
  288. {
  289. Id = ropItem.Id,
  290. DiId = ropItem.DIId,
  291. PriceName = ropItem.PrPriceName,
  292. PayCurrencyCode = thisCueencyCode,
  293. PayCurrencyName = thisCueencyName,
  294. Price = ropItem.PrPrice,
  295. CNYPrice = ropItem.RMBPrice,
  296. ThisRate = ropItem.DayRate,
  297. Payee = ropItem.Payee,
  298. PayTime = ropItem.AuditGMDate,
  299. OrbitalPrivateTransfer = ropItem.OrbitalPrivateTransfer,
  300. PayType = payStr,
  301. IsPay = ropItem.IsPay,
  302. Applicant = ropItem.Appliction
  303. };
  304. _promView.Add(gsd_PaymentRefund);
  305. }
  306. #region 收款退还 - 模拟数据
  307. //if (_promView.Count < 1)
  308. //{
  309. // _promView.Add(new Gsd_PaymentRefundAndOtherMoneyView()
  310. // {
  311. // Id = 0,
  312. // DiId = 2334,
  313. // PriceName = "模拟数据-费用名称",
  314. // PayCurrencyCode = "CNY",
  315. // PayCurrencyName = "人民币",
  316. // Price = 1000.00M,
  317. // CNYPrice = 1000.00M,
  318. // ThisRate = 1.00M,
  319. // Payee = "模拟数据-收款方",
  320. // PayTime = "2023-01-01 15:20:01",
  321. // OrbitalPrivateTransfer = 1,
  322. // PayType = "刷卡",
  323. // IsPay = 1,
  324. // Applicant = "刘华举"
  325. // });
  326. // _promView.Add(new Gsd_PaymentRefundAndOtherMoneyView()
  327. // {
  328. // Id = 0,
  329. // DiId = 2334,
  330. // PriceName = "模拟数据-费用名称",
  331. // PayCurrencyCode = "CNY",
  332. // PayCurrencyName = "人民币",
  333. // Price = 1000.00M,
  334. // CNYPrice = 1000.00M,
  335. // ThisRate = 1.00M,
  336. // Payee = "模拟数据-收款方",
  337. // PayTime = "2023-01-01 15:20:01",
  338. // OrbitalPrivateTransfer = 1,
  339. // PayType = "刷卡",
  340. // IsPay = 1,
  341. // Applicant = "刘华举"
  342. // });
  343. //}
  344. #endregion
  345. promTotalAmount = _promView.Sum(it => it.CNYPrice);
  346. _giView.PaymentRefundAndOtherMoneyViews = _promView;
  347. _giView.PaymentRefundAndOtherMoneyStr = string.Format(@"人民币总费用:{0} CNY", promTotalAmount.ConvertToDecimal1().ToString("#0.00"));
  348. decimal BalancePayment = frTotalAmount - prTotalAmount + promTotalAmount;
  349. _view.GroupIncome = _giView;
  350. _view.GroupIncomeStr = string.Format(@"<span style='color:red;'>剩余尾款:{0} CNY(包含了收款退还费用数据)</span>", BalancePayment.ConvertToDecimal1().ToString("#0.00"));
  351. #endregion
  352. #region 团组支出
  353. GroupExpenditureView _geView = new GroupExpenditureView();
  354. #region 酒店预定费用
  355. List<GroupHotelFeeView> groupHotelFeeViews = new List<GroupHotelFeeView>();
  356. //ccp.RMBPrice As CNYPrice
  357. //(((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice
  358. string hotelFeeSql = string.Format(@"Select hr.Id As HrId,hr.DiId As HrDiId,hr.City,hr.HotelName,hr.CheckInDate,hr.CheckOutDate,
  359. sd1.Name As PaymentCurrency,hr.SingleRoomPrice,hr.SingleRoomCount,hr.DoubleRoomPrice,
  360. hr.DoubleRoomCount,hr.SuiteRoomPrice,hr.SuiteRoomCount,hr.OtherRoomPrice,hr.OtherRoomCount,
  361. hr.BreakfastPrice,sd4.Name As BreakfastCurrency,hr.Isoppay,hr.GovernmentRent,
  362. sd5.Name As GovernmentRentCurrency,hr.CityTax,sd6.Name As CityTaxCurrency,
  363. ccp.PayMoney,(((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice,ccp.DayRate,ccp.Payee,ccp.OrbitalPrivateTransfer,
  364. sd2.Name As PayWay,sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant
  365. From Grp_HotelReservations hr
  366. Left Join Grp_CreditCardPayment ccp On hr.Id = ccp.CId
  367. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  368. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  369. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  370. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  371. Left Join Sys_SetData sd4 On hr.BreakfastCurrency = sd4.Id
  372. Left Join Sys_SetData sd5 On hr.GovernmentRentCurrency = sd5.Id
  373. Left Join Sys_SetData sd6 On hr.CityTaxCurrency = sd6.Id
  374. Where hr.IsDel = 0 And ccp.IsDel = 0 And ccp.CTable = 76 And ccp.IsAuditGM = 1 And ccp.PayMoney<> 0 And hr.DiId = {0}
  375. Order By CheckInDate Asc", _dto.DiId);
  376. groupHotelFeeViews = await _sqlSugar.SqlQueryable<GroupHotelFeeView>(hotelFeeSql).ToListAsync();
  377. List<int> hotelSubIds = groupHotelFeeViews.Select(it => it.HrId).ToList();
  378. List<Grp_HotelReservationsContent> groupHotelContentFeeViews = new List<Grp_HotelReservationsContent>();
  379. groupHotelContentFeeViews = await _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => hotelSubIds.Contains(it.HrId)).ToListAsync();
  380. decimal HotelCNYTotalPrice = 0.00M;
  381. var teamRateData = await _teamRateRep.PostGroupRateInfoByDiId(_dto.DiId);
  382. foreach (var item in groupHotelFeeViews)
  383. {
  384. var roomData = groupHotelContentFeeViews.Find(it => it.HrId == item.HrId && it.PriceType == 1); //房费
  385. item.RoomPrice = roomData?.Price ?? 0.00M;
  386. item.RoomPriceCurrency = _setDatas.Find(it => it.Id == roomData?.Currency)?.Name;
  387. string feeMark1 = roomData?.OrbitalPrivateTransfer == 0 ? "公转" : "私转";
  388. string isFeeMark1 = roomData?.IsOppay == 1 ? "是" : "否";
  389. item.RoomInfoTips = @$"当时汇率:{roomData?.Rate.ToString("#0.0000")} <br/>
  390. 收款方:{roomData?.Payee}<br/>
  391. 费用标识:{feeMark1} <br/>
  392. 支付方式:{_setDatas.Find(it => it.Id == roomData?.PayDId)?.Name} <br/>
  393. 卡类型:{_setDatas.Find(it => it.Id == roomData?.CTDId)?.Name}
  394. 是否由地接支付:{isFeeMark1} <br/>";
  395. var breakfastData = groupHotelContentFeeViews.Find(it => it.HrId == item.HrId && it.PriceType == 2); //早餐
  396. item.BreakfastPrice = breakfastData?.Price ?? 0.00M;
  397. item.BreakfastCurrency = _setDatas.Find(it => it.Id == breakfastData?.Currency)?.Name;
  398. string feeMark2 = breakfastData?.OrbitalPrivateTransfer == 0 ? "公转" : "私转";
  399. string isFeeMark2 = breakfastData?.IsOppay == 1 ? "是" : "否";
  400. item.BreakfastInfoTips = @$"当时汇率:{breakfastData?.Rate.ToString("#0.0000")} <br/>
  401. 收款方:{breakfastData?.Payee}<br/>
  402. 费用标识:{feeMark2} <br/>
  403. 支付方式:{_setDatas.Find(it => it.Id == roomData?.PayDId)?.Name} <br/>
  404. 卡类型:{_setDatas.Find(it => it.Id == roomData?.CTDId)?.Name} <br/>
  405. 是否由地接支付:{isFeeMark2} <br/>";
  406. var landTaxData = groupHotelContentFeeViews.Find(it => it.HrId == item.HrId && it.PriceType == 3); //地税
  407. item.GovernmentRent = landTaxData?.Price ?? 0.00M;
  408. item.GovernmentRentCurrency = _setDatas.Find(it => it.Id == landTaxData?.Currency)?.Name;
  409. string feeMark3 = landTaxData?.OrbitalPrivateTransfer == 0 ? "公转" : "私转";
  410. string isFeeMark3 = landTaxData?.IsOppay == 1 ? "是" : "否";
  411. item.GovernmentRentTips = @$"当时汇率:{landTaxData?.Rate.ToString("#0.0000")} <br/>
  412. 收款方:{landTaxData?.Payee}<br/>
  413. 费用标识:{feeMark3} <br/>
  414. 支付方式:{_setDatas.Find(it => it.Id == landTaxData?.PayDId)?.Name} <br/>
  415. 卡类型:{_setDatas.Find(it => it.Id == landTaxData?.CTDId)?.Name} <br/>
  416. 是否由地接支付:{isFeeMark3} <br/>";
  417. var cityTaxData = groupHotelContentFeeViews.Find(it => it.HrId == item.HrId && it.PriceType == 4); //城市税
  418. item.CityTax = cityTaxData?.Price ?? 0.00M;
  419. item.CityTaxCurrency = _setDatas.Find(it => it.Id == cityTaxData?.Currency)?.Name;
  420. string feeMark4 = cityTaxData?.OrbitalPrivateTransfer == 0 ? "公转" : "私转";
  421. string isFeeMark4 = landTaxData?.IsOppay == 1 ? "是" : "否";
  422. item.CityTaxTips = @$"当时汇率:{cityTaxData?.Rate.ToString("#0.0000")} <br/>
  423. 收款方:{cityTaxData?.Payee}<br/>
  424. 费用标识:{feeMark4} <br/>
  425. 支付方式:{_setDatas.Find(it => it.Id == cityTaxData?.PayDId)?.Name} <br/>
  426. 卡类型:{_setDatas.Find(it => it.Id == cityTaxData?.CTDId)?.Name} <br/>
  427. 是否由地接支付:{isFeeMark4} <br/>";
  428. HotelCNYTotalPrice += item.CNYPrice;
  429. item.PayMoney = item.PayMoney.ConvertToDecimal1();
  430. item.CNYPrice = item.CNYPrice.ConvertToDecimal1();
  431. }
  432. _geView.GroupHotelFeeViews = groupHotelFeeViews;
  433. _geView.GroupHotelFeeStr = string.Format(@"人民币总费用:{0} CNY", HotelCNYTotalPrice.ToString("#0.00"));
  434. #endregion
  435. #region 地接费用
  436. List<GroupCTGGRFeeView> groupCTGGRFeeViews = new List<GroupCTGGRFeeView>();
  437. string CTGGRFeeSql = string.Format(@"Select ctggr.Id As CTGGRId,ctggr.DiId As CTGGRDiId,ctggr.PriceName As Area,ctggrc.*,ctggrc.Price As PayMoney,
  438. sd2.name As PaymentCurrency,ccp.PayPercentage,
  439. (ctggrc.Price / (ccp.PayPercentage / 100)) As AmountPaid,
  440. (ctggrc.Price / (ccp.PayPercentage / 100) - ctggrc.Price) As BalancePayment,
  441. ccp.DayRate,(ctggrc.Price * ccp.DayRate) As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  442. ccp.OrbitalPrivateTransfer,sd1.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ctggr.CreateTime
  443. From Grp_CarTouristGuideGroundReservations ctggr
  444. Left Join ( Select cggrc.CTGGRId,sd1.Name As PriceName,cggrc.Price,sd2.Name As PriceCurrency,
  445. cggrc.PriceContent
  446. From Grp_CarTouristGuideGroundReservationsContent cggrc
  447. Left Join Sys_SetData sd1 On cggrc.SId = sd1.Id
  448. Left Join Sys_SetData sd2 On cggrc.Currency = sd2.Id
  449. Where cggrc.ISdel = 0 And cggrc.Price != 0.00
  450. ) ctggrc On ctggr.Id = ctggrc.CTGGRId
  451. Left Join Grp_CreditCardPayment ccp On ccp.IsDel = 0 And ccp.CTable = 79 And ctggr.Id = ccp.CId
  452. Left Join Sys_SetData sd1 On ccp.PayDId = sd1.Id
  453. Left Join Sys_SetData sd2 On ccp.PaymentCurrency = sd2.Id
  454. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  455. Where ctggr.IsDel = 0 And ccp.IsAuditGM = 1 And ctggr.DiId = {0}
  456. Order By CreateTime", _dto.DiId);
  457. groupCTGGRFeeViews = await _sqlSugar.SqlQueryable<GroupCTGGRFeeView>(CTGGRFeeSql).ToListAsync();
  458. string CTGGRFeeStr = "";
  459. decimal CTGGRCNYTotalPrice = 0.00M;
  460. //按1 地区,2 币种,3 汇率 分组计算
  461. var groupCTGGRFeeDatas = groupCTGGRFeeViews.GroupBy(it => it.Area);
  462. foreach (var ctggfr in groupCTGGRFeeDatas)
  463. {
  464. var ctggfr_curr = ctggfr.GroupBy(it => it.PaymentCurrency);
  465. if (ctggfr_curr.Count() > 0)
  466. {
  467. foreach (var curr in ctggfr_curr)
  468. {
  469. var ctggfr_rate = curr.GroupBy(it => it.DayRate);
  470. if (ctggfr_rate.Count() > 0)
  471. {
  472. foreach (var rate in ctggfr_rate)
  473. {
  474. CTGGRFeeStr += string.Format(@$"{ctggfr.Key} 总费用:{rate.Sum(it => it.AmountPaid).ToString("#0.00")}
  475. {rate.FirstOrDefault()?.PaymentCurrency}(人民币:
  476. {rate.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00"))).ToString("#0.00")} CNY 当时支付汇率:
  477. {rate.FirstOrDefault()?.DayRate.ToString("#0.0000")})\r\n");
  478. CTGGRCNYTotalPrice += rate.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  479. }
  480. }
  481. else
  482. {
  483. CTGGRFeeStr += string.Format(@$"{ctggfr.Key} 总费用:{curr.Sum(it => it.AmountPaid).ToString("#0.00")}
  484. {curr.FirstOrDefault()?.PaymentCurrency}(人民币:
  485. {curr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00"))).ToString("#0.00")} CNY 当时支付汇率:
  486. {curr.FirstOrDefault()?.DayRate.ToString("#0.0000")})\r\n");
  487. CTGGRCNYTotalPrice += curr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  488. }
  489. }
  490. }
  491. else
  492. {
  493. CTGGRFeeStr += string.Format(@$"{ctggfr.Key} 总费用:{ctggfr.Sum(it => it.AmountPaid).ToString("#0.00")}
  494. {ctggfr.FirstOrDefault()?.PaymentCurrency}(人民币:
  495. {ctggfr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00"))).ToString("#0.00")} CNY 当时支付汇率:
  496. {ctggfr.FirstOrDefault()?.DayRate.ToString("#0.0000")})\r\n");
  497. CTGGRCNYTotalPrice += ctggfr.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  498. }
  499. }
  500. foreach (var item in groupCTGGRFeeViews)
  501. {
  502. if (!string.IsNullOrEmpty(item.AuditGMDate))
  503. {
  504. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  505. }
  506. //CTGGRFeeStr += string.Format(@"{0} 总费用:{1} {2}(人民币:{3} CNY 当时支付汇率:{4})\r\n",
  507. // item.Area, item.AmountPaid.ConvertToDecimal1().ToString("#0.00"), item.PaymentCurrency, item.CNYPrice.ToString("#0.0000"), item.DayRate.ToString("#0.0000"));
  508. //CTGGRCNYTotalPrice += item.CNYPrice;
  509. }
  510. _geView.GroupCTGGRFeeViews = groupCTGGRFeeViews;
  511. _geView.GroupCTGGRFeeStr = string.Format(@"{0}人民币总费用:{1} CNY", CTGGRFeeStr, CTGGRCNYTotalPrice.ToString("#0.00"));
  512. #endregion
  513. #region 机票预订费用
  514. //(((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice
  515. //ccp.RMBPrice As CNYPrice
  516. List<GroupAirFeeView> groupAirFeeViews = new List<GroupAirFeeView>();
  517. string groupAirFeeSql = string.Format(@"Select atr.Id As AirId,atr.DIId As AirDiId,atr.FlightsCode,atr.FlightsCity,sd4.Name As AirTypeName,
  518. atr.FlightsDate,atr.FlightsTime,atr.ClientName,atr.ClientNum,ccp.PayMoney,
  519. sd1.Name As PayMoneyCurrency,(((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice,ccp.DayRate,ccp.Payee,ccp.AuditGMDate,
  520. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant,atr.CreateTime,
  521. atr.CType
  522. From Grp_AirTicketReservations atr
  523. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 85 And atr.Id = ccp.CId
  524. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  525. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  526. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  527. Left Join Sys_SetData sd4 On atr.CType = sd4.Id
  528. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  529. Where atr.IsDel = 0 And ccp.IsAuditGM = 1 And atr.DiId = {0} Order By CreateTime", _dto.DiId);
  530. groupAirFeeViews = await _sqlSugar.SqlQueryable<GroupAirFeeView>(groupAirFeeSql).ToListAsync();
  531. string str = "";
  532. List<dynamic> airClientPris = new List<dynamic>();
  533. decimal AirCNYTotalPrice = 0.00M;
  534. decimal JJCCNYTotalPrice = 0.00M, JJCPeopleNum = 0.00M, JJCAveragePrice = 0.00M;
  535. decimal GWCCNYTotalPrice = 0.00M, GWCPeopleNum = 0.00M, GWCAveragePrice = 0.00M;
  536. //if (groupAirFeeViews.Count > 0)
  537. //{
  538. // JJCCNYTotalPrice = groupAirFeeViews.Where(it => it.AirTypeName.Equals("经济舱")).Sum(it => it.CNYPrice);
  539. // JJCPeopleNum = groupAirFeeViews.Where(it => it.AirTypeName.Equals("经济舱")).Sum(it => it.ClientNum);
  540. // JJCAveragePrice = (JJCCNYTotalPrice / JJCPeopleNum).ConvertToDecimal1();
  541. // GWCCNYTotalPrice = groupAirFeeViews.Where(it => it.AirTypeName.Equals("公务舱")).Sum(it => it.CNYPrice);
  542. // GWCPeopleNum = groupAirFeeViews.Where(it => it.AirTypeName.Equals("公务舱")).Sum(it => it.ClientNum);
  543. // GWCAveragePrice = (GWCCNYTotalPrice / GWCPeopleNum).ConvertToDecimal1();
  544. //}
  545. int Index = 0;
  546. foreach (var item in groupAirFeeViews)
  547. {
  548. if (item.AirId > 2924)
  549. {
  550. string itemClientName = "";
  551. if (!string.IsNullOrEmpty(item.ClientName))
  552. {
  553. System.Text.RegularExpressions.Match m_EnName = Regex.Match(item.ClientName, @"[A-Za-z]+");
  554. System.Text.RegularExpressions.Match m_ZHName = Regex.Match(item.ClientName, @"[\u4e00-\u9fa5]");
  555. if (m_EnName.Success || m_ZHName.Success)
  556. {
  557. itemClientName = item.ClientName;
  558. decimal unitCost = 0.00M;
  559. AirCNYTotalPrice += item.CNYPrice;
  560. continue;
  561. }
  562. string[] clientIds = new string[] { };
  563. if (item.ClientName.Contains(','))
  564. {
  565. clientIds = item.ClientName.Split(',');
  566. }
  567. else
  568. {
  569. clientIds = new string[] { item.ClientName };
  570. }
  571. if (clientIds.Length > 0)
  572. {
  573. int[] output = Array.ConvertAll<string, int>(clientIds, delegate (string s) { return int.Parse(s); });
  574. if (output.Contains(-1))
  575. {
  576. itemClientName += $@"行程单";
  577. output = output.Where(val => val != -1).ToArray();
  578. }
  579. var clients = _clientDatas.Where(it => output.Contains(it.Id)).ToList();
  580. decimal unitCost = 0.00M;
  581. unitCost = (item.PayMoney / item.ClientNum).ConvertToDecimal1();
  582. int clienIndex = 1;
  583. foreach (var client in clients)
  584. {
  585. airClientPris.Add(new
  586. {
  587. CnName = client.LastName + client.FirstName,
  588. EnName = client.Pinyin,
  589. Price = unitCost,
  590. AirType = item.AirTypeName
  591. });
  592. string six = "";
  593. if (client.Sex == 0) six = "Mr";
  594. else if (client.Sex == 1) six = "Ms";
  595. itemClientName += string.Format(@"{0}.{1} {2};", clienIndex, client.LastName + client.FirstName, six);
  596. clienIndex++;
  597. }
  598. }
  599. }
  600. item.ClientName = itemClientName;
  601. }
  602. else
  603. {
  604. string clientPinYinName = "";
  605. decimal unitCost = 0.00M;
  606. int cNum = item.ClientNum == 0 ? 1 : item.ClientNum;
  607. unitCost = (item.PayMoney / cNum).ConvertToDecimal1();
  608. Regex r = new Regex("[0-9]");
  609. string name1 = item.ClientName;
  610. name1 = r.Replace(name1, "");
  611. string[] clientNames = name1.Split('.');
  612. for (int i = 0; i < item.ClientNum; i++)
  613. {
  614. string name = "";
  615. if (clientNames.Length > 0)
  616. {
  617. int index = i + 1;
  618. if (index < clientNames.Length)
  619. {
  620. name = clientNames[index].Replace("MR", "").Replace("MS", "").Trim();
  621. if (!string.IsNullOrEmpty(name))
  622. {
  623. airClientPris.Add(new
  624. {
  625. CnName = name,
  626. EnName = name,
  627. Price = unitCost,
  628. AirType = item.AirTypeName
  629. });
  630. }
  631. //if (name.Length > 0)
  632. //{
  633. // string nameLastStr = name[name.Length - 1].ToString();
  634. // if (nameLastStr.IsNumeric())
  635. // {
  636. // name = name.Substring(0, name.Length - 1).Trim();
  637. // }
  638. //}
  639. }
  640. }
  641. clientPinYinName += string.Format(@"{0}.{1}出票价为:{2} CNY;", Index + 1, name, unitCost.ToString("#0.00"));
  642. }
  643. }
  644. if (!string.IsNullOrEmpty(item.AuditGMDate))
  645. {
  646. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  647. }
  648. AirCNYTotalPrice += item.CNYPrice;
  649. }
  650. _geView.GroupAirFeeViews = groupAirFeeViews;
  651. if (airClientPris.Count > 0)
  652. {
  653. var peoplePriStr = "";
  654. var airClientPris1 = airClientPris.GroupBy(item => item.CnName)
  655. .Select(group => group.First())
  656. .ToList();
  657. int airClientPrisIndex = 1;
  658. foreach (var item in airClientPris1)
  659. {
  660. decimal price = 0.00M;
  661. var prices = airClientPris.Where(it => it.CnName == item.CnName).ToList();
  662. foreach (var pri in prices)
  663. {
  664. price += pri.Price;
  665. }
  666. peoplePriStr += $@"{airClientPrisIndex}.{item.EnName}出票价为: {price.ToString("#0.00")} CNY;";
  667. airClientPrisIndex++;
  668. }
  669. if (!string.IsNullOrEmpty(peoplePriStr))
  670. {
  671. str = $@"其中:{peoplePriStr}";
  672. }
  673. //经济舱均价
  674. var airJJCPris = airClientPris.Where(it => it.AirType == "经济舱").ToList();
  675. if (airJJCPris.Count > 0)
  676. {
  677. decimal jjcTotalPrice = 0.00M;
  678. foreach (var item in airJJCPris)
  679. {
  680. jjcTotalPrice += item.Price;
  681. }
  682. decimal jjcPeopleNum = airJJCPris.GroupBy(item => item.CnName)
  683. .Select(group => group.First())
  684. .ToList().Count(); ;
  685. JJCAveragePrice = jjcTotalPrice / jjcPeopleNum;
  686. }
  687. //公务舱均价
  688. var airGWCPris = airClientPris.Where(it => it.AirType == "公务舱").ToList();
  689. if (airGWCPris.Count > 0)
  690. {
  691. decimal gwcTotalPrice = 0.00M;
  692. foreach (var item in airGWCPris)
  693. {
  694. gwcTotalPrice += item.Price;
  695. }
  696. decimal gwcPeopleNum = airGWCPris.GroupBy(item => item.CnName)
  697. .Select(group => group.First())
  698. .ToList().Count();
  699. GWCAveragePrice = gwcTotalPrice / gwcPeopleNum;
  700. }
  701. }
  702. _geView.GroupAirFeeStr = $@"人民币总费用:{AirCNYTotalPrice.ToString("#0.00")} CNY\r\n{str}\r\n经济舱均价为:{JJCAveragePrice.ToString("#0.00")}CNY/人;公务舱均价为:{GWCAveragePrice.ToString("#0.00")}CNY/人;";
  703. #endregion
  704. #region 签证费用
  705. List<GroupVisaFeeView> groupVisaFeeViews = new List<GroupVisaFeeView>();
  706. string groupVisaFeeSql = string.Format(@"Select vi.Id As VisaId,vi.DIId As VisaDiId,vi.VisaClient,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  707. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  708. sd3.Name As CardTypeName,ccp.IsPay,u.CnName As Applicant,vi.CreateTime,
  709. (((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice
  710. From Grp_VisaInfo vi
  711. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 80 And vi.Id = ccp.CId
  712. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  713. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  714. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  715. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  716. Where vi.IsDel = 0 And ccp.IsAuditGM = 1 And vi.DIId = {0} Order By CreateTime", _dto.DiId);
  717. groupVisaFeeViews = await _sqlSugar.SqlQueryable<GroupVisaFeeView>(groupVisaFeeSql).ToListAsync();
  718. decimal VisaCNYTotalPirce = 0.00M;
  719. foreach (var item in groupVisaFeeViews)
  720. {
  721. string itemClientName = "";
  722. string visaClients = item.VisaClient;
  723. if (!string.IsNullOrEmpty(visaClients))
  724. {
  725. string[] clientIds = new string[] { };
  726. if (visaClients.Contains(','))
  727. {
  728. clientIds = visaClients.Split(',');
  729. }
  730. else
  731. {
  732. clientIds = new string[] { visaClients };
  733. }
  734. if (clientIds.Length > 0)
  735. {
  736. List<int> clientIds1 = new List<int>() { };
  737. foreach (var clientIdStr in clientIds)
  738. {
  739. if (clientIdStr.IsNumeric())
  740. {
  741. clientIds1.Add(int.Parse(clientIdStr));
  742. }
  743. }
  744. if (clientIds1.Count > 0)
  745. {
  746. var clients = _clientDatas.Where(it => clientIds1.Contains(it.Id)).ToList();
  747. foreach (var client in clients)
  748. {
  749. itemClientName += $"{client.LastName + client.FirstName},";
  750. }
  751. }
  752. else
  753. {
  754. itemClientName = visaClients;
  755. }
  756. }
  757. }
  758. if (itemClientName.Length > 0)
  759. {
  760. itemClientName = itemClientName.Substring(0, itemClientName.Length - 1);
  761. }
  762. item.VisaClient = itemClientName;
  763. VisaCNYTotalPirce += item.CNYPrice;
  764. if (!string.IsNullOrEmpty(item.AuditGMDate))
  765. {
  766. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  767. }
  768. }
  769. _geView.GroupVisaFeeViews = groupVisaFeeViews;
  770. _geView.GroupVisaFeeStr = string.Format(@"人民币总费用:{0} CNY", VisaCNYTotalPirce.ConvertToDecimal1().ToString("#.00"));
  771. #endregion
  772. #region 邀请/公务活动 CTable = 81
  773. List<GroupInvitationalFeeView> groupInvitationalFeeViews = new List<GroupInvitationalFeeView>();
  774. string groupInvitationalFeeSql = string.Format(@"Select ioa.Id As IOAId,ioa.DiId As IOADiId,ioa.InviterArea,ioa.Inviter,ioa.InviteTime,
  775. ioa.InviteCost,sd3.Name As InviteCurrency,ioa.SendCost,sd4.Name As SendCurrency,ioa.EventsCost,
  776. sd5.Name As EventsCurrency,ioa.TranslateCost,sd6.Name As TranslateCurrency,ccp.PayMoney,
  777. sd7.Name As PaymentCurrency,ccp.RMBPrice As CNYPrice,(((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice2,ccp.Payee,ccp.AuditGMDate,
  778. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ioa.CreateTime
  779. From Grp_InvitationOfficialActivities ioa
  780. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 81 And ioa.Id = ccp.CId
  781. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  782. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  783. Left Join Sys_SetData sd3 On ioa.InviteCurrency = sd3.Id
  784. Left Join Sys_SetData sd4 On ioa.SendCurrency = sd4.Id
  785. Left Join Sys_SetData sd5 On ioa.EventsCurrency = sd5.Id
  786. Left Join Sys_SetData sd6 On ioa.TranslateCurrency = sd6.Id
  787. Left Join Sys_SetData sd7 On ccp.PaymentCurrency = sd7.Id
  788. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  789. Where ioa.IsDel = 0 And ccp.IsAuditGM = 1 And ioa.Diid = {0} Order By CreateTime", _dto.DiId);
  790. groupInvitationalFeeViews = await _sqlSugar.SqlQueryable<GroupInvitationalFeeView>(groupInvitationalFeeSql).ToListAsync();
  791. #region 邀请/公务活动 - 模拟数据
  792. //if (groupInvitationalFeeViews.Count < 1)
  793. //{
  794. // groupInvitationalFeeViews.Add(new GroupInvitationalFeeView()
  795. // {
  796. // IOAId = 0,
  797. // IOADiId = 2334,
  798. // InviterArea = "模拟数据-邀请方地区",
  799. // Inviter = "模拟数据-邀请方",
  800. // InviteTime = "2023-10-10",
  801. // InviteCost = 100.00M,
  802. // InviteCurrency = "EUR",
  803. // SendCost = 100.00M,
  804. // SendCurrency = "EUR",
  805. // EventsCost = 10000.00M,
  806. // EventsCurrency = "EUR",
  807. // TranslateCost = 300.00M,
  808. // TranslateCurrency = "EUR",
  809. // PayMoney = 10500.00M,
  810. // PaymentCurrency = "EUR",
  811. // CNYPrice = 76765.50M,
  812. // Payee = "模拟数据-收款方",
  813. // AuditGMDate = "2023-12-05",
  814. // OrbitalPrivateTransfer = 1,
  815. // PayWay = "刷卡",
  816. // IsPay = 1,
  817. // Applicant = "刘华举"
  818. // });
  819. // groupInvitationalFeeViews.Add(new GroupInvitationalFeeView()
  820. // {
  821. // IOAId = 0,
  822. // IOADiId = 2334,
  823. // InviterArea = "模拟数据-邀请方地区",
  824. // Inviter = "模拟数据-邀请方",
  825. // InviteTime = "2023-10-10",
  826. // InviteCost = 100.00M,
  827. // InviteCurrency = "EUR",
  828. // SendCost = 100.00M,
  829. // SendCurrency = "EUR",
  830. // EventsCost = 10000.00M,
  831. // EventsCurrency = "EUR",
  832. // TranslateCost = 300.00M,
  833. // TranslateCurrency = "EUR",
  834. // PayMoney = 10500.00M,
  835. // PaymentCurrency = "EUR",
  836. // CNYPrice = 76765.50M,
  837. // Payee = "模拟数据-收款方",
  838. // AuditGMDate = "2023-12-05",
  839. // OrbitalPrivateTransfer = 1,
  840. // PayWay = "刷卡",
  841. // IsPay = 1,
  842. // Applicant = "刘华举"
  843. // });
  844. //}
  845. #endregion
  846. decimal InvitationalCNYTotalPrice = 0.00M;
  847. foreach (var item in groupInvitationalFeeViews)
  848. {
  849. InvitationalCNYTotalPrice += item.CNYPrice2;
  850. if (!string.IsNullOrEmpty(item.AuditGMDate))
  851. {
  852. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  853. }
  854. string currencyRateStr = "";
  855. List<string> currencys = new List<string>();
  856. if (!string.IsNullOrEmpty(item.InviteCurrency)) currencys.Add(item.InviteCurrency);
  857. if (!string.IsNullOrEmpty(item.SendCurrency)) currencys.Add(item.SendCurrency);
  858. if (!string.IsNullOrEmpty(item.EventsCurrency)) currencys.Add(item.EventsCurrency);
  859. if (!string.IsNullOrEmpty(item.TranslateCurrency)) currencys.Add(item.TranslateCurrency);
  860. if (!string.IsNullOrEmpty(item.PaymentCurrency)) currencys.Add(item.PaymentCurrency);
  861. currencyRateStr = await GeneralMethod.PostGroupRateByCTableAndCurrency(teamRateData, 81, currencys);
  862. item.CurrencyRateStr = currencyRateStr;
  863. }
  864. _geView.GroupInvitationalFeeViews = groupInvitationalFeeViews;
  865. _geView.GroupInvitationalFeeStr = string.Format(@"人民币总费用:{0} CNY", InvitationalCNYTotalPrice.ToString("#.00"));
  866. #endregion
  867. #region 保险费用
  868. List<GroupInsuranceFeeView> groupInsuranceFeeViews = new List<GroupInsuranceFeeView>();
  869. string groupInsuranceFeeSql = string.Format(@"Select ic.Id As InsuranceId,ic.Diid As InsuranceDiId,ClientName,ccp.PayMoney,ccp.RMBPrice As CNYPrice,
  870. sd1.Name As PayMoneyCurrency,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  871. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ic.CreateTime
  872. From Grp_Customers ic
  873. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 82 And ic.Id = ccp.CId
  874. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  875. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  876. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  877. Where ic.IsDel = 0 And ccp.IsAuditGM = 1 And ic.DiId = {0} Order By CreateTime", _dto.DiId);
  878. groupInsuranceFeeViews = await _sqlSugar.SqlQueryable<GroupInsuranceFeeView>(groupInsuranceFeeSql).ToListAsync();
  879. decimal InsuranceCNYTotalPrice = 0.00M;
  880. foreach (var item in groupInsuranceFeeViews)
  881. {
  882. InsuranceCNYTotalPrice += item.CNYPrice;
  883. string itemClientName = "";
  884. string insClients = item.ClientName;
  885. if (!string.IsNullOrEmpty(insClients))
  886. {
  887. //System.Text.RegularExpressions.Match m_EnName = Regex.Match(item.ClientName, @"[A-Za-z]+");
  888. //System.Text.RegularExpressions.Match m_ZHName = Regex.Match(item.ClientName, @"[\u4e00-\u9fa5]");
  889. //if (m_EnName.Success || m_ZHName.Success)
  890. //{
  891. // itemClientName = insClients;
  892. // continue;
  893. //}
  894. string[] clientIds = new string[] { };
  895. if (insClients.Contains(','))
  896. {
  897. clientIds = insClients.Split(',');
  898. }
  899. else
  900. {
  901. clientIds = new string[] { insClients };
  902. }
  903. if (clientIds.Length > 0)
  904. {
  905. List<int> output = new List<int>();
  906. foreach (var clientId in clientIds)
  907. {
  908. if (clientId.IsNumeric())
  909. {
  910. output.Add(int.Parse(clientId));
  911. }
  912. }
  913. if (output.Count > 0)
  914. {
  915. var clients = _clientDatas.Where(it => output.Contains(it.Id)).ToList();
  916. foreach (var client in clients)
  917. {
  918. itemClientName += $"{client.LastName + client.FirstName},";
  919. }
  920. if (itemClientName.Length > 0)
  921. {
  922. itemClientName = itemClientName.Substring(0, itemClientName.Length - 1);
  923. }
  924. }
  925. else
  926. {
  927. itemClientName = insClients;
  928. }
  929. }
  930. }
  931. item.ClientName = itemClientName;
  932. if (!string.IsNullOrEmpty(item.AuditGMDate))
  933. {
  934. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  935. }
  936. }
  937. _geView.GroupInsuranceFeeViews = groupInsuranceFeeViews;
  938. _geView.GroupInsuranceFeeStr = string.Format(@"人民币总费用:{0} CNY", InsuranceCNYTotalPrice.ToString("#0.00"));
  939. #endregion
  940. #region 其他款项费用 98
  941. List<GroupDecreaseFeeView> groupDecreaseFeeViews = new List<GroupDecreaseFeeView>();
  942. string groupDecreaseFeeSql = string.Format(@"Select dp.Id As DPId,dp.DiId As DPDiId,dp.PriceName,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  943. (((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice,
  944. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  945. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,dp.CreateTime
  946. From Grp_DecreasePayments dp
  947. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 98 And dp.Id = ccp.CId
  948. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  949. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  950. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  951. Where dp.IsDel = 0 And ccp.Ctable = 98 And ccp.IsAuditGM = 1 And dp.Diid = {0}
  952. Order By CreateTime", _dto.DiId);
  953. groupDecreaseFeeViews = await _sqlSugar.SqlQueryable<GroupDecreaseFeeView>(groupDecreaseFeeSql).ToListAsync();
  954. #region 保险费用 - 模拟数据
  955. //if (groupDecreaseFeeViews.Count < 1)
  956. //{
  957. // groupDecreaseFeeViews.Add(new GroupDecreaseFeeView()
  958. // {
  959. // DPId = 0,
  960. // DPDiId = 2334,
  961. // PriceName = "模拟数据-费用名称",
  962. // PayMoney = 1000.00M,
  963. // PayMoneyCurrency = "CNY",
  964. // DayRate = 1.0000M,
  965. // CNYPrice = 1.0000M,
  966. // AuditGMDate = "2023-12-10 12:13:00",
  967. // Payee = "模拟数据-付款方",
  968. // OrbitalPrivateTransfer = 1,
  969. // PayWay = "现金",
  970. // IsPay = 1,
  971. // Applicant = "刘华举"
  972. // });
  973. // groupDecreaseFeeViews.Add(new GroupDecreaseFeeView()
  974. // {
  975. // DPId = 0,
  976. // DPDiId = 2334,
  977. // PriceName = "模拟数据-费用名称",
  978. // PayMoney = 1000.00M,
  979. // PayMoneyCurrency = "CNY",
  980. // DayRate = 1.0000M,
  981. // CNYPrice = 1.0000M,
  982. // AuditGMDate = "2023-12-10 12:13:00",
  983. // Payee = "模拟数据-付款方",
  984. // OrbitalPrivateTransfer = 1,
  985. // PayWay = "现金",
  986. // IsPay = 1,
  987. // Applicant = "刘华举"
  988. // });
  989. //}
  990. #endregion
  991. decimal DecreaseCNYTotalPrice = 0.00M;
  992. foreach (var item in groupDecreaseFeeViews)
  993. {
  994. item.CNYPrice = Convert.ToDecimal(item.CNYPrice.ToString("#0.00"));
  995. DecreaseCNYTotalPrice += item.CNYPrice;
  996. if (!string.IsNullOrEmpty(item.AuditGMDate))
  997. {
  998. item.AuditGMDate = Convert.ToDateTime(item.AuditGMDate).ToString("yyyy-MM-dd HH:mm:ss");
  999. }
  1000. }
  1001. _geView.GroupDecreaseFeeViews = groupDecreaseFeeViews;
  1002. _geView.GroupDecreaseFeeStr = string.Format(@"人民币总费用:{0} CNY", DecreaseCNYTotalPrice.ToString("#0.00"));
  1003. #endregion
  1004. _view.GroupExpenditure = _geView;
  1005. #endregion
  1006. /*
  1007. * 团组报表计算方式
  1008. * 当前总支出 = 团组支出.Sum() + 超支费用.Sum()
  1009. * 应收金额 = 应收表.Sum()
  1010. * 已收金额 = 已收表.Sum()
  1011. * 应收利润(应收-支出) = 应收金额 - 收款退还 - 当前总支出
  1012. * 已收利润(已收-支出) = 已收金额 - 收款退还 - 当前总支出
  1013. *
  1014. */
  1015. decimal _totalExpenditure = 0.00M; //总支出
  1016. decimal _amountReceivable = 0.00M; //应收金额
  1017. decimal _amountReceived = 0.00M; //已收金额
  1018. decimal _receivableProfit = 0.00M; //应收利润
  1019. decimal _receivedProfit = 0.00M; //已收利润
  1020. _totalExpenditure = HotelCNYTotalPrice + CTGGRCNYTotalPrice + AirCNYTotalPrice + VisaCNYTotalPirce + InvitationalCNYTotalPrice +
  1021. InsuranceCNYTotalPrice + DecreaseCNYTotalPrice + exTotalAmount;
  1022. _amountReceivable = frTotalAmount;
  1023. _amountReceived = prTotalAmount;
  1024. _receivableProfit = _amountReceivable - promTotalAmount - _totalExpenditure;
  1025. _receivedProfit = _amountReceived - promTotalAmount - _totalExpenditure;
  1026. _view.FeeTotalStr = string.Format(@$"<span>
  1027. <span>当前总支出:{_totalExpenditure.ToString("#0.00")} CNY</span>
  1028. <span style='padding-left:10px;color: Green;'>应收金额:{_amountReceivable.ToString("#0.00")} CNY</span>
  1029. <span style='padding-left:10px;color: Green;'>已收金额:{_amountReceived.ToString("#0.00")} CNY</span>
  1030. <span style='padding-left:10px;color: Green;'>应收利润(应收-支出):{_receivableProfit.ToString("#0.00")} CNY</span>
  1031. <span style='padding-left:10px;color: Green;'>已收利润(已收-支出):{_receivedProfit.ToString("#0.00")} CNY</span>
  1032. </span>");
  1033. return Ok(JsonView(true, "查询成功!", _view));
  1034. }
  1035. else
  1036. {
  1037. return Ok(JsonView(false, "查询成功"));
  1038. }
  1039. }
  1040. #endregion
  1041. #region 报表/折线图统计
  1042. //企业利润-团组利润
  1043. //企业利润-会务利润
  1044. /// <summary>
  1045. /// 企业利润
  1046. /// Details
  1047. /// 待添加权限验证
  1048. /// </summary>
  1049. /// <param name="_dto">团组列表请求dto</param>
  1050. /// <returns></returns>
  1051. [HttpPost("PostCorporateProfit")]
  1052. //[JsonConverter(typeof(DecimalConverter), 2)]
  1053. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1054. public async Task<IActionResult> PostCorporateProfit(PostCorporateProfitDto _dto)
  1055. {
  1056. #region 参数验证
  1057. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  1058. if (_dto.PageId < 1) _dto.PageId = 38; //团组报表页面Id
  1059. if (_dto.Year < 1) return Ok(JsonView(false, "请输入有效的Year参数!"));
  1060. if (_dto.StatisticsType > 2 && _dto.StatisticsType < 1) return Ok(JsonView(false, "请输入有效的StatisticsType参数,1 月份 2 季度"));
  1061. if (_dto.BusinessType > 3 && _dto.BusinessType < 1) return Ok(JsonView(false, "请输入有效的BusinessType参数,1 所有 2 团组 3 会务"));
  1062. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1063. #region 页面操作权限验证
  1064. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  1065. //if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  1066. #endregion
  1067. string sqlWhere = string.Empty;
  1068. //起止时间
  1069. DateTime beginDt = Convert.ToDateTime($"{_dto.Year}-01-01 00:00:00");
  1070. DateTime endDt = Convert.ToDateTime($"{_dto.Year}-12-31 23:59:59");
  1071. sqlWhere = string.Format(@$" Where Isdel = 0 ");
  1072. //业务类型
  1073. List<int> groupTypeId = new List<int>();
  1074. if (_dto.BusinessType == 2) //团组
  1075. {
  1076. groupTypeId.AddRange(new List<int>() {
  1077. 38, // 政府团
  1078. 39, // 企业团
  1079. 40, // 散客团
  1080. 1048 // 高校团
  1081. });
  1082. }
  1083. else if (_dto.BusinessType == 3) //会务
  1084. {
  1085. groupTypeId.AddRange(new List<int>() {
  1086. 102, // 未知
  1087. 248, // 非团组
  1088. 302, // 成都-会务活动
  1089. 691, // 四川-会务活动
  1090. 762, // 四川-赛事项目收入
  1091. 1047 // 成都-赛事项目收入
  1092. });
  1093. }
  1094. if (groupTypeId.Count > 0)
  1095. {
  1096. sqlWhere += string.Format(@$" And TeamDid In ({string.Join(',', groupTypeId)})");
  1097. }
  1098. string sql = string.Format(@$"Select * From Grp_DelegationInfo {sqlWhere}");
  1099. var groupInfos = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).Where(it => it.CreateTime >= beginDt && it.CreateTime <= endDt).ToListAsync();
  1100. if (groupInfos.Count < 1) return Ok(JsonView(false, "暂无相关团组!"));
  1101. List<int> diIds = groupInfos.Select(it => it.Id).ToList();
  1102. List<CorporateProfit> corporateProfits = await CorporateProfit(diIds);
  1103. List<MonthInfo> months = new List<MonthInfo>();
  1104. if (_dto.StatisticsType == 1) //月份
  1105. {
  1106. months = GeneralMethod.GetMonthInfos(Convert.ToInt32(_dto.Year));
  1107. }
  1108. else if (_dto.StatisticsType == 1) //季度
  1109. {
  1110. months = GeneralMethod.GetQuarter(Convert.ToInt32(_dto.Year));
  1111. }
  1112. List<CorporateProfitMonthView> _view = new List<CorporateProfitMonthView>();
  1113. foreach (var item in months)
  1114. {
  1115. DateTime monthBeginDt = Convert.ToDateTime($"{_dto.Year}-{item.Month}-{item.Days.BeginDays} 00:00:00");
  1116. DateTime monthEndDt = Convert.ToDateTime($"{_dto.Year}-{item.Month}-{item.Days.EndDays} 23:59:59");
  1117. var corporateProfit = corporateProfits.Where(it => it.CreateDt >= monthBeginDt && it.CreateDt <= monthEndDt).ToList();
  1118. _view.Add(new CorporateProfitMonthView()
  1119. {
  1120. Month = item.Month,
  1121. Profit = corporateProfit.Sum(it => it.ReceivedProfit),
  1122. GroupInfos = corporateProfit.OrderBy(it => it.CreateDt).ToList()
  1123. });
  1124. }
  1125. return Ok(JsonView(true, "操作成功!", _view));
  1126. #endregion
  1127. }
  1128. /// <summary>
  1129. /// 计算团组利润
  1130. /// </summary>
  1131. /// <param name="diIds"></param>
  1132. /// <returns></returns>
  1133. private async Task<List<CorporateProfit>> CorporateProfit(List<int> diIds)
  1134. {
  1135. List<CorporateProfit> corporateProfits = new List<CorporateProfit>();
  1136. if (diIds.Count < 1)
  1137. {
  1138. return corporateProfits;
  1139. }
  1140. #region 计算团组利润
  1141. /*
  1142. * 团组报表计算方式
  1143. * 当前总支出 = 团组支出.Sum() + 超支费用.Sum()
  1144. * 应收金额 = 应收表.Sum()
  1145. * 已收金额 = 已收表.Sum()
  1146. * 应收利润(应收-支出) = 应收金额 - 收款退还 - 当前总支出
  1147. * 已收利润(已收-支出) = 已收金额 - 收款退还 - 当前总支出
  1148. *
  1149. */
  1150. string diIdStr = string.Join(",", diIds);
  1151. string sql = string.Format(@$"Select * From Grp_DelegationInfo Where Isdel = 0 And Id In ({diIdStr})");
  1152. var groupInfos = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToListAsync();
  1153. #region 费用类型 币种,转账,客户信息
  1154. List<Sys_SetData> _setDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToListAsync();
  1155. var _clientDatas = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync();
  1156. #endregion
  1157. foreach (var _diId in diIds)
  1158. {
  1159. List<ExpenditureInfo> expenditureInfos = new List<ExpenditureInfo>();
  1160. #region 团组收入
  1161. /*
  1162. * 应收报表
  1163. */
  1164. decimal frTotalAmount = 0.00M;//应收总金额
  1165. string _frSql = string.Format(@"Select fr.Id,fr.Diid,fr.PriceName,fr.Price,fr.Count,fr.Unit,fr.Currency,
  1166. sd.Name As CurrencyCode,sd.Remark As CurrencyName,fr.Rate,fr.ItemSumPrice,fr.CreateTime
  1167. From Fin_ForeignReceivables fr
  1168. Left Join Sys_SetData sd On fr.Currency = sd.Id
  1169. Where fr.IsDel = 0 And fr.Diid = {0} Order By CreateTime", _diId);
  1170. List<Gsd_ForeignReceivablesView> _frViews = await _sqlSugar.SqlQueryable<Gsd_ForeignReceivablesView>(_frSql).ToListAsync();
  1171. frTotalAmount = _frViews.Sum(it => it.ItemSumPrice);
  1172. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "应收项", Amount = frTotalAmount });
  1173. /*
  1174. * 已收报表
  1175. */
  1176. decimal prTotalAmount = 0.00M;//已收总金额
  1177. string _prSql = string.Format(@"Select pr.Id,pr.Diid,pr.SectionTime As SectionTimeDt,pr.Price,pr.Currency,
  1178. sd1.Name As CurrencyCode,sd1.Remark As CurrencyName,pr.Client,
  1179. pr.ReceivablesType,sd2.Name As ReceivablesTypeName,pr.Remark,pr.CreateTime
  1180. From Fin_ProceedsReceived pr
  1181. Left Join Sys_SetData sd1 On pr.Currency = sd1.Id
  1182. Left Join Sys_SetData sd2 On pr.ReceivablesType = sd2.Id
  1183. Where pr.IsDel = 0 and pr.Diid = {0} Order By CreateTime", _diId);
  1184. List<Gsd_ProceedsReceivedView> _prViews = await _sqlSugar.SqlQueryable<Gsd_ProceedsReceivedView>(_prSql).ToListAsync();
  1185. prTotalAmount = _prViews.Sum(it => it.Price);
  1186. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "已收项", Amount = prTotalAmount });
  1187. /*
  1188. * 超支费用
  1189. */
  1190. decimal exTotalAmount = 0.00M;
  1191. string _ecSql = string.Format(@"Select gec.Id As GECId,gec.DiId As GECDiId,gec.PriceName,ccp.PayMoney,sd1.Name As PaymentCurrency,
  1192. ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  1193. sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant,gec.CreateTime
  1194. From OA2023DB.dbo.Fin_GroupExtraCost gec
  1195. Left Join Grp_CreditCardPayment ccp On gec.Id = ccp.CId
  1196. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1197. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1198. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  1199. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1200. Where ccp.IsDel = 0 And ccp.CTable = 1015 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ccp.DiId = {0} Order By CreateTime", _diId);
  1201. List<Gsd_ExtraCostsView> _ExtraCostsViews = await _sqlSugar.SqlQueryable<Gsd_ExtraCostsView>(_ecSql).ToListAsync();
  1202. exTotalAmount = _ExtraCostsViews.Sum(it => it.CNYPrice);
  1203. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "超支费用", Amount = exTotalAmount });
  1204. /*
  1205. * 收款退还
  1206. */
  1207. decimal promTotalAmount = 0.00M;// 收款退还总金额
  1208. List<Gsd_PaymentRefundAndOtherMoneyView> _promView = new List<Gsd_PaymentRefundAndOtherMoneyView>();
  1209. //删除了 And prom.PriceType = 1
  1210. string _ropSql = string.Format(@"Select u.CnName As Appliction,prom.Id As PrId,prom.DiId As PrDiId,prom.Price As PrPrice,
  1211. prom.PriceName AS PrPriceName,prom.CurrencyId As PrCurrencyId,
  1212. prom.PayType As PrPayType,prom.PriceType As PrPriceType,ccp.*,prom.CreateTime As PrCreateTime
  1213. From Fin_PaymentRefundAndOtherMoney prom
  1214. Left Join Grp_CreditCardPayment ccp On prom.DiId = ccp.DIId And prom.Id = ccp.CId
  1215. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1216. Where prom.IsDel = 0 And prom.PayType = 1 And ccp.CTable = 285
  1217. And ccp.IsAuditGM = 1 And ccp.IsPay = 1
  1218. And prom.DiId = {0} Order By PrCreateTime", _diId);
  1219. var _promDatas = await _sqlSugar.SqlQueryable<Gsd_PaymentRefundAndOtherMoneyDataSource1View>(_ropSql).ToListAsync();
  1220. foreach (var ropItem in _promDatas)
  1221. {
  1222. string thisCueencyCode = "Unknown";
  1223. string thisCueencyName = "Unknown";
  1224. var currency = _setDatas.Where(it => it.Id == ropItem.PaymentCurrency).FirstOrDefault();
  1225. if (currency != null)
  1226. {
  1227. thisCueencyCode = currency.Name;
  1228. thisCueencyName = currency.Remark;
  1229. }
  1230. string orbitalPrivateTransferStr = "Unknown";
  1231. var orbitalPrivateTransfer = _setDatas.Where(it => it.Id == ropItem.OrbitalPrivateTransfer).FirstOrDefault();
  1232. if (orbitalPrivateTransfer != null)
  1233. {
  1234. orbitalPrivateTransferStr = orbitalPrivateTransfer.Name;
  1235. }
  1236. string payStr = "Unknown";
  1237. var pay = _setDatas.Where(it => it.Id == ropItem.PayDId).FirstOrDefault();
  1238. if (pay != null)
  1239. {
  1240. payStr = pay.Name;
  1241. }
  1242. Gsd_PaymentRefundAndOtherMoneyView gsd_PaymentRefund = new Gsd_PaymentRefundAndOtherMoneyView()
  1243. {
  1244. Id = ropItem.Id,
  1245. DiId = ropItem.DIId,
  1246. PriceName = ropItem.PrPriceName,
  1247. PayCurrencyCode = thisCueencyCode,
  1248. PayCurrencyName = thisCueencyName,
  1249. Price = ropItem.PrPrice,
  1250. CNYPrice = ropItem.RMBPrice,
  1251. ThisRate = ropItem.DayRate,
  1252. Payee = ropItem.Payee,
  1253. PayTime = ropItem.AuditGMDate,
  1254. OrbitalPrivateTransfer = ropItem.OrbitalPrivateTransfer,
  1255. PayType = payStr,
  1256. IsPay = ropItem.IsPay,
  1257. Applicant = ropItem.Appliction
  1258. };
  1259. _promView.Add(gsd_PaymentRefund);
  1260. }
  1261. promTotalAmount = _promView.Sum(it => it.CNYPrice);
  1262. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "收款退还", Amount = promTotalAmount });
  1263. #endregion
  1264. #region 团组支出
  1265. GroupExpenditureView _geView = new GroupExpenditureView();
  1266. #region 酒店预定费用
  1267. List<GroupHotelFeeView> groupHotelFeeViews = new List<GroupHotelFeeView>();
  1268. string hotelFeeSql = string.Format(@"Select hr.Id As HrId,hr.DiId As HrDiId,hr.City,hr.HotelName,hr.CheckInDate,hr.CheckOutDate,
  1269. sd1.Name As PaymentCurrency,hr.SingleRoomPrice,hr.SingleRoomCount,hr.DoubleRoomPrice,
  1270. hr.DoubleRoomCount,hr.SuiteRoomPrice,hr.SuiteRoomCount,hr.OtherRoomPrice,hr.OtherRoomCount,
  1271. hr.BreakfastPrice,sd4.Name As BreakfastCurrency,hr.Isoppay,hr.GovernmentRent,
  1272. sd5.Name As GovernmentRentCurrency,hr.CityTax,sd6.Name As CityTaxCurrency,
  1273. ccp.PayMoney,ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.OrbitalPrivateTransfer,
  1274. sd2.Name As PayWay,sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant
  1275. From Grp_HotelReservations hr
  1276. Left Join Grp_CreditCardPayment ccp On hr.Id = ccp.CId
  1277. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1278. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1279. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  1280. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1281. Left Join Sys_SetData sd4 On hr.BreakfastCurrency = sd4.Id
  1282. Left Join Sys_SetData sd5 On hr.GovernmentRentCurrency = sd5.Id
  1283. Left Join Sys_SetData sd6 On hr.CityTaxCurrency = sd6.Id
  1284. Where hr.IsDel = 0 And ccp.IsDel = 0 And ccp.CTable = 76 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And hr.DiId = {0}
  1285. Order By CheckInDate Asc", _diId);
  1286. groupHotelFeeViews = await _sqlSugar.SqlQueryable<GroupHotelFeeView>(hotelFeeSql).ToListAsync();
  1287. decimal HotelCNYTotalPrice = groupHotelFeeViews.Sum(it => it.CNYPrice);
  1288. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "酒店预定", Amount = HotelCNYTotalPrice });
  1289. #endregion
  1290. #region 地接费用
  1291. List<GroupCTGGRFeeView> groupCTGGRFeeViews = new List<GroupCTGGRFeeView>();
  1292. string CTGGRFeeSql = string.Format(@"Select ctggr.Id As CTGGRId,ctggr.DiId As CTGGRDiId,ctggr.Area,ctggrc.*,ctggrc.Price As PayMoney,
  1293. sd2.name As PaymentCurrency,ccp.PayPercentage,
  1294. (ctggrc.Price / (ccp.PayPercentage / 100)) As AmountPaid,
  1295. (ctggrc.Price / (ccp.PayPercentage / 100) - ctggrc.Price) As BalancePayment,
  1296. ccp.DayRate,(ctggrc.Price * ccp.DayRate) As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  1297. ccp.OrbitalPrivateTransfer,sd1.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ctggr.CreateTime
  1298. From Grp_CarTouristGuideGroundReservations ctggr
  1299. Left Join ( Select cggrc.CTGGRId,sd1.Name As PriceName,cggrc.Price,sd2.Name As PriceCurrency,
  1300. cggrc.PriceContent
  1301. From Grp_CarTouristGuideGroundReservationsContent cggrc
  1302. Left Join Sys_SetData sd1 On cggrc.SId = sd1.Id
  1303. Left Join Sys_SetData sd2 On cggrc.Currency = sd2.Id
  1304. Where cggrc.ISdel = 0 And cggrc.Price != 0.00
  1305. ) ctggrc On ctggr.Id = ctggrc.CTGGRId
  1306. Left Join Grp_CreditCardPayment ccp On ccp.IsDel = 0 And ccp.CTable = 79 And ctggr.Id = ccp.CId
  1307. Left Join Sys_SetData sd1 On ccp.PayDId = sd1.Id
  1308. Left Join Sys_SetData sd2 On ccp.PaymentCurrency = sd2.Id
  1309. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1310. Where ctggr.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ctggr.DiId = {0}
  1311. Order By CreateTime", _diId);
  1312. groupCTGGRFeeViews = await _sqlSugar.SqlQueryable<GroupCTGGRFeeView>(CTGGRFeeSql).ToListAsync();
  1313. decimal CTGGRCNYTotalPrice = groupCTGGRFeeViews.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  1314. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "地接", Amount = CTGGRCNYTotalPrice });
  1315. #endregion
  1316. #region 机票预订费用
  1317. List<GroupAirFeeView> groupAirFeeViews = new List<GroupAirFeeView>();
  1318. string groupAirFeeSql = string.Format(@"Select atr.Id As AirId,atr.DIId As AirDiId,atr.FlightsCode,atr.FlightsCity,sd4.Name As AirTypeName,
  1319. atr.FlightsDate,atr.FlightsTime,atr.ClientName,atr.ClientNum,ccp.PayMoney,
  1320. sd1.Name As PayMoneyCurrency,ccp.RMBPrice As CNYPrice,ccp.DayRate,ccp.Payee,ccp.AuditGMDate,
  1321. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,sd3.Name As CardType,ccp.IsPay,u.CnName As Applicant,atr.CreateTime
  1322. From Grp_AirTicketReservations atr
  1323. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 85 And atr.Id = ccp.CId
  1324. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1325. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1326. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  1327. Left Join Sys_SetData sd4 On atr.CType = sd4.Id
  1328. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1329. Where atr.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And atr.DiId = {0} Order By CreateTime", _diId);
  1330. groupAirFeeViews = await _sqlSugar.SqlQueryable<GroupAirFeeView>(groupAirFeeSql).ToListAsync();
  1331. decimal AirCNYTotalPrice = groupAirFeeViews.Sum(it => it.CNYPrice);
  1332. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "机票预订", Amount = AirCNYTotalPrice });
  1333. #endregion
  1334. #region 签证费用
  1335. List<GroupVisaFeeView> groupVisaFeeViews = new List<GroupVisaFeeView>();
  1336. string groupVisaFeeSql = string.Format(@"Select vi.Id As VisaId,vi.DIId As VisaDiId,vi.VisaClient,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  1337. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,
  1338. sd3.Name As CardTypeName,ccp.IsPay,u.CnName As Applicant,vi.CreateTime
  1339. From Grp_VisaInfo vi
  1340. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 80 And vi.Id = ccp.CId
  1341. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1342. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1343. Left Join Sys_SetData sd3 On ccp.CTDId = sd3.Id
  1344. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1345. Where vi.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And vi.DIId = {0} Order By CreateTime", _diId);
  1346. groupVisaFeeViews = await _sqlSugar.SqlQueryable<GroupVisaFeeView>(groupVisaFeeSql).ToListAsync();
  1347. decimal VisaCNYTotalPirce = groupVisaFeeViews.Sum(it => it.PayMoney);
  1348. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "签证", Amount = VisaCNYTotalPirce });
  1349. #endregion
  1350. #region 邀请/公务活动 CTable = 81
  1351. List<GroupInvitationalFeeView> groupInvitationalFeeViews = new List<GroupInvitationalFeeView>();
  1352. string groupInvitationalFeeSql = string.Format(@"Select ioa.Id As IOAId,ioa.DiId As IOADiId,ioa.InviterArea,ioa.Inviter,ioa.InviteTime,
  1353. ioa.InviteCost,sd3.Name As InviteCurrency,ioa.SendCost,sd4.Name As SendCurrency,ioa.EventsCost,
  1354. sd5.Name As EventsCurrency,ioa.TranslateCost,sd6.Name As TranslateCurrency,ccp.PayMoney,
  1355. sd7.Name As PaymentCurrency,ccp.RMBPrice As CNYPrice,ccp.Payee,ccp.AuditGMDate,
  1356. ccp.OrbitalPrivateTransfer,sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ioa.CreateTime
  1357. From Grp_InvitationOfficialActivities ioa
  1358. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 81 And ioa.Id = ccp.CId
  1359. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1360. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1361. Left Join Sys_SetData sd3 On ioa.InviteCurrency = sd3.Id
  1362. Left Join Sys_SetData sd4 On ioa.SendCurrency = sd4.Id
  1363. Left Join Sys_SetData sd5 On ioa.EventsCurrency = sd5.Id
  1364. Left Join Sys_SetData sd6 On ioa.TranslateCurrency = sd6.Id
  1365. Left Join Sys_SetData sd7 On ccp.PaymentCurrency = sd7.Id
  1366. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1367. Where ioa.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ioa.Diid = {0} Order By CreateTime", _diId);
  1368. groupInvitationalFeeViews = await _sqlSugar.SqlQueryable<GroupInvitationalFeeView>(groupInvitationalFeeSql).ToListAsync();
  1369. decimal InvitationalCNYTotalPrice = groupInvitationalFeeViews.Sum(it => it.CNYPrice);
  1370. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "邀请/公务活动", Amount = InvitationalCNYTotalPrice });
  1371. #endregion
  1372. #region 保险费用
  1373. List<GroupInsuranceFeeView> groupInsuranceFeeViews = new List<GroupInsuranceFeeView>();
  1374. string groupInsuranceFeeSql = string.Format(@"Select ic.Id As InsuranceId,ic.Diid As InsuranceDiId,ClientName,ccp.PayMoney,ccp.RMBPrice As CNYPrice,
  1375. sd1.Name As PayMoneyCurrency,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  1376. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,ic.CreateTime
  1377. From Grp_Customers ic
  1378. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 82 And ic.Id = ccp.CId
  1379. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1380. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1381. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1382. Where ic.IsDel = 0 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And ic.DiId = {0} Order By CreateTime", _diId);
  1383. groupInsuranceFeeViews = await _sqlSugar.SqlQueryable<GroupInsuranceFeeView>(groupInsuranceFeeSql).ToListAsync();
  1384. decimal InsuranceCNYTotalPrice = groupInsuranceFeeViews.Sum(it => it.CNYPrice);
  1385. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "保险费用", Amount = InsuranceCNYTotalPrice });
  1386. #endregion
  1387. #region 其他款项费用 98
  1388. List<GroupDecreaseFeeView> groupDecreaseFeeViews = new List<GroupDecreaseFeeView>();
  1389. string groupDecreaseFeeSql = string.Format(@"Select dp.Id As DPId,dp.DiId As DPDiId,dp.PriceName,ccp.PayMoney,sd1.Name As PayMoneyCurrency,
  1390. (((ccp.PayMoney * ccp.DayRate) / ccp.PayPercentage) * 100) As CNYPrice,
  1391. ccp.DayRate,ccp.Payee,ccp.AuditGMDate,ccp.OrbitalPrivateTransfer,
  1392. sd2.Name As PayWay,ccp.IsPay,u.CnName As Applicant,dp.CreateTime
  1393. From Grp_DecreasePayments dp
  1394. Left Join Grp_CreditCardPayment ccp On ccp.isdel = 0 And ccp.CTable = 98 And dp.Id = ccp.CId
  1395. Left Join Sys_SetData sd1 On ccp.PaymentCurrency = sd1.Id
  1396. Left Join Sys_SetData sd2 On ccp.PayDId = sd2.Id
  1397. Left Join Sys_Users u On ccp.CreateUserId = u.Id
  1398. Where dp.IsDel = 0 And ccp.Ctable = 98 And ccp.IsAuditGM = 1 And ccp.IsPay = 1 And dp.Diid = {0}
  1399. Order By CreateTime", _diId);
  1400. groupDecreaseFeeViews = await _sqlSugar.SqlQueryable<GroupDecreaseFeeView>(groupDecreaseFeeSql).ToListAsync();
  1401. decimal DecreaseCNYTotalPrice = groupDecreaseFeeViews.Sum(it => Convert.ToDecimal(it.CNYPrice.ToString("#0.00")));
  1402. expenditureInfos.Add(new ExpenditureInfo() { ItemName = "其他款项", Amount = DecreaseCNYTotalPrice });
  1403. #endregion
  1404. #endregion
  1405. /*
  1406. * 团组报表计算方式
  1407. * 当前总支出 = 团组支出.Sum() + 超支费用.Sum()
  1408. * 应收金额 = 应收表.Sum()
  1409. * 已收金额 = 已收表.Sum()
  1410. * 应收利润(应收-支出) = 应收金额 - 收款退还 - 当前总支出
  1411. * 已收利润(已收-支出) = 已收金额 - 收款退还 - 当前总支出
  1412. *
  1413. */
  1414. decimal _totalExpenditure = 0.00M; //总支出
  1415. decimal _amountReceivable = 0.00M; //应收金额
  1416. decimal _amountReceived = 0.00M; //已收金额
  1417. decimal _receivableProfit = 0.00M; //应收利润
  1418. decimal _receivedProfit = 0.00M; //已收利润
  1419. _totalExpenditure = HotelCNYTotalPrice + CTGGRCNYTotalPrice + AirCNYTotalPrice + VisaCNYTotalPirce + InvitationalCNYTotalPrice +
  1420. InsuranceCNYTotalPrice + DecreaseCNYTotalPrice + exTotalAmount;
  1421. _amountReceivable = frTotalAmount;
  1422. _amountReceived = prTotalAmount;
  1423. _receivableProfit = _amountReceivable - promTotalAmount - _totalExpenditure;
  1424. _receivedProfit = _amountReceived - promTotalAmount - _totalExpenditure;
  1425. var groupInfo = groupInfos.Find(it => it.Id == _diId);
  1426. corporateProfits.Add(new CorporateProfit()
  1427. {
  1428. DiId = _diId,
  1429. TeamName = groupInfo?.TeamName ?? "Unkwnon",
  1430. CreateDt = Convert.ToDateTime(groupInfo?.CreateTime),
  1431. TotalExpenditure = _totalExpenditure,
  1432. ExpenditureItem = expenditureInfos,
  1433. AmountReceivable = _amountReceivable,
  1434. AmountReceived = _amountReceived,
  1435. ReceivableProfit = _receivableProfit,
  1436. ReceivedProfit = _receivedProfit,
  1437. });
  1438. }
  1439. #endregion
  1440. return corporateProfits;
  1441. }
  1442. //未来预测-地区接团/出团量
  1443. //未来预测-地区酒店预订量
  1444. //未来预测-地区机票预订量
  1445. //未来预测-地区车辆预订量
  1446. /// <summary>
  1447. /// (国家/城市)地区预订数量(团,酒店,机票,车辆)
  1448. /// Details
  1449. /// 待添加权限验证
  1450. /// </summary>
  1451. /// <param name="_dto">团组列表请求dto</param>
  1452. /// <returns></returns>
  1453. [HttpPost("PostRegionalBookingsNumber")]
  1454. //[JsonConverter(typeof(DecimalConverter), 2)]
  1455. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1456. public async Task<IActionResult> PostRegionalBookingsNumber(PostRegionalBookingsNumberDto _dto)
  1457. {
  1458. #region 参数验证
  1459. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  1460. //if (_dto.PageId < 1) _dto.PageId = 38; //团组报表页面Id
  1461. if (_dto.Type > 1 && _dto.Type > 5) return Ok(JsonView(false, "请输入有效的Type参数,1 团 2 酒店 3 机票 4 车辆"));
  1462. if (_dto.Year < 1) return Ok(JsonView(false, "请输入有效的Year参数!"));
  1463. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1464. #region 页面操作权限验证
  1465. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  1466. //if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  1467. #endregion
  1468. string sqlWhere = string.Empty;
  1469. //起止时间
  1470. DateTime beginDt = Convert.ToDateTime($"{_dto.Year}-01-01 00:00:00");
  1471. DateTime endDt = Convert.ToDateTime($"{_dto.Year}-12-31 23:59:59");
  1472. sqlWhere = string.Format(@$" Where Isdel = 0 ");
  1473. string sql = string.Format(@$"Select * From Grp_DelegationInfo {sqlWhere}");
  1474. var groupInfos = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).Where(it => it.CreateTime >= beginDt && it.CreateTime <= endDt).ToListAsync();
  1475. if (groupInfos.Count < 1) return Ok(JsonView(false, "暂无相关团组!"));
  1476. List<GroupTypeNumberInfo> datas = new List<GroupTypeNumberInfo>();
  1477. foreach (var item in groupInfos)
  1478. {
  1479. var data = await GroupBookingsNumber(_dto.Type, item);
  1480. if (data.TypeItem.Count > 0)
  1481. {
  1482. datas.Add(data);
  1483. }
  1484. }
  1485. //类型处理
  1486. if (_dto.Type == 1)//接团
  1487. {
  1488. List<GroupBookingNumberView> views = new List<GroupBookingNumberView>();
  1489. dynamic groupData = null;
  1490. foreach (var item in datas)
  1491. {
  1492. if (item.TypeItem.Count > 0)
  1493. {
  1494. foreach (var item1 in item.TypeItem)
  1495. {
  1496. if (item1.RegionItem.Count > 0)
  1497. {
  1498. GroupInfo groupInfo = new GroupInfo()
  1499. {
  1500. DiId = item.DiId,
  1501. TeamName = item.GroupName,
  1502. CreateTime = groupInfos.Find(it => it.Id == item.DiId)?.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") ?? "Unknown",
  1503. ClientUnit = groupInfos.Find(it => it.Id == item.DiId)?.ClientUnit ?? "Unknown",
  1504. Principal = groupInfos.Find(it => it.Id == item.DiId)?.ClientName ?? "Unknown",
  1505. };
  1506. views.Add(new GroupBookingNumberView() { Name = item1.RegionItem[0].Name, Number = item1.RegionItem[0].Number, GroupItem = new List<GroupInfo>() { groupInfo } });
  1507. }
  1508. }
  1509. }
  1510. }
  1511. var viewsGroup = views.GroupBy(it => it.Name);
  1512. List<GroupBookingNumberView> _view = new List<GroupBookingNumberView>();
  1513. foreach (var item in viewsGroup)
  1514. {
  1515. List<GroupInfo> infos = new List<GroupInfo>();
  1516. foreach (var item1 in item)
  1517. {
  1518. infos.AddRange(item1.GroupItem);
  1519. }
  1520. infos = infos.OrderByDescending(it => it.CreateTime).ToList(); //
  1521. _view.Add(new GroupBookingNumberView() { Name = item.Key, Number = item.Count(), GroupItem = infos });
  1522. }
  1523. _view = _view.OrderByDescending(it => it.Number).Take(10).ToList();
  1524. return Ok(JsonView(true, "操作成功!", _view, _view.Count));
  1525. }
  1526. else if (_dto.Type == 2)
  1527. {
  1528. List<HotelBookingNumberView> views = new List<HotelBookingNumberView>();
  1529. foreach (var item in datas)
  1530. {
  1531. if (item.TypeItem.Count > 0)
  1532. {
  1533. foreach (var item1 in item.TypeItem)
  1534. {
  1535. if (item1.RegionItem.Count > 0)
  1536. {
  1537. foreach (var item2 in item1.RegionItem)
  1538. {
  1539. GroupInfo groupInfo = new GroupInfo()
  1540. {
  1541. DiId = item.DiId,
  1542. TeamName = item.GroupName,
  1543. CreateTime = groupInfos.Find(it => it.Id == item.DiId)?.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") ?? "Unknown",
  1544. ClientUnit = groupInfos.Find(it => it.Id == item.DiId)?.ClientUnit ?? "Unknown",
  1545. Principal = groupInfos.Find(it => it.Id == item.DiId)?.ClientName ?? "Unknown",
  1546. };
  1547. List<HotelInfo> hotels = new List<HotelInfo>();
  1548. foreach (var item3 in item2.Data)
  1549. {
  1550. StatisticsHotelInfo statisticsHotelInfos = JsonConvert.DeserializeObject<StatisticsHotelInfo>(JsonConvert.SerializeObject(item3));
  1551. HotelInfo hotelInfo = new HotelInfo()
  1552. {
  1553. HotelName = statisticsHotelInfos.HotelName,
  1554. SingleRoomNum = statisticsHotelInfos.SingleRoomNum,
  1555. DoubleRoomNum = statisticsHotelInfos.DoubleRoomNum,
  1556. SuiteRoomNum = statisticsHotelInfos.SuiteRoomNum,
  1557. OtherRoomNum = statisticsHotelInfos.OtherRoomNum,
  1558. GroupInfo = groupInfo
  1559. };
  1560. hotels.Add(hotelInfo);
  1561. }
  1562. views.Add(new HotelBookingNumberView() { Name = item1.RegionItem[0].Name, Number = item1.RegionItem[0].Number, HotelItem = hotels });
  1563. }
  1564. }
  1565. }
  1566. }
  1567. }
  1568. var viewsGroup = views.GroupBy(it => it.Name);
  1569. List<HotelBookingNumberView> _view = new List<HotelBookingNumberView>();
  1570. foreach (var item in viewsGroup)
  1571. {
  1572. List<HotelInfo> infos = new List<HotelInfo>();
  1573. foreach (var item1 in item)
  1574. {
  1575. infos.AddRange(item1.HotelItem);
  1576. }
  1577. _view.Add(new HotelBookingNumberView() { Name = item.Key, Number = item.Count(), HotelItem = infos });
  1578. }
  1579. _view = _view.OrderByDescending(it => it.Number).Take(10).ToList();
  1580. return Ok(JsonView(true, "操作成功!", views, views.Count));
  1581. }
  1582. return Ok(JsonView(false, "操作失败!"));
  1583. #endregion
  1584. }
  1585. /// <summary>
  1586. /// 计算团组ALLType预订数量
  1587. /// </summary>
  1588. /// <param name="diIds"></param>
  1589. /// <returns></returns>
  1590. private async Task<GroupTypeNumberInfo> GroupBookingsNumber(int type, Grp_DelegationInfo info)
  1591. {
  1592. GroupTypeNumberInfo _view = new GroupTypeNumberInfo();
  1593. if (info == null)
  1594. {
  1595. return _view;
  1596. }
  1597. _view.DiId = info.Id;
  1598. _view.GroupName = info.TeamName;
  1599. List<TypeInfo> _types = new List<TypeInfo>();
  1600. #region 计算团组ALLType预订数量
  1601. if (type == 1)
  1602. {
  1603. //接团 客户集团所在地区
  1604. string group_region = string.Empty;
  1605. int group_number = 0;
  1606. if (!string.IsNullOrEmpty(info.ClientUnit))
  1607. {
  1608. var _NewClientData = await _sqlSugar.Queryable<Crm_NewClientData>().Where(it => it.IsDel == 0 && it.Client.Equals(info.ClientUnit)).FirstAsync();
  1609. if (_NewClientData != null)
  1610. {
  1611. var regionInfo = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == _NewClientData.Lvlid).FirstAsync();
  1612. if (regionInfo != null)
  1613. {
  1614. group_region = regionInfo.Name.Replace("级", "");
  1615. group_number++;
  1616. }
  1617. }
  1618. }
  1619. if (group_number > 0)
  1620. {
  1621. _types.Add(new TypeInfo() { Id = 1, RegionItem = new List<RegionInfo>() { new RegionInfo() { Name = group_region, Number = group_number } } });
  1622. }
  1623. }
  1624. else if (type == 2)
  1625. {
  1626. //酒店
  1627. var hotelInfos = await _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && it.DiId == info.Id).ToListAsync();
  1628. if (hotelInfos.Count > 0)
  1629. {
  1630. List<RegionInfo> hotelRegions = new List<RegionInfo>();
  1631. foreach (var item in hotelInfos)
  1632. {
  1633. var hotelNumberInfo = new StatisticsHotelInfo()
  1634. {
  1635. HotelName = item.HotelName,
  1636. SingleRoomNum = item.SingleRoomCount,
  1637. DoubleRoomNum = item.DoubleRoomCount,
  1638. SuiteRoomNum = item.SuiteRoomCount,
  1639. OtherRoomNum = item.OtherRoomCount,
  1640. };
  1641. int hotelRoomTotal = item.SingleRoomCount + item.DoubleRoomCount + item.SuiteRoomCount + item.OtherRoomCount;
  1642. if (hotelRegions.Select(it => it.Name).ToList().Contains(item.City))
  1643. {
  1644. RegionInfo hotelRegion = hotelRegions.Find(it => it.Name.Equals(item.City));
  1645. if (hotelRegion != null)
  1646. {
  1647. hotelRegions.Remove(hotelRegion);
  1648. if (hotelRegion.Data.Count > 0)
  1649. {
  1650. hotelRegion.Data.Add(hotelNumberInfo);
  1651. }
  1652. hotelRegion.Number += hotelRoomTotal;
  1653. hotelRegions.Add(hotelRegion);
  1654. }
  1655. }
  1656. else
  1657. {
  1658. hotelRegions.Add(new RegionInfo() { Name = item.City, Number = hotelRoomTotal, Data = new List<dynamic>() { hotelNumberInfo } });
  1659. }
  1660. }
  1661. _types.Add(new TypeInfo() { Id = 2, RegionItem = hotelRegions });
  1662. }
  1663. }
  1664. else if (type == 3)
  1665. {
  1666. //机票
  1667. var airTicketInfos = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  1668. .LeftJoin<Grp_CreditCardPayment>((atr, ccp) => atr.Id == ccp.CId && ccp.IsPay == 1)
  1669. .LeftJoin<Sys_SetData>((atr, ccp, sd) => atr.CType == sd.Id)
  1670. .Where((atr, ccp, sd) => atr.IsDel == 0 && atr.DIId == info.Id)
  1671. .Select((atr, ccp, sd) => new { atr.ClientNum, atr.CType, ccp.Payee, AirType = sd.Name })
  1672. .ToListAsync();
  1673. if (airTicketInfos.Count > 0)
  1674. {
  1675. List<RegionInfo> airTicketRegions = new List<RegionInfo>();
  1676. foreach (var item in airTicketInfos)
  1677. {
  1678. var ticketClass = new
  1679. {
  1680. TiketClass = item.AirType,
  1681. Number = item.ClientNum
  1682. };
  1683. if (airTicketRegions.Select(it => it.Name).ToList().Contains(item.Payee))
  1684. {
  1685. RegionInfo airTicketRegion = airTicketRegions.Find(it => it.Name.Equals(item.Payee));
  1686. if (airTicketRegion != null)
  1687. {
  1688. airTicketRegions.Remove(airTicketRegion);
  1689. if (airTicketRegion.Data.Count > 0)
  1690. {
  1691. airTicketRegion.Data.Add(ticketClass);
  1692. }
  1693. airTicketRegion.Number += item.ClientNum;
  1694. airTicketRegions.Add(airTicketRegion);
  1695. }
  1696. }
  1697. else
  1698. {
  1699. airTicketRegions.Add(new RegionInfo() { Name = item.Payee, Number = item.ClientNum, Data = new List<dynamic>() { ticketClass } });
  1700. }
  1701. }
  1702. _types.Add(new TypeInfo() { Id = 3, RegionItem = airTicketRegions });
  1703. }
  1704. }
  1705. else if (type == 4)
  1706. {
  1707. //车辆
  1708. var opInfos = await _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(it => it.IsDel == 0 && it.DiId == info.Id).ToListAsync();
  1709. var opContentInfos = await _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(it => it.IsDel == 0 && it.DiId == info.Id).ToListAsync();
  1710. if (opInfos.Count > 0)
  1711. {
  1712. List<RegionInfo> opRegions = new List<RegionInfo>();
  1713. foreach (var item in opInfos)
  1714. {
  1715. int carNum = 0;
  1716. var opContentInfo = opContentInfos.Where(it => it.CTGGRId == item.Id && it.SId == 91).ToList();
  1717. if (opContentInfo.Count > 0)
  1718. {
  1719. foreach (var item1 in opContentInfo)
  1720. {
  1721. if (item1.Price > 0 && item1.Count > 0)
  1722. {
  1723. carNum += item1.Count;
  1724. }
  1725. }
  1726. }
  1727. if (carNum > 0)
  1728. {
  1729. var opData = new
  1730. {
  1731. ServiceCompany = item.ServiceCompany,
  1732. BusName = item.BusName,
  1733. Numbuer = carNum
  1734. };
  1735. if (opRegions.Select(it => it.Name).ToList().Contains(item.Area))
  1736. {
  1737. RegionInfo opRegion = opRegions.Find(it => it.Name.Equals(item.Area));
  1738. if (opRegion != null)
  1739. {
  1740. opRegions.Remove(opRegion);
  1741. if (opRegion.Data.Count > 0)
  1742. {
  1743. opRegion.Data.Add(opData);
  1744. }
  1745. opRegion.Number += carNum;
  1746. opRegions.Add(opRegion);
  1747. }
  1748. }
  1749. else
  1750. {
  1751. opRegions.Add(new RegionInfo() { Name = item.Area, Number = carNum, Data = new List<dynamic>() { opData } });
  1752. }
  1753. }
  1754. }
  1755. _types.Add(new TypeInfo() { Id = 4, RegionItem = opRegions });
  1756. }
  1757. }
  1758. #endregion
  1759. _view.TypeItem = _types;
  1760. return _view;
  1761. }
  1762. #endregion
  1763. #region 市场部销售额
  1764. /// <summary>
  1765. /// 市场部销售额
  1766. /// Init 基础数据(公司/人员/年份/季度/月份)
  1767. /// </summary>
  1768. /// <param name="_dto">市场部销售额请求dto</param>
  1769. /// <returns></returns>
  1770. [HttpPost("PostMarketingSalesInitData")]
  1771. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1772. public async Task<IActionResult> PostMarketingSalesInitData(MarketingSalesInitDataDto _dto)
  1773. {
  1774. #region 参数验证
  1775. MarketingSalesInitDataDtoFoalidator validationRules = new MarketingSalesInitDataDtoFoalidator();
  1776. var validResult = await validationRules.ValidateAsync(_dto);
  1777. if (!validResult.IsValid)
  1778. {
  1779. var errors = new StringBuilder();
  1780. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  1781. return Ok(JsonView(false, errors.ToString()));
  1782. }
  1783. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1784. #region 页面操作权限验证
  1785. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  1786. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  1787. #endregion
  1788. var companyData = _sqlSugar.Queryable<Sys_Company>().Where(it => it.IsDel == 0)
  1789. .Select(it => new { id = it.Id, name = it.CompanyName })
  1790. .ToList();
  1791. List<int> companyIds = companyData.Select(it => it.id).ToList();
  1792. List<int> pickGroupUserIds = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0)
  1793. .Select(it => it.JietuanOperator )
  1794. .ToList();
  1795. //var jobData = _sqlSugar.Queryable<Sys_JobPost>().Where(it => it.IsDel == 0 && companyIds.Contains(it.CompanyId) && (it.JobName.Contains("经理") || it.JobName.Contains("主管")))
  1796. // .Select(it => new { it.Id, it.CompanyId, it.DepId, it.JobName })
  1797. // .ToList();
  1798. //List<int> jobIds = jobData.Select(it => it.Id).ToList();
  1799. //(depIds.Contains(it.DepId) || jobIds.Contains(it.JobPostId)
  1800. //userId = 21
  1801. var userData = _sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && (pickGroupUserIds.Contains(it.Id) || it.Id == 21))
  1802. .Select(it => new { id = it.Id, companyId = it.CompanyId, name = it.CnName })
  1803. .ToList();
  1804. companyData.Insert(0, new { id = -1, name = "全部" });
  1805. userData.Insert(0, new { id = -1, companyId = -1, name = "全部" });
  1806. #region 年份
  1807. var dtData = new List<dynamic>();
  1808. int dt = DateTime.Now.Year;
  1809. for (int y = dt; y >= dt-4; y--)
  1810. {
  1811. //季度
  1812. var quarterDatas = new List<dynamic>();
  1813. quarterDatas.Add(new { name = "全部", beginDt = $"{y}-01-01", endDt = $"{y}-12-31" });
  1814. for (int q = 0; q < 4; q++)
  1815. {
  1816. dynamic quarterData = null;
  1817. if (q == 0)
  1818. {
  1819. var monthDatas = new List<dynamic>();
  1820. monthDatas.Add(new { name = $"全部", beginDt = $"{y}-01-01", endDt = $" {y}-03-31" });
  1821. for (int m = 1; m < 4; m++)
  1822. {
  1823. MonthlyTimeSegment timeSegment = new MonthlyTimeSegment(y, m);
  1824. monthDatas.Add(new { name = $"{ConvertToChinese(m)}", beginDt = timeSegment.Start.ToString("yyyy-MM-dd"), endDt = timeSegment.End.ToString("yyyy-MM-dd") });
  1825. }
  1826. //quarterData = new { name = "第一季度", beginDt = $"{y}-01-01", endDt = $" {y}-03-31", monthData = monthDatas };
  1827. quarterData = new { name = "第一季度", monthData = monthDatas };
  1828. }
  1829. else if (q == 1)
  1830. {
  1831. var monthDatas = new List<dynamic>();
  1832. monthDatas.Add(new { name = $"全部", beginDt = $"{y}-04-01", endDt = $"{y}-06-30" });
  1833. for (int m = 4; m < 7; m++)
  1834. {
  1835. MonthlyTimeSegment timeSegment = new MonthlyTimeSegment(y, m);
  1836. monthDatas.Add(new { name = $"{ConvertToChinese(m)}", beginDt = timeSegment.Start.ToString("yyyy-MM-dd"), endDt = timeSegment.End.ToString("yyyy-MM-dd") });
  1837. }
  1838. //quarterData = new { name = "第二季度", beginDt = $"{y}-04-01", endDt = $"{y}-06-30", monthData = monthDatas };
  1839. quarterData = new { name = "第二季度", monthData = monthDatas };
  1840. }
  1841. else if (q == 2)
  1842. {
  1843. var monthDatas = new List<dynamic>();
  1844. monthDatas.Add(new { name = $"全部", beginDt = $"{y}-07-01", endDt = $"{y}-09-30" });
  1845. for (int m = 7; m < 10; m++)
  1846. {
  1847. MonthlyTimeSegment timeSegment = new MonthlyTimeSegment(y, m);
  1848. monthDatas.Add(new { name = $"{ConvertToChinese(m)}", beginDt = timeSegment.Start.ToString("yyyy-MM-dd"), endDt = timeSegment.End.ToString("yyyy-MM-dd") });
  1849. }
  1850. //quarterData = new { name = "第三季度", beginDt = $"{y}-07-01", endDt = $"{y}-09-30", monthData = monthDatas };
  1851. quarterData = new { name = "第三季度", monthData = monthDatas };
  1852. }
  1853. else if (q == 3)
  1854. {
  1855. var monthDatas = new List<dynamic>();
  1856. monthDatas.Add(new { name = $"全部", beginDt = $"{y}-10-01", endDt = $"{y}-12-31" });
  1857. for (int m = 10; m < 13; m++)
  1858. {
  1859. MonthlyTimeSegment timeSegment = new MonthlyTimeSegment(y, m);
  1860. monthDatas.Add(new { name = $"{ConvertToChinese(m)}", beginDt = timeSegment.Start.ToString("yyyy-MM-dd"), endDt = timeSegment.End.ToString("yyyy-MM-dd") });
  1861. }
  1862. //quarterData = new { name = "第四季度", beginDt = $"{y}-10-01", endDt = $"{y}-12-31", monthData = monthDatas };
  1863. quarterData = new { name = "第四季度", monthData = monthDatas };
  1864. }
  1865. quarterDatas.Add(quarterData);
  1866. }
  1867. dtData.Add(new
  1868. {
  1869. year = y,
  1870. //yearData = new { beginDt = $"{y}-01-01", endDt = $"{y}-12-31" },
  1871. quarterData = quarterDatas,
  1872. });
  1873. }
  1874. #endregion
  1875. return Ok(JsonView(true, "操作成功!", new { companyData = companyData, userData = userData, dtData = dtData }));
  1876. #endregion
  1877. }
  1878. private static string ConvertToChinese(int month)
  1879. {
  1880. if (month < 1 || month > 12)
  1881. throw new ArgumentOutOfRangeException(nameof(month), "月份必须在1到12之间。");
  1882. var cultureInfo = new System.Globalization.CultureInfo("zh-CN");
  1883. var dateTimeFormat = cultureInfo.DateTimeFormat;
  1884. return dateTimeFormat.GetMonthName(month);
  1885. }
  1886. /// <summary>
  1887. /// 市场部销售额
  1888. /// 年度/季度/月度 报表(同比)
  1889. /// (增加团组查询条件 IsSure=1)
  1890. /// </summary>
  1891. /// <param name="_dto">市场部销售额请求dto</param>
  1892. /// <returns></returns>
  1893. [HttpPost("PostMarketingSalesStatistics")]
  1894. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1895. public async Task<IActionResult> PostMarketingSalesStatistics_Year(MarketingSalesStatisticsDto _dto)
  1896. {
  1897. #region 参数验证
  1898. MarketingSalesStatisticsDtoFoalidator validationRules = new MarketingSalesStatisticsDtoFoalidator();
  1899. var validResult = await validationRules.ValidateAsync(_dto);
  1900. if (!validResult.IsValid)
  1901. {
  1902. var errors = new StringBuilder();
  1903. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  1904. return Ok(JsonView(false, errors.ToString()));
  1905. }
  1906. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1907. #region 页面操作权限验证
  1908. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  1909. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  1910. #endregion
  1911. #endregion
  1912. string beginDt = $"{_dto.BeginDt} 00:00:00",endDt = $"{_dto.EndDt} 23:59:59";
  1913. return Ok(JsonView(true, "操作成功!", await GroupSales(_dto.CompanyId, _dto.GroupPickupUserId, beginDt, endDt)));
  1914. }
  1915. private async Task<List<int>> GetUserIds(int companyId, int groupPickupUserId)
  1916. {
  1917. //全部人员Id
  1918. //查询所有公司的市场部
  1919. List<int> pickGroupIds = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0).Select(it => it.JietuanOperator).Distinct().ToList();
  1920. List<int> userIds = new List<int>();
  1921. var userDatas = await _sqlSugar.Queryable<Sys_Users>()
  1922. .InnerJoin<Sys_Company>((u, c) => u.CompanyId == c.Id)
  1923. .Where((u, c) => u.IsDel == 0 && pickGroupIds.Contains( u.Id))
  1924. .Select((u, c) => new { u.Id, u.CompanyId, u.CnName })
  1925. .ToListAsync();
  1926. userIds = userDatas.Select(it => it.Id).ToList();
  1927. if (companyId > 0)
  1928. {
  1929. userIds = userDatas.Where(it => it.CompanyId == companyId).Select(it => it.Id).ToList();
  1930. }
  1931. if (groupPickupUserId > 0)
  1932. {
  1933. userIds = userDatas.Where(it => it.Id == groupPickupUserId).Select(it => it.Id).ToList();
  1934. }
  1935. return userIds;
  1936. }
  1937. /// <summary>
  1938. /// 计算团组销售额
  1939. /// </summary>
  1940. /// <param name="companyId"></param>
  1941. /// <param name="groupPickupUserId"></param>
  1942. /// <param name="beginDt"></param>
  1943. /// <param name="endDt"></param>
  1944. /// <returns></returns>
  1945. private async Task<SalesYOYView> GroupSales(int companyId, int groupPickupUserId,string beginDt, string endDt)
  1946. {
  1947. decimal thisSales = 0.00M, lastSales = 0.00M, yoy = 1.00M;
  1948. var _view = new SalesYOYView();
  1949. List<int> userIds = new List<int>();
  1950. userIds = await GetUserIds(companyId, groupPickupUserId);
  1951. string userSqlWhere = "";
  1952. if (userIds.Count > 0)
  1953. {
  1954. userSqlWhere = string.Format($" And Id IN ({string.Join(',', userIds)})");
  1955. }
  1956. else
  1957. {
  1958. _view = new SalesYOYView
  1959. {
  1960. thisYearSales = "0.00",
  1961. lastYearSales = "0.00",
  1962. };
  1963. return _view;
  1964. }
  1965. string sql = string.Format($@"SELECT
  1966. CAST(SUM(Sales) AS decimal(12,2)) AS Sales
  1967. FROM
  1968. (
  1969. SELECT
  1970. YEAR(di.VisitDate) AS [Year],
  1971. (
  1972. SELECT
  1973. CAST(SUM(ItemSumPrice * Rate) AS decimal(12,2))
  1974. FROM
  1975. Fin_ForeignReceivables
  1976. WHERE
  1977. IsDel = 0
  1978. AND AddingWay IN (0, 1, 2)
  1979. AND di.Id = Diid
  1980. ) AS Sales
  1981. FROM
  1982. Grp_DelegationInfo di
  1983. WHERE
  1984. di.IsDel = 0
  1985. AND di.IsSure = 1
  1986. AND di.JietuanOperator IN (
  1987. SELECT
  1988. Id
  1989. FROM
  1990. Sys_Users
  1991. WITH
  1992. (NoLock)
  1993. WHERE
  1994. IsDel = 0 {userSqlWhere}
  1995. )
  1996. AND di.VisitDate BETWEEN '{beginDt}' AND '{endDt}'
  1997. ) temp");
  1998. var newDB = _sqlSugar.CopyNew();
  1999. var salesData = newDB.SqlQueryable<SalesView>(sql).First();
  2000. thisSales = salesData?.Sales ?? 0.00M;
  2001. string lastBeginDt = Convert.ToDateTime(beginDt).AddYears(-1).ToString("yyyy-MM-dd HH:mm:ss"),
  2002. lastEndDt = Convert.ToDateTime(endDt).AddYears(-1).ToString("yyyy-MM-dd HH:mm:ss");
  2003. string lastSql = string.Format($@"SELECT
  2004. CAST(SUM(Sales) AS decimal(12,2)) AS Sales
  2005. FROM
  2006. (
  2007. SELECT
  2008. YEAR(di.VisitDate) AS [Year],
  2009. (
  2010. SELECT
  2011. CAST(SUM(ItemSumPrice * Rate) AS decimal(12,2))
  2012. FROM
  2013. Fin_ForeignReceivables
  2014. WHERE
  2015. IsDel = 0
  2016. AND AddingWay IN (0, 1, 2)
  2017. AND di.Id = Diid
  2018. ) AS Sales
  2019. FROM
  2020. Grp_DelegationInfo di
  2021. WHERE
  2022. di.IsDel = 0
  2023. AND di.IsSure = 1
  2024. AND di.JietuanOperator IN (
  2025. SELECT
  2026. Id
  2027. FROM
  2028. Sys_Users
  2029. WITH
  2030. (NoLock)
  2031. WHERE
  2032. IsDel = 0 {userSqlWhere}
  2033. )
  2034. AND di.Issure = 1
  2035. AND di.VisitDate BETWEEN '{lastBeginDt}' AND '{lastEndDt}'
  2036. ) temp");
  2037. var salesData1 = newDB.SqlQueryable<SalesView>(lastSql).First();
  2038. lastSales = salesData1?.Sales ?? 0.00M;
  2039. if (lastSales != 0 && thisSales != 0) yoy = (thisSales - lastSales) / lastSales;
  2040. _view = new SalesYOYView
  2041. {
  2042. thisYearSales = thisSales.ToString("#0.00"),
  2043. lastYearSales = lastSales.ToString("#0.00"),
  2044. yoy = yoy.ToString("#0.00")
  2045. };
  2046. return _view;
  2047. }
  2048. private class SalesView
  2049. {
  2050. public decimal Sales { get; set; }
  2051. }
  2052. private class SalesYOYView
  2053. {
  2054. public string thisYearSales { get; set; }
  2055. public string lastYearSales { get; set; }
  2056. public string yoy { get; set; }
  2057. }
  2058. /// <summary>
  2059. /// 市场部销售额
  2060. /// 团组列表
  2061. /// (增加团组查询条件 IsSure=1)
  2062. /// </summary>
  2063. /// <param name="_dto">市场部销售额请求dto</param>
  2064. /// <returns></returns>
  2065. [HttpPost("PostMarketingSalesGroupList")]
  2066. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2067. public async Task<IActionResult> PostMarketingSalesGroupList(MarketingSalesGroupListDto _dto)
  2068. {
  2069. #region 参数验证
  2070. MarketingSalesStatisticsDtoFoalidator validationRules = new MarketingSalesStatisticsDtoFoalidator();
  2071. var validResult = await validationRules.ValidateAsync(_dto);
  2072. if (!validResult.IsValid)
  2073. {
  2074. var errors = new StringBuilder();
  2075. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2076. return Ok(JsonView(false, errors.ToString()));
  2077. }
  2078. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2079. #region 页面操作权限验证
  2080. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2081. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2082. #endregion
  2083. #endregion
  2084. string userSql = "";
  2085. List<int> userIds = new List<int>();
  2086. userIds = await GetUserIds(_dto.CompanyId, _dto.GroupPickupUserId);
  2087. if (userIds.Count > 0)
  2088. {
  2089. userSql = @$" And di.JietuanOperator In ({string.Join(",",userIds)})";
  2090. }
  2091. if (!string.IsNullOrEmpty(_dto.SearchCriteria))
  2092. {
  2093. userSql += string.Format(@$" AND di.TeamName Like '%{_dto.SearchCriteria}%'");
  2094. }
  2095. string beginDt = $"{_dto.BeginDt} 00:00:00", endDt = $"{_dto.EndDt} 23:59:59";
  2096. string sql = string.Format(@$"SELECT
  2097. ROW_NUMBER() OVER (
  2098. ORDER BY
  2099. CollectionDays
  2100. ) AS RowNumber,
  2101. *
  2102. FROM
  2103. (
  2104. SELECT
  2105. di.Id,
  2106. di.TeamName,
  2107. di.ClientUnit,
  2108. di.ClientName,
  2109. di.VisitDate,
  2110. di.VisitPNumber,
  2111. di.JietuanOperator,
  2112. di.VisitEndDate,
  2113. (
  2114. SELECT
  2115. CAST(
  2116. COALESCE(SUM(ItemSumPrice * Rate), 0) AS DECIMAL(12, 2)
  2117. ) AS GroupSales
  2118. FROM
  2119. Fin_ForeignReceivables
  2120. WHERE
  2121. IsDel = 0
  2122. AND di.Id = Diid
  2123. AND AddingWay IN (0, 1, 2)
  2124. ) AS GroupSales,
  2125. u.CnName AS GroupPickupUser,
  2126. DATEADD(DAY, 7, di.VisitEndDate) AS CollectionDays
  2127. FROM
  2128. Grp_DelegationInfo di
  2129. WITH
  2130. (NoLock)
  2131. LEFT JOIN Sys_Users u ON di.JietuanOperator = u.Id
  2132. WHERE
  2133. di.Isdel = 0
  2134. AND di.IsSure = 1 {userSql}
  2135. AND VisitDate Between '{beginDt}' And '{endDt}'
  2136. ) Temp ");
  2137. RefAsync<int> total = 0;
  2138. var groupData = await _sqlSugar.SqlQueryable<MarketingSalesGroupList>(sql).ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);
  2139. return Ok(JsonView(true, "操作成功!", groupData, total));
  2140. }
  2141. /// <summary>
  2142. /// 市场部销售额
  2143. /// 客户类型、客户等级 统计
  2144. /// </summary>
  2145. /// <param name="_dto">市场部销售额请求dto</param>
  2146. /// <returns></returns>
  2147. [HttpPost("PostMarketingSalesGroupStatistics")]
  2148. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2149. public async Task<IActionResult> PostMarketingSalesGroupStatistics(MarketingSalesGroupStatisticsDto _dto)
  2150. {
  2151. #region 参数验证
  2152. MarketingSalesStatisticsDtoFoalidator validationRules = new MarketingSalesStatisticsDtoFoalidator();
  2153. var validResult = await validationRules.ValidateAsync(_dto);
  2154. if (!validResult.IsValid)
  2155. {
  2156. var errors = new StringBuilder();
  2157. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2158. return Ok(JsonView(false, errors.ToString()));
  2159. }
  2160. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2161. #region 页面操作权限验证
  2162. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2163. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2164. #endregion
  2165. #endregion
  2166. string beginDt = $"{_dto.BeginDt} 00:00:00", endDt = $"{_dto.EndDt} 23:59:59";
  2167. List<int> userIds = await GetUserIds(_dto.CompanyId, _dto.GroupPickupUserId);
  2168. string userSql = "";
  2169. if (userIds.Count > 0)
  2170. {
  2171. userSql = string.Format(@$" AND JietuanOperator IN ({string.Join(",",userIds)})");
  2172. }
  2173. string sql = "";
  2174. if (_dto.StatisticsType == 1 )
  2175. {
  2176. sql = string.Format(@$"Select
  2177. sd.[Name],
  2178. Count(*) As [Count]
  2179. From Grp_DelegationInfo di
  2180. Left Join Sys_SetData sd On di.TeamDid = sd.Id
  2181. Where di.Isdel = 0
  2182. And IsSure = 1 {userSql}
  2183. And VisitDate Between '{beginDt}' And '{endDt}'
  2184. Group By [Name]
  2185. Order By Count Desc");
  2186. }
  2187. else if (_dto.StatisticsType == 2)
  2188. {
  2189. sql = string.Format(@$"Select
  2190. sd.[Name],
  2191. Count(*) As [Count]
  2192. From Grp_DelegationInfo di
  2193. Left Join Sys_SetData sd On di.TeamLevSId = sd.Id
  2194. Where di.Isdel = 0
  2195. And IsSure = 1 {userSql}
  2196. And VisitDate Between '{beginDt}' And '{endDt}'
  2197. Group By [Name]
  2198. Order By Count Desc");
  2199. }
  2200. else return Ok(JsonView(false, "StatisticsType不在可取范围!"));
  2201. if (_dto.PortType == 1)
  2202. {
  2203. string sql1 = string.Format(@$"Select
  2204. sd.[Name],
  2205. Count(*) As [Count]
  2206. From Grp_DelegationInfo di
  2207. Left Join Sys_SetData sd On di.TeamDid = sd.Id
  2208. Where di.Isdel = 0
  2209. And IsSure = 1 {userSql}
  2210. And VisitDate Between '{beginDt}' And '{endDt}'
  2211. Group By [Name]
  2212. Order By Count Desc");
  2213. var customerTypeData = await _sqlSugar.SqlQueryable<MarketingSalesGroupStatisticsView>(sql1).ToListAsync();
  2214. string sql2 = string.Format(@$"Select
  2215. sd.[Name],
  2216. Count(*) As [Count]
  2217. From Grp_DelegationInfo di
  2218. Left Join Sys_SetData sd On di.TeamLevSId = sd.Id
  2219. Where di.Isdel = 0
  2220. And IsSure = 1 {userSql}
  2221. And VisitDate Between '{beginDt}' And '{endDt}'
  2222. Group By [Name]
  2223. Order By Count Desc");
  2224. var clientGradeData = await _sqlSugar.SqlQueryable<MarketingSalesGroupStatisticsView>(sql2).ToListAsync();
  2225. return Ok(JsonView(true, "操作成功!", new {
  2226. customerTypeData= customerTypeData,
  2227. clientGradeData = clientGradeData
  2228. }));
  2229. }
  2230. else if (_dto.PortType == 2 || _dto.PortType == 3)
  2231. {
  2232. var data = await _sqlSugar.SqlQueryable<MarketingSalesGroupStatisticsView>(sql).ToListAsync();
  2233. return Ok(JsonView(true, "操作成功!", data, data.Count));
  2234. }
  2235. else return Ok(JsonView(false, MsgTips.Port));
  2236. }
  2237. /// <summary>
  2238. /// 市场部销售额
  2239. /// 接单排名
  2240. /// </summary>
  2241. /// <param name="_dto">市场部销售额请求dto</param>
  2242. /// <returns></returns>
  2243. [HttpPost("PostMarketingSalesOrderRanking")]
  2244. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2245. public async Task<IActionResult> PostMarketingSalesOrderRanking(MarketingSalesOrderRankingDto _dto)
  2246. {
  2247. #region 参数验证
  2248. MarketingSalesStatisticsDtoFoalidator validationRules = new MarketingSalesStatisticsDtoFoalidator();
  2249. var validResult = await validationRules.ValidateAsync(_dto);
  2250. if (!validResult.IsValid)
  2251. {
  2252. var errors = new StringBuilder();
  2253. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2254. return Ok(JsonView(false, errors.ToString()));
  2255. }
  2256. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2257. #region 页面操作权限验证
  2258. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2259. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2260. #endregion
  2261. #endregion
  2262. string beginDt = $"{_dto.BeginDt} 00:00:00", endDt = $"{_dto.EndDt} 23:59:59";
  2263. List<int> userIds = await GetUserIds(_dto.CompanyId, _dto.GroupPickupUserId);
  2264. string userSql = "";
  2265. if (userIds.Count > 0)
  2266. {
  2267. userSql = string.Format(@$" AND JietuanOperator IN ({string.Join(",", userIds)})");
  2268. }
  2269. string sql = string.Format(@$"Select
  2270. ROW_NUMBER() Over(Order By Count(*) Desc) As RowNumber,
  2271. u.CnName As UserName,
  2272. Count(*) As [Count]
  2273. From Grp_DelegationInfo di
  2274. Left Join Sys_Users u On di.JietuanOperator = u.Id
  2275. Where di.Isdel = 0
  2276. AND IsSure = 1 {userSql}
  2277. And VisitDate Between '{beginDt}' And '{endDt}'
  2278. Group By CnName");
  2279. RefAsync<int> total = 0;
  2280. var rankingData = await _sqlSugar.SqlQueryable<MarketingSalesOrderRankingView>(sql).ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);
  2281. return Ok(JsonView(true, "操作成功!", rankingData, total));
  2282. }
  2283. /// <summary>
  2284. /// 市场部销售额
  2285. /// 客户拜访列表
  2286. /// </summary>
  2287. /// <param name="_dto">市场部销售额请求dto</param>
  2288. /// <returns></returns>
  2289. [HttpPost("PostMarketingSalesVCList")]
  2290. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2291. public async Task<IActionResult> PostMarketingSalesVCList(MarketingSalesVCListDto _dto)
  2292. {
  2293. #region 参数验证
  2294. MarketingSalesUserPageFuncDtoBaseFoalidator validationRules = new MarketingSalesUserPageFuncDtoBaseFoalidator();
  2295. var validResult = await validationRules.ValidateAsync(_dto);
  2296. if (!validResult.IsValid)
  2297. {
  2298. var errors = new StringBuilder();
  2299. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2300. return Ok(JsonView(false, errors.ToString()));
  2301. }
  2302. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2303. #region 页面操作权限验证
  2304. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2305. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2306. #endregion
  2307. #endregion
  2308. return Ok(await _visitingClientsRep._List(_dto.PortType,_dto.PageIndex,_dto.PageSize,_dto.DiId,_dto.Search));
  2309. }
  2310. /// <summary>
  2311. /// 市场部销售额
  2312. /// 客户拜访 操作(添加 Or 编辑)
  2313. /// </summary>
  2314. /// <param name="_dto">市场部销售额请求dto</param>
  2315. /// <returns></returns>
  2316. [HttpPost("PostMarketingSalesVCOperate")]
  2317. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2318. public async Task<IActionResult> PostMarketingSalesVCOperate(MarketingSalesVCOperrateDto _dto)
  2319. {
  2320. #region 参数验证
  2321. MarketingSalesUserPageFuncDtoBaseFoalidator validationRules = new MarketingSalesUserPageFuncDtoBaseFoalidator();
  2322. var validResult = await validationRules.ValidateAsync(_dto);
  2323. if (!validResult.IsValid)
  2324. {
  2325. var errors = new StringBuilder();
  2326. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2327. return Ok(JsonView(false, errors.ToString()));
  2328. }
  2329. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2330. #region 页面操作权限验证
  2331. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2332. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2333. #endregion
  2334. #endregion
  2335. return Ok(await _visitingClientsRep._AddOrEdit(_dto));
  2336. }
  2337. /// <summary>
  2338. /// 市场部销售额
  2339. /// 客户拜访 Del
  2340. /// </summary>
  2341. /// <param name="_dto">市场部销售额请求dto</param>
  2342. /// <returns></returns>
  2343. [HttpPost("PostMarketingSalesVCDel")]
  2344. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2345. public async Task<IActionResult> PostMarketingSalesVCDel(MarketingSalesVCDelDto _dto)
  2346. {
  2347. return Ok(await _visitingClientsRep._Del(_dto.Id,_dto.UserId));
  2348. }
  2349. /// <summary>
  2350. /// 市场部销售额
  2351. /// 客户拜访 操作 save
  2352. /// </summary>
  2353. /// <param name="_dto">市场部销售额请求dto</param>
  2354. /// <returns></returns>
  2355. [HttpPost("PostMarketingSalesVCSave")]
  2356. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2357. public async Task<IActionResult> PostMarketingSalesVCSave(MarketingSalesVCSaveDto _dto)
  2358. {
  2359. #region 参数验证
  2360. MarketingSalesUserPageFuncDtoBaseFoalidator validationRules = new MarketingSalesUserPageFuncDtoBaseFoalidator();
  2361. var validResult = await validationRules.ValidateAsync(_dto);
  2362. if (!validResult.IsValid)
  2363. {
  2364. var errors = new StringBuilder();
  2365. foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
  2366. return Ok(JsonView(false, errors.ToString()));
  2367. }
  2368. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  2369. #region 页面操作权限验证
  2370. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  2371. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
  2372. #endregion
  2373. #endregion
  2374. return Ok(await _visitingClientsRep._Save(_dto));
  2375. }
  2376. #endregion
  2377. }
  2378. }