StatisticsController.cs 120 KB

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