CarTouristGuideGroundRepository.cs 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569
  1. using Aspose.Words.Tables;
  2. using AutoMapper;
  3. using NPOI.SS.Formula.Functions;
  4. using NPOI.SS.UserModel;
  5. using NPOI.Util;
  6. using OASystem.Domain;
  7. using OASystem.Domain.AesEncryption;
  8. using OASystem.Domain.Dtos.Financial;
  9. using OASystem.Domain.Dtos.Groups;
  10. using OASystem.Domain.Dtos.QiYeWeChat;
  11. using OASystem.Domain.Entities.Financial;
  12. using OASystem.Domain.Entities.Groups;
  13. using OASystem.Domain.Entities.Resource;
  14. using OASystem.Domain.ViewModels.Groups;
  15. using OASystem.Infrastructure.Repositories.Financial;
  16. using OASystem.Infrastructure.Repositories.System;
  17. using OASystem.Infrastructure.Tools;
  18. using SqlSugar.Extensions;
  19. using System.Collections.Generic;
  20. using System.Linq;
  21. using System.Reflection;
  22. using static NPOI.HSSF.Util.HSSFColor;
  23. namespace OASystem.Infrastructure.Repositories.Groups
  24. {
  25. public class CarTouristGuideGroundRepository : BaseRepository<Grp_CarTouristGuideGroundReservations, Grp_CarTouristGuideGroundReservationsContent>
  26. {
  27. private readonly IMapper _mapper;
  28. private readonly CheckBoxsRepository _checkRep;
  29. private readonly SetDataRepository _setDataRep;
  30. private readonly DailyFeePaymentRepository _daiRep; //日付申请仓库
  31. private readonly GroupCostParameterRepository _groupCostParameterRepository;
  32. private readonly ForeignReceivablesRepository _foreignReceivablesRepository;
  33. public CarTouristGuideGroundRepository(SqlSugarClient sqlSugar, IMapper mapper, CheckBoxsRepository checkRep, SetDataRepository setDataRep,
  34. DailyFeePaymentRepository daiRep, GroupCostParameterRepository groupCostParameterRepository, ForeignReceivablesRepository foreignReceivablesRepository)
  35. : base(sqlSugar)
  36. {
  37. _mapper = mapper;
  38. _checkRep = checkRep;
  39. _setDataRep = setDataRep;
  40. _daiRep = daiRep;
  41. _groupCostParameterRepository = groupCostParameterRepository;
  42. _foreignReceivablesRepository = foreignReceivablesRepository;
  43. }
  44. public async Task<Result> OpCarTouristGuideGround(OpCarTouristGuideGroundDto dto)
  45. {
  46. Result result = new Result() { Code = -2, Msg = "未知错误" };
  47. BeginTran();
  48. try
  49. {
  50. int id = 0;
  51. var grp_CarTouristGuide = _mapper.Map<Grp_CarTouristGuideGroundReservations>(dto);
  52. if (dto.Status == 1)//添加
  53. {
  54. var grp_CarTouristGuideGround = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
  55. .First(a => a.IsDel == 0 &&
  56. a.Area == dto.Area &&
  57. a.BusName == dto.BusName &&
  58. a.ServiceGuide == dto.ServiceGuide &&
  59. a.DiId == dto.DiId &&
  60. a.BusTel == dto.BusTel &&
  61. a.ServiceTel == dto.ServiceTel &&
  62. a.PriceName == dto.PriceName
  63. );
  64. grp_CarTouristGuideGround = null;
  65. if (grp_CarTouristGuideGround != null)
  66. {
  67. return result = new Result() { Code = -1, Msg = "该笔费用已存在,请勿重复添加!" };
  68. }
  69. else
  70. {
  71. id = await AddAsyncReturnId(grp_CarTouristGuide);
  72. if (id == 0)
  73. {
  74. RollbackTran();
  75. result = new Result() { Code = -1, Msg = "添加失败,请稍后重试!" };
  76. }
  77. else
  78. {
  79. result = new Result() { Code = 0, Msg = "添加成功!" };
  80. }
  81. }
  82. }
  83. else if (dto.Status == 2)//修改
  84. {
  85. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_CarTouristGuideGroundReservations
  86. {
  87. Area = grp_CarTouristGuide.Area,
  88. ServiceCompany = grp_CarTouristGuide.ServiceCompany,
  89. ServiceGuide = grp_CarTouristGuide.ServiceGuide,
  90. ServiceTel = grp_CarTouristGuide.ServiceTel,
  91. BusName = grp_CarTouristGuide.BusName,
  92. BusDescription = grp_CarTouristGuide.BusDescription,
  93. BusTel = grp_CarTouristGuide.BusTel,
  94. ServiceStartTime = grp_CarTouristGuide.ServiceStartTime,
  95. ServiceEndTime = grp_CarTouristGuide.ServiceEndTime,
  96. ServiceDescription = grp_CarTouristGuide.ServiceDescription,
  97. QuotedPriceExplanation = grp_CarTouristGuide.QuotedPriceExplanation,
  98. OrbitalPrivateTransfer = grp_CarTouristGuide.OrbitalPrivateTransfer,
  99. Remark = grp_CarTouristGuide.Remark,
  100. PriceType = grp_CarTouristGuide.PriceType,
  101. PriceName = grp_CarTouristGuide.PriceName,
  102. });
  103. if (res)
  104. {
  105. id = dto.Id;
  106. result = new Result() { Code = 0, Msg = "修改成功!" };
  107. }
  108. else
  109. {
  110. RollbackTran();
  111. result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  112. }
  113. }
  114. #region add导游地接数据屏蔽
  115. //if (id != 0)
  116. //{
  117. // var _LocalGuideDataCar = _sqlSugar.Queryable<Res_LocalGuideData>()
  118. // .First(a =>
  119. // a.UnitName == AesEncryptionHelper.Encrypt(dto.BusName) &&
  120. // a.ContactTel == AesEncryptionHelper.Encrypt(dto.BusTel) &&
  121. // a.IsDel == 0
  122. // );
  123. // if (_LocalGuideDataCar == null)
  124. // {
  125. // var res_LocalGuideCar = new Res_LocalGuideData();
  126. // res_LocalGuideCar.UnitName = dto.BusName;
  127. // res_LocalGuideCar.ContactTel = dto.BusTel;
  128. // res_LocalGuideCar.CreateUserId = dto.CreateUserId;
  129. // EncryptionProcessor.EncryptProperties(res_LocalGuideCar);
  130. // int cId = await _sqlSugar.Insertable(res_LocalGuideCar).ExecuteReturnIdentityAsync();
  131. // }
  132. // var _LocalGuideDataService = _sqlSugar.Queryable<Res_LocalGuideData>()
  133. // .First(a =>
  134. // a.UnitName == AesEncryptionHelper.Encrypt(dto.ServiceCompany) &&
  135. // a.ContactTel == AesEncryptionHelper.Encrypt(dto.ServiceTel) &&
  136. // a.IsDel == 0
  137. // );
  138. // if (_LocalGuideDataService == null)
  139. // {
  140. // Res_LocalGuideData res_LocalGuideService = new Res_LocalGuideData();
  141. // res_LocalGuideService.UnitName = dto.ServiceCompany;
  142. // res_LocalGuideService.ContactTel = dto.ServiceTel;
  143. // res_LocalGuideService.Contact = dto.ServiceTel;
  144. // res_LocalGuideService.CreateUserId = dto.CreateUserId;
  145. // EncryptionProcessor.EncryptProperties(res_LocalGuideService);
  146. // int cId = await _sqlSugar.Insertable(res_LocalGuideService).ExecuteReturnIdentityAsync();
  147. // }
  148. //}
  149. #endregion
  150. CommitTran();
  151. }
  152. catch (Exception ex)
  153. {
  154. result = new Result() { Code = -2, Msg = "未知错误" + ex.Message };
  155. }
  156. return result;
  157. }
  158. public Result CarTouristGuideGroundContent(CarTouristGuideGroundContentDto dto)
  159. {
  160. Result result = new Result() { Code = -2, Msg = "未知错误" };
  161. try
  162. {
  163. Grp_CarTouristGuideGroundReservations grpCarOp = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().First(x => x.Id == dto.Id);
  164. if (!DateTime.TryParse(grpCarOp?.ServiceStartTime, out DateTime start))
  165. {
  166. result.Msg = "服务开始时间不存在!";
  167. result.Code = -1;
  168. return result;
  169. }
  170. if (!DateTime.TryParse(grpCarOp?.ServiceEndTime, out DateTime end))
  171. {
  172. result.Msg = "服务结束时间不存在!";
  173. result.Code = -1;
  174. return result;
  175. }
  176. if (DateTime.Compare(end, start) < 0)
  177. {
  178. result.Msg = "服务时间区间有误!结束时间不应该小于开始时间!";
  179. result.Code = -1;
  180. return result;
  181. }
  182. TimeSpan ts = end - start; //计算时间差
  183. int day = ts.Days;
  184. var diid = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == 79)
  185. .Select(x => x.DIId)
  186. .Distinct()
  187. .ToList();
  188. //团组下拉框
  189. List<Grp_DelegationInfo> _Delegations = diid.Any()
  190. ? _sqlSugar.Queryable<Grp_DelegationInfo>()
  191. .Where(x => x.IsDel == 0 && diid.Contains(x.Id)).ToList()
  192. : new List<Grp_DelegationInfo>();
  193. List<ShareGroupInfoIIView> grp_Delegations = _mapper.Map<List<ShareGroupInfoIIView>>(_Delegations);
  194. //支付方式
  195. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  196. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  197. //列表初始化
  198. List<Sys_SetData> TableInitialization = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 17 && a.IsDel == 0).ToList();
  199. List<SetDataInfoView> _TableInitialization = _mapper.Map<List<SetDataInfoView>>(TableInitialization);
  200. _TableInitialization = _TableInitialization.OrderBy(x => x.RemarkSort).ToList();
  201. List<Sys_SetData> ssd = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.STid == 78).ToList();
  202. List<SetDataInfoView> ssdv = _mapper.Map<List<Sys_SetData>, List<SetDataInfoView>>(ssd);
  203. var carTouristGuides = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>()
  204. .LeftJoin<Sys_SetData>((a, b) => b.IsDel == 0 && a.SId == b.Id)
  205. .Where(a => a.IsDel == 0 && a.CTGGRId == dto.Id)
  206. .Select((a, b) => new CarTouristGuideGroundReservationsContentView
  207. {
  208. SId = a.SId,
  209. Id = a.Id,
  210. Count = a.Count,
  211. DatePrice = a.DatePrice,
  212. Price = a.Price,
  213. PriceContent = a.PriceContent,
  214. Units = a.Units,
  215. SidName = b.Name
  216. })
  217. .ToList();
  218. var weikuanSign = new int[] { 1070, 1071, };
  219. TableInitialization.RemoveAll(x => weikuanSign.Contains(x.Id));
  220. var weiKuanArr = _TableInitialization.Where(x => weikuanSign.Contains(x.Id)).ToList();
  221. var weiKuanResultArr = carTouristGuides.Where(x => weikuanSign.Contains(x.SId)).ToList();
  222. carTouristGuides.RemoveAll(x => weikuanSign.Contains(x.SId));
  223. var existingSIdArr = new HashSet<int>(carTouristGuides.Select(x => x.SId));
  224. foreach (var itemSt in TableInitialization)
  225. {
  226. if (!existingSIdArr.Contains(itemSt.Id))
  227. {
  228. carTouristGuides.Add(new CarTouristGuideGroundReservationsContentView
  229. {
  230. SId = itemSt.Id,
  231. Count = 1,
  232. SidName = itemSt.Name,
  233. });
  234. existingSIdArr.Add(itemSt.Id);
  235. }
  236. }
  237. var groupResult = carTouristGuides.GroupBy(x => x.SId).ToDictionary(x => x.Key, x => x.ToList());
  238. foreach (var item in groupResult.Keys)
  239. {
  240. var startForTime = start;
  241. var dayResult = new List<CarTouristGuideGroundReservationsContentView>();
  242. for (var i = 0; i <= day; i++)
  243. {
  244. dayResult.Add(new CarTouristGuideGroundReservationsContentView
  245. {
  246. Count = 1,
  247. DatePrice = startForTime,
  248. SId = item,
  249. SidName = groupResult[item][0].SidName
  250. });
  251. startForTime = startForTime.AddDays(1);
  252. }
  253. if (groupResult[item].Count != day)
  254. {
  255. for (var m = 0; m < groupResult[item].Count; m++)
  256. {
  257. for (var m1 = 0; m1 < dayResult.Count; m1++)
  258. {
  259. if (groupResult[item][m].DatePrice == dayResult[m1].DatePrice)
  260. {
  261. dayResult[m1] = groupResult[item][m];
  262. }
  263. }
  264. }
  265. }
  266. else
  267. {
  268. groupResult[item] = groupResult[item].OrderBy(x => x.DatePrice).ToList();
  269. if (groupResult[item][0].DatePrice == dayResult[0].DatePrice && groupResult[item][day - 1].DatePrice == dayResult[day - 1].DatePrice)
  270. {
  271. dayResult = groupResult[item];
  272. }
  273. else
  274. {
  275. for (var m = 0; m < groupResult[item].Count; m++)
  276. {
  277. for (var m1 = 0; m1 < dayResult.Count; m1++)
  278. {
  279. if (groupResult[item][m].DatePrice == dayResult[m1].DatePrice)
  280. {
  281. dayResult[m1] = groupResult[item][m];
  282. }
  283. }
  284. }
  285. }
  286. }
  287. groupResult[item] = dayResult;
  288. }
  289. carTouristGuides = groupResult.Values.SelectMany(sublist => sublist).OrderBy(x => x.SId).ThenBy(x => x.DatePrice).ToList();
  290. var _CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment, Sys_SetData, Sys_SetData>(
  291. (g, s1, s2) => new JoinQueryInfos(
  292. JoinType.Left, g.PayDId == s1.Id,
  293. JoinType.Left, g.PaymentCurrency == s2.Id
  294. ))
  295. .Where((g, s1, s2) => g.CId == dto.Id && g.IsDel == 0 && g.CTable == 79)
  296. .Select((g, s1, s2) => new CarTouristCreditCardPaymentView
  297. {
  298. IsAuditGM = g.IsAuditGM,
  299. PayDId = g.PayDId,
  300. PaymentCurrency = g.PaymentCurrency,
  301. Payee = g.Payee,
  302. PayMoney = g.PayMoney,
  303. PayPercentage = g.PayPercentage,
  304. PayName = s1.Name,
  305. PaymentCurrencyName = s2.Name,
  306. OrbitalPrivateTransfer = g.OrbitalPrivateTransfer,
  307. OrbitalPrivateTransferStr = g.OrbitalPrivateTransfer == 0 ? "公转" : "私转",
  308. BankNo = g.BankNo,
  309. CardholderName = g.CardholderName,
  310. CompanyBankNo = g.CompanyBankNo,
  311. ConsumptionDate = g.ConsumptionDate,
  312. ConsumptionPatterns = g.ConsumptionPatterns,
  313. Ctdid = g.CTDId,
  314. OtherBankName = g.OtherBankName,
  315. OtherSideName = g.OtherSideName,
  316. OtherSideNo = g.OtherSideNo,
  317. })
  318. .First();
  319. Dictionary<string, string> soureDic = new Dictionary<string, string>()
  320. {
  321. {"车费", "VF"},
  322. {"导游费", "T/G S"},
  323. {"客户午餐费用" , "L"},
  324. {"导游景点费" , "T/G EF"},
  325. {"导游小费" , "T/G T"},
  326. // --
  327. {"司机小费", "DRV T"},
  328. {"司机餐补", "C/F M"},
  329. {"车超时费", "C/F OF"},
  330. {"导游餐补", "T/G M"},
  331. {"导游房补", "T/G A"},
  332. {"导游交通", "T/G TF"},
  333. {"客户早餐费用", "B"},
  334. {"客户晚餐费用", "D"},
  335. {"景点门票费", "EF"},
  336. {"饮料/零食/水果", "B/R/F"},
  337. {"翻译费", "I/F"},
  338. };
  339. var checkedItem = new List<string>();
  340. var checkedItemId = new List<int>();
  341. var isSaveCheck = false;
  342. if (string.IsNullOrWhiteSpace(grpCarOp.SelectCheck))
  343. {
  344. //获取成本选中
  345. var checkTopArr = _checkRep.GetCheckBoxsByDiid(grpCarOp.DiId);
  346. if (true)
  347. {
  348. var FindTop = checkTopArr.Find(x => x.CbType == "Top");
  349. if (FindTop != null)
  350. {
  351. var selectName = FindTop.CbValues.Split(',').ToList<string>();
  352. foreach (var soureKey in soureDic.Keys)
  353. {
  354. var find = selectName.Find(x => x == soureDic[soureKey]);
  355. if (find == null)
  356. {
  357. var Lindex = carTouristGuides.FindIndex(x => x.SidName == soureKey);
  358. //carTouristGuides.RemoveRange(Lindex, day + 1);
  359. }
  360. else
  361. {
  362. checkedItem.Add(soureKey);
  363. checkedItemId.Add(_TableInitialization.Find(x => x.Name == soureKey)!.Id);
  364. }
  365. }
  366. }
  367. else
  368. {
  369. checkedItem = _TableInitialization.Select(x => x.Name).ToList();
  370. checkedItemId.AddRange(_TableInitialization.Select(x => x.Id).ToList());
  371. }
  372. }
  373. }
  374. else
  375. {
  376. isSaveCheck = true;
  377. var checkedItemThis = grpCarOp.SelectCheck.Split(",").ToList<string>();
  378. int number = 0;
  379. foreach (var item in checkedItemThis)
  380. {
  381. if (!int.TryParse(item, out number))
  382. {
  383. checkedItemId.Add(_TableInitialization.Find(x => x.Name == item)!.Id);
  384. checkedItem.Add(item);
  385. }
  386. else
  387. {
  388. checkedItemId.Add(number);
  389. checkedItem.Add(_TableInitialization.Find(x => x.Id == int.Parse(item))!.Name);
  390. }
  391. }
  392. }
  393. if (grpCarOp.PriceType == 1062) //尾款id
  394. {
  395. if (isSaveCheck)
  396. {
  397. checkedItemId.AddRange(weiKuanArr.Select(x => x.Id).ToList());
  398. checkedItem.AddRange(weiKuanArr.Select(x => x.Name).ToList());
  399. checkedItemId = checkedItemId.Distinct().ToList();
  400. checkedItem = checkedItem.Distinct().ToList();
  401. }
  402. else
  403. {
  404. checkedItemId = weiKuanArr.Select(x => x.Id).ToList();
  405. checkedItem = weiKuanArr.Select(x => x.Name).ToList();
  406. }
  407. var weiPrice = weiKuanResultArr.Find(x => x.SId == 1070);
  408. if (weiPrice != null)
  409. {
  410. weiPrice.SidName = "尾款金额";
  411. }
  412. var weiOther = weiKuanResultArr.Find(x => x.SId == 1071);
  413. if (weiOther != null)
  414. {
  415. weiOther.SidName = "其他额外费用";
  416. }
  417. carTouristGuides.Add(weiPrice ??= new CarTouristGuideGroundReservationsContentView
  418. {
  419. Count = 1,
  420. DatePrice = DateTime.Now,
  421. Price = 0,
  422. PriceContent = "",
  423. SId = 1070,
  424. SidName = "尾款金额",
  425. Units = 0,
  426. });
  427. carTouristGuides.Add(weiOther ??= new CarTouristGuideGroundReservationsContentView
  428. {
  429. Count = 1,
  430. DatePrice = DateTime.Now,
  431. Price = 0,
  432. PriceContent = "",
  433. SId = 1071,
  434. SidName = "其他额外费用",
  435. Units = 0,
  436. });
  437. }
  438. else
  439. {
  440. _TableInitialization.RemoveAll(x => weikuanSign.Contains(x.Id));
  441. checkedItem.RemoveAll(x => x == "尾款金额" || x == "其他额外费用");
  442. checkedItemId.RemoveAll(x => weikuanSign.Contains(x));
  443. }
  444. //三公费用金额以及币种
  445. var boolParse = int.TryParse(grpCarOp.Area, out int natiId);
  446. var NationalTravelFee = _sqlSugar.Queryable<Grp_NationalTravelFee>()
  447. .LeftJoin<Sys_SetData>((a, b) => a.Currency == b.Id)
  448. .Where((a, b) => a.IsDel == 0 && b.IsDel == 0)
  449. .Select((a, b) => new
  450. {
  451. a.Id,
  452. a.Currency,
  453. CurrencyStr = b.Name,
  454. a.FoodCost,
  455. a.RoomCost,
  456. a.PublicCost,
  457. })
  458. .First((a) => boolParse == true && a.Id == natiId);
  459. var rate = new
  460. {
  461. grpCarOp.Rate,
  462. grpCarOp.toCurr
  463. };
  464. var bankCard = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 15)
  465. .Select(x => new
  466. {
  467. x.Id,
  468. x.Name
  469. })
  470. .OrderByDescending(x => x.Id)
  471. .ToList();
  472. if (dto.PortType == 1)
  473. {
  474. var data = new
  475. {
  476. Payment = _Payment,
  477. Delegations = grp_Delegations,
  478. carTouristGuides = carTouristGuides,
  479. CreditCardPayment = _CreditCardPayment,
  480. start,
  481. end,
  482. ssdv,
  483. checkedItem,
  484. existItem = _TableInitialization.Select(x => x.Name).ToList(),
  485. NationalTravelFee,
  486. rate,
  487. bankCard
  488. };
  489. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  490. }
  491. else if (dto.PortType == 2)
  492. {
  493. var data = new
  494. {
  495. Payment = _Payment,
  496. TableInitialization = _TableInitialization,
  497. carTouristGuides = carTouristGuides,
  498. CreditCardPayment = _CreditCardPayment ??= new CarTouristCreditCardPaymentView(),
  499. ssdv,
  500. checkedItemId,
  501. NationalTravelFee,
  502. rate,
  503. bankCard
  504. };
  505. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  506. }
  507. return result = new Result() { Code = -1, Msg = "请传入有效portType" };
  508. }
  509. catch (Exception ex)
  510. {
  511. return result = new Result() { Code = -2, Msg = "未知错误" };
  512. }
  513. }
  514. /// <summary>
  515. /// web弃用
  516. /// </summary>
  517. /// <param name="dto"></param>
  518. /// <returns></returns>
  519. public Result OpCarTouristGuideGroundContentById(CarTouristGuideGroundIdDto dto)
  520. {
  521. Result result = new Result() { Code = -2, Msg = "未知错误" };
  522. try
  523. {
  524. List<Grp_CarTouristGuideGroundReservationsContent> grp_CarTouristsContent = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.IsDel == 0 && a.CTGGRId == dto.Id).ToList();
  525. List<CarTouristGuideGroundReservationsContentView> carTouristGuides = _mapper.Map<List<CarTouristGuideGroundReservationsContentView>>(grp_CarTouristsContent);
  526. foreach (var item in carTouristGuides)
  527. {
  528. item.SidName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == item.SId).Name;
  529. }
  530. Grp_CreditCardPayment CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79);
  531. CarTouristCreditCardPaymentView _CreditCardPayment = _mapper.Map<CarTouristCreditCardPaymentView>(CreditCardPayment);
  532. if (_CreditCardPayment != null)
  533. {
  534. _CreditCardPayment.PayName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PayDId).Name;
  535. _CreditCardPayment.PaymentCurrencyName = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == _CreditCardPayment.PaymentCurrency).Name;
  536. if (_CreditCardPayment.OrbitalPrivateTransfer == 0) _CreditCardPayment.OrbitalPrivateTransferStr = "公转";
  537. else _CreditCardPayment.OrbitalPrivateTransferStr = "私转";
  538. }
  539. var data = new
  540. {
  541. CarTouristsContent = carTouristGuides,
  542. CreditCardPayment = _CreditCardPayment,
  543. };
  544. return result = new Result() { Code = 0, Msg = "查询成功", Data = data };
  545. }
  546. catch (Exception ex)
  547. {
  548. return result = new Result() { Code = -2, Msg = "未知错误(" + ex.Message + ")" };
  549. }
  550. }
  551. /// <summary>
  552. /// 根据diid查询op费用列表
  553. /// </summary>
  554. /// <param name="dto"></param>
  555. /// <returns></returns>
  556. public async Task<Result> QueryCarTouristGuideGroundByDiId(CarTouristGuideGroundDto dto)
  557. {
  558. Result result = new Result() { Code = -2, Msg = "未知错误" };
  559. if (dto.PortType == 0 || string.IsNullOrWhiteSpace(dto.PortType.ToString()))
  560. {
  561. return result = new Result() { Code = -1, Msg = "请传入PortType参数,请求端口分类 1 Web 2 Android 3 IOS" };
  562. }
  563. try
  564. {
  565. #region SQL条件拼接
  566. string sqlWhere = string.Empty;
  567. sqlWhere += string.Format(@"And t.DIId={0} and t.isdel={1}", dto.DiId, 0);
  568. string UserId = "";
  569. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a => a.DIId == dto.DiId && a.IsDel == 0 && a.CTId == 79).ToList();
  570. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  571. UserId += gta.UId + ",";
  572. if (!string.IsNullOrWhiteSpace(UserId))
  573. {
  574. UserId = UserId.Substring(0, UserId.Length - 1);
  575. }
  576. else
  577. {
  578. UserId = "0";
  579. }
  580. sqlWhere += string.Format(@" And t.CreateUserId in ({0})", UserId);
  581. if (dto.IsPaySign != -1)
  582. {
  583. sqlWhere += string.Format(@" And c.IsPay = {0} ", dto.IsPaySign);
  584. }
  585. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  586. {
  587. Regex r = new Regex("And");
  588. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  589. }
  590. #endregion
  591. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  592. int endIndex = startIndex + dto.PageSize - 1;
  593. Regex regex = new Regex("^[\u4e00-\u9fa5]*$");
  594. //城市列表
  595. var data = _sqlSugar.Queryable<Grp_NationalTravelFee>()
  596. .Where(x => x.IsDel == 0)
  597. .Select(x => new
  598. {
  599. x.Id,
  600. x.Country,
  601. x.City,
  602. })
  603. .ToList();
  604. if (dto.PortType == 1)
  605. {
  606. string sql = string.Format(@"select t.*,(select Name from Sys_SetData where isdel = 0 and id = t.priceType) as 'priceTypeStr',s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage,c.PayMoney,c.PayDid,c.IsPay from
  607. Grp_CarTouristGuideGroundReservations t
  608. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  609. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  610. order by c.IsAuditGM,c.PayPercentage desc", sqlWhere);
  611. List<Grp_CarTouristGuideGroundView> infoViews = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  612. foreach (var item in infoViews)
  613. {
  614. if (!regex.IsMatch(item.Area))
  615. {
  616. for (int i = 0; i < data.Count; i++)
  617. {
  618. if (item.Area.Equals(data[i].Id.ToString()))
  619. {
  620. item.Area = string.Format("{0} {1}", data[i].Country, data[i].City);
  621. }
  622. }
  623. }
  624. if (string.IsNullOrWhiteSpace(item.priceTypeStr))
  625. {
  626. item.priceTypeStr = "未选择!";
  627. }
  628. if (item.OrbitalPrivateTransfer == 0) item.OrbitalPrivateTransferStr = "公转";
  629. else if (item.OrbitalPrivateTransfer == 1) item.OrbitalPrivateTransferStr = "私转";
  630. item.ServiceStartTime = Convert.ToDateTime(item.ServiceStartTime).ToString("yyyy-MM-dd");
  631. item.ServiceEndTime = Convert.ToDateTime(item.ServiceEndTime).ToString("yyyy-MM-dd");
  632. item.ServiceQuotedPrice = item.PayMoney;
  633. item.PayThenMoney = Math.Round(item.PayPercentage / 100 * item.ServiceQuotedPrice, 2);
  634. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice - item.PayPercentage / 100 * item.ServiceQuotedPrice, 2);
  635. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  636. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  637. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  638. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  639. Sys_SetData s = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == item.PayDid);
  640. if (s != null)
  641. {
  642. item.PayStrd = s.Name;
  643. }
  644. else item.PayStrd = "未选择";
  645. }
  646. return result = new Result() { Code = 0, Msg = "查询成功!", Data = infoViews };
  647. }
  648. else if (dto.PortType == 2 || dto.PortType == 3)
  649. {
  650. string sql = string.Format(@"Select * From (
  651. Select row_number() over (order by c.IsAuditGM,c.PayPercentage desc) as RowNumber,t.*,(select Name from Sys_SetData where isdel = 0 and id = t.priceType) as 'priceTypeStr',s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage,c.PayDid,c.PayMoney
  652. from
  653. Grp_CarTouristGuideGroundReservations t
  654. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  655. left Join Sys_SetData s on s.Id=c.PaymentCurrency {0}
  656. ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);
  657. List<Grp_CarTouristGuideGroundView> grp_CarTourists = _sqlSugar.SqlQueryable<Grp_CarTouristGuideGroundView>(sql).ToList();
  658. foreach (var item in grp_CarTourists)
  659. {
  660. if (!regex.IsMatch(item.Area))
  661. {
  662. for (int i = 0; i < data.Count; i++)
  663. {
  664. if (item.Area.Equals(data[i].Id.ToString()))
  665. {
  666. item.Area = string.Format("{0} {1}", data[i].Country, data[i].City);
  667. }
  668. }
  669. }
  670. if (string.IsNullOrWhiteSpace(item.priceTypeStr))
  671. {
  672. item.priceTypeStr = "未选择!";
  673. }
  674. if (item.OrbitalPrivateTransfer == 0) item.OrbitalPrivateTransferStr = "公转";
  675. else if (item.OrbitalPrivateTransfer == 1) item.OrbitalPrivateTransferStr = "私转";
  676. item.ServiceStartTime = Convert.ToDateTime(item.ServiceStartTime).ToString("yyyy-MM-dd");
  677. item.ServiceEndTime = Convert.ToDateTime(item.ServiceEndTime).ToString("yyyy-MM-dd");
  678. if (item.IsAuditGM == 0) item.IsAuditGMStr = "未审核";
  679. else if (item.IsAuditGM == 1) item.IsAuditGMStr = "已通过";
  680. else if (item.IsAuditGM == 2) item.IsAuditGMStr = "未通过";
  681. else if (item.IsAuditGM == 3) item.IsAuditGMStr = "自动审核";
  682. item.ServiceQuotedPrice = item.PayMoney;
  683. item.PayThenMoney = Math.Round(item.PayPercentage / 100 * item.ServiceQuotedPrice, 2);
  684. item.RemainingBalance = Math.Round(item.ServiceQuotedPrice - item.PayPercentage / 100 * item.ServiceQuotedPrice, 2);
  685. Sys_SetData s = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == item.PayDid);
  686. if (s != null)
  687. {
  688. item.PayStrd = s.Name;
  689. }
  690. else item.PayStrd = "未选择";
  691. }
  692. string CountSql = string.Format(@"Select COUNT(1) as Count From (
  693. select t.*,s.Name as CurrencyStr,c.IsAuditGM,c.PayPercentage from
  694. Grp_CarTouristGuideGroundReservations t
  695. left Join Grp_CreditCardPayment c on CTable=79 and c.CId=t.Id and c.isdel=0
  696. left Join Sys_SetData s on s.Id=t.CId {0}
  697. ) temp ", sqlWhere);
  698. DataCount dataCount = _sqlSugar.SqlQueryable<DataCount>(CountSql).First();
  699. if (dataCount != null)
  700. {
  701. int count = dataCount.Count;
  702. float totalPage = (float)count / dto.PageSize;//总页数
  703. if (totalPage == 0) totalPage = 1;
  704. else totalPage = (int)Math.Ceiling((double)totalPage);
  705. ListViewBase<Grp_CarTouristGuideGroundView> rst = new ListViewBase<Grp_CarTouristGuideGroundView>();
  706. rst.DataList = grp_CarTourists;
  707. rst.DataCount = count;
  708. rst.CurrPageIndex = dto.PageIndex;
  709. rst.CurrPageSize = dto.PageSize;
  710. return result = new Result() { Code = 0, Msg = "查询成功!", Data = rst };
  711. }
  712. }
  713. }
  714. catch (Exception)
  715. {
  716. return result = new Result() { Code = -2, Msg = "未知错误" };
  717. }
  718. return result;
  719. }
  720. /// <summary>
  721. /// OP费用录入填写详情
  722. /// </summary>
  723. /// <param name="dto"></param>
  724. /// <returns></returns>
  725. public async Task<Result> OpCarTouristGuideGroundContent(OpCarTouristGuideGroundContentDto dto)
  726. {
  727. Result result = new Result() { Code = -2, Msg = "未知错误" };
  728. var di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.DiId && x.IsDel == 0);
  729. if (di == null)
  730. {
  731. result.Code = -1;
  732. result.Msg = "无该团组信息!";
  733. return result;
  734. }
  735. try
  736. {
  737. BeginTran();
  738. List<Grp_CarTouristGuideGroundReservationsContent> carTouristList = dto.OPContentList.Select(item => new Grp_CarTouristGuideGroundReservationsContent
  739. {
  740. Id = item.Id,
  741. DiId = dto.DiId,
  742. CTGGRId = dto.CTGGRId,
  743. SId = item.SId,
  744. Price = item.Price,
  745. PriceContent = item.priceContent,
  746. Currency = dto.Currency,
  747. CreateUserId = dto.CreateUserId,
  748. Units = item.Units,
  749. DatePrice = item.DatePrice,
  750. Count = item.Count,
  751. }).ToList();
  752. #region 旧数据处理
  753. string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm ss");
  754. var ids = carTouristList.Select(x1 => x1.Id);
  755. _ = _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(x => x.DiId == dto.DiId && x.CTGGRId == dto.CTGGRId && !ids.Contains(x.Id) && x.IsDel == 0).SetColumns(x => new Grp_CarTouristGuideGroundReservationsContent
  756. {
  757. IsDel = 1,
  758. DeleteTime = time,
  759. DeleteUserId = dto.CreateUserId,
  760. }).ExecuteCommand();
  761. #endregion
  762. if (carTouristList.Count > 0)
  763. {
  764. #region 超支处理
  765. Dictionary<int, int> mealsDic = new Dictionary<int, int>()
  766. {
  767. {988,1074},
  768. {93,1075},
  769. {989,1076},
  770. };
  771. //限制只能选择地区
  772. var opSingle = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().First(x => x.Id == dto.CTGGRId && x.IsDel == 0);
  773. var opSingleCityId = 0;
  774. Grp_NationalTravelFee cityPrice = null;
  775. string priceCity = string.Empty;
  776. //三公费用
  777. if (int.TryParse(opSingle.Area, out opSingleCityId))
  778. {
  779. cityPrice = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x =>
  780. x.Id == opSingleCityId
  781. ).First();
  782. priceCity = cityPrice == null ? string.Empty : cityPrice.Country + cityPrice?.City;
  783. }
  784. else
  785. {
  786. cityPrice = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x =>
  787. !string.IsNullOrEmpty(x.City) && x.City.Contains(opSingle.Area)
  788. ).First();
  789. priceCity = opSingle.Area;
  790. }
  791. cityPrice ??= new Grp_NationalTravelFee
  792. {
  793. FoodCost = 0.00M,
  794. Id = 0,
  795. };
  796. List<Tuple<int, string, int, decimal>> arr = new List<Tuple<int, string, int, decimal>>();
  797. arr.Add(new Tuple<int, string, int, decimal>(1074, "早餐超支费用", 1077, 1M)); // sid name setdataid 系数
  798. arr.Add(new Tuple<int, string, int, decimal>(1075, "午餐超支费用", 1078, 1M));
  799. arr.Add(new Tuple<int, string, int, decimal>(1076, "晚餐超支费用", 1079, 1M));
  800. arr.Add(new Tuple<int, string, int, decimal>(982, "车超时费用", 1050, 2.4M));
  801. arr.Add(new Tuple<int, string, int, decimal>(1059, "导游超时费用", 1072, 1M));
  802. arr.Add(new Tuple<int, string, int, decimal>(1085, "景点门票超支费用", 1086, 1.2M));
  803. arr.Add(new Tuple<int, string, int, decimal>(1073, "翻译超时费用", 1087, 1.5M));
  804. //超支费用表(数据添加) Fin_GroupExtraCost
  805. List<Fin_GroupExtraCost> groupExtraCostsArr = new List<Fin_GroupExtraCost>();
  806. List<List<Fin_GroupExtraCost>> enterOverspendArr = new List<List<Fin_GroupExtraCost>>();
  807. var aMeal = cityPrice.FoodCost.ObjToDecimal() / 2; //一顿三公费用
  808. var findSetDataCurr = _sqlSugar.Queryable<Sys_SetData>().First(q => q.Id == dto.toCurr && q.IsDel == 0);
  809. var carCurr = _sqlSugar.Queryable<Sys_SetData>().First(q => q.Id == carTouristList.First().Currency && q.IsDel == 0);
  810. foreach (var item in arr)
  811. {
  812. var a = carTouristList.Where(x => x.SId == item.Item1 && x.Price != 0).Select(x => new Fin_GroupExtraCost
  813. {
  814. Coefficient = item.Item4,
  815. CreateTime = DateTime.Now,
  816. CreateUserId = dto.CreateUserId,
  817. DiId = dto.DiId,
  818. FilePath = string.Empty,
  819. IsDel = 0,
  820. PriceCount = x.Count,
  821. Price = x.Price,
  822. PriceDt = x.DatePrice.ObjToDate(),
  823. PriceCurrency = x.Currency,
  824. PriceSum = x.Count * x.Price,
  825. PriceName = di.TeamName + "-" + priceCity + "-" + $"{item.Item2}(地接导入)",
  826. PriceType = 1028,
  827. PriceDetailType = item.Item3,
  828. Remark = x.PriceContent,
  829. Area = opSingleCityId
  830. }).ToList();
  831. if (a.Count > 0)
  832. {
  833. enterOverspendArr.Add(a);
  834. }
  835. }
  836. //数组中的费用
  837. if (enterOverspendArr.Count > 0)
  838. {
  839. groupExtraCostsArr.AddRange(enterOverspendArr.SelectMany(x => x).ToList());
  840. }
  841. var start = opSingle.ServiceStartTime.ObjToDate();
  842. var end = opSingle.ServiceEndTime.ObjToDate();
  843. string remake = string.Empty;
  844. var exitMealCount = 0;
  845. var price = 0M;
  846. //var day = 0;
  847. var consumerMealStr = string.Empty;
  848. var consumerMealNumber = 0;
  849. var consumerMealAllPrice = 0.00M;
  850. while (start <= end)
  851. {
  852. //查看每日每顿是否存在超支
  853. //不存在则加入退费 (三公一顿 - 消费金额)
  854. //93 , 989
  855. bool isExistsWu = carTouristList.Where(x => x.SId == mealsDic[93] && x.IsDel == 0 && DateTime.Compare(start, x.DatePrice.ObjToDate()) == 0 && x.Price > 0).Count() == 0;
  856. bool isExistsWan = carTouristList.Where(x => x.SId == mealsDic[989] && x.IsDel == 0 && DateTime.Compare(start, x.DatePrice.ObjToDate()) == 0 && x.Price > 0).Count() == 0;
  857. var mealPriceWu = carTouristList.Where(x => x.SId == 93 && x.IsDel == 0 && DateTime.Compare(start, x.DatePrice.ObjToDate()) == 0).Sum(x => x.Price * x.Count);
  858. var mealPriceWan = carTouristList.Where(x => x.SId == 989 && x.IsDel == 0 && DateTime.Compare(start, x.DatePrice.ObjToDate()) == 0).Sum(x => x.Price * x.Count);
  859. var mealPriceWuChao = carTouristList.Where(x => x.SId == mealsDic[93] && x.IsDel == 0 && DateTime.Compare(start, x.DatePrice.ObjToDate()) == 0).Sum(x => x.Price * x.Count);
  860. var mealPriceWanChao = carTouristList.Where(x => x.SId == mealsDic[989] && x.IsDel == 0 && DateTime.Compare(start, x.DatePrice.ObjToDate()) == 0).Sum(x => x.Price * x.Count);
  861. if (mealPriceWu > 0)
  862. {
  863. consumerMealStr += $"{start.ToString("M/d")}午餐消费{mealPriceWu + mealPriceWuChao}{carCurr?.Name},";
  864. consumerMealNumber++;
  865. consumerMealAllPrice += mealPriceWu + mealPriceWuChao;
  866. }
  867. if (mealPriceWan > 0)
  868. {
  869. consumerMealStr += $"{start.ToString("M/d")}晚餐消费{mealPriceWan + mealPriceWanChao}{carCurr?.Name},";
  870. consumerMealNumber++;
  871. consumerMealAllPrice += mealPriceWan + mealPriceWanChao;
  872. }
  873. if (isExistsWu && isExistsWan)
  874. {
  875. remake += $"{start.ToString("M/d")}午餐和晚餐,";
  876. exitMealCount += 2;
  877. price += (aMeal * 2 * di.VisitPNumber) - (mealPriceWu * dto.Rate) - (mealPriceWan * dto.Rate);
  878. }
  879. else if (isExistsWu)
  880. {
  881. remake += $"{start.ToString("M/d")}午餐,";
  882. exitMealCount += 1;
  883. price += (aMeal * di.VisitPNumber) - (mealPriceWu * dto.Rate);
  884. }
  885. else if (isExistsWan)
  886. {
  887. remake += $"{start.ToString("M/d")}晚餐,";
  888. exitMealCount += 1;
  889. price += (aMeal * di.VisitPNumber) - (mealPriceWan * dto.Rate);
  890. }
  891. start = start.AddDays(1);
  892. //day++;
  893. }
  894. var priceTypeArr = new int[] { 1061, 1069 };
  895. if (exitMealCount > 0 && priceTypeArr.Contains(opSingle.PriceType))
  896. {
  897. string searchKey = "宴请";
  898. remake = remake.TrimEnd(',');
  899. remake += $"财政 {findSetDataCurr?.Name} {aMeal} * {di.VisitPNumber} * {exitMealCount}餐";
  900. remake += $",[TuT]{consumerMealStr} 共{consumerMealNumber}顿 {consumerMealAllPrice} {carCurr?.Name}";
  901. decimal priceInt = price / di.VisitPNumber / exitMealCount;
  902. groupExtraCostsArr.Add(new Fin_GroupExtraCost
  903. {
  904. Coefficient = 1,
  905. CreateTime = DateTime.Now,
  906. CreateUserId = dto.CreateUserId,
  907. DiId = dto.DiId,
  908. FilePath = string.Empty,
  909. IsDel = 0,
  910. PriceCount = di.VisitPNumber * exitMealCount * -1,
  911. Price = priceInt,
  912. PriceDt = opSingle.ServiceStartTime.ObjToDate(),
  913. PriceCurrency = findSetDataCurr == null ? dto.toCurr : findSetDataCurr.Id,
  914. PriceSum = (di.VisitPNumber * exitMealCount * -1) * priceInt,
  915. PriceName = di.TeamName + "-" + priceCity + "-" + $"退餐费(地接导入)",
  916. PriceType = 1028,
  917. PriceDetailType = 1088,
  918. Remark = remake,
  919. Area = opSingleCityId,
  920. SYsupervisorConfirm = dto.OPContentList.Where(x => x.priceContent.Contains(searchKey)).Count() > 0 ? 1 : 0,
  921. });
  922. }
  923. var needToConfirm = new int[] { 1088, 1050 };
  924. if (groupExtraCostsArr.Count > 0)
  925. {
  926. foreach (var item in groupExtraCostsArr)
  927. {
  928. var ManagerConfirm = needToConfirm.Contains(item.PriceDetailType) ? 0 : 1;
  929. var SupervisorConfirm = needToConfirm.Contains(item.PriceDetailType) ? 0 : 1;
  930. var SYsupervisorConfirm = needToConfirm.Contains(item.PriceDetailType) ? 0 : 1;
  931. if (item.SYsupervisorConfirm > 0)
  932. {
  933. SYsupervisorConfirm = 1;
  934. }
  935. var QuerySgin = _sqlSugar.Queryable<Fin_GroupExtraCost>()
  936. .Where(x => x.PriceName == item.PriceName && x.DiId == item.DiId && x.IsDel == 0 && x.PriceDt.ToString("yyyy-MM-dd") == item.PriceDt.ToString("yyyy-MM-dd"))
  937. .First();
  938. if (QuerySgin == null)
  939. {
  940. var resultId = await PostGroupExtraCost_Operator(new Fin_GroupExtraCostDto_OP
  941. {
  942. coefficient = item.Coefficient,
  943. createUser = dto.CreateUserId,
  944. currency = item.PriceCurrency,
  945. diId = item.DiId,
  946. editType = 1,
  947. filePath = string.Empty,
  948. payee = dto.Payee,
  949. PortType = 1,
  950. PriceCount = item.PriceCount,
  951. priceName = item.PriceName,
  952. remark = item.Remark,
  953. price = item.Price,
  954. priceDetailType = item.PriceDetailType,
  955. priceType = item.PriceType,
  956. PriceDt = item.PriceDt.ToString("yyyy-MM-dd"),
  957. payType = dto.PayDId,
  958. costSign = dto.OrbitalPrivateTransfer,
  959. Area = item.Area,
  960. ManagerConfirm = ManagerConfirm,
  961. SupervisorConfirm = SupervisorConfirm,
  962. SYsupervisorConfirm = SYsupervisorConfirm
  963. });
  964. _sqlSugar.Insertable<Fin_LocalGuideRelevancyOverspend>(new Fin_LocalGuideRelevancyOverspend
  965. {
  966. CreateTime = DateTime.Now,
  967. CreateUserId = dto.CreateUserId,
  968. IsDel = 0,
  969. LocalGuideId = opSingle.Id,
  970. OverspendId = resultId.Data,
  971. }).ExecuteCommand();
  972. }
  973. else
  974. {
  975. item.Id = QuerySgin.Id;
  976. _ = await PostGroupExtraCost_Operator(new Fin_GroupExtraCostDto_OP
  977. {
  978. coefficient = item.Coefficient,
  979. createUser = dto.CreateUserId,
  980. currency = item.PriceCurrency,
  981. diId = item.DiId,
  982. editType = 2,
  983. filePath = string.Empty,
  984. payee = dto.Payee,
  985. PortType = 1,
  986. PriceCount = item.PriceCount,
  987. priceName = item.PriceName,
  988. remark = item.Remark,
  989. price = item.Price,
  990. priceDetailType = item.PriceDetailType,
  991. priceType = item.PriceType,
  992. PriceDt = item.PriceDt.ToString("yyyy-MM-dd"),
  993. payType = dto.PayDId,
  994. costSign = dto.OrbitalPrivateTransfer,
  995. Id = item.Id,
  996. Area = item.Area,
  997. });
  998. }
  999. }
  1000. _foreignReceivablesRepository.OverSpSeteceivables(new OverSpSeteceivablesDto
  1001. {
  1002. CreateUserId = dto.CreateUserId,
  1003. DiId = dto.DiId,
  1004. });
  1005. }
  1006. #endregion
  1007. var existingRecords = await _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>()
  1008. .Where(a => carTouristList.Select(item => item.Id).Contains(a.Id) &&
  1009. a.CTGGRId == dto.CTGGRId &&
  1010. a.IsDel == 0
  1011. )
  1012. .ToListAsync();
  1013. var existingRecordsDict = existingRecords.ToDictionary(a => (a.Id));
  1014. var insertList = new List<Grp_CarTouristGuideGroundReservationsContent>();
  1015. var updateList = new List<Grp_CarTouristGuideGroundReservationsContent>();
  1016. foreach (var item in carTouristList)
  1017. {
  1018. if (!existingRecordsDict.TryGetValue((item.Id), out var existingRecord))
  1019. {
  1020. insertList.Add(item);
  1021. }
  1022. else
  1023. {
  1024. existingRecord.Price = item.Price;
  1025. existingRecord.PriceContent = item.PriceContent;
  1026. existingRecord.Currency = dto.Currency;
  1027. existingRecord.Remark = item.Remark;
  1028. existingRecord.DatePrice = item.DatePrice;
  1029. existingRecord.Count = item.Count;
  1030. existingRecord.Units = item.Units;
  1031. updateList.Add(existingRecord);
  1032. }
  1033. }
  1034. // 执行批量插入
  1035. if (insertList.Any())
  1036. {
  1037. var insertIds = await _sqlSugar.Insertable(insertList).ExecuteReturnIdentityAsync();
  1038. if (insertIds == 0)
  1039. {
  1040. throw new Exception("添加失败,请稍后重试!");
  1041. }
  1042. }
  1043. // 执行批量更新
  1044. if (updateList.Any())
  1045. {
  1046. var updateCount = await _sqlSugar.Updateable(updateList).ExecuteCommandAsync();
  1047. if (updateCount == 0)
  1048. {
  1049. throw new Exception("修改失败,请稍后重试!");
  1050. }
  1051. }
  1052. }
  1053. Regex regex = new Regex("^[\u4e00-\u9fa5]{0,}$");
  1054. #region 修改C表数据
  1055. Grp_CreditCardPayment c = new Grp_CreditCardPayment();
  1056. c.PaymentCurrency = dto.Currency;
  1057. for (int i = 0; i < dto.SelectCheck.Count; i++)
  1058. {
  1059. if (!regex.IsMatch(dto.SelectCheck[i]))
  1060. {
  1061. for (int j = 0; j < carTouristList.Count; j++)
  1062. {
  1063. if (int.Parse(dto.SelectCheck[i]) == carTouristList[j].SId)
  1064. {
  1065. c.PayMoney += carTouristList[j].Price * carTouristList[j].Count;
  1066. }
  1067. }
  1068. }
  1069. else
  1070. {
  1071. c.PayMoney = carTouristList.Sum(x => x.Price * x.Count);
  1072. break;
  1073. }
  1074. }
  1075. c.PayPercentage = dto.PayPercentage;
  1076. c.ConsumptionDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1077. c.CTable = 79;
  1078. c.CId = dto.CTGGRId;
  1079. c.IsAuditGM = 0;
  1080. c.PayDId = dto.PayDId;
  1081. c.DIId = dto.DiId;
  1082. c.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  1083. c.Payee = dto.Payee;
  1084. c.CreateUserId = dto.CreateUserId;
  1085. //--------------------添加C表字段---------------
  1086. c.ConsumptionPatterns = dto.ConsumptionPatterns;
  1087. c.CTDId = dto.Ctdid;
  1088. c.BankNo = dto.BankNo;
  1089. c.CardholderName = dto.CardholderName;
  1090. c.ConsumptionDate = dto.ConsumptionDate;
  1091. c.CompanyBankNo = dto.CompanyBankNo;
  1092. c.OtherBankName = dto.OtherBankName;
  1093. c.OtherSideNo = dto.OtherSideNo;
  1094. c.OtherSideName = dto.OtherSideName;
  1095. //2025-04-07 第四次更改 PayDId == 72(刷卡) IsPay == 1
  1096. if (c.PayDId == 72) c.IsPay = 1;
  1097. else c.IsPay = 0;
  1098. c.RMBPrice = c.PayMoney;
  1099. c.DayRate = 1;
  1100. #region 老汇率获取
  1101. //Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 79);
  1102. //List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  1103. //if (_TeamRate != null)
  1104. //{
  1105. // Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  1106. // if (_SetData != null)
  1107. // {
  1108. // currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  1109. // CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  1110. // if (CurrencyRate != null)
  1111. // {
  1112. // c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  1113. // c.DayRate = CurrencyRate.Rate;
  1114. // }
  1115. // }
  1116. //}
  1117. #endregion
  1118. var rate = await _setDataRep.PostCurrencyByDiid(dto.DiId, 79, dto.Currency);
  1119. if (rate.Code == 0)
  1120. {
  1121. var rateData = rate.Data as CurrencyInfo;
  1122. if (rateData != null)
  1123. {
  1124. c.RMBPrice = c.PayMoney * rateData.Rate;
  1125. c.DayRate = rateData.Rate;
  1126. }
  1127. }
  1128. int noticeSign = 1; //企业微信通知标识
  1129. int noticeCcpId = 0;
  1130. Grp_CreditCardPayment grp_CreditCard = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.CTGGRId && a.IsDel == 0 && a.CTable == 79 && a.DIId == dto.DiId);
  1131. if (grp_CreditCard != null)//修改
  1132. {
  1133. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == dto.CTGGRId && a.CTable == 79 && a.DIId == dto.DiId).SetColumns(a => new Grp_CreditCardPayment
  1134. {
  1135. PaymentCurrency = c.PaymentCurrency,
  1136. PayMoney = c.PayMoney,
  1137. PayPercentage = c.PayPercentage,
  1138. CTable = c.CTable,
  1139. PayDId = c.PayDId,
  1140. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  1141. Payee = c.Payee,
  1142. IsPay = c.IsPay,
  1143. RMBPrice = c.RMBPrice,
  1144. DayRate = c.DayRate,
  1145. //添加属性
  1146. ConsumptionPatterns = c.ConsumptionPatterns,
  1147. CTDId = c.CTDId,
  1148. BankNo = c.BankNo,
  1149. CardholderName = c.CardholderName,
  1150. ConsumptionDate = c.ConsumptionDate,
  1151. CompanyBankNo = c.CompanyBankNo,
  1152. OtherBankName = c.OtherBankName,
  1153. OtherSideNo = c.OtherSideNo,
  1154. OtherSideName = c.OtherSideName
  1155. }).ExecuteCommandAsync();
  1156. noticeSign = 2;
  1157. noticeCcpId = grp_CreditCard.Id;
  1158. if (CTable == 0)
  1159. {
  1160. RollbackTran();
  1161. return result = new Result() { Code = -2, Msg = "修改失败" };
  1162. }
  1163. }
  1164. else//添加
  1165. {
  1166. int id = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  1167. noticeCcpId = id;
  1168. if (id == 0)
  1169. {
  1170. RollbackTran();
  1171. return result = new Result() { Code = -2, Msg = "添加失败" };
  1172. }
  1173. }
  1174. #endregion
  1175. _ = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservations>()
  1176. .Where(a => a.Id == dto.CTGGRId && a.DiId == dto.DiId && a.IsDel == 0)
  1177. .SetColumns(a => new Grp_CarTouristGuideGroundReservations
  1178. {
  1179. CId = dto.Currency,
  1180. ServiceQuotedPrice = c.PayMoney,
  1181. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  1182. SelectCheck = string.Join(',', dto.SelectCheck),
  1183. Rate = dto.Rate,
  1184. toCurr = dto.toCurr
  1185. })
  1186. .ExecuteCommandAsync();
  1187. var data = new { ccpId = noticeCcpId, sign = noticeSign };
  1188. result = new Result() { Code = 0, Msg = "保存成功", Data = data };
  1189. CommitTran();
  1190. }
  1191. catch (Exception ex)
  1192. {
  1193. RollbackTran();
  1194. result = new Result() { Code = -2, Msg = $"接口异常!({ex.Message})" };
  1195. }
  1196. return result;
  1197. }
  1198. /// <summary>
  1199. /// 超支费用
  1200. /// 1增、2改、3删
  1201. /// </summary>
  1202. /// <param name="dto"></param>
  1203. /// <returns></returns>
  1204. private async Task<Result> PostGroupExtraCost_Operator(Fin_GroupExtraCostDto_OP dto)
  1205. {
  1206. Result rt = new Result();
  1207. #region 验证
  1208. #endregion
  1209. Fin_GroupExtraCost _entity = new Fin_GroupExtraCost();
  1210. _entity.DiId = dto.diId;
  1211. _entity.PriceName = dto.priceName;
  1212. _entity.Price = dto.price;
  1213. _entity.PriceCurrency = dto.currency;
  1214. _entity.PriceType = dto.priceType;
  1215. _entity.Coefficient = dto.coefficient;
  1216. _entity.PriceDetailType = dto.priceDetailType;
  1217. _entity.FilePath = dto.filePath;
  1218. _entity.Remark = dto.remark;
  1219. _entity.PriceCount = dto.PriceCount;
  1220. _entity.PriceDt = DateTime.Parse(dto.PriceDt);
  1221. _entity.PriceSum = dto.price * dto.PriceCount;
  1222. _entity.Area = dto.Area;
  1223. _entity.SupervisorConfirm = dto.SupervisorConfirm;
  1224. _entity.ManagerConfirm = dto.ManagerConfirm;
  1225. _entity.SYsupervisorConfirm = dto.SYsupervisorConfirm;
  1226. _daiRep.BeginTran();
  1227. if (dto.editType == 1)
  1228. {
  1229. _entity.CreateUserId = dto.createUser;
  1230. _entity.CreateTime = DateTime.Now;
  1231. _entity.IsDel = 0;
  1232. int returnId = await _daiRep.AddAsyncReturnId<Fin_GroupExtraCost>(_entity);
  1233. if (returnId > 0)
  1234. {
  1235. dto.Id = returnId;
  1236. }
  1237. }
  1238. else if (dto.editType == 2)
  1239. {
  1240. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  1241. {
  1242. PriceName = dto.priceName,
  1243. Price = dto.price,
  1244. PriceCurrency = dto.currency,
  1245. PriceType = dto.priceType,
  1246. PriceDetailType = dto.priceDetailType,
  1247. Coefficient = dto.coefficient,
  1248. FilePath = dto.filePath,
  1249. Remark = dto.remark,
  1250. PriceCount = dto.PriceCount,
  1251. PriceDt = _entity.PriceDt,
  1252. PriceSum = _entity.PriceSum,
  1253. Area = _entity.Area,
  1254. });
  1255. if (!res)
  1256. {
  1257. _daiRep.RollbackTran();
  1258. //Ok(JsonView(false, "2操作失败!"))
  1259. rt.Msg = "2操作失败!";
  1260. return rt;
  1261. }
  1262. }
  1263. else if (dto.editType == 3)
  1264. {
  1265. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  1266. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  1267. {
  1268. IsDel = 1,
  1269. DeleteTime = delTime,
  1270. DeleteUserId = dto.createUser
  1271. });
  1272. if (!res)
  1273. {
  1274. _daiRep.RollbackTran();
  1275. rt.Msg = "3操作失败!";
  1276. return rt;
  1277. }
  1278. }
  1279. else
  1280. {
  1281. _daiRep.RollbackTran();
  1282. rt.Msg = "未知的editType";
  1283. return rt;
  1284. }
  1285. if (!(await extraCost_editCreditCardPayment(dto)))
  1286. {
  1287. rt.Msg = "ccp操作失败";
  1288. return rt;
  1289. }
  1290. _daiRep.CommitTran();
  1291. rt.Code = 0;
  1292. rt.Msg = "操作成功";
  1293. rt.Data = dto.Id;
  1294. return rt;
  1295. }
  1296. private async Task<bool> extraCost_editCreditCardPayment(Fin_GroupExtraCostDto_OP costDto)
  1297. {
  1298. //设置团组汇率
  1299. decimal dcm_dayrate = 1M;
  1300. decimal dcm_rmbPrice = costDto.price;
  1301. int ispay = costDto.payType == 72 ? 1 : 0;
  1302. if (costDto.costSign != 3)
  1303. {
  1304. //获取新汇率 int diId,int CId, int currencyId
  1305. Result rate = await _setDataRep.PostCurrencyByDiid(costDto.diId, 1015, costDto.currency);
  1306. if (rate.Code == 0)
  1307. {
  1308. var rateInfo = (rate.Data as CurrencyInfo);
  1309. if (rateInfo is not null)
  1310. {
  1311. dcm_dayrate = rateInfo.Rate;
  1312. dcm_rmbPrice = rateInfo.Rate * dcm_rmbPrice;
  1313. }
  1314. else
  1315. {
  1316. dcm_dayrate = 1;
  1317. }
  1318. }
  1319. }
  1320. Grp_CreditCardPayment ccp = _daiRep.Query<Grp_CreditCardPayment>(s => s.CId == costDto.Id && s.CTable == 1015).First();
  1321. if (ccp == null)
  1322. {
  1323. ccp = new Grp_CreditCardPayment();
  1324. ccp.PayDId = costDto.payType;// dto
  1325. ccp.ConsumptionPatterns = "";
  1326. ccp.ConsumptionDate = "";
  1327. ccp.CTDId = costDto.payCardId;// dto
  1328. ccp.BankNo = "";
  1329. ccp.CardholderName = "";
  1330. ccp.PayMoney = costDto.price;// dto
  1331. ccp.PaymentCurrency = costDto.currency;// dto
  1332. ccp.CompanyBankNo = "";
  1333. ccp.OtherBankName = "";
  1334. ccp.OtherSideNo = "";
  1335. ccp.OtherSideName = "";
  1336. ccp.Remark = "";
  1337. ccp.CreateUserId = costDto.createUser;
  1338. ccp.CreateTime = DateTime.Now;
  1339. ccp.MFOperator = 0;
  1340. ccp.MFOperatorDate = "";
  1341. ccp.IsAuditDM = 0;
  1342. ccp.AuditDMOperate = 0;
  1343. ccp.AuditDMDate = "";
  1344. ccp.IsAuditMF = 0;
  1345. ccp.AuditMFOperate = 0;
  1346. ccp.AuditMFDate = "";
  1347. ccp.IsAuditGM = 0;
  1348. ccp.AuditGMOperate = 0;
  1349. ccp.AuditGMDate = "";
  1350. ccp.IsPay = ispay; // upd
  1351. ccp.DIId = costDto.diId;// dto
  1352. ccp.CId = costDto.Id;// dto
  1353. ccp.CTable = 1015; //超支费用指向id
  1354. ccp.IsDel = 0;
  1355. ccp.PayPercentage = 100M;
  1356. ccp.PayThenMoney = 0M;
  1357. ccp.PayPercentageOld = 100M;
  1358. ccp.PayThenMoneyOld = 0M;
  1359. ccp.UpdateDate = "";
  1360. ccp.Payee = costDto.payee;// dto
  1361. ccp.OrbitalPrivateTransfer = costDto.costSign;// dto
  1362. ccp.ExceedBudget = 0;
  1363. ccp.DayRate = dcm_dayrate; //upd
  1364. ccp.RMBPrice = dcm_rmbPrice; //upd
  1365. int ccpInsertId = _daiRep.AddReturnId<Grp_CreditCardPayment>(ccp);
  1366. if (ccpInsertId > 0)
  1367. {
  1368. return true;
  1369. }
  1370. }
  1371. else
  1372. {
  1373. if (costDto.editType == 2)
  1374. {
  1375. bool res = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1376. {
  1377. PayDId = costDto.payType,
  1378. CTDId = costDto.payCardId,
  1379. PayMoney = costDto.price,
  1380. PaymentCurrency = costDto.currency,
  1381. IsPay = ispay,
  1382. Payee = costDto.payee,
  1383. OrbitalPrivateTransfer = costDto.costSign,
  1384. DayRate = dcm_dayrate,
  1385. RMBPrice = dcm_rmbPrice
  1386. });
  1387. return res;
  1388. }
  1389. else if (costDto.editType == 3)
  1390. {
  1391. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  1392. bool res2 = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1393. {
  1394. IsDel = 1,
  1395. DeleteTime = delTime,
  1396. DeleteUserId = costDto.createUser
  1397. });
  1398. return res2;
  1399. }
  1400. }
  1401. return false;
  1402. }
  1403. public async Task<Result> GroupExtraCost_OperatorList(List<Fin_GroupExtraCostDto_OP> dto)
  1404. {
  1405. Result rt = new Result();
  1406. foreach (var item in dto)
  1407. {
  1408. await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.PriceName == item.priceName && s.DiId == item.diId,
  1409. s => new Fin_GroupExtraCost
  1410. {
  1411. IsDel = 1,
  1412. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  1413. DeleteUserId = item.createUser
  1414. });
  1415. rt = await PostGroupExtraCost_Operator(item);
  1416. }
  1417. return rt;
  1418. }
  1419. }
  1420. }