CarTouristGuideGroundRepository.cs 68 KB

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