CarTouristGuideGroundRepository.cs 68 KB

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