CarTouristGuideGroundRepository.cs 74 KB

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