CarTouristGuideGroundRepository.cs 74 KB

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