CarTouristGuideGroundRepository.cs 74 KB

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