CarTouristGuideGroundRepository.cs 66 KB

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