CarTouristGuideGroundRepository.cs 66 KB

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