CarTouristGuideGroundRepository.cs 68 KB

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