CarTouristGuideGroundRepository.cs 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402
  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 addsTourClientList = new List<Grp_TourClientList>();
  672. var carExtraList = carTouristList.Where(x => x.SId == 982 && x.Price != 0).ToList();
  673. var mealPriceList = carTouristList.Where(x => (x.SId == 93 || x.SId == 988 || x.SId == 989) && x.Price != 0).GroupBy(x => x.DatePrice).ToList();
  674. var tgOvertime = carTouristList.Where(x => x.SId == 1059 && x.Price != 0 ).ToList();
  675. //成本数据
  676. List<Grp_GroupCost> _GroupCosts = new List<Grp_GroupCost>();
  677. var _GroupCostParameters = _groupCostParameterRepository.GetGroupCostParameterMainByDiid(dto.DiId);
  678. if (_GroupCostParameters != null && _GroupCostParameters.IsShare == 1)
  679. {
  680. _GroupCosts = _sqlSugar.Queryable<Grp_GroupCost>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
  681. }
  682. //处理date为空问题
  683. if (_GroupCosts.Count > 0)
  684. {
  685. for (int i = 0; i < _GroupCosts.Count; i++)
  686. {
  687. if (string.IsNullOrEmpty(_GroupCosts[i].Date))
  688. {
  689. if (i > 0)
  690. {
  691. _GroupCosts[i].Date = _GroupCosts[i - 1].Date;
  692. }
  693. }
  694. }
  695. var CostSoure = _GroupCosts.GroupBy(x => x.Date).ToList();
  696. _GroupCosts.Clear();
  697. foreach (var costSoure in CostSoure)
  698. {
  699. var cost = costSoure.ToList();
  700. cost[0].D = cost.Sum(x => x.D);
  701. cost[0].B = cost.Sum(x => x.B);
  702. cost[0].L = cost.Sum(x => x.L);
  703. _GroupCosts.Add(cost[0]);
  704. }
  705. }
  706. mealPriceList.ForEach(x =>
  707. {
  708. var row = tb.NewRow();
  709. row["日期"] = x.Key;
  710. row["费用"] = x.Sum(x => x.Price * x.Count);
  711. row["币种"] = x.FirstOrDefault()?.Currency;
  712. tb.Rows.Add(row);
  713. });
  714. //限制只能选择地区
  715. var opSingle = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().First(x => x.Id == dto.CTGGRId && x.IsDel == 0);
  716. var opSingleCityId = 0;
  717. Grp_NationalTravelFee cityPrice = null;
  718. string priceCity = string.Empty;
  719. //三公费用
  720. if (int.TryParse(opSingle.Area, out opSingleCityId))
  721. {
  722. cityPrice = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x =>
  723. x.Id == opSingleCityId
  724. ).First();
  725. priceCity = cityPrice == null ? string.Empty :cityPrice.Country + cityPrice?.City;
  726. }
  727. else
  728. {
  729. cityPrice = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x =>
  730. !string.IsNullOrEmpty(x.City) && x.City.Contains(opSingle.Area)
  731. ).First();
  732. priceCity = opSingle.Area;
  733. }
  734. //超支费用表(数据添加) Fin_GroupExtraCost
  735. List<Fin_GroupExtraCost> groupExtraCostsArr = new List<Fin_GroupExtraCost>();
  736. var di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.DiId && x.IsDel == 0);
  737. if (di == null)
  738. {
  739. result.Code = -1;
  740. result.Msg = "无该团组信息!";
  741. return result;
  742. }
  743. if (carExtraList.Count > 0)
  744. {
  745. foreach (var item in carExtraList)
  746. {
  747. groupExtraCostsArr.Add(new Fin_GroupExtraCost
  748. {
  749. Price = item.Price,
  750. CreateTime = DateTime.Now,
  751. CreateUserId = dto.CreateUserId,
  752. Coefficient = 1,
  753. DiId = dto.DiId,
  754. PriceCurrency = item.Currency,
  755. PriceName = di.TeamName +"-"+ priceCity + "-" + "车超时费(地接导入)",
  756. PriceType = 1028,
  757. PriceDt = item.DatePrice.ObjToDate(),
  758. PriceSum = item.Price * item.Count,
  759. PriceCount = item.Count,
  760. FilePath = string.Empty,
  761. PriceDetailType = 1050,
  762. });
  763. }
  764. }
  765. //导游超时费用
  766. if (tgOvertime.Count > 0)
  767. {
  768. foreach (var item in tgOvertime)
  769. {
  770. groupExtraCostsArr.Add(new Fin_GroupExtraCost
  771. {
  772. Price = item.Price,
  773. CreateTime = DateTime.Now,
  774. CreateUserId = dto.CreateUserId,
  775. Coefficient = 1,
  776. DiId = dto.DiId,
  777. PriceCurrency = item.Currency,
  778. PriceName = di.TeamName + "-" + priceCity + "-" + "导游超时费(地接导入)",
  779. PriceType = 1028,
  780. PriceDt = item.DatePrice.ObjToDate(),
  781. PriceSum = item.Price * item.Count,
  782. PriceCount = item.Count,
  783. FilePath = string.Empty,
  784. PriceDetailType = 1072,
  785. });
  786. }
  787. }
  788. if (_GroupCostParameters != null)
  789. {
  790. //币种
  791. var currOpResult = await _setDataRep.PostCurrencyByDiid(dto.DiId, 79, carTouristList[0].Currency);
  792. var currOp = currOpResult.Code == 0 ? (currOpResult.Data as CurrencyInfo) == null ? 1 : (currOpResult.Data as CurrencyInfo)!.Rate : 1;
  793. //三公费用汇率 (修改为对比成本)
  794. //var cityCurrResult = await _setDataRep.PostCurrencyByDiid(dto.DiId, 79, cityPrice.Currency);
  795. //var cityCurr = cityCurrResult.Code == 0 ? (cityCurrResult.Data as CurrencyInfo) == null ? 1 : (cityCurrResult.Data as CurrencyInfo)!.Rate : 1;
  796. //成本汇率
  797. var costCurr = _GroupCostParameters.Rate;
  798. if (tb.Rows.Count > 0)
  799. {
  800. foreach (DataRow item in tb.Rows)
  801. {
  802. var listTime = Convert.ToDateTime(item["日期"]);
  803. var costFliterArr = _GroupCosts.Where(x => DateTime.TryParse(x.Date, out DateTime costData)
  804. && costData.ToString("yyyy-MM-dd") == listTime.ToString("yyyy-MM-dd")).ToList();
  805. //成本日期费用
  806. decimal foodCost = (costFliterArr.Sum(x=>x.D) + costFliterArr.Sum(x => x.L) + costFliterArr.Sum(x => x.B)) * di.VisitPNumber;
  807. var price = Convert.ToDecimal(item["费用"]);
  808. if (item["币种"].ToString() != _GroupCostParameters.Currency.ToString().Trim()) //币种不相同
  809. {
  810. var a = item["币种"].ToString();
  811. var b = _GroupCostParameters.Currency.ToString().Trim();
  812. //币种str匹配不上在匹配Name
  813. if (int.TryParse(a,out int a1))
  814. {
  815. a = _sqlSugar.Queryable<Sys_SetData>().First(x=>x.IsDel ==0 && x.Id == a1).Name;
  816. }
  817. if (int.TryParse(b, out int b1))
  818. {
  819. b = _sqlSugar.Queryable<Sys_SetData>().First(x => x.IsDel == 0 && x.Id == b1).Name;
  820. }
  821. if (a != b)
  822. {
  823. //全部转换为rmb;
  824. item["费用"] = price * currOp;
  825. foodCost = (foodCost * costCurr);
  826. item["币种"] = "836";
  827. //cityPrice.Currency = 836;
  828. }
  829. }
  830. if (price > foodCost)
  831. {
  832. //每天费用大于三公费用
  833. groupExtraCostsArr.Add(new Fin_GroupExtraCost
  834. {
  835. Price = price - foodCost,
  836. CreateTime = DateTime.Now,
  837. CreateUserId = dto.CreateUserId,
  838. Coefficient = 1,
  839. DiId = dto.DiId,
  840. PriceCurrency = Convert.ToInt32(item["币种"]),
  841. PriceName = di.TeamName + "-" + priceCity + "-" + "餐费(地接导入)",
  842. PriceType = 1028,
  843. PriceDt = Convert.ToDateTime(item["日期"]),
  844. PriceSum = price - foodCost,
  845. PriceCount = 1,
  846. FilePath = string.Empty,
  847. PriceDetailType = 1049,
  848. });
  849. }
  850. }
  851. }
  852. }
  853. var isTrue = false;
  854. if (groupExtraCostsArr.Count > 0)
  855. {
  856. foreach (var item in groupExtraCostsArr)
  857. {
  858. 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();
  859. if (QuerySgin == null)
  860. {
  861. var resultThis = await PostGroupExtraCost_Operator(new Fin_GroupExtraCostDto_OP
  862. {
  863. coefficient = 1,
  864. createUser = dto.CreateUserId,
  865. currency = item.PriceCurrency,
  866. diId = item.DiId,
  867. editType = 1,
  868. filePath = string.Empty,
  869. payee = dto.Payee,
  870. PortType = 1,
  871. PriceCount = item.PriceCount,
  872. priceName = item.PriceName,
  873. remark = item.Remark,
  874. price = item.Price,
  875. priceDetailType = item.PriceDetailType,
  876. priceType = item.PriceType,
  877. PriceDt = item.PriceDt.ToString("yyyy-MM-dd"),
  878. payType = dto.PayDId,
  879. costSign = dto.OrbitalPrivateTransfer
  880. });
  881. isTrue = resultThis.Code == 0 ? true : false;
  882. }
  883. else
  884. {
  885. item.Id = QuerySgin.Id;
  886. var resultThis = await PostGroupExtraCost_Operator(new Fin_GroupExtraCostDto_OP
  887. {
  888. coefficient = 1,
  889. createUser = dto.CreateUserId,
  890. currency = item.PriceCurrency,
  891. diId = item.DiId,
  892. editType = 2,
  893. filePath = string.Empty,
  894. payee = dto.Payee,
  895. PortType = 1,
  896. PriceCount = item.PriceCount,
  897. priceName = item.PriceName,
  898. remark = item.Remark,
  899. price = item.Price,
  900. priceDetailType = item.PriceDetailType,
  901. priceType = item.PriceType,
  902. PriceDt = item.PriceDt.ToString("yyyy-MM-dd"),
  903. payType = dto.PayDId,
  904. costSign = dto.OrbitalPrivateTransfer,
  905. Id = item.Id,
  906. });
  907. isTrue = resultThis.Code == 0 ? true : false;
  908. }
  909. }
  910. }
  911. #endregion
  912. }
  913. foreach (var item in carTouristList)
  914. {
  915. Grp_CarTouristGuideGroundReservationsContent QueryData = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().First(a => a.SId == item.SId && a.Id == item.Id && a.DiId == item.DiId && a.IsDel == 0);
  916. if (QueryData == null)
  917. {
  918. int id = await _sqlSugar.Insertable(item).ExecuteReturnIdentityAsync();
  919. if (id == 0)
  920. {
  921. RollbackTran();
  922. return result = new Result() { Code = -2, Msg = "添加失败" };
  923. }
  924. }
  925. else
  926. {
  927. int CTable = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.Id == item.Id).SetColumns(a => new Grp_CarTouristGuideGroundReservationsContent
  928. {
  929. Price = item.Price,
  930. PriceContent = item.PriceContent,
  931. Currency = dto.Currency,
  932. Remark = item.Remark,
  933. DatePrice = item.DatePrice,
  934. Count = item.Count,
  935. Units = item.Units,
  936. }).ExecuteCommandAsync();
  937. if (CTable == 0)
  938. {
  939. RollbackTran();
  940. return result = new Result() { Code = -1, Msg = "修改失败,请稍后重试!" };
  941. }
  942. }
  943. }
  944. Regex regex = new Regex("^[\u4e00-\u9fa5]{0,}$");
  945. //修改C表数据
  946. //List<Grp_CarTouristGuideGroundReservationsContent> carTouristListEnd = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>().Where(a=>a.DiId==dto.DiId && a.CTGGRId==dto.CTGGRId && a.IsDel==0).ToList();
  947. Grp_CreditCardPayment c = new Grp_CreditCardPayment();
  948. c.PaymentCurrency = dto.Currency;
  949. for (int i = 0; i < dto.SelectCheck.Count; i++)
  950. {
  951. if (!regex.IsMatch(dto.SelectCheck[i]))
  952. {
  953. for (int j = 0; j < carTouristList.Count; j++)
  954. {
  955. if (int.Parse(dto.SelectCheck[i]) == carTouristList[j].SId)
  956. {
  957. c.PayMoney += carTouristList[j].Price * carTouristList[j].Count;
  958. }
  959. }
  960. }
  961. else
  962. {
  963. c.PayMoney = carTouristList.Sum(x => x.Price * x.Count);
  964. break;
  965. }
  966. }
  967. c.PayPercentage = dto.PayPercentage;
  968. c.ConsumptionDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  969. c.CTable = 79;
  970. c.CId = dto.CTGGRId;
  971. c.IsAuditGM = 0;
  972. c.PayDId = dto.PayDId;
  973. c.DIId = dto.DiId;
  974. c.OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer;
  975. c.Payee = dto.Payee;
  976. c.CreateUserId = dto.CreateUserId;
  977. if (c.PayDId == 72) c.IsPay = 1;
  978. else c.IsPay = 0;
  979. c.RMBPrice = c.PayMoney;
  980. c.DayRate = 1;
  981. #region 老汇率获取
  982. //Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == dto.DiId && a.IsDel == 0 && a.CTable == 79);
  983. //List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  984. //if (_TeamRate != null)
  985. //{
  986. // Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == c.PaymentCurrency);
  987. // if (_SetData != null)
  988. // {
  989. // currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  990. // CurrencyInfo CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  991. // if (CurrencyRate != null)
  992. // {
  993. // c.RMBPrice = c.PayMoney * Convert.ToDecimal(CurrencyRate.Rate);
  994. // c.DayRate = CurrencyRate.Rate;
  995. // }
  996. // }
  997. //}
  998. #endregion
  999. var rate = await _setDataRep.PostCurrencyByDiid(dto.DiId, 79 ,dto.Currency);
  1000. if (rate.Code == 0)
  1001. {
  1002. var rateData = rate.Data as CurrencyInfo;
  1003. if (rateData != null)
  1004. {
  1005. c.RMBPrice = c.PayMoney * rateData.Rate;
  1006. c.DayRate = rateData.Rate;
  1007. }
  1008. }
  1009. Grp_CreditCardPayment grp_CreditCard = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == dto.CTGGRId && a.IsDel == 0 && a.CTable == 79 && a.DIId == dto.DiId);
  1010. if (grp_CreditCard != null)//修改
  1011. {
  1012. 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
  1013. {
  1014. PaymentCurrency = c.PaymentCurrency,
  1015. PayMoney = c.PayMoney,
  1016. PayPercentage = c.PayPercentage,
  1017. CTable = c.CTable,
  1018. PayDId = c.PayDId,
  1019. OrbitalPrivateTransfer = c.OrbitalPrivateTransfer,
  1020. Payee = c.Payee,
  1021. IsPay = c.IsPay,
  1022. RMBPrice = c.RMBPrice,
  1023. DayRate = c.DayRate,
  1024. }).ExecuteCommandAsync();
  1025. if (CTable == 0)
  1026. {
  1027. RollbackTran();
  1028. return result = new Result() { Code = -2, Msg = "修改失败" };
  1029. }
  1030. }
  1031. else//添加
  1032. {
  1033. int id = await _sqlSugar.Insertable(c).ExecuteReturnIdentityAsync();
  1034. if (id == 0)
  1035. {
  1036. RollbackTran();
  1037. return result = new Result() { Code = -2, Msg = "添加失败" };
  1038. }
  1039. }
  1040. 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
  1041. {
  1042. CId = dto.Currency,
  1043. ServiceQuotedPrice = c.PayMoney,
  1044. OrbitalPrivateTransfer = dto.OrbitalPrivateTransfer,
  1045. SelectCheck = string.Join(',', dto.SelectCheck)
  1046. }).ExecuteCommandAsync();
  1047. if (CarTouristGuideCTable == 0)
  1048. {
  1049. RollbackTran();
  1050. return result = new Result() { Code = -2, Msg = "修改失败" };
  1051. }
  1052. result = new Result() { Code = 0, Msg = "保存成功" };
  1053. CommitTran();
  1054. }
  1055. catch (Exception ex)
  1056. {
  1057. RollbackTran();
  1058. return result = new Result() { Code = -2, Msg = "未知错误" };
  1059. }
  1060. return result;
  1061. }
  1062. /// <summary>
  1063. /// 超支费用
  1064. /// 1增、2改、3删
  1065. /// </summary>
  1066. /// <param name="dto"></param>
  1067. /// <returns></returns>
  1068. private async Task<Result> PostGroupExtraCost_Operator(Fin_GroupExtraCostDto_OP dto)
  1069. {
  1070. Result rt = new Result();
  1071. #region 验证
  1072. #endregion
  1073. Fin_GroupExtraCost _entity = new Fin_GroupExtraCost();
  1074. _entity.DiId = dto.diId;
  1075. _entity.PriceName = dto.priceName;
  1076. _entity.Price = dto.price;
  1077. _entity.PriceCurrency = dto.currency;
  1078. _entity.PriceType = dto.priceType;
  1079. _entity.Coefficient = dto.coefficient;
  1080. _entity.PriceDetailType = dto.priceDetailType;
  1081. _entity.FilePath = dto.filePath;
  1082. _entity.Remark = dto.remark;
  1083. _entity.PriceCount = dto.PriceCount;
  1084. _entity.PriceDt = DateTime.Parse(dto.PriceDt);
  1085. _entity.PriceSum = dto.price * dto.PriceCount;
  1086. _daiRep.BeginTran();
  1087. if (dto.editType == 1)
  1088. {
  1089. _entity.CreateUserId = dto.createUser;
  1090. _entity.CreateTime = DateTime.Now;
  1091. _entity.IsDel = 0;
  1092. int returnId = await _daiRep.AddAsyncReturnId<Fin_GroupExtraCost>(_entity);
  1093. if (returnId > 0)
  1094. {
  1095. dto.Id = returnId;
  1096. }
  1097. }
  1098. else if (dto.editType == 2)
  1099. {
  1100. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  1101. {
  1102. PriceName = dto.priceName,
  1103. Price = dto.price,
  1104. PriceCurrency = dto.currency,
  1105. PriceType = dto.priceType,
  1106. PriceDetailType = dto.priceDetailType,
  1107. Coefficient = dto.coefficient,
  1108. FilePath = dto.filePath,
  1109. Remark = dto.remark,
  1110. PriceCount = dto.PriceCount,
  1111. PriceDt = _entity.PriceDt,
  1112. PriceSum = _entity.PriceSum
  1113. });
  1114. if (!res)
  1115. {
  1116. _daiRep.RollbackTran();
  1117. //Ok(JsonView(false, "2操作失败!"))
  1118. rt.Msg = "2操作失败!";
  1119. return rt;
  1120. }
  1121. }
  1122. else if (dto.editType == 3)
  1123. {
  1124. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  1125. bool res = await _daiRep.UpdateAsync<Fin_GroupExtraCost>(s => s.Id == dto.Id, s => new Fin_GroupExtraCost
  1126. {
  1127. IsDel = 1,
  1128. DeleteTime = delTime,
  1129. DeleteUserId = dto.createUser
  1130. });
  1131. if (!res)
  1132. {
  1133. _daiRep.RollbackTran();
  1134. rt.Msg = "3操作失败!";
  1135. return rt;
  1136. }
  1137. }
  1138. else
  1139. {
  1140. _daiRep.RollbackTran();
  1141. rt.Msg = "未知的editType";
  1142. return rt;
  1143. }
  1144. if (!extraCost_editCreditCardPayment(dto))
  1145. {
  1146. rt.Msg = "ccp操作失败";
  1147. return rt;
  1148. }
  1149. _daiRep.CommitTran();
  1150. rt.Code = 0;
  1151. rt.Msg = "操作成功";
  1152. return rt;
  1153. }
  1154. private bool extraCost_editCreditCardPayment(Fin_GroupExtraCostDto_OP costDto)
  1155. {
  1156. //设置团组汇率
  1157. decimal dcm_dayrate = 1M;
  1158. decimal dcm_rmbPrice = costDto.price;
  1159. int ispay = costDto.payType == 72 ? 1 : 0;
  1160. if (costDto.costSign != 3)
  1161. {
  1162. Grp_TeamRate tr = _daiRep.Query<Grp_TeamRate>(s => s.DiId == costDto.diId && s.CTable == 1015).First();
  1163. if (tr != null)
  1164. {
  1165. if (costDto.currency == 49)
  1166. {
  1167. dcm_dayrate = tr.RateU;
  1168. dcm_rmbPrice = dcm_rmbPrice * tr.RateU;
  1169. }
  1170. else if (costDto.currency == 51)
  1171. {
  1172. dcm_dayrate = tr.RateE;
  1173. dcm_rmbPrice = dcm_rmbPrice * tr.RateE;
  1174. }
  1175. }
  1176. }
  1177. Grp_CreditCardPayment ccp = _daiRep.Query<Grp_CreditCardPayment>(s => s.CId == costDto.Id && s.CTable == 1015).First();
  1178. if (ccp == null)
  1179. {
  1180. ccp = new Grp_CreditCardPayment();
  1181. ccp.PayDId = costDto.payType;// dto
  1182. ccp.ConsumptionPatterns = "";
  1183. ccp.ConsumptionDate = "";
  1184. ccp.CTDId = costDto.payCardId;// dto
  1185. ccp.BankNo = "";
  1186. ccp.CardholderName = "";
  1187. ccp.PayMoney = costDto.price;// dto
  1188. ccp.PaymentCurrency = costDto.currency;// dto
  1189. ccp.CompanyBankNo = "";
  1190. ccp.OtherBankName = "";
  1191. ccp.OtherSideNo = "";
  1192. ccp.OtherSideName = "";
  1193. ccp.Remark = "";
  1194. ccp.CreateUserId = costDto.createUser;
  1195. ccp.CreateTime = DateTime.Now;
  1196. ccp.MFOperator = 0;
  1197. ccp.MFOperatorDate = "";
  1198. ccp.IsAuditDM = 0;
  1199. ccp.AuditDMOperate = 0;
  1200. ccp.AuditDMDate = "";
  1201. ccp.IsAuditMF = 0;
  1202. ccp.AuditMFOperate = 0;
  1203. ccp.AuditMFDate = "";
  1204. ccp.IsAuditGM = 0;
  1205. ccp.AuditGMOperate = 0;
  1206. ccp.AuditGMDate = "";
  1207. ccp.IsPay = ispay; // upd
  1208. ccp.DIId = costDto.diId;// dto
  1209. ccp.CId = costDto.Id;// dto
  1210. ccp.CTable = 1015; //超支费用指向id
  1211. ccp.IsDel = 0;
  1212. ccp.PayPercentage = 100M;
  1213. ccp.PayThenMoney = 0M;
  1214. ccp.PayPercentageOld = 100M;
  1215. ccp.PayThenMoneyOld = 0M;
  1216. ccp.UpdateDate = "";
  1217. ccp.Payee = costDto.payee;// dto
  1218. ccp.OrbitalPrivateTransfer = costDto.costSign;// dto
  1219. ccp.ExceedBudget = 0;
  1220. ccp.DayRate = dcm_dayrate; //upd
  1221. ccp.RMBPrice = dcm_rmbPrice; //upd
  1222. int ccpInsertId = _daiRep.AddReturnId<Grp_CreditCardPayment>(ccp);
  1223. if (ccpInsertId > 0)
  1224. {
  1225. return true;
  1226. }
  1227. }
  1228. else
  1229. {
  1230. if (costDto.editType == 2)
  1231. {
  1232. bool res = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1233. {
  1234. PayDId = costDto.payType,
  1235. CTDId = costDto.payCardId,
  1236. PayMoney = costDto.price,
  1237. PaymentCurrency = costDto.currency,
  1238. IsPay = ispay,
  1239. Payee = costDto.payee,
  1240. OrbitalPrivateTransfer = costDto.costSign,
  1241. DayRate = dcm_dayrate,
  1242. RMBPrice = dcm_rmbPrice
  1243. });
  1244. return res;
  1245. }
  1246. else if (costDto.editType == 3)
  1247. {
  1248. string delTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  1249. bool res2 = _daiRep.Update<Grp_CreditCardPayment>(s => s.Id == ccp.Id, s => new Grp_CreditCardPayment
  1250. {
  1251. IsDel = 1,
  1252. DeleteTime = delTime,
  1253. DeleteUserId = costDto.createUser
  1254. });
  1255. return res2;
  1256. }
  1257. }
  1258. return false;
  1259. }
  1260. }
  1261. }