CarTouristGuideGroundRepository.cs 70 KB

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