CarTouristGuideGroundRepository.cs 74 KB

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